#include "stdafx.h" #include #include "CmdProcessor.h" #include "CommandSet.h" const int CMD_HISTORY_CAPACITY = 50; CCmdProcessor::CCmdProcessor(void) : m_pNowCommand( NULL ), m_pLastDidCommand( NULL ), m_iCmdHistoryCapacity( CMD_HISTORY_CAPACITY ), m_iCmdIndex( -1 ), m_bCmdUpdated( false ), m_iLastCommandID( -1 ) //m_pLogReceiver( NULL ) { } CCmdProcessor::~CCmdProcessor(void) { // ¸í·É Å¥¿¡ ½×¿©Àִ°Š¸Þ¸ð¸® ÀüºÎ ÇØÁ¦ÇÑ´Ù. for_each( m_dqCmdList.begin(), m_dqCmdList.end(), DeleteData() ); } void CCmdProcessor::SetCommand( ICommand* pCommand ) { assert( NULL == m_pNowCommand && "Ä¿¸Çµå ½ÇÇàÁß¿¡ ´Ù½Ã Ä¿¸Çµå¸¦ ³¯¸®¸é ¾ÈµË´Ï´Ù." ); m_pNowCommand = pCommand; } void CCmdProcessor::DoCommand( void ) { if( m_pNowCommand->Recordable() ) { // ÀÏ´Ü Ä¿¸Çµå Æ÷ÀÎÅ͸¦ º¹»ç(Ä¿¸Çµå °´Ã¼¿¡ µû¶ó¼­´Â ±íÀº º¹»ç) // ÇØ¼­ ±× Æ÷ÀÎÅÍ·Î ÇöÀç Ä¿¸Çµå¸¦ ¼³Á¤ m_pNowCommand = m_pNowCommand->CreateSame(); ++m_iCmdIndex; // Ä¿¸Çµå À妽º°¡ ÃÖ»óÀ§°¡ ¾Æ´Ï¶ó¸é ±âÁ¸¿¡ ÀÖ´ø À§ÀÇ Ä¿¸ÇµåµéÀº ½Ï ³¯¸°´Ù. while( m_iCmdIndex <= (int)m_dqCmdList.size()-1 ) { delete m_dqCmdList.back(); m_dqCmdList.pop_back(); } m_dqCmdList.push_back( m_pNowCommand ); m_bCmdUpdated = true; // ÃÖ´ë °¹¼ö¸¦ ³Ñ¾î°¡Áö ¾Êµµ·Ï. if( (int)m_dqCmdList.size() > m_iCmdHistoryCapacity ) { delete m_dqCmdList.front(); m_dqCmdList.pop_front(); m_iCmdIndex = (int)m_dqCmdList.size() - 1; } } m_iLastCommandID = m_pNowCommand->GetTypeID(); m_pNowCommand->Excute(); m_pLastDidCommand = m_pNowCommand; const wxChar* pDesc = m_pNowCommand->GetDesc(); if( pDesc ) { m_strLastCmdMsg.assign( pDesc ); //if( m_pLogReceiver ) // m_pLogReceiver->DataChanged(); } m_pNowCommand = NULL; //m_bCmdUpdated = false; } bool CCmdProcessor::CanUndo( void ) { return -1 != m_iCmdIndex; } void CCmdProcessor::UndoCommand( void ) { // ¾ÈÀüÇÑ ÄÚµùÀ» ÇÏÀÚ. ļļļ. if( CanUndo() ) { // Undo °¡ È£Ã⠵Ǵ °úÁ¤¿¡¼­ Ä¿¸Çµå È÷½ºÅ丮¸¦ °»½ÅÇØÁÖ´Â // ³à¼®µéÀÌ Á¦´ë·Î ÀνÄÇÒ ¼ö ÀÖµµ·Ï Undo °¡ È£ÃâµÇ±â Àü¿¡ ÂüÁ¶ÇÒ µ¥ÀÌÅ͵éÀ» ¸¶·ÃÇØÁØ´Ù. ICommand* pCommand = m_dqCmdList.at( m_iCmdIndex ); // ½ÇÇàÃë¼Ò ÇÑ µÚÀÇ Ä¿¸Çµå À妽ºÀÌ´Ù. --m_iCmdIndex; m_bCmdUpdated = true; m_iLastCommandID = pCommand->GetTypeID(); pCommand->Undo(); m_pLastDidCommand = pCommand; m_strLastCmdMsg.assign( wxT("*Undo : ") ); const wxChar* pDesc = pCommand->GetDesc(); if( pDesc ) { m_strLastCmdMsg.append( pDesc ); //if( m_pLogReceiver ) // m_pLogReceiver->DataChanged(); } //m_bCmdUpdated = false; } else { m_bErrorOccured = true; m_strLastError.assign( wxT("[Command Invoker] UndoCommand() ÇÔ¼ö ½ÇÆÐ. ´õ ÀÌ»ó ½ÇÇà Ãë¼Ò ÇÒ ¼ö ¾ø½À´Ï´Ù.\n") ); } } bool CCmdProcessor::CanRedo( void ) { return m_iCmdIndex < ((int)m_dqCmdList.size()-1); } void CCmdProcessor::RedoCommand( void ) { // ¾ÈÀüÇÏ°íµµ ¹æ¾îÀûÀÎ ÄÚµù. -_-; if( CanRedo() ) { // Redo µµ Undo ¿Í ¸¶Âù°¡Áö. ++m_iCmdIndex; ICommand* pCommand = m_dqCmdList.at( m_iCmdIndex ); m_bCmdUpdated = true; m_iLastCommandID = pCommand->GetTypeID(); pCommand->Excute(); m_pLastDidCommand = pCommand; m_strLastCmdMsg.assign( wxT("*Redo : ") ); const wxChar* pDesc = pCommand->GetDesc(); if( pDesc ) { m_strLastCmdMsg.append( pDesc ); //if( m_pLogReceiver ) // m_pLogReceiver->DataChanged(); } //m_bCmdUpdated = false; } else { m_bErrorOccured = true; m_strLastError.assign( wxT("[Command Invoker] RedoCommand() ÇÔ¼ö ½ÇÆÐ. ´õ ÀÌ»ó Àç½ÇÇà ÇÒ ¼ö ¾ø½À´Ï´Ù.\n") ); } } void CCmdProcessor::OnUpdatedAllListeners( void ) { m_bCmdUpdated = false; m_iLastCommandID = CMD_NULL; } int CCmdProcessor::GetNumCmdHistory( void ) { return (int)m_dqCmdList.size(); } ICommand* CCmdProcessor::GetCmdHistory( int iIndex ) { return m_dqCmdList.at( iIndex ); } void CCmdProcessor::UpdateToThisHistory( int iCmdIndex ) { assert( iCmdIndex != -1 ); if( iCmdIndex != -1 ) { // Ä¿¸Çµå°¡ ÇöÀç Ä¿¸Çµåº¸´Ù ÃÖ±Ù Ä¿¸Çµå¶ó¸é redo if( m_iCmdIndex < iCmdIndex ) { while( m_iCmdIndex < iCmdIndex ) { RedoCommand(); } } else if( m_iCmdIndex > iCmdIndex ) { // Ä¿¸Çµå°¡ ÇöÀç Ä¿¸Çµåº¸´Ù ÀÌÀü Ä¿¸Çµå¶ó¸é undo while( m_iCmdIndex > iCmdIndex ) { UndoCommand(); } } } } const wxChar* CCmdProcessor::GetCommandMsg( void ) { //if( m_bCmdUpdated ) //{ return m_strLastCmdMsg.c_str(); //} //else // return NULL; } const wxChar* CCmdProcessor::GetLastError( void ) { m_bErrorOccured = false; return m_strLastError.c_str(); } void CCmdProcessor::Clear( void ) { m_pNowCommand = NULL; m_iCmdIndex = -1; m_bCmdUpdated = true; // ÀÌ·¡¾ß È÷½ºÅ丮¸¦ º¸¿©ÁÖ´Â ºäµéÀÌ ¾÷µ¥ÀÌÆ® ÇÑ´Ù. m_iLastCommandID = CMD_NULL; // ¸í·É Å¥¿¡ ½×¿©Àִ°Š¸Þ¸ð¸® ÀüºÎ ÇØÁ¦ÇÑ´Ù. for_each( m_dqCmdList.begin(), m_dqCmdList.end(), DeleteData() ); m_dqCmdList.clear(); } // //void CCmdProcessor::RemoveCommand( int iCmdType ) //{ // deque::iterator iter = m_dqCmdList.begin(); // for( iter; iter != m_dqCmdList.end(); ++iter ) // { // if( iCmdType == (*iter)->GetTypeID() ) // { // iter = m_dqCmdList.erase( iter ); // // if( m_dqCmdList.empty()) // break; // } // } //}