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