Salome HOME
51faa089840b9f1244884e880a5cda584c5980f7
[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/
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
29 typedef QIntDict<Plot2d_Curve> CurveDict;
30
31 class PLOT2D_EXPORT Plot2d_ViewFrame : public QWidget
32
33   Q_OBJECT
34
35   enum { NoOpId, FitAreaId, ZoomId, PanId, GlPanId, DumpId, 
36    ModeXLinearId, ModeXLogarithmicId, ModeYLinearId, ModeYLogarithmicId,
37    LegendId, CurvePointsId, CurveLinesId, CurveSplinesId };
38 public:
39   /* Construction/destruction */
40   Plot2d_ViewFrame( QWidget* parent, const QString& title = "" );
41   virtual ~Plot2d_ViewFrame();
42
43   enum ObjectType { MainTitle, XTitle, YTitle, Y2Title, XAxis, YAxis, Y2Axis };
44
45 public:
46   QWidget* getViewWidget();
47
48   /* display */
49   void    DisplayAll();
50   void    EraseAll();
51   void    Repaint();
52
53   void    Display( const Plot2d_Prs* );
54   void    Erase( const Plot2d_Prs*, const bool = false );
55   Plot2d_Prs* CreatePrs( const char* entry = 0 );
56
57   /* operations */
58   void    updateTitles();
59   void    setTitle( const QString& title );
60   QString getTitle() const { return myTitle; }
61   void    displayCurve( Plot2d_Curve* curve, bool update = false );
62   void    displayCurves( const curveList& curves, bool update = false );
63   void    eraseCurve( Plot2d_Curve* curve, bool update = false );
64   void    eraseCurves( const curveList& curves, bool update = false );
65   int     getCurves( curveList& clist );
66   const   CurveDict& getCurves() { return myCurves; }
67   int     hasCurve( Plot2d_Curve* curve );
68   bool    isVisible( Plot2d_Curve* curve );
69   void    updateCurve( Plot2d_Curve* curve, bool update = false );
70   void    updateLegend( const Plot2d_Prs* prs );
71   void    fitAll();
72   void    fitArea( const QRect& area );
73   void    fitData(const int mode,
74                   const double xMin, const double xMax,
75                   const double yMin, const double yMax,
76                   const double y2Min = 0, const double y2Max = 0);
77
78   void    getFitRanges(double& xMin, double& xMax,
79                        double& yMin, double& yMax,
80                        double& y2Min, double& y2Max);
81
82   /* view parameters */
83   void    copyPreferences( Plot2d_ViewFrame* );
84   void    setCurveType( int curveType, bool update = true );
85   int     getCurveType() const { return myCurveType; }
86   void    setCurveTitle( int curveKey, const QString& title );
87   void    showLegend( bool show, bool update = true );
88   void    setLegendPos( int pos );
89   int     getLegendPos() const { return myLegendPos; }
90   void    setMarkerSize( const int size, bool update = true  );
91   int     getMarkerSize() const { return myMarkerSize; }
92   void    setBackgroundColor( const QColor& color );
93   QColor  backgroundColor() const;
94   void    setXGrid( bool xMajorEnabled, const int xMajorMax,
95                     bool xMinorEnabled, const int xMinorMax, bool update = true );
96   void    setYGrid( bool yMajorEnabled, const int yMajorMax,
97                     bool yMinorEnabled, const int yMinorMax,
98                     bool y2MajorEnabled, const int y2MajorMax,
99                     bool y2MinorEnabled, const int y2MinorMax, bool update = true );
100   void    setTitle( bool enabled, const QString& title, ObjectType type, bool update = true );
101   QString getTitle( ObjectType type ) const;
102
103   void    setFont( const QFont& font, ObjectType type, bool update = true );
104   void    setHorScaleMode( const int mode, bool update = true );
105   int     getHorScaleMode() const { return myXMode; }
106   void    setVerScaleMode( const int mode, bool update = true );
107   int     getVerScaleMode() const { return myYMode; }
108
109   bool    isModeHorLinear();
110   bool    isModeVerLinear();
111   bool    isLegendShow() { return myShowLegend; };
112
113   // Protection against QwtCurve::drawLines() bug in Qwt 0.4.x: 
114   // it crashes if switched to X/Y logarithmic mode, when one or more points have
115   // non-positive X/Y coordinate
116   bool    isXLogEnabled() const;
117   bool    isYLogEnabled() const;
118
119   virtual bool print( const QString& file, const QString& format ) const;
120
121 protected:
122   int     testOperation( const QMouseEvent& );
123   void    readPreferences();
124   void    writePreferences();
125   QString getInfo( const QPoint& pnt );
126   virtual void wheelEvent( QWheelEvent* );
127
128 public slots:
129   void    onViewPan(); 
130   void    onViewZoom();
131   void    onViewFitAll();
132   void    onViewFitArea();
133   void    onViewGlobalPan(); 
134   void    onSettings();
135   void    onFitData();
136   void    onChangeBackground();
137
138 protected slots:
139   void    plotMousePressed( const QMouseEvent& );
140   void    plotMouseMoved( const QMouseEvent& );
141   void    plotMouseReleased( const QMouseEvent& );
142
143 signals:
144   void    vpModeHorChanged();
145   void    vpModeVerChanged();
146   void    vpCurveChanged();
147   void    contextMenuRequested( QContextMenuEvent *e );
148
149 protected:
150   Plot2d_Plot2d* myPlot;
151   int            myOperation;
152   QPoint         myPnt;
153   CurveDict      myCurves;
154
155   int            myCurveType;
156   bool           myShowLegend;
157   int            myLegendPos;
158   int            myMarkerSize;
159   QColor         myBackground;
160   QString        myTitle, myXTitle, myYTitle, myY2Title;
161   bool           myTitleEnabled, myXTitleEnabled, myYTitleEnabled, myY2TitleEnabled;
162   bool           myXGridMajorEnabled, myYGridMajorEnabled, myY2GridMajorEnabled;
163   bool           myXGridMinorEnabled, myYGridMinorEnabled, myY2GridMinorEnabled;
164   int            myXGridMaxMajor, myYGridMaxMajor, myY2GridMaxMajor;
165   int            myXGridMaxMinor, myYGridMaxMinor, myY2GridMaxMinor;
166   int            myXMode, myYMode;
167   double         myXDistance, myYDistance, myYDistance2;
168   bool           mySecondY;
169 };
170
171 class Plot2d_Plot2d : public QwtPlot 
172 {
173 public:
174   Plot2d_Plot2d( QWidget* parent );
175
176   void       replot();
177   void       getNextMarker( QwtSymbol::Style& typeMarker, QColor& color, Qt::PenStyle& typeLine );
178   QwtLegend* getLegend() {
179 #if QWT_VERSION < 0x040200
180      return d_legend;
181 #else  
182      return legend(); /* mpv: porting to the Qwt 4.2.0 */
183 #endif
184   }
185   virtual QSize       sizeHint() const;
186   virtual QSizePolicy sizePolicy() const;
187   virtual QSize       minimumSizeHint() const;
188
189 protected:
190   bool       existMarker( const QwtSymbol::Style typeMarker, const QColor& color, const Qt::PenStyle typeLine );
191
192 protected:
193   QValueList<QColor> myColors;
194 };
195
196 #endif