395 lines
8.4 KiB
C++
395 lines
8.4 KiB
C++
#include "stdafx.h"
|
|
#include "globalFunc.h"
|
|
#include "ElevationCheckDlg.h"
|
|
#include "Dbwell.h"
|
|
#include <map>
|
|
#include "DbPool.h"
|
|
#include "DbPipe.h"
|
|
|
|
void SplitText(const CString &sText, const CString &sToken, std::vector<CString> &vecText)
|
|
{
|
|
int nIndex = 0;
|
|
CString sTemp = sText;
|
|
do
|
|
{
|
|
nIndex = sTemp.Find(sToken, 0);
|
|
if (nIndex == -1)
|
|
{
|
|
vecText.push_back(sTemp);
|
|
}
|
|
else
|
|
{
|
|
vecText.push_back(sTemp.Left(nIndex));
|
|
sTemp = sTemp.Right(sTemp.GetLength() - nIndex - sToken.GetLength());
|
|
}
|
|
} while (nIndex != -1);
|
|
}
|
|
|
|
void SplitText(const CString &sText, CString &sChars, CString &sNum)
|
|
{
|
|
// cet 2012.8.24 modify
|
|
// CString sTemp = sText;
|
|
// int nIndex = sTemp.GetLength() - 1;
|
|
// TCHAR cTemp = sTemp[nIndex];
|
|
// while (cTemp >= _T('0') && cTemp <= _T('9'))
|
|
// {
|
|
// --nIndex;
|
|
// cTemp = sTemp[nIndex];
|
|
// }
|
|
// sChars = sTemp.Left(nIndex + 1);
|
|
// sNum = sTemp.Right(sTemp.GetLength() - nIndex - 1);
|
|
|
|
if (sText.IsEmpty())
|
|
{
|
|
return;
|
|
}
|
|
CString sTemp = sText;
|
|
int nIndex = sTemp.GetLength() - 1;
|
|
TCHAR cTemp = sTemp[nIndex];
|
|
while (cTemp >= _T('0') && cTemp <= _T('9'))
|
|
{
|
|
--nIndex;
|
|
if (nIndex < 0)
|
|
{
|
|
sNum = sText;
|
|
return;
|
|
}
|
|
cTemp = sTemp[nIndex];
|
|
}
|
|
sChars = sTemp.Left(nIndex + 1);
|
|
sNum = sTemp.Right(sTemp.GetLength() - nIndex - 1);
|
|
}
|
|
|
|
bool LongPipe(const CString &sText1, const CString &sText2)
|
|
{
|
|
std::vector<CString> vecStr1, vecStr2;
|
|
SplitText(sText1, _T("-"), vecStr1);
|
|
SplitText(sText2, _T("-"), vecStr2);
|
|
|
|
if (vecStr2.empty())
|
|
{
|
|
return true;
|
|
}
|
|
|
|
if (vecStr1.empty())
|
|
{
|
|
return false;
|
|
}
|
|
|
|
std::vector<CString>::iterator it1, it2;
|
|
CString sChars1, sChars2, sNum1, sNum2;
|
|
for (it1 = vecStr1.begin(), it2 = vecStr2.begin(); it1 != vecStr1.end() && it2 != vecStr2.end(); it1++, it2++)
|
|
{
|
|
sChars1.Empty();
|
|
sChars2.Empty();
|
|
sNum1.Empty();
|
|
sNum2.Empty();
|
|
SplitText(*it1, sChars1, sNum1);
|
|
SplitText(*it2, sChars2, sNum2);
|
|
|
|
if (sChars1.Compare(sChars2) == 1)
|
|
{
|
|
return false;
|
|
}
|
|
else if (sChars1.Compare(sChars2) == -1)
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
double dVal1 = _tstof(sNum1);
|
|
double dVal2 = _tstof(sNum2);
|
|
if (dVal1 > dVal2)
|
|
{
|
|
return false;
|
|
}
|
|
else if (dVal1 < dVal2)
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (it1 != vecStr1.end())
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (it2 != vecStr2.end())
|
|
{
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
CElevationCheckDlg::CElevationCheckDlg(CWnd* pParent /*=NULL*/)
|
|
: CModelessDialog(CElevationCheckDlg::IDD, pParent)
|
|
{
|
|
//{{AFX_DATA_INIT(CElevationCheckDlg)
|
|
//}}AFX_DATA_INIT
|
|
m_bIsVisible = true;
|
|
}
|
|
|
|
CElevationCheckDlg::~CElevationCheckDlg()
|
|
{
|
|
m_mapPipe.erase(m_mapPipe.begin(), m_mapPipe.end());
|
|
m_vecPipeIds.erase(m_vecPipeIds.begin(), m_vecPipeIds.end());
|
|
m_mapColor.erase(m_mapColor.begin(), m_mapColor.end());
|
|
}
|
|
|
|
void CElevationCheckDlg::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CModelessDialog::DoDataExchange(pDX);
|
|
//{{AFX_DATA_MAP(CElevationCheckDlg)
|
|
DDX_Control(pDX, IDC_LIST_LINE, m_wndLstPipe);
|
|
//}}AFX_DATA_MAP
|
|
}
|
|
|
|
BEGIN_MESSAGE_MAP(CElevationCheckDlg, CModelessDialog)
|
|
//{{AFX_MSG_MAP(CElevationCheckDlg)
|
|
ON_BN_CLICKED(IDC_BUTTON_EXIT, OnClose)
|
|
ON_BN_CLICKED(IDC_BUTTON_SHOW, OnBtnShowall)
|
|
ON_WM_CLOSE()
|
|
ON_WM_TIMER()
|
|
ON_LBN_SELCHANGE(IDC_LIST_LINE, OnSelPipeList)
|
|
//}}AFX_MSG_MAP
|
|
END_MESSAGE_MAP()
|
|
|
|
void CElevationCheckDlg::SetPipeName(std::vector<AcDbObjectId> &vecPipeIds)
|
|
{
|
|
std::vector<AcDbObjectId>::iterator it = vecPipeIds.begin();
|
|
CString sPipeName;
|
|
CString sWellName1;
|
|
CString sWellName2;
|
|
CDbPipe *pPipe = NULL;
|
|
AcDbObjectId idNode1, idNode2;
|
|
for (; it != vecPipeIds.end(); it++)
|
|
{
|
|
AcDbObjectId idPipe = *it;
|
|
acdbOpenObject(pPipe, idPipe, AcDb::kForRead);
|
|
if (pPipe == NULL)
|
|
{
|
|
continue;
|
|
}
|
|
idNode1 = pPipe->GetNode(0);
|
|
idNode2 = pPipe->GetNode(1);
|
|
pPipe->close();
|
|
|
|
GetWellName(idNode1, sWellName1);
|
|
GetWellName(idNode2, sWellName2);
|
|
|
|
if (LongPipe(sWellName1, sWellName2))
|
|
{
|
|
sPipeName.Format(_T("%s-%s"), sWellName1, sWellName2);
|
|
}
|
|
else
|
|
{
|
|
sPipeName.Format(_T("%s-%s"), sWellName2, sWellName1);
|
|
}
|
|
m_mapPipe.insert(std::make_pair(sPipeName, idPipe));
|
|
}
|
|
}
|
|
|
|
void CElevationCheckDlg::GetWellName(AcDbObjectId &idNode, CString &sWellName)
|
|
{
|
|
AcDbEntity *pEnt = NULL;;
|
|
acdbOpenAcDbEntity(pEnt, idNode, AcDb::kForRead);
|
|
if (pEnt == NULL)
|
|
{
|
|
return;
|
|
}
|
|
//考虑出现化粪池的情况
|
|
if (pEnt->isKindOf(CDbPool::desc()))
|
|
{
|
|
sWellName = _T("HC");
|
|
}
|
|
else if (pEnt->isKindOf(AecXDbWell::desc()))
|
|
{
|
|
AecXDbWell *pWell = (AecXDbWell *) pEnt;
|
|
sWellName = pWell->GetWellName();
|
|
}
|
|
pEnt->close();
|
|
}
|
|
|
|
BOOL CElevationCheckDlg::OnInitDialog()
|
|
{
|
|
CModelessDialog::OnInitDialog();
|
|
|
|
#if (ADS == 15)
|
|
SetTimer(1, 2000, NULL);
|
|
#else
|
|
SetTimer(1, 200, NULL);
|
|
#endif
|
|
|
|
//初始化列表框
|
|
std::vector<CString> vecPipeName;
|
|
std::map<CString, AcDbObjectId>::iterator it = m_mapPipe.begin();
|
|
for(; it != m_mapPipe.end(); it++)
|
|
{
|
|
CString sText = it->first;
|
|
vecPipeName.push_back(sText);
|
|
|
|
//保存不符合要求管线的颜色
|
|
CDbPipe *pPipe = NULL;
|
|
AcDbObjectId idPipe = it->second;
|
|
acdbOpenObject(pPipe, idPipe, AcDb::kForRead);
|
|
if (pPipe == NULL)
|
|
{
|
|
continue;
|
|
}
|
|
AcCmColor color = pPipe->color();
|
|
m_mapColor.insert(std::make_pair(idPipe, color));
|
|
pPipe->close();
|
|
}
|
|
|
|
std::sort(vecPipeName.begin(), vecPipeName.end(), LongPipe);//对列表框进行排序
|
|
|
|
std::vector<CString>::iterator iter = vecPipeName.begin();
|
|
for (; iter != vecPipeName.end(); iter++)
|
|
{
|
|
CString sPipeName = *iter;
|
|
m_wndLstPipe.AddString(sPipeName);
|
|
}
|
|
|
|
return TRUE; // return TRUE unless you set the focus to a control
|
|
// EXCEPTION: OCX Property Pages should return FALSE
|
|
}
|
|
|
|
void CElevationCheckDlg::ShowPipe(std::vector<AcDbObjectId> &vecPipeIds, int nColorIndex, bool bIsShow)
|
|
{
|
|
std::vector<AcDbObjectId>::iterator it = vecPipeIds.begin();
|
|
for (; it != vecPipeIds.end(); it++)
|
|
{
|
|
CDbPipe *pPipe = NULL;
|
|
AcDbObjectId idPipe = *it;
|
|
|
|
AcApDocument* pDoc = acDocManager->curDocument();
|
|
acDocManager->lockDocument(pDoc, AcAp::kWrite);
|
|
|
|
acdbOpenObject(pPipe, idPipe, AcDb::kForWrite);
|
|
if (pPipe == NULL)
|
|
{
|
|
continue;
|
|
}
|
|
if (bIsShow)
|
|
{
|
|
pPipe->setVisibility(AcDb::kVisible);
|
|
}
|
|
else
|
|
{
|
|
pPipe->setVisibility(AcDb::kInvisible);
|
|
}
|
|
|
|
//设置管段闪烁颜色不和原管段颜色相同
|
|
CString sLayer = pPipe->GetLayer();
|
|
AcCmColor color;
|
|
GetPipeColor(sLayer, color);
|
|
int nIndex = color.colorIndex();
|
|
if (nColorIndex == 256)//恢复管线颜色
|
|
{
|
|
std::map<AcDbObjectId, AcCmColor>::iterator itColor = m_mapColor.find(idPipe);
|
|
pPipe->setColor(itColor->second);
|
|
}
|
|
else//设置闪烁颜色
|
|
{
|
|
if (nIndex > 1 && nIndex < 8)
|
|
{
|
|
pPipe->setColorIndex(nIndex - 1);
|
|
}
|
|
else
|
|
{
|
|
pPipe->setColorIndex(nIndex + 50);
|
|
}
|
|
}
|
|
pPipe->close();
|
|
|
|
acedUpdateDisplay();
|
|
actrTransactionManager->flushGraphics();
|
|
acDocManager->unlockDocument(pDoc);
|
|
}
|
|
}
|
|
|
|
void CElevationCheckDlg::GetPipeColor(CString &sLayerName, AcCmColor &color)
|
|
{
|
|
AcDbLayerTable *pLyrTable = NULL;
|
|
AcDbLayerTableRecord *pLyrTblRecord = NULL;
|
|
|
|
AcDbDatabase *pDb = NULL;
|
|
pDb = acdbHostApplicationServices()->workingDatabase();
|
|
if(pDb != NULL)
|
|
{
|
|
if(pDb->getLayerTable(pLyrTable, AcDb::kForRead) != Acad::eOk)
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
|
|
if(pLyrTable->has(sLayerName))
|
|
{
|
|
if(pLyrTable->getAt(sLayerName, pLyrTblRecord, AcDb::kForRead, Adesk::kFalse) != Acad::eOk)
|
|
{
|
|
pLyrTable->close();
|
|
return;
|
|
}
|
|
color = pLyrTblRecord->color();
|
|
}
|
|
pLyrTable->close();
|
|
pLyrTblRecord->close();
|
|
}
|
|
|
|
|
|
void CElevationCheckDlg::OnBtnShowall()
|
|
{
|
|
UpdateData();
|
|
ShowPipe(m_vecPipeIds, 256, true);//还原上次高亮闪烁的管段
|
|
m_vecPipeIds.clear();
|
|
std::vector<AcDbObjectId> vecPipeIds;
|
|
std::map<CString, AcDbObjectId>::iterator it = m_mapPipe.begin();
|
|
for(; it != m_mapPipe.end(); it++)
|
|
{
|
|
m_vecPipeIds.push_back(it->second);
|
|
}
|
|
}
|
|
|
|
void CElevationCheckDlg::OnClose()
|
|
{
|
|
DestroyWindow();
|
|
GlobalFunc::PostCommand(_T("\3"), false);
|
|
}
|
|
|
|
void CElevationCheckDlg::OnTimer(UINT_PTR nIDEvent)
|
|
{
|
|
UpdateData();
|
|
ShowPipe(m_vecPipeIds, 50, m_bIsVisible);
|
|
m_bIsVisible = !m_bIsVisible;
|
|
CDialog::OnTimer(nIDEvent);
|
|
}
|
|
|
|
void CElevationCheckDlg::OnSelPipeList()
|
|
{
|
|
UpdateData();
|
|
ShowPipe(m_vecPipeIds, 256, true);//还原上次高亮闪烁的管段
|
|
m_vecPipeIds.clear();
|
|
int nIndex = m_wndLstPipe.GetCurSel();
|
|
if (nIndex < 0)//zxl 2011.11.15 add 避免高版本在list box 中空选 崩溃
|
|
{
|
|
return;
|
|
}
|
|
CString sText = _T("");
|
|
m_wndLstPipe.GetText(nIndex, sText);
|
|
|
|
std::map<CString, AcDbObjectId>::iterator it = m_mapPipe.find(sText);
|
|
if (it != m_mapPipe.end())
|
|
{
|
|
m_vecPipeIds.push_back(it->second);
|
|
}
|
|
}
|
|
|
|
BOOL CElevationCheckDlg::DestroyWindow()
|
|
{
|
|
KillTimer(1);
|
|
ShowPipe(m_vecPipeIds, 256, true);
|
|
return CModelessDialog::DestroyWindow();
|
|
}
|