]> Creatis software - creaEnvironment.git/blob - lib/kernel_Environment/InstantHandler_Txx.h
License Files Headers
[creaEnvironment.git] / lib / kernel_Environment / InstantHandler_Txx.h
1 /*
2  # ---------------------------------------------------------------------
3  #
4  # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5  #                        pour la SantÈ)
6  # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7  # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8  # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9  #
10  #  This software is governed by the CeCILL-B license under French law and
11  #  abiding by the rules of distribution of free software. You can  use,
12  #  modify and/ or redistribute the software under the terms of the CeCILL-B
13  #  license as circulated by CEA, CNRS and INRIA at the following URL
14  #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15  #  or in the file LICENSE.txt.
16  #
17  #  As a counterpart to the access to the source code and  rights to copy,
18  #  modify and redistribute granted by the license, users are provided only
19  #  with a limited warranty  and the software's author,  the holder of the
20  #  economic rights,  and the successive licensors  have only  limited
21  #  liability.
22  #
23  #  The fact that you are presently reading this means that you have had
24  #  knowledge of the CeCILL-B license and that you accept its terms.
25  # ------------------------------------------------------------------------ */
26
27 /*=========================================================================
28
29   Program:  instantHandler
30   Module:    $RCSfile: InstantHandler_Txx.h,v $
31   Language:  C++
32   Date:      $Date: 2012/11/15 12:12:26 $
33   Version:   $Revision: 1.2 $
34   Objective: Handles the change of instant among the concept already inscribed
35   Authot:       Monica Maria Lozano Romero
36
37   Copyright: (c) 2007
38   License:
39
40      This software is distributed WITHOUT ANY WARRANTY; without even
41      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
42      PURPOSE.  See the above copyright notice for more information.
43
44
45 =========================================================================*/
46
47 // SYSTEM INCLUDES
48
49
50 // PROJECT INCLUDES
51
52
53 // LOCAL INCLUDES
54 //#include "Instant.h"
55
56
57 // FORWARD REFERENCES
58
59 //NAMESPACE
60
61                                                 //====== LIFECYCLE ========
62                                                 
63                                                 template<class P>       
64                                                 InstantHandler<P>::InstantHandler(SomeEnvironment<P>* environment)throw (ViewerNDimensionsException)
65                                                         {
66                                                                 
67                                                                 this->hasNext=true;
68                                                                 this->hasPrevious=true;
69                                                                 this->actualConcept=NULL;
70                                                                 this->actualTime=0.0;
71                                                                 this->pauseTime=0.0;
72                                                                 if(environment)
73                                                                         {
74                                                                                 this->environment=environment;
75                                                                                 this->actualInstant=new Instant(environment->getNumberOfConcepts());
76                                                                         }
77                                                                 else
78                                                                         {
79                                                                                 this->environment=NULL;
80                                                                                 this->actualInstant=NULL;
81                                                                                 throw new ViewerNDimensionsException("ERROR ENVIRONMENT NULL");
82                                                                         }
83                                                                 
84                                                         }
85                                                 
86                                                 template<class P>       
87                                                 InstantHandler<P>::~InstantHandler()
88                                                         {
89                                                                 int i,size;
90                                                                 //deleting conceptsToChange
91                                                                 size=getSizeConceptsToChange();
92                                                                 for(i=0;i<size;i++)
93                                                                         {
94                                                                                 if(conceptsToChange[i])
95                                                                                         delete conceptsToChange[i];
96                                                                         }
97                                                                 this->conceptsToChange.clear();
98                                                                 //deleting actual concept
99                                                                 if(actualInstant) delete actualInstant;
100                                                                 
101
102
103                                                         }
104                                                                                                         
105                                                 //====== OPERATIONS =======
106                                                 /*
107                                                 *       Adds a concept to handled in the instant, it means, when 
108                                                 *       the next instant is used we are going to change this concepts in the instant
109                                                 *       PRECONDITION
110                                                 *       the calls to this functions are made in order of position, where the last position (it means
111                                                 *       the higher position defined) is the concept thats is going to handled the real time
112                                                 *       THE LAST POSITION HANDLEDS THE REAL TIME DOESNT MATTER THE CONCEPT
113                                                 *       EXAMPLE
114                                                 *       The user wants to reproduce doctors, pacients and time, and positions given are:
115                                                 *       0=reproduce doctors, 1= reproduce pacients, 2= time, then  1,2 are going to be reproduced
116                                                 *       by PLUS PLUS, and time by REAL TIME
117                                                 *       @param nameConcept, name of the concept
118                                                 *       @param mode, mode of change
119                                                 *       @param position, position of reproduction
120                                                 *       @return true if succesful, false otherwise
121                                                 */
122                                                 template<class P>
123                                                 bool InstantHandler<P>::addConceptToHandled(std::string nameConcept,int mode,int position) throw (ViewerNDimensionsException)
124                                                         {
125                                                                 if(environment)
126                                                                         {
127                                                                                 //creating the concept
128                                                                                 ConceptInstantHandler* conceptInstantHandler=new ConceptInstantHandler(nameConcept,mode,position);
129                                                                                 //looking  for its index
130                                                                                 int indexInInstant=environment->getIndexConcept(nameConcept);
131                                                                                 if(indexInInstant!=-1)
132                                                                                         conceptInstantHandler->setIndexInInstant(indexInInstant);
133                                                                                 else
134                                                                                         throw new ViewerNDimensionsException("ERROR CONCEPT ISN'T IN ENVIRONMENT");
135                                                                                 //setting it maximums
136                                                                                 int maximumIndex=environment->getSizeConcept(nameConcept);
137                                                                                 if(maximumIndex!=-1)
138                                                                                         conceptInstantHandler->setMaximumIndex(maximumIndex);
139                                                                                 else
140                                                                                         throw new ViewerNDimensionsException("ERROR CONCEPT ISN'T IN ENVIRONMENT");
141                                                                                 //adding the concept
142                                                                                 this->conceptsToChange.push_back(conceptInstantHandler);
143                                                                                 actualConcept=conceptsToChange[getSizeConceptsToChange()-1];
144                                                                                 actualInstant->setConcept(indexInInstant,conceptInstantHandler->geActualIndex());
145                                                                                 return true;
146                                                                         }
147                                                                 else
148                                                                         {
149                                                                                 return false;
150                                                                         }
151                                                         }
152
153                                                 
154                                                 /*
155                                                 *       Next instant of the concepts to change
156                                                 *       PRECONDITION
157                                                 *       conceptsToChange is ordered by the position of the concepts handled
158                                                 *       @param 
159                                                 *       @return
160                                                 */
161                                                 template<class P>
162                                                 void InstantHandler<P>::nextInstant() throw (ViewerNDimensionsException)
163                                                         {
164                                                                 if(actualConcept)
165                                                                 {
166                                                                         bool hasNextIndex=actualConcept->hasNextIndex();
167                                                                         int position=actualConcept->getPosition();
168                                                                         if(hasNextIndex)
169                                                                                 {
170                                                                                         actualConcept->nextIndex();
171                                                                                         actualInstant->setConcept(actualConcept->getIndexInInstant(),actualConcept->geActualIndex());
172                                                                                         
173                                                                                 }
174                                                                         else
175                                                                                 {
176                                                                                         while( (position-1)>=0 && !hasNextIndex)
177                                                                                                 {
178                                                                                                         actualConcept=conceptsToChange[position-1];     
179                                                                                                         hasNextIndex=actualConcept->hasNextIndex();
180                                                                                                         position=actualConcept->getPosition();
181                                                                                                 }
182                                                                                         if(hasNextIndex)
183                                                                                                 {
184                                                                                                         actualConcept->nextIndex();
185                                                                                                         actualInstant->setConcept(actualConcept->getIndexInInstant(),actualConcept->geActualIndex());
186                                                                                                         resetNextConcepts();
187                                                                                                         actualConcept=conceptsToChange[getSizeConceptsToChange()-1];                                                                                            
188                                                                                                 }
189                                                                                         else
190                                                                                                 actualConcept=conceptsToChange[getSizeConceptsToChange()-1];
191                                                                                         
192                                                                                 }
193                                                                         setHasNext();   
194                                                                         setHasPrevious();
195                                                                 }
196                                                                 else
197                                                                         throw new ViewerNDimensionsException("ERROR THERE ISN'T CONCEPTS TO HANDLED IN THE PLAYER");
198                                                         }
199                                                 
200                                         
201                                                 /*
202                                                 *       Previous instant of the actual concept
203                                                 *       @param 
204                                                 *       @return
205                                                 */
206                                                 template<class P>
207                                                 void InstantHandler<P>::previousInstant()throw (ViewerNDimensionsException)
208                                                         {
209                                                                 if(actualConcept)
210                                                                 {
211                                                                         bool hasPreviousIndex=actualConcept->hasPreviousIndex();
212                                                                         int position=actualConcept->getPosition();
213                                                                         if(hasPreviousIndex)
214                                                                                 {
215                                                                                         actualConcept->previousIndex();
216                                                                                         actualInstant->setConcept(actualConcept->getIndexInInstant(),actualConcept->geActualIndex());
217                                                                                         
218                                                                                 }
219                                                                         else
220                                                                                 {
221                                                                                         while( (position-1)>=0 && !hasPreviousIndex)
222                                                                                                 {
223                                                                                                         actualConcept=conceptsToChange[position-1];     
224                                                                                                         hasPreviousIndex=actualConcept->hasPreviousIndex();
225                                                                                                         position=actualConcept->getPosition();
226                                                                                                 }
227                                                                                         if(hasPreviousIndex)
228                                                                                                 {
229                                                                                                         actualConcept->previousIndex();
230                                                                                                         actualInstant->setConcept(actualConcept->getIndexInInstant(),actualConcept->geActualIndex());
231                                                                                                         setNextConcepts();
232                                                                                                         actualConcept=conceptsToChange[getSizeConceptsToChange()-1];
233                                                                                                 }
234                                                                                         else
235                                                                                                 actualConcept=conceptsToChange[getSizeConceptsToChange()-1];
236
237                                                                                 }
238                                                                         setHasPrevious();
239                                                                         setHasNext();
240                                                                 }
241                                                                 else
242                                                                         throw new ViewerNDimensionsException("ERROR THERE ISN'T CONCEPTS TO HANDLED IN THE PLAYER");
243                                                         }               
244
245                                                 /*
246                                                 * Removes all the concept handled
247                                                 */
248                                                 template<class P>
249                                                 void InstantHandler<P>::removeAllConcepts()
250                                                         {
251                                                                 int size,i;
252                                                                 size=getSizeConceptsToChange();
253                                                                 for(i=0;i<size;i++)
254                                                                         {
255                                                                                 if(conceptsToChange[i])
256                                                                                         delete conceptsToChange[i];
257                                                                         }
258                                                                 conceptsToChange.clear();
259                                                                 actualConcept=NULL;
260
261                                                         }
262                                                 
263                                                 /*
264                                                 *       Removes the concept with the name given
265                                                 *       @param nameConcept, name of the concept to remove
266                                                 *       WARNING the user know wich concept is erasing, also knows the
267                                                 *       mode of other concepts, if the user is deleting the concept that
268                                                 *       handled the real time, should change the mode to other concept that exist
269                                                 */
270                                                 template<class P>
271                                                 void InstantHandler<P>::removeConceptToHandled(std::string nameConcept)
272                                                         {
273                                                                 int size,i;
274                                                                 size=getSizeConceptsToChange();
275                                                                 std::vector<ConceptInstantHandler*>::iterator iteratorConcepts=conceptsToChange.begin();
276                                                                 ConceptInstantHandler* concepti;
277                                                                 std::string nameConcepti;
278                                                                 bool isConcept=false;
279                                                                 for(i=0;i<size && !isConcept;i++)
280                                                                         {
281                                                                                 concepti=conceptsToChange[i];
282                                                                                 nameConcepti=concepti->getName();
283                                                                                 if(nameConcepti.compare(nameConcept)==0)
284                                                                                         {
285                                                                                                 if(actualConcept==concepti)
286                                                                                                         actualConcept=NULL;
287                                                                                                 conceptsToChange.erase(iteratorConcepts);
288                                                                                                 actualConcept=conceptsToChange[size-1];
289                                                                                                 isConcept=true;
290                                                                                         }
291                                                                         iteratorConcepts++;
292                                                                         }
293                                                         }
294                                                 
295                                                 /*
296                                                 * sets all the concept to handled in 0
297                                                 */
298                                                 template<class P>
299                                                 void InstantHandler<P>::resetConceptsHandled()
300                                                         {
301                                                                 int size,i;
302                                                                 size=getSizeConceptsToChange();
303                                                                 ConceptInstantHandler* concepti;
304                                                                 int indexInInstant=-1;
305                                                                 for(i=0;i<size;i++)
306                                                                         {
307                                                                                 concepti=conceptsToChange[i];
308                                                                                 concepti->setActualIndex(0);
309                                                                                 indexInInstant=concepti->getIndexInInstant();
310                                                                                 actualInstant->setConcept(indexInInstant,0);
311                                                                         }
312                                                                 setHasNext();
313                                                                 setHasPrevious();
314                                                         }
315                                                 /*
316                                                 * Pause
317                                                 */
318                                                 /*
319                                                 template<class P>
320                                                 void InstantHandler<P>::pause()
321                                                         {
322                                                                 time_t seconds=time(NULL);
323                                                                 pauseTime=seconds*1000;
324                                                         }
325                                                 */
326                                                 //====== INQUIRY =========
327                                                 
328                                                 /*
329                                                 * get the actual instant fot the concept identified by the name
330                                                 */
331                                                 template<class P>
332                                                 Instant* InstantHandler<P>::getActualInstant()throw (ViewerNDimensionsException)
333                                                         {
334                                                                 if(this->actualInstant)
335                                                                         return this->actualInstant;
336                                                                 else
337                                                                         throw new ViewerNDimensionsException("ERROR ACTUAL INSTANT IS NOT SETTED");
338                                                         }
339                                                 
340                                                 
341                                                 /*
342                                                 * If the actual concept has next instant, it means, if the index of the concept
343                                                 * in the  instant is in the maximum value
344                                                 * @param nameConcept, concept for which we need to know if we are 
345                                                 * in its maximum value
346                                                 * @return true if IS NOT in the maximum, false otherwise 
347                                                 */
348                                                 template<class P>
349                                                 bool InstantHandler<P>::hasNextInstant()
350                                                         {
351                                                                 return hasNext;
352                                                         }
353                                                 
354                                                 
355                                                 
356                                                 /*
357                                                 * If the concept has previous instant, it means, if the index of the concept
358                                                 * in the  instant is positive
359                                                 * @param nameConcept, concept for which we need to know if we are 
360                                                 * in Zero
361                                                 * @return true if IS NOT in zero, false otherwise 
362                                                 */
363                                                 template<class P>
364                                                 bool InstantHandler<P>::hasPreviousInstant()
365                                                         {
366                                                                 return hasPrevious;
367                                                         }
368                                                 /*
369                                                 * returns the number con conceptsToHandled
370                                                 */
371                                                 template<class P>
372                                                 int InstantHandler<P>::getSizeConceptsToChange()
373                                                         {
374                                                                 return conceptsToChange.size();
375                                                         }
376                                                 /*
377                                                 * returns the number of possibles instants of the handler
378                                                 * it depends of the concepts added in conceptsTochange
379                                                 */
380                                                 template<class P>
381                                                 int InstantHandler<P>::getNumOfInstants()
382                                                         {
383                                                                 int i,size,numInstants=1;
384                                                                 size=getSizeConceptsToChange();
385                                                                 ConceptInstantHandler* concepti;
386                                                                 for(i=0;i<size;i++)
387                                                                         {
388                                                                                 concepti=conceptsToChange[i];
389                                                                                 numInstants*=concepti->getMaximumIndex();
390                                                                         }
391                                                                 return numInstants;
392
393                                                         }
394                                                         
395                                                 /*
396                                                 *       Returns the names of the concepts handled and its modes
397                                                 *       DEPRECATED
398                                                 */
399                                                 template<class P>
400                                                 void InstantHandler<P>::getConceptsInfo(std::vector<std::string>& namesConcepts,std::vector<int>& modes)
401                                                         {
402                                                                 int size,i;
403                                                                 size=getSizeConceptsToChange();
404                                                                 ConceptInstantHandler* concepti;
405                                                                 for(i=0;i<size;i++)
406                                                                         {
407                                                                                 concepti=conceptsToChange[i];
408                                                                                 namesConcepts.push_back(concepti->getName());
409                                                                                 modes.push_back(concepti->getMode());
410                                                                         }
411                                                         }
412                                                 /*
413                                                 *       Returns the name of the concept that handled the real time
414                                                 *       DEPRECATED
415                                                 */
416                                                 template<class P>
417                                                 void InstantHandler<P>::getTimeConcept(std::string& nameConcept)
418                                                         {
419                                                                 ConceptInstantHandler* concept=conceptsToChange[getSizeConceptsToChange()-1];
420                                                                 nameConcept=concept->getName();
421                                                         }
422
423                                                 //====== ACCESS ==========
424                                                 /*
425                                                 *       Sets the environment that is going to be handled
426                                                 *       @param environment, a pointer to the environmen
427                                                 *       @return
428                                                 */
429                                                 template<class P>
430                                                 void InstantHandler<P>::setEnvironment(SomeEnvironment<P>* environment)
431                                                         {
432                                                                 this->environment=environment;
433                                                         }
434                                                 /*
435                                                 *       Sets the actual instant of the instant handler
436                                                 */
437                                                 template<class P>
438                                                 void InstantHandler<P>::setActualInstant(Instant* instant)
439                                                         {       
440                                                                 if(!actualInstant)
441                                                                         actualInstant=new Instant(instant->getInstant());
442                                                                 else
443                                                                         {
444                                                                                 int i,size;
445                                                                                 size=actualInstant->getSize();
446                                                                                 for(i=0;i<size;i++)                                                                                     
447                                                                                                 actualInstant->setConcept(i,instant->getIndexInConcept(i));
448                                                                         }
449                                                                 setConceptsToChange();
450                                                         }
451                                                 
452                                                 /*
453                                                 *       Sets the  time of reproduction to the concept
454                                                 *       that depends of the real time of the reproduction
455                                                 *       (seconds)
456                                                 *       @param  timeReproduction
457                                                 */
458                                                 template<class P>
459                                                 void InstantHandler<P>::setTimeReproduction(double time)
460                                                         {
461                                                                 if(getSizeConceptsToChange()>0)
462                                                                 {
463                                                                         ConceptInstantHandler* concept=conceptsToChange[getSizeConceptsToChange()-1];
464                                                                         concept->setTimeReproduction(time);
465                                                                 }
466                                                         }
467                                                 /*
468                                                 *       Sets the actual time of the reproduction,
469                                                 *       is the real time (seconds)
470                                                 *       @param instant
471                                                 */
472                                                 template<class P>
473                                                 void InstantHandler<P>::setActualTime(double actualTime)
474                                                         {
475                                                                 ConceptInstantHandler* concept=conceptsToChange[getSizeConceptsToChange()-1];
476                                                                 concept->setActualTime(actualTime);
477                                                                 this->actualTime=actualTime;
478                                                         }
479                                                 /*
480                                                 * Set the mode of a concept that's being handled
481                                                 */
482                                                 template<class P>
483                                                 void InstantHandler<P>::setModeOfConcept(std::string nameConcept,int mode)
484                                                         {
485                                                                 int size,i;
486                                                                 size=getSizeConceptsToChange();
487                                                                 ConceptInstantHandler* concepti;
488                                                                 std::string nameConcepti;
489                                                                 bool isConcept=false;
490                                                                 for(i=0;i<size && !isConcept;i++)
491                                                                         {
492                                                                                 concepti=conceptsToChange[i];
493                                                                                 nameConcepti=concepti->getName();
494                                                                                 if(nameConcepti.compare(nameConcept)==0)
495                                                                                         {
496                                                                                                 isConcept=true;
497                                                                                                 concepti->setMode(mode);
498                                                                                         }
499
500                                                                         }
501                                                         }
502                                                 /*
503                                                 * Set handler
504                                                 */
505                                                 template<class P>
506                                                 void InstantHandler<P>::set()
507                                                         {
508                                                                 if(getSizeConceptsToChange()!=0)
509                                                                         actualConcept=conceptsToChange[getSizeConceptsToChange()-1];
510                                                         }
511                                                  /*
512                                                 * Set the increase Value for changing the instant
513                                                 */
514                                                 template<class P>
515                                                 void InstantHandler<P>::setIncreaseValue(int increase)
516                                                         {
517                                                                 int size,i;
518                                                                 size=conceptsToChange.size();
519                                                                 ConceptInstantHandler* concepti;
520                                                                 for(i=0;i<size;i++)
521                                                                         {
522                                                                                 concepti=conceptsToChange[i];
523                                                                                 concepti->setIncreaseValue(increase);
524                                                                         }
525
526                                                         }
527                                                 /*
528                                                 * Set the decrease Value for changing the instant
529                                                 */
530                                                 template<class P>
531                                                 void InstantHandler<P>::setDecreaseValue(int decrease)
532                                                         {
533                                                                 int size,i;
534                                                                 size=conceptsToChange.size();
535                                                                 ConceptInstantHandler* concepti;
536                                                                 for(i=0;i<size;i++)
537                                                                         {
538                                                                                 concepti=conceptsToChange[i];
539                                                                                 concepti->setDecreaseValue(decrease);
540                                                                         }
541                                                         }
542
543                                                 //====== PRIVATE METHODS=========
544                                                 
545                                                 /*
546                                                 *  Sets if the instant has next or not
547                                                 */
548                                                 
549                                                 template<class P>
550                                                 void InstantHandler<P>::setHasNext()
551                                                         {
552                                                                 int i, sizeConceptsToChange;
553                                                                 ConceptInstantHandler* concepti;
554                                                                 hasNext=false;
555                                                                 sizeConceptsToChange=getSizeConceptsToChange();
556                                                                 for(i=0;i<sizeConceptsToChange && !hasNext;i++)
557                                                                         {
558                                                                                 concepti=conceptsToChange[i];
559                                                                                 if(concepti->hasNextIndex())
560                                                                                                 hasNext=true;
561                                                                         }
562
563
564                                                         }
565                                                 /*
566                                                 *  Sets if the instant has previous or not
567                                                 */
568                                                 template<class P>
569                                                 void InstantHandler<P>::setHasPrevious()
570                                                         {
571                                                                 int i, sizeConceptsToChange;
572                                                                 ConceptInstantHandler* concepti;
573                                                                 hasPrevious=false;
574                                                                 sizeConceptsToChange=getSizeConceptsToChange();
575                                                                 for(i=0;i<sizeConceptsToChange && !hasPrevious;i++)
576                                                                         {
577                                                                                 concepti=conceptsToChange[i];
578                                                                                 if(concepti->hasPreviousIndex())
579                                                                                                 hasPrevious=true;
580                                                                         }
581                                                         }
582                                                 /*
583                                                 * actualize the actual index of the concepts handled
584                                                 */
585                                                 template<class P>
586                                                 void InstantHandler<P>::setConceptsToChange()
587                                                         {
588                                                                         int i,sizeConceptsToChange, indexInInstant,indexInConcept;
589                                                                         sizeConceptsToChange=getSizeConceptsToChange();
590                                                                         ConceptInstantHandler* concepti;
591                                                                         for(i=0;i<sizeConceptsToChange;i++)
592                                                                                 {
593                                                                                         concepti=conceptsToChange[i];
594                                                                                         indexInInstant=concepti->getIndexInInstant();
595                                                                                         indexInConcept=actualInstant->getIndexInConcept(indexInInstant);
596                                                                                         concepti->setActualIndex(indexInConcept);                                                                                       
597                                                                                 }
598                                                         }
599                                         /*
600                                         *       resets all the next concepts to zero
601                                         */
602                                         template<class P>
603                                         void InstantHandler<P>::resetNextConcepts()
604                                                 {
605                                                         int i,index,size;
606                                                         index=actualConcept->getPosition();
607                                                         size=getSizeConceptsToChange();
608                                                         ConceptInstantHandler* concepti;
609                                                         for(i=index+1;i<size;i++)
610                                                                 {
611                                                                         concepti=conceptsToChange[i];
612                                                                         concepti->setActualIndex(0);
613                                                                         concepti->resetInitialTime();
614                                                                         actualInstant->setConcept(concepti->getIndexInInstant(),0);
615                                                                 }
616                                                                 
617                                                 }
618                                         /*
619                                         * Sets the next index of concepts to handled to the maximum value
620                                         */
621                                         template<class P>
622                                         void InstantHandler<P>::setNextConcepts()
623                                                 {
624                                                         int i, index,size;
625                                                         index=actualConcept->getPosition();
626                                                         size=getSizeConceptsToChange();
627                                                         ConceptInstantHandler* concepti;
628                                                         for(i=index+1;i<size;i++)
629                                                                 {
630                                                                         concepti=conceptsToChange[i];
631                                                                         concepti->setActualIndex(concepti->getMaximumIndex()-1);
632                                                                         //concepti->resetInitialTime();
633                                                                         actualInstant->setConcept(concepti->getIndexInInstant(),concepti->geActualIndex());
634                                                                 }
635                                                 }
636                                         /*
637                                         * this method locates the new actual concept
638                                         * @param next, if has to locate the actual concept to the first concept that has next
639                                         * next=true, else search for the first concept that has previous
640                                         */
641                                         template<class P>
642                                         void InstantHandler<P>::toLocateActualConcept(bool next)
643                                                 {
644                                                                 int size=getSizeConceptsToChange();
645                                                                 if(next)
646                                                                         {
647                                                                                 
648                                                                                 if(actualConcept)
649                                                                                         {
650                                                                                                 bool hasNextIndex=actualConcept->hasNextIndex();
651                                                                                                 int position=actualConcept->getPosition();
652                                                                                                 while( (position-1)>=0 && !hasNextIndex)
653                                                                                                         {
654                                                                                                                 actualConcept=conceptsToChange[position-1];     
655                                                                                                                 hasNextIndex=actualConcept->hasNextIndex();
656                                                                                                                 position=actualConcept->getPosition();
657                                                                                                         }
658                                                                                         }
659                                                                                 else
660                                                                                         {       
661                                                                                                 if(size>0)
662                                                                                                         actualConcept=conceptsToChange[getSizeConceptsToChange()-1];
663                                                                                         }
664                                                                         }
665                                                                 else
666                                                                         {
667                                                                                 if(actualConcept)
668                                                                                         {
669                                                                                                 bool hasPreviousIndex=actualConcept->hasPreviousIndex();
670                                                                                                 int position=actualConcept->getPosition();
671                                                                                                 while( (position-1)>=0 && !hasPreviousIndex)
672                                                                                                         {
673                                                                                                                 actualConcept=conceptsToChange[position-1];     
674                                                                                                                 hasPreviousIndex=actualConcept->hasPreviousIndex();
675                                                                                                                 position=actualConcept->getPosition();
676                                                                                                         }
677                                                                                         }
678                                                                                 else
679                                                                                         {       
680                                                                                                 if(size>0)
681                                                                                                         actualConcept=conceptsToChange[getSizeConceptsToChange()-1];
682                                                                                         }
683                                                                         }
684                                                 
685                                                 }
686                   
687                   
688