- // 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();
- //设置当前省缺命令为NO_COMMAND
- CurrentCommand = NO_COMMAND;
- DocumentReady = FALSE;
- }
- CMiniCADDoc::~CMiniCADDoc()
- {
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMiniCADDoc serialization
- void CMiniCADDoc::Serialize(CArchive& ar)
- {
- if (ar.IsStoring())
- {
- }
- else
- {
- }
- FileInfo.Serialize(ar);
- m_ManageFileLayer.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;
- DocumentReady = TRUE;
- //获取新建文档的信息
- FileInfo = pApp->NewFileInfo;
- //改写最近文件列表
- pApp->pRecentFileList->Add((LPCTSTR)(FileInfo.m_FilePath + "\" + FileInfo.m_FileName));
- pApp->pRecentFileList->WriteList();
- FileInfo.m_PenColor = pApp->CADInfo.PenColor;
- FileInfo.m_LineStyle = pApp->CADInfo.LineStyle;
- FileInfo.m_BackColor = pApp->CADInfo.BackColor;
- SIZE size;
- size.cx = FileInfo.m_Size.cx + EXTRA_WIDTH * 2;
- size.cy = FileInfo.m_Size.cy + EXTRA_HIGTH * 2;
- m_ManageGraphObject.Initialize(size, FileInfo.m_LineStyle, FileInfo.m_PenColor);
- m_ManageGraphObject.GetCommandStack(&m_CommandStack);
- m_ManageGraphObject.GetManageFileLayer(&m_ManageFileLayer);
- return TRUE;
- }
- BOOL CMiniCADDoc::OnOpenDocument(LPCTSTR lpszPathName)
- {
- if (!CDocument::OnOpenDocument(lpszPathName))
- return FALSE;
- DocumentReady = TRUE;
- pApp->pRecentFileList->Add((LPCTSTR)(FileInfo.m_FilePath + "\" + FileInfo.m_FileName));
- pApp->pRecentFileList->WriteList();
- SIZE size;
- size.cx = FileInfo.m_Size.cx + EXTRA_WIDTH * 2;
- size.cy = FileInfo.m_Size.cy + EXTRA_HIGTH * 2;
- m_ManageGraphObject.Initialize(size, FileInfo.m_LineStyle, FileInfo.m_PenColor);
- m_ManageGraphObject.GetCommandStack(&m_CommandStack);
- m_ManageGraphObject.GetManageFileLayer(&m_ManageFileLayer);
- return TRUE;
- }
- void CMiniCADDoc::OnCloseDocument()
- {
- CDocument::OnCloseDocument();
- }
- BOOL CMiniCADDoc::SaveDocument()
- {
- int index = 0;
- CGraphObjectInfo* pLineInfo;
- CGraphObjectInfo* pRectInfo;
- CGraphObjectInfo* pCircleInfo;
- CGraphObjectInfo* pArcInfo;
- //将所有被临时删除的图形对象真正删除
- while(index < m_ManageGraphObject.m_LineInfoArray.GetSize())
- {
- pLineInfo = (CGraphObjectInfo*)m_ManageGraphObject.m_LineInfoArray.GetAt(index);
- if(pLineInfo->m_del == TRUE)
- m_ManageGraphObject.DelLine(index);
- else
- index++;
- }
- index = 0;
- while(index < m_ManageGraphObject.m_RectInfoArray.GetSize())
- {
- pRectInfo = (CGraphObjectInfo*)m_ManageGraphObject.m_RectInfoArray.GetAt(index);
- if(pRectInfo->m_del == TRUE)
- m_ManageGraphObject.DelRect(index);
- else
- index++;
- }
- index = 0;
- while(index < m_ManageGraphObject.m_CircleInfoArray.GetSize())
- {
- pCircleInfo = (CGraphObjectInfo*)m_ManageGraphObject.m_CircleInfoArray.GetAt(index);
- if(pCircleInfo->m_del == TRUE)
- m_ManageGraphObject.DelCircle(index);
- else
- index++;
- }
- index = 0;
- while(index < m_ManageGraphObject.m_ArcInfoArray.GetSize())
- {
- pArcInfo = (CGraphObjectInfo*)m_ManageGraphObject.m_ArcInfoArray.GetAt(index);
- if(pArcInfo->m_del == TRUE)
- m_ManageGraphObject.DelArc(index);
- else
- index++;
- }
- //清空命令堆栈
- m_CommandStack.RemoveAll();
- CString PathName = FileInfo.m_FilePath + "\" + FileInfo.m_FileName;
- return CDocument::OnSaveDocument(PathName);
- }