#include "stdafx.h" #include "AcDbObjectPtr.h" #include "DbPipe.h" #include "Dbwell.h" #include "Dbpool.h" #include "globalFunc.h" #include "PipeInterCheckDlg.h" #include "AecDbSymbMultiLeader.h" #include "layerdef.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif extern AcDbObjectId InitTextStyle(const TCHAR *pszStyle, AcDbDatabase *pDb = NULL); extern AcDbObjectId InitTextStyle(TTextStyle ts, AcDbDatabase *pDb = NULL); extern AcDbObjectId InitLayer(const TCHAR *szLayer, BOOL bApplyChange = TRUE); extern BOOL SearchOutdoorWell(Entity ent, Entity entEnd, SSearchPipeList *pListAll, PickSet &ssAll, BOOL bFeedSys); extern BOOL GetWellListData2(SSearchPipeList *pListAll, DList &lstWellSys); extern CString GetLayerNames(const TCHAR * szTgSubName); extern void DDX_GroupStatus(CDataExchange* pDX, int nIDC, int& value); static CPipeInterCheckDlg *pDlg = NULL; void CheckPipeInter() { RBList rbMask(RTDXF0, _T("AEC_ZT_PIPE"), 8, GetLayerNames(_T("管线")), NULL); PickSet ss(SS_FREE); int nRet = GlobalFunc::SelectEntities(_T("\n请选择检查范围<整张图>:"), ss, rbMask); if (nRet == RTCAN) { return; } else if (nRet != RTNORM) { ss.Get(_T("X"), NULL, NULL, rbMask); } if (ss.Length() == 0) { return; } CTemporaryResourceOverride vTemp; if (pDlg == NULL) { pDlg = new CPipeInterCheckDlg; pDlg->SetSelectedPipes(ss); pDlg->Create(CPipeInterCheckDlg::IDD, acedGetAcadFrame()); } if (pDlg->HasIntersectPipe()) { pDlg->ShowWindow(SW_SHOW); TCHAR szTmp[32]; ads_getstring(NULL, _T("\n按任意键退出:"), szTmp); } else { ads_printf(_T("\n未发现交叉点!")); } if (pDlg != NULL) { pDlg->DestroyWindow(); delete pDlg; pDlg = NULL; } } ///////////////////////////////////////////////////////////////////////////// // CPipeInterCheckDlg dialog BOOL CPipeInterCheckDlg::m_bGrpSetStatus = false; CPipeInterCheckDlg::CPipeInterCheckDlg(CWnd* pParent /*=NULL*/) : WGroupDlg(CPipeInterCheckDlg::IDD, pParent) { //{{AFX_DATA_INIT(CPipeInterCheckDlg) m_dDownLen = 0.4; m_dSafeDist = 0.0; m_iDimType = 0; m_iDownPipeType = 0; m_iDimPipeNotInter = 0; m_sElevUp = _T(""); m_sElevLow = _T(""); m_iPreWelldDeep = 3; m_bIsVisible = true; m_iCmbType = -1; //}}AFX_DATA_INIT } void CPipeInterCheckDlg::DoDataExchange(CDataExchange* pDX) { WGroupDlg::DoDataExchange(pDX); //{{AFX_DATA_MAP(CPipeInterCheckDlg) DDX_Control(pDX, IDC_COMBO_TYPE, m_cmbPipeType); DDX_Text(pDX, IDC_EDIT_DOWNLEN, m_csDownLen); DDX_Text(pDX, IDC_EDIT_SAFEDIST, m_csSafeDist); DDX_Radio(pDX, IDC_RADIO_DIMTYPE1, m_iDimType); DDX_Radio(pDX, IDC_RADIO_PIPETYPE1, m_iDownPipeType); DDX_Radio(pDX, IDC_RADIO_NOTDIM, m_iDimPipeNotInter); DDX_Text(pDX, IDC_STATIC_ELEV1, m_sElevUp); DDX_Text(pDX, IDC_STATIC_ELEV2, m_sElevLow); DDX_Control(pDX, IDC_STATIC_SET, m_grpSet); DDX_GroupStatus(pDX,IDC_STATIC_SET, m_bGrpSetStatus); DDX_CBIndex(pDX, IDC_COMBO_TYPE, m_iCmbType); if (m_csDownLen.GetLength() > 1) { m_csDownLen.TrimLeft(); m_csDownLen.TrimRight(); m_csDownLen.TrimRight(_T("0")); } m_dDownLen = _tstof(m_csDownLen); if (m_csSafeDist.GetLength() > 1) { m_csSafeDist.TrimLeft(); m_csSafeDist.TrimRight(); m_csSafeDist.TrimRight(_T("0")); } m_dSafeDist = _tstof(m_csSafeDist); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CPipeInterCheckDlg, WGroupDlg) //{{AFX_MSG_MAP(CPipeInterCheckDlg) ON_BN_CLICKED(IDC_RADIO_PIPETYPE1, OnRadioPipetype1) ON_BN_CLICKED(IDC_RADIO_PIPETYPE2, OnRadioPipetype2) ON_BN_CLICKED(IDC_RADIO_PIPETYPE3, OnRadioPipetype3) ON_BN_CLICKED(IDC_RADIO_PIPETYPE4, OnRadioPipetype4) ON_CBN_SELCHANGE(IDC_COMBO_TYPE, OnSelchangeComboType) ON_WM_DESTROY() ON_WM_CLOSE() ON_WM_TIMER() ON_BN_CLICKED(IDC_BTN_QUIT, OnBtnQuit) ON_BN_CLICKED(IDC_BTN_NOTDOWN, OnBtnNotdown) ON_BN_CLICKED(IDC_BTN_DOWN, OnBtnDown) ON_BN_CLICKED(IDC_RADIO_DIMTYPE1, OnRadioDimtype1) ON_BN_CLICKED(IDC_RADIO_DIMTYPE2, OnRadioDimtype2) ON_EN_KILLFOCUS(IDC_EDIT_DOWNLEN, OnKillfocusEditDownlen) ON_EN_KILLFOCUS(IDC_EDIT_SAFEDIST, OnKillfocusEditSafedist) ON_WM_PAINT() ON_BN_CLICKED(IDC_BTN_AUTODOWN, OnBtnAutoDown) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CPipeInterCheckDlg message handlers void CPipeInterCheckDlg::SetSelectedPipes(PickSet ss) { m_ssPipe.Free(); std::multimap mapPipe; for (long l = 0l; l < ss.Length(); l++) { Entity entPipe = ss[l]; OPENOBJ_BEGIN(entPipe, AcDb::kForRead, CDbPipe, pPipe); if(pPipe != NULL) { XPoint pt = pPipe->MidPoint(); mapPipe.insert(std::make_pair(pt.x, entPipe)); } OPENOBJ_END(); } std::multimap::iterator it; for (it = mapPipe.begin(); it != mapPipe.end(); it++) { m_ssPipe += (*it).second; } } bool CPipeInterCheckDlg::HasIntersectPipe() { if (m_mapInterPipeInfo.empty() && m_vecPtUnInter.empty()) { return false; } return true; } double CPipeInterCheckDlg::GetPipeStartEle(Entity entPipe) { double dUnitMeter = 1000; if(GlobalFunc::DocGetMeterUnitDraw()) dUnitMeter = 1; OPENOBJ_BEGIN(entPipe, AcDb::kForRead, CDbPipe, pPipe); if(pPipe != NULL) { AcDbObjectId nodeId1(NULL); double dn = pPipe->GetDnDiameter(); dn = GlobalFunc::GetPipeOutDByDn(pPipe->GetMaterial(), dn); dn = dn / 2000; TPipeSys::FlowDirection dir = pPipe->GetFlowDir(); if(dir == TPipeSys::kFromStart){ return pPipe->StartPoint().z/dUnitMeter - dn; } else { return pPipe->EndPoint().z/dUnitMeter - dn; } } OPENOBJ_END(); return 0; } double CPipeInterCheckDlg::GetPipeThick(Entity& ent) { double dThick = 0.0; CDbPipe *pPipe = NULL; AcDbObjectId ident; acdbGetObjectId(ident, ent); double dDn1 = 0.0; // 外径 double dDn2 = 0.0; // 内径 acdbOpenObject(pPipe, ident, AcDb::kForRead); if (pPipe != NULL) { double dDn = pPipe->GetDnDiameter(); int nMat = pPipe->GetMaterial(); dDn1 = GlobalFunc::GetPipeOutDByDn(nMat, dDn); dDn1 = dDn1 / 1000; CString strMat = GlobalFunc::GetPipeMaterialByIdx(nMat); dDn2 = GlobalFunc::GetPipeDjByDn(strMat, (int)dDn); pPipe->close(); } dThick = (dDn1 - dDn2) / 2; return dThick; } void CPipeInterCheckDlg::InitInterPipeInfo() { m_vecPtUnInter.clear(); m_mapInterPipeInfo.clear(); XPointList lstPtInt; double dUnitMeter = 1000; if(GlobalFunc::DocGetMeterUnitDraw()) dUnitMeter = 1; AcDbObjectId id1, id2; int len = m_ssPipe.Length(); for(long i = 0; i < m_ssPipe.Length(); i++) { Entity ent = m_ssPipe[i]; double nPipeEle(0), nDn(0), nDn2(0), nI(0), nI2(0), nDnPro(0), nDnPro2(0); TPipeSys::SysType sys1, sys2; nPipeEle = GetPipeStartEle(ent); if(fabs(nPipeEle) < 0.001) continue; XPoint ptStart, ptEnd, ptInt, ptWell; CString csMat; OPENOBJ_BEGIN(ent, AcDb::kForRead, CDbPipe, pPipe); if(pPipe != NULL) { id1 = pPipe->id(); int iMaterial = pPipe->GetMaterial(); csMat = GlobalFunc::GetPipeMaterialByIdx(iMaterial); sys1 = pPipe->GetSysType(); ptStart = pPipe->GetStartPoint(); ptEnd = pPipe->GetEndPoint(); nDnPro = pPipe->GetDnDiameter(); nI = pPipe->GetPipeGradient(); TPipeSys::FlowDirection dir = pPipe->GetFlowDir(); if(dir == TPipeSys::kFromStart) ptWell = ptStart; else ptWell = ptEnd; } OPENOBJ_END(); nDn = GlobalFunc::GetPipeOutDByDn(csMat, (int)nDnPro); ptStart.z = 0; ptEnd.z = 0; ptWell.z = 0; AcDbLine line1(ptStart.AsAcGePoint3d(), ptEnd.AsAcGePoint3d()); PickSet ssF(SS_FREE); RBList rbMask(RTDXF0, _T("AEC_ZT_PIPE"), 8, GetLayerNames(_T("管线")), NULL); ADSGePoint3d _ptStart(GlobalFunc::Wcs2Ucs(ptStart)), _ptEnd(GlobalFunc::Wcs2Ucs(ptEnd)); acedSSGet(_T("C"), &_ptStart, &_ptEnd, rbMask, ssF); XPoint ptWell2; for(long j = 0; j < ssF.Length(); j++) { Entity entTmp = ssF[j]; if(entTmp == ent) continue; XPoint pt1, pt2; GlobalFunc::GetPipePoint(entTmp, pt1, pt2); pt1.z = 0; pt2.z = 0; AcDbLine line2(pt1.AsAcGePoint3d(), pt2.AsAcGePoint3d()); AcGePoint3dArray arrPt; line2.intersectWith(&line1, AcDb::kOnBothOperands, arrPt); if (arrPt.length() != 1) { continue; } ptInt = arrPt[0]; XPoint *ptFind = lstPtInt.FindPoint(ptInt); if(ptInt == pt1 || ptInt == pt2 || ptInt == ptStart || ptInt == ptEnd || ptFind != NULL) continue; lstPtInt.NewAppend(ptInt); double nPipeEle1(0), nPipeEle2(0); double nDist2Well1 = ads_distance(ptInt, ptWell) / dUnitMeter; nPipeEle1 = nPipeEle - nDist2Well1*nI; nPipeEle2 = GetPipeStartEle(entTmp); CString csMat2; OPENOBJ_BEGIN(entTmp, AcDb::kForRead, CDbPipe, pPipe); if(pPipe != NULL) { id2 = pPipe->id(); int iMaterial = pPipe->GetMaterial(); csMat2 = GlobalFunc::GetPipeMaterialByIdx(iMaterial); sys2 = pPipe->GetSysType(); ptStart = pPipe->StartPoint(); ptEnd = pPipe->EndPoint(); nI2 = pPipe->GetPipeGradient(); nDnPro2 = pPipe->GetDnDiameter(); TPipeSys::FlowDirection dir = pPipe->GetFlowDir(); if(dir == TPipeSys::kFromStart) ptWell2 = ptStart; else ptWell2 = ptEnd; ptWell2.z = 0; double nDist2Well2 = ads_distance(ptInt, ptWell2) / dUnitMeter; nPipeEle2 = nPipeEle2 - nDist2Well2*nI2; } OPENOBJ_END(); nDn2 = GlobalFunc::GetPipeOutDByDn(csMat2, (int)nDnPro2); BOOL bHasInter2=FALSE; double dPipeEleUp1(0), dPipeEleUp2(0); if(nPipeEle1 < nPipeEle2) { dPipeEleUp1 = nPipeEle1 + nDn; double dDist2Pipe1 = dPipeEleUp1 - nPipeEle2; //底下管子的顶标高和上面管子底标高的距离 double dDist2Pipe2 = nPipeEle1 - nPipeEle2; //底下管子的底标高和上面管子底标高的距离 if(fabs(dDist2Pipe1) < m_dSafeDist || fabs(dDist2Pipe2) < nDn) //1判断2管的距离小于安全距离 bHasInter2 = TRUE; else if(nPipeEle2 > nPipeEle1 && nPipeEle2 < dPipeEleUp1) //2判断上面管子的底标高是否在下面管子内 bHasInter2 = TRUE; } else { dPipeEleUp2 = nPipeEle2 + nDn2; double dDist2Pipe1 = dPipeEleUp2 - nPipeEle1; double dDist2Pipe2 = nPipeEle2 - nPipeEle1; if(fabs(dDist2Pipe1) < m_dSafeDist || fabs(dDist2Pipe2) < nDn2) bHasInter2 = TRUE; else if(nPipeEle1 > nPipeEle2 && nPipeEle1 < dPipeEleUp2) bHasInter2 = TRUE; } if (fabs(nPipeEle1) < 1e-6) { nPipeEle1 = fabs(nPipeEle1); } if (fabs(nPipeEle2) < 1e-6) { nPipeEle2 = fabs(nPipeEle2); } BOOL bIsGravityPipe1(FALSE), bIsGravityPipe2(FALSE); if(sys1 == TPipeSys::kDirtWater || sys1 == TPipeSys::kRainWater || sys1 == TPipeSys::kUselessWater || sys1 == TPipeSys::kOther) bIsGravityPipe1 = TRUE; if(sys2 == TPipeSys::kDirtWater || sys2 == TPipeSys::kRainWater || sys2 == TPipeSys::kUselessWater || sys2 == TPipeSys::kOther) bIsGravityPipe2 = TRUE; InterPipesInfo info; info.ptInter = ptInt; // 标高相同时 降落管选取规则为重力流>压力流。 // 两个均为重力流时 污水>废水>雨水>其他重力流。 // 两个均为压力流的时候任意选择一个管线类型即可。 if (nPipeEle1 > nPipeEle2 || (fabs(nPipeEle1 - nPipeEle2) < 0.001 && ((!bIsGravityPipe1 && bIsGravityPipe2) || (sys2 == TPipeSys::kDirtWater && (sys1 == TPipeSys::kUselessWater || sys1 == TPipeSys::kRainWater || sys1 == TPipeSys::kOther)) || (sys2 == TPipeSys::kUselessWater && (sys1 == TPipeSys::kRainWater || sys1 == TPipeSys::kOther)) || (sys2 == TPipeSys::kRainWater && sys1 == TPipeSys::kOther)))) { info.idLow = id2; info.idUp = id1; info.dElevLow = nPipeEle2; info.dElevUp = nPipeEle1; info.sysLow = sys2; info.sysUp = sys1; info.dDnLow = nDnPro2; info.dDnUp = nDnPro; if(bHasInter2)// 相交需要移动 { ads_name name; acdbGetAdsName(name, id2); Entity ent = name; nPipeEle2 += GetPipeThick(ent); m_mapInterPipeInfo.insert(std::make_pair(nPipeEle2, info)); } else { m_vecPtUnInter.push_back(info); } } else { info.idLow = id1; info.idUp = id2; info.dElevLow = nPipeEle1; info.dElevUp = nPipeEle2; info.sysLow = sys1; info.sysUp = sys2; info.dDnLow = nDnPro; info.dDnUp = nDnPro2; if(bHasInter2)// 相交需要移动 { ads_name name; acdbGetAdsName(name, id1); Entity ent = name; nPipeEle1 += GetPipeThick(ent); m_mapInterPipeInfo.insert(std::make_pair(nPipeEle1, info)); } else { m_vecPtUnInter.push_back(info); } } } } m_itCurPipe = m_mapInterPipeInfo.rbegin(); } void CPipeInterCheckDlg::UpdateInterPipeInfo(const InterPipesInfo infoOld) { Entity ent1, ent2; ads_name name; acdbGetAdsName(name, infoOld.idLow); ent1 = name; acdbGetAdsName(name, infoOld.idUp); ent2 = name; double dUnitMeter = 1000; if(GlobalFunc::DocGetMeterUnitDraw()) dUnitMeter = 1; AcDbObjectId id1, id2; double nPipeEle(0), nDn(0), nDn2(0), nI(0), nI2(0), nDnPro(0), nDnPro2(0); TPipeSys::SysType sys1, sys2; nPipeEle = GetPipeStartEle(ent1); XPoint ptStart, ptEnd, ptInt, ptWell; CString csMat; OPENOBJ_BEGIN(ent1, AcDb::kForRead, CDbPipe, pPipe); if(pPipe != NULL) { id1 = pPipe->id(); int iMaterial = pPipe->GetMaterial(); csMat = GlobalFunc::GetPipeMaterialByIdx(iMaterial); sys1 = pPipe->GetSysType(); ptStart = pPipe->StartPoint(); ptEnd = pPipe->EndPoint(); nDnPro = pPipe->GetDnDiameter(); nI = pPipe->GetPipeGradient(); TPipeSys::FlowDirection dir = pPipe->GetFlowDir(); if(dir == TPipeSys::kFromStart) ptWell = ptStart; else ptWell = ptEnd; } OPENOBJ_END(); nDn = GlobalFunc::GetPipeOutDByDn(csMat, (int)nDnPro); ptInt = infoOld.ptInter; double nPipeEle1(0), nPipeEle2(0); double nDist2Well1 = ads_distance(ptInt, ptWell) / dUnitMeter; nPipeEle1 = nPipeEle - nDist2Well1*nI; nPipeEle2 = GetPipeStartEle(ent2); CString csMat2; OPENOBJ_BEGIN(ent2, AcDb::kForRead, CDbPipe, pPipe); if(pPipe != NULL) { id2 = pPipe->id(); int iMaterial = pPipe->GetMaterial(); csMat2 = GlobalFunc::GetPipeMaterialByIdx(iMaterial); sys2 = pPipe->GetSysType(); ptStart = pPipe->StartPoint(); ptEnd = pPipe->EndPoint(); nI2 = pPipe->GetPipeGradient(); nDnPro2 = pPipe->GetDnDiameter(); TPipeSys::FlowDirection dir = pPipe->GetFlowDir(); XPoint ptWell; if(dir == TPipeSys::kFromStart) ptWell = ptStart; else ptWell = ptEnd; ptWell.z = 0; double nDist2Well2 = ads_distance(ptInt, ptWell) / dUnitMeter; nPipeEle2 = nPipeEle2 - nDist2Well2*nI2; } OPENOBJ_END(); nDn2 = GlobalFunc::GetPipeOutDByDn(csMat2, (int)nDnPro2); BOOL bHasInter2 = FALSE; double dPipeEleUp1(0), dPipeEleUp2(0); if(nPipeEle1 < nPipeEle2) { dPipeEleUp1 = nPipeEle1 + nDn; double dDist2Pipe1 = dPipeEleUp1 - nPipeEle2; //底下管子的顶标高和上面管子底标高的距离 double dDist2Pipe2 = nPipeEle1 - nPipeEle2; //底下管子的底标高和上面管子底标高的距离 if(fabs(dDist2Pipe1) < m_dSafeDist || fabs(dDist2Pipe2) < nDn) //1判断2管的距离小于安全距离 bHasInter2 = TRUE; else if(nPipeEle2 > nPipeEle1 && nPipeEle2 < dPipeEleUp1) //2判断上面管子的底标高是否在下面管子内 bHasInter2 = TRUE; } else { dPipeEleUp2 = nPipeEle2 + nDn2; double dDist2Pipe1 = dPipeEleUp2 - nPipeEle1; double dDist2Pipe2 = nPipeEle2 - nPipeEle1; if(fabs(dDist2Pipe1) < m_dSafeDist || fabs(dDist2Pipe2) < nDn2) bHasInter2 = TRUE; else if(nPipeEle1 > nPipeEle2 && nPipeEle1 < dPipeEleUp2) bHasInter2 = TRUE; } if (fabs(nPipeEle1) < 1e-6) { nPipeEle1 = fabs(nPipeEle1); } if (fabs(nPipeEle2) < 1e-6) { nPipeEle2 = fabs(nPipeEle2); } BOOL bIsGravityPipe1(FALSE), bIsGravityPipe2(FALSE); if(sys1 == TPipeSys::kDirtWater || sys1 == TPipeSys::kRainWater || sys1 == TPipeSys::kUselessWater || sys1 == TPipeSys::kOther) bIsGravityPipe1 = TRUE; if(sys2 == TPipeSys::kDirtWater || sys2 == TPipeSys::kRainWater || sys2 == TPipeSys::kUselessWater || sys2 == TPipeSys::kOther) bIsGravityPipe2 = TRUE; InterPipesInfo info; info.ptInter = ptInt; // 标高相同时 降落管选取规则为重力流>压力流。 // 两个均为重力流时 污水>废水>雨水>其他重力流。 // 两个均为压力流的时候任意选择一个管线类型即可。 if (nPipeEle1 > nPipeEle2 || (fabs(nPipeEle1 - nPipeEle2) < 0.001 && ((!bIsGravityPipe1 && bIsGravityPipe2) || (sys2 == TPipeSys::kDirtWater && (sys1 == TPipeSys::kUselessWater || sys1 == TPipeSys::kRainWater || sys1 == TPipeSys::kOther)) || (sys2 == TPipeSys::kUselessWater && (sys1 == TPipeSys::kRainWater || sys1 == TPipeSys::kOther)) || (sys2 == TPipeSys::kRainWater && sys1 == TPipeSys::kOther)))) { info.idLow = id2; info.idUp = id1; info.dElevLow = nPipeEle2; info.dElevUp = nPipeEle1; info.sysLow = sys2; info.sysUp = sys1; info.dDnLow = nDnPro2; info.dDnUp = nDnPro; if(bHasInter2)// 相交需要移动 { ads_name name; acdbGetAdsName(name, id2); Entity ent = name; nPipeEle2 += GetPipeThick(ent); m_mapInterPipeInfo.insert(std::make_pair(nPipeEle2, info)); } else { m_vecPtUnInter.push_back(info); } } else { info.idLow = id1; info.idUp = id2; info.dElevLow = nPipeEle1; info.dElevUp = nPipeEle2; info.sysLow = sys1; info.sysUp = sys2; info.dDnLow = nDnPro; info.dDnUp = nDnPro2; if(bHasInter2)// 相交需要移动 { ads_name name; acdbGetAdsName(name, id1); Entity ent = name; nPipeEle1 += GetPipeThick(ent); m_mapInterPipeInfo.insert(std::make_pair(nPipeEle1, info)); } else { m_vecPtUnInter.push_back(info); } } } void CPipeInterCheckDlg::ModifyInterPipeInfo() { std::multimap mapInterPipeInfo; std::multimap::iterator itMap; for (itMap = m_mapInterPipeInfo.begin(); itMap != m_mapInterPipeInfo.end(); itMap++) { mapInterPipeInfo.insert(*itMap); } std::vector vecPtUnInter; std::vector::iterator it; for (it = m_vecPtUnInter.begin(); it != m_vecPtUnInter.end(); it++) { vecPtUnInter.push_back(*it); } m_vecPtUnInter.clear(); m_mapInterPipeInfo.clear(); for (itMap = mapInterPipeInfo.begin(); itMap != mapInterPipeInfo.end(); itMap++) { InterPipesInfo infoOld = itMap->second; UpdateInterPipeInfo(infoOld); } for (it = vecPtUnInter.begin(); it != vecPtUnInter.end(); it++) { UpdateInterPipeInfo(*it); } m_itCurPipe = m_mapInterPipeInfo.rbegin(); } void CPipeInterCheckDlg::DrawXLineByPt() { m_idMove = NULL; AcApDocument* pDoc = acDocManager->curDocument(); acDocManager->lockDocument(pDoc, AcAp::kWrite); double nDist1 = 15*GlobalFunc::DocGetPScale(); double nDist2 = 5*GlobalFunc::DocGetPScale(); std::multimap::iterator itMap; for (itMap = m_mapInterPipeInfo.begin(); itMap != m_mapInterPipeInfo.end(); itMap++) { XPoint ptInt = itMap->second.ptInter; XPoint p1, p2, p3, p4; ads_polar(ptInt, -GlobalFunc::Wcs2Ucs(0.0), nDist1, p1); ads_polar(p1, PI/2 - GlobalFunc::Wcs2Ucs(0.0), nDist1, p1); ads_polar(ptInt, PI - GlobalFunc::Wcs2Ucs(0.0), nDist1, p2); ads_polar(p2, PI/2 - GlobalFunc::Wcs2Ucs(0.0), -nDist1, p2); AcDbLine *pLine = new AcDbLine; pLine->setStartPoint(p1); pLine->setEndPoint(p2); pLine->setColorIndex(2); AcDbObjectId id1 = GlobalFunc::AddToModelSpace(pLine, Adesk::kTrue); m_ssLine += id1; ads_polar(ptInt, PI/2 - GlobalFunc::Wcs2Ucs(0.0), nDist1, p3); ads_polar(p3, PI - GlobalFunc::Wcs2Ucs(0.0), nDist1, p3); ads_polar(ptInt, PI/2 - GlobalFunc::Wcs2Ucs(0.0), -nDist1, p4); ads_polar(p4, -GlobalFunc::Wcs2Ucs(0.0), nDist1, p4); AcDbLine *pLine2 = new AcDbLine; pLine2->setStartPoint(p3); pLine2->setEndPoint(p4); pLine2->setColorIndex(2); AcDbObjectId id2 = GlobalFunc::AddToModelSpace(pLine2, Adesk::kTrue); m_ssLine += id2; } std::vector::iterator it; for (it = m_vecPtUnInter.begin(); it != m_vecPtUnInter.end(); it++) { XPoint ptInt = (*it).ptInter; XPoint p1, p2, p3, p4; ads_polar(ptInt, -GlobalFunc::Wcs2Ucs(0.0), nDist2, p1); ads_polar(p1, PI/2 - GlobalFunc::Wcs2Ucs(0.0), nDist2, p1); ads_polar(ptInt, PI - GlobalFunc::Wcs2Ucs(0.0), nDist2, p2); ads_polar(p2, PI/2 - GlobalFunc::Wcs2Ucs(0.0), -nDist2, p2); AcDbLine *pLine = new AcDbLine; pLine->setStartPoint(p1); pLine->setEndPoint(p2); pLine->setColorIndex(1); m_ssLine += GlobalFunc::AddToModelSpace(pLine, Adesk::kTrue); ads_polar(ptInt, PI/2 - GlobalFunc::Wcs2Ucs(0.0), nDist2, p3); ads_polar(p3, PI - GlobalFunc::Wcs2Ucs(0.0), nDist2, p3); ads_polar(ptInt, PI/2 - GlobalFunc::Wcs2Ucs(0.0), -nDist2, p4); ads_polar(p4, -GlobalFunc::Wcs2Ucs(0.0), nDist2, p4); AcDbLine *pLine2 = new AcDbLine; pLine2->setStartPoint(p3); pLine2->setEndPoint(p4); pLine2->setColorIndex(1); m_ssLine += GlobalFunc::AddToModelSpace(pLine2, Adesk::kTrue); } acedUpdateDisplay(); actrTransactionManager->flushGraphics(); acDocManager->unlockDocument(pDoc); } void CPipeInterCheckDlg::SetCurrentDlgData() { AcApDocument* pDoc = acDocManager->curDocument(); acDocManager->lockDocument(pDoc, AcAp::kWrite); m_ssLine.Erase(); m_ssLine.Free(); acedUpdateDisplay(); actrTransactionManager->flushGraphics(); acDocManager->unlockDocument(pDoc); DrawXLineByPt(); m_idMove = NULL; if (m_mapInterPipeInfo.empty()) { SetDlgCtrlStu(); return; } m_itCurPipe= m_mapInterPipeInfo.rbegin(); m_infoPipe = m_itCurPipe->second; ModifyDlgRadioStu(); UpdateData(FALSE); SetCurSelPipe(); } void CPipeInterCheckDlg::SetDimText() { CString sFormat; sFormat.Format(_T("%%s%%.%df"), m_iPreWelldDeep); CString sPipeNameUp = GlobalFunc::GetPipeNameBySys(m_infoPipe.sysUp); CString sPipeNameLow = GlobalFunc::GetPipeNameBySys(m_infoPipe.sysLow); double nPipeEle1 = m_infoPipe.dElevUp; double nPipeEle2 = m_infoPipe.dElevLow; double dDnUp = 0.0; double dDnLow = 0.0; CString csMat; OPENOBJ_BEGIN(m_infoPipe.idUp, AcDb::kForRead, CDbPipe, pPipe); if(pPipe != NULL) { int iMaterial = pPipe->GetMaterial(); csMat = GlobalFunc::GetPipeMaterialByIdx(iMaterial); } OPENOBJ_END(); dDnUp = GlobalFunc::GetPipeOutDByDn(csMat, (int)m_infoPipe.dDnUp); OPENOBJ_BEGIN(m_infoPipe.idLow, AcDb::kForRead, CDbPipe, pPipe); if(pPipe != NULL) { int iMaterial = pPipe->GetMaterial(); csMat = GlobalFunc::GetPipeMaterialByIdx(iMaterial); } OPENOBJ_END(); dDnLow = GlobalFunc::GetPipeOutDByDn(csMat, (int)m_infoPipe.dDnLow); if (m_iDimType == 1) // 外底与外顶标高 { nPipeEle2 += dDnLow; } else // 重力流内底与压力流中心标高 { BOOL bIsGravityPipeLow(FALSE), bIsGravityPipeUp(FALSE); if(m_infoPipe.sysUp == TPipeSys::kDirtWater || m_infoPipe.sysUp == TPipeSys::kRainWater || m_infoPipe.sysUp == TPipeSys::kUselessWater || m_infoPipe.sysUp == TPipeSys::kOther) bIsGravityPipeUp = TRUE; if(m_infoPipe.sysLow == TPipeSys::kDirtWater || m_infoPipe.sysLow == TPipeSys::kRainWater || m_infoPipe.sysLow == TPipeSys::kUselessWater || m_infoPipe.sysLow == TPipeSys::kOther) bIsGravityPipeLow = TRUE; if(!bIsGravityPipeUp) nPipeEle1 += dDnUp/ 2.0; else { ads_name name; acdbGetAdsName(name, m_infoPipe.idUp); Entity ent = name; nPipeEle1 += GetPipeThick(ent); } if(!bIsGravityPipeLow) nPipeEle2 += dDnLow / 2.0; else { ads_name name; acdbGetAdsName(name, m_infoPipe.idLow); Entity ent = name; nPipeEle2 += GetPipeThick(ent); } } if (fabs(nPipeEle1) < 0.001) { nPipeEle1 = 0.0; } if (fabs(nPipeEle2) < 0.001) { nPipeEle2 = 0.0; } m_sElevUp.Format(sFormat, sPipeNameUp, nPipeEle1); m_sElevLow.Format(sFormat, sPipeNameLow, nPipeEle2); } void CPipeInterCheckDlg::ModifyDlgRadioStu() { SetDimText(); CString sPipeNameUp = GlobalFunc::GetPipeNameBySys(m_infoPipe.sysUp); CString sPipeNameLow = GlobalFunc::GetPipeNameBySys(m_infoPipe.sysLow); m_cmbPipeType.ResetContent(); m_cmbPipeType.AddString(sPipeNameLow); m_cmbPipeType.AddString(sPipeNameUp); BOOL bIsGravityPipeLow(FALSE), bIsGravityPipeUp(FALSE); if(m_infoPipe.sysUp == TPipeSys::kDirtWater || m_infoPipe.sysUp == TPipeSys::kRainWater || m_infoPipe.sysUp == TPipeSys::kUselessWater || m_infoPipe.sysUp == TPipeSys::kOther) bIsGravityPipeUp = TRUE; if(m_infoPipe.sysLow == TPipeSys::kDirtWater || m_infoPipe.sysLow == TPipeSys::kRainWater || m_infoPipe.sysLow == TPipeSys::kUselessWater || m_infoPipe.sysLow == TPipeSys::kOther) bIsGravityPipeLow = TRUE; CWnd *pWndType1 = GetDlgItem(IDC_RADIO_PIPETYPE2); CWnd *pWndType2 = GetDlgItem(IDC_RADIO_PIPETYPE3); CWnd *pWndType3 = GetDlgItem(IDC_RADIO_PIPETYPE4); if (fabs(m_infoPipe.dDnLow - m_infoPipe.dDnUp) < 0.001) { pWndType1->EnableWindow(FALSE); if (m_iDownPipeType == 1) { m_iDownPipeType = 0; } } else { pWndType1->EnableWindow(TRUE); } if ((bIsGravityPipeLow && bIsGravityPipeUp) || (!bIsGravityPipeLow && !bIsGravityPipeUp)) { pWndType2->EnableWindow(FALSE); pWndType3->EnableWindow(FALSE); if (m_iDownPipeType == 2 || m_iDownPipeType == 3) { m_iDownPipeType = 0; } } else { pWndType2->EnableWindow(TRUE); pWndType3->EnableWindow(TRUE); } } void CPipeInterCheckDlg::SetCurSelPipe() { AcApDocument* pDoc = acDocManager->curDocument(); acDocManager->lockDocument(pDoc, AcAp::kWrite); BOOL bIsGravityPipeLow(FALSE), bIsGravityPipeUp(FALSE); if(m_infoPipe.sysUp == TPipeSys::kDirtWater || m_infoPipe.sysUp == TPipeSys::kRainWater || m_infoPipe.sysUp == TPipeSys::kUselessWater || m_infoPipe.sysUp == TPipeSys::kOther) bIsGravityPipeUp = TRUE; if(m_infoPipe.sysLow == TPipeSys::kDirtWater || m_infoPipe.sysLow == TPipeSys::kRainWater || m_infoPipe.sysLow == TPipeSys::kUselessWater || m_infoPipe.sysLow == TPipeSys::kOther) bIsGravityPipeLow = TRUE; if (m_iDownPipeType == 0) { m_idMove = m_infoPipe.idLow; m_cmbPipeType.SetCurSel(0); m_iCmbType = 0; } else if (m_iDownPipeType == 1) { if (m_infoPipe.dDnLow > m_infoPipe.dDnUp) { m_idMove = m_infoPipe.idUp; m_cmbPipeType.SetCurSel(1); m_iCmbType = 1; } else { m_idMove = m_infoPipe.idLow; m_cmbPipeType.SetCurSel(0); m_iCmbType = 0; } } else if (m_iDownPipeType == 2) { if (bIsGravityPipeLow) { m_idMove = m_infoPipe.idLow; m_cmbPipeType.SetCurSel(0); m_iCmbType = 0; } else { m_idMove = m_infoPipe.idUp; m_cmbPipeType.SetCurSel(1); m_iCmbType = 1; } } else if (m_iDownPipeType == 3) { if (!bIsGravityPipeLow) { m_idMove = m_infoPipe.idLow; m_cmbPipeType.SetCurSel(0); m_iCmbType = 0; } else { m_idMove = m_infoPipe.idUp; m_cmbPipeType.SetCurSel(1); m_iCmbType = 1; } } GlobalFunc::ArxZoomTo(m_infoPipe.ptInter, 100*GlobalFunc::DocGetPScale(), 100*GlobalFunc::DocGetPScale()); acedUpdateDisplay(); actrTransactionManager->flushGraphics(); acDocManager->unlockDocument(pDoc); } void CPipeInterCheckDlg::UpdateDlgData(bool bRead) { //CRegProperty regProp(GetRegLocation(), _T("TWTConfig")); //regProp.SetTopRootKey(HKEY_CURRENT_USER); if (bRead) { //if (!regProp.GetValue(_T("PipeInterDownLen"), m_dDownLen)) //{ // m_dDownLen = 0.4; //} //if (!regProp.GetValue(_T("PipeInterSafeDist"), m_dSafeDist)) //{ // m_dSafeDist = 0.0; //} m_csDownLen.Format(_T("%.3f"), m_dDownLen); // 消除数字小数点后面无意义的0 m_csDownLen.TrimRight(_T("0")); m_csDownLen.TrimRight(_T(".")); m_csSafeDist.Format(_T("%.3f"), m_dSafeDist); m_csSafeDist.TrimRight(_T("0")); m_csSafeDist.TrimRight(_T(".")); //regProp.GetValue(_T("PipeInterDimType"), m_iDimType); //regProp.GetValue(_T("PipeInterDimNotInter"), m_iDimPipeNotInter); UpdateData(FALSE); } else { UpdateData(TRUE); //regProp.SetValue(_T("PipeInterDownLen"), m_dDownLen); //regProp.SetValue(_T("PipeInterSafeDist"), m_dSafeDist); //regProp.SetValue(_T("PipeInterDimType"), m_iDimType); //regProp.SetValue(_T("PipeInterDimNotInter"), m_iDimPipeNotInter); } } BOOL CPipeInterCheckDlg::OnInitDialog() { WGroupDlg::OnInitDialog(); #if (ARX == 15) SetTimer(1, 2000, NULL); #else SetTimer(1, 200, NULL); #endif // 获取标高标注精度 //CRegProperty regProp(GetRegLocation(), _T("TWTConfig")); //regProp.SetTopRootKey(HKEY_CURRENT_USER); //TDbPsConfig *pConfig = GetDwgPsGlobal(AcDb::kForRead); //if (pConfig != NULL) //{ // m_iPreWelldDeep = pConfig->GetWellDeepPrecision(); // if(m_iPreWelldDeep == 99) // m_iPreWelldDeep = 0; // pConfig->close(); //} UpdateDlgData(true); UpdateData(FALSE); m_iOldDownPipeType = m_iDownPipeType; InitInterPipeInfo(); SetCurrentDlgData(); return TRUE; } void CPipeInterCheckDlg::OnTimer(UINT_PTR nIDEvent) { ShowLine(); m_bIsVisible = !m_bIsVisible; WGroupDlg::OnTimer(nIDEvent); } void CPipeInterCheckDlg::ShowLine() { if (m_idMove == NULL) { return; } AcApDocument* pDoc = acDocManager->curDocument(); acDocManager->lockDocument(pDoc, AcAp::kWrite); for (long l = 0l; l < m_ssLine.Length(); l++) { Entity ent = m_ssLine[l]; OPENOBJ_BEGIN(ent, AcDb::kForWrite, AcDbLine, pLine); if(pLine != NULL) { XPoint ptOnLine; pLine->getClosestPointTo(m_infoPipe.ptInter, ptOnLine); if (ptOnLine.Distance2d(m_infoPipe.ptInter) > 0.001) { continue; } if (m_bIsVisible) { pLine->setVisibility(AcDb::kVisible); } else { pLine->setVisibility(AcDb::kInvisible); } } OPENOBJ_END(); } acedUpdateDisplay(); actrTransactionManager->flushGraphics(); acDocManager->unlockDocument(pDoc); } void CPipeInterCheckDlg::OnRadioPipetype1() { UpdateData(TRUE); m_iOldDownPipeType = m_iDownPipeType; SetCurSelPipe(); } void CPipeInterCheckDlg::OnRadioPipetype2() { UpdateData(TRUE); m_iOldDownPipeType = m_iDownPipeType; SetCurSelPipe(); } void CPipeInterCheckDlg::OnRadioPipetype3() { UpdateData(TRUE); m_iOldDownPipeType = m_iDownPipeType; SetCurSelPipe(); } void CPipeInterCheckDlg::OnRadioPipetype4() { UpdateData(TRUE); m_iOldDownPipeType = m_iDownPipeType; SetCurSelPipe(); } void CPipeInterCheckDlg::OnSelchangeComboType() { int iOldType = m_iCmbType; UpdateData(); if (iOldType == m_iCmbType) { return; } AcApDocument* pDoc = acDocManager->curDocument(); acDocManager->lockDocument(pDoc, AcAp::kWrite); if (m_idMove == m_infoPipe.idLow) { m_idMove = m_infoPipe.idUp; } else { m_idMove = m_infoPipe.idLow; } acedUpdateDisplay(); actrTransactionManager->flushGraphics(); acDocManager->unlockDocument(pDoc); acedGetAcadDwgView()->SetFocus(); } void CPipeInterCheckDlg::OnDestroy() { WGroupDlg::OnDestroy(); m_vecPtUnInter.clear(); m_mapInterPipeInfo.clear(); m_ssPipe.Free(); AcApDocument* pDoc = acDocManager->curDocument(); acDocManager->lockDocument(pDoc, AcAp::kWrite); m_bIsVisible = true; ShowLine(); KillTimer(1); m_idMove = NULL; m_ssLine.Erase(); m_ssLine.Free(); acedUpdateDisplay(); actrTransactionManager->flushGraphics(); acDocManager->unlockDocument(pDoc); UpdateDlgData(false); } void CPipeInterCheckDlg::OnClose() { GlobalFunc::PostCommand(_T(" ")); WGroupDlg::OnClose(); } void CPipeInterCheckDlg::OnBtnQuit() { UpdateData(); ModifyInterPipeInfo(); AcApDocument* pDoc = acDocManager->curDocument(); acDocManager->lockDocument(pDoc, AcAp::kWrite); std::multimap::iterator itMap; for (itMap = m_mapInterPipeInfo.begin(); itMap != m_mapInterPipeInfo.end(); itMap++) { DoDimIntersectPipes(itMap->second); } if (m_iDimPipeNotInter == 1) { std::vector::iterator it; for (it = m_vecPtUnInter.begin(); it != m_vecPtUnInter.end(); it++) { DoDimIntersectPipes(*it); } } acedUpdateDisplay(); actrTransactionManager->flushGraphics(); acDocManager->unlockDocument(pDoc); GlobalFunc::PostCommand(_T(" ")); acedGetAcadDwgView()->SetFocus(); } void CPipeInterCheckDlg::OnBtnNotdown() { UpdateData(); m_bIsVisible = true; ShowLine(); m_itCurPipe++; if (m_itCurPipe == m_mapInterPipeInfo.rend()) { m_ssLine.Erase(); SetDlgCtrlStu(); OnBtnQuit(); return; } m_infoPipe = m_itCurPipe->second; ModifyDlgRadioStu(); UpdateData(FALSE); SetCurSelPipe(); acedGetAcadDwgView()->SetFocus(); } void CPipeInterCheckDlg::OnBtnDown() { UpdateData(); AcApDocument* pDoc = acDocManager->curDocument(); acDocManager->lockDocument(pDoc, AcAp::kWrite); ResetSelPipeSysElev(); m_iDownPipeType = m_iOldDownPipeType; m_ssLine.Erase(); m_ssLine.Free(); acedUpdateDisplay(); actrTransactionManager->flushGraphics(); acDocManager->unlockDocument(pDoc); ModifyInterPipeInfo(); SetCurrentDlgData(); acedGetAcadDwgView()->SetFocus(); } void CPipeInterCheckDlg::SetDlgCtrlStu(bool bEnableWindow) { Invalidate(); if (!bEnableWindow) { m_cmbPipeType.ResetContent(); m_cmbPipeType.EnableWindow(TRUE); m_cmbPipeType.AddString(_T("无碰撞点")); m_iCmbType = 0; m_cmbPipeType.EnableWindow(FALSE); m_sElevLow.Empty(); m_sElevUp.Empty(); if (m_vecPtUnInter.size() == 1) { m_infoPipe = m_vecPtUnInter[0]; SetDimText(); } CWnd *pWnd = GetDlgItem(IDC_EDIT_DOWNLEN); if (pWnd != NULL) { pWnd->EnableWindow(FALSE); } CWnd *pWndType1 = GetDlgItem(IDC_BTN_DOWN); CWnd *pWndType2 = GetDlgItem(IDC_BTN_NOTDOWN); CWnd *pWndType3 = GetDlgItem(IDC_BTN_AUTODOWN); pWndType1->EnableWindow(FALSE); pWndType2->EnableWindow(FALSE); pWndType3->EnableWindow(FALSE); CWnd *pWndDownType1 = GetDlgItem(IDC_RADIO_PIPETYPE1); CWnd *pWndDownType2 = GetDlgItem(IDC_RADIO_PIPETYPE2); CWnd *pWndDownType3 = GetDlgItem(IDC_RADIO_PIPETYPE3); CWnd *pWndDownType4 = GetDlgItem(IDC_RADIO_PIPETYPE4); pWndDownType1->EnableWindow(FALSE); pWndDownType2->EnableWindow(FALSE); pWndDownType3->EnableWindow(FALSE); pWndDownType4->EnableWindow(FALSE); UpdateData(FALSE); } else { m_cmbPipeType.EnableWindow(TRUE); m_sElevLow.Empty(); m_sElevUp.Empty(); CWnd *pWnd = GetDlgItem(IDC_EDIT_DOWNLEN); if (pWnd != NULL) { pWnd->EnableWindow(TRUE); } CWnd *pWndType1 = GetDlgItem(IDC_BTN_DOWN); CWnd *pWndType2 = GetDlgItem(IDC_BTN_NOTDOWN); CWnd *pWndType3 = GetDlgItem(IDC_BTN_AUTODOWN); pWndType1->EnableWindow(TRUE); pWndType2->EnableWindow(TRUE); pWndType3->EnableWindow(TRUE); CWnd *pWndDownType1 = GetDlgItem(IDC_RADIO_PIPETYPE1); CWnd *pWndDownType2 = GetDlgItem(IDC_RADIO_PIPETYPE2); CWnd *pWndDownType3 = GetDlgItem(IDC_RADIO_PIPETYPE3); CWnd *pWndDownType4 = GetDlgItem(IDC_RADIO_PIPETYPE4); pWndDownType1->EnableWindow(TRUE); pWndDownType2->EnableWindow(TRUE); pWndDownType3->EnableWindow(TRUE); pWndDownType4->EnableWindow(TRUE); } } void CPipeInterCheckDlg::ResetSelPipeSysElev() { AcDbObjectId idNodeStart, idNodeEnd; double dDeepStart = 0.0, dDeepEnd = 0.0; double dDn = 0.0; double dUnitMeter = 1000; if(GlobalFunc::DocGetMeterUnitDraw()) dUnitMeter = 1.0; OPENOBJ_BEGIN(m_idMove, AcDb::kForWrite, CDbPipe, pPipe); if(pPipe != NULL) { XPoint ptS, ptE; dDn = pPipe->GetDnDiameter() / 2; TPipeSys::FlowDirection dir = pPipe->GetFlowDir(); if (dir == TPipeSys::kFromStart) { ptS = pPipe->GetStartPoint(); ptE = pPipe->GetEndPoint(); double dLen = pPipe->GetPlanLength(); double dI = pPipe->GetPipeGradient(); ptS.z -= m_dDownLen * dUnitMeter; pPipe->SetStartPoint(ptS); double nDrop = dLen * dI * dUnitMeter; ptE.z = ptS.z - nDrop; pPipe->SetEndPoint(ptE); dDeepStart = ptS.z / dUnitMeter; dDeepEnd = ptE.z / dUnitMeter; idNodeStart = pPipe->GetNode(0); idNodeEnd = pPipe->GetNode(1); } else { ptE = pPipe->GetEndPoint(); ptS = pPipe->GetStartPoint(); double dLen = pPipe->GetPlanLength(); double dI = pPipe->GetPipeGradient(); ptE.z -= m_dDownLen * dUnitMeter; pPipe->SetEndPoint(ptE); double nDrop = dLen*dI; ptS.z = ptE.z - nDrop; pPipe->SetStartPoint(ptS); dDeepStart = ptE.z / dUnitMeter; dDeepEnd = ptS.z / dUnitMeter; idNodeEnd = pPipe->GetNode(0); idNodeStart = pPipe->GetNode(1); } } OPENOBJ_END(); Entity entStartWell, entEndWell; double nDeepStart = 0.0; OPENOBJ_BEGIN(idNodeStart, AcDb::kForWrite, AecXDbWell, pWell); if(pWell != NULL) { pWell->SetDropWell(TRUE); nDeepStart = dDeepStart - dDn / 1000; pWell->SetWellEleDown(nDeepStart); ads_name name; acdbGetAdsName(name, idNodeStart); entStartWell = name; } OPENOBJ_END(); if (!entStartWell) { OPENOBJ_BEGIN(idNodeEnd, AcDb::kForWrite, AecXDbWell, pWell); if(pWell != NULL) { nDeepStart = dDeepEnd - dDn / 1000; pWell->SetWellEleDown(nDeepStart); ads_name name; acdbGetAdsName(name, idNodeEnd); entStartWell = name; } OPENOBJ_END(); } if (!!entStartWell) { SSearchPipeList *pListAll = new SSearchPipeList(); PickSet ssAll(SS_FREE); ssAll += entStartWell; SearchOutdoorWell(entStartWell, entEndWell, pListAll, ssAll, FALSE); DList lstWellSys; GetWellListData2(pListAll, lstWellSys); ModifyWellSysByLastWell(lstWellSys, ssAll); CalcWellPipeSys(nDeepStart, lstWellSys); if (pListAll != NULL) { delete pListAll; pListAll = NULL; } } //TPipePerDocData *pData = GetCurPipeDocData(); //if (pData != NULL) //{ // pData->ApplyUpdates(); //} } void CPipeInterCheckDlg::ModifyWellSysByLastWell(DList &lstWellSys, const PickSet &ss) { if (lstWellSys.Length() < 2) { return; } AcDbObjectId id, idFront; AcDbObjectId idLastWell; id = lstWellSys[lstWellSys.Length() - 1]->m_ID; idFront = lstWellSys[lstWellSys.Length() - 2]->m_ID; if (!lstWellSys[lstWellSys.Length() - 1]->m_bIsWell) { PickSet ssNode; GlobalFunc::GetAllPipeAndNodeByPipe(id, idFront, ssNode); for (long l = 0; l < ssNode.Length(); l++) { Entity ent = ssNode[l]; if (ent.Is(_T("AEC_ZT_WELL")) && ent.In(&ss)) { acdbGetObjectId(idLastWell, ent); break; } } if (idLastWell == NULL) { return; } } else { return; } int nPos = 0; for(int i = 0; i < lstWellSys.Length(); i++) { if (lstWellSys[i]->m_ID == idLastWell) { nPos = i + 1; break; } } while (lstWellSys.Length() > nPos) { lstWellSys.Remove(nPos); } } void CPipeInterCheckDlg::CalcWellPipeSys(double nDeepStart, DList &lstWellSys) { double nPipeLen = 0.0; double nI = 0.0; double nFrontPipeEle = 0.0; bool bFindDropWell = false; for(int i = 0; i < lstWellSys.Length(); i++) { lstWellSys[i]->m_iSpare = 1; if(lstWellSys[i]->m_bIsWell) {//井 AcDbObjectId id = lstWellSys[i]->m_ID; if(nPipeLen > 0) { double nWellEle = lstWellSys[i]->m_nUpEle; double nWellDownEle = lstWellSys[i]->m_nDownEle; double nLastEnd = nDeepStart - nI * nPipeLen; double nWellDeep = nWellEle - nWellDownEle; //埋深 地面-井底 nFrontPipeEle = nLastEnd; if(lstWellSys[i]->m_bIsDropWell && nDeepStart > lstWellSys[i]->m_nDownEle) { nDeepStart = lstWellSys[i]->m_nDownEle; lstWellSys[i]->m_nFrondDownEle = nFrontPipeEle; break; } else { if (lstWellSys[i]->m_bIsDropWell) { if (bFindDropWell) { break; } bFindDropWell = true; } lstWellSys[i]->m_bIsDropWell = FALSE; double nRadiusFront(0), nRadiusBack(0); nRadiusFront = lstWellSys[i-1]->m_iDn; if(i != lstWellSys.Length()-1) { nRadiusBack = lstWellSys[i+1]->m_iDn; } //得到外径 double nDifference(0); if(nRadiusFront > 0 && nRadiusBack > 0) {//井前后管径差 nDifference = (nRadiusBack - nRadiusFront)/1000; } lstWellSys[i]->m_nFrondDownEle = nDeepStart - nI * nPipeLen; //管顶平接 nDeepStart = nDeepStart - nI * nPipeLen - nDifference; if(lstWellSys[i]->m_csName == _T("HC")) { OPENOBJ_BEGIN(id, AcDb::kForRead, CDbPool, pEquip); if(pEquip != NULL) { if(pEquip->GetSpare() > 0.01) nDeepStart -= pEquip->GetSpare(); else nDeepStart -= 0.1;//化粪池 } OPENOBJ_END(); } } lstWellSys[i]->m_nDownEle = nDeepStart; nWellDeep = nWellEle - nDeepStart; lstWellSys[i]->m_nDeep = nWellDeep; } } else if(!lstWellSys[i]->m_bIsWell) { //管 if(i == lstWellSys.Length() - 1) continue; nPipeLen = lstWellSys[i]->m_nLength; nI = lstWellSys[i]->m_nI; CString csPipeName = lstWellSys[i-1]->m_csName + lstWellSys[i+1]->m_csName; if(lstWellSys[i+1]->m_csName == _T("HC")) csPipeName += _T("进"); else if(lstWellSys[i-1]->m_csName == _T("HC")) csPipeName = lstWellSys[i-1]->m_csName + _T("出") + lstWellSys[i+1]->m_csName; } } ModifyWellPipeElev(lstWellSys); } void CPipeInterCheckDlg::ModifyWellPipeElev(DList &lstWellSys) { for(int i=0;im_bIsWell) {//井 AcDbObjectId id = lstWellSys[i]->m_ID; XPoint ptLoc; CString csEleLow, csEleUp; csEleLow.Format(_T("%.2f"), lstWellSys[i]->m_nDownEle); csEleUp.Format(_T("%.2f"), lstWellSys[i]->m_nUpEle); if(lstWellSys[i]->m_csName == _T("HC")) { OPENOBJ_BEGIN(id, AcDb::kForWrite, CDbPool, pEquip); if(pEquip != NULL) { pEquip->SetGroundEle(lstWellSys[i]->m_nUpEle); } OPENOBJ_END(); continue; } OPENOBJ_BEGIN(id, AcDb::kForWrite, AecXDbWell, pEquip); if(pEquip != NULL) { pEquip->SetDropWell(lstWellSys[i]->m_bIsDropWell); double nPipeDownEle = lstWellSys[i]->m_nFrondDownEle; double nPipeDownEle2 = lstWellSys[i]->m_nDownEle; if(i > 1) {//设置前管道 管底标高 AcDbObjectId idPipe = lstWellSys[i-1]->m_ID; pEquip->SetPipeEndEle(idPipe, XString(_T("%.3f"), lstWellSys[i]->m_nFrondDownEle)); } if(i < lstWellSys.Length()-1) {//设置后管道 管底标高 AcDbObjectId idPipe = lstWellSys[i+1]->m_ID; pEquip->SetPipeEndEle(idPipe, XString(_T("%.3f"), lstWellSys[i]->m_nDownEle)); } ptLoc = pEquip->GetLocation(); //搜索这个井其他连接管,最低标高才是井标高 int num = pEquip->GetInterfaceNum(); double nEleOther = lstWellSys[i]->m_nDownEle; for(int m = 0; m < num; m++) { CPipeInterface iFace; pEquip->GetInterface(m, iFace); CString csLabel = pEquip->GetISysLabel(m); if(csLabel != _T("") && nEleOther - _tstof(csLabel) > 0.001) nEleOther = _tstof(csLabel); } if(fabs(nEleOther - lstWellSys[i]->m_nDownEle) < 0.001) pEquip->SetWellEleDown(lstWellSys[i]->m_nDownEle); pEquip->SetWellEleUp(lstWellSys[i]->m_nUpEle); } OPENOBJ_END(); } else { int iDn = lstWellSys[i]->m_iDn; double nI = lstWellSys[i]->m_nI*1000; double nEleDown = lstWellSys[i-1]->m_nDownEle; ads_name ent; acdbGetAdsName(ent, lstWellSys[i]->m_ID); OPENOBJ_BEGIN(ent, AcDb::kForWrite, CDbPipe, pPipe); if(pPipe != NULL) { if (lstWellSys[i]->m_iSpare != 1) { break; } pPipe->SetPipeGradient(nI/1000); XPoint pt1(pPipe->GetStartPoint()), pt2(pPipe->GetEndPoint()); pt1.z = 0; pt2.z = 0; double dLen = pPipe->GetPlanLength(); double dI = pPipe->GetPipeGradient(); double nDrop = dLen*dI; if(GlobalFunc::DocGetMeterUnitDraw()) {//米 if(pPipe->GetFlowDir() == TPipeSys::kFromStart) { pt1.z = nEleDown + (double)iDn/2000; pt2.z = pt1.z - nDrop; } else { pt2.z = nEleDown + (double)iDn/2000; pt1.z = pt2.z - nDrop; } } else { nDrop = nDrop * 1000; if(pPipe->GetFlowDir() == TPipeSys::kFromStart) { pt1.z = nEleDown*1000 + (double)iDn/2; pt2.z = pt1.z - nDrop; } else { pt2.z = nEleDown*1000 + (double)iDn/2; pt1.z = pt2.z - nDrop; } } pPipe->SetStartPoint(pt1); pPipe->SetEndPoint(pt2); } OPENOBJ_END(); } } } void CPipeInterCheckDlg::OnRadioDimtype1() { UpdateData(TRUE); SetDimText(); UpdateData(FALSE); } void CPipeInterCheckDlg::OnRadioDimtype2() { UpdateData(TRUE); SetDimText(); UpdateData(FALSE); } void CPipeInterCheckDlg::OnKillfocusEditDownlen() { double dOldLen = m_dDownLen; if (!UpdateData() || m_dDownLen <= 0.0) { m_dDownLen = dOldLen; m_csDownLen.Format(_T("%.3f"), m_dDownLen); m_csDownLen.TrimRight(_T("0")); m_csDownLen.TrimRight(_T(".")); UpdateData(FALSE); CEdit *pWnd = (CEdit *)GetDlgItem(IDC_EDIT_DOWNLEN); if (pWnd != NULL) { pWnd->SetSel(0, -1); } } } bool StringIsAllNum(CString str) { // 判断字符是否是合法数字 CString sText = str.SpanIncluding(_T("0123456789.-")); // 小数点可以出现在中间,但只能出现一次 int nIndex = sText.Find(_T("."), 0); if (nIndex > 0) { nIndex = sText.Find(_T("."), ++nIndex); } // 负号可以出现在起始处,但只能出现一次 int nIndex2 = sText.Find(_T("-")); if (nIndex2 == 0) { nIndex2 = sText.Find(_T("-"), 1); } bool bFigure = true; if (str == sText && nIndex < 0 && nIndex2 <= 0)// 全是数字 { return true; } return false; } void CPipeInterCheckDlg::OnKillfocusEditSafedist() { double dOldDst = m_dSafeDist; if (!UpdateData() || m_dSafeDist < 0.0 || !StringIsAllNum(m_csSafeDist)) { m_dSafeDist = dOldDst; m_csSafeDist.Format(_T("%.3f"), m_dSafeDist); m_csSafeDist.TrimRight(_T("0")); m_csSafeDist.TrimRight(_T(".")); UpdateData(FALSE); CEdit *pWnd = (CEdit *)GetDlgItem(IDC_EDIT_SAFEDIST); if (pWnd != NULL) { pWnd->SetSel(0, -1); } } if (dOldDst != m_dSafeDist) { m_iDownPipeType = m_iOldDownPipeType; AcApDocument* pDoc = acDocManager->curDocument(); acDocManager->lockDocument(pDoc, AcAp::kWrite); m_ssLine.Erase(); m_ssLine.Free(); acedUpdateDisplay(); actrTransactionManager->flushGraphics(); acDocManager->unlockDocument(pDoc); SetDlgCtrlStu(true); ModifyInterPipeInfo(); SetCurrentDlgData(); acedGetAcadDwgView()->SetFocus(); } } void CPipeInterCheckDlg::DoDimIntersectPipes(InterPipesInfo infoPipe) { double dUnitMeter = 1000; if(GlobalFunc::DocGetMeterUnitDraw()) dUnitMeter = 1; CString sFormat; sFormat.Format(_T("%%s%%.%df"), m_iPreWelldDeep); CString sPipeNameUp = GlobalFunc::GetPipeNameBySys(infoPipe.sysUp); CString sPipeNameLow = GlobalFunc::GetPipeNameBySys(infoPipe.sysLow); double nPipeEle1 = 0.0; double nPipeEle2 = 0.0; double dDnUp = 0.0; double dDnLow = 0.0; CString csMat; OPENOBJ_BEGIN(infoPipe.idUp, AcDb::kForRead, CDbPipe, pPipe); if(pPipe != NULL) { int iMaterial = pPipe->GetMaterial(); csMat = GlobalFunc::GetPipeMaterialByIdx(iMaterial); double dDn = pPipe->GetDnDiameter(); dDnUp = GlobalFunc::GetPipeOutDByDn(csMat, (int)dDn); XPoint ptStart = pPipe->StartPoint(); XPoint ptEnd = pPipe->EndPoint(); double nI = pPipe->GetPipeGradient(); TPipeSys::FlowDirection dir = pPipe->GetFlowDir(); XPoint ptWell; if(dir == TPipeSys::kFromStart) ptWell = ptStart; else ptWell = ptEnd; nPipeEle1 = ptWell.z/dUnitMeter - dDnUp / 2; ptWell.z = 0; double nDist2Well = ptWell.Distance2d(infoPipe.ptInter) / dUnitMeter; nPipeEle1 = nPipeEle1 - nDist2Well * nI; } OPENOBJ_END(); OPENOBJ_BEGIN(infoPipe.idLow, AcDb::kForRead, CDbPipe, pPipe); if(pPipe != NULL) { int iMaterial = pPipe->GetMaterial(); csMat = GlobalFunc::GetPipeMaterialByIdx(iMaterial); double dDn = pPipe->GetDnDiameter(); dDnLow = GlobalFunc::GetPipeOutDByDn(csMat, (int)dDn); XPoint ptStart = pPipe->StartPoint(); XPoint ptEnd = pPipe->EndPoint(); double nI = pPipe->GetPipeGradient(); TPipeSys::FlowDirection dir = pPipe->GetFlowDir(); XPoint ptWell; if(dir == TPipeSys::kFromStart) ptWell = ptStart; else ptWell = ptEnd; nPipeEle2 = ptWell.z/dUnitMeter - dDnLow / 2; ptWell.z = 0; double nDist2Well = ptWell.Distance2d(infoPipe.ptInter) / dUnitMeter; nPipeEle2 = nPipeEle2 - nDist2Well * nI; } OPENOBJ_END(); if (m_iDimType == 1) // 外底与外顶标高 { nPipeEle2 += dDnLow; } else // 重力流内底与压力流中心标高 { BOOL bIsGravityPipeLow(FALSE), bIsGravityPipeUp(FALSE); if(infoPipe.sysUp == TPipeSys::kDirtWater || infoPipe.sysUp == TPipeSys::kRainWater || infoPipe.sysUp == TPipeSys::kUselessWater || infoPipe.sysUp == TPipeSys::kOther) bIsGravityPipeUp = TRUE; if(infoPipe.sysLow == TPipeSys::kDirtWater || infoPipe.sysLow == TPipeSys::kRainWater || infoPipe.sysLow == TPipeSys::kUselessWater || infoPipe.sysLow == TPipeSys::kOther) bIsGravityPipeLow = TRUE; if(!bIsGravityPipeUp) nPipeEle1 += dDnUp/ 2.0; else { ads_name name; acdbGetAdsName(name, infoPipe.idUp); Entity ent = name; nPipeEle1 += GetPipeThick(ent); } if(!bIsGravityPipeLow) nPipeEle2 += dDnLow / 2.0; else { ads_name name; acdbGetAdsName(name, infoPipe.idLow); Entity ent = name; nPipeEle2 += GetPipeThick(ent); } } if (fabs(nPipeEle1) < 0.001) { nPipeEle1 = 0.0; } if (fabs(nPipeEle2) < 0.001) { nPipeEle2 = 0.0; } CString sElevUp; sElevUp.Format(sFormat, sPipeNameUp, nPipeEle1); CString sElevLow; sElevLow.Format(sFormat, sPipeNameLow, nPipeEle2); XPoint ptTurn; XPoint ptInt = infoPipe.ptInter; double nDist1 = 15*GlobalFunc::DocGetPScale(); ads_polar(ptInt, PI/4, nDist1, ptTurn); AecXDbSymbMultiLeader *pLeader = new AecXDbSymbMultiLeader; XPointList lstVertexes; lstVertexes.Append(new XPoint(ptInt)); pLeader->SetLayoutRotation(GlobalFunc::Ucs2Wcs(0.0)); pLeader->SetLeaderVertexes(lstVertexes); pLeader->SetText1(sElevUp); pLeader->SetText2(sElevLow); pLeader->SetLeaderPoint(ptTurn); pLeader->SetArrow(AecXDbSymbMultiLeader::kNone); AcDbObjectId idTextStyle = InitTextStyle(g_Option::instance().g_csTwtDimStyle); pLeader->SetTextStyleId(idTextStyle); pLeader->SetTextLayerId(InitLayer(LAY_TEXT)); pLeader->SetTextHeight(g_Option::instance().g_nTwtDimHeight); pLeader->SetTextBaseLen(pLeader->GetDefaultTextBaseLen()+2); //pLeader->AddToCSpace(Adesk::kTrue); GlobalFunc::AddToCurrentSpace(pLeader, Adesk::kTrue); } void CPipeInterCheckDlg::OnPaint() { CPaintDC dc(this); if (m_vecPtUnInter.size() > 1 && m_mapInterPipeInfo.size() < 1) { return; } CStatic *pSta = (CStatic *)GetDlgItem(IDC_STATIC_LINE); CRect rect; pSta->GetWindowRect(rect); ScreenToClient(rect); CPen pen(PS_SOLID, 2, RGB(0,255,0));// 绿色 dc.SelectObject (&pen); CPoint ptLeft = rect.TopLeft(); CPoint ptRight = ptLeft; ptRight.x += 85; dc.MoveTo(ptLeft); dc.LineTo(ptRight); dc.MoveTo(ptLeft); CPoint ptBottom = ptLeft; ptBottom.x -= 30; ptBottom.y += 25; dc.LineTo(ptBottom); ReleaseDC(&dc); } void CPipeInterCheckDlg::OnBtnAutoDown() { while (!m_mapInterPipeInfo.empty()) { OnBtnDown(); } OnBtnQuit(); acedGetAcadDwgView()->SetFocus(); }