373 lines
8.3 KiB
C++
373 lines
8.3 KiB
C++
#include "StdAfx.h"
|
|
#include "LayerSiftDlg.h"
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////
|
|
CLayerFiltrationFileOperator::CLayerFiltrationFileOperator(LPCTSTR szFileName)
|
|
: m_sFileName(szFileName)
|
|
{
|
|
}
|
|
|
|
BOOL CLayerFiltrationFileOperator::ReadFile(CStringArray &aryLayers) const
|
|
{
|
|
CStdioFile txtFile;
|
|
UINT uLen = 0;
|
|
if (!txtFile.Open(m_sFileName, CFile::modeRead))
|
|
return FALSE;
|
|
|
|
CStringArray arSCurName;
|
|
CString sCurrString = _T("");
|
|
|
|
while (txtFile.ReadString(sCurrString))
|
|
{
|
|
if (sCurrString == _T(""))
|
|
continue;
|
|
|
|
arSCurName.Add(sCurrString);
|
|
}
|
|
|
|
int nSize = arSCurName.GetSize();
|
|
if (nSize > 0)
|
|
{
|
|
bool bFind(false);
|
|
for (int i=0; i<nSize; i++)
|
|
{
|
|
for (int j=0; j<aryLayers.GetSize(); j++)
|
|
{
|
|
if (arSCurName[i] == aryLayers[j])
|
|
{
|
|
bFind = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (!bFind)
|
|
aryLayers.Add(arSCurName[i]);
|
|
bFind = false;
|
|
}
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
BOOL CLayerFiltrationFileOperator::WriteFile(const CStringArray &aryLayers) const
|
|
{
|
|
CStdioFile txtFile;
|
|
UINT uLen = 0;
|
|
if (!txtFile.Open(m_sFileName, CFile::modeCreate | CFile::modeWrite))
|
|
return FALSE;
|
|
|
|
CString sRet = _T("\n");
|
|
|
|
//add tyj 20160905:默认图层设为空时,也可以写入文件
|
|
if(aryLayers.IsEmpty())
|
|
{
|
|
txtFile.WriteString(_T(""));
|
|
return TRUE;
|
|
}
|
|
|
|
for (int i=0; i<aryLayers.GetSize(); i++)
|
|
{
|
|
if (i != 0)
|
|
txtFile.WriteString(sRet);
|
|
txtFile.WriteString(aryLayers[i]);
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
BOOL CLayerFiltrationFileOperator::SplitString(CString sAllName, CStringArray &aryLayers)
|
|
{
|
|
CString sReturn = _T("&");
|
|
|
|
aryLayers.RemoveAll();
|
|
while (TRUE)
|
|
{
|
|
int nIndex = sAllName.Find(sReturn);
|
|
if (nIndex < 0) // 没找到
|
|
{
|
|
if (sAllName != _T(""))
|
|
aryLayers.Add(sAllName);
|
|
break;
|
|
}
|
|
else
|
|
{
|
|
CString sDump = sAllName.Mid(0, nIndex);
|
|
sAllName = sAllName.Mid(nIndex+1, sAllName.GetLength() - nIndex - 1);
|
|
if (sDump != _T(""))
|
|
aryLayers.Add(sDump);
|
|
}
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////
|
|
CString CLayerSiftDlg::s_sRet = _T("\r\n");
|
|
CString CLayerSiftDlg::s_sSplit = _T("&");
|
|
CString CLayerSiftDlg::m_csIniFileLayer = _T(""); // 图层
|
|
BOOL CLayerSiftDlg::m_bSelectEnt = FALSE;
|
|
CString CLayerSiftDlg::m_csTmpLayer = _T("");
|
|
|
|
IMPLEMENT_DYNAMIC(CLayerSiftDlg, CModelessDialog);
|
|
CLayerSiftDlg::CLayerSiftDlg(CWnd* pParent) : CModelessDialog(CLayerSiftDlg::IDD, pParent)
|
|
{
|
|
SPACE = -1;
|
|
|
|
CString csSysPath = g_sDwbPath;
|
|
csSysPath = csSysPath.Left(csSysPath.GetLength() - 5) + _T("\\sys\\");
|
|
|
|
// 因为该文件负有写入的责任,因此即使该文件不存在,也需要建立该指针
|
|
m_pFileBase = new CLayerFiltrationFileOperator(csSysPath + _T("LayerFiltration.txt"));
|
|
|
|
if (m_pFileBase != NULL)
|
|
{
|
|
if (m_bSelectEnt) // 当前是选择实体后,再次显示对话框
|
|
{
|
|
m_pFileBase->SplitString(m_csTmpLayer, m_aryTmpLayer);
|
|
}
|
|
else if (!m_csIniFileLayer.IsEmpty())
|
|
{
|
|
m_pFileBase->SplitString(m_csIniFileLayer, m_aryTmpLayer);
|
|
}
|
|
}
|
|
|
|
m_bSelectEnt = FALSE;
|
|
m_csTmpLayer = _T("");
|
|
}
|
|
|
|
CLayerSiftDlg::~CLayerSiftDlg()
|
|
{
|
|
if (m_pFileBase != NULL)
|
|
{
|
|
delete m_pFileBase;
|
|
m_pFileBase = NULL;
|
|
}
|
|
}
|
|
|
|
void CLayerSiftDlg::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CModelessDialog::DoDataExchange(pDX);
|
|
DDX_Control(pDX, IDC_EDIT_LAYER, m_edtLayerName);
|
|
}
|
|
|
|
BOOL CLayerSiftDlg::OnInitDialog()
|
|
{
|
|
CModelessDialog::OnInitDialog();
|
|
|
|
CString sText;
|
|
for (int i=0; i<m_aryTmpLayer.GetSize(); i++)
|
|
{
|
|
sText += m_aryTmpLayer[i];
|
|
sText += s_sRet;
|
|
}
|
|
|
|
m_edtLayerName.SetFont(GetFont());
|
|
m_edtLayerName.SetWindowText(sText);
|
|
m_edtLayerName.SetSel(sText.GetLength(), sText.GetLength(), FALSE);
|
|
|
|
InitSpaceSize();
|
|
|
|
CRect rectDlg;
|
|
GetWindowRect(&rectDlg);
|
|
GetClientRect(&rectDlg);
|
|
Layout(rectDlg.Width(), rectDlg.Height()); // 布置按钮
|
|
|
|
HICON hIcon = AfxGetApp()->LoadIcon(IDI_TG_LOGO);
|
|
SetIcon(hIcon, FALSE);
|
|
|
|
UpdateData(FALSE);
|
|
return TRUE;
|
|
}
|
|
|
|
void CLayerSiftDlg::InitSpaceSize()
|
|
{
|
|
CRect rectBtn;
|
|
GetDlgItem(IDC_BTN_SELECTINDRAW)->GetWindowRect(&rectBtn); // 图中选取<
|
|
ScreenToClient(&rectBtn);
|
|
|
|
BTNWID = rectBtn.Width();
|
|
BTNHEI = rectBtn.Height();
|
|
SPACEBTN = (int)(BTNHEI * 0.5);
|
|
|
|
CRect rectTable;
|
|
GetDlgItem(IDC_EDIT_LAYER)->GetWindowRect(&rectTable);
|
|
ScreenToClient(&rectTable);
|
|
|
|
SPACE = rectTable.left;
|
|
PSPACE = rectTable.top;
|
|
}
|
|
|
|
void CLayerSiftDlg::LstLayerRect(CRect &rect, int dlgCx, int dlgCy)
|
|
{
|
|
int nLastWid = dlgCx - SPACE*3 - BTNWID,
|
|
nHei = dlgCy - PSPACE*2;
|
|
|
|
rect.left = SPACE;
|
|
rect.right = rect.left + nLastWid;
|
|
rect.top = PSPACE;
|
|
rect.bottom = rect.top + nHei;
|
|
}
|
|
|
|
void CLayerSiftDlg::BtnSelectInDrawRect(CRect &rect, int dlgCx, int dlgCy)
|
|
{
|
|
rect.left = rect.right + SPACE;
|
|
rect.right = rect.left + BTNWID;
|
|
rect.top = rect.top;
|
|
rect.bottom = rect.top + BTNHEI;
|
|
}
|
|
|
|
void CLayerSiftDlg::BtnOkRect(CRect &rect, int dlgCx, int dlgCy)
|
|
{
|
|
BtnCancelRect(rect, dlgCx, dlgCy);
|
|
|
|
rect.bottom = rect.top - SPACEBTN;
|
|
rect.top = rect.bottom - BTNHEI;
|
|
}
|
|
|
|
void CLayerSiftDlg::BtnCancelRect(CRect &rect, int dlgCx, int dlgCy)
|
|
{
|
|
CRect rectRef;
|
|
LstLayerRect(rectRef, dlgCx, dlgCy);
|
|
|
|
rect.left = rectRef.right + SPACE;
|
|
rect.right = rect.left + BTNWID;
|
|
rect.bottom = dlgCy - PSPACE;
|
|
rect.top = rect.bottom - BTNHEI;
|
|
}
|
|
|
|
void CLayerSiftDlg::Layout(int cx, int cy)
|
|
{
|
|
CRect rectTable;
|
|
LstLayerRect(rectTable, cx, cy);
|
|
GetDlgItem(IDC_EDIT_LAYER)->SetWindowPos(NULL, rectTable.left, rectTable.top, rectTable.Width(), rectTable.Height(), SWP_NOZORDER);
|
|
|
|
BtnSelectInDrawRect(rectTable, cx, cy);
|
|
GetDlgItem(IDC_BTN_SELECTINDRAW)->SetWindowPos(NULL, rectTable.left, rectTable.top, rectTable.Width(), rectTable.Height(), SWP_NOZORDER);
|
|
|
|
BtnOkRect(rectTable, cx, cy);
|
|
GetDlgItem(IDOK)->SetWindowPos(NULL, rectTable.left, rectTable.top, rectTable.Width(), rectTable.Height(), SWP_NOZORDER);
|
|
|
|
BtnCancelRect(rectTable, cx, cy);
|
|
GetDlgItem(IDCANCEL)->SetWindowPos(NULL, rectTable.left, rectTable.top, rectTable.Width(), rectTable.Height(), SWP_NOZORDER);
|
|
}
|
|
|
|
BEGIN_MESSAGE_MAP(CLayerSiftDlg, CModelessDialog)
|
|
ON_BN_CLICKED(IDC_BTN_SELECTINDRAW, OnBlickSelectOnDraw)
|
|
ON_BN_CLICKED(IDOK, OnBnClickedOk)
|
|
ON_WM_SIZE()
|
|
ON_WM_GETMINMAXINFO()
|
|
END_MESSAGE_MAP()
|
|
|
|
// 支持对话框大小变化
|
|
void CLayerSiftDlg::OnSize(UINT nType, int cx, int cy)
|
|
{
|
|
CModelessDialog::OnSize(nType, cx, cy);
|
|
if (IsInitSizeData())
|
|
Layout(cx, cy);
|
|
}
|
|
|
|
// 设置拖动对话框时,最小不应该小于最初值
|
|
void CLayerSiftDlg::OnGetMinMaxInfo(MINMAXINFO* lpMMI)
|
|
{
|
|
lpMMI->ptMinTrackSize.x = 270;
|
|
lpMMI->ptMinTrackSize.y = 174;
|
|
|
|
CModelessDialog::OnGetMinMaxInfo(lpMMI);
|
|
}
|
|
|
|
void CLayerSiftDlg::OnBnClickedOk()
|
|
{
|
|
CString strName;
|
|
m_edtLayerName.GetWindowText(strName);
|
|
strName.Replace(s_sRet, s_sSplit);
|
|
strName.TrimLeft(_T("&"));
|
|
strName.TrimRight(_T("&"));
|
|
|
|
// 写文件
|
|
if (m_pFileBase != NULL)
|
|
{
|
|
m_pFileBase->SplitString(strName, m_aryTmpLayer);
|
|
m_pFileBase->WriteFile(m_aryTmpLayer);
|
|
m_csIniFileLayer = strName;
|
|
}
|
|
|
|
m_bSelectEnt = FALSE;
|
|
m_csTmpLayer = _T("");
|
|
CModelessDialog::OnOK();
|
|
}
|
|
|
|
void CLayerSiftDlg::OnBlickSelectOnDraw()
|
|
{
|
|
m_bSelectEnt = TRUE;
|
|
|
|
m_edtLayerName.GetWindowText(m_csTmpLayer);
|
|
m_csTmpLayer.Replace(s_sRet, s_sSplit);
|
|
m_csTmpLayer.TrimLeft(_T("&"));
|
|
m_csTmpLayer.TrimRight(_T("&"));
|
|
|
|
CModelessDialog::OnOK();
|
|
}
|
|
|
|
// 返回用户设置的图层名
|
|
CString CLayerSiftDlg::GetLayerName()
|
|
{
|
|
CString csText;
|
|
for (int i=0; i<m_aryTmpLayer.GetSize(); i++)
|
|
{
|
|
if (i != 0)
|
|
csText += s_sSplit;
|
|
csText += m_aryTmpLayer[i];
|
|
}
|
|
return csText;
|
|
}
|
|
|
|
void CLayerSiftDlg::SetLayerName(const CStringArray &aryLayers)
|
|
{
|
|
int nSize = aryLayers.GetSize();
|
|
if (nSize == 0) // 从文件中读取记忆值
|
|
{
|
|
GetLayerInIniFiles();
|
|
}
|
|
else // 判断是否需要向m_strLayerName里添加
|
|
{
|
|
bool bFind(false);
|
|
for (int i=0; i<nSize; i++)
|
|
{
|
|
for (int j=0; j<m_aryTmpLayer.GetSize(); j++)
|
|
{
|
|
if (aryLayers[i] == m_aryTmpLayer[j])
|
|
{
|
|
bFind = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (!bFind)
|
|
m_aryTmpLayer.Add(aryLayers[i]);
|
|
bFind = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
void CLayerSiftDlg::GetLayerInIniFiles()
|
|
{
|
|
CString csLayer;
|
|
if ((m_pFileBase!=NULL) && (m_pFileBase->ReadFile(m_aryTmpLayer)) && m_aryTmpLayer.GetSize()>0)
|
|
{
|
|
m_csIniFileLayer = _T("");
|
|
for (int i=0; i<m_aryTmpLayer.GetSize(); i++)
|
|
{
|
|
if (i != 0)
|
|
m_csIniFileLayer += s_sSplit;
|
|
m_csIniFileLayer += m_aryTmpLayer[i];
|
|
}
|
|
}
|
|
}
|