]> Creatis software - creaEnvironment.git/blob - lib/kernel_Environment/ConceptInstantHandler.cxx
*** empty log message ***
[creaEnvironment.git] / lib / kernel_Environment / ConceptInstantHandler.cxx
1                                                 
2
3 // SYSTEM INCLUDES
4 #include <iostream>
5 #include <string>
6 #include <vector>
7 #include <exception>
8 #include <stdio.h>
9 #include <time.h>
10
11 // PROJECT INCLUDES
12
13
14 // LOCAL INCLUDES
15 #include "ConceptInstantHandler.h"
16
17 // FORWARD REFERENCES
18
19                                                 
20
21                                                 
22                                                 //====== LIFECYCLE ========
23                                                 ConceptInstantHandler::ConceptInstantHandler(std::string name,int mode,int positionInReproduction)
24                                                         {
25                                                                         this->name=name;
26                                                                         this->mode=mode;
27                                                                         this->positionInReproduction=positionInReproduction;
28                                                                         this->increaseValue=1;
29                                                                         this->decreaseValue=1;
30                                                                         this->actualIndex=0;
31                                                                         this->scaleTime=0;
32                                                                         //timeReproduction=intervalTimer*maximumValue
33                                                                         this->timeReproduction=100;
34                                                                         this->actualTime=0;
35                                                                         this->initialTime=0;
36                                                         }
37                                                 ConceptInstantHandler::~ConceptInstantHandler()
38                                                         {
39                                                                 name.clear();
40                                                         }
41                                                 //====== OPERATIONS =======
42                                                 /*
43                                                 * change the actual index by increasing
44                                                 * the index until the maximum by the increaseValue
45                                                 */
46                                                 void ConceptInstantHandler::nextIndex()
47                                                         {
48                                                                 
49                                                                 //just plus plus
50                                                                 if(mode==PLUS_PLUS)
51                                                                                 actualIndex+=increaseValue;
52                                                                 //time scale
53                                                                 else
54                                                                         {
55                                                                                 time_t seconds=time(NULL);
56                                                                                 if(initialTime==0)                                                                      
57                                                                                         initialTime=seconds*1000;
58                                                                                 int time=seconds*1000;
59                                                                                 actualTime=time-initialTime;                    
60                                                                                 actualIndex=(int)actualTime*scaleTime;
61                                                                         }
62                                                                         
63
64                                                                 if(actualIndex>=maximumIndex)
65                                                                                 actualIndex=maximumIndex-1;
66         
67                                                                         
68                                                         }
69                                                 /*
70                                                 * change the actual index by decreasing
71                                                 * the index until zero  by the decreaseValue
72                                                 */
73                                                 void ConceptInstantHandler::previousIndex()
74                                                         {
75                                                                 //just plus plus
76                                                                 if(mode==PLUS_PLUS)
77                                                                         actualIndex-=decreaseValue;
78                                                                 
79                                                                 else
80                                                                         actualIndex=(int)actualTime*scaleTime;
81                                                                 
82                                                                 if(actualIndex<0)
83                                                                                 actualIndex=0;
84                                                                         
85                                                         }
86                                                 
87                                                 //====== INQUIRY =========
88                                                 /*
89                                                 *       @return name
90                                                 */
91                                                 std::string ConceptInstantHandler::getName()
92                                                         {
93                                                                 return this->name;
94                                                         }
95                                                 /*
96                                                 *       @return PositionInReproduction
97                                                 */
98                                                 int ConceptInstantHandler::getPosition()
99                                                         {
100                                                                 return this->positionInReproduction;
101                                                         }
102                                                 /*
103                                                 *       @return mode
104                                                 */
105                                                 int ConceptInstantHandler::getMode()
106                                                         {
107                                                                 return this->mode;
108                                                         }
109                                                 /*
110                                                 *       @return increaseValue
111                                                 */
112                                                 int ConceptInstantHandler::getIncreaseValue()
113                                                         {
114                                                                 return this->increaseValue;
115                                                         }
116                                                         
117                                                 /*
118                                                 *       @return decreaseValue
119                                                 */
120                                                 int ConceptInstantHandler::getDecreaseValue()
121                                                         {
122                                                                 return this->decreaseValue;
123                                                         }
124                                                 
125                                                 /*
126                                                 * @return indexInInstant
127                                                 */
128                                                 int ConceptInstantHandler::getIndexInInstant()
129                                                         {
130                                                                 return this->indexInInstant;
131                                                         }
132                                                 /*
133                                                 *       @return actualIndex
134                                                 */
135                                                 int ConceptInstantHandler::geActualIndex()
136                                                         {       
137                                                                 return actualIndex;
138                                                         }
139                                                 /*
140                                                 *       @return maximumIndex
141                                                 */
142                                                 
143                                                 int ConceptInstantHandler::getMaximumIndex()
144                                                         {
145                                                         return maximumIndex;
146                                                         }
147                                                 /*
148                                                 *       @return timeReproduction
149                                                 */
150                                                 double ConceptInstantHandler::getTimeReproduction()
151                                                         {
152                                                                 return timeReproduction;
153                                                         }
154                                                 /*
155                                                 *       @return scaleTime
156                                                 */
157                                                 double ConceptInstantHandler::getScale()
158                                                         {
159                                                                 return scaleTime;
160                                                         }
161                                                 /*
162                                                 * if the actual index is not the maximum index
163                                                 */
164                                                 bool ConceptInstantHandler::hasNextIndex()
165                                                         {
166                                                                 if(actualIndex<maximumIndex-1)
167                                                                          return true;
168                                                                 else return false;
169                                                         }
170                                                 /*
171                                                 * if the actual index is not zero
172                                                 */
173                                                 bool ConceptInstantHandler::hasPreviousIndex()
174                                                         {
175                                                                 if(actualIndex>0)
176                                                                          return true;
177                                                                 else return false;
178                                                         }
179                                                 /*
180                                                 * Get initial time
181                                                 */
182                                                 double ConceptInstantHandler::getInitialTime()
183                                                         {
184                                                                 return this->initialTime;
185                                                         }
186
187                                                 //====== ACCESS ==========
188                                                 /*
189                                                 *       Sets the name of the concept
190                                                 *       @param name, new name
191                                                 */
192                                                 void ConceptInstantHandler::setName(std::string name)
193                                                         {
194                                                                 this->name=name;
195                                                         }
196                                                 /*
197                                                 *       Sets the position of the concept
198                                                 *       @param position, position
199                                                 */
200                                                 void ConceptInstantHandler::setPosition(int position)
201                                                         {
202                                                                 this->positionInReproduction=position;
203                                                         }
204                                                 /*
205                                                 *       Sets the mode of the concept
206                                                 *       @param mode, new mode= REAL_TIME or
207                                                 *       PLUS_PLUS
208                                                 */
209                                                 void ConceptInstantHandler::setMode(int mode)
210                                                         {
211                                                                 if(this->mode==PLUS_PLUS)
212                                                                         {
213                                                                                 time_t seconds=time(NULL);
214                                                                                 int time=seconds*1000;  
215                                                                                 actualTime=actualIndex/scaleTime;
216                                                                                 initialTime=time-actualTime;
217                                                                         }
218                                                                 this->mode=mode;
219                                                         }
220                                                 /*
221                                                 *       Set Increase of the instant
222                                                 */
223                                                 void ConceptInstantHandler::setIncreaseValue(int increaseValue)
224                                                         {
225                                                                 this->increaseValue=increaseValue;
226                                                         }
227
228                                                 /*
229                                                 *       Set decrease of the instant
230                                                 */
231                                                 void ConceptInstantHandler::setDecreaseValue(int decreaseValue)
232                                                         {
233                                                                 this->decreaseValue=decreaseValue;
234                                                         }
235                                                 /*
236                                                 *  Sets  the index of the concept in the instant
237                                                 *  @param indexInInstant
238                                                 */
239                                                 void ConceptInstantHandler::setIndexInInstant(int indexInInstant)
240                                                         {
241                                                                 this->indexInInstant=indexInInstant;
242                                                         }
243                                                 /*
244                                                 *  Sets  sets the maximum value
245                                                 *  @param maximumIndex
246                                                 */
247                                                 void ConceptInstantHandler::setMaximumIndex(int maximumIndex)
248                                                         {
249                                                                 this->maximumIndex=maximumIndex;
250                                                                 scaleTime=(maximumIndex-1)/timeReproduction;
251                                                         }
252
253                                                 /*
254                                                 * set the actualIndex
255                                                 */
256                                                 void ConceptInstantHandler::setActualIndex(int index)
257                                                         {
258                                                                 if(index<=maximumIndex-1)
259                                                                         actualIndex=index;
260                                                                 //TODO else thow exception of out of bounds
261                                                         }
262                                                 /*
263                                                 * set the timeReproduction
264                                                 * @param timeReproduction
265                                                 */
266                                                 void ConceptInstantHandler::setTimeReproduction(double time)
267                                                         {
268                                                                 this->timeReproduction=(this->maximumIndex-1)*time;
269                                                                 scaleTime=(maximumIndex-1)/timeReproduction;
270                                                         }
271                                                 /*
272                                                 * set the scaleTime
273                                                 * @param scale
274                                                 */
275                                                 void ConceptInstantHandler::setScale(double scale)
276                                                         {
277                                                                 this->scaleTime=scale;
278                                                         }
279                                                 /*
280                                                 * set the actualTime
281                                                 * @param actualTime
282                                                 */
283                                                 void ConceptInstantHandler::setActualTime(double actualTime)
284                                                         {
285                                                                 this->actualTime=actualTime;
286                                                         }
287                                                 /*
288                                                 *       reset the initial time
289                                                 */
290                                                 void ConceptInstantHandler::resetInitialTime()
291                                                         {
292                                                                 this->initialTime=0;
293                                                         }
294                                                 /*
295                                                 * Sets the initial time
296                                                 */
297                                                 void ConceptInstantHandler::setInitialTime(double time)
298                                                         {
299                                                                 this->initialTime=time;
300                                                         }
301
302
303
304