1175 lines
52 KiB
C++
1175 lines
52 KiB
C++
#include "stdafx.h"
|
|
#include "AecDbHanger.h"
|
|
#include "MFCDbDwgFiler.h"
|
|
#include "AecDbEwPipe.h"
|
|
#include "dbgrip.h"
|
|
#include "AecGripCback.h"
|
|
#include "AcGiViewDraw.h"
|
|
#include "ImpMD5.h"
|
|
|
|
extern AcDbPolyline* FormatPolyline(AcGePoint3d* ppPts,int nCount);
|
|
extern AcGePoint3d MidPoint(const AcGePoint3d& pt1,const AcGePoint3d& pt2);
|
|
extern BOOL DLLIMPEXP GetDimGripOff();
|
|
extern void DLLIMPEXP OrthoProjected3DSolid(AcDb3dSolid* pSolidClone,const AcGePlane& plan,AcGeMatrix3d& xformPlanToWorld,AcDbVoidPtrArray& arEntPtrs);
|
|
|
|
Adesk::UInt32 AecDbHanger::kCurrentVersionNumber = 1;
|
|
static const Adesk::UInt16 kColorByBlock = 0;
|
|
static const Adesk::UInt16 kRed = 1;
|
|
static const Adesk::UInt16 kYellow = 2;
|
|
static const Adesk::UInt16 kGreen = 3;
|
|
static const Adesk::UInt16 kCyan = 4;
|
|
static const Adesk::UInt16 kBlue = 5;
|
|
static const Adesk::UInt16 kMagenta = 6;
|
|
static const Adesk::UInt16 kWhite = 7;
|
|
static const Adesk::UInt16 kColorByLayer = 256;
|
|
|
|
ACRX_DXF_DEFINE_MEMBERS (AecDbHanger, AecDbEntityBase,
|
|
AcDb::kDHL_CURRENT, AcDb::kMReleaseCurrent,
|
|
AcDbProxyEntity::kNoOperation | AcDbProxyEntity::kDisableProxyWarning,
|
|
AEC_DBHANGER,
|
|
"AecDbHanger"
|
|
"|Product Desc: shanghua earthworm app obj"
|
|
"|Company: shanghua inc"
|
|
"|WEB Address: www.shanghuasoft.com")
|
|
|
|
|
|
AecDbHanger::AecDbHanger(void)
|
|
{
|
|
m_pGripAppData = new AecGripData[GRIP_MAXNUM];
|
|
m_mapSpecXData.SetAt(KEY_NAME,_T("吊架"));
|
|
}
|
|
|
|
AecDbHanger::~AecDbHanger(void)
|
|
{
|
|
delete [] m_pGripAppData;
|
|
deleteContainerOfStd(m_solids);
|
|
deleteContainerOfStd(m_pipes);
|
|
}
|
|
|
|
Acad::ErrorStatus AecDbHanger::SetPosition(const AcGePoint3d& ptPos,const AcGeVector3d& vtL)
|
|
{
|
|
AssertWriteEnabled();
|
|
m_mapSpecXData.SetAt(KEY_POS,ptPos);
|
|
m_mapSpecXData.SetAt(PIPE_DIR,vtL);
|
|
return Acad::eOk;
|
|
}
|
|
|
|
AcGePoint3d AecDbHanger::GetPosition(AcGeVector3d& vtL) const
|
|
{
|
|
assertReadEnabled();
|
|
|
|
AcGePoint3d pt;
|
|
m_mapSpecXData.GetAt(KEY_POS,pt);
|
|
m_mapSpecXData.GetAt(PIPE_DIR,vtL);
|
|
return pt;
|
|
}
|
|
|
|
void AecDbHanger::SetHanger(const XHanger& data)
|
|
{
|
|
AssertWriteEnabled();
|
|
|
|
/*
|
|
// 吊杆数 1,2,3...
|
|
int nHs;
|
|
|
|
// 行数
|
|
int N;
|
|
|
|
// 吊杆直径
|
|
double dD;
|
|
|
|
// 是否角钢吊杆
|
|
bool bdDAsW;
|
|
|
|
// 行间距(m)
|
|
double V;
|
|
|
|
// 支架臂长度(mm)
|
|
double L;
|
|
|
|
// 角钢宽度(mm)
|
|
double W;
|
|
|
|
// 角钢厚度(mm)
|
|
double t;
|
|
|
|
// 材质
|
|
TCHAR szMat[33];
|
|
|
|
// 用途
|
|
TCHAR szUsage[33];
|
|
*/
|
|
m_mapSpecXData.SetAt(KEY_NHS,data.nHs);
|
|
m_mapSpecXData.SetAt(KEY_N,data.N);
|
|
m_mapSpecXData.SetAt(KEY_DD,data.dD);
|
|
m_mapSpecXData.SetAt(KEY_DASW,data.bdDAsW);
|
|
m_mapSpecXData.SetAt(KEY_V,data.V);
|
|
m_mapSpecXData.SetAt(KEY_L,data.L);
|
|
m_mapSpecXData.SetAt(KEY_W,data.W);
|
|
m_mapSpecXData.SetAt(KEY_T,data.t);
|
|
m_mapSpecXData.SetAt(KEY_MATERIAL,data.szMat);
|
|
m_mapSpecXData.SetAt(KEY_PURPOSE,data.szUsage);
|
|
}
|
|
|
|
bool AecDbHanger::GetASteelLength(ASteel& aSteel) const
|
|
{
|
|
assertReadEnabled();
|
|
|
|
XHanger hanger;
|
|
GetHanger(hanger);
|
|
|
|
memset(&aSteel, 0,sizeof(ASteel));
|
|
if (hanger.bdDAsW)
|
|
{
|
|
aSteel.W = hanger.W;
|
|
aSteel.t = hanger.t;
|
|
aSteel.L = hanger.L * hanger.N;
|
|
aSteel.L += hanger.N * hanger.V * 2;
|
|
_tcscpy(aSteel.szMat, hanger.szMat);
|
|
}
|
|
else
|
|
{
|
|
aSteel.W = hanger.W;
|
|
aSteel.t = hanger.t;
|
|
aSteel.L = hanger.L * hanger.N;
|
|
_tcscpy(aSteel.szMat, hanger.szMat);
|
|
|
|
aSteel.L2 = hanger.N * hanger.V * 2;
|
|
aSteel.D = hanger.dD;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
bool AecDbHanger::GetHanger(XHanger& data) const
|
|
{
|
|
assertReadEnabled();
|
|
|
|
BOOL bHasData = m_mapSpecXData.GetAt(KEY_NHS,data.nHs);
|
|
m_mapSpecXData.GetAt(KEY_N,data.N);
|
|
m_mapSpecXData.GetAt(KEY_DD,data.dD);
|
|
m_mapSpecXData.GetAt(KEY_DASW,data.bdDAsW);
|
|
m_mapSpecXData.GetAt(KEY_V,data.V);
|
|
m_mapSpecXData.GetAt(KEY_L,data.L);
|
|
m_mapSpecXData.GetAt(KEY_W,data.W);
|
|
m_mapSpecXData.GetAt(KEY_T,data.t);
|
|
|
|
CString sTemp;
|
|
m_mapSpecXData.GetAt(KEY_MATERIAL,sTemp);
|
|
_tcscpy(data.szMat,(LPCTSTR)sTemp);
|
|
|
|
m_mapSpecXData.GetAt(KEY_PURPOSE,sTemp);
|
|
_tcscpy(data.szUsage,(LPCTSTR)sTemp);
|
|
|
|
return bHasData ? true : false;
|
|
}
|
|
|
|
Acad::ErrorStatus AecDbHanger::dwgInFields(AcDbDwgFiler* pFiler)
|
|
{
|
|
AssertWriteEnabled();
|
|
|
|
//----- Read parent class information first.
|
|
Acad::ErrorStatus es = Acad::eOk;
|
|
if ( !pFiler->isKindOf(CMFCDbDwgFiler::desc()))
|
|
{
|
|
es = AecDbEntityBase::dwgInFields (pFiler) ;
|
|
if ( es != Acad::eOk )
|
|
return (es) ;
|
|
}
|
|
|
|
//----- Object version number needs to be read first
|
|
Adesk::UInt32 version =0 ;
|
|
if ( (es = pFiler->readUInt32 (&version)) != Acad::eOk )
|
|
return (es) ;
|
|
|
|
if ( version > AecDbHanger::kCurrentVersionNumber )
|
|
return (Acad::eMakeMeProxy);
|
|
|
|
m_mapSpecXData.dwgInFields(pFiler);
|
|
|
|
return Acad::eOk;
|
|
}
|
|
|
|
Acad::ErrorStatus AecDbHanger::dwgOutFields(AcDbDwgFiler* pFiler) const
|
|
{
|
|
assertReadEnabled();
|
|
|
|
//----- Save parent class information first.
|
|
Acad::ErrorStatus es = Acad::eOk;
|
|
if ( !pFiler->isKindOf(CMFCDbDwgFiler::desc()))
|
|
{
|
|
es = AecDbEntityBase::dwgOutFields (pFiler) ;
|
|
if ( es != Acad::eOk )
|
|
return (es) ;
|
|
}
|
|
|
|
//----- Object version number needs to be saved first
|
|
if ( (es =pFiler->writeUInt32 (AecDbHanger::kCurrentVersionNumber)) != Acad::eOk )
|
|
return (es) ;
|
|
|
|
m_mapSpecXData.dwgOutFields(pFiler);
|
|
|
|
return Acad::eOk;
|
|
}
|
|
|
|
Acad::ErrorStatus AecDbHanger::dxfInFields(AcDbDxfFiler* pFiler)
|
|
{
|
|
return Acad::eOk;
|
|
}
|
|
|
|
Acad::ErrorStatus AecDbHanger::dxfOutFields(AcDbDxfFiler* pFiler) const
|
|
{
|
|
return Acad::eOk;
|
|
}
|
|
|
|
Acad::ErrorStatus AecDbHanger::subExplode(AcDbVoidPtrArray& entitySet) const
|
|
{
|
|
return Acad::eOk;
|
|
}
|
|
|
|
void AecDbHanger::subList() const
|
|
{
|
|
assertReadEnabled();
|
|
AecDbEntityBase::subList();
|
|
|
|
acutPrintf(_T("\n属性数据:"));
|
|
m_mapSpecXData.List();
|
|
acutPrintf(_T("\n"));
|
|
}
|
|
|
|
bool AecDbHanger::GetBimInfoTip(CString& sInfoTip) const
|
|
{
|
|
assertReadEnabled();
|
|
|
|
XHanger data;
|
|
memset(&data,0,sizeof(XHanger));
|
|
GetHanger(data);
|
|
|
|
CString sField,sFmt;
|
|
sField = _T("吊架:\n");
|
|
sInfoTip += sField;
|
|
|
|
MAKEFIELD(_T("支架臂长度"),_T("%d"),(int)(data.L+0.5),sInfoTip);
|
|
|
|
MAKEFIELD(_T("行数"),_T("%d"),data.N,sInfoTip);
|
|
MAKEFIELD(_T("行间距"),_T("%.1f"),data.V,sInfoTip);
|
|
|
|
AcGePoint3d pt;
|
|
m_mapSpecXData.GetAt(KEY_POS,pt);
|
|
MAKEFIELD(_T("顶部标高"),_T("%.1f"),pt.z,sInfoTip);
|
|
|
|
MAKEFIELD(_T("角钢宽度"),_T("%.1f"),data.W,sInfoTip);
|
|
MAKEFIELD(_T("角钢厚度"),_T("%.1f"),data.t,sInfoTip);
|
|
|
|
MAKEFIELD(_T("材质"),_T("%s"),data.szMat,sInfoTip);
|
|
MAKEFIELD(_T("用途"),_T("%s"),data.szUsage,sInfoTip);
|
|
|
|
return true;
|
|
}
|
|
|
|
Acad::ErrorStatus AecDbHanger::copyFrom(const AcRxObject* pSrc)
|
|
{
|
|
AssertWriteEnabled();
|
|
|
|
AecDbHanger* pFit = AecDbHanger::cast(pSrc);
|
|
if (pFit != NULL)
|
|
{
|
|
m_mapSpecXData.Empty();
|
|
m_mapSpecXData.CopyFrom(&pFit->m_mapSpecXData);
|
|
}
|
|
return Acad::eOk;
|
|
}
|
|
|
|
Acad::ErrorStatus AecDbHanger::subTransformBy(const AcGeMatrix3d& xform)
|
|
{
|
|
AssertWriteEnabled();
|
|
|
|
AcGePoint3d pt;
|
|
AcGeVector3d vtL;
|
|
|
|
m_mapSpecXData.GetAt(KEY_POS,pt);
|
|
m_mapSpecXData.GetAt(PIPE_DIR,vtL);
|
|
|
|
pt.transformBy(xform);
|
|
vtL.transformBy(xform);
|
|
|
|
m_mapSpecXData.SetAt(KEY_POS,pt);
|
|
m_mapSpecXData.SetAt(PIPE_DIR,vtL);
|
|
|
|
return Acad::eOk;
|
|
}
|
|
|
|
#if ARX>16
|
|
Acad::ErrorStatus AecDbHanger::subGetGripPoints(AcDbGripDataPtrArray& grips,
|
|
const double curViewUnitSize,
|
|
const int gripSize,
|
|
const AcGeVector3d& curViewDir,
|
|
const int bitflags) const
|
|
{
|
|
|
|
assertReadEnabled();
|
|
|
|
AcGePoint3d pt;
|
|
AcGeVector3d vtL;
|
|
m_mapSpecXData.GetAt(KEY_POS,pt);
|
|
m_mapSpecXData.GetAt(PIPE_DIR,vtL);
|
|
|
|
XHanger holder;
|
|
GetHanger(holder);
|
|
|
|
vtL.normalize();
|
|
vtL *= holder.L;
|
|
|
|
pt += 0.5 * vtL;
|
|
AcGePoint3d pt2 = pt - vtL;
|
|
|
|
AcDbGripData* pGripData = NULL;
|
|
|
|
int i = 0;
|
|
pGripData = new AcDbGripData;
|
|
memset(&m_pGripAppData[i],0,sizeof(AecGripData));
|
|
m_pGripAppData[i].nIndex = i;
|
|
m_pGripAppData[i].ePos = eStart;
|
|
m_pGripAppData[i].ptGrip = pt;
|
|
m_pGripAppData[i].nColor = kBlue;
|
|
_tcscpy(m_pGripAppData[i].szTip,_T("位置夹点"));
|
|
m_pGripAppData[i].pOwner = (AcDbEntity*)this;
|
|
m_pGripAppData[i].idHost = objectId();
|
|
|
|
pGripData->setGripPoint(pt);
|
|
pGripData->setAppData((void*)&m_pGripAppData[i]);
|
|
pGripData->setWorldDraw(AecGripCback::WorldDrawfunc);
|
|
pGripData->setToolTipFunc(AecGripCback::GripToolTipFunc);
|
|
grips.append(pGripData);
|
|
|
|
if (!vtL.isZeroLength())
|
|
{
|
|
i = 1;
|
|
pGripData = new AcDbGripData;
|
|
memset(&m_pGripAppData[i],0,sizeof(AecGripData));
|
|
m_pGripAppData[i].nIndex = i;
|
|
m_pGripAppData[i].nColor = kBlue;
|
|
m_pGripAppData[i].ePos = eEnd;
|
|
m_pGripAppData[i].ptGrip = pt2;
|
|
_tcscpy(m_pGripAppData[i].szTip,_T("方位夹点"));
|
|
m_pGripAppData[i].pOwner = (AcDbEntity*)this;
|
|
m_pGripAppData[i].idHost = objectId();
|
|
|
|
pGripData->setGripPoint(pt2);
|
|
pGripData->setAppData((void*)&m_pGripAppData[i]);
|
|
pGripData->setWorldDraw(AecGripCback::WorldDrawfunc);
|
|
pGripData->setToolTipFunc(AecGripCback::GripToolTipFunc);
|
|
grips.append(pGripData);
|
|
}
|
|
|
|
//动态标注
|
|
//直线,半径 标注风格
|
|
if (!grips.isEmpty())
|
|
{
|
|
SubAddDimPoints(grips,curViewDir);
|
|
}
|
|
return Acad::eOk;
|
|
}
|
|
|
|
Acad::ErrorStatus AecDbHanger::subGetStretchPoints(AcGePoint3dArray& stretchPoints) const
|
|
{
|
|
assertReadEnabled();
|
|
|
|
AcGePoint3d pt;
|
|
AcGeVector3d vtL;
|
|
m_mapSpecXData.GetAt(KEY_POS,pt);
|
|
m_mapSpecXData.GetAt(PIPE_DIR,vtL);
|
|
|
|
XHanger holder;
|
|
GetHanger(holder);
|
|
|
|
vtL.normalize();
|
|
if(!vtL.isZeroLength())
|
|
{
|
|
vtL *= holder.L;
|
|
AcGePoint3d pt2 = pt + vtL;
|
|
stretchPoints.append(pt);
|
|
stretchPoints.append(pt2);
|
|
}
|
|
else
|
|
{
|
|
stretchPoints.append(pt);
|
|
}
|
|
return Acad::eOk;
|
|
}
|
|
|
|
Acad::ErrorStatus AecDbHanger::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;
|
|
}
|
|
|
|
AcGePoint3d pt;
|
|
AcGeVector3d vtL;
|
|
m_mapSpecXData.GetAt(KEY_POS,pt);
|
|
m_mapSpecXData.GetAt(PIPE_DIR,vtL);
|
|
|
|
int nGripIndex = arIndex.first();
|
|
if (nGripIndex == 0)
|
|
{
|
|
pt += offset;
|
|
m_mapSpecXData.SetAt(KEY_POS,pt);
|
|
return Acad::eOk;
|
|
}
|
|
|
|
if (nGripIndex == 1)
|
|
{
|
|
XHanger holder;
|
|
GetHanger(holder);
|
|
|
|
vtL.normalize();
|
|
vtL *= holder.L;
|
|
|
|
AcGePoint3d pt2 = pt + vtL;
|
|
|
|
pt2 -= offset;//反向
|
|
|
|
double dL = pt2.distanceTo(pt);
|
|
if (dL > 10.0)
|
|
{
|
|
vtL = pt2 - pt;
|
|
vtL.normalize();
|
|
m_mapSpecXData.SetAt(KEY_L,dL);
|
|
m_mapSpecXData.SetAt(PIPE_DIR,vtL);
|
|
}
|
|
}
|
|
return Acad::eOk;
|
|
}
|
|
|
|
Acad::ErrorStatus AecDbHanger::SubAddDimPoints(AcDbGripDataPtrArray& grips,const AcGeVector3d& curViewDir) const
|
|
{
|
|
if (GetDimGripOff())
|
|
return Acad::eOk;
|
|
|
|
AcGePoint3d pt,pt2;
|
|
AcGeVector3d vtL;
|
|
m_mapSpecXData.GetAt(KEY_POS,pt);
|
|
m_mapSpecXData.GetAt(PIPE_DIR,vtL);
|
|
|
|
XHanger holder;
|
|
GetHanger(holder);
|
|
|
|
vtL.normalize();
|
|
pt += 0.5 * vtL * holder.L;
|
|
pt2 = pt - vtL * holder.L;
|
|
|
|
AcGeVector3d vtDirX;
|
|
AcGePoint3d ptGe[3],ptMid;
|
|
ptGe[0] = pt;ptGe[0].z += 100.0;
|
|
ptGe[1] = pt2;ptGe[1].z += 100.0;
|
|
|
|
vtDirX = vtL;
|
|
vtDirX.rotateBy(PI / 2.0,AcGeVector3d::kZAxis);
|
|
vtDirX.normalize();
|
|
ptMid = MidPoint(ptGe[0],ptGe[1]);
|
|
vtDirX.normalize();
|
|
ptMid += vtDirX * 10.0 * 100.0;//标注文字位置
|
|
AddDimPoints(grips,curViewDir,ptGe[0],ptGe[1],ptMid,0);
|
|
|
|
ptGe[0] = pt;
|
|
ptGe[1] = pt;
|
|
ptGe[1].z -= holder.N * holder.V;
|
|
ptGe[0] -= vtL * 10.0;
|
|
ptGe[1] -= vtL * 10.0;
|
|
|
|
ptMid = MidPoint(ptGe[0],ptGe[1]);
|
|
vtDirX.normalize();
|
|
ptMid -= vtL * 10.0 * 100.0;//标注文字位置
|
|
AddDimPoints(grips,curViewDir,ptGe[0],ptGe[1],ptMid,0);
|
|
|
|
return Acad::eOk;
|
|
}
|
|
|
|
Acad::ErrorStatus AecDbHanger::AddDimPoints(AcDbGripDataPtrArray& grips,const AcGeVector3d& curViewDir,
|
|
const AcGePoint3d& ptSta,const AcGePoint3d& ptEnd,
|
|
const AcGePoint3d& ptMid,int nDimType,double dVal/* = -1.0*/,double dt) const
|
|
{
|
|
int i = grips.length();
|
|
EPosition ePos = eDim0;
|
|
memset(&m_pGripAppData[i],0,sizeof(AecGripData));
|
|
m_pGripAppData[i].nIndex = i;
|
|
m_pGripAppData[i].ePos = ePos;
|
|
m_pGripAppData[i].nColor = kGreen;
|
|
m_pGripAppData[i].ptGrip = ptMid;
|
|
m_pGripAppData[i].ptDim[0] = ptSta;
|
|
m_pGripAppData[i].ptDim[1] = ptEnd;
|
|
m_pGripAppData[i].nDimType = nDimType;
|
|
|
|
if (dVal > 1.e-3)
|
|
{
|
|
if (nDimType == 1)
|
|
{
|
|
_stprintf(m_pGripAppData[i].szTip,_T("R%.1f"),dVal);
|
|
}
|
|
else if (nDimType == 2)//@100 标注
|
|
{
|
|
_stprintf(m_pGripAppData[i].szTip,_T("Ø%.1f"),dVal);
|
|
}
|
|
else if (nDimType == 3)//角度标注
|
|
{
|
|
_stprintf(m_pGripAppData[i].szTip,_T("%.1f°"),dVal);
|
|
}
|
|
else if (nDimType == 4)//@107x3.5
|
|
{
|
|
_stprintf(m_pGripAppData[i].szTip,_T("Ø%.1fx%.1f"),dVal,dt);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
_tcscpy(m_pGripAppData[i].szTip,_T(" "));
|
|
}
|
|
_tcscpy(m_pGripAppData[i].szID,_T(" "));
|
|
m_pGripAppData[i].pOwner = (AcDbEntity*)this;
|
|
|
|
AcDbGripData* pGripData = new AcDbGripData;
|
|
pGripData->setGripPoint(ptMid);
|
|
pGripData->setAppData((void*)&m_pGripAppData[i]);
|
|
pGripData->setWorldDraw(AecGripCback::WorldDrawfunc);
|
|
pGripData->setToolTipFunc(AecGripCback::GripToolTipFunc);
|
|
grips.append(pGripData);
|
|
|
|
return Acad::eOk;
|
|
}
|
|
|
|
Acad::ErrorStatus AecDbHanger::subMoveStretchPointsAt(const AcDbIntArray& indices,const AcGeVector3d& offset)
|
|
{
|
|
if (indices.isEmpty())
|
|
return Acad::eOk;
|
|
|
|
AssertWriteEnabled();
|
|
|
|
AcGeMatrix3d xformM;
|
|
xformM.setToTranslation(offset);
|
|
|
|
if (indices.length() == 1)
|
|
{
|
|
AcGePoint3d pt;
|
|
AcGeVector3d vtL;
|
|
m_mapSpecXData.GetAt(KEY_POS,pt);
|
|
m_mapSpecXData.GetAt(PIPE_DIR,vtL);
|
|
|
|
int nGripIndex = indices.first();
|
|
if (nGripIndex == 0)
|
|
{
|
|
pt += offset;
|
|
m_mapSpecXData.SetAt(KEY_POS,pt);
|
|
return Acad::eOk;
|
|
}
|
|
|
|
if (nGripIndex == 1)
|
|
{
|
|
XHanger holder;
|
|
GetHanger(holder);
|
|
|
|
vtL.normalize();
|
|
vtL *= holder.L;
|
|
AcGePoint3d pt2 = pt + vtL;
|
|
|
|
pt2 += offset;
|
|
|
|
double dL = pt2.distanceTo(pt);
|
|
if (dL > 10.0)
|
|
{
|
|
vtL = pt2 - pt;
|
|
vtL.normalize();
|
|
|
|
m_mapSpecXData.SetAt(PIPE_DIR,vtL);
|
|
}
|
|
}
|
|
}
|
|
else if (indices.length() == 2)
|
|
{
|
|
AcGePoint3d pt;
|
|
m_mapSpecXData.GetAt(KEY_POS,pt);
|
|
|
|
pt += offset;
|
|
m_mapSpecXData.SetAt(KEY_POS,pt);
|
|
}
|
|
return Acad::eOk;
|
|
}
|
|
|
|
void AecDbHanger::GetGripText(int nPos, CString& sText)
|
|
{
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
//AEC 派生
|
|
Acad::ErrorStatus AecDbHanger::Draw2d(AcGiDraw &dc) const
|
|
{
|
|
assertReadEnabled();
|
|
|
|
//管线系统屏蔽掉
|
|
if ( dc.IsDragging() )
|
|
{
|
|
//return Acad::eOk;
|
|
}
|
|
|
|
//图层
|
|
AcDbObjectId idLay = dc.GetLayerId();
|
|
dc.SetLayer(layerId());
|
|
//dc.SetSelectionMarker(1);
|
|
|
|
int nCrBk = dc.GetColor();
|
|
int nColor = nCrBk;
|
|
if ( m_mapSpecXData.GetAt(_T("COLOR"),nColor) )
|
|
{
|
|
dc.SetColor(nColor);
|
|
}
|
|
|
|
if (Has2DBuffer())
|
|
{
|
|
AcDbEntity* pEnt = NULL;
|
|
const AcDbVoidPtrArray &ar2D = Get2DBuffer();
|
|
for (int i = 0;i < ar2D.length();i++)
|
|
{
|
|
pEnt = (AcDbEntity*)ar2D.at(i);
|
|
//pEnt->setColorIndex(nColor);
|
|
dc.DrawEntity(*pEnt);
|
|
}
|
|
|
|
dc.SetLayer(idLay);
|
|
dc.SetColor(nCrBk);
|
|
return Acad::eOk;
|
|
}
|
|
|
|
XHanger holder;
|
|
GetHanger(holder);
|
|
|
|
AcGePoint3d pt;
|
|
AcGeVector3d vtL;
|
|
m_mapSpecXData.GetAt(KEY_POS,pt);
|
|
m_mapSpecXData.GetAt(PIPE_DIR,vtL);
|
|
|
|
pt.z = 0.0;//2D
|
|
vtL.z = 0.0;//2D
|
|
vtL.normalize();
|
|
|
|
if (vtL.isZeroLength())//单杆
|
|
{
|
|
AcDbLine* pLn = NULL;
|
|
vtL = AcGeVector3d::kXAxis;
|
|
AcGeVector3d vtV = AcGeVector3d::kYAxis;
|
|
|
|
AcGePoint3d ptGe[5];
|
|
ptGe[1] = pt;
|
|
ptGe[1] -= 0.5 * vtL * holder.W;
|
|
ptGe[2] = ptGe[1] + vtL * holder.W;
|
|
|
|
pLn = new AcDbLine(ptGe[1],ptGe[2]);
|
|
pLn->setLayer(idLay);
|
|
dc.DrawEntity(pLn);
|
|
Add2DBuffer(pLn);
|
|
|
|
ptGe[0] = ptGe[1];
|
|
ptGe[0] += vtL * 0.5 * holder.W;
|
|
ptGe[0] += vtV * 0.5 * holder.W;
|
|
ptGe[3] -= vtV * holder.W;
|
|
|
|
pLn = new AcDbLine(ptGe[1],ptGe[2]);
|
|
pLn->setLayer(idLay);
|
|
dc.DrawEntity(pLn);
|
|
Add2DBuffer(pLn);
|
|
|
|
AcDbCircle* pCir = new AcDbCircle;
|
|
pCir->setCenter(pt);
|
|
pCir->setRadius(0.25 * holder.W);
|
|
pCir->setNormal(AcGeVector3d::kZAxis);
|
|
dc.DrawEntity(pCir);
|
|
Add2DBuffer(pCir);
|
|
}
|
|
else
|
|
{
|
|
AcGeVector3d vtV = vtL;
|
|
vtV.rotateBy(PI / 2.0,AcGeVector3d::kZAxis);
|
|
|
|
//居中
|
|
pt -= 0.5 * holder.L * vtL;
|
|
|
|
//
|
|
AcGePoint3d ptGe[5];
|
|
ptGe[0] = pt;
|
|
ptGe[0] += vtV * 0.5 * holder.W;
|
|
|
|
ptGe[1] = ptGe[0] + vtL * holder.L;
|
|
ptGe[2] = ptGe[1] - vtV * holder.W;
|
|
|
|
ptGe[3] = ptGe[0] - vtV * holder.W;
|
|
ptGe[4] = ptGe[0];
|
|
|
|
AcDbPolyline* pPl = FormatPolyline(ptGe,5);
|
|
if (pPl != NULL)
|
|
{
|
|
pPl->setLayer(idLay);
|
|
dc.DrawEntity(pPl);
|
|
Add2DBuffer(pPl);
|
|
}
|
|
|
|
//+ 字
|
|
if (holder.nHs > 1)
|
|
{
|
|
ptGe[1] = MidPoint(ptGe[0],ptGe[3]);
|
|
AcDbLine* pLn = NULL;
|
|
AcDbCircle* pCir = NULL;
|
|
|
|
double dLx = holder.L / (holder.nHs - 1);
|
|
for (int i = 0;i < holder.nHs;i++)
|
|
{
|
|
ptGe[1] -= 0.5 * vtL * holder.W;
|
|
ptGe[2] = ptGe[1] + vtL * holder.W;
|
|
|
|
pLn = new AcDbLine(ptGe[1],ptGe[2]);
|
|
pLn->setLayer(idLay);
|
|
dc.DrawEntity(pLn);
|
|
Add2DBuffer(pLn);
|
|
|
|
ptGe[0] = ptGe[1];
|
|
ptGe[0] += vtL * 0.5 * holder.W;
|
|
ptGe[0] += vtV * 0.5 * holder.W;
|
|
ptGe[2] = ptGe[0];
|
|
ptGe[2] -= vtV * holder.W;
|
|
|
|
pLn = new AcDbLine(ptGe[0],ptGe[2]);
|
|
pLn->setLayer(idLay);
|
|
dc.DrawEntity(pLn);
|
|
Add2DBuffer(pLn);
|
|
|
|
pCir = new AcDbCircle;
|
|
pCir->setCenter(MidPoint(ptGe[1],ptGe[2]));
|
|
pCir->setRadius(0.25 * holder.W);
|
|
pCir->setNormal(AcGeVector3d::kZAxis);
|
|
dc.DrawEntity(pCir);
|
|
Add2DBuffer(pCir);
|
|
|
|
ptGe[1] += vtL * 0.5 * holder.W;
|
|
ptGe[1] += vtL * dLx;
|
|
}
|
|
}
|
|
}
|
|
return Acad::eOk;
|
|
}
|
|
|
|
Acad::ErrorStatus AecDbHanger::Draw3d(AcGiDraw &dc) const
|
|
{
|
|
assertReadEnabled();
|
|
AcCmTransparency tr = transparency();
|
|
|
|
//管线系统屏蔽掉
|
|
if ( dc.IsDragging() )
|
|
{
|
|
//return Acad::eOk;
|
|
}
|
|
|
|
//图层
|
|
AcDbObjectId idLay = dc.GetLayerId();
|
|
dc.SetLayer(layerId());
|
|
|
|
int nCrBk = dc.GetColor();
|
|
int nColor = nCrBk;
|
|
if ( m_mapSpecXData.GetAt(_T("COLOR"),nColor) )
|
|
{
|
|
dc.SetColor(nColor);
|
|
}
|
|
|
|
if (Has3DBuffer())
|
|
{
|
|
AcDbEntity* pEnt = NULL;
|
|
const AcDbVoidPtrArray &ar3D = Get3DBuffer();
|
|
for (int i = 0;i < ar3D.length();i++)
|
|
{
|
|
pEnt = (AcDbEntity*)ar3D.at(i);
|
|
pEnt->setTransparency(tr);
|
|
dc.DrawEntity(*pEnt);
|
|
}
|
|
dc.SetLayer(idLay);
|
|
dc.SetColor(nCrBk);
|
|
return Acad::eOk;
|
|
}
|
|
|
|
deleteContainerOfStd(m_solids);
|
|
deleteContainerOfStd(m_pipes);
|
|
|
|
XHanger holder;
|
|
GetHanger(holder);
|
|
|
|
//pt 中含有顶标高
|
|
AcGePoint3d pt;
|
|
AcGeVector3d vtL;
|
|
m_mapSpecXData.GetAt(KEY_POS,pt);
|
|
m_mapSpecXData.GetAt(PIPE_DIR,vtL);
|
|
vtL.normalize();
|
|
|
|
AcGePoint3d ptTo;
|
|
if (vtL.isZeroLength())//单杆
|
|
{
|
|
ptTo = pt;
|
|
ptTo.z -= holder.L;
|
|
|
|
AcDb3dSolid* pSolid = Create3dRod(pt,ptTo,holder.dD,0.0,holder.bdDAsW);
|
|
if (pSolid != NULL)
|
|
{
|
|
pSolid->setTransparency(tr);
|
|
dc.DrawEntity(pSolid);
|
|
Add3DBuffer(pSolid);
|
|
}
|
|
|
|
//强固
|
|
AcGePoint3d ptGe[2];
|
|
if (holder.bdDAsW)
|
|
{
|
|
ptGe[0] = pt;
|
|
ptGe[0].x -= 2.0 * holder.W;
|
|
ptGe[1] = pt;
|
|
ptGe[1].x += 2.0 * holder.W;
|
|
|
|
pSolid = Create3dRod(ptGe[0],ptGe[1],holder.W,holder.t,holder.bdDAsW);
|
|
if (pSolid != NULL)
|
|
{
|
|
pSolid->setTransparency(tr);
|
|
dc.DrawEntity(pSolid);
|
|
Add3DBuffer(pSolid);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//绘制固定螺丝示意
|
|
ptGe[0] = pt;
|
|
ptGe[0].z += 8.0;//8mm
|
|
ptGe[1] = pt;
|
|
|
|
pSolid = Create3dRod(ptGe[0],ptGe[1],1.3 * holder.dD,0.0,holder.bdDAsW);
|
|
if (pSolid != NULL)
|
|
{
|
|
pSolid->setTransparency(tr);
|
|
dc.DrawEntity(pSolid);
|
|
Add3DBuffer(pSolid);
|
|
}
|
|
}
|
|
}
|
|
else //多行
|
|
{
|
|
AcGeVector3d vtV = vtL;
|
|
vtV.rotateBy(PI / 2.0,AcGeVector3d::kZAxis);
|
|
|
|
AcGePoint3d ptTo,ptL[2];
|
|
AcGePoint3d ptFr = pt;
|
|
ptL[0] = pt - vtL * 0.5 * holder.L;
|
|
ptL[1] = pt + vtL * 0.5 * holder.L;
|
|
|
|
ptL[0].z -= holder.N * holder.V;
|
|
ptL[1].z -= holder.N * holder.V;
|
|
|
|
AcDb3dSolid* pSolid = NULL;
|
|
for (int i = 0;i < holder.N;i++)
|
|
{
|
|
pSolid = Create3dRod(ptL[0],ptL[1],holder.W,holder.t,1);
|
|
if (pSolid != NULL)
|
|
{
|
|
pSolid->setTransparency(tr);
|
|
dc.DrawEntity(pSolid);
|
|
Add3DBuffer(pSolid);
|
|
}
|
|
ptL[0].z += holder.V;
|
|
ptL[1].z += holder.V;
|
|
}
|
|
|
|
AcGePoint3d ptGe[2];
|
|
//吊杆
|
|
if (holder.nHs > 1)
|
|
{
|
|
pt -= vtL * 0.5 * holder.L;
|
|
|
|
double dLx = holder.L / (holder.nHs - 1);
|
|
ptL[0] = pt;
|
|
ptL[1] = pt;
|
|
ptL[1].z -= holder.N * holder.V;
|
|
|
|
for (int i = 0;i < holder.nHs;i++)
|
|
{
|
|
if (i == holder.nHs - 1)
|
|
{
|
|
pSolid = Create3dRod(ptL[1],ptL[0],holder.bdDAsW ? holder.W : holder.dD,holder.bdDAsW ? holder.t : 0,holder.bdDAsW);
|
|
}
|
|
else
|
|
{
|
|
pSolid = Create3dRod(ptL[0],ptL[1],holder.bdDAsW ? holder.W : holder.dD,holder.bdDAsW ? holder.t : 0,holder.bdDAsW);
|
|
}
|
|
if (pSolid != NULL)
|
|
{
|
|
pSolid->setTransparency(tr);
|
|
dc.DrawEntity(pSolid);
|
|
Add3DBuffer(pSolid);
|
|
}
|
|
|
|
//强固
|
|
if (holder.bdDAsW)//角钢
|
|
{
|
|
ptGe[0] = ptL[0];
|
|
ptGe[0] -= 2.0 * holder.W * vtV;
|
|
ptGe[1] = ptL[0];
|
|
ptGe[1] += 2.0 * holder.W * vtV;
|
|
|
|
pSolid = Create3dRod(ptGe[0],ptGe[1],holder.W,holder.t,holder.bdDAsW);
|
|
if (pSolid != NULL)
|
|
{
|
|
pSolid->setTransparency(tr);
|
|
dc.DrawEntity(pSolid);
|
|
Add3DBuffer(pSolid);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//绘制固定螺丝示意
|
|
ptGe[0] = ptL[0];
|
|
ptGe[0].z += 8.0;//8mm
|
|
ptGe[1] = ptL[0];
|
|
|
|
pSolid = Create3dRod(ptGe[0],ptGe[1],1.3 * holder.dD,0.0,holder.bdDAsW);
|
|
if (pSolid != NULL)
|
|
{
|
|
pSolid->setTransparency(tr);
|
|
dc.DrawEntity(pSolid);
|
|
Add3DBuffer(pSolid);
|
|
}
|
|
}
|
|
|
|
ptL[0] += vtL * dLx;
|
|
ptL[1] += vtL * dLx;
|
|
}
|
|
}
|
|
}
|
|
return Acad::eOk;
|
|
}
|
|
|
|
//专业数据 和 绘制设置
|
|
AecDbObjXDataMap* AecDbHanger::GetSpecialtyData(AcDb::OpenMode bMode/* = AcDb::kForWrite*/)
|
|
{
|
|
switch(bMode)
|
|
{
|
|
case AcDb::kForRead:
|
|
{
|
|
assertReadEnabled();
|
|
break;
|
|
}
|
|
case AcDb::kForWrite:
|
|
{
|
|
if (!isWriteEnabled())
|
|
{
|
|
upgradeOpen();
|
|
}
|
|
assertWriteEnabled();
|
|
break;
|
|
}
|
|
case AcDb::kForNotify:
|
|
{
|
|
assertReadEnabled();
|
|
}
|
|
default:
|
|
break;
|
|
}
|
|
return &m_mapSpecXData;
|
|
}
|
|
|
|
const AecDbObjXDataMap* AecDbHanger::GetSpecialtyData() const
|
|
{
|
|
assertReadEnabled();
|
|
return &m_mapSpecXData;
|
|
}
|
|
|
|
AcDb3dSolid* AecDbHanger::Create3dRod(const AcGePoint3d& ptFr,const AcGePoint3d& ptTo,double dL1,double dt,int nShape,double dRegRoate) const
|
|
{
|
|
AcDb3dSolid* pPipe = NULL;
|
|
AcGiViewDraw dcTmp(NULL,NULL);
|
|
if (nShape == 0)//圆杆
|
|
{
|
|
AecDbEwPipe pipe;
|
|
pipe.SetSection(dL1,0.0);
|
|
pipe.SetStartPoint(ptFr);
|
|
pipe.SetEndPoint(ptTo);
|
|
m_pipes.push_back((AecDbEwPipe*)pipe.clone());
|
|
|
|
pipe.Draw3d(dcTmp);
|
|
pPipe = pipe.GetCreatPipe3dSolid();
|
|
}
|
|
else if(nShape == 1)//角钢
|
|
{
|
|
AecDbEwPipe pipe;
|
|
pipe.SetSection3(dL1,dt);
|
|
pipe.SetSectionRotation(dRegRoate);
|
|
pipe.SetStartPoint(ptFr);
|
|
pipe.SetEndPoint(ptTo);
|
|
m_pipes.push_back((AecDbEwPipe*)pipe.clone());
|
|
|
|
pipe.Draw3d(dcTmp);
|
|
pPipe = pipe.GetCreatPipe3dSolid();
|
|
}
|
|
else if (nShape == 2)//矩形
|
|
{
|
|
AecDbEwPipe pipe;
|
|
pipe.SetSection(dL1,dt,0.0);
|
|
pipe.SetSectionRotation(dRegRoate);
|
|
pipe.SetStartPoint(ptFr);
|
|
pipe.SetEndPoint(ptTo);
|
|
m_pipes.push_back((AecDbEwPipe*)pipe.clone());
|
|
pipe.Draw3d(dcTmp);
|
|
pPipe = pipe.GetCreatPipe3dSolid();
|
|
}
|
|
return pPipe;
|
|
}
|
|
|
|
int AecDbHanger::GetSectionDraw(const AcGePoint3d& ptFr,const AcGePoint3d& ptTo,const AcGeVector3d& vtViewDir,const AcGeVector3d& vtTo, AcDbVoidPtrArray& arRegPtrs) const
|
|
{
|
|
AcGeVector3d vtLn = ptTo - ptFr;
|
|
AcGeVector3d vtNorm = vtLn.crossProduct(vtViewDir);
|
|
|
|
AcGePlane plan;
|
|
plan.set(ptFr,vtNorm);
|
|
|
|
AcGeMatrix3d xform;
|
|
xform.setToPlaneToWorld(plan);
|
|
xform.invert();
|
|
|
|
if (Get3DBuffer().length() == 0)
|
|
{
|
|
AcGiViewDraw dc(NULL,NULL);
|
|
Draw3d(dc);
|
|
}
|
|
|
|
AcDbEntity* pEnt = NULL;
|
|
AcDb3dSolid* pSolid = NULL;
|
|
|
|
const AcDbVoidPtrArray &ar3D = Get3DBuffer();
|
|
for (int i = 0;i < ar3D.length();i++)
|
|
{
|
|
pEnt = (AcDbEntity*)ar3D.at(i);
|
|
|
|
pSolid = AcDb3dSolid::cast(pEnt);
|
|
if (pSolid != NULL)
|
|
{
|
|
//投影法
|
|
OrthoProjected3DSolid(pSolid,plan,xform,arRegPtrs);
|
|
}
|
|
}
|
|
return arRegPtrs.length();
|
|
}
|
|
|
|
CString AecDbHanger::getUniqueName() const
|
|
{
|
|
XHanger hanger;
|
|
::memset(&hanger, 0, sizeof(XHanger));
|
|
GetHanger(hanger);
|
|
|
|
::memset(hanger.szMat, 0, 33 * sizeof(TCHAR));
|
|
::memset(hanger.szUsage, 0, 33 * sizeof(TCHAR));
|
|
|
|
return ImpMD5(&hanger, sizeof(XHanger)).toString16W().c_str();
|
|
}
|
|
|
|
SHJson::WValue &AecDbHanger::ToJson(bool bExprotGeo) const
|
|
{
|
|
using namespace SHJson;
|
|
assertReadEnabled();
|
|
|
|
WValue &v = AecDbEntityBase::ToJson(bExprotGeo);
|
|
|
|
if (bExprotGeo)
|
|
{
|
|
AecDbHanger *pNew = (AecDbHanger*)clone();
|
|
pNew->SetPosition(AcGePoint3d::kOrigin, AcGeVector3d::kXAxis);
|
|
pNew->Clean3DBuffer();
|
|
AcGiViewDraw dc;
|
|
pNew->Draw3d(dc);
|
|
|
|
WValue ar;
|
|
ar.SetArray();
|
|
|
|
for (size_t i(0); i < pNew->m_solids.size(); ++i)
|
|
{
|
|
AcDbX3dSolid *pSolid(pNew->m_solids[i]);
|
|
if (!pSolid) continue;
|
|
WValue &x = pSolid->ToJson();
|
|
pushBack(ar, x);
|
|
}
|
|
if (!pNew->m_solids.empty())
|
|
addMember(v, _T("__solids__"), ar);
|
|
|
|
ar.SetArray();
|
|
for (size_t i(0); i < pNew->m_pipes.size(); ++i)
|
|
{
|
|
AecDbEwPipeBase *pPipe(pNew->m_pipes[i]);
|
|
if (!pPipe) continue;
|
|
WValue &x = pPipe->ToJson();
|
|
pushBack(ar, x);
|
|
}
|
|
if (!pNew->m_pipes.empty())
|
|
addMember(v, _T("__pipes__"), ar);
|
|
DELETE_PTR(pNew);
|
|
}
|
|
|
|
XHanger hanger;
|
|
::memset(&hanger, 0, sizeof(XHanger));
|
|
GetHanger(hanger);
|
|
|
|
/*
|
|
typedef struct XHanger // 吊架 {
|
|
int nHs;
|
|
int N;
|
|
double dD;
|
|
BOOL bdDAsW;
|
|
double V;
|
|
double L;
|
|
double W;
|
|
double t;
|
|
TCHAR szMat[33];
|
|
TCHAR szUsage[33];
|
|
double dResv[6];
|
|
int nResv[6];
|
|
TCHAR szResv[MAX_PATH]; }XHanger;
|
|
*/
|
|
|
|
WValue data;
|
|
addMember(data, _T("__nHs__"), hanger.nHs);
|
|
addMember(data, _T("__N__"), hanger.N);
|
|
addMember(data, _T("__dD__"), hanger.dD);
|
|
addMember(data, _T("__bdDAsW__"), hanger.bdDAsW);
|
|
addMember(data, _T("__V__"), hanger.V);
|
|
addMember(data, _T("__L__"), hanger.L);
|
|
addMember(data, _T("__W__"), hanger.W);
|
|
addMember(data, _T("__t__"), hanger.t);
|
|
addMember(data, _T("__szMat__"), hanger.szMat);
|
|
addMember(data, _T("__szUsage__"), hanger.szUsage);
|
|
addMember(data, _T("__szResv__"), hanger.szResv);
|
|
|
|
WValue ar;
|
|
ar.SetArray();
|
|
for (int i(0); i < 6; ++i)
|
|
pushBack(ar, hanger.dResv[i]);
|
|
addMember(data, _T("__dResv__"), ar);
|
|
|
|
ar.SetArray();
|
|
for (int i(0); i < 6; ++i)
|
|
pushBack(ar, hanger.nResv[i]);
|
|
addMember(data, _T("__nResv__"), ar);
|
|
|
|
addMember(v, _T("_hangerData_"), data);
|
|
|
|
return v;
|
|
}
|