1 // Copyright (C) 2007-2014 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 #include <SUIT_Session.h>
30 #include <SUIT_ResourceMgr.h>
34 QColor Plot2d_Object::mySelectionColor;
35 QColor Plot2d_Object::myHighlightedLegendTextColor;
38 * Read colors from the resource manager.
40 void Plot2d_Object::initColors() {
42 SUIT_Session* session = SUIT_Session::session();
46 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
48 mySelectionColor = resMgr->colorValue( "Plot2d", "SelectionColor", QColor(80,80,80) );
49 myHighlightedLegendTextColor = resMgr->colorValue( "Plot2d", "SelectedLegendFontColor", QColor(255,255,255) );
52 mySelectionColor = QColor(80,80,80);
53 myHighlightedLegendTextColor = QColor(255,255,255);
60 Plot2d_Object::Plot2d_Object()
61 : myAutoAssign( true ),
62 myHorTitle( "" ), myVerTitle( "" ),
63 myHorUnits( "" ), myVerUnits( "" ),
65 myXAxis( QwtPlot::xBottom ),
66 myYAxis( QwtPlot::yLeft ),
75 Plot2d_Object::~Plot2d_Object()
80 Copy constructor. Makes deep copy of data.
82 Plot2d_Object::Plot2d_Object( const Plot2d_Object& object )
84 myAutoAssign = object.isAutoAssign();
85 myHorTitle = object.getHorTitle();
86 myVerTitle = object.getVerTitle();
87 myHorUnits = object.getHorUnits();
88 myVerUnits = object.getVerUnits();
89 myName = object.getName();
90 myXAxis = object.getXAxis();
91 myYAxis = object.getYAxis();
92 myPoints = object.getPointList();
93 myScale = object.getScale();
97 operator=. Makes deep copy of data.
99 Plot2d_Object& Plot2d_Object::operator=( const Plot2d_Object& object )
101 myAutoAssign = object.isAutoAssign();
102 myHorTitle = object.getHorTitle();
103 myVerTitle = object.getVerTitle();
104 myHorUnits = object.getHorUnits();
105 myVerUnits = object.getVerUnits();
106 myName = object.getName();
107 myXAxis = object.getXAxis();
108 myYAxis = object.getYAxis();
109 myPoints = object.getPointList();
110 myScale = object.getScale();
115 Auto fill parameters of object by plot view
117 void Plot2d_Object::autoFill( const QwtPlot* )
122 * Updates object fields
124 void Plot2d_Object::updatePlotItem( QwtPlotItem* theItem )
126 if ( !theItem || theItem->rtti() != rtti() )
129 if ( theItem->yAxis() != getYAxis() || theItem->xAxis() != getXAxis() ) {
130 theItem->setAxis( getXAxis(), getYAxis() );
132 QwtPlot* aPlot = theItem->plot();
135 theItem->attach( aPlot );
138 QString name = !getName().isEmpty() ? getName() : getVerTitle();
140 name = name + QString("( *%1 )").arg(myScale);
141 theItem->setTitle( name );
145 \return title of table
147 QString Plot2d_Object::getTableTitle() const
153 Sets object's horizontal title
155 void Plot2d_Object::setHorTitle( const QString& title )
161 Gets object's horizontal title
163 QString Plot2d_Object::getHorTitle() const
169 Sets object's vertical title
171 void Plot2d_Object::setVerTitle( const QString& title )
177 Gets object's vertical title
179 QString Plot2d_Object::getVerTitle() const
185 Sets object's horizontal units
187 void Plot2d_Object::setHorUnits( const QString& units )
193 Gets object's horizontal units
195 QString Plot2d_Object::getHorUnits() const
201 Sets object's vertical units
203 void Plot2d_Object::setVerUnits( const QString& units )
209 Gets object's vertical units
211 QString Plot2d_Object::getVerUnits() const
219 void Plot2d_Object::setName( const QString& theName )
226 QString Plot2d_Object::getName() const
232 Sets object's scale factor
234 void Plot2d_Object::setScale( double theScale )
239 Gets object's scale factor
241 double Plot2d_Object::getScale() const
247 Adds one point for object.
249 void Plot2d_Object::addPoint( double theX, double theY, const QString& theText )
251 addPoint( Plot2d_Point( theX, theY, theText ) );
255 Adds one point for object.
257 void Plot2d_Object::addPoint( const Plot2d_Point& thePoint )
259 myPoints.append( thePoint );
263 Insert one point for object on some position.
265 void Plot2d_Object::insertPoint( int thePos, double theX, double theY,
266 const QString& theText )
268 insertPoint( thePos, Plot2d_Point( theX, theY, theText ) );
272 Insert one point for object on some position.
274 void Plot2d_Object::insertPoint( int thePos, const Plot2d_Point& thePoint )
277 myPoints.append( thePoint );
279 myPoints.insert( thePos, thePoint );
283 Delete one point for object on some position.
285 void Plot2d_Object::deletePoint(int thePos)
287 if ( thePos >= 0 && thePos < myPoints.count() )
288 myPoints.removeAt( thePos );
292 Remove all points for object.
294 void Plot2d_Object::clearAllPoints()
300 Gets object's data : abscissas of points
302 pointList Plot2d_Object::getPointList() const
308 Gets points by index.
311 Plot2d_Point& Plot2d_Object::getPoint(int index) {
312 return myPoints[index];
316 Gets object's data : abscissas of points
318 void Plot2d_Object::setPointList( const pointList& points )
326 void Plot2d_Object::setData( const double* hData, const double* vData, long size, const QStringList& lst )
329 QStringList::const_iterator anIt = lst.begin(), aLast = lst.end();
330 for ( long i = 0; i < size; i++, anIt++ )
331 addPoint( hData[i], vData[i], anIt==aLast ? QString() : *anIt );
335 Gets object's data : abscissas of points
337 double* Plot2d_Object::horData() const
339 int aNPoints = nbPoints();
340 double* aX = new double[aNPoints];
341 for (int i = 0; i < aNPoints; i++) {
342 aX[i] = myPoints[i].x;
348 Gets object's data : ordinates of points
350 double* Plot2d_Object::verData() const
352 int aNPoints = nbPoints();
353 double* aY = new double[aNPoints];
354 for (int i = 0; i < aNPoints; i++) {
355 aY[i] = myScale * myPoints[i].y;
363 long Plot2d_Object::getData( double** theX, double** theY ) const
365 int aNPoints = nbPoints();
366 *theX = new double[aNPoints];
367 *theY = new double[aNPoints];
368 for (int i = 0; i < aNPoints; i++) {
369 (*theX)[i] = myPoints[i].x;
370 (*theY)[i] = myScale * myPoints[i].y;
376 Changes text assigned to point of object
377 \param ind -- index of point
378 \param txt -- new text
380 void Plot2d_Object::setText( const int ind, const QString& txt )
382 if ( ind >= 0 && ind < myPoints.count() )
383 myPoints[ind].text = txt;
387 \return text assigned to point
388 \param ind -- index of point
390 QString Plot2d_Object::text( const int ind ) const
392 return ( ind >= 0 && ind < myPoints.count() ) ? myPoints[ind].text : QString();
396 Gets object's data : number of points
398 int Plot2d_Object::nbPoints() const
400 return myPoints.count();
404 Returns true if object has no data
406 bool Plot2d_Object::isEmpty() const
408 return myPoints.isEmpty();
412 Sets object's AutoAssign flag - in this case attributes will be set automatically
414 void Plot2d_Object::setAutoAssign( bool on )
420 Gets object's AutoAssign flag state
422 bool Plot2d_Object::isAutoAssign() const
430 void Plot2d_Object::setXAxis(QwtPlot::Axis theXAxis)
432 if (theXAxis == QwtPlot::xBottom || theXAxis == QwtPlot::xTop)
439 QwtPlot::Axis Plot2d_Object::getXAxis() const
447 void Plot2d_Object::setYAxis(QwtPlot::Axis theYAxis)
449 if (theYAxis == QwtPlot::yLeft || theYAxis == QwtPlot::yRight)
456 QwtPlot::Axis Plot2d_Object::getYAxis() const
462 Gets object's minimal abscissa
464 double Plot2d_Object::getMinX() const
466 double aMinX = 1e150;
467 pointList::const_iterator aIt;
468 for (aIt = myPoints.begin(); aIt != myPoints.end(); ++aIt)
469 aMinX = qMin( aMinX, (*aIt).x );
474 Gets object's maximal abscissa
476 double Plot2d_Object::getMaxX() const
478 double aMaxX = -1e150;
479 pointList::const_iterator aIt;
480 for (aIt = myPoints.begin(); aIt != myPoints.end(); ++aIt)
481 aMaxX = qMax( aMaxX, (*aIt).x );
486 Gets object's minimal ordinate
488 double Plot2d_Object::getMinY() const
490 double aMinY = 1e150;
491 pointList::const_iterator aIt;
492 for (aIt = myPoints.begin(); aIt != myPoints.end(); ++aIt)
493 aMinY = qMin( aMinY, myScale * (*aIt).y );
498 Gets object's maximal ordinate
500 double Plot2d_Object::getMaxY() const
502 double aMaxY = -1e150;
503 pointList::const_iterator aIt;
504 for (aIt = myPoints.begin(); aIt != myPoints.end(); ++aIt)
505 aMaxY = qMax( aMaxY, myScale * (*aIt).y );
510 Sets object's selected property
512 void Plot2d_Object::setSelected(const bool on) {
517 Gets object's selected property
519 bool Plot2d_Object::isSelected() const {
524 * Sets selection color of the object.
526 void Plot2d_Object::setSelectionColor(const QColor& c) {
527 mySelectionColor = c;
531 * Return selection color of the object.
533 QColor Plot2d_Object::selectionColor() {
534 return mySelectionColor;
538 * Sets font color of the selected legend item.
540 void Plot2d_Object::setHighlightedLegendTextColor(const QColor& c) {
541 myHighlightedLegendTextColor = c;
545 * Sets font color of the selected legend item.
547 QColor Plot2d_Object::highlightedLegendTextColor() {
548 return myHighlightedLegendTextColor;