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