268 lines
5.4 KiB
C++
268 lines
5.4 KiB
C++
#include "stdafx.h"
|
|
#include "DXBZDlg.h"
|
|
#include "UITools.h"
|
|
|
|
extern void SplitStrintToArray(LPCTSTR pszDescr,CStringArray& arInfo,TCHAR tcSpace);
|
|
IMPLEMENT_DYNAMIC(CDXBZDlg, CDialog)
|
|
|
|
CDXBZDlg::CDXBZDlg(CWnd* pParent /*=NULL*/)
|
|
: CDialog(CDXBZDlg::IDD, pParent)
|
|
{
|
|
}
|
|
|
|
CDXBZDlg::~CDXBZDlg()
|
|
{
|
|
}
|
|
|
|
void CDXBZDlg::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CDialog::DoDataExchange(pDX);
|
|
DDX_Control(pDX, IDC_LIST1, m_wndListCtrl);
|
|
}
|
|
|
|
BEGIN_MESSAGE_MAP(CDXBZDlg, CDialog)
|
|
ON_BN_CLICKED(IDOK, &CDXBZDlg::OnBnClickedOk)
|
|
ON_BN_CLICKED(IDC_BUTTON1, &CDXBZDlg::OnBnClickedButton1)
|
|
END_MESSAGE_MAP()
|
|
|
|
void CDXBZDlg::SetDimTexts(CStringArray& arTexts,AcGePoint3dArray& arPts)
|
|
{
|
|
if (arTexts.GetSize() > 0)
|
|
{
|
|
CString sText;
|
|
CStringList lstTxt;
|
|
|
|
for (int i = 0;i < arTexts.GetSize();i++)
|
|
{
|
|
sText = arTexts.GetAt(i);
|
|
if (lstTxt.Find(sText) == NULL)
|
|
{
|
|
m_arTexts.Add(sText);
|
|
m_arPts.append(arPts.at(i));
|
|
lstTxt.AddTail(sText);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void CDXBZDlg::GetDimTexts(CStringArray& arTexts,AcGePoint3dArray& arPts) const
|
|
{
|
|
if (m_arPts.length() > 0)
|
|
{
|
|
arTexts.Append(m_arTexts);
|
|
arPts.append(m_arPts);
|
|
}
|
|
}
|
|
|
|
BOOL CDXBZDlg::OnInitDialog()
|
|
{
|
|
CDialog::OnInitDialog();
|
|
|
|
m_ImageList.Create(IDB_BITMAP4,16,1,RGB(0, 255, 255));
|
|
|
|
m_wndListCtrl.SetImageList(&m_ImageList,LVSIL_SMALL);
|
|
m_wndListCtrl.SetExtendedStyle(LVS_EX_FULLROWSELECT);
|
|
m_wndListCtrl.InsertColumn(0,_T("标注文本"),LVCFMT_LEFT,180,180);
|
|
m_wndListCtrl.InsertColumn(1,_T("原文"),LVCFMT_LEFT,0,0);
|
|
m_wndListCtrl.InsertColumn(2,_T("位置"),LVCFMT_LEFT,0,0);
|
|
|
|
m_wndListCtrl.SetColumnItemData(0,NULL,ET_Edit);
|
|
|
|
RemoveByLastDelete();
|
|
RepeateByLastSave();
|
|
|
|
AcGePoint3d pt;
|
|
CString sPt;
|
|
int nItem = 0;
|
|
for (int i = 0;i < m_arTexts.GetSize();i++)
|
|
{
|
|
nItem = m_wndListCtrl.InsertItem(i,m_arTexts.GetAt(i),0);
|
|
m_wndListCtrl.SetItemText(nItem,1,m_arTexts.GetAt(i));
|
|
|
|
pt = m_arPts.at(i);
|
|
sPt.Format(_T("%g,%g,%g"),pt.x,pt.y,pt.z);
|
|
m_wndListCtrl.SetItemText(nItem,2,sPt);
|
|
m_mapPT2Pt.SetAt(sPt,pt);
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
void CDXBZDlg::OnBnClickedOk()
|
|
{
|
|
m_arTexts.RemoveAll();
|
|
m_arPts.removeAll();
|
|
|
|
CString sPt,sText,sOldText;
|
|
CStringArray arXYZ;
|
|
|
|
AcGePoint3d pt;
|
|
for(int i = 0;i < m_wndListCtrl.GetItemCount();i++)
|
|
{
|
|
sText = m_wndListCtrl.GetItemText(i,0);
|
|
sOldText = m_wndListCtrl.GetItemText(i,1);
|
|
sPt = m_wndListCtrl.GetItemText(i,2);
|
|
|
|
m_mapPT2Pt.Lookup(sPt,pt);
|
|
m_arPts.append(pt);
|
|
m_arTexts.Add(sText);
|
|
|
|
if (sText.CompareNoCase(sOldText) != 0)
|
|
{
|
|
SaveReModifyText(sOldText,sText);
|
|
}
|
|
}
|
|
OnOK();
|
|
}
|
|
|
|
void CDXBZDlg::OnBnClickedButton1()
|
|
{
|
|
//把删除的文本记录下来
|
|
POSITION ps = m_wndListCtrl.GetFirstSelectedItemPosition();
|
|
int nItem = m_wndListCtrl.GetNextSelectedItem(ps);
|
|
if (nItem != -1)
|
|
{
|
|
int nRes = AfxMessageBox(_T("删除为过滤性删除!删除的条目下次标注时过滤掉!确认要删除吗?"),MB_YESNO);
|
|
if (nRes == IDYES)
|
|
{
|
|
//写入临时文件
|
|
CString sFullPath = FilePath::GetSysDir();
|
|
sFullPath.MakeLower();
|
|
sFullPath += _T("\\DXBZDlg_DEL.lst");
|
|
|
|
UINT nOpenFlag = CFile::modeReadWrite | CFile::typeText;
|
|
CFileFind find;
|
|
if ( !find.FindFile(sFullPath) )
|
|
{
|
|
nOpenFlag = CFile::modeCreate | CFile::modeWrite;
|
|
}
|
|
|
|
CString sText = m_wndListCtrl.GetItemText(nItem,1);
|
|
sText += _T("\n");
|
|
|
|
CStdioFile file;
|
|
if (file.Open(sFullPath,nOpenFlag ))
|
|
{
|
|
file.SeekToEnd();
|
|
file.WriteString(sText);
|
|
file.Close();
|
|
}
|
|
|
|
CString sPt;
|
|
sPt = m_wndListCtrl.GetItemText(nItem,2);
|
|
|
|
m_mapPT2Pt.RemoveKey(sPt);
|
|
m_wndListCtrl.DeleteItem(nItem);
|
|
}
|
|
}
|
|
}
|
|
|
|
void CDXBZDlg::SaveReModifyText(const CString& sOldText,const CString& sText)
|
|
{
|
|
CString sFullPath = FilePath::GetSysDir();
|
|
sFullPath.MakeLower();
|
|
sFullPath += _T("\\DXBZDlg_MAP.lst");
|
|
|
|
UINT nOpenFlag = CFile::modeReadWrite | CFile::typeText;
|
|
CFileFind find;
|
|
if ( !find.FindFile(sFullPath) )
|
|
{
|
|
nOpenFlag = CFile::modeCreate | CFile::modeWrite;
|
|
}
|
|
|
|
CString sLine;
|
|
CStdioFile file;
|
|
if (file.Open(sFullPath,nOpenFlag ))
|
|
{
|
|
file.SeekToEnd();
|
|
|
|
//key
|
|
sLine = sOldText;
|
|
sLine += _T("\n");
|
|
file.WriteString(sLine);
|
|
|
|
//val
|
|
sLine = sText;
|
|
sLine += _T("\n");
|
|
file.WriteString(sLine);
|
|
|
|
file.Close();
|
|
}
|
|
}
|
|
|
|
void CDXBZDlg::RemoveByLastDelete()
|
|
{
|
|
CString sFullPath = FilePath::GetSysDir();
|
|
sFullPath.MakeLower();
|
|
sFullPath += _T("\\DXBZDlg_DEL.lst");
|
|
|
|
UINT nOpenFlag = CFile::modeRead | CFile::typeText;
|
|
|
|
CString sText,sText1;
|
|
CStdioFile file1;
|
|
|
|
if ( file1.Open(sFullPath,nOpenFlag ) )
|
|
{
|
|
while(file1.ReadString(sText))
|
|
{
|
|
sText.TrimRight(_T('\n'));
|
|
|
|
for (int i = 0;i < m_arTexts.GetSize();i++)
|
|
{
|
|
sText1 = m_arTexts.GetAt(i);
|
|
|
|
if (sText1.CompareNoCase(sText) == 0)
|
|
{
|
|
m_arTexts.RemoveAt(i);
|
|
m_arPts.removeAt(i);
|
|
|
|
i -= 1;
|
|
}
|
|
}
|
|
}
|
|
file1.Close();
|
|
}
|
|
}
|
|
|
|
void CDXBZDlg::RepeateByLastSave()
|
|
{
|
|
CMapStringToString mapOldToNew;
|
|
|
|
CString sFullPath = FilePath::GetSysDir();
|
|
sFullPath.MakeLower();
|
|
sFullPath += _T("\\DXBZDlg_MAP.lst");
|
|
|
|
UINT nOpenFlag = CFile::modeRead | CFile::typeText;
|
|
|
|
CString sLast,sText;
|
|
CStdioFile file1;
|
|
|
|
if (file1.Open(sFullPath,CFile::modeRead))
|
|
{
|
|
int nPos = 0;
|
|
while(file1.ReadString(sText))
|
|
{
|
|
sText.TrimRight(_T('\n'));
|
|
if (nPos % 2 == 1)//奇数 val
|
|
{
|
|
mapOldToNew.SetAt(sLast,sText);
|
|
}
|
|
else
|
|
{
|
|
sLast = sText;//偶数 key
|
|
}
|
|
|
|
nPos += 1;
|
|
}
|
|
file1.Close();
|
|
}
|
|
|
|
CString sVal;
|
|
for(int i = 0;i < m_arTexts.GetSize();i++)
|
|
{
|
|
sText = m_arTexts.GetAt(i);
|
|
if (mapOldToNew.Lookup(sText,sVal))
|
|
{
|
|
m_arTexts.SetAt(i,sVal);
|
|
}
|
|
}
|
|
} |