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();
75 QString Plot2d_Curve::getTableTitle() const
81 Sets curve's horizontal title
83 void Plot2d_Curve::setHorTitle( const QString& title )
89 Gets curve's horizontal title
91 QString Plot2d_Curve::getHorTitle() const
97 Sets curve's vertical title
99 void Plot2d_Curve::setVerTitle( const QString& title )
105 Gets curve's vertical title
107 QString Plot2d_Curve::getVerTitle() const
113 Sets curve's horizontal units
115 void Plot2d_Curve::setHorUnits( const QString& units )
121 Gets curve's horizontal units
123 QString Plot2d_Curve::getHorUnits() const
129 Sets curve's vertical units
131 void Plot2d_Curve::setVerUnits( const QString& units )
137 Gets curve's vertical units
139 QString Plot2d_Curve::getVerUnits() const
145 Adds one point for curve.
147 void Plot2d_Curve::addPoint(double theX, double theY)
152 myPoints.append(aPoint);
156 Insert one point for curve on some position.
158 void Plot2d_Curve::insertPoint(int thePos, double theX, double theY)
164 QValueList<Plot2d_Point>::iterator aIt;
166 for(aIt = myPoints.begin(); aIt != myPoints.end(); ++aIt) {
167 if (thePos == aCurrent) {
168 myPoints.insert(aIt, aPoint);
173 myPoints.append(aPoint);
177 Delete one point for curve on some position.
179 void Plot2d_Curve::deletePoint(int thePos)
181 QValueList<Plot2d_Point>::iterator aIt;
183 for(aIt = myPoints.begin(); aIt != myPoints.end(); ++aIt) {
184 if (thePos == aCurrent) {
185 myPoints.remove(aIt);
193 Remove all points for curve.
195 void Plot2d_Curve::clearAllPoints()
201 Gets curve's data : abscissas of points
203 pointList Plot2d_Curve::getPointList() const
211 void Plot2d_Curve::setData( const double* hData, const double* vData, long size )
214 for(long i = 0; i < size; i++) addPoint(hData[i], vData[i]);
218 Gets curve's data : abscissas of points
220 double* Plot2d_Curve::horData() const
222 int aNPoints = nbPoints();
223 double* aX = new double[aNPoints];
224 for (int i = 0; i < aNPoints; i++) {
225 aX[i] = myPoints[i].x;
231 Gets curve's data : ordinates of points
233 double* Plot2d_Curve::verData() const
235 int aNPoints = nbPoints();
236 double* aY = new double[aNPoints];
237 for (int i = 0; i < aNPoints; i++) {
238 aY[i] = myPoints[i].y;
244 Gets curve's data : number of points
246 int Plot2d_Curve::nbPoints() const
248 return myPoints.count();
252 Returns true if curve has no data
254 bool Plot2d_Curve::isEmpty() const
256 return myPoints.isEmpty();
260 Sets curve's AutoAssign flag - in this case attributes will be set automatically
262 void Plot2d_Curve::setAutoAssign( bool on )
268 Gets curve's AutoAssign flag state
270 bool Plot2d_Curve::isAutoAssign() const
276 Sets curve's color ( and resets AutoAssign flag )
278 void Plot2d_Curve::setColor( const QColor& color )
281 myAutoAssign = false;
287 QColor Plot2d_Curve::getColor() const
293 Sets curve's marker ( and resets AutoAssign flag )
295 void Plot2d_Curve::setMarker( MarkerType marker )
298 myAutoAssign = false;
304 Plot2d_Curve::MarkerType Plot2d_Curve::getMarker() const
310 Sets curve's line type and width ( and resets AutoAssign flag )
311 NOTE : A line width of 0 will produce a 1 pixel wide line using a fast algorithm for diagonals.
312 A line width of 1 will also produce a 1 pixel wide line, but uses a slower more accurate
313 algorithm for diagonals.
314 For horizontal and vertical lines a line width of 0 is the same as a line width of 1.
316 void Plot2d_Curve::setLine( LineType line, const int lineWidth )
319 myLineWidth = lineWidth;
320 if ( myLineWidth < 0 ) myLineWidth = 0;
321 myAutoAssign = false;
325 Gets curve's line type
327 Plot2d_Curve::LineType Plot2d_Curve::getLine() const
333 Gets curve's line width
335 int Plot2d_Curve::getLineWidth() const
343 void Plot2d_Curve::setYAxis(QwtPlot::Axis theYAxis)
345 if(theYAxis == QwtPlot::yLeft || theYAxis == QwtPlot::yRight)
352 QwtPlot::Axis Plot2d_Curve::getYAxis() const
358 Gets curve's minimal abscissa
360 double Plot2d_Curve::getMinX() const
362 QValueList<Plot2d_Point>::const_iterator aIt;
363 double aMinX = 1e150;
365 for(aIt = myPoints.begin(); aIt != myPoints.end(); ++aIt) {
366 if ( (*aIt).x < aMinX )
373 Gets curve's minimal ordinate
375 double Plot2d_Curve::getMinY() const
377 QValueList<Plot2d_Point>::const_iterator aIt;
378 double aMinY = 1e150;
380 for(aIt = myPoints.begin(); aIt != myPoints.end(); ++aIt) {
381 if ( (*aIt).y < aMinY )