882 lines
20 KiB
C++
882 lines
20 KiB
C++
#include "stdafx.h"
|
|
#include "AecDbXBG.h"
|
|
#include "AcGiViewDraw.h"
|
|
#include "CoreTools.h"
|
|
|
|
namespace
|
|
{
|
|
AcDbArc* createArcBy3Pt(const AcGePoint3d &pt1
|
|
, const AcGePoint3d &pt
|
|
, const AcGePoint3d &pt2)
|
|
{
|
|
|
|
AcGeCircArc3d geArc(pt1, pt, pt2);
|
|
return CoreTools::geArc2DbArc(geArc);
|
|
}
|
|
|
|
AcDbPolyline* curves2Polyline(AcDbVoidPtrArray &ar)
|
|
{
|
|
std::vector<AcDbPolyline*> polys;
|
|
CoreTools::MakePolyline(ar, polys);
|
|
deleteArrayVoidPtrs< AcDbPolyline>(ar);
|
|
if (polys.empty()) return NULL;
|
|
AcDbPolyline *pPoly = (AcDbPolyline*)(polys[0]->clone());
|
|
deleteContainerOfStd(polys);
|
|
return pPoly;
|
|
}
|
|
|
|
AcDbPolyline* makeBaseCurve(const int &nType
|
|
, const AcGePoint3d &Pos
|
|
, const double &L
|
|
, const double &W
|
|
, const double &S)
|
|
{
|
|
AcGeVector3d X(AcGeVector3d::kXAxis), Z(AcGeVector3d::kZAxis), Y(AcGeVector3d::kYAxis);
|
|
X.normalize();
|
|
Y.normalize();
|
|
Z.normalize();
|
|
|
|
AcGePoint3d ptLB(Pos);
|
|
ptLB -= X * L * .5;
|
|
ptLB -= Y * W * .5;
|
|
|
|
AcDbVoidPtrArray ar;
|
|
if (nType == 0) // 斜板管
|
|
{
|
|
AcGePoint3d pt(ptLB);
|
|
// 六边形 边长l0,三点对角线长l3, 四点对角线长l4;
|
|
double r(S);
|
|
double l0 = 2 * (r / tan(CoreTools::A2R(60.)));
|
|
double l3 = 2 * (l0 * sin(CoreTools::A2R(60.)));
|
|
double l4 = 2 * (r / sin(CoreTools::A2R(60.)));
|
|
|
|
//pt += X * l3 * .5;
|
|
AcGePoint3d ptOld(pt);
|
|
double segLen(l4 + l0);
|
|
int count(int((W + l0) / segLen));
|
|
int n((W + l0) / (l4 + l0));
|
|
double dLen = W - (n * l4) - (n - 1) * l0;
|
|
if (UP_ZERO(dLen))
|
|
{
|
|
AcGePoint3d pt1(pt), pt2(pt + Y * dLen * .5);
|
|
ar.append(new AcDbLine(pt1, pt2));
|
|
pt1 = pt2 + Y * ((n * l4) + (n - 1) * l0);
|
|
pt2 = pt1 + Y * dLen * .5;
|
|
ar.append(new AcDbLine(pt1, pt2));
|
|
pt += Y * dLen * .5;
|
|
}
|
|
|
|
AcGeVector3d vt60(Y), vt30(X);
|
|
vt60.rotateBy(CoreTools::A2R(60), Z);
|
|
vt30.rotateBy(CoreTools::A2R(30), Z);
|
|
for (int i = 0; i < n; ++i)
|
|
{
|
|
AcGePoint3d pt1(pt), pt2(pt + vt60 * l0);
|
|
ar.append(new AcDbLine(pt1, pt2));
|
|
|
|
pt1 = pt2;
|
|
pt2 = pt1 + Y * l0;
|
|
ar.append(new AcDbLine(pt1, pt2));
|
|
|
|
pt1 = pt2;
|
|
pt2 = pt1 + vt30 * l0;
|
|
ar.append(new AcDbLine(pt1, pt2));
|
|
|
|
if (i < n - 1)
|
|
{
|
|
pt1 = pt2;
|
|
pt2 = pt1 + Y * l0;
|
|
ar.append(new AcDbLine(pt1, pt2));
|
|
}
|
|
|
|
pt += Y * segLen;
|
|
}
|
|
}
|
|
else if (nType == 1) // 平行板
|
|
{
|
|
ar.append(new AcDbLine(ptLB, ptLB + Y * W));
|
|
}
|
|
else // 波形板
|
|
{
|
|
// 先生成一条基础线,沿Y走向
|
|
double r(S * .5), sp(S);
|
|
AcGePoint3d pt(ptLB);
|
|
AcGePoint3d ptOld(pt);
|
|
|
|
int i = 0;
|
|
while (sp <= W)
|
|
{
|
|
AcDbArc *pArc(NULL);
|
|
|
|
AcGePoint3d pt1(pt);
|
|
AcGePoint3d pt2(pt1 + Y * r);
|
|
AcGePoint3d pt3(pt1 + Y * 2 * r);
|
|
|
|
|
|
if (i % 2)
|
|
{
|
|
pt2 += X * r;
|
|
pArc = createArcBy3Pt(pt1, pt2, pt3);
|
|
pArc->setColorIndex(1);
|
|
}
|
|
else
|
|
{
|
|
pt2 -= X * r;
|
|
pArc = createArcBy3Pt(pt3, pt2, pt1);
|
|
pArc->setColorIndex(2);
|
|
}
|
|
|
|
ar.append(pArc);
|
|
|
|
pt += Y * r * 2;
|
|
sp += 2 * r;
|
|
++i;
|
|
}
|
|
|
|
// 剩余长度,用直线补上,补在起始位置
|
|
double dLen = W - int(W / (2 * r)) * 2 * r;
|
|
|
|
if (UP_ZERO(dLen))
|
|
{
|
|
ar.insertAt(0, new AcDbLine(pt, pt + Y * dLen * .5));
|
|
|
|
// 全部arc向Y方向 dLen
|
|
AcGeMatrix3d mat;
|
|
mat.setToTranslation(Y * dLen * .5);
|
|
for (int i = 0; i < ar.length(); ++i)
|
|
{
|
|
AcDbEntity *pEnt((AcDbEntity *)ar[i]);
|
|
pEnt->transformBy(mat);
|
|
}
|
|
|
|
ptOld.transformBy(mat);
|
|
ar.append(new AcDbLine(ptOld, ptOld - Y * dLen * .5));
|
|
}
|
|
|
|
}
|
|
|
|
AcDbPolyline *pPoly = curves2Polyline(ar);
|
|
return pPoly;
|
|
}
|
|
|
|
AcDbRegion* makeCutRegion(AcDbPolyline *pPoly)
|
|
{
|
|
if (!pPoly) return NULL;
|
|
|
|
if (pPoly->numVerts() < 3) return NULL;
|
|
|
|
if (!pPoly->isClosed())
|
|
pPoly->setClosed(true);
|
|
|
|
AcDbRegion *pReg = CoreTools::createRegion(pPoly);
|
|
if (!pReg) return NULL;
|
|
|
|
AcDbExtents ext;
|
|
pPoly->getGeomExtents(ext);
|
|
AcGePoint3d ptMax(ext.maxPoint()), ptMin(ext.minPoint());
|
|
double dY(ptMax.y - ptMin.y);
|
|
|
|
AcDbRegion *pRegMax(NULL);
|
|
{
|
|
AcGePoint3d pt0(ptMin)
|
|
, pt1(ptMin + AcGeVector3d::kYAxis * dY)
|
|
, pt2(ptMax)
|
|
, pt3(ptMax - AcGeVector3d::kYAxis * dY);
|
|
|
|
AcDbVoidPtrArray ar;
|
|
ar.append(new AcDbLine(pt0, pt1));
|
|
ar.append(new AcDbLine(pt1, pt2));
|
|
ar.append(new AcDbLine(pt2, pt3));
|
|
ar.append(new AcDbLine(pt3, pt0));
|
|
AcDbPolyline *pPoly = curves2Polyline(ar);
|
|
if (!pPoly)
|
|
{
|
|
DELETE_PTR(pReg);
|
|
return NULL;
|
|
}
|
|
pRegMax = CoreTools::createRegion(pPoly);
|
|
DELETE_PTR(pPoly);
|
|
}
|
|
|
|
if (!pRegMax)
|
|
{
|
|
DELETE_PTR(pReg);
|
|
return NULL;
|
|
}
|
|
|
|
if (pRegMax->booleanOper(AcDb::kBoolSubtract, pReg) == Acad::eOk)
|
|
{
|
|
DELETE_PTR(pReg);
|
|
return pRegMax;
|
|
}
|
|
|
|
DELETE_PTR(pReg);
|
|
return NULL;
|
|
}
|
|
|
|
AcDbRegion* makeMainRegion(int nType
|
|
, AcDbPolyline *pPoly
|
|
, const double &D
|
|
, const double &T)
|
|
{
|
|
|
|
if (!pPoly) return NULL;
|
|
|
|
AcGeVector3d X(AcGeVector3d::kXAxis), Z(AcGeVector3d::kZAxis), Y(AcGeVector3d::kYAxis);
|
|
|
|
AcDbExtents ext;
|
|
pPoly->getGeomExtents(ext);
|
|
AcGePoint3d ptMax(ext.maxPoint()), ptMin(ext.minPoint());
|
|
AcGePoint3d Pos(CoreTools::MidPt(ptMax, ptMin));
|
|
double W(ptMax.y - ptMin.y), L(ptMax.x - ptMin.x);
|
|
|
|
AcDbPolyline *pBase(makeBaseCurve(nType, Pos, L, W, D));
|
|
if (!pBase) return NULL;
|
|
|
|
if (nType == 0)
|
|
{
|
|
double R(D);
|
|
|
|
AcGePoint3d ptT(Pos + Y * .5 * W);
|
|
ptT -= X * .5 * L;
|
|
AcGePoint3d ptB(Pos - Y * .5 * W);
|
|
ptB -= X * .5 * L;
|
|
|
|
// 六边形 边长l0,三点对角线长l3, 四点对角线长l4;
|
|
double r(R);
|
|
double l0 = 2 * (r / tan(CoreTools::A2R(60.)));
|
|
double l3 = 2 * (l0 * sin(CoreTools::A2R(60.)));
|
|
double l4 = 2 * (r / sin(CoreTools::A2R(60.)));
|
|
|
|
// 先向X方向镜像出一个
|
|
AcDbPolyline *pBase2 = (AcDbPolyline*)pBase->clone();
|
|
AcGeMatrix3d mat;
|
|
mat.setToRotation(-PI, Y, ptB);
|
|
pBase2->transformBy(mat);
|
|
|
|
mat.setToTranslation(X * 3 * T);
|
|
pBase2->transformBy(mat);
|
|
|
|
|
|
AcDbVoidPtrArray ar, ar1;
|
|
|
|
pBase->explode(ar1);
|
|
ar.append(ar1);
|
|
ar1.removeAll(); // 不能清理内存, ar 内统一清
|
|
DELETE_PTR(pBase);
|
|
|
|
pBase2->explode(ar1);
|
|
ar.append(ar1);
|
|
DELETE_PTR(pBase2);
|
|
|
|
ar.append(new AcDbLine(ptT, ptT + X * 3 * T));
|
|
ar.append(new AcDbLine(ptB, ptB + X * 3 * T));
|
|
|
|
AcDbPolyline *pProfile = curves2Polyline(ar);
|
|
if (!pProfile) return NULL;
|
|
|
|
pProfile->getOffsetCurves(T, ar);
|
|
if (ar.isEmpty())
|
|
{
|
|
DELETE_PTR(pProfile);
|
|
return NULL;
|
|
}
|
|
|
|
AcDbPolyline *pProfile2 = (AcDbPolyline*)((AcDbEntity*)ar[0])->clone();
|
|
deleteArrayVoidPtrs< AcDbEntity>(ar);
|
|
|
|
double area1, area2;
|
|
pProfile->getArea(area1);
|
|
pProfile2->getArea(area2);
|
|
if (area2 > area1)
|
|
{
|
|
AcDbPolyline *p(pProfile);
|
|
pProfile = pProfile2;
|
|
pProfile2 = p;
|
|
}
|
|
|
|
AcDbRegion *pRegBig = CoreTools::createRegion(pProfile);
|
|
if (!pRegBig)
|
|
{
|
|
DELETE_PTR(pProfile);
|
|
DELETE_PTR(pProfile2);
|
|
return NULL;
|
|
}
|
|
|
|
AcDbRegion *pRegSml = CoreTools::createRegion(pProfile2);
|
|
if (!pRegSml)
|
|
{
|
|
DELETE_PTR(pRegBig);
|
|
DELETE_PTR(pProfile);
|
|
DELETE_PTR(pProfile2);
|
|
return NULL;
|
|
}
|
|
|
|
DELETE_PTR(pProfile);
|
|
DELETE_PTR(pProfile2);
|
|
|
|
|
|
if (pRegBig->booleanOper(AcDb::kBoolSubtract, pRegSml) != Acad::eOk)
|
|
{
|
|
DELETE_PTR(pRegBig);
|
|
DELETE_PTR(pRegSml);
|
|
return NULL;
|
|
}
|
|
|
|
DELETE_PTR(pRegSml);
|
|
|
|
return pRegBig;
|
|
}
|
|
else
|
|
{
|
|
AcGePoint3d ptT(Pos + Y * .5 * W);
|
|
ptT -= X * .5 * L;
|
|
AcGePoint3d ptB(Pos - Y * .5 * W);
|
|
ptB -= X * .5 * L;
|
|
|
|
AcDbVoidPtrArray ar, ar1;
|
|
pBase->explode(ar1);
|
|
ar.append(ar1);
|
|
ar1.removeAll(); // 不清理内存
|
|
pBase->getOffsetCurves(T, ar1);
|
|
if (ar1.isEmpty())
|
|
{
|
|
deleteArrayVoidPtrs< AcDbEntity>(ar);
|
|
return NULL;
|
|
}
|
|
|
|
ar.append((AcDbEntity*)(((AcDbEntity*)ar1[0])->clone()));
|
|
deleteArrayVoidPtrs< AcDbEntity>(ar1);
|
|
|
|
ar.append(new AcDbLine(ptT, ptT + X * T));
|
|
ar.append(new AcDbLine(ptB, ptB + X * T));
|
|
|
|
AcDbRegion *pReg = CoreTools::createRegion(ar);
|
|
deleteArrayVoidPtrs< AcDbEntity>(ar);
|
|
|
|
return pReg;
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
AcDbPolyline* getOffsetOfPolyline(double dOffset, AcDbPolyline* pPoly)
|
|
{
|
|
if (!pPoly) return NULL;
|
|
AcDbVoidPtrArray ar;
|
|
pPoly->getOffsetCurves(dOffset, ar);
|
|
if (ar.isEmpty()) return NULL;
|
|
|
|
if (!pPoly->isClosed() && pPoly->numVerts() > 2)
|
|
{
|
|
pPoly->setClosed(true);
|
|
}
|
|
|
|
if (!pPoly->isClosed())
|
|
{
|
|
AcDbPolyline *p = (AcDbPolyline*)((AcDbEntity*)(ar[0]))->clone();
|
|
deleteArrayVoidPtrs< AcDbEntity>(ar);
|
|
return p;
|
|
}
|
|
|
|
double area1(.0), area2(.0);
|
|
pPoly->getArea(area1);
|
|
((AcDbPolyline*)(ar[0]))->getArea(area2);
|
|
|
|
bool bReset(false);
|
|
if (UP_ZERO(dOffset)) // 变大
|
|
{
|
|
if (area2 < area1) // 没有变大,重新取curve
|
|
bReset = true;
|
|
}
|
|
else // 变小
|
|
{
|
|
if (area2 > area1) // 没有变小,重新取curve
|
|
bReset = true;
|
|
}
|
|
|
|
if (bReset)
|
|
{
|
|
deleteArrayVoidPtrs< AcDbEntity>(ar);
|
|
pPoly->getOffsetCurves(-dOffset, ar);
|
|
if (ar.isEmpty()) return NULL;
|
|
}
|
|
AcDbPolyline *p = (AcDbPolyline*)((AcDbEntity*)(ar[0]))->clone();
|
|
deleteArrayVoidPtrs< AcDbEntity>(ar);
|
|
return p;
|
|
}
|
|
}
|
|
|
|
Adesk::UInt32 AecDbXBG::kCurrentVersionNumber = 1;
|
|
|
|
IMP_XDATA_KEY(AecDbXBG, _MATERIAL_);
|
|
IMP_XDATA_KEY(AecDbXBG, _TYPE_);
|
|
IMP_XDATA_KEY(AecDbXBG, _R_);
|
|
IMP_XDATA_KEY(AecDbXBG, _S_);
|
|
IMP_XDATA_KEY(AecDbXBG, _T_);
|
|
IMP_XDATA_KEY(AecDbXBG, _A_);
|
|
IMP_XDATA_KEY(AecDbXBG, _H_);
|
|
IMP_XDATA_KEY(AecDbXBG, _PROFILE_);
|
|
|
|
ACRX_DXF_DEFINE_MEMBERS (AecDbXBG, AecDbEwPipeBase,
|
|
AcDb::kDHL_CURRENT, AcDb::kMReleaseCurrent,
|
|
AcDbProxyEntity::kNoOperation | AcDbProxyEntity::kDisableProxyWarning,
|
|
AEC_DBXBG,
|
|
"AecDbXBG"
|
|
"|Product Desc: shanghua earthworm app obj"
|
|
"|Company: shanghua inc"
|
|
"|WEB Address: www.shanghuasoft.com")
|
|
|
|
|
|
AecDbXBG::AecDbXBG(void)
|
|
{
|
|
m_mapSpecXData.SetAt(KEY_NAME,_T("斜板管"));
|
|
}
|
|
|
|
AecDbXBG::~AecDbXBG(void)
|
|
{
|
|
}
|
|
|
|
Acad::ErrorStatus AecDbXBG::dwgInFields(AcDbDwgFiler* pFiler)
|
|
{
|
|
AssertWriteEnabled();
|
|
|
|
//----- Read parent class information first.
|
|
Acad::ErrorStatus es = Acad::eOk;
|
|
es = AecDbEwPipeBase::dwgInFields(pFiler);
|
|
if (es != Acad::eOk)
|
|
return (es);
|
|
|
|
//----- Object version number needs to be read first
|
|
Adesk::UInt32 version(0);
|
|
if ((es = pFiler->readUInt32(&version)) != Acad::eOk)
|
|
return (es);
|
|
|
|
if (version > AecDbXBG::kCurrentVersionNumber)
|
|
return Acad::eMakeMeProxy;
|
|
|
|
return Acad::eOk;
|
|
}
|
|
|
|
Acad::ErrorStatus AecDbXBG::dwgOutFields(AcDbDwgFiler* pFiler) const
|
|
{
|
|
assertReadEnabled();
|
|
|
|
//----- Save parent class information first.
|
|
Acad::ErrorStatus es = Acad::eOk;
|
|
es = AecDbEwPipeBase::dwgOutFields(pFiler);
|
|
if (es != Acad::eOk)
|
|
return (es);
|
|
|
|
//----- Object version number needs to be saved first
|
|
if ((es = pFiler->writeUInt32(AecDbXBG::kCurrentVersionNumber)) != Acad::eOk)
|
|
return (es);
|
|
|
|
return Acad::eOk;
|
|
}
|
|
|
|
Acad::ErrorStatus AecDbXBG::dxfInFields(AcDbDxfFiler* pFiler)
|
|
{
|
|
return Acad::eNotImplementedYet;
|
|
}
|
|
|
|
Acad::ErrorStatus AecDbXBG::dxfOutFields(AcDbDxfFiler* pFiler) const
|
|
{
|
|
return Acad::eNotImplementedYet;
|
|
}
|
|
|
|
Acad::ErrorStatus AecDbXBG::subExplode(AcDbVoidPtrArray& entitySet) const
|
|
{
|
|
return Acad::eOk;
|
|
}
|
|
|
|
void AecDbXBG::subList() const {}
|
|
|
|
Acad::ErrorStatus AecDbXBG::subTransformBy(const AcGeMatrix3d &mat)
|
|
{
|
|
AssertWriteEnabled();
|
|
CString sPoly;
|
|
if (!m_mapSpecXData.GetAt(_T("_PROFILE_"), sPoly)) return Acad::eInvalidInput;
|
|
AcDbPolyline *pProfile = CoreTools::StringToPolyline(sPoly);
|
|
if (!pProfile) return Acad::eInvalidInput;
|
|
|
|
pProfile->transformBy(mat);
|
|
|
|
sPoly.Empty();
|
|
CoreTools::PolylineToString(pProfile, sPoly);
|
|
DELETE_PTR(pProfile);
|
|
|
|
if (sPoly.IsEmpty()) return Acad::eInvalidInput;
|
|
|
|
m_mapSpecXData.SetAt(_T("_PROFILE_"), sPoly);
|
|
|
|
return Acad::eOk;
|
|
}
|
|
|
|
Acad::ErrorStatus AecDbXBG::subGetGripPoints(AcGePoint3dArray& gripPoints,
|
|
AcDbIntArray& osnapModes,
|
|
AcDbIntArray& geomIds) const
|
|
{
|
|
assertReadEnabled();
|
|
CString sPoly(_T(""));
|
|
if (!m_mapSpecXData.GetAt(_T("_PROFILE_"), sPoly)) return Acad::eInvalidInput;
|
|
AcDbPolyline *pProfile = CoreTools::StringToPolyline(sPoly);
|
|
if (!pProfile) return Acad::eInvalidInput;
|
|
|
|
pProfile->getGripPoints(gripPoints, osnapModes, geomIds);
|
|
|
|
AcDbExtents ext;
|
|
pProfile->getGeomExtents(ext);
|
|
AcGePoint3d Pos(CoreTools::MidPt(ext.maxPoint(), ext.minPoint())), ptLB(ext.minPoint());
|
|
|
|
gripPoints.append(Pos);
|
|
|
|
DELETE_PTR(pProfile);
|
|
|
|
return Acad::eOk;
|
|
}
|
|
|
|
Acad::ErrorStatus AecDbXBG::subGetGripPoints(AcDbGripDataPtrArray& grips,
|
|
const double curViewUnitSize,
|
|
const int gripSize,
|
|
const AcGeVector3d& curViewDir,
|
|
const int bitflags) const { return Acad::eNotImplementedYet; }
|
|
|
|
Acad::ErrorStatus AecDbXBG::subMoveGripPointsAt(const AcDbVoidPtrArray& appData
|
|
, const AcGeVector3d& offset
|
|
, const int bitflags)
|
|
{
|
|
return Acad::eOk;
|
|
}
|
|
|
|
Acad::ErrorStatus AecDbXBG::subMoveGripPointsAt(const AcDbIntArray &indices, const AcGeVector3d &offset)
|
|
{
|
|
AcGeMatrix3d mat;
|
|
mat.setTranslation(offset);
|
|
return subTransformBy(mat);
|
|
}
|
|
|
|
void AecDbXBG::GetGripText(int nPos, CString& sText)
|
|
{
|
|
return;
|
|
}
|
|
|
|
Acad::ErrorStatus AecDbXBG::subIntersectWith(const AcDbEntity* pEnt,
|
|
AcDb::Intersect intType,
|
|
AcGePoint3dArray& points,
|
|
INT_PTR thisGsMarker,
|
|
INT_PTR otherGsMarker) const
|
|
{
|
|
return Acad::eNotImplementedYet;
|
|
}
|
|
|
|
Acad::ErrorStatus AecDbXBG::subIntersectWith(const AcDbEntity* pEnt,
|
|
AcDb::Intersect intType,
|
|
const AcGePlane& projPlane,
|
|
AcGePoint3dArray& points,
|
|
INT_PTR thisGsMarker,
|
|
INT_PTR otherGsMarker) const
|
|
{
|
|
return Acad::eNotImplementedYet;
|
|
}
|
|
|
|
Acad::ErrorStatus AecDbXBG::Draw2d(AcGiDraw &dc) const
|
|
{
|
|
assertReadEnabled();
|
|
|
|
int clr(256), oldclr;
|
|
m_mapSpecXData.GetAt(_T("COLOR"), clr);
|
|
oldclr = dc.GetColor();
|
|
dc.SetColor(clr);
|
|
|
|
if (Has2DBuffer())
|
|
{
|
|
Draw2DBuffers(dc);
|
|
return Acad::eOk;
|
|
}
|
|
|
|
AcGeVector3d X(AcGeVector3d::kXAxis), Y(AcGeVector3d::kYAxis), Z(AcGeVector3d::kZAxis);
|
|
|
|
CString sPoly(_T(""));
|
|
if (!m_mapSpecXData.GetAt(_T("_PROFILE_"), sPoly)) return Acad::eInvalidInput;
|
|
AcDbPolyline *pProfile = CoreTools::StringToPolyline(sPoly);
|
|
if (!pProfile) return Acad::eInvalidInput;
|
|
AcDbExtents ext;
|
|
pProfile->getGeomExtents(ext);
|
|
double L = ext.maxPoint().x - ext.minPoint().x;
|
|
double W = ext.maxPoint().y - ext.minPoint().y;
|
|
AcGePoint3d Pos(CoreTools::MidPt(ext.maxPoint(), ext.minPoint())), ptLB(ext.minPoint());
|
|
|
|
AcDbRegion *pReg = makeMainRegion(GetType(), pProfile, GetType() == 0 ? GetR() : GetS(), T);
|
|
if (!pReg)
|
|
{
|
|
DELETE_PTR(pProfile);
|
|
return Acad::eInvalidInput;
|
|
}
|
|
pReg->getGeomExtents(ext);
|
|
|
|
AcGeMatrix3d mat;
|
|
mat.setToTranslation(X * (ptLB.x - ext.minPoint().x));
|
|
pReg->transformBy(mat);
|
|
|
|
int count(0);
|
|
double l(.0);
|
|
if (GetType() == 0)
|
|
{
|
|
l = ext.maxPoint().x - ext.minPoint().x;
|
|
count = (int)(L / l + .01);
|
|
}
|
|
else
|
|
{
|
|
l = GetT() + GetS();
|
|
count = int((L - GetS()) / l + .01);
|
|
}
|
|
|
|
double dLen = L - l * count;
|
|
if (UP_ZERO(dLen))
|
|
{
|
|
mat.setToTranslation(X * dLen * .5);
|
|
pReg->transformBy(mat);
|
|
}
|
|
pReg->getGeomExtents(ext);
|
|
double xPos = ext.maxPoint().x;
|
|
|
|
AcDbVoidPtrArray arRegs;
|
|
arRegs.append(pReg);
|
|
for (int i = 1; i < count; ++i)
|
|
{
|
|
AcDbRegion *p = (AcDbRegion*)pReg->clone();
|
|
if (!p) continue;
|
|
p->transformBy(X * l * i);
|
|
arRegs.append(p);
|
|
}
|
|
|
|
AcDbRegion *pSubReg = makeCutRegion(pProfile);
|
|
if (!pSubReg)
|
|
{
|
|
DELETE_PTR(pProfile);
|
|
return Acad::eInvalidInput;
|
|
}
|
|
|
|
mat.setToTranslation(Z * GetH());
|
|
for (int i = 0; i < arRegs.length(); ++i)
|
|
{
|
|
AcDbRegion *p((AcDbRegion*)arRegs[i]);
|
|
AcDbRegion *pSub((AcDbRegion*)pSubReg->clone());
|
|
if (p->booleanOper(AcDb::kBoolSubtract, pSub) != Acad::eOk)
|
|
{
|
|
continue;
|
|
}
|
|
DELETE_PTR(pSub);
|
|
p->transformBy(mat);
|
|
Add2DBuffer(p);
|
|
}
|
|
|
|
DELETE_PTR(pProfile);
|
|
DELETE_PTR(pSubReg);
|
|
|
|
|
|
Draw2DBuffers(dc);
|
|
dc.SetColor(oldclr);
|
|
return Acad::eOk;
|
|
}
|
|
|
|
Acad::ErrorStatus AecDbXBG::Draw3d(AcGiDraw &dc) const
|
|
{
|
|
assertReadEnabled();
|
|
AcGeVector3d X(AcGeVector3d::kXAxis), Y(AcGeVector3d::kYAxis), Z(AcGeVector3d::kZAxis);
|
|
|
|
int clr(256), oldclr;
|
|
m_mapSpecXData.GetAt(_T("COLOR"), clr);
|
|
oldclr = dc.GetColor();
|
|
dc.SetColor(clr);
|
|
|
|
if (Has3DBuffer())
|
|
{
|
|
Draw3DBuffers(dc);
|
|
return Acad::eOk;
|
|
}
|
|
|
|
if (!Has2DBuffer())
|
|
{
|
|
AcGiViewDraw dc1;
|
|
Draw2d(dc1);
|
|
}
|
|
|
|
double H(GetH()), A(GetA());
|
|
AcGeMatrix3d mat0;
|
|
AcGeVector3d vtDir(AcGeVector3d::kXAxis);
|
|
if (EQUAL_ZERO(A))
|
|
{
|
|
vtDir = Z * H;
|
|
mat0.setToIdentity();
|
|
}
|
|
else
|
|
{
|
|
vtDir.rotateBy(CoreTools::A2R(A), -Y);
|
|
vtDir.normalize();
|
|
vtDir *= H / sin(CoreTools::A2R(A));
|
|
mat0.setToTranslation(-X * (H / tan(CoreTools::A2R(A))));
|
|
}
|
|
|
|
const AcDbVoidPtrArray &ar = Get2DBuffer();
|
|
|
|
AcDbExtents ext;
|
|
AcGePoint3d pt;
|
|
AcDbLine line;
|
|
|
|
AcDb3dSolid *pSubSolid(NULL);
|
|
if (!EQUAL_ZERO(A))
|
|
{
|
|
CString sPoly(_T(""));
|
|
if (!m_mapSpecXData.GetAt(_T("_PROFILE_"), sPoly)) return Acad::eInvalidInput;
|
|
AcDbPolyline *pProfile = CoreTools::StringToPolyline(sPoly);
|
|
if (pProfile)
|
|
{
|
|
AcDbPolyline *pL = getOffsetOfPolyline(H / tan(CoreTools::A2R(A)), pProfile);
|
|
if (pL)
|
|
{
|
|
AcDbRegion *pSubReg = CoreTools::createRegion(pL);
|
|
if (pSubReg)
|
|
{
|
|
AcDbRegion *pSubReg2 = CoreTools::createRegion(pProfile);
|
|
if (pSubReg2)
|
|
{
|
|
if (pSubReg->booleanOper(AcDb::kBoolSubtract, pSubReg2) == Acad::eOk)
|
|
{
|
|
pSubReg->getGeomExtents(ext);
|
|
pt = CoreTools::MidPt(ext.minPoint(), ext.maxPoint());
|
|
line.setStartPoint(pt);
|
|
line.setEndPoint(pt + AcGeVector3d::kZAxis * H);
|
|
|
|
pSubSolid = new AcDb3dSolid();
|
|
if (pSubSolid->extrudeAlongPath(pSubReg, &line) != Acad::eOk)
|
|
DELETE_PTR(pSubSolid);
|
|
}
|
|
DELETE_PTR(pSubReg2);
|
|
}
|
|
DELETE_PTR(pSubReg);
|
|
}
|
|
DELETE_PTR(pL);
|
|
}
|
|
DELETE_PTR(pProfile);
|
|
}
|
|
}
|
|
|
|
for (int i(0); i < ar.length(); ++i)
|
|
{
|
|
AcDbRegion *pReg((AcDbRegion*)ar[i]);
|
|
pReg->getGeomExtents(ext);
|
|
pt = CoreTools::MidPt(ext.maxPoint(), ext.minPoint());
|
|
line.setStartPoint(pt);
|
|
line.setEndPoint(pt - vtDir);
|
|
AcDb3dSolid *pSolid = new AcDb3dSolid();
|
|
if (pSolid->extrudeAlongPath(pReg, &line) == Acad::eOk)
|
|
{
|
|
if (pSubSolid)
|
|
{
|
|
AcDb3dSolid *p((AcDb3dSolid*)pSubSolid->clone());
|
|
pSolid->booleanOper(AcDb::kBoolSubtract, p);
|
|
DELETE_PTR(p);
|
|
}
|
|
Add3DBuffer(pSolid);
|
|
}
|
|
}
|
|
DELETE_PTR(pSubSolid);
|
|
|
|
// 角度不为0,则进行切割
|
|
|
|
const AcDbVoidPtrArray &ar3d = Get3DBuffer();
|
|
for (int i(0); i < ar3d.length(); ++i)
|
|
{
|
|
AcDbEntity *pEnt((AcDbEntity*)ar3d[i]);
|
|
pEnt->setTransparency(transparency());
|
|
}
|
|
|
|
|
|
Draw3DBuffers(dc);
|
|
dc.SetColor(oldclr);
|
|
return Acad::eOk;
|
|
}
|
|
|
|
bool AecDbXBG::TransformAssocInf(int nInf,const AcGeMatrix3d& xform)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
LPCTSTR AecDbXBG::GetGripCmd() const
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
bool AecDbXBG::GetSrcString(CString &src)
|
|
{
|
|
assertReadEnabled();
|
|
return m_mapSpecXData.GetAt(_T("_SRC_STRING_"), src) == 0 ? false : true;
|
|
}
|
|
|
|
void AecDbXBG::SetSrcString(LPCTSTR src)
|
|
{
|
|
assertWriteEnabled();
|
|
if (src && !CString(src).IsEmpty())
|
|
m_mapSpecXData.SetAt(_T("_SRC_STRING_"), src);
|
|
}
|
|
|
|
SHJson::WValue& AecDbXBG::ToJson(bool bExprotGeo) const
|
|
{
|
|
assertReadEnabled();
|
|
return AecDbEwPipeBase::ToJson(bExprotGeo);
|
|
}
|
|
|
|
bool AecDbXBG::ByJson(const SHJson::WValue &v)
|
|
{
|
|
AssertWriteEnabled();
|
|
return AecDbEwPipeBase::ByJson(v);
|
|
}
|
|
|
|
double AecDbXBG::getElevation()
|
|
{
|
|
assertReadEnabled();
|
|
|
|
CString sPoly;
|
|
if (!m_mapSpecXData.GetAt(_T("_PROFILE_"), sPoly)) return .0;
|
|
AcDbPolyline *pProfile = CoreTools::StringToPolyline(sPoly);
|
|
if (!pProfile) return .0;
|
|
|
|
return pProfile->elevation();
|
|
}
|
|
|
|
void AecDbXBG::setElevation(const double &dElev)
|
|
{
|
|
AssertWriteEnabled();
|
|
CString sPoly;
|
|
if (!m_mapSpecXData.GetAt(_T("_PROFILE_"), sPoly)) return;
|
|
AcDbPolyline *pProfile = CoreTools::StringToPolyline(sPoly);
|
|
if (!pProfile) return;
|
|
|
|
pProfile->setElevation(dElev);
|
|
|
|
sPoly.Empty();
|
|
CoreTools::PolylineToString(pProfile, sPoly);
|
|
DELETE_PTR(pProfile);
|
|
|
|
if (sPoly.IsEmpty()) return;
|
|
|
|
m_mapSpecXData.SetAt(_T("_PROFILE_"), sPoly);
|
|
|
|
return;
|
|
}
|
|
|
|
#include "HlrCutOption.h"
|
|
void AecDbXBG::ProcessHlrResult(const AcArray<AcDbEntity *> &ar
|
|
, const std::map<AcDbEntity *, AcArray<AcDbEntity *>> &preAr
|
|
, AcArray<AcDbEntity *> &output) const
|
|
{
|
|
HlrCutOption::ProcessHlrResult(this
|
|
, FALSE
|
|
, .0
|
|
, HlrCutOption::getHlrBLK_PARAEQU()
|
|
, ar
|
|
, preAr
|
|
, output);
|
|
}
|