MainFrm.cpp
上传用户:netltd
上传日期:2013-02-12
资源大小:7234k
文件大小:44k
- // MainFrm.cpp : implementation of the CMainFrame class
- #include "stdafx.h"
- #include "MainFrm.h"
- #include "MiniCADView.h"
- #include "MyNewDlg.h"
- #include "LayerAttributeDlg.h"
- #include "DrawingAttribute.h"
- #include "ProjectAttributeDlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame
- IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)
- BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
- ON_COMMAND_EX(ID_VIEW_MYOPTIONBAR, OnBarCheck)
- ON_UPDATE_COMMAND_UI(ID_VIEW_MYOPTIONBAR, OnUpdateControlBarMenu)
- ON_COMMAND_EX(ID_VIEW_MYWORKBAR, OnBarCheck)
- ON_UPDATE_COMMAND_UI(ID_VIEW_MYWORKBAR, OnUpdateControlBarMenu)
- //{{AFX_MSG_MAP(CMainFrame)
- ON_WM_CREATE()
- ON_COMMAND(ID_VIEW_MYDRAWTOOLBAR, OnViewMydrawtoolbar)
- ON_UPDATE_COMMAND_UI(ID_VIEW_MYDRAWTOOLBAR, OnUpdateViewMydrawtoolbar)
- ON_COMMAND(ID_FILE_NEWF, OnFileNewF)
- ON_COMMAND(ID_FILE_OPENF, OnFileOpenF)
- ON_COMMAND(ID_FILE_NEWP, OnFileNewP)
- ON_COMMAND(ID_FILE_OPENP, OnFileOpenP)
- ON_COMMAND(ID_FILE_NEWFTOP, OnFileNewFToP)
- ON_UPDATE_COMMAND_UI(ID_FILE_NEWFTOP, OnUpdateFileNewFToP)
- ON_NOTIFY(TCN_SELCHANGE, IDC_TAB, OnSelchangeTab)
- ON_NOTIFY(NM_CLICK, IDC_TREE, OnClickTree)
- ON_NOTIFY(NM_DBLCLK, IDC_TREE, OnDblclkTree)
- ON_NOTIFY(NM_RCLICK, IDC_TREE, OnRclickTree)
- ON_COMMAND(ID_VIEW_FULL, OnViewFull)
- ON_UPDATE_COMMAND_UI(ID_VIEW_FULL, OnUpdateViewFull)
- ON_WM_GETMINMAXINFO()
- ON_COMMAND(ID_FILE_OPENFTOP, OnFileOpenFToP)
- ON_UPDATE_COMMAND_UI(ID_FILE_OPENFTOP, OnUpdateFileOpenFToP)
- ON_COMMAND(ID_FILE_SAVEP, OnFileSaveP)
- ON_WM_CLOSE()
- ON_COMMAND(ID_FILE_CLOSEP, OnFileCloseP)
- ON_COMMAND(ID_FILE_CLOSEF, OnFileCloseF)
- ON_COMMAND(ID_FILE_SAVEF, OnFileSaveF)
- ON_COMMAND(ID_FILE_SAVEF_AS, OnFileSaveFAs)
- ON_COMMAND(ID_FILE_SAVEALL, OnFileSaveall)
- ON_NOTIFY(TVN_DELETEITEM, IDC_TREE, OnDeleteitemTree)
- ON_COMMAND(ID_LAYER_HIDE, OnLayerHide)
- ON_UPDATE_COMMAND_UI(ID_LAYER_HIDE, OnUpdateLayerHide)
- ON_COMMAND(ID_LAYER_LOCK, OnLayerLock)
- ON_UPDATE_COMMAND_UI(ID_LAYER_LOCK, OnUpdateLayerLock)
- ON_COMMAND(ID_LAYER_SHOW, OnLayerShow)
- ON_UPDATE_COMMAND_UI(ID_LAYER_SHOW, OnUpdateLayerShow)
- ON_COMMAND(ID_LAYER_UNLOCK, OnLayerUnlock)
- ON_UPDATE_COMMAND_UI(ID_LAYER_UNLOCK, OnUpdateLayerUnlock)
- ON_COMMAND(ID_FORMAT_LAYER, OnFormatLayer)
- ON_COMMAND(ID_LAYER_DELETE, OnLayerDelete)
- ON_COMMAND(ID_LAYER_CURRENT, OnLayerCurrent)
- ON_COMMAND(ID_FILE_ADDLAYER, OnFileAddlayer)
- ON_COMMAND(ID_LAYER_ATTRIBUTE, OnLayerAttribute)
- ON_COMMAND(ID_FILE_FILEATTRIBUTE, OnFileFileattribute)
- ON_COMMAND(ID_FILE_PROJECTATTRIBUTE, OnFileProjectattribute)
- ON_COMMAND(ID_FILE_DELFFROMP, OnFileDelFfromP)
- //}}AFX_MSG_MAP
- ON_UPDATE_COMMAND_UI_RANGE(ID_FILE_FILELIST, ID_FILE_FILELIST + RECENTFILELIST_NUM - 1, OnUpdateFileFilelist)
- ON_COMMAND_RANGE(ID_FILE_PROJECTLIST, ID_FILE_PROJECTLIST + 3, OnFileProjectlist)
- ON_UPDATE_COMMAND_UI_RANGE(ID_FILE_PROJECTLIST, ID_FILE_PROJECTLIST + RECENTFILELIST_NUM - 1, OnUpdateFileProjectlist)
- // Global help commands
- ON_COMMAND(ID_HELP_FINDER, CMDIFrameWnd::OnHelpFinder)
- ON_COMMAND(ID_HELP, CMDIFrameWnd::OnHelp)
- ON_COMMAND(ID_CONTEXT_HELP, CMDIFrameWnd::OnContextHelp)
- ON_COMMAND(ID_DEFAULT_HELP, CMDIFrameWnd::OnHelpFinder)
- END_MESSAGE_MAP()
- static UINT indicators[] =
- {
- ID_SEPARATOR, // status line indicator
- ID_SEPARATOR,
- ID_SEPARATOR,
- ID_INDICATOR_CAPS,
- ID_INDICATOR_NUM,
- ID_INDICATOR_SCRL,
- };
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame construction/destruction
- CMainFrame::CMainFrame()
- {
- pApp = (CMiniCADApp*)AfxGetApp();
- m_pWndFullScreen = NULL;
- }
- CMainFrame::~CMainFrame()
- {
- }
- int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
- return -1;
-
- if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
- | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
- !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
- {
- TRACE0("Failed to create toolbarn");
- return -1;
- }
- m_wndToolBar.SetWindowText (_T("标准工具条"));
- m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
- EnableDocking(CBRS_ALIGN_ANY);
- DockControlBar(&m_wndToolBar);
- if (!m_wndStatusBar.Create(this) ||
- !m_wndStatusBar.SetIndicators(indicators,
- sizeof(indicators)/sizeof(UINT)))
- {
- TRACE0("Failed to create status barn");
- return -1;
- }
- m_wndStatusBar.SetPaneInfo(1, 0, SBPS_NORMAL, 100);
- m_wndStatusBar.SetPaneInfo(2, 0, SBPS_NORMAL, 100);
- if (!m_MyWorkBar.Create(_T("工作区"), this, CSize(170, 150), TRUE, ID_VIEW_MYWORKBAR))
- {
- TRACE0("Failed to create myworkbarn");
- return -1;
- }
- m_MyWorkBar.SetBarStyle(m_MyWorkBar.GetBarStyle() | CBRS_TOOLTIPS | CBRS_FLYBY |
- CBRS_SIZE_DYNAMIC);
- m_MyWorkBar.EnableDocking(CBRS_ALIGN_LEFT | CBRS_ALIGN_RIGHT);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_MyWorkBar, AFX_IDW_DOCKBAR_LEFT);
-
- //创建位于左侧的绘图工具条
- if (!m_MyDrawToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_LEFT
- | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
- !m_MyDrawToolBar.LoadToolBar(IDR_MYDRAWTOOLBAR))
- {
- TRACE0("Failed to create toolbarn");
- return -1;
- }
- //设置绘图工具条标题
- m_MyDrawToolBar.SetWindowText (_T("绘图工具条"));
- //允许工具条浮动
- m_MyDrawToolBar.EnableDocking(CBRS_ALIGN_LEFT | CBRS_ALIGN_RIGHT);
- EnableDocking(CBRS_ALIGN_ANY);
- DockControlBar(&m_MyDrawToolBar);
- //创建位于左侧的修改工具条
- if (!m_MyModifyToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_LEFT
- | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
- !m_MyModifyToolBar.LoadToolBar(IDR_MYMODIFYTOOLBAR))
- {
- TRACE0("Failed to create toolbarn");
- return -1;
- }
- //设置修改工具条标题
- m_MyModifyToolBar.SetWindowText (_T("修改工具条"));
- //允许工具条浮动
- m_MyModifyToolBar.EnableDocking(CBRS_ALIGN_LEFT | CBRS_ALIGN_RIGHT);
- EnableDocking(CBRS_ALIGN_ANY);
- DockControlBar(&m_MyModifyToolBar);
- if (!m_MyOptionBar.Create(this, IDD_MYOPTIONBAR, ID_VIEW_MYOPTIONBAR))
{
TRACE0("Failed to create dialog bar m_MyOptionBarn");
return -1;
}
m_MyOptionBar.EnableDocking(CBRS_ALIGN_TOP | CBRS_ALIGN_BOTTOM);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_MyOptionBar);
- //初始化选项条
- m_MyOptionBar.Initialize();
- return 0;
- }
- BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
- {
- if( !CMDIFrameWnd::PreCreateWindow(cs) )
- return FALSE;
- cs.style = WS_OVERLAPPED | WS_CAPTION | FWS_ADDTOTITLE
- | WS_THICKFRAME | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_MAXIMIZE;
- cs.style &= ~FWS_ADDTOTITLE;
- return TRUE;
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame diagnostics
- #ifdef _DEBUG
- void CMainFrame::AssertValid() const
- {
- CMDIFrameWnd::AssertValid();
- }
- void CMainFrame::Dump(CDumpContext& dc) const
- {
- CMDIFrameWnd::Dump(dc);
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame message handlers
- void CMainFrame::OnViewMydrawtoolbar(UINT nID)
- {
- BOOL bVisible=m_MyDrawToolBar.GetStyle() & WS_VISIBLE ;
- //显示或隐藏绘图工具条
- ShowControlBar(&m_MyDrawToolBar, !bVisible, FALSE);
- RecalcLayout();
- return ;
- }
- void CMainFrame::OnUpdateViewMydrawtoolbar(CCmdUI* pCmdUI)
- {
- //设置绘图工具条显示、隐藏标志
- pCmdUI->SetCheck((m_MyDrawToolBar.GetStyle() & WS_VISIBLE) != 0);
- }
- //////////////////////////////////////////////////////////////////////////////////////////////
- void CMainFrame::OnFileNewF()
- {
- CMyNewSheet m_NewSheet(_T("新建"), this, 0);
- m_NewSheet.DoModal();
- }
- void CMainFrame::OnFileOpenF()
- {
- if(pApp->CADInfo.IsEmpty == TRUE)
- {
- //pApp->CADInfo.KindofNew = NEW_NONE;
- //pApp->CADInfo.IsEmpty = FALSE;
- }
- }
- void CMainFrame::OnFileSaveF()
- {
- if(pApp->CADInfo.IsEmpty == TRUE)
- return;
- CChildFrame* pChildWnd = (CChildFrame*)this->MDIGetActive();
- CMiniCADDoc* pDoc = (CMiniCADDoc*)pChildWnd->GetActiveDocument();
- pDoc->SaveDocument();
- }
- void CMainFrame::OnFileSaveFAs()
- {
- if(pApp->CADInfo.IsEmpty == TRUE)
- return;
- CString Filter="图纸文件(*.DRAWING_POSTFIX)|*.DRAWING_POSTFIX|所有文件(*.*)|*.*||";
- CString PathName;
- CChildFrame* pChildWnd = (CChildFrame*)this->MDIGetActive();
- CMiniCADDoc* pDoc = (CMiniCADDoc*)pChildWnd->GetActiveDocument();
- CFileDialog SaveFileDlg(FALSE, 0, pDoc->FileInfo.m_FileName,
- OFN_HIDEREADONLY|OFN_FILEMUSTEXIST|OFN_LONGNAMES, (LPCTSTR)Filter);
- SaveFileDlg.m_ofn.lpstrTitle=_T("另存为");
- if(SaveFileDlg.DoModal() != IDOK)
- return;
- //更改文档的文件名及路径
- PathName = SaveFileDlg.GetPathName(); //取得文件名(包含路径)
- pDoc->FileInfo.m_FileName = SaveFileDlg.GetFileName(); //取得文件名
- pDoc->FileInfo.m_FilePath = PathName.Left(PathName.GetLength()
- - pDoc->FileInfo.m_FileName.GetLength() - 1);
- if(pApp->CADInfo.KindofNew == NEW_PROJECT)
- {
- CFileIndex * pFileIndex = pApp->ProjectInfo.FindFileIndex(pDoc->FileInfo.m_Name);
- pFileIndex->SetFileIndex(pDoc->FileInfo.m_Name, pDoc->FileInfo.m_FileName,
- pDoc->FileInfo.m_FilePath);
- }
- pDoc->SaveDocument();
- }
- //保存全部文档
- void CMainFrame::OnFileSaveall()
- {
- CMultiDocTemplate* pDocTemplate;
- CMiniCADDoc* pDoc;
- POSITION DocTemplatePosition;
- POSITION DocPosition;
- //获取文档模板
- DocTemplatePosition = pApp->GetFirstDocTemplatePosition();
- pDocTemplate = (CMultiDocTemplate*)pApp->GetNextDocTemplate(DocTemplatePosition);
- ASSERT(pDocTemplate != NULL);
- DocPosition = pDocTemplate->GetFirstDocPosition();
- while(DocPosition != NULL)
- {
- pDoc = (CMiniCADDoc*)pDocTemplate->GetNextDoc(DocPosition);
- pDoc->SaveDocument();
- }
- }
- ////////////////////////////////////////////////////////////////////////////////////////////
- void CMainFrame::OnFileNewP()
- {
- //如果已存在新建的项目、图纸或元件
- if(pApp->CADInfo.IsEmpty == FALSE)
- {
- if(MessageBox("已有项目存在,是否继续?", "提示",
- MB_OKCANCEL | MB_ICONWARNING) == 2)
- return;
- else
- {
- //关闭当前项目
- OnFileCloseP();
- }
- }
-
- //显示“新建”属性框
- CMyNewProjectDlg m_NewProjectDlg;
- if(m_NewProjectDlg.NewProject(&pApp->ProjectInfo) == FALSE)
- return;
- pApp->CADInfo.IsEmpty = FALSE;
- pApp->CADInfo.KindofNew = NEW_PROJECT;
- m_MyWorkBar.pTree->InsertProject(pApp->ProjectInfo.Name);
- m_MyWorkBar.pTree->ShowWindow(TRUE);
-
- //更改最近项目列表
- pApp->pRecentProjectList->Add((LPCTSTR)(pApp->ProjectInfo.FilePath + "\"
- + pApp->ProjectInfo.FileName));
- pApp->pRecentProjectList->WriteList();
- //刚刚创建新项目,自动显示“增加图纸”对话框
- OnFileNewFToP();
- }
- void CMainFrame::OnFileOpenP()
- {
- //如果已存在新建的项目、图纸或元件
- if(pApp->CADInfo.IsEmpty == FALSE)
- {
- if(MessageBox("已有项目存在,是否继续?", "提示",
- MB_OKCANCEL | MB_ICONWARNING) == 2)
- return;
- else
- {
- //关闭当前项目
- OnFileCloseP();
- }
- }
- CString Filter="项目文件(*.PROJECT_POSTFIX)|PROJECT_POSTFIX|所有文件(*.*)|*.*||";
- CString PathName;
- //实例化一个CFileDialog类
- CFileDialog OpenProjectDlg(TRUE,0,0,OFN_HIDEREADONLY|OFN_FILEMUSTEXIST|OFN_LONGNAMES,(LPCTSTR)Filter);
- OpenProjectDlg.m_ofn.lpstrTitle=_T("打开项目文件");
- if(OpenProjectDlg.DoModal() != IDOK)
- return;
- PathName = OpenProjectDlg.GetPathName(); //取得文件名(包含路径)
- //打开项目
- if(!OpenProject(PathName))
- return;
- pApp->CADInfo.IsEmpty = FALSE;
- pApp->CADInfo.KindofNew = NEW_PROJECT;
- pApp->ProjectInfo.FileName = OpenProjectDlg.GetFileName(); //取得文件名
- pApp->ProjectInfo.FilePath = PathName.Left(PathName.GetLength()
- - pApp->ProjectInfo.FileName.GetLength() - 1);
- pApp->CADInfo.ProjectPath = pApp->ProjectInfo.FilePath;
-
- //更改最近项目列表
- pApp->pRecentProjectList->Add((LPCTSTR)(pApp->ProjectInfo.FilePath + "\"
- + pApp->ProjectInfo.FileName));
- pApp->pRecentProjectList->WriteList();
- }
- void CMainFrame::OnFileNewFToP()
- {
- if(pApp->CADInfo.KindofNew != NEW_PROJECT)
- return;
- CMyAddFileDlg MyAddFileDlg;
- //如果增加图纸成功
- //通过CMiniCADApp的成员变量NewFileInfo来传递新建文档参数
- if(MyAddFileDlg.AddFile(&pApp->NewFileInfo))
- {
- pApp->OnFileNew();//该函数会调用CDocument::OnNewDocument()
-
- CChildFrame* pChildWnd = (CChildFrame*)this->MDIGetActive();
- CMiniCADDoc* pDoc = (CMiniCADDoc*)pChildWnd->GetActiveDocument();
-
-
- pApp->ProjectInfo.AddFileIndex(pDoc->FileInfo.m_Name, pDoc->FileInfo.m_FileName,
- pDoc->FileInfo.m_FilePath);
- HTREEITEM fileitem = m_MyWorkBar.pTree->InsertFile(pDoc->FileInfo.m_Name);
-
- //增加一个缺省图层
- pDoc->m_ManageFileLayer.AddLayer("基层", TRUE, FALSE);
- CFileLayer* pLayer = pDoc->m_ManageFileLayer.GetLayer("基层");
- //设置缺省图层为当前图层
- pDoc->m_ManageFileLayer.SetCurrentLayerName("基层");
- m_MyWorkBar.pTree->InsertLayer(fileitem, pLayer->GetName(), ICON_CURRENTLAYER);
- }
- }
- void CMainFrame::OnUpdateFileNewFToP(CCmdUI* pCmdUI)
- {
- //使能“增加图纸-新建”菜单命令
- if(pApp->CADInfo.IsEmpty == FALSE && pApp->CADInfo.KindofNew == NEW_PROJECT)
- pCmdUI->Enable(TRUE);
- else
- pCmdUI->Enable(FALSE);
- }
- void CMainFrame::OnFileOpenFToP()
- {
- if(pApp->CADInfo.KindofNew != NEW_PROJECT)
- return;
- pApp->OnFileOpen();
- CChildFrame* pChildWnd = (CChildFrame*)this->MDIGetActive();
- CMiniCADDoc* pDoc = (CMiniCADDoc*)pChildWnd->GetActiveDocument();
-
- pApp->ProjectInfo.AddFileIndex(pDoc->FileInfo.m_Name, pDoc->FileInfo.m_FileName,
- pDoc->FileInfo.m_FilePath);
- //插入图纸项
- HTREEITEM fileitem = m_MyWorkBar.pTree->InsertFile(pDoc->FileInfo.m_Name);
- //插入图层项
- for(int i = 0; i < (int)pDoc->m_ManageFileLayer.GetLayerNum(); i++)
- {
- CFileLayer* pLayer = pDoc->m_ManageFileLayer.GetLayer(i);
- if(pLayer->IsShow() && !pLayer->IsLocked())
- {
- if(pLayer->GetName() == pDoc->m_ManageFileLayer.GetCurrentLayerName())
- m_MyWorkBar.pTree->InsertLayer(fileitem, pLayer->GetName(), ICON_CURRENTLAYER);
- else
- m_MyWorkBar.pTree->InsertLayer(fileitem, pLayer->GetName(), ICON_LAYER);
- }
- if(pLayer->IsShow() && pLayer->IsLocked())
- {
- if(pLayer->GetName() == pDoc->m_ManageFileLayer.GetCurrentLayerName())
- m_MyWorkBar.pTree->InsertLayer(fileitem, pLayer->GetName(), ICON_CURRENTLOCKLAYER);
- else
- m_MyWorkBar.pTree->InsertLayer(fileitem, pLayer->GetName(), ICON_LOCKLAYER);
- }
- if(!pLayer->IsShow() && !pLayer->IsLocked())
- {
- if(pLayer->GetName() == pDoc->m_ManageFileLayer.GetCurrentLayerName())
- m_MyWorkBar.pTree->InsertLayer(fileitem, pLayer->GetName(), ICON_CURRENTHIDELAYER);
- else
- m_MyWorkBar.pTree->InsertLayer(fileitem, pLayer->GetName(), ICON_HIDELAYER);
- }
- if(!pLayer->IsShow() && pLayer->IsLocked())
- {
- if(pLayer->GetName() == pDoc->m_ManageFileLayer.GetCurrentLayerName())
- m_MyWorkBar.pTree->InsertLayer(fileitem, pLayer->GetName(), ICON_CURRENTLOCKHIDELAYER);
- else
- m_MyWorkBar.pTree->InsertLayer(fileitem, pLayer->GetName(), ICON_LOCKHIDELAYER);
- }
- }
- }
- void CMainFrame::OnUpdateFileOpenFToP(CCmdUI* pCmdUI)
- {
- if(pApp->CADInfo.IsEmpty == FALSE && pApp->CADInfo.KindofNew == NEW_PROJECT)
- pCmdUI->Enable(TRUE);
- else
- pCmdUI->Enable(FALSE);
- }
- //从项目中删除文件
- void CMainFrame::OnFileDelFfromP()
- {
-
- }
- void CMainFrame::OnFileSaveP()
- {
- CFile fp;
- CString PathName;
- PathName = pApp->ProjectInfo.FilePath + "\" + pApp->ProjectInfo.FileName;
- //打开一个文件,如果该文件不存在就创建一个,如果已存在就将文件长度变为0
- fp.Open(PathName, CFile::modeCreate | CFile::modeWrite);
- if(fp == 0)
- {
- MessageBox("打开项目文件错误",
- "错误", MB_OK | MB_ICONERROR);
- return;
- }
-
- CArchive ar(&fp, CArchive::store);
- pApp->ProjectInfo.Serialize(ar);
- //必须先关闭ar,再关闭fp
- ar.Close();
- fp.Close();
- }
- void CMainFrame::OnFileCloseP()
- {
- if(MessageBox("关闭前是否保存全部文件?", "提示", MB_OKCANCEL
- | MB_ICONWARNING) == 1)
- OnFileSaveall();//保存全部图纸
-
- if(MessageBox("关闭前是否保存项目?", "提示", MB_OKCANCEL
- | MB_ICONWARNING) == 1)
- OnFileSaveP();//保存当前项目
- CMultiDocTemplate* pDocTemplate;
- CMiniCADDoc* pDoc;
- POSITION DocTemplatePosition;
- POSITION DocPosition;
- pApp->CADInfo.IsEmpty = TRUE;
- pApp->CADInfo.KindofNew = NEW_NONE;
- m_MyWorkBar.pTree->DeleteAllItems();
- m_MyWorkBar.pTree->ShowWindow(FALSE);
- //获取文档模板
- DocTemplatePosition = pApp->GetFirstDocTemplatePosition();
- pDocTemplate = (CMultiDocTemplate*)pApp->GetNextDocTemplate(DocTemplatePosition);
- DocPosition = pDocTemplate->GetFirstDocPosition();
- for(;;)
- {
- if(DocPosition == NULL)
- return;
- //获取文档
- pDoc = (CMiniCADDoc*)pDocTemplate->GetNextDoc(DocPosition);
- ASSERT(pDoc != NULL);
- pDoc->OnCloseDocument();
- }
- }
- ////////////////////////////////////////////////////////////////////////
- void CMainFrame::OnFileCloseF()
- {
-
- }
- //////////////////////////////////////////////////////////////////////////////////////////////
- void CMainFrame::OnSelchangeTab(NMHDR* pNMHDR, LRESULT* pResult)
- {
- CTabCtrl* m_Tab =(CTabCtrl*)m_MyWorkBar.GetDlgItem(IDC_TAB);
- switch(m_Tab->GetCurSel())
- {
- case 0:
- {
- //隐藏列表框
- CListCtrl* pList = (CListCtrl*)m_MyWorkBar.GetDlgItem(IDC_LIST);
- pList->ShowWindow(FALSE);
- //当有项目存在时才显示树形框
- if(pApp->CADInfo.KindofNew == NEW_PROJECT)
- m_MyWorkBar.pTree->ShowWindow(TRUE);
- }
- break;
- case 1:
- {
- //显示列表框
- m_MyWorkBar.pTree->ShowWindow(FALSE);
-
- CListCtrl* pList =
- (CListCtrl*)m_MyWorkBar.GetDlgItem(IDC_LIST);
- pList->ShowWindow(TRUE);
- }
- break;
- }
- *pResult = 0;
- }
- void CMainFrame::OnClickTree(NMHDR* pNMHDR, LRESULT* pResult)
- {
-
- *pResult = 0;
- }
- void CMainFrame::OnDblclkTree(NMHDR* pNMHDR, LRESULT* pResult)
- {
- CString name; //子项名
- CString PathName;
- HTREEITEM item = m_MyWorkBar.pTree->GetSelectedItem();
- ASSERT(item != NULL);
- name = m_MyWorkBar.pTree->GetItemText(item);
- //获取选中项的绑定值
- DWORD data = m_MyWorkBar.pTree->GetItemData(item);
-
- switch(data)
- {
- case TREE_FILE_ITEM:
- CMultiDocTemplate* pDocTemplate;
- CMiniCADDoc* pDoc;
- CMiniCADView* pView;
- CChildFrame* pChildFrame;
- POSITION DocTemplatePosition;
- POSITION DocPosition;
- POSITION ViewPosition;
- //获取文档模板
- DocTemplatePosition = pApp->GetFirstDocTemplatePosition();
- pDocTemplate = (CMultiDocTemplate*)pApp->GetNextDocTemplate(DocTemplatePosition);
- DocPosition = pDocTemplate->GetFirstDocPosition();
- for(;;)
- {
- if(DocPosition == NULL)
- {
- //如果DocPosition == NULL,说明文档没有打开
- //注意如果文件不存在,在CScrollView创建时会出错,现在
- //还不知道预先处理错误的方法
- CFileIndex* pFileIndex = pApp->ProjectInfo.FindFileIndex(name);
- ASSERT(pFileIndex != NULL);
- PathName = pFileIndex->GetFilePath() + "\" + pFileIndex->GetFileName();
- //给要激活的文档序号赋值
- ASSERT(AfxGetApp()->OpenDocumentFile(PathName) != NULL);
- CChildFrame* pChildWnd = (CChildFrame*)this->MDIGetActive();
- CMiniCADDoc* pDoc = (CMiniCADDoc*)pChildWnd->GetActiveDocument();
-
- //使图层子项保持展开或收拢
- m_MyWorkBar.pTree->Expand(item, TVE_TOGGLE);
- *pResult = 0;
- return;
- }
- //获取文档
- pDoc = (CMiniCADDoc*)pDocTemplate->GetNextDoc(DocPosition);
- if(pDoc->FileInfo.m_Name == name)
- break;
- }
- //获取文档的视图
- ViewPosition = pDoc->GetFirstViewPosition();
- pView = (CMiniCADView*)pDoc->GetNextView(ViewPosition);
- //激活子窗口
- pChildFrame = (CChildFrame*)pView->GetParentFrame();
- pChildFrame->MDIActivate( );
- //使图层子项保持展开或收拢
- m_MyWorkBar.pTree->Expand(item, TVE_TOGGLE);
- break;
- case TREE_LAYER_ITEM:
- break;
- }
-
- *pResult = 0;
- }
- void CMainFrame::OnRclickTree(NMHDR* pNMHDR, LRESULT* pResult)
- {
- CPoint point;
- CRect rect;
- CPoint pt;
- CMenu menu;
- //获取当前鼠标位置
- GetCursorPos(&pt);
- UINT flag;
- m_MyWorkBar.pTree->ScreenToClient(&pt);
- //获取被点击的Item
- HTREEITEM item = m_MyWorkBar.pTree->HitTest(pt, &flag);
- if(item == NULL)
- return;
- //如果不是点击在项的图标或标题上
- if(flag != TVHT_ONITEMLABEL && flag != TVHT_ONITEMICON)
- return;
- m_MyWorkBar.pTree->SelectItem(item);
- m_MyWorkBar.pTree->GetItemRect(item, &rect, TRUE);
- m_MyWorkBar.pTree->ClientToScreen(rect);
- point.y = rect.top;
- point.x = rect.right;
- DWORD data = m_MyWorkBar.pTree->GetItemData(item);
- switch(data)
- {
- case TREE_PROJECT_ITEM:
- ASSERT(menu.LoadMenu(IDR_POPUP_PROJECT));
- break;
- case TREE_FILE_ITEM:
- ASSERT(menu.LoadMenu(IDR_POPUP_DRAWING));
- break;
- case TREE_LAYER_ITEM:
- {
- ASSERT(menu.LoadMenu(IDR_POPUP_LAYER));
- HTREEITEM fileitem = m_MyWorkBar.pTree->GetParentItem(item);
- CString filename = m_MyWorkBar.pTree->GetItemText(fileitem);
- CMiniCADDoc* pDoc = GetDocument(filename);
- ASSERT(pDoc != NULL);
- CString layername = m_MyWorkBar.pTree->GetItemText(item);
- CFileLayer* pLayer = pDoc->m_ManageFileLayer.GetLayer(layername);
- if(pLayer->IsShow())
- menu.DeleteMenu(ID_LAYER_SHOW, MF_BYCOMMAND);
- else
- menu.DeleteMenu(ID_LAYER_HIDE, MF_BYCOMMAND);
- if(pLayer->IsLocked())
- menu.DeleteMenu(ID_LAYER_LOCK, MF_BYCOMMAND);
- else
- menu.DeleteMenu(ID_LAYER_UNLOCK, MF_BYCOMMAND);
- if(pLayer->GetName() == pDoc->m_ManageFileLayer.GetCurrentLayerName())
- menu.DeleteMenu(ID_LAYER_CURRENT, MF_BYCOMMAND);
- break;
- }
- }
- CMenu* pPopup = menu.GetSubMenu(0);
- ASSERT(pPopup != NULL);
- CWnd* pWndPopupOwner = m_MyWorkBar.pTree->GetSafeOwner();
- while (pWndPopupOwner->GetStyle() & WS_CHILD)
- pWndPopupOwner = pWndPopupOwner->GetParent();
- pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y,
- pWndPopupOwner);
- menu.DestroyMenu();
- *pResult = 0;
- }
- //////////////////////////////////////////////////////////////////////////////////////////////
- void CMainFrame::OnViewFull()
- {
- if (m_pWndFullScreen != NULL)
- {
- LockWindowUpdate();
- m_pWndFullScreen->LockWindowUpdate();
- m_pWndFullScreen->ShowControlBar(&m_pWndFullScreen->m_MyCommandBar, TRUE, FALSE);
- ShowControlBar(&m_wndToolBar, TRUE, FALSE);
- ShowControlBar(&m_wndStatusBar, TRUE, FALSE);
- ShowControlBar(&m_MyOptionBar, TRUE, FALSE);
- ShowControlBar(&m_MyDrawToolBar, TRUE, FALSE);
- ShowControlBar(&m_MyModifyToolBar, TRUE, FALSE);
- ShowControlBar(&m_MyWorkBar, TRUE, FALSE);
-
- //恢复原来状态
- SetWindowPlacement(&m_MainOldPlace);
- m_pWndFullScreen->SetWindowPlacement(&m_ChildOldPlace);
- UnlockWindowUpdate();
- m_pWndFullScreen->UnlockWindowUpdate();
- m_pWndFullScreen = NULL;
- }
- else
- {
- m_pWndFullScreen = (CChildFrame*)MDIGetActive();
- if(m_pWndFullScreen == NULL)
- return;
-
- LockWindowUpdate();
- m_pWndFullScreen->LockWindowUpdate();
- //隐藏各种工具条,注意应先使用LockWindowUpdate()禁止更新屏幕
- //这样可以加快全屏显示的速度
- m_pWndFullScreen->ShowControlBar(&m_pWndFullScreen->m_MyCommandBar, FALSE, FALSE);
- ShowControlBar(&m_wndToolBar, FALSE, FALSE);
- ShowControlBar(&m_wndStatusBar,FALSE, FALSE);
- ShowControlBar(&m_MyOptionBar, FALSE, FALSE);
- ShowControlBar(&m_MyDrawToolBar, FALSE, FALSE);
- ShowControlBar(&m_MyModifyToolBar, FALSE, FALSE);
- ShowControlBar(&m_MyWorkBar, FALSE, FALSE);
-
- m_pWndFullScreen->GetWindowPlacement(&m_ChildOldPlace);
- GetWindowPlacement(&m_MainOldPlace);
-
- CRect rectDesktop, rectDesired;
- //获取全屏显示所需的客户区
- if (!::SystemParametersInfo(SPI_GETWORKAREA, 0, &rectDesktop, 0))
- ::GetWindowRect(::GetDesktopWindow(), &rectDesktop);
- else
- {
- rectDesktop.right = ::GetSystemMetrics(SM_CXSCREEN);
- rectDesktop.bottom = ::GetSystemMetrics(SM_CYSCREEN);
- rectDesktop.right -= rectDesktop.left;
- rectDesktop.bottom -= rectDesktop.top;
- rectDesktop.left = rectDesktop.left;
- rectDesktop.top = rectDesktop.top;
- }
- rectDesired = rectDesktop;
- //根据客户区获取框架的尺寸
- ::AdjustWindowRect(&rectDesktop, GetStyle(), TRUE);
-
- rectDesktop.bottom += ::GetSystemMetrics(SM_CYBORDER); // See "Ask Dr. GUI #10"
- m_FullScreenPlace = rectDesktop;
-
- WINDOWPLACEMENT wpNew = m_MainOldPlace;
- wpNew.showCmd = SW_SHOWNORMAL;
- wpNew.rcNormalPosition = rectDesktop;
- //设置主框架新的状态和位置
- SetWindowPlacement(&wpNew);
-
- wpNew.rcNormalPosition = rectDesired;
- ::AdjustWindowRect(&(wpNew.rcNormalPosition), m_pWndFullScreen->GetStyle(), FALSE);
- //设置子框架新的状态和位置
- m_pWndFullScreen->SetWindowPlacement(&wpNew);
- UnlockWindowUpdate();
- m_pWndFullScreen->UnlockWindowUpdate();
- }
- }
- void CMainFrame::OnUpdateViewFull(CCmdUI* pCmdUI)
- {
- if(MDIGetActive() == NULL)
- {
- pCmdUI->Enable(FALSE);
- return;
- }
- else
- {
- pCmdUI->Enable(TRUE);
- pCmdUI->SetCheck(m_pWndFullScreen != NULL);
- }
- }
- void CMainFrame::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
- {
- if (m_pWndFullScreen != NULL)
- {
- //全屏显示时重新设置主框架最大化时的尺寸
- lpMMI->ptMaxSize.y = m_FullScreenPlace.Height();
- lpMMI->ptMaxTrackSize.y = m_FullScreenPlace.Height();
- lpMMI->ptMaxSize.x = m_FullScreenPlace.Width();
- lpMMI->ptMaxTrackSize.x = m_FullScreenPlace.Width();
- }
- else
- CMDIFrameWnd::OnGetMinMaxInfo(lpMMI);
- }
- BOOL CMainFrame::GetFullScreenSize(CWnd* pWnd, POINT& pt)
- {
- if (m_pWndFullScreen != NULL && pWnd->m_hWnd == m_pWndFullScreen->m_hWnd)
- {
- pt.x = m_FullScreenPlace.Width();
- pt.y = m_FullScreenPlace.Height();
- }
- return (m_pWndFullScreen != NULL);
- }
- /////////////////////////////////////////////////////////////////////////////////////////////
- //实现“最近项目”的菜单功能
- void CMainFrame::OnFileProjectlist(UINT nID)
- {
- UINT index;
- CString PathName;
- index = nID - ID_FILE_PROJECTLIST;
- PathName = (*(pApp->pRecentProjectList))[index];
- //如果已存在新建的项目、图纸或元件
- if(pApp->CADInfo.IsEmpty == FALSE)
- {
- //如果PathName是当前打开的项目,则返回
- if(PathName == pApp->ProjectInfo.FilePath + "\" + pApp->ProjectInfo.FileName)
- return;
- if(MessageBox("已有项目存在,是否继续?", "提示",
- MB_OKCANCEL | MB_ICONWARNING) == 2)
- return;
- else
- {
- //关闭当前项目
- OnFileCloseP();
- }
- }
- if(!OpenProject(PathName))
- return;
- pApp->CADInfo.IsEmpty = FALSE;
- pApp->CADInfo.KindofNew = NEW_PROJECT;
- //获取项目文件名
- pApp->ProjectInfo.FileName = PathName.Right(PathName.GetLength() - PathName.ReverseFind('\')
- - 1);
- //获取项目文件路径
- pApp->ProjectInfo.FilePath = PathName.Left(PathName.ReverseFind('\'));
- pApp->CADInfo.ProjectPath = pApp->ProjectInfo.FilePath;
-
- //更改最近项目列表
- pApp->pRecentProjectList->Add((LPCTSTR)(pApp->ProjectInfo.FilePath + "\"
- + pApp->ProjectInfo.FileName));
- pApp->pRecentProjectList->WriteList();
- }
- void CMainFrame::OnUpdateFileProjectlist(CCmdUI* pCmdUI)
- {
- if(pCmdUI->m_nID == ID_FILE_PROJECTLIST)
- {
- pApp->pRecentProjectList->CRecentFileListEx::UpdateMenu(pCmdUI);
- }
- pCmdUI->Enable(TRUE);
- }
- void CMainFrame::OnFileFilelist(UINT nID)
- {
- }
- void CMainFrame::OnUpdateFileFilelist(CCmdUI* pCmdUI)
- {
- if(pCmdUI->m_nID == ID_FILE_FILELIST)
- {
- //注意此时应该用基类CRecentFileList的UpdateMenu(CCmdUI* pCmdUI)
- //这是由CMenu的特点决定的,“最近文件”菜单项是第二个Popup菜单项,
- //其子菜单的pCmdUI->mIndex为0,pCmdUI->pMenu指向子菜单
- pApp->pRecentFileList->UpdateMenu(pCmdUI);
- }
- pCmdUI->Enable(TRUE);
- }
- void CMainFrame::OnClose()
- {
- if(pApp->CADInfo.KindofNew == NEW_PROJECT)
- {
- if(MessageBox("是否要退出?", "提示", MB_OKCANCEL
- | MB_ICONWARNING) == 2)
- return;
- //如果按下“确定”(按下“取消”返回值为2)
- if(MessageBox("退出前是否保存全部文件?", "提示", MB_OKCANCEL
- | MB_ICONWARNING) == 1)
- OnFileSaveall();
-
- if(MessageBox("退出前是否保存项目?", "提示", MB_OKCANCEL
- | MB_ICONWARNING) == 1)
- OnFileSaveP();
- }
- CMDIFrameWnd::OnClose();
- }
-
- void CMainFrame::OnDeleteitemTree(NMHDR* pNMHDR, LRESULT* pResult)
- {
- NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
-
-
- *pResult = 0;
- }
- void CMainFrame::OnFormatLayer()
- {
- CChildFrame* pChildWnd = (CChildFrame*)this->MDIGetActive();
- CMiniCADDoc* pDoc = (CMiniCADDoc*)pChildWnd->GetActiveDocument();
- ASSERT_VALID(pDoc);
- CFileLayerDlg dlg;
- dlg.Create(pDoc->FileInfo.m_Name, &pDoc->m_ManageFileLayer);
-
- HTREEITEM fileitem = m_MyWorkBar.pTree->FindFileItem(pDoc->FileInfo.m_Name);
- ASSERT(fileitem != NULL);
- CString filename = m_MyWorkBar.pTree->GetItemText(fileitem);
- //删除图纸项下的全部图层项
- for(;;)
- {
- HTREEITEM layeritem = m_MyWorkBar.pTree->GetChildItem(fileitem);
- if(layeritem == NULL)
- break;
- m_MyWorkBar.pTree->DeleteItem(layeritem);
- }
-
- //重新插入图层项
- for(int i = 0; i < (int)pDoc->m_ManageFileLayer.GetLayerNum(); i++)
- {
- CFileLayer* pLayer = pDoc->m_ManageFileLayer.GetLayer(i);
- if(pLayer->IsShow() && !pLayer->IsLocked())
- {
- if(pLayer->GetName() == pDoc->m_ManageFileLayer.GetCurrentLayerName())
- m_MyWorkBar.pTree->InsertLayer(fileitem, pLayer->GetName(), ICON_CURRENTLAYER);
- else
- m_MyWorkBar.pTree->InsertLayer(fileitem, pLayer->GetName(), ICON_LAYER);
- }
- if(pLayer->IsShow() && pLayer->IsLocked())
- {
- if(pLayer->GetName() == pDoc->m_ManageFileLayer.GetCurrentLayerName())
- m_MyWorkBar.pTree->InsertLayer(fileitem, pLayer->GetName(), ICON_CURRENTLOCKLAYER);
- else
- m_MyWorkBar.pTree->InsertLayer(fileitem, pLayer->GetName(), ICON_LOCKLAYER);
- }
- if(!pLayer->IsShow() && !pLayer->IsLocked())
- {
- if(pLayer->GetName() == pDoc->m_ManageFileLayer.GetCurrentLayerName())
- m_MyWorkBar.pTree->InsertLayer(fileitem, pLayer->GetName(), ICON_CURRENTHIDELAYER);
- else
- m_MyWorkBar.pTree->InsertLayer(fileitem, pLayer->GetName(), ICON_HIDELAYER);
- }
- if(!pLayer->IsShow() && pLayer->IsLocked())
- {
- if(pLayer->GetName() == pDoc->m_ManageFileLayer.GetCurrentLayerName())
- m_MyWorkBar.pTree->InsertLayer(fileitem, pLayer->GetName(), ICON_CURRENTLOCKHIDELAYER);
- else
- m_MyWorkBar.pTree->InsertLayer(fileitem, pLayer->GetName(), ICON_LOCKHIDELAYER);
- }
- }
-
- }
- void CMainFrame::OnFileProjectattribute()
- {
- CProjectAttributeDlg dlg;
- dlg.DoModal();
- }
- void CMainFrame::OnFileFileattribute()
- {
- CDrawingAttributeDlg dlg;
- dlg.DoModal();
- }
- void CMainFrame::OnLayerDelete()
- {
- HTREEITEM layeritem = m_MyWorkBar.pTree->GetSelectedItem();
- DWORD data = m_MyWorkBar.pTree->GetItemData(layeritem);
- ASSERT(data == TREE_LAYER_ITEM);
- CString layername = m_MyWorkBar.pTree->GetItemText(layeritem);
- HTREEITEM fileitem = m_MyWorkBar.pTree->GetParentItem(layeritem);
- CString filename = m_MyWorkBar.pTree->GetItemText(fileitem);
- CMiniCADDoc* pDoc = GetDocument(filename);
- CFileLayer* pLayer = pDoc->m_ManageFileLayer.GetLayer(layername);
- //如果删除的层是当前层
- if(pLayer->GetName() == pDoc->m_ManageFileLayer.GetCurrentLayerName())
- //当前层为空
- pDoc->m_ManageFileLayer.SetCurrentLayerName("");
- //删除图层
- pDoc->m_ManageFileLayer.DelLayer(layername);
- m_MyWorkBar.pTree->DeleteItem(layeritem);
- }
- void CMainFrame::OnLayerCurrent()
- {
- CFileLayer* pLayer;
- HTREEITEM layeritem = m_MyWorkBar.pTree->GetSelectedItem();
- DWORD data = m_MyWorkBar.pTree->GetItemData(layeritem);
- ASSERT(data == TREE_LAYER_ITEM);
- CString layername = m_MyWorkBar.pTree->GetItemText(layeritem);
- HTREEITEM fileitem = m_MyWorkBar.pTree->GetParentItem(layeritem);
- CString filename = m_MyWorkBar.pTree->GetItemText(fileitem);
- CMiniCADDoc* pDoc = GetDocument(filename);
- CString CurrentLayerName = pDoc->m_ManageFileLayer.GetCurrentLayerName();
- if(CurrentLayerName != "")
- {
- HTREEITEM CurrentLayerItem = m_MyWorkBar.pTree->FindLayerItem(fileitem,
- CurrentLayerName);
- //如果原先有当前层, 则修改原先当前图层项的图标,
- pLayer = pDoc->m_ManageFileLayer.GetLayer(CurrentLayerName);
- ASSERT(pLayer != NULL);
- if(pLayer->IsShow() && !pLayer->IsLocked())
- m_MyWorkBar.pTree->SetItemImage(CurrentLayerItem, ICON_LAYER, ICON_LAYER);
- if(pLayer->IsShow() && pLayer->IsLocked())
- m_MyWorkBar.pTree->SetItemImage(CurrentLayerItem, ICON_LOCKLAYER, ICON_LOCKLAYER);
- if(!pLayer->IsShow() && !pLayer->IsLocked())
- m_MyWorkBar.pTree->SetItemImage(CurrentLayerItem, ICON_HIDELAYER, ICON_HIDELAYER);
- if(!pLayer->IsShow() && pLayer->IsLocked())
- m_MyWorkBar.pTree->SetItemImage(CurrentLayerItem, ICON_LOCKHIDELAYER, ICON_LOCKHIDELAYER);
- }
- //设置当前图层
- pDoc->m_ManageFileLayer.SetCurrentLayerName(layername);
- pLayer = pDoc->m_ManageFileLayer.GetLayer(layername);
- //修改现在的当前图层项的图标
- if(pLayer->IsShow() && !pLayer->IsLocked())
- m_MyWorkBar.pTree->SetItemImage(layeritem, ICON_CURRENTLAYER, ICON_CURRENTLAYER);
- if(pLayer->IsShow() && pLayer->IsLocked())
- m_MyWorkBar.pTree->SetItemImage(layeritem, ICON_CURRENTLOCKLAYER,
- ICON_CURRENTLOCKLAYER);
- if(!pLayer->IsShow() && !pLayer->IsLocked())
- m_MyWorkBar.pTree->SetItemImage(layeritem, ICON_CURRENTHIDELAYER,
- ICON_CURRENTHIDELAYER);
- if(!pLayer->IsShow() && pLayer->IsLocked())
- m_MyWorkBar.pTree->SetItemImage(layeritem, ICON_CURRENTLOCKHIDELAYER,
- ICON_CURRENTLOCKHIDELAYER);
- if(!pLayer->IsShow() || pLayer->IsLocked())
- //如果当前图层被隐藏或被锁定,当前命令为NO_COMMAND
- pDoc->CurrentCommand = NO_COMMAND;
- }
- void CMainFrame::OnLayerHide()
- {
- HTREEITEM layeritem = m_MyWorkBar.pTree->GetSelectedItem();
- DWORD data = m_MyWorkBar.pTree->GetItemData(layeritem);
- ASSERT(data == TREE_LAYER_ITEM);
- CString layername = m_MyWorkBar.pTree->GetItemText(layeritem);
- HTREEITEM fileitem = m_MyWorkBar.pTree->GetParentItem(layeritem);
- CString filename = m_MyWorkBar.pTree->GetItemText(fileitem);
- CMiniCADDoc* pDoc = GetDocument(filename);
- CFileLayer* pLayer = pDoc->m_ManageFileLayer.GetLayer(layername);
- pLayer->SetShow(FALSE);
- //修改图标
- if(pLayer->IsLocked())
- {
- if(pLayer->GetName() == pDoc->m_ManageFileLayer.GetCurrentLayerName())
- m_MyWorkBar.pTree->SetItemImage(layeritem, ICON_CURRENTLOCKHIDELAYER, ICON_CURRENTLOCKHIDELAYER);
- else
- m_MyWorkBar.pTree->SetItemImage(layeritem, ICON_LOCKHIDELAYER, ICON_LOCKHIDELAYER);
- }
- else
- {
- if(pLayer->GetName() == pDoc->m_ManageFileLayer.GetCurrentLayerName())
- {
- m_MyWorkBar.pTree->SetItemImage(layeritem, ICON_CURRENTHIDELAYER, ICON_CURRENTHIDELAYER);
- //如果当前图层被隐藏,当前命令为NO_COMMAND
- pDoc->CurrentCommand = NO_COMMAND;
- }
- else
- m_MyWorkBar.pTree->SetItemImage(layeritem, ICON_HIDELAYER, ICON_HIDELAYER);
- }
- //更新视
- POSITION pos = pDoc->GetFirstViewPosition();
- CMiniCADView* pView = (CMiniCADView*)pDoc->GetNextView(pos);
- pView->Invalidate();
- }
- void CMainFrame::OnUpdateLayerHide(CCmdUI* pCmdUI)
- {
-
- }
- void CMainFrame::OnLayerShow()
- {
- HTREEITEM layeritem = m_MyWorkBar.pTree->GetSelectedItem();
- DWORD data = m_MyWorkBar.pTree->GetItemData(layeritem);
- ASSERT(data == TREE_LAYER_ITEM);
- CString layername = m_MyWorkBar.pTree->GetItemText(layeritem);
- HTREEITEM fileitem = m_MyWorkBar.pTree->GetParentItem(layeritem);
- CString filename = m_MyWorkBar.pTree->GetItemText(fileitem);
- CMiniCADDoc* pDoc = GetDocument(filename);
- CFileLayer* pLayer = pDoc->m_ManageFileLayer.GetLayer(layername);
- pLayer->SetShow(TRUE);
- //修改图标
- if(pLayer->IsLocked())
- {
- if(pLayer->GetName() == pDoc->m_ManageFileLayer.GetCurrentLayerName())
- m_MyWorkBar.pTree->SetItemImage(layeritem, ICON_CURRENTLOCKLAYER, ICON_CURRENTLOCKLAYER);
- else
- m_MyWorkBar.pTree->SetItemImage(layeritem, ICON_LOCKLAYER, ICON_LOCKLAYER);
- }
- else
- {
- if(pLayer->GetName() == pDoc->m_ManageFileLayer.GetCurrentLayerName())
- m_MyWorkBar.pTree->SetItemImage(layeritem, ICON_CURRENTLAYER, ICON_CURRENTLAYER);
- else
- m_MyWorkBar.pTree->SetItemImage(layeritem, ICON_LAYER, ICON_LAYER);
- }
- //更新视
- POSITION pos = pDoc->GetFirstViewPosition();
- CMiniCADView* pView = (CMiniCADView*)pDoc->GetNextView(pos);
- pView->Invalidate();
- }
- void CMainFrame::OnUpdateLayerShow(CCmdUI* pCmdUI)
- {
-
- }
- void CMainFrame::OnLayerLock()
- {
- HTREEITEM layeritem = m_MyWorkBar.pTree->GetSelectedItem();
- DWORD data = m_MyWorkBar.pTree->GetItemData(layeritem);
- ASSERT(data == TREE_LAYER_ITEM);
- CString layername = m_MyWorkBar.pTree->GetItemText(layeritem);
- HTREEITEM fileitem = m_MyWorkBar.pTree->GetParentItem(layeritem);
- CString filename = m_MyWorkBar.pTree->GetItemText(fileitem);
- CMiniCADDoc* pDoc = GetDocument(filename);
- CFileLayer* pLayer = pDoc->m_ManageFileLayer.GetLayer(layername);
- pLayer->SetLocked(TRUE);
- //修改图标
- if(pLayer->IsShow())
- {
- if(pLayer->GetName() == pDoc->m_ManageFileLayer.GetCurrentLayerName())
- {
- m_MyWorkBar.pTree->SetItemImage(layeritem, ICON_CURRENTLOCKLAYER, ICON_CURRENTLOCKLAYER);
- //如果当前图层被锁定,当前命令为NO_COMMAND
- pDoc->CurrentCommand = NO_COMMAND;
- }
- else
- m_MyWorkBar.pTree->SetItemImage(layeritem, ICON_LOCKLAYER, ICON_LOCKLAYER);
- }
- else
- {
- if(pLayer->GetName() == pDoc->m_ManageFileLayer.GetCurrentLayerName())
- m_MyWorkBar.pTree->SetItemImage(layeritem, ICON_CURRENTLOCKHIDELAYER, ICON_CURRENTLOCKHIDELAYER);
- else
- m_MyWorkBar.pTree->SetItemImage(layeritem, ICON_LOCKHIDELAYER, ICON_LOCKHIDELAYER);
- }
-
- }
- void CMainFrame::OnUpdateLayerLock(CCmdUI* pCmdUI)
- {
-
- }
- void CMainFrame::OnLayerUnlock()
- {
- HTREEITEM layeritem = m_MyWorkBar.pTree->GetSelectedItem();
- DWORD data = m_MyWorkBar.pTree->GetItemData(layeritem);
- ASSERT(data == TREE_LAYER_ITEM);
- CString layername = m_MyWorkBar.pTree->GetItemText(layeritem);
- HTREEITEM fileitem = m_MyWorkBar.pTree->GetParentItem(layeritem);
- CString filename = m_MyWorkBar.pTree->GetItemText(fileitem);
- CMiniCADDoc* pDoc = GetDocument(filename);
- CFileLayer* pLayer = pDoc->m_ManageFileLayer.GetLayer(layername);
- pLayer->SetLocked(FALSE);
- //修改图标
- if(pLayer->IsShow())
- {
- if(pLayer->GetName() == pDoc->m_ManageFileLayer.GetCurrentLayerName())
- m_MyWorkBar.pTree->SetItemImage(layeritem, ICON_CURRENTLAYER, ICON_CURRENTLAYER);
- else
- m_MyWorkBar.pTree->SetItemImage(layeritem, ICON_LAYER, ICON_LAYER);
- }
- else
- {
- if(pLayer->GetName() == pDoc->m_ManageFileLayer.GetCurrentLayerName())
- m_MyWorkBar.pTree->SetItemImage(layeritem, ICON_CURRENTHIDELAYER, ICON_CURRENTHIDELAYER);
- else
- m_MyWorkBar.pTree->SetItemImage(layeritem, ICON_HIDELAYER, ICON_HIDELAYER);
- }
- }
- void CMainFrame::OnUpdateLayerUnlock(CCmdUI* pCmdUI)
- {
-
- }
- void CMainFrame::OnLayerAttribute()
- {
- HTREEITEM layeritem = m_MyWorkBar.pTree->GetSelectedItem();
- DWORD data = m_MyWorkBar.pTree->GetItemData(layeritem);
- ASSERT(data == TREE_LAYER_ITEM);
- CString layername = m_MyWorkBar.pTree->GetItemText(layeritem);
- HTREEITEM fileitem = m_MyWorkBar.pTree->GetParentItem(layeritem);
- CString filename = m_MyWorkBar.pTree->GetItemText(fileitem);
- CMiniCADDoc* pDoc = GetDocument(filename);
-
- BOOL flag;
- do
- {
- flag = TRUE;
- CLayerAttributeDlg dlg;
- layername = dlg.Show(layername);
- HTREEITEM ChildItem = m_MyWorkBar.pTree->GetChildItem(fileitem);
- for(;;)
- {
- if(ChildItem == NULL)
- break;
- if(ChildItem != layeritem)
- {
- if(layername == m_MyWorkBar.pTree->GetItemText(ChildItem))
- {
- flag = FALSE;
- MessageBox("图层名不能重复", "错误", MB_OK | MB_ICONERROR);
- break;
- }
- }
- ChildItem = m_MyWorkBar.pTree->GetNextSiblingItem(ChildItem);
- }
- }
- while(flag == FALSE);
- m_MyWorkBar.pTree->SetItemText(layeritem, layername);
- }
- void CMainFrame::OnFileAddlayer()
- {
- HTREEITEM fileitem = m_MyWorkBar.pTree->GetSelectedItem();
- DWORD data = m_MyWorkBar.pTree->GetItemData(fileitem);
- ASSERT(data == TREE_FILE_ITEM);
- CString filename = m_MyWorkBar.pTree->GetItemText(fileitem);
-
- HTREEITEM layeritem = m_MyWorkBar.pTree->InsertLayer(fileitem, "基层", ICON_LAYER);
- m_MyWorkBar.pTree->SelectItem(layeritem);
- OnLayerAttribute();
- CString layername = m_MyWorkBar.pTree->GetItemText(layeritem);
- CMiniCADDoc* pDoc = GetDocument(filename);
- pDoc->m_ManageFileLayer.AddLayer(layername, TRUE, FALSE);
- }
- //////////////////////////////////////////////////////////////////////////////////////////
- //
- BOOL CMainFrame::OpenProject(CString PathName)
- {
- int index;
- CFile fp;
- fp.Open(PathName, CFile::modeCreate | CFile::modeNoTruncate
- | CFile::modeRead);
- if(fp == 0)
- {
- MessageBox("打开项目文件错误",
- "错误", MB_OK | MB_ICONERROR);
- return FALSE;
- }
-
- CArchive ar(&fp, CArchive::load);
- pApp->ProjectInfo.Serialize(ar);
- //显示树形控件,插入根项
- m_MyWorkBar.pTree->InsertProject(pApp->ProjectInfo.Name);
- m_MyWorkBar.pTree->ShowWindow(TRUE);
- //项目文档数置0,如果打开文档成功,项目文档数中增加1
- for(index = 0; index < pApp->ProjectInfo.GetFileIndexNum(); index++)
- {
- //注意如果文件不存在,在CScrollView创建时会出错,现在
- //还不知道预先处理错误的方法
- CFileIndex* pFileIndex = pApp->ProjectInfo.GetFileIndex(index);
- PathName = pFileIndex->GetFilePath() + "\" + pFileIndex->GetFileName();
- //打开图纸文件
- ASSERT(pApp->OpenDocumentFile(PathName) != NULL);
- CChildFrame* pChildWnd = (CChildFrame*)this->MDIGetActive();
- CMiniCADDoc* pDoc = (CMiniCADDoc*)pChildWnd->GetActiveDocument();
- //插入图纸项
- HTREEITEM fileitem = m_MyWorkBar.pTree->InsertFile(pDoc->FileInfo.m_Name);
-
- //插入图层项
- for(int i = 0; i < (int)pDoc->m_ManageFileLayer.GetLayerNum(); i++)
- {
- CFileLayer* pLayer = pDoc->m_ManageFileLayer.GetLayer(i);
- if(pLayer->IsShow() && !pLayer->IsLocked())
- {
- if(pLayer->GetName() == pDoc->m_ManageFileLayer.GetCurrentLayerName())
- m_MyWorkBar.pTree->InsertLayer(fileitem, pLayer->GetName(), ICON_CURRENTLAYER);
- else
- m_MyWorkBar.pTree->InsertLayer(fileitem, pLayer->GetName(), ICON_LAYER);
- }
- if(pLayer->IsShow() && pLayer->IsLocked())
- {
- if(pLayer->GetName() == pDoc->m_ManageFileLayer.GetCurrentLayerName())
- m_MyWorkBar.pTree->InsertLayer(fileitem, pLayer->GetName(), ICON_CURRENTLOCKLAYER);
- else
- m_MyWorkBar.pTree->InsertLayer(fileitem, pLayer->GetName(), ICON_LOCKLAYER);
- }
- if(!pLayer->IsShow() && !pLayer->IsLocked())
- {
- if(pLayer->GetName() == pDoc->m_ManageFileLayer.GetCurrentLayerName())
- m_MyWorkBar.pTree->InsertLayer(fileitem, pLayer->GetName(), ICON_CURRENTHIDELAYER);
- else
- m_MyWorkBar.pTree->InsertLayer(fileitem, pLayer->GetName(), ICON_HIDELAYER);
- }
- if(!pLayer->IsShow() && pLayer->IsLocked())
- {
- if(pLayer->GetName() == pDoc->m_ManageFileLayer.GetCurrentLayerName())
- m_MyWorkBar.pTree->InsertLayer(fileitem, pLayer->GetName(), ICON_CURRENTLOCKHIDELAYER);
- else
- m_MyWorkBar.pTree->InsertLayer(fileitem, pLayer->GetName(), ICON_LOCKHIDELAYER);
- }
- }
- }
- //关闭文件
- fp.Close();
- return TRUE;
- }
- CMiniCADDoc* CMainFrame::GetDocument(CString filename)
- {
- CMultiDocTemplate* pDocTemplate;
- CMiniCADDoc* pDoc;
- POSITION DocTemplatePosition;
- POSITION DocPosition;
- //获取文档模板
- DocTemplatePosition = pApp->GetFirstDocTemplatePosition();
- pDocTemplate = (CMultiDocTemplate*)pApp->GetNextDocTemplate(DocTemplatePosition);
- ASSERT(pDocTemplate != NULL);
- DocPosition = pDocTemplate->GetFirstDocPosition();
- while(DocPosition != NULL)
- {
- pDoc = (CMiniCADDoc*)pDocTemplate->GetNextDoc(DocPosition);
- if(filename == pDoc->FileInfo.m_Name)
- return pDoc;
- }
- return NULL;
- }