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