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. pApp = (CMiniCADApp*)AfxGetApp();
  23. DocumentIndex = 0;
  24.      
  25. m_HandleCommand.Intialize(pApp->CADInfo.PenColor, pApp->CADInfo.LineStyle);
  26. }
  27. CMiniCADDoc::~CMiniCADDoc()
  28. {
  29. }
  30. /////////////////////////////////////////////////////////////////////////////
  31. // CMiniCADDoc serialization
  32. void CMiniCADDoc::Serialize(CArchive& ar)
  33. {
  34. if (ar.IsStoring())
  35. {
  36. // TODO: add storing code here
  37. }
  38. else
  39. {
  40. // TODO: add loading code here
  41. }
  42. FileInfo.Serialize(ar);
  43. m_HandleCommand.m_OperateObject.Serialize(ar);
  44. }
  45. /////////////////////////////////////////////////////////////////////////////
  46. // CMiniCADDoc diagnostics
  47. #ifdef _DEBUG
  48. void CMiniCADDoc::AssertValid() const
  49. {
  50. CDocument::AssertValid();
  51. }
  52. void CMiniCADDoc::Dump(CDumpContext& dc) const
  53. {
  54. CDocument::Dump(dc);
  55. }
  56. #endif //_DEBUG
  57. /////////////////////////////////////////////////////////////////////////////
  58. // CMiniCADDoc commands
  59. BOOL CMiniCADDoc::OnNewDocument()
  60. {
  61. if (!CDocument::OnNewDocument())
  62. return FALSE;
  63. //获取新建文档的信息
  64. FileInfo = pApp->NewFileInfo;
  65.     
  66. //改写最近文件列表
  67. pApp->pRecentFileList->Add((LPCTSTR)(FileInfo.FilePath + "\" + FileInfo.FileName));
  68. pApp->pRecentFileList->WriteList();
  69. return TRUE;
  70. }
  71. BOOL CMiniCADDoc::OnOpenDocument(LPCTSTR lpszPathName) 
  72. {
  73. if (!CDocument::OnOpenDocument(lpszPathName))
  74. return FALSE;
  75. pApp->pRecentFileList->Add((LPCTSTR)(FileInfo.FilePath + "\" + FileInfo.FileName));
  76. pApp->pRecentFileList->WriteList();
  77. return TRUE;
  78. }
  79. void CMiniCADDoc::OnCloseDocument() 
  80. {
  81. CDocument::OnCloseDocument();
  82. }
  83. BOOL CMiniCADDoc::SaveDocument() 
  84. {
  85. // TODO: Add your specialized code here and/or call the base class
  86. /*
  87.     int index;
  88. CMyObjectInfo* pLineInfo;
  89. CMyObjectInfo* pRectInfo;
  90. CMyObjectInfo* pCircleInfo;
  91. CMyObjectInfo* pArcInfo;
  92. index = 0;
  93. while(index < m_OperateObject.m_LineInfoArray.GetSize())
  94. {
  95. pLineInfo = (CMyObjectInfo*)m_OperateObject.m_LineInfoArray.GetAt(index);
  96. if(pLineInfo->m_del == TRUE)
  97. {
  98. delete (CMyLine*)m_OperateObject.m_LineArray.GetAt(index);
  99. m_OperateObject.m_LineArray.RemoveAt(index);
  100. delete (CMyObjectInfo*)m_OperateObject.m_LineInfoArray.GetAt(index);
  101. m_OperateObject.m_LineInfoArray.RemoveAt(index);
  102. }
  103. else
  104. index++;
  105. }
  106. index = 0;
  107. while(index < m_OperateObject.m_RectInfoArray.GetSize())
  108. {
  109. pRectInfo = (CMyObjectInfo*)m_OperateObject.m_RectInfoArray.GetAt(index);
  110. if(pRectInfo->m_del == TRUE)
  111. {
  112. delete (CMyRect*)m_OperateObject.m_RectArray.GetAt(index);
  113. m_OperateObject.m_RectArray.RemoveAt(index);
  114. delete (CMyObjectInfo*)m_OperateObject.m_RectInfoArray.GetAt(index);
  115. m_OperateObject.m_RectInfoArray.RemoveAt(index);
  116. }
  117. else
  118. index++;
  119. }
  120. index = 0;
  121. while(index < m_OperateObject.m_CircleInfoArray.GetSize())
  122. {
  123. pCircleInfo = (CMyObjectInfo*)m_OperateObject.m_CircleInfoArray.GetAt(index);
  124. if(pCircleInfo->m_del == TRUE)
  125. {
  126. delete (CMyCircle*)m_OperateObject.m_CircleArray.GetAt(index);
  127. m_OperateObject.m_CircleArray.RemoveAt(index);
  128. delete (CMyObjectInfo*)m_OperateObject.m_CircleInfoArray.GetAt(index);
  129. m_OperateObject.m_CircleInfoArray.RemoveAt(index);
  130. }
  131. else
  132. index++;
  133. }
  134. index = 0;
  135. while(index < m_OperateObject.m_ArcInfoArray.GetSize())
  136. {
  137. pArcInfo = (CMyObjectInfo*)m_OperateObject.m_ArcInfoArray.GetAt(index);
  138. if(pArcInfo->m_del == TRUE)
  139. {
  140. delete (CMyArc*)m_OperateObject.m_ArcArray.GetAt(index);
  141. m_OperateObject.m_ArcArray.RemoveAt(index);
  142. delete (CMyObjectInfo*)m_OperateObject.m_ArcInfoArray.GetAt(index);
  143. m_OperateObject.m_ArcInfoArray.RemoveAt(index);
  144. }
  145. else
  146. index++;
  147. }
  148.     for(index = 0; index < MyCommand.m_CommandArray.GetSize(); index++)
  149. delete (CMyCommandStruct*)MyCommand.m_CommandArray.GetAt(index);
  150. MyCommand.m_CommandArray.RemoveAll();
  151.     MyCommand.CommandPointer = -1;
  152. */
  153. CString PathName = FileInfo.FilePath + "\" + FileInfo.FileName;
  154. return CDocument::OnSaveDocument(PathName);
  155. }