1 // Copyright (C) 2007-2013 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_Curve.cxx
23 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
25 #include "Plot2d_Curve.h"
26 #include "Plot2d_PlotItems.h"
27 #include <qwt_plot_curve.h>
29 const int DEFAULT_LINE_WIDTH = 0; // (default) line width
30 const int DEFAULT_MARKER_SIZE = 9; // default marker size
35 Plot2d_Curve::Plot2d_Curve()
38 myMarker( Plot2d::Circle ),
40 myLine( Plot2d::Solid ),
48 Plot2d_Curve::~Plot2d_Curve()
53 Copy constructor. Makes deep copy of data
55 Plot2d_Curve::Plot2d_Curve( const Plot2d_Curve& curve )
56 : Plot2d_Object( curve )
58 myColor = curve.getColor();
59 myMarker = curve.getMarker();
60 myMarkerSize = curve.getMarkerSize();
61 myLine = curve.getLine();
62 myLineWidth = curve.getLineWidth();
66 operator=. Makes deep copy of data
68 Plot2d_Curve& Plot2d_Curve::operator=( const Plot2d_Curve& curve )
70 Plot2d_Object::operator=(curve);
71 myColor = curve.getColor();
72 myMarker = curve.getMarker();
73 myMarkerSize = curve.getMarkerSize();
74 myLine = curve.getLine();
75 myLineWidth = curve.getLineWidth();
80 Get typeid for the plot2d curve class
82 int Plot2d_Curve::rtti()
84 return QwtPlotItem::Rtti_PlotCurve;
88 Create plot object for the curve
90 QwtPlotItem* Plot2d_Curve::createPlotItem()
92 QwtPlotCurve* aCurve = new Plot2d_QwtPlotCurve( getVerTitle(), getYAxis() );
93 updatePlotItem( aCurve );
98 Auto fill parameters of object by plot view
100 void Plot2d_Curve::autoFill( const QwtPlot* thePlot )
102 QwtSymbol::Style typeMarker;
104 Qt::PenStyle typeLine;
105 Plot2d::getNextMarker( rtti(), thePlot, typeMarker, color, typeLine );
108 setLine( Plot2d::qwt2plotLine( typeLine ), DEFAULT_LINE_WIDTH );
109 setMarker( Plot2d::qwt2plotMarker( typeMarker ) );
115 void Plot2d_Curve::updatePlotItem( QwtPlotItem* theItem )
117 if ( theItem->rtti() != rtti() )
120 Plot2d_QwtPlotCurve* aCurve = dynamic_cast<Plot2d_QwtPlotCurve*>( theItem );
124 Plot2d_Object::updatePlotItem( theItem );
126 Qt::PenStyle ps = Plot2d::plot2qwtLine( getLine() );
127 QwtSymbol::Style ms = Plot2d::plot2qwtMarker( getMarker() );
129 QColor aColor = isSelected() ? Plot2d_Object::selectionColor() : getColor();
130 int lineW = getLineWidth();
131 if ( isSelected() ) lineW += (lineW == 0 ? 3 : 2);
133 int markerS = isSelected() ? getMarkerSize() + 2 : getMarkerSize();
135 aCurve->setSelected(isSelected());
137 aCurve->setPen( QPen(aColor , lineW, ps ) );
138 aCurve->setSymbol( QwtSymbol( ms, QBrush( aColor ),
140 QSize( markerS , markerS ) ) );
142 aCurve->setLegendPen(QPen(getColor(), getLineWidth(), ps ));
143 aCurve->setLegendSymbol( QwtSymbol( ms, QBrush( getColor() ),
145 QSize( getMarkerSize() , getMarkerSize() )));
147 double *x, *y, *min, *max;
148 long nb = getData( &x, &y );
149 if(nb > 0 && x && y) {
150 aCurve->setData( x, y, nb );
154 getDeviationData(min, max, idx);
155 if(idx.size() > 0 && min && max) {
156 aCurve->setDeviationData(min,max,idx);
160 aCurve->clearDeviationData();
166 Sets curve's color ( and resets AutoAssign flag )
168 void Plot2d_Curve::setColor( const QColor& color )
171 setAutoAssign( false );
177 QColor Plot2d_Curve::getColor() const
183 Sets marker type and size ( and resets AutoAssign flag )
185 void Plot2d_Curve::setMarker( Plot2d::MarkerType marker, const int markerSize )
188 setMarkerSize( markerSize );
189 setAutoAssign( false );
193 Sets marker type ( and resets AutoAssign flag )
195 void Plot2d_Curve::setMarker( Plot2d::MarkerType marker )
198 setAutoAssign( false );
201 /* Sets Qwt marker type
203 void Plot2d_Curve::setMarkerStyle( QwtSymbol::Style style)
205 myMarkerStyle = style;
211 Plot2d::MarkerType Plot2d_Curve::getMarker() const
217 /* Gets Qwt marker type
219 QwtSymbol::Style Plot2d_Curve::getMarkerStyle() const
221 return myMarkerStyle;
227 Sets new marker size ( and resets AutoAssign flag )
229 void Plot2d_Curve::setMarkerSize( const int theSize )
231 myMarkerSize = theSize < 0 ? 0 : theSize;
232 setAutoAssign( false );
238 int Plot2d_Curve::getMarkerSize() const
244 Sets line type and width ( and resets AutoAssign flag )
245 NOTE : A line width of 0 will produce a 1 pixel wide line using a fast algorithm for diagonals.
246 A line width of 1 will also produce a 1 pixel wide line, but uses a slower more accurate
247 algorithm for diagonals.
248 For horizontal and vertical lines a line width of 0 is the same as a line width of 1.
250 void Plot2d_Curve::setLine( Plot2d::LineType line, const int lineWidth )
253 setLineWidth( lineWidth );
254 setAutoAssign( false );
258 Sets line type ( and resets AutoAssign flag )
260 void Plot2d_Curve::setLine( Plot2d::LineType line )
263 setAutoAssign( false );
269 Plot2d::LineType Plot2d_Curve::getLine() const
275 Sets line width ( and resets AutoAssign flag )
277 void Plot2d_Curve::setLineWidth( const int lineWidth )
279 myLineWidth = lineWidth < 0 ? 0 : lineWidth;
280 setAutoAssign( false );
286 int Plot2d_Curve::getLineWidth() const
291 Sets deviation data on the curve.
293 void Plot2d_Curve::setDeviationData( const double* min, const double* max,const QList<int>& idx) {
294 for( int i = 0; i < idx.size(); i++ ) {
295 if(idx[i] < myPoints.size()) {
296 myPoints[idx[i]].setDeviation(min[i], max[i]);
304 void Plot2d_Curve::getDeviationData( double*& theMin, double*& theMax, QList<int>& idx) const
308 for (int i = 0; i < nbPoints(); i++)
309 if(myPoints[i].hasDeviation())
313 theMin = new double[aNb];
314 theMax = new double[aNb];
315 for (int i = 0; i < nbPoints(); i++)
316 if(myPoints[i].hasDeviation()) {
317 myPoints[i].deviation(min,max);
326 Clear deviation data on the curve.
328 void Plot2d_Curve::clearDeviationData() {
329 for( int i=0; i < myPoints.size(); i++ )
330 myPoints[i].clearDeviation();
334 Gets object's minimal ordinate
336 double Plot2d_Curve::getMinY() const
338 double aMinY = 1e150;
339 pointList::const_iterator aIt;
341 for (aIt = myPoints.begin(); aIt != myPoints.end(); ++aIt) {
342 aMinY = qMin( aMinY, myScale * (*aIt).y );
343 if((*aIt).minDeviation(coeff))
344 aMinY = qMin( aMinY, coeff );
350 Gets object's maximal ordinate
352 double Plot2d_Curve::getMaxY() const
354 double aMaxY = -1e150;
355 pointList::const_iterator aIt;
357 for (aIt = myPoints.begin(); aIt != myPoints.end(); ++aIt) {
358 aMaxY = qMax( aMaxY, myScale * (*aIt).y);
359 if((*aIt).maxDeviation(coeff))
360 aMaxY = qMax( aMaxY, coeff);