1 /*=========================================================================
4 Module: $RCSfile: InstantPlayer_Txx.h,v $
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
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.
19 =========================================================================*/
35 //========= LYFECYCLE ==========
37 InstantPlayer<S>::InstantPlayer(SomeEnvironment<S>* environment)throw (ViewerNDimensionsException)
39 this->environment=environment;
41 this->instantHandler= new InstantHandler<S>(this->environment);
43 throw new ViewerNDimensionsException("ERROR ENVIRONMENT NULL");
44 //this->thingsOfInstant=NULL;
45 //this->timeReproduction=100;
49 InstantPlayer<S>::~InstantPlayer()
51 if(instantHandler) delete instantHandler;
55 //========= OPERATIONS =========
57 * When the user wants to play the dimensions selected by the user
58 * and are already defined
63 void InstantPlayer<S>::play()
65 //setTimeConceptToMode(REAL_TIME);
66 instantHandler->nextInstant();
69 * Paused the reproduction of the dimension played
73 void InstantPlayer<S>::pause()
75 //setTimeConceptToMode(PLUS_PLUS);
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
87 bool InstantPlayer<S>::nextInstant(bool loop)throw (ViewerNDimensionsException)
89 //setTimeConceptToMode(PLUS_PLUS);
90 bool hasChanged=false;
91 bool hasNextInstant=instantHandler->hasNextInstant();
94 instantHandler->nextInstant();
98 instantHandler->set();
101 instantHandler->resetConceptsHandled();
102 //instantHandler->set();
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
113 bool InstantPlayer<S>::previousInstant()throw (ViewerNDimensionsException)
115 //setTimeConceptToMode(PLUS_PLUS);
116 bool hasChanged=false;
117 bool hasPreviousInstant=instantHandler->hasPreviousInstant();
118 if(hasPreviousInstant)
120 instantHandler->previousInstant();
124 instantHandler->set();
129 * Used for stops the reproductioN
134 void InstantPlayer<S>::stop()
136 //setTimeConceptToMode(REAL_TIME);
137 instantHandler->resetConceptsHandled();
141 * Removes all the concept handled
144 void InstantPlayer<S>::removeAllConcepts()
146 instantHandler->removeAllConcepts();
151 * Removes the concept with the name given
152 * @param nameConcept, name of the concept to remove
155 void InstantPlayer<S>::removeConceptToHandled(std::string nameConcept)
157 instantHandler->removeConceptToHandled(nameConcept);
159 //====== INQUIRY ========
162 * Returns the things of the actual instant
165 std::vector<S*>* InstantPlayer<S>::getThingsOfInstant() throw (ViewerNDimensionsException)
167 Instant* actualInstant= instantHandler->getActualInstant();
168 //load the things of the actual instant
169 return environment->getThings(actualInstant);
173 * return the actual instant in the instant handler
176 Instant* InstantPlayer<S>::getActualInstant()throw (ViewerNDimensionsException)
178 return instantHandler->getActualInstant();
181 * add new concept to handled
183 * @param mode= REAL_TIME,PLUS_PLUS
184 * @param position, position in the player
187 bool InstantPlayer<S>::addConceptToHandled(std::string nameConcept,int mode,int position)throw (ViewerNDimensionsException)
189 return instantHandler->addConceptToHandled(nameConcept,mode,position);
192 * Returns the things of the actual instants and its names in the
196 void InstantPlayer<S>::getThingsWithName(std::vector<std::string>& names,std::vector< S* >& thingsVector)throw (ViewerNDimensionsException)
198 Instant* actualInstant= instantHandler->getActualInstant();
199 environment->getThings(names,thingsVector,actualInstant);
202 * Returns the names of the concepts handled and its modes
206 void InstantPlayer<S>::getConceptsInfo(std::vector<std::string>& namesConcepts,std::vector<int>& modes)
208 instantHandler->getConceptsInfo(namesConcepts,modes);
211 * Returns the name of the concept that handled the real time
215 void InstantPlayer<S>::getTimeConcept(std::string& nameConcept)
217 instantHandler->getTimeConcept(nameConcept);
220 * get the number of instants that is playing
223 int InstantPlayer<S>::getNumInstantsPlaying()
225 return instantHandler->getNumOfInstants();
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
232 void InstantPlayer<S>::getConceptsActualIndexes(std::map<std::string,int>* conceptsAndIndexes)throw (ViewerNDimensionsException)
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;
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();
252 //========= ACCESS =========
254 * Sets the time of reproduction of the concept
255 * that managed the real time
258 void InstantPlayer<S>::setTimeReproduction(double time)
260 //this->timeReproduction=time;
261 instantHandler->setTimeReproduction(time);
264 * Sets the environment
267 void InstantPlayer<S>::setEnvironment(SomeEnvironment<S>* environmment)
269 this->environment=environmment;
275 void InstantPlayer<S>::setActualInstant(Instant* actualInstant)
277 instantHandler->setActualInstant(actualInstant);
283 void InstantPlayer<S>::setActualInstant(std::vector<int>* actualInstant)
285 Instant* instant=new Instant(actualInstant);
286 instantHandler->setActualInstant(instant);
290 * Set the increase Value for changing the instant
293 void InstantPlayer<S>::setIncreaseValue(int increase)
295 instantHandler->setIncreaseValue(increase);
298 * Set the decrease Value for changing the instant
301 void InstantPlayer<S>::setDecreaseValue(int decrease)
303 instantHandler->setDecreaseValue(decrease);
307 * Set the mode of a concept that's being handled
311 void InstantPlayer<S>::setModeOfConcept(std::string nameConcept,int mode)
313 instantHandler->setModeOfConcept(nameConcept,mode);
316 * Set actual time to the instant handler
320 void InstantPlayer<S>::setActualTime(double actualTime)
322 instantHandler->setActualTime(actualTime);
325 * set the modes of the concept that handled the time
326 * to the plus plus mode
330 void InstantPlayer<S>::setTimeConceptToMode(int mode)
332 std::string nameConcept;
333 getTimeConcept(nameConcept);
334 setModeOfConcept(nameConcept,mode);