#ifndef __COMMANDS_HANDLER__ #define __COMMANDS_HANDLER__ //------------------------------------------------------------------------------------------------------------ // Includes //------------------------------------------------------------------------------------------------------------ #include "CommandObject.h" #include "CommandsRegisterStructure.h" #include "ContourWorkspace.h" #include "ICommandsUser.h" class ContourWorkspace; class CommandsHandler{ //------------------------------------------------------------------------------------------------------------ // Constructors & Destructors //------------------------------------------------------------------------------------------------------------ public: /* * Constructs the CommandsHandler */ CommandsHandler(); /* * Destructs the CommandsHandler */ ~CommandsHandler(); //------------------------------------------------------------------------------------------------------------ // Methods //------------------------------------------------------------------------------------------------------------ /* * Registers in the vectors of doneActions and unDoActions the given commands that all ready corresponds each other to the inverse of the otherone. * If is the first registered action notifies the posibleUNDO avaliability. * @param doneAction Is the action to register in the redo_actions vector. * @param unDoAction Is the action to register in the unDo_actions vector. */ void registerCommand(CommandObject* doneAction, CommandObject* unDoAction); /* * Undo a command. Managing the correspondig vectors and the execution of the inverse action to the - ACTUAL DONE- action * @return Returns true if the inverse command ( the actual to execute in UNDO actions ) is executed. If it is false the state of the vector must not change. */ bool undo(); /* * Redo a command. Managing the correspondig vectors and the execution of the inverse action to the - ACTUAL DONE- action * @return Returns true if the actual command to execute ( the actual to execute in REDO actions )has been executed. If it is false the state of the vector must not change. */ bool redo(); /* * Notitify if posibleREDO is posible or not. * @return Returns the state of posibleUNDO */ bool isPosibleUNDO(); /* * Indicates if posibleUNDO is posible or not. * @return Returns the state of posibleREDO */ bool isPosibleREDO(); /* * Sets posibleREDO state. * @param UNDOstate The state of posibleUNDO to set */ void setPosibleUNDO(bool UNDOstate); /* * Sets posibleUNDO state. * @param REDOstate The state of posibleREDO to set */ void setPosibleREDO(bool REDOstate); /* * Clear the registered actions in the DO and UNDO vectors. */ void clearActions(); /* * Returns hoy mane paired commands had been registered, if the done and unDo vectors dont match returns -1 as error code. * @return Returns how many paired-commands had been registered */ int getTotalCommands(); /* * Gets the actual command in the UNDO-list * @return Returns a pointer to the actual undo action */ CommandObject * getActual_UNDO(); /* * Gets the actual command in the REDO-list * @return Returns a pointer to the actual do action */ CommandObject * getActual_REDO(); /* * Gets the command at the given position in the DO (REDO) vector * @return The pointer to the referenced object by the position */ CommandObject * get_DO_CommandAt(int position); /* * Gets the command at the given position in the UNDO vector * @return The pointer to the referenced object by the position */ CommandObject * get_UNDO_CommandAt(int position); /* * Validates if it is posible of not to do UNDO and/or REDO and sets the corresponding values */ void validateOperationsAvaliability(); /* * Sets the model parent of the action handler * @param theModelParent The boss reference */ void setModelBoss(ICommandsUser * theModelParent); //------------------------------------------------------------------------------------------------------------ // Constants //------------------------------------------------------------------------------------------------------------ private: //------------------------------------------------------------------------------------------------------------ // Attributes //------------------------------------------------------------------------------------------------------------ CommandsRegisterStructure * redo_actions; CommandsRegisterStructure * unDo_actions; bool posibleUNDO; bool posibleREDO; ICommandsUser * theWorksSpaceBoss; bool isLastREDO_executed; bool isLastUNDO_executed; std::deque executionQueue; }; #endif