#include "stdafx.h" #include "BaseHoleOperation.h" #include "BaseHoleDlg.h" #include "SelectBlkDlg.h" #include "dbxutil.h" #include "DbEquipment.h" #include #include "TBaseHoleLableEdJig.h" #include "HydrantSetting.h" #include CBaseHoleOperation::CBaseHoleOperation() { m_bLabel = FALSE; m_bDimLabel = FALSE; m_nDist = 0; m_pArc = NULL; m_bArcWall = FALSE; } CBaseHoleOperation::~CBaseHoleOperation() { if (m_pArc != NULL) { delete m_pArc; } } XPoint CBaseHoleOperation::Mid(XPoint ptStart, XPoint ptEnd) { XPoint ptCenter ; ptCenter.x = (ptStart.x + ptEnd.x)/2; ptCenter.y = (ptStart.y + ptEnd.y)/2; ptCenter.z = (ptStart.z + ptEnd.z)/2; return ptCenter; } void CBaseHoleOperation::RunBaseHole(CBaseHoleDlg &baseHoleDlg) { //是否添加标注 m_bLabel = FALSE; //是否添加尺寸标注 m_bDimLabel = FALSE; while(TRUE) { m_bLabel =TRUE; RBList rbMask = ads_buildlist(RTDXF0, _T("LINE"), NULL); Entity entBaseLine , entWall; int nRet; TCHAR chKey = _T('\0'); const TCHAR* pKey = _T("F"); INITGET_BEG(0,pKey); nRet = SelectEntity(_T("\n请选择基准线[选择消火栓(F)]<自由布置>:"), entBaseLine, m_ptBaseLine, rbMask, pKey, chKey); INITGET_END(); #if (ADS == 19) if (chKey == _T('\0')) { TCHAR szCh[20]; acedGetInput(szCh); chKey = szCh[0]; } #endif acdbUcs2Wcs(m_ptBaseLine,m_ptBaseLine,false); m_ptBaseLine = asPnt3d(m_ptBaseLine); if (nRet == RTNORM) { // cet 2010.5.19 add 因m_ptBaseLine可能不在基准线上导致基础洞位置有误,故将m_ptBaseLine投影到基准线上 AcDbObjectId idBaseLine; acdbGetObjectId(idBaseLine, entBaseLine); AcDbLine *pLine = NULL; acdbOpenObject(pLine, idBaseLine, AcDb::kForRead); if (pLine == NULL) { continue; } pLine->getClosestPointTo(m_ptBaseLine, m_ptBaseLine, Adesk::kTrue); pLine->close(); if (acedGetInt(_T("\n请输入基础洞距基准线距离<退出>:"), &m_nDist) != RTNORM) { continue; } m_bDimLabel = TRUE; RBList rbMask2 = ads_buildlist(RTDXF0, _T("ATS_WALL"), NULL); if(SelectEntity(_T("\n请选择墙体<退出>"), entWall, rbMask2) != RTNORM) break; //基准线是否与墙体相邻 if (!IsInWall(entBaseLine, entWall)) { continue; } //创建基础洞 CreateBaseHole(baseHoleDlg, entWall, entBaseLine); } else if (nRet == RTERROR) { m_bDimLabel = FALSE; RBList rbMask2 = ads_buildlist(RTDXF0, _T("ATS_WALL"), NULL); if(SelectEntity1(_T("\n请选择墙线<退出>"), entWall, m_ptWallLine, rbMask2) != RTNORM) break; acdbUcs2Wcs(m_ptWallLine,m_ptWallLine,false); // m_ptWallLine = asPnt3d(m_ptWallLine); cet 2009.12.21 del //创建基础洞 CreateBaseHole(baseHoleDlg,entWall, entBaseLine); } else if (nRet == RTKWORD) { baseHoleDlg.ShowWindow(SW_HIDE); //为消火栓添加基础洞 if (chKey == _T('F') || chKey == _T('f')) { std::map mapEnt; SelectHydrant(mapEnt); if (mapEnt.size() == 1) //选择单个消火栓 { AcDbObjectId idWall, idHydrant; idHydrant = mapEnt.begin()->first; idWall = mapEnt.begin()->second; AddHoleToHydrant(idWall, idHydrant); } else if (!mapEnt.empty()) //当选择多个消火栓时 { TCHAR szSelChar[10]; int nStatus = acedGetString(0, _T("\n是否按消火栓箱高度精确开洞[Y/N]:"), szSelChar); if (nStatus == RTCAN) { continue; } else if (nStatus == RTNORM) { if (szSelChar[0] == 'Y' || szSelChar[0] == 'y') { AddBaseHoleByBatch(mapEnt); } else if (szSelChar[0] == 'N' || szSelChar[0] == 'n') { AddHoleToHydrant(mapEnt); //统一开大小相同的基础洞 } else if (szSelChar[0] == '\0') //默认操作 { AddBaseHoleByBatch(mapEnt); } } } } m_bDimLabel = FALSE; m_bLabel = FALSE; baseHoleDlg.ShowWindow(SW_SHOW); } else { m_bDimLabel = FALSE; m_bLabel = FALSE; break; } //添加标注 if (m_bLabel) { AddLabel(baseHoleDlg, m_ptWallLine); } //添加尺寸标注 if (m_bDimLabel) { if (m_bArcWall) { addArcLabel(); } else { AddDimLabel(m_ptBaseLine, m_ptWallLine, m_nDist); } } } } void CBaseHoleOperation::SelectHydrant(std::map &mapEnt) { RBList rbMask(RTDXF0, _T("ATS_EQUIPMENT"), 8, LAY_EQUIP_HYDRANT, NULL); PickSet ss(SS_FREE); if(SelectEntities(_T("\n请选择消火栓<退出>"), ss, rbMask) != RTNORM) { return; } PickSet ssInWall(SS_FREE); for(long i = 0; i < ss.Length(); i++) { Entity ent = ss[i]; IsInWall(ent, mapEnt); } } void CBaseHoleOperation::AddLabel(XPoint ptIns, double dAngle, LPCTSTR pszText) { if (pszText == NULL) { return; } TDbSymbMultiLeader *pLeader = new TDbSymbMultiLeader; if (pLeader != NULL) { XPointList lstVertexes; lstVertexes.Append(new XPoint(ptIns)); pLeader->SetLeaderVertexes(lstVertexes); pLeader->SetLeaderPoint(ptIns); pLeader->SetLayoutRotation(Ucs2Wcs(0.0)); pLeader->SetArrow(TDbSymbMultiLeader::kNone); pLeader->SetTextAlign(TDbSymbMultiLeader::kAtStart); AcDbObjectId idTextStyle = InitTwtTextStyle(g_csTwtDimStyle); pLeader->SetTextStyleId(idTextStyle); pLeader->SetTextLayerId(InitLayer(LAY_TEXT)); pLeader->SetTextHeight(g_nVPipeHeight); pLeader->SetTextBaseLen(pLeader->GetDefaultTextBaseLen() + 2); pLeader->SetText1(pszText); TLeaderEdJig jig(pLeader); jig.SetOperCode(TLeaderEdJig::kLeader); jig.SetPrompt(_T("\n输入引线位置<退出>: ")); if(jig.DoIt()==RTNORM) { lstVertexes.Reset(); lstVertexes.Append(new XPoint(ptIns)); pLeader->SetLeaderVertexes(lstVertexes); pLeader->AddToCSpace(Adesk::kFalse); pLeader->setLayer(LAY_VPIPE_DIM); pLeader->close(); } else { delete pLeader; pLeader = NULL; return; } } return; } Adesk::Boolean CBaseHoleOperation::AddLabel(CBaseHoleDlg &baseHoleDlg, XPoint ptStart) { TDbSymbMultiLeader *pLeader = new TDbSymbMultiLeader; if (pLeader != NULL) { XPointList lstVertexes; lstVertexes.Append(new XPoint(ptStart)); pLeader->SetLeaderVertexes(lstVertexes); pLeader->SetLeaderPoint(ptStart); pLeader->SetLayoutRotation(Ucs2Wcs(0.0)); pLeader->SetArrow(TDbSymbMultiLeader::kNone); pLeader->SetTextAlign(TDbSymbMultiLeader::kAtStart); AcDbObjectId idTextStyle = InitTwtTextStyle(g_csTwtDimStyle); pLeader->SetTextStyleId(idTextStyle); pLeader->SetTextLayerId(InitLayer(LAY_TEXT)); pLeader->SetTextHeight(g_nVPipeHeight); pLeader->SetTextBaseLen(pLeader->GetDefaultTextBaseLen()); pLeader->SetText1(baseHoleDlg.getSuperscript()); pLeader->SetText2(baseHoleDlg.getSubscript()); TBaseHoleLabelEdJig jig(pLeader); jig.SetDlgPtr(&baseHoleDlg); jig.SetOperCode(TLeaderEdJig::kLeader); jig.SetPrompt(_T("\n输入引线位置<退出>: ")); if(jig.DoIt()==RTNORM) { lstVertexes.Reset(); lstVertexes.Append(new XPoint(ptStart)); pLeader->SetLeaderVertexes(lstVertexes); pLeader->AddToCSpace(Adesk::kFalse); pLeader->setLayer(LAY_VPIPE_DIM); pLeader->close(); } else { delete pLeader; return Adesk::kFalse; } } return Adesk::kTrue; } void CBaseHoleOperation::AddDimLabel(XPoint ptStart, XPoint ptEnd, int dBaseLineDist) { double m_dScale = 2.0; TDbDimension2* pDim = new TDbDimension2; pDim->setLayer(InitLayer(LAY_DIM)); pDim->SetPScale(g_nVPipeHeight*20); pDim->SetLocation(ptStart); pDim->SetStyleId(InitDimStyle(DS_LINEAR)); pDim->SetRotation(ads_angle(ptEnd, ptStart)); pDim->SetLayoutRotation(Ucs2Wcs(0.0)); CString sLabel; pDim->AddSegment(ptStart); pDim->AddSegment(ptEnd); sLabel.Format(_T("%d"),dBaseLineDist); pDim->SetTextContent(0,sLabel); double dDist2DimLine = 0.0; pDim->SetDist2DimLine(dDist2DimLine, FALSE); TDimensionEdJig jig(pDim, _T("\n请点取尺寸线位置<退出>:")); jig.m_nFlag=1; if(jig.doIt() != RTNORM){ delete pDim; return; } dDist2DimLine = pDim->GetDist2DimLine(FALSE); AddToModelSpace(pDim, Adesk::kTrue); } void CBaseHoleOperation::CreateBaseHole(CBaseHoleDlg &baseHoleDlg,Entity entWall, Entity entBaseLine) { AcDbObjectId id2d = NULL; CString str = baseHoleDlg.m_strInsBlkName; id2d = GetBlkIdByName(baseHoleDlg.m_strInsBlkName); if (!id2d.isValid()) { return; } TDbOpening *pWin = new TDbOpening(); if (pWin == NULL) return; pWin->m_nIdStyle2d=id2d; pWin->SetKind(TOpeningData::OP_WINDOW); pWin->setLinetype(_T("DASHED")); pWin->InitHardPointerId(); pWin->m_pBayWin = new XBayWindow(); pWin->SetWidth(baseHoleDlg.getHoleWidth()); pWin->SetHeight(baseHoleDlg.getHoleHigh()); //基础洞插入点 XPoint ptInsert; OPENOBJ_BEGIN(entWall, AcDb::kForWrite, TDbWall, pWall); if (pWall != NULL) { //将选取点转化到墙体中心线上对应的一点 XCurveSegment segL,segR; pWall->GetSideCurve(segL,segR); XPoint ptStart, ptEnd; ptStart = Mid(segL.GetStartPoint(), segR.GetStartPoint()); ptEnd = Mid(segL.GetEndPoint(), segR.GetEndPoint()); XCurveSegment segCen(ptStart,ptEnd,segL.GetBulge()); //检查基准线与墙体的位置关系 XPoint ptBaseLineToWall; if (m_bDimLabel) { m_ptWallLine = segCen.MidPoint(); if (pWall->Is(CURVE_ARC)) { AdjustBaseHoleInsPt(entBaseLine, pWall, m_nDist); m_bArcWall = TRUE; } else { segCen.ProjectToMe(m_ptWallLine,ptInsert); segCen.ProjectToMe(m_ptBaseLine, ptBaseLineToWall); AcGeVector3d vtDir = ptInsert - ptBaseLineToWall; vtDir.normalize(); m_ptWallLine = ptBaseLineToWall + vtDir * m_nDist; m_ptBaseLine = ptBaseLineToWall; } ptInsert = m_ptWallLine; } segCen.ProjectToMe(m_ptWallLine,ptInsert); //检查选取的墙体上的经变化后是否仍在墙上 BOOL bFlag = FALSE; if (m_bArcWall) //弧墙 { IsInArcWall(bFlag, entBaseLine, pWall, baseHoleDlg); } else //直墙 { if (ptInsert.Distance(segCen.MidPoint()) <= ptStart.Distance(segCen.MidPoint())) { bFlag = FALSE; } } //检验待插入基础洞的宽度 if (ptStart.Distance(ptInsert) < baseHoleDlg.getHoleWidth() / 2 || ptEnd.Distance(ptInsert) < baseHoleDlg.getHoleWidth() /2 || bFlag) { adsout << _T("\n不能插到该墙上(宽度超出墙体或基准线距离过短)!"); delete pWin; m_bDimLabel = FALSE; m_bLabel = FALSE; } else { pWin->SetLocation(ptInsert); pWin->SetSill(baseHoleDlg.getBottomHigh()); if (pWall->Is(CURVE_ARC)) { pWin->SetKind(TOpeningData::OP_HOLE); pWin->m_nIdStyle2d = NULL; } if(pWall->CanInsertOpening(*pWin)) { pWin->SetWallId(pWall->objectId()); //设置旋转角度 pWin->SetRotation(segCen.Direction(ptInsert)); pWin->InitHardPointerId(); pWin->AddToMSpace(Adesk::kFalse); pWin->setLayer(InitLayer(LAY_TWT_HOLE)); pWall->assertWriteEnabled(); pWall->AddOpeningId(pWin->objectId()); pWin->close(); } else { adsout << _T("\n不能插到该墙上(门窗高度或宽度方向超出墙体)!"); delete pWin; m_bDimLabel = FALSE; m_bLabel = FALSE; } } } OPENOBJ_END(); } //弧墙时调整基准线上的选取点和基础洞插入点位置 void CBaseHoleOperation::AdjustBaseHoleInsPt(Entity entBaseLine , TDbWall *pWall, int nDist) { if (pWall != NULL) { XCurveSegment segL, segR; pWall->GetSideCurve(segL, segR); AcGePoint3d ptCir = segL.GetArc().GetCenterPt(); double dRadius = (segL.GetArc().GetRadius() + segR.GetArc().GetRadius()) / 2; double dStartAngle = segL.GetArc().GetStarAngle(); double dEndAngle = segL.GetArc().GetEndAngle(); AcGePoint3d ptBaseLineIns; AcGePoint3d ptNearToBaseLine; AcGePoint3d ptInsert; AcDbArc *pArc = new AcDbArc(ptCir, dRadius, dStartAngle, dEndAngle); if (pArc != NULL) { OPENOBJ_BEGIN(entBaseLine, AcDb::kForRead, AcDbLine, pLine); if (pLine != NULL) { AcGePoint3dArray arPt; pLine->intersectWith(pArc, AcDb::kExtendArg, arPt); if (arPt.length() > 0) { ptBaseLineIns = arPt[0]; AcGePoint3d pt1, pt2; AcGePoint3d ptStart, ptEnd; pArc->getStartPoint(ptStart); pArc->getEndPoint(ptEnd); pLine->getClosestPointTo(ptStart, AcGeVector3d::kZAxis, pt1); pLine->getClosestPointTo(ptEnd, AcGeVector3d::kZAxis, pt2); BOOL bNearToStartPt = FALSE; if (ptStart.distanceTo(pt1) < ptEnd.distanceTo(pt2)) { ptNearToBaseLine = ptStart; bNearToStartPt = TRUE; } else { ptNearToBaseLine = ptEnd; bNearToStartPt = FALSE; } double dArcLen = 0.0; pArc->getDistAtPoint(ptEnd, dArcLen); double dlen = nDist - ptNearToBaseLine.distanceTo(ptBaseLineIns); if (bNearToStartPt)//与弧线起点重合 { pArc->getPointAtDist(dlen, ptInsert); pArc->getPointAtDist(nDist / 2 -ptNearToBaseLine.distanceTo(ptBaseLineIns), m_ptMid); } else { pArc->getPointAtDist(dArcLen - dlen, ptInsert); pArc->getPointAtDist(dArcLen - nDist / 2 + ptNearToBaseLine.distanceTo(ptBaseLineIns), m_ptMid); } m_ptWallLine = ptInsert; m_ptBaseLine = ptBaseLineIns; m_pArc = pArc; } } OPENOBJ_END(); } } } void CBaseHoleOperation::addArcLabel() { // 已经取得标注弧 XArc ar(m_ptBaseLine, m_ptMid, m_ptWallLine); InitLayer(LAY_DIM, TRUE); TDbDimension2 dim; XCurveSegment segDim; segDim=ar; XPushVar osmode1(_T("OSMODE"),(OS_PER|OS_INT|OS_END)); TDbDimension2 *pDim=&dim; pDim->setLayer(LAY_DIM); pDim->SetStyleId(InitDimStyle(DS_ANGLE)); pDim->SetDist2DimLine(-6.0); XPoint ptFix; ads_polar(segDim.GetStartPoint(), segDim.IDirection(0)-PI/2, 2.0*DocGetPScale(), ptFix); pDim->SetLocation(ptFix); pDim->SetRotation(segDim.IDirection(0)); pDim->SetAngular(TRUE); pDim->SetDimArcLen(TRUE); pDim->SetObjRadius(ar.GetRadius()); pDim->SetDimRadius(ar.GetRadius()+8.0*DocGetPScale()); XArc arDimLine=ar; arDimLine.SetRadius(arDimLine.GetRadius() + 8.0*DocGetPScale()); pDim->AppendSegment(arDimLine.GetLength()); TDimensionEdJig jig(pDim, _T("\n请点取尺寸线位置<退出>: ")); jig.m_nFlag=1; jig.doIt(); int nRetCode=jig.GetRetCode(); if(nRetCode!=RTNORM) return; if(pDim->IsValid() && jig.GetRetCode()!=RTCAN) { TDbDimension2 *pDimNew=(TDbDimension2 *)pDim->clone(); ASSERT(pDimNew); pDimNew->AddToCSpace(Adesk::kTrue); } } void CBaseHoleOperation::IsInArcWall(BOOL &bFlag, Entity entBaseLine, TDbWall *pWall, CBaseHoleDlg &baseHoleDlg) { AcGePoint3dArray arPt; BOOL bNearToStartPt = FALSE; AcGePoint3d ptStart, ptEnd; double dLen = 0; //弧墙距基准线距离 if (pWall != NULL) { OPENOBJ_BEGIN(entBaseLine, AcDb::kForRead, AcDbLine, pLine); if (pLine != NULL) { AcGePoint3d pt1, pt2; m_pArc->getStartPoint(ptStart); m_pArc->getEndPoint(ptEnd); XCurveSegment segL , segR; pWall->GetSideCurve(segL,segR); AcGePoint3d ptS, ptE; pLine->getClosestPointTo(segL.StartPoint(), ptS); pLine->getClosestPointTo(segL.EndPoint(), ptE); dLen = ptS.distanceTo(segL.StartPoint()) < ptE.distanceTo(segL.EndPoint()) ? ptS.distanceTo(segL.StartPoint()) : ptE.distanceTo(segL.EndPoint()); } OPENOBJ_END(); } else { bFlag = TRUE; return; } double dArcLen ; m_pArc->getDistAtPoint(ptEnd, dArcLen); //是否基础洞超出弧墙 if ((dLen + dArcLen - baseHoleDlg.getHoleWidth() / 2) >= m_nDist &&(dLen + baseHoleDlg.getHoleWidth() / 2) <= m_nDist) { bFlag = FALSE; return; } else { bFlag = TRUE; return; } } BOOL CBaseHoleOperation::IsInWall(Entity &entBaseLine, Entity &entWall) { BOOL bFlag = FALSE; OPENOBJ_BEGIN(entWall, AcDb::kForWrite, TDbWall, pWall); if (pWall) { OPENOBJ_BEGIN(entBaseLine, AcDb::kForRead, AcDbLine, pLine); if (pLine != NULL) { AcGePoint3d ptStart ,ptEnd; ptStart = pWall->StartPoint(); ptEnd = pWall->EndPoint(); AcGePoint3d ptStoLine, ptEtoLine; pLine->getClosestPointTo(ptStart,ptStoLine); pLine->getClosestPointTo(ptEnd, ptEtoLine); if (ptEtoLine.distanceTo(ptEnd) < 1E-3 || ptStoLine.distanceTo(ptStart) < 1E-3) { bFlag = TRUE; } else { bFlag = FALSE; } } OPENOBJ_END(); } OPENOBJ_END(); return bFlag; } BOOL CBaseHoleOperation::IsInWall(Entity &ent, std::map &mapEnt) { PickSet ssSel(SS_FREE); XPoint ptIns; AcDbObjectId idH = NULL, idW = NULL; AcGePoint3d ptOnHydrant1, ptOnHydrant2; AcGePoint3d ptGeLB ,ptGeLT, ptGeRB, ptGeRT; OPENOBJ_BEGIN(ent, AcDb::kForRead, TDbEquipment, pEqu); if (pEqu) { idH = pEqu->objectId(); AcGeVector3d vtX = AcGeVector3d::kXAxis; AcGeVector3d vtY; ptIns = pEqu->GetLocation(); AcGeScale3d sca = pEqu->GetInsertScale(); double dAngle = pEqu->GetAngle(); vtX.rotateBy(dAngle,AcGeVector3d::kZAxis); vtY = vtX; vtY.rotateBy(PI/2,AcGeVector3d::kZAxis); const double dDist = 100; ptGeLB = ptIns - vtX * (sca.sx + dDist) / 2; ptGeLB = ptGeLB - vtY * (sca.sy + dDist) / 2; ptGeLT = ptGeLB + vtY * (sca.sy + dDist); ptGeRB = ptGeLB + vtX * (sca.sx + dDist); ptGeRT = ptGeRB + vtY * (sca.sy + dDist); ptOnHydrant1 = ptGeLB + vtX * dDist / 2 + vtY * dDist / 2; ptOnHydrant2 = ptGeLT - vtY * dDist + vtX * dDist / 2 + vtY * dDist / 2 ; } OPENOBJ_END(); //RBList rbFilter = acutBuildList(RTDXF0, _T("ATS_WALL"), 8, LAY_WALL,NULL); zxl 2013.07.23 modify 干掉图层 RBList rbFilter = acutBuildList(RTDXF0, _T("ATS_WALL"), NULL); TADSGePoint3d _pt1 = Wcs2Ucs(ptGeLB) , _pt2 = Wcs2Ucs(ptGeLT) , _pt3 = Wcs2Ucs(ptGeRT) , _pt4 = Wcs2Ucs(ptGeRB); RBList rbPt = acutBuildList(RTPOINT,&_pt1,RTPOINT,&_pt2,RTPOINT,&_pt3, RTPOINT,&_pt4,NULL); acedSSGet(_T("CP"),rbPt,NULL,rbFilter,ssSel); if (ssSel.Length() > 0) { Entity entWall; for (long i = 0; i < ssSel.Length(); i++) { entWall = ssSel[i]; OPENOBJ_BEGIN(entWall, AcDb::kForRead, TDbWall, pWall); if (pWall != NULL) { idW = pWall->objectId(); XCurveSegment segL, segR; pWall->GetSideCurve(segL,segR); if (IsIn2Line(segL, segR, ptOnHydrant1) && IsIn2Line(segL, segR, ptOnHydrant2)) { mapEnt.insert(std::make_pair(idH, idW)); } } OPENOBJ_END(); } return TRUE; } return FALSE; } // 为消火栓添加基础洞 void CBaseHoleOperation::AddHoleToHydrant(std::map &mapEnt) { std::map::iterator iter; for (iter = mapEnt.begin(); iter != mapEnt.end(); iter++) { AcDbObjectId idHydrant, idWall; idHydrant = iter->first; idWall = iter->second; XPoint ptIns; //基础洞插入点 BOOL bFlag = FALSE; // 判断操作是否正确 double dHoleWidth = 0.0; //洞宽 const double dHoleHigh = 1000.0; //洞高 double dBottomHigh = 0.0; //底高 OPENOBJ_BEGIN(idHydrant, AcDb::kForRead, TDbEquipment, pEquip); if (pEquip) { ptIns = pEquip->GetLocation(); AcGeScale3d sca = pEquip->GetInsertScale(); dHoleWidth = fabs(sca.sx); dBottomHigh = ptIns.z; bFlag = TRUE; } OPENOBJ_END(); AcDbObjectId id2d = NULL; XString xsBlk; LoadDwbBlock(_T("TWTSYS"), _T("00000513"), xsBlk); id2d = GetBlkIdByName(xsBlk); if (!id2d.isValid()) { return; } TDbOpening *pWin = new TDbOpening(); if (pWin == NULL) return; pWin->m_nIdStyle2d=id2d; pWin->SetKind(TOpeningData::OP_WINDOW); pWin->setLinetype(_T("DASHED")); pWin->InitHardPointerId(); pWin->m_pBayWin = new XBayWindow(); pWin->SetWidth(dHoleWidth); pWin->SetHeight(dHoleHigh); if (bFlag) { OPENOBJ_BEGIN(idWall, AcDb::kForWrite, TDbWall, pWall); if (pWall) { //将选取点转化到墙体中心线上对应的一点 XCurveSegment segL,segR; pWall->GetSideCurve(segL,segR); XPoint ptStart , ptEnd; ptStart = Mid(segL.GetStartPoint(), segR.GetStartPoint()); ptEnd = Mid(segL.GetEndPoint(), segR.GetEndPoint()); XCurveSegment segCen(ptStart,ptEnd,segL.GetBulge()); segCen.ProjectToMe(ptIns, ptIns); pWin->SetLocation(ptIns); pWin->SetSill(dBottomHigh); if (pWall->Is(CURVE_ARC)) { pWin->SetKind(TOpeningData::OP_HOLE); pWin->m_nIdStyle2d = NULL; } if(pWall->CanInsertOpening(*pWin)) { pWin->SetWallId(pWall->objectId()); //设置旋转角度 pWin->SetRotation(segCen.Direction(ptIns)); pWin->InitHardPointerId(); pWin->AddToMSpace(Adesk::kFalse); pWin->setLayer(InitLayer(LAY_TWT_HOLE)); pWall->assertWriteEnabled(); pWall->AddOpeningId(pWin->objectId()); pWin->close(); } else { adsout << _T("\n不能插到该墙上(门窗高度或宽度方向超出墙体)!"); delete pWin; m_bDimLabel = FALSE; m_bLabel = FALSE; } } else { delete pWin; pWin = NULL; } OPENOBJ_END() } else { delete pWin; pWin = NULL; } } } void CBaseHoleOperation::AddBaseHole(AcDbObjectId idWall, XPoint ptIns, double dWidth, double dHeight, double dBottomHeight) { if (!idWall.isValid()) { return; } AcDbObjectId id2d = AcDbObjectId::kNull; XString xsBlk; LoadDwbBlock(_T("TWTSYS"), _T("00000513"), xsBlk); id2d = GetBlkIdByName(xsBlk); if (!id2d.isValid()) { return; } TDbOpening *pWin = new TDbOpening(); if (pWin == NULL) { return; } pWin->m_nIdStyle2d=id2d; pWin->SetKind(TOpeningData::OP_WINDOW); pWin->setLinetype(_T("DASHED")); pWin->InitHardPointerId(); pWin->m_pBayWin = new XBayWindow(); pWin->SetWidth(dWidth); pWin->SetHeight(dHeight); TDbWall *pWall = NULL; acdbOpenObject(pWall, idWall, AcDb::kForWrite); if (pWall != NULL) { //将选取点转化到墙体中心线上对应的一点 XCurveSegment segL,segR; pWall->GetSideCurve(segL,segR); XPoint ptStart , ptEnd; ptStart = Mid(segL.GetStartPoint(), segR.GetStartPoint()); ptEnd = Mid(segL.GetEndPoint(), segR.GetEndPoint()); XCurveSegment segCen(ptStart,ptEnd,segL.GetBulge()); segCen.ProjectToMe(ptIns, ptIns); pWin->SetLocation(ptIns); pWin->SetSill(dBottomHeight); if (pWall->Is(CURVE_ARC)) { pWin->SetKind(TOpeningData::OP_HOLE); pWin->m_nIdStyle2d = NULL; } if(pWall->CanInsertOpening(*pWin)) { pWin->SetWallId(pWall->objectId()); //设置旋转角度 pWin->SetRotation(segCen.Direction(ptIns)); pWin->InitHardPointerId(); pWin->AddToMSpace(Adesk::kFalse); pWin->setLayer(InitLayer(LAY_TWT_HOLE)); pWall->assertWriteEnabled(); pWall->AddOpeningId(pWin->objectId()); pWin->close(); } else { adsout << _T("\n不能插到该墙上(门窗高度或宽度方向超出墙体)!"); delete pWin; m_bDimLabel = FALSE; m_bLabel = FALSE; } pWall->close(); } else { delete pWin; pWin = NULL; } } void CBaseHoleOperation::AddHoleToHydrant(AcDbObjectId idWall, AcDbObjectId idHydrant) { if (!idHydrant.isValid() || !idWall.isValid()) { return; } TDbEquipment *pEquip = NULL; acdbOpenObject(pEquip, idHydrant, AcDb::kForRead); if (pEquip != NULL) { AcGeScale3d sca = pEquip->GetInsertScale(); double dHydrantWidth = fabs(sca.sx); AcGeVector3d vtr = Ucs2Wcs(AcGeVector3d::kXAxis); vtr.rotateBy(pEquip->GetAngle(), Ucs2Wcs(AcGeVector3d::kZAxis)); BOOL bIsMirrorByY = pEquip->IsMirrorByY(); if (bIsMirrorByY) { vtr = -vtr; } XPoint ptIns; //基础洞插入点 ptIns = pEquip->GetLocation(); double dWidth = 0.0, dHeight = 0.0, dBottmHeight = 0.0; //基础洞的宽度,高度,底高 double dAngle = 0.0; BOOL bHydrantType = FALSE; //消火栓类型是否为平接 double dLen = pEquip->GetPipeLength(); pEquip->close(); if (fabs(dLen) < 1e-6) { bHydrantType = TRUE; } if (bHydrantType) //消火栓类型是水平接 { if (fabs(dHydrantWidth - 500) < 1e-6) { ptIns += vtr * (750 - 500 - 15 - 15) / 2; dWidth = 750; dHeight = 680; dBottmHeight = ptIns.z - 15; AddBaseHole(idWall, ptIns, dWidth, dHeight, dBottmHeight); AddLabel(ptIns, dAngle); } else if (fabs(dHydrantWidth - 650) < 1e-6) { ptIns += vtr * (900 - 650 - 15 - 15) / 2; dWidth = 900; dHeight = 830; dBottmHeight = ptIns.z - 15; AddBaseHole(idWall, ptIns, dWidth, dHeight, dBottmHeight); AddLabel(ptIns, dAngle); } else if (fabs(dHydrantWidth - 700) < 1e-6) { int nHeight = 0; int nStatus = acedGetInt(_T("\n请输入水平接消火栓箱的高度[1600/1700/1800]<1800>:"), &nHeight); if (nStatus == RTCAN) { return; } else if (nStatus == RTNORM) { if (nHeight == 1600) { ptIns += vtr * (950 - 700 - 15 - 15) / 2; dWidth = 950; dHeight = 1630; dBottmHeight = ptIns.z - 15; AddBaseHole(idWall, ptIns, dWidth, dHeight, dBottmHeight); AddLabel(ptIns, dAngle); } else if (nHeight == 1700) { ptIns += vtr * (950 - 700 - 15 - 15) / 2; dWidth = 950; dHeight = 1730; dBottmHeight = ptIns.z - 15; AddBaseHole(idWall, ptIns, dWidth, dHeight, dBottmHeight); AddLabel(ptIns, dAngle); } else if (nHeight == 1800) { ptIns += vtr * (950 - 700 - 15 - 15) / 2; dWidth = 950; dHeight = 1830; dBottmHeight = ptIns.z - 15; AddBaseHole(idWall, ptIns, dWidth, dHeight, dBottmHeight); AddLabel(ptIns, dAngle); } } else if (nStatus == RTNONE) { ptIns += vtr * (950 - 700 - 15 - 15) / 2; dWidth = 950; dHeight = 1830; dBottmHeight = ptIns.z - 15; AddBaseHole(idWall, ptIns, dWidth, dHeight, dBottmHeight); AddLabel(ptIns, dAngle); } } else if(fabs(dHydrantWidth - 750) < 1e-6) { int nHeight = 0; int nStatus = acedGetInt(_T("\n请输入水平接消火栓箱的高度[1900/2000]<2000>:"), &nHeight); if (nStatus == RTCAN) { return; } else if (nStatus == RTNORM) { if (nHeight == 1900) { ptIns += vtr * (1000 - 750 - 15 - 15) / 2; dWidth = 1000; dHeight = 1930; dBottmHeight = ptIns.z - 15; AddBaseHole(idWall, ptIns, dWidth, dHeight, dBottmHeight); AddLabel(ptIns, dAngle); } else if (nHeight == 2000) { ptIns += vtr * (1000 - 750 - 15 - 15) / 2; dWidth = 1000; dHeight = 2030; dBottmHeight = ptIns.z - 15; AddBaseHole(idWall, ptIns, dWidth, dHeight, dBottmHeight); AddLabel(ptIns, dAngle); } } else if (nStatus == RTNONE) { ptIns += vtr * (1000 - 750 - 15 - 15) / 2; dWidth = 1000; dHeight = 2030; dBottmHeight = ptIns.z - 15; AddBaseHole(idWall, ptIns, dWidth, dHeight, dBottmHeight); AddLabel(ptIns, dAngle); } } else { TCHAR szSelChar[10]; int nStatus = acedGetString(0, _T("\n是否对非标准水平接消火栓箱进行开洞[Y/N]:"), szSelChar); if (nStatus == RTCAN) { return; } else if (nStatus == RTNORM) { if (szSelChar[0] == 'Y' || szSelChar[0] == 'y') { dWidth = dHydrantWidth; dHeight = 1000; dBottmHeight = ptIns.z; AddBaseHole(idWall, ptIns, dWidth, dHeight, dBottmHeight); AddLabel(ptIns, dAngle); } else if (szSelChar[0] == 'N' || szSelChar[0] == 'n') { return; } } } } else //消火栓类型为 上接 { if (fabs(dHydrantWidth - 650) < 1e-6) { int nHeight = 0; int nStatus = acedGetInt(_T("\n请输入上接消火栓箱的高度[800/950]<800>:"), &nHeight); if (nStatus == RTCAN) { return; } else if (nStatus == RTNORM) { if (nHeight == 800) { ptIns += -vtr * (680 - 650 - 15 - 15) / 2; dWidth = 680; dHeight = 1050; dBottmHeight = ptIns.z - (1050 - 800 - 15); AddBaseHole(idWall, ptIns, dWidth, dHeight, dBottmHeight); AddLabel(ptIns, dAngle); } else if (nHeight == 950) { ptIns += -vtr * (680 - 650 - 15 - 15) / 2; dWidth = 680; dHeight = 1200; dBottmHeight = ptIns.z - (1200 - 950 - 15); AddBaseHole(idWall, ptIns, dWidth, dHeight, dBottmHeight); AddLabel(ptIns, dAngle); } } else if (nStatus == RTNONE) { ptIns += -vtr * (680 - 650 - 15 - 15) / 2; dWidth = 680; dHeight = 1050; dBottmHeight = ptIns.z - (1050 - 800 - 15); AddBaseHole(idWall, ptIns, dWidth, dHeight, dBottmHeight); AddLabel(ptIns, dAngle); } } else if (fabs(dHydrantWidth - 700) < 1e-6) { int nHeight = 0; int nStatus = acedGetInt(_T("\n请输入上接消火栓箱的高度[1000/1150/1600/1700/1800]<1000>:"), &nHeight); if (nStatus == RTCAN) { return; } else if (nStatus == RTNORM) { if (nHeight == 1000) { ptIns += -vtr * (730 - 700 - 15 - 15) / 2; dWidth = 730; dHeight = 1250; dBottmHeight = ptIns.z - (1250 - 1000 - 15); AddBaseHole(idWall, ptIns, dWidth, dHeight, dBottmHeight); AddLabel(ptIns, dAngle); } else if (nHeight == 1150) { ptIns += -vtr * (730 - 700 - 15 - 15) / 2; dWidth = 730; dHeight = 1400; dBottmHeight = ptIns.z - (1400 - 1150 - 15); AddBaseHole(idWall, ptIns, dWidth, dHeight, dBottmHeight); AddLabel(ptIns, dAngle); } else if (nHeight == 1600) { ptIns += -vtr * (730 - 700 - 15 - 15) / 2; dWidth = 730; dHeight = 1630; dBottmHeight = ptIns.z - (1630 - 1600 - 15); AddBaseHole(idWall, ptIns, dWidth, dHeight, dBottmHeight); AddLabel(ptIns, dAngle); } else if (nHeight == 1700) { ptIns += -vtr * (730 - 700 - 15 - 15) / 2; dWidth = 730; dHeight = 1730; dBottmHeight = ptIns.z - (1730 - 1700 - 15); AddBaseHole(idWall, ptIns, dWidth, dHeight, dBottmHeight); AddLabel(ptIns, dAngle); } else if (nHeight == 1800) { ptIns += -vtr * (730 - 700 - 15 - 15) / 2; dWidth = 730; dHeight = 1830; dBottmHeight = ptIns.z - (1830 - 1800 - 15); AddBaseHole(idWall, ptIns, dWidth, dHeight, dBottmHeight); AddLabel(ptIns, dAngle); } } else if (nStatus == RTNONE) { ptIns += -vtr * (730 - 700 - 15 - 15) / 2; dWidth = 730; dHeight = 1250; dBottmHeight = ptIns.z - (1250 - 1000 - 15); AddBaseHole(idWall, ptIns, dWidth, dHeight, dBottmHeight); AddLabel(ptIns, dAngle); } } else if (fabs(dHydrantWidth - 750) < 1e-6) { int nHeight = 0; int nStatus = acedGetInt(_T("\n请输入上接消火栓箱的高度[1200/1350/1900]<1200>:"), &nHeight); if (nStatus == RTCAN) { return; } else if (nStatus == RTNORM) { if (nHeight == 1200) { ptIns += -vtr * (780 - 750 - 15 - 15) / 2; dWidth = 780; dHeight = 1450; dBottmHeight = ptIns.z - (1450 - 1200 - 15); AddBaseHole(idWall, ptIns, dWidth, dHeight, dBottmHeight); AddLabel(ptIns, dAngle); } else if (nHeight == 1350) { ptIns += -vtr * (780 - 750 - 15 - 15) / 2; dWidth = 780; dHeight = 1600; dBottmHeight = ptIns.z - (1600 - 1350 - 15); AddBaseHole(idWall, ptIns, dWidth, dHeight, dBottmHeight); AddLabel(ptIns, dAngle); } else if (nHeight == 1900) { ptIns += -vtr * (780 - 750 - 15 - 15) / 2; dWidth = 780; dHeight = 1930; dBottmHeight = ptIns.z - (1930 - 1900 - 15); AddBaseHole(idWall, ptIns, dWidth, dHeight, dBottmHeight); AddLabel(ptIns, dAngle); } } else if (nStatus == RTNONE) { ptIns += -vtr * (780 - 750 - 15 - 15) / 2; dWidth = 780; dHeight = 1450; dBottmHeight = ptIns.z - (1450 - 1200 - 15); AddBaseHole(idWall, ptIns, dWidth, dHeight, dBottmHeight); AddLabel(ptIns, dAngle); } } else { TCHAR szSelChar[10]; int nStatus = acedGetString(0, _T("\n是否对非标准上接消火栓箱进行开洞[Y/N]:"), szSelChar); if (nStatus == RTCAN) { return; } else if (nStatus == RTNORM) { if (szSelChar[0] == 'Y' || szSelChar[0] == 'y') { dWidth = dHydrantWidth; dHeight = 1000; dBottmHeight = ptIns.z; AddBaseHole(idWall, ptIns, dWidth, dHeight, dBottmHeight); AddLabel(ptIns, dAngle); } else if (szSelChar[0] == 'N' || szSelChar[0] == 'n') { return; } } } } } } BOOL CBaseHoleOperation::IsIn2Line(const XCurveSegment &segL, const XCurveSegment &segR, XPoint ptTemp) { XPoint ptPro1, ptPro2; //投影点 segL.ProjectToMe(ptTemp, ptPro1); segR.ProjectToMe(ptTemp, ptPro2); ptPro1.z = ptTemp.z; ptPro2.z = ptTemp.z; double dLen1 = ptPro1.Distance(ptPro2); double dlen2 = ptPro1.Distance(ptTemp) + ptPro2.Distance(ptTemp); if (fabs(dLen1 - dlen2) < 1E-6) { return TRUE; } return FALSE; } void CBaseHoleOperation::AddBaseHoleByBatch(std::map &mapEnt) { CHydrantSetting hydrantSet; std::vector vecId1; //保存水平接消火栓id std::vector vecId2; //保存上接消火栓id //将消火栓分类 hydrantSet.Sort(mapEnt, vecId1, vecId2); //将消火栓根据其宽度排序 std::multimap mapId; //保存排序结果(<宽度,id>)按宽度排序 hydrantSet.Compositor(vecId1, mapId); // 排序 //为水平接消火栓开基础洞 double dB = 500.0; AddBaseHole(mapEnt, mapId, dB); dB = 650.0; AddBaseHole(mapEnt, mapId, dB); dB = 700.0; AddBaseHole(mapEnt, mapId, dB); dB = 750.0; AddBaseHole(mapEnt, mapId, dB); std::map mapTmp; std::vector vecTmp; std::multimap::iterator iter1; std::map::iterator iter2; for (iter1 = mapId.begin(); iter1 != mapId.end(); iter1++) { iter2 = mapEnt.find(iter1->second); if (iter2 != mapEnt.end()) { mapTmp.insert(std::make_pair(iter1->second, iter2->second)); vecTmp.push_back(iter1->second); } } //为上接消火栓开基础洞 mapId.clear(); hydrantSet.Compositor(vecId2, mapId); // 排序 dB = 650.0; AddBaseHole(mapEnt, mapId, dB, FALSE); dB = 700.0; AddBaseHole(mapEnt, mapId, dB, FALSE); dB = 750.0; AddBaseHole(mapEnt, mapId, dB, FALSE); //处理非标准消火栓 if (!mapId.empty()) { for (iter1 = mapId.begin(); iter1 != mapId.end(); iter1++) { iter2 = mapEnt.find(iter1->second); if (iter2 != mapEnt.end()) { mapTmp.insert(std::make_pair(iter1->second, iter2->second)); vecTmp.push_back(iter1->second); } } TCHAR szSelChar[10]; CHydrantSetting hydrantSet; int nColor = 1; hydrantSet.SetHydrantColor(vecTmp, nColor); int nStatus = acedGetString(0, _T("\n是否对非标准消火栓开洞[Y/N]:"), szSelChar); if (nStatus == RTNORM) { if (szSelChar[0] == 'Y' || szSelChar[0] == 'y' || szSelChar[0] == '\0') { AddHoleToHydrant(mapTmp); //统一开大小相同的基础洞 } } hydrantSet.SetHydrantColor(vecTmp, 256); } } void CBaseHoleOperation::AddBaseHoleByBatch(std::map &mapEnt, std::vector &vecId) { if (mapEnt.empty() || vecId.empty()) { return; } TDbEquipment *pEquip = NULL; AcDbObjectId idHydrant = vecId[0]; acdbOpenObject(pEquip, idHydrant, AcDb::kForRead); if (pEquip != NULL) { AcGeScale3d sca = pEquip->GetInsertScale(); double dHydrantWidth = fabs(sca.sx); XPoint ptIns; //基础洞插入点 double dWidth = 0.0, dHeight = 0.0, dBottmHeight = 0.0; //基础洞的宽度,高度,底高 BOOL bHydrantType = FALSE; //消火栓类型是否为平接 double dLen = pEquip->GetPipeLength(); pEquip->close(); if (fabs(dLen) < 1e-6) { bHydrantType = TRUE; } AcDbObjectId idWall = AcDbObjectId::kNull; int nSize = (int)vecId.size(); int i = 0; std::map::iterator iter; if (bHydrantType) //消火栓类型是水平接 { if (fabs(dHydrantWidth - 500) < 1e-6) { dWidth = 750; dHeight = 680; for (i = 0; i < nSize; i++) { idHydrant = vecId[i]; iter = mapEnt.find(idHydrant); if (iter != mapEnt.end()) { idWall = iter->second; getInsertPoint(idHydrant, ptIns); dBottmHeight = ptIns.z - 15; AddBaseHole(idWall, ptIns, dWidth, dHeight, dBottmHeight); } } } else if (fabs(dHydrantWidth - 650) < 1e-6) { dWidth = 900; dHeight = 830; for (i = 0; i < nSize; i++) { idHydrant = vecId[i]; iter = mapEnt.find(idHydrant); if (iter != mapEnt.end()) { idWall = iter->second; getInsertPoint(idHydrant, ptIns); dBottmHeight = ptIns.z - 15; AddBaseHole(idWall, ptIns, dWidth, dHeight, dBottmHeight); } } } else if (fabs(dHydrantWidth - 700) < 1e-6) { int nHeight = 0; int nStatus = acedGetInt(_T("\n请输入水平接消火栓箱的高度[1600/1700/1800]<1800>:"), &nHeight); if (nStatus == RTCAN) { return; } else if (nStatus == RTNORM) { if (nHeight == 1600) { dWidth = 950; dHeight = 1630; for (i = 0; i < nSize; i++) { idHydrant = vecId[i]; iter = mapEnt.find(idHydrant); if (iter != mapEnt.end()) { idWall = iter->second; getInsertPoint(idHydrant, ptIns); dBottmHeight = ptIns.z - 15; AddBaseHole(idWall, ptIns, dWidth, dHeight, dBottmHeight); } } } else if (nHeight == 1700) { dWidth = 950; dHeight = 1730; for (i = 0; i < nSize; i++) { idHydrant = vecId[i]; iter = mapEnt.find(idHydrant); if (iter != mapEnt.end()) { idWall = iter->second; getInsertPoint(idHydrant, ptIns); dBottmHeight = ptIns.z - 15; AddBaseHole(idWall, ptIns, dWidth, dHeight, dBottmHeight); } } } else if (nHeight == 1800) { dWidth = 950; dHeight = 1830; for (i = 0; i < nSize; i++) { idHydrant = vecId[i]; iter = mapEnt.find(idHydrant); if (iter != mapEnt.end()) { idWall = iter->second; getInsertPoint(idHydrant, ptIns); dBottmHeight = ptIns.z - 15; AddBaseHole(idWall, ptIns, dWidth, dHeight, dBottmHeight); } } } } else if (nStatus == RTNONE) { dWidth = 950; dHeight = 1830; for (i = 0; i < nSize; i++) { idHydrant = vecId[i]; iter = mapEnt.find(idHydrant); if (iter != mapEnt.end()) { idWall = iter->second; getInsertPoint(idHydrant, ptIns); dBottmHeight = ptIns.z - 15; AddBaseHole(idWall, ptIns, dWidth, dHeight, dBottmHeight); } } } } else if(fabs(dHydrantWidth - 750) < 1e-6) { int nHeight = 0; int nStatus = acedGetInt(_T("\n请输入水平接消火栓箱的高度[1900/2000]<2000>:"), &nHeight); if (nStatus == RTCAN) { return; } else if (nStatus == RTNORM) { if (nHeight == 1900) { dWidth = 1000; dHeight = 1930; for (i = 0; i < nSize; i++) { idHydrant = vecId[i]; iter = mapEnt.find(idHydrant); if (iter != mapEnt.end()) { idWall = iter->second; getInsertPoint(idHydrant, ptIns); dBottmHeight = ptIns.z - 15; AddBaseHole(idWall, ptIns, dWidth, dHeight, dBottmHeight); } } } else if (nHeight == 2000) { dWidth = 1000; dHeight = 2030; for (i = 0; i < nSize; i++) { idHydrant = vecId[i]; iter = mapEnt.find(idHydrant); if (iter != mapEnt.end()) { idWall = iter->second; getInsertPoint(idHydrant, ptIns); dBottmHeight = ptIns.z - 15; AddBaseHole(idWall, ptIns, dWidth, dHeight, dBottmHeight); } } } } else if (nStatus == RTNONE) { dWidth = 1000; dHeight = 2030; for (i = 0; i < nSize; i++) { idHydrant = vecId[i]; iter = mapEnt.find(idHydrant); if (iter != mapEnt.end()) { idWall = iter->second; getInsertPoint(idHydrant, ptIns); dBottmHeight = ptIns.z - 15; AddBaseHole(idWall, ptIns, dWidth, dHeight, dBottmHeight); } } } } else { TCHAR szSelChar[10]; int nStatus = acedGetString(0, _T("\n是否对非标准水平接消火栓箱进行开洞[Y/N]:"), szSelChar); if (nStatus == RTCAN) { return; } else if (nStatus == RTNORM) { if (szSelChar[0] == 'Y' || szSelChar[0] == 'y') { dWidth = dHydrantWidth; dHeight = 1000; for (i = 0; i < nSize; i++) { idHydrant = vecId[i]; iter = mapEnt.find(idHydrant); if (iter != mapEnt.end()) { idWall = iter->second; getInsertPoint(idHydrant, ptIns); dBottmHeight = ptIns.z; AddBaseHole(idWall, ptIns, dWidth, dHeight, dBottmHeight); } } } else if (szSelChar[0] == 'N' || szSelChar[0] == 'n') { return; } } } } else //消火栓类型为 上接 { if (fabs(dHydrantWidth - 650) < 1e-6) { int nHeight = 0; int nStatus = acedGetInt(_T("\n请输入上接消火栓箱的高度[800/950]<800>:"), &nHeight); if (nStatus == RTCAN) { return; } else if (nStatus == RTNORM) { if (nHeight == 800) { dWidth = 680; dHeight = 1050; for (i = 0; i < nSize; i++) { idHydrant = vecId[i]; iter = mapEnt.find(idHydrant); if (iter != mapEnt.end()) { idWall = iter->second; getInsertPoint(idHydrant, ptIns); dBottmHeight = ptIns.z - (1050 - 800 - 15); AddBaseHole(idWall, ptIns, dWidth, dHeight, dBottmHeight); } } } else if (nHeight == 950) { dWidth = 680; dHeight = 1200; for (i = 0; i < nSize; i++) { idHydrant = vecId[i]; iter = mapEnt.find(idHydrant); if (iter != mapEnt.end()) { idWall = iter->second; getInsertPoint(idHydrant, ptIns); dBottmHeight = ptIns.z - (1200 - 950 - 15); AddBaseHole(idWall, ptIns, dWidth, dHeight, dBottmHeight); } } } } else if (nStatus == RTNONE) { dWidth = 680; dHeight = 1050; for (i = 0; i < nSize; i++) { idHydrant = vecId[i]; iter = mapEnt.find(idHydrant); if (iter != mapEnt.end()) { idWall = iter->second; getInsertPoint(idHydrant, ptIns); dBottmHeight = ptIns.z - (1050 - 800 - 15); AddBaseHole(idWall, ptIns, dWidth, dHeight, dBottmHeight); } } } } else if (fabs(dHydrantWidth - 700) < 1e-6) { int nHeight = 0; int nStatus = acedGetInt(_T("\n请输入上接消火栓箱的高度[1000/1150/1600/1700/1800]<1000>:"), &nHeight); if (nStatus == RTCAN) { return; } else if (nStatus == RTNORM) { if (nHeight == 1000) { dWidth = 730; dHeight = 1250; for (i = 0; i < nSize; i++) { idHydrant = vecId[i]; iter = mapEnt.find(idHydrant); if (iter != mapEnt.end()) { idWall = iter->second; getInsertPoint(idHydrant, ptIns); dBottmHeight = ptIns.z - (1250 - 1000 - 15); AddBaseHole(idWall, ptIns, dWidth, dHeight, dBottmHeight); } } } else if (nHeight == 1150) { dWidth = 730; dHeight = 1400; for (i = 0; i < nSize; i++) { idHydrant = vecId[i]; iter = mapEnt.find(idHydrant); if (iter != mapEnt.end()) { idWall = iter->second; getInsertPoint(idHydrant, ptIns); dBottmHeight = ptIns.z - (1400 - 1150 - 15); AddBaseHole(idWall, ptIns, dWidth, dHeight, dBottmHeight); } } } else if (nHeight == 1600) { dWidth = 730; dHeight = 1630; for (i = 0; i < nSize; i++) { idHydrant = vecId[i]; iter = mapEnt.find(idHydrant); if (iter != mapEnt.end()) { idWall = iter->second; getInsertPoint(idHydrant, ptIns); dBottmHeight = ptIns.z - (1630 - 1600 - 15); AddBaseHole(idWall, ptIns, dWidth, dHeight, dBottmHeight); } } } else if (nHeight == 1700) { dWidth = 730; dHeight = 1730; for (i = 0; i < nSize; i++) { idHydrant = vecId[i]; iter = mapEnt.find(idHydrant); if (iter != mapEnt.end()) { idWall = iter->second; getInsertPoint(idHydrant, ptIns); dBottmHeight = ptIns.z - (1730 - 1700 - 15); AddBaseHole(idWall, ptIns, dWidth, dHeight, dBottmHeight); } } } else if (nHeight == 1800) { dWidth = 730; dHeight = 1830; for (i = 0; i < nSize; i++) { idHydrant = vecId[i]; iter = mapEnt.find(idHydrant); if (iter != mapEnt.end()) { idWall = iter->second; getInsertPoint(idHydrant, ptIns); dBottmHeight = ptIns.z - (1830 - 1800 - 15); AddBaseHole(idWall, ptIns, dWidth, dHeight, dBottmHeight); } } } } else if (nStatus == RTNONE) { dWidth = 730; dHeight = 1250; for (i = 0; i < nSize; i++) { idHydrant = vecId[i]; iter = mapEnt.find(idHydrant); if (iter != mapEnt.end()) { idWall = iter->second; getInsertPoint(idHydrant, ptIns); dBottmHeight = ptIns.z - (1250 - 1000 - 15); AddBaseHole(idWall, ptIns, dWidth, dHeight, dBottmHeight); } } } } else if (fabs(dHydrantWidth - 750) < 1e-6) { int nHeight = 0; int nStatus = acedGetInt(_T("\n请输入上接消火栓箱的高度[1200/1350/1900]<1200>:"), &nHeight); if (nStatus == RTCAN) { return; } else if (nStatus == RTNORM) { if (nHeight == 1200) { dWidth = 780; dHeight = 1450; for (i = 0; i < nSize; i++) { idHydrant = vecId[i]; iter = mapEnt.find(idHydrant); if (iter != mapEnt.end()) { idWall = iter->second; getInsertPoint(idHydrant, ptIns); dBottmHeight = ptIns.z - (1450 - 1200 - 15); AddBaseHole(idWall, ptIns, dWidth, dHeight, dBottmHeight); } } } else if (nHeight == 1350) { dWidth = 780; dHeight = 1600; for (i = 0; i < nSize; i++) { idHydrant = vecId[i]; iter = mapEnt.find(idHydrant); if (iter != mapEnt.end()) { idWall = iter->second; getInsertPoint(idHydrant, ptIns); dBottmHeight = ptIns.z - (1600 - 1350 - 15); AddBaseHole(idWall, ptIns, dWidth, dHeight, dBottmHeight); } } } else if (nHeight == 1900) { dWidth = 780; dHeight = 1930; for (i = 0; i < nSize; i++) { idHydrant = vecId[i]; iter = mapEnt.find(idHydrant); if (iter != mapEnt.end()) { idWall = iter->second; getInsertPoint(idHydrant, ptIns); dBottmHeight = ptIns.z - (1930 - 1900 - 15); AddBaseHole(idWall, ptIns, dWidth, dHeight, dBottmHeight); } } } } else if (nStatus == RTNONE) { dWidth = 780; dHeight = 1450; for (i = 0; i < nSize; i++) { idHydrant = vecId[i]; iter = mapEnt.find(idHydrant); if (iter != mapEnt.end()) { idWall = iter->second; getInsertPoint(idHydrant, ptIns); dBottmHeight = ptIns.z - (1450 - 1200 - 15); AddBaseHole(idWall, ptIns, dWidth, dHeight, dBottmHeight); } } } } else { dWidth = dHydrantWidth; dHeight = 1000; for (i = 0; i < nSize; i++) { idHydrant = vecId[i]; iter = mapEnt.find(idHydrant); if (iter != mapEnt.end()) { idWall = iter->second; getInsertPoint(idHydrant, ptIns); dBottmHeight = ptIns.z; AddBaseHole(idWall, ptIns, dWidth, dHeight, dBottmHeight); } } } } } } BOOL CBaseHoleOperation::getInsertPoint(AcDbObjectId idHydrant, XPoint &ptIns) { if(!idHydrant.isValid()) { return FALSE; } TDbEquipment *pEquip = NULL; acdbOpenObject(pEquip, idHydrant, AcDb::kForRead); if (pEquip != NULL) { AcGeScale3d sca = pEquip->GetInsertScale(); double dHydrantWidth = fabs(sca.sx); //消火栓宽度 AcGeVector3d vtr = Ucs2Wcs(AcGeVector3d::kXAxis); vtr.rotateBy(pEquip->GetAngle(), Ucs2Wcs(AcGeVector3d::kZAxis)); BOOL bIsMirrorByY = pEquip->IsMirrorByY(); if (bIsMirrorByY) { vtr = -vtr; } ptIns = pEquip->GetLocation(); BOOL bHydrantType = FALSE; //消火栓类型是否为平接 double dLen = pEquip->GetPipeLength(); if (fabs(dLen) < 1e-6) { bHydrantType = TRUE; } if (bHydrantType) //消火栓类型是水平接 { if (fabs(dHydrantWidth - 500) < 1e-6) { ptIns += vtr * (750 - 500 - 15 - 15) / 2; } else if (fabs(dHydrantWidth - 650) < 1e-6) { ptIns += vtr * (900 - 650 - 15 - 15) / 2; } else if (fabs(dHydrantWidth - 700) < 1e-6) { ptIns += vtr * (950 - 700 - 15 - 15) / 2; } else if(fabs(dHydrantWidth - 750) < 1e-6) { ptIns += vtr * (1000 - 750 - 15 - 15) / 2; } } else //消火栓类型为 上接 { if (fabs(dHydrantWidth - 650) < 1e-6) { ptIns += -vtr * (680 - 650 - 15 - 15) / 2; } else if (fabs(dHydrantWidth - 700) < 1e-6) { ptIns += -vtr * (730 - 700 - 15 - 15) / 2; } else if (fabs(dHydrantWidth - 750) < 1e-6) { ptIns += -vtr * (780 - 750 - 15 - 15) / 2; } } pEquip->close(); } else { return FALSE; } return TRUE; } void CBaseHoleOperation::AddBaseHole(std::map &mapEnt, std::multimap &mapId, double dB, BOOL bLevelHydrant) { std::vector vec; std::multimap::iterator itr = mapId.begin(); typedef std::multimap::iterator Iterator; std::pair pair; // 查询B = dB 的消火栓 pair = mapId.equal_range(dB); itr = pair.first; for (; itr != pair.second; itr++) { vec.push_back(itr->second); } if (!vec.empty()) { CString strPromt; strPromt.Format(_T("\n是否对B = %.0f"), dB); if (bLevelHydrant) { strPromt += _T("水平接消火栓箱精确开洞[Y/N]:"); } else { strPromt += _T("上接消火栓箱精确开洞[Y/N]:"); } TCHAR szSelChar[10]; CHydrantSetting hydrantSet; int nColor = 1; hydrantSet.SetHydrantColor(vec, nColor); int nStatus = acedGetString(0, strPromt, szSelChar); if (nStatus == RTNORM) { if (szSelChar[0] == 'Y' || szSelChar[0] == 'y') { AddBaseHoleByBatch(mapEnt, vec); } else if (szSelChar[0] == '\0') //默认操作 { AddBaseHoleByBatch(mapEnt, vec); } } mapId.erase(pair.first, pair.second); hydrantSet.SetHydrantColor(vec, 256); acedUpdateDisplay(); actrTransactionManager->flushGraphics(); } }