1 // Copyright (C) 2007-2024 CEA, EDF, 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, or (at your option) any later version.
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>
40 #include <QtxRubberBand.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;
129 class vtkTDxInteractorStyle;
134 class SVTK_GenericRenderWindowInteractor;
137 class QtxRectRubberBand;
139 #define VTK_INTERACTOR_STYLE_CAMERA_NONE 0
140 #define VTK_INTERACTOR_STYLE_CAMERA_ROTATE 1
141 #define VTK_INTERACTOR_STYLE_CAMERA_PAN 2
142 #define VTK_INTERACTOR_STYLE_CAMERA_ZOOM 3
143 #define VTK_INTERACTOR_STYLE_CAMERA_SPIN 4
144 #define VTK_INTERACTOR_STYLE_CAMERA_FIT 5
145 #define VTK_INTERACTOR_STYLE_CAMERA_SELECT 6
146 #define VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN 7
147 #define VTK_INTERACTOR_STYLE_CAMERA_SELECT_ROTATION_POINT 8
148 #define VTK_INTERACTOR_STYLE_CAMERA_INTERACTIVE_SELECTION 9
150 enum PolygonState { Disable, Start, InProcess, Finished, Closed, NotValid };
152 //! Introduce SALOME way of user interaction
154 This class defines SALOME way of user interaction for VTK viewer, as well,
155 as introduce a new selection mechanism
157 class SVTK_EXPORT SVTK_InteractorStyle: public vtkInteractorStyle
160 static SVTK_InteractorStyle *New();
161 vtkTypeMacro(SVTK_InteractorStyle, vtkInteractorStyle)
163 typedef boost::shared_ptr<SVTK_SelectionEvent> PSelectionEvent;
165 void SetTDxStyle(vtkTDxInteractorStyle*){}
167 //! Generate special #SVTK_SelectionEvent
168 virtual SVTK_SelectionEvent* GetSelectionEvent();
170 //! Generate special #SVTK_SelectionEvent with flipped Y coordinate
171 virtual SVTK_SelectionEvent* GetSelectionEventFlipY();
173 //! Redefined in order to add an observer (callback) for custom event (space mouse event)
174 virtual void SetInteractor( vtkRenderWindowInteractor* );
176 //! To invoke #vtkRenderWindowInteractor::CreateTimer
177 virtual void Render();
179 //! To implement cached rendering
180 virtual void OnTimer();
182 //! To reset reset view
183 virtual void OnConfigure();
185 //! To handle mouse move event
186 virtual void OnMouseMove();
188 //! To handle left mouse button down event (reimplemented from #vtkInteractorStyle)
189 virtual void OnLeftButtonDown();
191 //! To handle left mouse button up event (reimplemented from #vtkInteractorStyle)
192 virtual void OnLeftButtonUp();
194 //! To handle middle mouse button down event (reimplemented from #vtkInteractorStyle)
195 virtual void OnMiddleButtonDown();
197 //! To handle middle mouse button up event (reimplemented from #vtkInteractorStyle)
198 virtual void OnMiddleButtonUp();
200 //! To handle right mouse button down event (reimplemented from #vtkInteractorStyle)
201 virtual void OnRightButtonDown();
203 //! To handle right mouse button up event (reimplemented from #vtkInteractorStyle)
204 virtual void OnRightButtonUp();
206 //! To handle mouse wheel forward event (reimplemented from #vtkInteractorStyle)
207 virtual void OnMouseWheelForward();
209 //! To handle mouse wheel backward event (reimplemented from #vtkInteractorStyle)
210 virtual void OnMouseWheelBackward();
212 //! To handle mouse button double click event
213 virtual void OnMouseButtonDoubleClick();
215 //! To handle keyboard event (reimplemented from #vtkInteractorStyle)
216 virtual void OnChar();
218 //! To set current increment controller
219 void SetControllerIncrement(SVTK_ControllerIncrement*);
221 //! To modify current increment controller
222 void SetIncrementSpeed(const int, const int = 0);
224 //! To get current increment controller
225 SVTK_ControllerIncrement* ControllerIncrement();
227 //! Redefine vtkInteractorStyle::OnKeyDown
228 virtual void OnKeyDown();
230 //! Provide instructions for Picking
231 void ActionPicking();
233 //! To set current OnKeyDown controller
234 void SetControllerOnKeyDown(SVTK_ControllerOnKeyDown*);
236 //! To get current OnKeyDown controller
237 SVTK_ControllerOnKeyDown* ControllerOnKeyDown();
239 SVTK_Selector* GetSelector();
241 int CurrentState() const { return State; }
242 PolygonState GetPolygonState() const { return myPoligonState; }
243 void SetPolygonState( const PolygonState& thePolygonState )
244 { myPoligonState = thePolygonState; }
246 void SetAdvancedZoomingEnabled( const bool theState ) { myIsAdvancedZoomingEnabled = theState; }
247 bool IsAdvancedZoomingEnabled() const { return myIsAdvancedZoomingEnabled; }
249 //! releaze myLastHighlitedActor and myLastPreHighlitedActor
253 SVTK_InteractorStyle();
254 ~SVTK_InteractorStyle();
259 // Generic event bindings must be overridden in subclasses
260 virtual void OnMouseMove (int ctrl, int shift, int x, int y);
261 virtual void OnLeftButtonDown(int ctrl, int shift, int x, int y);
262 virtual void OnLeftButtonUp (int ctrl, int shift, int x, int y);
263 virtual void OnMiddleButtonDown(int ctrl, int shift, int x, int y);
264 virtual void OnMiddleButtonUp (int ctrl, int shift, int x, int y);
265 virtual void OnRightButtonDown(int ctrl, int shift, int x, int y);
266 virtual void OnRightButtonUp (int ctrl, int shift, int x, int y);
268 void RotateXY(int dx, int dy);
269 void PanXY(int x, int y, int oldX, int oldY);
270 void DollyXY(int dx, int dy);
271 void SpinXY(int dx, int dy, int oldX, int oldY);
272 void fitRect(const int left, const int top, const int right, const int bottom);
273 void Place(const int theX, const int theY);
274 void TranslateView(int toX, int toY, int fromX, int fromY);
277 IncrementalPan( const int incrX, const int incrY );
280 IncrementalZoom( const int incr );
283 IncrementalRotate( const int incrX, const int incrY );
286 InteractiveSelection();
288 // Main process event method (reimplemented from #vtkInteractorStyle)
291 ProcessEvents(vtkObject* object,
297 float RadianToDegree; // constant: for conv from deg to rad
303 void startGlobalPan();
308 void startPointSelection();
309 void startFocalPointSelection();
310 void startInteractiveSelection();
314 void startOperation(int operation);
315 void onStartOperation();
316 virtual void onFinishOperation();
317 void onOperation(QPoint mousePos);
318 void onCursorMove(QPoint mousePos);
319 void setCursor(const int operation);
321 void onSpaceMouseMove( double* data );
322 virtual void onSpaceMouseButton( int button );
324 void DominantCombinedSwitch();
329 void endDrawPolygon();
334 QCursor myZoomCursor;
335 QCursor myRotateCursor;
336 QCursor mySpinCursor;
337 QCursor myHandCursor;
338 QCursor myGlobalPanCursor;
345 vtkSmartPointer<SALOME_Actor> myLastHighlitedActor;
346 vtkSmartPointer<SALOME_Actor> myLastPreHighlitedActor;
348 //! "Increment" controller for pan/rotate/zoom operations
349 vtkSmartPointer<SVTK_ControllerIncrement> myControllerIncrement;
351 //!controls the behaviour of KeyDown event in SALOME way
352 vtkSmartPointer<SVTK_ControllerOnKeyDown> myControllerOnKeyDown;
354 // SpaceMouse short cuts
355 int mySMDecreaseSpeedBtn;
356 int mySMIncreaseSpeedBtn;
357 int mySMDominantCombinedSwitchBtn;
359 vtkSmartPointer<SVTK_GenericRenderWindowInteractor> myInteractor;
361 PSelectionEvent mySelectionEvent;
363 unsigned long myCurrRotationPointType;
364 unsigned long myPrevRotationPointType;
366 unsigned long myCurrFocalPointType;
367 unsigned long myPrevFocalPointType;
369 double myRotationPointX;
370 double myRotationPointY;
371 double myRotationPointZ;
373 vtkSmartPointer<SVTK_Actor> myHighlightSelectionPointActor;
374 vtkSmartPointer<vtkPointPicker> myPointPicker;
376 double myBBCenter[3];
377 double myInteractivePoint[3];
380 QtxRectRubberBand* myRectBand; //!< selection rectangle rubber band
381 QtxPolyRubberBand* myPolygonBand; //!< polygonal selection
382 QVector<QPoint> myPolygonPoints;
383 PolygonState myPoligonState;
385 bool myIsAdvancedZoomingEnabled;
389 #pragma warning ( default:4251 )