1 // Copyright (C) 2007-2016 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
23 #ifndef PLOT2D_VIEWFRAME_H
24 #define PLOT2D_VIEWFRAME_H
27 #include "Plot2d_Curve.h"
28 #ifndef NO_ANALYTICAL_CURVES
29 #include "Plot2d_AnalyticalCurve.h"
31 #include "Plot2d_NormalizeAlgorithm.h"
38 #include <qwt_symbol.h>
39 #include <qwt_scale_draw.h>
40 #include <qwt_plot_marker.h>
41 #include <qwt_plot_picker.h>
42 #include <qwt_plot_canvas.h>
43 #include <qwt_legend.h>
57 class Plot2d_AxisScaleDraw;
58 class Plot2d_QwtPlotPicker;
60 typedef QMultiHash<QwtPlotCurve*, Plot2d_Curve*> CurveDict;
61 typedef QMultiHash<QwtPlotItem*, Plot2d_Object*> ObjectDict;
63 class PLOT2D_EXPORT Plot2d_ViewFrame : public QWidget
64 #ifndef NO_ANALYTICAL_CURVES
65 , public Plot2d_CurveContainer
70 enum { NoOpId, FitAreaId, ZoomId, PanId, GlPanId, DumpId,
71 ModeXLinearId, ModeXLogarithmicId, ModeYLinearId, ModeYLogarithmicId,
72 LegendId, CurvePointsId, CurveLinesId, CurveSplinesId };
74 /* Construction/destruction */
75 Plot2d_ViewFrame( QWidget*, const QString& = "" );
76 virtual ~Plot2d_ViewFrame();
81 enum ObjectType { MainTitle, XTitle, YTitle, Y2Title, XAxis, YAxis, Y2Axis };
83 QWidget* getViewWidget();
86 virtual void DisplayAll();
87 virtual void EraseAll();
90 void Display( const Plot2d_Prs* );
91 void Erase( const Plot2d_Prs*, const bool = false );
92 Plot2d_Prs* CreatePrs( const char* = 0 );
94 virtual bool eventFilter( QObject*, QEvent* );
97 void updateTitles( const bool = true );
98 void setTitle( const QString& );
99 QString getTitle() const;
101 QVector< QVector<QwtPlotCurve *> > displayPlot2dCurveList( const QList< QList<Plot2d_Curve*> >& sysCoCurveList,
103 const QList< QList<bool> >& sides);
105 QVector< QVector<QwtPlotCurve *> > displayPlot2dCurveList( const QList<Plot2d_Curve*>& curveList,
108 const QList< bool >& sides);
110 Plot2d_Curve* createPlot2dCurve( QString & title,
112 QList<double> & xList,
113 QList<double> & yList,
114 QList<QString> & tooltipList,
115 Plot2d::LineType lineKind,
118 QwtSymbol::Style markerKind,
119 Plot2d_QwtPlotPicker* picker,
121 bool displayLegend=true);
123 QColor getPlot2dCurveColor( Plot2d_Curve* plot2dCurve);
125 QwtPlotCurve *createSegment( double *X, double *Y, int nbPoint,
126 Qt::PenStyle lineKind,
129 QwtSymbol::Style markerKind,
132 /* curves operations [ obsolete ] */
133 void displayCurve( Plot2d_Curve*, bool = false );
134 void displayCurves( const curveList&, bool = false );
135 void eraseCurve( Plot2d_Curve*, bool = false );
136 void eraseCurves( const curveList&, bool = false );
137 int getCurves( curveList& ) const;
138 CurveDict getCurves() const;
139 void updateCurve( Plot2d_Curve*, bool = false );
140 void processFiltering(bool = false);
142 /* objects operations */
143 QwtPlotItem* displayObject( Plot2d_Object*, bool = false );
144 void displayObjects( const objectList&, bool = false );
145 void eraseObject( Plot2d_Object*, bool = false );
146 void eraseObjects( const objectList&, bool = false );
147 void eraseBasicObject( QwtPlotItem*, bool = false );
148 void eraseBasicObjects( const QList<QwtPlotItem*> &, bool = false );
149 int getObjects( objectList& ) const;
150 bool isVisible( Plot2d_Object* ) const;
151 void updateObject( Plot2d_Object*, bool = false );
153 void updateLegend( const Plot2d_Prs* );
156 void fitArea( const QRect& );
157 void fitData( const int, const double, const double,
158 const double, const double,
159 const double = 0, const double = 0 );
161 void getFitRanges( double&, double&, double&, double&,
164 void getFitRangeByCurves( double&, double&, double&, double&,
167 void getFitRangeByMarkers(double&, double&, double&, double&,
170 #ifndef NO_ANALYTICAL_CURVES
171 void addAnalyticalCurve( Plot2d_AnalyticalCurve* );
172 void removeAnalyticalCurve( Plot2d_AnalyticalCurve* );
173 void updateAnalyticalCurve( Plot2d_AnalyticalCurve*, bool = false );
174 void updateAnalyticalCurves();
175 void deselectAnalyticalCurves();
177 AnalyticalCurveList getAnalyticalCurves() const;
178 Plot2d_AnalyticalCurve* getAnalyticalCurve(QwtPlotItem *);
181 void deselectObjects();
183 /* view parameters */
184 void copyPreferences( Plot2d_ViewFrame* );
185 void setCurveType( int, bool = true );
186 int getCurveType() const;
187 void setCurveTitle( Plot2d_Curve*, const QString& );
188 void setObjectTitle( Plot2d_Object*, const QString& );
189 void showLegend( bool, bool = true );
190 void setLegendPos( int );
191 int getLegendPos() const;
192 void setLegendSymbolType( int );
193 int getLegendSymbolType() const;
194 void setLegendFont( const QFont& );
195 QFont getLegendFont() const;
196 void setLegendFontColor( const QColor& );
197 QColor getLegendFontColor() const;
198 void setSelectedLegendFontColor( const QColor& );
199 QColor getSelectedLegendFontColor() const;
200 void setMarkerSize( const int, bool = true );
201 int getMarkerSize() const;
202 virtual void setBackgroundColor( const QColor& );
203 QColor backgroundColor() const;
204 virtual void setSelectionColor( const QColor& );
205 QColor selectionColor() const;
206 void setXGrid( bool, const int, bool, const int, bool = true );
207 void setYGrid( bool, const int, bool, const int,
208 bool, const int, bool, const int, bool = true );
209 void setTitle( bool, const QString&, ObjectType, bool = true );
210 QString getTitle( ObjectType ) const;
212 void setFont( const QFont&, ObjectType, bool = true );
213 void setHorScaleMode( const int, bool = true );
214 int getHorScaleMode() const;
215 void setVerScaleMode( const int, bool = true );
216 int getVerScaleMode() const;
217 void setNormLMaxMode( bool, bool = true);
218 bool getNormLMaxMode()const;
219 void setNormLMinMode( bool, bool = true);
220 bool getNormLMinMode()const;
221 void setNormRMaxMode( bool, bool = true);
222 bool getNormRMaxMode()const;
223 void setNormRMinMode( bool, bool = true);
224 bool getNormRMinMode()const;
227 bool isModeHorLinear();
228 bool isModeVerLinear();
229 bool isNormLMaxMode();
230 bool isNormLMinMode();
231 bool isNormRMaxMode();
232 bool isNormRMinMode();
234 bool isLegendShow() const;
236 // Protection against QwtCurve::drawLines() bug in Qwt 0.4.x:
237 // it crashes if switched to X/Y logarithmic mode, when one or more points have
238 // non-positive X/Y coordinate
239 bool isXLogEnabled() const;
240 bool isYLogEnabled() const;
241 void setEnableAxis( QwtPlot::Axis, bool );
243 virtual bool print( const QString&, const QString& ) const;
244 void printPlot( QPainter*, const QRectF& ) const;
246 QString getVisualParameters();
247 void setVisualParameters( const QString& );
249 void incrementalPan ( const int, const int );
250 void incrementalZoom( const int, const int );
252 QwtPlotCanvas* getPlotCanvas() const;
253 Plot2d_Curve* getClosestCurve( QPoint, double&, int& ) const;
255 Plot2d_Object* getPlotObject( QwtPlotItem* ) const;
256 QwtPlotItem* getPlotObject( Plot2d_Object* ) const;
257 QwtPlotCurve* getPlotCurve( Plot2d_Curve* ) const;
258 Plot2d_Plot2d* getPlot() const { return myPlot; }
260 void updatePlotItem(Plot2d_Object*, QwtPlotItem*);
262 int testOperation( const QMouseEvent& );
263 virtual void readPreferences();
264 virtual void writePreferences();
265 QString getInfo( const QPoint& );
266 virtual void wheelEvent( QWheelEvent* );
267 bool hasPlotCurve( Plot2d_Curve* ) const;
268 void setCurveType( QwtPlotCurve*, int );
269 bool hasPlotObject( Plot2d_Object* ) const;
270 QString getXmlVisualParameters();
271 bool setXmlVisualParameters(const QString&);
277 void onViewFitArea();
278 void onViewGlobalPan();
280 #ifndef NO_ANALYTICAL_CURVES
281 void onAnalyticalCurve();
284 void onChangeBackground();
293 virtual void customEvent( QEvent* );
294 void plotMousePressed( const QMouseEvent& );
295 bool plotMouseMoved( const QMouseEvent& );
296 void plotMouseReleased( const QMouseEvent& );
299 void vpModeHorChanged();
300 void vpModeVerChanged();
301 void vpNormLModeChanged();
302 void vpNormRModeChanged();
303 void vpCurveChanged();
304 void contextMenuRequested( QContextMenuEvent* );
305 void clicked (const QVariant&, int );
308 Plot2d_Plot2d* myPlot;
315 int myLegendSymbolType;
317 QColor myLegendColor;
318 QColor mySelectedLegendFontColor;
321 QColor mySelectionColor;
322 QString myTitle, myXTitle, myYTitle, myY2Title;
323 bool myTitleEnabled, myXTitleEnabled, myYTitleEnabled, myY2TitleEnabled;
324 bool myXGridMajorEnabled, myYGridMajorEnabled, myY2GridMajorEnabled;
325 bool myXGridMinorEnabled, myYGridMinorEnabled, myY2GridMinorEnabled;
326 int myXGridMaxMajor, myYGridMaxMajor, myY2GridMaxMajor;
327 int myXGridMaxMinor, myYGridMaxMinor, myY2GridMaxMinor;
328 int myXMode, myYMode;
329 bool myNormLMin, myNormLMax, myNormRMin, myNormRMax;
330 double myXDistance, myYDistance, myYDistance2;
332 ObjectDict myObjects;
333 #ifndef NO_ANALYTICAL_CURVES
334 AnalyticalCurveList myAnalyticalCurves;
336 Plot2d_NormalizeAlgorithm* myLNormAlgo;
337 Plot2d_NormalizeAlgorithm* myRNormAlgo;
340 // List of QwtPlotCurve curves to draw (created by Plot2d_Curve::createPlotItem() )
341 QList<QwtPlotItem*> myQwtPlotCurveList;
343 // List of intermittent segments to connect curves
344 QList<QwtPlotCurve*> myIntermittentSegmentList;
346 // List of curves Plot2d_Curve
347 QList<Plot2d_Curve*> myPlot2dCurveList;
350 class Plot2d_Plot2d : public QwtPlot
354 Plot2d_Plot2d( QWidget* );
355 virtual ~Plot2d_Plot2d();
357 void setLogScale( int, bool );
360 QwtAbstractLegend* getLegend();
361 QSize sizeHint() const;
362 QSize minimumSizeHint() const;
363 void defaultPicker();
364 void setPickerMousePattern( int, int = Qt::NoButton );
365 void setPicker( Plot2d_QwtPlotPicker *picker);
366 Plot2d_QwtPlotPicker* getPicker() { return myPicker; }
367 Plot2d_AxisScaleDraw* getScaleDraw() { return myScaleDraw; }
368 QList<QwtPlotMarker*> getSeparationLineList() { return mySeparationLineList; }
369 void clearSeparationLineList();
370 void setLegendSymbolType( const int );
371 int getLegendSymbolType();
372 QwtPlotMarker *createMarkerAndTooltip( QwtSymbol* symbol,
376 Plot2d_QwtPlotPicker *picker);
378 QwtPlotGrid* grid() const;
379 QwtPlotZoomer* zoomer() const;
381 virtual void updateYAxisIdentifiers();
383 // Methods to deal with axes ticks
385 void createAxisScaleDraw();
387 void unactivAxisScaleDraw( int numcall);
389 void displayXTicksAndLabels(
390 double XLeftmargin, double XRightMargin,
391 const QList< QPair< QString, QMap<double,QString> > > & devicesPosLabelTicks);
393 void createSeparationLine( double Xpos);
397 QList<QColor> myColors;
398 QwtPlotZoomer* myPlotZoomer;
399 Plot2d_AxisScaleDraw* myScaleDraw;
400 // The point picker associated with the graphic view
401 Plot2d_QwtPlotPicker *myPicker;
403 // List of verticals segments between two curves
404 QList<QwtPlotMarker*> mySeparationLineList;
405 int myLegendSymbolType;
408 class Plot2d_ScaleDraw: public QwtScaleDraw
411 Plot2d_ScaleDraw( char f = 'g', int prec = 6 );
413 virtual QwtText label( double value ) const;
415 int precision() const { return myPrecision; }
422 class Plot2d_YScaleDraw: public QwtScaleDraw
427 virtual QwtText label( double value ) const;
430 /* Definition of X axis graduations
432 class Plot2d_AxisScaleDraw: public QwtScaleDraw
435 static const QString DEVICE_FONT;
436 static const int DEVICE_FONT_SIZE;
437 static const int DEVICE_BY;
439 Plot2d_AxisScaleDraw(Plot2d_Plot2d* plot);
441 virtual ~Plot2d_AxisScaleDraw();
443 void unactivTicksDrawing( int numcall);
445 virtual void draw( QPainter * painter, const QPalette & palette) const;
447 virtual QwtText label(double value) const;
449 void setLabelTick(double value, QString label, bool isDevice = false);
451 void setTicks(const QList<double> aTicks);
453 void setInterval(double lowerBound, double upperBound);
457 double extent( const QFont &font ) const;
461 void drawLabel( QPainter* painter, double value) const;
463 void drawTick( QPainter* painter, double value, int len) const;
466 bool myActivTicksDrawing; // true => activate drawing ticks (with draw() )
467 int myNumTicksDrawingCall; // call number to ticks drawing
469 // Ticks list to display on X axis
470 QMap<double, QString> myLabelX; // position, label
472 QList<double> myTicks; // positions
474 // Systems names to display under X axis
475 QMap<double, QString> myLabelDevice;
477 Plot2d_Plot2d* myPlot; // Drawing zone QwtPlot
486 /* Management of tooltips associated with markers for curves points or others points
488 class Plot2d_QwtPlotPicker : public QwtPlotPicker
491 static const double BOUND_HV_SIZE;
493 Plot2d_QwtPlotPicker( int xAxis,
495 RubberBand rubberBand,
496 DisplayMode trackerMode,
497 QwtPlotCanvas *canvas);
499 Plot2d_QwtPlotPicker( int xAxis,
501 QwtPlotCanvas *canvas);
503 virtual ~Plot2d_QwtPlotPicker();
505 QList<QwtPlotMarker*> pMarkers; // points markers
506 QMap<QwtPlotMarker*, QwtText> pMarkersToolTip; // associations (marker,tooltip)
510 virtual QwtText trackerText( const QPoint & pos ) const;