CoreLog.cpp
上传用户:lj3531212
上传日期:2007-06-18
资源大小:346k
文件大小:2k
源码类别:

绘图程序

开发平台:

Visual C++

  1. // CoreLog.cpp: CCoreLog 
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "Core.h"
  6. #include "CoreLog.h"
  7. #include "UND_Base.h"
  8. CCoreLog::CCoreLog()
  9. {
  10. m_nUndoInfo = 0;
  11. m_nUndoUndo = 0;
  12. m_fp = NULL;
  13. m_logfile.Format("GrapgSoftTmp.log");
  14. }
  15. CCoreLog::~CCoreLog()
  16. {
  17. //空间的释放,所有的图形空间都是通过CUND_Create和CUND_Copy两个类来释放的,因为只有这两个类才会新建图形对象
  18. for (int ii = 0; ii < m_undoInfo.GetSize(); ii++)
  19. {
  20. m_undoInfo[ii]->Destroy();
  21. delete m_undoInfo[ii];
  22. }
  23. m_undoInfo.RemoveAll();
  24. CloseLog();
  25. remove(m_logfile);
  26. }
  27. void CCoreLog::OpenLog()
  28. {
  29. m_fp = fopen(m_logfile, "at");
  30. }
  31. void CCoreLog::CloseLog()
  32. {
  33. if (m_fp != NULL) {
  34. fclose(m_fp);
  35. m_fp = NULL;
  36. }
  37. }
  38. BOOL CCoreLog::WriteLogString(CString text)
  39. {
  40. FILE* fp = m_fp;
  41. if (fp == NULL)
  42. fp = fopen(m_logfile, "at");
  43. if (fp == NULL) return false;
  44. fseek(fp, 0, SEEK_END);
  45. fprintf(fp, "%sn", text);
  46. if (m_fp == NULL)
  47. fclose(fp);
  48. return true;
  49. }
  50. void CCoreLog::OnEditUndo(CCore* pCore)
  51. {
  52. if(m_nUndoUndo>0)
  53. {
  54. CUND_Base* pUndo=m_undoInfo.GetAt(m_nUndoUndo-1);
  55. pUndo->OnEditUndo(pCore);
  56. m_nUndoUndo--;
  57. }
  58. }
  59. void CCoreLog::OnEditRedo(CCore* pCore)
  60. {
  61. if(m_nUndoUndo<m_nUndoInfo)
  62. {
  63. m_nUndoUndo++;
  64. CUND_Base* pUndo=m_undoInfo.GetAt(m_nUndoUndo-1);
  65. pUndo->OnEditRedo(pCore);
  66. }
  67. }
  68. BOOL CCoreLog::IsAbleToUndo()
  69. {
  70. if (m_nUndoUndo > 0)
  71. return true;
  72. return false;
  73. }
  74. BOOL CCoreLog::IsAbleToRedo()
  75. {
  76. if (m_nUndoUndo < m_nUndoInfo)
  77. return true;
  78. return false;
  79. }
  80. void CCoreLog::AddUndoItem(CUND_Base* pUndo)
  81. {
  82. //先将后面已经撤消的撤消给删除 
  83. CUND_Base* pBase;
  84. for (int i = m_nUndoInfo-1; i > m_nUndoUndo-1; i--)
  85. {
  86. pBase = m_undoInfo[i];
  87. m_undoInfo.RemoveAt(i);
  88. delete pBase;
  89. }
  90. //将新的撤消项加到最后
  91. m_undoInfo.Add(pUndo);
  92. m_nUndoUndo++;
  93. m_nUndoInfo=m_nUndoUndo;
  94. }
  95. void CCoreLog::DelLastUndoItem()
  96. {
  97. if(m_nUndoInfo>0){
  98. CUND_Base* pBase;
  99. pBase = m_undoInfo[m_nUndoInfo-1];
  100. m_undoInfo.RemoveAt(m_nUndoInfo-1);
  101. delete pBase;
  102. m_nUndoInfo--;
  103. m_nUndoUndo--;
  104. }
  105. }
  106. //////////////////////////////////////////////////////////////////////////////////
  107. //End of File