]> Creatis software - creaContours.git/blob - lib/kernel_ManagerContour_NDimensions/CommandsRegisterStructure.cxx
some more unused variables
[creaContours.git] / lib / kernel_ManagerContour_NDimensions / CommandsRegisterStructure.cxx
1
2 //----------------------------------------------------------------------------------------------------------------
3 // Class definition include
4 //----------------------------------------------------------------------------------------------------------------
5 #include "CommandsRegisterStructure.h"
6
7 //----------------------------------------------------------------------------------------------------------------
8 // Class implementation
9 //----------------------------------------------------------------------------------------------------------------
10 /** @file CommandsRegisterStructure.cxx */
11
12 //------------------------------------------------------------------------------------------------------------
13 // Constructors & Destructors
14 //------------------------------------------------------------------------------------------------------------
15
16 /*
17         * Creates the CommandsRegisterStructure
18         */
19         CommandsRegisterStructure :: CommandsRegisterStructure()
20         { 
21                 actualIndexToExec = -1;         
22                 lastAction = -1;
23         }
24
25         /*
26         * Destroys the CommandsRegisterStructure
27         */
28         CommandsRegisterStructure :: ~CommandsRegisterStructure()
29         { 
30                 clearActions();         
31         }
32
33 //------------------------------------------------------------------------------------------------------------
34 // Methods
35 //------------------------------------------------------------------------------------------------------------
36
37         /**
38         * Registers a command in the vector with no verification, is should be well constructed
39         * @param theCommand The command to register
40         */
41         void CommandsRegisterStructure :: registerCommand(CommandObject * theCommand)
42         {
43                 //int antes =registeredActions.size();
44                 levelLastToActual(true);
45                 registeredActions.push_back(theCommand);
46                 actualIndexToExec = registeredActions.size()-1;
47                 lastAction = actualIndexToExec;
48                 //int despues =registeredActions.size();
49                 //int otr = 0;
50         }
51
52
53         /*
54         * Gets the -ACTUAL- command text 
55         * @return
56         */
57         /*std::string CommandsRegisterStructure :: getActualCommandText()
58         { 
59                 return !isEmpty() ? getCommandAt(actualIndexToExec)->includeToExecute(): " ";
60         }*/
61
62         /*
63         * Gets the -LAST- command text 
64         * @return
65         */
66         /*std::string CommandsRegisterStructure :: getLastCommandText()
67         { 
68                 return !isEmpty() ? getCommandAt(lastAction)->executeCommand(): " ";
69         }*/
70
71         /*
72         * Deletes all the registered actions and reinitialize the -ACTUAL- and  -LAST- 
73         */
74         void CommandsRegisterStructure ::  clearActions()
75         { 
76                 if(!registeredActions.empty())
77                 {
78                         for(int i=0; i < registeredActions.size(); i++)
79                         {
80                                 registeredActions[i] = NULL;
81                         }
82                         registeredActions.clear();              
83                         lastAction = -1;                
84                         actualIndexToExec = -1;
85                 }
86         }
87
88         /*
89         * Moves to the the previous position the -ACTUAL- 
90         * @return Indicates true if it was done
91         */
92         bool CommandsRegisterStructure :: moveBack_Actual()
93         { 
94                 if ( !isEmpty() &&  hasActualPrevious() )
95                 {
96                         actualIndexToExec--;
97                         return true;
98                 }
99                 return false;
100         }
101
102         /*
103         * Moves to the the next position the -ACTUAL- 
104         * @return Indicates true if it was done
105         */
106         bool CommandsRegisterStructure :: moveForward_Actual()
107         {
108                 if ( !isEmpty() &&  hasActualNext() )
109                 {
110                         actualIndexToExec++;
111                         return true;
112                 }
113                 return false;
114         }
115
116         /*
117         * Moves to the the previous position the -LAST- 
118         * @return Indicates true if it was done
119         */
120         bool CommandsRegisterStructure :: moveBack_Last()
121         { 
122                 if ( !isEmpty() && hasLastPrevious() )
123                 {
124                         lastAction--;
125                         return true;
126                 }
127                 return false;
128         }
129
130         /*
131         * Moves to the the next position the -LAST- 
132         * @return Indicates true if it was done
133         */
134         bool CommandsRegisterStructure :: moveForward_Last()
135         {
136                 if ( !isEmpty() && hasLastNext() )
137                 {
138                         lastAction++;
139                         return true;
140                 }
141                 return false;
142         }
143
144         /*
145         * Indicates if the -LAST-  has a next action or not
146         * @return Returns true if it has
147         */
148         bool CommandsRegisterStructure :: hasLastNext()
149         {
150                 int total = registeredActions.size();
151                 return total > 0 ? total -1 > lastAction : false;
152         }
153
154         /*
155         * Indicates if the -ACTUAL-  has a next action or not
156         * @return Returns true if it has
157         */
158         bool CommandsRegisterStructure :: hasActualNext()
159         {
160                 int total = registeredActions.size();
161                 return total > 0 ? total -1 > actualIndexToExec : false;
162         }
163
164         /*
165         * Indicates if the -LAST-  has a previous action or not
166         * @return Returns true if it has
167         */
168         bool CommandsRegisterStructure :: hasLastPrevious()
169         {
170                 return ! 0 < lastAction;
171         }
172
173         /*
174         * Indicates if the -ACTUAL-  has a previous action or not
175         * @return Returns true if it has
176         */
177         bool CommandsRegisterStructure :: hasActualPrevious()
178         {
179                 return 0 < actualIndexToExec;
180         }
181
182         /*
183         * Puts to point CommandsRegisterStructure ::  the -ACTUAL-  up to the -LAST-  . 
184         */
185         void CommandsRegisterStructure :: levelActualToLast()
186         { 
187                 actualIndexToExec = lastAction;
188         }
189
190         /*
191         * Puts to point CommandsRegisterStructure ::  the -LAST-  up to the -ACTUAL-  and erases automatically the actions after the 
192         * referenced last new position of the registered actions if nothing is given by parameter.
193         * @clearingAfterActual Indicates if is wondered to erase or not the mentioned range 
194         */
195         void CommandsRegisterStructure :: levelLastToActual( bool clearingAfterActual )
196         {
197                 if ( !isEmpty() )
198                 {
199                         lastAction = actualIndexToExec;
200                         if( clearingAfterActual )
201                         {
202                                 for (int a=registeredActions.size()-1; a>=0 && actualIndexToExec < a; a--)
203                                 {
204                                         if(actualIndexToExec < a)
205                                         {
206                                                 registeredActions.pop_back();
207                                         }
208                                 }                               
209                         }                       
210                 }
211         }
212
213         /*
214         * Clear all the elements in the vector bettween the -LAST-  and the end of the vector
215         */
216         void CommandsRegisterStructure ::  clearAll_afterLast()
217         {
218                 for (int a=registeredActions.size()-1; a>=0 && lastAction < a; a--)
219                 {
220                         if( lastAction < a )
221                         {
222                                 registeredActions.pop_back();
223                         }
224                 }               
225         }
226
227         /*
228         * Clear all the elements in the vector bettween the -ACTUAL-  and the start of the vector       
229         */
230         void CommandsRegisterStructure ::  clearAll_beforeActual()
231         { 
232                 std::vector <CommandObject*>::iterator frontIter;
233                 for (int a=0; a<registeredActions.size() && lastAction < a; a--)
234                 {
235                         frontIter = registeredActions.begin();
236                         if( actualIndexToExec > a )
237                         {
238                                 registeredActions.erase(frontIter);
239                         }
240                 }       
241         }
242
243         /**
244         * Indicates if there are actions in the vector of not
245         * @return Returns true is there are not registered actions      
246         */
247         bool CommandsRegisterStructure :: isEmpty()
248         { 
249                 return registeredActions.empty();
250         }
251
252         /**
253         * Indicates the quantity of actions that are registered
254         * @return Returns the total amount of registered actions in the vector
255         */
256         int CommandsRegisterStructure ::  getCommandsCount()
257         { 
258                 return registeredActions.size();
259         }
260
261         /*
262         * Gets the -ACTUAL-   information data pointer
263         * @return The pointer to the referenced object by the -ACTUAL- 
264         */
265         CommandObject * CommandsRegisterStructure :: getActual_Pointer ()
266         {
267                 return  getCommandAt(actualIndexToExec);
268         }
269
270         /*
271         * Gets the -LAST-   information data pointer 
272         * @return The pointer to the referenced object by the -LAST- 
273         */
274         CommandObject * CommandsRegisterStructure ::getLast_Pointer ()
275         { 
276                 return  getCommandAt(lastAction);
277         }
278
279         /*
280         * Gets the command at the given position 
281         * @return The pointer to the referenced object by the position
282         */
283         CommandObject * CommandsRegisterStructure :: getCommandAt(int position)
284         {
285                 if(position< getCommandsCount())
286                 {
287                         return registeredActions[position];
288                 }
289                 return NULL;
290         }
291
292         /*
293         * Gets the index of the actualAction in the vector
294         * @return actualIndexToExec Is the corresponding index
295         */
296         int CommandsRegisterStructure :: getActualIndex()
297         {
298                 return actualIndexToExec;
299         }
300
301         /*
302         * Gets the index of the lasAction in the vector
303         * @return lasAction Is the corresponding index
304         */
305         int CommandsRegisterStructure :: getLasIndex()
306         {
307                 return lastAction;
308         }
309
310         /*
311         * Sets the index of the actualAction in the vector
312         * @param newActualIndex Is the corresponding index
313         */
314         void CommandsRegisterStructure :: setActualIndex(int newActualIndex)
315         {
316                 actualIndexToExec = newActualIndex;
317         }
318
319         /*
320         * Sets the index of the lasAction in the vector
321         * @param newLasIndex Is the corresponding index
322         */
323         void CommandsRegisterStructure :: setLasIndex(int newLasIndex)
324         {
325                 lastAction = newLasIndex;
326         }
327
328         /*
329         * Gets the registered commands vector size
330         * @return Returns the vector size
331         */
332         int CommandsRegisterStructure :: getRegistereCommandsCount()
333         {
334                 return registeredActions.size();
335         }
336
337         /*
338         * Gets the total registered commands 
339         * @return Returns the total of commands
340         */
341         int CommandsRegisterStructure :: getTotalCommandsCount()
342         {
343                 int totalAccum = 0;
344                 for( int i=0; i< registeredActions.size(); i++)
345                 {
346                         totalAccum+= registeredActions[i]->count();
347                 }
348                 return totalAccum;
349         }
350    
351