1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : Plot2d_Curve.cxx
23 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
25 #include "Plot2d_Curve.h"
31 Plot2d_Curve::Plot2d_Curve()
32 : myHorTitle( "" ), myVerTitle( "" ),
33 myHorUnits( "" ), myVerUnits( "" ),
36 myMarker( Plot2d::Circle ),
37 myLine( Plot2d::Solid ),
39 myYAxis( QwtPlot::yLeft )
46 Plot2d_Curve::~Plot2d_Curve()
51 Copy constructor. Makes deep copy of data.
53 Plot2d_Curve::Plot2d_Curve( const Plot2d_Curve& curve )
55 myAutoAssign = curve.isAutoAssign();
56 myHorTitle = curve.getHorTitle();
57 myVerTitle = curve.getVerTitle();
58 myHorUnits = curve.getHorUnits();
59 myVerUnits = curve.getVerUnits();
60 myColor = curve.getColor();
61 myMarker = curve.getMarker();
62 myLine = curve.getLine();
63 myLineWidth = curve.getLineWidth();
64 myPoints = curve.getPointList();
68 operator=. Makes deep copy of data.
70 Plot2d_Curve& Plot2d_Curve::operator=( const Plot2d_Curve& curve )
72 myAutoAssign = curve.isAutoAssign();
73 myHorTitle = curve.getHorTitle();
74 myVerTitle = curve.getVerTitle();
75 myHorUnits = curve.getHorUnits();
76 myVerUnits = curve.getVerUnits();
77 myColor = curve.getColor();
78 myMarker = curve.getMarker();
79 myLine = curve.getLine();
80 myLineWidth = curve.getLineWidth();
81 myPoints = curve.getPointList();
86 \return title of table
88 QString Plot2d_Curve::getTableTitle() const
94 Sets curve's horizontal title
96 void Plot2d_Curve::setHorTitle( const QString& title )
102 Gets curve's horizontal title
104 QString Plot2d_Curve::getHorTitle() const
110 Sets curve's vertical title
112 void Plot2d_Curve::setVerTitle( const QString& title )
118 Gets curve's vertical title
120 QString Plot2d_Curve::getVerTitle() const
126 Sets curve's horizontal units
128 void Plot2d_Curve::setHorUnits( const QString& units )
134 Gets curve's horizontal units
136 QString Plot2d_Curve::getHorUnits() const
142 Sets curve's vertical units
144 void Plot2d_Curve::setVerUnits( const QString& units )
150 Gets curve's vertical units
152 QString Plot2d_Curve::getVerUnits() const
158 Adds one point for curve.
160 void Plot2d_Curve::addPoint(double theX, double theY, const QString& txt )
166 myPoints.append(aPoint);
170 Insert one point for curve on some position.
172 void Plot2d_Curve::insertPoint(int thePos, double theX, double theY, const QString& txt)
179 pointList::iterator aIt;
181 for(aIt = myPoints.begin(); aIt != myPoints.end(); ++aIt) {
182 if (thePos == aCurrent) {
183 myPoints.insert(aIt, aPoint);
188 myPoints.append(aPoint);
192 Delete one point for curve on some position.
194 void Plot2d_Curve::deletePoint(int thePos)
196 if ( thePos >= 0 && thePos < myPoints.count() )
197 myPoints.removeAt( thePos );
201 Remove all points for curve.
203 void Plot2d_Curve::clearAllPoints()
209 Gets curve's data : abscissas of points
211 pointList Plot2d_Curve::getPointList() const
219 void Plot2d_Curve::setData( const double* hData, const double* vData, long size, const QStringList& lst )
222 QStringList::const_iterator anIt = lst.begin(), aLast = lst.end();
223 for( long i = 0; i < size; i++, anIt++ )
224 addPoint( hData[i], vData[i], anIt==aLast ? QString() : *anIt );
228 Gets curve's data : abscissas of points
230 double* Plot2d_Curve::horData() const
232 int aNPoints = nbPoints();
233 double* aX = new double[aNPoints];
234 for (int i = 0; i < aNPoints; i++) {
235 aX[i] = myPoints[i].x;
241 Gets curve's data : ordinates of points
243 double* Plot2d_Curve::verData() const
245 int aNPoints = nbPoints();
246 double* aY = new double[aNPoints];
247 for (int i = 0; i < aNPoints; i++) {
248 aY[i] = myPoints[i].y;
254 Gets curve's data : number of points
256 int Plot2d_Curve::nbPoints() const
258 return myPoints.count();
262 Returns true if curve has no data
264 bool Plot2d_Curve::isEmpty() const
266 return myPoints.isEmpty();
270 Sets curve's AutoAssign flag - in this case attributes will be set automatically
272 void Plot2d_Curve::setAutoAssign( bool on )
278 Gets curve's AutoAssign flag state
280 bool Plot2d_Curve::isAutoAssign() const
286 Sets curve's color ( and resets AutoAssign flag )
288 void Plot2d_Curve::setColor( const QColor& color )
291 myAutoAssign = false;
297 QColor Plot2d_Curve::getColor() const
303 Sets curve's marker ( and resets AutoAssign flag )
305 void Plot2d_Curve::setMarker( Plot2d::MarkerType marker )
308 myAutoAssign = false;
314 Plot2d::MarkerType Plot2d_Curve::getMarker() const
320 Sets curve's line type and width ( and resets AutoAssign flag )
321 NOTE : A line width of 0 will produce a 1 pixel wide line using a fast algorithm for diagonals.
322 A line width of 1 will also produce a 1 pixel wide line, but uses a slower more accurate
323 algorithm for diagonals.
324 For horizontal and vertical lines a line width of 0 is the same as a line width of 1.
326 void Plot2d_Curve::setLine( Plot2d::LineType line, const int lineWidth )
329 myLineWidth = lineWidth;
330 if ( myLineWidth < 0 ) myLineWidth = 0;
331 myAutoAssign = false;
335 Gets curve's line type
337 Plot2d::LineType Plot2d_Curve::getLine() const
343 Gets curve's line width
345 int Plot2d_Curve::getLineWidth() const
353 void Plot2d_Curve::setYAxis(QwtPlot::Axis theYAxis)
355 if(theYAxis == QwtPlot::yLeft || theYAxis == QwtPlot::yRight)
362 QwtPlot::Axis Plot2d_Curve::getYAxis() const
368 Gets curve's minimal abscissa
370 double Plot2d_Curve::getMinX() const
372 pointList::const_iterator aIt;
373 double aMinX = 1e150;
375 for(aIt = myPoints.begin(); aIt != myPoints.end(); ++aIt) {
376 if ( (*aIt).x < aMinX )
383 Gets curve's minimal ordinate
385 double Plot2d_Curve::getMinY() const
387 pointList::const_iterator aIt;
388 double aMinY = 1e150;
390 for(aIt = myPoints.begin(); aIt != myPoints.end(); ++aIt) {
391 if ( (*aIt).y < aMinY )
398 Changes text assigned to point of curve
399 \param ind -- index of point
400 \param txt -- new text
402 void Plot2d_Curve::setText( const int ind, const QString& txt )
404 if( ind<0 || ind>=myPoints.count() )
407 myPoints[ind].text = txt;
411 \return text assigned to point
412 \param ind -- index of point
414 QString Plot2d_Curve::text( const int ind ) const
416 if( ind<0 || ind>=myPoints.count() )
419 return myPoints[ind].text;