1 // SALOME VTKViewer : build VTK viewer into Salome desktop
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SVTK_InteractorStyle.h
25 // Author : Christophe ATTANASIO
29 #ifndef __SVTK_InteractorStyle_h
30 #define __SVTK_InteractorStyle_h
34 #include "SVTK_SelectionEvent.h"
36 #include <boost/shared_ptr.hpp>
38 #include <vtkInteractorStyle.h>
39 #include <vtkSmartPointer.h>
46 #include <vtkObject.h>
48 //! Control the value of increment in SALOME way.
50 This class controls of value of increment,
51 for pan/rotate/zoom operations in SALOME way
53 class SVTK_ControllerIncrement : public vtkObject{
55 vtkTypeMacro(SVTK_ControllerIncrement, vtkObject);
56 static SVTK_ControllerIncrement* New();
58 //! Set start value of increment
59 void SetStartValue(const int );
61 //! Get current value of increment
64 //! Increace the increment value by add 1
65 virtual int Increase();
67 //! Decreace the increment value by subtract 1
68 virtual int Decrease();
70 SVTK_ControllerIncrement();
71 virtual ~SVTK_ControllerIncrement();
75 SVTK_ControllerIncrement(const SVTK_ControllerIncrement&);//Not implemented
76 void operator=(const SVTK_ControllerIncrement&); //Not implemented
79 //! Control the behaviour of KeyDown event in SALOME way.
81 This class controls the behaviour of KeyDown event
84 class SVTK_ControllerOnKeyDown : public vtkObject{
86 vtkTypeMacro(SVTK_ControllerOnKeyDown, vtkObject);
87 static SVTK_ControllerOnKeyDown* New();
89 //! Provides the action on event
90 virtual bool OnKeyDown(vtkInteractorStyle* );
93 SVTK_ControllerOnKeyDown();
94 virtual ~SVTK_ControllerOnKeyDown();
97 SVTK_ControllerOnKeyDown(const SVTK_ControllerOnKeyDown&);//Not implemented
98 void operator=(const SVTK_ControllerOnKeyDown&); //Not implemented
107 class SVTK_GenericRenderWindowInteractor;
109 #define VTK_INTERACTOR_STYLE_CAMERA_NONE 0
110 #define VTK_INTERACTOR_STYLE_CAMERA_ROTATE 1
111 #define VTK_INTERACTOR_STYLE_CAMERA_PAN 2
112 #define VTK_INTERACTOR_STYLE_CAMERA_ZOOM 3
113 #define VTK_INTERACTOR_STYLE_CAMERA_SPIN 4
114 #define VTK_INTERACTOR_STYLE_CAMERA_FIT 5
115 #define VTK_INTERACTOR_STYLE_CAMERA_SELECT 6
116 #define VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN 7
118 //! Introduce SALOME way of user interaction
120 This class defines SALOME way of user interaction for VTK viewer, as well,
121 as introduce a new selection mechanism
123 class SVTK_EXPORT SVTK_InteractorStyle: public vtkInteractorStyle
126 static SVTK_InteractorStyle *New();
127 vtkTypeMacro(SVTK_InteractorStyle, vtkInteractorStyle);
129 typedef boost::shared_ptr<SVTK_SelectionEvent> PSelectionEvent;
133 //! Generate special #SVTK_SelectionEvent
138 //! Generate special #SVTK_SelectionEvent with flipped Y coordinate
141 GetSelectionEventFlipY();
143 //! Redefined in order to add an observer (callback) for custom event (space mouse event)
146 SetInteractor( vtkRenderWindowInteractor* );
148 //! To invoke #vtkRenderWindowInteractor::CreateTimer
153 //! To implement cached rendering
158 //! To reset reset view
163 //! To handle mouse move event
168 //! To handle left mouse button down event (reimplemented from #vtkInteractorStyle)
173 //! To handle left mouse button up event (reimplemented from #vtkInteractorStyle)
178 //! To handle middle mouse button down event (reimplemented from #vtkInteractorStyle)
181 OnMiddleButtonDown();
183 //! To handle middle mouse button up event (reimplemented from #vtkInteractorStyle)
188 //! To handle right mouse button down event (reimplemented from #vtkInteractorStyle)
193 //! To handle right mouse button up event (reimplemented from #vtkInteractorStyle)
198 //! To handle keyboard event (reimplemented from #vtkInteractorStyle)
203 //! To set current increment controller
204 void SetControllerIncrement(SVTK_ControllerIncrement*);
206 //! To get current increment controller
207 SVTK_ControllerIncrement* ControllerIncrement();
209 //! Redefine vtkInteractorStyle::OnKeyDown
210 virtual void OnKeyDown();
212 //! Provide instructions for Picking
213 void ActionPicking();
215 //! To set current OnKeyDown controller
216 void SetControllerOnKeyDown(SVTK_ControllerOnKeyDown*);
218 //! To get current OnKeyDown controller
219 SVTK_ControllerOnKeyDown* ControllerOnKeyDown();
221 SVTK_Selector* GetSelector();
224 SVTK_InteractorStyle();
225 ~SVTK_InteractorStyle();
230 // Generic event bindings must be overridden in subclasses
231 virtual void OnMouseMove (int ctrl, int shift, int x, int y);
232 virtual void OnLeftButtonDown(int ctrl, int shift, int x, int y);
233 virtual void OnLeftButtonUp (int ctrl, int shift, int x, int y);
234 virtual void OnMiddleButtonDown(int ctrl, int shift, int x, int y);
235 virtual void OnMiddleButtonUp (int ctrl, int shift, int x, int y);
236 virtual void OnRightButtonDown(int ctrl, int shift, int x, int y);
237 virtual void OnRightButtonUp (int ctrl, int shift, int x, int y);
239 void RotateXY(int dx, int dy);
240 void PanXY(int x, int y, int oldX, int oldY);
241 void DollyXY(int dx, int dy);
242 void SpinXY(int dx, int dy, int oldX, int oldY);
243 void fitRect(const int left, const int top, const int right, const int bottom);
244 void Place(const int theX, const int theY);
245 void TranslateView(int toX, int toY, int fromX, int fromY);
248 IncrementalPan( const int incrX, const int incrY );
251 IncrementalZoom( const int incr );
254 IncrementalRotate( const int incrX, const int incrY );
256 // Main process event method (reimplemented from #vtkInteractorStyle)
259 ProcessEvents(vtkObject* object,
265 float RadianToDegree; // constant: for conv from deg to rad
271 void startGlobalPan();
278 void startOperation(int operation);
279 void onStartOperation();
280 virtual void onFinishOperation();
281 void onOperation(QPoint mousePos);
282 void onCursorMove(QPoint mousePos);
283 void setCursor(const int operation);
285 void onSpaceMouseMove( double* data );
286 virtual void onSpaceMouseButton( int button );
288 void DominantCombinedSwitch();
293 QCursor myZoomCursor;
294 QCursor myRotateCursor;
295 QCursor mySpinCursor;
296 QCursor myHandCursor;
297 QCursor myGlobalPanCursor;
304 vtkSmartPointer<SALOME_Actor> myLastHighlitedActor;
305 vtkSmartPointer<SALOME_Actor> myLastPreHighlitedActor;
307 //! "Increment" controller for pan/rotate/zoom operations
308 vtkSmartPointer<SVTK_ControllerIncrement> myControllerIncrement;
310 //!controls the behaviour of KeyDown event in SALOME way
311 vtkSmartPointer<SVTK_ControllerOnKeyDown> myControllerOnKeyDown;
313 // SpaceMouse short cuts
314 int mySMDecreaseSpeedBtn;
315 int mySMIncreaseSpeedBtn;
316 int mySMDominantCombinedSwitchBtn;
318 vtkSmartPointer<SVTK_GenericRenderWindowInteractor> myInteractor;
320 PSelectionEvent mySelectionEvent;
322 vtkSmartPointer<vtkPicker> myPicker;