]> SALOME platform Git repositories - modules/gui.git/blob - src/SVTK/SVTK_InteractorStyle.h
Salome HOME
7ea671df44c085df75c2b38134c0e82c65a30659
[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 "SVTK_SelectionEvent.h"
35
36 #include <boost/shared_ptr.hpp>
37
38 #include <vtkInteractorStyle.h>
39 #include <vtkSmartPointer.h>
40
41 #include <qcursor.h>
42 #include <qevent.h>
43
44 #include <map>
45
46 #include <vtkObject.h>
47 //
48 //-------------------------------------------
49 //! Control the value of increment  in SALOME way.
50 /*!
51   This class controls of value of increment,
52   for pan/rotate/zoom operations in SALOME way
53 */
54 class SVTK_ControllerIncrement : public vtkObject{
55  public:
56   vtkTypeMacro(SVTK_ControllerIncrement, vtkObject);
57   static SVTK_ControllerIncrement* New();
58
59   //! Set start value of increment
60   void SetStartValue(const int );
61
62   //! Get current value of increment
63   int Current()const;
64
65   //! Increace the increment value by add 1
66   virtual int Increase();
67
68   //! Decreace the increment value by subtract 1
69   virtual int Decrease();
70  protected:
71   SVTK_ControllerIncrement();
72   virtual ~SVTK_ControllerIncrement();
73  protected:
74   int  myIncrement;
75  private:
76   SVTK_ControllerIncrement(const SVTK_ControllerIncrement&);//Not implemented
77   void operator=(const SVTK_ControllerIncrement&);          //Not implemented
78 };
79 //
80 //-------------------------------------------
81 //! Control the behaviour of KeyDown event in SALOME way.
82 /*!
83   This class controls the behaviour of KeyDown event
84   in SALOME way
85 */
86 class SVTK_ControllerOnKeyDown : public vtkObject{
87  public:
88   vtkTypeMacro(SVTK_ControllerOnKeyDown, vtkObject);
89   static SVTK_ControllerOnKeyDown* New();
90
91   //! Provides the action on event 
92   virtual bool OnKeyDown(vtkInteractorStyle* );
93
94  protected:
95   SVTK_ControllerOnKeyDown();
96   virtual ~SVTK_ControllerOnKeyDown();
97   
98  private:
99   SVTK_ControllerOnKeyDown(const SVTK_ControllerOnKeyDown&);//Not implemented
100   void operator=(const SVTK_ControllerOnKeyDown&);          //Not implemented
101 };
102 //-------------------------------------------
103
104 class vtkCell;
105 class vtkPicker;
106
107 class SALOME_Actor;
108
109 class SVTK_Selector;
110 class SVTK_GenericRenderWindowInteractor;
111
112 #define VTK_INTERACTOR_STYLE_CAMERA_NONE    0
113 #define VTK_INTERACTOR_STYLE_CAMERA_ROTATE  1
114 #define VTK_INTERACTOR_STYLE_CAMERA_PAN     2
115 #define VTK_INTERACTOR_STYLE_CAMERA_ZOOM    3
116 #define VTK_INTERACTOR_STYLE_CAMERA_SPIN    4
117 #define VTK_INTERACTOR_STYLE_CAMERA_FIT        5
118 #define VTK_INTERACTOR_STYLE_CAMERA_SELECT     6
119 #define VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN 7
120
121 //! Introduce SALOME way of user interaction
122 /*!
123   This class defines SALOME way of user interaction for VTK viewer, as well, 
124   as introduce a new selection mechanism
125 */
126 class SVTK_EXPORT SVTK_InteractorStyle: public vtkInteractorStyle
127 {
128  public:
129   static SVTK_InteractorStyle *New();
130   vtkTypeMacro(SVTK_InteractorStyle, vtkInteractorStyle);
131
132   typedef boost::shared_ptr<SVTK_SelectionEvent> PSelectionEvent;
133
134   
135
136   //! Generate special #SVTK_SelectionEvent
137   virtual
138   SVTK_SelectionEvent*
139   GetSelectionEvent();
140
141   //! Generate special #SVTK_SelectionEvent with flipped Y coordinate
142   virtual
143   SVTK_SelectionEvent*
144   GetSelectionEventFlipY();
145
146   //! Redefined in order to add an observer (callback) for custorm event (space mouse event)
147   virtual
148   void
149   SetInteractor( vtkRenderWindowInteractor* );
150
151   //! To invoke #vtkRenderWindowInteractor::CreateTimer
152   virtual 
153   void
154   Render();
155
156   //! To implement cached rendering
157   virtual
158   void
159   OnTimer();
160
161   //! To reset reset view
162   virtual
163   void
164   OnConfigure();
165
166   //! To handle mouse move event
167   virtual 
168   void
169   OnMouseMove();
170
171   //! To handle left mouse button down event (reimplemented from #vtkInteractorStyle)
172   virtual
173   void
174   OnLeftButtonDown();
175
176   //! To handle left mouse button up event (reimplemented from #vtkInteractorStyle)
177   virtual
178   void
179   OnLeftButtonUp();
180
181   //! To handle middle mouse button down event (reimplemented from #vtkInteractorStyle)
182   virtual
183   void
184   OnMiddleButtonDown();
185
186   //! To handle middle mouse button up event (reimplemented from #vtkInteractorStyle)
187   virtual
188   void
189   OnMiddleButtonUp();
190
191   //! To handle right mouse button down event (reimplemented from #vtkInteractorStyle)
192   virtual
193   void
194   OnRightButtonDown();
195
196   //! To handle right mouse button up event (reimplemented from #vtkInteractorStyle)
197   virtual
198   void
199   OnRightButtonUp();
200
201   //! To handle keyboard event (reimplemented from #vtkInteractorStyle)
202   virtual
203   void
204   OnChar();
205
206   //! To set current increment controller 
207   void SetControllerIncrement(SVTK_ControllerIncrement*);
208
209   //! To get current increment controller 
210   SVTK_ControllerIncrement* ControllerIncrement();
211  
212   //! Redefine vtkInteractorStyle::OnKeyDown
213   virtual void OnKeyDown();
214
215   //! Provide instructions for Picking
216   void ActionPicking();
217
218   //! To set current OnKeyDown controller 
219   void SetControllerOnKeyDown(SVTK_ControllerOnKeyDown*);
220
221   //! To get current OnKeyDown controller 
222   SVTK_ControllerOnKeyDown* ControllerOnKeyDown();
223   
224   SVTK_Selector* GetSelector();
225
226  protected:
227   SVTK_InteractorStyle();
228   ~SVTK_InteractorStyle();
229
230   QWidget*
231   GetRenderWidget();
232   
233   // Generic event bindings must be overridden in subclasses
234   virtual void OnMouseMove  (int ctrl, int shift, int x, int y);
235   virtual void OnLeftButtonDown(int ctrl, int shift, int x, int y);
236   virtual void OnLeftButtonUp  (int ctrl, int shift, int x, int y);
237   virtual void OnMiddleButtonDown(int ctrl, int shift, int x, int y);
238   virtual void OnMiddleButtonUp  (int ctrl, int shift, int x, int y);
239   virtual void OnRightButtonDown(int ctrl, int shift, int x, int y);
240   virtual void OnRightButtonUp  (int ctrl, int shift, int x, int y);
241
242   void RotateXY(int dx, int dy);
243   void PanXY(int x, int y, int oldX, int oldY);
244   void DollyXY(int dx, int dy);
245   void SpinXY(int dx, int dy, int oldX, int oldY);
246   void fitRect(const int left, const int top, const int right, const int bottom);
247   void Place(const int theX, const int theY);
248   void TranslateView(int toX, int toY, int fromX, int fromY);
249
250   void
251   IncrementalPan( const int incrX, const int incrY );
252
253   void
254   IncrementalZoom( const int incr );
255
256   void
257   IncrementalRotate( const int incrX, const int incrY );
258
259   // Main process event method (reimplemented from #vtkInteractorStyle)
260   static 
261   void
262   ProcessEvents(vtkObject* object, 
263                 unsigned long event,
264                 void* clientData, 
265                 void* callData );
266
267   float MotionFactor;
268   float RadianToDegree;                 // constant: for conv from deg to rad
269   double myScale;
270
271  protected:
272   void startZoom();
273   void startPan();
274   void startGlobalPan();
275   void startRotate();
276   void startFitArea();
277   void startSpin();
278
279  protected:
280   void loadCursors();
281   void startOperation(int operation);
282   void onStartOperation();
283   virtual void onFinishOperation();
284   void onOperation(QPoint mousePos);
285   void onCursorMove(QPoint mousePos);
286   void setCursor(const int operation);
287
288   void onSpaceMouseMove( double* data );
289   virtual void onSpaceMouseButton( int button );
290
291   void DominantCombinedSwitch();
292   
293  protected:
294   QCursor                   myDefCursor;
295   QCursor                   myPanCursor;
296   QCursor                   myZoomCursor;
297   QCursor                   myRotateCursor;
298   QCursor                   mySpinCursor;
299   QCursor                   myHandCursor;
300   QCursor                   myGlobalPanCursor;
301   QPoint                    myPoint;
302   QPoint                    myOtherPoint;
303   bool                      myCursorState;
304   bool                      myShiftState;
305   int                       ForcedState;
306
307   vtkSmartPointer<SALOME_Actor> myLastHighlitedActor;
308   vtkSmartPointer<SALOME_Actor> myLastPreHighlitedActor;
309
310   //! "Increment" controller for pan/rotate/zoom operations
311   vtkSmartPointer<SVTK_ControllerIncrement> myControllerIncrement;
312
313   //!controls the behaviour of KeyDown event in SALOME way
314   vtkSmartPointer<SVTK_ControllerOnKeyDown> myControllerOnKeyDown;
315
316   // SpaceMouse short cuts
317   int                       mySMDecreaseSpeedBtn;
318   int                       mySMIncreaseSpeedBtn;
319   int                       mySMDominantCombinedSwitchBtn;
320   
321   vtkSmartPointer<SVTK_GenericRenderWindowInteractor> myInteractor;
322
323   PSelectionEvent mySelectionEvent;
324
325   vtkSmartPointer<vtkPicker> myPicker;
326 };
327
328 #endif