Graph.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // CGraph.cpp: implementation of the CGraph class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "drawobj.h"
  6. #include "./graph.h"
  7. //---------------------------------------------- CGraph ---------
  8. CGraph::CGraph(CSize size)
  9. {
  10. m_Type = 1;
  11. m_sizePic.cx = size.cx;
  12. m_sizePic.cy = size.cy;
  13. m_bGrid = FALSE;
  14. m_sizeGrid.cx = 40;
  15. m_sizeGrid.cy = 40;
  16. m_clrBack = RGB(230, 241, 249);//RGB(255, 255, 255);//RGB(92, 92, 92);
  17. }
  18. CGraph::~CGraph(void)
  19. {
  20. #if GRAPH_DEBUG
  21. if(!m_DrawObjList.IsEmpty())
  22. {
  23. for(POSITION pos = m_DrawObjList.GetHeadPosition();pos!=NULL;)
  24. {
  25. POSITION pos1 = pos ; //要在这里做一个备份
  26. CDrawObj *ct = (CDrawObj *)m_DrawObjList.GetNext(pos);//他会改变 pos的值
  27. m_DrawObjList.RemoveAt(pos1);
  28. delete ct;
  29. }
  30. m_DrawObjList.RemoveAll();
  31. ASSERT(m_DrawObjList.IsEmpty());
  32. }
  33. #else
  34. POSITION pos = m_DrawObjList.GetHeadPosition();
  35. while(pos!=NULL) delete m_DrawObjList.GetNext(pos);
  36. m_DrawObjList.RemoveAll();
  37. #endif
  38. }
  39. void CGraph::SetPicFile(CString strPicFile)
  40. {
  41. m_strPicFile = strPicFile;
  42. }
  43. void CGraph::Load(void)
  44. {
  45. #if GRAPH_DEBUG
  46. if(!m_DrawObjList.IsEmpty())
  47. {
  48. for(POSITION pos = m_DrawObjList.GetHeadPosition();pos!=NULL;)
  49. {
  50. POSITION pos1 = pos ; //要在这里做一个备份
  51. CDrawObj *ct = (CDrawObj *)m_DrawObjList.GetNext(pos);//他会改变 pos的值
  52. m_DrawObjList.RemoveAt(pos1);
  53. delete ct;
  54. }
  55. m_DrawObjList.RemoveAll();
  56. ASSERT(m_DrawObjList.IsEmpty());
  57. }
  58. #else
  59. POSITION pos = m_DrawObjList.GetHeadPosition();
  60. while(pos!=NULL) delete m_DrawObjList.GetNext(pos);
  61. m_DrawObjList.RemoveAll();
  62. #endif
  63. CFile file;
  64. if(file.Open(m_strPicFile,CFile::modeRead))
  65. {
  66. CArchive ar(&file,CArchive::load);
  67. ar >> m_Type;
  68. ar >> m_sizePic;
  69. ar >> m_sizeGrid;
  70. ar >> m_bGrid;
  71. ar >> m_clrBack;
  72. m_DrawObjList.Serialize(ar);
  73. ar.Close();
  74. file.Close();
  75. }
  76. }
  77. void CGraph::Store(void)
  78. {
  79. CFile file;
  80. if(file.Open(m_strPicFile,CFile::modeCreate|CFile::modeWrite))
  81. {
  82. CArchive ar(&file,CArchive::store);
  83. ar << m_Type;
  84. ar << m_sizePic;
  85. ar << m_sizeGrid;
  86. ar << m_bGrid;
  87. ar << m_clrBack;
  88. m_DrawObjList.Serialize(ar);
  89. ar.Flush();
  90. ar.Close();
  91. file.Flush();
  92. file.Close();
  93. }
  94. }