#include "stdafx.h" #include "resource.h" #include "ProjectManager.h" #include "acdocman.h" #include "Shlwapi.h" #include "TgAs.h" #define ID_INS_DRAWING 1 #define ID_DEL_DRAWING 2 #define ID_OPEN_DRAWING 3 #define ID_ADD_DRAWING 4 #define ID_NEW_COLLECT 5 #define ID_DEL_COLLECT 6 #define ID_REN_COLLECT 7 #define ID_EXPAND_COLLECT 8 #define ID_COLLAPSE_COLLECT 9 #define ID_ADD_CHILD_COLLECT 10 #define ID_INS_COLLECT 11 #define ID_EXPAND_WORKS 12 #define ID_COLLAPSE_WORKS 13 #define IDC_PROJECT_COMBO 14 #define ID_CUR_PROJECT 15 #define ID_NEW_PROJECT 16 #define ID_OPEN_PROJECT 17 #define ID_SET_PROJECT 18 #define ID_RECENT_PROJECT 19 #define ID_IMPORT_FLOOR 20 #define ID_EXPORT_FLOOR 21 #define ID_SAVE_PROJECT 22 #define ID_RECENT1 23 #define ID_RECENT2 24 #define ID_RECENT3 25 #define ID_RECENT4 26 #define ID_RECENT5 27 #define ID_RECENT6 28 #define ID_RECENT7 29 #define ID_RECENT8 30 // 最近工程限制数量 #define RECENT_MAX_NUM 8 BOOL GetDwgFilesDia(XStringList &lstFiles, CWnd *pParent, const TCHAR *pszDir, const TCHAR *pszTitle); extern TARCH_IMPEXP TDbConfig* GetDbConfigFromDict(AcDbDictionary *pXDict, AcDb::OpenMode mode); void SplitPath(const TCHAR* pathName, CString &filePath, CString &fileName) { TCHAR drive[_MAX_DRIVE], dir[_MAX_DIR], fname[_MAX_FNAME], ext[_MAX_EXT] = _T(""); _tsplitpath(pathName, drive, dir, fname, ext); filePath.Format(_T("%s%s"), drive, dir); fileName.Format(_T("%s"), fname); } CString GetLHeight(const CString szFullName) { CString szHeight = _T("3000"); AcDbDatabase db(false, true); #if ADS < 21 db.readDwgFile(szFullName, _SH_DENYNO, false); #else db.readDwgFile(szFullName, AcDbDatabase::kForReadAndAllShare, false); #endif TDbConfig *pCfg = GetDwgGlobal(AcDb::kForRead,&db); if (pCfg != NULL) { szHeight.Format(_T("%.2f"), pCfg->GetLHeight()); szHeight.TrimRight(_T("0")); szHeight.TrimRight(_T(".")); pCfg->close(); } return szHeight; } bool CanInsert(TProjectGroupItem*pGroup,CString sName) { return (pGroup!=NULL && pGroup->FindItem(sName,false,0)==NULL); } TProjectBar g_projectBar; BOOL g_bProjectBarDockLeft = FALSE; int g_iProjectBarWidth = 200; int g_iProjectBarUnFoldFlags = 0; TARCH_IMPEXP BOOL g_bProjectBarVisible; TARCH_IMPEXP BOOL g_bAutoOpenRecent; extern int TARCH_IMPEXP g_nProductId; #if ADS<16 CLSID g_projectBarId[] = { { 0x91239e2f, 0x4851, 0x4166, { 0x99, 0x85, 0xc6, 0x46, 0x26, 0x9f, 0x2b, 0xfd } }, { 0x91239e2f, 0x4852, 0x4166, { 0x99, 0x85, 0xc6, 0x46, 0x26, 0x9f, 0x2b, 0xfd } }, { 0x91239e2f, 0x4853, 0x4166, { 0x99, 0x85, 0xc6, 0x46, 0x26, 0x9f, 0x2b, 0xfd } }, { 0x91239e2f, 0x4854, 0x4166, { 0x99, 0x85, 0xc6, 0x46, 0x26, 0x9f, 0x2b, 0xfd } }, { 0x91239e2f, 0x4855, 0x4166, { 0x99, 0x85, 0xc6, 0x46, 0x26, 0x9f, 0x2b, 0xfd } }, { 0x91239e2f, 0x4856, 0x4166, { 0x99, 0x85, 0xc6, 0x46, 0x26, 0x9f, 0x2b, 0xfd } }, { 0x91239e2f, 0x4857, 0x4166, { 0x99, 0x85, 0xc6, 0x46, 0x26, 0x9f, 0x2b, 0xfd } }, { 0x91239e2f, 0x4858, 0x4166, { 0x99, 0x85, 0xc6, 0x46, 0x26, 0x9f, 0x2b, 0xfd } }, { 0x91239e2f, 0x4859, 0x4166, { 0x99, 0x85, 0xc6, 0x46, 0x26, 0x9f, 0x2b, 0xfd } } }; #else CLSID g_projectBarId[] = { { 0x91239e2f, 0x4861, 0x4166, { 0x99, 0x85, 0xc6, 0x46, 0x26, 0x9f, 0x2b, 0xfd } }, { 0x91239e2f, 0x4862, 0x4166, { 0x99, 0x85, 0xc6, 0x46, 0x26, 0x9f, 0x2b, 0xfd } }, { 0x91239e2f, 0x4863, 0x4166, { 0x99, 0x85, 0xc6, 0x46, 0x26, 0x9f, 0x2b, 0xfd } }, { 0x91239e2f, 0x4864, 0x4166, { 0x99, 0x85, 0xc6, 0x46, 0x26, 0x9f, 0x2b, 0xfd } }, { 0x91239e2f, 0x4865, 0x4166, { 0x99, 0x85, 0xc6, 0x46, 0x26, 0x9f, 0x2b, 0xfd } }, { 0x91239e2f, 0x4866, 0x4166, { 0x99, 0x85, 0xc6, 0x46, 0x26, 0x9f, 0x2b, 0xfd } }, { 0x91239e2f, 0x4867, 0x4166, { 0x99, 0x85, 0xc6, 0x46, 0x26, 0x9f, 0x2b, 0xfd } }, { 0x91239e2f, 0x4868, 0x4166, { 0x99, 0x85, 0xc6, 0x46, 0x26, 0x9f, 0x2b, 0xfd } }, { 0x91239e2f, 0x4869, 0x4166, { 0x99, 0x85, 0xc6, 0x46, 0x26, 0x9f, 0x2b, 0xfd } } }; #endif //////////////////////////////////////////////////////////////////////////////////////////////////////////// // COMMAND:工程管理命令入口,TProjectManager void ProjectManager() { CMDIFrameWnd *pAcadFrame = acedGetAcadFrame(); if (g_projectBar.GetSafeHwnd() == NULL) { #if ADS>15 g_projectBar.Create(TPR_MANGER_TITLE, WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|CBRS_FLYBY, CRect(0, 0, g_iProjectBarWidth, 600), pAcadFrame); CString csIconFile; XString sTchIni, sIconFile; if (FindFile(_T("tch.ini"), sTchIni)) { INI_struct *inis = NULL; if (CT_get_INIs(sTchIni, _T("Product"), &inis)) { TCHAR *pIcon = CT_get_INI2(inis, _T("IconFile")); if (pIcon != NULL) { csIconFile = pIcon; } CT_free_INIs(inis); } } if (FindFile(csIconFile, sIconFile)) { HICON hBig,hSmall; ::ExtractIconEx(sIconFile, 0, &hBig, &hSmall, 1); g_projectBar.SetIcon(hBig,TRUE); g_projectBar.SetIcon(hSmall,FALSE); } #else g_projectBar.Create(pAcadFrame, TPR_MANGER_TITLE, 10000, WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|CBRS_FLYBY, CRect(0,0,g_iProjectBarWidth,600)); #endif g_projectBar.SetToolID(&g_projectBarId[g_nProductId-1]); g_projectBar.EnableDocking(CBRS_ALIGN_LEFT|CBRS_ALIGN_RIGHT); // pAcadFrame->DockControlBar(&g_projectBar, g_bProjectBarDockLeft?AFX_IDW_DOCKBAR_LEFT:AFX_IDW_DOCKBAR_RIGHT); g_projectBar.RestoreControlBar(); pAcadFrame->ShowControlBar(&g_projectBar, TRUE, TRUE); pAcadFrame->RecalcLayout(); #if ADS>15 if (g_projectBar.IsFloating()) { g_projectBar.SetAutoRollup(TRUE); } #endif if (g_bAutoOpenRecent) { g_projectBar.OpenRecent(); } } else { pAcadFrame->ShowControlBar(&g_projectBar, !g_projectBar.IsWindowVisible(), TRUE); pAcadFrame->RecalcLayout(); } } // COMMAND:显示工程管理数据库,TProjectBar void ProjectBar() { CMDIFrameWnd *pAcadFrame = acedGetAcadFrame(); if (g_projectBar.GetSafeHwnd() == NULL) { #if ADS>15 g_projectBar.Create(TPR_MANGER_TITLE, WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|CBRS_FLYBY, CRect(0, 0, g_iProjectBarWidth, 600), pAcadFrame); CString csIconFile; XString sTchIni, sIconFile; if (FindFile(_T("tch.ini"), sTchIni)) { INI_struct *inis = NULL; if (CT_get_INIs(sTchIni, _T("Product"), &inis)) { TCHAR *pIcon = CT_get_INI2(inis, _T("IconFile")); if (pIcon != NULL) { csIconFile = pIcon; } CT_free_INIs(inis); } } if (FindFile(csIconFile, sIconFile)) { HICON hBig,hSmall; ::ExtractIconEx(sIconFile, 0, &hBig, &hSmall, 1); g_projectBar.SetIcon(hBig,TRUE); g_projectBar.SetIcon(hSmall,FALSE); } #else g_projectBar.Create(pAcadFrame, TPR_MANGER_TITLE, 10000, WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|CBRS_FLYBY, CRect(0,0,g_iProjectBarWidth,600)); #endif g_projectBar.SetToolID(&g_projectBarId[g_nProductId-1]); g_projectBar.EnableDocking(CBRS_ALIGN_LEFT|CBRS_ALIGN_RIGHT); // pAcadFrame->DockControlBar(&g_projectBar, g_bProjectBarDockLeft?AFX_IDW_DOCKBAR_LEFT:AFX_IDW_DOCKBAR_RIGHT); g_projectBar.RestoreControlBar(); pAcadFrame->ShowControlBar(&g_projectBar, TRUE, FALSE); pAcadFrame->RecalcLayout(); #if ADS>15 if (g_projectBar.IsFloating()) { g_projectBar.SetAutoRollup(TRUE); } #endif if (g_bAutoOpenRecent) { g_projectBar.OpenRecent(); } } else if (!g_projectBar.IsWindowVisible()) { pAcadFrame->ShowControlBar(&g_projectBar, TRUE, TRUE); pAcadFrame->RecalcLayout(); } } /////////////////////////////////////////////////////////////////////////////////////////////////////////////// // TFileTreeComboBox TFileTreeComboBox::TFileTreeComboBox() { XString sKey; sKey << GetRegLocation() << _T("\\Settings"); CRegProperty regProp(sKey, _T("ProjectBar")); regProp.SetTopRootKey(HKEY_CURRENT_USER); CString szRecent; regProp.GetValue(_T("RecentProject"), szRecent); TCHAR seps[] = _T(","); TCHAR *token = _tcstok((TCHAR*)(const TCHAR*)szRecent, seps); while (token != NULL) { m_lstRecent.AddTail(new CString(token)); token = _tcstok(NULL, seps); } } TFileTreeComboBox::~TFileTreeComboBox() { CString szRecent; if (m_lstRecent.GetDataNum() > 0) { szRecent = *m_lstRecent[0]; } int nNum = m_lstRecent.GetDataNum(); if (nNum > RECENT_MAX_NUM) { nNum = RECENT_MAX_NUM; } for (int i=1; i!")); return; } CString szFullName; g_project.GetFilePath(szFullName); szFullName += _T("Building.dbf"); CFileFind find; if (!find.FindFile(szFullName)) { AfxMessageBox(_T("没有发现楼层表!")); return; } CodeBase db; XDbfTable *pTable = db.Open(szFullName); if (!pTable) { AfxMessageBox(_T("打开楼层表出错!")); return; } pGroup->Clear(); CString szFloor, szName, szHeight; pTable->MoveFirst(); while (!pTable->IsEOF()) { GET_FIELD(pTable, _T("Floor"), szFloor); GET_FIELD(pTable, _T("DwgFile"), szName); GET_FIELD(pTable, _T("Height"), szHeight); TProjectFloor *pFloor = new TProjectFloor(szName); if (pFloor != NULL) { pFloor->SetLayerNo(szFloor); pFloor->SetHeight(_tstof(szHeight)); pGroup->AddTail(pFloor); } pTable->MoveNext(); } pTable->Close(); g_projectBar.Refresh(); } // 楼层表导出到同一目录下的bulding.dbf中 void TFileTreeComboBox::DoExportFloor() { TProjectGroupItem* pGroup = g_project.GetGroup(_T("楼层")); if (pGroup == NULL) { AfxMessageBox(_T("未找到楼层定义!")); return; } for (pGroup->MoveToFirst(); !pGroup->IsOut(); pGroup->MoveToNext()) { TProjectFloor *pFloor = (TProjectFloor *)pGroup->GetCurData(); if (pFloor != NULL && pFloor->IsFloorInFrame()) { AfxMessageBox(_T("导出楼层表失败,存在局部楼层")); return; } } CString szFullName; g_project.GetFilePath(szFullName); szFullName += _T("Building.dbf"); CodeBase db; CFileFind find; if (!find.FindFile(szFullName)) { FieldInfo fields[4]; fields[0] = FieldInfo(_T("Floor"), _T('C'), 64); fields[1] = FieldInfo(_T("DwgFile"), _T('C'), 64); fields[2] = FieldInfo(_T("Height"), _T('N'), 10); // Zyu modify on 100721,传入列数 // XDbfTable *pTable = db.Create(szFullName, fields); XDbfTable *pTable = db.Create(szFullName, fields, 4); pTable->Close(); } XDbfTable *pTable = db.Open(szFullName); if (!pTable) { MessageBox(_T("打开楼层表出错!")); return; } CString szFloor, szName, szHeight; pTable->MoveFirst(); for (pGroup->MoveToFirst(); !pGroup->IsOut(); pGroup->MoveToNext()) { TProjectFloor *pFloor = (TProjectFloor *)pGroup->GetCurData(); if (pFloor == NULL) continue; szFloor = pFloor->GetLayerNo(); szName = pFloor->GetName(); if (!pTable->IsEOF()) { SET_FIELD(pTable, _T("floor"), (const TCHAR*)szFloor); SET_FIELD(pTable, _T("dwgfile"), (const TCHAR*)szName); SET_FIELD(pTable, _T("height"), pFloor->GetHeight()); } else { pTable->AppendBegin(); SET_FIELD(pTable, _T("floor"), (const TCHAR*)szFloor); SET_FIELD(pTable, _T("dwgfile"), (const TCHAR*)szName); SET_FIELD(pTable, _T("height"), pFloor->GetHeight()); pTable->AppendEnd(); } pTable->MoveNext(); } while(!pTable->IsEOF()) { pTable->Delete(); pTable->MoveNext(); } pTable->Pack(); pTable->Close(); adsout<<_T("\n成功导出楼层表!\n命令:"); } void TFileTreeComboBox::DoOpenProject() { CFileDialog dlg(TRUE, _T("tpr"), NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT , _T("工程文件(*.tpr)|*.tpr||"), acedGetAcadFrame()); if (dlg.DoModal() != IDOK) return; if (g_project.Load(dlg.GetPathName())) { g_projectBar.Refresh(); g_project.RefreshTGExportDlg(); } } void TFileTreeComboBox::DoSetProject() { g_project.Save(); } void TFileTreeComboBox::DoRecentProject(int nPos,bool bRefresh) { if (m_lstRecent.IsValidIndex(nPos)) { if (g_project.Load(*m_lstRecent[nPos])) { if (bRefresh) g_projectBar.Refresh(); g_project.RefreshTGExportDlg(); } else m_lstRecent.Del(nPos); } } void TFileTreeComboBox::OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct) { if (nIDCtl == ODT_MENU) m_menu.MeasureItem(lpMeasureItemStruct); else CComboBox::OnMeasureItem(nIDCtl, lpMeasureItemStruct); } void TFileTreeComboBox::AddToRecent(const CString &szRecent) { CString szFullName = szRecent; szFullName.MakeLower(); for (m_lstRecent.MoveToFirst(); !m_lstRecent.IsOut(); m_lstRecent.MoveToNext()) { if (m_lstRecent.GetCurData() != NULL) { CString szTemp = *m_lstRecent.GetCurData(); szTemp.MakeLower(); if (szTemp == szFullName) m_lstRecent.DelCur(); } } m_lstRecent.InsertHead(new CString(szRecent)); } /////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////// #if ADS<16 BEGIN_MESSAGE_MAP(CAdUiPaletteSet,CAcUiDockControlBar) END_MESSAGE_MAP() IMPLEMENT_DYNAMIC(CAdUiPaletteSet,CAcUiDockControlBar) #endif // TProjectBar BEGIN_MESSAGE_MAP(TProjectBar, CAdUiPaletteSet) ON_WM_CREATE() ON_MESSAGE(WM_ACAD_KEEPFOCUS, OnAcadKeepFocus) ON_WM_DESTROY() ON_WM_TIMER() ON_MESSAGE(WM_USER_REFRESH_PROJECT_CMB, OnRefreshMsg) END_MESSAGE_MAP() TProjectBar::TProjectBar(): m_unfoldFlags(&g_iProjectBarUnFoldFlags, sizeof(g_iProjectBarUnFoldFlags)) { } int TProjectBar::OnCreate(LPCREATESTRUCT lpcs) { if (CAdUiPaletteSet::OnCreate(lpcs) == -1) return -1; CRect rect; rect.top = 0; rect.bottom = rect.top + 22; rect.left = 4; rect.right = rect.left + 100; m_comboBox.Create(WS_CHILD | WS_VISIBLE | WS_BORDER | CBS_DROPDOWNLIST, rect, this, IDC_PROJECT_COMBO); m_font.CreateStockObject(DEFAULT_GUI_FONT); m_comboBox.SetFont(&m_font); m_allGroups.Create(this); g_projectBar.Refresh(); // 将指针交给 g_project 以做刷新使用 g_project.SetTGProjectBarWnd(this); return 0; } void TProjectBar::OnDestroy() { CRect rect; GetWindowRect(rect); g_iProjectBarWidth = rect.Width(); g_bProjectBarVisible = (GetStyle()&WS_VISIBLE)!=0; CWnd *pWndFrame = acedGetAcadFrame(); if (pWndFrame != NULL) { CRect rectAcad; pWndFrame->GetClientRect(rectAcad); pWndFrame->ScreenToClient(rect); int xDist = abs(rect.left-rectAcad.left); int yDist = abs(rect.right-rectAcad.right); g_bProjectBarDockLeft = (xDist<=yDist); } for (long i=0; iIsFold()) m_unfoldFlags.Reset(i); else m_unfoldFlags.Set(i); } if (g_project.GetFileFullName() != _T("")) { g_project.Save(); } g_project.Clear(); CAdUiPaletteSet::OnDestroy(); g_project.SetTGProjectBarWnd(NULL); } void TProjectBar::OnTimer(UINT_PTR nIDEvent) { CAdUiPaletteSet::OnTimer(nIDEvent); if (nIDEvent == 1) { KillTimer(1); if (!!m_sCurCmd) { XString sCmd = m_sCurCmd; m_sCurCmd = _T(""); acedPostCommand(sCmd); } } } // Zyu modify on 100721,支持64位 //LONG TProjectBar::OnAcadKeepFocus( UINT, LONG ) LONG_PTR TProjectBar::OnAcadKeepFocus(UINT_PTR, LONG_PTR) { return FALSE; } void TProjectBar::SizeChanged(CRect* lpRect, BOOL bFloating, int nFlags) { CAdUiPaletteSet::SizeChanged(lpRect,bFloating,nFlags); CRect rect = *lpRect; rect.top += 10; rect.left += 4; m_comboBox.MoveWindow(rect); rect.top += 24; m_allGroups.MoveWindow(rect); } void TProjectBar::Refresh() { CString sName; if (!g_project.GetProjectName(sName)) sName = TPR_MANGER_TITLE; else sName = sName.Left(sName.Find(_T('.'))); m_comboBox.ResetContent(); m_comboBox.AddString(sName); m_comboBox.SetCurSel(0); sName = g_project.GetFileFullName(); if (sName != _T("")) m_comboBox.AddToRecent(sName); for (long i=0;iIsFold()) m_unfoldFlags.Reset(i); else m_unfoldFlags.Set(i); } m_allGroups.Clear(); CAcModuleResourceOverride vTemp; AddGroup(new TFileManager,IDD_ALL_FILE); // 图纸 // sg delete 100122,根据sr反馈,从8.5起,给设备专业开放楼层表 // if (g_nProductId!=3 && g_nProductId!=8 && g_nProductId!=6) // 电气\给排水\暖通没有楼层表 AddGroup(new TFloorTable, IDD_ALL_FLOOR); // 楼层表 AddGroup(new TAttribute, IDD_DATA); // 属性 for (i=0;iUnFold(); } } } LRESULT TProjectBar::OnRefreshMsg(WPARAM wp, LPARAM lp) { Refresh(); return TRUE; } /////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////// // TFileTreeCtrl TFileTreeCtrl::TFileTreeCtrl() { m_bEdit = FALSE; m_bDragging = FALSE; m_bRub = FALSE; } BEGIN_MESSAGE_MAP(TFileTreeCtrl, CTreeCtrl) ON_COMMAND_RANGE(ID_INS_DRAWING, ID_COLLAPSE_WORKS, OnMenuCommand) ON_WM_RBUTTONDOWN() ON_NOTIFY_REFLECT(TVN_ENDLABELEDIT, OnTvnEndlabeledit) ON_NOTIFY_REFLECT(TVN_BEGINDRAG, OnTvnBegindrag) ON_WM_MOUSEMOVE() ON_WM_LBUTTONDOWN() ON_WM_LBUTTONUP() ON_WM_TIMER() ON_NOTIFY_REFLECT(TVN_BEGINLABELEDIT, OnTvnBeginlabeledit) ON_WM_LBUTTONDBLCLK() ON_WM_DESTROY() ON_NOTIFY_REFLECT(TVN_SELCHANGED, OnTvnSelchanged) END_MESSAGE_MAP() void TFileTreeCtrl::OnMenuCommand(UINT id) { switch(id) { case ID_OPEN_DRAWING: DoOpenDrawing(); break; case ID_INS_DRAWING: DoInsDrawing(); break; case ID_DEL_DRAWING: DoDelDrawing(); break; case ID_ADD_DRAWING: DoAddDrawing(); break; case ID_ADD_CHILD_COLLECT: DoAddChildCollect(); break; case ID_INS_COLLECT: DoInsCollect(); break; case ID_REN_COLLECT: DoRenCollect(); break; case ID_DEL_COLLECT: DoDelCollect(); break; case ID_EXPAND_COLLECT: DoExpandCollect(); break; case ID_COLLAPSE_COLLECT: DoCollapseCollect(); break; case ID_EXPAND_WORKS: DoExpandWorks(); break; case ID_COLLAPSE_WORKS: DoCollapseWorks(); break; default: break; } } void TFileTreeCtrl::OnRButtonDown(UINT nFlags, CPoint point) { HTREEITEM hItem = HitTest(point); if (hItem != NULL) { SetFocus(); SelectItem(hItem); } CMenu popup; popup.CreatePopupMenu(); if (hItem == NULL) { popup.AppendMenu(MF_STRING, ID_EXPAND_WORKS, _T("全部展开")); popup.AppendMenu(MF_STRING, ID_COLLAPSE_WORKS, _T("全部收拢")); } else { TFileTreeData *pData = (TFileTreeData *)GetItemData(hItem); if (pData == NULL) return; int nType = pData->m_nType; if (nType == 0) { if (curDoc() != NULL) popup.AppendMenu(MF_STRING, ID_ADD_DRAWING, _T("添加图纸...")); popup.AppendMenu(MF_STRING, ID_ADD_CHILD_COLLECT, _T("添加子类别")); } else if (nType == 1) { TProjectGroupItem *pGroup = (TProjectGroupItem*) pData->m_pGroup; if (pGroup == NULL) return; if (pGroup->GetDataNum() > 0 && (GetItemState(hItem, TVIS_EXPANDED) & TVIS_EXPANDED) == TVIS_EXPANDED) { popup.AppendMenu(MF_STRING, ID_COLLAPSE_COLLECT, _T("收拢")); } else { popup.AppendMenu(MF_STRING, ID_EXPAND_COLLECT, _T("展开")); if (!ItemHasChildren(hItem)) popup.EnableMenuItem(ID_EXPAND_COLLECT, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); } popup.AppendMenu(MF_SEPARATOR); if (curDoc() != NULL) popup.AppendMenu(MF_STRING, ID_ADD_DRAWING, _T("添加图纸...")); popup.AppendMenu(MF_STRING, ID_INS_COLLECT, _T("添加类别")); popup.AppendMenu(MF_STRING, ID_ADD_CHILD_COLLECT, _T("添加子类别")); popup.AppendMenu(MF_SEPARATOR); popup.AppendMenu(MF_STRING, ID_REN_COLLECT, _T("重命名")); if (curDoc() != NULL) popup.AppendMenu(MF_STRING, ID_DEL_COLLECT, _T("移除")); } else if (nType == 2) { popup.AppendMenu(MF_STRING, ID_OPEN_DRAWING, _T("打开")); if (curDoc() != NULL) { popup.AppendMenu(MF_SEPARATOR); popup.AppendMenu(MF_STRING, ID_INS_DRAWING, _T("添加图纸...")); popup.AppendMenu(MF_STRING, ID_DEL_DRAWING, _T("移除")); } } } ClientToScreen(&point); popup.TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, this); } void TFileTreeCtrl::OnTvnBeginlabeledit(NMHDR *pNMHDR, LRESULT *pResult) { LPNMTVDISPINFO pTVDispInfo = reinterpret_cast(pNMHDR); if (m_bEdit) { m_bEdit = FALSE; *pResult = 0; } else *pResult = 1; } void TFileTreeCtrl::OnTvnEndlabeledit(NMHDR *pNMHDR, LRESULT *pResult) { LPNMTVDISPINFO pTVDispInfo = reinterpret_cast(pNMHDR); HTREEITEM hItem = pTVDispInfo->item.hItem; TFileTreeData *pData = (TFileTreeData*)GetItemData(hItem); if (pData == NULL || pData->m_pGroup == NULL) { *pResult = 0; return; } TProjectGroupItem *pParent = (TProjectGroupItem*)pData->m_pParentGroup; if (pParent == NULL) { *pResult = 0; return; } CString szName = pTVDispInfo->item.pszText; for (pParent->MoveToFirst(); !pParent->IsOut(); pParent->MoveToNext()) { TProjectGroupItem *pCur = (TProjectGroupItem*)pParent->GetCurData(); if (pCur != pData->m_pGroup && pCur->GetName() == szName && pCur->IsGroup()) { *pResult = 0; return; } } if (szName != _T("")) pData->m_pGroup->SetName(szName); *pResult = 1; } void TFileTreeCtrl::OnTvnBegindrag(NMHDR *pNMHDR, LRESULT *pResult) { LPNMTREEVIEW pNMTreeView = reinterpret_cast(pNMHDR); if ( (GetTickCount() - m_dwDragStart) < 60 ) return; m_hItemDragS = pNMTreeView->itemNew.hItem; m_hItemDragD = NULL; TFileTreeData *pData = (TFileTreeData *)GetItemData(m_hItemDragS); if (pData == NULL) return; m_pDragImage = CreateDragImage( m_hItemDragS ); if ( !m_pDragImage ) return; m_bDragging = true; m_pDragImage->BeginDrag ( 0,CPoint(8,8) ); CPoint pt = pNMTreeView->ptDrag; ClientToScreen( &pt ); m_pDragImage->DragEnter ( this,pt ); SetCapture(); m_nScrollTimerID = SetTimer( 2,40,NULL ); *pResult = 0; } void TFileTreeCtrl::OnMouseMove(UINT nFlags, CPoint point) { HTREEITEM hItem; UINT flags; if ( m_nHoverTimerID ) { KillTimer( m_nHoverTimerID ); m_nHoverTimerID = 0; } m_nHoverTimerID = SetTimer( 1,800,NULL ); m_HoverPoint = point; if ( m_bDragging ) { CPoint pt = point; CImageList::DragMove( pt ); if ( (hItem = HitTest(point,&flags)) != NULL && hItem != TVI_ROOT) { CImageList::DragShowNolock( false ); m_nShowFlag = GetShowFlag( hItem, pt ); if (m_nShowFlag != -2) m_hItemDragD = hItem; CImageList::DragShowNolock( true ); } CRect rect; GetClientRect( &rect ); if ( point.x < rect.left + 20 ) m_hItemDragD = NULL; } CTreeCtrl::OnMouseMove(nFlags, point); } void TFileTreeCtrl::OnLButtonDown(UINT nFlags, CPoint point) { m_dwDragStart = GetTickCount(); CTreeCtrl::OnLButtonDown(nFlags, point); } void TFileTreeCtrl::OnLButtonUp(UINT nFlags, CPoint point) { CTreeCtrl::OnLButtonUp(nFlags, point); if ( m_bDragging ) { if (m_bRub) { m_bRub = FALSE; DrawTempLine(m_ptSta, m_ptEnd); } m_bDragging = FALSE; CImageList::DragLeave( this ); CImageList::EndDrag(); ReleaseCapture(); delete m_pDragImage; SelectDropTarget( NULL ); if ( m_hItemDragS == m_hItemDragD || m_hItemDragD == NULL) { KillTimer( m_nScrollTimerID ); Invalidate(); return; } TFileTreeData *pData = (TFileTreeData *)GetItemData(m_hItemDragD); if (pData == NULL) { KillTimer( m_nScrollTimerID ); Invalidate(); return; } // 判断是否有相同项 //CString s2 = GetItemText(m_hItemDragD); //CString s1 = GetItemText(m_hItemDragS); HTREEITEM pParent = GetParentItem(m_hItemDragD); if (GetParentItem(m_hItemDragS) != pParent) { CString szText = GetItemText(m_hItemDragS); HTREEITEM hChild = GetChildItem(pParent); while( hChild != NULL ) { if (GetItemText(hChild) == szText) { KillTimer(m_nScrollTimerID); Invalidate(); return; } hChild = GetNextSiblingItem(hChild); } } Expand( m_hItemDragD,TVE_EXPAND ); HTREEITEM htiParent = m_hItemDragD; while( (htiParent = GetParentItem(htiParent)) != NULL ) { if ( htiParent == m_hItemDragS ) { KillTimer( m_nScrollTimerID ); Invalidate(); return; } } HTREEITEM htiNew; if (m_nShowFlag == -1) { HTREEITEM hPre = GetPrevSiblingItem(m_hItemDragD); if (hPre != NULL) htiNew = CopyBranch( m_hItemDragS,GetParentItem(m_hItemDragD),hPre ); else htiNew = CopyBranch( m_hItemDragS,GetParentItem(m_hItemDragD),TVI_FIRST ); } else if (m_nShowFlag == 0) { htiNew = CopyBranch( m_hItemDragS,m_hItemDragD,TVI_LAST ); } else if (m_nShowFlag == 1) { htiNew = CopyBranch( m_hItemDragS,GetParentItem(m_hItemDragD),m_hItemDragD ); } DeleteItemEx( m_hItemDragS ); SelectItem( htiNew ); KillTimer( m_nScrollTimerID ); } } void TFileTreeCtrl::OnTvnSelchanged(NMHDR *pNMHDR, LRESULT *pResult) { LPNMTREEVIEW pNMTreeView = reinterpret_cast(pNMHDR); CString szFullName; TFileTreeData *pData = (TFileTreeData *)GetItemData(pNMTreeView->itemNew.hItem); if (pData != NULL) { if (pData->m_nType == 2) { CString szItemText = GetItemText(pNMTreeView->itemNew.hItem); szFullName = g_project.GetDwgFullName(szItemText); } } // modified by whl on 060419 // TAttribute *pAtt = (TAttribute *)g_projectBar.m_allGroups.m_allGroup.GetAt(2); TAttribute *pAtt = (TAttribute *)g_projectBar.m_allGroups.m_allGroup.GetAt(g_projectBar.m_allGroups.m_allGroup.GetLastIndex()); if (pAtt != NULL) { pAtt->SetPreviewFile(szFullName); } *pResult = 0; } void TFileTreeCtrl::OnLButtonDblClk(UINT nFlags, CPoint point) { DoOpenDrawing(); CTreeCtrl::OnLButtonDblClk(nFlags, point); } // Zyu modify on 100721,支持64位 //void TFileTreeCtrl::OnTimer(UINT nIDEvent) void TFileTreeCtrl::OnTimer(UINT_PTR nIDEvent) { if ( nIDEvent == m_nHoverTimerID ) { KillTimer( m_nHoverTimerID ); m_nHoverTimerID = 0; HTREEITEM trItem = 0; UINT uFlag = 0; trItem = HitTest( m_HoverPoint,&uFlag ); if ( trItem && m_bDragging ) { SelectItem( trItem ); Expand( trItem,TVE_EXPAND ); } } else if ( nIDEvent == m_nScrollTimerID ) { m_TimerTicks++; CPoint pt; GetCursorPos( &pt ); CRect rect; GetClientRect( &rect ); ClientToScreen( &rect ); HTREEITEM hItem = GetFirstVisibleItem(); if ( pt.y < rect.top +10 ) { int slowscroll = 6 - (rect.top + 10 - pt.y )/20; if ( 0 == (m_TimerTicks % ((slowscroll > 0) ? slowscroll : 1)) ) { CImageList::DragShowNolock ( false ); SendMessage( WM_VSCROLL,SB_LINEUP ); SelectDropTarget( hItem ); m_hItemDragD = hItem; CImageList::DragShowNolock ( true ); } } else if ( pt.y > rect.bottom - 10 ) { int slowscroll = 6 - (pt.y - rect.bottom + 10)/20; if ( 0 == (m_TimerTicks % ((slowscroll > 0) ? slowscroll : 1)) ) { CImageList::DragShowNolock ( false ); SendMessage( WM_VSCROLL,SB_LINEDOWN ); int nCount = GetVisibleCount(); for ( int i=0 ; im_nType == 0) { nFlag = 0; SelectDropTarget( hItem ); } else if (pData->m_nType == 1) { rUp.bottom = rUp.top + lDis / 4; rDown.top = rDown.bottom - lDis / 4; rMid.top = rMid.top + lDis / 4; rMid.bottom = rMid.bottom - lDis / 4; if (rUp.PtInRect(pt)) { nFlag = -1; SelectDropTarget( NULL ); SelectItem(m_hItemDragS); m_ptSta = CPoint(rDc.left, rDc.top); m_ptEnd = CPoint(rect.right - 5, rDc.top); DrawTempLine(m_ptSta, m_ptEnd); m_bRub = TRUE; } else if (rDown.PtInRect(pt)) { nFlag = 1; SelectDropTarget( NULL ); SelectItem(m_hItemDragS); m_ptSta = CPoint(rDc.left, rDc.bottom); m_ptEnd = CPoint(rect.right - 5, rDc.bottom); DrawTempLine(m_ptSta, m_ptEnd); m_bRub = TRUE; } else if (rMid.PtInRect(pt)) { nFlag = 0; SelectDropTarget( hItem ); } } else if (pData->m_nType == 2) { rUp.bottom = rUp.top + lDis / 2; rDown.top = rDown.bottom - lDis / 2; if (rUp.PtInRect(pt)) { nFlag = -1; m_ptSta = CPoint(rDc.left, rDc.top); m_ptEnd = CPoint(rect.right - 5, rDc.top); DrawTempLine(m_ptSta, m_ptEnd); m_bRub = TRUE; } else if (rDown.PtInRect(pt)) { nFlag = 1; m_ptSta = CPoint(rDc.left, rDc.bottom); m_ptEnd = CPoint(rect.right - 5, rDc.bottom); DrawTempLine(m_ptSta, m_ptEnd); m_bRub = TRUE; } SelectDropTarget( NULL ); SelectItem(m_hItemDragS); } return nFlag; } void TFileTreeCtrl::DrawTempLine(CPoint ptSta, CPoint ptEnd) { CClientDC dc(this); CPen pen(PS_SOLID, 2, RGB(125,125,125)),*pOldPen; pOldPen = dc.SelectObject(&pen); dc.SetROP2(R2_XORPEN); dc.MoveTo(ptSta); dc.LineTo(ptSta.x-2, ptSta.y+2); dc.MoveTo(ptSta); dc.LineTo(ptSta.x-2, ptSta.y-2); dc.MoveTo(ptSta.x-2, ptSta.y); dc.LineTo(ptEnd.x+2, ptEnd.y); dc.MoveTo(ptEnd); dc.LineTo(ptEnd.x+2, ptEnd.y+2); dc.MoveTo(ptEnd); dc.LineTo(ptEnd.x+2, ptEnd.y-2); dc.MoveTo(ptEnd); dc.SelectObject(pOldPen); } HTREEITEM TFileTreeCtrl::CopyItem(HTREEITEM hItem, HTREEITEM htiNewParent, HTREEITEM htiAfter) { if (hItem == NULL || htiNewParent == NULL) return NULL; TFileTreeData *pData = (TFileTreeData *)GetItemData(hItem); if (pData == NULL) return NULL; TProjectGroupItem *pGroup = NULL; CString szText = GetItemText(hItem); if (pData->m_nType == 2) { TProjectFile *pItem = new TProjectFile(szText); pGroup = (TProjectGroupItem *)pItem; } else { pGroup = new TProjectGroupItem(szText); } if (pGroup == NULL) return NULL; TFileTreeData *pParentData = (TFileTreeData *)GetItemData(htiNewParent); if (pParentData == NULL) return NULL; TProjectGroupItem *pParentGroup = (TProjectGroupItem*)pParentData->m_pGroup; if (pParentGroup == NULL) return NULL; if (htiAfter == TVI_LAST) pParentGroup->AddTail(pGroup); else if (htiAfter == TVI_FIRST) pParentGroup->InsertHead(pGroup); else { int nPos = -1; TFileTreeData *pAfter = (TFileTreeData *)GetItemData(htiAfter); if (pAfter != NULL && pAfter->m_pGroup != NULL) nPos = pParentGroup->Find(pAfter->m_pGroup); pParentGroup->MoveTo(nPos); pParentGroup->InsertAfterCur(pGroup); } return InsertItemEx((TProjectGroupItem *)pGroup, htiNewParent, htiAfter); } HTREEITEM TFileTreeCtrl::CopyBranch(HTREEITEM htiBranch, HTREEITEM htiNewParent, HTREEITEM htiAfter) { HTREEITEM hChild; HTREEITEM hNewItem = CopyItem( htiBranch,htiNewParent,htiAfter ); hChild = GetChildItem( htiBranch ); while( hChild != NULL ) { CopyBranch( hChild,hNewItem,htiAfter ); hChild = GetNextSiblingItem( hChild ); } return hNewItem; } void TFileTreeCtrl::DeleteAllItemData(HTREEITEM hItem) { hItem = GetChildItem(hItem); while(hItem != NULL) { TFileTreeData *pData = (TFileTreeData *)GetItemData(hItem); delete pData; DeleteAllItemData(hItem); hItem = GetNextSiblingItem(hItem); } } BOOL TFileTreeCtrl::PreTranslateMessage(MSG* pMsg) { if (pMsg->message == WM_KEYDOWN) { // Zyu modify on 100722,支持64位 //int nVk = pMsg->wParam; INT_PTR nVk = pMsg->wParam; if (nVk == VK_DELETE&&pMsg->hwnd==GetSafeHwnd()) { HTREEITEM hItem = GetSelectedItem(); if (hItem == NULL) return CTreeCtrl::PreTranslateMessage(pMsg); TFileTreeData *pData = (TFileTreeData *)GetItemData(hItem); if (pData == NULL) return CTreeCtrl::PreTranslateMessage(pMsg); int nType = pData->m_nType; if (nType == 1) { TProjectGroupItem *pGroup = (TProjectGroupItem*)pData->m_pGroup; if (pGroup != NULL) { DoDelCollect(); return TRUE; } } else if (nType == 2) { DoDelDrawing(); return TRUE; } } else if (nVk == VK_F2) { HTREEITEM hItem = GetSelectedItem(); if (hItem == NULL) return CTreeCtrl::PreTranslateMessage(pMsg); TFileTreeData *pData = (TFileTreeData *)GetItemData(hItem); if (pData == NULL) return CTreeCtrl::PreTranslateMessage(pMsg); int nType = pData->m_nType; if (nType == 1) { DoRenCollect(); return TRUE; } } } return CTreeCtrl::PreTranslateMessage(pMsg); } HTREEITEM TFileTreeCtrl::InsertItemEx(TProjectItem *pGroup, HTREEITEM hParent, HTREEITEM hInsertAfter) { if (pGroup->GetName() == _T("")) return NULL; int nImage = (pGroup->IsGroup()) ? 1 : 2; if (hParent == TVI_ROOT) nImage = 0; HTREEITEM hItem = InsertItem(pGroup->GetName(), nImage, nImage, hParent, hInsertAfter); TProjectGroupItem *pParentGroup = NULL; if (hParent != NULL && hParent != TVI_ROOT) { TFileTreeData *pParent = (TFileTreeData *)GetItemData(hParent); if (pParent != NULL) pParentGroup = (TProjectGroupItem*)(pParent->m_pGroup); } TFileTreeData *pData = new TFileTreeData(nImage, hItem, pParentGroup, pGroup); // Zyu modify on 100722,支持64位 //SetItemData(hItem, (DWORD)pData); SetItemData(hItem, (DWORD_PTR)pData); return hItem; } void TFileTreeCtrl::DeleteItemEx(HTREEITEM hItem) { if (hItem == NULL || hItem == TVI_ROOT) return; HTREEITEM hChild = GetChildItem(hItem); while(hChild != NULL) { DeleteItemEx(hChild); hChild = GetNextSiblingItem(hChild); } TFileTreeData *pData = (TFileTreeData *)GetItemData(hItem); if (pData != NULL) { TProjectGroupItem *pParentGroup = pData->m_pParentGroup; if (!pData->m_pGroup->IsGroup())//图纸项 //在dwg中清除记录的工程数据库名 WritePrjToDwg(_T(""),g_project.GetDwgFullName(pData->m_pGroup->GetName())); if (pParentGroup != NULL) pParentGroup->FindAndDel(pData->m_pGroup); delete pData; } DeleteItem(hItem); } void TFileTreeCtrl::ExpandAll() { HTREEITEM hOldItem = GetSelectedItem(); HTREEITEM hItem = GetRootItem(); SelectItem(hItem); SendMessage(WM_KEYDOWN, VK_MULTIPLY); EnsureVisible(hItem); SelectItem(hOldItem); } void TFileTreeCtrl::CollapseAll() { HTREEITEM hItem = GetRootItem(); SelectItem(hItem); SendMessage(WM_KEYDOWN, VK_SUBTRACT); EnsureVisible(hItem); SelectItem(hItem); } BOOL TFileTreeCtrl::InitTreeCtrl() { m_pCurGroup = g_project.GetGroup(_T("图纸")); if (m_pCurGroup == NULL) return FALSE; CString szName; SplitPath(g_project.GetFileFullName(), CString(), szName); CString szOldName = m_pCurGroup->GetName(); m_pCurGroup->SetName(szName); HTREEITEM hRoot = GroupToTree(m_pCurGroup, TVI_ROOT); m_pCurGroup->SetName(szOldName); Expand(hRoot, TVE_EXPAND); return TRUE; } HTREEITEM TFileTreeCtrl::GroupToTree(TProjectGroupItem *pGroup, HTREEITEM hParent, HTREEITEM hInsertAfter) { if (pGroup == NULL) return NULL; HTREEITEM hItem = InsertItemEx(pGroup, hParent, hInsertAfter); if (pGroup->IsGroup()) { for (pGroup->MoveToFirst(); !pGroup->IsOut(); pGroup->MoveToNext()) { TProjectGroupItem *pChildGroup = (TProjectGroupItem *)pGroup->GetCurData(); GroupToTree(pChildGroup, hItem, hInsertAfter); } } return hItem; } // 图纸级 void TFileTreeCtrl::DoOpenDrawing() { HTREEITEM hItem = GetSelectedItem(); if (hItem == NULL || hItem == TVI_ROOT) return; TFileTreeData *pData = (TFileTreeData *)GetItemData(hItem); if (pData->m_pGroup == NULL || pData->m_pGroup->IsGroup()) return; OpenProjectDwg(g_project.GetDwgFullName(GetItemText(hItem))); } void TFileTreeCtrl::DoInsDrawing() { CString szPath; g_project.GetFilePath(szPath); XStringList lstFiles; if (!GetDwgFilesDia(lstFiles, this, szPath, _T("选择图纸"))) return; HTREEITEM hItem = GetSelectedItem(); if (hItem == NULL || hItem == TVI_ROOT) return; TFileTreeData *pData = (TFileTreeData *)GetItemData(hItem); if (pData == NULL) return; TProjectGroupItem *pParentGroup = pData->m_pParentGroup; long lPos = pParentGroup->Find(pData->m_pGroup); for (int i=0; iFindItem(szFileName) != NULL) if (!CanInsert(pParentGroup,szFileName)) { acutPrintf(_T("\n%s 项已存在\n"), szFileName); continue; } //在dwg中记录所属工程数据库名 if (FindFile(lstFiles[i])&&!WritePrjToDwg(g_project.GetFileFullName(),lstFiles[i])) { AfxMessageBox(XString(_T("无法将文件:%s加入工程!请检查文件是否只读."),lstFiles[i])); continue; } TProjectFile *pNewGroup = new TProjectFile(szFileName); if (pNewGroup != NULL) { pParentGroup->MoveTo(lPos); pParentGroup->InsertAfterCur(pNewGroup); InsertItemEx((TProjectGroupItem*)pNewGroup, GetParentItem(hItem), hItem); lPos++; } } SelectItem(hItem); } void TFileTreeCtrl::DoDelDrawing() { if (acDocManager->documentCount()<1) return; HTREEITEM hItem = GetSelectedItem(); TFileTreeData *pData = (TFileTreeData *)GetItemData(hItem); if (pData != NULL) DeleteItemEx(hItem); } // 项目级 void TFileTreeCtrl::DoAddDrawing() { HTREEITEM hItem = GetSelectedItem(); if (hItem == NULL || hItem == TVI_ROOT) return; TFileTreeData *pData = (TFileTreeData *)GetItemData(hItem); if (pData == NULL) return; CString szPath; g_project.GetFilePath(szPath); XStringList lstFiles; if (!GetDwgFilesDia(lstFiles, this, szPath, _T("选择图纸"))) return; TProjectGroupItem *pGroup = (TProjectGroupItem*) pData->m_pGroup; for (int i=0; iFindItem(szFileName) != NULL) if (!CanInsert(pGroup,szFileName)) { acutPrintf(_T("\n%s 项已存在\n"), szFileName); continue; } //在dwg中记录所属工程数据库名 if (FindFile(lstFiles[i])&&!WritePrjToDwg(g_project.GetFileFullName(),lstFiles[i])) { AfxMessageBox(XString(_T("无法将文件:%s加入工程!请检查文件是否只读."),lstFiles[i])); continue; } TProjectFile *pNewGroup = new TProjectFile(szFileName); if (pGroup != NULL) { pGroup->AddTail(pNewGroup); InsertItemEx((TProjectGroupItem*)pNewGroup, hItem, TVI_LAST); } } SelectItem(hItem); Expand(hItem, TVE_EXPAND); } void TFileTreeCtrl::DoInsCollect() { HTREEITEM hItem = GetSelectedItem(); if (hItem == NULL || hItem == TVI_ROOT) return; TFileTreeData *pData = (TFileTreeData *)GetItemData(hItem); if (pData == NULL) return; TProjectGroupItem *pGroup = pData->m_pParentGroup; if (pGroup == NULL) return; CString szName; int nCount = 1; HTREEITEM hParent = GetParentItem(hItem); while(1) { BOOL bFlag = FALSE; szName.Format(_T("新建项目 (%d)"), nCount); if (ItemHasChildren(hParent)) { HTREEITEM hChild = GetChildItem(hParent); while(hChild != NULL) { CString szItem = GetItemText(hChild); if (szItem == szName) { bFlag = TRUE; nCount++; break; } hChild = GetNextSiblingItem(hChild); } } if (!bFlag) break; } TProjectGroupItem *pNewGroup = new TProjectGroupItem(szName); if (pNewGroup != NULL) { long lPos = pGroup->Find(pData->m_pGroup); pGroup->MoveTo(lPos); pGroup->InsertAfterCur(pNewGroup); HTREEITEM hRes = InsertItemEx(pNewGroup, hParent, hItem); Expand(hParent, TVE_EXPAND); SelectItem(hRes); DoRenCollect(); } } void TFileTreeCtrl::DoAddChildCollect() { HTREEITEM hParent = GetSelectedItem(); if (hParent == NULL || hParent == TVI_ROOT) return; TFileTreeData *pData = (TFileTreeData *)GetItemData(hParent); if (pData == NULL || pData->m_pGroup == NULL) return; CString szName; int nCount = 1; while(1) { BOOL bFlag = FALSE; szName.Format(_T("新建项目 (%d)"), nCount); if (ItemHasChildren(hParent)) { HTREEITEM hChild = GetChildItem(hParent); while(hChild != NULL) { CString szItem = GetItemText(hChild); if (szItem == szName) { bFlag = TRUE; nCount++; break; } hChild = GetNextSiblingItem(hChild); } } if (!bFlag) break; } TProjectGroupItem *pNewGroup = new TProjectGroupItem(szName); if (pNewGroup != NULL) { TProjectGroupItem *pGroup = (TProjectGroupItem*) pData->m_pGroup; pGroup->AddTail(pNewGroup); HTREEITEM hRes = InsertItemEx(pNewGroup, hParent); Expand(hParent, TVE_EXPAND); SelectItem(hRes); DoRenCollect(); } } void TFileTreeCtrl::DoRenCollect() { m_bEdit = TRUE; HTREEITEM hItem = GetSelectedItem(); CEdit *pEdit = EditLabel(hItem); } void TFileTreeCtrl::DoDelCollect() { HTREEITEM hItem = GetSelectedItem(); DeleteItemEx(hItem); } void TFileTreeCtrl::DoExpandCollect() { HTREEITEM hItem = GetSelectedItem(); Expand(hItem, TVE_EXPAND); } void TFileTreeCtrl::DoCollapseCollect() { HTREEITEM hItem = GetSelectedItem(); Expand(hItem, TVE_COLLAPSE); } // 工程级 void TFileTreeCtrl::DoExpandWorks() { ExpandAll(); } void TFileTreeCtrl::DoCollapseWorks() { CollapseAll(); } /////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////// // TFileManager void TFileManager::DoDataExchange(CDataExchange* pDX) { WGroupBox::DoDataExchange(pDX); DDX_Control(pDX, IDC_TREE, m_ctrlTree); } BEGIN_MESSAGE_MAP(TFileManager, WGroupBox) ON_WM_SIZE() ON_COMMAND_RANGE(ID_DRAWING_LIST, ID_DRAWING_LIST+10, OnClickToolBar) ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, OnToolTipText) ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, OnToolTipText) END_MESSAGE_MAP() BOOL TFileManager::OnInitDialog() { WGroupBox::OnInitDialog(); m_ImageList.Create(16, 16, ILC_COLOR8, 1, 1); m_ImageList.SetBkColor(RGB(255,255,255)); m_ImageList.Add(AfxGetApp()->LoadIcon(IDI_ICON_PROJECT)); m_ImageList.Add(AfxGetApp()->LoadIcon(IDI_ICON_GROUP)); m_ImageList.Add(AfxGetApp()->LoadIcon(IDI_ICON_DWG)); m_ctrlTree.SetImageList(&m_ImageList, TVSIL_NORMAL); m_ctrlTree.InitTreeCtrl(); InitToolbar(); if (g_project.GetGroup(_T("楼层")) == NULL) { m_toolBar.EnableWindow(FALSE); m_ctrlTree.EnableWindow(FALSE); } return TRUE; } void TFileManager::OnSize(UINT nType, int cx, int cy) { WGroupBox::OnSize(nType, cx, cy); m_ctrlTree.MoveWindow(0, 28, cx, cy-28); CRect rect; m_toolBar.GetWindowRect(rect); ScreenToClient(rect); rect.right = rect.left+cy; m_toolBar.MoveWindow(rect); } void TFileManager::OnClickToolBar(UINT nID) { switch(nID) { case ID_DRAWING_LIST: DoDrawingList(); break; default: break; } } BOOL TFileManager::OnToolTipText(UINT, NMHDR* pNMHDR, LRESULT* pResult) { ASSERT(pNMHDR->code == TTN_NEEDTEXTA || pNMHDR->code == TTN_NEEDTEXTW); // if there is a top level routing frame then let it handle the message if (GetRoutingFrame() != NULL) return FALSE; // to be thorough we will need to handle UNICODE versions of the message also !! TOOLTIPTEXTA* pTTTA = (TOOLTIPTEXTA*)pNMHDR; TOOLTIPTEXTW* pTTTW = (TOOLTIPTEXTW*)pNMHDR; // TCHAR szFullText[512]; CString strTipText; // Zyu modify on 100723,消除64位编译警告 //UINT nID = pNMHDR->idFrom; UINT nID = (UINT)pNMHDR->idFrom; if (pNMHDR->code == TTN_NEEDTEXTA && (pTTTA->uFlags & TTF_IDISHWND) || pNMHDR->code == TTN_NEEDTEXTW && (pTTTW->uFlags & TTF_IDISHWND)) { // idFrom is actually the HWND of the tool // nID = ::GetDlgCtrlID((HWND)nID); return FALSE; // Add by whl on 060308 } if (nID != 0) // will be zero on a separator { { CAcModuleResourceOverride vTmp; strTipText.LoadString(nID); // =szFullText; } #ifndef _UNICODE if (pNMHDR->code == TTN_NEEDTEXTA) { lstrcpyn(pTTTA->szText, strTipText, sizeof(pTTTA->szText)); } else { _mbstowcsz(pTTTW->szText, strTipText, sizeof(pTTTW->szText)); } #else if (pNMHDR->code == TTN_NEEDTEXTA) { _wcstombsz(pTTTA->szText, strTipText,sizeof(pTTTA->szText)); } else { lstrcpyn(pTTTW->szText, strTipText, sizeof(pTTTW->szText)); } #endif *pResult = 0; // bring the tooltip window above other popup windows ::SetWindowPos(pNMHDR->hwndFrom, HWND_TOP, 0, 0, 0, 0,SWP_NOACTIVATE| SWP_NOSIZE|SWP_NOMOVE|SWP_NOOWNERZORDER); return TRUE; } return TRUE; } void TFileManager::InitToolbar() { CAcModuleResourceOverride vTmp; m_toolBar.Create(WS_VISIBLE | WS_CHILD | CCS_TOP | TBSTYLE_TOOLTIPS | CCS_ADJUSTABLE , CRect(0,0,0,0), this, IDR_TOOLBAR_MANAGE); const int nButtonNum = 1; int ButtonID[nButtonNum] = { ID_DRAWING_LIST }; TBBUTTON *pRTF_Button = new TBBUTTON[nButtonNum]; TBBUTTON *pIndex = pRTF_Button; for (int i=0; iiBitmap = i; pIndex->idCommand = ButtonID[i]; pIndex->fsStyle = TBSTYLE_BUTTON; pIndex->fsState = TBSTATE_ENABLED; pIndex++; } CSize size(16, 15); m_toolBar.SetButtonSize(size); m_toolBar.AddButtons(nButtonNum, pRTF_Button); delete[] pRTF_Button; m_toolBar.SetBitmapSize(size); m_toolBar.ModifyStyle(0, TBSTYLE_FLAT); m_toolBar.AddBitmap(1, IDR_TOOLBAR_MANAGE); } void TFileManager::DoDrawingList() { acedPostCommand(_T("TTitleList\n")); return; XString sCmd = GetFullCmdName(_T("TTitleList")); sCmd<<_T("\n"); g_projectBar.SendCommand(sCmd); } /////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////// // TFloorGrid——楼层表格 TFloorGrid::TFloorGrid() { AppendCol(_T("层号"), 30); AppendCol(_T("层高"), 30); AppendCol(_T("文件"), 30); SetColFixLength(); SetColPosFix(); } // 单击“文件”单元格 bool TFloorGrid::OnCellButtonDown(WDGridCell &cell, CString &res) { if (cell.GetColIndex() == 2) // 文件,选择标准层图形文件 { // add by whl on 070517 if (curDoc() == NULL) { AfxMessageBox(_T("请先打开一个图形!")); return false; } CString szPath; g_project.GetFilePath(szPath); struct resbuf *result = acutNewRb(RTSTR); #if ADS > 15 if (acedGetFileNavDialog(_T("选择标准层图形文件"), szPath, _T("dwg"), _T(""), 256, &result) != RTNORM) return false; #else if (acedGetFileD(_T("选择标准层图形文件"), szPath, _T("dwg"), 256, result) != RTNORM) return false; #endif if (result == NULL || result->restype != RTSTR) return false; CString szHeight = GetLHeight(result->resval.rstring); CString szFileName = g_project.GetDwgRelativeName(result->resval.rstring); acutRelRb(result); CString szLayerNo = cell.GetRow()[0].GetText(); if (szLayerNo == _T("")) szLayerNo = GetLayerNo(); WDGridRow &row = cell.GetRow(); row[0].SetText(szLayerNo); row[1].SetText(szHeight); row[2].SetText(szFileName); row.Refresh(); res = (const TCHAR*)cell; return true; } return false; } void TFloorGrid::OnDataChanged() { if (m_pCurGroup == NULL) return; GridToExtendData(GetCurRowIndex()); // 表格——>数据 m_pCurGroup->Clear(); for (int i=0; iSetName(pData->m_szName); pFloor->SetHeight(pData->m_dHeight); pFloor->SetLayerNo(pData->m_sLayerNo); pFloor->SetFloorInFrame(pData->m_iFlag != 0); pFloor->SetBasePoint(pData->m_ptBase); pFloor->SetRange(pData->m_ptMin, pData->m_ptMax); m_pCurGroup->AddTail(pFloor); } } AppendToTreeCtrl(); // 添加图纸目录 } // 双击“工程管理->楼层表->当前楼层”行首 void TFloorGrid::OnDblClick(WDGridRow&row) { // if (acDocManager->documentCount()<1) // return; // 准备文件名 TFloorGridData *pData = (TFloorGridData*)row.GetExtendData(); if (pData == NULL) return; if (!OpenProjectDwg(g_project.GetDwgFullName(pData->m_szName))) return; // 准备包围盒 XPoint ptBase, ptMin, ptMax; if (pData->m_iFlag != 0) { ptMin = pData->m_ptMin; ptMax = pData->m_ptMax; ptBase = pData->m_ptBase; } else { xg_getvar(_T("EXTMIN"),ptMin); // LIMMIN xg_getvar(_T("EXTMAX"),ptMax); // LIMMAX xg_getvar(_T("INSBASE"),ptBase); } arxZoom(ptMin, ptMax); XScreenDc dc(1, 1); // sg add 100202,支持UCS,将点进行转化 ptMin = Wcs2Ucs(ptMin); ptMax = Wcs2Ucs(ptMax); XRectAngle rect(ptMin, ptMax); XPoly2D poly; rect.AsPoly2D(poly); // sg delete 100202,最大、最小点已进行过Wcs2Ucs的转化 // poly.TransUCS(Groups(0), Groups(1)); dc << poly; ptBase = Wcs2Ucs(ptBase); // dc.SetColor(2); // 颜色改为红色 dc.Draw(ptBase, PS_CROSS_SLANT, 4); acedUpdateDisplay(); } void TFloorGrid::SetData(TProjectGroupItem *pGroup) { m_pCurGroup = pGroup; if (m_pCurGroup == NULL) return; for (int i=0; iGetDataNum(); i++) { TProjectFloor *pFloor = (TProjectFloor *)m_pCurGroup->GetAt(i); if (pFloor == NULL) continue; TFloorGridData *pData = new TFloorGridData; if (pData == NULL) continue; pData->m_szName = pFloor->GetName(); pData->m_dHeight = pFloor->GetHeight(); pData->m_sLayerNo=pFloor->GetLayerNo(); pData->m_iFlag = pFloor->IsFloorInFrame(); pData->m_ptBase = pFloor->GetBasePoint(); pFloor->GetRange(pData->m_ptMin, pData->m_ptMax); AppendRow(); GetRow(i).SetExtendData(pData); ExtendDataToGrid(pData, i); } AppendToTreeCtrl(); } // 数据——>表格 void TFloorGrid::ExtendDataToGrid(const TFloorGridData *pData, int nRow) { if (pData == NULL) return; GetCell(nRow, 0).SetText(pData->m_sLayerNo); CString szHeight; if (pData->m_dHeight > 1E-6) { szHeight.Format(_T("%.2f"), pData->m_dHeight); szHeight.TrimRight(_T("0")); szHeight.TrimRight(_T(".")); } GetCell(nRow, 1).SetText(szHeight); CString szName = pData->m_szName; if (szName != _T("")) { if (pData->m_iFlag != 0) szName += _T("<框选>"); } GetCell(nRow, 2).SetText(szName); } // 表格——>数据 TFloorGridData *TFloorGrid::GridToExtendData(int nRow) { if (nRow<0 || nRow>=GetRowNum()) return NULL; CString szLayerNo = GetCell(nRow, 0).GetText(); CString szHeight = GetCell(nRow, 1).GetText(); CString szName = GetCell(nRow, 2).GetText(); if (szLayerNo == _T("") && szHeight == _T("") && szName == _T("")) return NULL; TFloorGridData *pData = (TFloorGridData*)GetRow(nRow).GetExtendData(); if (pData == NULL) { pData = new TFloorGridData; GetRow(nRow).SetExtendData(pData); } pData->m_sLayerNo =GetRow(nRow)[0].GetText(); pData->m_dHeight = _tstof(szHeight); int nPos = szName.Find(_T("<框选>")); if (nPos == -1) { pData->m_iFlag = 0; pData->m_szName = szName; } else { pData->m_iFlag = 1; pData->m_szName = szName.Left(nPos); } return pData; } CString TFloorGrid::GetLayerNo() { CString szLayerNo; int nFirst = 0; int nLast = 0; int nCount = GetRowNum(); if (nCount > 0) { nFirst = GetFirstNo(0); nLast = GetLastNo(0); } for (int i=1; im_ctrlTree; if (pTree == NULL) return; TProjectGroupItem *pGroup = NULL; HTREEITEM hItem = pTree->GetChildItem(pTree->GetChildItem(TVI_ROOT)); while(hItem != NULL) { if (pTree->GetItemText(hItem)==FLOOR_GROUP) break; hItem = pTree->GetNextSiblingItem(hItem); } if (hItem == NULL) { HTREEITEM hParent = pTree->GetChildItem(TVI_ROOT); if (hParent == NULL) return; pGroup = new TProjectGroupItem(FLOOR_GROUP); pTree->m_pCurGroup->AddTail(pGroup); hItem = pTree->InsertItemEx(pGroup, hParent); } else { TFileTreeData *pData = (TFileTreeData *)pTree->GetItemData(hItem); pGroup = (TProjectGroupItem*)(pData->m_pGroup); } for (int i=0; im_szName; if (szName == _T("")) continue; // if (pTree->m_pCurGroup->FindItem(szName) == NULL) if (CanInsert(pGroup,szName)) { // 在dwg中记录所属工程数据库名 CString sFullName = g_project.GetDwgFullName(szName); if (!WritePrjToDwg(g_project.GetFileFullName(), sFullName)) continue; TProjectFile *pChild = new TProjectFile(szName); pGroup->AddTail(pChild); pTree->InsertItemEx(pChild, hItem); } } pTree->Expand(hItem, TVE_EXPAND); } /////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////// // TFloorTable BEGIN_MESSAGE_MAP(TFloorTable,WGroupBox) ON_WM_SIZE() ON_COMMAND_RANGE(ID_BUTTON_SELECTPART, ID_BUTTON_SELECTPART+10, OnClickToolBar) ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, OnToolTipText) ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, OnToolTipText) END_MESSAGE_MAP() BOOL TFloorTable::OnToolTipText(UINT, NMHDR* pNMHDR, LRESULT* pResult) { ASSERT(pNMHDR->code == TTN_NEEDTEXTA || pNMHDR->code == TTN_NEEDTEXTW); // if there is a top level routing frame then let it handle the message if (GetRoutingFrame() != NULL) return FALSE; // to be thorough we will need to handle UNICODE versions of the message also !! TOOLTIPTEXTA* pTTTA = (TOOLTIPTEXTA*)pNMHDR; TOOLTIPTEXTW* pTTTW = (TOOLTIPTEXTW*)pNMHDR; //TCHAR szFullText[512]; CString strTipText; // Zyu modify on 100723,消除64位编译警告 //UINT nID = pNMHDR->idFrom; UINT nID = (UINT)pNMHDR->idFrom; if (pNMHDR->code == TTN_NEEDTEXTA && (pTTTA->uFlags & TTF_IDISHWND) || pNMHDR->code == TTN_NEEDTEXTW && (pTTTW->uFlags & TTF_IDISHWND)) { // idFrom is actually the HWND of the tool //nID = ::GetDlgCtrlID((HWND)nID); return FALSE; // Add by whl on 060308 } if (nID != 0) // will be zero on a separator { { CAcModuleResourceOverride vTmp; strTipText.LoadString(nID); //=szFullText; } #ifndef _UNICODE if (pNMHDR->code == TTN_NEEDTEXTA) { lstrcpyn(pTTTA->szText, strTipText, sizeof(pTTTA->szText)); } else { _mbstowcsz(pTTTW->szText, strTipText, sizeof(pTTTW->szText)); } #else if (pNMHDR->code == TTN_NEEDTEXTA) { _wcstombsz(pTTTA->szText, strTipText,sizeof(pTTTA->szText)); } else { lstrcpyn(pTTTW->szText, strTipText, sizeof(pTTTW->szText)); } #endif *pResult = 0; // bring the tooltip window above other popup windows ::SetWindowPos(pNMHDR->hwndFrom, HWND_TOP, 0, 0, 0, 0,SWP_NOACTIVATE| SWP_NOSIZE|SWP_NOMOVE|SWP_NOOWNERZORDER); return TRUE; } return TRUE; } BOOL TFloorTable::OnInitDialog() { if (!WGroupBox::OnInitDialog()) return FALSE; m_grid.GetCol(2).SetRightButton(); if (!m_grid.Create(this, IDC_GRID)) return FALSE; InitToolbar(); InitGrid(); return TRUE; } void TFloorTable::OnSize(UINT nType,int cx,int cy) { WGroupBox::OnSize(nType,cx,cy); m_grid.MoveWindow(0, 28, cx, cy-28); m_grid.FitLastCol(); CRect rect; m_toolBar.GetWindowRect(rect); ScreenToClient(rect); rect.right = rect.left + cy; m_toolBar.MoveWindow(rect); } void TFloorTable::OnClickToolBar(UINT nID) { switch(nID) { case ID_BUTTON_SELECTPART: DoSelectPart(); break; case ID_SELECT_FILE: DoSelectFile(); break; case ID_BUILDING_MODEL: DoBuildingModel(); break; case ID_BUILDING_ELEV: DoBuildingElev(); break; case ID_BUILDING_SECT: DoBuildingSect(); break; case ID_CHECK_OPENING: DoCheckOpening(); break; case ID_OPENING_TABLE: DoOpeningTable(); break; default: break; } } void TFloorTable::InitToolbar() { CAcModuleResourceOverride vTmp; m_toolBar.Create(WS_VISIBLE | WS_CHILD | CCS_TOP | TBSTYLE_TOOLTIPS | CCS_ADJUSTABLE, CRect(0,0,0,0), this, IDR_TOOLBAR_FLOOR); const int nButtonNum = 7; int ButtonID[nButtonNum] = {ID_SELECT_FILE, ID_BUTTON_SELECTPART, ID_BUILDING_MODEL, ID_BUILDING_ELEV, ID_BUILDING_SECT, ID_CHECK_OPENING, ID_OPENING_TABLE}; TBBUTTON *pRTF_Button = new TBBUTTON[nButtonNum]; TBBUTTON *pIndex = pRTF_Button; for (int i=0; iiBitmap = i; pIndex->idCommand = ButtonID[i]; pIndex->fsStyle = TBSTYLE_BUTTON; pIndex->fsState = TBSTATE_ENABLED; pIndex++; } CSize size(16, 15); m_toolBar.SetButtonSize(size); m_toolBar.AddButtons(nButtonNum, pRTF_Button); delete[] pRTF_Button; pRTF_Button = new TBBUTTON; memset(pRTF_Button ,NULL, sizeof(TBBUTTON)); pRTF_Button->fsStyle = TBSTYLE_SEP; m_toolBar.InsertButton(2, pRTF_Button); delete pRTF_Button; m_toolBar.SetBitmapSize(size); m_toolBar.ModifyStyle(0, TBSTYLE_FLAT); m_toolBar.AddBitmap(7, IDR_TOOLBAR_FLOOR); // sg modify 100126,根据sr反馈,设备专业恢复楼层表显示,但要求屏蔽掉建筑立面、建筑剖面、门窗检查、门窗总表等命令 // 节能专业也要求屏蔽掉 //LH 2013-3-25 根据2014年加密需要水关键字8--14 暖6--15 电3--16 //if (g_nProductId==3 || g_nProductId==8 || g_nProductId==6 || g_nProductId==12) if (g_nProductId==kTELEC || g_nProductId==kTWT|| g_nProductId==kTHVAC|| g_nProductId==kTBEC) { m_toolBar.HideButton(ID_BUILDING_ELEV, TRUE); m_toolBar.HideButton(ID_BUILDING_SECT, TRUE); m_toolBar.HideButton(ID_CHECK_OPENING, TRUE); m_toolBar.HideButton(ID_OPENING_TABLE, TRUE); } } void TFloorTable::InitGrid() { m_pCurGroup = g_project.GetGroup(_T("楼层")); if (m_pCurGroup == NULL) { m_toolBar.EnableWindow(FALSE); m_grid.EnableWindow(FALSE); return; } m_grid.SetData(m_pCurGroup); } void TFloorTable::DoSelectFile() // 选择标准层图纸文件 { // add by whl on 070517 if (curDoc()==NULL) { AfxMessageBox(_T("请先打开一个图形!")); return; } CString szPath; g_project.GetFilePath(szPath); struct resbuf *result = acutNewRb(RTSTR); #if ADS> 15 if (acedGetFileNavDialog(_T("选择标准层图形文件"), szPath, _T("dwg"), _T(""), 256, &result) != RTNORM) return; #else if (acedGetFileD(_T("选择标准层图形文件"), szPath, _T("dwg"), 256, result) != RTNORM) return; #endif if (result == NULL || result->restype != RTSTR) return; CString szHeight = GetLHeight(result->resval.rstring); CString szFileName = g_project.GetDwgRelativeName(result->resval.rstring); acutRelRb(result); int nCur = m_grid.GetCurRowIndex(); if (!m_grid.IsValidRow(nCur)) { m_grid.AppendRow(); nCur = m_grid.GetRowNum()-1; m_grid.SetCurRowIndex(nCur); } WDGridRow &row = m_grid.GetRow(nCur); CString szLayerNo = row[0].GetText(); if (szLayerNo == _T("")) szLayerNo = m_grid.GetLayerNo(); row[0].SetText(szLayerNo); row[1].SetText(szHeight); row[2].SetText(szFileName); m_grid.OnDataChanged(); m_grid.Invalidate(); } void TFloorTable::DoSelectPart() // 框选楼层范围 { int bDwgTitled = 0; xg_getvar(_T("DWGTITLED"), &bDwgTitled); // 指出当前图形是否已命名 if (!bDwgTitled) { AfxMessageBox(_T("\n请先命名当前图!")); return; } acedPostCommand(_T("TSelectFloor\n")); return; XString sCmd = GetFullCmdName(_T("TSelectFloor")); // 选择“楼层” sCmd<<_T("\n"); g_projectBar.SendCommand(sCmd); } // 给表格控件中的“楼层框”传递数据 void TFloorTable::SelectPart(int nCur, XPoint ptMin, XPoint ptMax, XPoint ptBase) { if (!m_grid.IsValidRow(nCur)) { m_grid.AppendRow(); nCur = m_grid.GetRowNum() - 1; } int bDwgTitled = 0; xg_getvar(_T("DWGTITLED"), &bDwgTitled); // 指出当前图形是否已命名 if (!bDwgTitled) { adsout<<_T("\n请先命名当前图形文档!\n命令:"); return; } WDGridRow &row = m_grid.GetRow(nCur); // 获得表格中每行对应的数据类 TFloorGridData *pData = (TFloorGridData *)row.GetExtendData(); if (pData == NULL) { pData = new TFloorGridData; row.SetExtendData(pData); } // 获得楼层号 CString szLayerNo = m_grid.GetCell(nCur, 0).GetText(); if (szLayerNo == _T("")) { szLayerNo = m_grid.GetLayerNo(); m_grid.GetCell(nCur, 0).SetText(szLayerNo); pData->m_sLayerNo = m_grid.GetRow(nCur)[0].GetText(); } // 获取图纸名称 XString szFullName, szName; xg_getvar(_T("DWGPREFIX"), szFullName); // 存储图形文件的驱动器/目录前缀 xg_getvar(_T("DWGNAME"), szName); // 存储用户输入的图形名 szFullName << szName; CString szHeight = GetLHeight((const TCHAR*) szFullName); CString szFileName = g_project.GetDwgRelativeName((const TCHAR*)szFullName); pData->m_dHeight = _tstof(szHeight); pData->m_szName = szFileName; pData->m_iFlag = 1; pData->m_ptBase = ptBase; pData->m_ptMin = XPoint(min(ptMin.x, ptMax.x), min(ptMin.y, ptMax.y)); pData->m_ptMax = XPoint(max(ptMin.x, ptMax.x), max(ptMin.y, ptMax.y)); m_grid.ExtendDataToGrid(pData, nCur); m_grid.OnDataChanged(); m_grid.Invalidate(); adsout<<_T("\n成功定义楼层!\n命令:"); } void TFloorTable::DoBuildingModel() { acedPostCommand(_T("TGroupFloor\n")); return; XString sCmd = GetFullCmdName(_T("TGroupFloor")); // 三维组合 sCmd<<_T("\n"); g_projectBar.SendCommand(sCmd); } void TFloorTable::DoBuildingElev() { acedPostCommand(_T("TBudElev\n")); return; XString sCmd = GetFullCmdName(_T("TBudElev")); // 建筑立面 sCmd<<_T("\n"); g_projectBar.SendCommand(sCmd); } void TFloorTable::DoBuildingSect() { acedPostCommand(_T("TBudSect\n")); return; XString sCmd = GetFullCmdName(_T("TBudSect")); // 建筑剖面 sCmd<<_T("\n"); g_projectBar.SendCommand(sCmd); } void TFloorTable::DoCheckOpening() { acedPostCommand(_T("TValidOP\n")); return; XString sCmd = GetFullCmdName(_T("TValidOP")); // 门窗检查 sCmd<<_T("\n"); g_projectBar.SendCommand(sCmd); } void TFloorTable::DoOpeningTable() { acedPostCommand(_T("TPrjOP\n")); return; XString sCmd = GetFullCmdName(_T("TPrjOP")); // 门窗总表 sCmd<<_T("\n"); g_projectBar.SendCommand(sCmd); } // Command:TSelectFloor,选择“楼层”命令 void SelectFloor() { TFloorTable *pTable = (TFloorTable*)g_projectBar.FindGroupBox(_T("楼层")); if (pTable == NULL) { return; } int nCur = pTable->m_grid.GetCurRowIndex(); if (nCur < 0) // sg add 100202,增加程序的健壮性,发生错误及时停止 { return; } AsureWCS(); // 必须在Wcs下 XPoint ptBase, ptMin, ptMax; if (acedGetPoint(NULL, _T("\n选择第一个角点<取消>: "), ptMin) != RTNORM) { return; } if (acedGetCorner(ptMin, _T("\n另一个角点<取消>: "), ptMax) != RTNORM) { return; } if (acedGetPoint(NULL, _T("\n对齐点<取消>: "), ptBase) != RTNORM) { return; } pTable->SelectPart(nCur,ptMin,ptMax,ptBase); } /////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////// // TAttribute——属性 BEGIN_MESSAGE_MAP(TAttribute, WGroupBox) ON_WM_PAINT() ON_WM_SIZE() END_MESSAGE_MAP() void TAttribute::DoDataExchange(CDataExchange* pDX) { WGroupBox::DoDataExchange(pDX); DDX_Control(pDX, IDC_STATIC_PREVIEW, m_ctrlPreview); } void TAttribute::SetPreviewFile(const TCHAR* pszDwgfilename) { m_szFileName = pszDwgfilename; OnPaint(); } void TAttribute::OnPaint() { CPaintDC dc(this); if (!acdbDisplayPreviewFromDwg(m_szFileName, m_ctrlPreview.m_hWnd)) { CClientDC dc(&m_ctrlPreview); CRect rect; m_ctrlPreview.GetClientRect(rect); dc.FillSolidRect(rect, RGB(255,255,255)); //CPen pen(PS_SOLID, 1, RGB(0,0,0)),*pOldPen; //pOldPen = dc.SelectObject(&pen); //dc.Rectangle(rect); //dc.SelectObject(pOldPen); } } void TAttribute::OnSize(UINT nType, int cx, int cy) { WGroupBox::OnSize(nType, cx, cy); m_ctrlPreview.MoveWindow(0, 0, cx, cy); } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////