- // MiniCADDoc.cpp : implementation of the CMiniCADDoc class
- //
- #include "stdafx.h"
- #include "MiniCADDoc.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CMiniCADDoc
- IMPLEMENT_DYNCREATE(CMiniCADDoc, CDocument)
- BEGIN_MESSAGE_MAP(CMiniCADDoc, CDocument)
- //{{AFX_MSG_MAP(CMiniCADDoc)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////////////////
- // CMiniCADDoc construction/destruction
- CMiniCADDoc::CMiniCADDoc()
- {
- //初始化
- pApp = (CMiniCADApp*)AfxGetApp();
- PenColor = pApp->CADInfo.PenColor;
- LineStyle = pApp->CADInfo.LineStyle;
- BackColor = pApp->CADInfo.BackColor;
- //设置当前省缺命令为DRAW_SELECT
- CurrentCommand = DRAW_SELECT;
- DocumentIndex = 0;
- m_ManageGraphObject.Initialize(LineStyle, PenColor);
- m_ManageGraphObject.GetCommandStack(&m_CommandStack);
- }
- CMiniCADDoc::~CMiniCADDoc()
- {
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMiniCADDoc serialization
- void CMiniCADDoc::Serialize(CArchive& ar)
- {
- if (ar.IsStoring())
- {
- // TODO: add storing code here
- }
- else
- {
- // TODO: add loading code here
- }
- FileInfo.Serialize(ar);
- m_ManageGraphObject.Serialize(ar);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMiniCADDoc diagnostics
- #ifdef _DEBUG
- void CMiniCADDoc::AssertValid() const
- {
- CDocument::AssertValid();
- }
- void CMiniCADDoc::Dump(CDumpContext& dc) const
- {
- CDocument::Dump(dc);
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CMiniCADDoc commands
- BOOL CMiniCADDoc::OnNewDocument()
- {
- if (!CDocument::OnNewDocument())
- return FALSE;
- //获取新建文档的信息
- FileInfo = pApp->NewFileInfo;
- //改写最近文件列表
- pApp->pRecentFileList->Add((LPCTSTR)(FileInfo.FilePath + "\" + FileInfo.FileName));
- pApp->pRecentFileList->WriteList();
- return TRUE;
- }
- BOOL CMiniCADDoc::OnOpenDocument(LPCTSTR lpszPathName)
- {
- if (!CDocument::OnOpenDocument(lpszPathName))
- return FALSE;
- pApp->pRecentFileList->Add((LPCTSTR)(FileInfo.FilePath + "\" + FileInfo.FileName));
- pApp->pRecentFileList->WriteList();
- return TRUE;
- }
- void CMiniCADDoc::OnCloseDocument()
- {
- CDocument::OnCloseDocument();
- }
- BOOL CMiniCADDoc::SaveDocument()
- {
- // TODO: Add your specialized code here and/or call the base class
- /*
- int index;
- CMyObjectInfo* pLineInfo;
- CMyObjectInfo* pRectInfo;
- CMyObjectInfo* pCircleInfo;
- CMyObjectInfo* pArcInfo;
- index = 0;
- while(index < m_ManageGraphObject.m_LineInfoArray.GetSize())
- {
- pLineInfo = (CMyObjectInfo*)m_ManageGraphObject.m_LineInfoArray.GetAt(index);
- if(pLineInfo->m_del == TRUE)
- {
- delete (CMyLine*)m_ManageGraphObject.m_LineArray.GetAt(index);
- m_ManageGraphObject.m_LineArray.RemoveAt(index);
- delete (CMyObjectInfo*)m_ManageGraphObject.m_LineInfoArray.GetAt(index);
- m_ManageGraphObject.m_LineInfoArray.RemoveAt(index);
- }
- else
- index++;
- }
- index = 0;
- while(index < m_ManageGraphObject.m_RectInfoArray.GetSize())
- {
- pRectInfo = (CMyObjectInfo*)m_ManageGraphObject.m_RectInfoArray.GetAt(index);
- if(pRectInfo->m_del == TRUE)
- {
- delete (CMyRect*)m_ManageGraphObject.m_RectArray.GetAt(index);
- m_ManageGraphObject.m_RectArray.RemoveAt(index);
- delete (CMyObjectInfo*)m_ManageGraphObject.m_RectInfoArray.GetAt(index);
- m_ManageGraphObject.m_RectInfoArray.RemoveAt(index);
- }
- else
- index++;
- }
- index = 0;
- while(index < m_ManageGraphObject.m_CircleInfoArray.GetSize())
- {
- pCircleInfo = (CMyObjectInfo*)m_ManageGraphObject.m_CircleInfoArray.GetAt(index);
- if(pCircleInfo->m_del == TRUE)
- {
- delete (CMyCircle*)m_ManageGraphObject.m_CircleArray.GetAt(index);
- m_ManageGraphObject.m_CircleArray.RemoveAt(index);
- delete (CMyObjectInfo*)m_ManageGraphObject.m_CircleInfoArray.GetAt(index);
- m_ManageGraphObject.m_CircleInfoArray.RemoveAt(index);
- }
- else
- index++;
- }
- index = 0;
- while(index < m_ManageGraphObject.m_ArcInfoArray.GetSize())
- {
- pArcInfo = (CMyObjectInfo*)m_ManageGraphObject.m_ArcInfoArray.GetAt(index);
- if(pArcInfo->m_del == TRUE)
- {
- delete (CMyArc*)m_ManageGraphObject.m_ArcArray.GetAt(index);
- m_ManageGraphObject.m_ArcArray.RemoveAt(index);
- delete (CMyObjectInfo*)m_ManageGraphObject.m_ArcInfoArray.GetAt(index);
- m_ManageGraphObject.m_ArcInfoArray.RemoveAt(index);
- }
- else
- index++;
- }
- for(index = 0; index < MyCommand.m_CommandArray.GetSize(); index++)
- delete (CMyCommandStruct*)MyCommand.m_CommandArray.GetAt(index);
- MyCommand.m_CommandArray.RemoveAll();
- MyCommand.CommandPointer = -1;
- */
- CString PathName = FileInfo.FilePath + "\" + FileInfo.FileName;
- return CDocument::OnSaveDocument(PathName);
- }