1 // Copyright (C) 2007-2016 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, or (at your option) any later version.
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_Object.cxx
23 // Author : Natalia ERMOLAEVA, Open CASCADE S.A.S. (natalia.donis@opencascade.com)
26 #include "Plot2d_Object.h"
29 QColor Plot2d_Object::mySelectionColor;
30 QColor Plot2d_Object::myHighlightedLegendTextColor;
36 Plot2d_Object::Plot2d_Object()
37 : myAutoAssign( true ),
38 myHorTitle( "" ), myVerTitle( "" ),
39 myHorUnits( "" ), myVerUnits( "" ),
41 myXAxis( QwtPlot::xBottom ),
42 myYAxis( QwtPlot::yLeft ),
51 Plot2d_Object::~Plot2d_Object()
56 Copy constructor. Makes deep copy of data.
58 Plot2d_Object::Plot2d_Object( const Plot2d_Object& object )
60 myAutoAssign = object.isAutoAssign();
61 myHorTitle = object.getHorTitle();
62 myVerTitle = object.getVerTitle();
63 myHorUnits = object.getHorUnits();
64 myVerUnits = object.getVerUnits();
65 myName = object.getName();
66 myXAxis = object.getXAxis();
67 myYAxis = object.getYAxis();
68 myPoints = object.getPointList();
69 myScale = object.getScale();
73 operator=. Makes deep copy of data.
75 Plot2d_Object& Plot2d_Object::operator=( const Plot2d_Object& object )
77 myAutoAssign = object.isAutoAssign();
78 myHorTitle = object.getHorTitle();
79 myVerTitle = object.getVerTitle();
80 myHorUnits = object.getHorUnits();
81 myVerUnits = object.getVerUnits();
82 myName = object.getName();
83 myXAxis = object.getXAxis();
84 myYAxis = object.getYAxis();
85 myPoints = object.getPointList();
86 myScale = object.getScale();
91 Auto fill parameters of object by plot view
93 void Plot2d_Object::autoFill( const QwtPlot* )
98 * Updates object fields
100 void Plot2d_Object::updatePlotItem( QwtPlotItem* theItem )
102 if ( !theItem || theItem->rtti() != rtti() )
105 if ( theItem->yAxis() != getYAxis() || theItem->xAxis() != getXAxis() ) {
106 theItem->setAxes( getXAxis(), getYAxis() );
108 QwtPlot* aPlot = theItem->plot();
111 theItem->attach( aPlot );
114 QString name = !getName().isEmpty() ? getName() : getVerTitle();
116 name = name + QString("( *%1 )").arg(myScale);
117 theItem->setTitle( name );
121 \return title of table
123 QString Plot2d_Object::getTableTitle() const
129 Sets object's horizontal title
131 void Plot2d_Object::setHorTitle( const QString& title )
137 Gets object's horizontal title
139 QString Plot2d_Object::getHorTitle() const
145 Sets object's vertical title
147 void Plot2d_Object::setVerTitle( const QString& title )
153 Gets object's vertical title
155 QString Plot2d_Object::getVerTitle() const
161 Sets object's horizontal units
163 void Plot2d_Object::setHorUnits( const QString& units )
169 Gets object's horizontal units
171 QString Plot2d_Object::getHorUnits() const
177 Sets object's vertical units
179 void Plot2d_Object::setVerUnits( const QString& units )
185 Gets object's vertical units
187 QString Plot2d_Object::getVerUnits() const
195 void Plot2d_Object::setName( const QString& theName )
202 QString Plot2d_Object::getName() const
208 Sets object's scale factor
210 void Plot2d_Object::setScale( double theScale )
215 Gets object's scale factor
217 double Plot2d_Object::getScale() const
223 Adds one point for object.
225 void Plot2d_Object::addPoint( double theX, double theY, const QString& theText )
227 addPoint( Plot2d_Point( theX, theY, theText ) );
231 Adds one point for object.
233 void Plot2d_Object::addPoint( const Plot2d_Point& thePoint )
235 myPoints.append( thePoint );
239 Insert one point for object on some position.
241 void Plot2d_Object::insertPoint( int thePos, double theX, double theY,
242 const QString& theText )
244 insertPoint( thePos, Plot2d_Point( theX, theY, theText ) );
248 Insert one point for object on some position.
250 void Plot2d_Object::insertPoint( int thePos, const Plot2d_Point& thePoint )
253 myPoints.append( thePoint );
255 myPoints.insert( thePos, thePoint );
259 Delete one point for object on some position.
261 void Plot2d_Object::deletePoint(int thePos)
263 if ( thePos >= 0 && thePos < myPoints.count() )
264 myPoints.removeAt( thePos );
268 Remove all points for object.
270 void Plot2d_Object::clearAllPoints()
276 Gets object's data : abscissas of points
278 pointList Plot2d_Object::getPointList() const
284 Gets points by index.
287 Plot2d_Point& Plot2d_Object::getPoint(int index) {
288 return myPoints[index];
292 Gets object's data : abscissas of points
294 void Plot2d_Object::setPointList( const pointList& points )
302 void Plot2d_Object::setData( const double* hData, const double* vData, long size, const QStringList& lst )
305 QStringList::const_iterator anIt = lst.begin(), aLast = lst.end();
306 for ( long i = 0; i < size; i++, anIt++ )
307 addPoint( hData[i], vData[i], anIt==aLast ? QString() : *anIt );
311 Gets object's data : abscissas of points
313 double* Plot2d_Object::horData() const
315 int aNPoints = nbPoints();
316 double* aX = new double[aNPoints];
317 for (int i = 0; i < aNPoints; i++) {
318 aX[i] = myPoints[i].x;
324 Gets object's data : ordinates of points
326 double* Plot2d_Object::verData() const
328 int aNPoints = nbPoints();
329 double* aY = new double[aNPoints];
330 for (int i = 0; i < aNPoints; i++) {
331 aY[i] = myScale * myPoints[i].y;
339 long Plot2d_Object::getData( double** theX, double** theY ) const
341 int aNPoints = nbPoints();
342 *theX = new double[aNPoints];
343 *theY = new double[aNPoints];
344 for (int i = 0; i < aNPoints; i++) {
345 (*theX)[i] = myPoints[i].x;
346 (*theY)[i] = myScale * myPoints[i].y;
352 Changes text assigned to point of object
353 \param ind -- index of point
354 \param txt -- new text
356 void Plot2d_Object::setText( const int ind, const QString& txt )
358 if ( ind >= 0 && ind < myPoints.count() )
359 myPoints[ind].text = txt;
363 \return text assigned to point
364 \param ind -- index of point
366 QString Plot2d_Object::text( const int ind ) const
368 return ( ind >= 0 && ind < myPoints.count() ) ? myPoints[ind].text : QString();
372 Gets object's data : number of points
374 int Plot2d_Object::nbPoints() const
376 return myPoints.count();
380 Returns true if object has no data
382 bool Plot2d_Object::isEmpty() const
384 return myPoints.isEmpty();
388 Sets object's AutoAssign flag - in this case attributes will be set automatically
390 void Plot2d_Object::setAutoAssign( bool on )
396 Gets object's AutoAssign flag state
398 bool Plot2d_Object::isAutoAssign() const
406 void Plot2d_Object::setXAxis(QwtPlot::Axis theXAxis)
408 if (theXAxis == QwtPlot::xBottom || theXAxis == QwtPlot::xTop)
415 QwtPlot::Axis Plot2d_Object::getXAxis() const
423 void Plot2d_Object::setYAxis(QwtPlot::Axis theYAxis)
425 if (theYAxis == QwtPlot::yLeft || theYAxis == QwtPlot::yRight)
432 QwtPlot::Axis Plot2d_Object::getYAxis() const
438 Gets object's minimal abscissa
440 double Plot2d_Object::getMinX() const
442 double aMinX = 1e150;
443 pointList::const_iterator aIt;
444 for (aIt = myPoints.begin(); aIt != myPoints.end(); ++aIt)
445 aMinX = qMin( aMinX, (*aIt).x );
450 Gets object's maximal abscissa
452 double Plot2d_Object::getMaxX() const
454 double aMaxX = -1e150;
455 pointList::const_iterator aIt;
456 for (aIt = myPoints.begin(); aIt != myPoints.end(); ++aIt)
457 aMaxX = qMax( aMaxX, (*aIt).x );
462 Gets object's minimal ordinate
464 double Plot2d_Object::getMinY() const
466 double aMinY = 1e150;
467 pointList::const_iterator aIt;
468 for (aIt = myPoints.begin(); aIt != myPoints.end(); ++aIt)
469 aMinY = qMin( aMinY, myScale * (*aIt).y );
474 Gets object's maximal ordinate
476 double Plot2d_Object::getMaxY() const
478 double aMaxY = -1e150;
479 pointList::const_iterator aIt;
480 for (aIt = myPoints.begin(); aIt != myPoints.end(); ++aIt)
481 aMaxY = qMax( aMaxY, myScale * (*aIt).y );
486 Sets object's selected property
488 void Plot2d_Object::setSelected(const bool on) {
493 Gets object's selected property
495 bool Plot2d_Object::isSelected() const {
500 * Sets selection color of the object.
502 void Plot2d_Object::setSelectionColor(const QColor& c) {
503 mySelectionColor = c;
507 * Return selection color of the object.
509 QColor Plot2d_Object::selectionColor() {
510 return mySelectionColor;
514 * Sets font color of the selected legend item.
516 void Plot2d_Object::setHighlightedLegendTextColor(const QColor& c) {
517 myHighlightedLegendTextColor = c;
521 * Sets font color of the selected legend item.
523 QColor Plot2d_Object::highlightedLegendTextColor() {
524 return myHighlightedLegendTextColor;