Salome HOME
Copyrights update
[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 protected:
114   int     testOperation( const QMouseEvent& );
115   void    readPreferences();
116   void    writePreferences();
117   QString getInfo( const QPoint& pnt );
118   virtual void wheelEvent( QWheelEvent* );
119
120 public slots:
121   void    onViewPan(); 
122   void    onViewZoom();
123   void    onViewFitAll();
124   void    onViewFitArea();
125   void    onViewGlobalPan(); 
126   void    onSettings();
127   void    onFitData();
128   void    onChangeBackground();
129
130 protected slots:
131   void    plotMousePressed( const QMouseEvent& );
132   void    plotMouseMoved( const QMouseEvent& );
133   void    plotMouseReleased( const QMouseEvent& );
134
135 signals:
136   void    vpModeHorChanged();
137   void    vpModeVerChanged();
138   void    vpCurveChanged();
139   void    contextMenuRequested( QContextMenuEvent *e );
140
141 protected:
142   Plot2d_Plot2d* myPlot;
143   int            myOperation;
144   QPoint         myPnt;
145   CurveDict      myCurves;
146
147   int            myCurveType;
148   bool           myShowLegend;
149   int            myLegendPos;
150   int            myMarkerSize;
151   QColor         myBackground;
152   QString        myTitle, myXTitle, myYTitle, myY2Title;
153   bool           myTitleEnabled, myXTitleEnabled, myYTitleEnabled, myY2TitleEnabled;
154   bool           myXGridMajorEnabled, myYGridMajorEnabled, myY2GridMajorEnabled;
155   bool           myXGridMinorEnabled, myYGridMinorEnabled, myY2GridMinorEnabled;
156   int            myXGridMaxMajor, myYGridMaxMajor, myY2GridMaxMajor;
157   int            myXGridMaxMinor, myYGridMaxMinor, myY2GridMaxMinor;
158   int            myXMode, myYMode;
159   double         myXDistance, myYDistance, myYDistance2;
160   bool           mySecondY;
161 };
162
163 class Plot2d_Plot2d : public QwtPlot 
164 {
165 public:
166   Plot2d_Plot2d( QWidget* parent );
167
168   void       replot();
169   void       getNextMarker( QwtSymbol::Style& typeMarker, QColor& color, Qt::PenStyle& typeLine );
170   QwtLegend* getLegend() {
171 #if QWT_VERSION < 0x040200
172      return d_legend;
173 #else  
174      return legend(); /* mpv: porting to the Qwt 4.2.0 */
175 #endif
176   }
177   virtual QSize       sizeHint() const;
178   virtual QSizePolicy sizePolicy() const;
179   virtual QSize       minimumSizeHint() const;
180
181 protected:
182   bool       existMarker( const QwtSymbol::Style typeMarker, const QColor& color, const Qt::PenStyle typeLine );
183
184 protected:
185   QValueList<QColor> myColors;
186 };
187
188 #endif