1 #ifndef __COMMANDS_HANDLER__
2 #define __COMMANDS_HANDLER__
4 //------------------------------------------------------------------------------------------------------------
6 //------------------------------------------------------------------------------------------------------------
8 #include "CommandObject.h"
9 #include "CommandsRegisterStructure.h"
10 #include "ContourWorkspace.h"
11 #include "ICommandsUser.h"
13 class ContourWorkspace;
15 class CommandsHandler{
17 //------------------------------------------------------------------------------------------------------------
18 // Constructors & Destructors
19 //------------------------------------------------------------------------------------------------------------
24 * Constructs the CommandsHandler
29 * Destructs the CommandsHandler
32 //------------------------------------------------------------------------------------------------------------
34 //------------------------------------------------------------------------------------------------------------
37 * Registers in the vectors of doneActions and unDoActions the given commands that all ready corresponds each other to the inverse of the otherone.
38 * If is the first registered action notifies the posibleUNDO avaliability.
39 * @param doneAction Is the action to register in the redo_actions vector.
40 * @param unDoAction Is the action to register in the unDo_actions vector.
42 void registerCommand(CommandObject* doneAction, CommandObject* unDoAction);
45 * Undo a command. Managing the correspondig vectors and the execution of the inverse action to the - ACTUAL DONE- action
46 * @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.
51 * Redo a command. Managing the correspondig vectors and the execution of the inverse action to the - ACTUAL DONE- action
52 * @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.
57 * Notitify if posibleREDO is posible or not.
58 * @return Returns the state of posibleUNDO
63 * Indicates if posibleUNDO is posible or not.
64 * @return Returns the state of posibleREDO
69 * Sets posibleREDO state.
70 * @param UNDOstate The state of posibleUNDO to set
72 void setPosibleUNDO(bool UNDOstate);
75 * Sets posibleUNDO state.
76 * @param REDOstate The state of posibleREDO to set
78 void setPosibleREDO(bool REDOstate);
81 * Clear the registered actions in the DO and UNDO vectors.
86 * Returns hoy mane paired commands had been registered, if the done and unDo vectors dont match returns -1 as error code.
87 * @return Returns how many paired-commands had been registered
89 int getTotalCommands();
92 * Gets the actual command in the UNDO-list
93 * @return Returns a pointer to the actual undo action
95 CommandObject * getActual_UNDO();
98 * Gets the actual command in the REDO-list
99 * @return Returns a pointer to the actual do action
101 CommandObject * getActual_REDO();
104 * Gets the command at the given position in the DO (REDO) vector
105 * @return The pointer to the referenced object by the position
107 CommandObject * get_DO_CommandAt(int position);
110 * Gets the command at the given position in the UNDO vector
111 * @return The pointer to the referenced object by the position
113 CommandObject * get_UNDO_CommandAt(int position);
117 * Validates if it is posible of not to do UNDO and/or REDO and sets the corresponding values
119 void validateOperationsAvaliability();
122 * Sets the model parent of the action handler
123 * @param theModelParent The boss reference
125 void setModelBoss(ICommandsUser * theModelParent);
128 //------------------------------------------------------------------------------------------------------------
130 //------------------------------------------------------------------------------------------------------------
133 //------------------------------------------------------------------------------------------------------------
135 //------------------------------------------------------------------------------------------------------------
136 CommandsRegisterStructure * redo_actions;
138 CommandsRegisterStructure * unDo_actions;
144 ICommandsUser * theWorksSpaceBoss;
146 bool isLastREDO_executed;
148 bool isLastUNDO_executed;
150 std::deque<CommandObject *> executionQueue;