#include "StdAfx.h" #include "AcDbObjectPtr.h" #include "PositiveElevationCalc.h" #include "ElevationCalcDlg.h" #include "ElevationCalcCheckDlg.h" #include "DbPipe.h" #include "DbWell.h" #include namespace { CString GetWellName(AcDbObjectId id) { CString csWellName; OPENOBJ_BEGIN(id, AcDb::kForRead, AecXDbWell, pEquip); if (pEquip) { csWellName = pEquip->GetWellName(); } OPENOBJ_END(); return csWellName; } } PositiveElevationCalc::PositiveElevationCalc() { m_dLayingDepth = 1.1; m_dMinThick = 0.7; } void PositiveElevationCalc::InitCalcSys() { UpDatePipeSys(); SSearchPipeList *pList = NULL; pList = GetFarthestSWell(m_pAllList); //获得最远起点井 if (pList != NULL) { std::stack data; data.push(pList); while(!data.empty()) { SSearchPipeList *pSWell = NULL; pSWell = data.top(); data.pop(); if ((pSWell->m_iType == 3 || pSWell->m_iType == 4)&& pSWell->m_pPrevious != NULL && pSWell->m_iSpare != 2) //管段起点井 { int nNum = pSWell->m_lstNode.Length(); if (nNum == 1 || nNum == 0 || (nNum > 1 && pSWell->m_iSpare == 1)) { SSearchPipeList *pPipe = pSWell->m_pPrevious; if (pPipe->m_iType == 0 && pPipe->m_pPrevious != NULL) //管段 { SSearchPipeList *pEWell = pPipe->m_pPrevious; if (pEWell->m_iType == 3 || pEWell->m_iType == 4) // 管段终点井或化粪池 { pSWell->m_iSpare = 2; //表示井处理(注意只需标注管段起点井) CALCNODE node; node.idS = pSWell->m_ID; node.idE = pEWell->m_ID; node.idP = pPipe->m_ID; node.dPipeDn = pPipe->m_iDn; node.bSysStartWell = FALSE; node.bPool = FALSE; node.bIsDropWell = FALSE; // cet 2011.11.17 add ads_name name; acdbGetAdsName(name, pPipe->m_ID); node.dGradient = GlobalFunc::GetPipeGradient(name); node.dPipeLen = pPipe->m_nLength; if (pSWell->m_iType == 3) // 井 { node.dWellEleUpS = GetWellEleUp(pSWell->m_ID); node.strSWellName = GetWellName(pSWell->m_ID); node.dWellEleDownS = GetWellEleDown(pSWell->m_ID); node.bIsDropWell = IsDropWell(pSWell->m_ID); if (nNum == 0) //系统起点井 { pSWell->m_bNeedCale = TRUE; //已处理 node.bSysStartWell = TRUE; } } else if (pSWell->m_iType == 4) // 化粪池 { node.bPool = TRUE; node.dWellEleUpS = GetPoolGroundEle(node.idS); node.strSWellName = GetPoolName(node.idS) + _T("出"); } if (pEWell->m_iType == 3) // 井 { node.dWellEleUpE = GetWellEleUp(pEWell->m_ID); node.strEWellName = GetWellName(pEWell->m_ID); } else if (pEWell->m_iType == 4) // 化粪池 { node.dWellEleUpE = GetPoolGroundEle(node.idE); node.strEWellName = GetPoolName(node.idE) + _T("进"); } node.dGradientDist = node.dGradient * node.dPipeLen; node.dPipeEleS = 0.0; node.dPipeEleE = 0.0; node.dDeepS = 0.0; node.dDeepE = 0.0; m_vecLstData.push_back(node); data.push(pEWell); } } } else if (nNum > 1) //存在分支 { data.push(pSWell); SSearchPipeList *pTemp = GetFarthestSWell(pSWell); if (pTemp != NULL) { data.push(pTemp); } else { pSWell->m_iSpare = 1; //井上所有分支已处理 } } } else if (pSWell->m_lstNode.Length() > 1) // 排出端存在支路 { SSearchPipeList *pTemp = GetFarthestSWell(pSWell); if (pTemp != NULL) { data.push(pTemp); } } } } } void PositiveElevationCalc::AutoCalc(BOOL bModify) { acedSetStatusBarProgressMeter(_T("自动计算中..."), 0, m_vecLstData.size()); for (size_t i = 0; i < m_vecLstData.size(); i++) { acedSetStatusBarProgressMeterPos(i); CALCNODE &node = m_vecLstData[i]; if (node.bSysStartWell) //系统起点井 { double dLayingDepth = GetWellLayDepth(node.idS); // 埋设深度 node.dPipeEleS = node.dWellEleUpS - dLayingDepth; } else if (node.bIsDropWell) //跌水井 { node.dPipeEleS = node.dWellEleDownS; } else if (node.bPool) // 化粪池 { node.dPipeEleS = GetPipeEleDown(m_vecLstData, node.idS) - GetPoolDrop(node.idS); } else { double dPipeEleUp = GetPipeEleUp(m_vecLstData, node.idS); node.dPipeEleS = dPipeEleUp - GetPipeDjById(node.idP, node.dPipeDn) * 0.001; } // 检查起点井覆土厚度 double dThick = node.dWellEleUpS - (node.dPipeEleS + GetPipeDjById(node.idP, node.dPipeDn) * 0.001 + GetPipeThickById(node.idP, node.dPipeDn)); if (dThick + 0.001 < m_dMinThick) // 小于最小覆土厚度时调整为最小覆土厚度 { if (!node.bIsDropWell && !node.bPool) { node.dPipeEleS = node.dWellEleUpS - m_dMinThick - GetPipeDjById(node.idP, node.dPipeDn) * 0.001 - GetPipeThickById(node.idP, node.dPipeDn); if (!node.bSysStartWell && !node.bPool) { node.bIsDropWell = TRUE; node.dWellEleDownS = node.dPipeEleS; } } else if (node.bIsDropWell && bModify) // 跌水井 { // 变为普通井 node.bIsDropWell = FALSE; double dPipeEleUp = GetPipeEleUp(m_vecLstData, node.idS); node.dPipeEleS = dPipeEleUp - GetPipeDjById(node.idP, node.dPipeDn) * 0.001; dThick = node.dWellEleUpS - (node.dPipeEleS + GetPipeDjById(node.idP, node.dPipeDn) * 0.001 + GetPipeThickById(node.idP, node.dPipeDn)); if (dThick + 0.001 < m_dMinThick) { node.dPipeEleS = node.dWellEleUpS - m_dMinThick - GetPipeDjById(node.idP, node.dPipeDn) * 0.001 - GetPipeThickById(node.idP, node.dPipeDn); node.bIsDropWell = TRUE; } } } node.dPipeEleE = node.dPipeEleS - node.dGradientDist; // 检查终点井覆土厚度 dThick = node.dWellEleUpE - (node.dPipeEleE + GetPipeDjById(node.idP, node.dPipeDn) * 0.001 + GetPipeThickById(node.idP, node.dPipeDn)); if (dThick + 0.001 < m_dMinThick) // 小于最小覆土深度时调整为最小覆土深度 { node.dPipeEleE = node.dWellEleUpE - m_dMinThick - GetPipeDjById(node.idP, node.dPipeDn) * 0.001- GetPipeThickById(node.idP, node.dPipeDn); node.dPipeEleS = node.dPipeEleE + node.dGradientDist; if (!node.bSysStartWell && !node.bPool) { node.bIsDropWell = TRUE; //起点井设置为跌水井 node.dWellEleDownS = node.dPipeEleS; } } node.dDeepS = node.dWellEleUpS - node.dPipeEleS; node.dDeepE = node.dWellEleUpE - node.dPipeEleE; // 修改起点井埋深深度 if (node.bSysStartWell) { m_mapLayingDepth.erase(node.idS); m_mapLayingDepth.insert(std::make_pair(node.idS, node.dDeepS)); } } acedRestoreStatusBar(); } void PositiveElevationCalc::LayingDepthCalc() { UpdateSWellLayDepth(); // cet 2012.6.21 add 更新起点井埋深 acedSetStatusBarProgressMeter(_T("计算中..."), 0, m_vecLstData.size()); for (size_t i = 0; i < m_vecLstData.size(); i++) { acedSetStatusBarProgressMeterPos(i); CALCNODE &node = m_vecLstData[i]; if (node.bSysStartWell) //系统起点井 { double dLayingDepth = GetWellLayDepth(node.idS); // 埋设深度 node.dPipeEleS = node.dWellEleUpS - dLayingDepth; } else if (node.bIsDropWell) //跌水井 { node.dPipeEleS = node.dWellEleDownS; } else if (node.bPool) // 化粪池 { node.dPipeEleS = GetPipeEleDown(m_vecLstData, node.idS) - GetPoolDrop(node.idS); } else { node.bIsDropWell = isDropWell(m_vecLstData, node.idS); // cet 2011.6.8 add 判断井是否产生跌水 double dPipeEleUp = GetPipeEleUp(m_vecLstData, node.idS); node.dPipeEleS = dPipeEleUp - GetPipeDjById(node.idP, node.dPipeDn) * 0.001; } node.dGradientDist = node.dGradient * node.dPipeLen; node.dPipeEleE = node.dPipeEleS - node.dGradientDist; node.dDeepS = node.dWellEleUpS - node.dPipeEleS; node.dDeepE = node.dWellEleUpE - node.dPipeEleE; } acedRestoreStatusBar(); } void PositiveElevationCalc::CheckSys(CWnd *pWnd) { CheckSys(FALSE); } void PositiveElevationCalc::CheckSys(BOOL bModifyDropWell) { // 校核数据 acedSetStatusBarProgressMeter(_T("校核中..."), 0, m_vecLstData.size()); CString strError1, strError2, strError3; for (size_t i = 0; i < m_vecLstData.size(); i++) { acedSetStatusBarProgressMeterPos(i); const CALCNODE &node = m_vecLstData[i]; //起点井覆土厚度 double dThick1 = node.dWellEleUpS - (node.dPipeEleS + GetPipeDjById(node.idP, node.dPipeDn) * 0.001 + GetPipeThickById(node.idP, node.dPipeDn)); //终点井覆土厚度 double dThick2 = node.dWellEleUpE - (node.dPipeEleE + GetPipeDjById(node.idP, node.dPipeDn) * 0.001 + GetPipeThickById(node.idP, node.dPipeDn)); BOOL bCheck = FALSE; if (Compare(dThick1, m_dMinThick) == -1) { if (node.bIsDropWell) // 跌水井 { strError2 += node.strSWellName + _T("、"); } else if (node.bSysStartWell) // 管网起点井 { strError1 += node.strSWellName + _T("、"); } else { bCheck = TRUE; strError3 += node.strSWellName + _T("-") + node.strEWellName + _T("、"); } } if (Compare(dThick2, m_dMinThick) == -1 && !bCheck) { strError3 += node.strSWellName + _T("-") + node.strEWellName + _T("、"); } } acedRestoreStatusBar(); // 显示错误 CString strTemp = _T("、"); if (!strError1.IsEmpty()) { strError1 = strError1.Left(strError1.GetLength() - strTemp.GetLength()); strError1 += _T("起点井不符合最小覆土深度要求!\n"); strError1 += _T("-------------------------------\n"); } if (!strError2.IsEmpty()) { strError2 = strError2.Left(strError2.GetLength() - strTemp.GetLength()); strError2 += _T("跌水井井底标高不符合最小覆土深度要求!\n"); strError2 += _T("--------------------------------\n"); } if (!strError3.IsEmpty()) { strError3 = strError3.Left(strError3.GetLength() - strTemp.GetLength()); strError3 += _T("管段不符合最小覆土深度要求!\n"); strError3 += _T("--------------------------------\n"); } if (strError1.IsEmpty() && !strError2.IsEmpty() && strError3.IsEmpty() && bModifyDropWell) //只有跌水错误 { if(AfxMessageBox(_T("是否将不符合最小覆土深度的跌水井改为普通井!"), MB_YESNO) == IDYES) { AutoCalc(TRUE); } else // 反复提醒 { CheckSys(FALSE); } } else if ((!strError1.IsEmpty() || !strError2.IsEmpty() || !strError3.IsEmpty()) && !bModifyDropWell) { CTemporaryResourceOverride vTemp; CElevationCalcCheckDlg dlg; dlg.SetErrorType(strError1 + strError2 + strError3); if (dlg.DoModal() == IDOK) //自动计算 { AutoCalc(); CheckSys(TRUE); // 需检查是否有跌水井错误 } } } bool PositiveElevationCalc::isDropWell(std::vector &data, const AcDbObjectId &idSWell) { double dRet = 0.0; bool bFirst = true; bool bDorpWell = false; std::vector::iterator it; // cet 2011.7.5 modfiy 改为非const迭代器,方便修改 for (it = data.begin(); it != data.end(); it++) { if ((*it).idE == idSWell) { if (bFirst) { bFirst = false; dRet = (*it).dPipeEleE; } else if (fabs(dRet - (*it).dPipeEleE) > 0.0001) // 误差值 { bDorpWell = true; break; } } } // cet 2011.7.5 add 通过此函数判断出的跌水井可能导致计算错误,添加以下代码纠正错误 if (bDorpWell) { // 找出管内底标高最小值 bFirst = true; double dPipeDn = 0.0; AcDbObjectId idPipe; for (it = data.begin(); it != data.end(); it++) { if ((*it).idE == idSWell) { if (bFirst) { bFirst = false; dRet = (*it).dPipeEleE; idPipe = (*it).idP; dPipeDn = (*it).dPipeDn; } else if (dRet > (*it).dPipeEleE) { dRet = (*it).dPipeEleE; idPipe = (*it).idP; dPipeDn = (*it).dPipeDn; } } } if (!!idPipe) { // 管内顶标高 dRet += GetPipeDjById(idPipe, dPipeDn) * 0.001; for (it = data.begin(); it != data.end(); it++) { if ((*it).idS == idSWell) { break; } } // 根据管内顶平接,计算出it中管的起点管内底标高,并将值设置给起点井底标高 if (it != data.end()) { (*it).dWellEleDownS = dRet - GetPipeDjById((*it).idP, (*it).dPipeDn) * 0.001; } } } return bDorpWell; }