Files
envi-code/SourceCode/Code2026/CoreLibrary/AecDbBDPipeBase.cpp
T
2026-09-28 15:28:50 +08:00

2707 lines
63 KiB
C++

#include "stdafx.h"
#include "encryption.h"
#include "KTSetting.h"
#include "AecDbBDPipeBase.h"
#include "AecDbX3dPart.h"
#include "AecDbX3dPartEntity.h"
#include "MFCDbDwgFiler.h"
#include "CoreTools.h"
#include "AecDbOpening.h"
#include "geometry2json.h"
#include "AecCoverBooleanOper.h"
#include "AcGiViewDraw.h"
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;
#define LAY_PIPE_OUTSIDE _T("PIPE_OUT")
extern void DLLIMPEXP OrthoProjected3DSolid(AcDb3dSolid* pSolidClone,const AcGePlane& plan,AcGeMatrix3d& xformPlanToWorld,AcDbVoidPtrArray& arEntPtrs);
extern void RegionHatch(AcDbRegion* pRegionT,AcDbVoidPtrArray& arHatchPtrs,LPCTSTR pszPattern);
extern AcGePoint3d MidPoint(const AcGePoint3d& pt1,const AcGePoint3d& pt2);
extern Acad::ErrorStatus AddToModelSpace(AcDbEntity* pEnt,AcDbDatabase* pDb = NULL,bool bClose = true);
extern AcDbRegion* CreatePolygonRegionOnly(AcGePoint3d* pPoints,int nSize);
extern AcDbPolyline *FormatPolyline(AcGePoint3d *ppPts, int nCount);
extern void FillSolid(AcGePoint3d *pptGe, int nCount, AcDbVoidPtrArray &arHatchPtrs);
static void FreeBuffer(int n,AcArray<AecDbX3dPart*>& arPartPtrs)
{
AecDbX3dPart* pEnt = NULL;
while(arPartPtrs.length() > n )
{
pEnt = (AecDbX3dPart*)arPartPtrs.last();
if (pEnt != NULL)
{
arPartPtrs.removeLast();
delete pEnt;
}
}
}
static void FreeBuffer(int n, AcDbVoidPtrArray& arEntPtrs)
{
AcDbEntity* pEnt = NULL;
while (arEntPtrs.length() > n)
{
pEnt = (AcDbEntity*)arEntPtrs.last();
DELETE_PTR(pEnt);
arEntPtrs.removeLast();
}
}
extern void transfromRegion(AcDbRegion *pRegion, const AcGePoint3d &ptOnRegion, const AcGeVector3d &vtNormal, const AcGePoint3d &ptOnPlan);
Adesk::UInt32 AecDbBDPipeBase::kCurrentVersionNumber = 1;
ACRX_DXF_DEFINE_MEMBERS (AecDbBDPipeBase, AecDbEwPipeBase,
AcDb::kDHL_CURRENT, AcDb::kMReleaseCurrent,
AcDbProxyEntity::kNoOperation | AcDbProxyEntity::kDisableProxyWarning,
AEC_BDPIPE,
"AecDbBDPipeBase"
"|Product Desc: shanghua earthworm app obj"
"|Company: shanghua inc"
"|WEB Address: www.shanghuasoft.com")
AecDbBDPipeBase::AecDbBDPipeBase(void)
{
memset(m_dRotate,0,sizeof(double) * 3);
}
AecDbBDPipeBase::~AecDbBDPipeBase(void)
{
FreeBuffer(0,m_arX3DPartPtrs);
}
void AecDbBDPipeBase::AddX3dPart(AecDbX3dPart* pPart,int nBoolOper)
{
AssertWriteEnabled();
pPart->SetBoolOperFor(nBoolOper);
m_arX3DPartPtrs.append(pPart);
}
int AecDbBDPipeBase::GetX3dPartCount() const
{
assertReadEnabled();
return m_arX3DPartPtrs.length();
}
bool AecDbBDPipeBase::RemoveX3dPart(int nIndex)
{
AssertWriteEnabled();
if (nIndex > -1 && nIndex < m_arX3DPartPtrs.length())
{
AecDbX3dPart* pPart = m_arX3DPartPtrs.at(nIndex);
m_arX3DPartPtrs.removeAt(nIndex);
if (pPart != NULL)
{
delete pPart;
}
}
return false;
}
void AecDbBDPipeBase::RemoveAllX3dPart(bool bDelete)
{
AssertWriteEnabled();
while(!m_arX3DPartPtrs.isEmpty())
{
AecDbX3dPart* pPart = m_arX3DPartPtrs.last();
m_arX3DPartPtrs.removeLast();
if (bDelete)
{
delete pPart;
}
}
}
AecDbX3dPart* AecDbBDPipeBase::GetX3dPart(int nIndex) const
{
assertReadEnabled();
if (nIndex > -1 && nIndex < m_arX3DPartPtrs.length())
{
return m_arX3DPartPtrs.at(nIndex);
}
return NULL;
}
AecDbX3dPart* AecDbBDPipeBase::GetX3dPart(LPCTSTR pszID) const
{
assertReadEnabled();
if (!pszID) return NULL;
AecDbX3dPart* pPart = NULL;
for(int i = 0;i < m_arX3DPartPtrs.length();i++)
{
pPart = m_arX3DPartPtrs.at(i);
if (_tcscmp(pPart->GetGUID(),pszID) == 0)
{
return pPart;
}
}
return NULL;
}
//移除洞口,井结构
bool AecDbBDPipeBase::RemoveX3dPart(LPCTSTR pszGUID)
{
AssertWriteEnabled();
AecDbX3dPart* pPart = NULL;
for (int i = 0;i < m_arX3DPartPtrs.length();i++)
{
pPart = m_arX3DPartPtrs.at(i);
if ( _tcscmp(pPart->GetGUID(),pszGUID) == 0)
{
m_arX3DPartPtrs.removeAt(i);
delete pPart;
return true;
}
}
return false;
}
void AecDbBDPipeBase::AddMove(LPCTSTR pszID, AcGeVector3d& vtMove)
{
AssertWriteEnabled();
AecDbX3dPart* pPart = GetX3dPart(pszID);
if (pPart != NULL)
{
pPart->AddMove(vtMove);
}
}
void AecDbBDPipeBase::ResetMove(LPCTSTR pszID)
{
AssertWriteEnabled();
AecDbX3dPart* pPart = GetX3dPart(pszID);
if (pPart != NULL)
{
pPart->ResetMove();
}
}
AcGePoint3d AecDbBDPipeBase::GetPosition() const
{
assertReadEnabled();
AcGePoint3d ptCenPos;
m_mapSpecXData.GetAt(KEY_ORGPT,ptCenPos);
return ptCenPos;
}
void AecDbBDPipeBase::SetPosition(const AcGePoint3d& ptPos)
{
AssertWriteEnabled();
//改变basecurve
AcDbLine* pLn = AcDbLine::cast(m_pBaseCurve);
if (pLn != NULL)
{
AcGePoint3d ptSta = pLn->startPoint();
AcGePoint3d ptEnd = pLn->endPoint();
AcGeVector3d vt = ptEnd - ptSta;
ptSta = ptPos;
ptEnd = ptPos + vt;
pLn->setStartPoint(ptSta);
pLn->setEndPoint(ptEnd);
m_mapSpecXData.SetAt(KEY_ORGPT,ptPos,TRUE);
}
}
void AecDbBDPipeBase::SetRotation(int nAxisIndex,double dRotate)
{
AssertWriteEnabled();
if (nAxisIndex > -1 && nAxisIndex < 2)
{
m_dRotate[nAxisIndex] = dRotate;
}
}
double AecDbBDPipeBase::GetRotation(int nAxisIndex) const
{
assertReadEnabled();
if (nAxisIndex > -1 && nAxisIndex < 2)
{
return m_dRotate[nAxisIndex];
}
return 0.0;
}
void AecDbBDPipeBase::ResetRotation(int nAxisIndex/* = -1*/)
{
AssertWriteEnabled();
if (nAxisIndex > -1 && nAxisIndex < 2)
{
m_dRotate[nAxisIndex] = 0.0;
}
else if (nAxisIndex == -1)
{
m_dRotate[X] = 0.0;
m_dRotate[Y] = 0.0;
m_dRotate[Z] = 0.0;
}
}
void AecDbBDPipeBase::SetRotation(LPCTSTR pszID,int nAxis,double dRotateBy)
{
AssertWriteEnabled();
AecDbX3dPart* pPart = GetX3dPart(pszID);
if (pPart != NULL)
{
pPart->AddRotate(nAxis,dRotateBy);
}
}
void AecDbBDPipeBase::ResetRotation(LPCTSTR pszID,int nAxis)
{
AssertWriteEnabled();
AecDbX3dPart* pPart = GetX3dPart(pszID);
if (pPart != NULL)
{
pPart->ResetRotate(nAxis);
}
}
void AecDbBDPipeBase::DrawDTYG2D(AcGiDraw & dc) const
{
assertReadEnabled();
// 先判断缓存
if (!m_arDTYG2DBufPtrs.isEmpty())
{
for (int i = 0; i < m_arDTYG2DBufPtrs.length(); ++i)
{
AcDbEntity *pEnt((AcDbEntity*)m_arDTYG2DBufPtrs[i]);
dc.DrawEntity(*pEnt);
}
return;
}
// 在 3d buffers 里挑出来需要的 clone 一份
AecDbObjXDataMap xdata;
AcDbVoidPtrArray ar3d = Get3DBuffer();
for (int i = 0; i < ar3d.length(); ++i)
{
AcDbEntity *pEnt((AcDbEntity*)ar3d[i]);
AcDb3dSolid *pSolid = AcDb3dSolid::cast(pEnt);
if (!pSolid) continue;
xdata.Empty();
if (!xdata.Read(pSolid, _T("DTYG"))) continue;
AcDb3dSolid *p = (AcDb3dSolid*)pSolid->clone();
dc.DrawEntity(*p);
m_arDTYG2DBufPtrs.append(p);
}
if (!m_arDTYG2DBufPtrs.isEmpty()) return;
// 如果都没有,新建
int nVt;
AcDbObjectId ltid(KTSetting::InitLineStyle(_T("CENTER")));
for (int i = 0; i < m_arX3DPartPtrs.length(); ++i)
{
AecDbX3dPart *pPart(m_arX3DPartPtrs[i]);
if (!pPart) continue;
if (!pPart->GetSpecialtyData()->HasKey(_T("DTYG_TYPE"), nVt)) continue;
CString sType(_T(""));
pPart->GetSpecialtyData()->GetAt(_T("DTYG_TYPE"), sType);
//if (sType == _T("切割")) continue;
bool bSub = pPart->GetBoolOperFor() == AcDb::kBoolSubtract;
AcDb3dSolid *pSolid = pPart->CreateDraw3dSolid();
if (!pSolid)
{
pPart->Create();
pSolid = pPart->CreateDraw3dSolid();
}
if (pSolid)
{
if (bSub && ltid.isValid())
pSolid->setLinetype(ltid);
dc.DrawEntity(*pSolid);
m_arDTYG2DBufPtrs.append(pSolid);
}
}
}
Acad::ErrorStatus AecDbBDPipeBase::Draw2d(AcGiDraw &dc) const
{
return AecDbEwPipeBase::Draw2d(dc);
}
Acad::ErrorStatus AecDbBDPipeBase::Draw3d(AcGiDraw &dc) const
{
assertReadEnabled();
if (g_BALock::instance().Draw() != BIT_SUCCESS)
return Acad::eOk;
////管线系统屏蔽掉
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 (IsActive())
{
nColor = kMagenta;
m_mapSpecXData.GetAt(KEY_ACTIVECR,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);
if ( IsActive() )
{
BackupColorIndex(pEnt);
pEnt->setColorIndex(nColor);
}
else
{
SetBackupColorIndex(pEnt);
}
dc.DrawEntity(*pEnt);
}
dc.SetLayer(idLay);
dc.SetColor(nCrBk);
return Acad::eOk;
}
AcCmTransparency tr = transparency();
AcDb3dSolid* pSolidDraw = GetDraw3dSolid(false, nColor);
if (pSolidDraw != NULL)
{
pSolidDraw->setTransparency(tr);
pSolidDraw->setLayer(layerId());
//pSolidDraw->setColorIndex(nColor);
dc.DrawEntity(pSolidDraw);
Add3DBuffer(pSolidDraw);
}
dc.SetLayer(idLay);
dc.SetColor(nCrBk);
return Acad::eOk;
}
Acad::ErrorStatus AecDbBDPipeBase::copyFrom(const AcRxObject* pSrc)
{
assertWriteEnabled();
AecDbEwPipeBase::copyFrom(pSrc);
//?????需要测试 --- 通过dwgin/out复制了???
/*AecDbBDPipeBase *pBDSrc = AecDbBDPipeBase::cast(pSrc);
if (pBDSrc != NULL)
{
m_nActivePart = pBDSrc->m_nActivePart;
memcpy(m_dRotate, pBDSrc->m_dRotate, sizeof(double) * 3);
m_arX3DPartPtrs.removeAll();
m_arX3DPartPtrs.append(pBDSrc->m_arX3DPartPtrs);
m_arAssocPartEntIds.removeAll();
m_arAssocPartEntIds.append(pBDSrc->m_arAssocPartEntIds);
m_arDTYG2DBufPtrs.removeAll();
m_arDTYG2DBufPtrs.append(pBDSrc->m_arDTYG2DBufPtrs);
}*/
return Acad::eOk;
}
int AecDbBDPipeBase::GetDraw2dables(Adesk::UInt16 nDrawStyle, AcDbVoidPtrArray& arEntPtrs) const
{
assertReadEnabled();
AcDbObjectId idLay = layerId();
AcDbEntity* pEnt = NULL,*pEntCln = NULL;
const AcDbVoidPtrArray &ar2D = Get2DBuffer();
for (int i = 0;i < ar2D.length();i++)
{
pEnt = (AcDbEntity*)ar2D.at(i);
pEntCln = (AcDbEntity*)pEnt->clone();
pEntCln->setLayer(idLay);
arEntPtrs.append(pEntCln);
}
AcGePlane plan = AcGePlane::kXYPlane;
AcGeMatrix3d xform;
xform.setToPlaneToWorld(plan);
xform.invert();
AcDbVoidPtrArray arSubEntPtrs;
for (int j = 0;j < m_arDTYG2DBufPtrs.length();j++)
{
pEnt = (AcDbEntity*)m_arDTYG2DBufPtrs.at(j);
AcDb3dSolid* pSolid = AcDb3dSolid::cast(pEnt);
if (pSolid != NULL)
{
//投影法
OrthoProjected3DSolid(pSolid,plan,xform,arSubEntPtrs);
}
}
for (int k = 0;k < arSubEntPtrs.length();k++)
{
pEnt = (AcDbEntity*)arSubEntPtrs.at(k);
pEnt->setLayer(idLay);
arEntPtrs.append(pEnt);
}
return arEntPtrs.length();
}
AcDb3dSolid* AecDbBDPipeBase::GetDraw3dSolid(bool bAttachBimInf, int nColor,bool bSubtractHole/* = true*/) const
{
assertReadEnabled();
//底板总
AcDb3dSolid* pPipe = GetCreatPipe3dSolid();
if (pPipe != NULL)
{
pPipe->setColorIndex(nColor);
//旋转
AcGePoint3d ptCen;
m_mapSpecXData.GetAt(KEY_ORGPT,ptCen);
AcGeMatrix3d xRote;
xRote.setToRotation(m_dRotate[X],AcGeVector3d::kXAxis,ptCen);
pPipe->transformBy(xRote);
//原位置按轴旋转 轴Y
xRote.setToRotation(m_dRotate[Y],AcGeVector3d::kYAxis,ptCen);
pPipe->transformBy(xRote);
//原位置按轴旋转 轴Z
xRote.setToRotation(m_dRotate[Z],AcGeVector3d::kZAxis,ptCen);
pPipe->transformBy(xRote);
CString sGradX, sGradY;//ext. 1.5 dh / dl * 100 %
if (m_mapSpecXData.GetAt(KEY_GRADX, sGradX))
{
double dA = atan(_ttof(sGradX) / 100.0);
//绕Y
xRote.setToRotation(dA, AcGeVector3d::kYAxis, ptCen);
pPipe->transformBy(xRote);
}
if (m_mapSpecXData.GetAt(KEY_GRADY, sGradY))
{
double dB = atan(_ttof(sGradY) / 100.0);
//绕X
xRote.setToRotation(dB, AcGeVector3d::kXAxis, ptCen);
pPipe->transformBy(xRote);
}
}
//原点位置的单体异构
AcDb3dSolid* pSolidDraw = GetBooleanPart3D(pPipe);
//3.再开除关联的真实位置的part的对象
if (bSubtractHole && pSolidDraw != NULL)
{
BoolSubtractAssoc(pSolidDraw);
}
if (bAttachBimInf)
{
m_mapSpecXData.Write(pSolidDraw,BIMDATA_APP);
}
return pSolidDraw;
}
//临时方法
void AecDbBDPipeBase::RemovePartForSlice()
{
AssertWriteEnabled();
int bSlice = 0;
AecDbX3dPart* pPart = NULL;
for (int i = 0;i < m_arX3DPartPtrs.length();i++)
{
pPart = (AecDbX3dPart*)m_arX3DPartPtrs.at(i);
if ( pPart->GetSpecialtyData()->GetAt(KEY_FORSLICE,bSlice) )
{
m_arX3DPartPtrs.removeAt(i);
i -= 1;
delete pPart;
}
}
}
AcDb3dSolid* AecDbBDPipeBase::GetBooleanPart3D(AcDb3dSolid* pSolidAll) const
{
assertReadEnabled();
//1.合成全部整体
Acad::ErrorStatus es = Acad::eOk;
int nBoolOper = 0,bSlice = 0;
AcDb3dSolid* pSolidPart = NULL;
AecDbX3dPart* pPart = NULL;
for (int i = 0;i < m_arX3DPartPtrs.length();i++)
{
pPart = (AecDbX3dPart*)m_arX3DPartPtrs.at(i);
//融合PART需要slice 另行处理[Wall]
bSlice = 0;
if ( pPart->GetSpecialtyData()->GetAt(KEY_FORSLICE,bSlice) )
{
if (bSlice)
{
continue;
}
else
{
//...
}
}
nBoolOper = pPart->GetBoolOperFor();
if (nBoolOper == AcDb::kBoolUnite)
{
pSolidPart = pPart->CreateDraw3dSolid();
if (pSolidPart == NULL)
{
pPart->Create();
pSolidPart = pPart->CreateDraw3dSolid();
}
if (pSolidPart != NULL)
{
if (pSolidAll == NULL)
{
pSolidAll = pSolidPart;
continue;
}
if ( Acad::eOk == (es = pSolidAll->booleanOper(AcDb::kBoolUnite,pSolidPart) ) )
{
}
else
{
acutPrintf(_T("\nUnite Oper error:%d"),es);
}
}
}
}
//2.再开除洞口
for (int i = 0;i < m_arX3DPartPtrs.length();i++)
{
pPart = (AecDbX3dPart*)m_arX3DPartPtrs.at(i);
nBoolOper = pPart->GetBoolOperFor();
if (nBoolOper == AcDb::kBoolSubtract)
{
pSolidPart = pPart->CreateDraw3dSolid();
if (pSolidPart == NULL)
{
pPart->Create();
pSolidPart = pPart->CreateDraw3dSolid();
}
if (pSolidPart != NULL && pSolidAll != NULL)
{
if ( Acad::eOk == (es = pSolidAll->booleanOper(AcDb::kBoolSubtract,pSolidPart) ) )
{
}
else
{
acutPrintf(_T("\nSubtract Oper error:%d"),es);
}
}
}
}
//总体位置的移动和旋转
if (pSolidAll != NULL)
{
AcGePoint3d ptCen;
m_mapSpecXData.GetAt(KEY_ORGPT,ptCen);
AcGeMatrix3d xRote;
xRote.setToRotation(m_dRotate[X],AcGeVector3d::kXAxis,ptCen);
pSolidAll->transformBy(xRote);
//原位置按轴旋转 轴Y
xRote.setToRotation(m_dRotate[Y],AcGeVector3d::kYAxis,ptCen);
pSolidAll->transformBy(xRote);
//原位置按轴旋转 轴Z
xRote.setToRotation(m_dRotate[Z],AcGeVector3d::kZAxis,ptCen);
pSolidAll->transformBy(xRote);
}
return pSolidAll;
}
Acad::ErrorStatus AecDbBDPipeBase::BoolSubtractAssoc(AcDb3dSolid* pSolidDraw) const
{
assertReadEnabled();
//3.再开除关联的part的对象
Acad::ErrorStatus es;
AcDbEntity* pEnt = NULL;
AcDbObjectId id;
for (int i = 0;i < m_arAssocPartEntIds.length();i++)
{
id = m_arAssocPartEntIds.at(i);
if ( Acad::eOk == (es = acdbOpenAcDbEntity(pEnt,id,AcDb::kForRead)))
{
AecDbX3dPartEntity* pPartEnt = AecDbX3dPartEntity::cast(pEnt);
if (pPartEnt != NULL)
{
AcDbVoidPtrArray arSolidPtrs;
pPartEnt->GetForHouseSubtract(arSolidPtrs);
for(int ii = 0;ii < arSolidPtrs.length();ii++)
{
AcDb3dSolid* pSolidPart = (AcDb3dSolid*)arSolidPtrs.at(ii) ;
if (pSolidPart != NULL)
{
//TEST
//AddToModelSpace((AcDbEntity*)pSolidPart->clone());
if ( Acad::eOk == (es = pSolidDraw->booleanOper(AcDb::kBoolSubtract,pSolidPart) ) )
{
//TEST
//AddToModelSpace((AcDbEntity*)pSolidAll->clone());
}
else
{
acutPrintf(_T("\nSubtract Oper error:%d"),es);
}
}
}
}
pEnt->close();
}
}
return Acad::eOk;
}
Acad::ErrorStatus AecDbBDPipeBase::dwgInFields(AcDbDwgFiler* pFiler)
{
AssertWriteEnabled();
//----- Read parent class information first.
Acad::ErrorStatus es = Acad::eOk;
es = AecDbEwPipeBase::dwgInFields (pFiler) ;
if ( es != Acad::eOk )
return (es) ;
//----- Object version number needs to be read first
return _dwgInFields_for_DBWeir(pFiler);
}
Acad::ErrorStatus AecDbBDPipeBase::dwgOutFields(AcDbDwgFiler* pFiler) const
{
//----- Save parent class information first.
Acad::ErrorStatus es = Acad::eOk;
es = AecDbEwPipeBase::dwgOutFields (pFiler) ;
if (es != Acad::eOk)
return (es);
//----- Object version number needs to be saved first
return _dwgOutFields_for_DBWeir(pFiler);
}
Acad::ErrorStatus AecDbBDPipeBase::_dwgInFields_for_DBWeir(AcDbDwgFiler * pFiler)
{
Acad::ErrorStatus es;
Adesk::UInt32 version = 0;
if ((es = pFiler->readUInt32(&version)) != Acad::eOk)
return (es);
if (version > AecDbBDPipeBase::kCurrentVersionNumber)
return (Acad::eMakeMeProxy);
TCHAR* pszTemp = NULL;
pFiler->readString(&pszTemp);
if (pszTemp != NULL)
{
m_sGUID = pszTemp;
acutDelString(pszTemp);
}
pFiler->readDouble(&m_dRotate[X]);
pFiler->readDouble(&m_dRotate[Y]);
pFiler->readDouble(&m_dRotate[Z]);
Adesk::UInt32 nLen = 0;
pFiler->readUInt32(&nLen);
m_arX3DPartPtrs.removeAll();
AecDbX3dPart* pPart = NULL;
for (int i = 0; i < nLen; i++)
{
pPart = new AecDbX3dPart;
pPart->dwgInFields(pFiler);
m_arX3DPartPtrs.append(pPart);
}
AcDbSoftPointerId id;
m_arAssocPartEntIds.removeAll();
nLen = 0;
pFiler->readUInt32(&nLen);
for (int i = 0; i < nLen; i++)
{
pFiler->readSoftPointerId(&id);
if (m_arAssocPartEntIds.find(id) == -1)
m_arAssocPartEntIds.append(id);
}
return (pFiler->filerStatus());
}
Acad::ErrorStatus AecDbBDPipeBase::_dwgOutFields_for_DBWeir(AcDbDwgFiler * pFiler) const
{
Acad::ErrorStatus es;
if ((es = pFiler->writeUInt32(AecDbBDPipeBase::kCurrentVersionNumber)) != Acad::eOk)
return (es);
pFiler->writeString((LPCTSTR)m_sGUID);
pFiler->writeDouble(m_dRotate[X]);
pFiler->writeDouble(m_dRotate[Y]);
pFiler->writeDouble(m_dRotate[Z]);
Adesk::UInt32 nLen = m_arX3DPartPtrs.length();
pFiler->writeUInt32(nLen);
for (int i = 0; i < nLen; i++)
{
const AecDbX3dPart* pPart = m_arX3DPartPtrs.at(i);
pPart->dwgOutFields(pFiler);
}
AcDbObjectId id;
AcDbObjectIdArray arAssocPartEntIds;
//先清理掉无效的
nLen = m_arAssocPartEntIds.length();
for (int i = 0; i < nLen; i++)
{
id = m_arAssocPartEntIds.at(i);
if (id.isValid())
{
if (arAssocPartEntIds.find(id) == -1)
arAssocPartEntIds.append(id);
}
}
nLen = arAssocPartEntIds.length();
pFiler->writeUInt32(nLen);
for (int i = 0; i < nLen; i++)
{
id = arAssocPartEntIds.at(i);
pFiler->writeSoftPointerId(id);
}
return (pFiler->filerStatus());
}
Acad::ErrorStatus AecDbBDPipeBase::dxfInFields(AcDbDxfFiler* pFiler)
{
return Acad::eOk;
}
Acad::ErrorStatus AecDbBDPipeBase::dxfOutFields(AcDbDxfFiler* pFiler) const
{
return Acad::eOk;
}
bool AecDbBDPipeBase::AppendAssocPart(const AcDbObjectId& id)
{
AssertWriteEnabled();
if (m_arAssocPartEntIds.find(id) == -1)
{
m_arAssocPartEntIds.append(id);
return true;
}
return false;
}
bool AecDbBDPipeBase::RemoveAssocPart(int nIndex)
{
AssertWriteEnabled();
if (nIndex > -1 && nIndex < m_arAssocPartEntIds.length())
{
m_arAssocPartEntIds.removeAt(nIndex);
return true;
}
return false;
}
bool AecDbBDPipeBase::RemoveAssocPart(const AcDbObjectId & id)
{
AssertWriteEnabled();
for (int i = 0; i < m_arAssocPartEntIds.length(); ++i)
{
if (id == m_arAssocPartEntIds[i])
return RemoveAssocPart(i);
}
return false;
}
int AecDbBDPipeBase::GetAssocPartCount() const
{
assertReadEnabled();
return m_arAssocPartEntIds.length();
}
bool AecDbBDPipeBase::GetAssocPart(int nIndex,AcDbObjectId& id) const
{
assertReadEnabled();
if (nIndex > -1 && nIndex < m_arAssocPartEntIds.length())
{
id = m_arAssocPartEntIds.at(nIndex);
return true;
}
return false;
}
bool AecDbBDPipeBase::GetAssocPartIds(AcDbObjectIdArray& arIds) const
{
assertReadEnabled();
if (!m_arAssocPartEntIds.isEmpty())
arIds.append(m_arAssocPartEntIds);
return !arIds.isEmpty();
}
void AecDbBDPipeBase::AssertWriteEnabled(Adesk::Boolean autoUndo,Adesk::Boolean recordModified )
{
AecDbEwPipeBase::AssertWriteEnabled(autoUndo,recordModified);
deleteArrayVoidPtrs< AcDbEntity>(m_arDTYG2DBufPtrs);
}
Acad::ErrorStatus AecDbBDPipeBase::subTransformBy(const AcGeMatrix3d& xform)
{
AssertWriteEnabled();
AecDbEwPipeBase::subTransformBy(xform);
AcDbObjectId id;
AcDbEntity* pEnt = NULL;
Acad::ErrorStatus es = Acad::eOk;
//只处理移动情况
AcGePoint3d ptOrg(0,0,0);
ptOrg.transformBy(xform);
int nvt(0);
AecDbX3dPart* pPart = NULL;
for (int i = 0;i < m_arX3DPartPtrs.length();i++)
{
pPart = (AecDbX3dPart*)m_arX3DPartPtrs.at(i);
if (pPart->GetSpecialtyData()->HasKey(_T("DTYG_TYPE"), nvt))
{
if (pPart->GetX3dSolidCount() <= 0) continue;
AcDbX3dSolid *pSolid(pPart->GetX3dSolid(0));
if (!pSolid) continue;
pSolid->TransformBy(xform);
pPart->Create();
}
else
{
pPart->AddMove(ptOrg.asVector());
}
}
return Acad::eOk;
}
void AecDbBDPipeBase::subList() const
{
assertReadEnabled();
AecDbEwPipeBase::subList();
TCHAR szHandle[256];
acutPrintf(_T("\n关联对象%d个."),m_arAssocPartEntIds.length());
for(int i = 0;i < m_arAssocPartEntIds.length();i++)
{
//#if ADS > 141
// m_arAssocPartEntIds.at(i).handle().getIntoAsciiBuffer(szHandle,256);
//#else
m_arAssocPartEntIds.at(i).handle().getIntoAsciiBuffer(szHandle);
//#endif
acutPrintf(_T("\n句柄 = %s"),szHandle);
}
for (int ii = 0;ii < m_arX3DPartPtrs.length();ii++)
{
const AecDbX3dPart* pPart = m_arX3DPartPtrs.at(ii);
pPart->List();
}
}
void AecDbBDPipeBase::GetDTYGs(std::vector<AecDbX3dPart*> &xparts)
{
int nVt(0);
CString sName(_T(""));
AecDbX3dPart* pPart = NULL;
for (int i = 0;i < m_arX3DPartPtrs.length();i++)
{
pPart = (AecDbX3dPart*)m_arX3DPartPtrs.at(i);
if (!pPart) continue;
if (pPart->GetSpecialtyData()->HasKey(_T("DTYG_TYPE"), nVt))
xparts.push_back(pPart);
}
}
void AecDbBDPipeBase::GetDTYGsByName(LPCTSTR pszName, std::vector<CString>& guids)
{
if (!pszName) return;
int nVt(0);
CString sName(_T(""));
AecDbX3dPart* pPart = NULL;
for (int i = 0;i < m_arX3DPartPtrs.length();i++)
{
pPart = (AecDbX3dPart*)m_arX3DPartPtrs.at(i);
if (!pPart) continue;
if (!pPart->GetSpecialtyData()->HasKey(_T("DTYG_TYPE"), nVt)) continue;
pPart->GetName(sName);
nVt = sName.Find(pszName);
if (nVt != -1)
guids.push_back(pPart->GetGUID());
}
}
bool AecDbBDPipeBase::TransformDTYGPartEnt(const AcGeMatrix3d & xform)
{
if (!objectId().isValid()) return false;
std::vector<AecDbX3dPart*> parts(0);
GetDTYGs(parts);
if (parts.empty()) return false;
CString sType(_T("")), sReg(_T(""));
std::vector<CString> regs1, regs2;
AcGePoint3d pt1, pt2, pOrg;
AcGeVector3d vt;
double d1, d2;
for (size_t i = 0; i < parts.size(); ++i)
{
AecDbX3dPart *pPart(parts[i]);
if (!pPart) continue;
if (pPart->GetX3dSolidCount() <= 0) continue;
if (!pPart->GetSpecialtyData()->GetAt(_T("DTYG_TYPE"), sType)) continue;
AcDbX3dSolid *pSolid(pPart->GetX3dSolid(0));
if (!pSolid) continue;
if (sType == _T("立方体")
|| sType == _T("圆柱")
|| sType == _T("圆台")
|| sType == _T("四方台")
|| sType == _T("楔形体")
|| sType == _T("球台")
|| sType == _T("球体") )
{
pOrg = pSolid->GetOrgPoint();
pOrg.transformBy(xform);
pSolid->SetOrgPoint(pOrg);
}
//else if (sType == _T("圆柱"))
//{
//}
//else if (sType == _T("圆台"))
//{
//}
//else if (sType == _T("四方台"))
//{
//}
//else if (sType == _T("楔形体"))
//{
//}
//else if (sType == _T("球台"))
//{
//}
//else if (sType == _T("球体"))
//{
//}
else if (sType == _T("拉伸体") || sType == _T("切割"))
{
if (!pSolid->GetExturd2Data(sReg, pt1, pt2)) continue;
AcDbRegion *pReg = CoreTools::StringToRegion(sReg);
if (pReg)
{
pReg->transformBy(xform);
pt1.transformBy(xform);
pt2.transformBy(xform);
if (CoreTools::RegionToString(pReg, sReg))
pSolid->SetExturd2Data(sReg, pt1, pt2);
DELETE_PTR(pReg);
}
}
else if (sType == _T("旋转体"))
{
if (!pSolid->GetRevolve2Data(sReg, pt1, vt, d1, d2)) continue;
AcDbRegion *pReg = CoreTools::StringToRegion(sReg);
if (pReg)
{
pReg->transformBy(xform);
AcDbRay ray;
ray.setUnitDir(vt);
ray.setBasePoint(pt1);
ray.transformBy(xform);
vt = ray.unitDir();
pt1 = ray.basePoint();
if (CoreTools::RegionToString(pReg, sReg))
pSolid->SetRevolve2Data(sReg, pt1, vt, d1, d2);
DELETE_PTR(pReg);
}
}
else if (sType == _T("放样体"))
{
regs1.clear();
regs2.clear();
if (!pSolid->GetLoftData(regs1)) continue;
for (size_t i = 0; i < regs1.size(); ++i)
{
CString &s = regs1[i];
AcDbRegion *pReg = CoreTools::StringToRegion(s);
if (pReg)
{
pReg->transformBy(xform);
if (CoreTools::RegionToString(pReg, sReg))
regs2.push_back(sReg);
DELETE_PTR(pReg);
}
}
pSolid->SetLoftData(regs2);
}
else if (sType == _T("扫掠体"))
{
AcDbCurve *pCurve(NULL);
if (pSolid->GetSweepData(sReg, pCurve))
{
AcDbRegion *pReg = CoreTools::StringToRegion(sReg);
if (pReg)
{
pReg->transformBy(xform);
pCurve->transformBy(xform);
if (CoreTools::RegionToString(pReg, sReg))
pSolid->SetSweepData(sReg, pCurve);
DELETE_PTR(pReg);
}
DELETE_PTR(pCurve);
}
}
else
{
continue;
}
pSolid->ReCreate();
pPart->Create();
}
return true;
}
Acad::ErrorStatus AecDbBDPipeBase::TransformAssocPartEnt(const AcGeMatrix3d& xform)
{
assertWriteEnabled();
AcDbObjectId id;
AcDbEntity* pEnt = NULL;
Acad::ErrorStatus es;
if (objectId().isValid())
{
for (int i = 0;i < m_arAssocPartEntIds.length();i++)
{
id = m_arAssocPartEntIds.at(i);
if ( Acad::eOk == (es = acdbOpenAcDbEntity(pEnt,id,AcDb::kForWrite)))
{
pEnt->transformBy(xform);
pEnt->close();
}
}
}
return Acad::eOk;
}
Acad::ErrorStatus AecDbBDPipeBase::HoleAndPipeExtend(double dThickAdd,const AcGeVector3d& vtAdd)
{
AcDbObjectId id;
AcDbEntity* pEnt = NULL;
Acad::ErrorStatus es;
if (objectId().isValid())
{
for (int i = 0;i < m_arAssocPartEntIds.length();i++)
{
id = m_arAssocPartEntIds.at(i);
if ( Acad::eOk == (es = acdbOpenAcDbEntity(pEnt,id,AcDb::kForWrite)))
{
AecDbX3dPartEntity* pPart = AecDbX3dPartEntity::cast(pEnt);
if (pPart != NULL)
{
pPart->HoleAndPipeExtend(dThickAdd,vtAdd);
}
pEnt->close();
}
}
}
return Acad::eOk;
}
Acad::ErrorStatus AecDbBDPipeBase::subGetOsnapPoints( AcDb::OsnapMode osnapMode,
INT_PTR gsSelectionMark,
const AcGePoint3d& pickPoint,
const AcGePoint3d& lastPoint,
const AcGeMatrix3d& viewXform,
AcGePoint3dArray& snapPoints,
AcDbIntArray& geomIds) const
{
assertReadEnabled();
return AecDbEwPipeBase::subGetOsnapPoints(osnapMode,gsSelectionMark,pickPoint,lastPoint,viewXform,snapPoints,geomIds);
}
Acad::ErrorStatus AecDbBDPipeBase::subErase(Adesk::Boolean erasing)
{
if (erasing)
{
AcDbObjectId id;
AcDbEntity* pEnt = NULL;
Acad::ErrorStatus es;
for (int i = 0;i < m_arAssocPartEntIds.length();i++)
{
id = m_arAssocPartEntIds.at(i);
if ( Acad::eOk == (es = acdbOpenAcDbEntity(pEnt,id,AcDb::kForWrite)))
{
pEnt->erase(erasing);
pEnt->close();
}
}
}
return AecDbEwPipeBase::subErase(erasing);
}
void AecDbBDPipeBase::erased(const AcDbObject* dbObj,Adesk::Boolean pErasing/* = true*/)
{
//acutPrintf(_T("ent:%s erased!"),dbObj->isA()->name());
if (dbObj != NULL)
{
if (dbObj->isKindOf(AecDbX3dPartEntity::desc()))
{
//重新刷新三维
Clean3DBuffer();
if (!cloneMeForDragging())
{
acedPostCommand(_T("regen "));
}
}
}
}
void AecDbBDPipeBase::modified(const AcDbObject* dbObj)
{
if (dbObj != NULL)
{
if (dbObj->isKindOf(AecDbX3dPartEntity::desc()))
{
//重新刷新三维
Clean3DBuffer();
if (!cloneMeForDragging())
{
acedPostCommand(_T("regen "));
}
}
}
}
void AecDbBDPipeBase::modifyUndone(const AcDbObject* dbObj)
{
if (dbObj != NULL)
{
if (dbObj->isKindOf(AecDbX3dPartEntity::desc()))
{
//重新刷新三维
Clean3DBuffer();
if (!cloneMeForDragging())
{
acedPostCommand(_T("regen "));
}
}
}
}
//添加套管符号
void AecDbBDPipeBase::AddTPipeDim(const AcGeVector3d& vtNorm,AcDbLine* pLnCen,AecDbObjXDataMap* pxDataT,AcDbVoidPtrArray& arEntPtrs,const AcGeMatrix3d& xform) const
{
if (pLnCen != NULL && pxDataT != NULL)
{
AcDbObjectId idPipe = KTSetting::InitLayer(LAY_PIPE_OUTSIDE);
AcGePoint3d ptS = pLnCen->startPoint();
AcGePoint3d ptE = pLnCen->endPoint();
AcGeVector3d vtLn = ptE - ptS;
vtLn.normalize();
if (vtLn.isPerpendicularTo(vtNorm))//
{
AcGeVector3d vtXY = vtLn.crossProduct(vtNorm);
vtXY.normalize();
AcGePoint3d pt1,pt2,ptGe[2];
CString sType;
int nShape = 0,bNoDraw = 0;
pxDataT->GetAt(_T("nShape"),nShape);
pxDataT->GetAt(KEY_CENNODRAW,bNoDraw);
pxDataT->GetAt(KEY_PIPETYPE, sType);
if (bNoDraw)//中心线不画标识
{
return;
}
if (nShape == eCircle)//circle
{
AcGePoint3d pts[2], pte[2];
double dD = 0.0,dT = 0.0;
pxDataT->GetAt(_T("dD"),dD);
pxDataT->GetAt(_T("dH"),dT);
pt1 = MidPoint(ptS,ptE);
pt1 += vtXY * 0.5 * dD;
ptGe[0] = pt1 - vtLn * 0.5 * dT;
ptGe[1] = pt1 + vtLn * 0.5 * dT;
AcDbLine* pLn = new AcDbLine(ptGe[0],ptGe[1]);
pLn->transformBy(xform);
pLn->setLayer(idPipe);
if (pxDataT != NULL)
{
pxDataT->Write(pLn,BIMDATA_APP);
}
arEntPtrs.append(pLn);
pts[0] = ptGe[0];
pte[0] = ptGe[1];
ptGe[0] = pt1;
ptGe[1] = pt1 + vtXY * 0.15 * dD;
pLn = new AcDbLine(ptGe[0],ptGe[1]);
pLn->transformBy(xform);
pLn->setLayer(idPipe);
if (pxDataT != NULL)
{
pxDataT->Write(pLn,BIMDATA_APP);
}
arEntPtrs.append(pLn);
pt1 -= vtXY * dD;
ptGe[0] = pt1 - vtLn * 0.5 * dT;
ptGe[1] = pt1 + vtLn * 0.5 * dT;
pLn = new AcDbLine(ptGe[0],ptGe[1]);
pLn->transformBy(xform);
pLn->setLayer(idPipe);
if (pxDataT != NULL)
{
pxDataT->Write(pLn,BIMDATA_APP);
}
arEntPtrs.append(pLn);
pts[1] = ptGe[0];
pte[1] = ptGe[1];
ptGe[0] = pt1;
ptGe[1] = pt1 - vtXY * 0.15 * dD;
pLn = new AcDbLine(ptGe[0],ptGe[1]);
pLn->transformBy(xform);
pLn->setLayer(idPipe);
if (pxDataT != NULL)
{
pxDataT->Write(pLn,BIMDATA_APP);
}
arEntPtrs.append(pLn);
if (sType.Find(_T("柔性")) != -1)
{
ptGe[0] = pts[0];
ptGe[1] = pts[0] + vtXY * 0.15 * dD;
pLn = new AcDbLine(ptGe[0], ptGe[1]);
pLn->transformBy(xform);
pLn->setLayer(idPipe);
if (pxDataT != NULL)
{
pxDataT->Write(pLn, BIMDATA_APP);
}
arEntPtrs.append(pLn);
ptGe[0] = pte[0];
ptGe[1] = pte[0] + vtXY * 0.15 * dD;
pLn = new AcDbLine(ptGe[0], ptGe[1]);
pLn->transformBy(xform);
pLn->setLayer(idPipe);
if (pxDataT != NULL)
{
pxDataT->Write(pLn, BIMDATA_APP);
}
arEntPtrs.append(pLn);
ptGe[0] = pts[1];
ptGe[1] = pts[1] - vtXY * 0.15 * dD;
pLn = new AcDbLine(ptGe[0], ptGe[1]);
pLn->transformBy(xform);
pLn->setLayer(idPipe);
if (pxDataT != NULL)
{
pxDataT->Write(pLn, BIMDATA_APP);
}
arEntPtrs.append(pLn);
ptGe[0] = pte[1];
ptGe[1] = pte[1] - vtXY * 0.15 * dD;
pLn = new AcDbLine(ptGe[0], ptGe[1]);
pLn->transformBy(xform);
pLn->setLayer(idPipe);
if (pxDataT != NULL)
{
pxDataT->Write(pLn, BIMDATA_APP);
}
arEntPtrs.append(pLn);
}
}
else//rect
{
double dH = 0.0,dW = 0.0,dT = 0.0;
pxDataT->GetAt(_T("dW"),dH);
pxDataT->GetAt(_T("dL"),dW);
pxDataT->GetAt(_T("dH"),dT);
double dD = dH;
if (vtNorm.isParallelTo(AcGeVector3d::kZAxis))
dD = dW;
pt1 = MidPoint(ptS,ptE);
pt1 += vtXY * 0.5 * dD;
ptGe[0] = pt1 - vtLn * 0.5 * dT;
ptGe[1] = pt1 + vtLn * 0.5 * dT;
AcDbLine* pLn = new AcDbLine(ptGe[0],ptGe[1]);
pLn->transformBy(xform);
pLn->setLayer(idPipe);
if (pxDataT != NULL)
{
pxDataT->Write(pLn,BIMDATA_APP);
}
arEntPtrs.append(pLn);
ptGe[0] = pt1;
ptGe[1] = pt1 + vtXY * 0.15 * dD;
pLn = new AcDbLine(ptGe[0],ptGe[1]);
pLn->transformBy(xform);
pLn->setLayer(idPipe);
if (pxDataT != NULL)
{
pxDataT->Write(pLn,BIMDATA_APP);
}
arEntPtrs.append(pLn);
pt1 -= vtXY * dD;
ptGe[0] = pt1 - vtLn * 0.5 * dT;
ptGe[1] = pt1 + vtLn * 0.5 * dT;
pLn = new AcDbLine(ptGe[0],ptGe[1]);
pLn->transformBy(xform);
pLn->setLayer(idPipe);
if (pxDataT != NULL)
{
pxDataT->Write(pLn,BIMDATA_APP);
}
arEntPtrs.append(pLn);
ptGe[0] = pt1;
ptGe[1] = pt1 - vtXY * 0.15 * dD;
pLn = new AcDbLine(ptGe[0],ptGe[1]);
pLn->transformBy(xform);
pLn->setLayer(idPipe);
if (pxDataT != NULL)
{
pxDataT->Write(pLn,BIMDATA_APP);
}
arEntPtrs.append(pLn);
}
}
}
}
void AddRegionPolyline(AcDbRegion *pRegionT, AcDbVoidPtrArray &arRegionPtrs, const AecDbObjXDataMap &mapSetup);
void ConvertToPolyline(const AecDbObjXDataMap &mapSetup,AcDbVoidPtrArray& arCurPtrs, AcDbVoidPtrArray &arRegionPtrs)
{
double dWallW = 0.0;
mapSetup.GetAt(KEY_WALLW, dWallW);
AcDbEntity *pEnt = NULL;
for (int i = 0; i < arCurPtrs.length(); i++)
{
pEnt = (AcDbEntity *)arCurPtrs.at(i);
AcDbLine *pLn = AcDbLine::cast(pEnt);
AcDbPolyline *pPlT = AcDbPolyline::cast(pEnt);
AcDbRegion *pReg = AcDbRegion::cast(pEnt);
AcDbSpline *pSp = AcDbSpline::cast(pEnt);
//acutPrintf(_T("\nClass:%s"),pEnt->isA()->name());
if (pLn != NULL)
{
AcDbPolyline *pPl = new AcDbPolyline;
pPl->addVertexAt(0, pLn->startPoint().convert2d(AcGePlane::kXYPlane));
pPl->addVertexAt(1, pLn->endPoint().convert2d(AcGePlane::kXYPlane));
pPl->setConstantWidth(dWallW);
arRegionPtrs.append(pPl);
}
else if (pPlT != NULL)
{
pPlT->setConstantWidth(dWallW);
arRegionPtrs.append(pPlT);
}
else if (pReg != NULL)
{
AddRegionPolyline(pReg, arRegionPtrs, mapSetup);
}
else if (pSp != NULL)
{
AcDbCurve *pPlCrv = NULL;
pSp->toPolyline(pPlCrv);
if (pPlCrv != NULL)
{
AcDbPolyline *pPl = AcDbPolyline::cast(pPlCrv);
if (pPl != NULL)
{
pPl->setConstantWidth(dWallW);
arRegionPtrs.append(pPl);
}
else
{
//acutPrintf(_T("\nClass:%s"),pPlCrv->isA()->name());
arRegionPtrs.append(pPlCrv);
}
}
}
else
{
//acutPrintf(_T("\nClass:%s"),pEnt->isA()->name());
arRegionPtrs.append(pEnt);
}
}
}
void AddRegionPolyline(AcDbRegion* pRegionT,AcDbVoidPtrArray& arRegionPtrs,const AecDbObjXDataMap& mapSetup)
{
if (pRegionT != NULL)
{
AcDbVoidPtrArray arCurPtrs;
pRegionT->explode(arCurPtrs);
ConvertToPolyline(mapSetup,arCurPtrs,arRegionPtrs);
}
}
AcGeBoundBlock3d *CreateExtent3dBound(const AcGePoint3d &ptFr, const AcGePoint3d &ptTo, const AcGeVector3d &vtTo)
{
AcGeVector3d vt1 = ptTo - ptFr;
AcGeVector3d vtZ = vt1.crossProduct(vtTo);
vtZ.normalize();
AcGePoint3d ptGe[5];
ptGe[0] = ptFr + vtZ * 1.e6;//1000米
ptGe[1] = ptFr - vtZ * 1.e6;//1000米
ptGe[2] = ptTo - vtZ * 1.e6;//1000米
ptGe[3] = ptTo + vtZ * 1.e6;//1000米
ptGe[4] = ptGe[0];
vt1 = ptGe[1] - ptGe[0];
AcGeVector3d vt2 = ptGe[3] - ptGe[0];
AcGeVector3d vt3 = vtTo;
AcGeBoundBlock3d *pBound = new AcGeBoundBlock3d;
pBound->set(ptGe[0], vt1, vt2, vt3);
return pBound;
}
AcDb3dSolid * CreateExtent3dBox(const AcGePoint3d& ptFr, const AcGePoint3d& ptTo, const AcGeVector3d& vtTo)
{
AcGeVector3d vt1 = ptTo - ptFr;
AcGeVector3d vtZ = vt1.crossProduct(vtTo);
vtZ.normalize();
AcGePoint3d ptGe[5];
ptGe[0] = ptFr + vtZ * 1.e6;//1000米
ptGe[1] = ptFr - vtZ * 1.e6;//1000米
ptGe[2] = ptTo - vtZ * 1.e6;//1000米
ptGe[3] = ptTo + vtZ * 1.e6;//1000米
ptGe[4] = ptGe[0];
AcGePoint3d ptS = MidPoint(ptGe[0], ptGe[2]);
AcGePoint3d ptE = ptS + vtTo;
AcDbLine ln;
ln.setStartPoint(ptS);
ln.setEndPoint(ptE);
AcDbRegion *pRegionT = CreatePolygonRegionOnly(ptGe, 5);
if (pRegionT != NULL)
{
AcDb3dSolid *pSolidBox = new AcDb3dSolid;
if (Acad::eOk == pSolidBox->extrudeAlongPath(pRegionT, &ln))
{
delete pRegionT;
return pSolidBox;
}
delete pRegionT;
}
return NULL;
}
//包含素砼的剖切
int AecDbBDPipeBase::GetSectionDraw(const AcGePoint3d &ptFr, const AcGePoint3d &ptTo, const AcGeVector3d &vtViewDir, const AcGeVector3d &vtTo, AcDbVoidPtrArray &arRegionPtrs) const
{
assertReadEnabled();
int nIndexFr = arRegionPtrs.length();
AecDbObjXDataMap mapSetup;
const AecDbObjXDataMap *pSpecXData = GetSpecialtyData();
pSpecXData->GetAt(KEY_PQSZ, 9999, mapSetup);
BOOL bHatch = FALSE;
mapSetup.GetAt(KEY_QLBZHATCH, bHatch);
bHatch = AecDbEwPipeBase::hasHatch(this, bHatch);
//如果仅仅是切
AcDb3dSolid *pDraw3dSolid = NULL;
if (vtTo.isZeroLength())
{
if (Get3DBuffer().length() == 0)
{
AcGiViewDraw dc(NULL, NULL);
Draw3d(dc);
}
pDraw3dSolid = GetDraw3dSolid(false);
if (pDraw3dSolid != NULL)
{
//三维求交
AcDb3dSolid *pSolid3dExt = CreateExtent3dBox(ptFr, ptTo, vtTo);
if (pSolid3dExt != NULL)
{
if (Acad::eOk != pDraw3dSolid->booleanOper(AcDb::kBoolIntersect, pSolid3dExt))
{
pDraw3dSolid = GetDraw3dSolid(false);
}
}
AcGeBoundBlock3d *pBound3d = CreateExtent3dBound(ptFr, ptTo, vtTo);
AcDbRegion *pRegionT = NULL;
AcGeVector3d vtLn = ptTo - ptFr;
AcGeVector3d vtNorm = vtLn.crossProduct(vtViewDir);
AcGePlane plan;
plan.set(ptFr, vtNorm);
pDraw3dSolid->getSection(plan, pRegionT);
if (pRegionT != NULL)//可切
{
AcGeMatrix3d xformPlanToWorld;
xformPlanToWorld.setToPlaneToWorld(plan);
xformPlanToWorld.invert();
pRegionT->transformBy(xformPlanToWorld);
pRegionT->setLayer(layerId());
AddRegionPolyline(pRegionT, arRegionPtrs, mapSetup);
//arRegionPtrs.append(pRegionT);
//填充
AcDbVoidPtrArray arHatchPtrs;
if (bHatch)
{
CString sPattern;
GetSectionHatchPattern(sPattern);
RegionHatch(pRegionT, arHatchPtrs, sPattern);
if (!arHatchPtrs.isEmpty())
{
arRegionPtrs.append(arHatchPtrs);
}
}
SetSectionLayer(nIndexFr, arRegionPtrs, layerId());
nIndexFr = arRegionPtrs.length();
//附属物
AcDbVoidPtrArray arSolidPtrs, arCenLnPtrs;
GetAllHolesSolid(arSolidPtrs, arCenLnPtrs, xformPlanToWorld, pBound3d);
CString sName;
AecDbObjXDataMap xDataT;
AcDbLine *pLnCen = NULL;
for (int ii = 0; ii < arCenLnPtrs.length(); ii++)
{
AcDbEntity *pCenEnt = (AcDbEntity *)arCenLnPtrs.at(ii);
//根据arCenLnPtrs 绘制套管
xDataT.Empty();
xDataT.Read(pCenEnt, BIMDATA_APP);
if (xDataT.GetAt(KEY_NAME, sName))
{
if (sName.CompareNoCase(_T("套管")) == 0)
{
//添加套管符号
pLnCen = AcDbLine::cast(pCenEnt);
if (pLnCen != NULL)
AddTPipeDim(plan.normal(), pLnCen, &xDataT, arRegionPtrs, xformPlanToWorld);
}
}
pCenEnt->transformBy(xformPlanToWorld);
AcDbObjectId idLt = pCenEnt->linetypeId();
if (idLt != KTSetting::InitLineStyle(_T("DASH")))
{
pCenEnt->setLayer(KTSetting::InitLayer(_T("LAY_CL"), true));
pCenEnt->setLinetype(KTSetting::InitLineStyle(_T("CENTER")));
}
arRegionPtrs.append(pCenEnt);
}
AcDb3dSolid *pSolidT = NULL;
AcDbEntity *pEntT = NULL;
for (int k = 0; k < arSolidPtrs.length(); k++)
{
pEntT = (AcDbEntity *)arSolidPtrs.at(k);
pSolidT = AcDb3dSolid::cast(pEntT);
if (pSolidT != NULL)
{
pRegionT = NULL;
pSolidT->getSection(plan, pRegionT);
if (pRegionT != NULL)
{
pRegionT->transformBy(xformPlanToWorld);
pRegionT->setLayer(pSolidT->layer());
//如果是套管标注
pRegionT->setLayer(layerId());
arRegionPtrs.append(pRegionT);
}
delete pSolidT;
}
}
}
delete pDraw3dSolid;
delete pBound3d;
}
return arRegionPtrs.length();
}
AcGePlane plan;
AcGeVector3d vtU = ptTo - ptFr;
Acad::ErrorStatus es = Acad::eOk;
plan.set(ptFr, vtU, vtViewDir);
if (AecDbEwPipeBase::GetSectionDraw(plan, vtTo, arRegionPtrs))
{
SetSectionLayer(nIndexFr, arRegionPtrs, layerId());
return arRegionPtrs.length();
}
AcGePlane plan2;
plan2.set(ptFr, vtTo);
AcGeMatrix3d xform;
xform.setToPlaneToWorld(plan);
xform.invert();
if (Get3DBuffer().length() == 0)
{
AcGiViewDraw dc(NULL, NULL);
Draw3d(dc);
}
pDraw3dSolid = GetDraw3dSolid(false);
if (pDraw3dSolid == NULL)
{
SetSectionLayer(nIndexFr, arRegionPtrs, layerId());
return 0;
}
//三维求交
AcDb3dSolid *pSolid3dExt = CreateExtent3dBox(ptFr, ptTo, vtTo);
if (pSolid3dExt != NULL)
{
if (Acad::eOk != pDraw3dSolid->booleanOper(AcDb::kBoolIntersect, pSolid3dExt))
{
pDraw3dSolid = GetDraw3dSolid(false);
}
}
AcDbExtents ext;
pDraw3dSolid->getGeomExtents(ext);
double dX = ext.maxPoint().x - ext.minPoint().x;
double dY = ext.maxPoint().y - ext.minPoint().y;
double dz = ext.maxPoint().z - ext.minPoint().z;
double dMaxL = __max(dX, dY);
dMaxL = __max(dMaxL, dz);
dMaxL += 200.0;
AcGePoint3d ptGe[5];
ptGe[0] = ptFr;
ptGe[1] = ptTo;
ptGe[2] = ptTo + vtTo;
ptGe[3] = ptFr + vtTo;
ptGe[4] = ptGe[0];
AcGeVector3d vtLook = vtViewDir;
//提取8个点
AcGePoint3d ptGeT[8];
AcGePoint3dArray arBoxPts;
ptGeT[0] = ext.minPoint();
ptGeT[1] = ptGeT[0];
ptGeT[1].x = ext.maxPoint().x;
ptGeT[2] = ptGeT[1];
ptGeT[2].y = ext.maxPoint().y;
ptGeT[3] = ptGeT[0];
ptGeT[3].y = ext.maxPoint().y;
for (int i = 0; i < 4; i++)
{
arBoxPts.append(ptGeT[i]);
ptGeT[i].z = ext.maxPoint().z;
arBoxPts.append(ptGeT[i]);
}
AcDbLine ln3d;
ln3d.setStartPoint(arBoxPts.first());
AcGePoint3d ptE = arBoxPts.first() + vtViewDir * 1.5;
ln3d.setEndPoint(ptE);
AecCoverBooleanOper::SortPoints(arBoxPts, &ln3d, true);
AcGePoint3d ptNear = arBoxPts.last();
AcGePoint3d ptFar = arBoxPts.first();
AcGePoint3d ptMid = MidPoint(ptNear, ptFar);
AcGeVector3d vtN2F = ptFar - ptNear;
vtN2F *= 0.6;
ptFar = ptMid + vtN2F;
ptNear = ptMid - vtN2F;
vtN2F *= 2.0;
AcGePlane planNear(ptNear, vtLook);
AcGePoint3d ptOnMin;
ptOnMin = planNear.closestPointTo(ptGe[0]);
//调整到Near面
AcGeVector3d vtM = ptOnMin - ptGe[0];
for (int k = 0; k < 5; k++)
{
ptGe[k] += vtM;
}
//Near-->Far 拉伸路径
AcDbLine lnPath;
lnPath.setStartPoint(ptGe[0]);
ptE = ptGe[0] + vtN2F;
lnPath.setEndPoint(ptE);
struct resbuf rb;
acedGetVar(_T("useri3"), &rb);
AcDbRegion *pRegionT = CreatePolygonRegionOnly(ptGe, 5);
if (pRegionT != NULL)
{
AcDb3dSolid *pSolidBox = new AcDb3dSolid;
if (Acad::eOk == pSolidBox->extrudeAlongPath(pRegionT, &lnPath))
{
pSolidBox->setColorIndex(kRed);
if (rb.resval.rint == 1358)//特定情况下
{
//TEST
AcDb3dSolid *pSolidBoxCn = (AcDb3dSolid *)pSolidBox->clone();
pSolidBoxCn->setColorIndex(kRed);
AddToModelSpace(pSolidBoxCn);
}
}
else
{
if (rb.resval.rint == 1358)//特定情况下
{
//TEST
pRegionT->setColorIndex(kRed);
AddToModelSpace(pRegionT);
return 0;
}
}
AcGeBoundBlock3d* pBound3d = CreateExtent3dBound(ptFr,ptTo,vtTo);
AcDb3dSolid *pSolidBoxCln = (AcDb3dSolid *)pSolidBox->clone();
AcDb3dSolid *pSolidCln = (AcDb3dSolid *)pDraw3dSolid->clone();
pSolidCln->setRecordHistory(true);
pSolidCln->booleanOper(AcDb::kBoolIntersect, pSolidBox);
AcDbVoidPtrArray arRegPtrs;
//如果plan和 pSolidCln 相交
//根据材质填充,如果切到的墙体
AcDbRegion *pRegionSec = NULL;
pSolidCln->getSection(plan, pRegionSec);
if (pRegionSec != NULL)
{
pRegionSec->transformBy(xform);
AddRegionPolyline(pRegionSec, arRegionPtrs, mapSetup);
//arRegPtrs.append(pRegionSec);
//由于pSolidCln->booleanOper(AcDb::kBoolIntersect, pSolidBox); 再投影补上洞口线
AcDbVoidPtrArray arTemp;
OrthoProjected3DSolid(pSolidCln, plan, xform, arTemp);
ConvertToPolyline(mapSetup,arTemp, arRegionPtrs);
AcDbVoidPtrArray arHatchPtrs;
if (bHatch)
{
CString sPattern;
GetSectionHatchPattern(sPattern);
RegionHatch(pRegionSec, arHatchPtrs, sPattern);
if (!arHatchPtrs.isEmpty())
{
arRegionPtrs.append(arHatchPtrs);
}
}
delete pRegionSec;
AcDbVoidPtrArray arSolidPtrs, arCenLnPtrs;
GetAllHolesSolid(arSolidPtrs, arCenLnPtrs, xform,pBound3d);
CString sName;
AecDbObjXDataMap xDataT;
AcDbLine *pLnCen = NULL;
for (int ii = 0; ii < arCenLnPtrs.length(); ii++)
{
AcDbEntity *pCenEnt = (AcDbEntity *)arCenLnPtrs.at(ii);
if (pCenEnt != NULL)
{
//根据arCenLnPtrs 绘制套管
xDataT.Empty();
xDataT.Read(pCenEnt, BIMDATA_APP);
if (xDataT.GetAt(KEY_NAME, sName))
{
if (sName.CompareNoCase(_T("套管")) == 0)
{
//添加套管符号
pLnCen = AcDbLine::cast(pCenEnt);
if (pLnCen != NULL)
AddTPipeDim(plan.normal(), pLnCen, &xDataT, arRegionPtrs, xform);
}
}
pCenEnt->transformBy(xform);
AcDbObjectId idLt = pCenEnt->linetypeId();
if (idLt != KTSetting::InitLineStyle(_T("DASH")))
{
pCenEnt->setLayer(KTSetting::InitLayer(_T("LAY_CL"), true));
pCenEnt->setLinetype(KTSetting::InitLineStyle(_T("CENTER")));
}
arRegPtrs.append(pCenEnt);
}
}
AcDb3dSolid *pSolidT = NULL;
AcDbEntity *pEntT = NULL;
for (int k = 0; k < arSolidPtrs.length(); k++)
{
pEntT = (AcDbEntity *)arSolidPtrs.at(k);
pSolidT = AcDb3dSolid::cast(pEntT);
if (pSolidT != NULL)
{
//如果是门窗洞口,则不加getSection结果,门窗已经用符号代替
if (pSolidT->visibility() == AcDb::kInvisible)
{
delete pSolidT;
continue;
}
pRegionSec = NULL;
pSolidT->getSection(plan, pRegionSec);
if (pRegionSec != NULL)
{
pRegionSec->transformBy(xform);
pRegionSec->setLayer(layerId());
AddRegionPolyline(pRegionSec, arRegionPtrs, mapSetup);
//arRegPtrs.append(pRegionSec);
delete pRegionSec;
}
delete pSolidT;
}
}
}
else
{
//不科切,投影
AcDbVoidPtrArray arSolidPtrs, arCenLnPtrs;
GetAllHolesSolid(arSolidPtrs, arCenLnPtrs, xform, pBound3d);
FreeBuffer(0, arSolidPtrs);
CString sName;
AecDbObjXDataMap xDataT;
for (int kk = 0; kk < arCenLnPtrs.length(); kk++)
{
AcDbEntity *pEntT = (AcDbEntity *)arCenLnPtrs.at(kk);
if (pEntT != NULL)
{
//根据arCenLnPtrs 绘制套管
xDataT.Empty();
xDataT.Read(pEntT, BIMDATA_APP);
if (xDataT.GetAt(KEY_NAME, sName))
{
if (sName.CompareNoCase(_T("套管")) == 0)
{
//添加套管符号
AcDbLine *pLn = AcDbLine::cast(pEntT);
if (pLn != NULL)
AddTPipeDim(plan.normal(), pLn, &xDataT, arRegPtrs, xform);
}
}
pEntT->transformBy(xform);
}
}
//投影
OrthoProjected3DSolid(pSolidCln, plan, xform, arRegPtrs);
if (!arCenLnPtrs.isEmpty())
arRegPtrs.append(arCenLnPtrs);
}
if (rb.resval.rint == 1358)//特定情况下
{
//TEST
pSolidCln->setColorIndex(kRed);
AddToModelSpace(pSolidCln);
}
else
{
DELETE_PTR(pSolidCln);
}
DELETE_PTR(pRegionT);
DELETE_PTR(pSolidBox);
DELETE_PTR(pBound3d);
if (!arRegPtrs.isEmpty())
{
arRegionPtrs.append(arRegPtrs);
}
if (rb.resval.rint == 1358)//特定情况下
{
//TEST
pDraw3dSolid->setColorIndex(3);
AddToModelSpace(pDraw3dSolid);
}
else
{
DELETE_PTR(pDraw3dSolid);
}
}
SetSectionLayer(nIndexFr, arRegionPtrs, layerId());
return arRegionPtrs.length();
}
Acad::ErrorStatus AecDbBDPipeBase::GetAllHolesSolid(AcDbVoidPtrArray& arSolidPtrs,AcDbVoidPtrArray& arCenLnPtrs,const AcGeMatrix3d& xform, AcGeBoundBlock3d* pExt3d/* = NULL*/) const
{
assertReadEnabled();
AcDb3dSolid* pSolidDraw = GetDraw3dSolid(false,0,false);
if (pSolidDraw != NULL)
{
AcDb3dSolid* pSolidDrawCln = NULL;
//开洞
//2.在开除关联的part的对象
AcDb3dSolid* pSolidPart = NULL;
AcDbObjectId id;
AcDbEntity* pEnt = NULL;
Acad::ErrorStatus es;
AcDb3dSolid* pSolidT = NULL;
AcDbEntity* pEntT = NULL;
double dH = 0.0;
AcGeVector3d vtZ;
CString sName;
AcGePoint3d ptOrg,ptSta,ptEnd;
for (int i = 0;i < m_arAssocPartEntIds.length();i++)
{
id = m_arAssocPartEntIds.at(i);
if ( Acad::eOk == (es = acdbOpenAcDbEntity(pEnt,id,AcDb::kForRead)))
{
AecDbX3dPartEntity* pPartEnt = AecDbX3dPartEntity::cast(pEnt);
if (pPartEnt != NULL)
{
sName = pPartEnt->GetName();
//1.绘制洞口的中心线,符号线
if ( pPartEnt->GetSpecialtyData(AcDb::kForRead)->GetAt(_T("vtDir"),vtZ) )
{
ptOrg = pPartEnt->GetOrgPoint(true);
pPartEnt->GetSpecialtyData(AcDb::kForRead)->GetAt(_T("dH"),dH);
if (pExt3d != NULL)
{
AcDbVoidPtrArray arSolidPtrs;
pPartEnt->GetForHouseSubtract(arSolidPtrs);
if (!arSolidPtrs.isEmpty())
{
AcDbEntity *pEntS = (AcDbEntity*)arSolidPtrs.first();
AcDbExtents ext;
pEntS->getGeomExtents(ext);
AcGeBoundBlock3d blk;
blk.set(ext.minPoint(), ext.maxPoint());
if (pExt3d->isDisjoint(blk))
{
continue;
}
}
FreeBuffer(0, arSolidPtrs);
}
vtZ.normalize();
ptSta = ptOrg - vtZ * 1.2 * dH;
ptEnd = ptOrg + vtZ * 1.2 * dH;
AcDbLine* pLn = new AcDbLine(ptSta,ptEnd);//中心线
pLn->setLayer(KTSetting::InitLayer(_T("LAY_CL"),true));
pLn->setLinetype(KTSetting::InitLineStyle(_T("CENTER")));
AcDbPoint *pPt = new AcDbPoint;
pPt->setPosition(ptOrg);
pPt->setNormal(vtZ);
pPt->setLayer(KTSetting::InitLayer(_T("LAY_CL"), true));
AecDbObjXDataMap* pXData = pPartEnt->GetSpecialtyData(AcDb::kForRead);
if (pXData != NULL)
{
AecDbObjXDataMap xData;
xData.CopyFrom(pXData);
if (sName.CompareNoCase(_T("开洞")) == 0 || //开洞
sName.CompareNoCase(_T("套管")) == 0) //套管
{
//洞口或套管写标高
AecInterface inf;
if ( pPartEnt->GetInterface(0,inf) )
{
int nShap = 0;
xData.GetAt(_T("nShape"),nShap);//圆
if (inf.vtDir.isParallelTo(AcGeVector3d::kZAxis))
{
if (nShap == (int)eCircle)
{
xData.SetAt(KEY_CENEL,inf.ptPos.z);
}
else
{
xData.SetAt(KEY_BOTMEL,inf.ptPos.z);
}
}
else
{
if (nShap == (int)eCircle)
{
xData.SetAt(KEY_CENEL,inf.ptPos.z);
}
else
{
xData.SetAt(KEY_BOTMEL,inf.ptPos.z - 0.5 * inf.dSize2);
}
}
}
}
xData.SetAt(KEY_NAME,sName);
xData.SetAt(KEY_ORGPT,ptOrg);
xData.Write(pLn,BIMDATA_APP);
xData.Write(pPt, BIMDATA_APP);
}
arCenLnPtrs.append(pLn);
arCenLnPtrs.append(pPt);
vtZ.transformBy(xform);
AcGeLine3d ln(AcGePoint3d::kOrigin,vtZ);
if (AcGePlane::kXYPlane.isPerpendicularTo(ln))//垂直XY面
{
ptSta = ptOrg - AcGeVector3d::kXAxis * 1.2 * dH;
ptEnd = ptOrg + AcGeVector3d::kXAxis * 1.2 * dH;
pLn = new AcDbLine(ptSta,ptEnd);//中心线
pLn->setLayer(KTSetting::InitLayer(_T("LAY_CL"),true));
pLn->setLinetype(KTSetting::InitLineStyle(_T("CENTER")));
if (pXData != NULL)
{
AecDbObjXDataMap xData;
xData.CopyFrom(pXData);
xData.SetAt(KEY_NAME,sName);
if (sName.CompareNoCase(_T("开洞")) == 0 || //开洞
sName.CompareNoCase(_T("套管")) == 0) //套管
{
//洞口或套管写标高
AecInterface inf;
if ( pPartEnt->GetInterface(0,inf) )
{
int nShap = 0;
xData.GetAt(_T("nShape"),nShap);//圆
if (inf.vtDir.isParallelTo(AcGeVector3d::kZAxis))
{
if (nShap == (int)eCircle)
{
xData.SetAt(KEY_CENEL,inf.ptPos.z);
}
else
{
xData.SetAt(KEY_BOTMEL,inf.ptPos.z);
}
}
else
{
if (nShap == (int)eCircle)
{
xData.SetAt(KEY_CENEL,inf.ptPos.z);
}
else
{
xData.SetAt(KEY_BOTMEL,inf.ptPos.z - 0.5 * inf.dSize2);
}
}
//垂直XY面 绘制洞口示意 V线 矩形洞;
if (nShap == (int)eRect && sName.CompareNoCase(_T("开洞")) == 0)
{
double dL = 0, dW = 0;
xData.GetAt(_T("dL"), dL);
xData.GetAt(_T("dW"), dW);
xData.GetAt(_T("vtDir"), vtZ);
AcGeLine3d lnZ;
lnZ.set(ptOrg, vtZ);
if (AcGePlane::kXYPlane.isParallelTo(lnZ)) //洞中心方向线水平
{
AcGeVector3d vtX = vtZ;
vtX.rotateBy(-PI / 2.0, AcGeVector3d::kZAxis);
vtX.normalize();
//绘制洞口示意 V线 按默认水平放置的洞口
AcGePoint3d ptGe[5],pt1,pt2;
ptGe[0] = ptOrg;
ptGe[0] += vtX * 0.5 * dL;
ptGe[0] += AcGeVector3d::kZAxis * 0.5 * dW;
ptGe[1] = ptGe[0];
ptGe[1] -= vtX * dL;
ptGe[2] = ptGe[1];
ptGe[2] -= AcGeVector3d::kZAxis * dW;
pt1 = ptGe[1];
pt1.rotateBy(-PI / 36.0, vtZ, ptGe[0]);
pt2 = ptGe[1];
pt2.rotateBy(PI / 36.0, vtZ, ptGe[2]);
AcGeLine3d ln1(pt1, ptGe[0]);
AcGeLine3d ln2(pt2, ptGe[2]);
pt1 = ptGe[1];
if (ln1.intersectWith(ln2, ptGe[1]))
{
pt2 = ptGe[1];
AcDbLine* pLn1 = new AcDbLine(ptGe[0], ptGe[1]);
pLn1->setLayer(pPartEnt->layerId());
arCenLnPtrs.append(pLn1);
AcDbLine *pLn2 = new AcDbLine(ptGe[1], ptGe[2]);
pLn1->setLayer(pPartEnt->layerId());
arCenLnPtrs.append(pLn2);
CString sForUse;
xData.GetAt(KEY_FORUSE, sForUse);
if (sForUse.Find(_T("人孔")) != -1)
{
//人孔填充
ptGe[1] = pt1;
ptGe[3] = pt2;
ptGe[4] = ptGe[0];
//交叉设置点
AcGePoint3d ptS[4];
ptS[0] = ptGe[0];
ptS[1] = ptGe[1];
ptS[2] = ptGe[3];
ptS[3] = ptGe[2];
AcDbVoidPtrArray arHatchPtrs;
FillSolid(ptS,4,arHatchPtrs);
if (!arHatchPtrs.isEmpty())
{
arCenLnPtrs.append(arHatchPtrs);
}
}
}
}
}
else if (nShap == (int)eCircle && sName.CompareNoCase(_T("开洞")) == 0)
{
double dR = 0;
xData.GetAt(_T("dRad"), dR);
xData.GetAt(_T("vtDir"), vtZ);
AcGeLine3d lnZ;
lnZ.set(ptOrg, vtZ);
if (AcGePlane::kXYPlane.isParallelTo(lnZ)) //洞中心方向线水平
{
CString sForUse;
xData.GetAt(KEY_FORUSE, sForUse);
if (sForUse.Find(_T("人孔")) != -1)
{
AcGeVector3d vtX = vtZ;
vtX.rotateBy(-PI / 2.0, AcGeVector3d::kZAxis);
vtX.normalize();
AcGePoint3d ptGe[5], ptTmp;
AcGePoint2dArray vertices;
AcGeDoubleArray bulges;
AcGePlane plan;
plan.set(ptOrg, vtZ);
double dEl = AcGePoint3d::kOrigin.distanceTo(AcGePoint3d::kOrigin.orthoProject(plan));
AcGePoint3d ptOrgT = plan.closestPointTo(AcGePoint3d::kOrigin);
AcGeVector3d vtOrg = ptOrgT.asVector();
vtOrg.normalize();
vtZ.normalize();
if (!vtOrg.isCodirectionalTo(vtZ))
{
dEl *= -1.0;
}
AcDbHatch *pHatch = new AcDbHatch;
pHatch->setElevation(dEl);
pHatch->setNormal(vtZ);
AcGeMatrix3d mxECS;
pHatch->getEcs(mxECS);
mxECS.invert();
ptGe[0] = ptOrg;
ptGe[0].z += dR;
ptTmp = ptGe[0];
vertices.append(ptTmp.transformBy(mxECS).convert2d(AcGePlane::kXYPlane));
bulges.append(1.0);
ptGe[1] = ptGe[0];
ptGe[1].z -= 2.0 * dR;
ptTmp = ptGe[1];
vertices.append(ptTmp.transformBy(mxECS).convert2d(AcGePlane::kXYPlane));
bulges.append(-tan(0.6));
ptGe[2] = ptOrg;
ptGe[2].z += dR;
ptTmp = ptGe[2];
vertices.append(ptTmp.transformBy(mxECS).convert2d(AcGePlane::kXYPlane));
bulges.append(0.0);
pHatch->setAssociative(Adesk::kFalse);
pHatch->setPattern(AcDbHatch::kPreDefined, _T("SOLID"));
pHatch->setHatchStyle(AcDbHatch::kNormal);
pHatch->appendLoop(AcDbHatch::kExternal, vertices, bulges);
pHatch->evaluateHatch();
//TEST
//AddToModelSpace(pHatch);
arCenLnPtrs.append(pHatch);
}
}
}
}
}
xData.SetAt(KEY_ORGPT,ptOrg);
xData.SetAt(KEY_CENNODRAW,TRUE);//中心线不画标识
xData.Write(pLn,BIMDATA_APP);
}
arCenLnPtrs.append(pLn);
ptSta = ptOrg - AcGeVector3d::kZAxis * 1.2 * dH;
ptEnd = ptOrg + AcGeVector3d::kZAxis * 1.2 * dH;
pLn = new AcDbLine(ptSta,ptEnd);//中心线
pLn->setLayer(KTSetting::InitLayer(_T("LAY_CL"),true));
pLn->setLinetype(KTSetting::InitLineStyle(_T("CENTER")));
if (pXData != NULL)
{
AecDbObjXDataMap xData;
xData.CopyFrom(pXData);
xData.SetAt(KEY_NAME,sName);
if (sName.CompareNoCase(_T("开洞")) == 0 || //开洞
sName.CompareNoCase(_T("套管")) == 0) //套管
{
//洞口或套管写标高
AecInterface inf;
if ( pPartEnt->GetInterface(0,inf) )
{
int nShap = 0;
xData.GetAt(_T("nShape"),nShap);//圆
if (inf.vtDir.isParallelTo(AcGeVector3d::kZAxis))
{
if (nShap == (int)eCircle)
{
xData.SetAt(KEY_CENEL,inf.ptPos.z);
}
else
{
xData.SetAt(KEY_BOTMEL,inf.ptPos.z);
}
}
else
{
if (nShap == (int)eCircle)
{
xData.SetAt(KEY_CENEL,inf.ptPos.z);
}
else
{
xData.SetAt(KEY_BOTMEL,inf.ptPos.z - 0.5 * inf.dSize2);
}
}
}
}
xData.SetAt(KEY_ORGPT,ptOrg);
xData.SetAt(KEY_CENNODRAW,TRUE);//中心线不画标识
xData.Write(pLn,BIMDATA_APP);
}
arCenLnPtrs.append(pLn);
}
else if (AcGePlane::kXYPlane.isParallelTo(ln))//平行XY面
{
AecDbObjXDataMap xData;
xData.CopyFrom(pXData);
xData.SetAt(KEY_NAME, sName);
//平行XY面 绘制洞口示意 X 线
AcGePoint3d ptGe[4];
double dL = 0, dW = 0,dT = 0;
xData.GetAt(_T("dL"), dL);
xData.GetAt(_T("dW"), dW);
xData.GetAt(_T("dH"), dT);
xData.GetAt(_T("vtDir"), vtZ);
AcGeLine3d lnZ;
lnZ.set(ptOrg, vtZ);
if (AcGePlane::kXYPlane.isParallelTo(lnZ)) //洞水平 X 线
{
AcGeVector3d vtX = vtZ;
vtX.rotateBy(-PI / 2.0, AcGeVector3d::kZAxis);
vtX.normalize();
ptGe[0] = ptOrg;
ptGe[0] += AcGeVector3d::kZAxis * 0.5 * dW;
ptGe[0] += vtZ * 0.5 * dT;
ptGe[1] = ptGe[0];
ptGe[1] -= vtZ * dT;
ptGe[2] = ptGe[1];
ptGe[2] -= AcGeVector3d::kZAxis * dW;
ptGe[3] = ptGe[0];
ptGe[3] -= AcGeVector3d::kZAxis * dW;
int nShap = 0;
xData.GetAt(_T("nShape"), nShap);//圆
if (nShap == (int)eRect && sName.CompareNoCase(_T("开洞")) == 0)
{
AcDbLine *pLn1 = new AcDbLine(ptGe[0], ptGe[2]);
pLn1->setLayer(layerId());
pLn1->setLinetype(KTSetting::InitLineStyle(_T("DASH")));
arCenLnPtrs.append(pLn1);
AcDbLine *pLn2 = new AcDbLine(ptGe[1], ptGe[3]);
pLn2->setLayer(layerId());
pLn2->setLinetype(KTSetting::InitLineStyle(_T("DASH")));
arCenLnPtrs.append(pLn2);
AcDbLine *pLn3 = new AcDbLine(ptGe[0], ptGe[3]);
pLn3->setLayer(layerId());
pLn3->setLinetype(KTSetting::InitLineStyle(_T("DASH")));
arCenLnPtrs.append(pLn3);
AcDbLine *pLn4 = new AcDbLine(ptGe[1], ptGe[2]);
pLn4->setLayer(layerId());
pLn4->setLinetype(KTSetting::InitLineStyle(_T("DASH")));
arCenLnPtrs.append(pLn4);
}
}
else if (AcGePlane::kXYPlane.isPerpendicularTo(lnZ))
{
}
}
}
//2.减去 开洞 套管 的 虚Solid
if (sName.CompareNoCase(_T("开洞")) == 0 || //开洞
sName.CompareNoCase(_T("套管")) == 0) //套管
{
AcDbVoidPtrArray arSolids;
pPartEnt->GetForHouseSubtract(arSolids);
for (int k = 0;k < arSolids.length();k++)
{
pEntT = (AcDbEntity*)arSolids.at(k);
pSolidT = AcDb3dSolid::cast(pEntT);
if (pSolidT != NULL)
{
pSolidDrawCln = (AcDb3dSolid*)pSolidDraw->clone();
if ( Acad::eOk == (es = pSolidT->booleanOper(AcDb::kBoolIntersect,pSolidDrawCln) ) )
{
pSolidT->setLayer(pPartEnt->layerId());
arSolidPtrs.append(pSolidT);
}
else
{
delete pSolidDrawCln;
}
}
}
}
if(sName.CompareNoCase(_T("套管")) == 0)//套管
{
AcDb3dSolid* p3DPipe = pPartEnt->CreateDraw3dSolid();
if (p3DPipe != NULL)
{
p3DPipe->setLayer(pPartEnt->layerId());
arSolidPtrs.append(p3DPipe);
}
}
}
AecDbXOpening* pOpen = AecDbXOpening::cast(pEnt);
if (pOpen != NULL)
{
AcDbVoidPtrArray arSolids;
pOpen->GetForHouseSubtract(arSolids);
for (int k = 0;k < arSolids.length();k++)
{
pEntT = (AcDbEntity*)arSolids.at(k);
pSolidT = AcDb3dSolid::cast(pEntT);
if (pSolidT != NULL)
{
//求交获取精确的洞口。 主模型为了kBoolSubtract,洞口都是放大了一点,保证主模型kBoolSubtract洞口正确
//完全匹配的洞口 主模型(pSolidDraw) kBoolSubtract洞口时,会出现结果两侧不彻底的情况,多余两个面,数学边界问题
pSolidDrawCln = (AcDb3dSolid*)pSolidDraw->clone();
if ( Acad::eOk == (es = pSolidT->booleanOper(AcDb::kBoolIntersect,pSolidDraw) ) )
{
pSolidT->setLayer(pOpen->layerId());
pSolidT->setVisibility(AcDb::kInvisible);
arSolidPtrs.append(pSolidT);
}
else
{
delete pSolidDrawCln;
}
}
}
}
pEnt->close();
}
}
delete pSolidDraw;
}
return Acad::eOk;
}
SHJson::WValue& AecDbBDPipeBase::ToJson(bool bExprotGeo) const
{
assertReadEnabled();
using namespace SHJson;
WValue &v = AecDbEwPipeBase::ToJson(bExprotGeo);
WValue ar, sub;
if (bExprotGeo)
{
ar.SetArray();
for (size_t i = 0; i < m_arX3DPartPtrs.length(); ++i)
{
sub.SetNull();
sub = m_arX3DPartPtrs[i]->ToJson();
if (!sub.IsNull())
{
addMember(sub, _T("__owner__"), objectId().asOldId());
pushBack(ar, sub);
}
}
if (!ar.Empty())
addMember(v, _T("__arX3DPartPtrs__"), ar);
ar.SetArray();
for (size_t i = 0; i < 3; ++i)
pushBack(ar, m_dRotate[i]);
if (!ar.Empty())
addMember(v, _T("__dRotate__"), ar);
}
return v;
}
bool AecDbBDPipeBase::ByJson(const SHJson::WValue &v)
{
AssertWriteEnabled();
using namespace SHJson;
if (!AecDbEwPipeBase::ByJson(v)) return false;
MCIt it = v.FindMember(_T("__xRot__"));
if (it == v.MemberEnd()) return false;
m_dRotate[0] = it->value.GetDouble();
it = v.FindMember(_T("__yRot__"));
if (it == v.MemberEnd()) return false;
m_dRotate[1] = it->value.GetDouble();
it = v.FindMember(_T("__zRot__"));
if (it == v.MemberEnd()) return false;
m_dRotate[2] = it->value.GetDouble();
it = v.FindMember(_T("__attachment__"));
if (it == v.MemberEnd()) return false;
if (!it->value.IsArray()) return false;
deleteContainerOfArx<AecDbX3dPart>(m_arX3DPartPtrs);
for (VCIt i = it->value.Begin(); i != it->value.End(); ++i)
{
AecDbX3dPart *pPart = new AecDbX3dPart();
if (pPart->ByJson(*i))
m_arX3DPartPtrs.append(pPart);
else
DELETE_PTR(pPart);
}
return true;
}