1 // Copyright (C) 2007-2012 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_Object.cxx
23 // Author : Natalia ERMOLAEVA, Open CASCADE S.A.S. (natalia.donis@opencascade.com)
26 #include "Plot2d_Object.h"
29 #include <SUIT_Session.h>
30 #include <SUIT_ResourceMgr.h>
33 QColor Plot2d_Object::mySelectionColor;
34 QColor Plot2d_Object::myHighlightedLegendTextColor;
37 * Read colors from the resource manager.
39 void Plot2d_Object::initColors() {
40 SUIT_Session* session = SUIT_Session::session();
44 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
46 mySelectionColor = resMgr->colorValue( "Plot2d", "SelectionColor", QColor(80,80,80) );
47 myHighlightedLegendTextColor = resMgr->colorValue( "Plot2d", "SelectedLegendFontColor", QColor(255,255,255) );
54 Plot2d_Object::Plot2d_Object()
55 : myAutoAssign( true ),
56 myHorTitle( "" ), myVerTitle( "" ),
57 myHorUnits( "" ), myVerUnits( "" ),
59 myXAxis( QwtPlot::xBottom ),
60 myYAxis( QwtPlot::yLeft ),
69 Plot2d_Object::~Plot2d_Object()
74 Copy constructor. Makes deep copy of data.
76 Plot2d_Object::Plot2d_Object( const Plot2d_Object& object )
78 myAutoAssign = object.isAutoAssign();
79 myHorTitle = object.getHorTitle();
80 myVerTitle = object.getVerTitle();
81 myHorUnits = object.getHorUnits();
82 myVerUnits = object.getVerUnits();
83 myName = object.getName();
84 myXAxis = object.getXAxis();
85 myYAxis = object.getYAxis();
86 myPoints = object.getPointList();
87 myScale = object.getScale();
91 operator=. Makes deep copy of data.
93 Plot2d_Object& Plot2d_Object::operator=( const Plot2d_Object& object )
95 myAutoAssign = object.isAutoAssign();
96 myHorTitle = object.getHorTitle();
97 myVerTitle = object.getVerTitle();
98 myHorUnits = object.getHorUnits();
99 myVerUnits = object.getVerUnits();
100 myName = object.getName();
101 myXAxis = object.getXAxis();
102 myYAxis = object.getYAxis();
103 myPoints = object.getPointList();
104 myScale = object.getScale();
109 Auto fill parameters of object by plot view
111 void Plot2d_Object::autoFill( const QwtPlot* )
116 * Updates object fields
118 void Plot2d_Object::updatePlotItem( QwtPlotItem* theItem )
120 if ( !theItem || theItem->rtti() != rtti() )
123 if ( theItem->yAxis() != getYAxis() || theItem->xAxis() != getXAxis() ) {
124 theItem->setAxis( getXAxis(), getYAxis() );
126 QwtPlot* aPlot = theItem->plot();
129 theItem->attach( aPlot );
132 QString name = !getName().isEmpty() ? getName() : getVerTitle();
134 name = name + QString("( *%1 )").arg(myScale);
135 theItem->setTitle( name );
139 \return title of table
141 QString Plot2d_Object::getTableTitle() const
147 Sets object's horizontal title
149 void Plot2d_Object::setHorTitle( const QString& title )
155 Gets object's horizontal title
157 QString Plot2d_Object::getHorTitle() const
163 Sets object's vertical title
165 void Plot2d_Object::setVerTitle( const QString& title )
171 Gets object's vertical title
173 QString Plot2d_Object::getVerTitle() const
179 Sets object's horizontal units
181 void Plot2d_Object::setHorUnits( const QString& units )
187 Gets object's horizontal units
189 QString Plot2d_Object::getHorUnits() const
195 Sets object's vertical units
197 void Plot2d_Object::setVerUnits( const QString& units )
203 Gets object's vertical units
205 QString Plot2d_Object::getVerUnits() const
213 void Plot2d_Object::setName( const QString& theName )
220 QString Plot2d_Object::getName() const
226 Sets object's scale factor
228 void Plot2d_Object::setScale( double theScale )
233 Gets object's scale factor
235 double Plot2d_Object::getScale() const
241 Adds one point for object.
243 void Plot2d_Object::addPoint( double theX, double theY, const QString& theText )
245 addPoint( Plot2d_Point( theX, theY, theText ) );
249 Adds one point for object.
251 void Plot2d_Object::addPoint( const Plot2d_Point& thePoint )
253 myPoints.append( thePoint );
257 Insert one point for object on some position.
259 void Plot2d_Object::insertPoint( int thePos, double theX, double theY,
260 const QString& theText )
262 insertPoint( thePos, Plot2d_Point( theX, theY, theText ) );
266 Insert one point for object on some position.
268 void Plot2d_Object::insertPoint( int thePos, const Plot2d_Point& thePoint )
271 myPoints.append( thePoint );
273 myPoints.insert( thePos, thePoint );
277 Delete one point for object on some position.
279 void Plot2d_Object::deletePoint(int thePos)
281 if ( thePos >= 0 && thePos < myPoints.count() )
282 myPoints.removeAt( thePos );
286 Remove all points for object.
288 void Plot2d_Object::clearAllPoints()
294 Gets object's data : abscissas of points
296 pointList Plot2d_Object::getPointList() const
302 Gets points by index.
305 Plot2d_Point& Plot2d_Object::getPoint(int index) {
306 return myPoints[index];
310 Gets object's data : abscissas of points
312 void Plot2d_Object::setPointList( const pointList& points )
320 void Plot2d_Object::setData( const double* hData, const double* vData, long size, const QStringList& lst )
323 QStringList::const_iterator anIt = lst.begin(), aLast = lst.end();
324 for ( long i = 0; i < size; i++, anIt++ )
325 addPoint( hData[i], vData[i], anIt==aLast ? QString() : *anIt );
329 Gets object's data : abscissas of points
331 double* Plot2d_Object::horData() const
333 int aNPoints = nbPoints();
334 double* aX = new double[aNPoints];
335 for (int i = 0; i < aNPoints; i++) {
336 aX[i] = myPoints[i].x;
342 Gets object's data : ordinates of points
344 double* Plot2d_Object::verData() const
346 int aNPoints = nbPoints();
347 double* aY = new double[aNPoints];
348 for (int i = 0; i < aNPoints; i++) {
349 aY[i] = myScale * myPoints[i].y;
357 long Plot2d_Object::getData( double** theX, double** theY ) const
359 int aNPoints = nbPoints();
360 *theX = new double[aNPoints];
361 *theY = new double[aNPoints];
362 for (int i = 0; i < aNPoints; i++) {
363 (*theX)[i] = myPoints[i].x;
364 (*theY)[i] = myScale * myPoints[i].y;
370 Changes text assigned to point of object
371 \param ind -- index of point
372 \param txt -- new text
374 void Plot2d_Object::setText( const int ind, const QString& txt )
376 if ( ind >= 0 && ind < myPoints.count() )
377 myPoints[ind].text = txt;
381 \return text assigned to point
382 \param ind -- index of point
384 QString Plot2d_Object::text( const int ind ) const
386 return ( ind >= 0 && ind < myPoints.count() ) ? myPoints[ind].text : QString();
390 Gets object's data : number of points
392 int Plot2d_Object::nbPoints() const
394 return myPoints.count();
398 Returns true if object has no data
400 bool Plot2d_Object::isEmpty() const
402 return myPoints.isEmpty();
406 Sets object's AutoAssign flag - in this case attributes will be set automatically
408 void Plot2d_Object::setAutoAssign( bool on )
414 Gets object's AutoAssign flag state
416 bool Plot2d_Object::isAutoAssign() const
424 void Plot2d_Object::setXAxis(QwtPlot::Axis theXAxis)
426 if (theXAxis == QwtPlot::xBottom || theXAxis == QwtPlot::xTop)
433 QwtPlot::Axis Plot2d_Object::getXAxis() const
441 void Plot2d_Object::setYAxis(QwtPlot::Axis theYAxis)
443 if (theYAxis == QwtPlot::yLeft || theYAxis == QwtPlot::yRight)
450 QwtPlot::Axis Plot2d_Object::getYAxis() const
456 Gets object's minimal abscissa
458 double Plot2d_Object::getMinX() const
460 double aMinX = 1e150;
461 pointList::const_iterator aIt;
462 for (aIt = myPoints.begin(); aIt != myPoints.end(); ++aIt)
463 aMinX = qMin( aMinX, (*aIt).x );
468 Gets object's maximal abscissa
470 double Plot2d_Object::getMaxX() const
472 double aMaxX = -1e150;
473 pointList::const_iterator aIt;
474 for (aIt = myPoints.begin(); aIt != myPoints.end(); ++aIt)
475 aMaxX = qMax( aMaxX, (*aIt).x );
480 Gets object's minimal ordinate
482 double Plot2d_Object::getMinY() const
484 double aMinY = 1e150;
485 pointList::const_iterator aIt;
486 for (aIt = myPoints.begin(); aIt != myPoints.end(); ++aIt)
487 aMinY = qMin( aMinY, myScale * (*aIt).y );
492 Gets object's maximal ordinate
494 double Plot2d_Object::getMaxY() const
496 double aMaxY = -1e150;
497 pointList::const_iterator aIt;
498 for (aIt = myPoints.begin(); aIt != myPoints.end(); ++aIt)
499 aMaxY = qMax( aMaxY, myScale * (*aIt).y );
504 Sets object's selected property
506 void Plot2d_Object::setSelected(const bool on) {
511 Gets object's selected property
513 bool Plot2d_Object::isSelected() const {
518 * Sets selection color of the object.
520 void Plot2d_Object::setSelectionColor(const QColor& c) {
521 mySelectionColor = c;
525 * Return selection color of the object.
527 QColor Plot2d_Object::selectionColor() {
528 return mySelectionColor;
532 * Sets font color of the selected legend item.
534 void Plot2d_Object::setHighlightedLegendTextColor(const QColor& c) {
535 myHighlightedLegendTextColor = c;
539 * Sets font color of the selected legend item.
541 QColor Plot2d_Object::highlightedLegendTextColor() {
542 return myHighlightedLegendTextColor;