635 lines
12 KiB
C++
635 lines
12 KiB
C++
#include "StdAfx.h"
|
|
#include "ElevationCalc.h"
|
|
#include "DbWell.h"
|
|
#include "DbPool.h"
|
|
#include"TGAs.h"
|
|
#include <stack>
|
|
#include "LayDepthSetDlg.h"
|
|
|
|
SSearchPipeList* ElevationCalc::GetFarthestSWell(SSearchPipeList* pList)
|
|
{
|
|
std::vector<SSearchPipeList*> data;
|
|
GetStartWell(pList, data);
|
|
|
|
std::vector<SSearchPipeList*>::iterator it;
|
|
double dCurLen = -1;
|
|
SSearchPipeList *pTemp = NULL;
|
|
for(it = data.begin(); it != data.end(); it++)
|
|
{
|
|
if (!(*it)->m_bNeedCale && (*it)->m_nLength > dCurLen)
|
|
{
|
|
dCurLen = (*it)->m_nLength;
|
|
pTemp = *it;
|
|
}
|
|
}
|
|
|
|
return pTemp;
|
|
}
|
|
|
|
double ElevationCalc::GetWellEleUp(const AcDbObjectId &id)
|
|
{
|
|
double dRet = 0.0;
|
|
TDbWell *pWell = NULL;
|
|
acdbOpenObject(pWell, id, AcDb::kForRead);
|
|
if (pWell != NULL)
|
|
{
|
|
dRet = pWell->GetWellEleUp();
|
|
pWell->close();
|
|
}
|
|
|
|
return dRet;
|
|
}
|
|
|
|
double ElevationCalc::GetWellEleDown(const AcDbObjectId &id)
|
|
{
|
|
double dRet = 0.0;
|
|
TDbWell *pWell = NULL;
|
|
acdbOpenObject(pWell, id, AcDb::kForRead);
|
|
if (pWell != NULL)
|
|
{
|
|
dRet = pWell->GetWellEleDown();
|
|
pWell->close();
|
|
}
|
|
|
|
return dRet;
|
|
}
|
|
|
|
double ElevationCalc::GetPipeEleUp(const std::vector<CALCNODE> &data, const AcDbObjectId &idSWell)
|
|
{
|
|
double dRet = 0.0;
|
|
bool bFirst = true;
|
|
AcDbObjectId id;
|
|
int nDn = 0.0;
|
|
std::vector<CALCNODE>::const_iterator it;
|
|
for (it = data.begin(); it != data.end(); it++)
|
|
{
|
|
if ((*it).idE == idSWell)
|
|
{
|
|
if (bFirst)
|
|
{
|
|
bFirst = false;
|
|
dRet = (*it).dPipeEleE;
|
|
id = (*it).idP;
|
|
nDn = (int)(*it).dPipeDn;
|
|
}
|
|
else if (dRet > (*it).dPipeEleE)
|
|
{
|
|
dRet = (*it).dPipeEleE;
|
|
id = (*it).idP;
|
|
nDn = (int)(*it).dPipeDn;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!!id)
|
|
{
|
|
dRet += GetPipeDjById(id, nDn) * 0.001;
|
|
}
|
|
return dRet;
|
|
}
|
|
|
|
double ElevationCalc::GetPipeEleDown(const std::vector<CALCNODE> &data, const AcDbObjectId &idSWell)
|
|
{
|
|
double dRet = 0.0;
|
|
bool bFirst = true;
|
|
std::vector<CALCNODE>::const_iterator it;
|
|
for (it = data.begin(); it != data.end(); it++)
|
|
{
|
|
if ((*it).idE == idSWell)
|
|
{
|
|
if (bFirst)
|
|
{
|
|
bFirst = false;
|
|
dRet = (*it).dPipeEleE;
|
|
}
|
|
else if (dRet > (*it).dPipeEleE)
|
|
{
|
|
dRet = (*it).dPipeEleE;
|
|
}
|
|
}
|
|
}
|
|
return dRet;
|
|
}
|
|
|
|
double ElevationCalc::GetPoolDrop(const AcDbObjectId &id)
|
|
{
|
|
double dRet = 0.0;
|
|
TDbPool *pPool = NULL;
|
|
acdbOpenObject(pPool, id, AcDb::kForRead);
|
|
if (pPool != NULL)
|
|
{
|
|
dRet = pPool->GetSpare();
|
|
pPool->close();
|
|
}
|
|
|
|
if (dRet < 0.01) // cet 2011.6.20 add
|
|
{
|
|
dRet = 0.1;
|
|
}
|
|
|
|
return dRet;
|
|
}
|
|
|
|
double ElevationCalc::GetPoolGroundEle(const AcDbObjectId &id)
|
|
{
|
|
double dRet = 0.0;
|
|
TDbPool *pPool = NULL;
|
|
acdbOpenObject(pPool, id, AcDb::kForRead);
|
|
if (pPool != NULL)
|
|
{
|
|
dRet = pPool->GetGroundEle();
|
|
pPool->close();
|
|
}
|
|
return dRet;
|
|
}
|
|
|
|
CString ElevationCalc::GetPoolName(const AcDbObjectId &id)
|
|
{
|
|
CString strRet;
|
|
TDbPool *pPool = NULL;
|
|
acdbOpenObject(pPool, id, AcDb::kForRead);
|
|
if (pPool != NULL)
|
|
{
|
|
strRet = pPool->GetLabel();
|
|
pPool->close();
|
|
}
|
|
return strRet;
|
|
}
|
|
|
|
double ElevationCalc::GetWellLayDepth(const AcDbObjectId &id)
|
|
{
|
|
double dLayingDepth = m_dLayingDepth;
|
|
std::map<AcDbObjectId, double>::iterator it;
|
|
it = m_mapLayingDepth.find(id);
|
|
if (it != m_mapLayingDepth.end())
|
|
{
|
|
dLayingDepth = (*it).second;
|
|
}
|
|
else
|
|
{
|
|
double dWellDownEle = GetWellEleDown(id);
|
|
if (fabs(dWellDownEle) > 0.001)
|
|
{
|
|
dLayingDepth = GetWellEleUp(id) - dWellDownEle;
|
|
m_mapLayingDepth.insert(std::make_pair(id, dLayingDepth));
|
|
}
|
|
}
|
|
|
|
return dLayingDepth;
|
|
}
|
|
|
|
BOOL ElevationCalc::IsDropWell(AcDbObjectId &id)
|
|
{
|
|
BOOL bDropWell = FALSE;
|
|
TDbWell *pWell = NULL;
|
|
acdbOpenObject(pWell, id, AcDb::kForRead);
|
|
if (pWell != NULL)
|
|
{
|
|
bDropWell = pWell->IsDropWell();
|
|
pWell->close();
|
|
}
|
|
|
|
return bDropWell;
|
|
}
|
|
|
|
void ElevationCalc::GetStartWell(SSearchPipeList *pList, std::vector<SSearchPipeList*> &data)
|
|
{
|
|
std::stack<SSearchPipeList *> dataSt;
|
|
dataSt.push(pList);
|
|
while(!dataSt.empty())
|
|
{
|
|
SSearchPipeList *pTemp = dataSt.top();
|
|
dataSt.pop();
|
|
if (pTemp->m_iType == 3 && pTemp->m_lstNode.Length() == 0) //起点井
|
|
{
|
|
data.push_back(pTemp);
|
|
continue;
|
|
}
|
|
|
|
for(int i = 0; i < pTemp->m_lstNode.Length(); i++)
|
|
{
|
|
dataSt.push(pTemp->m_lstNode[i]);
|
|
}
|
|
}
|
|
}
|
|
|
|
void ElevationCalc::GetSWellByShow(std::vector<SSearchPipeList*> &data)
|
|
{
|
|
SSearchPipeList *pTemp = NULL;
|
|
pTemp = GetFarthestSWell(m_pAllList);
|
|
while(pTemp != NULL)
|
|
{
|
|
data.push_back(pTemp);
|
|
pTemp->m_bNeedCale = TRUE;
|
|
if (pTemp->m_lstNode.Length() >1)
|
|
{
|
|
GetSWellByShow(data);
|
|
}
|
|
|
|
pTemp = pTemp->m_pPrevious;
|
|
}
|
|
}
|
|
|
|
void ElevationCalc::SetPipeSys(SSearchPipeList *pList)
|
|
{
|
|
m_pAllList = pList;
|
|
InitPipeInfo();
|
|
}
|
|
|
|
void ElevationCalc::InitPipeInfo()
|
|
{
|
|
/* cet 2011.6.16 del 不考虑管材
|
|
m_mapPipeDj.clear();
|
|
m_mapPipeThick.clear();
|
|
|
|
// 获得管网中管道管材
|
|
CString strMat; // 管材
|
|
SSearchPipeList *pList = m_pAllList;
|
|
while(pList != NULL)
|
|
{
|
|
if (pList->m_iType == 0)
|
|
{
|
|
TDbPipe *pPipe = NULL;
|
|
acdbOpenObject(pPipe, pList->m_ID, AcDb::kForRead);
|
|
if (pPipe != NULL)
|
|
{
|
|
int nMat = pPipe->GetMaterial();
|
|
strMat = GetPipeMaterialByIdx(nMat);
|
|
pPipe->close();
|
|
}
|
|
break;
|
|
}
|
|
|
|
if (pList->m_lstNode.Length() > 0)
|
|
{
|
|
pList = pList->m_lstNode[0];
|
|
}
|
|
else
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
|
|
// 获取管径信息
|
|
if (!strMat.IsEmpty())
|
|
{
|
|
CodeBase db;
|
|
XString fullFile;
|
|
if(!FindFile(_T("pipe.dbf"), fullFile))
|
|
{
|
|
AfxMessageBox(_T("对不起,没有发现pipe.dbf文件!"));
|
|
return;
|
|
}
|
|
|
|
XDbfTable *pTable = db.Open(fullFile);
|
|
if(!pTable)
|
|
{
|
|
return;
|
|
}
|
|
|
|
CString strMaterial;
|
|
double dDn = 0.0, dDj = 0.0, dDn2 = 0.0;
|
|
for(pTable->MoveFirst();!pTable->IsEOF();pTable->MoveNext())
|
|
{
|
|
GET_FIELD(pTable, _T("GC"), strMaterial);
|
|
GET_FIELD(pTable, _T("DN"), dDn);
|
|
if(strMaterial.CompareNoCase(strMat) == 0)
|
|
{
|
|
GET_FIELD(pTable, _T("D"), dDn2); // 外径
|
|
GET_FIELD(pTable, _T("DJ"), dDj); // 内径
|
|
|
|
m_mapPipeDj.insert(std::make_pair(dDn, dDj));
|
|
m_mapPipeThick.insert(std::make_pair(dDn, (dDn2 - dDj) * 0.5));
|
|
}
|
|
}
|
|
pTable->Close();
|
|
}
|
|
*/
|
|
}
|
|
|
|
void ElevationCalc::SetLayingDepth(double dLayingDepth)
|
|
{
|
|
m_dLayingDepth = dLayingDepth;
|
|
}
|
|
|
|
void ElevationCalc::SetMinThick(double dMinThick)
|
|
{
|
|
m_dMinThick = dMinThick;
|
|
}
|
|
|
|
void ElevationCalc::Sort(std::vector<CALCNODE> &info)
|
|
{
|
|
std::vector<SSearchPipeList*>::iterator it1;
|
|
for(it1 = m_vecWell.begin(); it1 != m_vecWell.end(); it1++)
|
|
{
|
|
(*it1)->m_bNeedCale = FALSE;
|
|
}
|
|
|
|
std::vector<SSearchPipeList*> data;
|
|
GetSWellByShow(data);
|
|
|
|
// 按显示顺序排列表格信息
|
|
std::vector<CALCNODE> vec;
|
|
for(it1 = data.begin(); it1 != data.end(); it1++)
|
|
{
|
|
SSearchPipeList *pTemp = *it1;
|
|
while(pTemp != NULL)
|
|
{
|
|
if (pTemp->m_iType == 3 || pTemp->m_iType == 4)
|
|
{
|
|
bool bExist = false;
|
|
std::vector<CALCNODE>::iterator it;
|
|
for(it = vec.begin(); it != vec.end(); it++)
|
|
{
|
|
if ((*it).idS == pTemp->m_ID)
|
|
{
|
|
bExist = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (bExist)
|
|
{
|
|
break;
|
|
}
|
|
|
|
for(it = m_vecLstData.begin(); it != m_vecLstData.end(); it++)
|
|
{
|
|
if ((*it).idS == pTemp->m_ID)
|
|
{
|
|
vec.push_back(*it);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
pTemp = pTemp->m_pPrevious;
|
|
}
|
|
}
|
|
|
|
info = vec;
|
|
}
|
|
|
|
void ElevationCalc::UpDatePipeSys()
|
|
{
|
|
std::stack<SSearchPipeList *> data;
|
|
data.push(m_pAllList);
|
|
while(!data.empty())
|
|
{
|
|
SSearchPipeList *plist = data.top();
|
|
data.pop();
|
|
if (plist->m_iType == 0)
|
|
{
|
|
TDbPipe *pPipe = NULL;
|
|
acdbOpenObject(pPipe, plist->m_ID, AcDb::kForRead);
|
|
if (pPipe != NULL)
|
|
{
|
|
XPoint ptS, ptE;
|
|
ptS = pPipe->StartPoint();
|
|
ptE = pPipe->EndPoint();
|
|
ptS.z = 0;
|
|
ptE.z = 0;
|
|
plist->m_nLength = ptS.Distance(ptE);
|
|
if (!DocGetMeterUnitDraw())
|
|
{
|
|
plist->m_nLength /= 1000.0;
|
|
}
|
|
plist->m_iDn = pPipe->GetDnDiameter();
|
|
pPipe->close();
|
|
}
|
|
}
|
|
|
|
plist->m_iSpare = 0;
|
|
plist->m_bNeedCale = FALSE;
|
|
for(int i = 0; i < plist->m_lstNode.Length(); i++)
|
|
{
|
|
data.push(plist->m_lstNode[i]);
|
|
}
|
|
}
|
|
}
|
|
|
|
void ElevationCalc::CalcLenStartWellToEnd(SSearchPipeList *pList, double dCurLen)
|
|
{
|
|
if (pList->m_iType == 0)
|
|
{
|
|
dCurLen += pList->m_nLength;
|
|
}
|
|
else if (pList->m_iType == 3 && pList->m_lstNode.Length() == 0)
|
|
{
|
|
pList->m_nLength = dCurLen;
|
|
m_vecWell.push_back(pList);
|
|
return;
|
|
}
|
|
|
|
for (int i = 0; i < pList->m_lstNode.Length(); i++)
|
|
{
|
|
CalcLenStartWellToEnd(pList->m_lstNode[i], dCurLen);
|
|
}
|
|
}
|
|
|
|
void ElevationCalc::ModifyWellInfo(const AcDbObjectId &id, double dEleUp, double dEleDown, BOOL bDrop)
|
|
{
|
|
std::vector<CALCNODE>::iterator it;
|
|
for(it = m_vecLstData.begin(); it != m_vecLstData.end(); it++)
|
|
{
|
|
if ((*it).idS == id)
|
|
{
|
|
(*it).dWellEleUpS = dEleUp;
|
|
if (bDrop)
|
|
{
|
|
(*it).dWellEleDownS = dEleDown;
|
|
}
|
|
(*it).bIsDropWell = bDrop;
|
|
}
|
|
else if ((*it).idE == id)
|
|
{
|
|
(*it).dWellEleUpE = dEleUp;
|
|
}
|
|
}
|
|
}
|
|
|
|
void ElevationCalc::ModifyWellLayingDepth(const AcDbObjectId &id, double dLayingDepth)
|
|
{
|
|
m_mapLayingDepth.erase(id);
|
|
m_mapLayingDepth.insert(std::make_pair(id, dLayingDepth));
|
|
}
|
|
|
|
std::vector<CALCNODE>& ElevationCalc::GetLstData()
|
|
{
|
|
return m_vecLstData;
|
|
}
|
|
|
|
std::vector<SSearchPipeList*>& ElevationCalc::GetStartWell()
|
|
{
|
|
return m_vecWell;
|
|
}
|
|
|
|
// 管段壁厚
|
|
double ElevationCalc::GetPipeThickById(const AcDbObjectId &id, double dDn)
|
|
{
|
|
double dThick(0);
|
|
std::map<double,double>::iterator it;
|
|
it = m_mapPipeThick.find(dDn);
|
|
if (it != m_mapPipeThick.end())
|
|
{
|
|
dThick = (*it).second * 0.001;
|
|
}
|
|
return dThick;
|
|
}
|
|
|
|
void ElevationCalc::UpdateDropWell(const std::map<AcDbObjectId,double> &data)
|
|
{
|
|
m_mapDropWell = data;
|
|
}
|
|
|
|
void ElevationCalc::SetPipeEleDown(double dEle)
|
|
{
|
|
m_dPipeEleDown = dEle;
|
|
}
|
|
|
|
int ElevationCalc::Compare(double dVal1, double dVal2)
|
|
{
|
|
if (fabs(dVal1 - dVal2) < 1e-3)
|
|
{
|
|
return 0;
|
|
}
|
|
else if (dVal1 > dVal2)
|
|
{
|
|
return 1;
|
|
}
|
|
else
|
|
{
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
void ElevationCalc::ModifyPipe(const AcDbObjectId &idPipe, double dVal, BOOL bDn)
|
|
{
|
|
std::vector<CALCNODE>::iterator it;
|
|
for (it = m_vecLstData.begin(); it != m_vecLstData.end(); it++)
|
|
{
|
|
if ((*it).idP == idPipe)
|
|
{
|
|
if (bDn)
|
|
{
|
|
(*it).dPipeDn = dVal;
|
|
}
|
|
else
|
|
{
|
|
(*it).dGradient = dVal * 0.001;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
void ElevationCalc::GetCheckInfoforPipe(std::vector<AcDbObjectId> &data)
|
|
{
|
|
data = m_vecCheckforPipe;
|
|
}
|
|
|
|
double ElevationCalc::GetPipeDjById(const AcDbObjectId &id, double dDn)
|
|
{
|
|
// 使用nDn作为外径
|
|
double dPipeDn(0.0);
|
|
dPipeDn = dDn; // cet 2011.6.16 add 未找到时使用dDn
|
|
std::map<double,double>::iterator it;
|
|
it = m_mapPipeDj.find(dDn);
|
|
if (it != m_mapPipeDj.end())
|
|
{
|
|
dPipeDn = (*it).second;
|
|
}
|
|
return dPipeDn;
|
|
}
|
|
|
|
void ElevationCalc::EnableSetLayDepth( bool bVal )
|
|
{
|
|
m_bShowTip = bVal;
|
|
}
|
|
|
|
void ElevationCalc::SetLayDepthData( std::map<AcDbObjectId,LayingDepthNode> *pMapData )
|
|
{
|
|
m_pMapSWellLayDepth = pMapData;
|
|
}
|
|
|
|
void ElevationCalc::UpdateSWellLayDepth()
|
|
{
|
|
if (m_bShowTip)
|
|
{
|
|
int nSel = 0;
|
|
if (!m_bOnlySWell)
|
|
{
|
|
CLayDepthSetDlg dlg;
|
|
if (dlg.DoModal() != IDOK)
|
|
{
|
|
return;
|
|
}
|
|
|
|
nSel = dlg.GetSel();
|
|
}
|
|
else
|
|
{
|
|
nSel = 0;
|
|
}
|
|
|
|
switch (nSel)
|
|
{
|
|
case 0:
|
|
{
|
|
UpdateSWellLayDepth(eUserSet);
|
|
UpdateSWellLayDepth(eCalc);
|
|
UpdateSWellLayDepth(eUserModify);
|
|
UpdateSWellLayDepth(eLayingDepth);
|
|
break;
|
|
}
|
|
case 1:
|
|
{
|
|
break;
|
|
}
|
|
case 2:
|
|
{
|
|
UpdateSWellLayDepth(eCalc);
|
|
UpdateSWellLayDepth(eLayingDepth);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
UpdateSWellLayDepth(eLayingDepth);
|
|
}
|
|
}
|
|
|
|
void ElevationCalc::UpdateSWellLayDepth( LayingDepthType type )
|
|
{
|
|
if (m_pMapSWellLayDepth != NULL)
|
|
{
|
|
std::map<AcDbObjectId,LayingDepthNode>::iterator itM;
|
|
std::map<AcDbObjectId, double>::iterator it;
|
|
for (itM = m_pMapSWellLayDepth->begin(); itM != m_pMapSWellLayDepth->end(); itM++)
|
|
{
|
|
if (itM->second.type != type)
|
|
{
|
|
continue;
|
|
}
|
|
itM->second.type = eLayingDepth;
|
|
it = m_mapLayingDepth.find(itM->first);
|
|
if (it != m_mapLayingDepth.end())
|
|
{
|
|
it->second = m_dLayingDepth;
|
|
itM->second.dLayingDepth = m_dLayingDepth;
|
|
}
|
|
else
|
|
{
|
|
m_mapLayingDepth.insert(std::make_pair(itM->first, m_dLayingDepth));
|
|
itM->second.dLayingDepth = m_dLayingDepth;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void ElevationCalc::SetOnlySWell( bool bOnly )
|
|
{
|
|
m_bOnlySWell = bOnly;
|
|
}
|