]> Creatis software - creaContours.git/blob - lib/kernel_ManagerContour_NDimensions/CommandsHandler.h
d490dbf58f7472ddb20db015b1f4b754cd42b0f6
[creaContours.git] / lib / kernel_ManagerContour_NDimensions / CommandsHandler.h
1 #ifndef __COMMANDS_HANDLER__
2 #define __COMMANDS_HANDLER__
3
4 //------------------------------------------------------------------------------------------------------------
5 // Includes
6 //------------------------------------------------------------------------------------------------------------
7
8 #include "CommandObject.h"
9 #include "CommandsRegisterStructure.h"
10 #include "ContourWorkspace.h"
11 #include "ICommandsUser.h"
12
13 class ContourWorkspace;
14
15 class CommandsHandler{
16
17 //------------------------------------------------------------------------------------------------------------
18 // Constructors & Destructors
19 //------------------------------------------------------------------------------------------------------------
20 public:
21
22
23         /*
24         * Constructs the CommandsHandler
25         */
26         CommandsHandler();
27
28         /*
29         * Destructs the CommandsHandler
30         */
31         ~CommandsHandler();
32 //------------------------------------------------------------------------------------------------------------
33 // Methods
34 //------------------------------------------------------------------------------------------------------------
35
36         /*
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.
41         */
42         void registerCommand(CommandObject* doneAction, CommandObject* unDoAction);
43
44         /*
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.
47         */
48         bool undo();
49
50         /*
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.
53         */
54         bool redo();
55
56         /*
57         * Notitify if posibleREDO is posible or not.
58         * @return Returns the state of posibleUNDO
59         */
60         bool isPosibleUNDO();
61
62         /*
63         * Indicates if posibleUNDO is posible or not.
64         * @return Returns the state of posibleREDO
65         */
66         bool isPosibleREDO();
67
68         /*
69         * Sets  posibleREDO state.
70         * @param UNDOstate The state of posibleUNDO to set
71         */
72         void setPosibleUNDO(bool UNDOstate);
73
74         /*
75         * Sets posibleUNDO state.
76         * @param REDOstate The state of posibleREDO to set
77         */
78         void setPosibleREDO(bool REDOstate);
79         
80         /*
81         * Clear the registered actions in the DO and UNDO vectors.
82         */
83         void clearActions();
84
85         /*
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
88         */
89         int getTotalCommands();
90
91         /*
92         * Gets the actual command in the UNDO-list
93         * @return  Returns a pointer to the actual undo action
94         */
95         CommandObject * getActual_UNDO();
96
97         /*
98         * Gets the actual command in the REDO-list
99         * @return  Returns a pointer to the actual do action
100         */
101         CommandObject * getActual_REDO();
102
103         /*
104         * Gets the command at the given position in the DO (REDO) vector
105         * @return The pointer to the referenced object by the position
106         */
107         CommandObject * get_DO_CommandAt(int position);
108
109         /*
110         * Gets the command at the given position in the UNDO vector
111         * @return The pointer to the referenced object by the position
112         */
113         CommandObject * get_UNDO_CommandAt(int position);
114
115         
116         /*
117         * Validates if it is posible of not to do UNDO and/or REDO and sets the corresponding values
118         */
119         void validateOperationsAvaliability();
120
121         /*
122         * Sets the model parent of the action handler
123         * @param theModelParent The boss reference
124         */
125         void setModelBoss(ICommandsUser * theModelParent);
126
127
128 //------------------------------------------------------------------------------------------------------------
129 // Constants
130 //------------------------------------------------------------------------------------------------------------
131
132 private:        
133 //------------------------------------------------------------------------------------------------------------
134 // Attributes
135 //------------------------------------------------------------------------------------------------------------
136         CommandsRegisterStructure * redo_actions;
137
138         CommandsRegisterStructure * unDo_actions;
139
140         bool posibleUNDO;
141
142         bool posibleREDO;
143
144         ICommandsUser * theWorksSpaceBoss;
145
146         bool isLastREDO_executed;
147
148         bool isLastUNDO_executed;
149
150         std::deque<CommandObject *> executionQueue;     
151
152 };
153 #endif