creaContours_lib
CommandsHandler.h
Go to the documentation of this file.
1 /*# ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4 # pour la Sant�)
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
8 #
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.
15 #
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
20 # liability.
21 #
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 # ------------------------------------------------------------------------ */
25 
26 #ifndef __COMMANDS_HANDLER__
27 #define __COMMANDS_HANDLER__
28 
29 //------------------------------------------------------------------------------------------------------------
30 // Includes
31 //------------------------------------------------------------------------------------------------------------
32 
33 #include "CommandObject.h"
35 #include "ContourWorkspace.h"
36 #include "ICommandsUser.h"
37 
38 class ContourWorkspace;
39 
41 
42 //------------------------------------------------------------------------------------------------------------
43 // Constructors & Destructors
44 //------------------------------------------------------------------------------------------------------------
45 public:
46 
47 
48  /*
49  * Constructs the CommandsHandler
50  */
52 
53  /*
54  * Destructs the CommandsHandler
55  */
57 //------------------------------------------------------------------------------------------------------------
58 // Methods
59 //------------------------------------------------------------------------------------------------------------
60 
61  /*
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.
66  */
67  void registerCommand(CommandObject* doneAction, CommandObject* unDoAction);
68 
69  /*
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.
72  */
73  bool undo();
74 
75  /*
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.
78  */
79  bool redo();
80 
81  /*
82  * Notitify if posibleREDO is posible or not.
83  * @return Returns the state of posibleUNDO
84  */
85  bool isPosibleUNDO();
86 
87  /*
88  * Indicates if posibleUNDO is posible or not.
89  * @return Returns the state of posibleREDO
90  */
91  bool isPosibleREDO();
92 
93  /*
94  * Sets posibleREDO state.
95  * @param UNDOstate The state of posibleUNDO to set
96  */
97  void setPosibleUNDO(bool UNDOstate);
98 
99  /*
100  * Sets posibleUNDO state.
101  * @param REDOstate The state of posibleREDO to set
102  */
103  void setPosibleREDO(bool REDOstate);
104 
105  /*
106  * Clear the registered actions in the DO and UNDO vectors.
107  */
108  void clearActions();
109 
110  /*
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
113  */
114  int getTotalCommands();
115 
116  /*
117  * Gets the actual command in the UNDO-list
118  * @return Returns a pointer to the actual undo action
119  */
121 
122  /*
123  * Gets the actual command in the REDO-list
124  * @return Returns a pointer to the actual do action
125  */
127 
128  /*
129  * Gets the command at the given position in the DO (REDO) vector
130  * @return The pointer to the referenced object by the position
131  */
132  CommandObject * get_DO_CommandAt(int position);
133 
134  /*
135  * Gets the command at the given position in the UNDO vector
136  * @return The pointer to the referenced object by the position
137  */
138  CommandObject * get_UNDO_CommandAt(int position);
139 
140 
141  /*
142  * Validates if it is posible of not to do UNDO and/or REDO and sets the corresponding values
143  */
145 
146  /*
147  * Sets the model parent of the action handler
148  * @param theModelParent The boss reference
149  */
150  void setModelBoss(ICommandsUser * theModelParent);
151 
152 
153 //------------------------------------------------------------------------------------------------------------
154 // Constants
155 //------------------------------------------------------------------------------------------------------------
156 
157 private:
158 //------------------------------------------------------------------------------------------------------------
159 // Attributes
160 //------------------------------------------------------------------------------------------------------------
162 
164 
166 
168 
170 
172 
174 
175  std::deque<CommandObject *> executionQueue;
176 
177 };
178 #endif