|
|
|
|
#include "StdAfx.h"
|
|
|
|
|
#include "CommandMgr.h"
|
|
|
|
|
#include "LogMgr.h"
|
|
|
|
|
#include "GlobalFunction.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define MAX_UNDO_CNT 100//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
CCommandMgr gCommandMgr;
|
|
|
|
|
CCommandMgr::CCommandMgr(void)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
CCommandMgr::~CCommandMgr(void)
|
|
|
|
|
{
|
|
|
|
|
m_UndoQueue.clear();
|
|
|
|
|
m_RedoQueue.clear();
|
|
|
|
|
}
|
|
|
|
|
//p <20><>ָ<EFBFBD><D6B8><EFBFBD>ض<EFBFBD><D8B6>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
void CCommandMgr::AddUndoCommand(CCommandBase *p)
|
|
|
|
|
{
|
|
|
|
|
vector<Sptr<CObjBase>> Vec;
|
|
|
|
|
AddUndoCommand(p,Vec);
|
|
|
|
|
}
|
|
|
|
|
void CCommandMgr::AddUndoCommand(CCommandBase *p,vector<Sptr<CObjBase>> &pMarkObjectVec)
|
|
|
|
|
{
|
|
|
|
|
if(p->HasOpObj()==false)
|
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>
|
|
|
|
|
if(pMarkObjectVec.empty()==false)
|
|
|
|
|
{
|
|
|
|
|
vector<Sptr<CObjBase>>::iterator iter = pMarkObjectVec.begin();
|
|
|
|
|
vector<Sptr<CObjBase>>::iterator iter_end = pMarkObjectVec.end();
|
|
|
|
|
for(;iter!=iter_end;iter++)
|
|
|
|
|
{
|
|
|
|
|
p->AddOpObj((*iter));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else//û<><C3BB>ָ<EFBFBD><D6B8><EFBFBD>ͼ<EFBFBD><CDBC>뵱ǰѡ<C7B0><D1A1><EFBFBD><EFBFBD>obj
|
|
|
|
|
{
|
|
|
|
|
gLayer.GetObjContainer().AddObjToCmd(p,true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(p->HasOpObj()==false)//û<>в<EFBFBD><D0B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>
|
|
|
|
|
{
|
|
|
|
|
delete p;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
gCommandMgr.AddUndoCommandExt(p);
|
|
|
|
|
}
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>
|
|
|
|
|
void CCommandMgr::AddUndoCommandExt(CCommandBase *p)
|
|
|
|
|
{
|
|
|
|
|
//------------------------------------<2D><>־start
|
|
|
|
|
CLog log;
|
|
|
|
|
log.AddCmdLog();
|
|
|
|
|
log.str = p->GetStr();
|
|
|
|
|
gLogMgr->WriteLog(log);
|
|
|
|
|
//------------------------------------<2D><>־end
|
|
|
|
|
//<2F><><EFBFBD>浽<EFBFBD><E6B5BD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>
|
|
|
|
|
Sptr<CCommandBase> sPtr(p);
|
|
|
|
|
|
|
|
|
|
m_UndoQueue.push_back(sPtr);
|
|
|
|
|
if(m_UndoQueue.size()>MAX_UNDO_CNT)
|
|
|
|
|
{
|
|
|
|
|
m_UndoQueue.pop_front();
|
|
|
|
|
}
|
|
|
|
|
//֮ǰ<D6AE><C7B0>redo ȫ<><C8AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
m_RedoQueue.clear();
|
|
|
|
|
}
|
|
|
|
|
bool CCommandMgr::HasUndoCmd()
|
|
|
|
|
{
|
|
|
|
|
return !m_UndoQueue.empty();
|
|
|
|
|
}
|
|
|
|
|
bool CCommandMgr::HasRedoCmd()
|
|
|
|
|
{
|
|
|
|
|
return !m_RedoQueue.empty();
|
|
|
|
|
}
|
|
|
|
|
void CCommandMgr::Undo()
|
|
|
|
|
{
|
|
|
|
|
if(!m_UndoQueue.empty())
|
|
|
|
|
{
|
|
|
|
|
Sptr<CCommandBase> p = m_UndoQueue[m_UndoQueue.size()-1];
|
|
|
|
|
p->Undo();
|
|
|
|
|
m_RedoQueue.push_back(p);
|
|
|
|
|
m_UndoQueue.pop_back();
|
|
|
|
|
//------------------------------------<2D><>־start
|
|
|
|
|
CLog log;
|
|
|
|
|
log.AddCmdLog();
|
|
|
|
|
{
|
|
|
|
|
CString str = p->GetStr();
|
|
|
|
|
log.str = "_undo <20><><EFBFBD><EFBFBD>"+str;
|
|
|
|
|
}
|
|
|
|
|
gLogMgr->WriteLog(log);
|
|
|
|
|
//------------------------------------<2D><>־end
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void CCommandMgr::Redo()
|
|
|
|
|
{
|
|
|
|
|
if(!m_RedoQueue.empty())
|
|
|
|
|
{
|
|
|
|
|
Sptr<CCommandBase> p = m_RedoQueue[m_RedoQueue.size()-1];
|
|
|
|
|
p->Excute();
|
|
|
|
|
m_UndoQueue.push_back(p);
|
|
|
|
|
m_RedoQueue.pop_back();
|
|
|
|
|
//------------------------------------<2D><>־start
|
|
|
|
|
CLog log;
|
|
|
|
|
log.AddCmdLog();
|
|
|
|
|
{
|
|
|
|
|
CString str = p->GetStr();
|
|
|
|
|
log.str = "_redo <20><><EFBFBD><EFBFBD>"+str;
|
|
|
|
|
}
|
|
|
|
|
gLogMgr->WriteLog(log);
|
|
|
|
|
//------------------------------------<2D><>־end
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//<2F><><EFBFBD>ûس<C3BB>ָ<EFBFBD><D6B8>״̬
|
|
|
|
|
void CCommandMgr::Reset()
|
|
|
|
|
{
|
|
|
|
|
m_UndoQueue.clear();
|
|
|
|
|
m_RedoQueue.clear();
|
|
|
|
|
}
|