#include "stdafx.h" #include "AecDbPoolCell.h" #include "MFCDbDwgFiler.h" #include "CoreTools.h" namespace { AcDbRegion* CreateRegion(const AcGePoint3d &ptS , const AcGePoint3d &ptE , const double &wallHeight , const double &halfWallThickness) { AcGeVector3d vt(ptE - ptS); vt.rotateBy(PI * .5, AcGeVector3d::kZAxis); vt.normalize(); AcGePoint3d pt0(AcGePoint3d::kOrigin) , pt1(AcGePoint3d::kOrigin) , pt2(AcGePoint3d::kOrigin) , pt3(AcGePoint3d::kOrigin); pt0 = ptS + vt * halfWallThickness; pt1 = ptS - vt * halfWallThickness; pt2 = pt1 + AcGeVector3d::kZAxis * wallHeight; pt3 = pt2 + vt * 2 * halfWallThickness; AcDbVoidPtrArray arr(0); arr.append(new AcDbLine(pt0, pt1)); arr.append(new AcDbLine(pt1, pt2)); arr.append(new AcDbLine(pt2, pt3)); arr.append(new AcDbLine(pt3, pt0)); AcDbRegion *pReg = CoreTools::createRegion(arr); deleteArrayVoidPtrs< AcDbEntity>(arr); return pReg; } } IMP_XDATA_KEY(AecDbPoolCell,_H_); IMP_XDATA_KEY(AecDbPoolCell,_W_); IMP_XDATA_KEY(AecDbPoolCell,_L_); IMP_XDATA_KEY(AecDbPoolCell,_R_); IMP_XDATA_KEY(AecDbPoolCell,_A_); IMP_XDATA_KEY(AecDbPoolCell,_PT_); IMP_XDATA_KEY(AecDbPoolCell,_TS_); IMP_XDATA_KEY(AecDbPoolCell,_TH_); IMP_XDATA_KEY(AecDbPoolCell,_NAME_); Adesk::UInt32 AecDbPoolCell::kCurrentVersionNumber = 1; ACRX_DXF_DEFINE_MEMBERS (AecDbPoolCell, AecDbEntityBase, AcDb::kDHL_CURRENT, AcDb::kMReleaseCurrent, AcDbProxyEntity::kNoOperation | AcDbProxyEntity::kDisableProxyWarning, AEC_DBPOOLCELL, "AecDbPoolCell" "|Product Desc: shanghua earthworm app obj" "|Company: shanghua inc" "|WEB Address: www.shanghuasoft.com") AecDbPoolCell::AecDbPoolCell(void) { SetTH(3.); SetTStyle(_T("standard")); SetName(_T("")); } AecDbPoolCell::~AecDbPoolCell(void) { } const AecDbObjXDataMap* AecDbPoolCell::GetSpecialtyData() const { assertReadEnabled(); return &m_mapSpecXData; } AecDbObjXDataMap* AecDbPoolCell::GetSpecialtyData(AcDb::OpenMode bMode) { return &m_mapSpecXData; } Acad::ErrorStatus AecDbPoolCell::subExplode(AcDbVoidPtrArray& entitySet) const { if (IsCircle()) { AcDbCircle cir; GetCircle(cir); entitySet.append(cir.clone()); } else { AcDbPolyline poly; GetPolyline(poly); entitySet.append(poly.clone()); } AcDbText txt; GetText(txt); entitySet.append(txt.clone()); return Acad::eOk; } Acad::ErrorStatus AecDbPoolCell::copyFrom(const AcRxObject* pSrc) { assertReadEnabled(); AecDbPoolCell *pCell = AecDbPoolCell::cast(pSrc); if (!pCell) return Acad::eInvalidInput; m_mapSpecXData.CopyFrom(pCell->GetSpecialtyData()); //发送提资需要相同的ID extern CString IDCreate(); Adesk::Int16 nVal = acdbCurDwg()->useri4(); if (nVal != KEY_NOPROTECT) { int nVt = 0; CString sID = IDCreate(); if (m_mapSpecXData.HasKey(KEY_NO, nVt)) m_mapSpecXData.SetAt(KEY_NO, sID); } return Acad::eOk; } Acad::ErrorStatus AecDbPoolCell::subTransformBy(const AcGeMatrix3d& xform) { AssertWriteEnabled(); AcGePoint3d pt(GetPt()); pt.transformBy(xform); SetPt(pt); return Acad::eOk; } Acad::ErrorStatus AecDbPoolCell::subGetGripPoints(AcDbGripDataPtrArray & grips , const double curViewUnitSize , const int gripSize , const AcGeVector3d & curViewDir , const int bitflags) const { return Acad::eNotImplementedYet; } Acad::ErrorStatus AecDbPoolCell::subGetGripPoints(AcGePoint3dArray & gripPoints , AcDbIntArray & osnapModes , AcDbIntArray & geomIds) const { assertReadEnabled(); if (IsCircle()) { gripPoints.append(GetPt()); } else { AcDbPolyline poly; GetPolyline(poly); AcDbExtents ext; poly.getGeomExtents(ext); gripPoints.append(CoreTools::MidPt(ext.maxPoint(), ext.minPoint())); AcGePoint2d pt2d(AcGePoint2d::kOrigin); for (int i = 0; i < poly.numVerts(); ++i) { poly.getPointAt(i, pt2d); gripPoints.append(AcGePoint3d(pt2d.x, pt2d.y, .0)); } } return Acad::eOk; } Acad::ErrorStatus AecDbPoolCell::subMoveGripPointsAt(const AcDbIntArray & indices , const AcGeVector3d & offset) { AssertWriteEnabled(); AcGePoint3d pt(GetPt()); AcDbPolyline poly; GetPolyline(poly); bool bIsCircle(IsCircle()); double a(GetA()); int idx(0); for (int i = 0; i < indices.length(); ++i) { idx = indices[i]; if (bIsCircle) { pt += offset; SetPt(pt); } else { if (idx == 0) // 转 { a += AcGeVector3d::kXAxis.angleTo(offset, AcGeVector3d::kZAxis); SetA(a); } else { pt += offset; SetPt(pt); } } } return Acad::eOk; } Acad::ErrorStatus AecDbPoolCell::subGetOsnapPoints(AcDb::OsnapMode osnapMode , INT_PTR gsSelectionMark , const AcGePoint3d & pickPoint , const AcGePoint3d & lastPoint , const AcGeMatrix3d & viewXform , AcGePoint3dArray & snapPoints , AcDbIntArray & geomIds) const { assertReadEnabled(); if (IsCircle()) { AcDbCircle Cir; GetCircle(Cir); return Cir.getOsnapPoints(osnapMode, gsSelectionMark, pickPoint, lastPoint, viewXform, snapPoints, geomIds); } else { AcDbPolyline PLine; GetPolyline(PLine); return PLine.getOsnapPoints(osnapMode, gsSelectionMark, pickPoint, lastPoint, viewXform, snapPoints, geomIds); } return Acad::eInvalidInput; } Acad::ErrorStatus AecDbPoolCell::subGetGeomExtents(AcDbExtents & extents) const { assertReadEnabled(); if (IsCircle()) { AcDbCircle Cir; GetCircle(Cir); return Cir.getGeomExtents(extents); } else { AcDbPolyline PLine; GetPolyline(PLine); return PLine.getGeomExtents(extents); } return Acad::eInvalidInput; } Acad::ErrorStatus AecDbPoolCell::subIntersectWith(const AcDbEntity * pEnt , AcDb::Intersect intType , AcGePoint3dArray & points , INT_PTR thisGsMarker , INT_PTR otherGsMarker) const { assertReadEnabled(); if (IsCircle()) { AcDbCircle Cir; GetCircle(Cir); return Cir.intersectWith(pEnt, intType, points, thisGsMarker, otherGsMarker); } else { AcDbPolyline PLine; GetPolyline(PLine); return PLine.intersectWith(pEnt, intType, points, thisGsMarker, otherGsMarker); } return Acad::eInvalidInput; } Acad::ErrorStatus AecDbPoolCell::subIntersectWith(const AcDbEntity * pEnt , AcDb::Intersect intType , const AcGePlane & projPlane , AcGePoint3dArray & points , INT_PTR thisGsMarker , INT_PTR otherGsMarker) const { assertReadEnabled(); if (IsCircle()) { AcDbCircle Cir; GetCircle(Cir); return Cir.intersectWith(pEnt, intType, projPlane, points, thisGsMarker, otherGsMarker); } else { AcDbPolyline PLine; GetPolyline(PLine); return PLine.intersectWith(pEnt, intType, projPlane, points, thisGsMarker, otherGsMarker); } return Acad::eInvalidInput; } Acad::ErrorStatus AecDbPoolCell::Draw2d(AcGiDraw &dc) const { assertReadEnabled(); int prec(1); AcDbExtents ext; getGeomExtents(ext); dc.DrawText(GetString() , CoreTools::MidPt(ext.maxPoint() , ext.minPoint()) , AcGiDraw::kMiddleCenter , GetTH() , 1. , .0 , GetTStyle()); if (Has2DBuffer()) { Draw2DBuffers(dc); return Acad::eOk; } if (IsCircle()) { AcDbCircle *pCir = new AcDbCircle(); GetCircle(*pCir); dc.DrawEntity(*pCir); Add2DBuffer(pCir); } else { AcDbPolyline *pLine = new AcDbPolyline(); GetPolyline(*pLine); dc.DrawEntity(*pLine); Add2DBuffer(pLine); } return Acad::eOk; } Acad::ErrorStatus AecDbPoolCell::Draw3d(AcGiDraw &dc) const { return Draw2d(dc); } Acad::ErrorStatus AecDbPoolCell::dwgInFields (AcDbDwgFiler* pFiler) { AssertWriteEnabled(); //----- Read parent class information first. Acad::ErrorStatus es = Acad::eOk; if (!pFiler->isKindOf(CMFCDbDwgFiler::desc())) { es = AecDbEntityBase::dwgInFields(pFiler); if (es != Acad::eOk) return (es); } //----- Object version number needs to be read first Adesk::UInt32 version(0); if ((es = pFiler->readUInt32(&version)) != Acad::eOk) return (es); if (version > AecDbPoolCell::kCurrentVersionNumber) return Acad::eMakeMeProxy; m_mapSpecXData.dwgInFields(pFiler); return Acad::eOk; } Acad::ErrorStatus AecDbPoolCell::dwgOutFields(AcDbDwgFiler* pFiler) const { assertReadEnabled(); //----- Save parent class information first. Acad::ErrorStatus es = Acad::eOk; if (!pFiler->isKindOf(CMFCDbDwgFiler::desc())) { es = AecDbEntityBase::dwgOutFields(pFiler); if (es != Acad::eOk) return (es); } //----- Object version number needs to be saved first if ((es = pFiler->writeUInt32(AecDbPoolCell::kCurrentVersionNumber)) != Acad::eOk) return (es); m_mapSpecXData.dwgOutFields(pFiler); return Acad::eOk; } Acad::ErrorStatus AecDbPoolCell::dxfInFields (AcDbDxfFiler* pFiler) { return Acad::eNotImplementedYet; } Acad::ErrorStatus AecDbPoolCell::dxfOutFields(AcDbDxfFiler* pFiler) const { return Acad::eNotImplementedYet; } void AecDbPoolCell::subList() const { acutPrintf(_T("\n水池格子对象:")); acutPrintf(_T("\n\t名称:"), GetName()); if (!IsCircle()) { acutPrintf(_T("\n\t形状:方形")); acutPrintf(_T("\n\t长:%.2f毫米"), GetL()); acutPrintf(_T("\n\t宽:%.2f毫米"), GetW()); acutPrintf(_T("\n\t插入角度:%.2f度"), CoreTools::R2A(GetA())); } else { acutPrintf(_T("\n\t形状:圆形")); acutPrintf(_T("\n\t半径:%.2f毫米"), GetR()); } acutPrintf(_T("\n\t深:%.2f毫米"), GetH()); acutPrintf(_T("\n\t体积:%.2f立方米"), GetV() *10e-9); AcGePoint3d pt(GetPt()); acutPrintf(_T("\n\t位置:(%.2f, %.2f, %.2f)"), pt.x, pt.y, pt.z); } CString AecDbPoolCell::ToScript() const { assertReadEnabled(); CString str; m_mapSpecXData.Write(str, false); return str; } void AecDbPoolCell::FromScript(LPCTSTR psz) { AssertWriteEnabled(); if (!psz) return; m_mapSpecXData.Empty(); m_mapSpecXData.Read(psz, false); } bool AecDbPoolCell::IsCircle() const { if (EQUAL_ZERO(GetR())) return false; return true; } void AecDbPoolCell::GetCircle(AcDbCircle & cir) const { double r(GetR()); AcGePoint3d pt0(GetPt()); cir.setCenter(pt0); cir.setNormal(AcGeVector3d::kZAxis); cir.setRadius(r); } void AecDbPoolCell::GetPolyline(AcDbPolyline & poly) const { double a(GetA()), w(GetW()), l(GetL()); AcGePoint3d pt0(GetPt()); AcGeVector3d vt(AcGeVector3d::kXAxis); vt.rotateBy(a, AcGeVector3d::kZAxis); vt.normalize(); AcGeVector3d vtN(vt); vtN.rotateBy(PI * .5, AcGeVector3d::kZAxis); vtN.normalize(); pt0 -= vt * l * .5; pt0 += vtN * w * .5; poly.addVertexAt(0, pt0.convert2d(AcGePlane::kXYPlane)); pt0 += vt * l; poly.addVertexAt(1, pt0.convert2d(AcGePlane::kXYPlane)); pt0 -= vtN * w; poly.addVertexAt(2, pt0.convert2d(AcGePlane::kXYPlane)); pt0 -= vt * l; poly.addVertexAt(3, pt0.convert2d(AcGePlane::kXYPlane)); poly.setClosed(true); } void AecDbPoolCell::GetText(AcDbText & txt) const { AcDbExtents ext; getGeomExtents(ext); AcGePoint3d pt(CoreTools::MidPt(ext.maxPoint(), ext.minPoint())); int prec(1); CString sName(GetString()); txt.setTextString(sName); txt.setTextStyle(CoreTools::findTextStyleId(GetTStyle())); txt.setHeight(GetTH()); txt.setHorizontalMode(AcDb::kTextMid); txt.setVerticalMode(AcDb::kTextVertMid); txt.setPosition(pt); txt.setAlignmentPoint(pt); } CString AecDbPoolCell::GetString() const { int prec(2); CString str(_T("")); if (!GetName().IsEmpty()) { str = (GetName() + _T(" ")) + TypeConvert::d2s(GetV() * 10e-9, &prec) + _T("立方米"); } return str; //return CString(GetName().IsEmpty() ? _T("") : (GetName() + _T(" ")) + TypeConvert::d2s(GetV() * 10e-9, &prec) + _T("立方米")); } double AecDbPoolCell::GetV() const { double a(GetA()), w(GetW()), l(GetL()), r(GetR()), h(GetH()); if (IsCircle()) return PI * r * r * h; else return w * l * h; return .0; } void AecDbPoolCell::GetKeyPoints(AcGePoint2dArray & ar, const double &dWallT) { ar.removeAll(); double dH(GetH()); if (IsCircle()) { double dR(GetR() + dWallT * .5); ar.append(AcGePoint2d::kOrigin); } else { double dA(GetA()) , dL(GetL() + dWallT * .5) , dW(GetW() + dWallT * .5); AcGeVector2d vt(AcGeVector2d::kXAxis); vt.rotateBy(dA); AcGeVector2d vtN(vt); vtN.rotateBy(PI * .5); vt.normalize(); vtN.normalize(); // 围绕原点生成四个墙 AcGePoint2d pt0(GetPt().convert2d(AcGePlane::kXYPlane)) , pt1(AcGePoint2d::kOrigin) , pt2(AcGePoint2d::kOrigin) , pt3(AcGePoint2d::kOrigin); pt0 -= vt * dL * .5; pt0 += vtN * dW * .5; pt1 = pt0 + vt * dL; pt2 = pt1 - vtN * dW; pt3 = pt2 - vt * dL; ar.append(pt0); ar.append(pt1); ar.append(pt2); ar.append(pt3); } } void AecDbPoolCell::GetSimplyPoolCell(AcDbPolyline *pPoly, const double & dWallT) { AcGePoint2dArray ar(0); GetKeyPoints(ar, dWallT); for (size_t i = 0; i < ar.length(); ++i) { pPoly->addVertexAt((int)i, ar[(int)i]); } pPoly->setClosed(1); }