Salome HOME
Moved some functionality to VTKViewer_Utilities.h
[modules/kernel.git] / src / Plot2d / Plot2d_ViewFrame.h
1 //  Copyright (C) 2003  CEA/DEN, EDF R&D
2 //
3 //
4 //
5 //  File   : Plot2d_ViewFrame.h
6 //  Author : Vadim SANDLER
7 //  Module : SALOME
8 //  $Header$
9
10 #ifndef Plot2d_ViewFrame_H
11 #define Plot2d_ViewFrame_H
12
13 #include "QAD_ViewFrame.h"
14 #include "QAD_Popup.h"
15 #include "QAD_Action.h"
16 #include "Plot2d_Curve.h"
17 #include "Plot2d_CurveContainer.h"
18 #include "SALOME_Selection.h"
19 #include <qmainwindow.h>
20 #include <qmap.h>
21 #include <qintdict.h>
22 #include <qwt_plot.h>
23 #include <qwt_legend.h>
24
25 //=================================================================================
26 // class    : Plot2d_ViewFrame
27 // purpose  : Plot2d view frame
28 //=================================================================================
29 class Plot2d_Plot2d;
30 typedef QIntDict<Plot2d_Curve> CurveDict;
31
32 class QAD_EXPORT Plot2d_ViewFrame : public QAD_ViewFrame, public QAD_PopupClientServer 
33
34   Q_OBJECT
35
36   enum { NoOpId, FitAllId, FitAreaId, ZoomId, PanId, DumpId, 
37          ModeXLinearId, ModeXLogarithmicId, ModeYLinearId, ModeYLogarithmicId,
38          LegendId, CurvePointsId, CurveLinesId, CurveSplinesId, SettingsId, FitDataId, ChangeBackgroundId };
39 public:
40   /* Construction/destruction */
41   Plot2d_ViewFrame( QWidget* parent, const QString& title = "" );
42   virtual ~Plot2d_ViewFrame();
43
44 public:
45   /* inherited */
46   ViewType          getTypeView() const { return VIEW_PLOT2D; }
47   QWidget*          getViewWidget();
48   void              SetSelectionMode( Selection_Mode mode ) {}
49   void              onAdjustTrihedron( ) {}
50
51   /* popup management */
52   void              setPopupServer( QAD_Application* );
53   void              onCreatePopup();
54
55   /*  interactive object management */
56   void              highlight( const Handle(SALOME_InteractiveObject)& IObject, 
57                                bool highlight, bool update = true ) {}
58   void              unHighlightAll() {}
59   void              rename( const Handle(SALOME_InteractiveObject)& IObject,
60                             QString newName );
61   bool              isInViewer( const Handle(SALOME_InteractiveObject)& IObject );
62   bool              isVisible( const Handle(SALOME_InteractiveObject)& IObject );
63
64   /*  undo/redo management */
65   void              undo( SALOMEDS::Study_var aStudy,
66                           const char* StudyFrameEntry ) {}
67   void              redo( SALOMEDS::Study_var aStudy,
68                           const char* StudyFrameEntry ) {}
69
70   /* interactive objects handling */
71   Handle(SALOME_InteractiveObject) FindIObject( const char* Entry );
72
73   /* display */         
74   void           Display( const Handle(SALOME_InteractiveObject)& IObject, bool update = true );
75   void           DisplayOnly( const Handle(SALOME_InteractiveObject)& IObject );
76   void           Erase( const Handle(SALOME_InteractiveObject)& IObject, bool update = true );
77   void           DisplayAll();
78   void           EraseAll();
79   void           Repaint();
80
81   /* Reimplemented from SALOME_View */
82   void          Display( const SALOME_Prs2d* );
83   void          Erase( const SALOME_Prs2d*, const bool = false );
84   SALOME_Prs*   CreatePrs( const char* entry = 0 );
85   virtual void  BeforeDisplay( SALOME_Displayer* d );
86   virtual void  AfterDisplay ( SALOME_Displayer* d );
87
88   /* event filter */
89   bool    eventFilter( QObject* o, QEvent* e );
90
91   /* operations */
92   void    setTitle( const QString& title );
93   QString getTitle() const { return myTitle; }
94   void    displayCurve( Plot2d_Curve* curve, bool update = false );
95   void    displayCurves( Plot2d_CurveContainer& curves, bool update = false );
96   void    eraseCurve( Plot2d_Curve* curve, bool update = false );
97   void    eraseCurves( Plot2d_CurveContainer& curves, bool update = false );
98   int     getCurves( QList<Plot2d_Curve>& clist );
99   int     hasCurve( Plot2d_Curve* curve );
100   Plot2d_Curve* getCurveByIO( const Handle(SALOME_InteractiveObject)& theIObject );
101   void    updateCurve( Plot2d_Curve* curve, bool update = false );
102   void    fitAll();
103   void    fitArea( const QRect& area );
104
105   /* view parameters */
106   void    setCurveType( int curveType, bool update = true );
107   int     getCurveType() const { return myCurveType; }
108   void    showLegend( bool show, bool update = true );
109   void    setLegendPos( int pos );
110   int     getLegendPos() const { return myLegendPos; }
111   void    setMarkerSize( const int size, bool update = true  );
112   int     getMarkerSize() const { return myMarkerSize; }
113   void    setBackgroundColor( const QColor& color );
114   QColor  backgroundColor() const;
115   void    setXGrid( bool xMajorEnabled, const int xMajorMax, bool xMinorEnabled, const int xMinorMax, bool update = true );
116   void    setYGrid( bool yMajorEnabled, const int yMajorMax, bool yMinorEnabled, const int yMinorMax, bool update = true );
117   void    setMainTitle( bool enabled, const QString& title,  bool update = true);
118   void    setXTitle( bool enabled, const QString& title, bool update = true );
119   QString getXTitle() const { return myXTitle; }
120   void    setYTitle( bool enabled, const QString& title, bool update = true );
121   QString getYTitle() const { return myYTitle; }
122   void    setHorScaleMode( const int mode, bool update = true );
123   int     getHorScaleMode() const { return myXMode; }
124   void    setVerScaleMode( const int mode, bool update = true );
125   int     getVerScaleMode() const { return myYMode; }
126
127   void    incrementalPan ( const int incrX, const int incrY );
128   void    incrementalZoom( const int incrX, const int incrY );
129
130 protected:
131   void    createActions();
132   int     testOperation( const QMouseEvent& );
133   void    readPreferences();
134   void    writePreferences();
135   QString getInfo( const QPoint& pnt );
136   void    updateTitles();
137
138 public slots:
139   void    onViewPan(); 
140   void    onViewZoom();
141   void    onViewFitAll();
142   void    onViewFitArea();
143   void    onViewGlobalPan(); 
144   void    onViewRotate();
145   void    onViewReset();     
146   void    onViewFront(); 
147   void    onViewBack(); 
148   void    onViewRight(); 
149   void    onViewLeft();     
150   void    onViewBottom();
151   void    onViewTop();
152   void    onViewTrihedron(); 
153   void    onHorMode();
154   void    onVerMode();
155   void    onLegend();
156   void    onCurves();
157   void    onSettings();
158   void    onFitData();
159   void    onChangeBackground();
160
161   void    onPanLeft();
162   void    onPanRight();
163   void    onPanUp();
164   void    onPanDown();
165   void    onZoomIn();
166   void    onZoomOut();
167
168 protected slots:
169   void    onLegendClicked( long key );
170   void    plotMousePressed( const QMouseEvent& );
171   void    plotMouseMoved( const QMouseEvent& );
172   void    plotMouseReleased( const QMouseEvent& );
173
174 private:
175   Plot2d_Plot2d*               myPlot;
176   ActionMap                    myActions;
177   int                          myOperation;
178   QPoint                       myPnt;
179   CurveDict                    myCurves;
180
181   int                          myCurveType;
182   bool                         myShowLegend;
183   int                          myLegendPos;
184   int                          myMarkerSize;
185   QColor                       myBackground;
186   QString                      myTitle, myXTitle, myYTitle;
187   bool                         myTitleEnabled, myXTitleEnabled, myYTitleEnabled;
188   bool                         myXGridMajorEnabled, myYGridMajorEnabled;
189   bool                         myXGridMinorEnabled, myYGridMinorEnabled;
190   int                          myXGridMaxMajor, myYGridMaxMajor;
191   int                          myXGridMaxMinor, myYGridMaxMinor;
192   int                          myXMode, myYMode;
193 };
194
195 //=================================================================================
196 // class    : Plot2d_Plot2d
197 // purpose  : Plot2d View
198 //=================================================================================
199 class Plot2d_Plot2d : public QwtPlot 
200 {
201 public:
202   Plot2d_Plot2d( QWidget* parent );
203
204   void       replot();
205   void       getNextMarker( QwtSymbol::Style& typeMarker, QColor& color, Qt::PenStyle& typeLine );
206   QwtLegend* getLegend() { return d_legend; }
207
208 protected:
209   bool       existMarker( const QwtSymbol::Style typeMarker, const QColor& color, const Qt::PenStyle typeLine );
210
211 protected:
212   QValueList<QColor> myColors;
213 };
214
215 #endif // Plot2d_ViewFrame_H
216
217
218
219