#include "stdafx.h" #include "AecDbBuriedOutletDoghouse.h" #include "AecDbEarthWorm.h" ACRX_DXF_DEFINE_MEMBERS(AecDbBuriedOutletDoghouse, AecDbPortRoom, AcDb::kDHL_CURRENT, AcDb::kMReleaseCurrent, AcDbProxyEntity::kNoOperation | AcDbProxyEntity::kDisableProxyWarning, AEC_BODOGHOUSE, "AecDbBuriedOutletDoghouse" "|Product Desc: shanghua earthworm app obj" "|Company: shanghua inc" "|WEB Address: www.shanghuasoft.com") AecDbBuriedOutletDoghouse::AecDbBuriedOutletDoghouse(void) { //默认值 EWFnctNode m_m_fncNode; memset(&m_m_fncNode,0,sizeof(EWFnctNode)); m_fncNode.dDistFromPre = AS_MUNIT(5000.0);//5米位置 m_fncNode.eFnType = kBDOutLetHouse; _tcscpy(m_fncNode.szNodeSpec, _T("直埋引出")); _tcscpy(m_fncNode.szNodeDefSpec, _T("水管引出;电缆引出;燃气管引出")); m_fncNode.nRoomIndex = 999;//全部 m_fncNode.fNodeDef[0] = AS_MUNITF(1000.0f);//a m_fncNode.fNodeDef[1] = AS_MUNITF(1000.0f);//b m_fncNode.fNodeDef[2] = AS_MUNITF(500.0f);//c m_fncNode.fNodeDef[3] = AS_MUNITF(9000.0f);//d m_fncNode.fNodeDef[4] = AS_MUNITF(3000.0f);//e m_fncNode.fNodeDef[5] = AS_MUNITF(400.0f);//f //开口 m_fncNode.fNodeDef[9] = 0.0f;//0舱 m_fncNode.fNodeDef[10] = AS_MUNITF(1000.0f);//离内顶距离 m_fncNode.fNodeDef[11] = AS_MUNITF(400.0f);//左侧距离 m_fncNode.fNodeDef[12] = AS_MUNITF(500.0f);//孔直径 m_fncNode.fNodeDef[13] = AS_MUNITF(600.0f);//孔间距 m_fncNode.fNodeDef[14] = 3.0f;//3个 m_fncNode.fNodeDef[15] = -1.0f;//结束 //开口 m_fncNode.fNodeDef[16] = 1.0f;//1舱 m_fncNode.fNodeDef[17] = AS_MUNITF(1000.0f);//离内顶距离 m_fncNode.fNodeDef[18] = AS_MUNITF(500.0f);//左侧距离 m_fncNode.fNodeDef[19] = AS_MUNITF(150.0f);//孔直径 m_fncNode.fNodeDef[20] = AS_MUNITF(200.0f);//孔间距 m_fncNode.fNodeDef[21] = 4.0f;//4个 m_fncNode.fNodeDef[22] = -1.0f;//结束 //开口 m_fncNode.fNodeDef[23] = 2.0f;//2舱 m_fncNode.fNodeDef[24] = AS_MUNITF(1000.0f);//离内顶距离 m_fncNode.fNodeDef[25] = AS_MUNITF(200.0f);//左侧距离 m_fncNode.fNodeDef[26] = AS_MUNITF(800.0f);//孔直径 m_fncNode.fNodeDef[27] = AS_MUNITF(900.0f);//孔间距 m_fncNode.fNodeDef[28] = 2.0f;//3个 m_fncNode.fNodeDef[29] = -1.0f;//结束 } AecDbBuriedOutletDoghouse::~AecDbBuriedOutletDoghouse(void) { } Acad::ErrorStatus AecDbBuriedOutletDoghouse::dwgInFields (AcDbDwgFiler* pFiler) { assertWriteEnabled(); //----- Read parent class information first. Acad::ErrorStatus es = AecDbPortRoom::dwgInFields (pFiler) ; if ( es != Acad::eOk ) return (es) ; return (pFiler->filerStatus ()) ; } Acad::ErrorStatus AecDbBuriedOutletDoghouse::dwgOutFields(AcDbDwgFiler* pFiler) const { assertReadEnabled () ; //----- Save parent class information first. Acad::ErrorStatus es = AecDbPortRoom::dwgOutFields (pFiler) ; if ( es != Acad::eOk ) return (es) ; return (pFiler->filerStatus ()) ; } Acad::ErrorStatus AecDbBuriedOutletDoghouse::dxfInFields (AcDbDxfFiler* pFiler) { assertWriteEnabled(); //----- Read parent class information first. Acad::ErrorStatus es = AecDbPortRoom::dxfInFields (pFiler) ; if ( es != Acad::eOk ) return (es) ; return (pFiler->filerStatus ()) ; } Acad::ErrorStatus AecDbBuriedOutletDoghouse::dxfOutFields(AcDbDxfFiler* pFiler) const { assertReadEnabled () ; //----- Save parent class information first. Acad::ErrorStatus es = AecDbPortRoom::dxfOutFields (pFiler) ; if ( es != Acad::eOk ) return (es) ; return (pFiler->filerStatus ()) ; } Acad::ErrorStatus AecDbBuriedOutletDoghouse::Draw2d(AcGiDraw &dc) const { assertReadEnabled () ; if ( Acad::eOk != AecDbPortRoom::Draw2d(dc)) { //外部图块 } return Acad::eOk; } void AecDbBuriedOutletDoghouse::AddHoles(AcDb3dSolid* pSolidAll,AcGePoint3dArray& arRoomLTPts,const AcGeVector3d& vtDirXY,const AcGeVector3d& vtDirX,const AcGePoint2d& ptSize,int nRooms) const { double dD = 0.0,dH = 0.0; int nFrom = 9,nRoom = 0; AcGePoint3d ptCen,ptCen2; Acad::ErrorStatus es; while(nFrom < 63) { nRoom = (int)( m_fncNode.fNodeDef[nFrom + 0] ); if (nRoom > -1 && nRoom < nRooms) { //m_fncNode.fNodeDef[nFrom + 1];//离内顶距离 //m_fncNode.fNodeDef[nFrom + 2];//左侧距离 //m_fncNode.fNodeDef[nFrom + 3];//孔直径 //m_fncNode.fNodeDef[nFrom + 4];//孔间距 //m_fncNode.fNodeDef[nFrom + 5];//数量 //m_data.fNodeDef[nFrom + 6] = -1.0f//结束 if (m_fncNode.fNodeDef[nFrom + 3] < 0.0001f || m_fncNode.fNodeDef[nFrom + 5] < 0.0001f) { break; } dD = m_fncNode.fNodeDef[nFrom + 3]; dH = m_fncNode.fNodeDef[5]; ptCen = arRoomLTPts.at(nRoom); ptCen += m_fncNode.fNodeDef[nFrom + 2] * vtDirXY; ptCen.z -= m_fncNode.fNodeDef[nFrom + 1]; int nHols = (int)(m_fncNode.fNodeDef[nFrom + 5] + 0.1f); for (int j = 0;j < nHols;j++) { AcDb3dSolid* pSolid1 = AecDbEarthWorm::NewXCylinder(ptCen,dD,dH,vtDirX); ptCen2 = ptCen - vtDirX * ( ptSize.x - dH); AcDb3dSolid* pSolid2 = AecDbEarthWorm::NewXCylinder(ptCen2,dD,dH,vtDirX); if (Acad::eOk == ( es = pSolidAll->booleanOper(AcDb::kBoolSubtract,pSolid1) ) ) { } if (Acad::eOk == ( es = pSolidAll->booleanOper(AcDb::kBoolSubtract,pSolid2) ) ) { } ptCen += vtDirXY * m_fncNode.fNodeDef[nFrom + 4]; } } nFrom += 7; } } Acad::ErrorStatus AecDbBuriedOutletDoghouse::CreateDoghouse(ESection eSecType,const AcGePoint2dArray& arSizeDatas,AcGeLineSeg3d& ln,AecDbEarthWorm* pEW) const { if (pEW == NULL) return Acad::eInvalidInput; //ln和xy面的夹角 AcGeVector3d vtDir = ln.endPoint() - ln.startPoint(); vtDir.normalize(); AcGeVector3d vtDirXY = vtDir.orthoProject(AcGeVector3d::kZAxis); double dAngle = vtDirXY.angleTo(vtDir); //获取每个舱的三维位置 AcGePoint2d ptThick; AcArray arRooms; pEW->GetSectionRooms(eSecType,arSizeDatas,arRooms,ptThick,dAngle); pEW->TransformRegionPerpToLine(arRooms,ln); AcGePoint2d ptSize; pEW->GetWidthAndHeight(eSecType,arSizeDatas,ln,ptSize,true); int nWalls = arRooms.length() - 1; float fSpace = m_fncNode.fNodeDef[3] / (nWalls + 1); fSpace -= m_fncNode.fNodeDef[5]; // AcGePoint3d ptPos; const ERoom& room = arRooms.at(0); AcGeVector3d vtDirX = room.ptGe[1] - room.ptGe[0]; vtDirX.normalize(); ptPos = room.ptGe[3]; ptPos.z += ptThick.x; //到顶面 ptPos -= vtDirX * ptThick.x;//到外面 ptPos += vtDir * m_fncNode.dDistFromPre; //绘制房子 AcDbLine* pLn = NULL; AcDbVoidPtrArray arLnPtrs,arRegPtrs; AcGePoint3d ptGe[8]; /* m_fncNode.fNodeDef[0] = AS_MUNITF(1000.0f);//a m_fncNode.fNodeDef[1] = AS_MUNITF(1000.0f);//b m_fncNode.fNodeDef[2] = AS_MUNITF(500.0f);//c m_fncNode.fNodeDef[3] = AS_MUNITF(9000.0f);//d m_fncNode.fNodeDef[4] = AS_MUNITF(3000.0f);//e m_fncNode.fNodeDef[5] = AS_MUNITF(400.0f);//f */ ptGe[0] = ptPos; ptGe[1] = ptGe[0] + vtDirXY * m_fncNode.fNodeDef[3]; ptGe[2] = ptGe[1] + vtDirX * ptSize.x;//W ptGe[3] = ptGe[0] + vtDirX * ptSize.x; ptGe[4] = ptGe[0]; for (int i = 0;i < 4;i++) { pLn = new AcDbLine(ptGe[i],ptGe[i+1]); pLn->setNormal(AcGeVector3d::kZAxis); arLnPtrs.append(pLn); } Acad::ErrorStatus es; es = AcDbRegion::createFromCurves(arLnPtrs,arRegPtrs); if (arRegPtrs.length() == 0) { return Acad::eOk; } AddToSection2dDraw(arLnPtrs,0); arLnPtrs.removeAll(); AcDbLine lnPath; lnPath.setStartPoint(ptGe[0]); lnPath.setEndPoint(ptGe[0] + m_fncNode.fNodeDef[4] * AcGeVector3d::kZAxis); AcDbRegion* pRegOut = (AcDbRegion*)arRegPtrs.first(); arRegPtrs.removeAll(); AcDb3dSolid* pSolidAll = new AcDb3dSolid; if ( Acad::eOk == ( es = pSolidAll->extrudeAlongPath(pRegOut,&lnPath) ) ) { //减去内部 ptGe[0] += vtDirXY * m_fncNode.fNodeDef[5]; ptGe[0] += vtDirX * m_fncNode.fNodeDef[5]; ptGe[1] -= vtDirXY * m_fncNode.fNodeDef[5]; ptGe[1] += vtDirX * m_fncNode.fNodeDef[5]; ptGe[2] -= vtDirXY * m_fncNode.fNodeDef[5]; ptGe[2] -= vtDirX * m_fncNode.fNodeDef[5]; ptGe[3] += vtDirXY * m_fncNode.fNodeDef[5]; ptGe[3] -= vtDirX * m_fncNode.fNodeDef[5]; ptGe[4] = ptGe[0]; for (int i = 0;i < 4;i++) { pLn = new AcDbLine(ptGe[i],ptGe[i+1]); pLn->setNormal(AcGeVector3d::kZAxis); arLnPtrs.append(pLn); } es = AcDbRegion::createFromCurves(arLnPtrs,arRegPtrs); if (arRegPtrs.length() == 0) { DELETE_PTR(pSolidAll); FreeBuffer(0,arRegPtrs); return Acad::eOk; } AddToSection2dDraw(arLnPtrs,0); arLnPtrs.removeAll(); AcDbRegion* pRegIn = (AcDbRegion*)arRegPtrs.first(); lnPath.setStartPoint(ptGe[0]); lnPath.setEndPoint(ptGe[0] +( m_fncNode.fNodeDef[4] - m_fncNode.fNodeDef[5])* AcGeVector3d::kZAxis); AcDb3dSolid* pSolidInt = new AcDb3dSolid; if ( Acad::eOk == ( es = pSolidInt->extrudeAlongPath(pRegIn,&lnPath) ) ) { if (Acad::eOk == ( es = pSolidAll->booleanOper(AcDb::kBoolSubtract,pSolidInt) ) ) { AcGePoint3d ptLT = ptGe[3]; ptLT.z += ( m_fncNode.fNodeDef[4] - m_fncNode.fNodeDef[5]);//3m - 厚度 AcGePoint3dArray arRoomLTPts; for (int n = 0;n < arRooms.length();n++) { arRoomLTPts.append(ptLT); ptLT += ( fSpace + m_fncNode.fNodeDef[5]) * vtDirXY; } //开孔 AddHoles(pSolidAll,arRoomLTPts,vtDirXY,vtDirX,ptSize,arRooms.length()); //生成纵段2d实体 AcGePoint3d ptCen; Midpoint(ptGe[0],ptGe[3],ptCen); MakeVerSection2d(pSolidAll,ptCen); Midpoint(ptGe[0],ptGe[1],ptCen); MakeVerSection2d(pSolidAll,ptCen); Add3DBuffer(pSolidAll); //m_ar3DDrableBufPtrs.append(pSolidAll); } DELETE_PTR(pRegIn); } DELETE_PTR(pRegOut); } //绘制墙体 double dL = m_fncNode.fNodeDef[5]; double dW = ptSize.x - 2.0 * dL; double dH = m_fncNode.fNodeDef[4] - dL; for (int i = 0;i < nWalls;i++) { ptGe[0] += vtDirXY * fSpace; ptGe[3] += vtDirXY * fSpace; AcDb3dSolid* pWall = AecDbEarthWorm::NewXBox(ptGe[0],dL,dW,dH,vtDirXY,vtDirX); if (pWall != NULL) { MakeVerSection2d(pWall); Add3DBuffer(pWall); //m_ar3DDrableBufPtrs.append(pWall); } ptGe[0] += vtDirXY * dL; ptGe[3] += vtDirXY * dL; } return Acad::eOk; }