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 for ( iter = logicColorPoints.begin(); i<=maxIndex && !addedPoint; iter++ )
119 int before = (*iter)->getRealX() ;
120 if(before>xRealValue && i==0)
123 logicColorPoints.insert( iter, newColorPoint );
125 lastAddedPoint = newColorPoint;
127 else if(before<xRealValue && i==maxIndex)
130 logicColorPoints.insert( iter+1, newColorPoint );
132 lastAddedPoint = newColorPoint;
138 int after = (*nextIter)->getRealX();
139 if( before < xRealValue && after> xRealValue)
141 logicColorPoints.insert( nextIter, newColorPoint );
143 lastAddedPoint = newColorPoint;
152 bool LogicalColorBar :: deleteColorPoint ( double valErase )
154 bool deletedPoint = false;
155 std::vector <pColorPoint*>::iterator pointIterator = logicColorPoints.begin();
156 for(int i=0; i<logicColorPoints.size() && !deletedPoint; i++)
158 pColorPoint aPoint =**pointIterator;
159 if(aPoint.getRealX() == valErase)
161 logicColorPoints.erase(pointIterator);
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 );
172 bool foundedStart = false;
173 bool foundedEnd = false;
175 /*for (int i=0; i<logicColorPoints.size()&&(!foundedStart || !foundedEnd);i++)
177 pColorPoint colorPoint = logicColorPoints[i];
178 double actualValue = colorPoint->getRealX();
181 if((startSearched <= actualValue) )
184 if((startSearched == actualValue) )
190 if((actualValue <= endSearched) )
193 if((endSearched == actualValue))
199 for (int i=0; i<logicColorPoints.size()&& !foundedEnd;i++)
201 pColorPoint * colorPoint = logicColorPoints[i];
202 double actualValue = colorPoint->getRealX();
205 if((startSearched <= actualValue) )
208 //if((startSearched == actualValue) )
214 if((actualValue <= endSearched) )
217 if((endSearched == actualValue))
223 if(actualValue>=startSearched && actualValue<=endSearched)
225 if(startSearched<endSearched)
226 theInputQueue.push_back(colorPoint);
231 pColorPoint * LogicalColorBar :: getLastAddedPoint()
233 return lastAddedPoint;
236 pColorPoint * LogicalColorBar :: getPointAtIndex(int anIndex)
238 if(anIndex>=0 && logicColorPoints.size()>anIndex)
239 return logicColorPoints[anIndex];
245 int LogicalColorBar :: getCount()
247 return logicColorPoints.size();
250 void LogicalColorBar :: getDataAt(int index, double &x,int &red,int &green,int &blue)
252 pColorPoint * colorPoint = logicColorPoints[index];
253 wxColour color = colorPoint->getColor();
256 green = color.Green();
257 x = colorPoint->getRealX();
260 void LogicalColorBar :: clearPoints()
262 logicColorPoints.clear();
265 double LogicalColorBar :: getMinAddedValue()
267 return logicColorPoints.front()->getRealX();
270 double LogicalColorBar :: getMaxAddedValue()
272 return logicColorPoints.back()->getRealX();
275 void LogicalColorBar :: changeColor(double pointValue, wxColour theNewColor)
277 bool changedCol = false;
278 for(int i=0; i<logicColorPoints.size() && !changedCol; i++)
280 pColorPoint * aPoint = logicColorPoints[i];
281 if(aPoint->getRealX() == pointValue)
283 aPoint->setColor( theNewColor );
289 bool LogicalColorBar :: setColorPoints (std::vector<pColorPoint *> pointsVector)
291 bool addedAll = true;
292 for(int i=0; i<pointsVector.size() && addedAll; i++)
294 pColorPoint * aPoint = pointsVector[i];
295 addedAll &= addColorPoint(aPoint->getRealX(), aPoint->getColor());
299 minValue = getMinAddedValue();
300 maxValue = getMaxAddedValue();
303 logicColorPoints.clear();