#include "StdAfx.h" #include "DbPipeFitting.h" #include "DrawDrainChamfer.h" /*============================================================================* * Copyright(c), 1994-2007, Beijing Tangent Engineering Software Co.Ltd. * 作 者: 陈恩涛 * 创建时间: 2010-5-25 * 描 述: 排水倒角 * 归属项目: 给排水 * 历史记录: =============================================================================*/ //*************************************************************************************************** // 排水倒角 //*************************************************************************************************** extern void ResetPipeDir(SSearchPipeList *pListAll); void UpdateChamferLen(double &dChamferLen, bool bRead = true) { CRegProperty regProp(GetRegLocation(), _T("DrainChamfer")); regProp.SetTopRootKey(HKEY_CURRENT_USER); if (bRead) // 读 { if (!regProp.GetValue(_T("ChamferLen"), dChamferLen)) { dChamferLen = 3 * DocGetPScale(); } } else // 写 { regProp.SetValue(_T("ChamferLen"), dChamferLen); } } // 主要用于区分立管与扣弯 bool IsValidLayer(CString &strLayer) { if (strLayer.Compare(LAY_VPIPE_RAIN) == 0 || strLayer.Compare(LAY_VPIPE_DIRT) == 0 || strLayer.Compare(LAY_VPIPE_USELESS) == 0) { return true; } return false; } void FindVPipe(PickSet &ssVPipe, PickSet &ssAll) { TDbPipe *pPipe = NULL; for(long i = 0; i < ssAll.Length(); i++) { Entity ent = ssAll[i]; AcDbObjectId idEnt; acdbGetObjectId(idEnt, ent); acdbOpenObject(pPipe, idEnt, AcDb::kForRead); if (pPipe != NULL) { CString strLayer = pPipe->layer(); if (pPipe->IsVertical() && IsValidLayer(strLayer)) { ssVPipe += ent; } pPipe->close(); } } } // 立管是否共线 bool IsOnSameLine(PickSet &ss) { int nNum = ss.Length(); if (nNum == 0) { return false; } else if (nNum == 1) { return true; } else { Entity ent = ss[0L]; TDbPipe *pPipe = NULL; AcDbObjectId id; acdbGetObjectId(id, ent); AcGePoint3d ptS, ptE; acdbOpenObject(pPipe, id, AcDb::kForRead); if (pPipe != NULL) { pPipe->getStartPoint(ptS); pPipe->getEndPoint(ptE); pPipe->close(); } else { return false; } AcGeVector3d vt = ptE - ptS; for (long i = 1; i < nNum; i++) { Entity ent1 = ss[i]; acdbGetObjectId(id, ent1); AcGePoint3d pt1, pt2; acdbOpenObject(pPipe,id, AcDb::kForRead); if (pPipe != NULL) { pPipe->getStartPoint(pt1); pPipe->getEndPoint(pt2); pPipe->close(); } else { return false; } AcGeVector3d vt1 = pt1 - pt2; pt1.z = 0; ptS.z = 0; if (ptS.distanceTo(pt1) < 1e-3 && vt1.isParallelTo(vt)) { continue; } return false; } } return true; } bool CreatePipeSys(SSearchPipeList *&pListAll, PickSet &ssAll, Entity &entPipe, double &dChamferLen) { // 选择管道 PickSet ss(SS_FREE); RBList rbMask = ads_buildlist( -4, _T(""), -4, _T(""), -4, _T(""), -4, _T(""), -4, _T(""), -4, _T(""), -4, _T("or>"), NULL); int nRet; TCHAR chKey; const TCHAR* pKey = _T("A"); UpdateChamferLen(dChamferLen); if (ss.Length() == 0) { while (true) { INITGET_BEG(0,pKey); nRet = SelectEntities(_T("\n请选择管道{改变倒角长度(A)}<退出>:"), ss, rbMask, pKey, chKey); INITGET_END(); if (nRet == RTNORM) { break; } else if (nRet == RTKWORD) { if (chKey == _T('A') || chKey == _T('a')) { CString strTip; strTip.Format(_T("\n请输入倒角长度(mm)<%.0f>:"), dChamferLen); acedGetReal(strTip, &dChamferLen); UpdateChamferLen(dChamferLen, false); } } else { return false; } } } ssAll += ss; // 搜索立管 PickSet ssVPipe(SS_FREE); FindVPipe(ssVPipe,ss); if (IsOnSameLine(ssVPipe)) // 所有立管共线 { entPipe = ssVPipe[0L]; } else // 存在多个立管或没有立管 { if (SelectEntity(_T("\n请选择排水口<退出>:"), entPipe, rbMask) != RTNORM) { return false; } } // 以排水管道建立管道系统 ss.Free(); ss += entPipe; pListAll = new SSearchPipeList(); if (!SearchSprinkPipeSys(entPipe, NULL, pListAll, ss)) { adsout << _T("\n图中为环状管网请修改后再操作!"); return false; } return true; } bool ModifyPipeSysFlow(SSearchPipeList *&pListAll, Entity &entPipe) { // 修改管道流向 ads_name entHead; if(pListAll->m_lstNode.Length() == 2) { SSearchPipeList *p1 = pListAll->m_lstNode[0]; SSearchPipeList *p2 = pListAll->m_lstNode[1]; if(p1->m_lstNode.Length() >= 1 && p2->m_lstNode.Length() >= 1) { adsout << _T("\n请选择末端排水管道!"); return false; } if(p1->m_lstNode.Length() == 0) acdbGetAdsName(entHead, p1->m_ID); else if(p2->m_lstNode.Length() == 0) acdbGetAdsName(entHead, p2->m_ID); } XPoint ptS, ptE, ptLoc; GetPipePoint(entPipe, ptS, ptE); OPENOBJ_BEGIN(entHead, AcDb::kForRead, TDbPipeNode, pNode); if(pNode != NULL) { XPoint ptS2 = ptS; XPoint ptE2 = ptE; ptS2.z = 0; ptE2.z = 0; ptLoc = pNode->GetLocation(); ptLoc.z = 0; //先把主管线流向给纠正 OPENOBJ_BEGIN(entPipe, AcDb::kForWrite, TDbPipe, pPipe); if(pPipe != NULL) { if(ptLoc == ptS2) { pPipe->SetFlowDir(TPipeSys::kFromEnd); } else if(ptLoc == ptE2) { pPipe->SetFlowDir(TPipeSys::kFromStart); } } OPENOBJ_END(); } OPENOBJ_END(); //再把系统其他管线流向都纠正 ResetPipeDir(pListAll); return true; } //主命令函数 void DrainChamfer() { SSearchPipeList *pListAll = NULL; PickSet ssAll(SS_FREE); Entity entPipe; //排水管 double dChamferLen = 0.0; //倒角长度 if (CreatePipeSys(pListAll, ssAll, entPipe, dChamferLen)) // 建立管道系统 { if (ModifyPipeSysFlow(pListAll, entPipe)) // 修改管道流向 { // 生成倒角 CDrawDrainChamfer drawChamfer; drawChamfer.MakeChamfer(pListAll, ssAll, dChamferLen); } delete pListAll; } }