Version: 8.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Plot2d_ViewFrame.h
Go to the documentation of this file.
1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 
23 #ifndef PLOT2D_VIEWFRAME_H
24 #define PLOT2D_VIEWFRAME_H
25 
26 #include "Plot2d.h"
27 #include "Plot2d_Curve.h"
28 #ifndef NO_ANALYTICAL_CURVES
29 #include "Plot2d_AnalyticalCurve.h"
30 #endif
32 
33 #include <QWidget>
34 #include <QMultiHash>
35 #include <QMap>
36 #include <QList>
37 #include <QPainter>
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>
44 
45 #include <iostream>
46 #include <ostream>
47 
48 class Plot2d_Plot2d;
49 class Plot2d_Prs;
50 class Plot2d_Curve;
51 class Plot2d_Object;
52 class QCustomEvent;
53 class QwtPlotItem;
54 class QwtPlotCurve;
55 class QwtPlotGrid;
56 class QwtPlotZoomer;
59 
60 typedef QMultiHash<QwtPlotCurve*, Plot2d_Curve*> CurveDict;
61 typedef QMultiHash<QwtPlotItem*, Plot2d_Object*> ObjectDict;
62 
64 #ifndef NO_ANALYTICAL_CURVES
65  , public Plot2d_CurveContainer
66 #endif
67 {
68  Q_OBJECT
69 
70  enum { NoOpId, FitAreaId, ZoomId, PanId, GlPanId, DumpId,
71  ModeXLinearId, ModeXLogarithmicId, ModeYLinearId, ModeYLogarithmicId,
72  LegendId, CurvePointsId, CurveLinesId, CurveSplinesId };
73 public:
74  /* Construction/destruction */
75  Plot2d_ViewFrame( QWidget*, const QString& = "" );
76  virtual ~Plot2d_ViewFrame();
77 
78  void Init();
79  void SetPreference();
80 
82 
83  QWidget* getViewWidget();
84 
85  /* display */
86  virtual void DisplayAll();
87  virtual void EraseAll();
88  void Repaint();
89 
90  void Display( const Plot2d_Prs* );
91  void Erase( const Plot2d_Prs*, const bool = false );
92  Plot2d_Prs* CreatePrs( const char* = 0 );
93 
94  virtual bool eventFilter( QObject*, QEvent* );
95 
96  /* operations */
97  void updateTitles( const bool = true );
98  void setTitle( const QString& );
99  QString getTitle() const;
100 
101  QVector< QVector<QwtPlotCurve *> > displayPlot2dCurveList( const QList< QList<Plot2d_Curve*> >& sysCoCurveList,
102  bool displayLegend,
103  const QList< QList<bool> >& sides);
104 
105  QVector< QVector<QwtPlotCurve *> > displayPlot2dCurveList( const QList<Plot2d_Curve*>& curveList,
106  int groupsize,
107  bool displayLegend,
108  const QList< bool >& sides);
109 
110  Plot2d_Curve* createPlot2dCurve( QString & title,
111  QString & unit,
112  QList<double> & xList,
113  QList<double> & yList,
114  QList<QString> & tooltipList,
115  Plot2d::LineType lineKind,
116  int lineWidth,
117  QColor & lineColor,
118  QwtSymbol::Style markerKind,
119  Plot2d_QwtPlotPicker* picker,
120  bool toDraw,
121  bool displayLegend=true);
122 
123  QColor getPlot2dCurveColor( Plot2d_Curve* plot2dCurve);
124 
125  QwtPlotCurve *createSegment( double *X, double *Y, int nbPoint,
126  Qt::PenStyle lineKind,
127  int lineWidth,
128  QColor & lineColor,
129  QwtSymbol::Style markerKind,
130  bool side=false);
131 
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);
141 
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 );
152 
153  void updateLegend( const Plot2d_Prs* );
154  void updateLegend();
155  void fitAll();
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 );
160 
161  void getFitRanges( double&, double&, double&, double&,
162  double&, double&);
163 
164  void getFitRangeByCurves( double&, double&, double&, double&,
165  double&, double& );
166 
167  void getFitRangeByMarkers(double&, double&, double&, double&,
168  double&, double& );
169 
170 #ifndef NO_ANALYTICAL_CURVES
173  void updateAnalyticalCurve( Plot2d_AnalyticalCurve*, bool = false );
174  void updateAnalyticalCurves();
175  void deselectAnalyticalCurves();
176 
178  Plot2d_AnalyticalCurve* getAnalyticalCurve(QwtPlotItem *);
179 #endif
180 
181  void deselectObjects();
182 
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;
211 
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;
225 
226 
227  bool isModeHorLinear();
228  bool isModeVerLinear();
229  bool isNormLMaxMode();
230  bool isNormLMinMode();
231  bool isNormRMaxMode();
232  bool isNormRMinMode();
233 
234  bool isLegendShow() const;
235 
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 );
242 
243  virtual bool print( const QString&, const QString& ) const;
244  void printPlot( QPainter*, const QRectF& ) const;
245 
246  QString getVisualParameters();
247  void setVisualParameters( const QString& );
248 
249  void incrementalPan ( const int, const int );
250  void incrementalZoom( const int, const int );
251 
252  QwtPlotCanvas* getPlotCanvas() const;
253  Plot2d_Curve* getClosestCurve( QPoint, double&, int& ) const;
254 
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; }
259 
260  void updatePlotItem(Plot2d_Object*, QwtPlotItem*);
261 protected:
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&);
272 
273 public slots:
274  void onViewPan();
275  void onViewZoom();
276  void onViewFitAll();
277  void onViewFitArea();
278  void onViewGlobalPan();
279  void onSettings();
280 #ifndef NO_ANALYTICAL_CURVES
281  void onAnalyticalCurve();
282 #endif
283  void onFitData();
284  void onChangeBackground();
285  void onPanLeft();
286  void onPanRight();
287  void onPanUp();
288  void onPanDown();
289  void onZoomIn();
290  void onZoomOut();
291 
292 protected:
293  virtual void customEvent( QEvent* );
294  void plotMousePressed( const QMouseEvent& );
295  bool plotMouseMoved( const QMouseEvent& );
296  void plotMouseReleased( const QMouseEvent& );
297 
298 signals:
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 );
306 
307 protected:
310  QPoint myPnt;
311 
320  QColor myBackground;
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;
331  bool mySecondY;
333 #ifndef NO_ANALYTICAL_CURVES
335 #endif
339  private:
340  // List of QwtPlotCurve curves to draw (created by Plot2d_Curve::createPlotItem() )
342 
343  // List of intermittent segments to connect curves
345 
346  // List of curves Plot2d_Curve
348 };
349 
350 class Plot2d_Plot2d : public QwtPlot
351 {
352  Q_OBJECT
353 public:
355  virtual ~Plot2d_Plot2d();
356 
357  void setLogScale( int, bool );
358 
359  void replot();
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);
370  void setLegendSymbolType( const int );
371  int getLegendSymbolType();
372  QwtPlotMarker *createMarkerAndTooltip( QwtSymbol* symbol,
373  double X,
374  double Y,
375  QString & tooltip,
376  Plot2d_QwtPlotPicker *picker);
377 
378  QwtPlotGrid* grid() const;
379  QwtPlotZoomer* zoomer() const;
380 
381  virtual void updateYAxisIdentifiers();
382 
383  // Methods to deal with axes ticks
384 
385  void createAxisScaleDraw();
386  void applyTicks();
387  void unactivAxisScaleDraw( int numcall);
388 
390  double XLeftmargin, double XRightMargin,
391  const QList< QPair< QString, QMap<double,QString> > > & devicesPosLabelTicks);
392 
393  void createSeparationLine( double Xpos);
394 
395 protected:
396  QwtPlotGrid* myGrid;
400  // The point picker associated with the graphic view
402 private:
403  // List of verticals segments between two curves
406 };
407 
409 {
410 public:
411  Plot2d_ScaleDraw( char f = 'g', int prec = 6 );
412 
413  virtual QwtText label( double value ) const;
414 
415  int precision() const { return myPrecision; }
416 
417 private:
418  char myFormat;
420 };
421 
423 {
424 public:
426 
427  virtual QwtText label( double value ) const;
428 };
429 
430 /* Definition of X axis graduations
431  */
433 {
434 public:
435  static const QString DEVICE_FONT;
436  static const int DEVICE_FONT_SIZE;
437  static const int DEVICE_BY;
438 
440 
441  virtual ~Plot2d_AxisScaleDraw();
442 
443  void unactivTicksDrawing( int numcall);
444 
445  virtual void draw( QPainter * painter, const QPalette & palette) const;
446 
447  virtual QwtText label(double value) const;
448 
449  void setLabelTick(double value, QString label, bool isDevice = false);
450 
451  void setTicks(const QList<double> aTicks);
452 
453  void setInterval(double lowerBound, double upperBound);
454 
455  void applyTicks();
456 
457  double extent( const QFont &font ) const;
458 
459 protected:
460 
461  void drawLabel( QPainter* painter, double value) const;
462 
463  void drawTick( QPainter* painter, double value, int len) const;
464 
465 private:
466  bool myActivTicksDrawing; // true => activate drawing ticks (with draw() )
467  int myNumTicksDrawingCall; // call number to ticks drawing
468 
469  // Ticks list to display on X axis
470  QMap<double, QString> myLabelX; // position, label
471  //
472  QList<double> myTicks; // positions
473 
474  // Systems names to display under X axis
475  QMap<double, QString> myLabelDevice;
476 
477  Plot2d_Plot2d* myPlot; // Drawing zone QwtPlot
478 
479  double myLowerBound;
480  double myUpperBound;
481 };
482 
483 
484 
485 
486 /* Management of tooltips associated with markers for curves points or others points
487  */
489 {
490 public:
491  static const double BOUND_HV_SIZE;
492 
493  Plot2d_QwtPlotPicker( int xAxis,
494  int yAxis,
495  RubberBand rubberBand,
496  DisplayMode trackerMode,
497  QwtPlotCanvas *canvas);
498 
499  Plot2d_QwtPlotPicker( int xAxis,
500  int yAxis,
501  QwtPlotCanvas *canvas);
502 
503  virtual ~Plot2d_QwtPlotPicker();
504 
505  QList<QwtPlotMarker*> pMarkers; // points markers
506  QMap<QwtPlotMarker*, QwtText> pMarkersToolTip; // associations (marker,tooltip)
507 
508 protected:
509 
510  virtual QwtText trackerText( const QPoint & pos ) const;
511 
512 };
513 
514 #endif