]> Creatis software - creaEnvironment.git/blob - lib/kernel_Environment/InstantPlayer_Txx.h
ae3361d3930260b2f52f5e70b43529466694f77b
[creaEnvironment.git] / lib / kernel_Environment / InstantPlayer_Txx.h
1 /*=========================================================================
2
3   Program:  InstantPlayer
4   Module:    $RCSfile: InstantPlayer_Txx.h,v $
5   Language:  C++
6   Date:      $Date: 2008/10/31 15:08:40 $
7   Version:   $Revision: 1.1 $
8   Objective: it do the play methods as stop,pause, play, etc using an instant handler
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 // SYSTEM INCLUDES
21
22
23 // PROJECT INCLUDES
24
25
26 // LOCAL INCLUDES
27
28
29
30 // FORWARD REFERENCES
31
32 //NAMESPACE
33
34
35                         //========= LYFECYCLE ==========
36                         template<class S>
37                         InstantPlayer<S>::InstantPlayer(SomeEnvironment<S>* environment)throw (ViewerNDimensionsException)
38                                 {
39                                         this->environment=environment;
40                                         if(environment)
41                                                 this->instantHandler= new InstantHandler<S>(this->environment);
42                                         else
43                                                 throw new ViewerNDimensionsException("ERROR ENVIRONMENT NULL");
44                                         //this->thingsOfInstant=NULL;
45                                         //this->timeReproduction=100;
46                                 }
47                         
48                         template<class S>
49                         InstantPlayer<S>::~InstantPlayer()
50                                 {
51                                         if(instantHandler) delete instantHandler;
52                                 }
53                         
54                         
55                         //========= OPERATIONS =========
56                         /*
57                         *       When the user wants to play  the dimensions selected by the user
58                         *       and are already defined
59                         *       @return
60                         */
61                         /*
62                         template<class S>
63                         void InstantPlayer<S>::play()
64                                 {
65                                         //setTimeConceptToMode(REAL_TIME);
66                                         instantHandler->nextInstant();
67                                 }
68                         /*
69                         *       Paused the reproduction of the dimension played
70                         *       @return
71                         */
72                         template<class S> 
73                         void InstantPlayer<S>::pause()
74                                 {
75                                         //setTimeConceptToMode(PLUS_PLUS);
76                                         return;                 
77                                 }
78                         /*
79                         *       Used for change to the next instant in the reproduction
80                         *       Note: next instant from the instant that's being reproduced
81                         *       @param loop , if want to do next instant with looping
82                         *       @return true if the player has changed of instant, false if not
83                         */
84
85                         template<class S>
86          
87                         bool InstantPlayer<S>::nextInstant(bool loop)throw (ViewerNDimensionsException)
88                                 {
89                                         //setTimeConceptToMode(PLUS_PLUS);
90                                         bool hasChanged=false;
91                                         bool hasNextInstant=instantHandler->hasNextInstant();
92                                         if(hasNextInstant)
93                                                 {
94                                                         instantHandler->nextInstant();
95                                                         hasChanged=true;
96                                                 }
97                                         else if(!loop)
98                                                         instantHandler->set();
99                                         else if(loop)
100                                                 {
101                                                         instantHandler->resetConceptsHandled();
102                                                         //instantHandler->set();
103                                                         hasChanged=true;
104                                                 }
105                                         return hasChanged;
106                                 }
107                         /*
108                         *       Used for change to the previous instant in the reproduction
109                         *       Note: previous instant from the instant that's being reproduced
110                         *       @return true if the player has changed of instant, false if not
111                         */
112                         template<class S>
113                         bool InstantPlayer<S>::previousInstant()throw (ViewerNDimensionsException)
114                                 {
115                                         //setTimeConceptToMode(PLUS_PLUS);
116                                         bool hasChanged=false;
117                                         bool hasPreviousInstant=instantHandler->hasPreviousInstant();
118                                         if(hasPreviousInstant)
119                                                 {
120                                                         instantHandler->previousInstant();
121                                                         hasChanged=true;
122                                                 }
123                                         else
124                                                 instantHandler->set();
125                                         return hasChanged;
126                                                 
127                                 }
128                         /*
129                         *       Used for stops the reproductioN
130                         *       @param
131                         *       @return
132                         */
133                         template<class S>
134                          void InstantPlayer<S>::stop()
135                          {
136                                 //setTimeConceptToMode(REAL_TIME);
137                                 instantHandler->resetConceptsHandled();
138                                 
139                          }
140                         /*
141                         * Removes all the concept handled
142                         */
143                          template<class S>
144                          void InstantPlayer<S>::removeAllConcepts()
145                          {
146                                 instantHandler->removeAllConcepts();
147                                 
148                          }
149                         
150                          /*
151                          *      Removes the concept with the name given
152                          *      @param nameConcept, name of the concept to remove
153                          */
154                          template<class S>
155                          void InstantPlayer<S>::removeConceptToHandled(std::string nameConcept)
156                          {
157                                         instantHandler->removeConceptToHandled(nameConcept);    
158                          }
159                          //====== INQUIRY ========
160
161                          /*
162                          *      Returns the things of the actual instant
163                          */
164                          template<class S>
165                          std::vector<S*>* InstantPlayer<S>::getThingsOfInstant() throw (ViewerNDimensionsException)
166                                  {                                      
167                                         Instant* actualInstant= instantHandler->getActualInstant();
168                                         //load the things of the actual instant
169                                         return environment->getThings(actualInstant);
170                                  }
171                          
172                           /*
173                          * return the actual instant in the instant handler
174                          */
175                           template<class S>
176                          Instant* InstantPlayer<S>::getActualInstant()throw (ViewerNDimensionsException)
177                                   {
178                                         return instantHandler->getActualInstant();
179                                   }
180                           /*
181                          *       add new concept to handled 
182                          *       @param nameConcept
183                          *       @param mode= REAL_TIME,PLUS_PLUS
184                          *       @param position, position in the player
185                          */
186                           template<class S>
187                           bool InstantPlayer<S>::addConceptToHandled(std::string nameConcept,int mode,int position)throw (ViewerNDimensionsException)
188                                   {
189                                         return instantHandler->addConceptToHandled(nameConcept,mode,position);
190                                   }
191                          /*
192                          *  Returns the things of the actual instants and its names in the 
193                          *      environment
194                          */
195                          template<class S>
196                          void InstantPlayer<S>::getThingsWithName(std::vector<std::string>& names,std::vector< S* >& thingsVector)throw (ViewerNDimensionsException)
197                                  {
198                                         Instant* actualInstant= instantHandler->getActualInstant();
199                                         environment->getThings(names,thingsVector,actualInstant);
200                                  }
201                          /*
202                         * Returns the names of the concepts handled and its modes
203                         *       DEPRECATED
204                         */
205                           template<class S>
206                           void InstantPlayer<S>::getConceptsInfo(std::vector<std::string>& namesConcepts,std::vector<int>& modes)
207                                 {
208                                         instantHandler->getConceptsInfo(namesConcepts,modes);
209                                 }
210                          /*
211                          *      Returns the name of the concept that handled the real time
212                          *      DEPRECATED
213                          */
214                          template<class S>
215                          void InstantPlayer<S>::getTimeConcept(std::string& nameConcept)
216                                  {
217                                         instantHandler->getTimeConcept(nameConcept);
218                                  }
219                          /*
220                          * get the number of instants that is playing
221                          */
222                          template<class S>
223                          int InstantPlayer<S>::getNumInstantsPlaying()
224                                  {
225                                         return instantHandler->getNumOfInstants();
226                                  }
227                           /*
228                          *      Returns the names of the concept with its respectively actual value
229                          *      @param conceptsAndIndexes is where is going to be save the data searched
230                          */
231                           template<class S>
232                           void InstantPlayer<S>::getConceptsActualIndexes(std::map<std::string,int>* conceptsAndIndexes)throw (ViewerNDimensionsException)
233                                   {
234                                         std::vector<std::string> conceptsNames;
235                                         environment->getConceptsNames(conceptsNames);
236                                         int instantIndex,i,size,index;
237                                         size=conceptsNames.size();
238                                         Instant* actualInstant= getActualInstant();
239                                         std::string conceptNamei;
240                                         for(i=0;i<size;i++)
241                                                 {
242                                                         conceptNamei=conceptsNames[i];
243                                                         instantIndex=environment->getIndexConcept(conceptNamei);
244                                                         index=actualInstant->getIndexInConcept(instantIndex);
245                                                         conceptsAndIndexes->insert(std::pair<std::string,int>(conceptNamei,index));
246                                                         conceptNamei.clear();
247
248                                                 }
249                                         
250                                   }
251
252                          //========= ACCESS =========
253                          /*
254                          * Sets the time of reproduction of the concept 
255                          * that managed the real time
256                          */
257                          template<class S>
258                          void InstantPlayer<S>::setTimeReproduction(double time)
259                                  {
260                                         //this->timeReproduction=time;
261                                         instantHandler->setTimeReproduction(time);
262                                  }
263                          /*
264                          *      Sets the environment
265                          */
266                          template<class S>
267                          void InstantPlayer<S>::setEnvironment(SomeEnvironment<S>* environmment)
268                                  {
269                                         this->environment=environmment;
270                                  }
271                          /*
272                          *      Set Actual Instant
273                          */
274                          template<class S>
275                          void InstantPlayer<S>::setActualInstant(Instant* actualInstant)
276                                   {
277                                         instantHandler->setActualInstant(actualInstant);
278                                   }
279                           /*
280                          *      Set Actual Instant
281                          */
282                          template<class S>
283                          void InstantPlayer<S>::setActualInstant(std::vector<int>* actualInstant)
284                                  {
285                                         Instant* instant=new Instant(actualInstant);
286                                         instantHandler->setActualInstant(instant);
287                                         delete instant;
288                                  }
289                          /*
290                         * Set the increase Value for changing the instant
291                         */
292                         template<class S>
293                         void InstantPlayer<S>::setIncreaseValue(int increase)
294                                 {
295                                         instantHandler->setIncreaseValue(increase);
296                                 }
297                         /*
298                         * Set the decrease Value for changing the instant
299                         */
300                         template<class S>
301                         void InstantPlayer<S>::setDecreaseValue(int decrease)
302                                 {
303                                         instantHandler->setDecreaseValue(decrease);
304                                 }
305
306                           /*
307                          * Set the mode of a concept that's being handled
308                          */
309                          /*
310                           template<class S>
311                          void InstantPlayer<S>::setModeOfConcept(std::string nameConcept,int mode)
312                                   {
313                                         instantHandler->setModeOfConcept(nameConcept,mode);
314                                   }
315                          /*
316                          * Set actual time to the instant handler
317                          */
318                           /*
319                           template<class S>
320                          void InstantPlayer<S>::setActualTime(double actualTime)
321                                   {
322                                         instantHandler->setActualTime(actualTime);
323                                   }
324                           /*
325                          * set the modes of the concept that handled the time
326                          * to the plus plus mode
327                          */
328                         /* 
329                         template<class S>
330                         void InstantPlayer<S>::setTimeConceptToMode(int mode)
331                                   {
332                                         std::string nameConcept;
333                                         getTimeConcept(nameConcept);
334                                         setModeOfConcept(nameConcept,mode);
335                                   }
336                          */