#include "stdafx.h" #include "KTBlkRecsView.h" #include "KTSetting.h" #include "SWMCXXDlg.h" #include "CoreTools.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif #define WM_VIEWDBLCLKSEL (WM_USER + 0x1200) #define WM_TRUERELOAD (WM_USER + 0x1201) #define WM_ONITEMSEL (WM_USER + 0x1202) extern CAcExtensionModule Pool3dCmdDll; KTBlkRecsView::KTBlkRecsView(CWnd* pParent /*=NULL*/) : CDialog(KTBlkRecsView::IDD, pParent) { //{{AFX_DATA_INIT(KTBlkRecsView) //}}AFX_DATA_INIT m_bViewWindow = false; m_sRecName2D = _T(""); m_sRecName3D = _T(""); } void KTBlkRecsView::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(KTBlkRecsView) //DDX_Control(pDX, IDC_STATICVIEW, m_wndPreview); //}}AFX_DATA_MAP DDX_Control(pDX, IDC_LIST1, m_wndDwgFileList); } BEGIN_MESSAGE_MAP(KTBlkRecsView, CDialog) //{{AFX_MSG_MAP(KTBlkRecsView) ON_MESSAGE(WM_VIEWDBLCLKSEL,OnViewDlclkSel) ON_MESSAGE(WM_ONITEMSEL,OnViewItemSel) //}}AFX_MSG_MAP ON_BN_CLICKED(IDOK, &KTBlkRecsView::OnBnClickedOk) ON_LBN_SELCHANGE(IDC_LIST1, &KTBlkRecsView::OnLbnSelchangeList1) ON_BN_CLICKED(IDC_BUTTON1, &KTBlkRecsView::OnBnClickedButton1) END_MESSAGE_MAP() void KTBlkRecsView::SetCurRec(LPCTSTR pszCurBlk,BOOL bWindow) { m_sRecName2D = pszCurBlk; m_bViewWindow = bWindow ? true : false; } BOOL KTBlkRecsView::GetCurRec(CString& sDwgFile,CString& sName2D,CString& sName3D,CString& s3DwgFile) { sDwgFile = m_sDwgFile; sName2D = m_sRecName2D; sName3D = m_sRecName3D; s3DwgFile = m_sRecName3D; m_map2DTo3DFile.Lookup(sName2D,s3DwgFile); s3DwgFile.MakeLower(); if (s3DwgFile.Find(_T(".dwg")) == -1) s3DwgFile += _T(".dwg"); return FALSE; } BOOL KTBlkRecsView::OnInitDialog() { CDialog::OnInitDialog(); CRect rc; GetDlgItem(IDC_STATICVIEW)->GetWindowRect(rc); GetDlgItem(IDC_STATICVIEW)->ShowWindow(SW_HIDE); ScreenToClient(rc); m_wndPreview.Create(rc,this,IDC_STATICVIEW); m_wndPreview.Init(Pool3dCmdDll.ModuleResourceInstance(),3,5,0,NULL,false); //旧的方式 ShowSupportCells(); CString sDwgFile; if (m_map2DTo2DFile.Lookup(m_sRecName2D, sDwgFile)) { m_wndPreview.SetCurSelRec(sDwgFile,m_sRecName2D); } return TRUE; } //旧的cells下门窗显示方式 void KTBlkRecsView::ShowSupportCells() { CString sPath,sPath2; KTSetting::GetKTPsPath(sPath); sPath2 = sPath; if (m_bViewWindow) { sPath += _T("Support\\Cells\\WindowDb.txt"); } else { sPath += _T("Support\\Cells\\DoorDb.txt"); } CWaitCursor wait; CString sDwgFile,sRecName,sRecName3D; int nIndex = -1,nIndex2 = -1; CStdioFile file; if (file.Open(sPath,CFile::modeRead | CFile::typeText)) { CString sText,sFileName,s3DFileName; while(file.ReadString(sText)) { if (sText.FindOneOf(_T("//")) != -1) { continue; } nIndex = sText.Find(_T(';')); if (nIndex != -1) { CStringArray arFields; CoreTools::SplitStrintToArray(sText,arFields,_T(';')); if (arFields.GetSize() >= 3) { sFileName = arFields.GetAt(0); sDwgFile = sPath2 + _T("Support\\Cells\\") + sFileName; sRecName = arFields.GetAt(1); sRecName3D = arFields.GetAt(2); if (arFields.GetCount() > 3) { s3DFileName = arFields.GetAt(3); m_map2DTo3DFile.SetAt(sRecName,s3DFileName); } m_wndDwgFileList.AddString(sRecName); m_map2DTo3D.SetAt(sRecName,sRecName3D); m_map2DTo2DFile.SetAt(sRecName, sDwgFile); //m_wndPreview.Add(sDwgFile,ACDB_MODEL_SPACE,sRecName,false); m_wndPreview.PreviewWinDoor(sDwgFile,sRecName,sRecName,!m_bViewWindow,false); } } } file.Close(); } m_wndPreview.Redraw(); } LRESULT KTBlkRecsView::OnViewDlclkSel(WPARAM wparam,LPARAM lparam) { if (m_wndPreview.GetCurSelRec(m_sDwgFile,m_sRecName2D)) { m_map2DTo3D.Lookup(m_sRecName2D,m_sRecName3D); CDialog::EndDialog(IDOK); } return 0; } LRESULT KTBlkRecsView::OnViewItemSel(WPARAM wparam,LPARAM lparam) { int nTrueIndex = (int)wparam; CString sDwgFile,sRecName2D,sName; if (m_wndPreview.GetCurSelRec(sDwgFile,sRecName2D)) { int nItem = m_wndDwgFileList.FindString(0,sRecName2D); if (nItem != -1) { m_wndDwgFileList.SetCurSel(nItem); } } return 0; } void KTBlkRecsView::OnOK() { if (m_wndPreview.GetCurSelRec(m_sDwgFile,m_sRecName2D)) { m_map2DTo3D.Lookup(m_sRecName2D,m_sRecName3D); CDialog::OnOK(); } } void KTBlkRecsView::OnBnClickedOk() { OnOK(); } void KTBlkRecsView::OnLbnSelchangeList1() { int nSel = m_wndDwgFileList.GetCurSel(); if (nSel != -1) { CString sRecName2D; m_wndDwgFileList.GetText(nSel, sRecName2D); CString sDwgFile; m_map2DTo2DFile.Lookup(sRecName2D, sDwgFile); m_wndPreview.SetCurSelRec(sDwgFile,sRecName2D); } } void KTBlkRecsView::OnBnClickedButton1() { if (m_wndPreview.GetCurSelRec(m_sDwgFile,m_sRecName2D)) { m_map2DTo3D.Lookup(m_sRecName2D,m_sRecName3D); } CSWMCXXDlg dlg; dlg.m_sRecName = m_sRecName3D; TCHAR sDrive[MAX_PATH],sDir[MAX_PATH],sFileName[MAX_PATH],sExt[MAX_PATH]; #ifdef _UNICODE _wsplitpath(m_sDwgFile, sDrive, sDir, sFileName, sExt); #else _splitpath(m_sDwgFile, sDrive, sDir, sFileName, sExt); #endif CString s2dFileName1; s2dFileName1.Format(_T("%s%s"),sFileName,sExt); CString s3DFile; if (!m_map2DTo3DFile.Lookup(m_sRecName2D,s3DFile)) { dlg.m_s3DDwgFile.Format(_T("%s%s%s.dwg"),sDrive,sDir,m_sRecName3D); } else { dlg.m_s3DDwgFile.Format(_T("%s%s%s"),sDrive,sDir,s3DFile); } if (IDOK == dlg.DoModal()) { m_sRecName3D = dlg.m_sRecName; CString s3DDwgFile = dlg.m_s3DDwgFile; //复制到cell目录下 #ifdef _UNICODE _wsplitpath(s3DDwgFile, sDrive, sDir, sFileName, sExt); #else _splitpath(s3DDwgFile, sDrive, sDir, sFileName, sExt); #endif CString s3DDwgFileName; s3DDwgFileName.Format(_T("%s%s"),sFileName,sExt); CString sPath; KTSetting::GetKTPsPath(sPath); m_s3DDwgFile.Format(_T("%sSupport\\Cells\\%s.dwg"),sPath,sFileName); CFileFind find; if (!find.FindFile(m_s3DDwgFile)) { ::CopyFile(s3DDwgFile,m_s3DDwgFile,FALSE); } //写入txt 配置文件 if (m_bViewWindow) { sPath += _T("Support\\Cells\\WindowDb.txt"); } else { sPath += _T("Support\\Cells\\DoorDb.txt"); } int nIndex = -1,nIndex2 = -1; CStringArray arNewLines; CString sText,s2dFileName; CStdioFile file; if (file.Open(sPath,CFile::modeRead | CFile::typeText)) { CString sRecName,sRecName3D,s3DFile; //KTDOOR01.dwg;KTDOOR01;KTDOOR01_3D while(file.ReadString(sText)) { if (sText.FindOneOf(_T("//")) != -1) { arNewLines.Add(sText); continue; } nIndex = sText.Find(_T(';')); if (nIndex != -1) { CStringArray arFields; CoreTools::SplitStrintToArray(sText,arFields,_T(';')); if (arFields.GetSize() >= 3) { s2dFileName = arFields.GetAt(0); sRecName = arFields.GetAt(1); sRecName3D = arFields.GetAt(2); if (arFields.GetSize() > 3) { s3DFile = arFields.GetAt(3); } if (sRecName.CompareNoCase(m_sRecName2D) == 0 && s2dFileName1.CompareNoCase(s2dFileName) == 0) { sText.Format(_T("%s;%s;%s;%s\n"),s2dFileName,sRecName,m_sRecName3D,s3DDwgFileName); arNewLines.Add(sText); m_map2DTo3DFile.SetAt(sRecName,s3DDwgFileName); } else { arNewLines.Add(sText); } } else { arNewLines.Add(sText); } } else { arNewLines.Add(sText); } } file.Close(); } //重写 方法不好 if (file.Open(sPath,CFile::modeWrite | CFile::typeText)) { for(int i = 0;i < arNewLines.GetSize();i++) { sText = arNewLines.GetAt(i); sText.TrimRight(_T('\n')); sText += _T("\n"); file.WriteString(sText); } file.Close(); } } }