#include "stdafx.h" #include "AecDbVenDoghouse.h" #include "AecDbEarthWorm.h" extern AcGePoint3d MidPoint(const AcGePoint3d& pt1,const AcGePoint3d& pt2); ACRX_DXF_DEFINE_MEMBERS (AecDbVenDoghouse, AecDbPortRoom, AcDb::kDHL_CURRENT, AcDb::kMReleaseCurrent, AcDbProxyEntity::kNoOperation | AcDbProxyEntity::kDisableProxyWarning, AEC_VENDOGHOUSE, "AecDbVenDoghouse" "|Product Desc: shanghua earthworm app obj" "|Company: shanghua inc" "|WEB Address: www.shanghuasoft.com") AecDbVenDoghouse::AecDbVenDoghouse(void) { memset(&m_fncNode,0,sizeof(EWFnctNode)); m_fncNode.dDistFromPre = AS_MUNIT(8500.0); //分段节点的8.5米位置 m_fncNode.eFnType = kVenDoghouse; //通风口 _tcscpy(m_fncNode.szNodeSpec,_T("通风口")); //口位置 m_fncNode.fNodeDef[0] = AS_MUNITF(800.0f); //沿管廊方向内长 m_fncNode.fNodeDef[1] = AS_MUNITF(800.0f); //管廊断面方向内宽 m_fncNode.fNodeDef[2] = AS_MUNITF(2050.0f); //口1 左室定位尺寸,左对齐 m_fncNode.fNodeDef[3] = AS_MUNITF(500.0f); //口2 左室定位尺寸,左对齐 m_fncNode.fNodeDef[4] = AS_MUNITF(500.0f); //口3 左室定位尺寸,左对齐 m_fncNode.fNodeDef[5] = 0.0f; //结束 _tcscpy(m_fncNode.szNodeDefSpec,_T("通风口")); //房子描述尺寸 //房子描述尺寸 m_fncNode.fNodeDef[10] = AS_MUNITF(1300.0f);//房子左室定位尺寸,左对齐 m_fncNode.fNodeDef[11] = AS_MUNITF(250.0f); //墙厚 m_fncNode.fNodeDef[12] = AS_MUNITF(8600.0f);//横向室内宽度, m_fncNode.fNodeDef[13] = AS_MUNITF(2200.0f);//房子高度 m_fncNode.fNodeDef[14] = AS_MUNITF(4200.0f);//房子和通风井总高度 m_fncNode.fNodeDef[15] = AS_MUNITF(2500.0f);//房子纵向内长, m_fncNode.fNodeDef[16] = 0.0f;//n室(旧). 改为->新的方式 如 23.0f 为第2,3 舱室加 m_fncNode.fNodeDef[17] = AS_MUNITF(1800.0f);//房子出风口宽度: m_fncNode.fNodeDef[18] = AS_MUNITF(9000.0f);//房子伸出距离 X: m_fncNode.fNodeDef[19] = 0.0f; //通风巷道布置方向 m_fncNode.fNodeDef[20] = AS_MUNITF(1300.0f);//百叶窗总高 m_fncNode.fNodeDef[21] = AS_MUNITF(1800.0f);//百叶窗总高 m_fncNode.fNodeDef[23] = AS_MUNITF(250.0f); //墙厚 m_fncNode.fNodeDef[24] = AS_MUNITF(1000.0f);//门宽 m_fncNode.fNodeDef[25] = AS_MUNITF(2100.0f);//门高 m_fncNode.fNodeDef[26] = AS_MUNITF(600.0f);//位置 m_fncNode.fNodeDef[30] = 0.0f; //0 扶梯 1直梯 m_fncNode.fNodeDef[31] = AS_MUNITF(20.0f); //扶梯钢管直径 m_fncNode.fNodeDef[32] = AS_MUNITF(500.0f); //扶梯宽度 m_fncNode.fNodeDef[33] = AS_MUNITF(300.0f); //扶梯间距 m_fncNode.fNodeDef[34] = AS_MUNITF(180.0f); //扶梯踏脚伸出长度 m_fncNode.fNodeDef[35] = AS_MUNITF(120.0f); //扶梯固入墙纵向深 m_fncNode.fNodeDef[36] = AS_MUNITF(250.0f); //扶梯固入墙横向长 m_bShareDoubleHouse = false; } AecDbVenDoghouse::~AecDbVenDoghouse(void) { } Acad::ErrorStatus AecDbVenDoghouse::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 AecDbVenDoghouse::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 AecDbVenDoghouse::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 AecDbVenDoghouse::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 AecDbVenDoghouse::Draw2d(AcGiDraw &dc) const { if ( Acad::eOk == AecDbPortRoom::Draw2d(dc)) { return Acad::eOk; } return Acad::eOk; } Adesk::Boolean AecDbVenDoghouse::IsDraw2dByBlock() const { return Adesk::kTrue; } Acad::ErrorStatus AecDbVenDoghouse::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); //_T("RECT:3900x3600|2900x3600|400x300|EXT:...");//EXT为扩充字段 AcGePoint2d ptEWOIW = arSizeDatas.last(); /* memset(&m_fncNode,0,sizeof(EWFnctNode)); m_fncNode.dDistLen = AS_MUNIT(8500.0); //分段节点的8.5米位置 m_fncNode.eFnType = kVenDoghouse; //通风口 _tcscpy(m_fncNode.szNodeSpec,_T("通风口")); //口位置 m_fncNode.fNodeDef[0] = AS_MUNITF(800.0f); //沿管廊方向内长 m_fncNode.fNodeDef[1] = AS_MUNITF(800.0f); //管廊断面方向内宽 m_fncNode.fNodeDef[2] = AS_MUNITF(2050.0f); //口1 左室定位尺寸,左对齐 m_fncNode.fNodeDef[3] = AS_MUNITF(500.0f); //口2 左室定位尺寸,左对齐 m_fncNode.fNodeDef[4] = AS_MUNITF(500.0f); //口3 左室定位尺寸,左对齐 m_fncNode.fNodeDef[5] = 0.0f; //结束 _tcscpy(m_fncNode.szNodeDefSpec,_T("通风口")); //房子描述尺寸 m_fncNode.fNodeDef[10] = AS_MUNITF(1300.0f);//房子左室定位尺寸,左对齐 m_fncNode.fNodeDef[11] = AS_MUNITF(250.0f); //墙厚 m_fncNode.fNodeDef[12] = AS_MUNITF(4450.0f);//横向宽度, m_fncNode.fNodeDef[13] = AS_MUNITF(2200.0f);//房子高度 m_fncNode.fNodeDef[14] = AS_MUNITF(4200.0f);//房子和通风井高度 m_fncNode.fNodeDef[15] = AS_MUNITF(1800.0f);//房子纵向内宽, fncNode.fNodeDef[16] = 0.0f;//n室(旧). 改为->新的方式 如 23.0f 为第2,3 舱室加 m_fncNode.fNodeDef[17] = AS_MUNITF(1800.0f);//房子出风口 m_fncNode.fNodeDef[18] = AS_MUNITF(9000.0f);//房子伸出距离X m_fncNode.fNodeDef[19] = 0.0f; //通风巷道布置方向 */ //int nRoomOutIndex = (int)( m_fncNode.fNodeDef[16] + 0.5f); int nRoomOutIndex = (int)( m_fncNode.fNodeDef[19] + 0.5f); const ERoom& room1 = arRooms.first(); const ERoom& room2 = arRooms.last(); AcGeVector3d vtDirX = room1.ptGe[1] - room1.ptGe[0]; vtDirX.normalize(); AcGePoint3d ptPos; if (nRoomOutIndex == 0) { ptPos = room1.ptGe[3]; //左上角点 ptPos.z += ptThick.x; ptPos += vtDir * m_fncNode.dDistFromPre; //ptPos += vtDirX * m_fncNode.fNodeDef[10]; } else { ptPos = room2.ptGe[2]; //右上角点 ptPos.z += ptThick.x; ptPos += vtDir * m_fncNode.dDistFromPre; //ptPos -= vtDirX * m_fncNode.fNodeDef[10]; vtDirX.negate(); } Acad::ErrorStatus es = Acad::eOk; AcDb3dSolid* pHouse = NULL; //创建一个带屋顶的房子,屋顶有开口 double dL = m_fncNode.fNodeDef[15]; double dW = m_fncNode.fNodeDef[12]; double dH = m_fncNode.fNodeDef[13]; double dT = m_fncNode.fNodeDef[11]; double dX = m_fncNode.fNodeDef[18] + m_fncNode.fNodeDef[10] + ptEWOIW.x;//伸出 double dXW = m_fncNode.fNodeDef[17] + 2.0 * dT;//房子出风口 AcGePoint3d ptNew = ptPos; pHouse = CreateHouse(ptNew,dL,dW,dH,dT,dT,dX,dXW,vtDirXY,vtDirX,true); //通风井 ptNew.z += dH; dL = m_fncNode.fNodeDef[17] + 2.0 * dT; dW = m_fncNode.fNodeDef[17] + 2.0 * dT; dH = m_fncNode.fNodeDef[14] - m_fncNode.fNodeDef[13]; AcDb3dSolid* pHouseH = CreateHouse(ptNew,dL,dW,dH,dT,dT,0.0,0.0,vtDirXY,vtDirX,false); if (pHouseH != NULL) { MakeVerSection2d(pHouseH); if ( Acad::eOk != pHouse->booleanOper(AcDb::kBoolUnite,pHouseH) ) { DELETE_PTR(pHouseH); } } //开通风口 AcGePoint3d ptGeH = ptNew; ptGeH += vtDirXY * dT; ptGeH += vtDirX * dT; dL = m_fncNode.fNodeDef[17]; dW = m_fncNode.fNodeDef[17]; ptGeH.z -= 1.5 * dT; AcDb3dSolid* pSolidHole = AecDbEarthWorm::NewXBox(ptGeH,dL,dW,2.0 * dT,vtDir,vtDirX); if (pSolidHole != NULL) { if ( Acad::eOk != pHouse->booleanOper(AcDb::kBoolSubtract,pSolidHole) ) { DELETE_PTR(pSolidHole); } } //绘制顶部百叶 AcGePoint3d ptGe = ptNew; ptGe.z += dH; DrawBWindow(ptGe,vtDirX,vtDirXY); //绘制爬梯 ptGe.z -= m_fncNode.fNodeDef[14]; ptGe += 0.5 * (dW + dT) * vtDirXY; ptGe += dT * vtDirX; AcDbVoidPtrArray arr; DrawCatLadder(ptGe,vtDirXY,vtDirX,m_fncNode.fNodeDef[14],AS_MUNITF(500.f),arr); Add3DBuffer(arr); //DrawCatLadder(ptGe,vtDirXY,vtDirX,m_fncNode.fNodeDef[14],AS_MUNITF(500.f),m_ar3DDrableBufPtrs); if (pHouse != NULL) { Add3DBuffer(pHouse); //m_ar3DDrableBufPtrs.append(pHouse); } return Acad::eOk; } AcDb3dSolid* AecDbVenDoghouse::CreateHouse(AcGePoint3d& ptLB,double dL,double dW,double dH,double dT,double dHT,double dX,double dXW, const AcGeVector3d& vtDirL,const AcGeVector3d& vtDirW,bool bHasRoof) const { int nPts = 7; AcGePoint3d ptGe[7],ptGe4,ptGeFloor[7]; if (dX > 0.001) { ptGe[0] = ptLB; ptGe[1] = ptGe[0] + vtDirW * dW; ptGe[2] = ptGe[1] + vtDirL * dL; ptGe[3] = ptGe[2] - vtDirW * (dW + dX); ptGe[4] = ptGe[3] - vtDirL * dXW; ptGe[5] = ptGe[4] + vtDirW * dX; ptGe[6] = ptGe[0]; nPts = 7; ptGe4 = ptGe[4]; if (m_bShareDoubleHouse )//通风井靠左 { ptGe[0] = ptLB; ptGe[0] += vtDirL * dL; ptGe[1] = ptGe[0] + vtDirW * dW; ptGe[2] = ptGe[1] - vtDirL * dL; ptGe[3] = ptGe[2] - vtDirW * (dW + dX); ptGe[4] = ptGe[3] + vtDirL * dXW; ptGe[5] = ptGe[4] + vtDirW * dX; ptGe[6] = ptGe[0]; nPts = 7; ptGe4 = ptGe[3]; } } else { ptGe[0] = ptLB; ptGe[1] = ptGe[0] + vtDirW * dW; ptGe[2] = ptGe[1] + vtDirL * dL; ptGe[3] = ptGe[2] - vtDirW * dW; ptGe[4] = ptGe[0]; nPts = 5; ptGe4 = ptGe[4]; } AcDbLine* pLn = NULL; for (int i = 0;i < nPts - 1;i++) { pLn = new AcDbLine(ptGe[i],ptGe[i+1]); AddToSection2dDraw(pLn,0); } memcpy(ptGeFloor,ptGe,sizeof(AcGePoint3d) * 7); AcDbRegion* pInsReg = NULL; AcDb3dSolid* pOutSolid = NULL; AcDb3dSolid* pInsSolid = NULL; AcDbRegion* pOutReg = AecDbEarthWorm::CreatePolygonRegionOnly(ptGe,nPts); if (pOutReg != NULL) { if (nPts == 7) { if ( m_bShareDoubleHouse )//通风井靠左) { //offset ptGe[0] -= vtDirL * dT; ptGe[0] += vtDirW * dT; ptGe[1] -= vtDirL * dT; ptGe[1] -= vtDirW * dT; ptGe[2] += vtDirL * dT; ptGe[2] -= vtDirW * dT; ptGe[3] += vtDirL * dT; ptGe[3] += vtDirW * dT; ptGe[4] -= vtDirL * dT; ptGe[4] += vtDirW * dT; ptGe[5] -= vtDirL * dT; ptGe[5] += vtDirW * dT; ptGe[6] -= vtDirL * dT; ptGe[6] += vtDirW * dT; } else { ptGe[0] += vtDirL * dT; ptGe[0] += vtDirW * dT; ptGe[1] += vtDirL * dT; ptGe[1] -= vtDirW * dT; ptGe[2] -= vtDirL * dT; ptGe[2] -= vtDirW * dT; ptGe[3] -= vtDirL * dT; ptGe[3] += vtDirW * dT; ptGe[4] += vtDirL * dT; ptGe[4] += vtDirW * dT; ptGe[5] += vtDirL * dT; ptGe[5] += vtDirW * dT; ptGe[6] += vtDirL * dT; ptGe[6] += vtDirW * dT; } } else { ptGe[0] += vtDirL * dT; ptGe[0] += vtDirW * dT; ptGe[1] += vtDirL * dT; ptGe[1] -= vtDirW * dT; ptGe[2] -= vtDirL * dT; ptGe[2] -= vtDirW * dT; ptGe[3] -= vtDirL * dT; ptGe[3] += vtDirW * dT; ptGe[4] = ptGe[0]; } for (int i = 0;i < nPts - 1;i++) { pLn = new AcDbLine(ptGe[i],ptGe[i+1]); AddToSection2dDraw(pLn,0); } pInsReg = AecDbEarthWorm::CreatePolygonRegionOnly(ptGe,nPts); if (pInsReg != NULL) { AcDbLine ln; ln.setStartPoint(ptLB); AcGePoint3d ptEnd = ptLB; ptEnd.z += dH; ln.setEndPoint(ptEnd); Acad::ErrorStatus es; pOutSolid = new AcDb3dSolid; if ( Acad::eOk == (es = pOutSolid->extrudeAlongPath(pOutReg,&ln) ) ) { AcGePoint3d ptCen = MidPoint(ptGe[1],ptGe[0]); ln.setStartPoint(ptGe[0]); ptEnd = ptGe[0]; if (bHasRoof) ptEnd.z += (dH - dT); else ptEnd.z += dH; ln.setEndPoint(ptEnd); pInsSolid = new AcDb3dSolid; if ( Acad::eOk == (es = pInsSolid->extrudeAlongPath(pInsReg,&ln) ) ) { if ( Acad::eOk == ( es = pOutSolid->booleanOper(AcDb::kBoolSubtract,pInsSolid) ) ) { MakeVerSection2d(pOutSolid,ptCen); MakeVerSection2d(pOutSolid); if (bHasRoof) { //楼板厚度普遍在80~100mm之间,取90 ln.setStartPoint(ptGeFloor[0]); ln.setEndPoint(ptGeFloor[0] - AS_MUNIT(90.0) * AcGeVector3d::kZAxis); AcDb3dSolid* pSolidFloor = new AcDb3dSolid; if ( Acad::eOk == ( es = pSolidFloor->extrudeAlongPath(pOutReg,&ln) ) ) { if (Acad::eOk == ( es = pOutSolid->booleanOper(AcDb::kBoolUnite,pSolidFloor) ) ) { } } } ptLB = ptGe4; return pOutSolid; } } } } } if ( pInsReg != NULL) DELETE_PTR(pInsReg); if ( pOutSolid != NULL) DELETE_PTR(pOutSolid); if ( pInsSolid != NULL) DELETE_PTR(pInsSolid); if ( pOutReg != NULL) DELETE_PTR(pOutReg); return NULL; } Acad::ErrorStatus AecDbVenDoghouse::DrawBWindow(const AcGePoint3d& ptGe,const AcGeVector3d& vtDirX,const AcGeVector3d& vtDirXY) const { AcGeVector3d vtDirHor = vtDirX.orthoProject(AcGeVector3d::kZAxis); double dOutL = m_fncNode.fNodeDef[17]; if (dOutL < 0.01f) dOutL = m_fncNode.fNodeDef[15]; double dExt = AS_MUNIT(20.0);//屋檐 double dCap = dOutL + 2 * m_fncNode.fNodeDef[11] + 2 * dExt;//屋顶宽 double dH = AS_MUNIT(1000.0);//高度 double dThick = AS_MUNIT(20.0);//屋顶厚度 double dPageW = AS_MUNIT(20.0);//百叶宽度 //4个柱子,侧面百叶 AcGePoint3d ptPos = ptGe; ptPos -= dExt * vtDirHor; double dL = dCap; double dW = dCap; ptPos.z += dH; AcDb3dSolid* pCap = AecDbEarthWorm::NewXBox(ptPos,dL,dW,dThick,vtDirHor,vtDirXY); if (pCap != NULL) { Add3DBuffer(pCap); //m_ar3DDrableBufPtrs.append(pCap); } AcGePoint3d ptTmp = ptGe; //柱子1 dL = m_fncNode.fNodeDef[11]; dW = m_fncNode.fNodeDef[11]; AcDb3dSolid* pCol1 = AecDbEarthWorm::NewXBox(ptTmp,dL,dW,dH,vtDirHor,vtDirXY); if (pCol1 != NULL) { Add3DBuffer(pCol1); //m_ar3DDrableBufPtrs.append(pCol1); } //柱子2 ptTmp += (dOutL + m_fncNode.fNodeDef[11]) * vtDirHor; AcDb3dSolid* pCol2 = AecDbEarthWorm::NewXBox(ptTmp,dL,dW,dH,vtDirHor,vtDirXY); if (pCol2 != NULL) { Add3DBuffer(pCol2); //m_ar3DDrableBufPtrs.append(pCol2); } //柱子3 ptTmp = ptGe; ptTmp += (dOutL + m_fncNode.fNodeDef[11]) * vtDirXY; AcDb3dSolid* pCol3 = AecDbEarthWorm::NewXBox(ptTmp,dL,dW,dH,vtDirHor,vtDirXY); if (pCol3 != NULL) { Add3DBuffer(pCol3); //m_ar3DDrableBufPtrs.append(pCol3); } //柱子4 ptTmp += (dOutL + m_fncNode.fNodeDef[11]) * vtDirHor; AcDb3dSolid* pCol4 = AecDbEarthWorm::NewXBox(ptTmp,dL,dW,dH,vtDirHor,vtDirXY); if (pCol4 != NULL) { Add3DBuffer(pCol4); //m_ar3DDrableBufPtrs.append(pCol4); } //百叶... int nCount = (int)(dH / dPageW + 0.5); return Acad::eOk; }