You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
118 lines
3.0 KiB
C++
118 lines
3.0 KiB
C++
#include "StdAfx.h"
|
|
#include "CommandMgr.h"
|
|
#include "LogMgr.h"
|
|
#include "GlobalFunction.h"
|
|
|
|
|
|
#define MAX_UNDO_CNT 100//最大撤销次数
|
|
|
|
CCommandMgr gCommandMgr;
|
|
CCommandMgr::CCommandMgr(void)
|
|
{
|
|
}
|
|
CCommandMgr::~CCommandMgr(void)
|
|
{
|
|
m_UndoQueue.clear();
|
|
m_RedoQueue.clear();
|
|
}
|
|
//p 是指令特定的操作对象
|
|
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)
|
|
{
|
|
//加入指定的
|
|
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//没有指定就加入当前选择的obj
|
|
{
|
|
gLayer.GetObjContainer().AddObjToCmd(p,true);
|
|
}
|
|
}
|
|
if(p->HasOpObj()==false)//没有操作对象时不要添加指令
|
|
{
|
|
delete p;
|
|
return;
|
|
}
|
|
gCommandMgr.AddUndoCommandExt(p);
|
|
}
|
|
//添加指令
|
|
void CCommandMgr::AddUndoCommandExt(CCommandBase *p)
|
|
{
|
|
//------------------------------------日志start
|
|
CLogInfo LogInfo;
|
|
LogInfo.m_ClassName = "CCommandMgr";
|
|
LogInfo.m_FuncName = "AddUndoCommandExt";
|
|
LogInfo.m_LogMsg = p->GetStr();
|
|
gLogMgr->WriteLogInfo(LogInfo);
|
|
//------------------------------------日志end
|
|
//保存到智能指针
|
|
Sptr<CCommandBase> sPtr(p);
|
|
|
|
m_UndoQueue.push_back(sPtr);
|
|
if(m_UndoQueue.size()>MAX_UNDO_CNT)
|
|
{
|
|
m_UndoQueue.pop_front();
|
|
}
|
|
//之前的redo 全部清除
|
|
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();
|
|
//------------------------------------日志start
|
|
CLogInfo LogInfo;
|
|
LogInfo.m_ClassName = "CCommandMgr";
|
|
LogInfo.m_FuncName = "Undo";
|
|
LogInfo.m_LogMsg = p->GetStr();
|
|
gLogMgr->WriteLogInfo(LogInfo);
|
|
//------------------------------------日志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();
|
|
//------------------------------------日志start
|
|
CLogInfo LogInfo;
|
|
LogInfo.m_ClassName = "CCommandMgr";
|
|
LogInfo.m_FuncName = "Redo";
|
|
LogInfo.m_LogMsg = p->GetStr();
|
|
gLogMgr->WriteLogInfo(LogInfo);
|
|
//------------------------------------日志end
|
|
}
|
|
}
|
|
//重置回撤指令状态
|
|
void CCommandMgr::Reset()
|
|
{
|
|
m_UndoQueue.clear();
|
|
m_RedoQueue.clear();
|
|
} |