1 //------------------------------------------------------------------------------------------------------------
2 // Class definition include
3 //------------------------------------------------------------------------------------------------------------
4 #include "LogicalColorBar.h"
7 //------------------------------------------------------------------------------------------------------------
8 // Class implementation
9 //------------------------------------------------------------------------------------------------------------
10 /** file LogicalColorBar.cxx */
13 //------------------------------------------------------------------------------------------------------------
14 // Constructors & Destructors
15 //------------------------------------------------------------------------------------------------------------
17 LogicalColorBar :: LogicalColorBar ()
21 bar_orientation = true;
24 LogicalColorBar :: ~ LogicalColorBar ()
26 //logicColorPoints.clear();
29 //------------------------------------------------------------------------------------------------------------
30 // Methods Implementation
31 //------------------------------------------------------------------------------------------------------------
36 // Gets the first point
38 pColorPoint * LogicalColorBar :: getFirstPoint()
40 return logicColorPoints.front();
45 // Gets the last point
47 pColorPoint * LogicalColorBar :: getLastPoint()
49 return logicColorPoints.back();
53 double LogicalColorBar :: getMinValue()
59 void LogicalColorBar :: setMinValue(double valueMin)
65 double LogicalColorBar :: getMaxValue()
71 void LogicalColorBar :: setMaxValue(double valueMax)
77 bool LogicalColorBar :: getOrientation()
79 return bar_orientation;
82 void LogicalColorBar :: setOrientation(bool orientation)
84 bar_orientation = orientation;
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.
95 bool LogicalColorBar :: addColorPoint (double xRealValue, wxColour theColour )
97 bool addedPoint = false;
99 if(xRealValue>=minValue && xRealValue<=maxValue)
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
108 std::vector <pColorPoint*>::iterator iter;
109 std::vector <pColorPoint*>::iterator nextIter;
110 pColorPoint * newColorPoint = new pColorPoint ( xRealValue, theColour, false );
111 if(logicColorPoints.empty())
113 logicColorPoints.push_back(newColorPoint);
116 iter = logicColorPoints.begin();
117 for (i=0; i<=maxIndex && !addedPoint; i++)
120 int before = (*iter)->getRealX() ;
121 if(before>xRealValue && i==0)
124 logicColorPoints.insert( iter, newColorPoint );
126 lastAddedPoint = newColorPoint;
128 else if(before<xRealValue && i==maxIndex)
131 logicColorPoints.push_back(newColorPoint );
133 lastAddedPoint = newColorPoint;
139 int after = (*nextIter)->getRealX();
140 if( before < xRealValue && after> xRealValue)
142 logicColorPoints.insert( nextIter, newColorPoint );
144 lastAddedPoint = newColorPoint;
147 //std::cout<<"JCPaddColorPoint iterator "<<*iter<<std::endl;
156 bool LogicalColorBar :: deleteColorPoint ( double valErase )
158 bool deletedPoint = false;
159 std::vector <pColorPoint*>::iterator pointIterator = logicColorPoints.begin();
160 for(int i=0; i<logicColorPoints.size() && !deletedPoint; i++)
162 pColorPoint aPoint =**pointIterator;
163 if(aPoint.getRealX() == valErase)
165 logicColorPoints.erase(pointIterator);
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 );
176 bool foundedStart = false;
177 bool foundedEnd = false;
179 /*for (int i=0; i<logicColorPoints.size()&&(!foundedStart || !foundedEnd);i++)
181 pColorPoint colorPoint = logicColorPoints[i];
182 double actualValue = colorPoint->getRealX();
185 if((startSearched <= actualValue) )
188 if((startSearched == actualValue) )
194 if((actualValue <= endSearched) )
197 if((endSearched == actualValue))
203 for (int i=0; i<logicColorPoints.size()&& !foundedEnd;i++)
205 pColorPoint * colorPoint = logicColorPoints[i];
206 double actualValue = colorPoint->getRealX();
209 if((startSearched <= actualValue) )
212 //if((startSearched == actualValue) )
218 if((actualValue <= endSearched) )
221 if((endSearched == actualValue))
227 if(actualValue>=startSearched && actualValue<=endSearched)
229 if(startSearched<endSearched)
230 theInputQueue.push_back(colorPoint);
235 pColorPoint * LogicalColorBar :: getLastAddedPoint()
237 return lastAddedPoint;
240 pColorPoint * LogicalColorBar :: getPointAtIndex(int anIndex)
242 if(anIndex>=0 && logicColorPoints.size()>anIndex)
243 return logicColorPoints[anIndex];
249 int LogicalColorBar :: getCount()
251 return logicColorPoints.size();
254 void LogicalColorBar :: getDataAt(int index, double &x,int &red,int &green,int &blue)
256 pColorPoint * colorPoint = logicColorPoints[index];
257 wxColour color = colorPoint->getColor();
260 green = color.Green();
261 x = colorPoint->getRealX();
264 void LogicalColorBar :: clearPoints()
266 logicColorPoints.clear();
269 double LogicalColorBar :: getMinAddedValue()
271 return logicColorPoints.front()->getRealX();
274 double LogicalColorBar :: getMaxAddedValue()
276 return logicColorPoints.back()->getRealX();
279 void LogicalColorBar :: changeColor(double pointValue, wxColour theNewColor)
281 bool changedCol = false;
282 for(int i=0; i<logicColorPoints.size() && !changedCol; i++)
284 pColorPoint * aPoint = logicColorPoints[i];
285 if(aPoint->getRealX() == pointValue)
287 aPoint->setColor( theNewColor );
293 bool LogicalColorBar :: setColorPoints (std::vector<pColorPoint *> pointsVector)
295 bool addedAll = true;
296 for(int i=0; i<pointsVector.size() && addedAll; i++)
298 pColorPoint * aPoint = pointsVector[i];
299 addedAll &= addColorPoint(aPoint->getRealX(), aPoint->getColor());
303 minValue = getMinAddedValue();
304 maxValue = getMaxAddedValue();
307 logicColorPoints.clear();