123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- // CGraph.cpp: implementation of the CGraph class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "drawobj.h"
- #include "./graph.h"
- //---------------------------------------------- CGraph ---------
- CGraph::CGraph(CSize size)
- {
- m_Type = 1;
- m_sizePic.cx = size.cx;
- m_sizePic.cy = size.cy;
- m_bGrid = FALSE;
- m_sizeGrid.cx = 40;
- m_sizeGrid.cy = 40;
- m_clrBack = RGB(230, 241, 249);//RGB(255, 255, 255);//RGB(92, 92, 92);
- }
- CGraph::~CGraph(void)
- {
- #if GRAPH_DEBUG
- if(!m_DrawObjList.IsEmpty())
- {
- for(POSITION pos = m_DrawObjList.GetHeadPosition();pos!=NULL;)
- {
- POSITION pos1 = pos ; //要在这里做一个备份
- CDrawObj *ct = (CDrawObj *)m_DrawObjList.GetNext(pos);//他会改变 pos的值
- m_DrawObjList.RemoveAt(pos1);
- delete ct;
- }
- m_DrawObjList.RemoveAll();
- ASSERT(m_DrawObjList.IsEmpty());
- }
- #else
- POSITION pos = m_DrawObjList.GetHeadPosition();
- while(pos!=NULL) delete m_DrawObjList.GetNext(pos);
- m_DrawObjList.RemoveAll();
- #endif
- }
- void CGraph::SetPicFile(CString strPicFile)
- {
- m_strPicFile = strPicFile;
- }
- void CGraph::Load(void)
- {
- #if GRAPH_DEBUG
- if(!m_DrawObjList.IsEmpty())
- {
- for(POSITION pos = m_DrawObjList.GetHeadPosition();pos!=NULL;)
- {
- POSITION pos1 = pos ; //要在这里做一个备份
- CDrawObj *ct = (CDrawObj *)m_DrawObjList.GetNext(pos);//他会改变 pos的值
- m_DrawObjList.RemoveAt(pos1);
- delete ct;
- }
- m_DrawObjList.RemoveAll();
- ASSERT(m_DrawObjList.IsEmpty());
- }
- #else
- POSITION pos = m_DrawObjList.GetHeadPosition();
- while(pos!=NULL) delete m_DrawObjList.GetNext(pos);
- m_DrawObjList.RemoveAll();
- #endif
- CFile file;
- if(file.Open(m_strPicFile,CFile::modeRead))
- {
- CArchive ar(&file,CArchive::load);
- ar >> m_Type;
- ar >> m_sizePic;
- ar >> m_sizeGrid;
- ar >> m_bGrid;
- ar >> m_clrBack;
- m_DrawObjList.Serialize(ar);
- ar.Close();
- file.Close();
- }
- }
- void CGraph::Store(void)
- {
- CFile file;
- if(file.Open(m_strPicFile,CFile::modeCreate|CFile::modeWrite))
- {
- CArchive ar(&file,CArchive::store);
- ar << m_Type;
- ar << m_sizePic;
- ar << m_sizeGrid;
- ar << m_bGrid;
- ar << m_clrBack;
- m_DrawObjList.Serialize(ar);
- ar.Flush();
- ar.Close();
- file.Flush();
- file.Close();
- }
- }
|