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