1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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
23 // SALOME VTKViewer : build VTK viewer into Salome desktop
24 // File : SVTK_InteractorStyle.h
25 // Author : Christophe ATTANASIO
27 #ifndef __SVTK_InteractorStyle_h
28 #define __SVTK_InteractorStyle_h
32 #include "SVTK_SelectionEvent.h"
34 #include <boost/shared_ptr.hpp>
36 #include <vtkInteractorStyle.h>
37 #include <vtkSmartPointer.h>
43 #include <vtkObject.h>
46 #pragma warning ( disable:4251 )
50 //! Control the value of increment in arithmetic progression mode.
52 This class controls of value of increment,
53 for pan/rotate/zoom operations in arithmetic progression mode
55 class SVTK_EXPORT SVTK_ControllerIncrement : public vtkObject{
57 vtkTypeMacro(SVTK_ControllerIncrement, vtkObject);
58 static SVTK_ControllerIncrement* New();
60 //! Set start value of increment
61 void SetStartValue(const int );
63 //! Get current value of increment
66 //! Increace the increment value by add 1
67 virtual int Increase();
69 //! Decreace the increment value by subtract 1
70 virtual int Decrease();
72 SVTK_ControllerIncrement();
73 virtual ~SVTK_ControllerIncrement();
77 SVTK_ControllerIncrement(const SVTK_ControllerIncrement&);//Not implemented
78 void operator=(const SVTK_ControllerIncrement&); //Not implemented
82 //! Control the value of increment in geometric progression mode.
84 This class controls of value of increment,
85 for pan/rotate/zoom operations in geometric progression mode.
87 class SVTK_EXPORT SVTK_GeomControllerIncrement : public SVTK_ControllerIncrement{
89 vtkTypeMacro(SVTK_GeomControllerIncrement, SVTK_ControllerIncrement);
90 static SVTK_GeomControllerIncrement* New();
92 //! Increace the increment value by add 1
93 virtual int Increase();
95 //! Decreace the increment value by subtract 1
96 virtual int Decrease();
98 SVTK_GeomControllerIncrement();
99 virtual ~SVTK_GeomControllerIncrement();
101 SVTK_GeomControllerIncrement(const SVTK_GeomControllerIncrement&);//Not implemented
102 void operator=(const SVTK_GeomControllerIncrement&); //Not implemented
105 //! Control the behaviour of KeyDown event in SALOME way.
107 This class controls the behaviour of KeyDown event
110 class SVTK_EXPORT SVTK_ControllerOnKeyDown : public vtkObject{
112 vtkTypeMacro(SVTK_ControllerOnKeyDown, vtkObject);
113 static SVTK_ControllerOnKeyDown* New();
115 //! Provides the action on event
116 virtual bool OnKeyDown(vtkInteractorStyle* );
119 SVTK_ControllerOnKeyDown();
120 virtual ~SVTK_ControllerOnKeyDown();
123 SVTK_ControllerOnKeyDown(const SVTK_ControllerOnKeyDown&);//Not implemented
124 void operator=(const SVTK_ControllerOnKeyDown&); //Not implemented
127 class vtkPointPicker;
128 class vtkTDxInteractorStyle;
133 class SVTK_GenericRenderWindowInteractor;
138 #define VTK_INTERACTOR_STYLE_CAMERA_NONE 0
139 #define VTK_INTERACTOR_STYLE_CAMERA_ROTATE 1
140 #define VTK_INTERACTOR_STYLE_CAMERA_PAN 2
141 #define VTK_INTERACTOR_STYLE_CAMERA_ZOOM 3
142 #define VTK_INTERACTOR_STYLE_CAMERA_SPIN 4
143 #define VTK_INTERACTOR_STYLE_CAMERA_FIT 5
144 #define VTK_INTERACTOR_STYLE_CAMERA_SELECT 6
145 #define VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN 7
146 #define VTK_INTERACTOR_STYLE_CAMERA_SELECT_ROTATION_POINT 8
148 //! Introduce SALOME way of user interaction
150 This class defines SALOME way of user interaction for VTK viewer, as well,
151 as introduce a new selection mechanism
153 class SVTK_EXPORT SVTK_InteractorStyle: public vtkInteractorStyle
156 static SVTK_InteractorStyle *New();
157 vtkTypeMacro(SVTK_InteractorStyle, vtkInteractorStyle);
159 typedef boost::shared_ptr<SVTK_SelectionEvent> PSelectionEvent;
161 void SetTDxStyle(vtkTDxInteractorStyle*){}
163 //! Generate special #SVTK_SelectionEvent
164 virtual SVTK_SelectionEvent* GetSelectionEvent();
166 //! Generate special #SVTK_SelectionEvent with flipped Y coordinate
167 virtual SVTK_SelectionEvent* GetSelectionEventFlipY();
169 //! Redefined in order to add an observer (callback) for custom event (space mouse event)
170 virtual void SetInteractor( vtkRenderWindowInteractor* );
172 //! To invoke #vtkRenderWindowInteractor::CreateTimer
173 virtual void Render();
175 //! To implement cached rendering
176 virtual void OnTimer();
178 //! To reset reset view
179 virtual void OnConfigure();
181 //! To handle mouse move event
182 virtual void OnMouseMove();
184 //! To handle left mouse button down event (reimplemented from #vtkInteractorStyle)
185 virtual void OnLeftButtonDown();
187 //! To handle left mouse button up event (reimplemented from #vtkInteractorStyle)
188 virtual void OnLeftButtonUp();
190 //! To handle middle mouse button down event (reimplemented from #vtkInteractorStyle)
191 virtual void OnMiddleButtonDown();
193 //! To handle middle mouse button up event (reimplemented from #vtkInteractorStyle)
194 virtual void OnMiddleButtonUp();
196 //! To handle right mouse button down event (reimplemented from #vtkInteractorStyle)
197 virtual void OnRightButtonDown();
199 //! To handle right mouse button up event (reimplemented from #vtkInteractorStyle)
200 virtual void OnRightButtonUp();
202 //! To handle mouse wheel forward event (reimplemented from #vtkInteractorStyle)
203 virtual void OnMouseWheelForward();
205 //! To handle mouse wheel backward event (reimplemented from #vtkInteractorStyle)
206 virtual void OnMouseWheelBackward();
208 //! To handle keyboard event (reimplemented from #vtkInteractorStyle)
209 virtual void OnChar();
211 //! To set current increment controller
212 void SetControllerIncrement(SVTK_ControllerIncrement*);
214 //! To modify current increment controller
215 void SetIncrementSpeed(const int, const int = 0);
217 //! To get current increment controller
218 SVTK_ControllerIncrement* ControllerIncrement();
220 //! Redefine vtkInteractorStyle::OnKeyDown
221 virtual void OnKeyDown();
223 //! Provide instructions for Picking
224 void ActionPicking();
226 //! To set current OnKeyDown controller
227 void SetControllerOnKeyDown(SVTK_ControllerOnKeyDown*);
229 //! To get current OnKeyDown controller
230 SVTK_ControllerOnKeyDown* ControllerOnKeyDown();
232 SVTK_Selector* GetSelector();
234 int CurrentState() const { return State; }
236 void SetAdvancedZoomingEnabled( const bool theState ) { myIsAdvancedZoomingEnabled = theState; }
237 bool IsAdvancedZoomingEnabled() const { return myIsAdvancedZoomingEnabled; }
240 SVTK_InteractorStyle();
241 ~SVTK_InteractorStyle();
246 // Generic event bindings must be overridden in subclasses
247 virtual void OnMouseMove (int ctrl, int shift, int x, int y);
248 virtual void OnLeftButtonDown(int ctrl, int shift, int x, int y);
249 virtual void OnLeftButtonUp (int ctrl, int shift, int x, int y);
250 virtual void OnMiddleButtonDown(int ctrl, int shift, int x, int y);
251 virtual void OnMiddleButtonUp (int ctrl, int shift, int x, int y);
252 virtual void OnRightButtonDown(int ctrl, int shift, int x, int y);
253 virtual void OnRightButtonUp (int ctrl, int shift, int x, int y);
255 void RotateXY(int dx, int dy);
256 void PanXY(int x, int y, int oldX, int oldY);
257 void DollyXY(int dx, int dy);
258 void SpinXY(int dx, int dy, int oldX, int oldY);
259 void fitRect(const int left, const int top, const int right, const int bottom);
260 void Place(const int theX, const int theY);
261 void TranslateView(int toX, int toY, int fromX, int fromY);
264 IncrementalPan( const int incrX, const int incrY );
267 IncrementalZoom( const int incr );
270 IncrementalRotate( const int incrX, const int incrY );
272 // Main process event method (reimplemented from #vtkInteractorStyle)
275 ProcessEvents(vtkObject* object,
281 float RadianToDegree; // constant: for conv from deg to rad
287 void startGlobalPan();
292 void startPointSelection();
293 void startFocalPointSelection();
297 void startOperation(int operation);
298 void onStartOperation();
299 virtual void onFinishOperation();
300 void onOperation(QPoint mousePos);
301 void onCursorMove(QPoint mousePos);
302 void setCursor(const int operation);
304 void onSpaceMouseMove( double* data );
305 virtual void onSpaceMouseButton( int button );
307 void DominantCombinedSwitch();
315 QCursor myZoomCursor;
316 QCursor myRotateCursor;
317 QCursor mySpinCursor;
318 QCursor myHandCursor;
319 QCursor myGlobalPanCursor;
326 vtkSmartPointer<SALOME_Actor> myLastHighlitedActor;
327 vtkSmartPointer<SALOME_Actor> myLastPreHighlitedActor;
329 //! "Increment" controller for pan/rotate/zoom operations
330 vtkSmartPointer<SVTK_ControllerIncrement> myControllerIncrement;
332 //!controls the behaviour of KeyDown event in SALOME way
333 vtkSmartPointer<SVTK_ControllerOnKeyDown> myControllerOnKeyDown;
335 // SpaceMouse short cuts
336 int mySMDecreaseSpeedBtn;
337 int mySMIncreaseSpeedBtn;
338 int mySMDominantCombinedSwitchBtn;
340 vtkSmartPointer<SVTK_GenericRenderWindowInteractor> myInteractor;
342 PSelectionEvent mySelectionEvent;
344 unsigned long myCurrRotationPointType;
345 unsigned long myPrevRotationPointType;
347 unsigned long myCurrFocalPointType;
348 unsigned long myPrevFocalPointType;
350 double myRotationPointX;
351 double myRotationPointY;
352 double myRotationPointZ;
354 vtkSmartPointer<SVTK_Actor> myHighlightSelectionPointActor;
355 vtkSmartPointer<vtkPointPicker> myPointPicker;
357 vtkFloatingPointType myBBCenter[3];
360 QRubberBand* myRectBand; //!< selection rectangle rubber band
362 bool myIsAdvancedZoomingEnabled;
366 #pragma warning ( default:4251 )