Version: 9.12.0
SVTK_InteractorStyle.h
Go to the documentation of this file.
1 // Copyright (C) 2007-2023 CEA, EDF, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 
23 // SALOME VTKViewer : build VTK viewer into Salome desktop
24 // File : SVTK_InteractorStyle.h
25 // Author : Christophe ATTANASIO
26 
27 #ifndef __SVTK_InteractorStyle_h
28 #define __SVTK_InteractorStyle_h
29 
30 #include "SVTK.h"
31 
32 #include "SVTK_SelectionEvent.h"
33 
34 #include <boost/shared_ptr.hpp>
35 
36 #include <vtkInteractorStyle.h>
37 #include <vtkSmartPointer.h>
38 
39 #include <QCursor>
40 #include <QtxRubberBand.h>
41 
42 #include <map>
43 
44 #include <vtkObject.h>
45 
46 #ifdef WIN32
47 #pragma warning ( disable:4251 )
48 #endif
49 
50 //
52 
57  public:
59  static SVTK_ControllerIncrement* New();
60 
62  void SetStartValue(const int );
63 
65  int Current()const;
66 
68  virtual int Increase();
69 
71  virtual int Decrease();
72  protected:
74  virtual ~SVTK_ControllerIncrement();
75  protected:
77  private:
79  void operator=(const SVTK_ControllerIncrement&); //Not implemented
80 };
81 
82 //
84 
89  public:
91  static SVTK_GeomControllerIncrement* New();
92 
94  virtual int Increase();
95 
97  virtual int Decrease();
98  protected:
100  virtual ~SVTK_GeomControllerIncrement();
101  private:
103  void operator=(const SVTK_GeomControllerIncrement&); //Not implemented
104 };
105 //
107 
112  public:
114  static SVTK_ControllerOnKeyDown* New();
115 
117  virtual bool OnKeyDown(vtkInteractorStyle* );
118 
119  protected:
121  virtual ~SVTK_ControllerOnKeyDown();
122 
123  private:
125  void operator=(const SVTK_ControllerOnKeyDown&); //Not implemented
126 };
127 
128 class vtkPointPicker;
129 class vtkTDxInteractorStyle;
130 
131 class SALOME_Actor;
132 
133 class SVTK_Selector;
135 class SVTK_Actor;
136 
137 class QtxRectRubberBand;
138 
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
149 
151 
153 
158 {
159  public:
162 
163  typedef boost::shared_ptr<SVTK_SelectionEvent> PSelectionEvent;
164 
165  void SetTDxStyle(vtkTDxInteractorStyle*){}
166 
168  virtual SVTK_SelectionEvent* GetSelectionEvent();
169 
171  virtual SVTK_SelectionEvent* GetSelectionEventFlipY();
172 
174  virtual void SetInteractor( vtkRenderWindowInteractor* );
175 
177  virtual void Render();
178 
180  virtual void OnTimer();
181 
183  virtual void OnConfigure();
184 
186  virtual void OnMouseMove();
187 
189  virtual void OnLeftButtonDown();
190 
192  virtual void OnLeftButtonUp();
193 
195  virtual void OnMiddleButtonDown();
196 
198  virtual void OnMiddleButtonUp();
199 
201  virtual void OnRightButtonDown();
202 
204  virtual void OnRightButtonUp();
205 
207  virtual void OnMouseWheelForward();
208 
210  virtual void OnMouseWheelBackward();
211 
213  virtual void OnMouseButtonDoubleClick();
214 
216  virtual void OnChar();
217 
219  void SetControllerIncrement(SVTK_ControllerIncrement*);
220 
222  void SetIncrementSpeed(const int, const int = 0);
223 
225  SVTK_ControllerIncrement* ControllerIncrement();
226 
228  virtual void OnKeyDown();
229 
231  void ActionPicking();
232 
234  void SetControllerOnKeyDown(SVTK_ControllerOnKeyDown*);
235 
237  SVTK_ControllerOnKeyDown* ControllerOnKeyDown();
238 
239  SVTK_Selector* GetSelector();
240 
241  int CurrentState() const { return State; }
242  PolygonState GetPolygonState() const { return myPoligonState; }
243  void SetPolygonState( const PolygonState& thePolygonState )
244  { myPoligonState = thePolygonState; }
245 
246  void SetAdvancedZoomingEnabled( const bool theState ) { myIsAdvancedZoomingEnabled = theState; }
247  bool IsAdvancedZoomingEnabled() const { return myIsAdvancedZoomingEnabled; }
248 
250  void FreeActors();
251 
252  protected:
255 
256  QWidget*
257  GetRenderWidget();
258 
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);
267 
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);
275 
276  void
277  IncrementalPan( const int incrX, const int incrY );
278 
279  void
280  IncrementalZoom( const int incr );
281 
282  void
283  IncrementalRotate( const int incrX, const int incrY );
284 
285  void
286  InteractiveSelection();
287 
288  // Main process event method (reimplemented from #vtkInteractorStyle)
289  static
290  void
291  ProcessEvents(vtkObject* object,
292  unsigned long event,
293  void* clientData,
294  void* callData );
295 
297  float RadianToDegree; // constant: for conv from deg to rad
298  double myScale;
299 
300  protected:
301  void startZoom();
302  void startPan();
303  void startGlobalPan();
304  void startRotate();
305  void startFitArea();
306  void startSpin();
307 
308  void startPointSelection();
309  void startFocalPointSelection();
310  void startInteractiveSelection();
311 
312  protected:
313  void loadCursors();
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);
320 
321  void onSpaceMouseMove( double* data );
322  virtual void onSpaceMouseButton( int button );
323 
324  void DominantCombinedSwitch();
325 
326  void drawRect();
327  void endDrawRect();
328  void drawPolygon();
329  void endDrawPolygon();
330 
331  protected:
332  QCursor myDefCursor;
333  QCursor myPanCursor;
334  QCursor myZoomCursor;
335  QCursor myRotateCursor;
336  QCursor mySpinCursor;
337  QCursor myHandCursor;
339  QPoint myPoint;
340  QPoint myOtherPoint;
344 
345  vtkSmartPointer<SALOME_Actor> myLastHighlitedActor;
346  vtkSmartPointer<SALOME_Actor> myLastPreHighlitedActor;
347 
349  vtkSmartPointer<SVTK_ControllerIncrement> myControllerIncrement;
350 
352  vtkSmartPointer<SVTK_ControllerOnKeyDown> myControllerOnKeyDown;
353 
354  // SpaceMouse short cuts
358 
359  vtkSmartPointer<SVTK_GenericRenderWindowInteractor> myInteractor;
360 
361  PSelectionEvent mySelectionEvent;
362 
363  unsigned long myCurrRotationPointType;
364  unsigned long myPrevRotationPointType;
365 
366  unsigned long myCurrFocalPointType;
367  unsigned long myPrevFocalPointType;
368 
372 
373  vtkSmartPointer<SVTK_Actor> myHighlightSelectionPointActor;
374  vtkSmartPointer<vtkPointPicker> myPointPicker;
375 
376  double myBBCenter[3];
377  double myInteractivePoint[3];
379 
382  QVector<QPoint> myPolygonPoints;
384 
386 };
387 
388 #ifdef WIN32
389 #pragma warning ( default:4251 )
390 #endif
391 
392 #endif
#define SVTK_EXPORT
Definition: SVTK.h:37
PolygonState
Definition: SVTK_InteractorStyle.h:150
@ Closed
Definition: SVTK_InteractorStyle.h:150
@ NotValid
Definition: SVTK_InteractorStyle.h:150
@ InProcess
Definition: SVTK_InteractorStyle.h:150
@ Disable
Definition: SVTK_InteractorStyle.h:150
@ Finished
Definition: SVTK_InteractorStyle.h:150
@ Start
Definition: SVTK_InteractorStyle.h:150
Definition: QtxRubberBand.h:76
Definition: QtxRubberBand.h:61
The class is a basic one for all SALOME VTK presentation.
Definition: SALOME_Actor.h:73
This class used for internal SVTK package purpose (highlight and prehighlight)
Definition: SVTK_Actor.h:47
Control the value of increment in arithmetic progression mode.
Definition: SVTK_InteractorStyle.h:56
vtkTypeMacro(SVTK_ControllerIncrement, vtkObject) static SVTK_ControllerIncrement *New()
int myIncrement
Definition: SVTK_InteractorStyle.h:76
SVTK_ControllerIncrement(const SVTK_ControllerIncrement &)
void operator=(const SVTK_ControllerIncrement &)
Control the behaviour of KeyDown event in SALOME way.
Definition: SVTK_InteractorStyle.h:111
void operator=(const SVTK_ControllerOnKeyDown &)
vtkTypeMacro(SVTK_ControllerOnKeyDown, vtkObject) static SVTK_ControllerOnKeyDown *New()
SVTK_ControllerOnKeyDown(const SVTK_ControllerOnKeyDown &)
Definition: SVTK_GenericRenderWindowInteractor.h:98
Control the value of increment in geometric progression mode.
Definition: SVTK_InteractorStyle.h:88
SVTK_GeomControllerIncrement(const SVTK_GeomControllerIncrement &)
vtkTypeMacro(SVTK_GeomControllerIncrement, SVTK_ControllerIncrement) static SVTK_GeomControllerIncrement *New()
void operator=(const SVTK_GeomControllerIncrement &)
Introduce SALOME way of user interaction.
Definition: SVTK_InteractorStyle.h:158
PolygonState GetPolygonState() const
Definition: SVTK_InteractorStyle.h:242
void SetPolygonState(const PolygonState &thePolygonState)
Definition: SVTK_InteractorStyle.h:243
unsigned long myCurrRotationPointType
Definition: SVTK_InteractorStyle.h:363
QCursor mySpinCursor
Definition: SVTK_InteractorStyle.h:336
vtkSmartPointer< SALOME_Actor > myLastHighlitedActor
Definition: SVTK_InteractorStyle.h:345
static SVTK_InteractorStyle * New()
int ForcedState
Definition: SVTK_InteractorStyle.h:343
virtual void OnMiddleButtonUp(int ctrl, int shift, int x, int y)
unsigned long myCurrFocalPointType
Definition: SVTK_InteractorStyle.h:366
QCursor myPanCursor
Definition: SVTK_InteractorStyle.h:333
void SetAdvancedZoomingEnabled(const bool theState)
Definition: SVTK_InteractorStyle.h:246
vtkSmartPointer< SVTK_ControllerIncrement > myControllerIncrement
"Increment" controller for pan/rotate/zoom operations
Definition: SVTK_InteractorStyle.h:349
QCursor myRotateCursor
Definition: SVTK_InteractorStyle.h:335
QtxRectRubberBand * myRectBand
selection rectangle rubber band
Definition: SVTK_InteractorStyle.h:380
bool IsAdvancedZoomingEnabled() const
Definition: SVTK_InteractorStyle.h:247
double myRotationPointZ
Definition: SVTK_InteractorStyle.h:371
virtual void OnLeftButtonUp(int ctrl, int shift, int x, int y)
vtkSmartPointer< SVTK_GenericRenderWindowInteractor > myInteractor
Definition: SVTK_InteractorStyle.h:359
vtkSmartPointer< SVTK_Actor > myHighlightSelectionPointActor
Definition: SVTK_InteractorStyle.h:373
vtkSmartPointer< vtkPointPicker > myPointPicker
Definition: SVTK_InteractorStyle.h:374
float MotionFactor
Definition: SVTK_InteractorStyle.h:296
int mySMDominantCombinedSwitchBtn
Definition: SVTK_InteractorStyle.h:357
QtxPolyRubberBand * myPolygonBand
polygonal selection
Definition: SVTK_InteractorStyle.h:381
unsigned long myPrevRotationPointType
Definition: SVTK_InteractorStyle.h:364
float RadianToDegree
Definition: SVTK_InteractorStyle.h:297
QVector< QPoint > myPolygonPoints
Definition: SVTK_InteractorStyle.h:382
unsigned long myPrevFocalPointType
Definition: SVTK_InteractorStyle.h:367
QCursor myGlobalPanCursor
Definition: SVTK_InteractorStyle.h:338
int mySMIncreaseSpeedBtn
Definition: SVTK_InteractorStyle.h:356
vtkTypeMacro(SVTK_InteractorStyle, vtkInteractorStyle) typedef boost void SetTDxStyle(vtkTDxInteractorStyle *)
Definition: SVTK_InteractorStyle.h:165
double myScale
Definition: SVTK_InteractorStyle.h:298
virtual void OnMouseMove(int ctrl, int shift, int x, int y)
QPoint myPoint
Definition: SVTK_InteractorStyle.h:339
virtual void OnRightButtonUp(int ctrl, int shift, int x, int y)
int mySMDecreaseSpeedBtn
Definition: SVTK_InteractorStyle.h:355
PSelectionEvent mySelectionEvent
Definition: SVTK_InteractorStyle.h:361
QCursor myZoomCursor
Definition: SVTK_InteractorStyle.h:334
vtkSmartPointer< SVTK_ControllerOnKeyDown > myControllerOnKeyDown
controls the behaviour of KeyDown event in SALOME way
Definition: SVTK_InteractorStyle.h:352
bool myBBFirstCheck
Definition: SVTK_InteractorStyle.h:378
int CurrentState() const
Definition: SVTK_InteractorStyle.h:241
bool myShiftState
Definition: SVTK_InteractorStyle.h:342
bool myIsAdvancedZoomingEnabled
Definition: SVTK_InteractorStyle.h:385
QCursor myDefCursor
Definition: SVTK_InteractorStyle.h:332
double myRotationPointY
Definition: SVTK_InteractorStyle.h:370
double myRotationPointX
Definition: SVTK_InteractorStyle.h:369
QPoint myOtherPoint
Definition: SVTK_InteractorStyle.h:340
bool myCursorState
Definition: SVTK_InteractorStyle.h:341
PolygonState myPoligonState
Definition: SVTK_InteractorStyle.h:383
vtkSmartPointer< SALOME_Actor > myLastPreHighlitedActor
Definition: SVTK_InteractorStyle.h:346
QCursor myHandCursor
Definition: SVTK_InteractorStyle.h:337
Define an abstract interface for selection in SVTK package.
Definition: SVTK_Selector.h:58
The structure is used for passing all infromation necessary for claculation of the selection.
Definition: SVTK_SelectionEvent.h:41