Back to index

salome-gui  6.5.0
Plot2d_Curve.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_Curve.cxx
00023 //  Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
00024 
00025 #include "Plot2d_Curve.h"
00026 #include "Plot2d_PlotItems.h"
00027 #include <qwt_plot_curve.h>
00028 
00029 const int DEFAULT_LINE_WIDTH  =  0;     // (default) line width
00030 const int DEFAULT_MARKER_SIZE =  9;     // default marker size
00031 
00035 Plot2d_Curve::Plot2d_Curve()
00036 : Plot2d_Object(),
00037   myColor( 0, 0, 0 ), 
00038   myMarker( Plot2d::Circle ), 
00039   myMarkerSize( 0 ), 
00040   myLine( Plot2d::Solid ), 
00041   myLineWidth( 0 )
00042 {
00043 }
00044 
00048 Plot2d_Curve::~Plot2d_Curve()
00049 {
00050 }
00051 
00055 Plot2d_Curve::Plot2d_Curve( const Plot2d_Curve& curve )
00056 : Plot2d_Object( curve )
00057 {
00058   myColor      = curve.getColor();
00059   myMarker     = curve.getMarker();
00060   myMarkerSize = curve.getMarkerSize();
00061   myLine       = curve.getLine();
00062   myLineWidth  = curve.getLineWidth();
00063 }
00064 
00068 Plot2d_Curve& Plot2d_Curve::operator=( const Plot2d_Curve& curve )
00069 {
00070   Plot2d_Object::operator=(curve);
00071   myColor      = curve.getColor();
00072   myMarker     = curve.getMarker();
00073   myMarkerSize = curve.getMarkerSize();
00074   myLine       = curve.getLine();
00075   myLineWidth  = curve.getLineWidth();
00076   return *this;
00077 }
00078 
00082 int Plot2d_Curve::rtti()
00083 {
00084   return QwtPlotItem::Rtti_PlotCurve;
00085 }
00086 
00090 QwtPlotItem* Plot2d_Curve::createPlotItem()
00091 {
00092   QwtPlotCurve* aCurve = new Plot2d_QwtPlotCurve( getVerTitle(), getYAxis() );
00093   updatePlotItem( aCurve );
00094   return aCurve;
00095 }
00096 
00100 void Plot2d_Curve::autoFill( const QwtPlot* thePlot )
00101 {
00102   QwtSymbol::Style typeMarker;
00103   QColor           color;
00104   Qt::PenStyle     typeLine;
00105   Plot2d::getNextMarker( rtti(), thePlot, typeMarker, color, typeLine );
00106 
00107   setColor( color );
00108   setLine( Plot2d::qwt2plotLine( typeLine ), DEFAULT_LINE_WIDTH );
00109   setMarker( Plot2d::qwt2plotMarker( typeMarker ) );
00110 }
00111 
00115 void Plot2d_Curve::updatePlotItem( QwtPlotItem* theItem )
00116 {
00117   if ( theItem->rtti() != rtti() )
00118     return;
00119 
00120   Plot2d_QwtPlotCurve* aCurve = dynamic_cast<Plot2d_QwtPlotCurve*>( theItem );
00121   if ( !aCurve )
00122     return;
00123 
00124   Plot2d_Object::updatePlotItem( theItem );
00125 
00126   Qt::PenStyle     ps = Plot2d::plot2qwtLine( getLine() );
00127   QwtSymbol::Style ms = Plot2d::plot2qwtMarker( getMarker() );
00128   
00129   QColor aColor = isSelected() ?  Plot2d_Object::selectionColor() : getColor();
00130   int lineW = getLineWidth(); 
00131   if ( isSelected() ) lineW += (lineW == 0 ? 3 : 2);
00132 
00133   int markerS = isSelected() ? getMarkerSize() + 2 : getMarkerSize();
00134 
00135   aCurve->setSelected(isSelected());
00136 
00137   aCurve->setPen( QPen(aColor , lineW, ps ) );
00138   aCurve->setSymbol( QwtSymbol( ms, QBrush( aColor ), 
00139                             QPen( aColor ), 
00140                             QSize( markerS , markerS ) ) );
00141 
00142   aCurve->setLegendPen(QPen(getColor(), getLineWidth(), ps ));
00143   aCurve->setLegendSymbol( QwtSymbol( ms, QBrush( getColor() ), 
00144                                   QPen( getColor() ), 
00145                                   QSize( getMarkerSize() , getMarkerSize() )));
00146   
00147   double *x, *y, *min, *max;
00148   long nb = getData( &x, &y );
00149   if(nb > 0 && x && y) {
00150     aCurve->setData( x, y, nb );
00151     delete x;
00152     delete y;
00153     QList<int> idx;
00154     getDeviationData(min, max, idx);
00155     if(idx.size() > 0 && min && max) {
00156       aCurve->setDeviationData(min,max,idx);
00157       delete min;
00158       delete max;
00159     } else {
00160       aCurve->clearDeviationData();
00161     }
00162   }
00163 }
00164 
00168 void Plot2d_Curve::setColor( const QColor& color )
00169 {
00170   myColor = color;
00171   setAutoAssign( false );
00172 }
00173 
00177 QColor Plot2d_Curve::getColor() const
00178 {
00179   return myColor;
00180 }
00181 
00185 void Plot2d_Curve::setMarker( Plot2d::MarkerType marker, const int markerSize )
00186 {
00187   setMarker( marker );
00188   setMarkerSize( markerSize );
00189   setAutoAssign( false );
00190 }
00191 
00195 void Plot2d_Curve::setMarker( Plot2d::MarkerType marker )
00196 {
00197   myMarker = marker;
00198   setAutoAssign( false );
00199 }
00200 
00201 /* Sets Qwt marker type
00202  */
00203 void Plot2d_Curve::setMarkerStyle( QwtSymbol::Style style)
00204 {
00205   myMarkerStyle = style;
00206 }
00207 
00211 Plot2d::MarkerType Plot2d_Curve::getMarker() const
00212 {
00213   return myMarker;
00214 }
00215 
00216 
00217 /* Gets Qwt marker type
00218  */
00219 QwtSymbol::Style Plot2d_Curve::getMarkerStyle() const
00220 {
00221   return myMarkerStyle;
00222 }
00223 
00224 
00225 
00229 void Plot2d_Curve::setMarkerSize( const int theSize )
00230 {
00231   myMarkerSize = theSize < 0 ? 0 : theSize;
00232   setAutoAssign( false );
00233 }
00234 
00238 int Plot2d_Curve::getMarkerSize() const
00239 {
00240   return myMarkerSize;
00241 }
00242 
00250 void Plot2d_Curve::setLine( Plot2d::LineType line, const int lineWidth )
00251 {
00252   setLine( line );
00253   setLineWidth( lineWidth );
00254   setAutoAssign( false );
00255 }
00256 
00260 void Plot2d_Curve::setLine( Plot2d::LineType line )
00261 {
00262   myLine = line;
00263   setAutoAssign( false );
00264 }
00265 
00269 Plot2d::LineType Plot2d_Curve::getLine() const
00270 {
00271   return myLine;
00272 }
00273 
00277 void Plot2d_Curve::setLineWidth( const int lineWidth )
00278 {
00279   myLineWidth = lineWidth < 0 ? 0 : lineWidth;
00280   setAutoAssign( false );
00281 }
00282 
00286 int Plot2d_Curve::getLineWidth() const
00287 {
00288   return myLineWidth;
00289 }
00293 void Plot2d_Curve::setDeviationData( const double* min, const double* max,const QList<int>& idx) {
00294   for( int i = 0; i < idx.size(); i++ ) {
00295     if(idx[i] < myPoints.size()) {
00296       myPoints[idx[i]].setDeviation(min[i], max[i]);
00297     }
00298   }
00299 }
00300 
00304 void Plot2d_Curve::getDeviationData( double*& theMin, double*& theMax, QList<int>& idx) const
00305 {
00306   int aNb = 0;
00307   idx.clear();
00308   for (int i = 0; i < nbPoints(); i++)
00309     if(myPoints[i].hasDeviation())
00310       aNb++;
00311   if(aNb) {
00312     double min, max;
00313     theMin = new double[aNb];
00314     theMax = new double[aNb];
00315     for (int i = 0; i < nbPoints(); i++)
00316       if(myPoints[i].hasDeviation()) {
00317         myPoints[i].deviation(min,max);
00318         theMin[i] = min;
00319         theMax[i] = max;
00320         idx.push_back(i);
00321       }
00322   }
00323 }
00324 
00328 void Plot2d_Curve::clearDeviationData() {
00329   for( int i=0; i < myPoints.size(); i++ )
00330     myPoints[i].clearDeviation();
00331 }
00332 
00336 double Plot2d_Curve::getMinY() const
00337 {
00338   double aMinY = 1e150;
00339   pointList::const_iterator aIt;
00340   double coeff = 0.0;
00341   for (aIt = myPoints.begin(); aIt != myPoints.end(); ++aIt) {    
00342    (*aIt).minDeviation(coeff);
00343     aMinY = qMin( aMinY, myScale * (*aIt).y - coeff);
00344   }
00345   return aMinY;
00346 }
00347 
00351 double Plot2d_Curve::getMaxY() const
00352 {
00353   double aMaxY = -1e150;
00354   pointList::const_iterator aIt;
00355   double coeff = 0.0;
00356   for (aIt = myPoints.begin(); aIt != myPoints.end(); ++aIt) {
00357     (*aIt).maxDeviation(coeff);
00358     aMaxY = qMax( aMaxY, myScale * (*aIt).y + coeff);
00359   }
00360   return aMaxY;
00361 }