]> Creatis software - creaContours.git/blob - lib/kernel_ManagerContour_NDimensions/OutlineModelManager.cxx
2c7d7033df0acd23ce3246e736f79bb6bbe88be8
[creaContours.git] / lib / kernel_ManagerContour_NDimensions / OutlineModelManager.cxx
1
2 //----------------------------------------------------------------------------------------------------------------
3 // Class definition include
4 //----------------------------------------------------------------------------------------------------------------
5 #include "OutlineModelManager.h"
6
7 //----------------------------------------------------------------------------------------------------------------
8 // Class implementation
9 //----------------------------------------------------------------------------------------------------------------
10 /** @file OutlineModelManager.cxx */
11
12 //------------------------------------------------------------------------------------------------------------
13 // Constructors & Destructors
14 //------------------------------------------------------------------------------------------------------------
15 /*
16         * Creates the outline manager
17         */
18         OutlineModelManager :: OutlineModelManager( SomeEnvironment<ImageSourceThing *> *imSourceEnv, SomeEnvironment<ImageSectionThing *> *imSectionEnv, SomeEnvironment<AxeThing *> *axesEnv, SomeEnvironment<ContourThing *> *contourEnv )
19         {
20                 actualInstant                           = NULL;
21                 imageSourceEnvironment          = imSourceEnv;
22                 imagesSectionEnvironment        = imSectionEnv;
23                 axesEnvironment                         = axesEnv;
24                 outlinesEnvironment                     = contourEnv;
25
26                 workSpace                                       = new ContourWorkspace(this);//implies a shared workSpace
27                 keyGenerator                            = * new PrefixMaxKeyGenerator();        
28                 counterIdKey                            = 0;
29
30                 actualInstantWrapping           = new InstantMembersNameList();
31                 changeSourceImage                       = true; 
32
33                 bool allOK      = keyGenerator.addKeyThing("Axes", "Axe");
34                 allOK &= keyGenerator.addKeyThing("Image Sources", "Image source");
35                 allOK &= keyGenerator.addKeyThing("Image Sections", "Image section");
36                 allOK &= keyGenerator.addKeyThing("Outlines", "Outline");
37                 //setAutomaticConcepts();
38         }
39
40         /*
41         * Destroys the outline manager
42         */
43         OutlineModelManager :: ~OutlineModelManager()
44         {
45                 clean();
46                 delete actualInstant;
47                 delete workSpace;
48                 delete actualInstantWrapping;           
49         }
50
51 //------------------------------------------------------------------------------------------------------------
52 // Methods 
53 //------------------------------------------------------------------------------------------------------------
54
55
56         /*
57         * Creates and sets a workSpace object
58         * @return Retourns the created workSpace
59         */
60         ContourWorkspace * OutlineModelManager :: createWorkSpace()
61         {
62                 workSpace = new ContourWorkspace(this);
63                 return workSpace;
64         }
65
66         /*
67         * Sets the workSpace object
68         * @param  aWorkSpace The workSpace to set 
69         */
70         void OutlineModelManager :: setWorkSpace( ContourWorkspace * aWorkSpace )
71         {
72                 workSpace = aWorkSpace;
73         }
74
75         /*
76         * Executes a command over an outline object
77         * @param imaKName Is the key name of the outline
78         * @param theCommand Is the command to execute
79         * @param fromRegistration Indicates if the execution is directed from the registration, by default comes from the GUI = false.
80         */
81         bool OutlineModelManager :: executeCommand_OutlineModel(std::string outKName, CommandObject * theCommand, bool fromRegistration)
82         {
83                 ContourThing * theOutline = *outlinesEnvironment->getThingByName( outKName );
84                 if(!fromRegistration)
85                 {
86                         CommandObject * undoCommand = theOutline->getUndoCommandOf( theCommand );
87                         workSpace->callRegisterCommand(theCommand, undoCommand);
88                 }
89                 return theOutline->executeCommand( theCommand );
90         }
91
92         /*
93         * Executes a command identifying which actions have to realize before executing it.
94         * @param theCommand Is the command to execute
95         * @param fromRegistration Indicates if the execution is directed from the registration, by default comes from the GUI = false.
96         */
97         bool OutlineModelManager :: executeCommand(CommandObject * theCommand, bool fromRegistration)
98         {
99                 bool executedCom = true;
100                 //TODO**********************************************************************************************************************************************
101                 //Interpreting who is the one that executes the command
102
103                 //Modifiying the command in necessary for detaching interpreted information
104
105                 //If is an outline, sending the command to execute the specific command
106
107                 return executedCom;
108         }
109
110         /*
111         * Executes a command queue identifying which actions have to realize before executing it, using FIFO for each.
112         * @param executionQueue Is the command queue to execute
113         * @param fromRegistration Indicates if the execution is directed from the registration, by default comes from the GUI = false.
114         */
115         bool OutlineModelManager ::  executeCommandsQueue(std::deque<CommandObject *> executionQueue, bool fromRegistration)
116         {
117                 bool executedComs = executionQueue.size()>0 ? true : false;
118                 while( executionQueue.size()>0 )
119                 {                       
120                         CommandObject * aCmmand = executionQueue.front();
121                         executedComs &= executeCommand(aCmmand, fromRegistration);
122                         executionQueue.pop_front();
123                 }
124                 return executedComs;
125         }
126
127         
128         /*
129         * Sets the concepts of the environments and includes the concepts managed by the program 
130         * @conceptsScript Is the script for with the concepts descrition
131         * @return Returns true if successful insert of the given concepts, false otherwise
132         */
133         bool OutlineModelManager :: setUserConcepts(std::string conceptsScript)
134         {
135                 bool allOK = true;
136                 int endSub;
137                 std::string::size_type equalIndex = conceptsScript.find("=", 0);
138                 std::string::size_type nextIndex = 0;
139                 while( equalIndex != std::string::npos && allOK) 
140                 {       
141             endSub = equalIndex;
142                         std::string concept = conceptsScript.substr( 0, endSub ); 
143                         conceptsScript.erase( 0, endSub+1 ); 
144                         std::cout << "C: " << concept <<std::endl;                      
145                         nextIndex = conceptsScript.find(";", 0);
146                         std::string cSize;
147                         if(nextIndex != std::string::npos)
148                         {
149                                 endSub = nextIndex;
150                                 cSize = conceptsScript.substr( 0, endSub ); 
151                                 conceptsScript.erase( 0, endSub+1 ); 
152                         }
153                         else
154                         {
155                                 endSub = conceptsScript.size();         
156                                 cSize = conceptsScript.substr( 0, endSub ); 
157                                 conceptsScript.erase( 0, endSub ); 
158                         }                       
159                         int intReturn = atoi(cSize.c_str());                    
160                         std::cout << "SZ: "<<intReturn <<std::endl;     
161                         equalIndex = conceptsScript.find("=", 0);       
162                         if( intReturn>0 )
163                                 allOK &= addUserConcept(concept, intReturn);
164                         else
165                                 allOK = false;
166                 }               
167                 return allOK;
168         }
169
170         /*
171         * Add a concept to all the environments 
172         * @param theConceptName Is the name of the new concept
173         * @param conceptSize Is the size of the concept, that represent the ammount of concept posible instances 
174         * @return Returns true if successful insert of concept, false otherwise
175         */              
176         bool OutlineModelManager :: addUserConcept(std::string theConceptName, int conceptSize)
177         {       
178                 bool allOK = axesEnvironment->addConcept(theConceptName, conceptSize);
179                 allOK &= imagesSectionEnvironment->addConcept(theConceptName, conceptSize);
180                 allOK &= imageSourceEnvironment->addConcept(theConceptName, conceptSize);
181                 allOK &= outlinesEnvironment->addConcept(theConceptName, conceptSize);
182                 return allOK;
183         }
184
185         /**
186         * Gets the outlines at an instant form the outline's environment
187         * @param anInstant The instant wondered to get outlines at
188         * @param ifAnnotate Indicates if it is needed to annotate the searched outlines
189         * @return The vector to the outlines at the given instance
190         */
191         std::vector<NameWrapper *> OutlineModelManager :: getActualInstantOutlines ()
192         {
193                 return actualInstantWrapping->getOutlinesNamesVector();
194         }
195
196 //EED01
197         void OutlineModelManager :: ChangeContourOfList(std::string keyName, Instant *instant)
198         {
199                 int ispartofstaticlist = IsPartOfStaticList(keyName);
200                 if (ispartofstaticlist==-1)
201                 {
202                         staticContourLst.push_back(  this->outlinesEnvironment->getThingByName(keyName)  );
203                         this->outlinesEnvironment->removeThingFromInstant(keyName, instant);
204                 } else {
205                         ContourThing **contourthing  = staticContourLst[ispartofstaticlist];
206                         this->outlinesEnvironment->addInstantToThing    ( keyName , instant );                  
207                         staticContourLst.erase( staticContourLst.begin()+ispartofstaticlist );
208                 }
209         }
210
211
212         /**
213         * Gets the outlines at an instant form the outline's environment
214         * @param anInstant The instant wondered to get outlines at
215         * @param ifAnnotate Indicates if it is needed to annotate the searched outlines
216         * @return The vector to the outlines at the given instance
217         */
218         std::vector<ContourThing**>  OutlineModelManager :: getOutlinesAtInstant(Instant * anInstant, bool ifAnnotate)
219         {
220                 std::vector<std::string> kNamesVector;
221                 std::vector<ContourThing **> outlinesVector; //= new std::vector<ContourThing **>();
222                 outlinesEnvironment->getThings( kNamesVector, outlinesVector, anInstant);
223
224 //EED01
225                 int i,sizeStaticContourLst =  staticContourLst.size();
226                 for ( i=0 ; i<sizeStaticContourLst ; i++ )
227                 {
228                         ContourThing **contourthing  = staticContourLst[i];
229                         outlinesVector.push_back( contourthing );
230                         kNamesVector.push_back( (*contourthing)->getName() );
231                 }// for i
232
233                 if (ifAnnotate)
234                 {
235                         annotateOutlinesWrap(kNamesVector, outlinesVector);
236                 }
237                 return outlinesVector;
238         }
239
240 //EED01
241         std::vector<std::string> OutlineModelManager :: GetLstNameThingsStatic()
242         {
243                 std::vector<std::string> result;
244                 int i,sizeStaticContourLst =  staticContourLst.size();
245                 for ( i=0 ; i<sizeStaticContourLst ; i++ )
246                 {
247                         ContourThing **contourthing  = staticContourLst[i];
248                         result.push_back( (*contourthing)->getName() );
249                 }// for i
250                 return result;
251         }
252
253         std::vector<std::string> OutlineModelManager :: GetLstNameThings()
254         {
255                 std::vector<std::string> kNamesVector;
256                 std::vector<ContourThing **> outlinesVector; //= new std::vector<ContourThing **>();
257                 std::vector<Instant *> lstInstants = getOutlineInstants();
258                 int i,sizeLstInstants = lstInstants.size(); 
259                 Instant *instant;
260                 for ( i=0 ; i<sizeLstInstants ; i++ )
261                 {
262                         instant = lstInstants[i];
263                         outlinesEnvironment->getThings( kNamesVector, outlinesVector, instant);
264                 } // for i
265                 return kNamesVector;
266         }
267
268
269         /**
270         * Gets the outlines at a specific form the outline's environment
271         * @param aGroupName The name of the group containing the outlines names to get
272         * @return The vector to the outlines at the given group
273         */ 
274         std::vector<ContourThing*> OutlineModelManager :: getOutlinesFromGroup(std::string aGroupName)
275         {
276                 std::vector<ContourThing *> outlinesVector;
277                 std::map< std::string,OutlineGroup * >::iterator iterP = outlineGroups.find(aGroupName);
278                 if ( iterP != outlineGroups.end() )
279                 {       
280                         std::vector<std::string> kNamesVector = iterP->second->getGroupOutlinesNames(); 
281                         for(int i=0; i<kNamesVector.size();i++)
282                         {
283                                 ContourThing * outlineI = getOutlineByKeyName(kNamesVector[i]);
284                                 outlinesVector.push_back(outlineI);
285                         }                       
286                 }
287                 return outlinesVector;
288         }
289
290         /**
291         * Gets the outlines at a specific form the outline's environment
292         * @param aGroupName The name of the group containing the outlines names to get
293         * @return The vector to the outlineGroups at the given group
294         */ 
295         bool OutlineModelManager :: addOutlinesGroup( std::string theOutlineName, OutlineGroup * theGroup )
296         {
297         outlineGroups.insert(std::pair <std::string, OutlineGroup *> ( theOutlineName, theGroup ));                             
298                 std::map<std::string, OutlineGroup *> :: iterator iter = NULL;
299                 iter = outlineGroups.find( theOutlineName );
300                 bool ifAdded = iter->first.compare( theOutlineName ) == 0;
301                 return ifAdded;
302         }
303         /*
304         * Gets the an outline given the keyName used to be indexed in the outlines's environment
305         * @param outKName Is the outline keyName to search
306         * @return  The corresponding unique outline with the given key name
307         */
308         ContourThing* OutlineModelManager :: getOutlineByKeyName(std::string outKName)
309         {
310                 return *(outlinesEnvironment->getThingByName(outKName));
311         }
312
313         /*
314         * Gets the an imageSourceThing given the keyName used to be indexed in the ImageSourceThing's environment
315         * @param outKName Is the imageSourceThing keyName to search
316         * @return  The corresponding unique outline with the given key name
317         */
318         ImageSourceThing* OutlineModelManager ::getImageSourceThingByKeyName(std::string iSeourceKName)
319         {
320                 return *(imageSourceEnvironment->getThingByName(iSeourceKName));
321         }
322
323         /*
324         * Gets the an imageSectionThing given the keyName used to be indexed in the ImageSectionThing's environment
325         * @param outISectionName Is the imageSectionThing keyName to search
326         * @return  The corresponding unique outline with the given key name
327         */
328         ImageSectionThing* OutlineModelManager ::getImageSectionThingByKeyName(std::string iSectionName)
329         {
330                 return *(imagesSectionEnvironment->getThingByName(iSectionName));
331         }
332
333         /*
334         * Creates an outlineThing with a given name, if no name is given it would have an automatic
335         * @param aName The name for the outlineThing
336                 * @return Returns the key name of the created outline, or ""if it wasn't created
337         */
338 //      bool OutlineModelManager :: createOutline(std::string aName, ContourThing * &theOutline)
339         std::string  OutlineModelManager :: createOutline(manualContourModel * model, std::vector<int> theInstantData, std::string aName)
340         {
341                 ContourThing * theOutline = new ContourThing ( model );
342                 theOutline->setName(aName);             
343                 return addOutline( theOutline, new Instant( &theInstantData ) );                                
344         }
345
346         /*
347         * Creates an axeThing with a given name
348         * @param aDescription The description for the axeThing
349         * @return Returns true if the creation of the axe was successful
350         */
351         //bool OutlineModelManager :: createAxe(std::string aDescription, AxeThing * &theAxe)
352         bool  OutlineModelManager :: createAxe(std::string aDescription, Instant * theInstantData)
353         {
354                 AxeThing * theAxe = new AxeThing ();
355                 theAxe->setDescription(aDescription);                 
356                 return addAxe(theAxe, theInstantData);          
357         }
358
359         /*
360         * Creates an imageSourceThing with a given name
361         * @param aSource The name for the imageSourceThing
362         * @return Returns true if the creation of the imageSource was successful
363         */
364         //bool OutlineModelManager :: createImageSource(std::string aSource, ImageSourceThing * &imageSource)
365         bool OutlineModelManager :: createImageSource(std::string aSource, Instant * theInstantData)
366         {
367 //              imageSource = new ImageSourceThing(aSource);                
368                 //return addImageSource(new ImageSourceThing(aSource), theInstantData);         
369                 return NULL;//***********************************************************************************************
370         }
371
372         /*
373         * Creates an imageSectionThing with a given name
374         * @param aSecImageData The name for the imageSectionThing
375         * @return Returns true if the creation of the imageSection was successful
376         */
377         //bool OutlineModelManager :: createImageSection(std::string aSecImageData, ImageSectionThing * &imageSection)
378         bool OutlineModelManager :: createImageSection(std::string aSecImageData, Instant * theInstantData)
379         {
380                 //imageSection = new ImageSectionThing(aSecImageData);               
381 //              return addImageSection(new ImageSectionThing(aSecImageData), theInstantData);   
382                 return NULL;
383         }
384
385         /*
386         * Adds an outlineThing 
387         * @param theOutline The outline/contour (thing)
388         * @param theInstantData Is the instant for the outline to add
389         * @return Returns true if the addition of the outline was successful
390         */
391         std::string OutlineModelManager :: addOutline( ContourThing * theOutline, Instant * theInstantData)
392         {               
393                 std::string kName;
394
395 // EED 
396 //              bool added  = keyGenerator.generateKeyOf("Outlines", outlinesEnvironment->getNumberOfThings(),kName);
397
398                 counterIdKey++;
399                 bool added = keyGenerator.generateKeyOf( "Outlines", counterIdKey , kName );
400
401                 if( theOutline->getName().compare("")==0 )
402                 {
403                         theOutline->setName(kName);
404                 }
405                 added &= outlinesEnvironment->addThingWithInstant(kName,theOutline, theInstantData);
406                 if( added )
407                         return kName;
408                 else
409                         return "";              
410         }
411
412
413         int OutlineModelManager::IsPartOfStaticList(std::string ss)
414         {
415                 int iBack=-1;
416                 int i, size = staticContourLst.size();
417                 for( i=0 ; i<size ; i++ )
418                 {
419                         ContourThing **contourthing  = staticContourLst[i];
420                         if ((*contourthing)->getName() == ss)
421                         {
422                                 iBack=i;
423                         } // getName() == ss
424                 }
425                 return iBack;
426         }
427
428
429         /*
430         * Remove an outlineThing 
431         * @param theOutline The outline/contour (thing)
432         */
433         void OutlineModelManager :: removeOutline( std::string ss )
434         {               
435                         outlinesEnvironment->removeThing( ss );
436         }
437
438 //EED01
439         void OutlineModelManager :: removeAllOutlines()
440         {
441                 //
442                 staticContourLst.clear();
443
444                 //
445                 std::vector< ContourThing **>  thingsVector;
446                 outlinesEnvironment->getThingsOfEnvironment( &thingsVector );
447                 int i,sizeThingVector = thingsVector.size();
448                 for(i=0;i<sizeThingVector;i++) 
449                 {
450                         ContourThing ** contourthing =  thingsVector[i];
451                     removeOutline(  (*contourthing)->getName()   );
452                 }
453         }
454
455
456         /*
457         * Adds an axeThing 
458         * @param thaAxe The axe (thing)
459         * @param theInstantData Is the instant for the axe to add
460         * @return Returns true if the addition of the axe was successful
461         */
462         bool OutlineModelManager :: addAxe( AxeThing * theAxe , Instant * theInstantData)
463         {
464                 std::string kName;
465                 bool added  = keyGenerator.generateKeyOf("Axes", axesEnvironment->getNumberOfThings(),kName);           
466                 added &= axesEnvironment->addThingWithInstant(kName,theAxe, theInstantData);
467                 return added;
468         }
469
470         /*
471         * Adds an imageSourceThing 
472         * @param imgageSource The image source (thing)
473         * @param theInstantData Is the instant for the source to add
474         * @return Returns true if the addition of the imageSource was successful
475         */
476         bool OutlineModelManager :: addImageSource(ImageSourceThing * imageSource, Instant * theInstantData)
477         {
478                 std::string kName;
479                 bool added  = keyGenerator.generateKeyOf("Image Sources", imageSourceEnvironment->getNumberOfThings(),kName);
480                 added &= imageSourceEnvironment->addThingWithInstant(kName,imageSource, theInstantData );
481                 return added;
482         }
483
484         /*
485         * Adds an imageSectionThing with a given name, if no name is given it would have an automatic
486         * @param aName The imageSection (thing)
487         * @param theInstantData Is the instant for the imageSection to add
488         * @return Returns true if the addition of the imageSection was successful
489         */
490         bool OutlineModelManager :: addImageSection(ImageSectionThing * imageSection, Instant * theInstantData)
491         {               
492                 std::string kName;
493                 bool added  = keyGenerator.generateKeyOf("Image Sections", imagesSectionEnvironment->getNumberOfThings(),kName);
494                 added &= imagesSectionEnvironment->addThingWithInstant(kName, imageSection, theInstantData);
495                 return added;
496         }
497
498         /*
499         * Annotates an outline keyname at the actual instant
500         * @param kOutlineName The key name to annotate
501         * @param theRealName The real name asigned to the outline
502         */
503         void OutlineModelManager :: annotateOutlineWrap(std::string kOutlineName, std::string theRealName)
504         {
505                 actualInstantWrapping -> addOutlineName(kOutlineName, theRealName);
506         }
507
508         /*
509         * Annotates a set of outline keynames-real names wrapping at the actual instant
510         * @param kNamesVector The key names vector to annotate
511         * @param theOutlinesVector The outlines pointers vector to get the real names from
512         */
513         void OutlineModelManager :: annotateOutlinesWrap(std::vector<std::string> kNamesVector, std::vector<ContourThing **> theOutlinesVector)
514         {
515                 actualInstantWrapping ->clean();
516                 for(int i=0; i<kNamesVector.size(); i++)
517                 {
518                         ContourThing * anOutline = *theOutlinesVector[i];
519                         actualInstantWrapping -> addOutlineName( kNamesVector[i], anOutline->getName() );
520                 }
521         }
522         
523         /*
524         * Annotates the actual outline keyName-real name wrapping at the actual instant
525         * @param actualKeyOutline The key name to annotate
526         * @param theRealName The real name asigned to the actual outline
527         */
528         void OutlineModelManager :: annotateActualOutlineWrap(std::string actualKeyOutline, std::string theRealName)
529         {
530                 actualInstantWrapping -> setActualOutline(actualKeyOutline, theRealName);
531         }
532
533         /*
534         * Annotate the actual axe keyName-real name wrapping at the actual instant
535         * @param actualKeyAxe The key name to annotate
536         * @param theRealName The real name asigned to the actual axe
537         */
538         void OutlineModelManager :: annotateActualAxeWrap(std::string actualKeyAxe, std::string theRealName)
539         {
540                 actualInstantWrapping -> setActualAxeWrap(actualKeyAxe, theRealName);
541         }
542
543         /*
544         * Annotate the annotateActualSection image keyName-real name wrapping at the actual instant
545         * @param actualKeyImage The key name to annotate
546         * @param theRealName The real name asigned to the annotateActualSection
547         */
548         void OutlineModelManager :: annotateActualSectionImageWrap(std::string actualKeyImage, std::string theRealName)//---BORRAR...
549         {
550                 actualInstantWrapping -> setActualSectionImageNamesWrapp(actualKeyImage, theRealName);
551         } 
552
553         /*
554         * Annotate the annotateActualSource image keyName-real name wrapping at the actual instant
555         * @param actualKeyImage The key name to annotate
556         * @param theRealName The real name asigned to the annotateActualSource 
557         */
558         void OutlineModelManager :: annotateActualSourceImageWrap(std::string actualKeyImage, std::string theRealName)//---BORRAR...
559         {
560                 actualInstantWrapping -> setActualSourceImageNamesWrapp(actualKeyImage, theRealName);
561         } 
562
563
564         /*
565         * Sets the actual instant and manage the search of the corresponding elements with the specified instant in all the enviornments
566         * @param newActualInstantData Is the instant data
567         */
568         void OutlineModelManager :: setInstant(Instant * newActualInstantData)
569         {
570                 actualInstant = newActualInstantData;
571                 updateToActualInstant();
572         }
573
574         /*
575         * Gets the an axe with a given keyName
576         * @axeKName The axe keyName for searching in the axes environment
577         * @return The corresponding axe
578         */
579         AxeThing * OutlineModelManager :: getAxeByKeyName(std::string axeKName)
580         {
581                 return *axesEnvironment->getThingByName(axeKName);
582         }
583
584         /*
585         * Gets the instants of a specific outline
586         * @param thekName Is the name of the outline
587         * @return The instants set 
588         */
589         std::vector<Instant *> OutlineModelManager :: getOutlineInstantsByName(std::string thekName)
590         {               
591                 return *outlinesEnvironment->getInstantsOfThing(thekName);              
592         }
593
594         /*
595         * Gets all instants outlines
596         * @return The instants set 
597         */
598         std::vector<Instant *> OutlineModelManager :: getOutlineInstants()
599         {               
600                 return *outlinesEnvironment->getExistingInstants();             
601         }
602
603
604
605         /*
606         * Includes an instant to the specified axe
607         * @param outKName Is outline key name
608         * @param anInstantData Is the instant data
609         * @return Returns if the insertion was successful or not
610         */
611         bool OutlineModelManager :: includeOutlineInstant(std::string outKName,Instant * anInstantData)
612         {
613                 return outlinesEnvironment->addInstantToThing(outKName,anInstantData);
614         }
615
616         /*
617         * Includes an instant to the specified axe
618         * @param axeKName Is axe key name
619         * @param anInstantData Is the instant data
620         * @return Returns if the insertion was successful or not
621         */
622         bool OutlineModelManager :: includeAxeInstant(std::string axeKName,Instant * anInstantData)
623         {
624                 return axesEnvironment->addInstantToThing( axeKName,anInstantData );
625         }
626
627         /*
628         * Includes an instant to the specified image section
629         * @param imaKName Is the image section key name
630         * @param anInstantData Is the instant data
631         * @return Returns if the insertion was successful or not
632         */
633         bool OutlineModelManager :: includeImageSectionInstant(std::string imaKName,Instant * anInstantData)
634         {
635                 return imagesSectionEnvironment->addInstantToThing( imaKName,anInstantData );
636         }
637
638         /*
639         * Includes an instant to the specified image source
640         * @param imaKName Is the image section key name
641         * @param anInstantData Is the instant data
642         * @return Returns if the insertion was successful or not
643         */
644         bool OutlineModelManager :: includeImageSourceInstant(std::string imaKName,Instant * anInstantData)
645         {
646                 return imageSourceEnvironment->addInstantToThing( imaKName,anInstantData );
647         }
648         
649         /*
650         *       Method that retorns the name of each concept and the size of it.
651         *       @param conceptNameVect, Vector in which is disposed to be setted the name for each of the included concepts
652         *       @param conceptSizeVect, Vector in which is disposed to be setted the size for each of the included concepts
653         */
654         void OutlineModelManager :: getConceptsInformation(std::vector<std::string>& conceptNameVect, std::vector<int>& conceptSizeVect)
655         {
656                 if( outlinesEnvironment != NULL )
657                 {
658                         //if (outlinesEnvironment->getNumberOfThings()>0)
659                                 outlinesEnvironment->getConceptsInformation(conceptNameVect, conceptSizeVect);
660                 }       
661         }
662
663
664         /*
665         * Gets the contourWorspace 
666         * @return Returns the workspace
667         */
668         ContourWorkspace * OutlineModelManager :: getContourWorkspace()
669         {
670                 return workSpace;
671         }
672
673
674         /*
675         * Cleans the outline model manager and its dependencies
676         */
677         void OutlineModelManager :: clean()
678         {
679                 /*axesEnvironment->clean();
680                 imagesSectionEnvironment->clean();
681                 imageSourceEnvironment->clean();
682                 outlinesEnvironment->clean();*/
683                 outlineGroups.clear();
684                 actualInstantWrapping->clean();
685                 keyGenerator.clear();
686                 //workSpace->clear();
687         }
688
689         /*
690         * Update the registered objects in the InstantMemebersNameList, is the one that really changes the instant in the model
691         */
692         void OutlineModelManager :: updateToActualInstant()
693         {               
694                 Instant * longInstant = actualInstant;
695                 /*Instant * mediumInstant = new Instant();
696                 Instant * shortInstant = new Instant();         
697                 std::vector<int>* theInstant = longInstant->getInstant();
698                 for(int i=1; i<theInstant->size(); i++)
699                 {
700                         if (i>=2)
701                                 shortInstant->addConcept( (*theInstant)[i] );
702                         mediumInstant->addConcept( (*theInstant)[i] );
703                 }
704                 
705                 //getting the sourceAtInstant
706                 std::vector<std::string> kSourceVector;
707                 std::vector<ImageSourceThing **> imSourceVector;
708                 imageSourceEnvironment->getThings(kSourceVector, imSourceVector, shortInstant);
709                 annotateActualSourceImageWrap(kSourceVector[0], (**imSourceVector[0]).getSourceImage());
710
711         //getting the aAxeAtInstant 
712                 std::vector<std::string> kAxeVector;
713                 std::vector<AxeThing **> axesVector;
714                 axesEnvironment->getThings(kAxeVector, axesVector, mediumInstant);
715                 if ( !kAxeVector.empty() )
716                         annotateActualAxeWrap(kAxeVector[0], (**axesVector[0]).getDescription());
717
718                 //getting the sectionAtInstant
719                 std::vector<std::string> kSectionVector;
720                 std::vector<ImageSectionThing **> imSectionVector;
721                 imagesSectionEnvironment->getThings(kSectionVector, imSectionVector, longInstant); if ( !kSectionVector.empty() )
722             //annotateActualSectionImageWrap(kSectionVector[0], (**imSectionVector[0]).getImageData());
723                 */
724                 
725                 //getting the outlines          
726
727                 std::vector<ContourThing ** > vect = getOutlinesAtInstant( longInstant );
728
729         }
730         
731         /*
732         * Sets the automatic managed concepts including them in the environments. That are at the beginning of the instant vector for the corresponding environments.   
733         * @return Returns true if successful insert of the automatic concepts, false otherwise
734         */
735         bool OutlineModelManager :: setAutomaticConcepts()
736         {
737                 axeConcept = "Axe";
738                 axeDepthConcept = "Axe Depth";
739                 int axeC_size = 10;
740                 int axeDepthC_size = INT_MAX;
741
742                 bool allOK = axesEnvironment->addConcept(axeConcept, axeC_size);
743                 allOK &= imagesSectionEnvironment->addConcept(axeConcept, axeC_size);
744                 allOK &= outlinesEnvironment->addConcept(axeConcept, axeC_size);
745                 
746                 allOK &= imagesSectionEnvironment->addConcept(axeDepthConcept, axeDepthC_size);
747                 allOK &= outlinesEnvironment->addConcept(axeDepthConcept, axeDepthC_size);
748 /*
749                 allOK &= keyGenerator.addKeyThing("Axes", "Axe");
750                 allOK &= keyGenerator.addKeyThing("Image Sources", "Image source");
751                 allOK &= keyGenerator.addKeyThing("Image Sections", "Image section");
752                 allOK &= keyGenerator.addKeyThing("Outlines", "Outline");*/
753
754                 return allOK;
755         }
756
757
758         std::string OutlineModelManager :: createCopyContourOf( std::string anExistingKName, std::vector<int> &instantNoTouchData )
759         {
760                 manualContourModel * manModelContour  = getOutlineByKeyName( anExistingKName )->getModel()->Clone();
761                 return createOutline( manModelContour, instantNoTouchData );
762         }
763
764         void OutlineModelManager::SaveThingName( FILE *pFile, std::string nameThing )
765         {
766                 std::vector< Instant * > *lstInstants;
767                 lstInstants = outlinesEnvironment->getInstantsOfThing( nameThing );
768                 Instant *instant = (*lstInstants)[0];
769                 std::vector<int> *vecInst =instant->getInstant();
770                 int i,sizeVecInst = vecInst->size();
771                 fprintf(pFile,"Instant ");
772                 for ( i=0 ; i<sizeVecInst ; i++ )
773                 {
774                         fprintf(pFile,"%d ",(*vecInst)[i]);
775                 }
776                 fprintf(pFile,"\n");
777                 ContourThing *contourthing = *outlinesEnvironment->getThingByName(nameThing);
778                 contourthing->getModel()->Save(pFile);
779         }
780