1 /*# ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 # This software is governed by the CeCILL-B license under French law and
10 # abiding by the rules of distribution of free software. You can use,
11 # modify and/ or redistribute the software under the terms of the CeCILL-B
12 # license as circulated by CEA, CNRS and INRIA at the following URL
13 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 # or in the file LICENSE.txt.
16 # As a counterpart to the access to the source code and rights to copy,
17 # modify and redistribute granted by the license, users are provided only
18 # with a limited warranty and the software's author, the holder of the
19 # economic rights, and the successive licensors have only limited
22 # The fact that you are presently reading this means that you have had
23 # knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
26 #ifndef __COMMANDS_HANDLER__
27 #define __COMMANDS_HANDLER__
29 //------------------------------------------------------------------------------------------------------------
31 //------------------------------------------------------------------------------------------------------------
33 #include "CommandObject.h"
34 #include "CommandsRegisterStructure.h"
35 #include "ContourWorkspace.h"
36 #include "ICommandsUser.h"
38 class ContourWorkspace;
40 class CommandsHandler{
42 //------------------------------------------------------------------------------------------------------------
43 // Constructors & Destructors
44 //------------------------------------------------------------------------------------------------------------
49 * Constructs the CommandsHandler
54 * Destructs the CommandsHandler
57 //------------------------------------------------------------------------------------------------------------
59 //------------------------------------------------------------------------------------------------------------
62 * Registers in the vectors of doneActions and unDoActions the given commands that all ready corresponds each other to the inverse of the otherone.
63 * If is the first registered action notifies the posibleUNDO avaliability.
64 * @param doneAction Is the action to register in the redo_actions vector.
65 * @param unDoAction Is the action to register in the unDo_actions vector.
67 void registerCommand(CommandObject* doneAction, CommandObject* unDoAction);
70 * Undo a command. Managing the correspondig vectors and the execution of the inverse action to the - ACTUAL DONE- action
71 * @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.
76 * Redo a command. Managing the correspondig vectors and the execution of the inverse action to the - ACTUAL DONE- action
77 * @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.
82 * Notitify if posibleREDO is posible or not.
83 * @return Returns the state of posibleUNDO
88 * Indicates if posibleUNDO is posible or not.
89 * @return Returns the state of posibleREDO
94 * Sets posibleREDO state.
95 * @param UNDOstate The state of posibleUNDO to set
97 void setPosibleUNDO(bool UNDOstate);
100 * Sets posibleUNDO state.
101 * @param REDOstate The state of posibleREDO to set
103 void setPosibleREDO(bool REDOstate);
106 * Clear the registered actions in the DO and UNDO vectors.
111 * Returns hoy mane paired commands had been registered, if the done and unDo vectors dont match returns -1 as error code.
112 * @return Returns how many paired-commands had been registered
114 int getTotalCommands();
117 * Gets the actual command in the UNDO-list
118 * @return Returns a pointer to the actual undo action
120 CommandObject * getActual_UNDO();
123 * Gets the actual command in the REDO-list
124 * @return Returns a pointer to the actual do action
126 CommandObject * getActual_REDO();
129 * Gets the command at the given position in the DO (REDO) vector
130 * @return The pointer to the referenced object by the position
132 CommandObject * get_DO_CommandAt(int position);
135 * Gets the command at the given position in the UNDO vector
136 * @return The pointer to the referenced object by the position
138 CommandObject * get_UNDO_CommandAt(int position);
142 * Validates if it is posible of not to do UNDO and/or REDO and sets the corresponding values
144 void validateOperationsAvaliability();
147 * Sets the model parent of the action handler
148 * @param theModelParent The boss reference
150 void setModelBoss(ICommandsUser * theModelParent);
153 //------------------------------------------------------------------------------------------------------------
155 //------------------------------------------------------------------------------------------------------------
158 //------------------------------------------------------------------------------------------------------------
160 //------------------------------------------------------------------------------------------------------------
161 CommandsRegisterStructure * redo_actions;
163 CommandsRegisterStructure * unDo_actions;
169 ICommandsUser * theWorksSpaceBoss;
171 bool isLastREDO_executed;
173 bool isLastUNDO_executed;
175 std::deque<CommandObject *> executionQueue;