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
23 #ifndef PLOT2D_VIEWFRAME_H
24 #define PLOT2D_VIEWFRAME_H
27 #include "Plot2d_Curve.h"
28 #include "Plot2d_AnalyticalCurve.h"
29 #include "Plot2d_NormalizeAlgorithm.h"
36 #include <qwt_symbol.h>
37 #include <qwt_scale_draw.h>
38 #include <qwt_plot_marker.h>
39 #include <qwt_plot_picker.h>
53 class Plot2d_AxisScaleDraw;
54 class Plot2d_QwtPlotPicker;
56 typedef QMultiHash<QwtPlotCurve*, Plot2d_Curve*> CurveDict;
57 typedef QMultiHash<QwtPlotItem*, Plot2d_Object*> ObjectDict;
59 class PLOT2D_EXPORT Plot2d_ViewFrame : public QWidget, public Plot2d_CurveContainer
63 enum { NoOpId, FitAreaId, ZoomId, PanId, GlPanId, DumpId,
64 ModeXLinearId, ModeXLogarithmicId, ModeYLinearId, ModeYLogarithmicId,
65 LegendId, CurvePointsId, CurveLinesId, CurveSplinesId };
67 /* Construction/destruction */
68 Plot2d_ViewFrame( QWidget*, const QString& = "" );
69 virtual ~Plot2d_ViewFrame();
71 enum ObjectType { MainTitle, XTitle, YTitle, Y2Title, XAxis, YAxis, Y2Axis };
73 QWidget* getViewWidget();
76 virtual void DisplayAll();
77 virtual void EraseAll();
80 void Display( const Plot2d_Prs* );
81 void Erase( const Plot2d_Prs*, const bool = false );
82 Plot2d_Prs* CreatePrs( const char* = 0 );
84 virtual bool eventFilter( QObject*, QEvent* );
88 void setTitle( const QString& );
89 QString getTitle() const;
91 QVector< QVector<QwtPlotCurve *> > displayPlot2dCurveList( const QList< QList<Plot2d_Curve*> >& sysCoCurveList,
93 const QList< QList<bool> >& sides);
95 QVector< QVector<QwtPlotCurve *> > displayPlot2dCurveList( const QList<Plot2d_Curve*>& curveList,
98 const QList< bool >& sides);
100 Plot2d_Curve* createPlot2dCurve( QString & title,
102 QList<double> & xList,
103 QList<double> & yList,
104 QList<QString> & tooltipList,
105 Plot2d::LineType lineKind,
108 QwtSymbol::Style markerKind,
109 Plot2d_QwtPlotPicker* picker,
111 bool displayLegend=true);
113 QColor getPlot2dCurveColor( Plot2d_Curve* plot2dCurve);
115 QwtPlotCurve *createSegment( double *X, double *Y, int nbPoint,
116 Qt::PenStyle lineKind,
119 QwtSymbol::Style markerKind,
122 /* curves operations [ obsolete ] */
123 void displayCurve( Plot2d_Curve*, bool = false );
124 void displayCurves( const curveList&, bool = false );
125 void eraseCurve( Plot2d_Curve*, bool = false );
126 void eraseCurves( const curveList&, bool = false );
127 int getCurves( curveList& ) const;
128 CurveDict getCurves() const;
129 void updateCurve( Plot2d_Curve*, bool = false );
130 void processFiltering(bool = false);
132 /* objects operations */
133 QwtPlotItem* displayObject( Plot2d_Object*, bool = false );
134 void displayObjects( const objectList&, bool = false );
135 void eraseObject( Plot2d_Object*, bool = false );
136 void eraseObjects( const objectList&, bool = false );
137 void eraseBasicObject( QwtPlotItem*, bool = false );
138 void eraseBasicObjects( const QList<QwtPlotItem*> &, bool = false );
139 int getObjects( objectList& ) const;
140 bool isVisible( Plot2d_Object* ) const;
141 void updateObject( Plot2d_Object*, bool = false );
143 void updateLegend( const Plot2d_Prs* );
146 void fitArea( const QRect& );
147 void fitData( const int, const double, const double,
148 const double, const double,
149 const double = 0, const double = 0 );
151 void getFitRanges( double&, double&, double&, double&,
154 void getFitRangeByCurves( double&, double&, double&, double&,
157 void getFitRangeByMarkers(double&, double&, double&, double&,
160 void addAnalyticalCurve( Plot2d_AnalyticalCurve* );
161 void removeAnalyticalCurve( Plot2d_AnalyticalCurve* );
162 void updateAnalyticalCurve( Plot2d_AnalyticalCurve*, bool = false );
163 void updateAnalyticalCurves();
164 void deselectAnalyticalCurves();
165 void deselectObjects();
167 AnalyticalCurveList getAnalyticalCurves() const;
168 Plot2d_AnalyticalCurve* getAnalyticalCurve(QwtPlotItem *);
170 /* view parameters */
171 void copyPreferences( Plot2d_ViewFrame* );
172 void setCurveType( int, bool = true );
173 int getCurveType() const;
174 void setCurveTitle( Plot2d_Curve*, const QString& );
175 void setObjectTitle( Plot2d_Object*, const QString& );
176 void showLegend( bool, bool = true );
177 void setLegendPos( int );
178 int getLegendPos() const;
179 void setLegendFont( const QFont& );
180 QFont getLegendFont() const;
181 void setLegendFontColor( const QColor& );
182 QColor getLegendFontColor() const;
183 void setMarkerSize( const int, bool = true );
184 int getMarkerSize() const;
185 void setBackgroundColor( const QColor& );
186 QColor backgroundColor() const;
187 void setXGrid( bool, const int, bool, const int, bool = true );
188 void setYGrid( bool, const int, bool, const int,
189 bool, const int, bool, const int, bool = true );
190 void setTitle( bool, const QString&, ObjectType, bool = true );
191 QString getTitle( ObjectType ) const;
193 void setFont( const QFont&, ObjectType, bool = true );
194 void setHorScaleMode( const int, bool = true );
195 int getHorScaleMode() const;
196 void setVerScaleMode( const int, bool = true );
197 int getVerScaleMode() const;
198 void setNormLMaxMode( bool, bool = true);
199 bool getNormLMaxMode()const;
200 void setNormLMinMode( bool, bool = true);
201 bool getNormLMinMode()const;
202 void setNormRMaxMode( bool, bool = true);
203 bool getNormRMaxMode()const;
204 void setNormRMinMode( bool, bool = true);
205 bool getNormRMinMode()const;
208 bool isModeHorLinear();
209 bool isModeVerLinear();
210 bool isNormLMaxMode();
211 bool isNormLMinMode();
212 bool isNormRMaxMode();
213 bool isNormRMinMode();
215 bool isLegendShow() const;
217 // Protection against QwtCurve::drawLines() bug in Qwt 0.4.x:
218 // it crashes if switched to X/Y logarithmic mode, when one or more points have
219 // non-positive X/Y coordinate
220 bool isXLogEnabled() const;
221 bool isYLogEnabled() const;
222 void setEnableAxis( QwtPlot::Axis, bool );
224 virtual bool print( const QString&, const QString& ) const;
225 void printPlot( QPainter*, const QRect&,
226 const QwtPlotPrintFilter& = QwtPlotPrintFilter() ) const;
228 QString getVisualParameters();
229 void setVisualParameters( const QString& );
231 void incrementalPan ( const int, const int );
232 void incrementalZoom( const int, const int );
234 QwtPlotCanvas* getPlotCanvas() const;
235 Plot2d_Curve* getClosestCurve( QPoint, double&, int& ) const;
237 Plot2d_Object* getPlotObject( QwtPlotItem* ) const;
238 QwtPlotItem* getPlotObject( Plot2d_Object* ) const;
239 QwtPlotCurve* getPlotCurve( Plot2d_Curve* ) const;
240 Plot2d_Plot2d* getPlot() const { return myPlot; }
242 void updatePlotItem(Plot2d_Object*, QwtPlotItem*);
244 int testOperation( const QMouseEvent& );
245 void readPreferences();
246 void writePreferences();
247 QString getInfo( const QPoint& );
248 virtual void wheelEvent( QWheelEvent* );
249 bool hasPlotCurve( Plot2d_Curve* ) const;
250 void setCurveType( QwtPlotCurve*, int );
251 bool hasPlotObject( Plot2d_Object* ) const;
252 QString getXmlVisualParameters();
253 bool setXmlVisualParameters(const QString&);
263 void onViewFitArea();
264 void onViewGlobalPan();
266 void onAnalyticalCurve();
268 void onChangeBackground();
277 virtual void customEvent( QEvent* );
278 void plotMousePressed( const QMouseEvent& );
279 bool plotMouseMoved( const QMouseEvent& );
280 void plotMouseReleased( const QMouseEvent& );
283 void vpModeHorChanged();
284 void vpModeVerChanged();
285 void vpNormLModeChanged();
286 void vpNormRModeChanged();
287 void vpCurveChanged();
288 void contextMenuRequested( QContextMenuEvent* );
289 void legendClicked( QwtPlotItem* );
292 Plot2d_Plot2d* myPlot;
300 QColor myLegendColor;
303 QString myTitle, myXTitle, myYTitle, myY2Title;
304 bool myTitleEnabled, myXTitleEnabled, myYTitleEnabled, myY2TitleEnabled;
305 bool myXGridMajorEnabled, myYGridMajorEnabled, myY2GridMajorEnabled;
306 bool myXGridMinorEnabled, myYGridMinorEnabled, myY2GridMinorEnabled;
307 int myXGridMaxMajor, myYGridMaxMajor, myY2GridMaxMajor;
308 int myXGridMaxMinor, myYGridMaxMinor, myY2GridMaxMinor;
309 int myXMode, myYMode;
310 bool myNormLMin, myNormLMax, myNormRMin, myNormRMax;
311 double myXDistance, myYDistance, myYDistance2;
313 ObjectDict myObjects;
314 AnalyticalCurveList myAnalyticalCurves;
315 Plot2d_NormalizeAlgorithm* myLNormAlgo;
316 Plot2d_NormalizeAlgorithm* myRNormAlgo;
319 // List of QwtPlotCurve curves to draw (created by Plot2d_Curve::createPlotItem() )
320 QList<QwtPlotItem*> myQwtPlotCurveList;
322 // List of intermittent segments to connect curves
323 QList<QwtPlotCurve*> myIntermittentSegmentList;
325 // List of curves Plot2d_Curve
326 QList<Plot2d_Curve*> myPlot2dCurveList;
329 class Plot2d_Plot2d : public QwtPlot
333 Plot2d_Plot2d( QWidget* );
334 virtual ~Plot2d_Plot2d();
336 void setLogScale( int, bool );
339 QwtLegend* getLegend();
340 QSize sizeHint() const;
341 QSize minimumSizeHint() const;
342 void defaultPicker();
343 void setPickerMousePattern( int, int = Qt::NoButton );
344 void setPicker( Plot2d_QwtPlotPicker *picker);
345 Plot2d_QwtPlotPicker* getPicker() { return myPicker; }
346 Plot2d_AxisScaleDraw* getScaleDraw() { return myScaleDraw; }
347 QList<QwtPlotMarker*> getSeparationLineList() { return mySeparationLineList; }
348 void clearSeparationLineList();
349 QwtPlotMarker *createMarkerAndTooltip( QwtSymbol symbol,
353 Plot2d_QwtPlotPicker *picker);
355 bool polished() const;
356 QwtPlotGrid* grid() const;
357 QwtPlotZoomer* zoomer() const;
359 virtual void updateYAxisIdentifiers();
361 // Methods to deal with axes ticks
363 void createAxisScaleDraw();
365 void unactivAxisScaleDraw( int numcall);
367 void displayXTicksAndLabels(
368 double XLeftmargin, double XRightMargin,
369 const QList< QPair< QString, QMap<double,QString> > > & devicesPosLabelTicks);
371 void createSeparationLine( double Xpos);
375 virtual void polish();
378 void onScaleDivChanged();
382 QList<QColor> myColors;
384 QwtPlotZoomer* myPlotZoomer;
385 Plot2d_AxisScaleDraw* myScaleDraw;
386 // The point picker associated with the graphic view
387 Plot2d_QwtPlotPicker *myPicker;
389 // List of verticals segments between two curves
390 QList<QwtPlotMarker*> mySeparationLineList;
393 class Plot2d_ScaleDraw: public QwtScaleDraw
396 Plot2d_ScaleDraw( char f = 'g', int prec = 6 );
397 Plot2d_ScaleDraw( const QwtScaleDraw& scaleDraw, char f = 'g', int prec = 6 );
399 virtual QwtText label( double value ) const;
401 int precision() const { return myPrecision; }
408 class Plot2d_YScaleDraw: public QwtScaleDraw
413 virtual QwtText label( double value ) const;
416 /* Definition of X axis graduations
418 class Plot2d_AxisScaleDraw: public QwtScaleDraw
421 static const QString DEVICE_FONT;
422 static const int DEVICE_FONT_SIZE;
423 static const int DEVICE_BY;
425 Plot2d_AxisScaleDraw(Plot2d_Plot2d* plot);
427 virtual ~Plot2d_AxisScaleDraw();
429 void unactivTicksDrawing( int numcall);
431 virtual void draw( QPainter * painter, const QPalette & palette) const;
433 virtual QwtText label(double value) const;
435 void setLabelTick(double value, QString label, bool isDevice = false);
437 void setTicks(const QList<double> aTicks);
439 void setInterval(double lowerBound, double upperBound);
445 void drawLabel( QPainter* painter, double value) const;
447 void drawTick( QPainter* painter, double value, int len) const;
450 bool myActivTicksDrawing; // true => activate drawing ticks (with draw() )
451 int myNumTicksDrawingCall; // call number to ticks drawing
453 // Ticks list to display on X axis
454 QMap<double, QString> myLabelX; // position, label
456 QList<double> myTicks; // positions
458 // Systems names to display under X axis
459 QMap<double, QString> myLabelDevice;
461 Plot2d_Plot2d* myPlot; // Drawing zone QwtPlot
470 /* Management of tooltips associated with markers for curves points or others points
472 class Plot2d_QwtPlotPicker : public QwtPlotPicker
475 static const double BOUND_HV_SIZE;
477 Plot2d_QwtPlotPicker( int xAxis,
480 RubberBand rubberBand,
481 DisplayMode trackerMode,
482 QwtPlotCanvas *canvas);
484 Plot2d_QwtPlotPicker( int xAxis,
486 QwtPlotCanvas *canvas);
488 virtual ~Plot2d_QwtPlotPicker();
490 QList<QwtPlotMarker*> pMarkers; // points markers
491 QMap<QwtPlotMarker*, QwtText> pMarkersToolTip; // associations (marker,tooltip)
495 virtual QwtText trackerText( const QwtDoublePoint & pos ) const;