1 // Copyright (C) 2007-2008 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
22 // SALOME VTKViewer : build VTK viewer into Salome desktop
23 // File : SVTK_InteractorStyle.h
24 // Author : Christophe ATTANASIO
28 #ifndef __SVTK_InteractorStyle_h
29 #define __SVTK_InteractorStyle_h
33 #include "SVTK_SelectionEvent.h"
35 #include <boost/shared_ptr.hpp>
37 #include <vtkInteractorStyle.h>
38 #include <vtkSmartPointer.h>
44 #include <vtkObject.h>
47 #pragma warning ( disable:4251 )
51 //! Control the value of increment in arithmetic progression mode.
53 This class controls of value of increment,
54 for pan/rotate/zoom operations in arithmetic progression mode
56 class SVTK_EXPORT SVTK_ControllerIncrement : public vtkObject{
58 vtkTypeMacro(SVTK_ControllerIncrement, vtkObject);
59 static SVTK_ControllerIncrement* New();
61 //! Set start value of increment
62 void SetStartValue(const int );
64 //! Get current value of increment
67 //! Increace the increment value by add 1
68 virtual int Increase();
70 //! Decreace the increment value by subtract 1
71 virtual int Decrease();
73 SVTK_ControllerIncrement();
74 virtual ~SVTK_ControllerIncrement();
78 SVTK_ControllerIncrement(const SVTK_ControllerIncrement&);//Not implemented
79 void operator=(const SVTK_ControllerIncrement&); //Not implemented
83 //! Control the value of increment in geometric progression mode.
85 This class controls of value of increment,
86 for pan/rotate/zoom operations in geometric progression mode.
88 class SVTK_EXPORT SVTK_GeomControllerIncrement : public SVTK_ControllerIncrement{
90 vtkTypeMacro(SVTK_GeomControllerIncrement, SVTK_ControllerIncrement);
91 static SVTK_GeomControllerIncrement* New();
93 //! Increace the increment value by add 1
94 virtual int Increase();
96 //! Decreace the increment value by subtract 1
97 virtual int Decrease();
99 SVTK_GeomControllerIncrement();
100 virtual ~SVTK_GeomControllerIncrement();
102 SVTK_GeomControllerIncrement(const SVTK_GeomControllerIncrement&);//Not implemented
103 void operator=(const SVTK_GeomControllerIncrement&); //Not implemented
106 //! Control the behaviour of KeyDown event in SALOME way.
108 This class controls the behaviour of KeyDown event
111 class SVTK_EXPORT SVTK_ControllerOnKeyDown : public vtkObject{
113 vtkTypeMacro(SVTK_ControllerOnKeyDown, vtkObject);
114 static SVTK_ControllerOnKeyDown* New();
116 //! Provides the action on event
117 virtual bool OnKeyDown(vtkInteractorStyle* );
120 SVTK_ControllerOnKeyDown();
121 virtual ~SVTK_ControllerOnKeyDown();
124 SVTK_ControllerOnKeyDown(const SVTK_ControllerOnKeyDown&);//Not implemented
125 void operator=(const SVTK_ControllerOnKeyDown&); //Not implemented
128 class vtkPointPicker;
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;
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 keyboard event (reimplemented from #vtkInteractorStyle)
203 virtual void OnChar();
205 //! To set current increment controller
206 void SetControllerIncrement(SVTK_ControllerIncrement*);
208 //! To modify current increment controller
209 void SetIncrementSpeed(const int, const int = 0);
211 //! To get current increment controller
212 SVTK_ControllerIncrement* ControllerIncrement();
214 //! Redefine vtkInteractorStyle::OnKeyDown
215 virtual void OnKeyDown();
217 //! Provide instructions for Picking
218 void ActionPicking();
220 //! To set current OnKeyDown controller
221 void SetControllerOnKeyDown(SVTK_ControllerOnKeyDown*);
223 //! To get current OnKeyDown controller
224 SVTK_ControllerOnKeyDown* ControllerOnKeyDown();
226 SVTK_Selector* GetSelector();
228 int CurrentState() const { return State; }
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();
284 void startFocalPointSelection();
288 void startOperation(int operation);
289 void onStartOperation();
290 virtual void onFinishOperation();
291 void onOperation(QPoint mousePos);
292 void onCursorMove(QPoint mousePos);
293 void setCursor(const int operation);
295 void onSpaceMouseMove( double* data );
296 virtual void onSpaceMouseButton( int button );
298 void DominantCombinedSwitch();
306 QCursor myZoomCursor;
307 QCursor myRotateCursor;
308 QCursor mySpinCursor;
309 QCursor myHandCursor;
310 QCursor myGlobalPanCursor;
317 vtkSmartPointer<SALOME_Actor> myLastHighlitedActor;
318 vtkSmartPointer<SALOME_Actor> myLastPreHighlitedActor;
320 //! "Increment" controller for pan/rotate/zoom operations
321 vtkSmartPointer<SVTK_ControllerIncrement> myControllerIncrement;
323 //!controls the behaviour of KeyDown event in SALOME way
324 vtkSmartPointer<SVTK_ControllerOnKeyDown> myControllerOnKeyDown;
326 // SpaceMouse short cuts
327 int mySMDecreaseSpeedBtn;
328 int mySMIncreaseSpeedBtn;
329 int mySMDominantCombinedSwitchBtn;
331 vtkSmartPointer<SVTK_GenericRenderWindowInteractor> myInteractor;
333 PSelectionEvent mySelectionEvent;
335 unsigned long myCurrRotationPointType;
336 unsigned long myPrevRotationPointType;
338 unsigned long myCurrFocalPointType;
339 unsigned long myPrevFocalPointType;
341 double myRotationPointX;
342 double myRotationPointY;
343 double myRotationPointZ;
345 vtkSmartPointer<SVTK_Actor> myHighlightSelectionPointActor;
346 vtkSmartPointer<vtkPointPicker> myPointPicker;
348 vtkFloatingPointType myBBCenter[3];
351 QRubberBand* myRectBand; //!< selection rectangle rubber band
355 #pragma warning ( default:4251 )