]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/LogicalColorBar.cxx
feaf8f776dda817359931a00d4aa963b474f13af
[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; // JPRx
102                         //pColorPoint * colorPoint, nextColorPoint;
103                         int maxIndex= logicColorPoints.size()-1;
104                         // int nextIndex = 0; // JPRx
105                         //int nextX = 0; // JPRx
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                         }else{                          
116                                 iter = logicColorPoints.begin();
117                                 for (i=0; i<=maxIndex && !addedPoint; i++)
118                                 {
119                                         nextIter = iter;
120                                         int before = (*iter)->getRealX() ;
121                                         if(before>xRealValue && i==0)
122                                         {
123                                                 //Is the first point
124                                                 logicColorPoints.insert( iter, newColorPoint );
125                                                 addedPoint =true;
126                                                 lastAddedPoint = newColorPoint;
127                                         }
128                                         else if(before<xRealValue && i==maxIndex)
129                                         {
130                                                 //Is the last point 
131                                                 logicColorPoints.push_back(newColorPoint );     
132                                                 addedPoint =true;
133                                                 lastAddedPoint = newColorPoint;
134                                         }
135                                         else if(i<maxIndex)
136                                         {
137                                                 //
138                                                 nextIter++;                     
139                                                 int after = (*nextIter)->getRealX();                            
140                                                 if( before < xRealValue && after> xRealValue)
141                                                 {
142                                                         logicColorPoints.insert( nextIter, newColorPoint );     
143                                                         addedPoint =true;
144                                                         lastAddedPoint = newColorPoint;
145                                                 }
146                                         }               
147                                         //std::cout<<"JCPaddColorPoint iterator "<<*iter<<std::endl;
148                                         if(!addedPoint)
149                                                 ++iter;
150                                 }               
151                         }                       
152                 }
153                 return addedPoint;              
154         }
155
156         bool LogicalColorBar :: deleteColorPoint ( double  valErase )
157         {
158                 bool deletedPoint = false;              
159                 std::vector <pColorPoint*>::iterator pointIterator = logicColorPoints.begin();
160                 for(int i=0; i<logicColorPoints.size() && !deletedPoint; i++)
161                 {
162                         pColorPoint  aPoint =**pointIterator;
163                         if(aPoint.getRealX() == valErase)
164                         {
165                                 logicColorPoints.erase(pointIterator);
166                                 deletedPoint = true;
167                         }                       
168                         pointIterator++;
169                 }
170                 return deletedPoint;
171         }
172         
173         void LogicalColorBar :: getPointersToRangeLimits( std::deque<pColorPoint *> &theInputQueue, int &startIndex, int &endIndex, int startSearched, int endSearched )
174         //void LogicalColorBar :: getListIndexRangeLimits( std::vector<pColorPoint *> &theVector, bool &startFOUND, bool &endFOUND, int startSearched, int endSearched );
175         {
176                 bool foundedStart = false;
177                 bool foundedEnd = false;
178                 
179                 /*for (int i=0; i<logicColorPoints.size()&&(!foundedStart || !foundedEnd);i++)
180                 {
181                         pColorPoint colorPoint = logicColorPoints[i];
182                         double actualValue = colorPoint->getRealX();
183                         if(!foundedStart)
184                         {
185                                 if((startSearched <= actualValue) )
186                                 {
187                                         startIndex = i;
188                                         if((startSearched == actualValue) )
189                                                 foundedStart = true;
190                                 }                                       
191                         }
192                         if(!foundedEnd)
193                         {
194                                 if((actualValue <= endSearched) )
195                                 {
196                                         endIndex = i;
197                                         if((endSearched == actualValue))
198                                                 foundedEnd = true;
199                                 }                       
200                         }                                               
201                 }               */
202
203                 for (int i=0; i<logicColorPoints.size()&& !foundedEnd;i++)
204                 {
205                         pColorPoint * colorPoint = logicColorPoints[i];
206                         double actualValue = colorPoint->getRealX();
207                         if(!foundedStart)
208                         {
209                                 if((startSearched <= actualValue) )
210                                 {
211                                         startIndex = i;
212                                         //if((startSearched == actualValue) )                                   
213                                         foundedStart = true;                                                                                    
214                                 }                                       
215                         }
216                         if(!foundedEnd)
217                         {
218                                 if((actualValue <= endSearched) )
219                                 {
220                                         endIndex = i;
221                                         if((endSearched == actualValue))
222                                         {
223                                                 foundedEnd = true;                                              
224                                         }
225                                 }                       
226                         }                                               
227                         if(actualValue>=startSearched && actualValue<=endSearched)
228                         {
229                                 if(startSearched<endSearched)
230                                         theInputQueue.push_back(colorPoint);
231                         }
232                 }                       
233         }
234
235         pColorPoint * LogicalColorBar :: getLastAddedPoint()
236         {
237                 return lastAddedPoint;
238         }
239
240         pColorPoint * LogicalColorBar :: getPointAtIndex(int anIndex)
241         {
242                 if(anIndex>=0 && logicColorPoints.size()>anIndex)
243                         return logicColorPoints[anIndex];
244                 else
245                         return NULL;
246         }
247
248         
249         int LogicalColorBar :: getCount()
250         {
251                 return logicColorPoints.size();
252         }
253
254         void LogicalColorBar :: getDataAt(int index, double &x,int &red,int &green,int &blue)
255         {
256                 pColorPoint * colorPoint = logicColorPoints[index];             
257                 wxColour color = colorPoint->getColor();
258                 red = color.Red();
259                 blue = color.Blue();
260                 green = color.Green();
261                 x = colorPoint->getRealX();
262         }
263
264         void LogicalColorBar :: clearPoints()
265         {       
266                 logicColorPoints.clear();
267         }
268
269         double LogicalColorBar :: getMinAddedValue()
270         {
271                 return logicColorPoints.front()->getRealX();            
272         }
273
274         double LogicalColorBar :: getMaxAddedValue()
275         {
276                 return logicColorPoints.back()->getRealX();
277         }
278
279         void LogicalColorBar :: changeColor(double pointValue, wxColour theNewColor)
280         {
281                 bool changedCol = false;
282                 for(int i=0; i<logicColorPoints.size() && !changedCol; i++)
283                 {
284                         pColorPoint * aPoint = logicColorPoints[i];
285                         if(aPoint->getRealX() == pointValue)
286                         {
287                                 aPoint->setColor( theNewColor );
288                                 changedCol = true;
289                         }                       
290                 }
291         }
292
293         bool LogicalColorBar :: setColorPoints (std::vector<pColorPoint *> pointsVector)
294         {
295                 bool addedAll = true;
296                 for(int i=0; i<pointsVector.size() && addedAll; i++)
297                 {
298                         pColorPoint * aPoint  = pointsVector[i];
299                         addedAll &= addColorPoint(aPoint->getRealX(), aPoint->getColor());
300                 }
301                 if(addedAll)
302                 {
303                         minValue = getMinAddedValue();
304                         maxValue = getMaxAddedValue();
305                 }
306                 else
307                         logicColorPoints.clear();
308
309                 return addedAll;
310         }
311    
312