MainFrm.cpp
上传用户:netltd
上传日期:2013-02-12
资源大小:7234k
文件大小:44k
源码类别:

绘图程序

开发平台:

Visual C++

  1. // MainFrm.cpp : implementation of the CMainFrame class
  2. #include "stdafx.h"
  3. #include "MainFrm.h"
  4. #include "MiniCADView.h"
  5. #include "MyNewDlg.h"
  6. #include "LayerAttributeDlg.h"
  7. #include "DrawingAttribute.h"
  8. #include "ProjectAttributeDlg.h"
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #undef THIS_FILE
  12. static char THIS_FILE[] = __FILE__;
  13. #endif
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CMainFrame
  16. IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)
  17. BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
  18.     ON_COMMAND_EX(ID_VIEW_MYOPTIONBAR, OnBarCheck)
  19. ON_UPDATE_COMMAND_UI(ID_VIEW_MYOPTIONBAR, OnUpdateControlBarMenu)
  20. ON_COMMAND_EX(ID_VIEW_MYWORKBAR, OnBarCheck)
  21. ON_UPDATE_COMMAND_UI(ID_VIEW_MYWORKBAR, OnUpdateControlBarMenu)
  22. //{{AFX_MSG_MAP(CMainFrame)
  23. ON_WM_CREATE()
  24. ON_COMMAND(ID_VIEW_MYDRAWTOOLBAR, OnViewMydrawtoolbar)
  25. ON_UPDATE_COMMAND_UI(ID_VIEW_MYDRAWTOOLBAR, OnUpdateViewMydrawtoolbar)
  26. ON_COMMAND(ID_FILE_NEWF, OnFileNewF)
  27. ON_COMMAND(ID_FILE_OPENF, OnFileOpenF)
  28. ON_COMMAND(ID_FILE_NEWP, OnFileNewP)
  29. ON_COMMAND(ID_FILE_OPENP, OnFileOpenP)
  30. ON_COMMAND(ID_FILE_NEWFTOP, OnFileNewFToP)
  31. ON_UPDATE_COMMAND_UI(ID_FILE_NEWFTOP, OnUpdateFileNewFToP)
  32. ON_NOTIFY(TCN_SELCHANGE, IDC_TAB, OnSelchangeTab)
  33. ON_NOTIFY(NM_CLICK, IDC_TREE, OnClickTree)
  34. ON_NOTIFY(NM_DBLCLK, IDC_TREE, OnDblclkTree)
  35. ON_NOTIFY(NM_RCLICK, IDC_TREE, OnRclickTree)
  36. ON_COMMAND(ID_VIEW_FULL, OnViewFull)
  37. ON_UPDATE_COMMAND_UI(ID_VIEW_FULL, OnUpdateViewFull)
  38. ON_WM_GETMINMAXINFO()
  39. ON_COMMAND(ID_FILE_OPENFTOP, OnFileOpenFToP)
  40. ON_UPDATE_COMMAND_UI(ID_FILE_OPENFTOP, OnUpdateFileOpenFToP)
  41. ON_COMMAND(ID_FILE_SAVEP, OnFileSaveP)
  42. ON_WM_CLOSE()
  43. ON_COMMAND(ID_FILE_CLOSEP, OnFileCloseP)
  44. ON_COMMAND(ID_FILE_CLOSEF, OnFileCloseF)
  45. ON_COMMAND(ID_FILE_SAVEF, OnFileSaveF)
  46. ON_COMMAND(ID_FILE_SAVEF_AS, OnFileSaveFAs)
  47. ON_COMMAND(ID_FILE_SAVEALL, OnFileSaveall)
  48. ON_NOTIFY(TVN_DELETEITEM, IDC_TREE, OnDeleteitemTree)
  49. ON_COMMAND(ID_LAYER_HIDE, OnLayerHide)
  50. ON_UPDATE_COMMAND_UI(ID_LAYER_HIDE, OnUpdateLayerHide)
  51. ON_COMMAND(ID_LAYER_LOCK, OnLayerLock)
  52. ON_UPDATE_COMMAND_UI(ID_LAYER_LOCK, OnUpdateLayerLock)
  53. ON_COMMAND(ID_LAYER_SHOW, OnLayerShow)
  54. ON_UPDATE_COMMAND_UI(ID_LAYER_SHOW, OnUpdateLayerShow)
  55. ON_COMMAND(ID_LAYER_UNLOCK, OnLayerUnlock)
  56. ON_UPDATE_COMMAND_UI(ID_LAYER_UNLOCK, OnUpdateLayerUnlock)
  57. ON_COMMAND(ID_FORMAT_LAYER, OnFormatLayer)
  58. ON_COMMAND(ID_LAYER_DELETE, OnLayerDelete)
  59. ON_COMMAND(ID_LAYER_CURRENT, OnLayerCurrent)
  60. ON_COMMAND(ID_FILE_ADDLAYER, OnFileAddlayer)
  61. ON_COMMAND(ID_LAYER_ATTRIBUTE, OnLayerAttribute)
  62. ON_COMMAND(ID_FILE_FILEATTRIBUTE, OnFileFileattribute)
  63. ON_COMMAND(ID_FILE_PROJECTATTRIBUTE, OnFileProjectattribute)
  64. ON_COMMAND(ID_FILE_DELFFROMP, OnFileDelFfromP)
  65. //}}AFX_MSG_MAP
  66. ON_UPDATE_COMMAND_UI_RANGE(ID_FILE_FILELIST, ID_FILE_FILELIST + RECENTFILELIST_NUM - 1, OnUpdateFileFilelist)
  67. ON_COMMAND_RANGE(ID_FILE_PROJECTLIST, ID_FILE_PROJECTLIST + 3, OnFileProjectlist)
  68. ON_UPDATE_COMMAND_UI_RANGE(ID_FILE_PROJECTLIST, ID_FILE_PROJECTLIST + RECENTFILELIST_NUM - 1, OnUpdateFileProjectlist)
  69. // Global help commands
  70. ON_COMMAND(ID_HELP_FINDER, CMDIFrameWnd::OnHelpFinder)
  71. ON_COMMAND(ID_HELP, CMDIFrameWnd::OnHelp)
  72. ON_COMMAND(ID_CONTEXT_HELP, CMDIFrameWnd::OnContextHelp)
  73. ON_COMMAND(ID_DEFAULT_HELP, CMDIFrameWnd::OnHelpFinder)
  74. END_MESSAGE_MAP()
  75. static UINT indicators[] =
  76. {
  77. ID_SEPARATOR, // status line indicator
  78. ID_SEPARATOR,
  79. ID_SEPARATOR,
  80. ID_INDICATOR_CAPS,
  81. ID_INDICATOR_NUM,
  82. ID_INDICATOR_SCRL,
  83. };
  84. /////////////////////////////////////////////////////////////////////////////
  85. // CMainFrame construction/destruction
  86. CMainFrame::CMainFrame()
  87. {
  88. pApp = (CMiniCADApp*)AfxGetApp();
  89. m_pWndFullScreen = NULL;
  90. }
  91. CMainFrame::~CMainFrame()
  92. {
  93. }
  94. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  95. {
  96. if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
  97. return -1;
  98. if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
  99. | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
  100. !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
  101. {
  102. TRACE0("Failed to create toolbarn");
  103. return -1;      
  104. }
  105. m_wndToolBar.SetWindowText (_T("标准工具条"));
  106. m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
  107. EnableDocking(CBRS_ALIGN_ANY);
  108. DockControlBar(&m_wndToolBar);
  109. if (!m_wndStatusBar.Create(this) ||
  110. !m_wndStatusBar.SetIndicators(indicators,
  111.   sizeof(indicators)/sizeof(UINT)))
  112. {
  113. TRACE0("Failed to create status barn");
  114. return -1;      
  115. }
  116.     m_wndStatusBar.SetPaneInfo(1, 0, SBPS_NORMAL, 100);
  117. m_wndStatusBar.SetPaneInfo(2, 0, SBPS_NORMAL, 100);
  118. if (!m_MyWorkBar.Create(_T("工作区"), this, CSize(170, 150), TRUE, ID_VIEW_MYWORKBAR))
  119. {
  120. TRACE0("Failed to create myworkbarn");
  121.     return -1;      
  122. }
  123.     m_MyWorkBar.SetBarStyle(m_MyWorkBar.GetBarStyle() | CBRS_TOOLTIPS | CBRS_FLYBY | 
  124.                         CBRS_SIZE_DYNAMIC);
  125. m_MyWorkBar.EnableDocking(CBRS_ALIGN_LEFT | CBRS_ALIGN_RIGHT); EnableDocking(CBRS_ALIGN_ANY); DockControlBar(&m_MyWorkBar, AFX_IDW_DOCKBAR_LEFT);
  126.    
  127.     //创建位于左侧的绘图工具条
  128. if (!m_MyDrawToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_LEFT
  129.     | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
  130.     !m_MyDrawToolBar.LoadToolBar(IDR_MYDRAWTOOLBAR))
  131. {
  132.     TRACE0("Failed to create toolbarn");
  133. return -1;     
  134. }
  135.     //设置绘图工具条标题
  136. m_MyDrawToolBar.SetWindowText (_T("绘图工具条"));
  137. //允许工具条浮动
  138. m_MyDrawToolBar.EnableDocking(CBRS_ALIGN_LEFT | CBRS_ALIGN_RIGHT);
  139. EnableDocking(CBRS_ALIGN_ANY);
  140. DockControlBar(&m_MyDrawToolBar);
  141. //创建位于左侧的修改工具条
  142. if (!m_MyModifyToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_LEFT
  143.     | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
  144.     !m_MyModifyToolBar.LoadToolBar(IDR_MYMODIFYTOOLBAR))
  145. {
  146.     TRACE0("Failed to create toolbarn");
  147. return -1;     
  148. }
  149.     //设置修改工具条标题
  150. m_MyModifyToolBar.SetWindowText (_T("修改工具条"));
  151. //允许工具条浮动
  152. m_MyModifyToolBar.EnableDocking(CBRS_ALIGN_LEFT | CBRS_ALIGN_RIGHT);
  153. EnableDocking(CBRS_ALIGN_ANY);
  154. DockControlBar(&m_MyModifyToolBar);
  155. 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);
  156. //初始化选项条
  157. m_MyOptionBar.Initialize();
  158. return 0;
  159. }
  160. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  161. {
  162. if( !CMDIFrameWnd::PreCreateWindow(cs) )
  163. return FALSE;
  164. cs.style = WS_OVERLAPPED | WS_CAPTION | FWS_ADDTOTITLE
  165. | WS_THICKFRAME | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_MAXIMIZE;
  166. cs.style &= ~FWS_ADDTOTITLE;
  167.     return TRUE;
  168. }
  169. /////////////////////////////////////////////////////////////////////////////
  170. // CMainFrame diagnostics
  171. #ifdef _DEBUG
  172. void CMainFrame::AssertValid() const
  173. {
  174. CMDIFrameWnd::AssertValid();
  175. }
  176. void CMainFrame::Dump(CDumpContext& dc) const
  177. {
  178. CMDIFrameWnd::Dump(dc);
  179. }
  180. #endif //_DEBUG
  181. /////////////////////////////////////////////////////////////////////////////
  182. // CMainFrame message handlers
  183. void CMainFrame::OnViewMydrawtoolbar(UINT nID) 
  184. {
  185. BOOL bVisible=m_MyDrawToolBar.GetStyle() & WS_VISIBLE ;
  186. //显示或隐藏绘图工具条
  187. ShowControlBar(&m_MyDrawToolBar, !bVisible, FALSE);
  188. RecalcLayout();
  189. return ;
  190. }
  191. void CMainFrame::OnUpdateViewMydrawtoolbar(CCmdUI* pCmdUI) 
  192. {
  193. //设置绘图工具条显示、隐藏标志
  194. pCmdUI->SetCheck((m_MyDrawToolBar.GetStyle() & WS_VISIBLE) != 0);
  195. }
  196. //////////////////////////////////////////////////////////////////////////////////////////////
  197. void CMainFrame::OnFileNewF() 
  198. {
  199. CMyNewSheet m_NewSheet(_T("新建"), this, 0);
  200. m_NewSheet.DoModal();
  201. }
  202. void CMainFrame::OnFileOpenF() 
  203. {
  204. if(pApp->CADInfo.IsEmpty == TRUE)
  205. {
  206. //pApp->CADInfo.KindofNew = NEW_NONE;
  207. //pApp->CADInfo.IsEmpty = FALSE;
  208. }
  209. }
  210. void CMainFrame::OnFileSaveF() 
  211. {
  212. if(pApp->CADInfo.IsEmpty == TRUE)
  213. return;
  214. CChildFrame* pChildWnd = (CChildFrame*)this->MDIGetActive();
  215.     CMiniCADDoc* pDoc = (CMiniCADDoc*)pChildWnd->GetActiveDocument();
  216. pDoc->SaveDocument();
  217. }
  218. void CMainFrame::OnFileSaveFAs() 
  219. {
  220. if(pApp->CADInfo.IsEmpty == TRUE)
  221. return;
  222. CString Filter="图纸文件(*.DRAWING_POSTFIX)|*.DRAWING_POSTFIX|所有文件(*.*)|*.*||";
  223. CString PathName;
  224. CChildFrame* pChildWnd = (CChildFrame*)this->MDIGetActive();
  225.     CMiniCADDoc* pDoc = (CMiniCADDoc*)pChildWnd->GetActiveDocument();
  226. CFileDialog SaveFileDlg(FALSE, 0, pDoc->FileInfo.m_FileName, 
  227.                     OFN_HIDEREADONLY|OFN_FILEMUSTEXIST|OFN_LONGNAMES, (LPCTSTR)Filter);
  228.     SaveFileDlg.m_ofn.lpstrTitle=_T("另存为");
  229.     if(SaveFileDlg.DoModal() != IDOK)
  230. return;
  231. //更改文档的文件名及路径
  232.     PathName = SaveFileDlg.GetPathName();   //取得文件名(包含路径)
  233. pDoc->FileInfo.m_FileName = SaveFileDlg.GetFileName(); //取得文件名  
  234.     pDoc->FileInfo.m_FilePath = PathName.Left(PathName.GetLength() 
  235.                                    - pDoc->FileInfo.m_FileName.GetLength() - 1);
  236. if(pApp->CADInfo.KindofNew == NEW_PROJECT)
  237. {
  238. CFileIndex * pFileIndex = pApp->ProjectInfo.FindFileIndex(pDoc->FileInfo.m_Name);
  239. pFileIndex->SetFileIndex(pDoc->FileInfo.m_Name, pDoc->FileInfo.m_FileName, 
  240.                      pDoc->FileInfo.m_FilePath);
  241. }
  242. pDoc->SaveDocument();
  243. }
  244. //保存全部文档
  245. void CMainFrame::OnFileSaveall() 
  246. {
  247. CMultiDocTemplate* pDocTemplate;
  248.     CMiniCADDoc* pDoc;
  249. POSITION DocTemplatePosition;
  250. POSITION DocPosition;
  251. //获取文档模板
  252. DocTemplatePosition = pApp->GetFirstDocTemplatePosition();
  253. pDocTemplate = (CMultiDocTemplate*)pApp->GetNextDocTemplate(DocTemplatePosition);
  254.     ASSERT(pDocTemplate != NULL);
  255. DocPosition = pDocTemplate->GetFirstDocPosition();
  256. while(DocPosition != NULL)
  257. {
  258. pDoc = (CMiniCADDoc*)pDocTemplate->GetNextDoc(DocPosition);
  259. pDoc->SaveDocument();
  260. }
  261. }
  262. ////////////////////////////////////////////////////////////////////////////////////////////
  263. void CMainFrame::OnFileNewP() 
  264. {
  265. //如果已存在新建的项目、图纸或元件
  266. if(pApp->CADInfo.IsEmpty == FALSE)
  267. {
  268. if(MessageBox("已有项目存在,是否继续?", "提示", 
  269.           MB_OKCANCEL | MB_ICONWARNING) == 2)
  270.   return;
  271. else
  272. {
  273. //关闭当前项目
  274.             OnFileCloseP(); 
  275. }
  276. }
  277. //显示“新建”属性框
  278. CMyNewProjectDlg m_NewProjectDlg;
  279. if(m_NewProjectDlg.NewProject(&pApp->ProjectInfo) == FALSE)
  280. return;
  281. pApp->CADInfo.IsEmpty = FALSE;
  282. pApp->CADInfo.KindofNew = NEW_PROJECT;
  283. m_MyWorkBar.pTree->InsertProject(pApp->ProjectInfo.Name);
  284. m_MyWorkBar.pTree->ShowWindow(TRUE);
  285. //更改最近项目列表
  286.     pApp->pRecentProjectList->Add((LPCTSTR)(pApp->ProjectInfo.FilePath +  "\" 
  287.                           + pApp->ProjectInfo.FileName));
  288. pApp->pRecentProjectList->WriteList();
  289. //刚刚创建新项目,自动显示“增加图纸”对话框
  290. OnFileNewFToP(); 
  291. }
  292. void CMainFrame::OnFileOpenP() 
  293. {
  294. //如果已存在新建的项目、图纸或元件
  295. if(pApp->CADInfo.IsEmpty == FALSE)
  296. {
  297. if(MessageBox("已有项目存在,是否继续?", "提示", 
  298.           MB_OKCANCEL | MB_ICONWARNING) == 2)
  299.   return;
  300. else
  301. {
  302. //关闭当前项目
  303.             OnFileCloseP(); 
  304. }
  305.   }
  306.     CString Filter="项目文件(*.PROJECT_POSTFIX)|PROJECT_POSTFIX|所有文件(*.*)|*.*||";
  307. CString PathName;
  308.     //实例化一个CFileDialog类
  309.     CFileDialog OpenProjectDlg(TRUE,0,0,OFN_HIDEREADONLY|OFN_FILEMUSTEXIST|OFN_LONGNAMES,(LPCTSTR)Filter);
  310.     OpenProjectDlg.m_ofn.lpstrTitle=_T("打开项目文件");
  311.     if(OpenProjectDlg.DoModal() != IDOK)
  312. return;
  313.     PathName = OpenProjectDlg.GetPathName();   //取得文件名(包含路径)
  314. //打开项目
  315. if(!OpenProject(PathName))
  316. return;
  317. pApp->CADInfo.IsEmpty = FALSE;
  318. pApp->CADInfo.KindofNew = NEW_PROJECT; 
  319. pApp->ProjectInfo.FileName = OpenProjectDlg.GetFileName(); //取得文件名  
  320.     pApp->ProjectInfo.FilePath = PathName.Left(PathName.GetLength() 
  321.                                    - pApp->ProjectInfo.FileName.GetLength() - 1);
  322.     pApp->CADInfo.ProjectPath = pApp->ProjectInfo.FilePath;
  323. //更改最近项目列表
  324. pApp->pRecentProjectList->Add((LPCTSTR)(pApp->ProjectInfo.FilePath +  "\" 
  325.                           + pApp->ProjectInfo.FileName));
  326. pApp->pRecentProjectList->WriteList();
  327. }
  328. void CMainFrame::OnFileNewFToP() 
  329. {
  330.     if(pApp->CADInfo.KindofNew != NEW_PROJECT)
  331. return;
  332.     CMyAddFileDlg MyAddFileDlg;
  333. //如果增加图纸成功
  334. //通过CMiniCADApp的成员变量NewFileInfo来传递新建文档参数
  335. if(MyAddFileDlg.AddFile(&pApp->NewFileInfo))
  336. {
  337. pApp->OnFileNew();//该函数会调用CDocument::OnNewDocument()
  338.     
  339.       CChildFrame* pChildWnd = (CChildFrame*)this->MDIGetActive();
  340. CMiniCADDoc* pDoc = (CMiniCADDoc*)pChildWnd->GetActiveDocument();
  341. pApp->ProjectInfo.AddFileIndex(pDoc->FileInfo.m_Name, pDoc->FileInfo.m_FileName,
  342.                            pDoc->FileInfo.m_FilePath);
  343. HTREEITEM fileitem = m_MyWorkBar.pTree->InsertFile(pDoc->FileInfo.m_Name);
  344. //增加一个缺省图层
  345. pDoc->m_ManageFileLayer.AddLayer("基层", TRUE, FALSE);
  346. CFileLayer* pLayer = pDoc->m_ManageFileLayer.GetLayer("基层");
  347. //设置缺省图层为当前图层
  348. pDoc->m_ManageFileLayer.SetCurrentLayerName("基层");
  349. m_MyWorkBar.pTree->InsertLayer(fileitem, pLayer->GetName(), ICON_CURRENTLAYER);
  350. }
  351. }
  352. void CMainFrame::OnUpdateFileNewFToP(CCmdUI* pCmdUI) 
  353. {
  354. //使能“增加图纸-新建”菜单命令
  355. if(pApp->CADInfo.IsEmpty == FALSE && pApp->CADInfo.KindofNew == NEW_PROJECT)
  356. pCmdUI->Enable(TRUE);
  357. else
  358. pCmdUI->Enable(FALSE);
  359. }
  360. void CMainFrame::OnFileOpenFToP() 
  361. {
  362. if(pApp->CADInfo.KindofNew != NEW_PROJECT)
  363. return;
  364. pApp->OnFileOpen();
  365. CChildFrame* pChildWnd = (CChildFrame*)this->MDIGetActive();
  366. CMiniCADDoc* pDoc = (CMiniCADDoc*)pChildWnd->GetActiveDocument();
  367.         
  368. pApp->ProjectInfo.AddFileIndex(pDoc->FileInfo.m_Name, pDoc->FileInfo.m_FileName,
  369.                             pDoc->FileInfo.m_FilePath);
  370. //插入图纸项
  371. HTREEITEM fileitem = m_MyWorkBar.pTree->InsertFile(pDoc->FileInfo.m_Name);
  372. //插入图层项
  373. for(int i = 0; i < (int)pDoc->m_ManageFileLayer.GetLayerNum(); i++)
  374. {
  375. CFileLayer* pLayer = pDoc->m_ManageFileLayer.GetLayer(i);
  376. if(pLayer->IsShow() && !pLayer->IsLocked())
  377. {
  378. if(pLayer->GetName() == pDoc->m_ManageFileLayer.GetCurrentLayerName())
  379. m_MyWorkBar.pTree->InsertLayer(fileitem, pLayer->GetName(), ICON_CURRENTLAYER);
  380. else
  381. m_MyWorkBar.pTree->InsertLayer(fileitem, pLayer->GetName(), ICON_LAYER);
  382. }
  383. if(pLayer->IsShow() && pLayer->IsLocked())
  384. {
  385. if(pLayer->GetName() == pDoc->m_ManageFileLayer.GetCurrentLayerName())
  386. m_MyWorkBar.pTree->InsertLayer(fileitem, pLayer->GetName(), ICON_CURRENTLOCKLAYER);
  387. else
  388. m_MyWorkBar.pTree->InsertLayer(fileitem, pLayer->GetName(), ICON_LOCKLAYER);
  389. }
  390. if(!pLayer->IsShow() && !pLayer->IsLocked())
  391. {
  392. if(pLayer->GetName() == pDoc->m_ManageFileLayer.GetCurrentLayerName())
  393. m_MyWorkBar.pTree->InsertLayer(fileitem, pLayer->GetName(), ICON_CURRENTHIDELAYER);
  394. else
  395. m_MyWorkBar.pTree->InsertLayer(fileitem, pLayer->GetName(), ICON_HIDELAYER);
  396. }
  397. if(!pLayer->IsShow() && pLayer->IsLocked())
  398. {
  399. if(pLayer->GetName() == pDoc->m_ManageFileLayer.GetCurrentLayerName())
  400. m_MyWorkBar.pTree->InsertLayer(fileitem, pLayer->GetName(), ICON_CURRENTLOCKHIDELAYER);
  401. else
  402. m_MyWorkBar.pTree->InsertLayer(fileitem, pLayer->GetName(), ICON_LOCKHIDELAYER);
  403. }
  404. }
  405. }
  406. void CMainFrame::OnUpdateFileOpenFToP(CCmdUI* pCmdUI) 
  407. {
  408. if(pApp->CADInfo.IsEmpty == FALSE && pApp->CADInfo.KindofNew == NEW_PROJECT)
  409. pCmdUI->Enable(TRUE);
  410. else
  411. pCmdUI->Enable(FALSE);
  412. }
  413. //从项目中删除文件
  414. void CMainFrame::OnFileDelFfromP() 
  415. {
  416. }
  417. void CMainFrame::OnFileSaveP() 
  418. {
  419. CFile fp;
  420. CString PathName;
  421. PathName = pApp->ProjectInfo.FilePath + "\" + pApp->ProjectInfo.FileName;
  422. //打开一个文件,如果该文件不存在就创建一个,如果已存在就将文件长度变为0
  423. fp.Open(PathName, CFile::modeCreate | CFile::modeWrite); 
  424. if(fp == 0)
  425. {
  426. MessageBox("打开项目文件错误",
  427. "错误", MB_OK | MB_ICONERROR);
  428. return;
  429. }
  430.     
  431. CArchive ar(&fp, CArchive::store);
  432.     pApp->ProjectInfo.Serialize(ar);
  433. //必须先关闭ar,再关闭fp
  434. ar.Close();
  435. fp.Close();
  436. }
  437. void CMainFrame::OnFileCloseP() 
  438. {
  439. if(MessageBox("关闭前是否保存全部文件?", "提示", MB_OKCANCEL 
  440.    | MB_ICONWARNING) == 1)
  441.    OnFileSaveall();//保存全部图纸
  442. if(MessageBox("关闭前是否保存项目?", "提示", MB_OKCANCEL 
  443.    | MB_ICONWARNING) == 1)
  444.    OnFileSaveP();//保存当前项目
  445. CMultiDocTemplate* pDocTemplate;
  446.     CMiniCADDoc* pDoc;
  447. POSITION DocTemplatePosition;
  448. POSITION DocPosition;
  449. pApp->CADInfo.IsEmpty = TRUE;
  450. pApp->CADInfo.KindofNew = NEW_NONE;
  451. m_MyWorkBar.pTree->DeleteAllItems();
  452. m_MyWorkBar.pTree->ShowWindow(FALSE);
  453. //获取文档模板
  454. DocTemplatePosition = pApp->GetFirstDocTemplatePosition();
  455. pDocTemplate = (CMultiDocTemplate*)pApp->GetNextDocTemplate(DocTemplatePosition);
  456. DocPosition = pDocTemplate->GetFirstDocPosition();
  457. for(;;)
  458. {
  459. if(DocPosition == NULL)
  460. return;
  461. //获取文档
  462. pDoc = (CMiniCADDoc*)pDocTemplate->GetNextDoc(DocPosition);
  463. ASSERT(pDoc != NULL); 
  464. pDoc->OnCloseDocument();
  465. }
  466. }
  467. ////////////////////////////////////////////////////////////////////////
  468. void CMainFrame::OnFileCloseF() 
  469. {
  470. }
  471. //////////////////////////////////////////////////////////////////////////////////////////////
  472. void CMainFrame::OnSelchangeTab(NMHDR* pNMHDR, LRESULT* pResult) 
  473. {
  474. CTabCtrl* m_Tab =(CTabCtrl*)m_MyWorkBar.GetDlgItem(IDC_TAB);
  475. switch(m_Tab->GetCurSel())
  476. {
  477. case 0:
  478. {
  479. //隐藏列表框
  480. CListCtrl* pList = (CListCtrl*)m_MyWorkBar.GetDlgItem(IDC_LIST);
  481.        pList->ShowWindow(FALSE);
  482. //当有项目存在时才显示树形框
  483. if(pApp->CADInfo.KindofNew == NEW_PROJECT)
  484. m_MyWorkBar.pTree->ShowWindow(TRUE);
  485. }
  486. break;
  487. case 1:
  488. {
  489. //显示列表框
  490. m_MyWorkBar.pTree->ShowWindow(FALSE);
  491. CListCtrl* pList =
  492. (CListCtrl*)m_MyWorkBar.GetDlgItem(IDC_LIST);
  493. pList->ShowWindow(TRUE);
  494. }
  495. break;
  496. }
  497. *pResult = 0;
  498. }
  499. void CMainFrame::OnClickTree(NMHDR* pNMHDR, LRESULT* pResult) 
  500. {
  501. *pResult = 0;
  502. }
  503. void CMainFrame::OnDblclkTree(NMHDR* pNMHDR, LRESULT* pResult) 
  504. {
  505. CString name;      //子项名
  506. CString PathName;
  507. HTREEITEM  item = m_MyWorkBar.pTree->GetSelectedItem();
  508. ASSERT(item != NULL);
  509. name = m_MyWorkBar.pTree->GetItemText(item);
  510. //获取选中项的绑定值
  511. DWORD data = m_MyWorkBar.pTree->GetItemData(item);
  512. switch(data)
  513. {
  514. case TREE_FILE_ITEM:
  515. CMultiDocTemplate* pDocTemplate;
  516. CMiniCADDoc* pDoc;
  517. CMiniCADView* pView;
  518. CChildFrame* pChildFrame;
  519. POSITION DocTemplatePosition;
  520. POSITION DocPosition;
  521. POSITION ViewPosition;
  522. //获取文档模板
  523. DocTemplatePosition = pApp->GetFirstDocTemplatePosition();
  524. pDocTemplate = (CMultiDocTemplate*)pApp->GetNextDocTemplate(DocTemplatePosition);
  525. DocPosition = pDocTemplate->GetFirstDocPosition();
  526. for(;;)
  527. {
  528. if(DocPosition == NULL)
  529. {
  530. //如果DocPosition == NULL,说明文档没有打开
  531. //注意如果文件不存在,在CScrollView创建时会出错,现在
  532. //还不知道预先处理错误的方法
  533. CFileIndex* pFileIndex = pApp->ProjectInfo.FindFileIndex(name);
  534. ASSERT(pFileIndex != NULL);
  535. PathName = pFileIndex->GetFilePath() + "\" + pFileIndex->GetFileName();
  536. //给要激活的文档序号赋值
  537. ASSERT(AfxGetApp()->OpenDocumentFile(PathName) != NULL);
  538. CChildFrame* pChildWnd = (CChildFrame*)this->MDIGetActive();
  539. CMiniCADDoc* pDoc = (CMiniCADDoc*)pChildWnd->GetActiveDocument();
  540.     
  541. //使图层子项保持展开或收拢
  542. m_MyWorkBar.pTree->Expand(item, TVE_TOGGLE);
  543. *pResult = 0;
  544. return;
  545. }
  546. //获取文档
  547. pDoc = (CMiniCADDoc*)pDocTemplate->GetNextDoc(DocPosition);
  548. if(pDoc->FileInfo.m_Name == name)
  549. break;
  550. }
  551. //获取文档的视图
  552. ViewPosition = pDoc->GetFirstViewPosition();
  553. pView = (CMiniCADView*)pDoc->GetNextView(ViewPosition);
  554. //激活子窗口
  555. pChildFrame = (CChildFrame*)pView->GetParentFrame();
  556. pChildFrame->MDIActivate( );
  557. //使图层子项保持展开或收拢
  558. m_MyWorkBar.pTree->Expand(item, TVE_TOGGLE);
  559. break;
  560. case TREE_LAYER_ITEM:
  561. break;
  562. }
  563.       
  564. *pResult = 0;
  565. }
  566. void CMainFrame::OnRclickTree(NMHDR* pNMHDR, LRESULT* pResult) 
  567. {
  568. CPoint point;
  569.   CRect rect;
  570. CPoint pt;
  571. CMenu menu;
  572. //获取当前鼠标位置
  573. GetCursorPos(&pt);
  574. UINT flag;
  575. m_MyWorkBar.pTree->ScreenToClient(&pt);
  576. //获取被点击的Item
  577. HTREEITEM item = m_MyWorkBar.pTree->HitTest(pt, &flag);
  578. if(item == NULL)
  579. return;
  580. //如果不是点击在项的图标或标题上
  581. if(flag != TVHT_ONITEMLABEL && flag != TVHT_ONITEMICON)
  582. return;
  583. m_MyWorkBar.pTree->SelectItem(item);
  584. m_MyWorkBar.pTree->GetItemRect(item, &rect, TRUE); 
  585. m_MyWorkBar.pTree->ClientToScreen(rect);
  586. point.y = rect.top;
  587. point.x = rect.right;
  588. DWORD data = m_MyWorkBar.pTree->GetItemData(item);
  589. switch(data)
  590. {
  591.     case TREE_PROJECT_ITEM: 
  592. ASSERT(menu.LoadMenu(IDR_POPUP_PROJECT));
  593. break;
  594.     case TREE_FILE_ITEM:
  595. ASSERT(menu.LoadMenu(IDR_POPUP_DRAWING));
  596. break;
  597. case TREE_LAYER_ITEM:
  598. {
  599. ASSERT(menu.LoadMenu(IDR_POPUP_LAYER));
  600. HTREEITEM fileitem = m_MyWorkBar.pTree->GetParentItem(item);
  601. CString filename = m_MyWorkBar.pTree->GetItemText(fileitem);
  602. CMiniCADDoc* pDoc = GetDocument(filename);
  603. ASSERT(pDoc != NULL);
  604. CString layername = m_MyWorkBar.pTree->GetItemText(item);
  605. CFileLayer* pLayer = pDoc->m_ManageFileLayer.GetLayer(layername);
  606. if(pLayer->IsShow())
  607. menu.DeleteMenu(ID_LAYER_SHOW, MF_BYCOMMAND);
  608. else
  609. menu.DeleteMenu(ID_LAYER_HIDE, MF_BYCOMMAND);
  610. if(pLayer->IsLocked())
  611. menu.DeleteMenu(ID_LAYER_LOCK, MF_BYCOMMAND);
  612. else
  613. menu.DeleteMenu(ID_LAYER_UNLOCK, MF_BYCOMMAND);
  614. if(pLayer->GetName() == pDoc->m_ManageFileLayer.GetCurrentLayerName())
  615. menu.DeleteMenu(ID_LAYER_CURRENT, MF_BYCOMMAND);
  616. break;
  617. }
  618. }
  619. CMenu* pPopup = menu.GetSubMenu(0);
  620. ASSERT(pPopup != NULL);
  621. CWnd* pWndPopupOwner = m_MyWorkBar.pTree->GetSafeOwner();
  622. while (pWndPopupOwner->GetStyle() & WS_CHILD)
  623. pWndPopupOwner = pWndPopupOwner->GetParent();
  624. pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y,
  625. pWndPopupOwner);
  626. menu.DestroyMenu();
  627. *pResult = 0;
  628. }
  629. //////////////////////////////////////////////////////////////////////////////////////////////
  630. void CMainFrame::OnViewFull() 
  631. {
  632. if (m_pWndFullScreen != NULL)
  633. {
  634. LockWindowUpdate();
  635. m_pWndFullScreen->LockWindowUpdate();
  636. m_pWndFullScreen->ShowControlBar(&m_pWndFullScreen->m_MyCommandBar, TRUE, FALSE);
  637. ShowControlBar(&m_wndToolBar, TRUE, FALSE);
  638. ShowControlBar(&m_wndStatusBar, TRUE, FALSE);
  639. ShowControlBar(&m_MyOptionBar, TRUE, FALSE);
  640. ShowControlBar(&m_MyDrawToolBar, TRUE, FALSE);
  641. ShowControlBar(&m_MyModifyToolBar, TRUE, FALSE);
  642. ShowControlBar(&m_MyWorkBar, TRUE, FALSE);
  643.         
  644. //恢复原来状态
  645. SetWindowPlacement(&m_MainOldPlace);
  646. m_pWndFullScreen->SetWindowPlacement(&m_ChildOldPlace);
  647. UnlockWindowUpdate();
  648. m_pWndFullScreen->UnlockWindowUpdate();
  649. m_pWndFullScreen = NULL;
  650. }
  651. else
  652. {
  653. m_pWndFullScreen = (CChildFrame*)MDIGetActive();
  654. if(m_pWndFullScreen == NULL)
  655. return;
  656. LockWindowUpdate();
  657. m_pWndFullScreen->LockWindowUpdate();
  658. //隐藏各种工具条,注意应先使用LockWindowUpdate()禁止更新屏幕
  659. //这样可以加快全屏显示的速度
  660.         m_pWndFullScreen->ShowControlBar(&m_pWndFullScreen->m_MyCommandBar, FALSE, FALSE);
  661. ShowControlBar(&m_wndToolBar, FALSE, FALSE);
  662. ShowControlBar(&m_wndStatusBar,FALSE, FALSE);
  663. ShowControlBar(&m_MyOptionBar, FALSE, FALSE);
  664. ShowControlBar(&m_MyDrawToolBar, FALSE, FALSE);
  665. ShowControlBar(&m_MyModifyToolBar, FALSE, FALSE);
  666. ShowControlBar(&m_MyWorkBar, FALSE, FALSE);
  667. m_pWndFullScreen->GetWindowPlacement(&m_ChildOldPlace);
  668. GetWindowPlacement(&m_MainOldPlace);
  669. CRect rectDesktop, rectDesired;
  670. //获取全屏显示所需的客户区
  671. if (!::SystemParametersInfo(SPI_GETWORKAREA, 0, &rectDesktop, 0))
  672.   ::GetWindowRect(::GetDesktopWindow(), &rectDesktop);
  673. else
  674. {
  675. rectDesktop.right = ::GetSystemMetrics(SM_CXSCREEN);
  676. rectDesktop.bottom = ::GetSystemMetrics(SM_CYSCREEN);
  677. rectDesktop.right -= rectDesktop.left;
  678. rectDesktop.bottom -= rectDesktop.top;
  679. rectDesktop.left = rectDesktop.left;
  680. rectDesktop.top = rectDesktop.top;
  681. }
  682. rectDesired = rectDesktop;
  683. //根据客户区获取框架的尺寸
  684.     ::AdjustWindowRect(&rectDesktop, GetStyle(), TRUE);
  685. rectDesktop.bottom += ::GetSystemMetrics(SM_CYBORDER); // See "Ask Dr. GUI #10"
  686. m_FullScreenPlace = rectDesktop;
  687. WINDOWPLACEMENT wpNew = m_MainOldPlace;
  688. wpNew.showCmd =  SW_SHOWNORMAL;
  689. wpNew.rcNormalPosition = rectDesktop;
  690. //设置主框架新的状态和位置
  691. SetWindowPlacement(&wpNew);
  692. wpNew.rcNormalPosition = rectDesired;
  693. ::AdjustWindowRect(&(wpNew.rcNormalPosition), m_pWndFullScreen->GetStyle(), FALSE);
  694. //设置子框架新的状态和位置
  695. m_pWndFullScreen->SetWindowPlacement(&wpNew);
  696. UnlockWindowUpdate();
  697. m_pWndFullScreen->UnlockWindowUpdate();
  698. }
  699. }
  700. void CMainFrame::OnUpdateViewFull(CCmdUI* pCmdUI) 
  701. {
  702. if(MDIGetActive() == NULL)
  703. {
  704. pCmdUI->Enable(FALSE);
  705. return;
  706. }
  707. else
  708. {
  709. pCmdUI->Enable(TRUE);
  710. pCmdUI->SetCheck(m_pWndFullScreen != NULL);
  711. }
  712. }
  713. void CMainFrame::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI) 
  714. {
  715. if (m_pWndFullScreen != NULL)
  716. {
  717. //全屏显示时重新设置主框架最大化时的尺寸
  718. lpMMI->ptMaxSize.y = m_FullScreenPlace.Height();
  719.   lpMMI->ptMaxTrackSize.y = m_FullScreenPlace.Height();
  720. lpMMI->ptMaxSize.x = m_FullScreenPlace.Width();
  721. lpMMI->ptMaxTrackSize.x = m_FullScreenPlace.Width();
  722. }
  723. else
  724. CMDIFrameWnd::OnGetMinMaxInfo(lpMMI);  
  725. }
  726. BOOL CMainFrame::GetFullScreenSize(CWnd* pWnd, POINT& pt) 
  727. {
  728. if (m_pWndFullScreen != NULL && pWnd->m_hWnd == m_pWndFullScreen->m_hWnd)
  729. {
  730. pt.x = m_FullScreenPlace.Width();
  731. pt.y = m_FullScreenPlace.Height();
  732. }
  733. return (m_pWndFullScreen != NULL);
  734. }
  735. /////////////////////////////////////////////////////////////////////////////////////////////
  736. //实现“最近项目”的菜单功能
  737. void CMainFrame::OnFileProjectlist(UINT nID)
  738. {   
  739. UINT index;
  740. CString PathName;
  741. index = nID - ID_FILE_PROJECTLIST;
  742. PathName = (*(pApp->pRecentProjectList))[index];
  743. //如果已存在新建的项目、图纸或元件
  744. if(pApp->CADInfo.IsEmpty == FALSE)
  745. {
  746. //如果PathName是当前打开的项目,则返回
  747. if(PathName == pApp->ProjectInfo.FilePath + "\" + pApp->ProjectInfo.FileName)
  748. return;
  749. if(MessageBox("已有项目存在,是否继续?", "提示", 
  750.           MB_OKCANCEL | MB_ICONWARNING) == 2)
  751.   return;
  752. else
  753. {
  754. //关闭当前项目
  755.             OnFileCloseP(); 
  756. }
  757.   }
  758. if(!OpenProject(PathName))
  759. return;
  760. pApp->CADInfo.IsEmpty = FALSE;
  761. pApp->CADInfo.KindofNew = NEW_PROJECT; 
  762. //获取项目文件名
  763. pApp->ProjectInfo.FileName = PathName.Right(PathName.GetLength() - PathName.ReverseFind('\') 
  764.                                     - 1);
  765. //获取项目文件路径
  766.     pApp->ProjectInfo.FilePath = PathName.Left(PathName.ReverseFind('\'));
  767.     pApp->CADInfo.ProjectPath = pApp->ProjectInfo.FilePath;
  768. //更改最近项目列表
  769. pApp->pRecentProjectList->Add((LPCTSTR)(pApp->ProjectInfo.FilePath +  "\" 
  770.                           + pApp->ProjectInfo.FileName));
  771. pApp->pRecentProjectList->WriteList();
  772. }
  773. void CMainFrame::OnUpdateFileProjectlist(CCmdUI* pCmdUI) 
  774. {
  775. if(pCmdUI->m_nID == ID_FILE_PROJECTLIST)
  776. {
  777. pApp->pRecentProjectList->CRecentFileListEx::UpdateMenu(pCmdUI);
  778. }
  779. pCmdUI->Enable(TRUE);
  780. }
  781. void CMainFrame::OnFileFilelist(UINT nID)
  782. {
  783. }
  784. void CMainFrame::OnUpdateFileFilelist(CCmdUI* pCmdUI) 
  785. {
  786. if(pCmdUI->m_nID == ID_FILE_FILELIST)
  787. {
  788. //注意此时应该用基类CRecentFileList的UpdateMenu(CCmdUI* pCmdUI)
  789. //这是由CMenu的特点决定的,“最近文件”菜单项是第二个Popup菜单项,
  790. //其子菜单的pCmdUI->mIndex为0,pCmdUI->pMenu指向子菜单
  791. pApp->pRecentFileList->UpdateMenu(pCmdUI);
  792. }
  793. pCmdUI->Enable(TRUE);
  794. }
  795. void CMainFrame::OnClose() 
  796. {
  797. if(pApp->CADInfo.KindofNew == NEW_PROJECT)
  798. {
  799. if(MessageBox("是否要退出?", "提示", MB_OKCANCEL 
  800.    | MB_ICONWARNING) == 2)
  801.    return;
  802. //如果按下“确定”(按下“取消”返回值为2)
  803. if(MessageBox("退出前是否保存全部文件?", "提示", MB_OKCANCEL 
  804.    | MB_ICONWARNING) == 1)
  805.    OnFileSaveall();
  806. if(MessageBox("退出前是否保存项目?", "提示", MB_OKCANCEL 
  807.    | MB_ICONWARNING) == 1)
  808.    OnFileSaveP();
  809. }
  810. CMDIFrameWnd::OnClose();
  811. }
  812.  
  813. void CMainFrame::OnDeleteitemTree(NMHDR* pNMHDR, LRESULT* pResult) 
  814. {
  815. NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
  816. *pResult = 0;
  817. }
  818. void CMainFrame::OnFormatLayer() 
  819. {
  820. CChildFrame* pChildWnd = (CChildFrame*)this->MDIGetActive();
  821. CMiniCADDoc* pDoc = (CMiniCADDoc*)pChildWnd->GetActiveDocument();
  822. ASSERT_VALID(pDoc);
  823. CFileLayerDlg dlg;
  824. dlg.Create(pDoc->FileInfo.m_Name, &pDoc->m_ManageFileLayer);
  825. HTREEITEM fileitem = m_MyWorkBar.pTree->FindFileItem(pDoc->FileInfo.m_Name);
  826. ASSERT(fileitem != NULL);
  827. CString filename  = m_MyWorkBar.pTree->GetItemText(fileitem);
  828. //删除图纸项下的全部图层项
  829. for(;;)
  830. {
  831. HTREEITEM layeritem = m_MyWorkBar.pTree->GetChildItem(fileitem);
  832. if(layeritem == NULL)
  833. break;
  834. m_MyWorkBar.pTree->DeleteItem(layeritem);
  835. }
  836.     
  837. //重新插入图层项
  838. for(int i = 0; i < (int)pDoc->m_ManageFileLayer.GetLayerNum(); i++)
  839. {
  840. CFileLayer* pLayer = pDoc->m_ManageFileLayer.GetLayer(i);
  841. if(pLayer->IsShow() && !pLayer->IsLocked())
  842. {
  843. if(pLayer->GetName() == pDoc->m_ManageFileLayer.GetCurrentLayerName())
  844. m_MyWorkBar.pTree->InsertLayer(fileitem, pLayer->GetName(), ICON_CURRENTLAYER);
  845. else
  846. m_MyWorkBar.pTree->InsertLayer(fileitem, pLayer->GetName(), ICON_LAYER);
  847. }
  848. if(pLayer->IsShow() && pLayer->IsLocked())
  849. {
  850. if(pLayer->GetName() == pDoc->m_ManageFileLayer.GetCurrentLayerName())
  851. m_MyWorkBar.pTree->InsertLayer(fileitem, pLayer->GetName(), ICON_CURRENTLOCKLAYER);
  852. else
  853. m_MyWorkBar.pTree->InsertLayer(fileitem, pLayer->GetName(), ICON_LOCKLAYER);
  854. }
  855. if(!pLayer->IsShow() && !pLayer->IsLocked())
  856. {
  857. if(pLayer->GetName() == pDoc->m_ManageFileLayer.GetCurrentLayerName())
  858. m_MyWorkBar.pTree->InsertLayer(fileitem, pLayer->GetName(), ICON_CURRENTHIDELAYER);
  859. else
  860. m_MyWorkBar.pTree->InsertLayer(fileitem, pLayer->GetName(), ICON_HIDELAYER);
  861. }
  862. if(!pLayer->IsShow() && pLayer->IsLocked())
  863. {
  864. if(pLayer->GetName() == pDoc->m_ManageFileLayer.GetCurrentLayerName())
  865. m_MyWorkBar.pTree->InsertLayer(fileitem, pLayer->GetName(), ICON_CURRENTLOCKHIDELAYER);
  866. else
  867. m_MyWorkBar.pTree->InsertLayer(fileitem, pLayer->GetName(), ICON_LOCKHIDELAYER);
  868. }
  869. }
  870. }
  871. void CMainFrame::OnFileProjectattribute() 
  872. {
  873. CProjectAttributeDlg dlg;
  874. dlg.DoModal();
  875. }
  876. void CMainFrame::OnFileFileattribute() 
  877. {
  878. CDrawingAttributeDlg dlg;
  879. dlg.DoModal();
  880. }
  881. void CMainFrame::OnLayerDelete() 
  882. {
  883. HTREEITEM layeritem = m_MyWorkBar.pTree->GetSelectedItem();
  884. DWORD data = m_MyWorkBar.pTree->GetItemData(layeritem);
  885. ASSERT(data == TREE_LAYER_ITEM);
  886. CString layername =  m_MyWorkBar.pTree->GetItemText(layeritem);
  887. HTREEITEM fileitem = m_MyWorkBar.pTree->GetParentItem(layeritem);
  888. CString filename =  m_MyWorkBar.pTree->GetItemText(fileitem);
  889. CMiniCADDoc* pDoc = GetDocument(filename);
  890. CFileLayer* pLayer = pDoc->m_ManageFileLayer.GetLayer(layername);
  891. //如果删除的层是当前层
  892. if(pLayer->GetName() == pDoc->m_ManageFileLayer.GetCurrentLayerName())
  893. //当前层为空
  894. pDoc->m_ManageFileLayer.SetCurrentLayerName("");
  895. //删除图层
  896.     pDoc->m_ManageFileLayer.DelLayer(layername);
  897. m_MyWorkBar.pTree->DeleteItem(layeritem);
  898. }
  899. void CMainFrame::OnLayerCurrent() 
  900. {
  901. CFileLayer* pLayer;
  902. HTREEITEM layeritem = m_MyWorkBar.pTree->GetSelectedItem();
  903. DWORD data = m_MyWorkBar.pTree->GetItemData(layeritem);
  904. ASSERT(data == TREE_LAYER_ITEM);
  905. CString layername =  m_MyWorkBar.pTree->GetItemText(layeritem);
  906. HTREEITEM fileitem = m_MyWorkBar.pTree->GetParentItem(layeritem);
  907. CString filename =  m_MyWorkBar.pTree->GetItemText(fileitem);
  908. CMiniCADDoc* pDoc = GetDocument(filename);
  909. CString CurrentLayerName = pDoc->m_ManageFileLayer.GetCurrentLayerName();
  910. if(CurrentLayerName != "")
  911. {
  912. HTREEITEM CurrentLayerItem = m_MyWorkBar.pTree->FindLayerItem(fileitem,
  913.                                                           CurrentLayerName);
  914. //如果原先有当前层, 则修改原先当前图层项的图标,
  915. pLayer = pDoc->m_ManageFileLayer.GetLayer(CurrentLayerName);
  916. ASSERT(pLayer != NULL);
  917. if(pLayer->IsShow() && !pLayer->IsLocked())
  918. m_MyWorkBar.pTree->SetItemImage(CurrentLayerItem, ICON_LAYER, ICON_LAYER);
  919. if(pLayer->IsShow() && pLayer->IsLocked())
  920. m_MyWorkBar.pTree->SetItemImage(CurrentLayerItem, ICON_LOCKLAYER, ICON_LOCKLAYER);
  921. if(!pLayer->IsShow() && !pLayer->IsLocked())
  922. m_MyWorkBar.pTree->SetItemImage(CurrentLayerItem, ICON_HIDELAYER, ICON_HIDELAYER);
  923. if(!pLayer->IsShow() && pLayer->IsLocked())
  924. m_MyWorkBar.pTree->SetItemImage(CurrentLayerItem, ICON_LOCKHIDELAYER, ICON_LOCKHIDELAYER);
  925. }
  926. //设置当前图层
  927.     pDoc->m_ManageFileLayer.SetCurrentLayerName(layername);
  928. pLayer = pDoc->m_ManageFileLayer.GetLayer(layername);
  929. //修改现在的当前图层项的图标
  930. if(pLayer->IsShow() && !pLayer->IsLocked())
  931. m_MyWorkBar.pTree->SetItemImage(layeritem, ICON_CURRENTLAYER, ICON_CURRENTLAYER);
  932. if(pLayer->IsShow() && pLayer->IsLocked())
  933. m_MyWorkBar.pTree->SetItemImage(layeritem, ICON_CURRENTLOCKLAYER, 
  934.                                 ICON_CURRENTLOCKLAYER);
  935. if(!pLayer->IsShow() && !pLayer->IsLocked())
  936. m_MyWorkBar.pTree->SetItemImage(layeritem, ICON_CURRENTHIDELAYER, 
  937.                                 ICON_CURRENTHIDELAYER);
  938. if(!pLayer->IsShow() && pLayer->IsLocked())
  939. m_MyWorkBar.pTree->SetItemImage(layeritem, ICON_CURRENTLOCKHIDELAYER, 
  940.                                 ICON_CURRENTLOCKHIDELAYER);
  941.     if(!pLayer->IsShow() || pLayer->IsLocked())
  942. //如果当前图层被隐藏或被锁定,当前命令为NO_COMMAND
  943. pDoc->CurrentCommand = NO_COMMAND;
  944. }
  945. void CMainFrame::OnLayerHide() 
  946. {
  947. HTREEITEM layeritem = m_MyWorkBar.pTree->GetSelectedItem();
  948. DWORD data = m_MyWorkBar.pTree->GetItemData(layeritem);
  949. ASSERT(data == TREE_LAYER_ITEM);
  950. CString layername =  m_MyWorkBar.pTree->GetItemText(layeritem);
  951. HTREEITEM fileitem = m_MyWorkBar.pTree->GetParentItem(layeritem);
  952. CString filename =  m_MyWorkBar.pTree->GetItemText(fileitem);
  953. CMiniCADDoc* pDoc = GetDocument(filename);
  954. CFileLayer* pLayer = pDoc->m_ManageFileLayer.GetLayer(layername);
  955. pLayer->SetShow(FALSE);
  956. //修改图标
  957. if(pLayer->IsLocked())
  958. {
  959. if(pLayer->GetName() == pDoc->m_ManageFileLayer.GetCurrentLayerName())
  960. m_MyWorkBar.pTree->SetItemImage(layeritem, ICON_CURRENTLOCKHIDELAYER, ICON_CURRENTLOCKHIDELAYER);
  961. else
  962. m_MyWorkBar.pTree->SetItemImage(layeritem, ICON_LOCKHIDELAYER, ICON_LOCKHIDELAYER);
  963. }
  964. else
  965. {
  966. if(pLayer->GetName() == pDoc->m_ManageFileLayer.GetCurrentLayerName())
  967. {
  968. m_MyWorkBar.pTree->SetItemImage(layeritem, ICON_CURRENTHIDELAYER, ICON_CURRENTHIDELAYER);
  969. //如果当前图层被隐藏,当前命令为NO_COMMAND
  970. pDoc->CurrentCommand = NO_COMMAND;
  971. }
  972. else
  973. m_MyWorkBar.pTree->SetItemImage(layeritem, ICON_HIDELAYER, ICON_HIDELAYER);
  974. }
  975. //更新视
  976. POSITION pos = pDoc->GetFirstViewPosition();
  977. CMiniCADView* pView = (CMiniCADView*)pDoc->GetNextView(pos);
  978. pView->Invalidate();
  979. }
  980. void CMainFrame::OnUpdateLayerHide(CCmdUI* pCmdUI) 
  981. {
  982. }
  983. void CMainFrame::OnLayerShow() 
  984. {
  985. HTREEITEM layeritem = m_MyWorkBar.pTree->GetSelectedItem();
  986. DWORD data = m_MyWorkBar.pTree->GetItemData(layeritem);
  987. ASSERT(data == TREE_LAYER_ITEM);
  988. CString layername =  m_MyWorkBar.pTree->GetItemText(layeritem);
  989. HTREEITEM fileitem = m_MyWorkBar.pTree->GetParentItem(layeritem);
  990. CString filename =  m_MyWorkBar.pTree->GetItemText(fileitem);
  991. CMiniCADDoc* pDoc = GetDocument(filename);
  992. CFileLayer* pLayer = pDoc->m_ManageFileLayer.GetLayer(layername);
  993. pLayer->SetShow(TRUE);
  994. //修改图标
  995. if(pLayer->IsLocked())
  996. {
  997. if(pLayer->GetName() == pDoc->m_ManageFileLayer.GetCurrentLayerName())
  998. m_MyWorkBar.pTree->SetItemImage(layeritem, ICON_CURRENTLOCKLAYER, ICON_CURRENTLOCKLAYER);
  999. else
  1000. m_MyWorkBar.pTree->SetItemImage(layeritem, ICON_LOCKLAYER, ICON_LOCKLAYER);
  1001. }
  1002. else
  1003. {
  1004. if(pLayer->GetName() == pDoc->m_ManageFileLayer.GetCurrentLayerName())
  1005. m_MyWorkBar.pTree->SetItemImage(layeritem, ICON_CURRENTLAYER, ICON_CURRENTLAYER);
  1006. else
  1007. m_MyWorkBar.pTree->SetItemImage(layeritem, ICON_LAYER, ICON_LAYER);
  1008. }
  1009. //更新视
  1010. POSITION pos = pDoc->GetFirstViewPosition();
  1011. CMiniCADView* pView = (CMiniCADView*)pDoc->GetNextView(pos);
  1012. pView->Invalidate();
  1013. }
  1014. void CMainFrame::OnUpdateLayerShow(CCmdUI* pCmdUI) 
  1015. {
  1016. }
  1017. void CMainFrame::OnLayerLock() 
  1018. {
  1019. HTREEITEM layeritem = m_MyWorkBar.pTree->GetSelectedItem();
  1020. DWORD data = m_MyWorkBar.pTree->GetItemData(layeritem);
  1021. ASSERT(data == TREE_LAYER_ITEM);
  1022. CString layername =  m_MyWorkBar.pTree->GetItemText(layeritem);
  1023. HTREEITEM fileitem = m_MyWorkBar.pTree->GetParentItem(layeritem);
  1024. CString filename =  m_MyWorkBar.pTree->GetItemText(fileitem);
  1025. CMiniCADDoc* pDoc = GetDocument(filename);
  1026. CFileLayer* pLayer = pDoc->m_ManageFileLayer.GetLayer(layername);
  1027. pLayer->SetLocked(TRUE);
  1028. //修改图标
  1029. if(pLayer->IsShow())
  1030. {
  1031. if(pLayer->GetName() == pDoc->m_ManageFileLayer.GetCurrentLayerName())
  1032. {
  1033. m_MyWorkBar.pTree->SetItemImage(layeritem, ICON_CURRENTLOCKLAYER, ICON_CURRENTLOCKLAYER);
  1034. //如果当前图层被锁定,当前命令为NO_COMMAND
  1035. pDoc->CurrentCommand = NO_COMMAND;
  1036. }
  1037. else
  1038. m_MyWorkBar.pTree->SetItemImage(layeritem, ICON_LOCKLAYER, ICON_LOCKLAYER);
  1039. }
  1040. else
  1041. {
  1042. if(pLayer->GetName() == pDoc->m_ManageFileLayer.GetCurrentLayerName())
  1043. m_MyWorkBar.pTree->SetItemImage(layeritem, ICON_CURRENTLOCKHIDELAYER, ICON_CURRENTLOCKHIDELAYER);
  1044. else
  1045. m_MyWorkBar.pTree->SetItemImage(layeritem, ICON_LOCKHIDELAYER, ICON_LOCKHIDELAYER);
  1046. }
  1047. }
  1048. void CMainFrame::OnUpdateLayerLock(CCmdUI* pCmdUI) 
  1049. {
  1050. }
  1051. void CMainFrame::OnLayerUnlock() 
  1052. {
  1053. HTREEITEM layeritem = m_MyWorkBar.pTree->GetSelectedItem();
  1054. DWORD data = m_MyWorkBar.pTree->GetItemData(layeritem);
  1055. ASSERT(data == TREE_LAYER_ITEM);
  1056. CString layername =  m_MyWorkBar.pTree->GetItemText(layeritem);
  1057. HTREEITEM fileitem = m_MyWorkBar.pTree->GetParentItem(layeritem);
  1058. CString filename =  m_MyWorkBar.pTree->GetItemText(fileitem);
  1059. CMiniCADDoc* pDoc = GetDocument(filename);
  1060. CFileLayer* pLayer = pDoc->m_ManageFileLayer.GetLayer(layername);
  1061. pLayer->SetLocked(FALSE);
  1062. //修改图标
  1063. if(pLayer->IsShow())
  1064. {
  1065. if(pLayer->GetName() == pDoc->m_ManageFileLayer.GetCurrentLayerName())
  1066. m_MyWorkBar.pTree->SetItemImage(layeritem, ICON_CURRENTLAYER, ICON_CURRENTLAYER);
  1067. else
  1068. m_MyWorkBar.pTree->SetItemImage(layeritem, ICON_LAYER, ICON_LAYER);
  1069. }
  1070. else
  1071. {
  1072. if(pLayer->GetName() == pDoc->m_ManageFileLayer.GetCurrentLayerName())
  1073. m_MyWorkBar.pTree->SetItemImage(layeritem, ICON_CURRENTHIDELAYER, ICON_CURRENTHIDELAYER);
  1074. else
  1075. m_MyWorkBar.pTree->SetItemImage(layeritem, ICON_HIDELAYER, ICON_HIDELAYER);
  1076. }
  1077. }
  1078. void CMainFrame::OnUpdateLayerUnlock(CCmdUI* pCmdUI) 
  1079. {
  1080. }
  1081. void CMainFrame::OnLayerAttribute() 
  1082. {
  1083. HTREEITEM layeritem = m_MyWorkBar.pTree->GetSelectedItem();
  1084. DWORD data = m_MyWorkBar.pTree->GetItemData(layeritem);
  1085. ASSERT(data == TREE_LAYER_ITEM);
  1086. CString layername =  m_MyWorkBar.pTree->GetItemText(layeritem);
  1087. HTREEITEM fileitem = m_MyWorkBar.pTree->GetParentItem(layeritem);
  1088. CString filename =  m_MyWorkBar.pTree->GetItemText(fileitem);
  1089. CMiniCADDoc* pDoc = GetDocument(filename);
  1090. BOOL flag;
  1091. do
  1092. {
  1093. flag = TRUE;
  1094. CLayerAttributeDlg dlg;
  1095. layername = dlg.Show(layername);
  1096. HTREEITEM ChildItem = m_MyWorkBar.pTree->GetChildItem(fileitem);
  1097. for(;;)
  1098. {
  1099. if(ChildItem == NULL)
  1100. break;
  1101. if(ChildItem != layeritem)
  1102. {
  1103. if(layername == m_MyWorkBar.pTree->GetItemText(ChildItem))
  1104. {
  1105. flag = FALSE;
  1106. MessageBox("图层名不能重复", "错误", MB_OK | MB_ICONERROR);
  1107. break;
  1108. }
  1109. }
  1110. ChildItem = m_MyWorkBar.pTree->GetNextSiblingItem(ChildItem);
  1111. }
  1112. }
  1113. while(flag == FALSE);
  1114. m_MyWorkBar.pTree->SetItemText(layeritem, layername);
  1115. }
  1116. void CMainFrame::OnFileAddlayer() 
  1117. {
  1118. HTREEITEM fileitem = m_MyWorkBar.pTree->GetSelectedItem();
  1119. DWORD data = m_MyWorkBar.pTree->GetItemData(fileitem);
  1120. ASSERT(data == TREE_FILE_ITEM);
  1121. CString filename =  m_MyWorkBar.pTree->GetItemText(fileitem);
  1122. HTREEITEM layeritem = m_MyWorkBar.pTree->InsertLayer(fileitem, "基层", ICON_LAYER);
  1123. m_MyWorkBar.pTree->SelectItem(layeritem);
  1124. OnLayerAttribute();
  1125. CString layername = m_MyWorkBar.pTree->GetItemText(layeritem);
  1126. CMiniCADDoc* pDoc = GetDocument(filename);
  1127.     pDoc->m_ManageFileLayer.AddLayer(layername, TRUE, FALSE);
  1128. }
  1129. //////////////////////////////////////////////////////////////////////////////////////////
  1130. //
  1131. BOOL CMainFrame::OpenProject(CString PathName)
  1132. {
  1133. int index;
  1134. CFile fp;
  1135. fp.Open(PathName, CFile::modeCreate | CFile::modeNoTruncate 
  1136.     | CFile::modeRead); 
  1137. if(fp == 0)
  1138. {
  1139. MessageBox("打开项目文件错误",
  1140. "错误", MB_OK | MB_ICONERROR);
  1141. return FALSE;
  1142. }
  1143.    
  1144. CArchive ar(&fp, CArchive::load);
  1145.     pApp->ProjectInfo.Serialize(ar);
  1146. //显示树形控件,插入根项
  1147. m_MyWorkBar.pTree->InsertProject(pApp->ProjectInfo.Name);
  1148. m_MyWorkBar.pTree->ShowWindow(TRUE);
  1149. //项目文档数置0,如果打开文档成功,项目文档数中增加1
  1150. for(index = 0; index < pApp->ProjectInfo.GetFileIndexNum(); index++)
  1151. {
  1152. //注意如果文件不存在,在CScrollView创建时会出错,现在
  1153. //还不知道预先处理错误的方法
  1154. CFileIndex* pFileIndex =  pApp->ProjectInfo.GetFileIndex(index);
  1155. PathName = pFileIndex->GetFilePath() + "\" + pFileIndex->GetFileName();
  1156. //打开图纸文件
  1157. ASSERT(pApp->OpenDocumentFile(PathName) != NULL);
  1158. CChildFrame* pChildWnd = (CChildFrame*)this->MDIGetActive();
  1159. CMiniCADDoc* pDoc = (CMiniCADDoc*)pChildWnd->GetActiveDocument();
  1160.         //插入图纸项
  1161. HTREEITEM fileitem = m_MyWorkBar.pTree->InsertFile(pDoc->FileInfo.m_Name);
  1162.         
  1163. //插入图层项
  1164. for(int i = 0; i < (int)pDoc->m_ManageFileLayer.GetLayerNum(); i++)
  1165. {
  1166. CFileLayer* pLayer = pDoc->m_ManageFileLayer.GetLayer(i);
  1167. if(pLayer->IsShow() && !pLayer->IsLocked())
  1168. {
  1169. if(pLayer->GetName() == pDoc->m_ManageFileLayer.GetCurrentLayerName())
  1170. m_MyWorkBar.pTree->InsertLayer(fileitem, pLayer->GetName(), ICON_CURRENTLAYER);
  1171. else
  1172. m_MyWorkBar.pTree->InsertLayer(fileitem, pLayer->GetName(), ICON_LAYER);
  1173. }
  1174. if(pLayer->IsShow() && pLayer->IsLocked())
  1175. {
  1176. if(pLayer->GetName() == pDoc->m_ManageFileLayer.GetCurrentLayerName())
  1177. m_MyWorkBar.pTree->InsertLayer(fileitem, pLayer->GetName(), ICON_CURRENTLOCKLAYER);
  1178. else
  1179. m_MyWorkBar.pTree->InsertLayer(fileitem, pLayer->GetName(), ICON_LOCKLAYER);
  1180. }
  1181. if(!pLayer->IsShow() && !pLayer->IsLocked())
  1182. {
  1183. if(pLayer->GetName() == pDoc->m_ManageFileLayer.GetCurrentLayerName())
  1184. m_MyWorkBar.pTree->InsertLayer(fileitem, pLayer->GetName(), ICON_CURRENTHIDELAYER);
  1185. else
  1186. m_MyWorkBar.pTree->InsertLayer(fileitem, pLayer->GetName(), ICON_HIDELAYER);
  1187. }
  1188. if(!pLayer->IsShow() && pLayer->IsLocked())
  1189. {
  1190. if(pLayer->GetName() == pDoc->m_ManageFileLayer.GetCurrentLayerName())
  1191. m_MyWorkBar.pTree->InsertLayer(fileitem, pLayer->GetName(), ICON_CURRENTLOCKHIDELAYER);
  1192. else
  1193. m_MyWorkBar.pTree->InsertLayer(fileitem, pLayer->GetName(), ICON_LOCKHIDELAYER);
  1194. }
  1195. }
  1196. }
  1197.     //关闭文件
  1198. fp.Close();
  1199. return TRUE;
  1200. }
  1201. CMiniCADDoc*  CMainFrame::GetDocument(CString filename)
  1202. {
  1203. CMultiDocTemplate* pDocTemplate;
  1204.     CMiniCADDoc* pDoc;
  1205. POSITION DocTemplatePosition;
  1206. POSITION DocPosition;
  1207. //获取文档模板
  1208. DocTemplatePosition = pApp->GetFirstDocTemplatePosition();
  1209. pDocTemplate = (CMultiDocTemplate*)pApp->GetNextDocTemplate(DocTemplatePosition);
  1210. ASSERT(pDocTemplate != NULL);
  1211. DocPosition = pDocTemplate->GetFirstDocPosition();
  1212. while(DocPosition != NULL)
  1213. {
  1214. pDoc = (CMiniCADDoc*)pDocTemplate->GetNextDoc(DocPosition);
  1215. if(filename == pDoc->FileInfo.m_Name)
  1216. return pDoc;
  1217. }
  1218. return NULL;
  1219. }