]> Creatis software - creaEnvironment.git/blob - lib/kernel_Environment/InstantPlayer_Txx.h
License Files Headers
[creaEnvironment.git] / lib / kernel_Environment / InstantPlayer_Txx.h
1 /*
2  # ---------------------------------------------------------------------
3  #
4  # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5  #                        pour la SantÈ)
6  # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7  # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8  # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9  #
10  #  This software is governed by the CeCILL-B license under French law and
11  #  abiding by the rules of distribution of free software. You can  use,
12  #  modify and/ or redistribute the software under the terms of the CeCILL-B
13  #  license as circulated by CEA, CNRS and INRIA at the following URL
14  #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15  #  or in the file LICENSE.txt.
16  #
17  #  As a counterpart to the access to the source code and  rights to copy,
18  #  modify and redistribute granted by the license, users are provided only
19  #  with a limited warranty  and the software's author,  the holder of the
20  #  economic rights,  and the successive licensors  have only  limited
21  #  liability.
22  #
23  #  The fact that you are presently reading this means that you have had
24  #  knowledge of the CeCILL-B license and that you accept its terms.
25  # ------------------------------------------------------------------------ */
26
27 /*=========================================================================
28
29   Program:  InstantPlayer
30   Module:    $RCSfile: InstantPlayer_Txx.h,v $
31   Language:  C++
32   Date:      $Date: 2012/11/15 12:12:26 $
33   Version:   $Revision: 1.2 $
34   Objective: it do the play methods as stop,pause, play, etc using an instant handler
35   Authot:       Monica Maria Lozano Romero
36
37   Copyright: (c) 2007
38   License:
39
40      This software is distributed WITHOUT ANY WARRANTY; without even
41      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
42      PURPOSE.  See the above copyright notice for more information.
43
44
45 =========================================================================*/                     
46 // SYSTEM INCLUDES
47
48
49 // PROJECT INCLUDES
50
51
52 // LOCAL INCLUDES
53
54
55
56 // FORWARD REFERENCES
57
58 //NAMESPACE
59
60
61                         //========= LYFECYCLE ==========
62                         template<class S>
63                         InstantPlayer<S>::InstantPlayer(SomeEnvironment<S>* environment)throw (ViewerNDimensionsException)
64                                 {
65                                         this->environment=environment;
66                                         if(environment)
67                                                 this->instantHandler= new InstantHandler<S>(this->environment);
68                                         else
69                                                 throw new ViewerNDimensionsException("ERROR ENVIRONMENT NULL");
70                                         //this->thingsOfInstant=NULL;
71                                         //this->timeReproduction=100;
72                                 }
73                         
74                         template<class S>
75                         InstantPlayer<S>::~InstantPlayer()
76                                 {
77                                         if(instantHandler) delete instantHandler;
78                                 }
79                         
80                         
81                         //========= OPERATIONS =========
82                         /*
83                         *       When the user wants to play  the dimensions selected by the user
84                         *       and are already defined
85                         *       @return
86                         */
87                         /*
88                         template<class S>
89                         void InstantPlayer<S>::play()
90                                 {
91                                         //setTimeConceptToMode(REAL_TIME);
92                                         instantHandler->nextInstant();
93                                 }
94                         /*
95                         *       Paused the reproduction of the dimension played
96                         *       @return
97                         */
98                         template<class S> 
99                         void InstantPlayer<S>::pause()
100                                 {
101                                         //setTimeConceptToMode(PLUS_PLUS);
102                                         return;                 
103                                 }
104                         /*
105                         *       Used for change to the next instant in the reproduction
106                         *       Note: next instant from the instant that's being reproduced
107                         *       @param loop , if want to do next instant with looping
108                         *       @return true if the player has changed of instant, false if not
109                         */
110
111                         template<class S>
112          
113                         bool InstantPlayer<S>::nextInstant(bool loop)throw (ViewerNDimensionsException)
114                                 {
115                                         //setTimeConceptToMode(PLUS_PLUS);
116                                         bool hasChanged=false;
117                                         bool hasNextInstant=instantHandler->hasNextInstant();
118                                         if(hasNextInstant)
119                                                 {
120                                                         instantHandler->nextInstant();
121                                                         hasChanged=true;
122                                                 }
123                                         else if(!loop)
124                                                         instantHandler->set();
125                                         else if(loop)
126                                                 {
127                                                         instantHandler->resetConceptsHandled();
128                                                         //instantHandler->set();
129                                                         hasChanged=true;
130                                                 }
131                                         return hasChanged;
132                                 }
133                         /*
134                         *       Used for change to the previous instant in the reproduction
135                         *       Note: previous instant from the instant that's being reproduced
136                         *       @return true if the player has changed of instant, false if not
137                         */
138                         template<class S>
139                         bool InstantPlayer<S>::previousInstant()throw (ViewerNDimensionsException)
140                                 {
141                                         //setTimeConceptToMode(PLUS_PLUS);
142                                         bool hasChanged=false;
143                                         bool hasPreviousInstant=instantHandler->hasPreviousInstant();
144                                         if(hasPreviousInstant)
145                                                 {
146                                                         instantHandler->previousInstant();
147                                                         hasChanged=true;
148                                                 }
149                                         else
150                                                 instantHandler->set();
151                                         return hasChanged;
152                                                 
153                                 }
154                         /*
155                         *       Used for stops the reproductioN
156                         *       @param
157                         *       @return
158                         */
159                         template<class S>
160                          void InstantPlayer<S>::stop()
161                          {
162                                 //setTimeConceptToMode(REAL_TIME);
163                                 instantHandler->resetConceptsHandled();
164                                 
165                          }
166                         /*
167                         * Removes all the concept handled
168                         */
169                          template<class S>
170                          void InstantPlayer<S>::removeAllConcepts()
171                          {
172                                 instantHandler->removeAllConcepts();
173                                 
174                          }
175                         
176                          /*
177                          *      Removes the concept with the name given
178                          *      @param nameConcept, name of the concept to remove
179                          */
180                          template<class S>
181                          void InstantPlayer<S>::removeConceptToHandled(std::string nameConcept)
182                          {
183                                         instantHandler->removeConceptToHandled(nameConcept);    
184                          }
185                          //====== INQUIRY ========
186
187                          /*
188                          *      Returns the things of the actual instant
189                          */
190                          template<class S>
191                          std::vector<S*>* InstantPlayer<S>::getThingsOfInstant() throw (ViewerNDimensionsException)
192                                  {                                      
193                                         Instant* actualInstant= instantHandler->getActualInstant();
194                                         //load the things of the actual instant
195                                         return environment->getThings(actualInstant);
196                                  }
197                          
198                           /*
199                          * return the actual instant in the instant handler
200                          */
201                           template<class S>
202                          Instant* InstantPlayer<S>::getActualInstant()throw (ViewerNDimensionsException)
203                                   {
204                                         return instantHandler->getActualInstant();
205                                   }
206                           /*
207                          *       add new concept to handled 
208                          *       @param nameConcept
209                          *       @param mode= REAL_TIME,PLUS_PLUS
210                          *       @param position, position in the player
211                          */
212                           template<class S>
213                           bool InstantPlayer<S>::addConceptToHandled(std::string nameConcept,int mode,int position)throw (ViewerNDimensionsException)
214                                   {
215                                         return instantHandler->addConceptToHandled(nameConcept,mode,position);
216                                   }
217                          /*
218                          *  Returns the things of the actual instants and its names in the 
219                          *      environment
220                          */
221                          template<class S>
222                          void InstantPlayer<S>::getThingsWithName(std::vector<std::string>& names,std::vector< S* >& thingsVector)throw (ViewerNDimensionsException)
223                                  {
224                                         Instant* actualInstant= instantHandler->getActualInstant();
225                                         environment->getThings(names,thingsVector,actualInstant);
226                                  }
227                          /*
228                         * Returns the names of the concepts handled and its modes
229                         *       DEPRECATED
230                         */
231                           template<class S>
232                           void InstantPlayer<S>::getConceptsInfo(std::vector<std::string>& namesConcepts,std::vector<int>& modes)
233                                 {
234                                         instantHandler->getConceptsInfo(namesConcepts,modes);
235                                 }
236                          /*
237                          *      Returns the name of the concept that handled the real time
238                          *      DEPRECATED
239                          */
240                          template<class S>
241                          void InstantPlayer<S>::getTimeConcept(std::string& nameConcept)
242                                  {
243                                         instantHandler->getTimeConcept(nameConcept);
244                                  }
245                          /*
246                          * get the number of instants that is playing
247                          */
248                          template<class S>
249                          int InstantPlayer<S>::getNumInstantsPlaying()
250                                  {
251                                         return instantHandler->getNumOfInstants();
252                                  }
253                           /*
254                          *      Returns the names of the concept with its respectively actual value
255                          *      @param conceptsAndIndexes is where is going to be save the data searched
256                          */
257                           template<class S>
258                           void InstantPlayer<S>::getConceptsActualIndexes(std::map<std::string,int>* conceptsAndIndexes)throw (ViewerNDimensionsException)
259                                   {
260                                         std::vector<std::string> conceptsNames;
261                                         environment->getConceptsNames(conceptsNames);
262                                         int instantIndex,i,size,index;
263                                         size=conceptsNames.size();
264                                         Instant* actualInstant= getActualInstant();
265                                         std::string conceptNamei;
266                                         for(i=0;i<size;i++)
267                                                 {
268                                                         conceptNamei=conceptsNames[i];
269                                                         instantIndex=environment->getIndexConcept(conceptNamei);
270                                                         index=actualInstant->getIndexInConcept(instantIndex);
271                                                         conceptsAndIndexes->insert(std::pair<std::string,int>(conceptNamei,index));
272                                                         conceptNamei.clear();
273
274                                                 }
275                                         
276                                   }
277
278                          //========= ACCESS =========
279                          /*
280                          * Sets the time of reproduction of the concept 
281                          * that managed the real time
282                          */
283                          template<class S>
284                          void InstantPlayer<S>::setTimeReproduction(double time)
285                                  {
286                                         //this->timeReproduction=time;
287                                         instantHandler->setTimeReproduction(time);
288                                  }
289                          /*
290                          *      Sets the environment
291                          */
292                          template<class S>
293                          void InstantPlayer<S>::setEnvironment(SomeEnvironment<S>* environmment)
294                                  {
295                                         this->environment=environmment;
296                                  }
297                          /*
298                          *      Set Actual Instant
299                          */
300                          template<class S>
301                          void InstantPlayer<S>::setActualInstant(Instant* actualInstant)
302                                   {
303                                         instantHandler->setActualInstant(actualInstant);
304                                   }
305                           /*
306                          *      Set Actual Instant
307                          */
308                          template<class S>
309                          void InstantPlayer<S>::setActualInstant(std::vector<int>* actualInstant)
310                                  {
311                                         Instant* instant=new Instant(actualInstant);
312                                         instantHandler->setActualInstant(instant);
313                                         delete instant;
314                                  }
315                          /*
316                         * Set the increase Value for changing the instant
317                         */
318                         template<class S>
319                         void InstantPlayer<S>::setIncreaseValue(int increase)
320                                 {
321                                         instantHandler->setIncreaseValue(increase);
322                                 }
323                         /*
324                         * Set the decrease Value for changing the instant
325                         */
326                         template<class S>
327                         void InstantPlayer<S>::setDecreaseValue(int decrease)
328                                 {
329                                         instantHandler->setDecreaseValue(decrease);
330                                 }
331
332                           /*
333                          * Set the mode of a concept that's being handled
334                          */
335                          /*
336                           template<class S>
337                          void InstantPlayer<S>::setModeOfConcept(std::string nameConcept,int mode)
338                                   {
339                                         instantHandler->setModeOfConcept(nameConcept,mode);
340                                   }
341                          /*
342                          * Set actual time to the instant handler
343                          */
344                           /*
345                           template<class S>
346                          void InstantPlayer<S>::setActualTime(double actualTime)
347                                   {
348                                         instantHandler->setActualTime(actualTime);
349                                   }
350                           /*
351                          * set the modes of the concept that handled the time
352                          * to the plus plus mode
353                          */
354                         /* 
355                         template<class S>
356                         void InstantPlayer<S>::setTimeConceptToMode(int mode)
357                                   {
358                                         std::string nameConcept;
359                                         getTimeConcept(nameConcept);
360                                         setModeOfConcept(nameConcept,mode);
361                                   }
362                          */