Back to index

salome-gui  6.5.0
Plot2d_Object.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 //  File   : Plot2d_Object.cxx
00023 //  Author : Natalia ERMOLAEVA, Open CASCADE S.A.S. (natalia.donis@opencascade.com)
00024 //
00025 
00026 #include "Plot2d_Object.h"
00027 
00028 
00029 #include <SUIT_Session.h>
00030 #include <SUIT_ResourceMgr.h>
00031 
00032 // Static members
00033 QColor Plot2d_Object::mySelectionColor;
00034 QColor Plot2d_Object::myHighlightedLegendTextColor;
00035 
00036 /*
00037  * Read colors from the resource manager.
00038 */
00039 void Plot2d_Object::initColors() {
00040   SUIT_Session* session = SUIT_Session::session();
00041   if(!session)
00042     return;
00043 
00044   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
00045   if(resMgr) {
00046     mySelectionColor = resMgr->colorValue( "Plot2d", "SelectionColor", QColor(80,80,80) );
00047     myHighlightedLegendTextColor = resMgr->colorValue( "Plot2d", "SelectedLegendFontColor", QColor(255,255,255) );
00048   }
00049 }
00050 
00054 Plot2d_Object::Plot2d_Object()
00055 : myAutoAssign( true ),
00056   myHorTitle( "" ), myVerTitle( "" ),
00057   myHorUnits( "" ), myVerUnits( "" ),
00058   myName( "" ),
00059   myXAxis( QwtPlot::xBottom ),
00060   myYAxis( QwtPlot::yLeft ),
00061   myIsSelected(false),
00062   myScale ( 1.0 )
00063 {
00064 }
00065 
00069 Plot2d_Object::~Plot2d_Object()
00070 {
00071 }
00072 
00076 Plot2d_Object::Plot2d_Object( const Plot2d_Object& object )
00077 {
00078   myAutoAssign = object.isAutoAssign();
00079   myHorTitle   = object.getHorTitle();
00080   myVerTitle   = object.getVerTitle();
00081   myHorUnits   = object.getHorUnits();
00082   myVerUnits   = object.getVerUnits();
00083   myName       = object.getName();
00084   myXAxis      = object.getXAxis();
00085   myYAxis      = object.getYAxis();
00086   myPoints     = object.getPointList();
00087   myScale      = object.getScale();
00088 }
00089 
00093 Plot2d_Object& Plot2d_Object::operator=( const Plot2d_Object& object )
00094 {
00095   myAutoAssign = object.isAutoAssign();
00096   myHorTitle   = object.getHorTitle();
00097   myVerTitle   = object.getVerTitle();
00098   myHorUnits   = object.getHorUnits();
00099   myVerUnits   = object.getVerUnits();
00100   myName       = object.getName();
00101   myXAxis      = object.getXAxis();
00102   myYAxis      = object.getYAxis();
00103   myPoints     = object.getPointList();
00104   myScale      = object.getScale();
00105   return *this;
00106 }
00107 
00111 void Plot2d_Object::autoFill( const QwtPlot* )
00112 {
00113 }
00114 
00118 void Plot2d_Object::updatePlotItem( QwtPlotItem* theItem )
00119 {
00120   if ( !theItem || theItem->rtti() != rtti() )
00121     return;
00122 
00123   if ( theItem->yAxis() != getYAxis() || theItem->xAxis() != getXAxis() ) {
00124     theItem->setAxis( getXAxis(), getYAxis() );
00125 
00126     QwtPlot* aPlot = theItem->plot();
00127     if ( aPlot ) {
00128       theItem->detach();
00129       theItem->attach( aPlot );
00130     }
00131   }
00132   QString name = !getName().isEmpty() ? getName() : getVerTitle();
00133   if( myScale != 1.0 )
00134       name = name + QString("( *%1 )").arg(myScale);
00135   theItem->setTitle( name );
00136 }
00137 
00141 QString Plot2d_Object::getTableTitle() const
00142 {
00143   return QString();
00144 }
00145 
00149 void Plot2d_Object::setHorTitle( const QString& title )
00150 {
00151   myHorTitle = title;
00152 }
00153 
00157 QString Plot2d_Object::getHorTitle() const
00158 {
00159   return myHorTitle;
00160 }
00161 
00165 void Plot2d_Object::setVerTitle( const QString& title )
00166 {
00167   myVerTitle = title;
00168 }
00169 
00173 QString Plot2d_Object::getVerTitle() const
00174 {
00175   return myVerTitle;
00176 }
00177 
00181 void Plot2d_Object::setHorUnits( const QString& units )
00182 {
00183   myHorUnits = units;
00184 }
00185 
00189 QString Plot2d_Object::getHorUnits() const
00190 {
00191   return myHorUnits;
00192 }
00193 
00197 void Plot2d_Object::setVerUnits( const QString& units )
00198 {
00199   myVerUnits = units;
00200 }
00201 
00205 QString Plot2d_Object::getVerUnits() const
00206 {
00207   return myVerUnits;
00208 }
00209 
00213 void Plot2d_Object::setName( const QString& theName )
00214 {
00215   myName = theName;
00216 }
00220 QString Plot2d_Object::getName() const
00221 {
00222   return myName;
00223 }
00224 
00228 void Plot2d_Object::setScale( double theScale )
00229 {
00230   myScale = theScale;
00231 }
00235 double Plot2d_Object::getScale() const
00236 {
00237   return myScale;
00238 }
00239 
00243 void Plot2d_Object::addPoint( double theX, double theY, const QString& theText )
00244 {
00245   addPoint( Plot2d_Point( theX, theY, theText ) );
00246 }
00247 
00251 void Plot2d_Object::addPoint( const Plot2d_Point& thePoint )
00252 {
00253   myPoints.append( thePoint );
00254 }
00255 
00259 void Plot2d_Object::insertPoint( int thePos, double theX, double theY,
00260                              const QString& theText )
00261 {
00262   insertPoint( thePos, Plot2d_Point( theX, theY, theText ) );
00263 }
00264 
00268 void Plot2d_Object::insertPoint( int thePos, const Plot2d_Point& thePoint )
00269 {
00270   if ( thePos < 0 )
00271     myPoints.append( thePoint );
00272   else
00273     myPoints.insert( thePos, thePoint );
00274 }
00275 
00279 void Plot2d_Object::deletePoint(int thePos)
00280 {
00281   if ( thePos >= 0 && thePos < myPoints.count() )
00282     myPoints.removeAt( thePos );
00283 }
00284 
00288 void Plot2d_Object::clearAllPoints()
00289 {
00290   myPoints.clear();
00291 }
00292 
00296 pointList Plot2d_Object::getPointList() const
00297 {
00298   return myPoints;
00299 }
00300 
00305 Plot2d_Point& Plot2d_Object::getPoint(int index) {
00306        return myPoints[index];
00307 }
00308 
00312 void Plot2d_Object::setPointList( const pointList& points )
00313 {
00314   myPoints = points;
00315 }
00316 
00320 void Plot2d_Object::setData( const double* hData, const double* vData, long size, const QStringList& lst )
00321 {
00322   clearAllPoints();
00323   QStringList::const_iterator anIt = lst.begin(), aLast = lst.end(); 
00324   for ( long i = 0; i < size; i++, anIt++ )
00325     addPoint( hData[i], vData[i], anIt==aLast ? QString() : *anIt );
00326 }
00327 
00331 double* Plot2d_Object::horData() const
00332 {
00333   int aNPoints = nbPoints();
00334   double* aX = new double[aNPoints];
00335   for (int i = 0; i < aNPoints; i++) {
00336     aX[i] = myPoints[i].x;
00337   }
00338   return aX;
00339 }
00340 
00344 double* Plot2d_Object::verData() const
00345 {
00346   int aNPoints = nbPoints();
00347   double* aY = new double[aNPoints];
00348   for (int i = 0; i < aNPoints; i++) {
00349     aY[i] = myScale * myPoints[i].y;
00350   }
00351   return aY;
00352 }
00353 
00357 long Plot2d_Object::getData( double** theX, double** theY ) const
00358 {
00359   int aNPoints = nbPoints();
00360   *theX = new double[aNPoints];
00361   *theY = new double[aNPoints];
00362   for (int i = 0; i < aNPoints; i++) {
00363     (*theX)[i] = myPoints[i].x;
00364     (*theY)[i] = myScale * myPoints[i].y;
00365   }
00366   return aNPoints;
00367 }
00368 
00374 void Plot2d_Object::setText( const int ind, const QString& txt )
00375 {
00376   if ( ind >= 0 && ind < myPoints.count() )
00377     myPoints[ind].text = txt;
00378 }
00379 
00384 QString Plot2d_Object::text( const int ind ) const
00385 {
00386   return ( ind >= 0 && ind < myPoints.count() ) ? myPoints[ind].text : QString();
00387 }
00388 
00392 int Plot2d_Object::nbPoints() const
00393 {
00394   return myPoints.count();
00395 }
00396 
00400 bool Plot2d_Object::isEmpty() const
00401 {
00402   return myPoints.isEmpty();
00403 }
00404 
00408 void Plot2d_Object::setAutoAssign( bool on )
00409 {
00410   myAutoAssign = on;
00411 }
00412 
00416 bool Plot2d_Object::isAutoAssign() const
00417 {
00418   return myAutoAssign;
00419 }
00420 
00424 void Plot2d_Object::setXAxis(QwtPlot::Axis theXAxis)
00425 {
00426   if (theXAxis == QwtPlot::xBottom || theXAxis == QwtPlot::xTop)
00427     myXAxis = theXAxis;
00428 }
00429 
00433 QwtPlot::Axis Plot2d_Object::getXAxis() const
00434 {
00435   return myXAxis;
00436 }
00437 
00441 void Plot2d_Object::setYAxis(QwtPlot::Axis theYAxis)
00442 {
00443   if (theYAxis == QwtPlot::yLeft || theYAxis == QwtPlot::yRight)
00444     myYAxis = theYAxis;
00445 }
00446 
00450 QwtPlot::Axis Plot2d_Object::getYAxis() const
00451 {
00452   return myYAxis;
00453 }
00454 
00458 double Plot2d_Object::getMinX() const
00459 {
00460   double aMinX = 1e150;
00461   pointList::const_iterator aIt;
00462   for (aIt = myPoints.begin(); aIt != myPoints.end(); ++aIt)
00463     aMinX = qMin( aMinX, (*aIt).x );
00464   return aMinX;
00465 }
00466 
00470 double Plot2d_Object::getMaxX() const
00471 {
00472   double aMaxX = -1e150;
00473   pointList::const_iterator aIt;
00474   for (aIt = myPoints.begin(); aIt != myPoints.end(); ++aIt)
00475     aMaxX = qMax( aMaxX, (*aIt).x );
00476   return aMaxX;
00477 }
00478 
00482 double Plot2d_Object::getMinY() const
00483 {
00484   double aMinY = 1e150;
00485   pointList::const_iterator aIt;
00486   for (aIt = myPoints.begin(); aIt != myPoints.end(); ++aIt)
00487     aMinY = qMin( aMinY, myScale * (*aIt).y );
00488   return aMinY;
00489 }
00490 
00494 double Plot2d_Object::getMaxY() const
00495 {
00496   double aMaxY = -1e150;
00497   pointList::const_iterator aIt;
00498   for (aIt = myPoints.begin(); aIt != myPoints.end(); ++aIt)
00499     aMaxY = qMax( aMaxY, myScale * (*aIt).y );
00500   return aMaxY;
00501 }
00502 
00506 void Plot2d_Object::setSelected(const bool on) {
00507   myIsSelected = on;
00508 }
00509 
00513 bool Plot2d_Object::isSelected() const {
00514   return myIsSelected;
00515 }
00516 
00520 void Plot2d_Object::setSelectionColor(const QColor& c) {
00521   mySelectionColor = c;
00522 }
00523 
00527 QColor Plot2d_Object::selectionColor() {
00528   return mySelectionColor;
00529 }
00530 
00534 void Plot2d_Object::setHighlightedLegendTextColor(const QColor& c) {
00535   myHighlightedLegendTextColor = c;
00536 }
00537 
00541 QColor Plot2d_Object::highlightedLegendTextColor() {
00542   return myHighlightedLegendTextColor;
00543 }