]> SALOME platform Git repositories - modules/gui.git/blob - src/Plot2d/Plot2d_ViewFrame.h
Salome HOME
e2e99e9e2b6c62b84d7a6470f2a67c57fe3116ce
[modules/gui.git] / src / Plot2d / Plot2d_ViewFrame.h
1 //  Copyright (C) 2007-2008  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.
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 #ifndef PLOT2D_VIEWFRAME_H
23 #define PLOT2D_VIEWFRAME_H
24
25 #include "Plot2d_Curve.h"
26 #include <QWidget>
27 #include <QMultiHash>
28 #include <QList>
29 #include <qwt_symbol.h>
30 #include <qwt_scale_draw.h>
31
32 class Plot2d_Plot2d;
33 class Plot2d_Prs;
34 class QCustomEvent;
35 class QwtPlotCurve;
36 class QwtPlotGrid;
37 class QwtPlotZoomer;
38
39 typedef QMultiHash<QwtPlotCurve*, Plot2d_Curve*> CurveDict;
40
41 class PLOT2D_EXPORT Plot2d_ViewFrame : public QWidget
42
43   Q_OBJECT
44
45   enum { NoOpId, FitAreaId, ZoomId, PanId, GlPanId, DumpId, 
46    ModeXLinearId, ModeXLogarithmicId, ModeYLinearId, ModeYLogarithmicId,
47    LegendId, CurvePointsId, CurveLinesId, CurveSplinesId };
48 public:
49   /* Construction/destruction */
50   Plot2d_ViewFrame( QWidget* parent, const QString& title = "" );
51   virtual ~Plot2d_ViewFrame();
52
53   enum ObjectType { MainTitle, XTitle, YTitle, Y2Title, XAxis, YAxis, Y2Axis };
54
55 public:
56   QWidget* getViewWidget();
57
58   /* display */
59   void    DisplayAll();
60   void    EraseAll();
61   void    Repaint();
62
63   void    Display( const Plot2d_Prs* );
64   void    Erase( const Plot2d_Prs*, const bool = false );
65   Plot2d_Prs* CreatePrs( const char* entry = 0 );
66
67   virtual bool eventFilter(QObject* watched, QEvent* e);
68
69   /* operations */
70   void    updateTitles();
71   void    setTitle( const QString& title );
72   QString getTitle() const { return myTitle; }
73   void    displayCurve( Plot2d_Curve* curve, bool update = false );
74   void    displayCurves( const curveList& curves, bool update = false );
75   void    eraseCurve( Plot2d_Curve* curve, bool update = false );
76   void    eraseCurves( const curveList& curves, bool update = false );
77   int     getCurves( curveList& clist );
78   const   CurveDict& getCurves();
79   bool    isVisible( Plot2d_Curve* curve );
80   void    updateCurve( Plot2d_Curve* curve, bool update = false );
81   void    updateLegend( const Plot2d_Prs* prs );
82   void    fitAll();
83   void    fitArea( const QRect& area );
84   void    fitData(const int mode,
85                   const double xMin, const double xMax,
86                   const double yMin, const double yMax,
87                   const double y2Min = 0, const double y2Max = 0);
88
89   void    getFitRanges(double& xMin, double& xMax,
90                        double& yMin, double& yMax,
91                        double& y2Min, double& y2Max);
92
93   /* view parameters */
94   void    copyPreferences( Plot2d_ViewFrame* );
95   void    setCurveType( int curveType, bool update = true );
96   int     getCurveType() const { return myCurveType; }
97   void    setCurveTitle( Plot2d_Curve* curve, const QString& title );
98   void    showLegend( bool show, bool update = true );
99   void    setLegendPos( int pos );
100   int     getLegendPos() const { return myLegendPos; }
101   void    setMarkerSize( const int size, bool update = true  );
102   int     getMarkerSize() const { return myMarkerSize; }
103   void    setBackgroundColor( const QColor& color );
104   QColor  backgroundColor() const;
105   void    setXGrid( bool xMajorEnabled, const int xMajorMax,
106                     bool xMinorEnabled, const int xMinorMax, bool update = true );
107   void    setYGrid( bool yMajorEnabled, const int yMajorMax,
108                     bool yMinorEnabled, const int yMinorMax,
109                     bool y2MajorEnabled, const int y2MajorMax,
110                     bool y2MinorEnabled, const int y2MinorMax, bool update = true );
111   void    setTitle( bool enabled, const QString& title, ObjectType type, bool update = true );
112   QString getTitle( ObjectType type ) const;
113
114   void    setFont( const QFont& font, ObjectType type, bool update = true );
115   void    setHorScaleMode( const int mode, bool update = true );
116   int     getHorScaleMode() const { return myXMode; }
117   void    setVerScaleMode( const int mode, bool update = true );
118   int     getVerScaleMode() const { return myYMode; }
119
120   bool    isModeHorLinear();
121   bool    isModeVerLinear();
122   bool    isLegendShow() { return myShowLegend; };
123
124   // Protection against QwtCurve::drawLines() bug in Qwt 0.4.x: 
125   // it crashes if switched to X/Y logarithmic mode, when one or more points have
126   // non-positive X/Y coordinate
127   bool    isXLogEnabled() const;
128   bool    isYLogEnabled() const;
129
130   virtual bool print( const QString& file, const QString& format ) const;
131
132   QString getVisualParameters();
133   void    setVisualParameters( const QString& parameters );
134
135   void    incrementalPan ( const int incrX, const int incrY );
136   void    incrementalZoom( const int incrX, const int incrY );
137
138 protected:
139   int     testOperation( const QMouseEvent& );
140   void    readPreferences();
141   void    writePreferences();
142   QString getInfo( const QPoint& pnt );
143   virtual void wheelEvent( QWheelEvent* );
144   QwtPlotCurve* getPlotCurve( Plot2d_Curve* curve );
145   bool    hasPlotCurve( Plot2d_Curve* curve );
146   void    setCurveType( QwtPlotCurve* curve, int curveType );
147
148 public slots:
149   void    onViewPan(); 
150   void    onViewZoom();
151   void    onViewFitAll();
152   void    onViewFitArea();
153   void    onViewGlobalPan(); 
154   void    onSettings();
155   void    onFitData();
156   void    onChangeBackground();
157   void    onPanLeft();
158   void    onPanRight();
159   void    onPanUp();
160   void    onPanDown();
161   void    onZoomIn();
162   void    onZoomOut();
163
164 protected:
165   virtual void customEvent( QEvent* );
166   void    plotMousePressed( const QMouseEvent& );
167   bool    plotMouseMoved( const QMouseEvent& );
168   void    plotMouseReleased( const QMouseEvent& );
169
170 signals:
171   void    vpModeHorChanged();
172   void    vpModeVerChanged();
173   void    vpCurveChanged();
174   void    contextMenuRequested( QContextMenuEvent *e );
175   void    legendClicked( QwtPlotItem* );
176
177 protected:
178   Plot2d_Plot2d* myPlot;
179   int            myOperation;
180   QPoint         myPnt;
181
182   int            myCurveType;
183   bool           myShowLegend;
184   int            myLegendPos;
185   int            myMarkerSize;
186   QColor         myBackground;
187   QString        myTitle, myXTitle, myYTitle, myY2Title;
188   bool           myTitleEnabled, myXTitleEnabled, myYTitleEnabled, myY2TitleEnabled;
189   bool           myXGridMajorEnabled, myYGridMajorEnabled, myY2GridMajorEnabled;
190   bool           myXGridMinorEnabled, myYGridMinorEnabled, myY2GridMinorEnabled;
191   int            myXGridMaxMajor, myYGridMaxMajor, myY2GridMaxMajor;
192   int            myXGridMaxMinor, myYGridMaxMinor, myY2GridMaxMinor;
193   int            myXMode, myYMode;
194   double         myXDistance, myYDistance, myYDistance2;
195   bool           mySecondY;
196 };
197
198 class Plot2d_Plot2d : public QwtPlot 
199 {
200   Q_OBJECT
201 public:
202   Plot2d_Plot2d( QWidget* parent );
203
204   void       setLogScale( int axisId, bool log10 );
205
206   void       replot();
207   void       getNextMarker( QwtSymbol::Style& typeMarker, QColor& color, Qt::PenStyle& typeLine );
208   QwtLegend* getLegend() {
209 #if QWT_VERSION < 0x040200
210      return d_legend;
211 #else  
212      return legend(); /* mpv: porting to the Qwt 4.2.0 */
213 #endif
214   }
215   virtual QSize       sizeHint() const;
216   virtual QSizePolicy sizePolicy() const;
217   virtual QSize       minimumSizeHint() const;
218   void                defaultPicker();
219   void                setPickerMousePattern( int button, int state = Qt::NoButton );
220
221   bool                polished() const { return myIsPolished; }
222   QwtPlotGrid*        grid() { return myGrid; };
223   CurveDict& getCurves() { return myCurves; }
224   Plot2d_Curve*       getClosestCurve( QPoint p, double& distance, int& index );
225
226 public slots:
227   virtual void polish();
228
229 protected:
230   bool       existMarker( const QwtSymbol::Style typeMarker, const QColor& color, const Qt::PenStyle typeLine );
231
232 protected slots:
233   void onScaleDivChanged();
234
235 protected:
236   CurveDict          myCurves;
237   QwtPlotGrid*       myGrid;
238   QList<QColor>      myColors;
239   bool               myIsPolished;
240   QwtPlotZoomer*     myPlotZoomer;
241 };
242
243 class Plot2d_ScaleDraw: public QwtScaleDraw
244 {
245 public:
246   Plot2d_ScaleDraw( char f = 'g', int prec = 6 );
247   Plot2d_ScaleDraw( const QwtScaleDraw& scaleDraw, char f = 'g', int prec = 6 );
248
249   virtual QwtText label( double value ) const;
250
251   int precision() const { return myPrecision; }
252
253 private:
254   char myFormat;
255   int  myPrecision;
256 };
257
258 #endif