1 // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/
19 #include "Plot2d_Curve.h"
25 Plot2d_Curve::Plot2d_Curve()
26 : myHorTitle( "" ), myVerTitle( "" ),
27 myHorUnits( "" ), myVerUnits( "" ),
28 myAutoAssign( true ), myColor( 0,0,0 ), myMarker( Circle ), myLine( Solid ), myLineWidth( 0 ),
29 myYAxis( QwtPlot::yLeft )
36 Plot2d_Curve::~Plot2d_Curve()
41 Copy constructor. Makes deep copy of data.
43 Plot2d_Curve::Plot2d_Curve( const Plot2d_Curve& curve )
45 myAutoAssign = curve.isAutoAssign();
46 myHorTitle = curve.getHorTitle();
47 myVerTitle = curve.getVerTitle();
48 myHorUnits = curve.getHorUnits();
49 myVerUnits = curve.getVerUnits();
50 myColor = curve.getColor();
51 myMarker = curve.getMarker();
52 myLine = curve.getLine();
53 myLineWidth = curve.getLineWidth();
54 myPoints = curve.getPointList();
58 operator=. Makes deep copy of data.
60 Plot2d_Curve& Plot2d_Curve::operator=( const Plot2d_Curve& curve )
62 myAutoAssign = curve.isAutoAssign();
63 myHorTitle = curve.getHorTitle();
64 myVerTitle = curve.getVerTitle();
65 myHorUnits = curve.getHorUnits();
66 myVerUnits = curve.getVerUnits();
67 myColor = curve.getColor();
68 myMarker = curve.getMarker();
69 myLine = curve.getLine();
70 myLineWidth = curve.getLineWidth();
71 myPoints = curve.getPointList();
76 \return title of table
78 QString Plot2d_Curve::getTableTitle() const
84 Sets curve's horizontal title
86 void Plot2d_Curve::setHorTitle( const QString& title )
92 Gets curve's horizontal title
94 QString Plot2d_Curve::getHorTitle() const
100 Sets curve's vertical title
102 void Plot2d_Curve::setVerTitle( const QString& title )
108 Gets curve's vertical title
110 QString Plot2d_Curve::getVerTitle() const
116 Sets curve's horizontal units
118 void Plot2d_Curve::setHorUnits( const QString& units )
124 Gets curve's horizontal units
126 QString Plot2d_Curve::getHorUnits() const
132 Sets curve's vertical units
134 void Plot2d_Curve::setVerUnits( const QString& units )
140 Gets curve's vertical units
142 QString Plot2d_Curve::getVerUnits() const
148 Adds one point for curve.
150 void Plot2d_Curve::addPoint(double theX, double theY)
155 myPoints.append(aPoint);
159 Insert one point for curve on some position.
161 void Plot2d_Curve::insertPoint(int thePos, double theX, double theY)
167 QValueList<Plot2d_Point>::iterator aIt;
169 for(aIt = myPoints.begin(); aIt != myPoints.end(); ++aIt) {
170 if (thePos == aCurrent) {
171 myPoints.insert(aIt, aPoint);
176 myPoints.append(aPoint);
180 Delete one point for curve on some position.
182 void Plot2d_Curve::deletePoint(int thePos)
184 QValueList<Plot2d_Point>::iterator aIt;
186 for(aIt = myPoints.begin(); aIt != myPoints.end(); ++aIt) {
187 if (thePos == aCurrent) {
188 myPoints.remove(aIt);
196 Remove all points for curve.
198 void Plot2d_Curve::clearAllPoints()
204 Gets curve's data : abscissas of points
206 pointList Plot2d_Curve::getPointList() const
214 void Plot2d_Curve::setData( const double* hData, const double* vData, long size )
217 for(long i = 0; i < size; i++) addPoint(hData[i], vData[i]);
221 Gets curve's data : abscissas of points
223 double* Plot2d_Curve::horData() const
225 int aNPoints = nbPoints();
226 double* aX = new double[aNPoints];
227 for (int i = 0; i < aNPoints; i++) {
228 aX[i] = myPoints[i].x;
234 Gets curve's data : ordinates of points
236 double* Plot2d_Curve::verData() const
238 int aNPoints = nbPoints();
239 double* aY = new double[aNPoints];
240 for (int i = 0; i < aNPoints; i++) {
241 aY[i] = myPoints[i].y;
247 Gets curve's data : number of points
249 int Plot2d_Curve::nbPoints() const
251 return myPoints.count();
255 Returns true if curve has no data
257 bool Plot2d_Curve::isEmpty() const
259 return myPoints.isEmpty();
263 Sets curve's AutoAssign flag - in this case attributes will be set automatically
265 void Plot2d_Curve::setAutoAssign( bool on )
271 Gets curve's AutoAssign flag state
273 bool Plot2d_Curve::isAutoAssign() const
279 Sets curve's color ( and resets AutoAssign flag )
281 void Plot2d_Curve::setColor( const QColor& color )
284 myAutoAssign = false;
290 QColor Plot2d_Curve::getColor() const
296 Sets curve's marker ( and resets AutoAssign flag )
298 void Plot2d_Curve::setMarker( MarkerType marker )
301 myAutoAssign = false;
307 Plot2d_Curve::MarkerType Plot2d_Curve::getMarker() const
313 Sets curve's line type and width ( and resets AutoAssign flag )
314 NOTE : A line width of 0 will produce a 1 pixel wide line using a fast algorithm for diagonals.
315 A line width of 1 will also produce a 1 pixel wide line, but uses a slower more accurate
316 algorithm for diagonals.
317 For horizontal and vertical lines a line width of 0 is the same as a line width of 1.
319 void Plot2d_Curve::setLine( LineType line, const int lineWidth )
322 myLineWidth = lineWidth;
323 if ( myLineWidth < 0 ) myLineWidth = 0;
324 myAutoAssign = false;
328 Gets curve's line type
330 Plot2d_Curve::LineType Plot2d_Curve::getLine() const
336 Gets curve's line width
338 int Plot2d_Curve::getLineWidth() const
346 void Plot2d_Curve::setYAxis(QwtPlot::Axis theYAxis)
348 if(theYAxis == QwtPlot::yLeft || theYAxis == QwtPlot::yRight)
355 QwtPlot::Axis Plot2d_Curve::getYAxis() const
361 Gets curve's minimal abscissa
363 double Plot2d_Curve::getMinX() const
365 QValueList<Plot2d_Point>::const_iterator aIt;
366 double aMinX = 1e150;
368 for(aIt = myPoints.begin(); aIt != myPoints.end(); ++aIt) {
369 if ( (*aIt).x < aMinX )
376 Gets curve's minimal ordinate
378 double Plot2d_Curve::getMinY() const
380 QValueList<Plot2d_Point>::const_iterator aIt;
381 double aMinY = 1e150;
383 for(aIt = myPoints.begin(); aIt != myPoints.end(); ++aIt) {
384 if ( (*aIt).y < aMinY )