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 //-------------------------------------------
49 //! Control the value of increment in SALOME way.
51 This class controls of value of increment,
52 for pan/rotate/zoom operations in SALOME way
54 class SVTK_ControllerIncrement : public vtkObject{
56 vtkTypeMacro(SVTK_ControllerIncrement, vtkObject);
57 static SVTK_ControllerIncrement* New();
59 //! Set start value of increment
60 void SetStartValue(const int );
62 //! Get current value of increment
65 //! Increace the increment value by add 1
66 virtual int Increase();
68 //! Decreace the increment value by subtract 1
69 virtual int Decrease();
71 SVTK_ControllerIncrement();
72 virtual ~SVTK_ControllerIncrement();
76 SVTK_ControllerIncrement(const SVTK_ControllerIncrement&);//Not implemented
77 void operator=(const SVTK_ControllerIncrement&); //Not implemented
80 //-------------------------------------------
81 //! Control the behaviour of KeyDown event in SALOME way.
83 This class controls the behaviour of KeyDown event
86 class SVTK_ControllerOnKeyDown : public vtkObject{
88 vtkTypeMacro(SVTK_ControllerOnKeyDown, vtkObject);
89 static SVTK_ControllerOnKeyDown* New();
91 //! Provides the action on event
92 virtual bool OnKeyDown(vtkInteractorStyle* );
95 SVTK_ControllerOnKeyDown();
96 virtual ~SVTK_ControllerOnKeyDown();
99 SVTK_ControllerOnKeyDown(const SVTK_ControllerOnKeyDown&);//Not implemented
100 void operator=(const SVTK_ControllerOnKeyDown&); //Not implemented
102 //-------------------------------------------
110 class SVTK_GenericRenderWindowInteractor;
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
121 //! Introduce SALOME way of user interaction
123 This class defines SALOME way of user interaction for VTK viewer, as well,
124 as introduce a new selection mechanism
126 class SVTK_EXPORT SVTK_InteractorStyle: public vtkInteractorStyle
129 static SVTK_InteractorStyle *New();
130 vtkTypeMacro(SVTK_InteractorStyle, vtkInteractorStyle);
132 typedef boost::shared_ptr<SVTK_SelectionEvent> PSelectionEvent;
136 //! Generate special #SVTK_SelectionEvent
141 //! Generate special #SVTK_SelectionEvent with flipped Y coordinate
144 GetSelectionEventFlipY();
146 //! Redefined in order to add an observer (callback) for custorm event (space mouse event)
149 SetInteractor( vtkRenderWindowInteractor* );
151 //! To invoke #vtkRenderWindowInteractor::CreateTimer
156 //! To implement cached rendering
161 //! To reset reset view
166 //! To handle mouse move event
171 //! To handle left mouse button down event (reimplemented from #vtkInteractorStyle)
176 //! To handle left mouse button up event (reimplemented from #vtkInteractorStyle)
181 //! To handle middle mouse button down event (reimplemented from #vtkInteractorStyle)
184 OnMiddleButtonDown();
186 //! To handle middle mouse button up event (reimplemented from #vtkInteractorStyle)
191 //! To handle right mouse button down event (reimplemented from #vtkInteractorStyle)
196 //! To handle right mouse button up event (reimplemented from #vtkInteractorStyle)
201 //! To handle keyboard event (reimplemented from #vtkInteractorStyle)
206 //! To set current increment controller
207 void SetControllerIncrement(SVTK_ControllerIncrement*);
209 //! To get current increment controller
210 SVTK_ControllerIncrement* ControllerIncrement();
212 //! Redefine vtkInteractorStyle::OnKeyDown
213 virtual void OnKeyDown();
215 //! Provide instructions for Picking
216 void ActionPicking();
218 //! To set current OnKeyDown controller
219 void SetControllerOnKeyDown(SVTK_ControllerOnKeyDown*);
221 //! To get current OnKeyDown controller
222 SVTK_ControllerOnKeyDown* ControllerOnKeyDown();
224 SVTK_Selector* GetSelector();
227 SVTK_InteractorStyle();
228 ~SVTK_InteractorStyle();
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);
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);
251 IncrementalPan( const int incrX, const int incrY );
254 IncrementalZoom( const int incr );
257 IncrementalRotate( const int incrX, const int incrY );
259 // Main process event method (reimplemented from #vtkInteractorStyle)
262 ProcessEvents(vtkObject* object,
268 float RadianToDegree; // constant: for conv from deg to rad
274 void startGlobalPan();
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);
288 void onSpaceMouseMove( double* data );
289 virtual void onSpaceMouseButton( int button );
291 void DominantCombinedSwitch();
296 QCursor myZoomCursor;
297 QCursor myRotateCursor;
298 QCursor mySpinCursor;
299 QCursor myHandCursor;
300 QCursor myGlobalPanCursor;
307 vtkSmartPointer<SALOME_Actor> myLastHighlitedActor;
308 vtkSmartPointer<SALOME_Actor> myLastPreHighlitedActor;
310 //! "Increment" controller for pan/rotate/zoom operations
311 vtkSmartPointer<SVTK_ControllerIncrement> myControllerIncrement;
313 //!controls the behaviour of KeyDown event in SALOME way
314 vtkSmartPointer<SVTK_ControllerOnKeyDown> myControllerOnKeyDown;
316 // SpaceMouse short cuts
317 int mySMDecreaseSpeedBtn;
318 int mySMIncreaseSpeedBtn;
319 int mySMDominantCombinedSwitchBtn;
321 vtkSmartPointer<SVTK_GenericRenderWindowInteractor> myInteractor;
323 PSelectionEvent mySelectionEvent;
325 vtkSmartPointer<vtkPicker> myPicker;