2404 lines
51 KiB
C++
2404 lines
51 KiB
C++
#include "stdafx.h"
|
||
#include "StdArx.h"
|
||
#include "dbproxy.h"
|
||
#include "AecDbEwPipeDim.h"
|
||
#include "AcGiExplodeDraw.h"
|
||
#include "dbgrip.h"
|
||
#include "AecGripCback.h"
|
||
#include "coretools.h"
|
||
|
||
|
||
const CString AecDbEwPipeDim::_Custom_No_R_ = L"_Custom_No_R_";
|
||
|
||
namespace
|
||
{
|
||
void GetTextAlignment(const AcGiDraw::TextAlignment &align
|
||
, AcDb::TextHorzMode &nHMode
|
||
, AcDb::TextVertMode &nVMode)
|
||
{
|
||
// 对齐方式需要进行换算
|
||
switch (align)
|
||
{
|
||
case AcGiDraw::kTopLeft:
|
||
nHMode = AcDb::kTextLeft;
|
||
nVMode = AcDb::kTextTop;
|
||
break;
|
||
case AcGiDraw::kTopCenter:
|
||
nHMode = AcDb::kTextCenter;
|
||
nVMode = AcDb::kTextTop;
|
||
break;
|
||
case AcGiDraw::kTopRight:
|
||
nHMode = AcDb::kTextRight;
|
||
nVMode = AcDb::kTextTop;
|
||
break;
|
||
case AcGiDraw::kMiddleLeft:
|
||
nHMode = AcDb::kTextLeft;
|
||
nVMode = AcDb::kTextVertMid;
|
||
break;
|
||
case AcGiDraw::kMiddleCenter:
|
||
nHMode = AcDb::kTextCenter;
|
||
nVMode = AcDb::kTextVertMid;
|
||
break;
|
||
case AcGiDraw::kMiddleRight:
|
||
nHMode = AcDb::kTextRight;
|
||
nVMode = AcDb::kTextVertMid;
|
||
break;
|
||
case AcGiDraw::kBottomLeft:
|
||
nHMode = AcDb::kTextLeft;
|
||
nVMode = AcDb::kTextBottom;
|
||
break;
|
||
case AcGiDraw::kBottomCenter:
|
||
nHMode = AcDb::kTextCenter;
|
||
nVMode = AcDb::kTextBottom;
|
||
break;
|
||
case AcGiDraw::kBottomRight:
|
||
nHMode = AcDb::kTextRight;
|
||
nVMode = AcDb::kTextBottom;
|
||
break;
|
||
case AcGiDraw::kLeft:
|
||
nHMode = AcDb::kTextLeft;
|
||
nVMode = AcDb::kTextBase;
|
||
break;
|
||
case AcGiDraw::kCenter:
|
||
nHMode = AcDb::kTextCenter;
|
||
nVMode = AcDb::kTextBase;
|
||
break;
|
||
case AcGiDraw::kRight:
|
||
nHMode = AcDb::kTextRight;
|
||
nVMode = AcDb::kTextBase;
|
||
case AcGiDraw::kMiddle:
|
||
nHMode = AcDb::kTextMid;
|
||
nVMode = (AcDb::TextVertMode)0;
|
||
break;
|
||
default:
|
||
nHMode = (AcDb::TextHorzMode)0;
|
||
nVMode = (AcDb::TextVertMode)0;
|
||
break;
|
||
}
|
||
}
|
||
|
||
AcGiDraw::TextAlignment GetTextAlignment(const AcDb::TextHorzMode &nHMode, const AcDb::TextVertMode &nVMode)
|
||
{
|
||
AcGiDraw::TextAlignment nAlign;
|
||
|
||
// 上
|
||
if (nHMode == AcDb::kTextLeft && nVMode == AcDb::kTextTop)
|
||
{
|
||
nAlign = AcGiDraw::kTopLeft;
|
||
}
|
||
else if (nHMode == AcDb::kTextCenter && nVMode == AcDb::kTextTop)
|
||
{
|
||
nAlign = AcGiDraw::kTopCenter;
|
||
}
|
||
else if (nHMode == AcDb::kTextRight && nVMode == AcDb::kTextTop)
|
||
{
|
||
nAlign = AcGiDraw::kTopRight;
|
||
}
|
||
|
||
// 中
|
||
else if (nHMode == AcDb::kTextLeft && nVMode == AcDb::kTextVertMid)
|
||
{
|
||
nAlign = AcGiDraw::kMiddleLeft;
|
||
}
|
||
else if (nHMode == AcDb::kTextCenter && nVMode == AcDb::kTextVertMid)
|
||
{
|
||
nAlign = AcGiDraw::kMiddleCenter;
|
||
}
|
||
else if (nHMode == AcDb::kTextRight && nVMode == AcDb::kTextVertMid)
|
||
{
|
||
nAlign = AcGiDraw::kMiddleRight;
|
||
}
|
||
|
||
// 下
|
||
else if (nHMode == AcDb::kTextLeft && nVMode == AcDb::kTextBottom)
|
||
{
|
||
nAlign = AcGiDraw::kBottomLeft;
|
||
}
|
||
else if (nHMode == AcDb::kTextCenter && nVMode == AcDb::kTextBottom)
|
||
{
|
||
nAlign = AcGiDraw::kBottomCenter;
|
||
}
|
||
else if (nHMode == AcDb::kTextRight && nVMode == AcDb::kTextBottom)
|
||
{
|
||
nAlign = AcGiDraw::kBottomRight;
|
||
}
|
||
|
||
// 基线
|
||
else if (nHMode == AcDb::kTextLeft && nVMode == AcDb::kTextBase)
|
||
{
|
||
nAlign = AcGiDraw::kLeft;
|
||
}
|
||
else if (nHMode == AcDb::kTextCenter && nVMode == AcDb::kTextBase)
|
||
{
|
||
nAlign = AcGiDraw::kCenter;
|
||
}
|
||
else if (nHMode == AcDb::kTextRight && nVMode == AcDb::kTextBase)
|
||
{
|
||
nAlign = AcGiDraw::kRight;
|
||
}
|
||
|
||
else if (nHMode == AcDb::kTextMid)
|
||
{
|
||
nAlign = AcGiDraw::kMiddle;
|
||
}
|
||
else //kTextAlign, kTextFit
|
||
{
|
||
nAlign = AcGiDraw::kUnknown;
|
||
}
|
||
|
||
return nAlign;
|
||
}
|
||
|
||
void drawProxyEntity(const AcDbVoidPtrArray *pAr, AcGiWorldDraw *pWd)
|
||
{
|
||
if (!pAr) return;
|
||
Adesk::UInt16 clr = pWd->subEntityTraits().color();
|
||
AcDbObjectId layerID = pWd->subEntityTraits().layerId();
|
||
for (int i = 0; i < pAr->length(); ++i)
|
||
{
|
||
AcDbEntity *pEnt((AcDbEntity *)pAr->at(i));
|
||
if (pEnt->isKindOf(AcDbBlockReference::desc()))
|
||
{
|
||
AcDbBlockReference *pRef((AcDbBlockReference *)pEnt);
|
||
AcDbBlockTableRecord *pRec(NULL);
|
||
AcDbObject *pObj(NULL);
|
||
AcDbEntity *pSubEnt(NULL);
|
||
if (acdbOpenAcDbObject(pObj, pRef->blockTableRecord(), AcDb::kForRead) == Acad::eOk)
|
||
{
|
||
pRec = (AcDbBlockTableRecord *)pObj;
|
||
AcDbBlockTableRecordIterator *pBlockIterator;
|
||
pRec->newIterator(pBlockIterator, Adesk::kTrue, Adesk::kFalse);
|
||
for (pBlockIterator->start(); !pBlockIterator->done(); pBlockIterator->step())
|
||
{
|
||
pBlockIterator->getEntity(pSubEnt, AcDb::kForWrite, Adesk::kTrue);
|
||
pSubEnt->setColorIndex(pEnt->colorIndex());
|
||
pSubEnt->setLayer(pEnt->layerId());
|
||
pSubEnt->close();
|
||
}
|
||
pObj->close();
|
||
delete pBlockIterator;
|
||
}
|
||
}
|
||
pWd->subEntityTraits().setColor(pEnt->colorIndex());
|
||
pWd->subEntityTraits().setLayer(pEnt->layerId());
|
||
if (pEnt)
|
||
pEnt->worldDraw(pWd);
|
||
}
|
||
pWd->subEntityTraits().setColor(clr);
|
||
pWd->subEntityTraits().setLayer(layerID);
|
||
}
|
||
}
|
||
|
||
|
||
//#define VERSION_TDBFITTINGBASE 1
|
||
// 增加了 m_mapSpecXData
|
||
#define VERSION_TDBFITTINGBASE 2
|
||
#define MESH_N 20
|
||
#define MESH_M 2
|
||
|
||
#define DIM_EL _T("\\U+2200")
|
||
#define DIM_TOP_EL _T("\\U+2201")
|
||
#define DIM_CEN_EL _T("\\U+2202")
|
||
#define DIM_BOM_EL _T("\\U+2203")
|
||
|
||
static const Adesk::UInt16 kBlue = 5;
|
||
|
||
ACRX_DXF_DEFINE_MEMBERS( AecDbEwPipeDim
|
||
, AecDbEntityBase
|
||
, AcDb::kDHL_CURRENT
|
||
, AcDb::kMReleaseCurrent
|
||
, 1
|
||
, AEC_EWPIPEDIM
|
||
, "AecDbEwPipeDim | 缺乏解释器,图形看不见,请下载插件");
|
||
|
||
AecDbEwPipeDim::AecDbEwPipeDim(void)
|
||
{
|
||
m_nStyle = 1; //0: 引出标注 1: 在线标注 //2: 批量标注
|
||
m_nDir = 0; //0: 水平标注 1: 垂直标注
|
||
m_nDimText = 0; //0: 只标上标 1: 上下标
|
||
|
||
m_sUpScr = _T(""); //上标脚本
|
||
m_sDownScr = _T(""); //下标脚本
|
||
|
||
m_dTextH = 2.5; //打印纸面字高度 2.5
|
||
m_dWScale = 0.75; //打印纸面字宽度 1
|
||
m_dD = 100; //上下标的间隙,在线标注用到
|
||
m_pGripAppData = new AecGripData[9];
|
||
}
|
||
|
||
AecDbEwPipeDim::~AecDbEwPipeDim(void)
|
||
{
|
||
}
|
||
|
||
void AecDbEwPipeDim::AddAecDbWEntity(const AcDbObjectId& idObj)
|
||
{
|
||
AssertWriteEnabled();
|
||
m_aridAttachs.append(idObj);
|
||
}
|
||
|
||
AcDbObjectId AecDbEwPipeDim::GetAecDbWEntity(int nIndex)
|
||
{
|
||
assertReadEnabled();
|
||
if (nIndex > -1 && nIndex < m_aridAttachs.length() )
|
||
{
|
||
return m_aridAttachs.at(nIndex);
|
||
}
|
||
return AcDbObjectId::kNull;
|
||
}
|
||
|
||
int AecDbEwPipeDim::GetAecDbWEntityCount()
|
||
{
|
||
assertReadEnabled();
|
||
return m_aridAttachs.length();
|
||
}
|
||
|
||
void AecDbEwPipeDim::SetDimStyle(short nStyle)
|
||
{
|
||
AssertWriteEnabled();
|
||
m_nStyle = nStyle;
|
||
}
|
||
|
||
short AecDbEwPipeDim::GetDimStyle()
|
||
{
|
||
assertReadEnabled();
|
||
return m_nStyle;
|
||
}
|
||
|
||
void AecDbEwPipeDim::SetDimDir(short nDir)
|
||
{
|
||
AssertWriteEnabled();
|
||
m_nDir = nDir;
|
||
}
|
||
|
||
short AecDbEwPipeDim::GetDimDir()
|
||
{
|
||
assertReadEnabled();
|
||
return m_nDir;
|
||
}
|
||
|
||
void AecDbEwPipeDim::SetDimTextUporDownFlag(short nDimText)
|
||
{
|
||
AssertWriteEnabled();
|
||
m_nDimText = nDimText;
|
||
}
|
||
|
||
short AecDbEwPipeDim::GetDimTextUporDownnFlag()
|
||
{
|
||
assertReadEnabled();
|
||
return m_nDimText;
|
||
}
|
||
|
||
void AecDbEwPipeDim::SetISODim(short nIsISO)
|
||
{
|
||
AssertWriteEnabled();
|
||
m_nIsISO = nIsISO;
|
||
}
|
||
|
||
short AecDbEwPipeDim::IsISODim()
|
||
{
|
||
assertReadEnabled();
|
||
return m_nIsISO;
|
||
}
|
||
|
||
void AecDbEwPipeDim::SetTextStyleId(AcDbObjectId& idStyle)
|
||
{
|
||
AssertWriteEnabled();
|
||
m_idTextSty = idStyle;
|
||
}
|
||
|
||
AcDbObjectId AecDbEwPipeDim::GetTextStyleId()
|
||
{
|
||
assertReadEnabled();
|
||
return m_idTextSty;
|
||
}
|
||
|
||
void AecDbEwPipeDim::SetTextLayerId(AcDbObjectId id)
|
||
{
|
||
AssertWriteEnabled();
|
||
m_idTextLayer = id;
|
||
}
|
||
|
||
AcDbObjectId AecDbEwPipeDim::GetTextLayerId()
|
||
{
|
||
assertReadEnabled();
|
||
return m_idTextLayer;
|
||
}
|
||
|
||
void AecDbEwPipeDim::AddDimText(LPCTSTR pszUp,LPCTSTR pszDown)
|
||
{
|
||
AssertWriteEnabled();
|
||
if (pszUp != NULL)
|
||
{
|
||
m_arsUps.Add(pszUp);
|
||
}
|
||
if (pszDown != NULL)
|
||
{
|
||
m_arsDowns.Add(pszDown);
|
||
}
|
||
}
|
||
|
||
void AecDbEwPipeDim::RemoveAt(int nPos,int nIndex)
|
||
{
|
||
AssertWriteEnabled();
|
||
if (nPos == -1)
|
||
{
|
||
if (nIndex > -1 && nIndex < m_arsDowns.GetSize())
|
||
{
|
||
m_arsDowns.RemoveAt(nIndex);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (nIndex > -1 && nIndex < m_arsUps.GetSize())
|
||
{
|
||
m_arsUps.RemoveAt(nIndex);
|
||
}
|
||
}
|
||
}
|
||
|
||
void AecDbEwPipeDim::RemoveAll(int nPos)
|
||
{
|
||
AssertWriteEnabled();
|
||
if (nPos == -1)
|
||
{
|
||
m_arsDowns.RemoveAll();
|
||
}
|
||
else
|
||
{
|
||
m_arsUps.RemoveAll();
|
||
}
|
||
}
|
||
|
||
void AecDbEwPipeDim::GetDimText(int nIndex,CString& sUp,CString& sDown)
|
||
{
|
||
assertReadEnabled();
|
||
|
||
if (nIndex > -1 && nIndex < m_arsUps.GetSize() )
|
||
{
|
||
sUp = m_arsUps.GetAt(nIndex);
|
||
}
|
||
if (nIndex > -1 && nIndex < m_arsDowns.GetSize() )
|
||
{
|
||
sDown = m_arsDowns.GetAt(nIndex);
|
||
}
|
||
}
|
||
|
||
void AecDbEwPipeDim::SetDimupScript(LPCTSTR pszUpScr)
|
||
{
|
||
AssertWriteEnabled();
|
||
m_sUpScr = pszUpScr;
|
||
}
|
||
|
||
void AecDbEwPipeDim::GetDimupScript(CString& sUpScr)
|
||
{
|
||
assertReadEnabled();
|
||
sUpScr = m_sUpScr;
|
||
}
|
||
|
||
void AecDbEwPipeDim::SetDimdownScript(LPCTSTR pszDownScr)
|
||
{
|
||
AssertWriteEnabled();
|
||
m_sDownScr = pszDownScr;
|
||
}
|
||
|
||
void AecDbEwPipeDim::GetDimdownScript(CString& sDownScr)
|
||
{
|
||
assertReadEnabled();
|
||
sDownScr = m_sDownScr;
|
||
}
|
||
|
||
double AecDbEwPipeDim::GetTextHeight()
|
||
{
|
||
assertReadEnabled();
|
||
return m_dTextH;
|
||
}
|
||
|
||
void AecDbEwPipeDim::SetTextHeight(double dH)
|
||
{
|
||
AssertWriteEnabled();
|
||
m_dTextH = dH;
|
||
}
|
||
|
||
double AecDbEwPipeDim::GetTextWidthScale()
|
||
{
|
||
assertReadEnabled();
|
||
return m_dWScale;
|
||
}
|
||
|
||
void AecDbEwPipeDim::SetTextWidthScale(double dScale)
|
||
{
|
||
AssertWriteEnabled();
|
||
m_dWScale = dScale;
|
||
}
|
||
|
||
void AecDbEwPipeDim::AppendPoint(AcGePoint3d& pt)
|
||
{
|
||
AssertWriteEnabled();
|
||
m_arPoints.append(pt);
|
||
}
|
||
|
||
void AecDbEwPipeDim::AppendNoPoint(AcGePoint3d& pt)
|
||
{
|
||
AssertWriteEnabled();
|
||
m_arNoPoints.append(pt);
|
||
}
|
||
|
||
void AecDbEwPipeDim::UpdateFromParam()
|
||
{
|
||
|
||
}
|
||
|
||
void AecDbEwPipeDim::SetDimupdownSpace(double dD)
|
||
{
|
||
AssertWriteEnabled();
|
||
m_dD = dD;
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbEwPipeDim::Draw2d(AcGiDraw &dc) const
|
||
{
|
||
assertReadEnabled();
|
||
|
||
dc.SetTextStyle(m_idTextSty);
|
||
dc.SetLayer(m_idTextLayer);
|
||
|
||
if (Has2DBuffer())
|
||
{
|
||
const AcDbVoidPtrArray &Ar = Get2DBuffer();
|
||
|
||
Adesk::UInt16 oldClr = dc.GetColor();
|
||
Adesk::UInt16 newClr;
|
||
for (int i = 0; i < Ar.length(); ++i)
|
||
{
|
||
const AcDbEntity *pEnt = (AcDbEntity *)Ar.at(i);
|
||
dc.DrawEntity(*pEnt);
|
||
}
|
||
dc.SetColor(oldClr);
|
||
return Acad::eOk;
|
||
}
|
||
|
||
switch (m_nStyle)
|
||
{
|
||
case 0: //引出标注
|
||
{
|
||
DrawLeaderDim(dc);
|
||
break;
|
||
}
|
||
case 1: //在线标注
|
||
{
|
||
DrawOnlineDim(dc);
|
||
break;
|
||
}
|
||
case 2: //批量标注
|
||
{
|
||
DrawPolylineDim(dc);
|
||
break;
|
||
}
|
||
case 3: //序号标注
|
||
{
|
||
DrawSNo(dc);
|
||
break;
|
||
}
|
||
case 4: //引出多行带框标注---桥架用
|
||
{
|
||
DrawMBoxLineLdDim(dc);
|
||
break;
|
||
}
|
||
default:
|
||
break;
|
||
}
|
||
return Acad::eOk;
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbEwPipeDim::DrawLeaderDim(AcGiDraw &dc) const
|
||
{
|
||
if (m_arPoints.length() < 2 )
|
||
{
|
||
return Acad::eInvalidInput;
|
||
}
|
||
|
||
if (m_arsUps.IsEmpty() && m_arsDowns.IsEmpty()) return Acad::eInvalidInput;
|
||
|
||
double len(.0);
|
||
|
||
AcGePoint3d ptFr = m_arPoints.first();
|
||
AcGePoint3d ptTo = m_arPoints.at(1);
|
||
CString sDimUp =_T("");
|
||
CString sDimDown = _T("");
|
||
dc.SetLayer(layerId());
|
||
//dc.DrawLine(AcGeLineSeg3d(ptFr,ptTo));
|
||
AcDbLine *pLine(new AcDbLine(ptFr,ptTo));
|
||
if (pLine)
|
||
{
|
||
pLine->setLayer(layerId());
|
||
Add2DBuffer(pLine);
|
||
dc.DrawEntity(*pLine);
|
||
}
|
||
|
||
//绘制点
|
||
MakeWDot(dc, ptFr);
|
||
|
||
AcGeVector3d vtDir = ptTo - ptFr;
|
||
|
||
// 得到引线长度
|
||
CString sUp(_T("")), sDown(_T(""));
|
||
if (!m_arsUps.IsEmpty()) sUp = m_arsUps[0];
|
||
if (!m_arsDowns.IsEmpty()) sDown = m_arsDowns[0];
|
||
|
||
CString sLeft(_T("")), sRight(_T(""));
|
||
short elType(-1);
|
||
ParseDownString(sDown, elType, sLeft, sRight);
|
||
//if (sLeft.IsEmpty())
|
||
// sLeft = sDown;
|
||
|
||
double d1 = UnderLineLength(sUp);
|
||
|
||
double d2 = UnderLineLength(sLeft + sRight) + m_dTextH * m_dPScale;
|
||
if (sLeft.IsEmpty() && sRight.IsEmpty())
|
||
d2 = UnderLineLength(sDown);
|
||
|
||
if (sUp.IsEmpty())
|
||
d1 = UnderLineLength(sDown);
|
||
|
||
double dLenderLen = d1 > d2 ? d1 : d2;
|
||
|
||
// 得到引线的方向,和文字位置
|
||
AcGePoint3d ptPosUp = ptTo;
|
||
AcGePoint3d ptPosDw = ptPosUp;
|
||
AcGeVector3d vtLeader(AcGeVector3d::kIdentity);
|
||
AcGeVector3d vtText(AcGeVector3d::kIdentity);
|
||
if (m_nDir == 0)
|
||
{
|
||
vtText = AcGeVector3d::kXAxis;
|
||
if (vtDir.x < 1.e-10)
|
||
{
|
||
vtLeader = -AcGeVector3d::kXAxis;
|
||
ptPosUp = ptTo + vtLeader * dLenderLen;
|
||
}
|
||
else
|
||
{
|
||
vtLeader = AcGeVector3d::kXAxis;
|
||
}
|
||
ptPosUp += AcGeVector3d::kYAxis * .1;
|
||
ptPosDw = ptPosUp - AcGeVector3d::kYAxis * .2;
|
||
}
|
||
else
|
||
{
|
||
vtText = AcGeVector3d::kYAxis;
|
||
if (vtDir.y < 1.e-10)
|
||
{
|
||
vtLeader = -AcGeVector3d::kYAxis;
|
||
ptPosUp = ptTo + vtLeader * dLenderLen;
|
||
}
|
||
else
|
||
{
|
||
vtLeader = AcGeVector3d::kYAxis;
|
||
}
|
||
ptPosUp -= AcGeVector3d::kXAxis * .1;
|
||
ptPosDw = ptPosUp + AcGeVector3d::kXAxis * .2;
|
||
}
|
||
|
||
// 绘制引线
|
||
//dc.DrawLine(AcGeLineSeg3d(ptTo, ptTo + vtLeader * dLenderLen));
|
||
pLine = new AcDbLine(ptTo, ptTo + vtLeader * dLenderLen);
|
||
if (pLine)
|
||
{
|
||
pLine->setLayer(layerId());
|
||
Add2DBuffer(pLine);
|
||
dc.DrawEntity(*pLine);
|
||
}
|
||
|
||
// 绘制上文字
|
||
TextEx(dc, AcGiDraw::kBottomLeft, ptPosUp, vtText, sUp, len);
|
||
if (/*m_nDimText != 0 &&*/ !sDown.IsEmpty())//允许下标
|
||
{
|
||
len = 0.0;
|
||
if (!sDown.IsEmpty())
|
||
TextEx(dc, AcGiDraw::kTopLeft, ptPosDw, vtText, sDown, len,-1);
|
||
|
||
/*if (elType > -1)//有标高 不用标高字体自画
|
||
{
|
||
ptPosDw += vtText * len;
|
||
DrawEl(dc
|
||
, (ptPosDw + (m_nDir == 0 ? -AcGeVector3d::kYAxis : AcGeVector3d::kXAxis) * m_dTextH * m_dPScale)
|
||
, m_nDir == 0 ? .0 : (PI * .5)
|
||
, elType
|
||
, m_dTextH * m_dPScale,-1);
|
||
|
||
ptPosDw += vtText * m_dTextH * m_dPScale;
|
||
TextEx(dc, AcGiDraw::kTopLeft, ptPosDw, vtText, sRight, len,-1);
|
||
}*/
|
||
}
|
||
return Acad::eOk;
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbEwPipeDim::MakeWDot(AcGiDraw &dc,AcGePoint3d &ptGeCen) const
|
||
{
|
||
//打印点 0.25
|
||
double dPlotDotD = 0.25 * m_dPScale;
|
||
|
||
double dDotRadius = dPlotDotD * 0.5;
|
||
AcGePoint2d ptGeCenDot = ptGeCen.convert2d(AcGePlane::kXYPlane);
|
||
AcGePoint2d ptGe[4];
|
||
double dBulge = tan(PI / 8.0);
|
||
|
||
ptGe[0] = ptGeCenDot + dDotRadius * AcGeVector2d::kYAxis;
|
||
ptGe[1] = ptGeCenDot + dDotRadius * AcGeVector2d::kXAxis;
|
||
ptGe[2] = ptGeCenDot - dDotRadius * AcGeVector2d::kYAxis;
|
||
ptGe[3] = ptGeCenDot - dDotRadius * AcGeVector2d::kXAxis;
|
||
|
||
AcDbPolyline *pDot = new AcDbPolyline;
|
||
pDot->addVertexAt(0, ptGe[0], -dBulge);
|
||
pDot->addVertexAt(1, ptGe[1], -dBulge);
|
||
pDot->addVertexAt(2, ptGe[2], -dBulge);
|
||
pDot->addVertexAt(3, ptGe[3], -dBulge);
|
||
pDot->addVertexAt(4, ptGe[0], 0.0);
|
||
pDot->setConstantWidth(dPlotDotD);
|
||
pDot->setClosed(Adesk::kTrue);
|
||
pDot->setNormal(AcGeVector3d::kZAxis);
|
||
|
||
Add2DBuffer(pDot);
|
||
dc.DrawEntity(*pDot);
|
||
|
||
return Acad::eOk;
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbEwPipeDim::DrawMBoxLineLdDim(AcGiDraw& dc) const
|
||
{
|
||
if (m_arPoints.length() != 3)
|
||
{
|
||
return Acad::eInvalidInput;
|
||
}
|
||
|
||
if (m_arsUps.IsEmpty()) return Acad::eInvalidInput;
|
||
|
||
double len(.0);
|
||
|
||
AcGePoint3d ptFr = m_arPoints.first();
|
||
AcGePoint3d ptTo = m_arPoints.at(1);
|
||
AcGePoint3d ptDir = m_arPoints.last();
|
||
CString sDimUp = _T("");
|
||
CString sDimDown = _T("");
|
||
dc.SetLayer(layerId());
|
||
//dc.DrawLine(AcGeLineSeg3d(ptFr,ptTo));
|
||
AcDbLine *pLine(new AcDbLine(ptFr, ptTo));
|
||
if (pLine)
|
||
{
|
||
pLine->setLayer(layerId());
|
||
Add2DBuffer(pLine);
|
||
dc.DrawEntity(*pLine);
|
||
}
|
||
|
||
//绘制点
|
||
MakeWDot(dc,ptFr);
|
||
|
||
//
|
||
AcGeVector3d vtDir = ptDir - ptTo;
|
||
double dLenderLen = 0;
|
||
AcGePoint3d ptPosUp;
|
||
AcGeVector3d vtLeader, vtText,vtV;
|
||
AcGePoint2d ptTxtBox;
|
||
AcGePoint3d ptGe[4];
|
||
|
||
// 得到引线长度
|
||
CString sUp(_T("")), sDown(_T(""));
|
||
for (int i = 0;i < m_arsUps.GetSize();i++)
|
||
{
|
||
sUp = m_arsUps.GetAt(i);
|
||
|
||
ptTxtBox = DimTextExtent(sUp);
|
||
dLenderLen = ptTxtBox.x;
|
||
dLenderLen += (0.5 * m_dTextH * m_dPScale);//加上半个字高
|
||
|
||
ptPosUp = ptTo;
|
||
|
||
//得到引线的方向,和文字位置
|
||
vtLeader = AcGeVector3d::kIdentity;
|
||
vtText = AcGeVector3d::kIdentity;
|
||
|
||
if (m_nDir == 0)
|
||
{
|
||
vtText = AcGeVector3d::kXAxis;
|
||
if (vtDir.x < 1.e-10)
|
||
{
|
||
vtLeader = -AcGeVector3d::kXAxis;
|
||
ptPosUp = ptTo + vtLeader * dLenderLen;
|
||
}
|
||
else
|
||
{
|
||
vtLeader = AcGeVector3d::kXAxis;
|
||
}
|
||
ptPosUp += AcGeVector3d::kYAxis * .1;
|
||
}
|
||
else
|
||
{
|
||
vtText = AcGeVector3d::kYAxis;
|
||
if (vtDir.y < 1.e-10)
|
||
{
|
||
vtLeader = -AcGeVector3d::kYAxis;
|
||
ptPosUp = ptTo + vtLeader * dLenderLen;
|
||
}
|
||
else
|
||
{
|
||
vtLeader = AcGeVector3d::kYAxis;
|
||
}
|
||
ptPosUp -= AcGeVector3d::kXAxis * .1;
|
||
}
|
||
|
||
vtV = vtLeader;
|
||
vtV.rotateBy(PI / 2.0, AcGeVector3d::kZAxis);
|
||
vtV.normalize();
|
||
|
||
// 绘制引线 U 型线
|
||
ptGe[0] = ptTo + vtV * ptTxtBox.y;
|
||
ptGe[1] = ptTo;
|
||
ptGe[2] = ptTo + vtLeader * dLenderLen;
|
||
ptGe[3] = ptGe[2] + vtV * ptTxtBox.y;
|
||
|
||
ptGe[0] += vtV * 0.5 * m_dTextH * m_dPScale;//文字有0.4空隙
|
||
ptGe[3] += vtV * 0.5 * m_dTextH * m_dPScale;//文字有0.4空隙
|
||
|
||
for (int ii = 0;ii < 3;ii++)
|
||
{
|
||
pLine = new AcDbLine(ptGe[ii], ptGe[ii+1]);
|
||
if (pLine)
|
||
{
|
||
pLine->setLayer(layerId());
|
||
Add2DBuffer(pLine);
|
||
dc.DrawEntity(*pLine);
|
||
}
|
||
}
|
||
|
||
// 绘制上文字
|
||
TextEx(dc, AcGiDraw::kBottomLeft, ptPosUp, vtText, sUp, len);
|
||
|
||
//封口
|
||
if (i == m_arsUps.GetSize() - 1)
|
||
{
|
||
pLine = new AcDbLine(ptGe[0], ptGe[3]);
|
||
if (pLine)
|
||
{
|
||
pLine->setLayer(layerId());
|
||
Add2DBuffer(pLine);
|
||
dc.DrawEntity(*pLine);
|
||
}
|
||
}
|
||
|
||
ptTo += vtV * ptTxtBox.y;
|
||
ptTo += vtV * 0.5 * m_dTextH * m_dPScale;//文字有0.4空隙
|
||
}
|
||
return Acad::eOk;
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbEwPipeDim::DrawOnlineDim(AcGiDraw & dc) const
|
||
{
|
||
//在线标注为单个的在线标注
|
||
if (m_arPoints.length() != 2 ) return Acad::eInvalidInput;
|
||
|
||
double txtLen(.0);
|
||
|
||
AcGePoint3d ptFr(m_arPoints.first()), ptTo(m_arPoints.last());
|
||
|
||
AcGeVector3d vtDir = ptTo - ptFr;
|
||
vtDir.normalize();
|
||
|
||
AcGeVector3d vtV(vtDir);
|
||
vtV.rotateBy(-PI * .5, AcGeVector3d::kZAxis);
|
||
vtV.normalize();
|
||
|
||
CString sDimUp(_T("")), sDimDown(_T(""));
|
||
if (!m_arsUps.IsEmpty())
|
||
{
|
||
sDimUp = m_arsUps.GetAt(0);
|
||
TextEx(dc, AcGiDraw::kBottomLeft, ptFr, vtDir, sDimUp, txtLen);
|
||
}
|
||
|
||
if (!m_arsDowns.IsEmpty())
|
||
{
|
||
sDimDown = m_arsDowns.GetAt(0);
|
||
ptFr += (vtV * (m_dD + 20));
|
||
|
||
short nType(-1);
|
||
CString sLeft, sRight;
|
||
if (ParseDownString(sDimDown, nType, sLeft, sRight) != Acad::eOk)
|
||
return Acad::eInvalidInput;
|
||
|
||
TextEx(dc, AcGiDraw::kTopLeft, ptFr, vtDir, sDimDown, txtLen,-1);
|
||
|
||
/*if (nType > -1)//有标高
|
||
{
|
||
ptFr += (vtDir * txtLen);
|
||
|
||
double dAngle = AcGeVector3d::kXAxis.angleTo(vtDir, AcGeVector3d::kZAxis);
|
||
DrawEl(dc, ptFr + (vtV * m_dTextH * m_dPScale), dAngle, nType, m_dTextH * m_dPScale,-1);
|
||
|
||
ptFr += (vtDir * (m_dTextH * m_dPScale));
|
||
TextEx(dc, AcGiDraw::kTopLeft, ptFr, vtDir, sRight, txtLen,-1);
|
||
}*/
|
||
}
|
||
return Acad::eOk;
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbEwPipeDim::DrawPolylineDim(AcGiDraw &dc) const
|
||
{
|
||
if (m_arPoints.length() == 0)
|
||
{
|
||
return Acad::eInvalidInput;
|
||
}
|
||
|
||
AcGePoint3d ptFr;
|
||
AcGePoint3d ptTo;
|
||
dc.SetLayer(layerId());
|
||
for (int i = 0; i < m_arPoints.length() - 1; i++)
|
||
{
|
||
ptFr = m_arPoints.at(i);
|
||
ptTo = m_arPoints.at(i + 1);
|
||
//dc.DrawLine(AcGeLineSeg3d(ptFr, ptTo));
|
||
AcDbLine *pL(new AcDbLine(ptFr, ptTo));
|
||
if (pL)
|
||
{
|
||
pL->setLayer(layerId());
|
||
Add2DBuffer(pL);
|
||
dc.DrawEntity(pL);
|
||
}
|
||
}
|
||
|
||
ptTo = m_arPoints.last();
|
||
|
||
//计算最大的文字需要的下画线长度
|
||
double dLen = 0.0;
|
||
CString sDimup,sDimDown = _T("");
|
||
for (int i = 0;i < m_arsUps.GetSize();i++)
|
||
{
|
||
sDimup = m_arsUps.GetAt(i);
|
||
dLen = __max(dLen, UnderLineLength(sDimup));
|
||
}
|
||
|
||
//文字标注比例
|
||
struct resbuf rb;
|
||
double dDimScale = 1.0;
|
||
acedGetVar(_T("dimscale"),&rb);
|
||
dDimScale = rb.resval.rreal;
|
||
|
||
AcGeVector3d vtH = AcGeVector3d::kYAxis;
|
||
vtH *= m_dTextH * 1.2 * GetPScale();//全局比例
|
||
|
||
ptFr = ptTo;
|
||
ptTo += dLen * AcGeVector3d::kXAxis;
|
||
|
||
for (int i = 0;i < m_arsUps.GetSize();i++)
|
||
{
|
||
sDimup = m_arsUps.GetAt(i);
|
||
DrawText(dc,ptFr,ptTo,sDimup,sDimDown,AcGeVector3d::kXAxis);
|
||
ptTo += vtH;
|
||
ptFr += vtH;
|
||
}
|
||
return Acad::eOk;
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbEwPipeDim::DrawSNo(AcGiDraw &dc) const
|
||
{
|
||
assertReadEnabled();
|
||
|
||
if (m_arPoints.length() == 0)
|
||
{
|
||
return Acad::eInvalidInput;
|
||
}
|
||
|
||
AcDbObjectId idLayOld = dc.GetLayerId();
|
||
AcDbObjectId idTextSt = dc.GetTextStyle();
|
||
|
||
AcGePoint3d ptFr;
|
||
AcGePoint3d ptTo;
|
||
dc.SetLayer(m_idTextLayer);
|
||
dc.SetTextStyle(m_idTextSty);
|
||
|
||
double dR = m_dTextH *m_dPScale;
|
||
AcGeVector3d vt;
|
||
|
||
ptFr = m_arPoints.last();
|
||
ptFr.z = 0.0;
|
||
AcGeVector3d vtH = AcGeVector3d::kXAxis;
|
||
vtH *= 2.0 * dR;
|
||
|
||
CString sDimup;
|
||
double dRLen = dR;
|
||
|
||
double dCirR = 1.2 * dR;
|
||
m_mapSpecXData.GetAt(_Custom_No_R_, dCirR);
|
||
|
||
for (int i = 0;i < m_arsUps.GetSize();i++)
|
||
{
|
||
sDimup = m_arsUps.GetAt(i);
|
||
|
||
//dc.DrawText(sDimup, ptFr, AcGiDraw::kMiddle, m_dTextH * m_dPScale,1.0, 0.0, NULL);
|
||
|
||
TextEx(dc, AcGiDraw::kTopCenter, ptFr, AcGeVector3d::kXAxis, sDimup, dRLen);
|
||
|
||
//dc.DrawCircle(ptFr,1.2 * dR,AcGeVector3d::kZAxis);
|
||
|
||
AcDbCircle *pC(new AcDbCircle(ptFr, AcGeVector3d::kZAxis, dCirR));
|
||
if (pC)
|
||
{
|
||
Add2DBuffer(pC);
|
||
dc.DrawEntity(pC);
|
||
}
|
||
|
||
ptFr += vtH;
|
||
}
|
||
|
||
for (int i = 0;i < m_arPoints.length() - 1;i++)
|
||
{
|
||
ptFr = m_arPoints.at(i);
|
||
ptTo = m_arPoints.at(i+1);
|
||
ptFr.z = 0.0;
|
||
ptTo.z = 0.0;
|
||
|
||
vt = ptFr - ptTo;
|
||
vt.normalize();
|
||
vt *= dCirR;
|
||
|
||
ptTo += vt;
|
||
//dc.DrawLine(AcGeLineSeg3d(ptFr,ptTo));
|
||
AcDbLine *pL(new AcDbLine(ptFr,ptTo));
|
||
if (pL)
|
||
{
|
||
pL->setLayer(layerId());
|
||
Add2DBuffer(pL);
|
||
dc.DrawEntity(pL);
|
||
}
|
||
}
|
||
|
||
dc.SetLayer(idLayOld);
|
||
dc.SetTextStyle(idTextSt);
|
||
|
||
return Acad::eOk;
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbEwPipeDim::DrawText(AcGiDraw &dc,AcGePoint3d ptFr,AcGePoint3d ptTo,
|
||
LPCTSTR pszDimup,LPCTSTR pszDimDown,
|
||
const AcGeVector3d& vtDimType,BOOL bHasUnderline) const
|
||
{
|
||
//可能含有标高,三角形标注!!!
|
||
//1. 在线标注
|
||
if (vtDimType.isZeroLength()) //在线标注,方向同管线
|
||
{
|
||
double dAngle = 0;
|
||
AcGeVector3d vtFrTo = ptTo - ptFr;
|
||
AcGeVector3d vtV = vtFrTo;
|
||
|
||
dAngle = AcGeVector3d::kXAxis.angleTo(vtFrTo,AcGeVector3d::kZAxis);
|
||
|
||
double dDot = vtFrTo.dotProduct(AcGeVector3d::kXAxis);
|
||
if (dDot > 0 ) //I,IV 象限 同向绘制文字
|
||
{
|
||
if (pszDimup != NULL)
|
||
{
|
||
DrawText(dc,pszDimup,ptFr,dAngle);
|
||
}
|
||
|
||
if (pszDimDown != NULL)
|
||
{
|
||
vtV.normalize();
|
||
vtV.rotateBy(-PI / 2.0,AcGeVector3d::kZAxis);
|
||
vtV *= m_dTextH * 1.2 * GetPScale();//间隙0.1
|
||
|
||
ptFr += vtV;
|
||
DrawText(dc,pszDimDown,ptFr,dAngle);
|
||
}
|
||
}
|
||
else if (dDot < 1.e-10)//反方向 II III 象限,或垂直
|
||
{
|
||
if (dDot > -1.e-10) //如果垂直 Y
|
||
{
|
||
if (vtFrTo.isCodirectionalTo(AcGeVector3d::kYAxis)) //垂直 和 Y+ 同向绘制文字
|
||
{
|
||
if (pszDimup != NULL)
|
||
{
|
||
DrawText(dc,pszDimup,ptFr,PI / 2.0);
|
||
}
|
||
|
||
if (pszDimDown != NULL)
|
||
{
|
||
ptFr += m_dTextH * 1.1 * GetPScale() * AcGeVector3d::kXAxis;//间隙0.1;
|
||
DrawText(dc,pszDimDown,ptFr,PI / 2.0);
|
||
}
|
||
}
|
||
else //反方向绘制文字 -Y 方向
|
||
{
|
||
if (pszDimup != NULL)
|
||
{
|
||
double dLen = UnderLineLength(pszDimup);
|
||
AcGePoint3d ptPos = ptFr - dLen * AcGeVector3d::kYAxis;
|
||
DrawText(dc,pszDimup,ptPos,PI / 2.0);
|
||
}
|
||
|
||
if (pszDimDown != NULL)
|
||
{
|
||
double dLen = UnderLineLength(pszDimDown);
|
||
AcGePoint3d ptPos = ptFr - dLen * AcGeVector3d::kYAxis;
|
||
ptPos.x += m_dTextH * 1.1 * GetPScale();//间隙0.1;
|
||
DrawText(dc,pszDimDown,ptPos,PI / 2.0);
|
||
}
|
||
}
|
||
}
|
||
else // 不垂直 反方向绘制文字
|
||
{
|
||
dAngle = AcGeVector3d::kXAxis.angleTo(vtFrTo,AcGeVector3d::kZAxis);
|
||
if (vtFrTo.x < 1.e-10 && vtFrTo.y > 1.e-10)
|
||
{
|
||
dAngle += PI;
|
||
}
|
||
|
||
//if (vtFrTo.x < 1.e-10 && vtFrTo.y < 1.e-10)
|
||
//{
|
||
// dAngle = PI - dAngle;
|
||
//}
|
||
|
||
if (pszDimup != NULL)
|
||
{
|
||
vtFrTo.normalize();
|
||
double dLen = UnderLineLength(pszDimup);
|
||
AcGePoint3d ptPos = ptFr + dLen * vtFrTo;
|
||
|
||
DrawText(dc,pszDimup,ptPos,dAngle);
|
||
}
|
||
|
||
if (pszDimDown != NULL)
|
||
{
|
||
vtFrTo.normalize();
|
||
double dLen = UnderLineLength(pszDimDown);
|
||
AcGePoint3d ptPos = ptFr + dLen * vtFrTo;
|
||
vtFrTo.rotateBy(PI / 2.0,AcGeVector3d::kZAxis);
|
||
ptPos += vtFrTo * m_dTextH * 1.1 * GetPScale();
|
||
DrawText(dc,pszDimDown,ptPos,dAngle);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
else //水平或垂直标注
|
||
{
|
||
AcGeVector3d vtFrTo = ptTo - ptFr;
|
||
|
||
//2.水平标注
|
||
if (vtDimType.isParallelTo(AcGeVector3d::kXAxis)) //水平标注
|
||
{
|
||
if (pszDimup != NULL)
|
||
{
|
||
DrawText(dc,pszDimup,ptFr,0.0);
|
||
}
|
||
|
||
if (pszDimDown != NULL)
|
||
{
|
||
AcGePoint3d ptPos = ptFr;
|
||
ptPos.y -= m_dTextH * 1.1 * GetPScale();
|
||
DrawText(dc,pszDimDown,ptPos,0.0);
|
||
}
|
||
}
|
||
|
||
//3.垂直标注
|
||
if (vtDimType.isParallelTo(AcGeVector3d::kYAxis))//垂直标注
|
||
{
|
||
if (vtFrTo.isCodirectionalTo(AcGeVector3d::kYAxis)) //垂直 和 Y+ 同向绘制文字
|
||
{
|
||
if (pszDimup != NULL)
|
||
{
|
||
DrawText(dc,pszDimup,ptFr,PI / 2.0);
|
||
}
|
||
|
||
if (pszDimDown != NULL)
|
||
{
|
||
ptFr.x += m_dTextH * 1.1 * GetPScale();//间隙0.1;
|
||
DrawText(dc,pszDimDown,ptFr,PI / 2.0);
|
||
}
|
||
}
|
||
else //反方向绘制文字 -Y 方向
|
||
{
|
||
if (pszDimup != NULL)
|
||
{
|
||
double dLen = UnderLineLength(pszDimup);
|
||
AcGePoint3d ptPos = ptFr - dLen * AcGeVector3d::kYAxis;
|
||
DrawText(dc,pszDimup,ptPos,PI / 2.0);
|
||
}
|
||
|
||
if (pszDimDown != NULL)
|
||
{
|
||
double dLen = UnderLineLength(pszDimDown);
|
||
AcGePoint3d ptPos = ptFr - dLen * AcGeVector3d::kYAxis;
|
||
ptPos.x += m_dTextH * 1.1 * GetPScale();//间隙0.1;
|
||
DrawText(dc,pszDimDown,ptPos,PI / 2.0);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
if (bHasUnderline)
|
||
{
|
||
AcGeLineSeg3d ln(ptFr,ptTo);
|
||
//dc.DrawLine(ln);
|
||
AcDbLine *pL(new AcDbLine(ptFr,ptTo));
|
||
if (pL)
|
||
{
|
||
pL->setLayer(layerId());
|
||
Add2DBuffer(pL);
|
||
dc.DrawEntity(pL);
|
||
}
|
||
}
|
||
return Acad::eOk;
|
||
}
|
||
|
||
/*
|
||
#define DIM_EL _T("\\U+2200")
|
||
#define DIM_TOP_EL _T("\\U+2201")
|
||
#define DIM_CEN_EL _T("\\U+2202")
|
||
#define DIM_BOM_EL _T("\\U+2203")
|
||
*/
|
||
|
||
Acad::ErrorStatus AecDbEwPipeDim::ParseDownString(LPCTSTR psz
|
||
, short &nElType
|
||
, CString &sLeft
|
||
, CString &sRight ) const
|
||
{
|
||
if (!psz) return Acad::eInvalidInput;
|
||
|
||
CString sDimTxt(psz);
|
||
|
||
nElType = -1;
|
||
if (sDimTxt.Find(DIM_EL) != -1 ||
|
||
sDimTxt.Find(DIM_TOP_EL) != -1 ||
|
||
sDimTxt.Find(DIM_CEN_EL) != -1 ||
|
||
sDimTxt.Find(DIM_BOM_EL) != -1)
|
||
{
|
||
int nPos = -1, nLen = 0;
|
||
if ((nPos = sDimTxt.Find(DIM_EL)) != -1)
|
||
{
|
||
sLeft = sDimTxt.Mid(0, nPos);
|
||
nLen = (int)_tcslen(DIM_EL);
|
||
sRight = sDimTxt.Mid(nPos + nLen);
|
||
nElType = 0;
|
||
}
|
||
|
||
if ((nPos = sDimTxt.Find(DIM_TOP_EL)) != -1)
|
||
{
|
||
sLeft = sDimTxt.Mid(0, nPos);
|
||
nLen = (int)_tcslen(DIM_TOP_EL);
|
||
sRight = sDimTxt.Mid(nPos + nLen);
|
||
nElType = 1;
|
||
}
|
||
|
||
if ((nPos = sDimTxt.Find(DIM_CEN_EL)) != -1)
|
||
{
|
||
sLeft = sDimTxt.Mid(0, nPos);
|
||
nLen = (int)_tcslen(DIM_CEN_EL);
|
||
sRight = sDimTxt.Mid(nPos + nLen);
|
||
nElType = 2;
|
||
}
|
||
|
||
if ((nPos = sDimTxt.Find(DIM_BOM_EL)) != -1)
|
||
{
|
||
sLeft = sDimTxt.Mid(0, nPos);
|
||
nLen = (int)_tcslen(DIM_BOM_EL);
|
||
sRight = sDimTxt.Mid(nPos + nLen);
|
||
nElType = 3;
|
||
}
|
||
}
|
||
return Acad::eOk;
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbEwPipeDim::DrawText(AcGiDraw &dc,LPCTSTR pszText,AcGePoint3d& ptFr,double dAngle) const
|
||
{
|
||
//标高问题
|
||
CString sDimTxt = pszText;
|
||
if (sDimTxt.IsEmpty())
|
||
return Acad::eOk;
|
||
|
||
if (sDimTxt.Find(DIM_EL) != -1 ||
|
||
sDimTxt.Find(DIM_TOP_EL) != -1 ||
|
||
sDimTxt.Find(DIM_CEN_EL) != -1 ||
|
||
sDimTxt.Find(DIM_BOM_EL) != -1)
|
||
{
|
||
int nPos = -1,nLen = 0,nElType = 0;
|
||
CString sLeft = _T(""),sEl = _T(""),sRight = _T("");
|
||
if ( (nPos = sDimTxt.Find(DIM_EL)) != -1)
|
||
{
|
||
sLeft = sDimTxt.Mid(0,nPos);
|
||
nLen = (int)_tcslen(DIM_EL);
|
||
sEl = sDimTxt.Mid(nPos,nLen);
|
||
sRight = sDimTxt.Mid(nPos + nLen);
|
||
nElType = 0;
|
||
}
|
||
|
||
if ( (nPos = sDimTxt.Find(DIM_TOP_EL)) != -1)
|
||
{
|
||
sLeft = sDimTxt.Mid(0,nPos);
|
||
nLen = (int)_tcslen(DIM_TOP_EL);
|
||
sEl = sDimTxt.Mid(nPos,nLen);
|
||
sRight = sDimTxt.Mid(nPos + nLen);
|
||
nElType = 1;
|
||
}
|
||
|
||
if ( (nPos = sDimTxt.Find(DIM_CEN_EL)) != -1)
|
||
{
|
||
sLeft = sDimTxt.Mid(0,nPos);
|
||
nLen = (int)_tcslen(DIM_CEN_EL);
|
||
sEl = sDimTxt.Mid(nPos,nLen);
|
||
sRight = sDimTxt.Mid(nPos + nLen);
|
||
nElType = 2;
|
||
}
|
||
|
||
if ( (nPos = sDimTxt.Find(DIM_BOM_EL) ) != -1)
|
||
{
|
||
sLeft = sDimTxt.Mid(0,nPos);
|
||
nLen = (int)_tcslen(DIM_BOM_EL);
|
||
sEl = sDimTxt.Mid(nPos,nLen);
|
||
sRight = sDimTxt.Mid(nPos + nLen);
|
||
nElType = 3;
|
||
}
|
||
|
||
//标左
|
||
sLeft.TrimRight();
|
||
DrawText2(dc,sLeft,ptFr,dAngle);
|
||
|
||
//标中
|
||
//AcGeVector3d vtDir = AcGeVector3d::kXAxis;
|
||
//vtDir.rotateBy(dAngle,AcGeVector3d::kZAxis);
|
||
DrawEl(dc,ptFr,dAngle,nElType,m_dTextH * GetPScale());
|
||
|
||
//标右
|
||
if (!sRight.IsEmpty())
|
||
{
|
||
DrawText2(dc,sRight,ptFr,dAngle);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
DrawText2(dc,pszText,ptFr,dAngle);
|
||
}
|
||
return Acad::eOk;
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbEwPipeDim::TextEx( AcGiDraw & dc
|
||
, const AcGiDraw::TextAlignment & ta
|
||
, const AcGePoint3d & ptPos
|
||
, const AcGeVector3d & vtDir
|
||
, LPCTSTR psz
|
||
, double &len
|
||
, int nUpOrDwn/* = 1*/) const
|
||
{
|
||
if (!psz || CString(psz).IsEmpty()) return Acad::eInvalidInput;
|
||
|
||
dc.SetLayer(m_idTextLayer);
|
||
dc.SetTextStyle(m_idTextSty);
|
||
|
||
double dAngle = AcGeVector3d::kXAxis.angleTo(vtDir, AcGeVector3d::kZAxis);
|
||
if (dAngle > PI && dAngle < 1.5 * PI)
|
||
dAngle -= PI;
|
||
|
||
if (dAngle > 0.5 * PI && dAngle < PI)
|
||
dAngle = 2.0 * PI - (PI - dAngle);
|
||
|
||
AcGeVector3d vtUD = vtDir;
|
||
vtUD.rotateBy(nUpOrDwn * PI / 2.0,AcGeVector3d::kZAxis);
|
||
vtUD.normalize();
|
||
vtUD *= 0.4 * m_dTextH * m_dPScale;//文字高度0.4空隙
|
||
AcGePoint3d ptPos2 = ptPos + vtUD;
|
||
|
||
dc.DrawText(psz, ptPos2, ta, m_dTextH * m_dPScale, m_dWScale, dAngle, NULL);
|
||
|
||
AcDbVoidPtrArray arTxt;
|
||
AcGiExplodeDraw dc2(arTxt);
|
||
dc2.SetLayer(m_idTextLayer);
|
||
dc2.SetTextStyle(m_idTextSty);
|
||
dc2.DrawText(psz, ptPos2, ta, m_dTextH * m_dPScale, m_dWScale, dAngle, NULL);
|
||
|
||
if (!arTxt.isEmpty())
|
||
{
|
||
Add2DBuffer((AcDbEntity*)arTxt.first());
|
||
}
|
||
|
||
////错误,标注方向可能任意方向,内部y 减加不对2023-6-1
|
||
// 求 vDir 方向长度
|
||
// 不需要设置角度,因为无论什么角度,文字对象长是一样的
|
||
/*AcDbText *pDbTxt = new AcDbText;
|
||
if (pDbTxt)
|
||
{
|
||
pDbTxt->setTextString(psz);
|
||
|
||
pDbTxt->setTextStyle(m_idTextSty);
|
||
pDbTxt->setHeight(m_dTextH * m_dPScale);
|
||
pDbTxt->setWidthFactor(m_dWScale);
|
||
pDbTxt->setRotation(dAngle);
|
||
|
||
AcDbExtents ext;
|
||
pDbTxt->getGeomExtents(ext);
|
||
len = ext.maxPoint().distanceTo(ext.minPoint());
|
||
AcGePoint3d pt, ptExt(ext.maxPoint().x - ext.minPoint().x
|
||
, ext.maxPoint().y
|
||
, m_dTextH * m_dPScale);
|
||
|
||
//错误,标注方向可能任意方向,内部y 减加不对
|
||
pt = AcGiDraw::Align2Base(ta, ptPos2, ptExt);
|
||
|
||
pDbTxt->setPosition(pt);
|
||
|
||
pDbTxt->setColorIndex(dc.GetColor());
|
||
|
||
pDbTxt->setLayer(m_idTextLayer);
|
||
|
||
dc.DrawEntity(*pDbTxt);
|
||
Add2DBuffer(pDbTxt);
|
||
}*/
|
||
return Acad::eOk;
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbEwPipeDim::DrawText2(AcGiDraw &dc,LPCTSTR pszText,AcGePoint3d& ptFr,double dAngle) const
|
||
{
|
||
dc.SetLayer(m_idTextLayer);
|
||
dc.SetTextStyle(m_idTextSty);
|
||
//dc.DrawText(pszText, ptFr, AcGiDraw::kBottomLeft, m_dTextH * GetPScale(), 1, dAngle, NULL);
|
||
|
||
AcDbText *pDbTxt = new AcDbText;
|
||
if (pDbTxt)
|
||
{
|
||
pDbTxt->setTextString(pszText);
|
||
|
||
pDbTxt->setTextStyle(m_idTextSty);
|
||
pDbTxt->setHeight(m_dTextH * GetPScale());
|
||
pDbTxt->setWidthFactor(1);
|
||
pDbTxt->setRotation(dAngle);
|
||
|
||
AcDbExtents ext;
|
||
pDbTxt->getGeomExtents(ext);
|
||
AcGePoint3d pt, ptExt(ext.maxPoint().x - ext.minPoint().x
|
||
, ext.maxPoint().y
|
||
, m_dTextH * m_dPScale);
|
||
|
||
pt = AcGiDraw::Align2Base(AcGiDraw::kBottomLeft, ptFr, ptExt);
|
||
pDbTxt->setPosition(pt);
|
||
pDbTxt->setColorIndex(dc.GetColor());
|
||
pDbTxt->setLayer(m_idTextLayer);
|
||
|
||
dc.DrawEntity(*pDbTxt);
|
||
Add2DBuffer(pDbTxt);
|
||
}
|
||
|
||
return Acad::eOk;
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbEwPipeDim::DrawEl(AcGiDraw &dc,AcGePoint3d& ptFr,double dAngle,short nElType,double dH, int nUpOrDwn/* = 1*/) const
|
||
{
|
||
AcGeVector3d vtDir = AcGeVector3d::kXAxis;
|
||
vtDir.rotateBy(dAngle,AcGeVector3d::kZAxis);
|
||
|
||
AcGeVector3d vtV = vtDir;
|
||
vtV.rotateBy(PI / 2.0,AcGeVector3d::kZAxis);
|
||
|
||
dH *= 0.8;
|
||
double dL = dH / 0.866;
|
||
AcGePoint3d ptGe[8];
|
||
|
||
AcGeVector3d vtUD = vtV;
|
||
vtUD.normalize();
|
||
vtUD *= nUpOrDwn;
|
||
vtUD *= 0.4 * m_dTextH * m_dPScale;//文字高度0.4空隙
|
||
AcGePoint3d ptPos2 = ptFr + vtUD;
|
||
|
||
ptGe[0] = ptPos2;
|
||
ptGe[0] += dL * 0.5 * vtDir;
|
||
ptGe[1] = ptGe[0] + dL * 0.5 * vtDir;
|
||
ptGe[1] += dH * vtV;
|
||
ptGe[2] = ptGe[1] - dL * vtDir;
|
||
ptGe[3] = ptGe[0];
|
||
|
||
ptFr += dL * 1.1 * vtDir;
|
||
|
||
AcDbLine *pLine(NULL);
|
||
AcGeLineSeg3d ln;
|
||
switch(nElType)
|
||
{
|
||
case 0://DIM_EL
|
||
{
|
||
for (int i = 0;i <= 2;i++)
|
||
{
|
||
ln.set(ptGe[i], ptGe[i+1]);
|
||
//dc.DrawLine(ln);
|
||
pLine = new AcDbLine(ptGe[i], ptGe[i+1]);
|
||
if (pLine)
|
||
{
|
||
pLine->setLayer(layerId());
|
||
Add2DBuffer(pLine);
|
||
dc.DrawEntity(pLine);
|
||
}
|
||
}
|
||
break;
|
||
}
|
||
case 1://DIM_TOP_EL
|
||
{
|
||
for (int i = 0;i <= 2;i++)
|
||
{
|
||
ln.set(ptGe[i], ptGe[i+1]);
|
||
//dc.DrawLine(ln);
|
||
|
||
pLine = new AcDbLine(ptGe[i], ptGe[i + 1]);
|
||
if (pLine)
|
||
{
|
||
pLine->setLayer(layerId());
|
||
Add2DBuffer(pLine);
|
||
dc.DrawEntity(pLine);
|
||
}
|
||
}
|
||
|
||
Midpoint(ptGe[0],ptGe[1],ptGe[4]);
|
||
Midpoint(ptGe[0],ptGe[2],ptGe[5]);
|
||
|
||
ln.set(ptGe[4], ptGe[5]);
|
||
//dc.DrawLine(ln);
|
||
|
||
pLine = new AcDbLine(ptGe[4], ptGe[5]);
|
||
if (pLine)
|
||
{
|
||
pLine->setLayer(layerId());
|
||
Add2DBuffer(pLine);
|
||
dc.DrawEntity(pLine);
|
||
}
|
||
|
||
break;
|
||
}
|
||
case 2://DIM_CEN_EL
|
||
{
|
||
for (int i = 0;i <= 2;i++)
|
||
{
|
||
ln.set(ptGe[i], ptGe[i+1]);
|
||
//dc.DrawLine(ln);
|
||
pLine = new AcDbLine(ptGe[i], ptGe[i + 1]);
|
||
if (pLine)
|
||
{
|
||
pLine->setLayer(layerId());
|
||
Add2DBuffer(pLine);
|
||
dc.DrawEntity(pLine);
|
||
}
|
||
}
|
||
Midpoint(ptGe[1],ptGe[2],ptGe[4]);
|
||
ln.set(ptGe[0], ptGe[4]);
|
||
//dc.DrawLine(ln);
|
||
|
||
pLine = new AcDbLine(ptGe[0], ptGe[4]);
|
||
if (pLine)
|
||
{
|
||
pLine->setLayer(layerId());
|
||
Add2DBuffer(pLine);
|
||
dc.DrawEntity(pLine);
|
||
}
|
||
|
||
break;
|
||
}
|
||
case 3://DIM_BOM_EL
|
||
{
|
||
for (int i = 0;i <= 2;i++)
|
||
{
|
||
ln.set(ptGe[i], ptGe[i+1]);
|
||
//dc.DrawLine(ln);
|
||
|
||
pLine = new AcDbLine(ptGe[i], ptGe[i + 1]);
|
||
if (pLine)
|
||
{
|
||
pLine->setLayer(layerId());
|
||
Add2DBuffer(pLine);
|
||
dc.DrawEntity(pLine);
|
||
}
|
||
}
|
||
|
||
Midpoint(ptGe[0],ptGe[1],ptGe[4]);
|
||
Midpoint(ptGe[0],ptGe[2],ptGe[5]);
|
||
|
||
AcGiDraw::AcGiPoly2d pl;
|
||
AcGiDraw::Vertex3d vt;
|
||
|
||
vt.pt = ptGe[0];
|
||
vt.dBulge = .0;
|
||
pl.append(vt);
|
||
|
||
vt.pt = ptGe[4];
|
||
vt.dBulge = .0;
|
||
pl.append(vt);
|
||
|
||
vt.pt = ptGe[5];
|
||
vt.dBulge = .0;
|
||
pl.append(vt);
|
||
|
||
vt.pt = ptGe[0];
|
||
vt.dBulge = .0;
|
||
pl.append(vt);
|
||
|
||
//dc.DrawSolid(pl);
|
||
|
||
AcDbPolyline *pPoly = new AcDbPolyline();
|
||
if (pPoly)
|
||
{
|
||
pPoly->addVertexAt(0, AcGePoint2d(ptGe[0].x, ptGe[0].y));
|
||
pPoly->addVertexAt(1, AcGePoint2d(ptGe[4].x, ptGe[4].y));
|
||
pPoly->addVertexAt(2, AcGePoint2d(ptGe[5].x, ptGe[5].y));
|
||
pPoly->addVertexAt(3, AcGePoint2d(ptGe[0].x, ptGe[0].y));
|
||
Add2DBuffer(pPoly);
|
||
dc.DrawEntity(*pPoly);
|
||
}
|
||
|
||
break;
|
||
}
|
||
default:
|
||
break;
|
||
}
|
||
return Acad::eOk;
|
||
}
|
||
|
||
double AecDbEwPipeDim::UnderLineLength(LPCTSTR pszDimup) const
|
||
{
|
||
AcGiTextStyle giTxtStyle;
|
||
fromAcDbTextStyle(giTxtStyle,m_idTextSty);
|
||
|
||
giTxtStyle.setTextSize(m_dTextH * GetPScale());
|
||
giTxtStyle.setXScale(m_dWScale);
|
||
|
||
//标高脚本按一个'W'字处理
|
||
CString sDimup = pszDimup;
|
||
sDimup.Replace(DIM_EL,_T("W"));
|
||
sDimup.Replace(DIM_TOP_EL,_T("W"));
|
||
sDimup.Replace(DIM_CEN_EL,_T("W"));
|
||
sDimup.Replace(DIM_BOM_EL,_T("W"));
|
||
|
||
int nLen = sDimup.GetLength();
|
||
AcGePoint2d pt2d = giTxtStyle.extents(sDimup,Adesk::kFalse,nLen,Adesk::kTrue);
|
||
|
||
return pt2d.x;
|
||
}
|
||
|
||
AcGePoint2d AecDbEwPipeDim::DimTextExtent(LPCTSTR pszDimup) const
|
||
{
|
||
AcGiTextStyle giTxtStyle;
|
||
fromAcDbTextStyle(giTxtStyle, m_idTextSty);
|
||
|
||
giTxtStyle.setTextSize(m_dTextH * GetPScale());
|
||
giTxtStyle.setXScale(m_dWScale);
|
||
|
||
//标高脚本按一个'W'字处理
|
||
CString sDimup = pszDimup;
|
||
sDimup.Replace(DIM_EL, _T("W"));
|
||
sDimup.Replace(DIM_TOP_EL, _T("W"));
|
||
sDimup.Replace(DIM_CEN_EL, _T("W"));
|
||
sDimup.Replace(DIM_BOM_EL, _T("W"));
|
||
|
||
int nLen = sDimup.GetLength();
|
||
AcGePoint2d pt2d = giTxtStyle.extents(sDimup, Adesk::kFalse, nLen, Adesk::kTrue);
|
||
return pt2d;
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbEwPipeDim::subGetGripPoints (AcDbGripDataPtrArray& grips,
|
||
const double curViewUnitSize,
|
||
const int gripSize,
|
||
const AcGeVector3d& curViewDir,
|
||
const int bitflags) const
|
||
{
|
||
assertReadEnabled();
|
||
|
||
if (m_arPoints.length() > 0)
|
||
{
|
||
memset(&m_pGripAppData[0],0,sizeof(AecGripData));
|
||
m_pGripAppData[0].nIndex = 0;
|
||
m_pGripAppData[0].ePos = eStart;
|
||
m_pGripAppData[0].nColor = kBlue;
|
||
m_pGripAppData[0].ptGrip = m_arPoints.at(0);
|
||
m_pGripAppData[0].pOwner = (AcDbEntity*)this;
|
||
|
||
AcDbGripData* pGripData = new AcDbGripData;
|
||
pGripData->setGripPoint(m_arPoints.at(0));
|
||
pGripData->setAppData((void*)&m_pGripAppData[0]);
|
||
pGripData->setWorldDraw(AecGripCback::WorldDrawfunc);
|
||
pGripData->setToolTipFunc(AecGripCback::GripToolTipFunc);
|
||
grips.append(pGripData);
|
||
|
||
if (m_arPoints.length() > 1)
|
||
{
|
||
memset(&m_pGripAppData[1],0,sizeof(AecGripData));
|
||
m_pGripAppData[1].nIndex = 1;
|
||
m_pGripAppData[1].ePos = eEnd;
|
||
m_pGripAppData[1].nColor = kBlue;
|
||
m_pGripAppData[1].ptGrip = m_arPoints.at(1);
|
||
m_pGripAppData[1].pOwner = (AcDbEntity*)this;
|
||
|
||
pGripData = new AcDbGripData;
|
||
pGripData->setGripPoint(m_arPoints.at(1));
|
||
pGripData->setAppData((void*)&m_pGripAppData[1]);
|
||
pGripData->setWorldDraw(AecGripCback::WorldDrawfunc);
|
||
pGripData->setToolTipFunc(AecGripCback::GripToolTipFunc);
|
||
grips.append(pGripData);
|
||
}
|
||
}
|
||
return Acad::eOk;
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbEwPipeDim::subMoveGripPointsAt(const AcDbVoidPtrArray& appData,const AcGeVector3d& offset,const int bitflags)
|
||
{
|
||
AssertWriteEnabled();
|
||
|
||
AecGripData* pAppData = NULL;
|
||
AcDbIntArray arIndex;
|
||
|
||
if ( !appData.isEmpty() )
|
||
{
|
||
pAppData = (AecGripData*)appData.first();
|
||
arIndex.append(pAppData->nIndex);
|
||
}
|
||
else
|
||
{
|
||
return Acad::eOk;
|
||
}
|
||
|
||
int nGripIndex = arIndex.first();
|
||
AcGePoint3d ptGe;
|
||
switch(nGripIndex)
|
||
{
|
||
case 0:
|
||
{
|
||
ptGe = m_arPoints.at(0);
|
||
ptGe += offset;
|
||
m_arPoints.setAt(0,ptGe);
|
||
|
||
break;
|
||
}
|
||
case 1:
|
||
{
|
||
ptGe = m_arPoints.at(1);
|
||
ptGe += offset;
|
||
m_arPoints.setAt(1,ptGe);
|
||
|
||
break;
|
||
}
|
||
default:
|
||
break;
|
||
}
|
||
|
||
return Acad::eOk;
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbEwPipeDim::copyFrom(const AcRxObject* pSrc)
|
||
{
|
||
AssertWriteEnabled();
|
||
|
||
AecDbEwPipeDim* pDimSrc = AecDbEwPipeDim::cast(pSrc);
|
||
if (pDimSrc != NULL)
|
||
{
|
||
m_nStyle = pDimSrc->m_nStyle;
|
||
m_nDir = pDimSrc->m_nDir;
|
||
m_nDimText = pDimSrc->m_nDimText;
|
||
m_nIsISO = pDimSrc->m_nIsISO;
|
||
|
||
m_arsUps.RemoveAll();
|
||
m_arsUps.Append(pDimSrc->m_arsUps);
|
||
|
||
m_sUpScr = pDimSrc->m_sUpScr;
|
||
|
||
m_arsDowns.RemoveAll();
|
||
m_arsDowns.Append(pDimSrc->m_arsDowns);
|
||
|
||
m_sDownScr = pDimSrc->m_sDownScr;
|
||
|
||
m_dTextH = pDimSrc->m_dTextH;
|
||
m_dWScale = pDimSrc->m_dWScale;
|
||
m_dD = pDimSrc->m_dD;
|
||
m_dPScale = pDimSrc->m_dPScale;
|
||
m_idTextSty = pDimSrc->m_idTextSty;
|
||
m_idTextLayer = pDimSrc->m_idTextLayer;
|
||
|
||
m_arPoints.removeAll();
|
||
m_arPoints.append(pDimSrc->m_arPoints);
|
||
|
||
m_arNoPoints.removeAll();
|
||
m_arNoPoints.append(pDimSrc->m_arNoPoints);
|
||
|
||
m_aridAttachs.removeAll();
|
||
m_aridAttachs.append(pDimSrc->m_aridAttachs);
|
||
}
|
||
return Acad::eOk;
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbEwPipeDim::subGetOsnapPoints( AcDb::OsnapMode osnapMode,
|
||
INT_PTR gsSelectionMark,
|
||
const AcGePoint3d& pickPoint,
|
||
const AcGePoint3d& lastPoint,
|
||
const AcGeMatrix3d& viewXform,
|
||
AcGePoint3dArray& snapPoints,
|
||
AcDbIntArray& geomIds) const
|
||
{
|
||
assertReadEnabled();
|
||
|
||
AcDbPolyline pl;
|
||
for (int i = 0;i < m_arPoints.length();i++)
|
||
{
|
||
pl.addVertexAt(i,m_arPoints.at(i).convert2d(AcGePlane::kXYPlane));
|
||
}
|
||
return pl.getOsnapPoints(osnapMode,gsSelectionMark,pickPoint,lastPoint,viewXform,snapPoints,geomIds);
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbEwPipeDim::subTransformBy(const AcGeMatrix3d& xform)
|
||
{
|
||
AssertWriteEnabled();
|
||
|
||
AcGePoint3d ptGe;
|
||
for (int i = 0;i < m_arPoints.length();i++)
|
||
{
|
||
ptGe = m_arPoints.at(i);
|
||
ptGe.transformBy(xform);
|
||
m_arPoints.setAt(i,ptGe);
|
||
}
|
||
|
||
return Acad::eOk;
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbEwPipeDim::subExplode(AcDbVoidPtrArray& entitySet) const
|
||
{
|
||
AcGiExplodeDraw draw(entitySet);
|
||
Draw2d(draw);
|
||
|
||
return Acad::eOk;
|
||
}
|
||
|
||
bool AecDbEwPipeDim::GetSNDimCircle(AcDbCircle& cir) const
|
||
{
|
||
assertReadEnabled();
|
||
|
||
if (m_arPoints.isEmpty())
|
||
return false;
|
||
|
||
AcGePoint3d ptFr = m_arPoints.last();
|
||
ptFr.z = 0.0;
|
||
AcGeVector3d vtH = AcGeVector3d::kXAxis;
|
||
|
||
double dR = m_dTextH * m_dPScale;
|
||
vtH *= 2.0 * dR;
|
||
|
||
if (m_arsUps.IsEmpty())
|
||
return false;
|
||
|
||
cir.setCenter(ptFr);
|
||
cir.setRadius(1.2 * dR);
|
||
cir.setNormal(AcGeVector3d::kZAxis);
|
||
|
||
return true;
|
||
}
|
||
|
||
bool AecDbEwPipeDim::IsSNOverlapping(const AecDbEwPipeDim* pDim) const
|
||
{
|
||
assertReadEnabled();
|
||
|
||
AcDbCircle cir1;
|
||
if ( GetSNDimCircle(cir1) )
|
||
{
|
||
AcDbCircle cir2;
|
||
if ( pDim->GetSNDimCircle(cir2) )
|
||
{
|
||
AcGePoint3dArray arPts;
|
||
cir2.intersectWith(&cir1,AcDb::kOnBothOperands,arPts);
|
||
|
||
return !arPts.isEmpty();
|
||
}
|
||
}
|
||
return false;
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbEwPipeDim::dxfOutFields(AcDbDxfFiler* pFiler) const
|
||
{
|
||
return Acad::eOk;
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbEwPipeDim::dxfInFields(AcDbDxfFiler* pFiler)
|
||
{
|
||
AssertWriteEnabled();
|
||
return Acad::eOk;
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbEwPipeDim::dwgOutFields(AcDbDwgFiler* pFiler) const
|
||
{
|
||
Acad::ErrorStatus es;
|
||
|
||
// Call dwgOutFields from TDbInterfacesObj
|
||
if ((es = AecDbEntityBase::dwgOutFields(pFiler)) != Acad::eOk)
|
||
{
|
||
return es;
|
||
}
|
||
|
||
// Write version number.
|
||
pFiler->writeItem((Adesk::UInt16) VERSION_TDBFITTINGBASE);
|
||
|
||
pFiler->writeInt16(m_nStyle);
|
||
pFiler->writeInt16(m_nDir);
|
||
pFiler->writeInt16(m_nDimText);
|
||
pFiler->writeInt16(m_nIsISO);
|
||
|
||
pFiler->writeInt32((Adesk::Int32)m_arsUps.GetSize());
|
||
for (int i = 0;i < m_arsUps.GetSize();i++)
|
||
{
|
||
pFiler->writeString((const TCHAR *)m_arsUps.GetAt(i));
|
||
}
|
||
pFiler->writeString((const TCHAR *)m_sUpScr);
|
||
|
||
Adesk::UInt32 nSize;
|
||
nSize = (Adesk::UInt32)m_arsDowns.GetSize();
|
||
|
||
pFiler->writeUInt32(nSize);
|
||
for (int i = 0;i < m_arsDowns.GetSize();i++)
|
||
{
|
||
pFiler->writeString((const TCHAR *)m_arsDowns.GetAt(i));
|
||
}
|
||
pFiler->writeString((const TCHAR *)m_sDownScr);
|
||
|
||
pFiler->writeDouble(m_dTextH);
|
||
pFiler->writeDouble(m_dWScale);
|
||
pFiler->writeDouble(m_dD);
|
||
pFiler->writeDouble(m_dPScale);
|
||
|
||
pFiler->writeSoftPointerId(m_idTextSty);
|
||
pFiler->writeSoftPointerId(m_idTextLayer);
|
||
|
||
pFiler->writeInt32(m_arPoints.length());
|
||
for (int i = 0;i < m_arPoints.length();i++)
|
||
{
|
||
pFiler->writePoint3d(m_arPoints.at(i));
|
||
}
|
||
|
||
pFiler->writeInt32(m_arNoPoints.length());
|
||
for (int i = 0;i < m_arNoPoints.length();i++)
|
||
{
|
||
pFiler->writePoint3d(m_arNoPoints.at(i));
|
||
}
|
||
|
||
pFiler->writeInt32(m_aridAttachs.length());
|
||
for (int i = 0;i < m_aridAttachs.length();i++)
|
||
{
|
||
pFiler->writeSoftPointerId(m_aridAttachs.at(i));
|
||
}
|
||
|
||
m_mapSpecXData.dwgOutFields(pFiler);
|
||
return Acad::eOk;
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbEwPipeDim::dwgInFields(AcDbDwgFiler* pFiler)
|
||
{
|
||
AssertWriteEnabled();
|
||
|
||
Acad::ErrorStatus es;
|
||
|
||
// Call dwgInFields from TDbInterfacesObj
|
||
if ((es = AecDbEntityBase::dwgInFields(pFiler)) != Acad::eOk)
|
||
{
|
||
return es;
|
||
}
|
||
|
||
// Read version number.
|
||
Adesk::UInt16 version;
|
||
pFiler->readItem(&version);
|
||
|
||
if (version > VERSION_TDBFITTINGBASE)
|
||
return Acad::eMakeMeProxy;
|
||
|
||
pFiler->readInt16(&m_nStyle);
|
||
pFiler->readInt16(&m_nDir);
|
||
pFiler->readInt16(&m_nDimText);
|
||
pFiler->readInt16(&m_nIsISO);
|
||
|
||
Adesk::Int32 nUps = 0;
|
||
pFiler->readInt32(&nUps);
|
||
|
||
m_arsUps.RemoveAll();
|
||
TCHAR* pszText = NULL;
|
||
for (int i = 0;i < nUps;i++)
|
||
{
|
||
pFiler->readString(&pszText);
|
||
m_arsUps.Add(pszText);
|
||
}
|
||
pFiler->readString(&pszText);
|
||
m_sUpScr = pszText;
|
||
|
||
Adesk::Int32 nDowns = 0;
|
||
pFiler->readInt32(&nDowns);
|
||
|
||
m_arsDowns.RemoveAll();
|
||
for (int i = 0;i < nDowns;i++)
|
||
{
|
||
pFiler->readString(&pszText);
|
||
m_arsDowns.Add(pszText);
|
||
}
|
||
|
||
pFiler->readString(&pszText);
|
||
m_sDownScr = pszText;
|
||
|
||
pFiler->readDouble(&m_dTextH);
|
||
pFiler->readDouble(&m_dWScale);
|
||
pFiler->readDouble(&m_dD);
|
||
pFiler->readDouble(&m_dPScale);
|
||
|
||
AcDbSoftPointerId id;
|
||
pFiler->readSoftPointerId(&id);
|
||
m_idTextSty = id;
|
||
|
||
pFiler->readSoftPointerId(&id);
|
||
m_idTextLayer = id;
|
||
|
||
Adesk::Int32 nPts = 0;
|
||
pFiler->readInt32(&nPts);
|
||
|
||
m_arPoints.removeAll();
|
||
AcGePoint3d ptGe;
|
||
for (int i = 0;i < nPts;i++)
|
||
{
|
||
pFiler->readPoint3d(&ptGe);
|
||
m_arPoints.append(ptGe);
|
||
}
|
||
|
||
nPts = 0;
|
||
pFiler->readInt32(&nPts);
|
||
|
||
m_arNoPoints.removeAll();
|
||
for (int i = 0;i < nPts;i++)
|
||
{
|
||
pFiler->readPoint3d(&ptGe);
|
||
m_arNoPoints.append(ptGe);
|
||
}
|
||
|
||
Adesk::Int32 nLen = 0;
|
||
pFiler->readInt32(&nLen);
|
||
|
||
m_aridAttachs.removeAll();
|
||
for (int i = 0;i < nLen;i++)
|
||
{
|
||
pFiler->readSoftPointerId(&id);
|
||
m_aridAttachs.append(id);
|
||
}
|
||
|
||
if (version >= 2)
|
||
{
|
||
m_mapSpecXData.dwgInFields(pFiler);
|
||
}
|
||
return Acad::eOk;
|
||
}
|
||
|
||
void AecDbEwPipeDim::SetPScale(double dScale)
|
||
{
|
||
AssertWriteEnabled();
|
||
m_dPScale = dScale;
|
||
}
|
||
|
||
double AecDbEwPipeDim::GetPScale() const
|
||
{
|
||
assertReadEnabled();
|
||
return m_dPScale;
|
||
}
|
||
|
||
#define ELE_FLAG _T("标高")
|
||
namespace
|
||
{
|
||
bool isHoleElevDim(AecDbEwPipeDim *pDim)
|
||
{
|
||
CString sUp, sDw;
|
||
pDim->GetDimText(0, sUp, sDw);
|
||
if (sUp.Find(ELE_FLAG) != -1)
|
||
return true;
|
||
|
||
if (sDw.Find(ELE_FLAG) != -1)
|
||
return true;
|
||
|
||
return false;
|
||
}
|
||
|
||
bool isPipeElevDim(AecDbEwPipeDim *pDim)
|
||
{
|
||
CString sUp, sDw;
|
||
pDim->GetDimupScript(sUp);
|
||
pDim->GetDimdownScript(sDw);
|
||
if (sUp.Find(ELE_FLAG) != -1)
|
||
return true;
|
||
|
||
if (sDw.Find(ELE_FLAG) != -1)
|
||
return true;
|
||
|
||
return false;
|
||
}
|
||
// {}-{}*{}&{}
|
||
// 收集-,*,&
|
||
void collectSplite(LPCTSTR psz, std::set<CString> &ss)
|
||
{
|
||
CString str(psz);
|
||
int idx1(0), idx2(0);
|
||
while (true)
|
||
{
|
||
idx1 = str.Find(_T("}{"), idx2);
|
||
idx2 = str.Find(_T("}{"), idx1 + 1);
|
||
if (idx1 == -1 || idx2 == -1) break;
|
||
|
||
ss.insert(str.Mid(idx1 + 2, idx2 - idx1 - 2));
|
||
}
|
||
}
|
||
|
||
bool IsHit(LPCTSTR psz, const std::set<CString> &sps)
|
||
{
|
||
std::set<CString>::const_iterator it(sps.begin());
|
||
for (; it != sps.end(); ++it)
|
||
{
|
||
const CString &sp(*it);
|
||
if (sp == psz)
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
|
||
int getIndexByFilter(LPCTSTR psz, LPCTSTR filter, const std::set<CString> &sps)
|
||
{
|
||
CString str(psz), sMid;
|
||
int idx1(0), idx2(0), idx(0);
|
||
while (true)
|
||
{
|
||
idx1 = str.Find(_T("{"), idx2);
|
||
idx2 = str.Find(_T("}"), idx1);
|
||
if (idx1 == -1 || idx2 == -1) break;
|
||
sMid = str.Mid(idx1 + 1, idx2 - idx1 - 1);
|
||
if (IsHit(sMid, sps))
|
||
continue;
|
||
if (sMid == filter)
|
||
break;
|
||
++idx;
|
||
}
|
||
return idx;
|
||
}
|
||
|
||
// 判断 psz 的 start 位置的字符在不在 sps 里面,如果在里面,说明start后面是一个分隔符
|
||
// end则是分隔符后的第一个字符位置
|
||
bool IsHit(LPCTSTR psz, const std::set<CString> &sps, const int &start, int &end)
|
||
{
|
||
std::set<CString>::const_iterator it(sps.begin());
|
||
CString strSrc(psz), sMid;
|
||
int spLen(0), srcLen(strSrc.GetLength());
|
||
for (; it != sps.end(); ++it)
|
||
{
|
||
const CString &sp(*it);
|
||
spLen = sp.GetLength();
|
||
if (spLen + start >= srcLen) continue;
|
||
sMid = strSrc.Mid(start, spLen);
|
||
if (sMid == sp) // 击中
|
||
{
|
||
end = start + spLen;
|
||
return true;
|
||
}
|
||
}
|
||
|
||
return false;
|
||
}
|
||
|
||
int SplitString(LPCTSTR psz, const std::set<CString> &sps, std::vector<CString> &strs)
|
||
{
|
||
CString str(psz);
|
||
int end(0), prev(0);
|
||
for (int i(0); i < str.GetLength(); ++i)
|
||
{
|
||
if (IsHit(psz, sps, i, end))
|
||
{
|
||
strs.push_back(str.Mid(prev, i - prev));
|
||
prev = end;
|
||
i = end;
|
||
continue;
|
||
}
|
||
}
|
||
|
||
strs.push_back(std::wstring(str).substr(end).c_str());
|
||
|
||
return (int)strs.size();
|
||
}
|
||
|
||
bool getHoleElev(LPCTSTR psz, double &dElev_mm, int &start, int &end)
|
||
{
|
||
std::wstring str(psz);
|
||
size_t idx(str.find(ELE_FLAG));
|
||
if (idx == -1)
|
||
return false;
|
||
|
||
start = idx + CString(ELE_FLAG).GetLength();
|
||
str = str.substr(start);
|
||
if (CoreTools::IsMeterUnitForHoleElevDim())
|
||
{
|
||
str = str.substr(0, str.size() - 1);
|
||
dElev_mm = TypeConvert::s2f(str.c_str());
|
||
dElev_mm *= 1000;
|
||
}
|
||
else
|
||
{
|
||
str = str.substr(0, str.size() - 2);
|
||
dElev_mm = TypeConvert::s2f(str.c_str());
|
||
}
|
||
end = start + str.size();
|
||
return true;
|
||
}
|
||
|
||
bool getPipeElev(LPCTSTR pszSrc, LPCTSTR pszTxt, double &dEle_mm, int &start, int &end)
|
||
{
|
||
CString sSrc(pszSrc), sElev;
|
||
std::set<CString> sps;
|
||
std::vector<CString> ss;
|
||
int idxElev(0);
|
||
if (sSrc.Find(ELE_FLAG) != -1)
|
||
{
|
||
collectSplite(sSrc, sps);
|
||
idxElev = getIndexByFilter(sSrc, ELE_FLAG, sps);
|
||
SplitString(pszTxt, sps, ss);
|
||
if (idxElev < ss.size())
|
||
sElev = ss[idxElev];
|
||
}
|
||
else
|
||
return false;
|
||
|
||
std::wstring wTxt(pszTxt);
|
||
start = wTxt.find(sElev);
|
||
|
||
std::wstring s(sElev);
|
||
size_t idx(s.find(_T("\\")));
|
||
if (idx != -1)
|
||
{
|
||
sElev = s.substr(idx + 7).c_str();
|
||
start += 7;
|
||
}
|
||
end = start + sElev.GetLength();
|
||
|
||
dEle_mm = TypeConvert::s2f(sElev);
|
||
|
||
if (CoreTools::IsMeterUnitForPipeElevDim())
|
||
dEle_mm *= 1000;
|
||
|
||
return true;
|
||
}
|
||
|
||
CString makeNewString(LPCTSTR psz
|
||
, const int &start
|
||
, const int &end
|
||
, const double &dElve_mm
|
||
, const bool bPipeElev)
|
||
{
|
||
std::wstring ws(psz);
|
||
std::wstring s1 = ws.substr(0, start);
|
||
std::wstring s2 = ws.substr(end);
|
||
|
||
bool bMeter(false);
|
||
int nPrec(0);
|
||
if (bPipeElev)
|
||
{
|
||
bMeter = CoreTools::IsMeterUnitForPipeElevDim();
|
||
nPrec = CoreTools::getPrecForPipeElevDim();
|
||
}
|
||
else
|
||
{
|
||
bMeter = CoreTools::IsMeterUnitForHoleElevDim();
|
||
nPrec = CoreTools::getPrecForHoleElevDim();
|
||
}
|
||
|
||
double d(dElve_mm);
|
||
if (bMeter)
|
||
d *= .001;
|
||
|
||
CString format(_T(""));
|
||
format.Format(_T("%s%%.%df%s"), s1.c_str(), nPrec, s2.c_str());
|
||
|
||
CString s;
|
||
s.Format(format, d);
|
||
|
||
return s;
|
||
}
|
||
}
|
||
|
||
bool AecDbEwPipeDim::GetElevation(double &dEle_mm)
|
||
{
|
||
if (!HasElevation()) return false;
|
||
|
||
CString sUp, sDw;
|
||
if (!m_arsUps.IsEmpty())
|
||
sUp = m_arsUps[0];
|
||
if (!m_arsDowns.IsEmpty())
|
||
sDw = m_arsDowns[0];
|
||
|
||
int start, end;
|
||
CString sElev;
|
||
|
||
if (isHoleElevDim(this))
|
||
{
|
||
if (sUp.Find(ELE_FLAG) != -1)
|
||
{
|
||
getHoleElev(sUp, dEle_mm, start, end);
|
||
}
|
||
|
||
if (sDw.Find(ELE_FLAG) != -1)
|
||
{
|
||
getHoleElev(sDw, dEle_mm, start, end);
|
||
}
|
||
}
|
||
else if (isPipeElevDim(this))
|
||
{
|
||
if (m_sUpScr.Find(ELE_FLAG) != -1)
|
||
{
|
||
getPipeElev(m_sUpScr, sUp, dEle_mm, start, end);
|
||
}
|
||
|
||
if (m_sDownScr.Find(ELE_FLAG) != -1)
|
||
{
|
||
getPipeElev(m_sDownScr, sDw, dEle_mm, start, end);
|
||
}
|
||
}
|
||
|
||
sElev.Format(_T("%.2f"), dEle_mm);
|
||
dEle_mm = TypeConvert::s2f(sElev);
|
||
|
||
return true;
|
||
}
|
||
|
||
bool AecDbEwPipeDim::HasElevation()
|
||
{
|
||
CString sUp, sDw;
|
||
if (!m_arsUps.IsEmpty())
|
||
sUp = m_arsUps[0];
|
||
if (!m_arsDowns.IsEmpty())
|
||
sDw = m_arsDowns[0];
|
||
|
||
if (m_sUpScr.Find(ELE_FLAG) != -1)
|
||
return true;
|
||
|
||
if (m_sDownScr.Find(ELE_FLAG) != -1)
|
||
return true;
|
||
|
||
if (sUp.Find(ELE_FLAG) != -1)
|
||
return true;
|
||
|
||
if (sDw.Find(ELE_FLAG) != -1)
|
||
return true;
|
||
|
||
return false;
|
||
}
|
||
|
||
void AecDbEwPipeDim::ModifyElevation(const double &dDelta_m)
|
||
{
|
||
AssertWriteEnabled();
|
||
|
||
CString sUp, sDw;
|
||
if (!m_arsUps.IsEmpty())
|
||
sUp = m_arsUps[0];
|
||
if (!m_arsDowns.IsEmpty())
|
||
sDw = m_arsDowns[0];
|
||
|
||
double dNew(dDelta_m * 1000), dOld;
|
||
int start, end;
|
||
if (isHoleElevDim(this))
|
||
{
|
||
if (sUp.Find(ELE_FLAG) != -1)
|
||
{
|
||
getHoleElev(sUp, dOld, start, end);
|
||
dNew += dOld;
|
||
sUp = makeNewString(sUp, start, end, dNew, false);
|
||
if (!m_arsUps.IsEmpty())
|
||
m_arsUps[0] = sUp;
|
||
}
|
||
|
||
if (sDw.Find(ELE_FLAG) != -1)
|
||
{
|
||
getHoleElev(sDw, dOld, start, end);
|
||
dNew += dOld;
|
||
sDw = makeNewString(sDw, start, end, dNew, false);
|
||
if (!m_arsDowns.IsEmpty())
|
||
m_arsDowns[0] = sDw;
|
||
}
|
||
}
|
||
else if (isPipeElevDim(this))
|
||
{
|
||
if (m_sUpScr.Find(ELE_FLAG) != -1)
|
||
{
|
||
getPipeElev(m_sUpScr, sUp, dOld, start, end);
|
||
dNew += dOld;
|
||
sUp = makeNewString(sUp, start, end, dNew, true);
|
||
if (!m_arsUps.IsEmpty())
|
||
m_arsUps[0] = sUp;
|
||
}
|
||
|
||
if (m_sDownScr.Find(ELE_FLAG) != -1)
|
||
{
|
||
getPipeElev(m_sDownScr, sDw, dOld, start, end);
|
||
dNew += dOld;
|
||
sDw = makeNewString(sDw, start, end, dNew, true);
|
||
if (!m_arsDowns.IsEmpty())
|
||
m_arsDowns[0] = sDw;
|
||
}
|
||
}
|
||
|
||
return;
|
||
}
|
||
|
||
int AecDbEwPipeDim::GetDraw2dables(Adesk::UInt16 nDrawStyle, AcDbVoidPtrArray &arEntPtrs) const
|
||
{
|
||
assertReadEnabled();
|
||
|
||
AcDbEntity *pEnt = NULL, *pEntT = NULL;
|
||
const AcDbVoidPtrArray &ar2D = Get2DBuffer();
|
||
for (int i = 0; i < ar2D.length(); i++)
|
||
{
|
||
pEnt = (AcDbEntity *)ar2D.at(i);
|
||
pEntT = (AcDbEntity *)pEnt->clone();
|
||
|
||
pEntT->setLayer(pEnt->layer());
|
||
|
||
arEntPtrs.append(pEntT);
|
||
}
|
||
return arEntPtrs.length();
|
||
}
|
||
|
||
void AecDbEwPipeDim::saveAs(AcGiWorldDraw *pWd, AcDb::SaveType saveType)
|
||
{
|
||
AcGiRegenType rtype = pWd->regenType();
|
||
if (rtype == kAcGiSaveWorldDrawForProxy)
|
||
{
|
||
drawProxyEntity(&Get2DBuffer(), pWd);
|
||
}
|
||
else
|
||
{
|
||
AcDbEntity::saveAs(pWd, saveType);
|
||
}
|
||
}
|
||
|
||
|
||
const AecDbObjXDataMap* AecDbEwPipeDim::GetSpecialtyData() const
|
||
{
|
||
assertReadEnabled();
|
||
return &m_mapSpecXData;
|
||
|
||
}
|
||
AecDbObjXDataMap* AecDbEwPipeDim::GetSpecialtyData(AcDb::OpenMode bMode)
|
||
{
|
||
if (bMode == AcDb::kForWrite)
|
||
{
|
||
if (!isWriteEnabled())
|
||
{
|
||
upgradeOpen();
|
||
}
|
||
assertWriteEnabled();
|
||
}
|
||
else
|
||
{
|
||
assertReadEnabled();
|
||
}
|
||
return &m_mapSpecXData;
|
||
}
|
||
|
||
bool AecDbEwPipeDim::SetCustomNoR(const double &v)
|
||
{
|
||
AssertWriteEnabled();
|
||
return m_mapSpecXData.SetAt(_Custom_No_R_, v) == 1 ? true : false;
|
||
}
|
||
|
||
double AecDbEwPipeDim::GetCustomNoR() const
|
||
{
|
||
assertReadEnabled();
|
||
double v;
|
||
m_mapSpecXData.GetAt(_Custom_No_R_, v);
|
||
return v;
|
||
}
|
||
|