284 lines
7.5 KiB
C++
284 lines
7.5 KiB
C++
#include "stdafx.h"
|
|
#include "dbproxy.h"
|
|
#include "layerDefine.h"
|
|
#include "TDbEquRelativeDim.h"
|
|
|
|
namespace
|
|
{
|
|
//读扩展数据
|
|
CString ReadXdata(Entity ent, const TCHAR*szName)
|
|
{
|
|
AcDbObjectId eId;
|
|
AcDbEntity *pEnt = NULL;
|
|
acdbGetObjectId(eId, ent);
|
|
acdbOpenObject(pEnt, eId, AcDb::kForRead);
|
|
if(!pEnt)
|
|
return _T("");
|
|
resbuf *pRb = pEnt->xData(szName);
|
|
|
|
CString csRet;
|
|
if (pRb != NULL) {
|
|
resbuf *pTemp = pRb;
|
|
if (pTemp->rbnext != NULL) {
|
|
pTemp = pTemp->rbnext;
|
|
if (pTemp->restype == 1000)
|
|
csRet = pTemp->resval.rstring;
|
|
}
|
|
}
|
|
ads_relrb(pRb);
|
|
pEnt->close();
|
|
return csRet;
|
|
}
|
|
}
|
|
|
|
//{{AFX_ARX_MACRO
|
|
ACRX_DXF_DEFINE_MEMBERS( TDbEquRelativeDim, TDbEntity,
|
|
AcDb::kDHL_CURRENT, AcDb::kMReleaseCurrent,
|
|
AcDbProxyEntity::kAllAllowedBits,
|
|
ATS_EQURELATIVEDIM, "图形无法解析, 请下载上华软件|网址: www.shanghuasoft.com");
|
|
//}}AFX_ARX_MACRO
|
|
|
|
IMPLEMENT_TENTBASE(TDbEquRelativeDim);
|
|
|
|
TDbEquRelativeDim::TDbEquRelativeDim(Entity& ent,int nColor)
|
|
{
|
|
m_ent = ent;
|
|
m_id.setNull();
|
|
m_ent.GetData(10,&m_ptIns);
|
|
m_nTextHeight = 3.0/10;
|
|
m_dTextRowDis = 1.2;
|
|
m_dLineBaseLen = 0.0;
|
|
m_idTextStyle = InitTextStyle(_T("_TEL_DIM"));
|
|
GetDimContent(m_sDimText);
|
|
if(nColor == 255)
|
|
m_nColor = GetLayerColor(InitLayer(LAY_CABLELAY_EQUIP));
|
|
else
|
|
m_nColor = nColor;
|
|
m_dLineBaseLen = GetTextLen(m_sDimText) / GetPScale();
|
|
m_ptTurn = m_ptIns - TSysCoordinateTool::GetCurrentViewWCSKYAxis() * 5*GetPScale();
|
|
}
|
|
|
|
TDbEquRelativeDim::TDbEquRelativeDim()
|
|
{
|
|
m_ent.Erase();
|
|
m_id.setNull();
|
|
m_nTextHeight = 3.0;
|
|
m_dTextRowDis = 1.2;
|
|
m_dLineBaseLen = 0.0;
|
|
m_idTextStyle = InitTextStyle(_T("_TEL_DIM"));
|
|
GetDimContent(m_sDimText);
|
|
m_nColor = GetLayerColor(InitLayer(LAY_CABLELAY_EQUIP));
|
|
m_dLineBaseLen = GetTextLen(m_sDimText) / GetPScale();
|
|
m_ptTurn = m_ptIns - TSysCoordinateTool::GetCurrentViewWCSKYAxis() * 5*GetPScale();
|
|
}
|
|
|
|
TDbEquRelativeDim::~TDbEquRelativeDim()
|
|
{
|
|
|
|
}
|
|
|
|
//得到字长
|
|
double TDbEquRelativeDim::GetTextLen(LPCTSTR lpText) const
|
|
{
|
|
double dTextLen = 0.0;
|
|
|
|
if (lpText == NULL)
|
|
return dTextLen;
|
|
|
|
CString sText = lpText;
|
|
if (sText.IsEmpty())
|
|
return dTextLen;
|
|
double dHeight = m_nTextHeight;
|
|
AcDbObjectId idStyle = m_idTextStyle;
|
|
|
|
CString sStyleName = GetSymbolName(idStyle);
|
|
struct resbuf* pRb = acutBuildList(RTDXF0, _T("TEXT"),
|
|
1, lpText,
|
|
7, sStyleName,
|
|
40, dHeight,
|
|
41, GetPScale(),
|
|
0);
|
|
|
|
ads_point adsPt1, adsPt2;
|
|
int iRet = acedTextBox(pRb, adsPt1, adsPt2);
|
|
acutRelRb(pRb);
|
|
|
|
dTextLen = asPnt3d(adsPt1).distanceTo(asPnt3d(adsPt2));
|
|
TDbText text;
|
|
text.setPropertiesFrom(this);
|
|
text.SetText((const TCHAR*)lpText);
|
|
AcDbObjectId id = m_idTextStyle;
|
|
text.SetStyleId(id);
|
|
text.SetLocation(m_ptIns);
|
|
text.SetHeight(m_nTextHeight);
|
|
XPoint pt = text.GetExtents();
|
|
dTextLen = asPnt3d(adsPt1).distanceTo(pt) + dHeight*GetPScale();
|
|
return dTextLen;
|
|
}
|
|
|
|
BOOL TDbEquRelativeDim::GetDimContent(CString& sDimText)
|
|
{
|
|
sDimText.Empty();
|
|
|
|
//读取设备的扩展数据值
|
|
CString sDI,sDO,sAI,sAO,sCOM,sPos;
|
|
sDI = ReadXdata(m_ent,_T("xdata_equip_di"));
|
|
sDO = ReadXdata(m_ent,_T("xdata_equip_do"));
|
|
sAI = ReadXdata(m_ent,_T("xdata_equip_ai"));
|
|
sAO = ReadXdata(m_ent,_T("xdata_equip_ao"));
|
|
sCOM = ReadXdata(m_ent,_T("xdata_equip_com"));
|
|
sPos = ReadXdata(m_ent,_T("xdata_equip_pos"));
|
|
|
|
if (!sDI.IsEmpty())
|
|
sDimText += _T("DI=") + sDI + _T(",");
|
|
if (!sDO.IsEmpty())
|
|
sDimText += _T("DO=") + sDO + _T(",");
|
|
if (!sAI.IsEmpty())
|
|
sDimText += _T("AI=") + sAI + _T(",");
|
|
if (!sAO.IsEmpty())
|
|
sDimText += _T("AO=") + sAO + _T(",");
|
|
if (!sCOM.IsEmpty())
|
|
sDimText += _T("COM=") + sCOM + _T(",");
|
|
if (!sPos.IsEmpty())
|
|
sDimText += _T("POS=") + sPos;
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
Acad::ErrorStatus TDbEquRelativeDim::ExplodeOrDraw2d(XExplodeDraw &dc) const
|
|
{
|
|
ExplodeOrDraw2dLine(dc);
|
|
ExplodeOrDraw2dText(dc);
|
|
|
|
return Acad::eOk;
|
|
}
|
|
|
|
//创建标注线
|
|
void TDbEquRelativeDim::ExplodeOrDraw2dLine(XExplodeDraw &dc) const
|
|
{
|
|
if (m_sDimText.IsEmpty()) return;
|
|
|
|
AcDbPolyline pline;
|
|
double dTextDistP = m_dTextRowDis;
|
|
pline.reset(Adesk::kFalse,0);
|
|
|
|
AcGePoint3d ptS,ptT,ptE,ptTmpE;
|
|
int nCount = 0;
|
|
double dTextLen = m_dLineBaseLen * GetPScale(),dHeight = m_nTextHeight;
|
|
|
|
AcGeVector3d vtDir = TSysCoordinateTool::GetCurrentViewWCSKXAxis();
|
|
vtDir.normalize();
|
|
|
|
ptE = m_ptTurn + vtDir*dTextLen;
|
|
|
|
pline.addVertexAt(0,m_ptIns.convert2d(AcGePlane::kXYPlane));
|
|
pline.addVertexAt(1,m_ptTurn.convert2d(AcGePlane::kXYPlane));
|
|
pline.addVertexAt(2,ptE.convert2d(AcGePlane::kXYPlane));
|
|
|
|
//构建方格
|
|
AcGeVector3d vtLableDir = vtDir;
|
|
vtLableDir.normalize();
|
|
|
|
if (m_ptTurn.y > m_ptIns.y)
|
|
{
|
|
if (vtDir.angleTo(TSysCoordinateTool::GetCurrentViewWCSKXAxis()) < PI/2)
|
|
vtLableDir.rotateBy(PI/2,TSysCoordinateTool::GetCurrentViewWCSKZAxis());
|
|
else
|
|
vtLableDir.rotateBy(-PI/2,TSysCoordinateTool::GetCurrentViewWCSKZAxis());
|
|
}
|
|
else
|
|
{
|
|
if (vtDir.angleTo(TSysCoordinateTool::GetCurrentViewWCSKXAxis()) < PI/2)
|
|
vtLableDir.rotateBy(-PI/2,TSysCoordinateTool::GetCurrentViewWCSKZAxis());
|
|
else
|
|
vtLableDir.rotateBy(PI/2,TSysCoordinateTool::GetCurrentViewWCSKZAxis());
|
|
}
|
|
|
|
ptE += dHeight*GetPScale()*(1 + 0.5)*vtLableDir*dTextDistP;
|
|
pline.addVertexAt(3,ptE.convert2d(AcGePlane::kXYPlane));
|
|
ptE = ptE - vtDir * dTextLen;
|
|
pline.addVertexAt(4,ptE.convert2d(AcGePlane::kXYPlane));
|
|
pline.addVertexAt(5,m_ptTurn.convert2d(AcGePlane::kXYPlane));
|
|
|
|
pline.setColorIndex(m_nColor);
|
|
//将画好的表格挪到对应的高度
|
|
AcGeMatrix3d xform;
|
|
AcGeVector3d vec(0, 0, m_ptIns.z);
|
|
xform.setToTranslation(vec);
|
|
pline.transformBy(xform);
|
|
|
|
dc.Polyline(pline);
|
|
}
|
|
|
|
//创建标注文字
|
|
void TDbEquRelativeDim::ExplodeOrDraw2dText(XExplodeDraw &dc) const
|
|
{
|
|
if (m_sDimText.IsEmpty()) return;
|
|
|
|
double dTextDistP = m_dTextRowDis;
|
|
AcDbText *pText = NULL;
|
|
CString sText;
|
|
AcGePoint3d ptTextT = m_ptTurn;
|
|
AcGeVector3d vtDir = TSysCoordinateTool::GetCurrentViewWCSKXAxis();
|
|
AcDbObjectId idStyle = m_idTextStyle;
|
|
|
|
double dTextLen = m_dLineBaseLen * GetPScale(),dHeight = m_nTextHeight;
|
|
|
|
if (vtDir.angleTo(TSysCoordinateTool::GetCurrentViewWCSKXAxis()) > PI/2)
|
|
ptTextT += (dTextLen - (dHeight / 2)*GetPScale())*vtDir;
|
|
else
|
|
ptTextT += vtDir*(dHeight / 2)*GetPScale();
|
|
|
|
AcGeVector3d vtLableDir = vtDir;
|
|
vtLableDir.normalize();
|
|
AcGePoint3d ptGe1 = m_ptTurn;
|
|
AcGePoint3d ptGe2 = m_ptIns;
|
|
//绘制方格
|
|
if (ptGe1.y > ptGe2.y)
|
|
{
|
|
if (vtDir.angleTo(TSysCoordinateTool::GetCurrentViewWCSKXAxis()) < PI/2)
|
|
vtLableDir.rotateBy(PI/2,TSysCoordinateTool::GetCurrentViewWCSKZAxis());
|
|
else
|
|
vtLableDir.rotateBy(-PI/2,TSysCoordinateTool::GetCurrentViewWCSKZAxis());
|
|
|
|
ptTextT.y += dHeight*GetPScale()*0.25;
|
|
}
|
|
else
|
|
{
|
|
if (vtDir.angleTo(TSysCoordinateTool::GetCurrentViewWCSKXAxis()) < PI/2)
|
|
vtLableDir.rotateBy(-PI/2,TSysCoordinateTool::GetCurrentViewWCSKZAxis());
|
|
else
|
|
vtLableDir.rotateBy(PI/2,TSysCoordinateTool::GetCurrentViewWCSKZAxis());
|
|
|
|
ptTextT.y += dHeight*GetPScale()*0.25;
|
|
ptTextT += dHeight*GetPScale()*(1 + 0.5)*vtLableDir*dTextDistP;
|
|
}
|
|
|
|
ptTextT.y += dHeight*GetPScale()*((1 + 0.5)*dTextDistP - 1) / 2 - dHeight*GetPScale()*0.25;
|
|
|
|
double dRotation = 0.0;
|
|
AcGeVector3d vtDirX = TSysCoordinateTool::GetCurrentViewWCSKXAxis();
|
|
AcGeVector3d vtVerT = TSysCoordinateTool::GetCurrentViewWCSKYAxis();
|
|
if (vtDir.angleTo(vtVerT) < PI/2)
|
|
dRotation = vtDir.angleTo(vtDirX);
|
|
else
|
|
dRotation = 2*PI - vtDir.angleTo(vtDirX);
|
|
if (vtDir.angleTo(vtDirX) > PI/2)
|
|
dRotation -= PI;
|
|
|
|
TDbText text;
|
|
text.setPropertiesFrom(this);
|
|
text.SetText((const TCHAR*)m_sDimText);
|
|
text.SetStyleId(idStyle);
|
|
text.SetLocation(ptTextT);
|
|
text.SetHeight(dHeight);
|
|
text.SetRotation(Ucs2Wcs(dRotation));
|
|
text.setColorIndex(m_nColor);
|
|
|
|
TPushProperty vProp1(&text, dc);
|
|
if(dc.IsFullExplode())
|
|
text.ExplodeOrDraw2d(dc);
|
|
else
|
|
dc.DrawEntity(text);
|
|
}
|