587 lines
13 KiB
C++
587 lines
13 KiB
C++
#include "stdafx.h"
|
|
#include "LayoutLegendDlg.h"
|
|
#include "TGAs.h"
|
|
#include "rxregsvc.h"
|
|
|
|
|
|
CLegendFiltrationFileOperator::CLegendFiltrationFileOperator(LPCTSTR szFileName)
|
|
: m_sFileName(szFileName)
|
|
{
|
|
}
|
|
|
|
BOOL CLegendFiltrationFileOperator::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 CLegendFiltrationFileOperator::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");
|
|
|
|
for (int i=0; i<aryLayers.GetSize(); i++)
|
|
{
|
|
if (i != 0)
|
|
txtFile.WriteString(sRet);
|
|
txtFile.WriteString(aryLayers[i]);
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
BOOL CLegendFiltrationFileOperator::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;
|
|
}
|
|
|
|
|
|
S_VEC ClayoutLegendDlg::s_vecLegendLst;
|
|
ClayoutLegendDlg::ClayoutLegendDlg(CWnd* pParent):
|
|
CModelessDialog(ClayoutLegendDlg::IDD, pParent),
|
|
m_iSelectLstCurSel(-1),
|
|
m_iDragBeginItem(0),
|
|
m_iDragEndItem(0),
|
|
m_iDragFlag(-1)
|
|
{
|
|
|
|
CString csSysPath = g_sDwbPath;
|
|
csSysPath = csSysPath.Left(csSysPath.GetLength() - 5) + _T("\\sys\\");
|
|
|
|
// 因为该文件负有写入的责任,因此即使该文件不存在,也需要建立该指针
|
|
m_pFileBase = new CLegendFiltrationFileOperator(csSysPath + _T("LegendFiltration.txt"));
|
|
m_pFileBase->ReadFile(m_aryTmpLegend);
|
|
}
|
|
|
|
ClayoutLegendDlg::~ClayoutLegendDlg()
|
|
{
|
|
if (m_pFileBase != NULL)
|
|
{
|
|
m_aryTmpLegend.RemoveAll();
|
|
m_aryTmpLegend.Add(m_strColumnNum);
|
|
for (size_t i=0;i<s_vecLegendLst.size();i++)
|
|
{
|
|
m_aryTmpLegend.Add(s_vecLegendLst[i].sItem);
|
|
}
|
|
m_pFileBase->WriteFile(m_aryTmpLegend);
|
|
delete m_pFileBase;
|
|
m_pFileBase = NULL;
|
|
}
|
|
}
|
|
|
|
void ClayoutLegendDlg::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CModelessDialog::DoDataExchange(pDX);
|
|
DDX_Control(pDX, IDC_CMB_COLUMN, m_cloumnNumBox);
|
|
DDX_CBString(pDX,IDC_CMB_COLUMN,m_strColumnNum);
|
|
}
|
|
|
|
BEGIN_MESSAGE_MAP(ClayoutLegendDlg, CModelessDialog)
|
|
ON_NOTIFY(NM_DBLCLK, IDC_LIS_SELECTLEGEND, OnNMDblclkLisSelectlegend)
|
|
ON_BN_CLICKED(IDC_BUT_ADD, OnBnClickedButAdd)
|
|
ON_NOTIFY(NM_DBLCLK, IDC_LIS_LEGENDLIST, OnNMDblclkLisLegendlist)
|
|
ON_BN_CLICKED(IDC_BUT_DELETE, OnBnClickedButDelete)
|
|
ON_NOTIFY(LVN_BEGINDRAG, IDC_LIS_LEGENDLIST,OnLvnBegindragLisLegendlist)
|
|
ON_NOTIFY(LVN_HOTTRACK, IDC_LIS_LEGENDLIST, OnLvnHotTrackLisLegendlist)
|
|
ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIS_SELECTLEGEND, OnLvnItemchangedLisSelectlegend)
|
|
ON_BN_CLICKED(IDC_BUT_NEWLEGEND, OnBnClickedButNewlegend)
|
|
ON_CBN_SELCHANGE(IDC_CMB_COLUMN, OnCbnSelchangeCmbColumn)
|
|
ON_CBN_EDITCHANGE(IDC_CMB_COLUMN, OnCbnEditchangeCmbColumn)
|
|
ON_WM_PAINT()
|
|
ON_BN_CLICKED(IDC_BUT_EMPTY, &ClayoutLegendDlg::OnBnClickedButEmpty)
|
|
END_MESSAGE_MAP()
|
|
|
|
BOOL ClayoutLegendDlg::OnInitDialog()
|
|
{
|
|
CModelessDialog::OnInitDialog();
|
|
|
|
//初始化对话框控件位置
|
|
|
|
CListCtrl *pSelectList = ((CListCtrl*)(GetDlgItem(IDC_LIS_SELECTLEGEND)));
|
|
DWORD dwStyle = pSelectList->GetExtendedStyle();
|
|
dwStyle |= LVS_EX_FULLROWSELECT;
|
|
pSelectList->SetExtendedStyle(dwStyle);
|
|
CRect rect;
|
|
pSelectList->GetClientRect(rect);
|
|
pSelectList->InsertColumn(0,_T(""),LVCFMT_LEFT,3*rect.Width());
|
|
|
|
DWORD style = ((CListCtrl*)(GetDlgItem(IDC_LIS_LEGENDLIST)))->GetExtendedStyle();
|
|
((CListCtrl*)(GetDlgItem(IDC_LIS_LEGENDLIST)))->SetExtendedStyle((style|LVS_EX_FULLROWSELECT));
|
|
((CListCtrl*)(GetDlgItem(IDC_LIS_LEGENDLIST)))->InsertColumn(0,_T(""),LVCFMT_LEFT,rect.Width());
|
|
|
|
//初始化
|
|
if(LoadDBFFile(_T("总图图例.TK")))
|
|
{
|
|
UpdateLegendSel();
|
|
GetLegendLst();
|
|
UpdateLegendLst();
|
|
m_iSelectLstCurSel = 0;
|
|
}
|
|
for (int i = 1 ; i <= 10; ++i) {
|
|
CString strNum;
|
|
strNum.Format(_T("%d"), i);
|
|
m_cloumnNumBox.InsertString(i-1, strNum);
|
|
}
|
|
if (!m_strColumnNum.IsEmpty())
|
|
{
|
|
m_cloumnNumBox.SetWindowText(m_strColumnNum);
|
|
}
|
|
else
|
|
{
|
|
m_cloumnNumBox.SetCurSel(0);
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
bool ClayoutLegendDlg::LoadDBFFile(LPCTSTR szName)
|
|
{
|
|
|
|
//文件路径
|
|
XString sFilePath;
|
|
if (!FindFile(szName, sFilePath))
|
|
{
|
|
CString sTip;
|
|
sTip.Format(_T("对不起,没有发现[%s]文件!"),szName);
|
|
AfxMessageBox(sTip);
|
|
return false;
|
|
}
|
|
|
|
//打开文件
|
|
CodeBase db;
|
|
XDbfTable *pTable = db.Open(sFilePath);
|
|
if (pTable == NULL)
|
|
{
|
|
acutPrintf(_T("\n打开文件%s失败!\n"), sFilePath);
|
|
return false;
|
|
}
|
|
|
|
//清空容器
|
|
while (!m_vecLegendSel.empty())
|
|
{
|
|
m_vecLegendSel.pop_back();
|
|
}
|
|
|
|
//读取数据
|
|
CString sKind;
|
|
CString sItem;
|
|
CString sDrawing;
|
|
while(!pTable->IsEOF())
|
|
{
|
|
GET_FIELD(pTable, _T("Kind"), sKind);
|
|
GET_FIELD(pTable, _T("Item"), sItem);
|
|
GET_FIELD(pTable, _T("Drawing"), sDrawing);
|
|
|
|
if (pTable->IsDeleted())
|
|
{
|
|
pTable->MoveNext();
|
|
continue;
|
|
}
|
|
|
|
LEGENDDATA tem;
|
|
tem.sKind = sKind;
|
|
tem.sItem = sItem;
|
|
tem.sDrawing = sDrawing;
|
|
m_vecLegendSel.push_back(tem);
|
|
|
|
|
|
pTable->MoveNext();
|
|
}
|
|
|
|
pTable->Close();
|
|
|
|
if ((int)m_vecLegendSel.size()<=0)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
void ClayoutLegendDlg::UpdateLegendSel()
|
|
{
|
|
CListCtrl *pLst = ((CListCtrl*)(GetDlgItem(IDC_LIS_SELECTLEGEND)));
|
|
pLst->DeleteAllItems();
|
|
|
|
for (size_t i=0;i<m_vecLegendSel.size();i++)
|
|
{
|
|
pLst->InsertItem(i,_T(""));
|
|
pLst->SetItemText(i,0,m_vecLegendSel[i].sItem);
|
|
}
|
|
}
|
|
|
|
void ClayoutLegendDlg::UpdateLegendLst()
|
|
{
|
|
//如果有图例被删除
|
|
for (int index = 0; index < (int)s_vecLegendLst.size(); index++)
|
|
{
|
|
if (!IsItemExist(m_vecLegendSel,s_vecLegendLst[index]))
|
|
{
|
|
S_VEC::iterator iteor = s_vecLegendLst.begin() + index;
|
|
s_vecLegendLst.erase(iteor);
|
|
}
|
|
else//查看是否重命名
|
|
{
|
|
S_VEC::iterator iterRe;
|
|
iterRe = find(m_vecLegendSel.begin(),m_vecLegendSel.end(),s_vecLegendLst[index]);
|
|
if (s_vecLegendLst[index].sItem != (*iterRe).sItem)
|
|
{
|
|
s_vecLegendLst[index].sItem = (*iterRe).sItem;
|
|
}
|
|
}
|
|
}
|
|
//更新列表显示
|
|
CListCtrl *pLst = ((CListCtrl*)(GetDlgItem(IDC_LIS_LEGENDLIST)));
|
|
pLst->DeleteAllItems();
|
|
for (size_t i=0;i<s_vecLegendLst.size();i++)
|
|
{
|
|
pLst->InsertItem(i,_T(""));
|
|
pLst->SetItemText(i,0,s_vecLegendLst[i].sItem);
|
|
}
|
|
}
|
|
|
|
bool ClayoutLegendDlg::IsItemExist(S_VEC &vec,LEGENDDATA &tem)
|
|
{
|
|
bool bRe = false;
|
|
S_VEC::iterator iterRe;
|
|
iterRe = find(vec.begin(),vec.end(),tem);
|
|
if (iterRe != vec.end())
|
|
{
|
|
bRe = true;
|
|
}
|
|
return bRe;
|
|
}
|
|
//双击选择图例列表
|
|
void ClayoutLegendDlg::OnNMDblclkLisSelectlegend(NMHDR *pNMHDR, LRESULT *pResult)
|
|
{
|
|
LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
|
|
*pResult = 0;
|
|
int iSel = pNMItemActivate->iItem;
|
|
if(iSel != -1)
|
|
{
|
|
if (!IsItemExist(s_vecLegendLst,m_vecLegendSel[iSel]))
|
|
{
|
|
s_vecLegendLst.push_back(m_vecLegendSel[iSel]);
|
|
UpdateLegendLst();
|
|
}
|
|
else
|
|
{
|
|
AfxMessageBox(_T("已选择此图例!"));
|
|
}
|
|
}
|
|
}
|
|
//添加按钮
|
|
void ClayoutLegendDlg::OnBnClickedButAdd()
|
|
{
|
|
int iSel = ((CListCtrl*)(GetDlgItem(IDC_LIS_SELECTLEGEND)))->GetSelectionMark();
|
|
if (iSel != -1)
|
|
{
|
|
if (!IsItemExist(s_vecLegendLst,m_vecLegendSel[iSel]))
|
|
{
|
|
s_vecLegendLst.push_back(m_vecLegendSel[iSel]);
|
|
UpdateLegendLst();
|
|
}
|
|
else
|
|
{
|
|
AfxMessageBox(_T("已选择此图例!"));
|
|
}
|
|
}
|
|
}
|
|
|
|
void ClayoutLegendDlg::OnNMDblclkLisLegendlist(NMHDR *pNMHDR, LRESULT *pResult)
|
|
{
|
|
LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
|
|
*pResult = 0;
|
|
if(pNMItemActivate->iItem != -1)
|
|
{
|
|
S_VEC::iterator itor = s_vecLegendLst.begin()+pNMItemActivate->iItem;
|
|
s_vecLegendLst.erase(itor);
|
|
UpdateLegendLst();
|
|
}
|
|
}
|
|
|
|
void ClayoutLegendDlg::OnBnClickedButDelete()
|
|
{
|
|
int iSel = ((CListCtrl*)(GetDlgItem(IDC_LIS_LEGENDLIST)))->GetSelectionMark();
|
|
if (iSel != -1)
|
|
{
|
|
S_VEC::iterator itor = s_vecLegendLst.begin()+iSel;
|
|
s_vecLegendLst.erase(itor);
|
|
UpdateLegendLst();
|
|
}
|
|
}
|
|
|
|
void ClayoutLegendDlg::OnLvnBegindragLisLegendlist(NMHDR *pNMHDR, LRESULT *pResult)
|
|
{
|
|
LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
|
|
*pResult = 0;
|
|
if (pNMLV->iItem != -1)
|
|
{
|
|
m_iDragFlag = 0;
|
|
m_iDragBeginItem = pNMLV->iItem;
|
|
}
|
|
}
|
|
|
|
void ClayoutLegendDlg::OnLvnHotTrackLisLegendlist(NMHDR *pNMHDR, LRESULT *pResult)
|
|
{
|
|
LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
|
|
*pResult = 0;
|
|
int iCurSel = pNMLV->iItem;
|
|
if (iCurSel != -1)
|
|
{
|
|
m_iDragEndItem = iCurSel;
|
|
if (m_iDragFlag == 0)
|
|
{
|
|
((CListCtrl*)(GetDlgItem(IDC_LIS_LEGENDLIST)))->SetItemState(iCurSel,LVIS_FOCUSED,LVIS_FOCUSED);
|
|
}
|
|
}
|
|
}
|
|
|
|
BOOL ClayoutLegendDlg::PreTranslateMessage(MSG* pMsg)
|
|
{
|
|
if (pMsg->message == WM_LBUTTONUP)
|
|
{
|
|
if ((m_iDragFlag == 0) && (m_iDragEndItem != -1))
|
|
{
|
|
m_iDragFlag = -1;
|
|
CRect rect;
|
|
GetDlgItem(IDC_LIS_LEGENDLIST)->GetWindowRect(rect);
|
|
POINT pt = pMsg->pt;
|
|
if (rect.PtInRect(pt))
|
|
{
|
|
S_VEC::iterator itor = s_vecLegendLst.begin()+m_iDragBeginItem;
|
|
LEGENDDATA item = s_vecLegendLst[m_iDragBeginItem];
|
|
s_vecLegendLst.erase(itor);
|
|
itor = s_vecLegendLst.begin()+m_iDragEndItem;
|
|
s_vecLegendLst.insert(itor,1,item);
|
|
UpdateLegendLst();
|
|
}
|
|
}
|
|
}
|
|
|
|
return CModelessDialog::PreTranslateMessage(pMsg);
|
|
}
|
|
|
|
void ClayoutLegendDlg::OnLvnItemchangedLisSelectlegend(NMHDR *pNMHDR, LRESULT *pResult)
|
|
{
|
|
LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
|
|
*pResult = 0;
|
|
int iSel = pNMLV->iItem;
|
|
if (iSel !=-1)
|
|
{
|
|
m_iSelectLstCurSel = iSel;
|
|
|
|
CRect rect;
|
|
GetDlgItem(IDC_STATIC_SHOWPIC)->GetWindowRect(rect);
|
|
ScreenToClient(rect);
|
|
InvalidateRect(rect,FALSE);
|
|
}
|
|
}
|
|
|
|
void ClayoutLegendDlg::OnPaint()
|
|
{
|
|
CPaintDC dc(this);
|
|
|
|
ShowPic(m_iSelectLstCurSel);
|
|
}
|
|
|
|
void ClayoutLegendDlg::ShowPic(int index)
|
|
{
|
|
CWnd *pShowPic = GetDlgItem(IDC_STATIC_SHOWPIC);
|
|
if (pShowPic && (0<=index) && (index<(int)m_vecLegendSel.size()))
|
|
{
|
|
CDC *pDC = pShowPic->GetDC();
|
|
CRect rect;
|
|
pShowPic->GetClientRect(&rect);
|
|
m_ShowPicDC.InitDC(pDC,rect,GetAcadBackColor());
|
|
CString sName;
|
|
sName.Format(_T("总图图例(%s)"),m_vecLegendSel[index].sDrawing);
|
|
XString sFile;
|
|
sFile << sName;
|
|
m_ShowPicDC.PaintSlide(sFile);
|
|
|
|
m_ShowPicDC.SetDC(NULL);
|
|
pShowPic->ReleaseDC(pDC);
|
|
}
|
|
}
|
|
|
|
void ClayoutLegendDlg::OnBnClickedButNewlegend()
|
|
{
|
|
if (!AT_loaded(_T("wfB")))
|
|
{
|
|
#ifndef ZWCAD
|
|
int nRet = acrxLoadModule(_T("wfB.arx"), Adesk::kTrue, true);
|
|
#else
|
|
int nRet = acrxLoadModule(_T("wfB.zrx"), Adesk::kTrue, true);
|
|
#endif
|
|
if (!nRet)
|
|
{
|
|
return ;
|
|
}
|
|
}
|
|
|
|
//隐藏自己
|
|
GetParent()->EnableWindow(TRUE);
|
|
GetParent()->SetFocus();
|
|
GetParent()->SetActiveWindow();
|
|
ShowWindow(SW_HIDE);
|
|
|
|
CString szFileName = _T("总图.TKW"), sLibFile = g_sDwbPath;
|
|
sLibFile += szFileName;
|
|
|
|
XString sBlockName = _T("总图图例(00000001)");
|
|
RBList rbCmd = ads_buildlist(RTSTR, _T("ITkw"), RTSTR,
|
|
sLibFile, RTNIL, RTSTR,
|
|
(const TCHAR *)sBlockName, NULL);
|
|
|
|
resbuf *rbRes = NULL;
|
|
if (ads_invoke(rbCmd, &rbRes)==RTNORM && rbRes)
|
|
{
|
|
if (rbRes && rbRes->restype==RTSTR)
|
|
{
|
|
sBlockName = rbRes->resval.rstring;
|
|
}
|
|
|
|
ads_relrb(rbRes);
|
|
}
|
|
|
|
//重新显示
|
|
if(LoadDBFFile(_T("总图图例.TK")))
|
|
{
|
|
UpdateLegendSel();
|
|
UpdateLegendLst();
|
|
}
|
|
GetParent()->EnableWindow(FALSE);
|
|
EnableWindow(TRUE);
|
|
SetActiveWindow();
|
|
ShowWindow(SW_SHOW);
|
|
GetParent()->EnableWindow(TRUE);
|
|
}
|
|
|
|
|
|
LEGENDDATA ClayoutLegendDlg:: operator [] (int i) const
|
|
{
|
|
return s_vecLegendLst[i];
|
|
}
|
|
|
|
int ClayoutLegendDlg::GetSize()
|
|
{
|
|
return (int)s_vecLegendLst.size();
|
|
}
|
|
void ClayoutLegendDlg::OnCbnSelchangeCmbColumn()
|
|
{
|
|
UpdateData();
|
|
CString strNum;
|
|
m_cloumnNumBox.GetWindowText(strNum);
|
|
}
|
|
void ClayoutLegendDlg::OnCbnEditchangeCmbColumn()
|
|
{
|
|
CString strColumn;
|
|
m_cloumnNumBox.GetWindowText(strColumn);
|
|
if (!strColumn.IsEmpty())
|
|
{
|
|
CString sTem;
|
|
sTem.Format(_T("%d"),_ttoi(strColumn));
|
|
if (sTem != strColumn || sTem == _T("0"))
|
|
{
|
|
AfxMessageBox(_T("请输入大于0的数值!"));
|
|
UpdateData(FALSE);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
AfxMessageBox(_T("请输入大于0的数值!"));
|
|
UpdateData(FALSE);
|
|
}
|
|
UpdateData(TRUE);
|
|
}
|
|
|
|
void ClayoutLegendDlg::OnBnClickedButEmpty()
|
|
{
|
|
s_vecLegendLst.clear();
|
|
UpdateLegendLst();
|
|
}
|
|
void ClayoutLegendDlg::GetLegendLst()
|
|
{
|
|
s_vecLegendLst.clear();
|
|
if (m_aryTmpLegend.GetSize() > 0)
|
|
{
|
|
m_strColumnNum = m_aryTmpLegend.GetAt(0);
|
|
}
|
|
if (m_aryTmpLegend.GetSize() > 1)
|
|
{
|
|
for (int i = 1; i < m_aryTmpLegend.GetSize(); ++i)
|
|
{
|
|
CString strLegend = m_aryTmpLegend.GetAt(i);
|
|
for (int n = 0; n < m_vecLegendSel.size(); ++n)
|
|
{
|
|
if (m_vecLegendSel[n].sItem == strLegend)
|
|
{
|
|
s_vecLegendLst.push_back(m_vecLegendSel[n]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|