]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/LogicalColorBar.cxx
creaMaracasVisu Library
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / pPlotter / LogicalColorBar.cxx
1 //------------------------------------------------------------------------------------------------------------
2 // Class definition include
3 //------------------------------------------------------------------------------------------------------------
4 #include "LogicalColorBar.h"
5
6
7 //------------------------------------------------------------------------------------------------------------
8 // Class implementation
9 //------------------------------------------------------------------------------------------------------------
10 /** file LogicalColorBar.cxx */
11
12
13 //------------------------------------------------------------------------------------------------------------
14 // Constructors & Destructors
15 //------------------------------------------------------------------------------------------------------------
16
17         LogicalColorBar :: LogicalColorBar () 
18         {
19                 minValue = 0;
20                 maxValue = 0;
21                 bar_orientation = true;
22         }
23
24         LogicalColorBar :: ~ LogicalColorBar () 
25         {
26                 //logicColorPoints.clear();
27         }
28
29 //------------------------------------------------------------------------------------------------------------
30 // Methods Implementation 
31 //------------------------------------------------------------------------------------------------------------
32
33
34
35 //
36         // Gets the first point
37         //
38         pColorPoint * LogicalColorBar :: getFirstPoint()
39         {
40                 return logicColorPoints.front();
41         }
42
43
44         //
45         // Gets the last point
46         //
47         pColorPoint * LogicalColorBar :: getLastPoint()
48         {
49                 return logicColorPoints.back();
50         }
51
52
53         double LogicalColorBar :: getMinValue()
54         {
55                 return minValue;
56         }
57
58
59         void  LogicalColorBar :: setMinValue(double valueMin)
60         {
61                 minValue = valueMin;
62         }
63
64
65         double LogicalColorBar :: getMaxValue()
66         {
67                 return maxValue;
68         }
69
70
71         void LogicalColorBar :: setMaxValue(double valueMax)
72         {
73                 maxValue = valueMax;
74         }
75
76
77         bool LogicalColorBar :: getOrientation()
78         {
79                 return bar_orientation;
80         }
81
82         void LogicalColorBar :: setOrientation(bool orientation)
83         {
84                 bar_orientation = orientation;
85         }
86
87         //
88         // Adds a color degrade point to the color bar.
89         // param xRealValue The real xValue of the point
90         // param theColour The assigned color for the point
91         // param temporalStart Indicates if the inserted point is the temporal startShowing point
92         // param temporalEnd Indicates if the inserted point is the temporal startShowing point
93         // return Returns true if the point was succesfully inserted.
94         ////
95         bool LogicalColorBar :: addColorPoint (double xRealValue, wxColour theColour )
96         {
97                 bool addedPoint = false;
98                 
99                 if(xRealValue>=minValue && xRealValue<=maxValue)
100                 {
101                         bool ifContinue = true;
102                         //pColorPoint * colorPoint, nextColorPoint;
103                         int maxIndex= logicColorPoints.size()-1;
104                         int nextIndex = 0;
105                         int nextX = 0;
106                         int i = 0;
107                                         
108                         std::vector <pColorPoint*>::iterator iter;
109                         std::vector <pColorPoint*>::iterator nextIter;
110                         pColorPoint * newColorPoint = new pColorPoint ( xRealValue, theColour, false );
111                         if(logicColorPoints.empty())
112                         {
113                                 logicColorPoints.push_back(newColorPoint);
114                                 addedPoint = true;
115                         }
116                         for ( iter = logicColorPoints.begin(); i<=maxIndex && !addedPoint; iter++ )
117                         {
118                                 nextIter = iter;
119                                 int before = (*iter)->getRealX() ;
120                                 if(before>xRealValue && i==0)
121                                 {
122                                         //Is the first point
123                                         logicColorPoints.insert( iter, newColorPoint );
124                                         addedPoint =true;
125                                         lastAddedPoint = newColorPoint;
126                                 }
127                                 else if(before<xRealValue && i==maxIndex)
128                                 {
129                                         //Is the last point 
130                                         logicColorPoints.insert( iter+1, newColorPoint );       
131                                         addedPoint =true;
132                                         lastAddedPoint = newColorPoint;
133                                 }
134                                 else if(i<maxIndex)
135                                 {
136                                         //
137                                         nextIter++;                     
138                                         int after = (*nextIter)->getRealX();                            
139                                         if( before < xRealValue && after> xRealValue)
140                                         {
141                                                 logicColorPoints.insert( nextIter, newColorPoint );     
142                                                 addedPoint =true;
143                                                 lastAddedPoint = newColorPoint;
144                                         }
145                                 }                               
146                                 i++;
147                         }               
148                 }
149                 return addedPoint;              
150         }
151
152         bool LogicalColorBar :: deleteColorPoint ( double  valErase )
153         {
154                 bool deletedPoint = false;              
155                 std::vector <pColorPoint*>::iterator pointIterator = logicColorPoints.begin();
156                 for(int i=0; i<logicColorPoints.size() && !deletedPoint; i++)
157                 {
158                         pColorPoint  aPoint =**pointIterator;
159                         if(aPoint.getRealX() == valErase)
160                         {
161                                 logicColorPoints.erase(pointIterator);
162                                 deletedPoint = true;
163                         }                       
164                         pointIterator++;
165                 }
166                 return deletedPoint;
167         }
168         
169         void LogicalColorBar :: getPointersToRangeLimits( std::deque<pColorPoint *> &theInputQueue, int &startIndex, int &endIndex, int startSearched, int endSearched )
170         //void LogicalColorBar :: getListIndexRangeLimits( std::vector<pColorPoint *> &theVector, bool &startFOUND, bool &endFOUND, int startSearched, int endSearched );
171         {
172                 bool foundedStart = false;
173                 bool foundedEnd = false;
174                 
175                 /*for (int i=0; i<logicColorPoints.size()&&(!foundedStart || !foundedEnd);i++)
176                 {
177                         pColorPoint colorPoint = logicColorPoints[i];
178                         double actualValue = colorPoint->getRealX();
179                         if(!foundedStart)
180                         {
181                                 if((startSearched <= actualValue) )
182                                 {
183                                         startIndex = i;
184                                         if((startSearched == actualValue) )
185                                                 foundedStart = true;
186                                 }                                       
187                         }
188                         if(!foundedEnd)
189                         {
190                                 if((actualValue <= endSearched) )
191                                 {
192                                         endIndex = i;
193                                         if((endSearched == actualValue))
194                                                 foundedEnd = true;
195                                 }                       
196                         }                                               
197                 }               */
198
199                 for (int i=0; i<logicColorPoints.size()&& !foundedEnd;i++)
200                 {
201                         pColorPoint * colorPoint = logicColorPoints[i];
202                         double actualValue = colorPoint->getRealX();
203                         if(!foundedStart)
204                         {
205                                 if((startSearched <= actualValue) )
206                                 {
207                                         startIndex = i;
208                                         //if((startSearched == actualValue) )                                   
209                                         foundedStart = true;                                                                                    
210                                 }                                       
211                         }
212                         if(!foundedEnd)
213                         {
214                                 if((actualValue <= endSearched) )
215                                 {
216                                         endIndex = i;
217                                         if((endSearched == actualValue))
218                                         {
219                                                 foundedEnd = true;                                              
220                                         }
221                                 }                       
222                         }                                               
223                         if(actualValue>=startSearched && actualValue<=endSearched)
224                         {
225                                 if(startSearched<endSearched)
226                                         theInputQueue.push_back(colorPoint);
227                         }
228                 }                       
229         }
230
231         pColorPoint * LogicalColorBar :: getLastAddedPoint()
232         {
233                 return lastAddedPoint;
234         }
235
236         pColorPoint * LogicalColorBar :: getPointAtIndex(int anIndex)
237         {
238                 if(anIndex>=0 && logicColorPoints.size()>anIndex)
239                         return logicColorPoints[anIndex];
240                 else
241                         return NULL;
242         }
243
244         
245         int LogicalColorBar :: getCount()
246         {
247                 return logicColorPoints.size();
248         }
249
250         void LogicalColorBar :: getDataAt(int index, double &x,int &red,int &green,int &blue)
251         {
252                 pColorPoint * colorPoint = logicColorPoints[index];             
253                 wxColour color = colorPoint->getColor();
254                 red = color.Red();
255                 blue = color.Blue();
256                 green = color.Green();
257                 x = colorPoint->getRealX();
258         }
259
260         void LogicalColorBar :: clearPoints()
261         {       
262                 logicColorPoints.clear();
263         }
264
265         double LogicalColorBar :: getMinAddedValue()
266         {
267                 return logicColorPoints.front()->getRealX();            
268         }
269
270         double LogicalColorBar :: getMaxAddedValue()
271         {
272                 return logicColorPoints.back()->getRealX();
273         }
274
275         void LogicalColorBar :: changeColor(double pointValue, wxColour theNewColor)
276         {
277                 bool changedCol = false;
278                 for(int i=0; i<logicColorPoints.size() && !changedCol; i++)
279                 {
280                         pColorPoint * aPoint = logicColorPoints[i];
281                         if(aPoint->getRealX() == pointValue)
282                         {
283                                 aPoint->setColor( theNewColor );
284                                 changedCol = true;
285                         }                       
286                 }
287         }
288
289         bool LogicalColorBar :: setColorPoints (std::vector<pColorPoint *> pointsVector)
290         {
291                 bool addedAll = true;
292                 for(int i=0; i<pointsVector.size() && addedAll; i++)
293                 {
294                         pColorPoint * aPoint  = pointsVector[i];
295                         addedAll &= addColorPoint(aPoint->getRealX(), aPoint->getColor());
296                 }
297                 if(addedAll)
298                 {
299                         minValue = getMinAddedValue();
300                         maxValue = getMaxAddedValue();
301                 }
302                 else
303                         logicColorPoints.clear();
304
305                 return addedAll;
306         }
307    
308