Salome HOME
Merge with branch V2_2_0_VISU_improvement
[modules/gui.git] / src / SVTK / SVTK_InteractorStyle.h
1 //  SALOME VTKViewer : build VTK viewer into Salome desktop
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : SVTK_InteractorStyle.h
25 //  Author : Christophe ATTANASIO
26 //  Module : SALOME
27 //  $Header$
28
29 #ifndef __SVTK_InteractorStyle_h
30 #define __SVTK_InteractorStyle_h
31
32 #include "SVTK.h"
33
34 #include <vtkInteractorStyle.h>
35
36 class vtkCell;
37 class vtkRenderWindowInteractor;
38
39 #include <qobject.h>
40 #include <qcursor.h>
41
42 #include <map>
43
44 #include "VTKViewer_Filter.h"
45
46 class VTKViewer_Trihedron;
47
48 class SALOME_Actor;
49 class SVTK_Actor;
50 class SVTK_Viewer;
51 class SVTK_Selector;
52 class SVTK_ViewWindow;
53 class SVTK_RenderWindowInteractor;
54
55 #define VTK_INTERACTOR_STYLE_CAMERA_NONE    0
56 #define VTK_INTERACTOR_STYLE_CAMERA_ROTATE  1
57 #define VTK_INTERACTOR_STYLE_CAMERA_PAN     2
58 #define VTK_INTERACTOR_STYLE_CAMERA_ZOOM    3
59 #define VTK_INTERACTOR_STYLE_CAMERA_SPIN    4
60 #define VTK_INTERACTOR_STYLE_CAMERA_FIT        5
61 #define VTK_INTERACTOR_STYLE_CAMERA_SELECT     6
62 #define VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN 7
63
64 class SVTK_EXPORT SVTK_InteractorStyle : public QObject, 
65   public vtkInteractorStyle
66 {
67   Q_OBJECT;
68
69  public:
70   // Description:
71   // This class must be supplied with a vtkRenderWindowInteractor wrapper or
72   // parent. This class should not normally be instantiated by application
73   // programmers.
74   static SVTK_InteractorStyle *New();
75   vtkTypeMacro(SVTK_InteractorStyle, vtkInteractorStyle);
76
77   virtual void SetInteractor(vtkRenderWindowInteractor *theInteractor);
78   void setViewWindow(SVTK_ViewWindow* theViewWindow);
79   void setGUIWindow(QWidget* theWindow);
80
81   virtual int GetState();
82
83   //merge with V2_2_0_VISU_improvements:void setTriedron(VTKViewer_Trihedron* theTrihedron);
84   void setPreselectionProp(const double& theRed = 0, 
85                            const double& theGreen = 1,
86                            const double& theBlue = 1, 
87                            const int& theWidth = 5);
88
89   // Generic event bindings must be overridden in subclasses
90   void OnMouseMove  (int ctrl, int shift, int x, int y);
91   void OnLeftButtonDown(int ctrl, int shift, int x, int y);
92   void OnLeftButtonUp  (int ctrl, int shift, int x, int y);
93   void OnMiddleButtonDown(int ctrl, int shift, int x, int y);
94   void OnMiddleButtonUp  (int ctrl, int shift, int x, int y);
95   void OnRightButtonDown(int ctrl, int shift, int x, int y);
96   void OnRightButtonUp  (int ctrl, int shift, int x, int y);
97
98   void OnSelectionModeChanged();
99
100   //merge with V2_2_0_VISU_improvements:void  ViewFitAll();
101
102   void                     SetFilter( const Handle(VTKViewer_Filter)& );
103   Handle(VTKViewer_Filter) GetFilter( const int );  
104   bool                     IsFilterPresent( const int );
105   void                     RemoveFilter( const int );
106   bool                     IsValid( SALOME_Actor* theActor,
107                                     const int     theId,
108                                     const bool    theIsNode = false );
109   
110   void                     IncrementalPan   ( const int incrX, const int incrY );
111   void                     IncrementalZoom  ( const int incr );
112   void                     IncrementalRotate( const int incrX, const int incrY );
113
114  protected:
115   SVTK_InteractorStyle();
116   ~SVTK_InteractorStyle();
117   SVTK_InteractorStyle(const SVTK_InteractorStyle&) {};
118   void operator=(const SVTK_InteractorStyle&) {};
119
120   SVTK_Selector* GetSelector();
121
122   void RotateXY(int dx, int dy);
123   void PanXY(int x, int y, int oldX, int oldY);
124   void DollyXY(int dx, int dy);
125   void SpinXY(int dx, int dy, int oldX, int oldY);
126   void fitRect(const int left, const int top, const int right, const int bottom);
127   void Place(const int theX, const int theY);
128   void TranslateView(int toX, int toY, int fromX, int fromY);
129   bool IsInRect(vtkActor* theActor, 
130                 const int left, const int top, 
131                 const int right, const int bottom);
132   bool IsInRect(vtkCell* theCell, 
133                 const int left, const int top, 
134                 const int right, const int bottom);
135   bool IsInRect(float* thePoint, 
136                 const int left, const int top, 
137                 const int right, const int bottom);
138
139   float MotionFactor;
140   float RadianToDegree;                 // constant: for conv from deg to rad
141   double myScale;
142
143   SALOME_Actor* myPreViewActor;
144
145   SVTK_Actor* myPreSelectionActor;
146   SALOME_Actor* mySelectedActor;
147   int myElemId;
148   int myEdgeId;
149   int myNodeId;
150
151  public:
152   bool eventFilter(QObject* object, QEvent* event);
153   void startZoom();
154   void startPan();
155   void startGlobalPan();
156   void startRotate();
157   void startFitArea();
158   void startSpin();
159   bool needsRedrawing();
160
161  protected:
162   void loadCursors();
163   void startOperation(int operation);
164   void onStartOperation();
165   void onFinishOperation();
166   void onOperation(QPoint mousePos);
167   void onCursorMove(QPoint mousePos);
168   void setCursor(const int operation);
169
170  protected:
171   QCursor                   myDefCursor;
172   QCursor                   myPanCursor;
173   QCursor                   myZoomCursor;
174   QCursor                   myRotateCursor;
175   QCursor                   mySpinCursor;
176   QCursor                   myHandCursor;
177   QCursor                   myGlobalPanCursor;
178   QPoint                    myPoint;
179   QPoint                    myOtherPoint;
180   bool                      myCursorState;
181   bool                      myShiftState;
182   int                       ForcedState;
183   
184   SVTK_RenderWindowInteractor* myInteractor;
185   SVTK_ViewWindow*          myViewWindow;
186   //merge with V2_2_0_VISU_improvements:VTKViewer_Trihedron*      myTrihedron;
187   QWidget*                  myGUIWindow;
188   
189   std::map<int, Handle(VTKViewer_Filter)> myFilters;
190
191   //  members from old version
192   double                    DeltaElevation;
193   double                    DeltaAzimuth;
194   int                       LastPos[2];
195 };
196
197 #endif