]> SALOME platform Git repositories - modules/gui.git/blob - src/Plot2d/Plot2d_ViewFrame.h
Salome HOME
108cbd9573cf42cfce02593947365b170cfcc3c1
[modules/gui.git] / src / Plot2d / Plot2d_ViewFrame.h
1 // Copyright (C) 2005  OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
2 // 
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either 
6 // version 2.1 of the License.
7 // 
8 // This library is distributed in the hope that it will be useful 
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public  
14 // License along with this library; if not, write to the Free Software 
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 #ifndef PLOT2D_VIEWFRAME_H
20 #define PLOT2D_VIEWFRAME_H
21
22 #include "Plot2d_Curve.h"
23 #include <qwidget.h>
24 #include <qintdict.h>
25
26 class Plot2d_Plot2d;
27 class Plot2d_Prs;
28 class QCustomEvent;
29
30 typedef QIntDict<Plot2d_Curve> CurveDict;
31
32 class PLOT2D_EXPORT Plot2d_ViewFrame : public QWidget
33
34   Q_OBJECT
35
36   enum { NoOpId, FitAreaId, ZoomId, PanId, GlPanId, DumpId, 
37    ModeXLinearId, ModeXLogarithmicId, ModeYLinearId, ModeYLogarithmicId,
38    LegendId, CurvePointsId, CurveLinesId, CurveSplinesId };
39 public:
40   /* Construction/destruction */
41   Plot2d_ViewFrame( QWidget* parent, const QString& title = "" );
42   virtual ~Plot2d_ViewFrame();
43
44   enum ObjectType { MainTitle, XTitle, YTitle, Y2Title, XAxis, YAxis, Y2Axis };
45
46 public:
47   QWidget* getViewWidget();
48
49   /* display */
50   void    DisplayAll();
51   void    EraseAll();
52   void    Repaint();
53
54   void    Display( const Plot2d_Prs* );
55   void    Erase( const Plot2d_Prs*, const bool = false );
56   Plot2d_Prs* CreatePrs( const char* entry = 0 );
57
58   /* operations */
59   void    updateTitles();
60   void    setTitle( const QString& title );
61   QString getTitle() const { return myTitle; }
62   void    displayCurve( Plot2d_Curve* curve, bool update = false );
63   void    displayCurves( const curveList& curves, bool update = false );
64   void    eraseCurve( Plot2d_Curve* curve, bool update = false );
65   void    eraseCurves( const curveList& curves, bool update = false );
66   int     getCurves( curveList& clist );
67   const   CurveDict& getCurves() { return myCurves; }
68   int     hasCurve( Plot2d_Curve* curve );
69   bool    isVisible( Plot2d_Curve* curve );
70   void    updateCurve( Plot2d_Curve* curve, bool update = false );
71   void    updateLegend( const Plot2d_Prs* prs );
72   void    fitAll();
73   void    fitArea( const QRect& area );
74   void    fitData(const int mode,
75                   const double xMin, const double xMax,
76                   const double yMin, const double yMax,
77                   const double y2Min = 0, const double y2Max = 0);
78
79   void    getFitRanges(double& xMin, double& xMax,
80                        double& yMin, double& yMax,
81                        double& y2Min, double& y2Max);
82
83   /* view parameters */
84   void    copyPreferences( Plot2d_ViewFrame* );
85   void    setCurveType( int curveType, bool update = true );
86   int     getCurveType() const { return myCurveType; }
87   void    setCurveTitle( int curveKey, const QString& title );
88   void    showLegend( bool show, bool update = true );
89   void    setLegendPos( int pos );
90   int     getLegendPos() const { return myLegendPos; }
91   void    setMarkerSize( const int size, bool update = true  );
92   int     getMarkerSize() const { return myMarkerSize; }
93   void    setBackgroundColor( const QColor& color );
94   QColor  backgroundColor() const;
95   void    setXGrid( bool xMajorEnabled, const int xMajorMax,
96                     bool xMinorEnabled, const int xMinorMax, bool update = true );
97   void    setYGrid( bool yMajorEnabled, const int yMajorMax,
98                     bool yMinorEnabled, const int yMinorMax,
99                     bool y2MajorEnabled, const int y2MajorMax,
100                     bool y2MinorEnabled, const int y2MinorMax, bool update = true );
101   void    setTitle( bool enabled, const QString& title, ObjectType type, bool update = true );
102   QString getTitle( ObjectType type ) const;
103
104   void    setFont( const QFont& font, ObjectType type, bool update = true );
105   void    setHorScaleMode( const int mode, bool update = true );
106   int     getHorScaleMode() const { return myXMode; }
107   void    setVerScaleMode( const int mode, bool update = true );
108   int     getVerScaleMode() const { return myYMode; }
109
110   bool    isModeHorLinear();
111   bool    isModeVerLinear();
112   bool    isLegendShow() { return myShowLegend; };
113
114   // Protection against QwtCurve::drawLines() bug in Qwt 0.4.x: 
115   // it crashes if switched to X/Y logarithmic mode, when one or more points have
116   // non-positive X/Y coordinate
117   bool    isXLogEnabled() const;
118   bool    isYLogEnabled() const;
119
120   virtual bool print( const QString& file, const QString& format ) const;
121
122   QString getVisualParameters();
123   void    setVisualParameters( const QString& parameters );
124
125   void    incrementalPan ( const int incrX, const int incrY );
126   void    incrementalZoom( const int incrX, const int incrY );
127
128 protected:
129   int     testOperation( const QMouseEvent& );
130   void    readPreferences();
131   void    writePreferences();
132   QString getInfo( const QPoint& pnt );
133   virtual void wheelEvent( QWheelEvent* );
134
135 public slots:
136   void    onViewPan(); 
137   void    onViewZoom();
138   void    onViewFitAll();
139   void    onViewFitArea();
140   void    onViewGlobalPan(); 
141   void    onSettings();
142   void    onFitData();
143   void    onChangeBackground();
144
145   void    onPanLeft();
146   void    onPanRight();
147   void    onPanUp();
148   void    onPanDown();
149   void    onZoomIn();
150   void    onZoomOut();
151
152 protected:
153   virtual void customEvent( QCustomEvent* );
154
155 protected slots:
156   void    plotMousePressed( const QMouseEvent& );
157   void    plotMouseMoved( const QMouseEvent& );
158   void    plotMouseReleased( const QMouseEvent& );
159
160 signals:
161   void    vpModeHorChanged();
162   void    vpModeVerChanged();
163   void    vpCurveChanged();
164   void    contextMenuRequested( QContextMenuEvent *e );
165
166 protected:
167   Plot2d_Plot2d* myPlot;
168   int            myOperation;
169   QPoint         myPnt;
170   CurveDict      myCurves;
171
172   int            myCurveType;
173   bool           myShowLegend;
174   int            myLegendPos;
175   int            myMarkerSize;
176   QColor         myBackground;
177   QString        myTitle, myXTitle, myYTitle, myY2Title;
178   bool           myTitleEnabled, myXTitleEnabled, myYTitleEnabled, myY2TitleEnabled;
179   bool           myXGridMajorEnabled, myYGridMajorEnabled, myY2GridMajorEnabled;
180   bool           myXGridMinorEnabled, myYGridMinorEnabled, myY2GridMinorEnabled;
181   int            myXGridMaxMajor, myYGridMaxMajor, myY2GridMaxMajor;
182   int            myXGridMaxMinor, myYGridMaxMinor, myY2GridMaxMinor;
183   int            myXMode, myYMode;
184   double         myXDistance, myYDistance, myYDistance2;
185   bool           mySecondY;
186 };
187
188 class Plot2d_Plot2d : public QwtPlot 
189 {
190   Q_OBJECT
191 public:
192   Plot2d_Plot2d( QWidget* parent );
193
194   void       replot();
195   void       getNextMarker( QwtSymbol::Style& typeMarker, QColor& color, Qt::PenStyle& typeLine );
196   QwtLegend* getLegend() {
197 #if QWT_VERSION < 0x040200
198      return d_legend;
199 #else  
200      return legend(); /* mpv: porting to the Qwt 4.2.0 */
201 #endif
202   }
203   virtual QSize       sizeHint() const;
204   virtual QSizePolicy sizePolicy() const;
205   virtual QSize       minimumSizeHint() const;
206
207   bool                polished() const { return myIsPolished; }
208
209 public slots:
210   virtual void polish();
211
212 protected:
213   bool       existMarker( const QwtSymbol::Style typeMarker, const QColor& color, const Qt::PenStyle typeLine );
214
215 protected:
216   QValueList<QColor> myColors;
217   bool               myIsPolished;
218 };
219
220 #endif