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.salome-platform.org/ or email : webmaster.salome@opencascade.com
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>
49 #pragma warning ( disable:4251 )
53 //! Control the value of increment in SALOME way.
55 This class controls of value of increment,
56 for pan/rotate/zoom operations in SALOME way
58 class SVTK_EXPORT SVTK_ControllerIncrement : public vtkObject{
60 vtkTypeMacro(SVTK_ControllerIncrement, vtkObject);
61 static SVTK_ControllerIncrement* New();
63 //! Set start value of increment
64 void SetStartValue(const int );
66 //! Get current value of increment
69 //! Increace the increment value by add 1
70 virtual int Increase();
72 //! Decreace the increment value by subtract 1
73 virtual int Decrease();
75 SVTK_ControllerIncrement();
76 virtual ~SVTK_ControllerIncrement();
80 SVTK_ControllerIncrement(const SVTK_ControllerIncrement&);//Not implemented
81 void operator=(const SVTK_ControllerIncrement&); //Not implemented
84 //! Control the behaviour of KeyDown event in SALOME way.
86 This class controls the behaviour of KeyDown event
89 class SVTK_EXPORT SVTK_ControllerOnKeyDown : public vtkObject{
91 vtkTypeMacro(SVTK_ControllerOnKeyDown, vtkObject);
92 static SVTK_ControllerOnKeyDown* New();
94 //! Provides the action on event
95 virtual bool OnKeyDown(vtkInteractorStyle* );
98 SVTK_ControllerOnKeyDown();
99 virtual ~SVTK_ControllerOnKeyDown();
102 SVTK_ControllerOnKeyDown(const SVTK_ControllerOnKeyDown&);//Not implemented
103 void operator=(const SVTK_ControllerOnKeyDown&); //Not implemented
107 class vtkPointPicker;
112 class SVTK_GenericRenderWindowInteractor;
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
125 //! Introduce SALOME way of user interaction
127 This class defines SALOME way of user interaction for VTK viewer, as well,
128 as introduce a new selection mechanism
130 class SVTK_EXPORT SVTK_InteractorStyle: public vtkInteractorStyle
133 static SVTK_InteractorStyle *New();
134 vtkTypeMacro(SVTK_InteractorStyle, vtkInteractorStyle);
136 typedef boost::shared_ptr<SVTK_SelectionEvent> PSelectionEvent;
140 //! Generate special #SVTK_SelectionEvent
145 //! Generate special #SVTK_SelectionEvent with flipped Y coordinate
148 GetSelectionEventFlipY();
150 //! Redefined in order to add an observer (callback) for custom event (space mouse event)
153 SetInteractor( vtkRenderWindowInteractor* );
155 //! To invoke #vtkRenderWindowInteractor::CreateTimer
160 //! To implement cached rendering
165 //! To reset reset view
170 //! To handle mouse move event
175 //! To handle left mouse button down event (reimplemented from #vtkInteractorStyle)
180 //! To handle left mouse button up event (reimplemented from #vtkInteractorStyle)
185 //! To handle middle mouse button down event (reimplemented from #vtkInteractorStyle)
188 OnMiddleButtonDown();
190 //! To handle middle mouse button up event (reimplemented from #vtkInteractorStyle)
195 //! To handle right mouse button down event (reimplemented from #vtkInteractorStyle)
200 //! To handle right mouse button up event (reimplemented from #vtkInteractorStyle)
205 //! To handle keyboard event (reimplemented from #vtkInteractorStyle)
210 //! To set current increment controller
211 void SetControllerIncrement(SVTK_ControllerIncrement*);
213 //! To get current increment controller
214 SVTK_ControllerIncrement* ControllerIncrement();
216 //! Redefine vtkInteractorStyle::OnKeyDown
217 virtual void OnKeyDown();
219 //! Provide instructions for Picking
220 void ActionPicking();
222 //! To set current OnKeyDown controller
223 void SetControllerOnKeyDown(SVTK_ControllerOnKeyDown*);
225 //! To get current OnKeyDown controller
226 SVTK_ControllerOnKeyDown* ControllerOnKeyDown();
228 SVTK_Selector* GetSelector();
231 SVTK_InteractorStyle();
232 ~SVTK_InteractorStyle();
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);
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);
255 IncrementalPan( const int incrX, const int incrY );
258 IncrementalZoom( const int incr );
261 IncrementalRotate( const int incrX, const int incrY );
263 // Main process event method (reimplemented from #vtkInteractorStyle)
266 ProcessEvents(vtkObject* object,
272 float RadianToDegree; // constant: for conv from deg to rad
278 void startGlobalPan();
283 void startPointSelection();
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);
294 void onSpaceMouseMove( double* data );
295 virtual void onSpaceMouseButton( int button );
297 void DominantCombinedSwitch();
302 QCursor myZoomCursor;
303 QCursor myRotateCursor;
304 QCursor mySpinCursor;
305 QCursor myHandCursor;
306 QCursor myGlobalPanCursor;
313 vtkSmartPointer<SALOME_Actor> myLastHighlitedActor;
314 vtkSmartPointer<SALOME_Actor> myLastPreHighlitedActor;
316 //! "Increment" controller for pan/rotate/zoom operations
317 vtkSmartPointer<SVTK_ControllerIncrement> myControllerIncrement;
319 //!controls the behaviour of KeyDown event in SALOME way
320 vtkSmartPointer<SVTK_ControllerOnKeyDown> myControllerOnKeyDown;
322 // SpaceMouse short cuts
323 int mySMDecreaseSpeedBtn;
324 int mySMIncreaseSpeedBtn;
325 int mySMDominantCombinedSwitchBtn;
327 vtkSmartPointer<SVTK_GenericRenderWindowInteractor> myInteractor;
329 PSelectionEvent mySelectionEvent;
331 unsigned long myCurrRotationPointType;
332 unsigned long myPrevRotationPointType;
334 double myRotationPointX;
335 double myRotationPointY;
336 double myRotationPointZ;
338 vtkSmartPointer<SVTK_Actor> myHighlightRotationPointActor;
339 vtkSmartPointer<vtkPointPicker> myPointPicker;
341 vtkFloatingPointType myBBCenter[3];
346 #pragma warning ( default:4251 )