297 lines
7.1 KiB
C++
297 lines
7.1 KiB
C++
#include "StdAfx.h"
|
|
#include "StdArx.h"
|
|
#include "dbproxy.h"
|
|
#include "geassign.h"
|
|
#include "acgi.h"
|
|
|
|
#include "TDbECabletry.h"
|
|
#include "TEImpCabletry.h"
|
|
|
|
#define VERSION_TDBECABLETRY 1
|
|
|
|
//{{AFX_ARX_MACRO
|
|
ACRX_DXF_DEFINE_MEMBERS( TDbECabletry, TDbPipeBase,
|
|
AcDb::kDHL_CURRENT, AcDb::kMReleaseCurrent,
|
|
AcDbProxyEntity::kAllAllowedBits,
|
|
ATS_CABLETRY, "图形无法解析, 请下载上华软件|网址: www.shanghuasoft.com");
|
|
|
|
//}}AFX_ARX_MACRO
|
|
IMPLEMENT_TENTBASE(TDbECabletry);
|
|
|
|
namespace
|
|
{
|
|
// dc - 屏幕DC
|
|
// curve 多段线
|
|
// idx 打算要绘制的多段线中一部分曲线的索引
|
|
// clr 绘制色号
|
|
void DrawLineToScreenByComplexCurve(XScreenDc &dc, const TComplexCurve &curve, int idx, int clr)
|
|
{
|
|
TDb::TCurveElement el;
|
|
memset(&el, 0, sizeof(TDb::TCurveElement));
|
|
el = curve[idx];
|
|
XCurveSegment lCurve(el.ptGe[0], el.ptGe[1], 0);
|
|
lCurve.StartPoint() = Wcs2Ucs(lCurve.StartPoint());
|
|
lCurve.EndPoint() = Wcs2Ucs(lCurve.EndPoint());
|
|
dc.SetColor(clr);
|
|
dc << lCurve;
|
|
}
|
|
|
|
//add axc 2013-09-25增加支持弧形桥架起始点和终止点标高颜色设置
|
|
void DrawLineToScreenByComplexCurveForArc(XScreenDc &dc, const TComplexCurve &curve)
|
|
{
|
|
TDb::TCurveElement elStart,elEnd;
|
|
memset(&elStart, 0, sizeof(TDb::TCurveElement));
|
|
memset(&elEnd, 0, sizeof(TDb::TCurveElement));
|
|
elStart = curve[2];
|
|
elEnd = curve[0];
|
|
XCurveSegment lCurveStart(elStart.ptGe[0], elEnd.ptGe[2], 0);
|
|
lCurveStart.StartPoint() = Wcs2Ucs(lCurveStart.StartPoint());
|
|
lCurveStart.EndPoint() = Wcs2Ucs(lCurveStart.EndPoint());
|
|
dc.SetColor(3);
|
|
dc << lCurveStart;
|
|
|
|
XCurveSegment lCurveEnd(elEnd.ptGe[0], elStart.ptGe[2], 0);
|
|
lCurveEnd.StartPoint() = Wcs2Ucs(lCurveEnd.StartPoint());
|
|
lCurveEnd.EndPoint() = Wcs2Ucs(lCurveEnd.EndPoint());
|
|
dc.SetColor(1);
|
|
dc << lCurveEnd;
|
|
}
|
|
//axc 2013-11-22 解决桥架在无线连接时由于边数不为4而显示错误的问题,重新获得边数(4条)
|
|
void GetCurveElement(TDbXDataMap &XDataMap,TComplexCurve &cplCurve)
|
|
{
|
|
int nCover = 1;
|
|
double dW = 0.0;
|
|
double dH = 0.0;
|
|
AcGeVector3d vtNorm;
|
|
AcGePoint3d ptSta,ptEnd,ptGeT;
|
|
|
|
XDataMap.GetAt(KEY_B,dW);
|
|
XDataMap.GetAt(KEY_H,dH);
|
|
XDataMap.GetAt(KEY_NORMAL,vtNorm);
|
|
XDataMap.GetAt(KEY_START,ptSta);
|
|
XDataMap.GetAt(KEY_END,ptEnd);
|
|
XDataMap.GetAt(KEY_COVER,nCover);
|
|
vtNorm.normalize();
|
|
AcGePoint3d ptGe[5];
|
|
AcGeVector3d vtLine = ptEnd - ptSta;
|
|
AcGeVector3d vtVer = vtLine;
|
|
vtVer.rotateBy(PI / 2.0,vtNorm);
|
|
vtVer.normalize();
|
|
|
|
TDb::TCurveElement el;
|
|
memset(&el,0,sizeof(TDb::TCurveElement));
|
|
AcGeLine3d line3d(AcGePoint3d::kOrigin,AcGePoint3d::kOrigin + 5.0 * vtNorm);
|
|
|
|
if(AcGePlane::kXYPlane.isParallelTo(line3d))
|
|
{
|
|
vtVer = vtNorm;
|
|
|
|
vtVer.normalize();
|
|
AcGeVector3d vt01 = vtVer;
|
|
vt01.rotateBy(PI / 2.0,AcGeVector3d::kZAxis);
|
|
|
|
ptGe[0] = ptEnd + dW / 2.0 * vt01;
|
|
ptGe[1] = ptEnd - dW / 2.0 * vt01;
|
|
ptGe[3] = ptGe[0] + dH * vtVer;
|
|
ptGe[2] = ptGe[1] + dH * vtVer;
|
|
ptGe[4] = ptGe[0];
|
|
}
|
|
else
|
|
{
|
|
ptGe[0] = ptEnd + dW / 2.0 * vtVer;
|
|
ptGe[1] = ptEnd - dW / 2.0 * vtVer;
|
|
ptGe[3] = ptSta + dW / 2.0 * vtVer;
|
|
ptGe[2] = ptSta - dW / 2.0 * vtVer;
|
|
ptGe[4] = ptGe[0];
|
|
}
|
|
if(!vtNorm.isParallelTo(AcGeVector3d::kZAxis))
|
|
{
|
|
//for (int i = 0; i <= 1; ++i)
|
|
for (int i = 0; i <= 2; ++i)//modify by axc 2013.7.29修改边的循环索引值为2
|
|
{
|
|
el.ptGe[0] = ptGe[i];
|
|
el.ptGe[1] = ptGe[i+1];
|
|
el.ptGe[2] = ptGe[i+1];
|
|
cplCurve.append(el);
|
|
}
|
|
//el.ptGe[0] = ptGe[0];
|
|
el.ptGe[0] = ptGe[0];
|
|
el.ptGe[1] = ptGe[3];
|
|
el.ptGe[2] = ptGe[3];
|
|
cplCurve.append(el);
|
|
|
|
if (nCover)
|
|
{
|
|
el.ptGe[0] = ptGe[2];
|
|
el.ptGe[1] = ptGe[3];
|
|
el.ptGe[2] = ptGe[3];
|
|
cplCurve.append(el);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
for (int i = 0; i <= 3; ++i)
|
|
{
|
|
el.ptGe[0] = ptGe[i];
|
|
el.ptGe[1] = ptGe[i+1];
|
|
el.ptGe[2] = ptGe[i+1];
|
|
cplCurve.append(el);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
TDbECabletry::TDbECabletry()
|
|
{
|
|
//{{AFX_ARX_DATA_INIT(TDbECabletry)
|
|
//}}AFX_ARX_DATA_INIT
|
|
m_XDataMap.SetAt(KEY_DXF,_T("ATS_CABLETRY"));
|
|
m_pImpPipeBase = new TEImpCabletry(this);
|
|
}
|
|
|
|
TDbECabletry::~TDbECabletry()
|
|
{
|
|
if (m_pImpPipeBase != NULL)
|
|
{
|
|
delete m_pImpPipeBase;
|
|
}
|
|
}
|
|
|
|
Acad::ErrorStatus TDbECabletry::dxfOutFields(AcDbDxfFiler* pFiler) const
|
|
{
|
|
assertReadEnabled();
|
|
Acad::ErrorStatus es;
|
|
|
|
if ((es = TDbPipeBase::dxfOutFields(pFiler)) != Acad::eOk)
|
|
return es;
|
|
|
|
// Write subclass marker.
|
|
pFiler->writeItem(AcDb::kDxfSubclass, _T("TDbECabletry"));
|
|
|
|
// Write version number.
|
|
pFiler->writeItem(AcDb::kDxfInt16, (Adesk::UInt16) VERSION_TDBECABLETRY);
|
|
return es;
|
|
}
|
|
|
|
Acad::ErrorStatus TDbECabletry::dxfInFields(AcDbDxfFiler* pFiler)
|
|
{
|
|
assertWriteEnabled();
|
|
struct resbuf rb;
|
|
|
|
if ((TDbPipeBase::dxfInFields(pFiler) != Acad::eOk) ||
|
|
!pFiler->atSubclassData(_T("TDbECabletry")))
|
|
return pFiler->filerStatus();
|
|
|
|
// Read version number.
|
|
pFiler->readItem(&rb);
|
|
if (rb.restype != AcDb::kDxfInt16)
|
|
{
|
|
pFiler->pushBackItem();
|
|
pFiler->setError(Acad::eInvalidDxfCode,
|
|
_T("Error: expected object version group code %d"),
|
|
AcDb::kDxfInt16);
|
|
return pFiler->filerStatus();
|
|
}
|
|
else
|
|
{
|
|
Adesk::UInt16 version = rb.resval.rint;
|
|
if (version > VERSION_TDBECABLETRY)
|
|
return Acad::eMakeMeProxy;
|
|
}
|
|
return pFiler->filerStatus();
|
|
}
|
|
|
|
Acad::ErrorStatus TDbECabletry::dwgOutFields(AcDbDwgFiler* pFiler) const
|
|
{
|
|
assertReadEnabled();
|
|
Acad::ErrorStatus es;
|
|
|
|
// Call dwgOutFields from TDbInterfacesObj
|
|
if ((es = TDbPipeBase::dwgOutFields(pFiler)) != Acad::eOk)
|
|
{
|
|
return es;
|
|
}
|
|
|
|
// Write version number.
|
|
pFiler->writeItem((Adesk::UInt16) VERSION_TDBECABLETRY);
|
|
|
|
return pFiler->filerStatus();
|
|
}
|
|
|
|
Acad::ErrorStatus TDbECabletry::dwgInFields(AcDbDwgFiler* pFiler)
|
|
{
|
|
assertWriteEnabled();
|
|
Acad::ErrorStatus es;
|
|
|
|
// Call dwgInFields from TDbInterfacesObj
|
|
if ((es = TDbPipeBase::dwgInFields(pFiler)) != Acad::eOk)
|
|
{
|
|
return es;
|
|
}
|
|
|
|
// Read version number.
|
|
Adesk::UInt16 version;
|
|
pFiler->readItem(&version);
|
|
if (version > VERSION_TDBECABLETRY)
|
|
return Acad::eMakeMeProxy;
|
|
|
|
switch (version)
|
|
{
|
|
case (1):
|
|
{
|
|
break;
|
|
}
|
|
default:
|
|
break;
|
|
}
|
|
return pFiler->filerStatus();
|
|
}
|
|
|
|
Acad::ErrorStatus TDbECabletry::subGetTransformedCopy( const AcGeMatrix3d& xform,AcDbEntity*& pEnt) const
|
|
{
|
|
assertReadEnabled();
|
|
|
|
pEnt = new TDbECabletry;
|
|
(TDbECabletry*)pEnt->copyFrom(this);
|
|
pEnt->transformBy(xform);
|
|
|
|
return Acad::eOk;
|
|
}
|
|
|
|
void TDbECabletry::SetCabletryColor()
|
|
{
|
|
TComplexCurve cplCurve;
|
|
cplCurve.setLogicalLength(0);
|
|
XScreenDc dc(1);
|
|
//add axc 2013-09-25增加支持弧形桥架
|
|
int nCable = -1;
|
|
m_XDataMap.GetAt(KEY_CABLE,nCable);
|
|
if (nCable == eArcCabletray)
|
|
{
|
|
MakeCurves(cplCurve);
|
|
DrawLineToScreenByComplexCurveForArc(dc,cplCurve);
|
|
}
|
|
else
|
|
{
|
|
GetCurveElement(m_XDataMap,cplCurve);
|
|
DrawLineToScreenByComplexCurve(dc, cplCurve, 0, 3); // 第一段线,为终点,绿色
|
|
DrawLineToScreenByComplexCurve(dc, cplCurve, 2, 1); // 第二段线,为起点,红色
|
|
}
|
|
acedUpdateDisplay();
|
|
}
|
|
|
|
void TDbECabletry::GetClapDirByPt(const AcGePoint3d& pt,AcGeVector3d& vtDir)
|
|
{
|
|
if (m_pImpPipeBase)
|
|
{
|
|
//axc modify 2014-10-15 16平台弧形弯通不显示隔板,原因是因为16平台无dynamic_cast函数
|
|
TEImpCabletry* pCab = (TEImpCabletry*)(m_pImpPipeBase);
|
|
//TEImpCabletry* pCab = dynamic_cast<TEImpCabletry*>(m_pImpPipeBase);
|
|
if (pCab)
|
|
{
|
|
pCab->GetClapDirByPt(pt,vtDir);
|
|
}
|
|
}
|
|
|
|
}
|