7816 lines
166 KiB
C++
7816 lines
166 KiB
C++
#include "stdafx.h"
|
||
#include "encryption.h"
|
||
#include "AecDbEwPipeBase.h"
|
||
#include "KTCADUtilityEx.h"
|
||
#include "MFCDbDwgFiler.h"
|
||
#include "AecDb3dRoadAxisLine.h"
|
||
#include "KTModelLayoutXData.h"
|
||
#include "KTSetting.h"
|
||
#include "AcGiExplodeDraw.h"
|
||
#include ".\HGRID\hpolygon.h"
|
||
#include ".\HGRID\hgrid.h"
|
||
#include "AecCoverBooleanOper.h"
|
||
#include "dbgrip.h"
|
||
#include "AecGripCback.h"
|
||
#include "geometry2json.h"
|
||
#include "CoreTools.h"
|
||
#include "KTCadUtility.h"
|
||
#include "GiDrawUtility.h"
|
||
#include "AcGiViewDraw.h"
|
||
#include "AcDbX3dSolid.h"
|
||
|
||
#ifndef EW_EARTHWORMINIT
|
||
#define EW_EARTHWORMINIT _T("EW_EARTHWORMINIT")
|
||
#endif
|
||
|
||
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;
|
||
static const Adesk::UInt16 kGold = 30;
|
||
static const Adesk::UInt16 kPurple = 200;
|
||
static const Adesk::UInt16 kMagenta2 = 210;
|
||
|
||
extern CString IDCreate();
|
||
extern double PixelToWcs(int nPixel);
|
||
extern AcGePoint3d MidPoint(const AcGePoint3d& pt1,const AcGePoint3d& pt2);
|
||
extern Acad::ErrorStatus AddToModelSpace(AcDbEntity* pEnt,AcDbDatabase* pDb = NULL,bool bClose = true);
|
||
extern void DLLIMPEXP OrthoProjected3DSolid(AcDb3dSolid* pSolidClone,const AcGePlane& plan,AcGeMatrix3d& xformPlanToWorld,AcDbVoidPtrArray& arEntPtrs);
|
||
extern void DLLIMPEXP OrthoProjected3DSolid2(AcDb3dSolid* pSolidClone,const AcGePlane& plan,const AcGePlane& planCut,AcGeMatrix3d& xformPlanToWorld,AcDbVoidPtrArray& arEntPtrs);
|
||
extern AcDbPolyline* FormatPolyline(AcGePoint3d* ppPts,int nCount);
|
||
extern void SortPoints(AcGePoint3dArray& points,AcDbCurve* pLine);
|
||
extern AcDbCurve* GetMinOffsetCurve(AcDbCurve* pPl,double dOff);
|
||
|
||
namespace
|
||
{
|
||
// pline投影到平面pln上,投影方向dir
|
||
AcDbPolyline* makeProject(const AcDbPolyline *pSrc
|
||
, const AcGePlane &pln
|
||
, const AcGeVector3d &dir)
|
||
{
|
||
#if ARX > 18
|
||
{
|
||
// 如果 _pln 和 pln 共面,则不投影
|
||
AcDb::Planarity pa;
|
||
AcGePlane _pln;
|
||
pSrc->getPlane(_pln, pa);
|
||
if (_pln.isCoplanarTo(pln, AcGeContext::gTol))
|
||
return (AcDbPolyline *)pSrc->clone();
|
||
}
|
||
|
||
AcGeCurve3d *pGeCrv(NULL);
|
||
pSrc->getAcGeCurve(pGeCrv);
|
||
if (!pGeCrv) return NULL;
|
||
|
||
pGeCrv->transformBy(AcGeMatrix3d::projection(pln, dir));
|
||
|
||
AcDbPolyline *pNew(NULL);
|
||
#ifndef ZWCAD
|
||
if (AcDbCurve::createFromAcGeCurve(*pGeCrv, (AcDbCurve *&)pNew) != Acad::eOk)
|
||
#else
|
||
if (AcDbCurve::createFromZcGeCurve(*pGeCrv, (AcDbCurve *&)pNew) != Acad::eOk)
|
||
#endif
|
||
{
|
||
acutPrintf(_T("GeCurve 转换 DbCurve 失败。"));
|
||
DELETE_PTR(pNew);
|
||
}
|
||
|
||
DELETE_PTR(pGeCrv);
|
||
return pNew;
|
||
#else
|
||
return NULL;
|
||
#endif
|
||
}
|
||
|
||
// 绘制斜底板
|
||
AcDb3dSolid *drawXDB(const AecDbObjXDataMap *pXData)
|
||
{
|
||
// 得到水平截面
|
||
CString sProfile(_T(""));
|
||
pXData->GetAt(KEY_POINTS, sProfile);
|
||
if(sProfile.IsEmpty())
|
||
{
|
||
acutPrintf(_T("\n无法得到斜板轮廓。"));
|
||
return NULL;
|
||
}
|
||
|
||
AcDbPolyline *pXYPoly = CoreTools::StringToPolyline(sProfile);
|
||
if (!pXYPoly)
|
||
{
|
||
acutPrintf(_T("\n还原水平多段线失败。"));
|
||
return NULL;
|
||
}
|
||
|
||
// 代表旋转方向的直线的起止点
|
||
AcGePoint3d ptS, ptE;
|
||
if (!pXData->GetAt(_T("_XDB_FLAG_PTS_"), ptS)
|
||
|| !pXData->GetAt(_T("_XDB_FLAG_PTE_"), ptE))
|
||
{
|
||
acutPrintf(_T("\n无法得到斜板起止点。"));
|
||
return NULL;
|
||
}
|
||
|
||
double dIDist;
|
||
if (!pXData->GetAt(_T("_XDB_FLAG_DIST_"), dIDist))
|
||
{
|
||
acutPrintf(_T("\n无法得到斜板斜度。"));
|
||
return NULL;
|
||
}
|
||
|
||
double dElev;
|
||
if (!pXData->GetAt(_T("_XDB_FLAG_ELEV_"), dElev))
|
||
{
|
||
acutPrintf(_T("\n无法得到斜板标高。"));
|
||
return NULL;
|
||
}
|
||
|
||
double dThick(.0);
|
||
if (!pXData->GetAt(KEY_BOMTHICK, dThick))
|
||
{
|
||
acutPrintf(_T("\n无法得到斜板厚度。"));
|
||
return NULL;
|
||
}
|
||
|
||
AcDbRegion *pReg(NULL);
|
||
AcGePoint3d ptCen;
|
||
{
|
||
AcGePoint3d ptO(ptS), pt2(ptE);
|
||
ptO.z = pt2.z = dElev;
|
||
double dDeltaH(ptO.distanceTo(pt2) * (1 / dIDist));
|
||
pt2.z += dDeltaH;
|
||
|
||
AcGeVector3d vtNorm(pt2 - ptO), vtPlineNorm(pXYPoly->normal()), vtRotaAxis;
|
||
vtNorm.normalize();
|
||
vtRotaAxis = vtPlineNorm.crossProduct(vtNorm);
|
||
vtRotaAxis.normalize();
|
||
vtNorm.rotateBy(-PI * .5, vtRotaAxis);
|
||
|
||
AcGeMatrix3d mat;
|
||
AcGePlane pln(ptO, vtNorm);
|
||
|
||
AcDbPolyline* pL = makeProject(pXYPoly, pln, AcGeVector3d::kZAxis);
|
||
DELETE_PTR(pXYPoly);
|
||
if (!pL)
|
||
{
|
||
#ifndef NDEBUG
|
||
CoreTools::CloneAndAddToModelSpace(pL, 1);
|
||
#endif
|
||
acutPrintf(_T("\n多段线投影失败。"));
|
||
return NULL;
|
||
}
|
||
pL->getPointAt(0, ptCen);
|
||
pReg = CoreTools::createRegion(pL);
|
||
DELETE_PTR(pL);
|
||
if (!pReg)
|
||
{
|
||
acutPrintf(_T("\n多段线投影失败。"));
|
||
return NULL;
|
||
}
|
||
}
|
||
|
||
AcDb3dSolid *pSo(NULL);
|
||
{
|
||
AcDbSweepOptions sweepOp;
|
||
pSo = new AcDb3dSolid;
|
||
AcDbLine line(ptCen, ptCen + (AcGeVector3d::kZAxis * -dThick));
|
||
|
||
// extrudeAlongPath()函数在截面与路径不垂直的情况下,结果不可预测,故使用createSweptSolid()
|
||
Acad::ErrorStatus es = pSo->createSweptSolid(pReg, &line, sweepOp);
|
||
DELETE_PTR(pReg);
|
||
|
||
if (es != Acad::eOk)
|
||
{
|
||
acutPrintf(_T("\n绘制斜板失败。"));
|
||
DELETE_PTR(pSo);
|
||
}
|
||
}
|
||
return pSo;
|
||
}
|
||
}
|
||
|
||
static void FreeBuffer(int n,AcDbVoidPtrArray& arEntPtrs)
|
||
{
|
||
AcDbEntity* pEnt = NULL;
|
||
while(arEntPtrs.length() > n )
|
||
{
|
||
pEnt = (AcDbEntity*)arEntPtrs.last();
|
||
if (pEnt != NULL)
|
||
{
|
||
pEnt->erase();
|
||
pEnt->close();
|
||
arEntPtrs.removeLast();
|
||
DELETE_PTR(pEnt);
|
||
}
|
||
}
|
||
}
|
||
|
||
double GetPipeDoubleLineMaxD()
|
||
{
|
||
AecDbObjXDataMap xDataMap;
|
||
CString sDia(_T(""));
|
||
double dMaD(.0);
|
||
|
||
if (KTModelLayoutXData::ReadModelXData(EW_EARTHWORMINIT, xDataMap))
|
||
{
|
||
dMaD = 500;
|
||
if (xDataMap.GetAt(DOC_PIPEMAXDIA, sDia))
|
||
dMaD = _ttof(sDia);
|
||
return AS_MUNIT(dMaD);
|
||
}
|
||
else if (KTModelLayoutXData::ReadModelXData(KT_PIPEINIT, xDataMap))
|
||
{
|
||
dMaD = 200.;
|
||
xDataMap.GetAt(DOC_PIPEMAXDIA, dMaD);
|
||
return dMaD;
|
||
}
|
||
return 100.;
|
||
}
|
||
|
||
DLLIMPEXP void transfromRegion(AcDbRegion *pRegion, const AcGePoint3d &ptOnRegion, const AcGeVector3d &vtNormal, const AcGePoint3d &ptOnPlan)
|
||
{
|
||
if (pRegion == NULL)
|
||
return;
|
||
|
||
AcGeVector3d vtNormReg;
|
||
pRegion->getNormal(vtNormReg);
|
||
|
||
if (vtNormReg.isParallelTo(vtNormal))//平行
|
||
{
|
||
AcGeMatrix3d xform;
|
||
|
||
// 把 region 上的点也转到面上
|
||
AcGePoint3d pt(ptOnRegion);
|
||
pt.transformBy(xform);
|
||
|
||
// 再把region在面上平移
|
||
xform.setToIdentity();
|
||
xform.setToTranslation(ptOnPlan - pt);
|
||
pRegion->transformBy(xform);
|
||
}
|
||
else
|
||
{
|
||
AcGePlane plan;
|
||
plan.set(ptOnPlan, vtNormal);
|
||
AcGePoint3d pt0, pt1, pt2;
|
||
plan.get(pt0, pt1, pt2);
|
||
|
||
AcGeMatrix3d xform;
|
||
xform.setToPlaneToWorld(plan);
|
||
|
||
// 把region转到此面上
|
||
pRegion->transformBy(xform);
|
||
|
||
// 把 region 上的点也转到面上
|
||
AcGePoint3d pt(ptOnRegion);
|
||
pt.transformBy(xform);
|
||
|
||
// 再把region在面上平移
|
||
xform.setToIdentity();
|
||
xform.setToTranslation(ptOnPlan - pt);
|
||
pRegion->transformBy(xform);
|
||
}
|
||
}
|
||
|
||
|
||
// 把region变换到以 vtNormal为法向,以ptOnPlan为中心的面上,并且, 将region上的点ptOnRegion与平面中心点ptOnPlan对齐
|
||
DLLIMPEXP void invertTransfromRegion(AcDbRegion *pRegion, const AcGePoint3d &ptOnRegion, const AcGeVector3d &vtNormal, const AcGePoint3d &ptOnPlan)
|
||
{
|
||
if (pRegion == NULL)
|
||
return;
|
||
|
||
AcGeVector3d vtNormReg;
|
||
pRegion->getNormal(vtNormReg);
|
||
|
||
/*if (vtNormReg.isParallelTo(vtNormal))//平行
|
||
{
|
||
AcGeMatrix3d xform;
|
||
|
||
// 把 region 上的点也转到面上
|
||
AcGePoint3d pt(ptOnRegion);
|
||
pt.transformBy(xform);
|
||
|
||
// 再把region在面上平移
|
||
xform.setToIdentity();
|
||
xform.setToTranslation(ptOnPlan - pt);
|
||
|
||
xform.invert();
|
||
pRegion->transformBy(xform);
|
||
}
|
||
else*/
|
||
{
|
||
AcGePlane plan;
|
||
plan.set(ptOnPlan, vtNormal);
|
||
AcGePoint3d pt0, pt1, pt2;
|
||
plan.get(pt0, pt1, pt2);
|
||
|
||
AcGeMatrix3d xform;
|
||
xform.setToPlaneToWorld(plan);
|
||
|
||
// 把 region 上的点也转到面上
|
||
AcGePoint3d pt(ptOnRegion);
|
||
pt.transformBy(xform);
|
||
|
||
// 再把region在面上平移
|
||
xform.setToIdentity();
|
||
xform.setToTranslation(ptOnPlan - pt);
|
||
xform.invert();
|
||
pRegion->transformBy(xform);
|
||
|
||
xform.setToPlaneToWorld(plan);
|
||
xform.invert();
|
||
pRegion->transformBy(xform);
|
||
}
|
||
}
|
||
|
||
int GetOrthoProjectedCurve(AcDbRegion* pReg,AcGePlane& plan,AcDbVoidPtrArray& arCurPtrs,bool bMerge = false)
|
||
{
|
||
AcDbVoidPtrArray arSubCur,arSubCurT;
|
||
pReg->explode(arSubCur);
|
||
|
||
AecComplexCurve cmpl;
|
||
|
||
AcDbEntity* pEnt = NULL;
|
||
AcDbCurve* pCur = NULL,*pProj = NULL;
|
||
for (int i = 0;i < arSubCur.length();i++)
|
||
{
|
||
pEnt = (AcDbEntity*)arSubCur.at(i);
|
||
|
||
pCur = AcDbCurve::cast(pEnt);
|
||
if (pCur != NULL)
|
||
{
|
||
pCur->getOrthoProjectedCurve(plan,pProj);
|
||
if (pProj != NULL)
|
||
{
|
||
if ( bMerge )
|
||
{
|
||
if (-1 == cmpl.append(pProj) )
|
||
{
|
||
arCurPtrs.append(pProj);
|
||
}
|
||
else
|
||
{
|
||
delete pProj;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
arCurPtrs.append(pProj);
|
||
}
|
||
}
|
||
}
|
||
delete pEnt;
|
||
}
|
||
|
||
if (bMerge)
|
||
{
|
||
cmpl.merge();
|
||
|
||
for (int i = 0;i < cmpl.length();i++)
|
||
{
|
||
pProj = cmpl.segat(i);
|
||
arCurPtrs.append(pProj);
|
||
}
|
||
}
|
||
return arCurPtrs.length();
|
||
}
|
||
|
||
Adesk::UInt32 AecDbEwPipeBase::kCurrentVersionNumber = 7;//升级7
|
||
ACRX_DXF_DEFINE_MEMBERS (AecDbEwPipeBase, AecDbCurveBase,
|
||
AcDb::kDHL_CURRENT, AcDb::kMReleaseCurrent,
|
||
AcDbProxyEntity::kNoOperation | AcDbProxyEntity::kDisableProxyWarning,
|
||
AEC_DBEWPIPEBASE,
|
||
"AecDbEwPipeBase"
|
||
"|Product Desc: shanghua earthworm app obj"
|
||
"|Company: shanghua inc"
|
||
"|WEB Address: www.shanghuasoft.com")
|
||
|
||
|
||
AecDbEwPipeBase::AecDbEwPipeBase(void)
|
||
{
|
||
m_pRegion = NULL;
|
||
m_pBaseCurve = NULL;
|
||
|
||
m_nInfActive = -1;
|
||
m_bActive = false;
|
||
m_sGUID = IDCreate();
|
||
m_mapSpecXData.SetAt(KEY_NO,m_sGUID);
|
||
m_bShowFlowDir = false;
|
||
m_bIsMainLock = false;
|
||
m_bIsMinLock = false;
|
||
m_arBreaks.removeAll();
|
||
m_pGripAppData = new AecGripData[GRIP_LENGTH];
|
||
}
|
||
|
||
AecDbEwPipeBase::~AecDbEwPipeBase(void)
|
||
{
|
||
FreeBuffer(0,m_arDrawBuffer3d1);
|
||
FreeBuffer(0,m_arDrawBuffer3d2);
|
||
FreeBuffer(0,m_ar2DDrableBufPtrs2);
|
||
if (m_pRegion != NULL)
|
||
{
|
||
delete m_pRegion;
|
||
m_pRegion = NULL;
|
||
}
|
||
|
||
if (m_pBaseCurve != NULL)
|
||
{
|
||
delete m_pBaseCurve;
|
||
m_pBaseCurve = NULL;
|
||
}
|
||
delete [] m_pGripAppData;
|
||
}
|
||
|
||
AcGePoint3d AecDbEwPipeBase::StartPoint() const
|
||
{
|
||
assertReadEnabled();
|
||
|
||
AcGePoint3d ptS;
|
||
this->getStartPoint(ptS);
|
||
return ptS;
|
||
}
|
||
|
||
AcGePoint3d AecDbEwPipeBase::EndPoint() const
|
||
{
|
||
assertReadEnabled();
|
||
AcGePoint3d ptS;
|
||
this->getEndPoint(ptS);
|
||
return ptS;
|
||
}
|
||
|
||
AcDbCurve* AecDbEwPipeBase::BaseCurveDwgInFields(AcDbDwgFiler* pFiler,int nVer)
|
||
{
|
||
assertWriteEnabled();
|
||
|
||
TCHAR* pszClass = NULL;
|
||
pFiler->readString(&pszClass);
|
||
|
||
AcRxObject* pRx = acrxClassDictionary->at(pszClass);
|
||
if (pRx != NULL)
|
||
{
|
||
acutDelString(pszClass);
|
||
|
||
AcRxClass* pRxClass = (AcRxClass* )pRx;
|
||
AcDbCurve* pBaseCurve = (AcDbCurve*)pRxClass->create();
|
||
|
||
AcGeVector3d vtNorm;
|
||
|
||
AcDbLine* pLine = AcDbLine::cast(pBaseCurve);
|
||
if (pLine != NULL)
|
||
{
|
||
AcGePoint3d ptSta,ptEnd;
|
||
pFiler->readPoint3d(&ptSta);
|
||
pFiler->readPoint3d(&ptEnd);
|
||
pFiler->readVector3d(&vtNorm);
|
||
|
||
pLine->setStartPoint(ptSta);
|
||
pLine->setEndPoint(ptEnd);
|
||
pLine->setNormal(vtNorm);
|
||
|
||
return pBaseCurve;
|
||
}
|
||
|
||
AcDbArc* pArc = AcDbArc::cast(pBaseCurve);
|
||
if (pArc != NULL)
|
||
{
|
||
AcGePoint3d ptCen;
|
||
double dRad = 0.0,dSta = 0.0,dEnd = 0.0;
|
||
pFiler->readPoint3d(&ptCen);
|
||
pFiler->readDouble(&dRad);
|
||
pFiler->readDouble(&dSta);
|
||
pFiler->readDouble(&dEnd);
|
||
pFiler->readVector3d(&vtNorm);
|
||
|
||
pArc->setCenter(ptCen);
|
||
pArc->setRadius(dRad);
|
||
pArc->setStartAngle(dSta);
|
||
pArc->setEndAngle(dEnd);
|
||
pArc->setNormal(vtNorm);
|
||
|
||
return pBaseCurve;
|
||
}
|
||
|
||
AcDbCircle* pCir = AcDbCircle::cast(pBaseCurve);
|
||
if (pCir != NULL)
|
||
{
|
||
AcGePoint3d ptCen;
|
||
double dRad = 0.0;
|
||
pFiler->readPoint3d(&ptCen);
|
||
pFiler->readDouble(&dRad);
|
||
pFiler->readVector3d(&vtNorm);
|
||
|
||
pCir->setCenter(ptCen);
|
||
pCir->setRadius(dRad);
|
||
pCir->setNormal(vtNorm);
|
||
return pBaseCurve;
|
||
}
|
||
|
||
AcDbPolyline* pPl = AcDbPolyline::cast(pBaseCurve);
|
||
if (pPl != NULL)
|
||
{
|
||
double dEl = 0.0;
|
||
Adesk::UInt32 nVts = 0;
|
||
pFiler->readUInt32(&nVts);
|
||
|
||
pFiler->readDouble(&dEl);
|
||
pFiler->readVector3d(&vtNorm);
|
||
|
||
AcGePlane plan;
|
||
plan.set(AcGePoint3d::kOrigin,vtNorm);
|
||
|
||
AcGePoint3d pt3d;
|
||
double dBulge = 0.0,dS = 0,dE = 0;
|
||
for (int i = 0;i < nVts;i++)
|
||
{
|
||
pFiler->readPoint3d(&pt3d );
|
||
pFiler->readDouble(&dBulge);
|
||
if (nVer > 5)//6 版本
|
||
{
|
||
pFiler->readDouble(&dS);
|
||
pFiler->readDouble(&dE);
|
||
}
|
||
pPl->addVertexAt(i,pt3d.convert2d(plan),dBulge,dS,dE);
|
||
}
|
||
pPl->setNormal(vtNorm);
|
||
pPl->setElevation(dEl);
|
||
return pBaseCurve;
|
||
}
|
||
|
||
AcDbEllipse* pEl = AcDbEllipse::cast(pBaseCurve);
|
||
if (pEl != NULL)
|
||
{
|
||
AcGePoint3d ptCen;
|
||
double dRatio = 0.0;
|
||
AcGeVector3d vtMaj;
|
||
double dSta = 0.0,dEnd = 0.0;
|
||
|
||
pFiler->readPoint3d(&ptCen);
|
||
pFiler->readDouble(&dRatio);
|
||
pFiler->readVector3d(&vtMaj);
|
||
pFiler->readDouble(&dSta);
|
||
pFiler->readDouble(&dEnd);
|
||
pFiler->readVector3d(&vtNorm);
|
||
|
||
pEl->set(ptCen,vtNorm,vtMaj,dRatio,dSta,dEnd);
|
||
return pBaseCurve;
|
||
}
|
||
|
||
AcDbSpline* pSp = AcDbSpline::cast(pBaseCurve);
|
||
if (pSp != NULL)
|
||
{
|
||
//...
|
||
}
|
||
|
||
//只支持标准点链接的3dpl线
|
||
AcDb3dPolyline* pPl3d = AcDb3dPolyline::cast(pBaseCurve);
|
||
if (pPl3d != NULL)
|
||
{
|
||
AcDb3dPolylineVertex* pVtex = NULL;
|
||
Adesk::UInt32 nLen = 0;
|
||
AcGePoint3d pt3d;
|
||
|
||
pFiler->readUInt32(&nLen);
|
||
for (int j = 0;j < nLen;j++)
|
||
{
|
||
pFiler->readPoint3d(&pt3d);
|
||
|
||
pVtex = new AcDb3dPolylineVertex;
|
||
pVtex->setPosition(pt3d);
|
||
pPl3d->appendVertex(pVtex);
|
||
}
|
||
return pBaseCurve;
|
||
}
|
||
|
||
AecDb3dRoadAxisLine* pRoadAxis = AecDb3dRoadAxisLine::cast(pBaseCurve);
|
||
if (pRoadAxis != NULL)
|
||
{
|
||
pRoadAxis->dwgInFields(pFiler);
|
||
return pRoadAxis;
|
||
}
|
||
}
|
||
return NULL;
|
||
}
|
||
|
||
namespace
|
||
{
|
||
Acad::ErrorStatus rawBooleanOperWrapper(AcDbRegion *pRegion1, AcDbRegion *pRegion2, AcDb::BoolOperType operation)
|
||
{
|
||
Acad::ErrorStatus es = Acad::eOk;
|
||
|
||
__try
|
||
{
|
||
// 尝试执行极易崩溃的底层代码
|
||
es = pRegion1->booleanOper(operation, pRegion2);
|
||
}
|
||
__except (EXCEPTION_EXECUTE_HANDLER)
|
||
{
|
||
// 捕获到了 0xC0000005 等系统级崩溃
|
||
// 返回一个特殊的错误码,或者就用 eGeneralModelingFailure 代表引擎崩溃
|
||
|
||
AcGePoint3d origin(AcGePoint3d::kOrigin);
|
||
AcGeVector3d xAxis(AcGeVector3d::kXAxis);
|
||
AcGeVector3d yAxis(AcGeVector3d::kYAxis);
|
||
double perimeter(.0);
|
||
double area(.0);
|
||
AcGePoint2d centroid(AcGePoint2d::kOrigin);
|
||
double momInertia[2] = {};
|
||
double prodInertia(.0);
|
||
double prinMoments[2] = {};
|
||
AcGeVector2d prinAxes[2] = {};
|
||
double radiiGyration[2] = {};
|
||
AcGePoint2d extentsLow(AcGePoint2d::kOrigin);
|
||
AcGePoint2d extentsHigh(AcGePoint2d::kOrigin);
|
||
|
||
pRegion1->getAreaProp(origin, xAxis, yAxis, perimeter, area, centroid, momInertia
|
||
, prodInertia, prinMoments, prinAxes, radiiGyration, extentsLow, extentsHigh);
|
||
|
||
pRegion2->getAreaProp(origin, xAxis, yAxis, perimeter, area, centroid, momInertia
|
||
, prodInertia, prinMoments, prinAxes, radiiGyration, extentsLow, extentsHigh);
|
||
|
||
es = Acad::eGeneralModelingFailure;
|
||
}
|
||
|
||
return es;
|
||
}
|
||
|
||
bool isRegionNull(AcDbRegion *pRegion)
|
||
{
|
||
AcGePoint3d origin(AcGePoint3d::kOrigin);
|
||
AcGeVector3d xAxis(AcGeVector3d::kXAxis);
|
||
AcGeVector3d yAxis(AcGeVector3d::kYAxis);
|
||
double perimeter(.0);
|
||
double area(.0);
|
||
AcGePoint2d centroid(AcGePoint2d::kOrigin);
|
||
double momInertia[2] = {};
|
||
double prodInertia(.0);
|
||
double prinMoments[2] = {};
|
||
AcGeVector2d prinAxes[2] = {};
|
||
double radiiGyration[2] = {};
|
||
AcGePoint2d extentsLow(AcGePoint2d::kOrigin);
|
||
AcGePoint2d extentsHigh(AcGePoint2d::kOrigin);
|
||
|
||
Acad::ErrorStatus es = pRegion->getAreaProp(origin, xAxis, yAxis, perimeter, area, centroid, momInertia
|
||
, prodInertia, prinMoments , prinAxes, radiiGyration, extentsLow, extentsHigh);
|
||
|
||
return es != Acad::eOk;
|
||
}
|
||
}
|
||
|
||
AcDbRegion *AecDbEwPipeBase::RegionFromCurvesDwgInFields(AcDbDwgFiler *pFiler, Adesk::UInt32 nLen)
|
||
{
|
||
AcDbCurve* pCurve = NULL;
|
||
AcDbVoidPtrArray arCurPtrs;
|
||
|
||
for(int i = 0;i < nLen;i++)
|
||
{
|
||
pCurve = BaseCurveDwgInFields(pFiler);
|
||
if (pCurve != NULL)
|
||
{
|
||
arCurPtrs.append(pCurve);
|
||
}
|
||
}
|
||
|
||
if (!arCurPtrs.isEmpty())
|
||
{
|
||
AcDbRegion* pRegion = NULL;
|
||
AcDbRegion* pRegionBig = NULL;
|
||
|
||
AcDbVoidPtrArray arRegPtrs;
|
||
Acad::ErrorStatus es = AcDbRegion::createFromCurves(arCurPtrs,arRegPtrs);
|
||
if (es == eInvalidInput)
|
||
{
|
||
AcDbVoidPtrArray arRes;
|
||
AcDbCurve* pCurveT = KTCADUtilityEx::ConvertBoundCurve(arCurPtrs,arRes);
|
||
if (pCurveT != NULL)
|
||
{
|
||
AcDbPolyline* pPl = AcDbPolyline::cast(pCurveT);
|
||
if (pPl != NULL)
|
||
{
|
||
pPl->setClosed(Adesk::kTrue);
|
||
}
|
||
arRes.removeAll();
|
||
arRes.append(pCurveT);
|
||
|
||
es = AcDbRegion::createFromCurves(arRes,arRegPtrs);
|
||
if (es != Acad::eOk)
|
||
{
|
||
FreeBuffer(0,arCurPtrs);
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
FreeBuffer(0,arCurPtrs);
|
||
}
|
||
|
||
if (arRegPtrs.isEmpty()) return NULL;
|
||
|
||
// 此处逻辑重新梳理
|
||
double dArea = .0, dAreaTmp = .0;
|
||
if (arRegPtrs.length() == 1)
|
||
pRegionBig = (AcDbRegion *)arRegPtrs.at(0);
|
||
else
|
||
{ // 得到最大面积的region
|
||
pRegionBig = (AcDbRegion *)arRegPtrs.at(0);
|
||
pRegionBig->getArea(dArea);
|
||
for (int i = 1; i < arRegPtrs.length(); ++i)
|
||
{
|
||
pRegion = (AcDbRegion *)arRegPtrs.at(i);
|
||
pRegion->getArea(dAreaTmp);
|
||
if (dAreaTmp > dArea)
|
||
{
|
||
dArea = dAreaTmp;
|
||
pRegionBig = pRegion;
|
||
}
|
||
}
|
||
}
|
||
|
||
if (pRegionBig != NULL)
|
||
{
|
||
int nPos = arRegPtrs.find(pRegionBig);
|
||
if (nPos != -1)
|
||
{
|
||
arRegPtrs.removeAt(nPos);
|
||
}
|
||
|
||
Acad::ErrorStatus es;
|
||
for (int j = 0;j < arRegPtrs.length();j++)
|
||
{
|
||
pRegion = (AcDbRegion*)arRegPtrs.at(j);
|
||
|
||
if (isRegionNull(pRegion) && isRegionNull(pRegionBig))
|
||
{
|
||
continue;
|
||
}
|
||
|
||
es = pRegionBig->booleanOper(AcDb::kBoolSubtract, pRegion);
|
||
}
|
||
return pRegionBig;
|
||
}
|
||
}
|
||
return NULL;
|
||
}
|
||
|
||
AcDbRegion* AecDbEwPipeBase::RegionAcisInDwgInFields(AcDbDwgFiler* pFiler)
|
||
{
|
||
//高版本acis方式
|
||
CString sFileName;
|
||
TCHAR* pszFileName = NULL;
|
||
pFiler->readString(&pszFileName);
|
||
if (pszFileName != NULL)
|
||
{
|
||
//Region_%s.dat
|
||
sFileName = pszFileName;
|
||
acutDelString(pszFileName);
|
||
|
||
Adesk::UInt32 nLen = 0;
|
||
pFiler->readUInt32(&nLen);
|
||
|
||
if (nLen > 0)
|
||
{
|
||
char* pszTxt = new char[nLen];
|
||
pFiler->readBytes(pszTxt,nLen);
|
||
|
||
if (sFileName.CompareNoCase(_T("errorfile")) == 0)
|
||
{
|
||
//原生写法
|
||
AcDbRegion* pRegion = (AcDbRegion*)AcDbRegion::desc()->create();
|
||
Acad::ErrorStatus es = pRegion->dwgInFields(pFiler);
|
||
|
||
return pRegion;
|
||
}
|
||
else
|
||
{
|
||
CString sFullPath = FilePath::getSystemTemporaryFolder();
|
||
sFullPath += _T("\\");
|
||
sFullPath += sFileName;
|
||
|
||
CFile file;
|
||
if (file.Open(sFullPath, CFile::modeCreate | CFile::modeWrite))
|
||
{
|
||
file.Write(pszTxt,nLen);
|
||
file.Close();
|
||
|
||
AcDbVoidPtrArray arBodyPtrs;
|
||
Acad::ErrorStatus es;
|
||
if ( Acad::eOk == (es = AcDbBody::acisIn(sFullPath,arBodyPtrs) ) )
|
||
{
|
||
if (arBodyPtrs.length() > 0)
|
||
{
|
||
AcDbEntity* pEnt = (AcDbEntity*)arBodyPtrs.first();
|
||
AcDbRegion* pRegion = AcDbRegion::cast(pEnt);
|
||
if (pRegion != NULL)
|
||
{
|
||
::DeleteFile(sFullPath);
|
||
delete[] pszTxt;
|
||
|
||
return pRegion;
|
||
}
|
||
//可能其他的合成或boolsubstract...
|
||
}
|
||
}
|
||
::DeleteFile(sFullPath);
|
||
}
|
||
}
|
||
delete[] pszTxt;
|
||
}
|
||
}
|
||
return NULL;
|
||
}
|
||
|
||
AcDbRegion* AecDbEwPipeBase::SectionRegionDwgInFields(AcDbDwgFiler* pFiler,int nVer)
|
||
{
|
||
assertWriteEnabled();
|
||
|
||
if (nVer < 4)//低版本方式
|
||
{
|
||
Adesk::UInt32 nLen = 0;
|
||
pFiler->readUInt32(&nLen);
|
||
|
||
return RegionFromCurvesDwgInFields(pFiler,nLen);
|
||
}
|
||
else
|
||
{
|
||
//高版本方式
|
||
Adesk::UInt32 nLen = 0;
|
||
pFiler->readUInt32(&nLen);
|
||
if (nLen > 0)
|
||
{
|
||
return RegionFromCurvesDwgInFields(pFiler,nLen);
|
||
}
|
||
else
|
||
{
|
||
//acutPrintf(_T("\nacis dwgin..."));
|
||
return RegionAcisInDwgInFields(pFiler);
|
||
}
|
||
}
|
||
return NULL;
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbEwPipeBase::dwgInFields(AcDbDwgFiler* pFiler)
|
||
{
|
||
AssertWriteEnabled();
|
||
|
||
//----- Read parent class information first.
|
||
Acad::ErrorStatus es = Acad::eOk;
|
||
if ( !pFiler->isKindOf(CMFCDbDwgFiler::desc()))
|
||
{
|
||
es = AecDbCurveBase::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 > AecDbEwPipeBase::kCurrentVersionNumber )
|
||
return (Acad::eMakeMeProxy) ;
|
||
|
||
m_mapSpecXData.Empty();
|
||
m_mapSpecXData.dwgInFields(pFiler);
|
||
if (version > 4)
|
||
m_mapSpecXData.SetAt(_T("&FOR&WEIR&"), (DWORD)version);
|
||
//如果没有编号
|
||
//默认分配编号
|
||
DefaultNo();
|
||
|
||
//读取类类型
|
||
CString sClass = _T("");
|
||
m_mapSpecXData.GetAt(KEY_CLASS,sClass);
|
||
|
||
if (m_pBaseCurve != NULL)
|
||
delete m_pBaseCurve;
|
||
m_pBaseCurve = BaseCurveDwgInFields(pFiler, version);
|
||
|
||
if (m_pRegion != NULL)
|
||
delete m_pRegion;
|
||
m_pRegion = SectionRegionDwgInFields(pFiler,version);
|
||
|
||
Adesk::Int32 nLen = 0;
|
||
pFiler->readInt32(&nLen);
|
||
|
||
BreakPos bp;
|
||
m_arBreaks.removeAll();
|
||
for (int i = 0;i < nLen;i++)
|
||
{
|
||
pFiler->readPoint3d(&bp.ptGe);
|
||
pFiler->readDouble(&bp.dLen);
|
||
|
||
if (version > 2)
|
||
{
|
||
pFiler->readInt16(&bp.nType);
|
||
}
|
||
m_arBreaks.append(bp);
|
||
}
|
||
|
||
pFiler->readInt16(&m_nInfActive);
|
||
|
||
Adesk::Int16 nFlowDir = 0;
|
||
pFiler->readInt16(&nFlowDir);
|
||
m_bShowFlowDir = false;
|
||
if (nFlowDir > 0)
|
||
{
|
||
m_bShowFlowDir = true;
|
||
}
|
||
|
||
m_bIsMainLock =false;
|
||
pFiler->readInt16(&nFlowDir);
|
||
if (nFlowDir > 0)
|
||
{
|
||
m_bIsMainLock = true;
|
||
}
|
||
|
||
m_bIsMinLock =false;
|
||
pFiler->readInt16(&nFlowDir);
|
||
if (nFlowDir > 0)
|
||
{
|
||
m_bIsMinLock = true;
|
||
m_bIsMainLock = false;
|
||
}
|
||
|
||
TCHAR* pszTemp = NULL;
|
||
pFiler->readString(&pszTemp);
|
||
if (pszTemp != NULL)
|
||
{
|
||
m_sGUID = pszTemp;
|
||
acutDelString(pszTemp);
|
||
}
|
||
|
||
pFiler->readSoftPointerId(&m_idSingleLayer);
|
||
pFiler->readSoftPointerId(&m_idSingleLnType);
|
||
|
||
pFiler->readSoftPointerId(&m_idDoubleLayer);
|
||
pFiler->readSoftPointerId(&m_idDoubleLnType);
|
||
|
||
if (version >= 2)//新加
|
||
{
|
||
pFiler->readSoftPointerId(&m_idDashLayer);
|
||
pFiler->readSoftPointerId(&m_idCenterLayer);
|
||
}
|
||
|
||
if (layerId().isNull())
|
||
setLayer(m_idDoubleLayer);
|
||
|
||
if (version > 6)
|
||
{
|
||
ReadUserInterface(pFiler);
|
||
}
|
||
|
||
return (pFiler->filerStatus ());
|
||
}
|
||
|
||
bool AecDbEwPipeBase::ReadUserInterface(AcDbDwgFiler *pFiler)
|
||
{
|
||
//读取用户接口
|
||
m_arUserInfs.removeAll();
|
||
AecUserInterface userInf;
|
||
|
||
Adesk::UInt32 nLen = 0;
|
||
pFiler->readUInt32(&nLen);
|
||
|
||
TCHAR* pszTemp = NULL;
|
||
for (Adesk::UInt32 i = 0; i < nLen; i++)
|
||
{
|
||
memset(&userInf, 0, sizeof(AecUserInterface));
|
||
|
||
pFiler->readString(&pszTemp);
|
||
if (pszTemp != NULL)
|
||
{
|
||
_tcscpy(userInf.szNo, pszTemp);
|
||
acutDelString(pszTemp);
|
||
}
|
||
|
||
Adesk::UInt16 nPts = 0;
|
||
pFiler->readUInt16(&nPts);
|
||
userInf.nPoints = nPts;
|
||
|
||
for (Adesk::UInt16 j = 0; j < nPts; j++)
|
||
{
|
||
pFiler->readPoint3d(&userInf.ptGe[j]);
|
||
}
|
||
|
||
pFiler->readVector3d(&userInf.vtDir);
|
||
|
||
pszTemp = NULL;
|
||
pFiler->readString(&pszTemp);
|
||
|
||
if (pszTemp != NULL)
|
||
{
|
||
_tcscpy(userInf.szSys, pszTemp);
|
||
acutDelString(pszTemp);
|
||
}
|
||
m_arUserInfs.append(userInf);
|
||
}
|
||
return false;
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbEwPipeBase::BaseCurveDwgOutFields(AcDbCurve* pBaseCurve,AcDbDwgFiler* pFiler) const
|
||
{
|
||
assertReadEnabled();
|
||
|
||
if (pBaseCurve != NULL)
|
||
{
|
||
LPCTSTR pszClass = pBaseCurve->isA()->name();
|
||
pFiler->writeString(pszClass);
|
||
|
||
AcDbLine* pLine = AcDbLine::cast(pBaseCurve);
|
||
if (pLine != NULL)
|
||
{
|
||
AcGePoint3d ptSta = pLine->startPoint();
|
||
AcGePoint3d ptEnd = pLine->endPoint();
|
||
|
||
pFiler->writePoint3d(ptSta);
|
||
pFiler->writePoint3d(ptEnd);
|
||
pFiler->writeVector3d(pLine->normal());
|
||
|
||
return Acad::eOk;
|
||
}
|
||
|
||
AcDbArc* pArc = AcDbArc::cast(pBaseCurve);
|
||
if (pArc != NULL)
|
||
{
|
||
pFiler->writePoint3d(pArc->center());
|
||
pFiler->writeDouble(pArc->radius());
|
||
pFiler->writeDouble(pArc->startAngle());
|
||
pFiler->writeDouble(pArc->endAngle());
|
||
pFiler->writeVector3d(pArc->normal());
|
||
return Acad::eOk;
|
||
}
|
||
|
||
AcDbCircle* pCir = AcDbCircle::cast(pBaseCurve);
|
||
if (pCir != NULL)
|
||
{
|
||
pFiler->writePoint3d(pCir->center());
|
||
pFiler->writeDouble(pCir->radius());
|
||
pFiler->writeVector3d(pCir->normal());
|
||
return Acad::eOk;
|
||
}
|
||
|
||
AcDbPolyline* pPl = AcDbPolyline::cast(pBaseCurve);
|
||
if (pPl != NULL)
|
||
{
|
||
Adesk::UInt32 nVts = pPl->numVerts();
|
||
pFiler->writeUInt32(nVts);
|
||
|
||
pFiler->writeDouble(pPl->elevation());
|
||
pFiler->writeVector3d(pPl->normal());
|
||
|
||
AcGePoint3d pt3d;
|
||
double dBulge = 0.0,dS = 0,dE = 0;
|
||
for (int i = 0;i < nVts;i++)
|
||
{
|
||
pPl->getPointAt(i,pt3d);
|
||
pPl->getBulgeAt(i,dBulge);
|
||
pPl->getWidthsAt(i, dS, dE);
|
||
|
||
pFiler->writePoint3d( pt3d );
|
||
pFiler->writeDouble(dBulge);
|
||
pFiler->writeDouble(dS);//>5 ver
|
||
pFiler->writeDouble(dE);
|
||
}
|
||
return Acad::eOk;
|
||
}
|
||
|
||
AcDbEllipse* pEl = AcDbEllipse::cast(pBaseCurve);
|
||
if (pEl != NULL)
|
||
{
|
||
pFiler->writePoint3d(pEl->center());
|
||
pFiler->writeDouble(pEl->radiusRatio());
|
||
pFiler->writeVector3d(pEl->majorAxis());
|
||
pFiler->writeDouble(pEl->startAngle());
|
||
pFiler->writeDouble(pEl->endAngle());
|
||
pFiler->writeVector3d(pEl->normal());
|
||
return Acad::eOk;
|
||
}
|
||
|
||
AcDbSpline* pSp = AcDbSpline::cast(pBaseCurve);
|
||
if (pSp != NULL)
|
||
{
|
||
//...
|
||
return Acad::eOk;
|
||
}
|
||
|
||
//只支持标准点链接的3dpl线
|
||
AcDb3dPolyline* pPl3d = AcDb3dPolyline::cast(pBaseCurve);
|
||
if (pPl3d != NULL)
|
||
{
|
||
AcGePoint3dArray arPts;
|
||
|
||
AcDbEntity* pVEnt = NULL;
|
||
AcDbObjectIterator* pIt = pPl3d->vertexIterator();
|
||
for (pIt->start();!pIt->done();pIt->step())
|
||
{
|
||
pVEnt = pIt->entity();
|
||
|
||
AcDb3dPolylineVertex* pVtex = AcDb3dPolylineVertex::cast(pVEnt);
|
||
if (pVtex != NULL )
|
||
{
|
||
arPts.append(pVtex->position());
|
||
}
|
||
}
|
||
|
||
pFiler->writeInt32(arPts.length());
|
||
for (int j = 0;j < arPts.length();j++)
|
||
{
|
||
pFiler->writePoint3d(arPts.at(j));
|
||
}
|
||
return Acad::eOk;
|
||
}
|
||
|
||
AecDb3dRoadAxisLine* pRoadAxis = AecDb3dRoadAxisLine::cast(pBaseCurve);
|
||
if (pRoadAxis != NULL)
|
||
{
|
||
return pRoadAxis->dwgOutFields(pFiler);
|
||
}
|
||
}
|
||
return Acad::eOk;
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbEwPipeBase::RegionExplodeDwgOutFields(AcDbDwgFiler* pFiler,AcDbVoidPtrArray& arCurPtrs) const
|
||
{
|
||
Adesk::UInt32 nCurs = arCurPtrs.length();
|
||
pFiler->writeUInt32(nCurs);
|
||
|
||
AcDbCurve* pCurve = NULL;
|
||
for (int i = 0;i < arCurPtrs.length();i++)
|
||
{
|
||
pCurve = (AcDbCurve*)arCurPtrs.at(i);
|
||
BaseCurveDwgOutFields(pCurve,pFiler);
|
||
delete pCurve;
|
||
}
|
||
return Acad::eOk;
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbEwPipeBase::RegionAcisoutDwgOutFields(AcDbDwgFiler* pFiler) const
|
||
{
|
||
if (m_pRegion == NULL)
|
||
return Acad::eInvalidInput;
|
||
|
||
//开始写acis方式
|
||
//避免多文档crash
|
||
TCHAR szHandleStr[19];
|
||
memset(szHandleStr,0,sizeof(szHandleStr) );
|
||
objectId().handle().getIntoAsciiBuffer(szHandleStr);
|
||
|
||
CString sFileName;
|
||
sFileName.Format(_T("Region_%s.dat"),szHandleStr);
|
||
|
||
CString sFullPath = FilePath::getSystemTemporaryFolder();
|
||
sFullPath += _T("\\");
|
||
sFullPath += sFileName;
|
||
|
||
AcDbVoidPtrArray arBodyPtrs;
|
||
arBodyPtrs.append(m_pRegion);
|
||
|
||
Acad::ErrorStatus es;
|
||
if (Acad::eOk == (es = AcDbBody::acisOut(sFullPath, arBodyPtrs)))
|
||
{
|
||
CFile file;
|
||
if (file.Open(sFullPath, CFile::modeRead))
|
||
{
|
||
//确认REGION不会超过32位数量级字节
|
||
//强制转换兼容可能的07-09CAD
|
||
ULONGLONG dwFileLength = file.GetLength();
|
||
Adesk::UInt32 nLen = (Adesk::UInt32)dwFileLength;
|
||
|
||
char* pszTxt = new char[nLen];
|
||
file.Read(pszTxt, nLen);
|
||
file.Close();
|
||
|
||
pFiler->writeString((LPCTSTR)sFileName);
|
||
pFiler->writeUInt32(nLen);
|
||
pFiler->writeBytes(pszTxt,nLen);
|
||
|
||
::DeleteFile(sFullPath);
|
||
delete[] pszTxt;
|
||
return Acad::eOk;
|
||
}
|
||
else
|
||
{
|
||
pFiler->writeString(_T("errorfile"));
|
||
|
||
char* pszTxt = new char[7];
|
||
memset(pszTxt,0,7);
|
||
|
||
pFiler->writeUInt32(7);
|
||
|
||
pFiler->writeBytes(pszTxt,7);
|
||
|
||
//原生写法
|
||
es = m_pRegion->dwgOutFields(pFiler);
|
||
|
||
return es;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
pFiler->writeString(_T("errorfile"));
|
||
|
||
char* pszTxt = new char[7];
|
||
memset(pszTxt,0,7);
|
||
|
||
pFiler->writeUInt32(7);
|
||
|
||
pFiler->writeBytes(pszTxt,7);
|
||
|
||
//原生写法
|
||
es = m_pRegion->dwgOutFields(pFiler);
|
||
|
||
return es;
|
||
}
|
||
return Acad::eOutOfMemory;
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbEwPipeBase::SectionRegionDwgOutFields(AcDbDwgFiler* pFiler,int nVer) const
|
||
{
|
||
assertReadEnabled();
|
||
|
||
if (m_pRegion != NULL)
|
||
{
|
||
if (nVer < 4)//旧版本,保持原样,有错误漏洞
|
||
{
|
||
AcDbVoidPtrArray arCurPtrs;
|
||
m_pRegion->explode(arCurPtrs);
|
||
|
||
if (!arCurPtrs.isEmpty())
|
||
{
|
||
return RegionExplodeDwgOutFields(pFiler,arCurPtrs);
|
||
}
|
||
else
|
||
{
|
||
//旧版本错误漏洞
|
||
//旧版本不考虑 nVer已经升级
|
||
//...
|
||
}
|
||
}
|
||
else
|
||
{
|
||
AcDbVoidPtrArray arCurPtrs;
|
||
m_pRegion->explode(arCurPtrs);
|
||
|
||
//如果炸碎成功
|
||
if (!arCurPtrs.isEmpty())
|
||
{
|
||
//轻量化写法
|
||
return RegionExplodeDwgOutFields(pFiler,arCurPtrs);
|
||
}
|
||
else
|
||
{
|
||
//补救措施,重量化写法
|
||
//写入长度0 旧版本<4 情况不考虑 nVer已经升级
|
||
Adesk::UInt32 nCurs = 0;
|
||
pFiler->writeUInt32(nCurs);
|
||
|
||
return RegionAcisoutDwgOutFields(pFiler);
|
||
}
|
||
}
|
||
}
|
||
return Acad::eOk;
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbEwPipeBase::DefaultNo()
|
||
{
|
||
CString sNo;
|
||
if (!m_mapSpecXData.GetAt(KEY_NO,sNo))
|
||
{
|
||
static int nNo = 1;
|
||
sNo.Format(_T("No.%d"),nNo);
|
||
m_mapSpecXData.SetAt(KEY_NO,sNo);
|
||
nNo++;
|
||
}
|
||
return Acad::eOk;
|
||
}
|
||
|
||
void AecDbEwPipeBase::SetPlotWidth(double dW)
|
||
{
|
||
AssertWriteEnabled();
|
||
m_mapSpecXData.SetAt(KEY_PLOTW,dW);
|
||
|
||
//清除缓存,由本体二维样本重建
|
||
Clean2DBuffer();
|
||
}
|
||
|
||
void AecDbEwPipeBase::WriteUserInterface(AcDbDwgFiler *pFiler) const
|
||
{
|
||
assertReadEnabled();
|
||
|
||
pFiler->writeUInt32(m_arUserInfs.length());
|
||
|
||
for (int i = 0;i < m_arUserInfs.length();i++)
|
||
{
|
||
const AecUserInterface &inf = m_arUserInfs.at(i);
|
||
|
||
pFiler->writeString(inf.szNo);
|
||
|
||
pFiler->writeUInt16(inf.nPoints);
|
||
|
||
for (Adesk::UInt16 ii = 0;ii < inf.nPoints;ii++)
|
||
{
|
||
pFiler->writePoint3d(inf.ptGe[ii]);
|
||
}
|
||
|
||
pFiler->writeVector3d(inf.vtDir);
|
||
|
||
pFiler->writeString(inf.szSys);
|
||
}
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbEwPipeBase::dwgOutFields(AcDbDwgFiler* pFiler) const
|
||
{
|
||
assertReadEnabled();
|
||
|
||
//----- Save parent class information first.
|
||
Acad::ErrorStatus es = Acad::eOk;
|
||
if ( !pFiler->isKindOf(CMFCDbDwgFiler::desc()))
|
||
{
|
||
es = AecDbCurveBase::dwgOutFields (pFiler) ;
|
||
if ( es != Acad::eOk )
|
||
return (es) ;
|
||
}
|
||
|
||
//----- Object version number needs to be saved first
|
||
if ( (es =pFiler->writeUInt32 (AecDbEwPipeBase::kCurrentVersionNumber)) != Acad::eOk )
|
||
return (es) ;
|
||
|
||
m_mapSpecXData.dwgOutFields(pFiler);
|
||
|
||
if (m_pBaseCurve != NULL)
|
||
BaseCurveDwgOutFields(m_pBaseCurve,pFiler);
|
||
else
|
||
pFiler->writeString(_T("-xxxx_"));
|
||
|
||
if (m_pRegion != NULL)
|
||
{
|
||
SectionRegionDwgOutFields(pFiler,AecDbEwPipeBase::kCurrentVersionNumber);
|
||
}
|
||
else
|
||
{
|
||
//补位
|
||
pFiler->writeUInt32(0);
|
||
|
||
pFiler->writeString(_T("***"));
|
||
|
||
char pszTxt[7];
|
||
memset(pszTxt,0,sizeof(char)*7);
|
||
|
||
pFiler->writeUInt32(7);
|
||
pFiler->writeBytes(pszTxt,7);
|
||
}
|
||
|
||
Adesk::Int32 nLen = m_arBreaks.length();
|
||
pFiler->writeInt32(nLen);
|
||
|
||
for (int i = 0;i < nLen;i++)
|
||
{
|
||
const BreakPos& bp = m_arBreaks.at(i);
|
||
pFiler->writePoint3d(bp.ptGe);
|
||
pFiler->writeDouble(bp.dLen);
|
||
|
||
if (AecDbEwPipeBase::kCurrentVersionNumber > 2)
|
||
{
|
||
pFiler->writeInt16(bp.nType);
|
||
}
|
||
}
|
||
|
||
pFiler->writeInt16(m_nInfActive);
|
||
|
||
pFiler->writeInt16(m_bShowFlowDir ? 1 : 0);
|
||
pFiler->writeInt16(m_bIsMainLock ? 1 : 0);
|
||
pFiler->writeInt16(m_bIsMinLock ? 1 : 0);
|
||
|
||
pFiler->writeString((LPCTSTR)m_sGUID);
|
||
|
||
pFiler->writeSoftPointerId(m_idSingleLayer);
|
||
pFiler->writeSoftPointerId(m_idSingleLnType);
|
||
|
||
pFiler->writeSoftPointerId(m_idDoubleLayer);
|
||
pFiler->writeSoftPointerId(m_idDoubleLnType);
|
||
|
||
if (AecDbEwPipeBase::kCurrentVersionNumber >= 2)//新加
|
||
{
|
||
pFiler->writeSoftPointerId(m_idDashLayer);
|
||
pFiler->writeSoftPointerId(m_idCenterLayer);
|
||
}
|
||
|
||
WriteUserInterface(pFiler);
|
||
|
||
return (pFiler->filerStatus ());
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbEwPipeBase::dxfInFields(AcDbDxfFiler* pFiler)
|
||
{
|
||
AssertWriteEnabled();
|
||
return Acad::eOk;
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbEwPipeBase::dxfOutFields(AcDbDxfFiler* pFiler) const
|
||
{
|
||
assertReadEnabled();
|
||
|
||
return Acad::eOk;
|
||
}
|
||
|
||
Acad::ErrorStatus ReMakeSureCopy(AcDbCurve* pCurTo,AcDbCurve* pCurFr)
|
||
{
|
||
AecDbCurveBase::CopyObject(*pCurFr,*pCurTo);
|
||
return Acad::eOk;
|
||
|
||
//!!!
|
||
AcDbLine* pLn = AcDbLine::cast(pCurTo);
|
||
if (pLn != NULL)
|
||
{
|
||
AcDbLine* pLn2 = AcDbLine::cast(pCurFr);
|
||
if (pLn2 != NULL)
|
||
{
|
||
pLn->setStartPoint(pLn2->startPoint());
|
||
pLn->setEndPoint(pLn2->endPoint());
|
||
pLn->setNormal(pLn2->normal());
|
||
}
|
||
}
|
||
|
||
AcDbArc* pArc = AcDbArc::cast(pCurTo);
|
||
if (pArc != NULL)
|
||
{
|
||
AcDbArc* pArc2 = AcDbArc::cast(pCurFr);
|
||
if (pArc2 != NULL)
|
||
{
|
||
pArc->setCenter(pArc2->center());
|
||
pArc->setRadius(pArc2->radius());
|
||
pArc->setStartAngle(pArc2->startAngle());
|
||
pArc->setEndAngle(pArc2->endAngle());
|
||
pArc->setNormal(pArc2->normal());
|
||
}
|
||
}
|
||
|
||
AcDbCircle* pCir = AcDbCircle::cast(pCurTo);
|
||
if (pCir != NULL)
|
||
{
|
||
AcDbCircle* pCir2 = AcDbCircle::cast(pCurFr);
|
||
if (pCir2 != NULL)
|
||
{
|
||
pCir->setCenter(pCir2->center());
|
||
pCir->setRadius(pCir2->radius());
|
||
pCir->setNormal(pCir2->normal());
|
||
}
|
||
}
|
||
|
||
AcDbPolyline* pPl = AcDbPolyline::cast(pCurTo);
|
||
if (pPl != NULL)
|
||
{
|
||
AcDbPolyline* pPl2 = AcDbPolyline::cast(pCurFr);
|
||
if (pPl2 != NULL)
|
||
{
|
||
if (pPl2->numVerts() == pPl->numVerts())
|
||
{
|
||
pPl->setNormal(pPl2->normal());
|
||
pPl->setElevation(pPl2->elevation());
|
||
|
||
AcGePoint2d pt2d;
|
||
double dBulge = 0.0,dSta = 0.0,dEnd = 0.0;
|
||
for (int i = 0;i < pPl2->numVerts();i++)
|
||
{
|
||
pPl2->getPointAt(i,pt2d);
|
||
pPl2->getBulgeAt(i,dBulge);
|
||
pPl2->getWidthsAt(i,dSta,dEnd);
|
||
pPl->setPointAt(i,pt2d);
|
||
pPl->setBulgeAt(i,dBulge);
|
||
pPl->setWidthsAt(i,dSta,dEnd);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
AecDb3dRoadAxisLine* pRoad = AecDb3dRoadAxisLine::cast(pCurTo);
|
||
if (pRoad != NULL)
|
||
{
|
||
AecDb3dRoadAxisLine* pRoad2 = AecDb3dRoadAxisLine::cast(pCurFr);
|
||
if (pRoad2 != NULL)
|
||
{
|
||
pRoad->ReMakeSureCopy(pRoad2);
|
||
}
|
||
}
|
||
return Acad::eOk;
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbEwPipeBase::copyFrom(const AcRxObject* pSrc)
|
||
{
|
||
assertWriteEnabled();
|
||
|
||
AecDbCurveBase::copyFrom(pSrc);
|
||
|
||
AecDbEwPipeBase* pBase = AecDbEwPipeBase::cast(pSrc);
|
||
if (pBase != NULL)
|
||
{
|
||
CopyObject(*pBase,*this);
|
||
|
||
|
||
//轨迹数据
|
||
AcGeVector3d vtL;
|
||
Acad::ErrorStatus es;
|
||
if (pBase->m_pBaseCurve)
|
||
{
|
||
if (m_pBaseCurve == NULL)
|
||
{
|
||
//!!!clone为何属性信息复制失败
|
||
m_pBaseCurve = (AcDbCurve *)pBase->m_pBaseCurve->clone();
|
||
ReMakeSureCopy(m_pBaseCurve, pBase->m_pBaseCurve);
|
||
}
|
||
else
|
||
{
|
||
es = m_pBaseCurve->copyFrom(pBase->m_pBaseCurve);
|
||
ReMakeSureCopy(m_pBaseCurve, pBase->m_pBaseCurve);
|
||
}
|
||
|
||
struct resbuf *pRb = pBase->m_pBaseCurve->xData();
|
||
if (pRb != NULL)
|
||
{
|
||
m_pBaseCurve->setXData(pRb);
|
||
acutRelRb(pRb);
|
||
}
|
||
}
|
||
|
||
//截面数据
|
||
if (pBase->m_pRegion)
|
||
{
|
||
if (m_pRegion == NULL)
|
||
{
|
||
m_pRegion = (AcDbRegion *)pBase->m_pRegion->clone();
|
||
}
|
||
else
|
||
{
|
||
es = m_pRegion->copyFrom((AcDbRegion *)pBase->m_pRegion);
|
||
}
|
||
}
|
||
|
||
m_nInfActive = pBase->m_nInfActive;
|
||
m_bActive = pBase->m_bActive;
|
||
m_bShowFlowDir = pBase->m_bShowFlowDir;
|
||
m_bIsMainLock = pBase->m_bIsMainLock;
|
||
m_bIsMinLock = pBase->m_bIsMinLock;
|
||
|
||
m_arBreaks.removeAll();
|
||
m_arBreaks.append(pBase->m_arBreaks);
|
||
|
||
//其他按通用图层和线型
|
||
//单线图层和线型
|
||
m_idSingleLayer = pBase->m_idSingleLayer;
|
||
m_idSingleLnType = pBase->m_idSingleLnType;
|
||
|
||
//双线图层和线型
|
||
m_idDoubleLayer = pBase->m_idDoubleLayer;
|
||
m_idDoubleLnType = pBase->m_idDoubleLnType;
|
||
|
||
m_idDashLayer = pBase->m_idDashLayer;
|
||
m_idCenterLayer = pBase->m_idCenterLayer;
|
||
|
||
AcDbObjectId idLay = pBase->layerId();
|
||
es = setLayer(pBase->layerId());
|
||
|
||
//专业数据
|
||
m_mapSpecXData.Empty();
|
||
m_mapSpecXData.CopyFrom(&pBase->m_mapSpecXData);
|
||
|
||
//发送提资需要相同的ID
|
||
Adesk::Int16 nVal = acdbCurDwg()->useri4();
|
||
if (nVal != KEY_NOPROTECT)
|
||
{
|
||
int nVt = 0;
|
||
CString sID = IDCreate();
|
||
m_sGUID = sID;
|
||
|
||
if (m_mapSpecXData.HasKey(KEY_NO, nVt))
|
||
m_mapSpecXData.SetAt(KEY_NO, sID);
|
||
}
|
||
|
||
this->m_arUserInfs.removeAll();
|
||
this->m_arUserInfs.append(pBase->m_arUserInfs);
|
||
}
|
||
return Acad::eOk;
|
||
}
|
||
|
||
#if ARX>16
|
||
void AecDbEwPipeBase::subList() const
|
||
{
|
||
assertReadEnabled();
|
||
|
||
AecDbCurveBase::subList();
|
||
|
||
acutPrintf(_T("\nGUID:%s"),m_sGUID);
|
||
|
||
acutPrintf(_T("\n放样线:"));
|
||
if (m_pBaseCurve != NULL)
|
||
{
|
||
m_pBaseCurve->list();
|
||
}
|
||
|
||
acutPrintf(_T("\n截面:"));
|
||
if (m_pRegion != NULL)
|
||
{
|
||
m_pRegion->list();
|
||
}
|
||
|
||
acutPrintf(_T("\n属性数据:"));
|
||
m_mapSpecXData.List();
|
||
}
|
||
|
||
bool IsObjectInCurrentSelectionSet(const AcDbObjectId& idHole)
|
||
{
|
||
//acedGetCurrentSelectionSet获取不准确,没有当前选择集合时,始终获取是上次的
|
||
//AcDbObjectIdArray arIds;
|
||
//acedGetCurrentSelectionSet(arIds);
|
||
|
||
ads_name ssSet,ent;
|
||
CKTCadUtility::GetCurrentPickSet(ssSet);
|
||
|
||
if ( Acad::eOk == acdbGetAdsName(ent,idHole) )
|
||
{
|
||
if (RTNORM == acedSSMemb(ent,ssSet) )
|
||
{
|
||
acedSSFree(ssSet);
|
||
return true;
|
||
}
|
||
}
|
||
acedSSFree(ssSet);
|
||
return false;
|
||
|
||
/*int nFat = -1;
|
||
if ( !arIds.find(idHole,nFat) )
|
||
return false;
|
||
return true;*/
|
||
}
|
||
|
||
void AecDbEwPipeBase::GetAssocHandleObjs(AcDbObjectIdArray& arIds)
|
||
{
|
||
assertReadEnabled();
|
||
|
||
//关联的洞口和套管联动
|
||
AecDbObjXDataMap::It it = m_mapSpecXData.Begin();
|
||
AecDbObjXDataMap::It end = m_mapSpecXData.End();
|
||
|
||
CString sKey;
|
||
AecXData cVal;
|
||
memset(&cVal,0,sizeof(AecXData));
|
||
|
||
AcDbObjectId idSrc,idCloned;
|
||
for (; it != end;)
|
||
{
|
||
if (!m_mapSpecXData.GetNext(it, sKey,cVal)) break;
|
||
if ( sKey.Find(_T("$H")) != -1 && cVal.nVt == VT_BSTR )//可能的实体句柄
|
||
{
|
||
AcDbHandle handle(cVal.pszVal);
|
||
|
||
AcDbObjectId idHole;
|
||
if ( Acad::eOk == acdbCurDwg()->getAcDbObjectId(idHole,false,handle) )
|
||
arIds.append(idHole);
|
||
|
||
acutPrintf(_T("\nAssoc:%s"),cVal.pszVal);
|
||
}
|
||
}
|
||
}
|
||
|
||
bool AecDbEwPipeBase::GetPositionGrip(int nIndex, AecGripData *&pGrip) const
|
||
{
|
||
if (nIndex < GRIP_LENGTH && nIndex >= 0)
|
||
{
|
||
pGrip = &m_pGripAppData[nIndex];
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
|
||
//用户接口
|
||
void AecDbEwPipeBase::AddUserInterface(const AecUserInterface &inf)
|
||
{
|
||
AssertWriteEnabled();
|
||
m_arUserInfs.append(inf);
|
||
}
|
||
|
||
bool AecDbEwPipeBase::RemoveUserInterface(const TCHAR *pszNo)
|
||
{
|
||
if (pszNo == NULL)
|
||
return false;
|
||
|
||
AssertWriteEnabled();
|
||
for (int i = 0;i < m_arUserInfs.length();i++)
|
||
{
|
||
AecUserInterface &inf = m_arUserInfs.at(i);
|
||
if (_tcscmp(inf.szNo, pszNo) == 0)
|
||
{
|
||
m_arUserInfs.removeAt(i);
|
||
return true;
|
||
}
|
||
}
|
||
return false;
|
||
}
|
||
|
||
bool AecDbEwPipeBase::RemoveUserInterface(int nIndex)
|
||
{
|
||
AssertWriteEnabled();
|
||
if (nIndex > -1 && nIndex < m_arUserInfs.length())
|
||
{
|
||
m_arUserInfs.removeAt(nIndex);
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
|
||
int AecDbEwPipeBase::GetUserInterfaceCount() const
|
||
{
|
||
assertReadEnabled();
|
||
return m_arUserInfs.length();
|
||
}
|
||
|
||
bool AecDbEwPipeBase::GetUserInterface(int nIndex, AecUserInterface &inf) const
|
||
{
|
||
assertReadEnabled();
|
||
if (nIndex > -1 && nIndex < m_arUserInfs.length())
|
||
{
|
||
inf = m_arUserInfs.at(nIndex);
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
|
||
bool AecDbEwPipeBase::GetUserInterface(const AcGePoint3d &ptHit, AecUserInterface &inf) const
|
||
{
|
||
assertReadEnabled();
|
||
|
||
AcGePoint3d ptInf;
|
||
for (int i = 0;i < m_arUserInfs.length();i++)
|
||
{
|
||
const AecUserInterface &infu = m_arUserInfs.at(i);
|
||
if (infu.nPoints == 2)
|
||
{
|
||
ptInf = infu.ptGe[0] + infu.vtDir;
|
||
if (ptHit.distanceTo(ptInf) < 1.e-3)
|
||
{
|
||
inf = infu;
|
||
return true;
|
||
}
|
||
}
|
||
else if (infu.nPoints == 4)//目前只考虑矩形
|
||
{
|
||
ptInf = MidPoint(infu.ptGe[0], infu.ptGe[2]) + infu.vtDir;
|
||
if (ptHit.distanceTo(ptInf) < 1.e-3)
|
||
{
|
||
inf = infu;
|
||
return true;
|
||
}
|
||
}
|
||
}
|
||
return false;
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbEwPipeBase::subTransformBy(const AcGeMatrix3d& xform)
|
||
{
|
||
AssertWriteEnabled();
|
||
if (m_pBaseCurve != NULL)
|
||
{
|
||
m_pBaseCurve->transformBy(xform);
|
||
|
||
AcGePoint3d ptOrg;
|
||
if ( m_mapSpecXData.GetAt(KEY_ORGPT,ptOrg) )
|
||
{
|
||
ptOrg.transformBy(xform);
|
||
m_mapSpecXData.SetAt(KEY_ORGPT,ptOrg);
|
||
}
|
||
}
|
||
|
||
double dEl = 0.0;
|
||
if (m_mapSpecXData.GetAt(PIPE_EL, dEl))
|
||
{
|
||
AcGePoint3d pt(0, 0, dEl);
|
||
pt.transformBy(xform);
|
||
m_mapSpecXData.SetAt(PIPE_EL, pt.z);
|
||
}
|
||
|
||
//套管,洞口联动
|
||
if (objectId().isValid())//确认变换时处理
|
||
{
|
||
//多余一个的选择的集合,不处理套管,洞口联动
|
||
//防止重复处理
|
||
//acedGetCurrentSelectionSet获取不准确,没有当前选择集合时,始终获取是上次的
|
||
/*AcDbObjectIdArray arIds;
|
||
acedGetCurrentSelectionSet(arIds);
|
||
if ( arIds.length() > 1 )
|
||
{
|
||
return Acad::eOk;
|
||
}*/
|
||
|
||
ads_name ssSet;
|
||
CKTCadUtility::GetCurrentPickSet(ssSet);
|
||
Adesk::Int32 nLenS = 0;
|
||
acedSSLength(ssSet,&nLenS);
|
||
if (nLenS > 1)
|
||
{
|
||
acedSSFree(ssSet);
|
||
return Acad::eOk;
|
||
}
|
||
acedSSFree(ssSet);
|
||
|
||
//关联的洞口和套管联动
|
||
AecDbObjXDataMap::It it = m_mapSpecXData.Begin();
|
||
AecDbObjXDataMap::It end = m_mapSpecXData.End();
|
||
|
||
CString sKey;
|
||
AecXData cVal;
|
||
memset(&cVal,0,sizeof(AecXData));
|
||
|
||
AcDbObjectId idSrc,idCloned;
|
||
for (; it != end;)
|
||
{
|
||
if (!m_mapSpecXData.GetNext(it, sKey, cVal)) break;
|
||
if (sKey.Find(_T("$H")) != -1 && cVal.nVt == VT_BSTR)//可能的实体句柄
|
||
{
|
||
AcDbHandle handle(cVal.pszVal);
|
||
|
||
AcDbObjectId idHole;
|
||
if ( Acad::eOk == acdbCurDwg()->getAcDbObjectId(idHole,false,handle) )
|
||
{
|
||
if ( !IsObjectInCurrentSelectionSet(idHole) )
|
||
{
|
||
//acutPrintf(_T("\n%s"),cVal.pszVal);
|
||
|
||
AcDbEntity* pEnt = NULL;
|
||
if (Acad::eOk == acdbOpenAcDbEntity(pEnt,idHole,AcDb::kForWrite))
|
||
{
|
||
pEnt->transformBy(xform);
|
||
pEnt->close();
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
//用户接口联动
|
||
for (int i = 0;i < m_arUserInfs.length();i++)
|
||
{
|
||
AecUserInterface &inf = m_arUserInfs.at(i);
|
||
for(int j = 0;j < inf.nPoints;j++)
|
||
{
|
||
inf.ptGe[j].transformBy(xform);
|
||
inf.vtDir.transformBy(xform);
|
||
}
|
||
}
|
||
|
||
return Acad::eOk;
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbEwPipeBase::subGetGripPoints(AcDbGripDataPtrArray& grips,
|
||
const double curViewUnitSize,
|
||
const int gripSize,
|
||
const AcGeVector3d& curViewDir,
|
||
const int bitflags) const
|
||
{
|
||
assertReadEnabled();
|
||
if (m_pBaseCurve != NULL)
|
||
{
|
||
return m_pBaseCurve->getGripPoints(grips,curViewUnitSize,gripSize,curViewDir,bitflags);
|
||
}
|
||
return Acad::eNotImplemented;
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbEwPipeBase::subMoveGripPointsAt(const AcDbVoidPtrArray& appData, const AcGeVector3d& offset, const int bitflags)
|
||
{
|
||
AssertWriteEnabled();
|
||
if (m_pBaseCurve != NULL)
|
||
{
|
||
return m_pBaseCurve->moveGripPointsAt(appData,offset,bitflags);
|
||
}
|
||
return Acad::eNotImplemented;
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbEwPipeBase::subGetStretchPoints(AcGePoint3dArray& stretchPoints) const
|
||
{
|
||
assertReadEnabled();
|
||
if (m_pBaseCurve != NULL)
|
||
{
|
||
return m_pBaseCurve->getStretchPoints(stretchPoints);
|
||
}
|
||
return Acad::eOk;
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbEwPipeBase::subMoveStretchPointsAt(const AcDbIntArray& indices,const AcGeVector3d& offset)
|
||
{
|
||
AssertWriteEnabled();
|
||
if (m_pBaseCurve != NULL)
|
||
{
|
||
return m_pBaseCurve->moveStretchPointsAt(indices,offset);
|
||
}
|
||
return Acad::eOk;
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbEwPipeBase::subGetGripPoints(AcGePoint3dArray& gripPoints,AcDbIntArray& osnapModes,AcDbIntArray& geomIds) const
|
||
{
|
||
assertReadEnabled();
|
||
if (m_pBaseCurve != NULL)
|
||
{
|
||
return m_pBaseCurve->getGripPoints(gripPoints,osnapModes,geomIds);
|
||
}
|
||
return Acad::eOk;
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbEwPipeBase::subMoveGripPointsAt(const AcDbIntArray& indices,const AcGeVector3d& offset)
|
||
{
|
||
AssertWriteEnabled();
|
||
if (m_pBaseCurve != NULL)
|
||
{
|
||
return m_pBaseCurve->moveGripPointsAt(indices,offset);
|
||
}
|
||
return Acad::eOk;
|
||
}
|
||
|
||
void AecDbEwPipeBase::GetGripText(int nPos, CString& sText)
|
||
{
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbEwPipeBase::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();
|
||
|
||
if (i >= GRIP_LENGTH)//多余不显示
|
||
return Acad::eOk;
|
||
|
||
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 AecDbEwPipeBase::subIntersectWith(const AcDbEntity* pEnt,
|
||
AcDb::Intersect intType,
|
||
AcGePoint3dArray& points,
|
||
INT_PTR thisGsMarker,
|
||
INT_PTR otherGsMarker) const
|
||
{
|
||
assertReadEnabled();
|
||
|
||
Acad::ErrorStatus es(Acad::eOk);
|
||
if (m_pBaseCurve != NULL)
|
||
{
|
||
//放开后很慢
|
||
es = m_pBaseCurve->intersectWith(pEnt,intType,points,thisGsMarker,otherGsMarker);
|
||
|
||
//EXTEND 仅仅需要 m_pBaseCurve 求交
|
||
struct resbuf rb;
|
||
acedGetVar(_T("CMDNAMES"),&rb);
|
||
if (_tcscmp(rb.resval.rstring,_T("EXTEND")) != 0)
|
||
{
|
||
AcDbEntity* pEntT = NULL;
|
||
const AcDbVoidPtrArray& ar2D = Get2DBuffer();
|
||
|
||
AcGePoint3dArray arPts1;
|
||
for (int i = 0;i < ar2D.length();i++)
|
||
{
|
||
pEntT = (AcDbEntity*)ar2D.at(i);
|
||
es = pEntT->intersectWith(pEnt,intType,points,thisGsMarker,otherGsMarker);
|
||
}
|
||
}
|
||
}
|
||
return es;
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbEwPipeBase::subIntersectWith(const AcDbEntity* pEnt,
|
||
AcDb::Intersect intType,
|
||
const AcGePlane& projPlane,
|
||
AcGePoint3dArray& points,
|
||
INT_PTR thisGsMarker,
|
||
INT_PTR otherGsMarker) const
|
||
{
|
||
assertReadEnabled();
|
||
|
||
Acad::ErrorStatus es;
|
||
if (m_pBaseCurve != NULL)
|
||
{
|
||
//放开后很慢
|
||
es = m_pBaseCurve->intersectWith(pEnt,intType,projPlane,points,thisGsMarker,otherGsMarker);
|
||
|
||
//EXTEND 仅仅需要 m_pBaseCurve 求交
|
||
struct resbuf rb;
|
||
acedGetVar(_T("CMDNAMES"),&rb);
|
||
if (_tcscmp(rb.resval.rstring,_T("EXTEND")) != 0)
|
||
{
|
||
AcDbEntity* pEntT = NULL;
|
||
const AcDbVoidPtrArray& ar2D = Get2DBuffer();
|
||
|
||
AcGePoint3dArray arPts1;
|
||
for (int i = 0;i < ar2D.length();i++)
|
||
{
|
||
pEntT = (AcDbEntity*)ar2D.at(i);
|
||
es = pEntT->intersectWith(pEnt,intType,projPlane,points,thisGsMarker,otherGsMarker);
|
||
}
|
||
}
|
||
}
|
||
return es;
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbEwPipeBase::subGetOsnapPoints(AcDb::OsnapMode osnapMode,
|
||
INT_PTR gsSelectionMark,
|
||
const AcGePoint3d& pickPoint,
|
||
const AcGePoint3d& lastPoint,
|
||
const AcGeMatrix3d& viewXform,
|
||
AcGePoint3dArray& snapPoints,
|
||
AcDbIntArray& geomIds) const
|
||
{
|
||
assertReadEnabled();
|
||
|
||
if (m_pBaseCurve != NULL)
|
||
{
|
||
m_pBaseCurve->getOsnapPoints(osnapMode,gsSelectionMark,pickPoint,lastPoint,viewXform,snapPoints,geomIds);
|
||
}
|
||
|
||
AcDbEntity* pEnt = NULL;
|
||
const AcDbVoidPtrArray& ar2D = Get2DBuffer();
|
||
|
||
AcGePoint3dArray arPts1;
|
||
for (int i = 0;i < ar2D.length();i++)
|
||
{
|
||
pEnt = (AcDbEntity*)ar2D.at(i);
|
||
pEnt->getOsnapPoints(osnapMode,gsSelectionMark,pickPoint,lastPoint,viewXform,arPts1,geomIds);
|
||
}
|
||
|
||
const AcDbVoidPtrArray& ar3D = Get3DBuffer();
|
||
for (int i = 0;i < ar3D.length();i++)
|
||
{
|
||
pEnt = (AcDbEntity*)ar3D.at(i);
|
||
pEnt->getOsnapPoints(osnapMode,gsSelectionMark,pickPoint,lastPoint,viewXform,arPts1,geomIds);
|
||
}
|
||
|
||
if (!arPts1.isEmpty()) snapPoints.append(arPts1);
|
||
return Acad::eOk;
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbEwPipeBase::subGetGeomExtents(AcDbExtents& extents) const
|
||
{
|
||
assertReadEnabled();
|
||
|
||
if (m_pBaseCurve != NULL)
|
||
{
|
||
AcDbExtents ext1;
|
||
AcDbEntity* pEnt = NULL;
|
||
const AcDbVoidPtrArray &ar3D = Get3DBuffer();
|
||
for (int i = 0;i < ar3D.length();i++)
|
||
{
|
||
pEnt = (AcDbEntity*)ar3D.at(i);
|
||
pEnt->getGeomExtents(ext1);
|
||
extents.addExt(ext1);
|
||
}
|
||
|
||
const AcDbVoidPtrArray &ar2D = Get2DBuffer();
|
||
for (int j = 0;j < ar2D.length();j++)
|
||
{
|
||
pEnt = (AcDbEntity*)ar2D.at(j);
|
||
pEnt->getGeomExtents(ext1);
|
||
extents.addExt(ext1);
|
||
}
|
||
}
|
||
return Acad::eOk;
|
||
}
|
||
|
||
#endif
|
||
|
||
AcDbCurve* AecDbEwPipeBase::GetBaseCurve(bool bOrthoProjectToXY ) const
|
||
{
|
||
assertReadEnabled();
|
||
|
||
if (m_pBaseCurve != NULL)
|
||
{
|
||
AcDbCurve* pCurve = (AcDbCurve*)m_pBaseCurve->clone();
|
||
#ifndef ZWCAD
|
||
ReMakeSureCopy(pCurve,m_pBaseCurve);
|
||
#endif
|
||
|
||
if (bOrthoProjectToXY)
|
||
{
|
||
AcDbArc* pArc = AcDbArc::cast(pCurve);
|
||
if (pArc != NULL)
|
||
{
|
||
AcGeVector3d vtNorm = pArc->normal();
|
||
if (vtNorm.isParallelTo(AcGeVector3d::kZAxis))
|
||
{
|
||
AcGePoint3d ptCen = pArc->center();
|
||
ptCen.z = 0.0;
|
||
pArc->setCenter(ptCen);
|
||
return pCurve;
|
||
}
|
||
else
|
||
{
|
||
AcDbCurve* pProjCrv = NULL;
|
||
pCurve->getOrthoProjectedCurve(AcGePlane::kXYPlane,pProjCrv);
|
||
|
||
DELETE_PTR(pCurve);
|
||
return pProjCrv;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
AcDbPolyline* pPl = AcDbPolyline::cast(pCurve);
|
||
if (pPl != NULL)
|
||
{
|
||
return pPl;
|
||
}
|
||
|
||
AcGePoint3d ptSta,ptEnd;
|
||
AcDbLine* pLn = AcDbLine::cast(pCurve);
|
||
if (pLn != NULL)
|
||
{
|
||
pCurve->getStartPoint(ptSta);
|
||
pCurve->getEndPoint(ptEnd);
|
||
|
||
AcGeVector3d vt = ptEnd - ptSta;
|
||
if (vt.isParallelTo(AcGeVector3d::kZAxis))
|
||
{
|
||
return pCurve;
|
||
}
|
||
}
|
||
|
||
AcDbCurve* pProjCrv = NULL;
|
||
pCurve->getOrthoProjectedCurve(AcGePlane::kXYPlane,pProjCrv);
|
||
pLn = AcDbLine::cast(pProjCrv);
|
||
if (pLn != NULL)
|
||
{
|
||
pLn->setNormal(AcGeVector3d::kZAxis);
|
||
}
|
||
//避免其他0长度线
|
||
double dE = 0,dL = 0;
|
||
pProjCrv->getEndParam(dE);
|
||
pProjCrv->getDistAtParam(dE,dL);
|
||
if (dL < 1.e-3)//不可以投影
|
||
{
|
||
delete pProjCrv;
|
||
return pCurve;
|
||
}
|
||
|
||
DELETE_PTR(pCurve);
|
||
return pProjCrv;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
return pCurve;
|
||
}
|
||
}
|
||
return NULL;
|
||
}
|
||
|
||
AcDbCurve* AecDbEwPipeBase::GetNativeCurve() const
|
||
{
|
||
assertReadEnabled();
|
||
return m_pBaseCurve;
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbEwPipeBase::subErase(Adesk::Boolean erasing)
|
||
{
|
||
return AecDbCurveBase::subErase(erasing);
|
||
}
|
||
|
||
//按照0.1米分化
|
||
#define CURVE_DIVIDE 0.1
|
||
|
||
AcDbCurve* FormatPolyline(AcDbCurve* pBaseCur)
|
||
{
|
||
if (pBaseCur->isKindOf(AcDbLine::desc()) ||
|
||
pBaseCur->isKindOf(AcDbArc::desc()) ||
|
||
pBaseCur->isKindOf(AcDbPolyline::desc()))
|
||
{
|
||
AcDbVoidPtrArray arpCurve,arpResult;
|
||
arpCurve.append((AcDbCurve*)pBaseCur->clone());
|
||
|
||
return KTCADUtilityEx::ConvertBoundCurve(arpCurve,arpResult);
|
||
}
|
||
else //分化
|
||
{
|
||
//acutPrintf(_T("\nClass : %s"),pBaseCur->isA()->name());
|
||
|
||
double dSta = 0.0,dEnd = 0.0;
|
||
pBaseCur->getStartParam(dSta);
|
||
pBaseCur->getEndParam(dEnd);
|
||
|
||
int nCount =(int) ( (dEnd - dSta) / CURVE_DIVIDE + 0.5);
|
||
double dStep = (dEnd - dSta) / nCount;
|
||
|
||
AcDbPolyline* pPl = new AcDbPolyline;
|
||
|
||
Acad::ErrorStatus es;
|
||
int nPos = 0;
|
||
AcGePoint3d ptTmp;
|
||
while(nPos <= nCount)
|
||
{
|
||
es = pBaseCur->getPointAtParam(dSta,ptTmp);
|
||
if (Acad::eOk == es)
|
||
{
|
||
pPl->addVertexAt(nPos,ptTmp.convert2d(AcGePlane::kXYPlane));
|
||
nPos += 1;
|
||
}
|
||
dSta += dStep;
|
||
}
|
||
return pPl;
|
||
}
|
||
return NULL;
|
||
}
|
||
|
||
AcDbCurve* FormatLine(AcDbCurve* pBaseCur)
|
||
{
|
||
if (pBaseCur->isKindOf(AcDbLine::desc()))
|
||
{
|
||
AcDbLine* pLn = (AcDbLine*)pBaseCur->clone();
|
||
return pLn;
|
||
}
|
||
return FormatPolyline(pBaseCur);
|
||
}
|
||
|
||
AcDbCurve* FormatPolyline(const AcGePoint3d& ptFr,const AcGePoint3d& ptTo)
|
||
{
|
||
AcDbPolyline* pPl = new AcDbPolyline;
|
||
pPl->addVertexAt(0,ptFr.convert2d(AcGePlane::kXYPlane));
|
||
pPl->addVertexAt(1,ptTo.convert2d(AcGePlane::kXYPlane));
|
||
return pPl;
|
||
}
|
||
|
||
//只针对管子
|
||
Acad::ErrorStatus AecDbEwPipeBase::Draw2dSingleSegment(AcGiDraw &dc,AcDbPolyline* pPl) const
|
||
{
|
||
assertReadEnabled();
|
||
|
||
if (pPl != NULL)
|
||
{
|
||
dc.DrawEntity(pPl);
|
||
Add2DBuffer(pPl);
|
||
}
|
||
return Acad::eOk;
|
||
}
|
||
|
||
void AecDbEwPipeBase::DrawGradient(AcGiDraw &dc,AcDbCurve* pBaseCur) const
|
||
{
|
||
assertReadEnabled();
|
||
|
||
if (pBaseCur != NULL)
|
||
{
|
||
double dDn = 0.0;
|
||
if (m_mapSpecXData.GetAt(PIPE_DN,dDn))
|
||
{
|
||
AcGePoint3d ptSta,ptEnd;
|
||
pBaseCur->getStartPoint(ptSta);
|
||
pBaseCur->getEndPoint(ptEnd);
|
||
|
||
int nGradient = -1;
|
||
if (ptEnd.z > ptSta.z)//增高
|
||
{
|
||
nGradient = 1;
|
||
}
|
||
|
||
AcDbCurve* pProjCrv = NULL;
|
||
pBaseCur->getOrthoProjectedCurve(AcGePlane::kXYPlane,pProjCrv);
|
||
|
||
if (pProjCrv != NULL)
|
||
{
|
||
AcGeVector3d vtDir = ptEnd - ptSta;
|
||
vtDir.z = 0.0;
|
||
vtDir.normalize();
|
||
|
||
double dEnd = 0.0,dLen = 0.0;
|
||
pProjCrv->getEndParam(dEnd);
|
||
pProjCrv->getDistAtParam(dEnd,dLen);
|
||
|
||
double dStep = dDn * 0.5;
|
||
double dh = 0.866 * dStep;
|
||
|
||
int nSteps = (int)(dLen / dh);
|
||
|
||
AcGePoint3d ptGe[3],ptFr;
|
||
ptFr = ptSta;ptFr.z = 0.0;
|
||
|
||
AcGeVector3d vtV = vtDir;
|
||
vtV.rotateBy(PI / 2.0,AcGeVector3d::kZAxis);
|
||
|
||
AcDbPolyline* pPlGr = NULL;
|
||
for (int i = 0;i < nSteps / 2 - 2;i++)
|
||
{
|
||
ptFr += 2 * dh * vtDir;
|
||
if (nGradient > 0)
|
||
{
|
||
ptGe[1] = ptFr + dh * vtDir;
|
||
ptGe[0] = ptFr + 0.5 * dStep * vtV;
|
||
ptGe[2] = ptFr - 0.5 * dStep * vtV;
|
||
}
|
||
else
|
||
{
|
||
ptGe[1] = ptFr;
|
||
ptGe[0] = ptFr + 0.5 * dStep * vtV;
|
||
ptGe[0] += dh * vtDir;
|
||
|
||
ptGe[2] = ptFr - 0.5 * dStep * vtV;
|
||
ptGe[2] += dh * vtDir;
|
||
}
|
||
|
||
pPlGr = FormatPolyline(ptGe,3);
|
||
dc.DrawEntity(pPlGr);
|
||
Add2DBuffer(pPlGr);
|
||
|
||
//dc.DrawPolyline(3,ptGe);
|
||
}
|
||
DELETE_PTR(pProjCrv);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
void SetZeroEl(AcDbEntity* pEntCln)
|
||
{
|
||
AcGePoint3d pt1,pt2;
|
||
AcDbLine* pLn = AcDbLine::cast(pEntCln);
|
||
if (pLn != NULL)
|
||
{
|
||
pt1 = pLn->startPoint();
|
||
pt1.z = 0.0;
|
||
pt2 = pLn->endPoint();
|
||
pt2.z = 0.0;
|
||
pLn->setStartPoint(pt1);
|
||
pLn->setEndPoint(pt2);
|
||
}
|
||
|
||
AcDbArc* pArc = AcDbArc::cast(pEntCln);
|
||
if (pArc != NULL)
|
||
{
|
||
pt1 = pArc->center();
|
||
pt1.z = 0.0;
|
||
pArc->setCenter(pt1);
|
||
}
|
||
|
||
AcDbCircle* pCir = AcDbCircle::cast(pEntCln);
|
||
if (pCir != NULL)
|
||
{
|
||
pt1 = pCir->center();
|
||
pt1.z = 0.0;
|
||
pCir->setCenter(pt1);
|
||
}
|
||
|
||
AcDbPolyline* pPl = AcDbPolyline::cast(pEntCln);
|
||
if (pPl != NULL)
|
||
{
|
||
pPl->setElevation(0);
|
||
}
|
||
}
|
||
|
||
void AecDbEwPipeBase::DrawHatch(AcGiDraw &dc) const
|
||
{
|
||
assertReadEnabled();
|
||
//获取二维的闭合区域
|
||
PipeHatch sHatch;
|
||
if (GetHatch(sHatch))
|
||
{
|
||
const AcDbVoidPtrArray& arEntPtrs = Get2DBuffer();
|
||
AcDbEntity* pEnt = NULL;
|
||
AcDbEntity* pEntCln = NULL;
|
||
AcDbVoidPtrArray arEntClnPtrs,arRelt;
|
||
|
||
for (int i = 0;i < arEntPtrs.length();i++)
|
||
{
|
||
pEnt = (AcDbEntity*)arEntPtrs.at(i);
|
||
|
||
// 填充不处理
|
||
if (AcDbHatch::cast(pEnt)) continue;
|
||
|
||
if (pEnt != NULL)
|
||
{
|
||
pEntCln = (AcDbEntity*)pEnt->isA()->create();
|
||
CopyObject(*pEnt, *pEntCln);
|
||
//设置成0标高
|
||
SetZeroEl(pEntCln);
|
||
arEntClnPtrs.append(pEntCln);
|
||
}
|
||
}
|
||
|
||
AcDbCurve* pCurve = KTCADUtilityEx::ConvertBoundCurve(arEntClnPtrs,arRelt);
|
||
if (pCurve != NULL)
|
||
{
|
||
//if ( pCurve->isClosed() )
|
||
{
|
||
AcDbPolyline* pPl = AcDbPolyline::cast(pCurve);
|
||
if (pPl != NULL)
|
||
{
|
||
pPl->setElevation(.0);
|
||
pPl->setClosed(Adesk::kTrue);
|
||
DrawHatch(dc,pPl);
|
||
}
|
||
}
|
||
delete pCurve;
|
||
}
|
||
FreeBuffer(0,arRelt);
|
||
}
|
||
}
|
||
|
||
void AecDbEwPipeBase::DrawHatch(AcGiDraw& dc,AcDbPolyline* pPl) const
|
||
{
|
||
assertReadEnabled();
|
||
if (pPl != NULL)
|
||
{
|
||
PipeHatch sHatch;
|
||
if (GetHatch(sHatch))
|
||
{
|
||
AcGiDraw::Vertex3d vt;
|
||
AcGiDraw::AcGiPoly2d polyReg;
|
||
for (int i = 0;i < pPl->numVerts();i++)
|
||
{
|
||
pPl->getPointAt(i,vt.pt);
|
||
pPl->getBulgeAt(i,vt.dBulge);
|
||
polyReg.append(vt);
|
||
}
|
||
|
||
if (!polyReg.isEmpty())
|
||
{
|
||
AcDbHatch* pHatch = dc.DrawHatch(polyReg,sHatch.szPattern,sHatch.dScale,sHatch.dAngle);
|
||
if (pHatch != NULL)
|
||
{
|
||
Add2DBuffer(pHatch);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
void MakeShortCurve(AcDbCurve* pCurve,double dFL,int nPos)
|
||
{
|
||
if (pCurve != NULL)
|
||
{
|
||
AcGePoint3d pt;
|
||
AcGeVector3d vt;
|
||
AcDbLine* pLn = AcDbLine::cast(pCurve);
|
||
if (pLn != NULL)
|
||
{
|
||
vt = pLn->endPoint() - pLn->startPoint();
|
||
vt.normalize();
|
||
vt *= dFL;
|
||
|
||
if (nPos == 0)
|
||
{
|
||
pt = pLn->startPoint();
|
||
pt += vt;
|
||
pLn->setStartPoint(pt);
|
||
}
|
||
else
|
||
{
|
||
pt = pLn->endPoint();
|
||
pt -= vt;
|
||
pLn->setEndPoint(pt);
|
||
}
|
||
}
|
||
|
||
AcDbPolyline* pPl = AcDbPolyline::cast(pCurve);
|
||
if (pPl != NULL)
|
||
{
|
||
if ( pPl->numVerts() == 2 && pPl->isOnlyLines() )
|
||
{
|
||
AcGePoint3d pt1,pt2;
|
||
pPl->getPointAt(0,pt1);
|
||
pPl->getPointAt(1,pt2);
|
||
|
||
vt = pt2 - pt1;
|
||
vt.normalize();
|
||
vt *= dFL;
|
||
|
||
AcGePlane plan;
|
||
AcDb::Planarity pnty;
|
||
pPl->getPlane(plan,pnty);
|
||
|
||
if (nPos == 0)
|
||
{
|
||
pt1 += vt;
|
||
pPl->setPointAt(0,pt1.convert2d(plan));
|
||
}
|
||
else
|
||
{
|
||
pt2 -= vt;
|
||
pPl->setPointAt(1,pt2.convert2d(plan));
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbEwPipeBase::Draw2d(AcGiDraw &dc) const
|
||
{
|
||
assertReadEnabled();
|
||
if (g_BALock::instance().Draw() != BIT_SUCCESS)
|
||
return Acad::eOk;
|
||
|
||
//管线系统屏蔽掉
|
||
if ( dc.IsDragging() )
|
||
{
|
||
//return Acad::eOk;
|
||
}
|
||
|
||
AcDbObjectId idCurLay = dc.GetLayerId();
|
||
AcDbObjectId idCurLty = dc.GetLineTypeId();
|
||
Adesk::UInt16 nCrBk = colorIndex();
|
||
|
||
//双线,宽度
|
||
int nStyle = 0,nShape = 0;
|
||
m_mapSpecXData.GetAt(KEY_2DSTYLE,nStyle);
|
||
|
||
m_mapSpecXData.GetAt(KEY_SECSHAPE,nShape);
|
||
|
||
double dSingleW = 0.0;
|
||
m_mapSpecXData.GetAt(KEY_SINGLEW,dSingleW);
|
||
|
||
double dDbLineW = 0.0;
|
||
m_mapSpecXData.GetAt(KEY_DBLINEW,dDbLineW);
|
||
|
||
//是否绘制坡度线
|
||
int nDrawGradient = 0;
|
||
m_mapSpecXData.GetAt(KEY_DRAWGRAD,nDrawGradient);
|
||
|
||
//double dXDrawScale = 1.0;//dSingleW已经含有
|
||
//dSingleW *= dXDrawScale;
|
||
|
||
AcGeVector3d vtDir(0,0,1);
|
||
AcDbCurve* pBaseCurXY = GetBaseCurve(true);
|
||
if (pBaseCurXY == NULL)
|
||
{
|
||
return Acad::eOk;
|
||
}
|
||
if (m_pBaseCurve == NULL)
|
||
{
|
||
return Acad::eOk;
|
||
}
|
||
|
||
if (Has2DBuffer())
|
||
{
|
||
AcDbObjectId idLnT = linetypeId();
|
||
AcDbObjectId idLayT = layerId();
|
||
int nColorE = nCrBk;
|
||
AcDbEntity* pEnt = NULL;
|
||
AcDbObjectId idLn,idLay;
|
||
const AcDbVoidPtrArray &ar2D = Get2DBuffer();
|
||
for (int i = 0;i < ar2D.length();i++)
|
||
{
|
||
pEnt = (AcDbEntity*)ar2D.at(i);
|
||
nColorE = pEnt->colorIndex();
|
||
idLn = pEnt->linetypeId();
|
||
idLay = pEnt->layerId();
|
||
dc.SetColor(nColorE);
|
||
dc.SetLayer(idLay);
|
||
dc.SetLineType(idLn);
|
||
dc.SetLineWidth(0);
|
||
dc.SetLineWeight(AcDb::kLnWt000);
|
||
pEnt->setLineWeight(AcDb::kLnWt000);
|
||
dc.DrawEntity(*pEnt);
|
||
}
|
||
|
||
dc.SetLayer(idCurLay);
|
||
dc.SetLineType(idCurLty);
|
||
dc.SetColor(nCrBk);
|
||
return Acad::eOk;
|
||
}
|
||
|
||
int nColor = nCrBk;
|
||
if ( m_mapSpecXData.GetAt(_T("COLOR"),nColor) )//中心线颜色
|
||
{
|
||
dc.SetColor(nColor);
|
||
}
|
||
|
||
//取起点切向量
|
||
double dSta = 0.0;
|
||
m_pBaseCurve->getStartParam(dSta);
|
||
m_pBaseCurve->getFirstDeriv(dSta,vtDir);
|
||
vtDir.normalize();
|
||
|
||
double dDn = 0.0,dD = 0.0;
|
||
if (m_mapSpecXData.GetAt(PIPE_DN,dDn))
|
||
{
|
||
if (dDn - GetPipeDoubleLineMaxD() > 1.e-3)
|
||
{
|
||
nStyle = 2;
|
||
}
|
||
}
|
||
double dOd = 0.0,dThk = 0.0,dEl = 0.0;
|
||
m_mapSpecXData.GetAt(PIPE_OD,dOd);
|
||
m_mapSpecXData.GetAt(PIPE_THICK,dThk);
|
||
int nDir = 0;
|
||
m_mapSpecXData.GetAt(PIPE_DRAWDIR,nDir);
|
||
dD = dDn;
|
||
|
||
//绘制设置的半径
|
||
WPipe::EDia eDir = (WPipe::EDia)nDir;
|
||
if (eDir == WPipe::eOD)
|
||
{
|
||
dD = dOd;
|
||
}
|
||
else if(eDir == WPipe::eID)
|
||
{
|
||
dD = dOd - 2.0 * dThk;
|
||
}
|
||
|
||
AcDbCurve* pTemp = NULL;
|
||
AcGeLine3d ln3d(AcGePoint3d::kOrigin,10.0 * vtDir);
|
||
|
||
AcGeVector3d vtDrawPlanNorm = AcGeVector3d::kZAxis;
|
||
AcGePlane planXY;
|
||
dc.GetDraw2DPlan(planXY);
|
||
vtDrawPlanNorm = planXY.normal();
|
||
|
||
DrawContext dcCon;
|
||
dcCon.dD = dD;
|
||
dcCon.vtDrawPlanNorm = vtDrawPlanNorm;
|
||
dcCon.dSingleW = dSingleW;
|
||
dcCon.dDbLineW = dDbLineW;
|
||
dcCon.nShape = nShape;
|
||
dcCon.nDrawGradient = nDrawGradient;
|
||
dcCon.nColor = nColor;
|
||
dcCon.idCurLay = idCurLay;
|
||
dcCon.idCurLty = idCurLty;
|
||
dcCon.nCrBk = nCrBk;
|
||
dcCon.vtDir = vtDir;
|
||
dcCon.pBaseCurXY = pBaseCurXY;
|
||
|
||
dc.SetLineWidth(0);
|
||
dc.SetLineWeight(AcDb::kLnWt000);
|
||
|
||
switch(nStyle)
|
||
{
|
||
case 0://单线
|
||
case 1://单线
|
||
{
|
||
DrawSingle2d(dc,dcCon);
|
||
break;
|
||
}
|
||
case 2://双线
|
||
{
|
||
DrawDouble2d(dc,dcCon);
|
||
|
||
break;
|
||
}
|
||
default:
|
||
break;
|
||
}
|
||
|
||
//可能的绘制法兰管子
|
||
DrawFlangInf2d(dc);
|
||
|
||
DrawUserInf(dc);
|
||
|
||
return Acad::eOk;
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbEwPipeBase::DrawSingle2d(AcGiDraw &dc,DrawContext& dcCon) const
|
||
{
|
||
dc.SetLayer(m_idSingleLayer);
|
||
//dc.SetLineType(m_idSingleLnType);
|
||
dc.SetLineType(KTSetting::InitLineStyle(_T("Continuous")));
|
||
|
||
if (dcCon.vtDir.isParallelTo(dcCon.vtDrawPlanNorm))//立管
|
||
{
|
||
if (dcCon.nShape == eCircle)
|
||
{
|
||
AcGePoint3d ptSta;
|
||
m_pBaseCurve->getStartPoint(ptSta);
|
||
ptSta.z = 0.0;//在0标高上绘制立管
|
||
|
||
double dD = 0.0;
|
||
m_mapSpecXData.GetAt(KEY_SIZE1,dD);
|
||
m_mapSpecXData.GetAt(PIPE_D,dD);
|
||
|
||
AcGePoint3d ptCen;
|
||
m_mapSpecXData.GetAt(KEY_SECCEN,ptCen);//可能偏心绘制
|
||
|
||
AcGeMatrix3d xformMove;
|
||
AcGeVector3d vtM = ptCen.asVector();
|
||
xformMove.setToTranslation(vtM);
|
||
|
||
//没有关联关系,立管才绘制圆
|
||
BOOL bZNDraw = 0;
|
||
m_mapSpecXData.GetAt(PIPE_Z2DDRAW,bZNDraw);
|
||
if (bZNDraw)
|
||
{
|
||
AcDbCircle* pCir = new AcDbCircle;
|
||
pCir->setRadius(0.5 * dD);
|
||
pCir->setCenter(ptSta);
|
||
pCir->setNormal(dcCon.vtDrawPlanNorm);
|
||
|
||
pCir->transformBy(xformMove);
|
||
pCir->setColorIndex(dcCon.nColor);
|
||
m_mapSpecXData.Write(pCir,BIMDATA_APP);
|
||
dc.DrawEntity(pCir);
|
||
Add2DBuffer(pCir);
|
||
}
|
||
|
||
//中心线
|
||
//加入中心线
|
||
AcDbCurve* pCenCrv = GetBaseCurve(false);
|
||
if (pCenCrv != NULL)
|
||
{
|
||
pCenCrv->setLayer(m_idCenterLayer);
|
||
m_mapSpecXData.Write(pCenCrv,BIMDATA_APP);
|
||
dc.DrawEntity(pCenCrv);
|
||
Add2DBuffer(pCenCrv);
|
||
}
|
||
}
|
||
else//其他形状
|
||
{
|
||
if (m_pRegion != NULL)
|
||
{
|
||
AcDbVoidPtrArray arCurPtrs;
|
||
double dAngle = 0.0;
|
||
if ( m_mapSpecXData.GetAt(KEY_ROTATION,dAngle) )
|
||
{
|
||
AcDbRegion* pRegnCln = (AcDbRegion*)m_pRegion->clone();
|
||
if (pRegnCln != NULL)
|
||
{
|
||
AcGeMatrix3d xformR;
|
||
xformR.setToRotation(dAngle,dcCon.vtDrawPlanNorm);
|
||
pRegnCln->transformBy(xformR);
|
||
pRegnCln->explode(arCurPtrs);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
m_pRegion->explode(arCurPtrs);
|
||
}
|
||
|
||
AcGePoint3d ptSta;
|
||
dcCon.pBaseCurXY->getStartPoint(ptSta);
|
||
ptSta.z = 0.0;//在0标高上绘制立管
|
||
|
||
AcGePoint3d ptCen = ptSta;
|
||
m_mapSpecXData.GetAt(KEY_SECCEN,ptCen);//可能偏心绘制
|
||
|
||
AcGeMatrix3d xformOffset;
|
||
AcGeVector3d vtM = ptCen.asVector();
|
||
xformOffset.setToTranslation(vtM);
|
||
AcGeMatrix3d xformMove;
|
||
xformMove.setToTranslation(ptSta.asVector());
|
||
|
||
AcDbEntity* pSubEnt = NULL;
|
||
for (int n = 0;n < arCurPtrs.length();n++)
|
||
{
|
||
pSubEnt = (AcDbEntity*)arCurPtrs.at(n);
|
||
pSubEnt->transformBy(xformOffset);
|
||
pSubEnt->transformBy(xformMove);
|
||
pSubEnt->setColorIndex(dcCon.nColor);
|
||
m_mapSpecXData.Write(pSubEnt,BIMDATA_APP);
|
||
dc.DrawEntity(pSubEnt);
|
||
Add2DBuffer(pSubEnt);
|
||
}
|
||
|
||
//中心线
|
||
//加入中心线
|
||
AcDbCurve* pCenCrv = GetBaseCurve(false);
|
||
if (pCenCrv != NULL)
|
||
{
|
||
pCenCrv->setLayer(m_idCenterLayer);
|
||
m_mapSpecXData.Write(pCenCrv,BIMDATA_APP);
|
||
dc.DrawEntity(pCenCrv);
|
||
Add2DBuffer(pCenCrv);
|
||
}
|
||
}
|
||
}
|
||
DELETE_PTR(dcCon.pBaseCurXY);
|
||
dcCon.pBaseCurXY = NULL;
|
||
}
|
||
else //单线,水平或倾斜
|
||
{
|
||
AcGeLine3d ln3d(AcGePoint3d::kOrigin,10.0 * dcCon.vtDir);
|
||
AcGePlane planXY;
|
||
dc.GetDraw2DPlan(planXY);
|
||
|
||
//斜度不是平行XY面的投影到XY面
|
||
if (!ln3d.isParallelTo(planXY))
|
||
{
|
||
//绘制梯度线
|
||
if (dcCon.nDrawGradient > 0)
|
||
{
|
||
DrawGradient(dc,m_pBaseCurve);
|
||
}
|
||
}
|
||
|
||
AcGePoint3d ptSta,ptFr;
|
||
AcGePoint3d ptEnd;
|
||
m_pBaseCurve->getStartPoint(ptSta);
|
||
m_pBaseCurve->getEndPoint(ptEnd);
|
||
|
||
double dEl = ptSta.z;//中心标高
|
||
m_mapSpecXData.GetAt(PIPE_EL,dEl);
|
||
|
||
ptSta.z = 0.0;
|
||
ptEnd.z = 0.0;
|
||
|
||
//断管符号
|
||
AcDbPolyline* pPl = NULL;
|
||
AcGePoint3d ptGeT,ptGeBK;
|
||
AcGePoint3dArray arPoints;
|
||
CString sIndex;
|
||
for(int i = 0;i < PIPE_BROKENNUM;i++)
|
||
{
|
||
sIndex.Format(_T("BKOP%d"),i);
|
||
if (m_mapSpecXData.GetAt(sIndex,ptGeBK))
|
||
{
|
||
ptGeT = ptSta + dcCon.vtDir * ptGeBK.x;
|
||
arPoints.append(ptGeT);
|
||
|
||
ptGeT += dcCon.vtDir * ptGeBK.y;
|
||
arPoints.append(ptGeT);
|
||
}
|
||
}
|
||
|
||
//排序
|
||
if (arPoints.length() > 0)
|
||
{
|
||
AcDbLine ln(ptSta,ptEnd);
|
||
AecCoverBooleanOper::SortPoints(arPoints,&ln);
|
||
|
||
BOOL bStaBrk = FALSE;
|
||
if (arPoints.first().distanceTo(ptSta) < 1.e-3)
|
||
{
|
||
bStaBrk = TRUE;
|
||
}
|
||
|
||
BOOL bEndBrk = FALSE;
|
||
if (arPoints.last().distanceTo(ptEnd) < 1.e-3)
|
||
{
|
||
bEndBrk = TRUE;
|
||
}
|
||
|
||
arPoints.insertAt(0,ptSta);
|
||
arPoints.append(ptEnd);
|
||
}
|
||
|
||
if (arPoints.length() > 0)
|
||
{
|
||
AecDbObjXDataMap xData;
|
||
xData.SetAt(PIPE_EL,dEl);
|
||
xData.CopyFrom(&m_mapSpecXData);
|
||
|
||
AcDbCurve* pTemp = NULL;
|
||
AecComplexCurve cplCurve;
|
||
//sta- 1...2-3...4-5...end
|
||
for (int i = 0;i < arPoints.length() - 1;i++)
|
||
{
|
||
ptFr = arPoints.at(i);
|
||
ptGeBK = arPoints.at(i + 1);
|
||
|
||
if (i % 2 == 0) //偶数
|
||
{
|
||
pTemp = FormatPolyline(ptFr,ptGeBK);
|
||
pPl = AcDbPolyline::cast(pTemp);
|
||
if (pPl != NULL)
|
||
{
|
||
pPl->setConstantWidth(dcCon.dSingleW);
|
||
pPl->setLayer(m_idSingleLayer);
|
||
//pPl->setLinetype(m_idSingleLnType);
|
||
pPl->setLinetype(KTSetting::InitLineStyle(_T("Continuous")));
|
||
pPl->setColorIndex(dcCon.nColor);
|
||
xData.Write(pPl,BIMDATA_APP);
|
||
Draw2dSingleSegment(dc,pPl);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
DrawBrokenOpen(dc,ptFr,ptGeBK,dcCon.dD,cplCurve);
|
||
}
|
||
}
|
||
|
||
AecComplexCurveDraw draw2d;
|
||
draw2d.SetEdage(cplCurve);
|
||
draw2d.Draw2d(dc);
|
||
|
||
AcDbCurve* pCurveT = NULL;
|
||
for (int kk = 0;kk < cplCurve.length();kk++)
|
||
{
|
||
pCurveT = cplCurve.segat(kk);
|
||
if (pCurveT != NULL)
|
||
{
|
||
Add2DBuffer(pCurveT);
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (dcCon.dSingleW < 1.e-6)
|
||
{
|
||
if (dcCon.pBaseCurXY != NULL)
|
||
{
|
||
dcCon.pBaseCurXY->setLayer(m_idSingleLayer);
|
||
dcCon.pBaseCurXY->setColorIndex(dcCon.nColor);
|
||
dcCon.pBaseCurXY->setLinetype(KTSetting::InitLineStyle(_T("Continuous")));
|
||
|
||
AecDbObjXDataMap xData;
|
||
xData.CopyFrom(&m_mapSpecXData);
|
||
xData.SetAt(PIPE_EL,dEl);
|
||
xData.Write(dcCon.pBaseCurXY,BIMDATA_APP);
|
||
|
||
dc.DrawEntity(*dcCon.pBaseCurXY);
|
||
Add2DBuffer(dcCon.pBaseCurXY);
|
||
dcCon.pBaseCurXY = NULL;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
//转换为pl线绘制 XY面
|
||
AcDbCurve* pCrv = FormatPolyline(dcCon.pBaseCurXY);
|
||
|
||
AcDbPolyline* pPl = AcDbPolyline::cast(pCrv);
|
||
if (pPl != NULL)
|
||
{
|
||
pPl->setConstantWidth(dcCon.dSingleW);
|
||
pPl->setLayer(m_idSingleLayer);
|
||
//pPl->setLinetype(m_idSingleLnType);
|
||
pPl->setLinetype(KTSetting::InitLineStyle(_T("Continuous")));
|
||
pPl->setColorIndex(dcCon.nColor);
|
||
|
||
AecDbObjXDataMap xData;
|
||
xData.CopyFrom(&m_mapSpecXData);
|
||
xData.SetAt(PIPE_EL,dEl);
|
||
xData.Write(pPl,BIMDATA_APP);
|
||
Draw2dSingleSegment(dc,pPl);
|
||
}
|
||
else
|
||
{
|
||
dcCon.pBaseCurXY->setLayer(m_idSingleLayer);
|
||
dcCon.pBaseCurXY->setColorIndex(dcCon.nColor);
|
||
dcCon.pBaseCurXY->setLinetype(KTSetting::InitLineStyle(_T("Continuous")));
|
||
AecDbObjXDataMap xData;
|
||
xData.CopyFrom(&m_mapSpecXData);
|
||
xData.SetAt(PIPE_EL,dEl);
|
||
xData.Write(dcCon.pBaseCurXY,BIMDATA_APP);
|
||
|
||
dc.DrawEntity(*dcCon.pBaseCurXY);
|
||
Add2DBuffer(dcCon.pBaseCurXY);
|
||
dcCon.pBaseCurXY = NULL;
|
||
}
|
||
}
|
||
}
|
||
//DELETE_PTR(pBaseCurXY);
|
||
}
|
||
|
||
dc.SetColor(dcCon.nCrBk);
|
||
dc.SetLayer(dcCon.idCurLay);
|
||
dc.SetLineType(dcCon.idCurLty);
|
||
|
||
return Acad::eOk;
|
||
}
|
||
|
||
void ConverToPolyline(AcDbCurve*& pCurve,double dWidth)
|
||
{
|
||
AcDbPolyline* pPl = AcDbPolyline::cast(pCurve);
|
||
if (pPl != NULL)
|
||
{
|
||
pPl->setConstantWidth(dWidth);
|
||
}
|
||
else
|
||
{
|
||
AcDbLine* pLn = AcDbLine::cast(pCurve);
|
||
if (pLn != NULL)
|
||
{
|
||
pPl = new AcDbPolyline;
|
||
pPl->addVertexAt(0,pLn->startPoint().convert2d(AcGePlane::kXYPlane));
|
||
pPl->addVertexAt(1,pLn->endPoint().convert2d(AcGePlane::kXYPlane));
|
||
pPl->setConstantWidth(dWidth);
|
||
|
||
delete pCurve;
|
||
pCurve = pPl;
|
||
}
|
||
}
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbEwPipeBase::DrawDouble2d(AcGiDraw &dc,DrawContext& dcCon) const
|
||
{
|
||
if (dcCon.vtDir.isParallelTo(dcCon.vtDrawPlanNorm))//口向上下
|
||
{
|
||
if (dcCon.nShape == eCircle)
|
||
{
|
||
AcGePoint3d ptSta;
|
||
m_pBaseCurve->getStartPoint(ptSta);
|
||
ptSta.z = 0.0;//在0标高上绘制立管
|
||
|
||
double dD = dcCon.dD;
|
||
//m_mapSpecXData.GetAt(KEY_SIZE1,dD);
|
||
//m_mapSpecXData.GetAt(PIPE_D,dD);
|
||
|
||
AcGePoint3d ptCen = ptSta;
|
||
m_mapSpecXData.GetAt(KEY_SECCEN,ptCen);//可能偏心绘制
|
||
|
||
AcGeMatrix3d xformMove;
|
||
AcGeVector3d vtM = ptCen.asVector();
|
||
xformMove.setToTranslation(vtM);
|
||
|
||
CString sHandle;
|
||
m_mapSpecXData.GetAt(PIPE_CONNECT,sHandle);
|
||
|
||
//没有关联关系,立管才绘制圆
|
||
BOOL bZNDraw = 0;
|
||
m_mapSpecXData.GetAt(PIPE_Z2DDRAW,bZNDraw);
|
||
if (bZNDraw)
|
||
{
|
||
AcDbCircle* pCir = new AcDbCircle;
|
||
pCir->setRadius(0.5 * dD);
|
||
pCir->setCenter(ptSta);
|
||
pCir->setNormal(AcGeVector3d::kZAxis);
|
||
pCir->setLayer(layerId());
|
||
pCir->transformBy(xformMove);
|
||
m_mapSpecXData.Write(pCir,BIMDATA_APP);
|
||
dc.DrawEntity(pCir);
|
||
Add2DBuffer(pCir);
|
||
}
|
||
|
||
//绘制标记+
|
||
double dCmd = 5.0;//毫米
|
||
if (CoreTools::IsMetersUnit())
|
||
dCmd *= .001;
|
||
|
||
AcGePoint3d pt[2];
|
||
pt[0] = ptSta;pt[0].x -= dCmd;
|
||
pt[1] = ptSta;pt[1].x += dCmd;
|
||
|
||
AcDbLine* pLn = new AcDbLine(pt[0],pt[1]);
|
||
pLn->setColorIndex(dcCon.nColor);
|
||
pLn->setLayer(layerId());
|
||
m_mapSpecXData.Write(pLn,BIMDATA_APP);
|
||
dc.DrawEntity(pLn);
|
||
Add2DBuffer(pLn);
|
||
pt[0] = ptSta;pt[0].y -= dCmd;
|
||
pt[1] = ptSta;pt[1].y += dCmd;
|
||
pLn = new AcDbLine(pt[0],pt[1]);
|
||
pLn->setLayer(layerId());
|
||
pLn->setColorIndex(dcCon.nColor);
|
||
m_mapSpecXData.Write(pLn,BIMDATA_APP);
|
||
dc.DrawEntity(pLn);
|
||
Add2DBuffer(pLn);
|
||
|
||
|
||
//中心线
|
||
//加入中心线
|
||
AcDbCurve* pCenCrv = GetBaseCurve(false);
|
||
if (pCenCrv != NULL)
|
||
{
|
||
pCenCrv->setLayer(m_idCenterLayer);
|
||
pCenCrv->setColorIndex(dcCon.nColor);
|
||
pCenCrv->setLinetype(KTSetting::InitLineStyle(_T("CENTER2")));
|
||
m_mapSpecXData.Write(pCenCrv,BIMDATA_APP);
|
||
dc.DrawEntity(pCenCrv);
|
||
Add2DBuffer(pCenCrv);
|
||
}
|
||
}
|
||
else//方管,获其他截面管
|
||
{
|
||
if (m_pRegion != NULL)
|
||
{
|
||
AcGePoint3d ptCen;
|
||
m_mapSpecXData.GetAt(KEY_SECCEN,ptCen);
|
||
|
||
AcDbRegion* pRegCln = (AcDbRegion*)m_pRegion->clone();
|
||
|
||
double dAngle = 0.0;
|
||
AcDbVoidPtrArray arCurPtrs;
|
||
if ( m_mapSpecXData.GetAt(KEY_ROTATION,dAngle) )
|
||
{
|
||
if (pRegCln != NULL)
|
||
{
|
||
AcGeMatrix3d xformR;
|
||
xformR.setToRotation(dAngle,AcGeVector3d::kZAxis);//pi-dangle
|
||
pRegCln->transformBy(xformR);
|
||
pRegCln->explode(arCurPtrs);
|
||
|
||
//绘制方向->测试
|
||
/*AcGePoint3d pt1,pt2;
|
||
dcCon.pBaseCurXY->getStartPoint(pt1);
|
||
pt1.z = 0.0;//在0标高上绘制立管
|
||
pt2 = pt1;
|
||
|
||
AcGeVector3d vt(1,0,0);
|
||
vt.rotateBy(dAngle,AcGeVector3d::kZAxis);
|
||
pt2 = pt1 + vt * 300.0;
|
||
|
||
AcDbLine* pLnT = new AcDbLine(pt1,pt2);
|
||
dc.DrawEntity(pLnT);
|
||
Add2DBuffer(pLnT);*/
|
||
}
|
||
}
|
||
else
|
||
{
|
||
pRegCln->explode(arCurPtrs);
|
||
}
|
||
delete pRegCln;
|
||
|
||
AcGePoint3d ptSta;
|
||
AcGeMatrix3d xformMove;
|
||
dcCon.pBaseCurXY->getStartPoint(ptSta);
|
||
ptSta.z = 0.0;//在0标高上绘制立管
|
||
|
||
//移到sta位置
|
||
AcGeVector3d vtM = ptSta - ptCen;
|
||
xformMove.setToTranslation(vtM);
|
||
|
||
AcDbEntity* pSubEnt = NULL;
|
||
for (int n = 0;n < arCurPtrs.length();n++)
|
||
{
|
||
pSubEnt = (AcDbEntity*)arCurPtrs.at(n);
|
||
pSubEnt->transformBy(xformMove);
|
||
pSubEnt->setColorIndex(dcCon.nColor);
|
||
pSubEnt->setLayer(layerId());
|
||
m_mapSpecXData.Write(pSubEnt,BIMDATA_APP);
|
||
dc.DrawEntity(pSubEnt);
|
||
Add2DBuffer(pSubEnt);
|
||
}
|
||
|
||
//中心线
|
||
//加入中心线
|
||
AcDbCurve* pCenCrv = GetBaseCurve(false);
|
||
if (pCenCrv != NULL)
|
||
{
|
||
pCenCrv->setLayer(m_idCenterLayer);
|
||
pCenCrv->setColorIndex(dcCon.nColor);
|
||
pCenCrv->setLinetype(KTSetting::InitLineStyle(_T("CENTER2")));
|
||
|
||
m_mapSpecXData.Write(pCenCrv,BIMDATA_APP);
|
||
dc.DrawEntity(pCenCrv);
|
||
Add2DBuffer(pCenCrv);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
else //水平或者斜管
|
||
{
|
||
AcGeLine3d ln3d(AcGePoint3d::kOrigin,10.0 * dcCon.vtDir);
|
||
AcGePlane planXY;
|
||
dc.GetDraw2DPlan(planXY);
|
||
|
||
//斜度不是平行XY面的投影到XY面
|
||
if (!ln3d.isParallelTo(planXY))//斜管
|
||
{
|
||
//绘制梯度线
|
||
if (dcCon.nDrawGradient > 0)
|
||
{
|
||
DrawGradient(dc,m_pBaseCurve);
|
||
}
|
||
}
|
||
|
||
AcGePoint3d ptSta,ptFr;
|
||
AcGePoint3d ptEnd;
|
||
AcGeVector3d vtTmp;
|
||
m_pBaseCurve->getStartPoint(ptSta);
|
||
m_pBaseCurve->getEndPoint(ptEnd);
|
||
|
||
double dEl = ptSta.z;
|
||
m_mapSpecXData.GetAt(PIPE_EL,dEl);
|
||
|
||
ptSta.z = 0.0;
|
||
ptEnd.z = 0.0;
|
||
|
||
//避开一个法兰的位置
|
||
double dFL = 0.0;
|
||
int nConnectType = 0;//焊接0 承插1 螺纹2 法兰管3
|
||
m_mapSpecXData.GetAt(PIPE_CONNECT,nConnectType);
|
||
if (nConnectType == 3)
|
||
{
|
||
m_mapSpecXData.GetAt(PIPE_INTERFACEL,dFL);
|
||
vtTmp = ptEnd - ptSta;
|
||
vtTmp.normalize();
|
||
}
|
||
|
||
//断管符号
|
||
AcDbPolyline* pPl = NULL;
|
||
AcGePoint3d ptGeT,ptGeBK;
|
||
AcGePoint3dArray arPoints;
|
||
CString sIndex;
|
||
dcCon.vtDir.normalize();
|
||
for(int i = 0;i < PIPE_BROKENNUM;i++)
|
||
{
|
||
sIndex.Format(_T("BKOP%d"),i);
|
||
if (m_mapSpecXData.GetAt(sIndex,ptGeBK))
|
||
{
|
||
ptGeT = ptSta + dcCon.vtDir * ptGeBK.x;//开始位置
|
||
ptGeT.z = 0.0;
|
||
arPoints.append(ptGeT);
|
||
|
||
ptGeT += dcCon.vtDir * ptGeBK.y;//断开长度
|
||
ptGeT.z = 0.0;
|
||
arPoints.append(ptGeT);
|
||
}
|
||
}
|
||
|
||
//遮挡虚线
|
||
AcGePoint3dArray arDashBreak;
|
||
for (int n = 0;n < m_arBreaks.length();n++)
|
||
{
|
||
const BreakPos& brp = m_arBreaks.at(n);
|
||
if (brp.nType == -1)//虚段
|
||
{
|
||
m_pBaseCurve->getClosestPointTo(brp.ptGe,ptGeT);
|
||
ptGeT.z = 0.0;
|
||
|
||
arDashBreak.append(ptGeT);
|
||
ptGeT -= 0.5 * brp.dLen * dcCon.vtDir;
|
||
arPoints.append(ptGeT);
|
||
|
||
ptGeT += brp.dLen * dcCon.vtDir;
|
||
arPoints.append(ptGeT);
|
||
}
|
||
}
|
||
|
||
//排序
|
||
if (arPoints.length() > 0)
|
||
{
|
||
AcDbLine ln(ptSta,ptEnd);
|
||
AecCoverBooleanOper::SortPoints(arPoints,&ln);
|
||
|
||
BOOL bStaBrk = FALSE;
|
||
if (arPoints.first().distanceTo(ptSta) < 1.e-3)
|
||
{
|
||
bStaBrk = TRUE;
|
||
}
|
||
|
||
BOOL bEndBrk = FALSE;
|
||
if (arPoints.last().distanceTo(ptEnd) < 1.e-3)
|
||
{
|
||
bEndBrk = TRUE;
|
||
}
|
||
|
||
//STA+END
|
||
arPoints.insertAt(0,ptSta);
|
||
arPoints.append(ptEnd);
|
||
}
|
||
|
||
AecComplexCurve cplCurve;
|
||
AcGeVector3d vt1,vt2;
|
||
//sta- 1...2-3...4-5...end
|
||
for (int i = 0;i < arPoints.length() - 1;i++)
|
||
{
|
||
ptFr = arPoints.at(i);
|
||
ptGeBK = arPoints.at(i + 1);
|
||
|
||
if (i % 2 == 0) //偶数,后面绘制
|
||
{
|
||
//...
|
||
}
|
||
else
|
||
{
|
||
bool bDash = false;
|
||
for (int nn = 0;nn < arDashBreak.length();nn++)
|
||
{
|
||
ptGeT = arDashBreak.at(nn);
|
||
|
||
vt1 = ptGeT - ptFr;
|
||
vt2 = ptGeT - ptGeBK;
|
||
if (!vt1.isCodirectionalTo(vt2))
|
||
{
|
||
//是虚线
|
||
bDash = true;
|
||
break;
|
||
}
|
||
}
|
||
|
||
if (bDash)
|
||
{
|
||
DrawDashSegment(dc,ptFr,ptGeBK,dcCon.dD,cplCurve);
|
||
}
|
||
else
|
||
{
|
||
DrawBrokenOpen(dc,ptFr,ptGeBK,dcCon.dD,cplCurve);
|
||
}
|
||
}
|
||
}
|
||
|
||
//断符号绘制
|
||
AecComplexCurveDraw draw2d;
|
||
draw2d.SetEdage(cplCurve);
|
||
draw2d.Draw2d(dc);
|
||
|
||
AcDbCurve* pCurveT = NULL;
|
||
for (int kk = 0;kk < cplCurve.length();kk++)
|
||
{
|
||
pCurveT = cplCurve.segat(kk);
|
||
if (pCurveT != NULL)
|
||
{
|
||
Add2DBuffer(pCurveT);
|
||
}
|
||
}
|
||
|
||
//中心线
|
||
AcDbVoidPtrArray arCurPtrs;
|
||
if (arPoints.length() > 2)
|
||
{
|
||
//STA+END
|
||
arPoints.removeFirst();
|
||
arPoints.removeLast();
|
||
|
||
dcCon.pBaseCurXY->getSplitCurves(arPoints,arCurPtrs);
|
||
DELETE_PTR(dcCon.pBaseCurXY);
|
||
dcCon.pBaseCurXY = NULL;
|
||
}
|
||
else
|
||
{
|
||
arCurPtrs.append(dcCon.pBaseCurXY);
|
||
}
|
||
|
||
//外线 截面
|
||
AcGePoint3d ptCen;
|
||
m_mapSpecXData.GetAt(KEY_SECCEN,ptCen);
|
||
double dUW = 0.0,dDW = 0.0,dW = 0.0;
|
||
if (m_pRegion != NULL)
|
||
{
|
||
//region水平投影放置为准
|
||
AcDbExtents ext;
|
||
m_pRegion->getGeomExtents(ext);
|
||
|
||
dW = ext.maxPoint().x - ext.minPoint().x;
|
||
|
||
//dUW 原点到最小点的距离 正
|
||
//dDW 原点到最大点的距离 负
|
||
//正负按照AcDbCurve::getOffsetCurves(dOff 要求
|
||
|
||
dUW = -ext.minPoint().x;
|
||
dDW = -ext.maxPoint().x;
|
||
|
||
int nShape = 0;
|
||
if (m_mapSpecXData.GetAt(KEY_SHAPE, nShape) && _tcscmp(this->isA()->name(), _T("AecDbBeam")) == 0)
|
||
{
|
||
if (dUW > dDW && nShape == 4)//槽钢 梁 左对齐表达画法
|
||
{
|
||
dDW = ext.minPoint().x;
|
||
dUW = ext.maxPoint().x;
|
||
}
|
||
}
|
||
}
|
||
|
||
//1.中心线
|
||
//统一Format polyline 线
|
||
dc.SetLayer(layerId());
|
||
dc.SetLineType(linetypeId());
|
||
|
||
AcDbCurve* pCurTmp = NULL,*pTemp = NULL;
|
||
AcDbLine* pLnPl = NULL;
|
||
BOOL bHide = FALSE;
|
||
|
||
int nCenNDraw = 0;
|
||
m_mapSpecXData.GetAt(KEY_CENNODRAW,nCenNDraw);
|
||
|
||
for(int j = 0;j < arCurPtrs.length();j++)
|
||
{
|
||
pCurTmp = (AcDbCurve*)arCurPtrs.at(j);
|
||
|
||
//1. 绘制中心线
|
||
//统一Format polyline 线
|
||
if (nCenNDraw == FALSE)//绘制中心线
|
||
{
|
||
//pTemp = FormatPolyline(pCurTmp);
|
||
pTemp = FormatLine(pCurTmp);
|
||
pLnPl = AcDbLine::cast(pTemp);
|
||
if (pLnPl != NULL)
|
||
{
|
||
//是否取总线图层
|
||
//dc.SetLayer(layerId());
|
||
//dc.SetLineType(linetypeId());
|
||
//pPl->setConstantWidth(dSingleW);
|
||
|
||
pLnPl->setLayer(m_idCenterLayer);
|
||
//pLnPl->setColorIndex(dcCon.nColor);//
|
||
pLnPl->setColorIndex(kColorByLayer);
|
||
pLnPl->setLinetype(KTSetting::InitLineStyle(_T("CENTER2")));
|
||
|
||
//中间是否被节点打断???
|
||
AecDbObjXDataMap xData;
|
||
xData.CopyFrom(&m_mapSpecXData);
|
||
xData.SetAt(PIPE_EL,dEl);
|
||
xData.Write(pLnPl,BIMDATA_APP);
|
||
dc.SetLayer(m_idCenterLayer);
|
||
dc.DrawEntity(pLnPl);
|
||
Add2DBuffer(pLnPl);
|
||
|
||
dc.SetLayer(dcCon.idCurLay);
|
||
dc.SetLineType(dcCon.idCurLty);
|
||
}
|
||
else
|
||
{
|
||
pPl = AcDbPolyline::cast(pTemp);
|
||
if (pPl != NULL)
|
||
{
|
||
//是否取总线图层
|
||
//dc.SetLayer(layerId());
|
||
//dc.SetLineType(linetypeId());
|
||
//pPl->setConstantWidth(dSingleW);
|
||
|
||
pPl->setLayer(m_idCenterLayer);
|
||
pPl->setColorIndex(kColorByLayer);
|
||
pPl->setLinetype(KTSetting::InitLineStyle(_T("CENTER2")));
|
||
AecDbObjXDataMap xData;
|
||
xData.CopyFrom(&m_mapSpecXData);
|
||
xData.SetAt(PIPE_EL,dEl);
|
||
xData.Write(pPl,BIMDATA_APP);
|
||
//中间是否被节点打断???
|
||
dc.SetLayer(m_idCenterLayer);
|
||
dc.DrawEntity(pPl);
|
||
Add2DBuffer(pPl);
|
||
|
||
dc.SetLayer(dcCon.idCurLay);
|
||
dc.SetLineType(dcCon.idCurLty);
|
||
}
|
||
}
|
||
}
|
||
/*else//不绘制中心线
|
||
{
|
||
//...
|
||
}*/
|
||
|
||
//2. 绘制外线
|
||
if (j % 2 == 0) //偶数
|
||
{
|
||
dc.SetColor(dcCon.nCrBk);
|
||
|
||
//2.外边线
|
||
//统一Format polyline 线
|
||
dc.SetLayer(m_idDoubleLayer);
|
||
dc.SetLineType(linetypeId());
|
||
|
||
AcDbVoidPtrArray arUCurPtrs,arDCurPtrs;
|
||
if (dcCon.vtDrawPlanNorm.isCodirectionalTo(AcGeVector3d::kZAxis))
|
||
{
|
||
pCurTmp->getOffsetCurves(dUW,arUCurPtrs);
|
||
pCurTmp->getOffsetCurves(dDW,arDCurPtrs);
|
||
}
|
||
else
|
||
{
|
||
//绘制投影面
|
||
pCurTmp->getOffsetCurvesGivenPlaneNormal(dcCon.vtDrawPlanNorm,dUW,arUCurPtrs);
|
||
pCurTmp->getOffsetCurvesGivenPlaneNormal(dcCon.vtDrawPlanNorm,dDW,arDCurPtrs);
|
||
}
|
||
//DELETE_PTR(pCurTmp);
|
||
|
||
//中间是否被节点打断???
|
||
AcGePoint3d ptTmp;
|
||
AcGePoint3dArray arPtSta,arPtEnd;
|
||
AcDbCurve* pCurve = NULL;
|
||
for (int i = 0;i < arUCurPtrs.length();i++)
|
||
{
|
||
pCurve = (AcDbCurve*)arUCurPtrs.at(i);
|
||
|
||
if (i == 0)
|
||
{
|
||
pCurve->getStartPoint(ptTmp);
|
||
arPtSta.append(ptTmp);
|
||
|
||
if (dFL > 1.e-3)//有法兰,外线少画一个厚度
|
||
{
|
||
MakeShortCurve(pCurve,dFL,0);
|
||
}
|
||
}
|
||
|
||
if (i == arUCurPtrs.length() - 1)
|
||
{
|
||
pCurve->getEndPoint(ptTmp);
|
||
arPtEnd.append(ptTmp);
|
||
|
||
if (dFL > 1.e-3)//有法兰,外线少画一个厚度
|
||
{
|
||
MakeShortCurve(pCurve,dFL,1);
|
||
}
|
||
}
|
||
|
||
ConverToPolyline(pCurve,dcCon.dDbLineW);
|
||
pCurve->setLayer(m_idDoubleLayer);
|
||
pCurve->setLinetype(linetypeId());
|
||
pCurve->setColorIndex(kColorByLayer);//外线不设置颜色,随层
|
||
dc.DrawEntity(pCurve);
|
||
Add2DBuffer(pCurve);
|
||
}
|
||
|
||
for (int i = 0;i < arDCurPtrs.length();i++)
|
||
{
|
||
pCurve = (AcDbCurve*)arDCurPtrs.at(i);
|
||
|
||
if (i == 0)
|
||
{
|
||
pCurve->getStartPoint(ptTmp);
|
||
arPtSta.append(ptTmp);
|
||
|
||
if (dFL > 1.e-3)//有法兰,外线少画一个厚度
|
||
{
|
||
MakeShortCurve(pCurve,dFL,0);
|
||
}
|
||
}
|
||
|
||
if (i == arDCurPtrs.length() - 1)
|
||
{
|
||
pCurve->getEndPoint(ptTmp);
|
||
arPtEnd.append(ptTmp);
|
||
|
||
if (dFL > 1.e-3)//有法兰,外线少画一个厚度
|
||
{
|
||
MakeShortCurve(pCurve,dFL,1);
|
||
}
|
||
}
|
||
|
||
ConverToPolyline(pCurve,dcCon.dDbLineW);
|
||
pCurve->setLayer(m_idDoubleLayer);
|
||
pCurve->setLinetype(linetypeId());
|
||
pCurve->setColorIndex(kColorByLayer);
|
||
dc.DrawEntity(pCurve);
|
||
Add2DBuffer(pCurve);
|
||
}
|
||
|
||
//封开始端口
|
||
if ( j == 0 && arPtSta.length() == 2 )
|
||
{
|
||
//市政封口线为细线
|
||
/*vtTmp = arPtSta.last() - arPtSta.first();
|
||
vtTmp.normalize();
|
||
arPtSta.first() -= vtTmp * 0.5 * dcCon.dDbLineW;
|
||
arPtSta.last() += vtTmp * 0.5 * dcCon.dDbLineW;
|
||
|
||
pPl = FormatPolyline(arPtSta.asArrayPtr(),2);
|
||
pPl->setConstantWidth(dcCon.dDbLineW);
|
||
pPl->setLayer(m_idDoubleLayer);
|
||
pPl->setLinetype(linetypeId());
|
||
pPl->setColorIndex(kColorByLayer);
|
||
|
||
dc.DrawEntity(pPl);
|
||
Add2DBuffer(pPl);*/
|
||
|
||
bHide = FALSE;
|
||
m_mapSpecXData.GetAt(KEY_HIDESTART,bHide);
|
||
|
||
if (!bHide)
|
||
{
|
||
AcDbLine* pLn = new AcDbLine;
|
||
pLn->setStartPoint(arPtSta.first());
|
||
pLn->setEndPoint(arPtSta.last());
|
||
pLn->setNormal(dcCon.vtDrawPlanNorm);
|
||
pLn->setLayer(m_idDoubleLayer);
|
||
pLn->setLinetype(linetypeId());
|
||
pLn->setColorIndex(kColorByLayer);
|
||
dc.DrawEntity(pLn);
|
||
Add2DBuffer(pLn);
|
||
}
|
||
}
|
||
|
||
//封末端端口
|
||
if ( j == (arCurPtrs.length() - 1) && arPtEnd.length() == 2)
|
||
{
|
||
//市政封口线为细线
|
||
/*vtTmp = arPtEnd.last() - arPtEnd.first();
|
||
vtTmp.normalize();
|
||
arPtEnd.first() -= vtTmp * 0.5 * dcCon.dDbLineW;
|
||
arPtEnd.last() += vtTmp * 0.5 * dcCon.dDbLineW;
|
||
pPl = FormatPolyline(arPtEnd.asArrayPtr(),2);
|
||
pPl->setConstantWidth(dcCon.dDbLineW);
|
||
pPl->setLayer(m_idDoubleLayer);
|
||
pPl->setLinetype(linetypeId());
|
||
pPl->setColorIndex(kColorByLayer);
|
||
dc.DrawEntity(pPl);
|
||
Add2DBuffer(pPl);*/
|
||
|
||
bHide = FALSE;
|
||
m_mapSpecXData.GetAt(KEY_HIDEEND, bHide);
|
||
if (!bHide)
|
||
{
|
||
AcDbLine* pLn = new AcDbLine;
|
||
pLn->setStartPoint(arPtEnd.first());
|
||
pLn->setEndPoint(arPtEnd.last());
|
||
pLn->setNormal(dcCon.vtDrawPlanNorm);
|
||
pLn->setLayer(m_idDoubleLayer);
|
||
pLn->setLinetype(linetypeId());
|
||
pLn->setColorIndex(kColorByLayer);
|
||
dc.DrawEntity(pLn);
|
||
Add2DBuffer(pLn);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
FreeBuffer(0,arCurPtrs);
|
||
dc.SetColor(dcCon.nCrBk);
|
||
dc.SetLayer(dcCon.idCurLay);
|
||
dc.SetLineType(dcCon.idCurLty);
|
||
}
|
||
|
||
return Acad::eOk;
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbEwPipeBase::DrawFlangInf2d(AcGiDraw &dc) const
|
||
{
|
||
return Acad::eOk;
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbEwPipeBase::DrawUserInf(AcGiDraw &dc) const
|
||
{
|
||
return Acad::eOk;
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbEwPipeBase::DrawFlangInf3d(AcGiDraw &dc) const
|
||
{
|
||
return Acad::eOk;
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbEwPipeBase::DrawUserInf3d(AcGiDraw &dc) const
|
||
{
|
||
return Acad::eOk;
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbEwPipeBase::GetAllHolesSolid(AcDbVoidPtrArray& arSolidPtrs,AcDbVoidPtrArray& arCenLnPtrs,const AcGeMatrix3d& xform) const
|
||
{
|
||
return Acad::eOk;
|
||
}
|
||
|
||
void AecDbEwPipeBase::DrawDashSegment(AcGiDraw &dc,AcGePoint3d& ptFr,AcGePoint3d& ptTo,double dD,AecComplexCurve& cplCurve) const
|
||
{
|
||
AcGeVector3d vtDir = ptTo - ptFr;
|
||
vtDir.normalize();
|
||
|
||
AcGePlane planXY;
|
||
dc.GetDraw2DPlan(planXY);
|
||
|
||
AcGeVector3d vtU = vtDir;
|
||
vtU.rotateBy(PI / 2.0,planXY.normal());
|
||
vtU.normalize();
|
||
vtU *= 0.5 * dD;
|
||
|
||
AecEqui::AecCurveElement el;
|
||
memset(&el,0,sizeof(AecEqui::AecCurveElement));
|
||
el.bHided = 0;
|
||
el.ptGe[0] = ptFr + vtU;
|
||
el.ptGe[1] = ptTo + vtU;
|
||
el.ptGe[2] = el.ptGe[1];
|
||
el.idSubLty = KTSetting::InitLineStyle(_T("DASH"));
|
||
el.idSubLay = dc.GetLayerId();
|
||
|
||
if (m_idDashLayer.isValid())
|
||
el.idSubLay = m_idDashLayer;
|
||
|
||
cplCurve.append(el);
|
||
|
||
el.ptGe[0] = ptFr - vtU;
|
||
el.ptGe[1] = ptTo - vtU;
|
||
el.ptGe[2] = el.ptGe[1];
|
||
cplCurve.append(el);
|
||
}
|
||
|
||
void AecDbEwPipeBase::DrawBrokenOpen(AcGiDraw &dc,AcGePoint3d& ptFr,AcGePoint3d& ptTo,double dD,AecComplexCurve& cplCurve) const
|
||
{
|
||
assertReadEnabled();
|
||
|
||
AcGePoint3d ptSta;
|
||
AcGePoint3d ptEnd;
|
||
m_pBaseCurve->getStartPoint(ptSta);
|
||
m_pBaseCurve->getEndPoint(ptEnd);
|
||
ptSta.z = ptFr.z;ptEnd.z = ptTo.z;
|
||
|
||
//如果是市政则不画两侧符号
|
||
//int nTrade = 0;
|
||
//m_mapSpecXData.GetAt(DOC_TRADE,nTrade);
|
||
//if (nTrade == WPipe::eCivial)
|
||
//{
|
||
// //如果在管端,为管端断管
|
||
// if (ptFr.distanceTo(ptSta) < 1.e-3 ||
|
||
// ptFr.distanceTo(ptEnd) < 1.e-3)
|
||
// {
|
||
// //管端断管绘制保留
|
||
// }
|
||
// else
|
||
// {
|
||
// return;
|
||
// }
|
||
//}
|
||
|
||
AcGeVector3d vtDir = ptTo - ptFr;
|
||
vtDir.normalize();
|
||
|
||
if (ptFr.distanceTo(ptTo) < 1.e-3)
|
||
vtDir = ptEnd - ptSta;
|
||
vtDir.normalize();
|
||
|
||
DrawSide(dc,ptFr,vtDir,dD,cplCurve,false);
|
||
|
||
if (ptFr.distanceTo(ptTo) > 1.e-3)
|
||
{
|
||
DrawSide(dc,ptTo,-vtDir,dD,cplCurve,true);
|
||
}
|
||
}
|
||
|
||
void AecDbEwPipeBase::DrawSide(AcGiDraw &dc,AcGePoint3d ptSideCen,AcGeVector3d vcDir,double dD,AecComplexCurve& cplCurve,bool bMirror) const
|
||
{
|
||
AcGePlane planXY;
|
||
dc.GetDraw2DPlan(planXY);
|
||
|
||
//arc 1,arc2,arc3
|
||
AcGePoint3d ptArc1[3],ptArc2[3],ptArc3[3];
|
||
|
||
AcGeVector3d vcPipe = vcDir;
|
||
AcGeVector3d vcTemp = vcDir;
|
||
vcPipe.rotateBy(PI / 2.0,planXY.normal());
|
||
vcPipe.normalize();
|
||
vcPipe *= dD / 2.0;
|
||
|
||
ptArc1[0] = ptSideCen + vcPipe;
|
||
ptArc1[2] = ptSideCen;
|
||
vcTemp.normalize();
|
||
vcTemp *= 0.5 * dD * ( 1.0 - sin(PI / 3.0));
|
||
Midpoint(ptArc1[0],ptArc1[2],ptArc1[1]);
|
||
ptArc1[1] += vcTemp;
|
||
|
||
//
|
||
ptArc2[0] = ptArc1[2];
|
||
ptArc2[2] = ptSideCen - vcPipe;
|
||
Midpoint(ptArc2[0],ptArc2[2],ptArc2[1]);
|
||
ptArc2[1] -= vcTemp;
|
||
|
||
//
|
||
ptArc3[0] = ptArc2[0];
|
||
ptArc3[2] = ptArc2[2];
|
||
Midpoint(ptArc3[0],ptArc3[2],ptArc3[1]);
|
||
ptArc3[1] += vcTemp;
|
||
|
||
AecEqui::AecCurveElement el;
|
||
memset(&el,0,sizeof(AecEqui::AecCurveElement));
|
||
|
||
el.ptGe[0] = ptArc1[0];
|
||
el.ptGe[1] = ptArc1[1];
|
||
el.ptGe[2] = ptArc1[2];
|
||
cplCurve.append(el);
|
||
|
||
el.ptGe[0] = ptArc2[0];
|
||
el.ptGe[1] = ptArc2[1];
|
||
el.ptGe[2] = ptArc2[2];
|
||
cplCurve.append(el);
|
||
|
||
el.ptGe[0] = ptArc3[0];
|
||
el.ptGe[1] = ptArc3[1];
|
||
el.ptGe[2] = ptArc3[2];
|
||
cplCurve.append(el);
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbEwPipeBase::Draw3d(AcGiDraw &dc) const
|
||
{
|
||
assertReadEnabled();
|
||
|
||
AcCmTransparency tr = transparency();
|
||
AcCmTransparency oldTr = dc.SetTransparency(tr);
|
||
|
||
////管线系统屏蔽掉
|
||
if ( dc.IsDragging() )
|
||
{
|
||
//return Acad::eOk;
|
||
}
|
||
|
||
if (m_pBaseCurve == NULL)
|
||
return Acad::eInvalidInput;
|
||
|
||
//图层
|
||
AcDbObjectId idLay = dc.GetLayerId();
|
||
dc.SetLayer(layerId());
|
||
|
||
int nCrBk = dc.GetColor();
|
||
|
||
DrawInfArrow(dc);
|
||
|
||
int nColor = nCrBk;
|
||
if ( m_mapSpecXData.GetAt(_T("COLOR"),nColor) )
|
||
{
|
||
dc.SetColor(nColor);
|
||
}
|
||
|
||
int nSegIndex = m_nInfActive / 2;
|
||
if (m_nInfActive < 0)
|
||
nSegIndex = -1;
|
||
|
||
if (IsActive())
|
||
{
|
||
nColor = kMagenta;
|
||
m_mapSpecXData.GetAt(KEY_ACTIVECR,nColor);
|
||
dc.SetColor(nColor);
|
||
}
|
||
|
||
//AcDb3dSolid
|
||
if (Has3DBuffer())
|
||
{
|
||
AcDbEntity* pEnt = NULL;
|
||
const AcDbVoidPtrArray &ar3D = Get3DBuffer();
|
||
for (int i = 0;i < ar3D.length();i++)
|
||
{
|
||
pEnt = (AcDbEntity*)ar3D.at(i);
|
||
if (nSegIndex == i)//线缆段
|
||
{
|
||
pEnt->setColorIndex(kMagenta);
|
||
}
|
||
else
|
||
{
|
||
if ( IsActive() )
|
||
{
|
||
BackupColorIndex(pEnt);
|
||
pEnt->setColorIndex(nColor);
|
||
}
|
||
else
|
||
{
|
||
SetBackupColorIndex(pEnt);
|
||
}
|
||
}
|
||
dc.DrawEntity(*pEnt);
|
||
}
|
||
|
||
dc.SetLayer(idLay);
|
||
dc.SetColor(nCrBk);
|
||
return Acad::eOk;
|
||
}
|
||
|
||
AcGePoint3d ptCen,ptGe;
|
||
m_mapSpecXData.GetAt(KEY_SECCEN,ptCen);
|
||
|
||
AcGePoint3dArray arPts;
|
||
double dW = 0.0,dDis = 0.0;
|
||
int nType = 0;
|
||
|
||
for (int i = 0;i < m_arBreaks.length();i++)
|
||
{
|
||
ptGe = m_arBreaks.at(i).ptGe;
|
||
dW = m_arBreaks.at(i).dW;
|
||
nType = m_arBreaks.at(i).nType;
|
||
|
||
if (nType != -1)//不是虚段 2025-9-18
|
||
{
|
||
m_pBaseCurve->getDistAtPoint(ptGe, dDis);
|
||
|
||
dDis -= 0.5 * dW;
|
||
m_pBaseCurve->getPointAtDist(dDis, ptGe);
|
||
arPts.append(ptGe);
|
||
|
||
dDis += dW;
|
||
m_pBaseCurve->getPointAtDist(dDis, ptGe);
|
||
|
||
int nFd = -1;
|
||
if (!arPts.find(ptGe, nFd) )
|
||
{
|
||
arPts.append(ptGe);
|
||
}
|
||
else
|
||
{
|
||
arPts.removeLast();
|
||
}
|
||
}
|
||
}
|
||
|
||
if (m_pRegion == NULL)
|
||
{
|
||
dc.SetLayer(idLay);
|
||
dc.SetColor(nCrBk);
|
||
return Acad::eOk;
|
||
}
|
||
|
||
AecDbX3dPart part;
|
||
BoolSubtractUserInf3d(part);
|
||
part.Create();
|
||
AcDb3dSolid *pSolidCut = part.CreateDraw3dSolid();
|
||
|
||
AcDbRegion* pRegnCln = (AcDbRegion*)m_pRegion->clone();
|
||
double dAngle = 0.0;
|
||
if ( m_mapSpecXData.GetAt(KEY_ROTATION,dAngle) )
|
||
{
|
||
if (pRegnCln != NULL)
|
||
{
|
||
//向下绘制,且有旋转处理.原因不明
|
||
//dAngle = 2.0 * PI - dAngle;
|
||
AcDbLine* pLn = AcDbLine::cast(m_pBaseCurve);
|
||
if (pLn != NULL)
|
||
{
|
||
AcGePoint3d ptS = pLn->startPoint();
|
||
AcGePoint3d ptE = pLn->endPoint();
|
||
AcGeVector3d vtL = ptE - ptS;
|
||
if (vtL.isCodirectionalTo(-AcGeVector3d::kZAxis))
|
||
{
|
||
if ( fabs(dAngle) > 1.e-6)
|
||
dAngle = 2.0 * PI - dAngle;
|
||
}
|
||
}
|
||
|
||
AcGeMatrix3d xformR;
|
||
xformR.setToRotation(dAngle,AcGeVector3d::kZAxis);
|
||
pRegnCln->transformBy(xformR);
|
||
}
|
||
}
|
||
|
||
//加入中心线
|
||
AcDbCurve* pCenCrv = GetBaseCurve(false);
|
||
if (pCenCrv != NULL)
|
||
{
|
||
pCenCrv->setLayer(m_idCenterLayer);
|
||
pCenCrv->setLinetype(KTSetting::InitLineStyle(_T("CENTER2")));
|
||
dc.DrawEntity(pCenCrv);
|
||
Add3DBuffer(pCenCrv);
|
||
}
|
||
|
||
if (arPts.length() > 0)
|
||
{
|
||
AcDbVoidPtrArray arCurPtrs;
|
||
m_pBaseCurve->getSplitCurves(arPts,arCurPtrs);
|
||
|
||
AcDbCurve* pBaseCrv = NULL;
|
||
AcDbEntity* p3dEnt = NULL;
|
||
for (int j = 0;j < arCurPtrs.length();j++)
|
||
{
|
||
pBaseCrv = (AcDbCurve*)arCurPtrs.at(j);
|
||
|
||
p3dEnt = dc.DrawPipe(pBaseCrv,pRegnCln,ptCen);
|
||
if (p3dEnt != NULL)
|
||
{
|
||
p3dEnt->setColorIndex(nColor);
|
||
Add3DBuffer(p3dEnt);
|
||
}
|
||
DELETE_PTR(pBaseCrv);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
AcDbCurve* pBaseCurve = GetBaseCurve(false);
|
||
|
||
AecDb3dRoadAxisLine* pALn = AecDb3dRoadAxisLine::cast(pBaseCurve);
|
||
if (pALn != NULL)
|
||
{
|
||
if ( pALn->IsSubTangentContinue() )//如果相切连续
|
||
{
|
||
// 原来的方式 ,相切连续
|
||
AcDbCurve* pCurve = NULL;
|
||
AcDbEntity* p3dEnt = NULL;
|
||
|
||
int nCount = pALn->GetCurveSegCount();
|
||
for (int ii = 0;ii < nCount;ii++)
|
||
{
|
||
pCurve = pALn->GetCurveSeg(ii);
|
||
|
||
p3dEnt = dc.DrawPipe(pCurve,pRegnCln,ptCen);
|
||
if (p3dEnt != NULL)
|
||
{
|
||
p3dEnt->setColorIndex(nColor);
|
||
Add3DBuffer(p3dEnt);
|
||
}
|
||
}
|
||
}
|
||
else//不相切连续
|
||
{
|
||
AcDbEntity* p3dEnt = NULL;
|
||
AcDbPolyline* pPl2d = pALn->ConvertTo2dPline();
|
||
if (pPl2d != NULL)
|
||
{
|
||
p3dEnt = dc.DrawPipe(pPl2d,pRegnCln,ptCen);
|
||
if (p3dEnt != NULL)
|
||
{
|
||
p3dEnt->setColorIndex(nColor);
|
||
Add3DBuffer(p3dEnt);
|
||
}
|
||
delete pPl2d;
|
||
}
|
||
else
|
||
{
|
||
AcDb3dPolyline* p3dPl = NULL;
|
||
|
||
AcGePoint2d ptDR;
|
||
if ( pALn->ReadDandRatio(ptDR))
|
||
{
|
||
if (ptDR.x > 1.e-2)
|
||
{
|
||
p3dPl = pALn->ConvertTo3dPline(ptDR.y);
|
||
}
|
||
else
|
||
{
|
||
p3dPl = pALn->ConvertTo3dPline(100.0);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
p3dPl = pALn->ConvertTo3dPline(100.0);
|
||
}
|
||
|
||
if (p3dPl != NULL)
|
||
{
|
||
//有点慢
|
||
p3dEnt = dc.DrawPipe(p3dPl,pRegnCln,ptCen);
|
||
if (p3dEnt != NULL)
|
||
{
|
||
p3dEnt->setColorIndex(nColor);
|
||
Add3DBuffer(p3dEnt);
|
||
}
|
||
delete p3dPl;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
AcDbLine* pLn = AcDbLine::cast(pBaseCurve);
|
||
if (pLn != NULL)
|
||
{
|
||
//如果是衬塑管
|
||
double dGast = GetGasketThick();
|
||
|
||
AcGePoint3d ptS = pLn->startPoint();
|
||
AcGePoint3d ptE = pLn->endPoint();
|
||
AcGeVector3d vtL = ptE - ptS;
|
||
|
||
if (dGast > 1.e-1)
|
||
{
|
||
vtL.normalize();
|
||
ptS += vtL * 0.5 * dGast;
|
||
ptE -= vtL * 0.5 * dGast;
|
||
pLn->setStartPoint(ptS);
|
||
pLn->setEndPoint(ptE);
|
||
}
|
||
double dAngle = 0.0;
|
||
m_mapSpecXData.GetAt(KEY_ROTATION,dAngle);
|
||
}
|
||
|
||
int oldClr = dc.GetColor();
|
||
AcDbObjectId oldLy = dc.GetLayerId();
|
||
|
||
bool bIsPipe(false);
|
||
int app(-1);
|
||
m_mapSpecXData.GetAt(PIPE_EAPP, app);
|
||
if (app == WPipe::eButtweld // 是否是管线
|
||
|| app == WPipe::eVictaulic
|
||
|| app == WPipe::eSanitary
|
||
|| app == WPipe::eFlange)
|
||
{
|
||
bIsPipe = true;
|
||
}
|
||
|
||
CString sys;
|
||
if (bIsPipe && m_mapSpecXData.GetAt(PIPE_SYS, sys))
|
||
{
|
||
//虚函数
|
||
AcDbObjectId idLy = CoreTools::getLyForPipe(sys);
|
||
int clr = CoreTools::getColorByPipeSys(sys, !CoreTools::IsUsePipeOutClrFor3DRender());
|
||
dc.SetColor(clr);
|
||
dc.SetLayer(idLy);
|
||
}
|
||
else
|
||
{
|
||
dc.SetColor(nColor);
|
||
}
|
||
AcDbEntity* p3dEnt = dc.DrawPipe(pBaseCurve,pRegnCln,ptCen);
|
||
if (p3dEnt)
|
||
{
|
||
if (pSolidCut != NULL)
|
||
{
|
||
AcDb3dSolid *pSolidEnt = AcDb3dSolid::cast(p3dEnt);
|
||
if (pSolidEnt != NULL)
|
||
{
|
||
pSolidEnt->booleanOper(AcDb::kBoolSubtract, pSolidCut);
|
||
}
|
||
}
|
||
p3dEnt->setColorIndex(dc.GetColor());
|
||
p3dEnt->setLayer(dc.GetLayerId());
|
||
|
||
Add3DBuffer(p3dEnt);
|
||
}
|
||
|
||
dc.SetColor(oldClr);
|
||
dc.SetLayer(oldLy);
|
||
|
||
}
|
||
delete pBaseCurve;
|
||
}
|
||
|
||
//可能的绘制法兰管子
|
||
DrawFlangInf3d(dc);
|
||
|
||
DrawUserInf3d(dc);
|
||
|
||
//如果Clone REGION,则删除临时
|
||
if (pRegnCln != m_pRegion)
|
||
{
|
||
delete pRegnCln;
|
||
}
|
||
|
||
dc.SetLayer(idLay);
|
||
dc.SetColor(nCrBk);
|
||
|
||
dc.SetTransparency(oldTr);
|
||
return Acad::eOk;
|
||
}
|
||
|
||
extern AcDbRegion *CreateRegion(const AcGePoint3d *pptGe, int nPoints, const AcGeVector3d &vtNorm, double dt);
|
||
Acad::ErrorStatus AecDbEwPipeBase::BoolSubtractUserInf3d(AecDbX3dPart &part) const
|
||
{
|
||
assertReadEnabled();
|
||
|
||
AcCmTransparency tr = transparency();
|
||
|
||
double dt = 0.0;
|
||
m_mapSpecXData.GetAt(PIPE_THICK, dt);
|
||
|
||
AcGeVector3d vtDirThick;
|
||
AecUserInterface inf2;
|
||
AcDbLine lnPath;
|
||
AcDbRegion *pRegion = NULL;
|
||
for (int i = 0; i < m_arUserInfs.length(); i++)
|
||
{
|
||
const AecUserInterface &inf = m_arUserInfs.at(i);
|
||
memcpy(&inf2, &inf, sizeof(AecUserInterface));
|
||
|
||
vtDirThick = inf.vtDir;
|
||
vtDirThick.normalize();
|
||
vtDirThick *= 2.0 * dt;
|
||
|
||
lnPath.setStartPoint(inf.ptGe[0] - vtDirThick);
|
||
lnPath.setEndPoint(inf.ptGe[0] + vtDirThick);
|
||
|
||
for (int ii = 0; ii < inf2.nPoints; ii++)
|
||
{
|
||
inf2.ptGe[ii] -= vtDirThick;
|
||
}
|
||
|
||
if (inf.nPoints >= 3) //多边形
|
||
{
|
||
pRegion = CreateRegion(inf2.ptGe, inf2.nPoints, inf2.vtDir, 0);
|
||
if (pRegion != NULL)
|
||
{
|
||
//CoreTools::AddToModelSpace(pRegion);
|
||
//CoreTools::CloneAndAddToModelSpace(&lnPath);
|
||
AcDbX3dSolid *pX3dSolidTop = new AcDbX3dSolid;
|
||
pX3dSolidTop->CreateExtrude(pRegion, lnPath);
|
||
part.AddX3dSolid(pX3dSolidTop);
|
||
}
|
||
}
|
||
else if (inf.nPoints == 2)//圆
|
||
{
|
||
pRegion = CreateRegion(inf2.ptGe, inf2.nPoints, inf2.vtDir, 0);
|
||
if (pRegion != NULL)
|
||
{
|
||
AcDbX3dSolid *pX3dSolidTop = new AcDbX3dSolid;
|
||
pX3dSolidTop->CreateExtrude(pRegion, lnPath);
|
||
part.AddX3dSolid(pX3dSolidTop);
|
||
}
|
||
}
|
||
}
|
||
return Acad::eOk;
|
||
}
|
||
|
||
AcDb3dSolid* AecDbEwPipeBase::GetCreatPipe3dSolid() const
|
||
{
|
||
assertReadEnabled();
|
||
|
||
AcDbVoidPtrArray ar3DSolidPtrs;
|
||
GetCreatPipe3dSolid(ar3DSolidPtrs);
|
||
|
||
if (ar3DSolidPtrs.isEmpty())
|
||
return NULL;
|
||
|
||
AcDbEntity* pEntT = NULL;
|
||
AcDb3dSolid* pSolidAll = NULL;
|
||
|
||
for (int i = 0;i < ar3DSolidPtrs.length();i++)
|
||
{
|
||
pEntT = (AcDbEntity*)ar3DSolidPtrs.at(i);
|
||
pSolidAll = AcDb3dSolid::cast(pEntT);
|
||
if (pSolidAll != NULL)
|
||
{
|
||
ar3DSolidPtrs.removeAt(i);
|
||
break;
|
||
}
|
||
}
|
||
|
||
struct resbuf rb;
|
||
acedGetVar(_T("useri3"),&rb);
|
||
|
||
Acad::ErrorStatus es;
|
||
AcDb3dSolid* pSolid = NULL;
|
||
AcDbEntity* pEnt = NULL;
|
||
|
||
for (int i = 0;i < ar3DSolidPtrs.length();i++)
|
||
{
|
||
pEnt = (AcDbEntity*)ar3DSolidPtrs.at(i);
|
||
if (pEnt != NULL)
|
||
{
|
||
pSolid = AcDb3dSolid::cast(pEnt);
|
||
|
||
if (pSolid != NULL)
|
||
{
|
||
if (rb.resval.rint == 1357)//特定情况下,绘制道路设计线,测试用
|
||
{
|
||
AddToModelSpace((AcDbEntity*)pSolid->clone());
|
||
}
|
||
|
||
es = pSolidAll->booleanOper(AcDb::kBoolUnite,pSolid);
|
||
if (es != Acad::eOk)
|
||
{
|
||
//...
|
||
}
|
||
}
|
||
}
|
||
}
|
||
return pSolidAll;
|
||
}
|
||
|
||
int AecDbEwPipeBase::GetCreatPipe3dSolid(AcDbVoidPtrArray& ar3DSolidPtrs) const
|
||
{
|
||
if ( Get3DBuffer().length() > 0)
|
||
{
|
||
return GetDraw3dables(ar3DSolidPtrs,false);
|
||
}
|
||
|
||
if (!m_pRegion)
|
||
return 0;
|
||
|
||
AcGePoint3d ptCen,ptGe;
|
||
m_mapSpecXData.GetAt(KEY_SECCEN,ptCen);
|
||
|
||
AcGePoint3dArray arPts;
|
||
double dW = 0.0,dDis = 0.0;
|
||
int nType = 0;
|
||
|
||
for (int i = 0;i < m_arBreaks.length();i++)
|
||
{
|
||
ptGe = m_arBreaks.at(i).ptGe;
|
||
dW = m_arBreaks.at(i).dW;
|
||
nType = m_arBreaks.at(i).nType;
|
||
|
||
if (nType != 0)
|
||
continue;
|
||
|
||
m_pBaseCurve->getDistAtPoint(ptGe,dDis);
|
||
|
||
dDis -= 0.5 * dW;
|
||
m_pBaseCurve->getPointAtDist(dDis,ptGe);
|
||
arPts.append(ptGe);
|
||
|
||
dDis += dW;
|
||
m_pBaseCurve->getPointAtDist(dDis,ptGe);
|
||
arPts.append(ptGe);
|
||
}
|
||
|
||
AcDbRegion* pRegnCln = m_pRegion;
|
||
double dAngle = 0.0;
|
||
if ( m_mapSpecXData.GetAt(KEY_ROTATION,dAngle) )
|
||
{
|
||
pRegnCln = (AcDbRegion*)m_pRegion->clone();
|
||
if (pRegnCln != NULL)
|
||
{
|
||
AcGeMatrix3d xformR;
|
||
xformR.setToRotation(dAngle,AcGeVector3d::kZAxis);
|
||
pRegnCln->transformBy(xformR);
|
||
}
|
||
}
|
||
|
||
AcGiExplodeDraw dc(ar3DSolidPtrs);
|
||
if (arPts.length() > 0)
|
||
{
|
||
AcDbVoidPtrArray arCurPtrs;
|
||
m_pBaseCurve->getSplitCurves(arPts,arCurPtrs);
|
||
|
||
AcDbCurve* pBaseCrv = NULL;
|
||
for (int j = 0;j < arCurPtrs.length();j++)
|
||
{
|
||
pBaseCrv = (AcDbCurve*)arCurPtrs.at(j);
|
||
dc.DrawPipe(pBaseCrv,pRegnCln,ptCen);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
AecDb3dRoadAxisLine* pALn = AecDb3dRoadAxisLine::cast(m_pBaseCurve);
|
||
if (pALn != NULL)
|
||
{
|
||
if ( pALn->IsSubTangentContinue() )//如果相切连续
|
||
{
|
||
// 原来的方式 ,相切连续
|
||
AcDbCurve* pCurve = NULL;
|
||
AcDbEntity* p3dEnt = NULL;
|
||
|
||
int nCount = pALn->GetCurveSegCount();
|
||
for (int ii = 0;ii < nCount;ii++)
|
||
{
|
||
pCurve = pALn->GetCurveSeg(ii);
|
||
|
||
p3dEnt = dc.DrawPipe(pCurve,pRegnCln,ptCen);
|
||
if (p3dEnt != NULL)
|
||
{
|
||
Add3DBuffer(p3dEnt);
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
AcDbPolyline* pPl2d = pALn->ConvertTo2dPline();
|
||
if (pPl2d != NULL)
|
||
{
|
||
dc.DrawPipe(pPl2d,pRegnCln,ptCen);
|
||
delete pPl2d;
|
||
}
|
||
else
|
||
{
|
||
AcDb3dPolyline* p3dPl = NULL;
|
||
|
||
AcGePoint2d ptDR;
|
||
if ( pALn->ReadDandRatio(ptDR))
|
||
{
|
||
if (ptDR.x > 1.e-2)
|
||
{
|
||
p3dPl = pALn->ConvertTo3dPline(ptDR.y);
|
||
}
|
||
else
|
||
{
|
||
p3dPl = pALn->ConvertTo3dPline(100.0);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
p3dPl = pALn->ConvertTo3dPline(100.0);
|
||
}
|
||
|
||
if (p3dPl != NULL)
|
||
{
|
||
//有点慢
|
||
dc.DrawPipe(p3dPl,pRegnCln,ptCen);
|
||
delete p3dPl;
|
||
}
|
||
}
|
||
}
|
||
|
||
/*AcGePoint2d ptDR;
|
||
if ( pALn->ReadDandRatio(ptDR) )
|
||
{
|
||
AecDb3dRoadAxisLine* pALnNew = pALn;//pALn->GetFittedRoadAxisLine(ptDR.x,ptDR.y);
|
||
if (pALnNew != NULL)
|
||
{
|
||
AcDbCurve* pCurve = NULL;
|
||
AcDbEntity* p3dEnt = NULL;
|
||
|
||
AcGeVector3d vtSta,vtEnd;
|
||
double dSta = 0.0,dEnd = 0.0;
|
||
AcGePoint3d ptSta,ptEnd;
|
||
bool bDir = false;
|
||
|
||
AcGeMatrix3d xformR;
|
||
xformR.setToRotation(PI,AcGeVector3d::kYAxis,ptCen);
|
||
|
||
AcArray<CurveDir> curDirs;
|
||
pALnNew->GetCurveDirs(curDirs);
|
||
|
||
int nCount = curDirs.length();
|
||
for (int ii = 0;ii < nCount;ii++)
|
||
{
|
||
pCurve = curDirs.at(ii).pCurve;
|
||
bDir = curDirs.at(ii).bDir;
|
||
|
||
//两头延伸10毫米,以便求交成功
|
||
pCurve->getStartParam(dSta);
|
||
pCurve->getFirstDeriv(dSta,vtSta);
|
||
vtSta.negate();//向外
|
||
vtSta.normalize();
|
||
|
||
pCurve->getEndParam(dEnd);
|
||
pCurve->getFirstDeriv(dEnd,vtEnd);
|
||
vtEnd.normalize();
|
||
|
||
struct resbuf rb;
|
||
acedGetVar(_T("INSUNITS"), &rb);
|
||
|
||
if (rb.resval.rint == AcDb::kUnitsMeters)//米单位
|
||
{
|
||
ptSta += vtSta * AS_MUNIT(10.0);
|
||
ptEnd += vtEnd * AS_MUNIT(10.0);
|
||
}
|
||
else if(rb.resval.rint == AcDb::kUnitsMillimeters)//毫米单位
|
||
{
|
||
ptSta += vtSta * 10.0;
|
||
ptEnd += vtEnd * 10.0;
|
||
}
|
||
|
||
pCurve->extend(Adesk::kTrue,ptSta);
|
||
pCurve->extend(Adesk::kFalse,ptEnd);
|
||
|
||
if (bDir)//顺序
|
||
{
|
||
dc.DrawPipe(pCurve,pRegnCln,ptCen);
|
||
}
|
||
else//逆序
|
||
{
|
||
AcDbRegion* pRegCln2 = (AcDbRegion*)pRegnCln->clone();
|
||
pRegCln2->transformBy(xformR);
|
||
|
||
dc.DrawPipe(pCurve,pRegCln2,ptCen);
|
||
delete pRegCln2;
|
||
}
|
||
}
|
||
|
||
if (pALnNew != pALn) delete pALnNew;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
AcDbCurve* pCurve = NULL;
|
||
AcDbEntity* p3dEnt = NULL;
|
||
|
||
AcGeVector3d vtSta,vtEnd;
|
||
double dSta = 0.0,dEnd = 0.0;
|
||
AcGePoint3d ptSta,ptEnd;
|
||
bool bDir = false;
|
||
|
||
AcGeMatrix3d xformR;
|
||
xformR.setToRotation(PI,AcGeVector3d::kYAxis,ptCen);
|
||
|
||
AcArray<CurveDir> curDirs;
|
||
pALn->GetCurveDirs(curDirs);
|
||
|
||
int nCount = curDirs.length();
|
||
for (int ii = 0;ii < nCount;ii++)
|
||
{
|
||
pCurve = curDirs.at(ii).pCurve;
|
||
|
||
//两头延伸10毫米,以便求交成功
|
||
pCurve->getStartParam(dSta);
|
||
pCurve->getFirstDeriv(dSta,vtSta);
|
||
|
||
vtSta.negate();//向外
|
||
vtSta.normalize();
|
||
|
||
pCurve->getEndParam(dEnd);
|
||
pCurve->getFirstDeriv(dEnd,vtEnd);
|
||
vtEnd.normalize();
|
||
|
||
struct resbuf rb;
|
||
acedGetVar(_T("INSUNITS"), &rb);
|
||
|
||
if (rb.resval.rint == AcDb::kUnitsMeters)//米单位
|
||
{
|
||
ptSta += vtSta * AS_MUNIT(10.0);
|
||
ptEnd += vtEnd * AS_MUNIT(10.0);
|
||
}
|
||
else if(rb.resval.rint == AcDb::kUnitsMillimeters)//毫米单位
|
||
{
|
||
ptSta += vtSta * 10.0;
|
||
ptEnd += vtEnd * 10.0;
|
||
}
|
||
|
||
bDir = curDirs.at(ii).bDir;
|
||
|
||
pCurve->extend(Adesk::kTrue,ptSta);
|
||
pCurve->extend(Adesk::kFalse,ptEnd);
|
||
|
||
if (bDir)//顺序
|
||
{
|
||
dc.DrawPipe(pCurve,pRegnCln,ptCen);
|
||
}
|
||
else//逆序
|
||
{
|
||
AcDbRegion* pRegCln2 = (AcDbRegion*)pRegnCln->clone();
|
||
pRegCln2->transformBy(xformR);
|
||
|
||
dc.DrawPipe(pCurve,pRegCln2,ptCen);
|
||
|
||
delete pRegCln2;
|
||
}
|
||
}
|
||
}*/
|
||
}
|
||
else
|
||
{
|
||
BOOL bXDB(FALSE);
|
||
m_mapSpecXData.GetAt(_T("_KEY_XDB_Flag_"), bXDB);
|
||
if (bXDB == FALSE)
|
||
{
|
||
dc.DrawPipe(m_pBaseCurve, pRegnCln, ptCen);
|
||
}
|
||
else
|
||
{ // 处理斜底板
|
||
#if ARX > 18
|
||
AcDb3dSolid *pSo(drawXDB(&m_mapSpecXData));
|
||
if (pSo) ar3DSolidPtrs.append(pSo);
|
||
#endif
|
||
}
|
||
}
|
||
}
|
||
|
||
//如果是旋转的REGION,则删除临时
|
||
if (pRegnCln != m_pRegion)
|
||
{
|
||
delete pRegnCln;
|
||
}
|
||
return ar3DSolidPtrs.length();
|
||
}
|
||
|
||
bool AecDbEwPipeBase::IsArcBaseCurve() const
|
||
{
|
||
assertReadEnabled();
|
||
|
||
AcDbArc* pArc = AcDbArc::cast(m_pBaseCurve);
|
||
if (pArc != NULL)
|
||
{
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
|
||
void AecDbEwPipeBase::DrawSubAxis(AcGiDraw &dc,AcDbEntity* pEnt) const
|
||
{
|
||
if (pEnt != NULL)
|
||
{
|
||
AcDb3dSolid* pSolid = AcDb3dSolid::cast(pEnt);
|
||
if (pSolid != NULL)
|
||
{
|
||
double dVol = 0.0,momInertia[3],prodInertia[3],prinMoments[3],radiiGyration[3];
|
||
AcGePoint3d ptOrg;
|
||
AcGeVector3d prinAxes[3];
|
||
AcDbExtents extents;
|
||
|
||
//然后变换到0,0,0点
|
||
pSolid->getMassProp(dVol,ptOrg,momInertia,prodInertia,prinMoments,prinAxes,radiiGyration,extents);
|
||
|
||
AcGeVector3dArray arVtAxis;
|
||
arVtAxis.append(AcGeVector3d::kXAxis);
|
||
arVtAxis.append(AcGeVector3d::kYAxis);
|
||
arVtAxis.append(AcGeVector3d::kZAxis);
|
||
|
||
Adesk::Int16 nBk = dc.GetColor();
|
||
|
||
AcGeVector3d vtDir;
|
||
for (int i = 0;i < arVtAxis.length();i++)
|
||
{
|
||
vtDir = arVtAxis.at(i);
|
||
|
||
if (vtDir.isZeroLength())
|
||
continue;
|
||
|
||
vtDir.normalize();
|
||
|
||
Adesk::Int16 nCr = dc.GetColor();
|
||
|
||
if (i == 0)
|
||
dc.SetColor(1);//red
|
||
else if (i == 1)
|
||
dc.SetColor(3);//gree
|
||
else if (i == 2)
|
||
dc.SetColor(5);//blue
|
||
else
|
||
dc.SetColor(i+1);
|
||
|
||
vtDir.normalize();
|
||
vtDir *= PixelToWcs(30);
|
||
|
||
//clinder
|
||
AcGePoint3d ptGeFr = ptOrg;
|
||
AcGePoint3d ptGeTo = ptGeFr + vtDir;
|
||
AcDbEntity* p3d = dc.DrawCone(ptGeFr,PixelToWcs(2),ptGeTo,PixelToWcs(2));
|
||
if (p3d != NULL)
|
||
{
|
||
|
||
}
|
||
|
||
//arrow
|
||
ptGeFr = ptGeTo;
|
||
vtDir.normalize();
|
||
ptGeTo += vtDir * PixelToWcs(15);
|
||
p3d = dc.DrawCone(ptGeFr,PixelToWcs(5),ptGeTo,0.001);
|
||
if (p3d != NULL)
|
||
{
|
||
|
||
}
|
||
dc.SetColor(nCr);
|
||
}
|
||
|
||
dc.SetColor(nBk);
|
||
}
|
||
}
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbEwPipeBase::DrawInfArrow(AcGiDraw &dc) const
|
||
{
|
||
assertReadEnabled();
|
||
|
||
int app(-1);
|
||
m_mapSpecXData.GetAt(PIPE_EAPP, app);
|
||
if (app == WPipe::eButtweld // 是否是管线
|
||
|| app == WPipe::eVictaulic
|
||
|| app == WPipe::eSanitary
|
||
|| app == WPipe::eFlange)
|
||
{
|
||
return Acad::eOk;
|
||
}
|
||
|
||
if (m_nInfActive >= 0 )
|
||
{
|
||
AcArray<AecInterface> arInfs;
|
||
GetInterface(arInfs);
|
||
|
||
if ( m_nInfActive < arInfs.length() )
|
||
{
|
||
AecInterface& inf = arInfs.at(m_nInfActive);
|
||
|
||
AcGeVector3d vtDir = inf.vtDir;
|
||
vtDir.normalize();
|
||
|
||
Adesk::Int16 nCr = dc.GetColor();
|
||
|
||
dc.SetColor(kYellow);//red
|
||
|
||
vtDir.normalize();
|
||
vtDir *= PixelToWcs(30);
|
||
|
||
//clinder
|
||
AcGePoint3d ptGeFr = inf.ptPos;
|
||
AcGePoint3d ptGeTo = ptGeFr + vtDir;
|
||
AcDbEntity* p3d = dc.DrawCone(ptGeFr,PixelToWcs(1),ptGeTo,PixelToWcs(1));
|
||
if (p3d != NULL)
|
||
{
|
||
|
||
}
|
||
|
||
//arrow
|
||
ptGeFr = ptGeTo;
|
||
vtDir.normalize();
|
||
ptGeTo += vtDir * PixelToWcs(15);
|
||
p3d = dc.DrawCone(ptGeFr,PixelToWcs(5),ptGeTo,1.e-3);
|
||
if (p3d != NULL)
|
||
{
|
||
|
||
}
|
||
dc.SetColor(nCr);
|
||
}
|
||
}
|
||
return Acad::eOk;
|
||
}
|
||
|
||
LPCTSTR AecDbEwPipeBase::GetGripCmd() const
|
||
{
|
||
assertReadEnabled();
|
||
return NULL;
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbEwPipeBase::SetBaseCurve(const AcGePoint3dArray& arPts)
|
||
{
|
||
//AcDbLine, AcDbArc, AcDbEllipse
|
||
//AcDbSpline, AcDb2dPolyline, AcDb3dPolyline.
|
||
AssertWriteEnabled();
|
||
ClearForDraw2dables();
|
||
|
||
m_mapSpecXData.SetAt(KEY_CLASS,_T("AcDb3dPolyline"));
|
||
|
||
AcDb3dPolyline* p3dpL = new AcDb3dPolyline;
|
||
AcDb3dPolylineVertex *pVer = NULL;
|
||
|
||
AcGePoint3d ptGe;
|
||
for (int i = 0; i < arPts.length(); i++)
|
||
{
|
||
ptGe = arPts.at(i);
|
||
|
||
pVer = new AcDb3dPolylineVertex;
|
||
pVer->setPosition(ptGe);
|
||
p3dpL->appendVertex(pVer);
|
||
}
|
||
|
||
if (m_pBaseCurve != NULL)
|
||
DELETE_PTR(m_pBaseCurve);
|
||
|
||
m_pBaseCurve = p3dpL;
|
||
|
||
return Acad::eOk;
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbEwPipeBase::SetBaseCurve(const AcGePoint3d& ptSta,const AcGePoint3d& ptEnd)
|
||
{
|
||
AssertWriteEnabled();
|
||
|
||
AcDbLine ln(ptSta,ptEnd);
|
||
return SetBaseCurve(&ln);
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbEwPipeBase::SetBaseCurve(const AcGePoint3d& ptSta,const AcGeVector3d& vtDir)
|
||
{
|
||
AssertWriteEnabled();
|
||
|
||
AcGePoint3d ptEnd = ptSta + vtDir;
|
||
AcDbLine ln(ptSta,ptEnd);
|
||
|
||
return SetBaseCurve(&ln);
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbEwPipeBase::SetBaseCurve(const AcArray<EWStackPoint>& arStackPts)
|
||
{
|
||
ClearForDraw2dables();
|
||
return Acad::eOk;
|
||
}
|
||
|
||
void AecDbEwPipeBase::AssertWriteEnabled(Adesk::Boolean autoUndo,Adesk::Boolean recordModified )
|
||
{
|
||
//if (objectId().isValid())
|
||
{
|
||
Clean2DBuffer();
|
||
Clean3DBuffer();
|
||
//FreeBuffer(0,m_ar2DDrableBufPtrs);
|
||
//FreeBuffer(0,m_ar3DDrableBufPtrs);
|
||
FreeBuffer(0,m_ar2DDrableBufPtrs2);
|
||
|
||
//m_ar3DDrableBufPtrs.removeAll();
|
||
//m_ar2DDrableBufPtrs.removeAll();
|
||
//m_ar2DDrableBufPtrs2.removeAll();
|
||
|
||
AecDbCurveBase::AssertWriteEnabled(autoUndo, recordModified);
|
||
//assertWriteEnabled();
|
||
}
|
||
}
|
||
|
||
bool AecDbEwPipeBase::ReadDandRatio(AcGePoint2d& ptDRatio) const
|
||
{
|
||
assertReadEnabled();
|
||
|
||
if (m_pBaseCurve == NULL)
|
||
return false;
|
||
|
||
// 扩展数据
|
||
struct resbuf* pTmpRb = m_pBaseCurve->xData(_T("RATIO"));
|
||
if (pTmpRb != NULL)
|
||
{
|
||
struct resbuf* pTmp = pTmpRb;
|
||
struct resbuf* pTmpRadio = NULL;
|
||
|
||
while(pTmp != NULL)
|
||
{
|
||
if (pTmp->restype == AcDb::kDxfXdReal)//
|
||
{
|
||
ptDRatio.x = pTmp->resval.rreal;
|
||
|
||
pTmpRadio = pTmp->rbnext;
|
||
if (pTmpRadio != NULL && pTmpRadio->restype == AcDb::kDxfXdReal)
|
||
{
|
||
ptDRatio.y = pTmpRadio->resval.rreal;
|
||
|
||
acutRelRb(pTmpRb);
|
||
return true;
|
||
}
|
||
}
|
||
pTmp = pTmp->rbnext;
|
||
}
|
||
}
|
||
return false;
|
||
}
|
||
|
||
void AecDbEwPipeBase::SetHatch(LPCTSTR pszPatternName,double dAngle,double dScale)
|
||
{
|
||
AssertWriteEnabled();
|
||
if (pszPatternName != NULL)
|
||
{
|
||
m_mapSpecXData.SetAt(KEY_PATTERN,pszPatternName);
|
||
m_mapSpecXData.SetAt(KEY_PATTERNANG,dAngle);
|
||
m_mapSpecXData.SetAt(KEY_PATTERNSCA,dScale);
|
||
}
|
||
}
|
||
|
||
bool AecDbEwPipeBase::GetHatch(PipeHatch& sHatch) const
|
||
{
|
||
assertReadEnabled();
|
||
|
||
CString sPattern;
|
||
if ( m_mapSpecXData.GetAt(KEY_PATTERN,sPattern) )
|
||
{
|
||
//memset(&sHatch,0,sizeof(PipeHatch));
|
||
_tcscpy(sHatch.szPattern,(LPCTSTR)sPattern);
|
||
m_mapSpecXData.GetAt(KEY_PATTERNANG,sHatch.dAngle);
|
||
m_mapSpecXData.GetAt(KEY_PATTERNSCA,sHatch.dScale);
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbEwPipeBase::ClearForDraw2dables()
|
||
{
|
||
//不得实现,为子类二位特化图形用
|
||
return Acad::eOk;
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbEwPipeBase::SetBaseCurve(const AcDbCurve* pCurve)
|
||
{
|
||
//AcDbLine, AcDbArc, AcDbEllipse
|
||
//AcDbSpline, AcDb3dPolyline.
|
||
AssertWriteEnabled();
|
||
ClearForDraw2dables();
|
||
|
||
if (pCurve != NULL)
|
||
{
|
||
CString sClass = pCurve->isA()->name();
|
||
m_mapSpecXData.SetAt(KEY_CLASS,sClass);
|
||
|
||
if (m_pBaseCurve != NULL)
|
||
DELETE_PTR(m_pBaseCurve);
|
||
|
||
m_pBaseCurve = (AcDbCurve*)pCurve->clone();
|
||
|
||
// 扩展数据
|
||
AcGePoint2d ptDRatio(-1.0,-1.0);
|
||
struct resbuf* pTmpRb = pCurve->xData(_T("RATIO"));
|
||
if (pTmpRb != NULL)
|
||
{
|
||
struct resbuf* pTmp = pTmpRb;
|
||
struct resbuf* pTmpRadio = NULL;
|
||
|
||
while(pTmp != NULL)
|
||
{
|
||
if (pTmp->restype == AcDb::kDxfXdReal)//
|
||
{
|
||
ptDRatio.x = pTmp->resval.rreal;
|
||
|
||
pTmpRadio = pTmp->rbnext;
|
||
if (pTmpRadio != NULL && pTmpRadio->restype == AcDb::kDxfXdReal)
|
||
{
|
||
ptDRatio.y = pTmpRadio->resval.rreal;
|
||
break;
|
||
}
|
||
}
|
||
pTmp = pTmp->rbnext;
|
||
}
|
||
acutRelRb(pTmpRb);
|
||
|
||
if ( ptDRatio.x > 1.e-6 && ptDRatio.y > 1.e-6 )
|
||
{
|
||
m_mapSpecXData.SetAt(PIPE_RATIO,ptDRatio.y);
|
||
m_mapSpecXData.SetAt(PIPE_DN,ptDRatio.x);
|
||
}
|
||
}
|
||
return Acad::eOk;
|
||
}
|
||
return Acad::eInvalidInput;
|
||
}
|
||
|
||
//通用设置截面
|
||
Acad::ErrorStatus AecDbEwPipeBase::SetSection(AcDbPolyline* pPl,const AcGePoint3d& ptCen)
|
||
{
|
||
AssertWriteEnabled();
|
||
|
||
if (pPl != NULL)
|
||
{
|
||
if (m_pRegion != NULL)
|
||
DELETE_PTR(m_pRegion);
|
||
|
||
AcDbVoidPtrArray arCurPtrs,arRegnPtrs;
|
||
arCurPtrs.append(pPl);
|
||
|
||
if ( Acad::eOk == AcDbRegion::createFromCurves(arCurPtrs,arRegnPtrs) )
|
||
{
|
||
if (!arRegnPtrs.isEmpty() )
|
||
{
|
||
m_pRegion = (AcDbRegion*)arRegnPtrs.first();
|
||
m_mapSpecXData.SetAt(KEY_SECCEN,ptCen);
|
||
m_mapSpecXData.SetAt(KEY_SECSHAPE,eUserDef);
|
||
return Acad::eOk;
|
||
}
|
||
}
|
||
m_mapSpecXData.SetAt(PIPE_THICK,0.0);
|
||
}
|
||
return Acad::eInvalidInput;
|
||
}
|
||
|
||
//设置截面为管道外径和壁厚
|
||
Acad::ErrorStatus AecDbEwPipeBase::SetSection(double dD,double dt)
|
||
{
|
||
if (dD < 1.e-6 )
|
||
return Acad::eInvalidInput;
|
||
|
||
AssertWriteEnabled();
|
||
|
||
AcDbVoidPtrArray arCurPtrs,arRegnPtrs;
|
||
AcDbCircle* pCir = new AcDbCircle;
|
||
pCir->setRadius(dD * 0.5);
|
||
pCir->setNormal(AcGeVector3d::kZAxis);
|
||
arCurPtrs.append(pCir);
|
||
|
||
AcDbRegion* pRegion = NULL;
|
||
if ( Acad::eOk == AcDbRegion::createFromCurves(arCurPtrs,arRegnPtrs) )
|
||
{
|
||
pRegion = (AcDbRegion*)arRegnPtrs.first();
|
||
arRegnPtrs.removeAll();
|
||
FreeBuffer(0,arCurPtrs);
|
||
}
|
||
else
|
||
acutPrintf(_T("\n生成截面失败!(1)"));
|
||
|
||
|
||
if (dt > 1.e-3)
|
||
{
|
||
AcDbCircle* pCir2 = new AcDbCircle;
|
||
pCir2->setRadius(dD * 0.5 - dt);
|
||
pCir2->setNormal(AcGeVector3d::kZAxis);
|
||
arCurPtrs.append(pCir2);
|
||
|
||
AcDbRegion* pRegionIn = NULL;
|
||
if (Acad::eOk == AcDbRegion::createFromCurves(arCurPtrs, arRegnPtrs))
|
||
{
|
||
pRegionIn = (AcDbRegion*)arRegnPtrs.first();
|
||
if (pRegion->booleanOper(AcDb::kBoolSubtract, pRegionIn) != Acad::eOk)
|
||
{
|
||
acutPrintf(_T("\nboolean失败!(3)"));
|
||
}
|
||
}
|
||
else
|
||
{
|
||
acutPrintf(_T("\n生成截面失败!(2)"));
|
||
}
|
||
FreeBuffer(0,arCurPtrs);
|
||
}
|
||
|
||
if (m_pRegion != NULL)
|
||
DELETE_PTR(m_pRegion);
|
||
|
||
m_mapSpecXData.SetAt(KEY_SIZE1,dD);
|
||
m_mapSpecXData.SetAt(KEY_SIZE2,dD);
|
||
m_mapSpecXData.SetAt(KEY_SECSHAPE,eCircle);
|
||
m_mapSpecXData.SetAt(PIPE_THICK,dt);
|
||
|
||
m_pRegion = pRegion;
|
||
m_mapSpecXData.SetAt(KEY_SECCEN,AcGePoint3d::kOrigin);
|
||
|
||
return m_pRegion != NULL ? Acad::eOk : Acad::eInvalidInput;
|
||
}
|
||
|
||
//设置为方管 长x宽x厚 水平面为长,Z向为宽
|
||
Acad::ErrorStatus AecDbEwPipeBase::SetSection(double dL,double dW,double dt)
|
||
{
|
||
if (dL < 1.e-6 || dW < 1.e-6 )
|
||
return Acad::eInvalidInput;
|
||
|
||
AssertWriteEnabled();
|
||
|
||
AcGePoint3d ptGe[5];
|
||
AcDbVoidPtrArray arCurPtrs;
|
||
|
||
ptGe[0] = AcGePoint3d::kOrigin;
|
||
ptGe[0].x -= 0.5 * dL;
|
||
ptGe[0].y += 0.5 * dW;
|
||
|
||
ptGe[1] = ptGe[0];
|
||
ptGe[1].x += dL;
|
||
|
||
ptGe[2] = ptGe[1];
|
||
ptGe[2].y -= dW;
|
||
|
||
ptGe[3] = ptGe[0];
|
||
ptGe[3].y -= dW;
|
||
ptGe[4] = ptGe[0];
|
||
|
||
if (m_pRegion != NULL)
|
||
DELETE_PTR(m_pRegion);
|
||
|
||
m_mapSpecXData.SetAt(KEY_SIZE1,dL);
|
||
m_mapSpecXData.SetAt(KEY_SIZE2,dW);
|
||
m_mapSpecXData.SetAt(KEY_SECSHAPE,eRect);
|
||
m_mapSpecXData.SetAt(PIPE_THICK,dt);
|
||
|
||
AcDbVoidPtrArray arRegnPtrs;
|
||
AcDbLine* pLn = NULL;
|
||
for (int i = 0;i < 4;i++)
|
||
{
|
||
pLn = new AcDbLine;
|
||
pLn->setStartPoint(ptGe[i]);
|
||
pLn->setEndPoint(ptGe[i+1]);
|
||
arCurPtrs.append(pLn);
|
||
}
|
||
|
||
if ( Acad::eOk == AcDbRegion::createFromCurves(arCurPtrs,arRegnPtrs) )
|
||
{
|
||
if (!arRegnPtrs.isEmpty() )
|
||
{
|
||
m_pRegion = (AcDbRegion*)arRegnPtrs.first();
|
||
m_mapSpecXData.SetAt(KEY_SECCEN,AcGePoint3d::kOrigin);
|
||
}
|
||
}
|
||
FreeBuffer(0,arCurPtrs);
|
||
|
||
Acad::ErrorStatus es;
|
||
if (dt > 1.e-6)
|
||
{
|
||
dL -= 2.0 * dt;
|
||
dW -= 2.0 * dt;
|
||
|
||
ptGe[0] = AcGePoint3d::kOrigin;
|
||
ptGe[0].x -= 0.5 * dL;
|
||
ptGe[0].y += 0.5 * dW;
|
||
|
||
ptGe[1] = ptGe[0];
|
||
ptGe[1].x += dL;
|
||
|
||
ptGe[2] = ptGe[1];
|
||
ptGe[2].y -= dW;
|
||
|
||
ptGe[3] = ptGe[0];
|
||
ptGe[3].y -= dW;
|
||
ptGe[4] = ptGe[0];
|
||
|
||
arCurPtrs.removeAll();
|
||
for (int i = 0;i < 4;i++)
|
||
{
|
||
pLn = new AcDbLine;
|
||
pLn->setStartPoint(ptGe[i]);
|
||
pLn->setEndPoint(ptGe[i+1]);
|
||
arCurPtrs.append(pLn);
|
||
}
|
||
|
||
arRegnPtrs.removeAll();
|
||
if ( Acad::eOk == AcDbRegion::createFromCurves(arCurPtrs,arRegnPtrs) )
|
||
{
|
||
if (!arRegnPtrs.isEmpty() )
|
||
{
|
||
AcDbRegion* pRegionIn = (AcDbRegion*)arRegnPtrs.first();
|
||
if (m_pRegion != NULL && pRegionIn != NULL)
|
||
{
|
||
es = m_pRegion->booleanOper(AcDb::kBoolSubtract,pRegionIn);
|
||
if (es == Acad::eOk)
|
||
{
|
||
DELETE_PTR(pRegionIn);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
FreeBuffer(0,arCurPtrs);
|
||
}
|
||
|
||
return m_pRegion != NULL ? Acad::eOk : Acad::eInvalidInput;
|
||
}
|
||
|
||
extern AcDbRegion* CreateRetangeRegion(AcGePoint3d* pPoints,int nSize);
|
||
Acad::ErrorStatus AecDbEwPipeBase::SetSection(double dThick,double dH,double dYOff,EAlign kAlign)
|
||
{
|
||
if (dThick < 1.e-6 || dH < 1.e-6 )
|
||
return Acad::eInvalidInput;
|
||
|
||
AssertWriteEnabled();
|
||
|
||
/*
|
||
0/4 1
|
||
+-----+
|
||
| |
|
||
| |
|
||
| |
|
||
+-----+
|
||
3 2
|
||
*/
|
||
|
||
AcGePoint3d ptGe[5];
|
||
ptGe[0].set(0,0,0);
|
||
ptGe[0].y += (dYOff + 0.5 * dH);//中心
|
||
|
||
ptGe[0].x -= 0.5 * dThick;
|
||
ptGe[0].y += 0.5 * dH;
|
||
|
||
ptGe[1] = ptGe[0];
|
||
ptGe[1].x += dThick;
|
||
|
||
ptGe[2] = ptGe[1];
|
||
ptGe[2].y -= dH;
|
||
|
||
ptGe[3] = ptGe[2];
|
||
ptGe[3].x -= dThick;
|
||
ptGe[4] = ptGe[0];
|
||
|
||
//底标高基准点
|
||
AcGePoint3d ptCen;
|
||
ptCen.set(0,0,0);
|
||
|
||
switch(kAlign)
|
||
{
|
||
case kMid://居中
|
||
{
|
||
break;
|
||
}
|
||
case kLeft://左侧
|
||
{
|
||
for (int i = 0;i < 5;i++)
|
||
{
|
||
ptGe[i].x -= dThick;
|
||
}
|
||
ptCen.x -= dThick;
|
||
break;
|
||
}
|
||
case kRight:
|
||
{
|
||
for (int i = 0;i < 5;i++)
|
||
{
|
||
ptGe[i].x += dThick;
|
||
}
|
||
ptCen.x += dThick;
|
||
break;
|
||
}
|
||
default:
|
||
break;
|
||
}
|
||
|
||
AcDbRegion* pReg = CreateRetangeRegion(ptGe,5);
|
||
SetSection(pReg,ptCen);
|
||
|
||
//TEST
|
||
//AddToModelSpace(pReg);
|
||
delete pReg;
|
||
|
||
//记录底部标高数值
|
||
m_mapSpecXData.SetAt(KEY_SIZE1,dThick);
|
||
m_mapSpecXData.SetAt(KEY_SIZE2,dH);
|
||
m_mapSpecXData.SetAt(PIPE_EL,dYOff);
|
||
m_mapSpecXData.SetAt(KEY_SECSHAPE,eRect);//标准
|
||
m_mapSpecXData.SetAt(KEY_ALIGN,kAlign);
|
||
|
||
return m_pRegion != NULL ? Acad::eOk : Acad::eInvalidInput;
|
||
}
|
||
|
||
//通用截面
|
||
Acad::ErrorStatus AecDbEwPipeBase::SetSection(AcDbRegion* pReg,const AcGePoint3d& ptCen)
|
||
{
|
||
AssertWriteEnabled();
|
||
|
||
if (pReg != NULL)
|
||
{
|
||
if (m_pRegion != NULL)
|
||
DELETE_PTR(m_pRegion);
|
||
|
||
m_pRegion = (AcDbRegion*)pReg->clone();
|
||
if (m_pRegion != NULL)
|
||
{
|
||
m_mapSpecXData.SetAt(KEY_SECCEN,ptCen);
|
||
m_mapSpecXData.SetAt(KEY_SECSHAPE,eUserDef);
|
||
m_mapSpecXData.SetAt(PIPE_THICK,0.0);
|
||
return Acad::eOk;
|
||
}
|
||
}
|
||
return Acad::eOk;
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbEwPipeBase::SetSectionN(double dR, int nSides)
|
||
{
|
||
if (nSides < 3) return Acad::eInvalidInput;
|
||
|
||
AcGePoint3dArray arPts;
|
||
|
||
AcGePoint3d pt0, pt1;
|
||
pt0.set(0, 0, 0);
|
||
pt1.set(dR, 0, 0);
|
||
|
||
for (int i = 0; i < nSides; i++)
|
||
{
|
||
arPts.append(pt1);
|
||
pt1.rotateBy(2.0 * PI / nSides, AcGeVector3d::kZAxis);
|
||
}
|
||
pt1.set(dR, 0, 0);
|
||
arPts.append(pt1);
|
||
|
||
AcDbVoidPtrArray arRegnPtrs, arCurPtrs;
|
||
AcDbPolyline *pPl = FormatPolyline(arPts.asArrayPtr(), arPts.length());
|
||
if (pPl != NULL)
|
||
{
|
||
arCurPtrs.append(pPl);
|
||
AcDbCurve *pCrv = NULL;
|
||
|
||
if (m_pRegion != NULL)
|
||
DELETE_PTR(m_pRegion);
|
||
|
||
m_mapSpecXData.SetAt(KEY_X, dR);
|
||
m_mapSpecXData.SetAt(KEY_N, nSides);
|
||
m_mapSpecXData.SetAt(KEY_SECSHAPE, eNSides);
|
||
|
||
if (Acad::eOk == AcDbRegion::createFromCurves(arCurPtrs, arRegnPtrs))
|
||
{
|
||
if (!arRegnPtrs.isEmpty())
|
||
{
|
||
m_pRegion = (AcDbRegion *)arRegnPtrs.first();
|
||
m_mapSpecXData.SetAt(KEY_SECCEN, AcGePoint3d::kOrigin);
|
||
}
|
||
}
|
||
FreeBuffer(0, arCurPtrs);
|
||
}
|
||
return Acad::eOk;
|
||
}
|
||
|
||
//通用获取外径和壁厚
|
||
Acad::ErrorStatus AecDbEwPipeBase::GetODAndThick(AcGePoint2d& ptODt) const
|
||
{
|
||
assertReadEnabled();
|
||
|
||
int nShape = 0;
|
||
m_mapSpecXData.GetAt(KEY_SECSHAPE,nShape);
|
||
if (nShape == eCircle || nShape == eRect)
|
||
{
|
||
double dSize1 = 0.0,dSize2 = 0.0,dt = 0.0;
|
||
m_mapSpecXData.GetAt(KEY_SIZE1,dSize1);
|
||
m_mapSpecXData.GetAt(KEY_SIZE2,dSize2);
|
||
m_mapSpecXData.GetAt(PIPE_THICK,dt);
|
||
|
||
if (nShape == eCircle)
|
||
{
|
||
ptODt.set(dSize2,dt);
|
||
}
|
||
else
|
||
{
|
||
ptODt.set(dSize1,dt);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
double dW = 0.0,dt = 0.0;
|
||
if (m_pRegion != NULL)
|
||
{
|
||
//region水平投影放置为准
|
||
AcDbExtents ext;
|
||
m_pRegion->getGeomExtents(ext);
|
||
|
||
dW = ext.maxPoint().x - ext.minPoint().x;
|
||
GetThick(2,dt);
|
||
|
||
if (dt < 1.e-6)
|
||
{
|
||
//水平线和region求交,排序求最左侧的两点为壁厚
|
||
AcDbVoidPtrArray arCurPtrs;
|
||
m_pRegion->explode(arCurPtrs);
|
||
|
||
AcDbXline xln;
|
||
xln.setBasePoint(MidPoint(ext.maxPoint(),ext.minPoint()));
|
||
xln.setUnitDir(AcGeVector3d::kXAxis);
|
||
|
||
AcGePoint3dArray arPts;
|
||
AcDbEntity* pEnt = NULL;
|
||
for (int i = 0;i < arCurPtrs.length();i++)
|
||
{
|
||
pEnt = (AcDbEntity*)arCurPtrs.at(i);
|
||
xln.intersectWith(pEnt,AcDb::kOnBothOperands,arPts);
|
||
}
|
||
FreeBuffer(0,arCurPtrs);
|
||
|
||
AecCoverBooleanOper::SortPoints(arPts,&xln);
|
||
|
||
if (arPts.length() > 1)
|
||
{
|
||
dt = arPts.at(0).distanceTo(arPts.at(1));
|
||
}
|
||
}
|
||
ptODt.set(dW,dt);
|
||
}
|
||
}
|
||
return Acad::eOk;
|
||
}
|
||
|
||
double GetMinPointToCen(AcDbRay& rayTop,const AcDbVoidPtrArray& arCurPtrs,const AcGePoint3d& ptCen)
|
||
{
|
||
AcGePoint3d ptTmp;
|
||
AcGePoint3dArray arPts;
|
||
AcDbCurve* pCurve = NULL;
|
||
|
||
double dDist = 0.0,dMin = -1.0;
|
||
for (int i = 0;i < arCurPtrs.length();i++)
|
||
{
|
||
pCurve = (AcDbCurve*)arCurPtrs.at(i);
|
||
|
||
arPts.removeAll();
|
||
rayTop.intersectWith(pCurve,AcDb::kOnBothOperands,arPts);
|
||
|
||
for (int k = 0;k < arPts.length();k++)
|
||
{
|
||
ptTmp = arPts.at(k);
|
||
dDist = ptCen.distanceTo(ptTmp);
|
||
|
||
if (dMin < -1.e-2)
|
||
{
|
||
dMin = dDist;
|
||
}
|
||
else
|
||
{
|
||
dMin = __min(dDist,dMin);
|
||
}
|
||
}
|
||
}
|
||
return dMin;
|
||
}
|
||
|
||
double GetMaxPointToCen(AcDbRay& rayTop,const AcDbVoidPtrArray& arCurPtrs,const AcGePoint3d& ptCen)
|
||
{
|
||
AcGePoint3d ptTmp;
|
||
AcGePoint3dArray arPts;
|
||
AcDbCurve* pCurve = NULL;
|
||
AcDbEntity* pEnt = NULL;
|
||
|
||
double dDist = 0.0,dMin = -1.0;
|
||
for (int i = 0;i < arCurPtrs.length();i++)
|
||
{
|
||
pEnt = (AcDbEntity*)arCurPtrs.at(i);
|
||
if (pEnt != NULL)
|
||
{
|
||
//acutPrintf(_T("\nclass = %s"),pEnt->isA()->name());
|
||
pCurve = AcDbCurve::cast(pEnt);
|
||
if (pCurve != NULL)
|
||
{
|
||
arPts.removeAll();
|
||
pCurve->intersectWith(&rayTop,AcDb::kOnBothOperands,arPts);
|
||
|
||
for (int k = 0;k < arPts.length();k++)
|
||
{
|
||
ptTmp = arPts.at(k);
|
||
dDist = ptCen.distanceTo(ptTmp);
|
||
|
||
if (dMin < -1.e-2)
|
||
{
|
||
dMin = dDist;
|
||
}
|
||
else
|
||
{
|
||
dMin = __max(dDist,dMin);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
return dMin;
|
||
}
|
||
|
||
//获取垂直切外径和上下厚度
|
||
Acad::ErrorStatus AecDbEwPipeBase::GetODAndID(AcGePoint2d& ptrODtTop,AcGePoint2d& ptrODtBom) const
|
||
{
|
||
assertReadEnabled();
|
||
|
||
int nShape = 0;
|
||
m_mapSpecXData.GetAt(KEY_SECSHAPE,nShape);
|
||
if (nShape == eCircle || nShape == eRect)
|
||
{
|
||
double dSize1 = 0.0,dSize2 = 0.0,dt = 0.0;
|
||
m_mapSpecXData.GetAt(KEY_SIZE1,dSize1);//OD,L
|
||
m_mapSpecXData.GetAt(KEY_SIZE2,dSize2);//OD,W
|
||
m_mapSpecXData.GetAt(PIPE_THICK,dt);
|
||
|
||
if (nShape == eCircle)
|
||
{
|
||
ptrODtTop.set(0.5 * dSize1,dt);
|
||
ptrODtBom.set(0.5 * dSize1,dt);
|
||
}
|
||
else
|
||
{
|
||
ptrODtTop.set(0.5 * dSize2,dt);
|
||
ptrODtBom.set(0.5 * dSize2,dt);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
double dW = 0.0,dt = 0.0;
|
||
if (m_pRegion != NULL)//要求上下有厚度的管状界面, 不可以为U 型界面
|
||
{
|
||
AcDbExtents ext;
|
||
m_pRegion->getGeomExtents(ext);
|
||
|
||
double dOD = ext.maxPoint().y - ext.minPoint().y;
|
||
ptrODtTop.x = dOD;
|
||
ptrODtBom.x = dOD;
|
||
|
||
m_mapSpecXData.GetAt(KEY_THICKT4,ptrODtTop.y);//顶部
|
||
m_mapSpecXData.GetAt(KEY_THICKT5,ptrODtBom.y);//底部
|
||
}
|
||
}
|
||
return Acad::eOk;
|
||
}
|
||
|
||
static BOOL IsGSFMaterial(LPCTSTR pszMertial)
|
||
{
|
||
CString sMertial = pszMertial;
|
||
//目前只能按照材质判断
|
||
if (sMertial.Find(_T("衬塑")) != -1 ||
|
||
sMertial.Find(_T("SRPE")) != -1 ||
|
||
sMertial.Find(_T("HG/T 20538")) != -1)
|
||
{
|
||
return TRUE;
|
||
}
|
||
return FALSE;
|
||
}
|
||
|
||
double AecDbEwPipeBase::GetLength(bool bHasBreakOpenLen) const
|
||
{
|
||
assertReadEnabled();
|
||
|
||
double dEnd = 0.0,dLen = 0.0;
|
||
if (m_pBaseCurve != NULL)
|
||
{
|
||
m_pBaseCurve->getEndParam(dEnd);
|
||
m_pBaseCurve->getDistAtParam(dEnd,dLen);
|
||
}
|
||
|
||
CString sMat;
|
||
m_mapSpecXData.GetAt(PIPE_MATERIAL, sMat);
|
||
if (IsGSFMaterial(sMat))//衬塑管-垫片厚度(一边一半)
|
||
{
|
||
dLen -= GetGasketThick();
|
||
}
|
||
|
||
if (bHasBreakOpenLen)
|
||
{
|
||
CString sIndex;
|
||
AcGePoint3d ptGe;
|
||
for (int i = 0;i < PIPE_BROKENNUM;i++)
|
||
{
|
||
sIndex.Format(_T("BKOP%d"),i);
|
||
if (m_mapSpecXData.GetAt(sIndex,ptGe))//ptGe.x 定位 y 撕开长度,z 省略长度
|
||
{
|
||
dLen += ptGe.z;
|
||
}
|
||
}
|
||
}
|
||
return dLen;
|
||
}
|
||
|
||
double AecDbEwPipeBase::GetSectionArea(bool bHasInside) const
|
||
{
|
||
assertReadEnabled();
|
||
|
||
int nShape = 0;
|
||
double dArea = 0.0,dD = 0.0,dt = 0.0,dS2=0.0;
|
||
m_mapSpecXData.GetAt(KEY_SECSHAPE,nShape);
|
||
|
||
if (nShape == eCircle)
|
||
{
|
||
m_mapSpecXData.GetAt(KEY_SIZE1,dD);
|
||
m_mapSpecXData.GetAt(PIPE_THICK,dt);
|
||
|
||
if (bHasInside)
|
||
{
|
||
dArea = PI * 0.25 * dD * dD - PI * 0.25 * (dD - 2.0 * dt) * (dD - 2.0 * dt);
|
||
}
|
||
else
|
||
{
|
||
dArea = PI * 0.25 * dD * dD - PI * 0.25;
|
||
}
|
||
}
|
||
else if (nShape == eRect)
|
||
{
|
||
m_mapSpecXData.GetAt(KEY_SIZE1,dD);
|
||
m_mapSpecXData.GetAt(KEY_SIZE2,dS2);
|
||
m_mapSpecXData.GetAt(PIPE_THICK,dt);
|
||
|
||
if (bHasInside )
|
||
{
|
||
dArea = dD * dS2 - (dD - 2.0 *dt) * (dS2 - 2.0 * dt);
|
||
}
|
||
else
|
||
{
|
||
dArea = dD * dS2;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (m_pRegion != NULL)
|
||
{
|
||
if (bHasInside)
|
||
{
|
||
AcDbVoidPtrArray arCurPtrs,arRegPtrs;
|
||
m_pRegion->explode(arCurPtrs);
|
||
|
||
AcDbRegion::createFromCurves(arCurPtrs,arRegPtrs);
|
||
|
||
AcDbRegion* pRegAll = NULL;
|
||
AcDbRegion* pReg = NULL;
|
||
|
||
for (int i = 0;i < arRegPtrs.length();i++)
|
||
{
|
||
pReg = (AcDbRegion*)arRegPtrs.at(i);
|
||
if (pRegAll == NULL)
|
||
{
|
||
pRegAll = pReg;
|
||
}
|
||
else
|
||
{
|
||
pRegAll->booleanOper(AcDb::kBoolUnite,pReg);
|
||
}
|
||
}
|
||
if (pRegAll != NULL)
|
||
{
|
||
pRegAll->getArea(dArea);
|
||
delete pRegAll;
|
||
}
|
||
FreeBuffer(0,arCurPtrs);
|
||
}
|
||
else
|
||
{
|
||
m_pRegion->getArea(dArea);
|
||
}
|
||
}
|
||
}
|
||
return dArea;
|
||
}
|
||
|
||
double AecDbEwPipeBase::CalBigRegionArea() const
|
||
{
|
||
assertReadEnabled();
|
||
if (m_pRegion == NULL)
|
||
return 0.0;
|
||
|
||
AcDbVoidPtrArray arCurPtrs,arSubEntPtrs;
|
||
m_pRegion->explode(arCurPtrs);
|
||
|
||
AcDbEntity* pEnt = NULL;
|
||
for (int i = 0;i < arCurPtrs.length();i++)
|
||
{
|
||
pEnt = (AcDbEntity*)arCurPtrs.at(i);
|
||
if (pEnt->isKindOf(AcDbRegion::desc()))
|
||
{
|
||
pEnt->explode(arSubEntPtrs);
|
||
}
|
||
else
|
||
{
|
||
arSubEntPtrs.append(pEnt);
|
||
}
|
||
}
|
||
|
||
AcDbVoidPtrArray arRegPtrs;
|
||
AcDbRegion::createFromCurves(arSubEntPtrs,arRegPtrs);
|
||
|
||
double dAreaMax = -1.0,dArea = 0.0;
|
||
AcDbRegion* pRegionSub = NULL;
|
||
for (int i = 0;i < arRegPtrs.length();i++)
|
||
{
|
||
pRegionSub = (AcDbRegion*)arRegPtrs.at(i);
|
||
pRegionSub->getArea(dArea);
|
||
dAreaMax = __max(dAreaMax,fabs(dArea));
|
||
}
|
||
FreeBuffer(0,arSubEntPtrs);
|
||
return dAreaMax;
|
||
}
|
||
|
||
AcDbRegion* AecDbEwPipeBase::GetBigRegion() const
|
||
{
|
||
assertReadEnabled();
|
||
|
||
if (m_pRegion == NULL)
|
||
return NULL;
|
||
|
||
AcDbRegion* pRegMax = NULL;
|
||
AcDbVoidPtrArray arCurPtrs,arSubEntPtrs;
|
||
m_pRegion->explode(arCurPtrs);
|
||
|
||
AcDbEntity* pEnt = NULL;
|
||
for (int i = 0;i < arCurPtrs.length();i++)
|
||
{
|
||
pEnt = (AcDbEntity*)arCurPtrs.at(i);
|
||
if (pEnt->isKindOf(AcDbRegion::desc()))
|
||
{
|
||
pEnt->explode(arSubEntPtrs);
|
||
}
|
||
else
|
||
{
|
||
arSubEntPtrs.append(pEnt);
|
||
}
|
||
}
|
||
|
||
AcDbVoidPtrArray arRegPtrs;
|
||
AcDbRegion::createFromCurves(arSubEntPtrs,arRegPtrs);
|
||
|
||
int nPos = -1;
|
||
double dAreaMax = -1.0,dArea = 0.0;
|
||
AcDbRegion* pRegionSub = NULL;
|
||
for (int i = 0;i < arRegPtrs.length();i++)
|
||
{
|
||
pRegionSub = (AcDbRegion*)arRegPtrs.at(i);
|
||
pRegionSub->getArea(dArea);
|
||
|
||
if (dAreaMax - dArea < 1.e-2)
|
||
{
|
||
dAreaMax = dArea;
|
||
pRegMax = pRegionSub;
|
||
nPos = i;
|
||
}
|
||
}
|
||
if (nPos != -1)
|
||
{
|
||
arSubEntPtrs.removeAt(nPos);
|
||
}
|
||
FreeBuffer(0,arSubEntPtrs);
|
||
return pRegMax;
|
||
}
|
||
|
||
|
||
AcDbRegion* CreateRegion(AcGePoint3d* ptGe,int nCount)
|
||
{
|
||
AcDbVoidPtrArray arLnPtrs;
|
||
AcDbLine* pLn = NULL;
|
||
for (int i = 0;i < nCount - 1;i++)
|
||
{
|
||
pLn = new AcDbLine(ptGe[i],ptGe[i+2]);
|
||
arLnPtrs.append(pLn);
|
||
}
|
||
pLn = new AcDbLine(ptGe[0],ptGe[nCount - 1]);
|
||
arLnPtrs.append(pLn);
|
||
|
||
AcDbVoidPtrArray arRegPtrs;
|
||
AcDbRegion::createFromCurves(arLnPtrs,arRegPtrs);
|
||
FreeBuffer(0,arLnPtrs);
|
||
|
||
if (!arRegPtrs.isEmpty())
|
||
{
|
||
AcDbRegion* pReg = (AcDbRegion*)arRegPtrs.first();
|
||
return pReg;
|
||
}
|
||
return NULL;
|
||
}
|
||
|
||
AcDbRegion* AecDbEwPipeBase::GeCavityRegion() const
|
||
{
|
||
assertReadEnabled();
|
||
|
||
if (m_pRegion == NULL)
|
||
return NULL;
|
||
|
||
Acad::ErrorStatus es;
|
||
AcDbRegion* pRegMax = GetBigRegion();
|
||
if (pRegMax != NULL)
|
||
{
|
||
AcDbRegion* pSubReg = (AcDbRegion*)m_pRegion->clone();
|
||
es = pRegMax->booleanOper(AcDb::kBoolSubtract,pSubReg);
|
||
return pRegMax;
|
||
}
|
||
return NULL;
|
||
}
|
||
|
||
AcDbRegion* AecDbEwPipeBase::GetSection() const
|
||
{
|
||
assertReadEnabled();
|
||
|
||
if (m_pRegion != NULL)
|
||
{
|
||
AcDbRegion* pRegCln = (AcDbRegion*)m_pRegion->clone();
|
||
CopyObject(*m_pRegion,*pRegCln);
|
||
return pRegCln;
|
||
}
|
||
return NULL;
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbEwPipeBase::SetSectionRotation(double dAngle)
|
||
{
|
||
AssertWriteEnabled();
|
||
if (fabs(dAngle) < 1.e-10)
|
||
{
|
||
m_mapSpecXData.RemoveAt(KEY_ROTATION);
|
||
}
|
||
else
|
||
{
|
||
m_mapSpecXData.SetAt(KEY_ROTATION,dAngle);
|
||
}
|
||
return Acad::eOk;
|
||
}
|
||
|
||
double AecDbEwPipeBase::GetSectionRotation() const
|
||
{
|
||
assertReadEnabled();
|
||
double dAngle = 0.0;
|
||
m_mapSpecXData.GetAt(KEY_ROTATION,dAngle);
|
||
return dAngle;
|
||
}
|
||
|
||
|
||
Acad::ErrorStatus AecDbEwPipeBase::AddBrokenOpen(double dOffFrSta,double dSize,double dTrueSize)
|
||
{
|
||
AssertWriteEnabled();
|
||
CString sIndex;
|
||
AcGePoint3d ptGe;
|
||
ptGe.set(dOffFrSta, dSize, dTrueSize);
|
||
|
||
if (dTrueSize < -1.e-10)//虚断
|
||
{
|
||
//绘制虚断
|
||
AcGePoint3d ptSta, ptFr;
|
||
AcGePoint3d ptEnd;
|
||
m_pBaseCurve->getStartPoint(ptSta);
|
||
m_pBaseCurve->getEndPoint(ptEnd);
|
||
AcGeVector3d vtDir = ptEnd - ptSta;
|
||
vtDir.normalize();
|
||
|
||
AcGePoint3d pt1 = ptSta + vtDir * ptGe.x;
|
||
AcGePoint3d pt2 = pt1 + vtDir * ptGe.y;
|
||
|
||
BreakPos bp;
|
||
bp.ptGe = MidPoint(pt1, pt2);
|
||
bp.nType = -1;
|
||
bp.dW = 0.0;
|
||
bp.dLen = pt1.distanceTo(pt2);
|
||
m_arBreaks.append(bp);
|
||
return Acad::eOk;
|
||
}
|
||
else
|
||
{
|
||
//先去除此处可能的续断
|
||
AcGePoint3d ptSta;
|
||
AcGePoint3d ptEnd;
|
||
m_pBaseCurve->getStartPoint(ptSta);
|
||
m_pBaseCurve->getEndPoint(ptEnd);
|
||
AcGeVector3d vtDir = ptEnd - ptSta;
|
||
vtDir.normalize();
|
||
|
||
AcGePoint3d pt1 = ptSta + vtDir * ptGe.x;
|
||
AcGePoint3d pt2 = pt1 + vtDir * ptGe.y;
|
||
AcGeVector3d vt1, vt2;
|
||
for (int i = 0;i < m_arBreaks.length();i++)
|
||
{
|
||
BreakPos &bp = m_arBreaks.at(i);
|
||
|
||
vt1 = bp.ptGe - pt1;
|
||
vt2 = bp.ptGe - pt2;
|
||
|
||
if (vt1.dotProduct(vt2) < -1.e-10)//相反
|
||
{
|
||
m_arBreaks.removeAt(i);
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
for (int i = 0;i < PIPE_BROKENNUM;i++)
|
||
{
|
||
sIndex.Format(_T("BKOP%d"),i);
|
||
if (!m_mapSpecXData.GetAt(sIndex,ptGe))
|
||
{
|
||
ptGe.set(dOffFrSta,dSize,dTrueSize);
|
||
m_mapSpecXData.SetAt(sIndex,ptGe);
|
||
break;
|
||
}
|
||
}
|
||
return Acad::eOk;
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbEwPipeBase::RemoveBrokenOpen(double dOffFrSta)
|
||
{
|
||
AssertWriteEnabled();
|
||
CString sIndex;
|
||
AcGePoint3d ptGe;
|
||
|
||
for (int i = 0;i < PIPE_BROKENNUM;i++)
|
||
{
|
||
sIndex.Format(_T("BKOP%d"),i);
|
||
if (m_mapSpecXData.GetAt(sIndex,ptGe))
|
||
{
|
||
if ( (dOffFrSta - ptGe.x) > -1.e-10 && ( dOffFrSta - ptGe.x - ptGe.y) < 1.e-10)
|
||
{
|
||
m_mapSpecXData.RemoveAt(sIndex);
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
return Acad::eOk;
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbEwPipeBase::RemoveBrokenOpen(int nIndex)
|
||
{
|
||
AssertWriteEnabled();
|
||
CString sIndex;
|
||
AcGePoint3d ptGe;
|
||
|
||
if (nIndex == -1)
|
||
{
|
||
for (int i = 0;i < PIPE_BROKENNUM;i++)
|
||
{
|
||
sIndex.Format(_T("BKOP%d"),i);
|
||
m_mapSpecXData.RemoveAt(sIndex);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
sIndex.Format(_T("BKOP%d"),nIndex);
|
||
m_mapSpecXData.RemoveAt(sIndex);
|
||
}
|
||
|
||
return Acad::eOk;
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbEwPipeBase::GetBrokenOpenPnts(AcGePoint3dArray& arPnts) const
|
||
{
|
||
assertReadEnabled();
|
||
|
||
if (m_pBaseCurve == NULL)
|
||
return Acad::eOk;
|
||
|
||
AcGeVector3d vtDir;
|
||
double dSta = 0.0;
|
||
|
||
m_pBaseCurve->getStartParam(dSta);
|
||
m_pBaseCurve->getFirstDeriv(dSta,vtDir);
|
||
vtDir.normalize();
|
||
|
||
CString sIndex;
|
||
AcGePoint3d ptGeT,ptGeBK;
|
||
|
||
AcGePoint3d ptSta,ptEnd;
|
||
m_pBaseCurve->getStartPoint(ptSta);
|
||
m_pBaseCurve->getEndPoint(ptEnd);
|
||
ptSta.z = 0.0;
|
||
ptEnd.z = 0.0;
|
||
|
||
for(int i = 0;i < PIPE_BROKENNUM;i++)
|
||
{
|
||
sIndex.Format(_T("BKOP%d"),i);
|
||
if (m_mapSpecXData.GetAt(sIndex,ptGeBK))
|
||
{
|
||
ptGeT = ptSta + vtDir * ptGeBK.x;
|
||
arPnts.append(ptGeT);
|
||
|
||
ptGeT += vtDir * ptGeBK.y;
|
||
arPnts.append(ptGeT);
|
||
}
|
||
}
|
||
return Acad::eOk;
|
||
}
|
||
|
||
void AecDbEwPipeBase::SetActive(bool bActive)
|
||
{
|
||
assertWriteEnabled();
|
||
m_bActive = bActive;
|
||
if (!m_bActive)
|
||
{
|
||
m_nInfActive = -1;
|
||
}
|
||
}
|
||
|
||
LPCTSTR AecDbEwPipeBase::GetGUID() const
|
||
{
|
||
assertReadEnabled();
|
||
return m_sGUID;
|
||
}
|
||
|
||
void AecDbEwPipeBase::NewGUID()
|
||
{
|
||
assertWriteEnabled();
|
||
m_sGUID = IDCreate();
|
||
}
|
||
|
||
bool AecDbEwPipeBase::IsActive() const
|
||
{
|
||
assertReadEnabled();
|
||
return m_bActive;
|
||
}
|
||
|
||
//获取首尾切线方向[接口方向]
|
||
AcGeVector3d AecDbEwPipeBase::GetHeadDir() const
|
||
{
|
||
assertReadEnabled();
|
||
|
||
AcGeVector3d vtDir = AcGeVector3d::kXAxis;
|
||
AcDbCurve* pBase = GetBaseCurve(false);
|
||
if (pBase != NULL)
|
||
{
|
||
double dSta = 0.0;
|
||
pBase->getStartParam(dSta);
|
||
pBase->getFirstDeriv(dSta,vtDir);
|
||
delete pBase;
|
||
}
|
||
return vtDir;
|
||
}
|
||
|
||
AcGeVector3d AecDbEwPipeBase::GetTailDir() const
|
||
{
|
||
assertReadEnabled();
|
||
|
||
AcGeVector3d vtDir = AcGeVector3d::kXAxis;
|
||
AcDbCurve* pBase = GetBaseCurve(false);
|
||
if (pBase != NULL)
|
||
{
|
||
double dSta = 0.0;
|
||
pBase->getEndParam(dSta);
|
||
pBase->getFirstDeriv(dSta,vtDir);
|
||
delete pBase;
|
||
}
|
||
return vtDir;
|
||
}
|
||
|
||
DLLIMPEXP AcDbArc* FormatArc(const AcGePoint3d& ptGe1,const AcGePoint3d& ptGe2,const AcGePoint3d& ptGe3)
|
||
{
|
||
AcDbArc* pArcThis = NULL;
|
||
AcGeCircArc3d cirArc3d;
|
||
cirArc3d.set(ptGe1,ptGe2,ptGe3);//可能逆弧
|
||
|
||
AcGeVector3d vtNorm = cirArc3d.normal();
|
||
if (vtNorm.isParallelTo(AcGeVector3d::kZAxis))
|
||
{
|
||
if (!vtNorm.isCodirectionalTo(AcGeVector3d::kZAxis))
|
||
{
|
||
vtNorm.negate();//相反
|
||
}
|
||
}
|
||
AcDbCircle cir;
|
||
cir.setCenter(cirArc3d.center());
|
||
cir.setRadius(cirArc3d.radius());
|
||
cir.setNormal(vtNorm);
|
||
|
||
AcGePoint3dArray arPts;
|
||
arPts.append(ptGe1);
|
||
arPts.append(ptGe3);
|
||
|
||
AcDbVoidPtrArray arCurPtrs;
|
||
cir.getSplitCurves(arPts,arCurPtrs);
|
||
|
||
double dPara = 0.0;
|
||
AcDbCurve* pCurve = NULL;
|
||
for (int j = 0;j < arCurPtrs.length();j++)
|
||
{
|
||
pCurve = (AcDbCurve*)arCurPtrs.at(j);
|
||
if (pCurve != NULL)
|
||
{
|
||
if (Acad::eOk == pCurve->getParamAtPoint(ptGe2,dPara))//中点在圆弧上
|
||
{
|
||
AcDbArc* pArc = AcDbArc::cast(pCurve);
|
||
if (pArc != NULL)
|
||
{
|
||
pArcThis = pArc;
|
||
arCurPtrs.removeAt(j);
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
FreeBuffer(0,arCurPtrs);
|
||
return pArcThis;
|
||
}
|
||
|
||
//设置起点的标高,后续根据坡度计算高程
|
||
void AecDbEwPipeBase::SetStartElevation(float dEl)
|
||
{
|
||
AssertWriteEnabled();
|
||
|
||
if (m_pBaseCurve != NULL)
|
||
{
|
||
AecDb3dRoadAxisLine* pRoadAx = AecDb3dRoadAxisLine::cast(m_pBaseCurve);
|
||
if (pRoadAx != NULL)
|
||
{
|
||
AcGePoint3d ptSta,ptSta2;
|
||
pRoadAx->getStartPoint(ptSta);
|
||
|
||
ptSta2 = ptSta;
|
||
ptSta2.z = dEl;
|
||
|
||
AcGeVector3d vt = ptSta2 - ptSta;
|
||
AcGeMatrix3d xform;
|
||
xform.setToTranslation(vt);
|
||
pRoadAx->transformBy(xform);
|
||
|
||
return;
|
||
}
|
||
}
|
||
|
||
AcGePoint3d ptGe[3];
|
||
AcDbCurve* pBase = GetBaseCurve(false);
|
||
if (pBase != NULL)
|
||
{
|
||
AcDbLine* pLine = AcDbLine::cast(pBase);
|
||
if (pLine != NULL)
|
||
{
|
||
ptGe[0] = pLine->startPoint();
|
||
ptGe[0].z = dEl;
|
||
|
||
//修改了标高
|
||
pLine->setStartPoint(ptGe[0]);
|
||
}
|
||
|
||
AcDbArc* pArc = AcDbArc::cast(pBase);
|
||
if (pArc != NULL)
|
||
{
|
||
pArc->getStartPoint(ptGe[0]);
|
||
pArc->getEndPoint(ptGe[2]);
|
||
|
||
double dSta = 0.0,dEnd = 0.0;
|
||
pArc->getStartParam(dSta);
|
||
pArc->getEndParam(dEnd);
|
||
pArc->getPointAtParam( (dSta + dEnd) / 2.0,ptGe[1]);
|
||
|
||
ptGe[0].z = dEl;
|
||
|
||
//三点合成圆弧
|
||
AcDbArc* pArcT = FormatArc(ptGe[0],ptGe[1],ptGe[2]);
|
||
if (pArcT != NULL)
|
||
{
|
||
pArc->setStartAngle(pArcT->startAngle());
|
||
pArc->setEndAngle(pArcT->endAngle());
|
||
pArc->setCenter(pArcT->center());
|
||
pArc->setRadius(pArcT->radius());
|
||
|
||
DELETE_PTR(pArcT);
|
||
}
|
||
}
|
||
|
||
//pPl 一般指在水平面
|
||
AcDbPolyline* pPl = AcDbPolyline::cast(pBase);
|
||
if (pPl != NULL)
|
||
{
|
||
if (pPl->numVerts() > 0)
|
||
{
|
||
pPl->setElevation(dEl);
|
||
}
|
||
}
|
||
|
||
AcDb3dPolyline* p3dPl = AcDb3dPolyline::cast(pBase);
|
||
if (p3dPl != NULL)
|
||
{
|
||
p3dPl->getStartPoint(ptGe[0]);
|
||
ptGe[0].z = dEl;
|
||
|
||
AcDbObjectIterator* pIt = p3dPl->vertexIterator();
|
||
if (pIt != NULL)
|
||
{
|
||
pIt->start();
|
||
AcDbEntity* pVert = pIt->entity();
|
||
if (pVert != NULL)
|
||
{
|
||
AcDb3dPolylineVertex* pVertex = AcDb3dPolylineVertex::cast(pVert);
|
||
if (pVertex != NULL)
|
||
{
|
||
pVertex->setPosition(ptGe[0]);
|
||
}
|
||
}
|
||
DELETE_PTR(pIt);
|
||
}
|
||
}
|
||
|
||
AcDbSpline* pSp = AcDbSpline::cast(pBase);
|
||
if (pSp != NULL )
|
||
{
|
||
if (pSp->numFitPoints() > 0)
|
||
{
|
||
pSp->getFitPointAt(0,ptGe[0]);
|
||
ptGe[0].z = dEl;
|
||
pSp->setFitPointAt(0,ptGe[0]);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
float AecDbEwPipeBase::StartElevation() const
|
||
{
|
||
assertReadEnabled();
|
||
|
||
AcGePoint3d ptSta;
|
||
AcDbCurve* pBase = GetBaseCurve(false);
|
||
if (pBase != NULL)
|
||
{
|
||
pBase->getStartPoint(ptSta);
|
||
return (float)ptSta.z;
|
||
}
|
||
return 0.0f;
|
||
}
|
||
|
||
//通过末点标高计算起点标高
|
||
void AecDbEwPipeBase::SetEndElevation(float dEl)
|
||
{
|
||
AcGePoint3d ptGe[3];
|
||
AcDbCurve* pBase = GetBaseCurve(false);
|
||
if (pBase != NULL)
|
||
{
|
||
AcDbLine* pLine = AcDbLine::cast(pBase);
|
||
if (pLine != NULL)
|
||
{
|
||
ptGe[0] = pLine->endPoint();
|
||
ptGe[0].z = dEl;
|
||
|
||
//修改了标高
|
||
pLine->setEndPoint(ptGe[0]);
|
||
}
|
||
|
||
AcDbArc* pArc = AcDbArc::cast(pBase);
|
||
if (pArc != NULL)
|
||
{
|
||
pArc->getStartPoint(ptGe[0]);
|
||
pArc->getEndPoint(ptGe[2]);
|
||
|
||
double dSta = 0.0,dEnd = 0.0;
|
||
pArc->getStartParam(dSta);
|
||
pArc->getEndParam(dEnd);
|
||
pArc->getPointAtParam( (dSta + dEnd) / 2.0,ptGe[1]);
|
||
|
||
ptGe[2].z = dEl;
|
||
//三点合成圆弧
|
||
AcDbArc* pArcT = FormatArc(ptGe[0],ptGe[1],ptGe[2]);
|
||
if (pArcT != NULL)
|
||
{
|
||
pArc->setStartAngle(pArcT->startAngle());
|
||
pArc->setEndAngle(pArcT->endAngle());
|
||
pArc->setCenter(pArcT->center());
|
||
pArc->setRadius(pArcT->radius());
|
||
|
||
DELETE_PTR(pArcT);
|
||
}
|
||
}
|
||
|
||
//pPl 一般指在水平面
|
||
AcDbPolyline* pPl = AcDbPolyline::cast(pBase);
|
||
if (pPl != NULL)
|
||
{
|
||
if (pPl->numVerts() > 0)
|
||
{
|
||
pPl->setElevation(dEl);
|
||
}
|
||
}
|
||
|
||
AcDb3dPolyline* p3dPl = AcDb3dPolyline::cast(pBase);
|
||
if (p3dPl != NULL)
|
||
{
|
||
p3dPl->getEndPoint(ptGe[2]);
|
||
ptGe[2].z = dEl;
|
||
|
||
AcDbObjectIterator* pIt = p3dPl->vertexIterator();
|
||
if (pIt != NULL)
|
||
{
|
||
pIt->start(true);
|
||
AcDbEntity* pVert = pIt->entity();
|
||
if (pVert != NULL)
|
||
{
|
||
AcDb3dPolylineVertex* pVertex = AcDb3dPolylineVertex::cast(pVert);
|
||
if (pVertex != NULL)
|
||
{
|
||
pVertex->setPosition(ptGe[2]);
|
||
}
|
||
}
|
||
DELETE_PTR(pIt);
|
||
}
|
||
}
|
||
|
||
AcDbSpline* pSp = AcDbSpline::cast(pBase);
|
||
if (pSp != NULL )
|
||
{
|
||
if (pSp->numFitPoints() > 0)
|
||
{
|
||
pSp->getFitPointAt(pSp->numFitPoints() - 1,ptGe[0]);
|
||
ptGe[0].z = dEl;
|
||
pSp->setFitPointAt(pSp->numFitPoints() - 1,ptGe[0]);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
float AecDbEwPipeBase::EndElevation() const
|
||
{
|
||
assertReadEnabled();
|
||
|
||
AcGePoint3d ptEnd;
|
||
AcDbCurve* pBase = GetBaseCurve(false);
|
||
if (pBase != NULL)
|
||
{
|
||
pBase->getEndPoint(ptEnd);
|
||
return (float)ptEnd.z;
|
||
}
|
||
|
||
return 0.0f;
|
||
}
|
||
|
||
//获取位置标高0 中心 1顶部 2内底部 3 外底部 4内顶部
|
||
float AecDbEwPipeBase::GetElevation(int nPos) const
|
||
{
|
||
assertReadEnabled();
|
||
return 0.0;
|
||
}
|
||
|
||
void AecDbEwPipeBase::SetVertexElevation(int nGripIndex,float dEl)
|
||
{
|
||
AssertWriteEnabled();
|
||
}
|
||
|
||
float AecDbEwPipeBase::GetVertexElevation(int nGripIndex) const
|
||
{
|
||
assertReadEnabled();
|
||
|
||
return 0.0f;
|
||
}
|
||
|
||
//设置坡度,只有直线,3dpoly 有坡度意义
|
||
bool AecDbEwPipeBase::SetGradientAt(int nPos, double dGradient)
|
||
{
|
||
assertWriteEnabled();
|
||
|
||
if (m_pBaseCurve != NULL)
|
||
{
|
||
AcDbLine* pLn = AcDbLine::cast(m_pBaseCurve);
|
||
if (pLn != NULL)
|
||
{
|
||
if (nPos == 0)
|
||
{
|
||
AcGePoint3d ptSta,ptEnd;
|
||
pLn->getStartPoint(ptSta);
|
||
pLn->getEndPoint(ptEnd);
|
||
|
||
double dXL = fabs(ptEnd.x - ptSta.x);
|
||
//dg = (ptend.z - ptsta.z) / dXL * 100;
|
||
ptEnd.z = ptSta.z + dGradient * 0.01 * dXL;
|
||
pLn->setEndPoint(ptEnd);
|
||
return true;
|
||
}
|
||
}
|
||
|
||
AcDb3dPolyline* pPl3d = AcDb3dPolyline::cast(m_pBaseCurve);
|
||
if (pPl3d != NULL)
|
||
{
|
||
|
||
}
|
||
}
|
||
return false;
|
||
}
|
||
|
||
double AecDbEwPipeBase::GetGradientAt(int nPos) const
|
||
{
|
||
assertReadEnabled();
|
||
|
||
return 0.0;
|
||
}
|
||
|
||
//专业数据 和绘制设置
|
||
AecDbObjXDataMap* AecDbEwPipeBase::GetSpecialtyData(AcDb::OpenMode bMode)
|
||
{
|
||
switch(bMode)
|
||
{
|
||
case AcDb::kForRead:
|
||
{
|
||
assertReadEnabled();
|
||
break;
|
||
}
|
||
case AcDb::kForWrite:
|
||
{
|
||
if (!isWriteEnabled())
|
||
{
|
||
upgradeOpen();
|
||
}
|
||
assertWriteEnabled();
|
||
break;
|
||
}
|
||
case AcDb::kForNotify:
|
||
{
|
||
if (!isWriteEnabled())
|
||
{
|
||
upgradeOpen();
|
||
}
|
||
}
|
||
default:
|
||
break;
|
||
}
|
||
return &m_mapSpecXData;
|
||
}
|
||
|
||
const AecDbObjXDataMap* AecDbEwPipeBase::GetSpecialtyData() const
|
||
{
|
||
assertReadEnabled();
|
||
return &m_mapSpecXData;
|
||
}
|
||
|
||
//获取二维视图显示的图形
|
||
int AecDbEwPipeBase::GetDraw2dables(Adesk::UInt16 nDrawStyle, AcDbVoidPtrArray& arEntPtrs) const
|
||
{
|
||
assertReadEnabled();
|
||
|
||
AecDbObjXDataMap xData;
|
||
|
||
AcDbEntity* pEntCln = NULL,*pEnt = NULL;
|
||
const AcDbVoidPtrArray &ar2D = Get2DBuffer();
|
||
for (int i = 0;i < ar2D.length();i++)
|
||
{
|
||
pEnt = (AcDbEntity*)ar2D.at(i);
|
||
pEntCln = (AcDbEntity*)pEnt->clone();
|
||
|
||
if (xData.Read(pEnt,BIMDATA_APP))
|
||
{
|
||
xData.SetAt(KEY_ID,m_sGUID);
|
||
xData.Write(pEntCln,BIMDATA_APP);
|
||
}
|
||
arEntPtrs.append(pEntCln);
|
||
}
|
||
return arEntPtrs.length();
|
||
}
|
||
|
||
//获取三维显示图形
|
||
int AecDbEwPipeBase::GetDraw3dables(AcDbVoidPtrArray& arEntPtrs,bool bWriteBimInfo) const
|
||
{
|
||
assertReadEnabled();
|
||
|
||
AcDbEntity* pEnt = NULL,*pEntClone = NULL;
|
||
if (!Has3DBuffer())
|
||
{
|
||
AcGiViewDraw dc(NULL, NULL);
|
||
Draw3d(dc);
|
||
}
|
||
const AcDbVoidPtrArray &ar3D = Get3DBuffer();
|
||
for (int i = 0;i < ar3D.length();i++)
|
||
{
|
||
pEnt = (AcDbEntity*)ar3D.at(i);
|
||
pEntClone = (AcDbEntity*)pEnt->clone();//clone 后图形不显示
|
||
if (pEntClone != NULL)
|
||
{
|
||
//使得图形刷新一下
|
||
pEntClone->transformBy(AcGeMatrix3d::kIdentity);
|
||
|
||
int nColor = 0;
|
||
if ( m_mapSpecXData.GetAt(_T("COLOR"),nColor) )
|
||
{
|
||
pEntClone->setColorIndex(nColor);
|
||
}
|
||
else
|
||
{
|
||
pEntClone->setColorIndex(colorIndex());
|
||
}
|
||
pEntClone->setLayer(layerId());
|
||
if (bWriteBimInfo)
|
||
{
|
||
m_mapSpecXData.Write(pEntClone,BIMDATA_APP);
|
||
}
|
||
arEntPtrs.append(pEntClone);
|
||
}
|
||
}
|
||
return arEntPtrs.length();
|
||
}
|
||
|
||
//整体体积
|
||
double AecDbEwPipeBase::GetVolume(bool bIsBody) const
|
||
{
|
||
assertReadEnabled();
|
||
|
||
double dVol = 0.0;
|
||
if (bIsBody)//本体体积
|
||
{
|
||
if (m_pRegion != NULL && m_pBaseCurve != NULL)
|
||
{
|
||
double dArea = 0.0;
|
||
m_pRegion->getArea(dArea);
|
||
|
||
double dEnd = 0.0,dLen = 0.0;
|
||
m_pBaseCurve->getEndParam(dEnd);
|
||
m_pBaseCurve->getDistAtParam(dEnd,dLen);
|
||
|
||
dVol = dArea * dLen;
|
||
}
|
||
}
|
||
else//总挖体积
|
||
{
|
||
return AecDbCurveBase::GetVolume(bIsBody);
|
||
}
|
||
return dVol;
|
||
}
|
||
|
||
//腔体体积 nRoom = -1 全部
|
||
double AecDbEwPipeBase::GetCavityVolume(int nRoom) const
|
||
{
|
||
assertReadEnabled();
|
||
|
||
double dVol = 0.0;
|
||
//m_pRegion始终在水平面
|
||
if (m_pRegion != NULL && m_pBaseCurve != NULL)
|
||
{
|
||
//默认一次砸碎为curve曲线集
|
||
AcDbVoidPtrArray arCurPtrs;
|
||
m_pRegion->explode(arCurPtrs);
|
||
|
||
AcDbVoidPtrArray arRegPtrs;
|
||
AcDbRegion::createFromCurves(arCurPtrs,arRegPtrs);
|
||
|
||
FreeBuffer(0,arCurPtrs);
|
||
|
||
double dArea = -1.0,dArea1 = 0.0;
|
||
AcDbRegion* pReg = NULL;
|
||
for (int i = 0;i < arRegPtrs.length();i++)
|
||
{
|
||
pReg = (AcDbRegion*)arRegPtrs.at(i);
|
||
pReg->getArea(dArea1);
|
||
|
||
if (dArea < 0.0)
|
||
{
|
||
dArea = dArea1;
|
||
}
|
||
else
|
||
{
|
||
dArea = __min(dArea,dArea1);//取最小,默认一个腔体loop
|
||
}
|
||
}
|
||
|
||
double dEnd = 0.0,dLen = 0.0;
|
||
m_pBaseCurve->getEndParam(dEnd);
|
||
m_pBaseCurve->getDistAtParam(dEnd,dLen);
|
||
|
||
FreeBuffer(0,arRegPtrs);
|
||
dVol = dArea * dLen;
|
||
}
|
||
|
||
return dVol;
|
||
}
|
||
|
||
//外表面积
|
||
double AecDbEwPipeBase::GetOutSideArea() const
|
||
{
|
||
assertReadEnabled();
|
||
|
||
double dArea = 0.0;
|
||
//m_pRegion始终在水平面
|
||
if (m_pRegion != NULL && m_pBaseCurve != NULL)
|
||
{
|
||
//默认一次砸碎为curve曲线集
|
||
AcDbVoidPtrArray arCurPtrs;
|
||
m_pRegion->explode(arCurPtrs);
|
||
|
||
AcDbVoidPtrArray arRegPtrs;
|
||
AcDbRegion::createFromCurves(arCurPtrs,arRegPtrs);
|
||
|
||
FreeBuffer(0,arCurPtrs);
|
||
|
||
double dL = -1.0,dL1 = 0.0;
|
||
AcDbRegion* pReg = NULL;
|
||
for (int i = 0;i < arRegPtrs.length();i++)
|
||
{
|
||
pReg = (AcDbRegion*)arRegPtrs.at(i);
|
||
pReg->getPerimeter(dL1);
|
||
|
||
if (dL < 0.0)
|
||
{
|
||
dL = dL1;
|
||
}
|
||
else
|
||
{
|
||
dL = __max(dL,dL1);//取最最大,默认一个腔体loop
|
||
}
|
||
}
|
||
|
||
double dEnd = 0.0,dLen = 0.0;
|
||
m_pBaseCurve->getEndParam(dEnd);
|
||
m_pBaseCurve->getDistAtParam(dEnd,dLen);
|
||
FreeBuffer(0,arRegPtrs);
|
||
dArea = dL * dLen;
|
||
}
|
||
return dArea;
|
||
}
|
||
|
||
//内表面积
|
||
double AecDbEwPipeBase::GetInSideArea() const
|
||
{
|
||
assertReadEnabled();
|
||
|
||
|
||
double dArea = 0.0;
|
||
//m_pRegion始终在水平面
|
||
if (m_pRegion != NULL && m_pBaseCurve != NULL)
|
||
{
|
||
//默认一次砸碎为curve曲线集
|
||
AcDbVoidPtrArray arCurPtrs;
|
||
m_pRegion->explode(arCurPtrs);
|
||
|
||
AcDbVoidPtrArray arRegPtrs;
|
||
AcDbRegion::createFromCurves(arCurPtrs,arRegPtrs);
|
||
|
||
if (arRegPtrs.length() == 1)
|
||
{
|
||
FreeBuffer(0,arRegPtrs);
|
||
return 0.0;
|
||
}
|
||
|
||
FreeBuffer(0,arCurPtrs);
|
||
|
||
double dL = -1.0,dL1 = 0.0;
|
||
AcDbRegion* pReg = NULL;
|
||
for (int i = 0;i < arRegPtrs.length();i++)
|
||
{
|
||
pReg = (AcDbRegion*)arRegPtrs.at(i);
|
||
pReg->getPerimeter(dL1);
|
||
|
||
if (dL < 0.0)
|
||
{
|
||
dL = dL1;
|
||
}
|
||
else
|
||
{
|
||
dL = __min(dL,dL1);//取最最小,默认一个腔体loop
|
||
}
|
||
}
|
||
|
||
double dEnd = 0.0,dLen = 0.0;
|
||
m_pBaseCurve->getEndParam(dEnd);
|
||
m_pBaseCurve->getDistAtParam(dEnd,dLen);
|
||
|
||
FreeBuffer(0,arRegPtrs);
|
||
dArea = dL * dLen;
|
||
}
|
||
return dArea;
|
||
}
|
||
|
||
//壁厚 0 上壁厚 1下壁厚 2水平壁厚
|
||
bool AecDbEwPipeBase::GetThick(int nPos,double& dThick) const
|
||
{
|
||
assertReadEnabled();
|
||
|
||
switch(nPos)
|
||
{
|
||
case 0://上壁厚
|
||
{
|
||
m_mapSpecXData.GetAt(KEY_THICKT4,dThick);
|
||
return true;
|
||
break;
|
||
}
|
||
case 1://1下壁厚
|
||
{
|
||
m_mapSpecXData.GetAt(KEY_THICKT5,dThick);
|
||
return true;
|
||
break;
|
||
}
|
||
case 2://2水平壁厚
|
||
{
|
||
m_mapSpecXData.GetAt(KEY_THICKT1,dThick);
|
||
return true;
|
||
break;
|
||
}
|
||
case 4://2水平壁厚
|
||
{
|
||
m_mapSpecXData.GetAt(KEY_THICKT1,dThick);
|
||
return true;
|
||
break;
|
||
}
|
||
default:
|
||
{
|
||
if (m_mapSpecXData.GetAt(PIPE_THICK,dThick))
|
||
{
|
||
return true;
|
||
}
|
||
}
|
||
break;
|
||
}
|
||
return false;
|
||
}
|
||
|
||
int AecDbEwPipeBase::GetActiveInf() const
|
||
{
|
||
assertReadEnabled();
|
||
return m_nInfActive;
|
||
}
|
||
|
||
void AecDbEwPipeBase::SetActiveInf(int nIndex)
|
||
{
|
||
assertWriteEnabled();
|
||
m_nInfActive = nIndex;
|
||
}
|
||
|
||
void AecDbEwPipeBase::LockInf(int nInf)
|
||
{
|
||
bool bUpgraded = false;
|
||
if (!isWriteEnabled())
|
||
{
|
||
upgradeOpen();
|
||
bUpgraded = true;
|
||
}
|
||
|
||
CString sKey;
|
||
if (nInf == -1)
|
||
{
|
||
int nCnt = GetInterfaceCount();
|
||
for (int k = 0;k < nCnt;k++)
|
||
{
|
||
sKey.Format(_T("LK_%d"),k);
|
||
m_mapSpecXData.RemoveAt(sKey);
|
||
}
|
||
|
||
if (bUpgraded)
|
||
{
|
||
downgradeOpen();
|
||
}
|
||
return;
|
||
}
|
||
|
||
sKey.Format(_T("LK_%d"),nInf);
|
||
m_mapSpecXData.SetAt(sKey,nInf);
|
||
|
||
if (bUpgraded)
|
||
{
|
||
downgradeOpen();
|
||
}
|
||
}
|
||
|
||
bool AecDbEwPipeBase::TransformAssocInf(int nInf,const AcGeMatrix3d& xform)
|
||
{
|
||
return false;
|
||
}
|
||
|
||
double AecDbEwPipeBase::GetGasketThick() const
|
||
{
|
||
CString sMat;
|
||
m_mapSpecXData.GetAt(PIPE_MATERIAL, sMat);
|
||
|
||
BOOL bIsGSF = IsGSFMaterial(sMat);
|
||
if (!bIsGSF)
|
||
return 0;//非衬塑管不考虑
|
||
|
||
CString sGastInf;
|
||
m_mapSpecXData.GetAt(PIPE_GASKET, sGastInf);
|
||
|
||
CStringArray arGastInfs;
|
||
SplitStrintToArray(sGastInf, arGastInfs, _T('/'));
|
||
|
||
if (arGastInfs.GetSize() >= 3)
|
||
{
|
||
double dUnits = 1.0;//默认毫米
|
||
if (CoreTools::IsMetersUnit())
|
||
dUnits *= .001;
|
||
|
||
return _ttof(arGastInfs.GetAt(2)) * dUnits;
|
||
}
|
||
return 0.0;
|
||
}
|
||
|
||
bool AecDbEwPipeBase::GetInterface(AcArray<AecInterface>& arInfs) const
|
||
{
|
||
assertReadEnabled();
|
||
|
||
if (m_pBaseCurve != NULL)
|
||
{
|
||
AcGePoint3d ptSta,ptEnd;
|
||
m_pBaseCurve->getStartPoint(ptSta);
|
||
m_pBaseCurve->getEndPoint(ptEnd);
|
||
|
||
AcGeVector3d vtSta,vtEnd;
|
||
m_pBaseCurve->getFirstDeriv(ptSta,vtSta);
|
||
vtSta.negate();//向外
|
||
|
||
m_pBaseCurve->getFirstDeriv(ptEnd,vtEnd);
|
||
vtSta.normalize(); vtEnd.normalize();
|
||
|
||
AecInterface inf;
|
||
|
||
inf.idOwner = objectId();
|
||
m_mapSpecXData.GetAt(KEY_SIZE1,inf.dSize1);
|
||
m_mapSpecXData.GetAt(KEY_SIZE2,inf.dSize2);
|
||
|
||
//重定向DN,当外径或内径画时,端口插阀门可查
|
||
m_mapSpecXData.GetAt(PIPE_DN, inf.dSize1);
|
||
m_mapSpecXData.GetAt(PIPE_DN, inf.dSize2);
|
||
|
||
int nConnectType = 0;
|
||
m_mapSpecXData.GetAt(PIPE_CONNECT, nConnectType);
|
||
inf.nConnectType = (short)nConnectType;
|
||
|
||
inf.ptPos = ptSta;
|
||
inf.vtDir = vtSta;
|
||
inf.nLevel = 0;
|
||
inf.dGasket = GetGasketThick();
|
||
arInfs.append(inf);
|
||
|
||
inf.ptPos = ptEnd;
|
||
inf.vtDir = vtEnd;
|
||
inf.nLevel = 1;
|
||
inf.dGasket = GetGasketThick();
|
||
arInfs.append(inf);
|
||
|
||
for (int i = 0;i < m_arUserInfs.length();i++)
|
||
{
|
||
const AecUserInterface &infu = m_arUserInfs.at(i);
|
||
if (infu.nPoints == 2)
|
||
{
|
||
inf.ptPos = infu.ptGe[0];
|
||
inf.dSize1 = infu.ptGe[0].distanceTo(infu.ptGe[1]);
|
||
inf.nSectType = 1;
|
||
inf.vtDir = infu.vtDir;
|
||
inf.ptPos += infu.vtDir;
|
||
inf.nLevel = i + 2;
|
||
inf.dGasket = GetGasketThick();
|
||
arInfs.append(inf);
|
||
}
|
||
else if (infu.nPoints == 4)//目前只考虑矩形
|
||
{
|
||
inf.ptPos = MidPoint(infu.ptGe[0], infu.ptGe[2]);
|
||
inf.dSize1 = infu.ptGe[0].distanceTo(infu.ptGe[1]);
|
||
inf.dSize2 = infu.ptGe[1].distanceTo(infu.ptGe[2]);
|
||
inf.nSectType = 0;
|
||
inf.vtDir = infu.vtDir;
|
||
inf.ptPos += infu.vtDir;
|
||
inf.nLevel = i + 2;
|
||
inf.dGasket = GetGasketThick();
|
||
arInfs.append(inf);
|
||
}
|
||
}
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbEwPipeBase::TransformBy(const AcGeMatrix3d xform)
|
||
{
|
||
AssertWriteEnabled();
|
||
if (m_pBaseCurve != NULL)
|
||
{
|
||
m_pBaseCurve->transformBy(xform);
|
||
}
|
||
/*if (m_pRegion != NULL)
|
||
{
|
||
m_pRegion->transformBy(xform);
|
||
}*/
|
||
return Acad::eOk;
|
||
}
|
||
|
||
int AecDbEwPipeBase::GetInterfaceCount() const
|
||
{
|
||
assertReadEnabled();
|
||
|
||
AcArray<AecInterface> arInfs;
|
||
GetInterface(arInfs);
|
||
|
||
return arInfs.length();
|
||
}
|
||
|
||
bool AecDbEwPipeBase::GetInterface(int nIndex,AecInterface& inf) const
|
||
{
|
||
assertReadEnabled();
|
||
|
||
AcArray<AecInterface> arInfs;
|
||
GetInterface(arInfs);
|
||
|
||
if (nIndex > -1 && nIndex < arInfs.length())
|
||
{
|
||
inf = arInfs.at(nIndex);
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
|
||
void AecDbEwPipeBase::SetSingleLayer(const AcDbObjectId& idLayer)
|
||
{
|
||
AssertWriteEnabled();
|
||
m_idSingleLayer = idLayer;
|
||
}
|
||
|
||
AcDbObjectId AecDbEwPipeBase::GetSingleLayer() const
|
||
{
|
||
assertReadEnabled();
|
||
return m_idSingleLayer;
|
||
}
|
||
|
||
void AecDbEwPipeBase::SetSingleLineType(const AcDbObjectId& idLt)
|
||
{
|
||
AssertWriteEnabled();
|
||
m_idSingleLnType = idLt;
|
||
}
|
||
|
||
AcDbObjectId AecDbEwPipeBase::GetSingleLineType() const
|
||
{
|
||
assertReadEnabled();
|
||
return m_idSingleLnType;
|
||
}
|
||
|
||
void AecDbEwPipeBase::SetDoubleLayer(const AcDbObjectId& idLayer)
|
||
{
|
||
AssertWriteEnabled();
|
||
m_idDoubleLayer = idLayer;
|
||
}
|
||
|
||
AcDbObjectId AecDbEwPipeBase::GetDoubleLayer() const
|
||
{
|
||
assertReadEnabled();
|
||
return m_idDoubleLayer;
|
||
}
|
||
|
||
void AecDbEwPipeBase::SetDoubleLineType(const AcDbObjectId& idLt)
|
||
{
|
||
AssertWriteEnabled();
|
||
m_idDoubleLnType = idLt;
|
||
}
|
||
|
||
AcDbObjectId AecDbEwPipeBase::GetDoubleLineType() const
|
||
{
|
||
assertReadEnabled();
|
||
return m_idDoubleLnType;
|
||
}
|
||
|
||
void transfromPointEx(AcGePoint3d& ptOn,const AcGeVector3d &vtNormal,const AcGePoint3d &ptOnPlan)
|
||
{
|
||
AcGePlane plan;
|
||
plan.set(ptOnPlan, vtNormal);
|
||
|
||
AcGePoint3d ptOn2;
|
||
AcGeMatrix3d xform;
|
||
xform.setToPlaneToWorld(plan);
|
||
|
||
// 把region转到此面上
|
||
ptOn.transformBy(xform);
|
||
}
|
||
|
||
void transfromPoint(AcGePoint3d& ptOn,const AcGePoint3d& ptOnRegion,const AcGeVector3d &vtNormal,const AcGePoint3d &ptOnPlan)
|
||
{
|
||
AcGePlane plan;
|
||
plan.set(ptOnPlan, vtNormal);
|
||
AcGePoint3d pt0, pt1, pt2;
|
||
plan.get(pt0, pt1, pt2);
|
||
|
||
AcGeMatrix3d xform;
|
||
xform.setToPlaneToWorld(plan);
|
||
|
||
// 把region转到此面上
|
||
ptOn.transformBy(xform);
|
||
|
||
// 把 region 上的点也转到面上
|
||
AcGePoint3d pt(ptOnRegion);
|
||
pt.transformBy(xform);
|
||
|
||
// 再把region在面上平移
|
||
xform.setToIdentity();
|
||
xform.setToTranslation(ptOnPlan - pt);
|
||
ptOn.transformBy(xform);
|
||
}
|
||
|
||
void transfromPoint(AcGePoint3d& ptOn,const AcGeVector3d &vtNormal,const AcGePoint3d &ptOnPlan)
|
||
{
|
||
AcGePlane plan;
|
||
plan.set(ptOnPlan, vtNormal);
|
||
AcGePoint3d pt0, pt1, pt2;
|
||
plan.get(pt0, pt1, pt2);
|
||
|
||
AcGeMatrix3d xform;
|
||
xform.setToPlaneToWorld(plan);
|
||
|
||
// 把region转到此面上
|
||
ptOn.transformBy(xform);
|
||
|
||
// 把 region 上的点也转到面上
|
||
AcGePoint3d pt(ptOn);
|
||
pt.transformBy(xform);
|
||
|
||
// 再把region在面上平移
|
||
xform.setToIdentity();
|
||
xform.setToTranslation(ptOnPlan - pt);
|
||
ptOn.transformBy(xform);
|
||
}
|
||
|
||
void transfromCurve(AcDbCurve* pCurve,const AcGePoint3d& ptOnRegion,const AcGeVector3d &vtNormal,const AcGePoint3d &ptOnPlan)
|
||
{
|
||
AcGePlane plan;
|
||
plan.set(ptOnPlan, vtNormal);
|
||
AcGePoint3d pt0, pt1, pt2;
|
||
plan.get(pt0, pt1, pt2);
|
||
|
||
AcGeMatrix3d xform;
|
||
xform.setToPlaneToWorld(plan);
|
||
|
||
// 把region转到此面上
|
||
pCurve->transformBy(xform);
|
||
|
||
// 把 region 上的点也转到面上
|
||
AcGePoint3d pt(ptOnRegion);
|
||
pt.transformBy(xform);
|
||
|
||
// 再把region在面上平移
|
||
xform.setToIdentity();
|
||
xform.setToTranslation(ptOnPlan - pt);
|
||
pCurve->transformBy(xform);
|
||
}
|
||
|
||
AcDbRegion* CreatePolygonRegionOnly(AcGePoint3d* pPoints,int nSize)
|
||
{
|
||
AcDbVoidPtrArray arCurPtrs;
|
||
for (int i = 0;i < nSize-1;i++)//5
|
||
{
|
||
if (pPoints[i].distanceTo(pPoints[i+1]) > 1.e-6)
|
||
{
|
||
AcDbLine* pLine = new AcDbLine(pPoints[i],pPoints[i+1]);
|
||
arCurPtrs.append(pLine);
|
||
|
||
//TEST
|
||
//AcDbLine* pCLn = (AcDbLine*)pLine->clone();
|
||
//pCLn->setColorIndex(1);
|
||
//AddToModelSpace(pCLn);
|
||
}
|
||
}
|
||
|
||
AcDbVoidPtrArray arRegPtrs;
|
||
AcDbRegion* pReg = NULL;
|
||
Acad::ErrorStatus es = Acad::eOk;
|
||
if ( Acad::eOk == ( es = AcDbRegion::createFromCurves(arCurPtrs,arRegPtrs) ) )
|
||
{
|
||
//FREE
|
||
AcDbEntity* pEnt = NULL;
|
||
for (int i = 0;i < arCurPtrs.length();i++)
|
||
{
|
||
pEnt = (AcDbEntity*)arCurPtrs.at(i);
|
||
DELETE_PTR(pEnt);
|
||
}
|
||
return (AcDbRegion*)arRegPtrs.first();
|
||
}
|
||
|
||
//error FREE
|
||
FreeBuffer(0,arCurPtrs);
|
||
return NULL;
|
||
}
|
||
|
||
//符号法
|
||
bool AecDbEwPipeBase::GetSectionDraw(AcGePlane& plan,const AcGeVector3d& vtTo,AcDbVoidPtrArray& arRegionPtrs) const
|
||
{
|
||
return false;
|
||
}
|
||
|
||
void DeepExplode(AcDbEntity* pEnt,AcDbVoidPtrArray& arCurPtrs,AcDbVoidPtrArray& arSubRegPtrs)
|
||
{
|
||
AcDbVoidPtrArray arPtrs;
|
||
pEnt->explode(arPtrs);
|
||
|
||
AcDbEntity* pEntT = NULL;
|
||
AcDbCurve* pCurve = NULL;
|
||
AcDbCurve* pCurT = NULL;
|
||
|
||
for (int i = 0;i < arPtrs.length();i++)
|
||
{
|
||
pEntT = (AcDbEntity*)arPtrs.at(i);
|
||
|
||
AcDbRegion* pReg = AcDbRegion::cast(pEntT);
|
||
if (pReg != NULL)
|
||
{
|
||
arSubRegPtrs.append(pReg);
|
||
}
|
||
else
|
||
{
|
||
pCurve = AcDbCurve::cast(pEntT);
|
||
if (pCurve != NULL)
|
||
{
|
||
arCurPtrs.append(pCurve);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
void DeepSpline(AcDbVoidPtrArray& arCurPtrs)
|
||
{
|
||
AcDbVoidPtrArray arLnPtrs;
|
||
|
||
AcDbSpline* pSp = NULL;
|
||
for (int i = 0;i < arCurPtrs.length();i++)
|
||
{
|
||
AcDbEntity* pEnt = (AcDbEntity*)arCurPtrs.at(i);
|
||
if (pEnt != NULL)
|
||
{
|
||
pSp = AcDbSpline::cast(pEnt);
|
||
if (pSp != NULL)
|
||
{
|
||
AcGePoint3d ptS,ptE;
|
||
for (int j = 0;j < pSp->numControlPoints() - 1;j++)
|
||
{
|
||
pSp->getControlPointAt(j,ptS);
|
||
pSp->getControlPointAt(j+1,ptE);
|
||
|
||
AcDbLine* pLn = new AcDbLine(ptS,ptE);
|
||
arLnPtrs.append(pLn);
|
||
}
|
||
arCurPtrs.removeAt(i);
|
||
i -= 1;
|
||
delete pSp;
|
||
}
|
||
}
|
||
}
|
||
|
||
if (!arLnPtrs.isEmpty())
|
||
{
|
||
arCurPtrs.append(arLnPtrs);
|
||
}
|
||
}
|
||
|
||
DLLIMPEXP void RegionHatch(AcDbRegion* pRegionT,AcDbVoidPtrArray& arHatchPtrs,LPCTSTR pszPattern)
|
||
{
|
||
AcDbHatch* pHatch = NULL;
|
||
if (pRegionT != NULL && pszPattern != NULL)
|
||
{
|
||
AcDbVoidPtrArray arSubRegPtrs;
|
||
AcDbVoidPtrArray arCurPtrs,arReslt;
|
||
|
||
arCurPtrs.removeAll();
|
||
arReslt.removeAll();
|
||
DeepExplode(pRegionT,arCurPtrs,arSubRegPtrs);
|
||
|
||
DeepSpline(arCurPtrs);
|
||
|
||
AcDbCurve* pCurve = KTCADUtilityEx::ConvertBoundCurve(arCurPtrs,arReslt);
|
||
AcDbPolyline* pPl = AcDbPolyline::cast(pCurve);
|
||
if (pPl != NULL)
|
||
{
|
||
PipeHatch sHatch;
|
||
_tcscpy(sHatch.szPattern,pszPattern);
|
||
sHatch.dAngle = 0.0;
|
||
sHatch.dScale = 100.0;
|
||
|
||
AcGiDraw::Vertex3d vt;
|
||
AcGiDraw::AcGiPoly2d polyReg;
|
||
for (int i = 0;i < pPl->numVerts();i++)
|
||
{
|
||
pPl->getPointAt(i,vt.pt);
|
||
pPl->getBulgeAt(i,vt.dBulge);
|
||
polyReg.append(vt);
|
||
}
|
||
|
||
if (!polyReg.isEmpty())
|
||
{
|
||
AcGiViewDraw dc(NULL,NULL);
|
||
pHatch = dc.DrawHatch(polyReg,sHatch.szPattern,sHatch.dScale,sHatch.dAngle);
|
||
|
||
if (pHatch != NULL)
|
||
{
|
||
arHatchPtrs.append(pHatch);
|
||
}
|
||
}
|
||
delete pPl;
|
||
}
|
||
|
||
if (!arSubRegPtrs.isEmpty())
|
||
{
|
||
AcDbRegion* pRegion = NULL;
|
||
for (int i = 0;i < arSubRegPtrs.length();i++)
|
||
{
|
||
pRegion = (AcDbRegion*)arSubRegPtrs.at(i);
|
||
RegionHatch(pRegion,arHatchPtrs,pszPattern);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
DLLIMPEXP void PolylineHatch(AcDbPolyline *pPl, AcDbVoidPtrArray &arHatchPtrs, LPCTSTR pszPattern,const AcGeVector3d& vtZ)
|
||
{
|
||
AcDbHatch *pHatch = NULL;
|
||
AcDbSolid *pSolid = NULL;
|
||
|
||
if (pszPattern != NULL)
|
||
{
|
||
Acad::ErrorStatus es;
|
||
if (pPl != NULL)
|
||
{
|
||
PipeHatch sHatch;
|
||
_tcscpy(sHatch.szPattern, pszPattern);
|
||
sHatch.dAngle = 0.0;
|
||
sHatch.dScale = 100.0;
|
||
|
||
AcGiDraw::Vertex3d vt;
|
||
AcGiDraw::AcGiPoly2d polyReg;
|
||
for (int i = 0; i < pPl->numVerts(); i++)
|
||
{
|
||
pPl->getPointAt(i, vt.pt);
|
||
pPl->getBulgeAt(i, vt.dBulge);
|
||
polyReg.append(vt);
|
||
}
|
||
|
||
if (!polyReg.isEmpty())
|
||
{
|
||
AcGiViewDraw dc(NULL, NULL);
|
||
pHatch = dc.DrawHatch(polyReg, sHatch.szPattern, sHatch.dScale, sHatch.dAngle);
|
||
|
||
if (pHatch != NULL)
|
||
{
|
||
arHatchPtrs.append(pHatch);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
DLLIMPEXP void FillSolid(AcGePoint3d* pptGe,int nCount, AcDbVoidPtrArray &arHatchPtrs)
|
||
{
|
||
if (nCount > 2)
|
||
{
|
||
AcGeVector3d vt1 = pptGe[1] - pptGe[0];
|
||
AcGeVector3d vt2 = pptGe[2] - pptGe[1];
|
||
AcGeVector3d vtZ = vt1.crossProduct(vt2);
|
||
|
||
Acad::ErrorStatus es;
|
||
AcDbSolid *pSolid = new AcDbSolid;
|
||
pSolid->setNormal(vtZ);
|
||
|
||
for(int i = 0;i < nCount;i++)
|
||
{
|
||
es = pSolid->setPointAt(i, pptGe[i]);
|
||
}
|
||
arHatchPtrs.append(pSolid);
|
||
}
|
||
}
|
||
|
||
void AecDbEwPipeBase::SetSectionLayer(int nIndexFr,AcDbVoidPtrArray& arRegionPtrs,const AcDbObjectId& idLayer) const
|
||
{
|
||
if (idLayer.isValid())
|
||
{
|
||
AcDbObjectId idT;
|
||
AcDbEntity* pEnt = NULL;
|
||
for (int i = nIndexFr;i < arRegionPtrs.length();i++)
|
||
{
|
||
pEnt = (AcDbEntity*)arRegionPtrs.at(i);
|
||
if (pEnt != NULL)
|
||
{
|
||
idT = pEnt->layerId();
|
||
if (!idT.isValid())
|
||
{
|
||
pEnt->setLayer(idLayer);
|
||
pEnt->setColorIndex(kColorByLayer);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
//切割法
|
||
int AecDbEwPipeBase::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 = hasHatch(this, bHatch);
|
||
|
||
//如果仅仅是切
|
||
AcDb3dSolid* pDraw3dSolid = NULL;
|
||
if (vtTo.isZeroLength())
|
||
{
|
||
if (Get3DBuffer().length() == 0)
|
||
{
|
||
AcGiViewDraw dc(NULL,NULL);
|
||
Draw3d(dc);
|
||
}
|
||
|
||
pDraw3dSolid = GetCreatPipe3dSolid();
|
||
if (pDraw3dSolid != NULL)
|
||
{
|
||
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());
|
||
arRegionPtrs.append(pRegionT);
|
||
|
||
//填充
|
||
AcDbHatch* pHatch = NULL;
|
||
AcDbVoidPtrArray arHatchPtrs;
|
||
|
||
if (bHatch)
|
||
{
|
||
CString sPattern = _T("AR-CONC");
|
||
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);
|
||
|
||
AcDbLine* pLnCen = NULL;
|
||
for (int ii = 0;ii < arCenLnPtrs.length();ii++)
|
||
{
|
||
pLnCen = (AcDbLine*)arCenLnPtrs.at(ii);
|
||
pLnCen->transformBy(xformPlanToWorld);
|
||
pLnCen->setLayer(KTSetting::InitLayer(_T("LAY_CL"),true));
|
||
pLnCen->setLinetype(KTSetting::InitLineStyle(_T("CENTER2")));
|
||
arRegionPtrs.append(pLnCen);
|
||
}
|
||
|
||
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;
|
||
}
|
||
return arRegionPtrs.length();
|
||
}
|
||
|
||
AcGePlane plan;
|
||
AcGeVector3d vtU = ptTo - ptFr;
|
||
|
||
Acad::ErrorStatus es = Acad::eOk;
|
||
plan.set(ptFr,vtU,vtViewDir);
|
||
|
||
if (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 = GetCreatPipe3dSolid();
|
||
if (pDraw3dSolid == NULL)
|
||
{
|
||
SetSectionLayer(nIndexFr,arRegionPtrs,layerId());
|
||
return 0;
|
||
}
|
||
|
||
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;
|
||
}
|
||
}
|
||
|
||
AcDb3dSolid* pSolidBoxCln = (AcDb3dSolid*)pSolidBox->clone();
|
||
AcDb3dSolid* pSolidCln = (AcDb3dSolid*)pDraw3dSolid->clone();
|
||
pSolidCln->booleanOper(AcDb::kBoolIntersect,pSolidBox);
|
||
pSolidCln->setRecordHistory(true);
|
||
AcDbVoidPtrArray arRegPtrs;
|
||
|
||
//如果plan和 pSolidCln 相交
|
||
//根据材质填充,如果切到的墙体
|
||
AcDbRegion* pRegionSec = NULL;
|
||
pSolidCln->getSection(plan,pRegionSec);
|
||
if (pRegionSec != NULL)
|
||
{
|
||
pRegionSec->transformBy(xform);
|
||
arRegPtrs.append(pRegionSec);
|
||
|
||
AcDbHatch* pHatch = NULL;
|
||
AcDbVoidPtrArray arHatchPtrs;
|
||
|
||
if (bHatch)
|
||
{
|
||
CString sPattern;
|
||
GetSectionHatchPattern(sPattern);
|
||
RegionHatch(pRegionSec,arHatchPtrs,sPattern);
|
||
if (!arHatchPtrs.isEmpty())
|
||
{
|
||
arRegionPtrs.append(arHatchPtrs);
|
||
}
|
||
}
|
||
|
||
|
||
AcDbVoidPtrArray arSolidPtrs,arCenLnPtrs;
|
||
GetAllHolesSolid(arSolidPtrs,arCenLnPtrs,xform);
|
||
|
||
AcDbLine* pLnCen = NULL;
|
||
for (int ii = 0;ii < arCenLnPtrs.length();ii++)
|
||
{
|
||
pLnCen = (AcDbLine*)arCenLnPtrs.at(ii);
|
||
pLnCen->transformBy(xform);
|
||
pLnCen->setLayer(KTSetting::InitLayer(_T("LAY_CL"),true));
|
||
pLnCen->setLinetype(KTSetting::InitLineStyle(_T("CENTER2")));
|
||
arRegPtrs.append(pLnCen);
|
||
}
|
||
|
||
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)
|
||
{
|
||
pRegionSec = NULL;
|
||
pSolidT->getSection(plan,pRegionSec);
|
||
|
||
if (pRegionSec != NULL)
|
||
{
|
||
pRegionSec->transformBy(xform);
|
||
|
||
pRegionSec->setLayer(layerId());
|
||
arRegPtrs.append(pRegionSec);
|
||
}
|
||
delete pSolidT;
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
OrthoProjected3DSolid(pSolidCln,plan,xform,arRegPtrs);
|
||
}
|
||
|
||
if (rb.resval.rint == 1358)//特定情况下
|
||
{
|
||
//TEST
|
||
pSolidCln->setColorIndex(kRed);
|
||
AddToModelSpace(pSolidCln);
|
||
}
|
||
else
|
||
{
|
||
DELETE_PTR(pSolidCln);
|
||
}
|
||
DELETE_PTR(pRegionT);
|
||
DELETE_PTR(pSolidBox);
|
||
|
||
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 AecDbEwPipeBase::SetSection2(const double & r, const double & t,bool bCenOrg/* = false*/)
|
||
{
|
||
AssertWriteEnabled();
|
||
/*
|
||
| | O | |
|
||
\ \ / /
|
||
\ \ / /
|
||
\ \ / /
|
||
\ \_pt1_/ /
|
||
\______/
|
||
pt0
|
||
O - 原点
|
||
O->pt1 r 内径
|
||
pt0->pt1 厚度
|
||
*/
|
||
AcGeVector3d vtX(AcGeVector3d::kXAxis);
|
||
AcGeVector3d vtY(AcGeVector3d::kYAxis);
|
||
|
||
AcGePoint3d ptCen = AcGePoint3d::kOrigin;
|
||
if (bCenOrg)
|
||
{
|
||
ptCen -= vtY * 0.5 * (r + t);
|
||
}
|
||
|
||
AcGePoint3d ptO(ptCen);
|
||
|
||
AcDbPolyline pl;
|
||
pl.addVertexAt(0, (ptO - vtX * (r + t)).convert2d(AcGePlane::kXYPlane), 1);
|
||
pl.addVertexAt(1, (ptO + vtX * (r + t)).convert2d(AcGePlane::kXYPlane));
|
||
pl.addVertexAt(3, (ptO + vtX * r).convert2d(AcGePlane::kXYPlane), -1);
|
||
pl.addVertexAt(2, (ptO - vtX * r).convert2d(AcGePlane::kXYPlane));
|
||
pl.setClosed(true);
|
||
return SetSection(&pl, AcGePoint3d::kOrigin);
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbEwPipeBase::SetSection1(const double & w, const double & h, const double & t,bool bCenOrg/* = false*/)
|
||
{
|
||
AssertWriteEnabled();
|
||
/*
|
||
pt7 _ pt6 pt3 _ pt2
|
||
| | | |
|
||
| | | |
|
||
| |pt5 pt4| |
|
||
| |__________| |
|
||
|______________|
|
||
pt0 O pt1
|
||
O - 原点
|
||
pt0->pt1 w
|
||
pt1->pt2 h
|
||
pt2->pt3 t
|
||
*/
|
||
|
||
AcGePoint3d pt0, pt1, pt2, pt3, pt4, pt5, pt6, pt7;
|
||
|
||
AcGeVector3d vtX(AcGeVector3d::kXAxis);
|
||
AcGeVector3d vtY(AcGeVector3d::kYAxis);
|
||
|
||
AcGePoint3d ptOrg = AcGePoint3d::kOrigin;
|
||
if (bCenOrg)
|
||
{
|
||
ptOrg -= vtY * 0.5 * h;
|
||
}
|
||
|
||
pt0 = ptOrg - vtX * (.5 * w);
|
||
pt1 = pt0 + vtX * w;
|
||
pt2 = pt1 + vtY * h;
|
||
pt3 = pt2 - vtX * t;
|
||
pt4 = pt3 - vtY * (h - t);
|
||
pt5 = pt4 - vtX * (w - 2 * t);
|
||
pt6 = pt5 + vtY * (h - t);
|
||
pt7 = pt6 - vtX * t;
|
||
|
||
AcDbPolyline pl;
|
||
pl.addVertexAt(0, pt0.convert2d(AcGePlane::kXYPlane));
|
||
pl.addVertexAt(1, pt1.convert2d(AcGePlane::kXYPlane));
|
||
pl.addVertexAt(2, pt2.convert2d(AcGePlane::kXYPlane));
|
||
pl.addVertexAt(3, pt3.convert2d(AcGePlane::kXYPlane));
|
||
pl.addVertexAt(4, pt4.convert2d(AcGePlane::kXYPlane));
|
||
pl.addVertexAt(5, pt5.convert2d(AcGePlane::kXYPlane));
|
||
pl.addVertexAt(6, pt6.convert2d(AcGePlane::kXYPlane));
|
||
pl.addVertexAt(7, pt7.convert2d(AcGePlane::kXYPlane));
|
||
pl.setClosed(true);
|
||
|
||
return SetSection(&pl, AcGePoint3d::kOrigin);
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbEwPipeBase::SetSection3(double dL,double dt)
|
||
{
|
||
AssertWriteEnabled();
|
||
|
||
AcGePoint3d ptGe[7];
|
||
|
||
ptGe[0].set(0,0,0);
|
||
ptGe[0].x -= dL;
|
||
|
||
ptGe[1].set(0,0,0);
|
||
|
||
ptGe[2] = ptGe[1];
|
||
ptGe[2].y -= dL;
|
||
|
||
ptGe[3] = ptGe[2];
|
||
ptGe[3].x -= dt;
|
||
|
||
ptGe[4] = ptGe[1];
|
||
ptGe[4].x -= dt * 1.414213562373095;
|
||
ptGe[4].y -= dt * 1.414213562373095;
|
||
|
||
ptGe[5] = ptGe[0];
|
||
ptGe[5].y -= dt;
|
||
ptGe[6] = ptGe[0];
|
||
|
||
//调整为中心
|
||
for (int i = 0;i < 7;i++)
|
||
{
|
||
ptGe[i].x += 0.5 * dL;
|
||
}
|
||
|
||
if (m_pRegion != NULL)
|
||
DELETE_PTR(m_pRegion);
|
||
|
||
m_mapSpecXData.SetAt(KEY_SIZE1,dL);
|
||
m_mapSpecXData.SetAt(KEY_SECSHAPE,eEquilTri);
|
||
m_mapSpecXData.SetAt(PIPE_THICK,dt);
|
||
|
||
AcDbVoidPtrArray arRegnPtrs,arCurPtrs;
|
||
AcDbLine* pLn = NULL;
|
||
for (int i = 0;i < 6;i++)
|
||
{
|
||
pLn = new AcDbLine;
|
||
pLn->setStartPoint(ptGe[i]);
|
||
pLn->setEndPoint(ptGe[i+1]);
|
||
arCurPtrs.append(pLn);
|
||
}
|
||
|
||
if ( Acad::eOk == AcDbRegion::createFromCurves(arCurPtrs,arRegnPtrs) )
|
||
{
|
||
if (!arRegnPtrs.isEmpty() )
|
||
{
|
||
m_pRegion = (AcDbRegion*)arRegnPtrs.first();
|
||
m_mapSpecXData.SetAt(KEY_SECCEN,AcGePoint3d::kOrigin);
|
||
}
|
||
}
|
||
FreeBuffer(0,arCurPtrs);
|
||
|
||
return Acad::eOk;
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbEwPipeBase::SetSection3(double dLx,double dLy,double dt)
|
||
{
|
||
AssertWriteEnabled();
|
||
|
||
AcGePoint3d ptGe[7];
|
||
|
||
ptGe[0].set(0,0,0);
|
||
|
||
ptGe[1] = ptGe[0];
|
||
ptGe[1].x += dLx;
|
||
|
||
ptGe[2] = ptGe[0];
|
||
ptGe[2].y += dLy;
|
||
|
||
AcDbVoidPtrArray arRegnPtrs,arCurPtrs;
|
||
AcDbPolyline* pPl = FormatPolyline(ptGe,3);
|
||
if (pPl != NULL)
|
||
{
|
||
arCurPtrs.append(pPl);
|
||
AcDbCurve* pCrv = NULL;
|
||
|
||
if (dt > 1.e-6 && dt < __min(0.5 *dLx,0.5 *dLy))
|
||
{
|
||
pCrv = GetMinOffsetCurve(pPl,dt);
|
||
if (pCrv != NULL)
|
||
{
|
||
arCurPtrs.append(pCrv);
|
||
}
|
||
}
|
||
|
||
if (m_pRegion != NULL)
|
||
DELETE_PTR(m_pRegion);
|
||
|
||
m_mapSpecXData.SetAt(KEY_X,dLx);
|
||
m_mapSpecXData.SetAt(KEY_Y,dLy);
|
||
m_mapSpecXData.SetAt(KEY_SECSHAPE,eEquilTri);
|
||
m_mapSpecXData.SetAt(PIPE_THICK,dt);
|
||
|
||
if ( Acad::eOk == AcDbRegion::createFromCurves(arCurPtrs,arRegnPtrs) )
|
||
{
|
||
if (!arRegnPtrs.isEmpty() )
|
||
{
|
||
m_pRegion = (AcDbRegion*)arRegnPtrs.first();
|
||
m_mapSpecXData.SetAt(KEY_SECCEN,AcGePoint3d::kOrigin);
|
||
}
|
||
}
|
||
FreeBuffer(0,arCurPtrs);
|
||
}
|
||
return Acad::eOk;
|
||
}
|
||
|
||
void AecDbEwPipeBase::SetDashLayer(const AcDbObjectId& idLayer)
|
||
{
|
||
AssertWriteEnabled();
|
||
m_idDashLayer = idLayer;
|
||
}
|
||
|
||
AcDbObjectId AecDbEwPipeBase::GetDashLayer() const
|
||
{
|
||
assertReadEnabled();
|
||
return m_idDashLayer;
|
||
}
|
||
|
||
void AecDbEwPipeBase::SetCenterLayer(const AcDbObjectId& idLayer)
|
||
{
|
||
AssertWriteEnabled();
|
||
m_idCenterLayer = idLayer;
|
||
}
|
||
|
||
AcDbObjectId AecDbEwPipeBase::GetCenterLayer() const
|
||
{
|
||
assertReadEnabled();
|
||
return m_idCenterLayer;
|
||
}
|
||
|
||
SHJson::WValue& AecDbEwPipeBase::ToJson(bool bExprotGeo) const
|
||
{
|
||
using namespace SHJson;
|
||
|
||
assertReadEnabled();
|
||
|
||
WValue &v = AecDbCurveBase::ToJson(bExprotGeo);
|
||
|
||
addMember(v, _T("__sGUID__"), m_sGUID);
|
||
|
||
AcDbCurve *pBaseCurve(GetBaseCurve());
|
||
if (pBaseCurve && bExprotGeo)
|
||
{
|
||
addMember(v, _T("__path__"), GEO2JSON::path(*pBaseCurve).ToJson());
|
||
|
||
AcDbRegion *pReg(GetSection());
|
||
if (pReg)
|
||
{
|
||
addMember(v, _T("__section__"), GEO2JSON::region(*pReg).ToJson());
|
||
AcGePoint3d ptCen;
|
||
m_mapSpecXData.GetAt(KEY_SECCEN, ptCen);
|
||
|
||
AcGePoint3d ptStart(AcGePoint3d::kOrigin);
|
||
pBaseCurve->getStartPoint(ptStart);
|
||
AcGePoint3d ptEnd;
|
||
pBaseCurve->getEndPoint(ptEnd);
|
||
|
||
AcGeVector3d vtNormal(AcGeVector3d::kIdentity);
|
||
pBaseCurve->getFirstDeriv(ptStart, vtNormal);
|
||
|
||
GiDrawUtility::transfromRegion(pReg, ptCen, vtNormal, ptStart);
|
||
addMember(v, _T("__section2__"), GEO2JSON::region(*pReg).ToJson());
|
||
DELETE_PTR(pReg);
|
||
}
|
||
DELETE_PTR(pBaseCurve);
|
||
}
|
||
return v;
|
||
}
|
||
|
||
bool AecDbEwPipeBase::ByJson(const SHJson::WValue &v)
|
||
{
|
||
AssertWriteEnabled();
|
||
if (!AecDbCurveBase::ByJson(v)) return false;
|
||
|
||
AcGePoint3d ptCen;
|
||
m_mapSpecXData.GetAt(KEY_SECCEN, ptCen);
|
||
|
||
MCIt itPath = v.FindMember(_T("__path__"));
|
||
MCIt itReg = v.FindMember(_T("__section__"));
|
||
if (itPath != v.MemberEnd() && itReg != v.MemberEnd())
|
||
{
|
||
GEO2JSON::path pa;
|
||
pa.ByJson(itPath->value);
|
||
AcDbCurve *pCurve = pa.asDbCurve();
|
||
if (pCurve)
|
||
{
|
||
SetBaseCurve(pCurve);
|
||
DELETE_PTR(pCurve);
|
||
}
|
||
|
||
GEO2JSON::region reg;
|
||
reg.ByJson(itReg->value);
|
||
AcDbRegion *pReg = reg.asDbRegion();
|
||
if (pReg)
|
||
{
|
||
SetSection(pReg, ptCen);
|
||
DELETE_PTR(pReg);
|
||
}
|
||
|
||
return true;
|
||
}
|
||
|
||
return false;
|
||
}
|
||
|
||
#include "AecDbMultiPartEntity.h"
|
||
#include "AecDbWall.h"
|
||
#include "AecDbBeam.h"
|
||
#include "AecDbSlab.h"
|
||
#include "AecDbColumn.h"
|
||
bool AecDbEwPipeBase::hasHatch(const AcDbEntity *pEnt, const int &var)
|
||
{
|
||
AecDbXWall *pWall = AecDbXWall::cast(pEnt);
|
||
AecDbBeam *pBeam = AecDbBeam::cast(pEnt);
|
||
AecDbXSlab *pSlab = AecDbXSlab::cast(pEnt);
|
||
AecDbColumn *pColumn = AecDbColumn::cast(pEnt);
|
||
AecDbMultiPartEntity *pMulti = AecDbMultiPartEntity::cast(pEnt);
|
||
|
||
if (pWall)
|
||
{
|
||
if ((var & 0x1) != 0) return true;
|
||
}
|
||
|
||
if (pBeam)
|
||
{
|
||
if ((var & 0x2) != 0) return true;
|
||
}
|
||
|
||
if (pSlab)
|
||
{
|
||
if ((var & 0x4) != 0) return true;
|
||
}
|
||
|
||
if (pColumn)
|
||
{
|
||
if ((var & 0x8) != 0) return true;
|
||
}
|
||
|
||
if (pMulti)
|
||
{
|
||
if ((var & 0x10) != 0) return true;
|
||
}
|
||
|
||
return false;
|
||
}
|