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

绘图程序

开发平台:

Visual C++

  1. // MiniCADDoc.cpp : implementation of the CMiniCADDoc class
  2. //
  3. #include "stdafx.h"
  4. #include "MiniCADDoc.h"
  5. #ifdef _DEBUG
  6. #define new DEBUG_NEW
  7. #undef THIS_FILE
  8. static char THIS_FILE[] = __FILE__;
  9. #endif
  10. /////////////////////////////////////////////////////////////////////////////
  11. // CMiniCADDoc
  12. IMPLEMENT_DYNCREATE(CMiniCADDoc, CDocument)
  13. BEGIN_MESSAGE_MAP(CMiniCADDoc, CDocument)
  14. //{{AFX_MSG_MAP(CMiniCADDoc)
  15. //}}AFX_MSG_MAP
  16. END_MESSAGE_MAP()
  17. /////////////////////////////////////////////////////////////////////////////
  18. /////////////////////////////////////////////////////////////////////////////
  19. // CMiniCADDoc construction/destruction
  20. CMiniCADDoc::CMiniCADDoc()
  21. {
  22. //初始化
  23. pApp = (CMiniCADApp*)AfxGetApp();
  24. PenColor = pApp->CADInfo.PenColor;      
  25. LineStyle = pApp->CADInfo.LineStyle;     
  26. BackColor = pApp->CADInfo.BackColor;   
  27. //设置当前省缺命令为DRAW_SELECT
  28. CurrentCommand = DRAW_SELECT;
  29. DocumentIndex = 0;
  30. m_ManageGraphObject.Initialize(LineStyle, PenColor);
  31. m_ManageGraphObject.GetCommandStack(&m_CommandStack);
  32. }
  33. CMiniCADDoc::~CMiniCADDoc()
  34. {
  35. }
  36. /////////////////////////////////////////////////////////////////////////////
  37. // CMiniCADDoc serialization
  38. void CMiniCADDoc::Serialize(CArchive& ar)
  39. {
  40. if (ar.IsStoring())
  41. {
  42. // TODO: add storing code here
  43. }
  44. else
  45. {
  46. // TODO: add loading code here
  47. }
  48. FileInfo.Serialize(ar);
  49. m_ManageGraphObject.Serialize(ar);
  50. }
  51. /////////////////////////////////////////////////////////////////////////////
  52. // CMiniCADDoc diagnostics
  53. #ifdef _DEBUG
  54. void CMiniCADDoc::AssertValid() const
  55. {
  56. CDocument::AssertValid();
  57. }
  58. void CMiniCADDoc::Dump(CDumpContext& dc) const
  59. {
  60. CDocument::Dump(dc);
  61. }
  62. #endif //_DEBUG
  63. /////////////////////////////////////////////////////////////////////////////
  64. // CMiniCADDoc commands
  65. BOOL CMiniCADDoc::OnNewDocument()
  66. {
  67. if (!CDocument::OnNewDocument())
  68. return FALSE;
  69. //获取新建文档的信息
  70. FileInfo = pApp->NewFileInfo;
  71.     
  72. //改写最近文件列表
  73. pApp->pRecentFileList->Add((LPCTSTR)(FileInfo.FilePath + "\" + FileInfo.FileName));
  74. pApp->pRecentFileList->WriteList();
  75. return TRUE;
  76. }
  77. BOOL CMiniCADDoc::OnOpenDocument(LPCTSTR lpszPathName) 
  78. {
  79. if (!CDocument::OnOpenDocument(lpszPathName))
  80. return FALSE;
  81. pApp->pRecentFileList->Add((LPCTSTR)(FileInfo.FilePath + "\" + FileInfo.FileName));
  82. pApp->pRecentFileList->WriteList();
  83. return TRUE;
  84. }
  85. void CMiniCADDoc::OnCloseDocument() 
  86. {
  87. CDocument::OnCloseDocument();
  88. }
  89. BOOL CMiniCADDoc::SaveDocument() 
  90. {
  91. // TODO: Add your specialized code here and/or call the base class
  92. /*
  93.     int index;
  94. CMyObjectInfo* pLineInfo;
  95. CMyObjectInfo* pRectInfo;
  96. CMyObjectInfo* pCircleInfo;
  97. CMyObjectInfo* pArcInfo;
  98. index = 0;
  99. while(index < m_ManageGraphObject.m_LineInfoArray.GetSize())
  100. {
  101. pLineInfo = (CMyObjectInfo*)m_ManageGraphObject.m_LineInfoArray.GetAt(index);
  102. if(pLineInfo->m_del == TRUE)
  103. {
  104. delete (CMyLine*)m_ManageGraphObject.m_LineArray.GetAt(index);
  105. m_ManageGraphObject.m_LineArray.RemoveAt(index);
  106. delete (CMyObjectInfo*)m_ManageGraphObject.m_LineInfoArray.GetAt(index);
  107. m_ManageGraphObject.m_LineInfoArray.RemoveAt(index);
  108. }
  109. else
  110. index++;
  111. }
  112. index = 0;
  113. while(index < m_ManageGraphObject.m_RectInfoArray.GetSize())
  114. {
  115. pRectInfo = (CMyObjectInfo*)m_ManageGraphObject.m_RectInfoArray.GetAt(index);
  116. if(pRectInfo->m_del == TRUE)
  117. {
  118. delete (CMyRect*)m_ManageGraphObject.m_RectArray.GetAt(index);
  119. m_ManageGraphObject.m_RectArray.RemoveAt(index);
  120. delete (CMyObjectInfo*)m_ManageGraphObject.m_RectInfoArray.GetAt(index);
  121. m_ManageGraphObject.m_RectInfoArray.RemoveAt(index);
  122. }
  123. else
  124. index++;
  125. }
  126. index = 0;
  127. while(index < m_ManageGraphObject.m_CircleInfoArray.GetSize())
  128. {
  129. pCircleInfo = (CMyObjectInfo*)m_ManageGraphObject.m_CircleInfoArray.GetAt(index);
  130. if(pCircleInfo->m_del == TRUE)
  131. {
  132. delete (CMyCircle*)m_ManageGraphObject.m_CircleArray.GetAt(index);
  133. m_ManageGraphObject.m_CircleArray.RemoveAt(index);
  134. delete (CMyObjectInfo*)m_ManageGraphObject.m_CircleInfoArray.GetAt(index);
  135. m_ManageGraphObject.m_CircleInfoArray.RemoveAt(index);
  136. }
  137. else
  138. index++;
  139. }
  140. index = 0;
  141. while(index < m_ManageGraphObject.m_ArcInfoArray.GetSize())
  142. {
  143. pArcInfo = (CMyObjectInfo*)m_ManageGraphObject.m_ArcInfoArray.GetAt(index);
  144. if(pArcInfo->m_del == TRUE)
  145. {
  146. delete (CMyArc*)m_ManageGraphObject.m_ArcArray.GetAt(index);
  147. m_ManageGraphObject.m_ArcArray.RemoveAt(index);
  148. delete (CMyObjectInfo*)m_ManageGraphObject.m_ArcInfoArray.GetAt(index);
  149. m_ManageGraphObject.m_ArcInfoArray.RemoveAt(index);
  150. }
  151. else
  152. index++;
  153. }
  154.     for(index = 0; index < MyCommand.m_CommandArray.GetSize(); index++)
  155. delete (CMyCommandStruct*)MyCommand.m_CommandArray.GetAt(index);
  156. MyCommand.m_CommandArray.RemoveAll();
  157.     MyCommand.CommandPointer = -1;
  158. */
  159. CString PathName = FileInfo.FilePath + "\" + FileInfo.FileName;
  160. return CDocument::OnSaveDocument(PathName);
  161. }