CoreLog.cpp
资源名称:44757463.rar [点击查看]
上传用户:lj3531212
上传日期:2007-06-18
资源大小:346k
文件大小:2k
源码类别:
绘图程序
开发平台:
Visual C++
- // CoreLog.cpp: CCoreLog
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "Core.h"
- #include "CoreLog.h"
- #include "UND_Base.h"
- CCoreLog::CCoreLog()
- {
- m_nUndoInfo = 0;
- m_nUndoUndo = 0;
- m_fp = NULL;
- m_logfile.Format("GrapgSoftTmp.log");
- }
- CCoreLog::~CCoreLog()
- {
- //空间的释放,所有的图形空间都是通过CUND_Create和CUND_Copy两个类来释放的,因为只有这两个类才会新建图形对象
- for (int ii = 0; ii < m_undoInfo.GetSize(); ii++)
- {
- m_undoInfo[ii]->Destroy();
- delete m_undoInfo[ii];
- }
- m_undoInfo.RemoveAll();
- CloseLog();
- remove(m_logfile);
- }
- void CCoreLog::OpenLog()
- {
- m_fp = fopen(m_logfile, "at");
- }
- void CCoreLog::CloseLog()
- {
- if (m_fp != NULL) {
- fclose(m_fp);
- m_fp = NULL;
- }
- }
- BOOL CCoreLog::WriteLogString(CString text)
- {
- FILE* fp = m_fp;
- if (fp == NULL)
- fp = fopen(m_logfile, "at");
- if (fp == NULL) return false;
- fseek(fp, 0, SEEK_END);
- fprintf(fp, "%sn", text);
- if (m_fp == NULL)
- fclose(fp);
- return true;
- }
- void CCoreLog::OnEditUndo(CCore* pCore)
- {
- if(m_nUndoUndo>0)
- {
- CUND_Base* pUndo=m_undoInfo.GetAt(m_nUndoUndo-1);
- pUndo->OnEditUndo(pCore);
- m_nUndoUndo--;
- }
- }
- void CCoreLog::OnEditRedo(CCore* pCore)
- {
- if(m_nUndoUndo<m_nUndoInfo)
- {
- m_nUndoUndo++;
- CUND_Base* pUndo=m_undoInfo.GetAt(m_nUndoUndo-1);
- pUndo->OnEditRedo(pCore);
- }
- }
- BOOL CCoreLog::IsAbleToUndo()
- {
- if (m_nUndoUndo > 0)
- return true;
- return false;
- }
- BOOL CCoreLog::IsAbleToRedo()
- {
- if (m_nUndoUndo < m_nUndoInfo)
- return true;
- return false;
- }
- void CCoreLog::AddUndoItem(CUND_Base* pUndo)
- {
- //先将后面已经撤消的撤消给删除
- CUND_Base* pBase;
- for (int i = m_nUndoInfo-1; i > m_nUndoUndo-1; i--)
- {
- pBase = m_undoInfo[i];
- m_undoInfo.RemoveAt(i);
- delete pBase;
- }
- //将新的撤消项加到最后
- m_undoInfo.Add(pUndo);
- m_nUndoUndo++;
- m_nUndoInfo=m_nUndoUndo;
- }
- void CCoreLog::DelLastUndoItem()
- {
- if(m_nUndoInfo>0){
- CUND_Base* pBase;
- pBase = m_undoInfo[m_nUndoInfo-1];
- m_undoInfo.RemoveAt(m_nUndoInfo-1);
- delete pBase;
- m_nUndoInfo--;
- m_nUndoUndo--;
- }
- }
- //////////////////////////////////////////////////////////////////////////////////
- //End of File