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

绘图程序

开发平台:

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. //设置当前省缺命令为NO_COMMAND
  25. CurrentCommand = NO_COMMAND;
  26. DocumentReady = FALSE;
  27. }
  28. CMiniCADDoc::~CMiniCADDoc()
  29. {
  30. }
  31. /////////////////////////////////////////////////////////////////////////////
  32. // CMiniCADDoc serialization
  33. void CMiniCADDoc::Serialize(CArchive& ar)
  34. {
  35. if (ar.IsStoring())
  36. {
  37. }
  38. else
  39. {
  40. }
  41. FileInfo.Serialize(ar);
  42. m_ManageFileLayer.Serialize(ar);
  43. m_ManageGraphObject.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. DocumentReady = TRUE;
  64. //获取新建文档的信息
  65. FileInfo = pApp->NewFileInfo;
  66.     
  67. //改写最近文件列表
  68. pApp->pRecentFileList->Add((LPCTSTR)(FileInfo.m_FilePath + "\" + FileInfo.m_FileName));
  69. pApp->pRecentFileList->WriteList();
  70. FileInfo.m_PenColor = pApp->CADInfo.PenColor;      
  71. FileInfo.m_LineStyle = pApp->CADInfo.LineStyle;     
  72. FileInfo.m_BackColor = pApp->CADInfo.BackColor;   
  73. SIZE size;
  74. size.cx = FileInfo.m_Size.cx + EXTRA_WIDTH * 2; 
  75. size.cy = FileInfo.m_Size.cy + EXTRA_HIGTH * 2;
  76. m_ManageGraphObject.Initialize(size, FileInfo.m_LineStyle, FileInfo.m_PenColor);
  77. m_ManageGraphObject.GetCommandStack(&m_CommandStack);
  78. m_ManageGraphObject.GetManageFileLayer(&m_ManageFileLayer);
  79. return TRUE;
  80. }
  81. BOOL CMiniCADDoc::OnOpenDocument(LPCTSTR lpszPathName) 
  82. {
  83. if (!CDocument::OnOpenDocument(lpszPathName))
  84. return FALSE;
  85. DocumentReady = TRUE;
  86. pApp->pRecentFileList->Add((LPCTSTR)(FileInfo.m_FilePath + "\" + FileInfo.m_FileName));
  87. pApp->pRecentFileList->WriteList();
  88. SIZE size;
  89. size.cx = FileInfo.m_Size.cx + EXTRA_WIDTH * 2; 
  90. size.cy = FileInfo.m_Size.cy + EXTRA_HIGTH * 2;
  91. m_ManageGraphObject.Initialize(size, FileInfo.m_LineStyle, FileInfo.m_PenColor);
  92.     m_ManageGraphObject.GetCommandStack(&m_CommandStack);
  93. m_ManageGraphObject.GetManageFileLayer(&m_ManageFileLayer);
  94. return TRUE;
  95. }
  96. void CMiniCADDoc::OnCloseDocument() 
  97. {
  98. CDocument::OnCloseDocument();
  99. }
  100. BOOL CMiniCADDoc::SaveDocument() 
  101. {
  102.     int index = 0;
  103. CGraphObjectInfo* pLineInfo;
  104. CGraphObjectInfo* pRectInfo;
  105. CGraphObjectInfo* pCircleInfo;
  106. CGraphObjectInfo* pArcInfo;
  107. //将所有被临时删除的图形对象真正删除
  108. while(index < m_ManageGraphObject.m_LineInfoArray.GetSize())
  109. {
  110. pLineInfo = (CGraphObjectInfo*)m_ManageGraphObject.m_LineInfoArray.GetAt(index);
  111. if(pLineInfo->m_del == TRUE)
  112. m_ManageGraphObject.DelLine(index);
  113. else
  114. index++;
  115. }
  116. index = 0;
  117. while(index < m_ManageGraphObject.m_RectInfoArray.GetSize())
  118. {
  119. pRectInfo = (CGraphObjectInfo*)m_ManageGraphObject.m_RectInfoArray.GetAt(index);
  120. if(pRectInfo->m_del == TRUE)
  121. m_ManageGraphObject.DelRect(index);
  122. else
  123. index++;
  124. }
  125. index = 0;
  126. while(index < m_ManageGraphObject.m_CircleInfoArray.GetSize())
  127. {
  128. pCircleInfo = (CGraphObjectInfo*)m_ManageGraphObject.m_CircleInfoArray.GetAt(index);
  129. if(pCircleInfo->m_del == TRUE)
  130.     m_ManageGraphObject.DelCircle(index); 
  131. else
  132. index++;
  133. }
  134. index = 0;
  135. while(index < m_ManageGraphObject.m_ArcInfoArray.GetSize())
  136. {
  137. pArcInfo = (CGraphObjectInfo*)m_ManageGraphObject.m_ArcInfoArray.GetAt(index);
  138. if(pArcInfo->m_del == TRUE)
  139. m_ManageGraphObject.DelArc(index); 
  140. else
  141. index++;
  142. }
  143. //清空命令堆栈
  144.     m_CommandStack.RemoveAll();
  145.     
  146. CString PathName = FileInfo.m_FilePath + "\" + FileInfo.m_FileName;
  147. return CDocument::OnSaveDocument(PathName);
  148. }