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