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 # ------------------------------------------------------------------------ */
27 //----------------------------------------------------------------------------------------------------------------
28 // Class definition include
29 //----------------------------------------------------------------------------------------------------------------
30 #include "CommandsRegisterStructure.h"
32 //----------------------------------------------------------------------------------------------------------------
33 // Class implementation
34 //----------------------------------------------------------------------------------------------------------------
35 /** @file CommandsRegisterStructure.cxx */
37 //------------------------------------------------------------------------------------------------------------
38 // Constructors & Destructors
39 //------------------------------------------------------------------------------------------------------------
42 * Creates the CommandsRegisterStructure
44 CommandsRegisterStructure :: CommandsRegisterStructure()
46 actualIndexToExec = -1;
51 * Destroys the CommandsRegisterStructure
53 CommandsRegisterStructure :: ~CommandsRegisterStructure()
58 //------------------------------------------------------------------------------------------------------------
60 //------------------------------------------------------------------------------------------------------------
63 * Registers a command in the vector with no verification, is should be well constructed
64 * @param theCommand The command to register
66 void CommandsRegisterStructure :: registerCommand(CommandObject * theCommand)
68 //int antes =registeredActions.size();
69 levelLastToActual(true);
70 registeredActions.push_back(theCommand);
71 actualIndexToExec = registeredActions.size()-1;
72 lastAction = actualIndexToExec;
73 //int despues =registeredActions.size();
79 * Gets the -ACTUAL- command text
82 /*std::string CommandsRegisterStructure :: getActualCommandText()
84 return !isEmpty() ? getCommandAt(actualIndexToExec)->includeToExecute(): " ";
88 * Gets the -LAST- command text
91 /*std::string CommandsRegisterStructure :: getLastCommandText()
93 return !isEmpty() ? getCommandAt(lastAction)->executeCommand(): " ";
97 * Deletes all the registered actions and reinitialize the -ACTUAL- and -LAST-
99 void CommandsRegisterStructure :: clearActions()
101 if(!registeredActions.empty())
103 for(int i=0; i < registeredActions.size(); i++)
105 registeredActions[i] = NULL;
107 registeredActions.clear();
109 actualIndexToExec = -1;
114 * Moves to the the previous position the -ACTUAL-
115 * @return Indicates true if it was done
117 bool CommandsRegisterStructure :: moveBack_Actual()
119 if ( !isEmpty() && hasActualPrevious() )
128 * Moves to the the next position the -ACTUAL-
129 * @return Indicates true if it was done
131 bool CommandsRegisterStructure :: moveForward_Actual()
133 if ( !isEmpty() && hasActualNext() )
142 * Moves to the the previous position the -LAST-
143 * @return Indicates true if it was done
145 bool CommandsRegisterStructure :: moveBack_Last()
147 if ( !isEmpty() && hasLastPrevious() )
156 * Moves to the the next position the -LAST-
157 * @return Indicates true if it was done
159 bool CommandsRegisterStructure :: moveForward_Last()
161 if ( !isEmpty() && hasLastNext() )
170 * Indicates if the -LAST- has a next action or not
171 * @return Returns true if it has
173 bool CommandsRegisterStructure :: hasLastNext()
175 int total = registeredActions.size();
176 return total > 0 ? total -1 > lastAction : false;
180 * Indicates if the -ACTUAL- has a next action or not
181 * @return Returns true if it has
183 bool CommandsRegisterStructure :: hasActualNext()
185 int total = registeredActions.size();
186 return total > 0 ? total -1 > actualIndexToExec : false;
190 * Indicates if the -LAST- has a previous action or not
191 * @return Returns true if it has
193 bool CommandsRegisterStructure :: hasLastPrevious()
195 return ! 0 < lastAction;
199 * Indicates if the -ACTUAL- has a previous action or not
200 * @return Returns true if it has
202 bool CommandsRegisterStructure :: hasActualPrevious()
204 return 0 < actualIndexToExec;
208 * Puts to point CommandsRegisterStructure :: the -ACTUAL- up to the -LAST- .
210 void CommandsRegisterStructure :: levelActualToLast()
212 actualIndexToExec = lastAction;
216 * Puts to point CommandsRegisterStructure :: the -LAST- up to the -ACTUAL- and erases automatically the actions after the
217 * referenced last new position of the registered actions if nothing is given by parameter.
218 * @clearingAfterActual Indicates if is wondered to erase or not the mentioned range
220 void CommandsRegisterStructure :: levelLastToActual( bool clearingAfterActual )
224 lastAction = actualIndexToExec;
225 if( clearingAfterActual )
227 for (int a=registeredActions.size()-1; a>=0 && actualIndexToExec < a; a--)
229 if(actualIndexToExec < a)
231 registeredActions.pop_back();
239 * Clear all the elements in the vector bettween the -LAST- and the end of the vector
241 void CommandsRegisterStructure :: clearAll_afterLast()
243 for (int a=registeredActions.size()-1; a>=0 && lastAction < a; a--)
247 registeredActions.pop_back();
253 * Clear all the elements in the vector bettween the -ACTUAL- and the start of the vector
255 void CommandsRegisterStructure :: clearAll_beforeActual()
257 std::vector <CommandObject*>::iterator frontIter;
258 for (int a=0; a<registeredActions.size() && lastAction < a; a--)
260 frontIter = registeredActions.begin();
261 if( actualIndexToExec > a )
263 registeredActions.erase(frontIter);
269 * Indicates if there are actions in the vector of not
270 * @return Returns true is there are not registered actions
272 bool CommandsRegisterStructure :: isEmpty()
274 return registeredActions.empty();
278 * Indicates the quantity of actions that are registered
279 * @return Returns the total amount of registered actions in the vector
281 int CommandsRegisterStructure :: getCommandsCount()
283 return registeredActions.size();
287 * Gets the -ACTUAL- information data pointer
288 * @return The pointer to the referenced object by the -ACTUAL-
290 CommandObject * CommandsRegisterStructure :: getActual_Pointer ()
292 return getCommandAt(actualIndexToExec);
296 * Gets the -LAST- information data pointer
297 * @return The pointer to the referenced object by the -LAST-
299 CommandObject * CommandsRegisterStructure ::getLast_Pointer ()
301 return getCommandAt(lastAction);
305 * Gets the command at the given position
306 * @return The pointer to the referenced object by the position
308 CommandObject * CommandsRegisterStructure :: getCommandAt(int position)
310 if(position< getCommandsCount())
312 return registeredActions[position];
318 * Gets the index of the actualAction in the vector
319 * @return actualIndexToExec Is the corresponding index
321 int CommandsRegisterStructure :: getActualIndex()
323 return actualIndexToExec;
327 * Gets the index of the lasAction in the vector
328 * @return lasAction Is the corresponding index
330 int CommandsRegisterStructure :: getLasIndex()
336 * Sets the index of the actualAction in the vector
337 * @param newActualIndex Is the corresponding index
339 void CommandsRegisterStructure :: setActualIndex(int newActualIndex)
341 actualIndexToExec = newActualIndex;
345 * Sets the index of the lasAction in the vector
346 * @param newLasIndex Is the corresponding index
348 void CommandsRegisterStructure :: setLasIndex(int newLasIndex)
350 lastAction = newLasIndex;
354 * Gets the registered commands vector size
355 * @return Returns the vector size
357 int CommandsRegisterStructure :: getRegistereCommandsCount()
359 return registeredActions.size();
363 * Gets the total registered commands
364 * @return Returns the total of commands
366 int CommandsRegisterStructure :: getTotalCommandsCount()
369 for( int i=0; i< registeredActions.size(); i++)
371 totalAccum+= registeredActions[i]->count();