Salome HOME
Introduce a SALOME_IntaractiveObject attribute
[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   void setTriedron(VTKViewer_Trihedron* theTrihedron);
82   void setPreselectionProp(const double& theRed = 0, 
83                            const double& theGreen = 1,
84                            const double& theBlue = 1, 
85                            const int& theWidth = 5);
86
87   // Generic event bindings must be overridden in subclasses
88   void OnMouseMove  (int ctrl, int shift, int x, int y);
89   void OnLeftButtonDown(int ctrl, int shift, int x, int y);
90   void OnLeftButtonUp  (int ctrl, int shift, int x, int y);
91   void OnMiddleButtonDown(int ctrl, int shift, int x, int y);
92   void OnMiddleButtonUp  (int ctrl, int shift, int x, int y);
93   void OnRightButtonDown(int ctrl, int shift, int x, int y);
94   void OnRightButtonUp  (int ctrl, int shift, int x, int y);
95
96   void OnSelectionModeChanged();
97
98   void  ViewFitAll();
99
100   void                     SetFilter( const Handle(VTKViewer_Filter)& );
101   Handle(VTKViewer_Filter) GetFilter( const int );  
102   bool                     IsFilterPresent( const int );
103   void                     RemoveFilter( const int );
104   bool                     IsValid( SALOME_Actor* theActor,
105                                     const int     theId,
106                                     const bool    theIsNode = false );
107   
108   void                     IncrementalPan   ( const int incrX, const int incrY );
109   void                     IncrementalZoom  ( const int incr );
110   void                     IncrementalRotate( const int incrX, const int incrY );
111
112  protected:
113   SVTK_InteractorStyle();
114   ~SVTK_InteractorStyle();
115   SVTK_InteractorStyle(const SVTK_InteractorStyle&) {};
116   void operator=(const SVTK_InteractorStyle&) {};
117
118   SVTK_Selector* GetSelector();
119
120   void RotateXY(int dx, int dy);
121   void PanXY(int x, int y, int oldX, int oldY);
122   void DollyXY(int dx, int dy);
123   void SpinXY(int dx, int dy, int oldX, int oldY);
124   void fitRect(const int left, const int top, const int right, const int bottom);
125   void Place(const int theX, const int theY);
126   void TranslateView(int toX, int toY, int fromX, int fromY);
127   bool IsInRect(vtkActor* theActor, 
128                 const int left, const int top, 
129                 const int right, const int bottom);
130   bool IsInRect(vtkCell* theCell, 
131                 const int left, const int top, 
132                 const int right, const int bottom);
133   bool IsInRect(float* thePoint, 
134                 const int left, const int top, 
135                 const int right, const int bottom);
136
137   int State;
138   float MotionFactor;
139   float RadianToDegree;                 // constant: for conv from deg to rad
140   double myScale;
141
142   SALOME_Actor* myPreViewActor;
143
144   SVTK_Actor* myPreSelectionActor;
145   SALOME_Actor* mySelectedActor;
146   int myElemId;
147   int myEdgeId;
148   int myNodeId;
149
150  public:
151   bool eventFilter(QObject* object, QEvent* event);
152   void startZoom();
153   void startPan();
154   void startGlobalPan();
155   void startRotate();
156   void startFitArea();
157   void startSpin();
158   bool needsRedrawing();
159
160  protected:
161   void loadCursors();
162   void startOperation(int operation);
163   void onStartOperation();
164   void onFinishOperation();
165   void onOperation(QPoint mousePos);
166   void onCursorMove(QPoint mousePos);
167   void setCursor(const int operation);
168
169  protected:
170   QCursor                   myDefCursor;
171   QCursor                   myPanCursor;
172   QCursor                   myZoomCursor;
173   QCursor                   myRotateCursor;
174   QCursor                   mySpinCursor;
175   QCursor                   myHandCursor;
176   QCursor                   myGlobalPanCursor;
177   QPoint                    myPoint;
178   QPoint                    myOtherPoint;
179   bool                      myCursorState;
180   bool                      myShiftState;
181   int                       ForcedState;
182   
183   SVTK_RenderWindowInteractor* myInteractor;
184   SVTK_ViewWindow*          myViewWindow;
185   VTKViewer_Trihedron*      myTrihedron;
186   QWidget*                  myGUIWindow;
187   
188   std::map<int, Handle(VTKViewer_Filter)> myFilters;
189
190   //  members from old version
191   double                    DeltaElevation;
192   double                    DeltaAzimuth;
193   int                       LastPos[2];
194 };
195
196 #endif