1039 lines
26 KiB
C++
1039 lines
26 KiB
C++
#include "stdafx.h"
|
|
#include "AecDbRadiusDim.h"
|
|
#include "PushProperty.h"
|
|
#include "AecDbDimension.h"
|
|
#include "AecDbText.h"
|
|
#include "globalFunc.h"
|
|
#include "AcDbObjectPtr.h"
|
|
#include "superlist.h"
|
|
#include "gecurveinline.h"
|
|
#include "ADSgepointdir2d.h"
|
|
#include "SortedVertexList.h"
|
|
#include "PushMemVar.h"
|
|
|
|
#pragma region AecXDbRadiusDim
|
|
const Adesk::UInt8 AecXDbRadiusDim::g_nVersion = 1;
|
|
|
|
ACRX_DXF_DEFINE_MEMBERS(AecXDbRadiusDim, AecXDbEntityBaseEx, AcDb::kDHL_CURRENT, AcDb::kMReleaseCurrent,
|
|
1, AEC_BANJINGBIAOZHU, "AEC_BANJINGBIAOZHU|图形无法解析, 请下载上华软件|网址: www.shanghuasoft.com");
|
|
|
|
AecXDbRadiusDim::AecXDbRadiusDim()
|
|
{
|
|
m_nDimFlag = 0;
|
|
m_nDimLen = 26.0;
|
|
}
|
|
|
|
|
|
AecXDbRadiusDim::~AecXDbRadiusDim()
|
|
{
|
|
}
|
|
|
|
// 从DWG读入数据:
|
|
Acad::ErrorStatus AecXDbRadiusDim::dwgInFields(AcDbDwgFiler* pFiler)
|
|
{
|
|
AssertWriteEnabled();
|
|
|
|
Acad::ErrorStatus es = AecXDbEntityBaseEx::dwgInFields(pFiler);
|
|
if (es != Acad::eOk) return es;
|
|
Adesk::UInt8 nVer;
|
|
pFiler->readItem(&nVer);
|
|
if (nVer > g_nVersion) {// Version is too new
|
|
return Acad::eMakeMeProxy;
|
|
}
|
|
|
|
pFiler->readItem(&m_nDimFlag);
|
|
pFiler->readItem(&m_idDimStyle);
|
|
pFiler->readItem(&m_nDimLen);
|
|
pFiler->readItem((AcGePoint3d *)&m_ptCenter);
|
|
pFiler->readItem((AcGePoint2d *)&m_ptOnArc);
|
|
m_sText = _T("");
|
|
if (m_nDimFlag & DF_TEXT)
|
|
GlobalFunc::ReadString(pFiler, m_sText);
|
|
if (m_nDimFlag & DF_POSITION)
|
|
pFiler->readItem((AcGePoint2d *)&m_ptText);
|
|
return pFiler->filerStatus();
|
|
}
|
|
|
|
Acad::ErrorStatus AecXDbRadiusDim::dwgOutFields(AcDbDwgFiler* pFiler) const
|
|
{
|
|
assertReadEnabled();
|
|
Acad::ErrorStatus es = AecXDbEntityBaseEx::dwgOutFields(pFiler);
|
|
if (es != Acad::eOk) return es;
|
|
|
|
pFiler->writeItem(g_nVersion);
|
|
pFiler->writeItem(m_nDimFlag);
|
|
pFiler->writeItem(m_idDimStyle);
|
|
pFiler->writeItem(m_nDimLen);
|
|
pFiler->writeItem((const AcGePoint3d &)m_ptCenter);
|
|
pFiler->writeItem((const AcGePoint2d &)m_ptOnArc);
|
|
if (m_nDimFlag & DF_TEXT)
|
|
pFiler->writeString(m_sText);
|
|
if (m_nDimFlag & DF_POSITION)
|
|
pFiler->writeItem((const AcGePoint2d &)m_ptText);
|
|
return pFiler->filerStatus();
|
|
}
|
|
|
|
Acad::ErrorStatus AecXDbRadiusDim::dxfInFields(AcDbDxfFiler* pFiler)
|
|
{
|
|
AssertWriteEnabled();
|
|
|
|
Acad::ErrorStatus es = AecXDbEntityBaseEx::dxfInFields(pFiler);
|
|
if (es != Acad::eOk)
|
|
return es;
|
|
|
|
if (!pFiler->atSubclassData(_T("AecXDbRadiusDim"))) {
|
|
return Acad::eBadDxfSequence;
|
|
}
|
|
|
|
TCString sText, sName;
|
|
double nDist;
|
|
int nFlag;
|
|
ADSGePoint3d pt1, pt2, pt3;
|
|
Adesk::UInt32 fieldsFlags = 0;
|
|
resbuf rb;
|
|
while ((es == Acad::eOk)
|
|
&& ((es = pFiler->readResBuf(&rb)) == Acad::eOk)) {
|
|
switch (rb.restype) {
|
|
case AcDb::kDxfInt16:
|
|
nFlag = rb.resval.rint;
|
|
fieldsFlags |= 0x01;
|
|
break;
|
|
case AcDb::kDxfXCoord:
|
|
pt1 = rb.resval.rpoint;
|
|
fieldsFlags |= 0x02;
|
|
break;
|
|
case AcDb::kDxfXCoord + 1:
|
|
pt2 = rb.resval.rpoint;
|
|
fieldsFlags |= 0x04;
|
|
break;
|
|
case AcDb::kDxfXCoord + 5:
|
|
pt3 = rb.resval.rpoint;
|
|
fieldsFlags |= 0x08;
|
|
break;
|
|
case AcDb::kDxfText:
|
|
fieldsFlags |= 0x10;
|
|
sText = rb.resval.rstring;
|
|
break;
|
|
case AcDb::kDxfDimStyleName:
|
|
sName = rb.resval.rstring;
|
|
fieldsFlags |= 0x20;
|
|
break;
|
|
case AcDb::kDxfReal:
|
|
fieldsFlags |= 0x40;
|
|
nDist = rb.resval.rreal;
|
|
break;
|
|
//fall through intentional
|
|
default:
|
|
// An unrecognized group. Push it back so that
|
|
// the subclass can read it again.
|
|
pFiler->pushBackItem();
|
|
es = Acad::eEndOfFile;
|
|
break;
|
|
}
|
|
}
|
|
|
|
// At this point the es variable must contain eEndOfFile
|
|
// - either from readResBuf() or from pushback. If not,
|
|
// it indicates that an error happened and we should
|
|
// return immediately.
|
|
//
|
|
if (es != Acad::eEndOfFile)
|
|
return Acad::eInvalidResBuf;
|
|
|
|
if (!(fieldsFlags & 0x02)) {
|
|
pFiler->setError(Acad::eMissingDxfField,
|
|
_T("\nMissing DXF group code: 10"));
|
|
return Acad::eMissingDxfField;
|
|
}
|
|
if (!(fieldsFlags & 0x04)) {
|
|
pFiler->setError(Acad::eMissingDxfField,
|
|
_T("\nMissing DXF group code: 11"));
|
|
return Acad::eMissingDxfField;
|
|
}
|
|
if (!(fieldsFlags & 0x08)) {
|
|
pFiler->setError(Acad::eMissingDxfField,
|
|
_T("\nMissing DXF group code: 15"));
|
|
return Acad::eMissingDxfField;
|
|
}
|
|
|
|
if (fieldsFlags & 0x01)
|
|
m_nDimFlag = nFlag;
|
|
m_ptCenter = pt1;
|
|
m_ptText = pt2;
|
|
m_ptOnArc = pt3;
|
|
|
|
if (fieldsFlags & 0x10)
|
|
m_sText = sText;
|
|
AcDbObjectId id;
|
|
if (fieldsFlags & 0x20) {
|
|
id = GlobalFunc::GetDimStyleId(sName);
|
|
}
|
|
if (!id) {
|
|
TCString style;
|
|
GlobalFunc::TGGetVar(_T("DIMSTYLE"), style);
|
|
m_idDimStyle = GlobalFunc::GetTextStyleId(style);
|
|
}
|
|
else
|
|
m_idDimStyle = id;
|
|
|
|
if (fieldsFlags & 0x40)
|
|
m_nDimLen = nDist;
|
|
|
|
return pFiler->filerStatus();
|
|
}
|
|
|
|
Acad::ErrorStatus AecXDbRadiusDim::dxfOutFields(AcDbDxfFiler* pFiler) const
|
|
{
|
|
assertReadEnabled();
|
|
Acad::ErrorStatus es = AecXDbEntityBaseEx::dxfOutFields(pFiler);
|
|
assert(es == Acad::eOk);
|
|
|
|
es = pFiler->writeItem(AcDb::kDxfSubclass, _T("AecXDbRadiusDim"));
|
|
assert(es == Acad::eOk);
|
|
pFiler->writeInt16(AcDb::kDxfInt16, m_nDimFlag);
|
|
pFiler->writePoint2d(AcDb::kDxfXCoord, m_ptCenter.AsAcGePoint2d());
|
|
pFiler->writePoint2d(AcDb::kDxfXCoord + 1, m_ptText.AsAcGePoint2d());
|
|
pFiler->writePoint2d(AcDb::kDxfXCoord + 5, m_ptOnArc.AsAcGePoint2d());
|
|
pFiler->writeString(AcDb::kDxfText, (const TCHAR *)m_sText);
|
|
TCString sName = GlobalFunc::GetSymbolName(m_idDimStyle);
|
|
pFiler->writeString(AcDb::kDxfDimStyleName, (const TCHAR *)sName); //3
|
|
pFiler->writeDouble(AcDb::kDxfReal, m_nDimLen);
|
|
return pFiler->filerStatus();
|
|
}
|
|
|
|
void AecXDbRadiusDim::CopyPropertiesFrom(AcDbEntity *pSrcEntity, unsigned gMatchFlag)
|
|
{
|
|
AssertWriteEnabled();
|
|
AecXDbEntityBaseEx::CopyPropertiesFrom(pSrcEntity, gMatchFlag);
|
|
AecXDbRadiusDim *pSrc = AecXDbRadiusDim::cast(pSrcEntity);
|
|
if (pSrc) {
|
|
if (database() == NULL ||
|
|
pSrcEntity->database() == NULL ||
|
|
database() == pSrcEntity->database())//add by whl on 060317
|
|
{
|
|
m_idDimStyle = pSrc->m_idDimStyle; //尺寸标注类型
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
Acad::ErrorStatus
|
|
AecXDbRadiusDim::subGetOsnapPoints(AcDb::OsnapMode osnapMode,
|
|
INT_PTR gsSelectionMark,
|
|
const AcGePoint3d& pickPoint,
|
|
const AcGePoint3d& lastPoint,
|
|
const AcGeMatrix3d& viewXform,
|
|
AcGePoint3dArray& snapPoints,
|
|
AcDbIntArray& geomIds) const
|
|
{
|
|
assertReadEnabled();
|
|
Acad::ErrorStatus es = Acad::eOk;
|
|
|
|
switch (osnapMode) {
|
|
case AcDb::kOsModeNode:
|
|
snapPoints.append(m_ptOnArc);
|
|
break;
|
|
case AcDb::kOsModeIns: {
|
|
ADSGePoint3d ptText = GetTextPos();
|
|
snapPoints.append(ptText);
|
|
}
|
|
break;
|
|
default:
|
|
es = AecXDbEntityBaseEx::subGetOsnapPoints(osnapMode, gsSelectionMark, pickPoint,
|
|
lastPoint, viewXform, snapPoints,
|
|
geomIds);
|
|
}
|
|
|
|
return es;
|
|
}
|
|
|
|
// Overriden functions for edit
|
|
// to do:
|
|
// 允许通过夹点改变边界
|
|
Acad::ErrorStatus AecXDbRadiusDim::subGetGripPoints(AcGePoint3dArray& gripPoints,
|
|
AcDbIntArray& osnapModes,
|
|
AcDbIntArray& geomIds) const
|
|
{
|
|
assertReadEnabled();
|
|
gripPoints.append(m_ptCenter); //0
|
|
ADSGePoint3d ptFix = GetDimStartPoint();
|
|
gripPoints.append(ptFix); //1
|
|
gripPoints.append(m_ptOnArc); //2
|
|
ADSGePoint3d ptText = GetTextPos(); //3
|
|
gripPoints.append(ptText);
|
|
return Acad::eOk;
|
|
}
|
|
|
|
Acad::ErrorStatus AecXDbRadiusDim::subGetGripPoints(AcDbGripDataPtrArray & grips, const double curViewUnitSize, const int gripSize, const AcGeVector3d & curViewDir, const int bitflags) const
|
|
{
|
|
return Acad::eNotImplementedYet;
|
|
}
|
|
|
|
// stretch points is diffrent from grep points, with no midpoint included
|
|
Acad::ErrorStatus AecXDbRadiusDim::subGetStretchPoints(AcGePoint3dArray & stretchPoints) const
|
|
{
|
|
assertReadEnabled();
|
|
AcDbIntArray osnapModes;
|
|
AcDbIntArray geomIds;
|
|
return subGetGripPoints(stretchPoints, osnapModes, geomIds);
|
|
}
|
|
|
|
|
|
|
|
// Active when being rotated, scaled, moved, etc.
|
|
// Scale is disabled here
|
|
Acad::ErrorStatus AecXDbRadiusDim::subTransformBy(const AcGeMatrix3d& xform)
|
|
{
|
|
AssertWriteEnabled();
|
|
AecXDbEntityBaseEx::subTransformBy(xform);
|
|
ads_matrix mat;
|
|
GlobalFunc::AsAdsMatrix(xform, mat);
|
|
m_ptCenter.TransformBy(mat);
|
|
m_ptOnArc.TransformBy(mat);
|
|
BOOL bIsDefault = TRUE;
|
|
ADSGePoint3d ptText = GetTextPos(&bIsDefault);
|
|
if (!bIsDefault) {
|
|
ptText.TransformBy(mat);
|
|
SetTextPos(ptText);
|
|
}
|
|
return Acad::eOk;
|
|
}
|
|
|
|
|
|
|
|
// 功能: 夹点操作
|
|
Acad::ErrorStatus AecXDbRadiusDim::subMoveGripPointsAt(
|
|
const AcDbIntArray& indices,
|
|
const AcGeVector3d& offset)
|
|
{
|
|
AssertWriteEnabled();
|
|
if (offset.length() < g_Option::instance()._DIST_SNAP)
|
|
return Acad::eOk;
|
|
ADSGePoint3d vtOffset(offset[0], offset[1]);
|
|
AcGePoint3dArray ptArray;
|
|
ADSGePoint3d ptFix = GetDimStartPoint();
|
|
for (int i = 0; i < indices.length(); i++) {
|
|
int idx = indices[i];
|
|
switch (idx) {
|
|
case 0:
|
|
m_ptCenter += vtOffset;
|
|
break;
|
|
case 1:
|
|
ptFix += vtOffset;
|
|
break;
|
|
case 2:
|
|
m_ptOnArc += vtOffset;
|
|
break;
|
|
case 3: {
|
|
ADSGePoint3d ptText = GetTextPos();
|
|
ptText += vtOffset;
|
|
SetTextPos(ptText);
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
if (indices.contains(1)) {
|
|
GeLine ln(m_ptCenter, m_ptOnArc);
|
|
ADSGePoint3d ptOnLine;
|
|
ptFix.Project(&ln, ptOnLine);
|
|
double nDist = ptOnLine.Distance2d(m_ptOnArc);
|
|
if ((ptOnLine & ln) == PR_EXTEND &&
|
|
ptOnLine.Distance2d(ln.EndPoint()) < ptOnLine.Distance2d(ln.StartPoint())) {
|
|
nDist = -nDist;
|
|
}
|
|
SetDimLen(nDist, FALSE);
|
|
}
|
|
return Acad::eOk;
|
|
}
|
|
|
|
|
|
// 功能: 夹点操作
|
|
Acad::ErrorStatus AecXDbRadiusDim::subMoveStretchPointsAt(
|
|
const AcDbIntArray& indices,
|
|
const AcGeVector3d& offset)
|
|
{
|
|
return subMoveGripPointsAt(indices, offset);
|
|
}
|
|
|
|
// 取得夹点说明
|
|
Acad::ErrorStatus AecXDbRadiusDim::GetGripText(int i, CString &cs) const
|
|
{
|
|
Acad::ErrorStatus es = Acad::eOk;
|
|
switch (i) {
|
|
case 0:
|
|
cs = _T("移动圆心");
|
|
break;
|
|
case 1:
|
|
cs = _T("移动引线位置");
|
|
break;
|
|
case 2:
|
|
cs = _T("移动标注点");
|
|
break;
|
|
case 3:
|
|
cs = _T("移动文字");
|
|
break;
|
|
default:
|
|
es = Acad::eInvalidInput;
|
|
}
|
|
return es;
|
|
}
|
|
|
|
Acad::ErrorStatus AecXDbRadiusDim::Draw2d(AcGiDraw &dc) const
|
|
{
|
|
assertReadEnabled();
|
|
|
|
GlobalFunc::_LoadConfig();
|
|
|
|
if (Has2DBuffer())
|
|
{
|
|
dc.SetColor(colorIndex());
|
|
dc.SetLayer(layerId());
|
|
BaseEx::_Draw2DBuffers(dc, true);
|
|
return Acad::eOk;
|
|
}
|
|
|
|
//modified by whl on 060223
|
|
//BOOL bCheckDim=DocGetCheckDim();
|
|
BOOL bCheckDim = GlobalFunc::DocGetCheckDim() && !g_Option::instance().g_bExplodeSubText;
|
|
|
|
double nPScale = GetPScale();
|
|
double nArrowLen = 2.0;
|
|
double nArrowWidth = 0.66;
|
|
double dimgap = 0, dimtxt = 0;
|
|
double dimscale = 1.0, dimasz = 1.0;
|
|
int dimclrd = 0, dimclrt = 0;
|
|
int dimdec = 0;
|
|
double dimlfac = 1.0; //单位换算系数;
|
|
TCString sDimPrefix, sDimSuffix;
|
|
AcDbObjectId dimblk;
|
|
AcDbObjectId dimtxsty;
|
|
OPENOBJ_BEGIN(m_idDimStyle, AcDb::kForRead, AcDbDimStyleTableRecord, pDimStyle);
|
|
if (pDimStyle) {
|
|
dimdec = pDimStyle->dimdec();
|
|
dimgap = pDimStyle->dimgap();
|
|
dimtxt = pDimStyle->dimtxt();
|
|
dimscale = GetPScale(); //pDimStyle->dimscale();
|
|
dimasz = pDimStyle->dimasz();
|
|
dimtxsty = pDimStyle->dimtxsty();
|
|
dimblk = pDimStyle->dimblk();
|
|
dimlfac = pDimStyle->dimlfac();
|
|
//sTextStyle=GlobalFunc::GetSymbolName(dimtxsty);
|
|
dimclrd = pDimStyle->dimclrd().colorIndex();
|
|
dimclrt = pDimStyle->dimclrt().colorIndex();
|
|
const TCHAR *dimpost = pDimStyle->dimpost();
|
|
const TCHAR *pStr = NULL;
|
|
if (dimpost)
|
|
pStr = _tcsstr(dimpost, _T("<>"));
|
|
if (pStr) {
|
|
GlobalFunc::_StrCpy(sDimPrefix, dimpost, pStr);
|
|
GlobalFunc::_StrCpy(sDimSuffix, pStr + 2, NULL);
|
|
}
|
|
else if (dimpost) {
|
|
_tcscpy(sDimSuffix, dimpost);
|
|
}
|
|
}
|
|
else {
|
|
return Acad::eInvalidInput;
|
|
}
|
|
OPENOBJ_END();
|
|
|
|
int nOldColor = dc.GetColor();
|
|
AcDbPolyline pline;
|
|
ADSGePoint3d ptStart = GetDimStartPoint();
|
|
ADSGePoint3d ptEnd = GetDimEndPoint();
|
|
|
|
if (!IsDiameter())
|
|
{
|
|
ADSGePoint3d ptArrow;
|
|
ads_polar(ptEnd, ads_angle(ptEnd, ptStart), nArrowLen * nPScale, ptArrow);
|
|
pline.addVertexAt(0, ptStart);
|
|
pline.addVertexAt(1, ptArrow);
|
|
pline.addVertexAt(2, ptEnd);
|
|
/*pline.setWidthsAt(1, nArrowWidth*nPScale, 0.0);*/
|
|
|
|
//TGGeCurveSegment(const TADSGePoint3d &spt, const TADSGePoint3d &ept, ads_real dAng, int flg = LS_FINITE);
|
|
GeCurveSegment segDim(ptStart, ptEnd, 0, LS_FINITE);
|
|
|
|
//支持箭头的更改
|
|
if (!dimblk) // 尺寸箭头
|
|
{
|
|
// sg modify 120412,解决“实心闭合”样式,不支持设置“箭头大小”的问题
|
|
double dXSize = 1.0 * dimscale * dimasz,
|
|
dYSize = 0.33 * dimscale * dimasz;
|
|
|
|
int nDealOldDimArrowSize = 1;
|
|
if (nDealOldDimArrowSize == 0 && fabs(dimasz - 1.0) < 1.0E-3) // 旧版本的“实心闭合”样式
|
|
{
|
|
dXSize *= 2;
|
|
dYSize *= 2;
|
|
}
|
|
|
|
ADSGePointDir2d pt1, pt2;
|
|
segDim.Polar(dXSize, pt1);
|
|
segDim.Polar(dXSize, pt2, FALSE);
|
|
|
|
AcDbPolyline *plArrow2 = new AcDbPolyline();
|
|
plArrow2->setPropertiesFrom(this);
|
|
plArrow2->addVertexAt(0, pt2);
|
|
plArrow2->setWidthsAt(0, dYSize, 0.0);
|
|
plArrow2->addVertexAt(1, segDim.EndPoint());
|
|
plArrow2->setWidthsAt(1, 0.0, 0.0);
|
|
dc.DrawEntity(*plArrow2);
|
|
Add2DBuffer(plArrow2);
|
|
}
|
|
else
|
|
{
|
|
DrawBlock(dc
|
|
, dimblk
|
|
, segDim.EndPoint()
|
|
, AcGeScale3d(dimscale * dimasz, dimscale * dimasz, dimscale * dimasz)
|
|
, segDim.IDirection(1) + PI);
|
|
DrawBlock(dc
|
|
, dimblk
|
|
, segDim.StartPoint()
|
|
, AcGeScale3d(dimscale * dimasz, dimscale * dimasz, dimscale * dimasz)
|
|
, segDim.IDirection(0));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//直径标注
|
|
double nAng = ads_angle(m_ptOnArc, m_ptCenter);
|
|
ADSGePoint3d ptOnArc0, ptArrow0, ptArrow;
|
|
ads_polar(m_ptCenter, nAng, GetRadius(), ptOnArc0);
|
|
ads_polar(ptOnArc0, nAng + PI, nArrowLen * nPScale, ptArrow0);
|
|
ads_polar(m_ptOnArc, nAng, nArrowLen * nPScale, ptArrow);
|
|
|
|
pline.addVertexAt(0, ptOnArc0);
|
|
//pline.addVertexAt(1, ptArrow0);
|
|
//pline.addVertexAt(2, ptArrow);
|
|
pline.addVertexAt(1, m_ptOnArc);
|
|
//pline.setWidthsAt(0, 0.0, nArrowWidth*nPScale);
|
|
//pline.setWidthsAt(2, nArrowWidth*nPScale, 0.0);
|
|
if (m_nDimLen < 0) { //外标注
|
|
ADSGePoint3d ptStart = GetDimStartPoint();
|
|
pline.addVertexAt(2, ptStart);
|
|
}
|
|
|
|
GeCurveSegment segDim(ptOnArc0, m_ptOnArc, 0, LS_FINITE);
|
|
//支持箭头的更改
|
|
if (!dimblk) // 尺寸箭头
|
|
{
|
|
// sg modify 120412,解决“实心闭合”样式,不支持设置“箭头大小”的问题
|
|
double dXSize = 1.0 * dimscale * dimasz,
|
|
dYSize = 0.33 * dimscale * dimasz;
|
|
|
|
int nDealOldDimArrowSize = 1;
|
|
if (nDealOldDimArrowSize == 0 && fabs(dimasz - 1.0) < 1.0E-3) // 旧版本的“实心闭合”样式
|
|
{
|
|
dXSize *= 2;
|
|
dYSize *= 2;
|
|
}
|
|
|
|
ADSGePointDir2d pt1, pt2;
|
|
segDim.Polar(dXSize, pt1);
|
|
segDim.Polar(dXSize, pt2, FALSE);
|
|
|
|
AcDbPolyline *plArrow1 = new AcDbPolyline();
|
|
plArrow1->setPropertiesFrom(this);
|
|
plArrow1->addVertexAt(0, pt1);
|
|
plArrow1->setWidthsAt(0, dYSize, 0.0);
|
|
plArrow1->addVertexAt(1, segDim.StartPoint());
|
|
plArrow1->setWidthsAt(1, 0.0, 0.0);
|
|
dc.DrawEntity(*plArrow1);
|
|
Add2DBuffer(plArrow1);
|
|
|
|
AcDbPolyline *plArrow2 = new AcDbPolyline();;
|
|
plArrow2->setPropertiesFrom(this);
|
|
plArrow2->addVertexAt(0, pt2);
|
|
plArrow2->setWidthsAt(0, dYSize, 0.0);
|
|
plArrow2->addVertexAt(1, segDim.EndPoint());
|
|
plArrow2->setWidthsAt(1, 0.0, 0.0);
|
|
dc.DrawEntity(*plArrow2);
|
|
|
|
|
|
}
|
|
else
|
|
{
|
|
DrawBlock(dc
|
|
, dimblk
|
|
, segDim.EndPoint()
|
|
, AcGeScale3d(dimscale * dimasz, dimscale * dimasz, dimscale * dimasz)
|
|
, segDim.IDirection(1) + PI);
|
|
DrawBlock(dc
|
|
, dimblk
|
|
, segDim.StartPoint()
|
|
, AcGeScale3d(dimscale * dimasz, dimscale * dimasz, dimscale * dimasz)
|
|
, segDim.IDirection(0));
|
|
}
|
|
}
|
|
pline.setPropertiesFrom(this);
|
|
if (dimclrd && dimclrd != 256)
|
|
pline.setColorIndex(dimclrd);
|
|
|
|
if (dimclrd) dc.SetColor(dimclrd);
|
|
AcDbPolyline *pL = (AcDbPolyline*)pline.clone();
|
|
dc.DrawEntity(*pL);
|
|
Add2DBuffer(pL);
|
|
|
|
|
|
// 文字
|
|
AecXDbText dimText;
|
|
dimText.SetPScale(GetPScale());
|
|
dimText.setPropertiesFrom(this);
|
|
dimText.SetAlignment(AcGiDraw::kMiddleCenter);
|
|
dimText.SetHeight(dimtxt);
|
|
dimText.SetStyleId(dimtxsty);
|
|
if (dimclrt) dimText.setColorIndex(dimclrt);
|
|
|
|
BOOL bIsDefPos = TRUE;
|
|
ADSGePoint3d ptText = GetTextPos(&bIsDefPos);
|
|
double nTextRot = NormalViewAngle(ads_angle(ptStart, ptEnd));
|
|
BOOL bIsDefText = TRUE;
|
|
TCString sText0 = GetText(&bIsDefText);
|
|
TCString sText;
|
|
if (bIsDefText) {
|
|
if (sDimPrefix[0]) {
|
|
sText << sDimPrefix << &sText0[1] << sDimSuffix;
|
|
}
|
|
else {
|
|
sText << sDimPrefix << sText0 << sDimSuffix;
|
|
}
|
|
}
|
|
else {
|
|
sText << sText0;
|
|
}
|
|
dimText.SetRotation(Wcs2Layout(nTextRot));
|
|
dimText.SetLocation(ptText);
|
|
dimText.SetAlignment(AcGiDraw::kMiddleCenter);
|
|
dimText.SetText(sText);
|
|
DrawBaseEx(dc, dimText);
|
|
|
|
GeCurveSegment seg(ptStart, ptEnd, 0.0, LS_INFINITE);
|
|
if (bCheckDim && !bIsDefText) {
|
|
TCString sCheckText(256);
|
|
TCString sDefText = GetDefaultText();
|
|
sCheckText << _T("(");
|
|
if (sDimPrefix[0]) {
|
|
sCheckText << sDimPrefix << &sDefText[1];
|
|
}
|
|
else {
|
|
sCheckText << sDefText;
|
|
}
|
|
sCheckText << sDimSuffix << _T(")");
|
|
ADSGePoint3d ptCheckText;
|
|
if (bIsDefPos) {
|
|
ADSGePoint3d ptOnSeg;
|
|
if (seg.ProjectToMe(ptText, ptOnSeg) == RTNORM) {
|
|
ptOnSeg.Mirror(ptText, ptCheckText);
|
|
}
|
|
}
|
|
else {
|
|
int nSideText = seg.OnWhichSide(ptText);
|
|
if (nSideText == OFFSET_RIGHT)
|
|
ads_polar(ptText, seg.GeLine::Direction() - PI / 2, nPScale * (dimgap + dimtxt), ptCheckText);
|
|
else
|
|
ads_polar(ptText, seg.GeLine::Direction() + PI / 2, nPScale * (dimgap + dimtxt), ptCheckText);
|
|
}
|
|
dimText.setColorIndex(1);
|
|
dimText.SetLocation(ptCheckText);
|
|
dimText.SetText(sCheckText);
|
|
DrawBaseEx(dc, dimText);
|
|
}
|
|
dc.SetColor(nOldColor);
|
|
return Acad::eOk;
|
|
}
|
|
|
|
int AecXDbRadiusDim::ConvertText(TConvertTextPtr ptr, void *pData)
|
|
{
|
|
TCString sText;
|
|
int nRet = ptr(m_sText, sText, pData);
|
|
if (nRet == RTNORM) {
|
|
AssertWriteEnabled();
|
|
m_sText = sText;
|
|
}
|
|
return nRet;
|
|
}
|
|
|
|
void AecXDbRadiusDim::GetDimText(AecXDbText &dimText) const
|
|
{
|
|
BOOL bIsDefText = TRUE;
|
|
TCString sText = GetText(&bIsDefText);
|
|
TextPosition pos;
|
|
|
|
AcDbObjectId dimtxsty;
|
|
double dimtxt = 3.0;
|
|
OPENOBJ_BEGIN(m_idDimStyle, AcDb::kForRead, AcDbDimStyleTableRecord, pDimStyle);
|
|
if (pDimStyle) {
|
|
dimtxsty = pDimStyle->dimtxsty();
|
|
dimtxt = pDimStyle->dimtxt();
|
|
}
|
|
OPENOBJ_END();
|
|
|
|
|
|
|
|
dimText.setPropertiesFrom(this);
|
|
dimText.SetAlignment(AcGiDraw::kMiddleCenter);
|
|
dimText.SetHeight(dimtxt);
|
|
dimText.SetStyleId(dimtxsty);
|
|
|
|
ADSGePoint3d ptText = GetTextPos();
|
|
double nTextRot = NormalViewAngle(ads_angle(GetDimStartPoint(), GetDimEndPoint()));
|
|
dimText.SetRotation(Wcs2Layout(nTextRot));
|
|
dimText.SetLocation(ptText);
|
|
dimText.SetAlignment(AcGiDraw::kMiddleCenter);
|
|
if (bIsDefText)
|
|
dimText.SetText(_T(""));
|
|
else
|
|
dimText.SetText(sText);
|
|
}
|
|
|
|
// 返回发现的位置,同时posStart往前移动(以便继续找下一个使用),
|
|
TextPosition
|
|
AecXDbRadiusDim::FindSubText(const TCHAR *sSubText, TextPosition &posStart, TextRange *pRange) const
|
|
{
|
|
assertReadEnabled();
|
|
AecXDbText dimText;
|
|
dimText.SetPScale(GetPScale());
|
|
GetDimText(dimText);
|
|
TextPosition pos = dimText.FindSubText(sSubText, posStart, pRange);
|
|
return pos;
|
|
}
|
|
|
|
// 返回下一次查找的开始位置
|
|
TextPosition
|
|
AecXDbRadiusDim::ReplaceSubText(const TextPosition &posRep, const TCHAR *sRepText, TextRange *pRange)
|
|
{
|
|
AssertWriteEnabled();
|
|
AecXDbText dimText;
|
|
dimText.SetPScale(GetPScale());
|
|
GetDimText(dimText);
|
|
TextPosition pos = dimText.ReplaceSubText(posRep, sRepText, pRange);
|
|
SetText(dimText.GetText());
|
|
return pos;
|
|
}
|
|
|
|
const TCHAR *AecXDbRadiusDim::GetDefaultLayer() const
|
|
{
|
|
extern TCHAR* LAY_DIM;
|
|
return LAY_DIM;
|
|
}
|
|
|
|
DrawModeType AecXDbRadiusDim::GetDrawType() const
|
|
{
|
|
return k2DOnly;
|
|
}
|
|
|
|
/* * * * * * * * * * 取 动 态 属 性 显 示 数 据 的 函 数 * * * * * * * * * */
|
|
void AecXDbRadiusDim::GetTips(PtrList<ObjInfoUnit> &lstInfo) const
|
|
{
|
|
lstInfo.Append(new ObjInfoUnit(_T("对象类型"), IsDiameter() ? _T("直径标注") : _T("半径标注")));
|
|
lstInfo.Append(new ObjInfoUnit(_T("标注样式"), GlobalFunc::GetSymbolName(m_idDimStyle)));
|
|
TCString sDist;
|
|
GlobalFunc::ftoa(fabs(m_nDimLen), 1, sDist);
|
|
sDist << _T("P");
|
|
lstInfo.Append(new ObjInfoUnit(_T("尺寸线长度"), sDist));
|
|
lstInfo.Append(new ObjInfoUnit(_T("测量值"), GetDefaultText()));
|
|
lstInfo.Append(new ObjInfoUnit(_T("替代文字"), m_sText));
|
|
}
|
|
|
|
|
|
// Helper Method
|
|
BOOL AecXDbRadiusDim::ConvertFrom(const AcDbRadialDimension *pDim)
|
|
{
|
|
AssertWriteEnabled();
|
|
|
|
AcDbObjectId idStyle = pDim->dimensionStyle();
|
|
TCString sText;
|
|
sText = pDim->dimensionText();
|
|
if (pDim->normal() != AcGeVector3d(0, 0, 1) || !idStyle)
|
|
return FALSE;
|
|
|
|
setPropertiesFrom(pDim);
|
|
m_idDimStyle = idStyle;
|
|
if (!pDim->isUsingDefaultTextPosition()) {
|
|
m_ptText = pDim->textPosition();
|
|
m_nDimFlag |= DF_POSITION;
|
|
}
|
|
else m_nDimFlag &= ~DF_POSITION;
|
|
|
|
|
|
if (!!sText) {
|
|
m_sText = sText;
|
|
m_nDimFlag |= DF_TEXT;
|
|
}
|
|
else {
|
|
m_nDimFlag &= ~DF_TEXT;
|
|
}
|
|
|
|
m_ptCenter = pDim->center();
|
|
m_ptOnArc = pDim->chordPoint();
|
|
m_nDimLen = m_ptCenter.Distance2d(m_ptOnArc) / GetPScale();
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Properties
|
|
// Modified by ZJQ on 2003/01/23
|
|
// 支持直径标注
|
|
ADSGePoint3d
|
|
AecXDbRadiusDim::GetDimStartPoint() const
|
|
{
|
|
ADSGePoint3d ptStart;
|
|
//if(IsDiameter())
|
|
// ads_polar(m_ptOnArc, ads_angle(m_ptOnArc, m_ptCenter), GetRadius()*2, ptStart);
|
|
//else
|
|
ads_polar(m_ptOnArc, ads_angle(m_ptOnArc, m_ptCenter), m_nDimLen * GetPScale(), ptStart);
|
|
return ptStart;
|
|
}
|
|
|
|
ADSGePoint3d
|
|
AecXDbRadiusDim::GetDimEndPoint() const
|
|
{
|
|
return m_ptOnArc;
|
|
}
|
|
|
|
ADSGePoint3d
|
|
AecXDbRadiusDim::GetDimCenter() const
|
|
{
|
|
return m_ptCenter;
|
|
}
|
|
|
|
double
|
|
AecXDbRadiusDim::GetDimLen(BOOL bAsPaperUnit) const
|
|
{
|
|
double nVal = m_nDimLen;
|
|
if (!bAsPaperUnit) nVal *= GetPScale();
|
|
return nVal;
|
|
}
|
|
|
|
AcDbObjectId
|
|
AecXDbRadiusDim::GetStyleId() const
|
|
{
|
|
return m_idDimStyle;
|
|
}
|
|
|
|
ADSGePoint3d
|
|
AecXDbRadiusDim::GetTextPos(BOOL *bIsDefault) const
|
|
{
|
|
ADSGePoint3d ptText;
|
|
if (m_nDimFlag & DF_POSITION) {
|
|
ptText = m_ptText;
|
|
if (bIsDefault) *bIsDefault = FALSE;
|
|
}
|
|
else {
|
|
ptText = GetDefaultTextPos();
|
|
if (bIsDefault) *bIsDefault = TRUE;
|
|
}
|
|
return ptText;
|
|
}
|
|
|
|
// Modify on 2003/01/23
|
|
// 支持直径标注
|
|
ADSGePoint3d
|
|
AecXDbRadiusDim::GetDefaultTextPos() const
|
|
{
|
|
AcDbObjectId dimtxsty;
|
|
double dimtxt = 3.0;
|
|
double dimgap = 0.0;
|
|
double dimlfac = 1.0;
|
|
OPENOBJ_BEGIN(m_idDimStyle, AcDb::kForRead, AcDbDimStyleTableRecord, pDimStyle);
|
|
ASSERT(pDimStyle);
|
|
dimtxt = pDimStyle->dimtxt();
|
|
dimgap = pDimStyle->dimgap();
|
|
dimtxsty = pDimStyle->dimtxsty();
|
|
dimlfac = pDimStyle->dimlfac();
|
|
OPENOBJ_END();
|
|
|
|
double nScale = GetPScale();
|
|
double nTextHeight = dimtxt * nScale;
|
|
AecXDbText text;
|
|
text.SetPScale(GetPScale());
|
|
text.setPropertiesFrom(this);
|
|
text.SetText(GetText());
|
|
text.SetStyleId(dimtxsty);
|
|
text.SetHeight(nTextHeight, FALSE);
|
|
ADSGePoint3d ptExt = text.GetExtents();
|
|
|
|
ADSGePoint3d ptText, ptTemp;
|
|
|
|
if (!IsDiameter() || m_nDimLen < 0) {
|
|
ADSGePoint3d ptStart = GetDimStartPoint();
|
|
double nRot = ads_angle(ptStart, m_ptOnArc);
|
|
ads_polar(ptStart, nRot, ptExt.x / 2 + dimgap * nScale, ptTemp);
|
|
ads_polar(ptTemp, NormalViewAngle(nRot) + PI / 2, (dimgap + dimtxt / 2) * nScale, ptText);
|
|
}
|
|
else {
|
|
double nRot = ads_angle(m_ptCenter, m_ptOnArc);
|
|
//ads_polar(m_ptCenter, nRot+PI, ptExt.x/2, ptTemp);
|
|
ads_polar(m_ptCenter, NormalViewAngle(nRot) + PI / 2, (dimgap + dimtxt / 2) * nScale, ptText);
|
|
}
|
|
return ptText;
|
|
}
|
|
|
|
TCString
|
|
AecXDbRadiusDim::GetText(BOOL *bIsDefault) const
|
|
{
|
|
TCString sText;
|
|
if (m_nDimFlag & DF_TEXT) {
|
|
sText = m_sText;
|
|
if (bIsDefault) *bIsDefault = FALSE;
|
|
}
|
|
else {
|
|
sText = GetDefaultText();
|
|
if (bIsDefault) *bIsDefault = TRUE;
|
|
}
|
|
return sText;
|
|
}
|
|
|
|
// Modify on 2002/02/05 by ZJQ
|
|
// 支持单位换算dimlfac
|
|
// Modify on 2003/01/23 by ZJQ
|
|
// 支持直径标注
|
|
TCString
|
|
AecXDbRadiusDim::GetDefaultText() const
|
|
{
|
|
int dimdec = 0;
|
|
double dimlfac = 1.0;
|
|
double dimrnd = 0;
|
|
OPENOBJ_BEGIN(m_idDimStyle, AcDb::kForRead, AcDbDimStyleTableRecord, pDimStyle);
|
|
ASSERT(pDimStyle);
|
|
dimdec = pDimStyle->dimdec();
|
|
dimlfac = pDimStyle->dimlfac();
|
|
dimrnd = pDimStyle->dimrnd();
|
|
OPENOBJ_END();
|
|
TCString sText, sTemp, sTemrnd;
|
|
double dTemLen(0), dTemrnd(0);
|
|
TCString sDimrnd;
|
|
if (IsDiameter())
|
|
{
|
|
GlobalFunc::ftoa(m_ptCenter.Distance2d(m_ptOnArc) * dimlfac * 2, dimdec, sTemp);
|
|
GlobalFunc::ftoa(dimrnd, dimdec, sDimrnd);
|
|
dTemLen = _tstof(sTemp);
|
|
dTemrnd = _tstof(sDimrnd);
|
|
if (!GlobalFunc::Equal(dTemrnd, 0, 0.00000001))
|
|
{
|
|
double dT = dTemLen / dTemrnd;
|
|
TCString sT;
|
|
GlobalFunc::ftoa(dT, 0, sT);
|
|
dT = _tstof(sT);
|
|
int nt = (int)dT;
|
|
double dDimNum = dTemrnd * nt;
|
|
GlobalFunc::ftoa(dDimNum, dimdec, sTemp);
|
|
}
|
|
//////zzg090515//////////////
|
|
sText << _T("%%c") << sTemp;
|
|
}
|
|
else
|
|
{
|
|
GlobalFunc::ftoa(m_ptCenter.Distance2d(m_ptOnArc) * dimlfac, dimdec, sTemp);
|
|
GlobalFunc::ftoa(dimrnd, dimdec, sDimrnd);
|
|
dTemLen = _tstof(sTemp);
|
|
dTemrnd = _tstof(sDimrnd);
|
|
if (!GlobalFunc::Equal(dTemrnd, 0, 0.00000001))
|
|
{
|
|
double dT = dTemLen / dTemrnd;
|
|
TCString sT;
|
|
GlobalFunc::ftoa(dT, 0, sT);
|
|
dT = _tstof(sT);
|
|
int nt = (int)dT;
|
|
double dDimNum = dTemrnd * nt;
|
|
GlobalFunc::ftoa(dDimNum, dimdec, sTemp);
|
|
}
|
|
//////zzg090515//////////////
|
|
sText << _T("R") << sTemp;
|
|
}
|
|
//////// 处理 标注样式中舍入的问题zzg 090515
|
|
return sText;
|
|
}
|
|
|
|
void
|
|
AecXDbRadiusDim::SetDimEndPoint(ADSGePoint3d ptEnd)
|
|
{
|
|
AssertWriteEnabled();
|
|
m_ptOnArc = ptEnd;
|
|
}
|
|
|
|
void
|
|
AecXDbRadiusDim::SetDimCenter(ADSGePoint3d ptCen)
|
|
{
|
|
AssertWriteEnabled();
|
|
m_ptCenter = ptCen;
|
|
}
|
|
|
|
void AecXDbRadiusDim::SetDimLen(double nLen, BOOL bAsPaperUnit)
|
|
{
|
|
AssertWriteEnabled();
|
|
if (bAsPaperUnit) m_nDimLen = nLen;
|
|
else m_nDimLen = nLen / GetPScale();
|
|
}
|
|
|
|
void AecXDbRadiusDim::SetStyleId(AcDbObjectId id)
|
|
{
|
|
AssertWriteEnabled();
|
|
m_idDimStyle = id;
|
|
}
|
|
|
|
void AecXDbRadiusDim::SetTextPos(ADSGePoint3d ptPos)
|
|
{
|
|
AssertWriteEnabled();
|
|
ADSGePoint3d ptDefault = GetDefaultTextPos();
|
|
if (ptPos.Distance2d(ptDefault) < g_Option::instance()._DIST_SNAP) {
|
|
m_nDimFlag &= ~DF_POSITION;
|
|
}
|
|
else {
|
|
m_ptText = ptPos;
|
|
m_nDimFlag |= DF_POSITION;
|
|
}
|
|
}
|
|
|
|
void AecXDbRadiusDim::SetText(const TCHAR *pszText)
|
|
{
|
|
AssertWriteEnabled();
|
|
if (!pszText) m_sText = _T("");
|
|
else m_sText = pszText;
|
|
if (!m_sText) {
|
|
m_nDimFlag &= ~DF_TEXT;
|
|
}
|
|
else {
|
|
m_nDimFlag |= DF_TEXT;
|
|
}
|
|
}
|
|
|
|
void AecXDbRadiusDim::SetDiameter(BOOL bTrue)
|
|
{
|
|
AssertWriteEnabled();
|
|
if (bTrue)
|
|
m_nDimFlag |= DF_DIAMETER;
|
|
else
|
|
m_nDimFlag &= ~DF_DIAMETER;
|
|
}
|
|
|
|
BOOL AecXDbRadiusDim::IsDiameter() const
|
|
{
|
|
return ((m_nDimFlag & DF_DIAMETER) != 0);
|
|
}
|
|
|
|
// sg add 101116,支持统一标高
|
|
bool AecXDbRadiusDim::UnifyElevation(double dElevation)
|
|
{
|
|
AssertWriteEnabled();
|
|
m_ptCenter.z = dElevation;
|
|
m_ptOnArc.z = dElevation;
|
|
|
|
ADSGePoint3d ptText = GetTextPos();
|
|
ptText.z = dElevation;
|
|
SetTextPos(ptText);
|
|
return true;
|
|
}
|
|
#pragma endregion
|
|
|