Version: 8.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SVTK_InteractorStyle.h
Go to the documentation of this file.
1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, 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:
58  vtkTypeMacro(SVTK_ControllerIncrement, vtkObject);
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:
78  SVTK_ControllerIncrement(const SVTK_ControllerIncrement&);//Not implemented
79  void operator=(const SVTK_ControllerIncrement&); //Not implemented
80 };
81 
82 //
84 
89  public:
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:
113  vtkTypeMacro(SVTK_ControllerOnKeyDown, vtkObject);
114  static SVTK_ControllerOnKeyDown* New();
115 
117  virtual bool OnKeyDown(vtkInteractorStyle* );
118 
119  protected:
121  virtual ~SVTK_ControllerOnKeyDown();
122 
123  private:
124  SVTK_ControllerOnKeyDown(const SVTK_ControllerOnKeyDown&);//Not implemented
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 
150 
152 
157 {
158  public:
159  static SVTK_InteractorStyle *New();
161 
162  typedef boost::shared_ptr<SVTK_SelectionEvent> PSelectionEvent;
163 
164  void SetTDxStyle(vtkTDxInteractorStyle*){}
165 
167  virtual SVTK_SelectionEvent* GetSelectionEvent();
168 
170  virtual SVTK_SelectionEvent* GetSelectionEventFlipY();
171 
173  virtual void SetInteractor( vtkRenderWindowInteractor* );
174 
176  virtual void Render();
177 
179  virtual void OnTimer();
180 
182  virtual void OnConfigure();
183 
185  virtual void OnMouseMove();
186 
188  virtual void OnLeftButtonDown();
189 
191  virtual void OnLeftButtonUp();
192 
194  virtual void OnMiddleButtonDown();
195 
197  virtual void OnMiddleButtonUp();
198 
200  virtual void OnRightButtonDown();
201 
203  virtual void OnRightButtonUp();
204 
206  virtual void OnMouseWheelForward();
207 
209  virtual void OnMouseWheelBackward();
210 
212  virtual void OnMouseButtonDoubleClick();
213 
215  virtual void OnChar();
216 
218  void SetControllerIncrement(SVTK_ControllerIncrement*);
219 
221  void SetIncrementSpeed(const int, const int = 0);
222 
224  SVTK_ControllerIncrement* ControllerIncrement();
225 
227  virtual void OnKeyDown();
228 
230  void ActionPicking();
231 
233  void SetControllerOnKeyDown(SVTK_ControllerOnKeyDown*);
234 
236  SVTK_ControllerOnKeyDown* ControllerOnKeyDown();
237 
238  SVTK_Selector* GetSelector();
239 
240  int CurrentState() const { return State; }
241  PolygonState GetPolygonState() const { return myPoligonState; }
242  void SetPolygonState( const PolygonState& thePolygonState )
243  { myPoligonState = thePolygonState; }
244 
245  void SetAdvancedZoomingEnabled( const bool theState ) { myIsAdvancedZoomingEnabled = theState; }
246  bool IsAdvancedZoomingEnabled() const { return myIsAdvancedZoomingEnabled; }
247 
249  void FreeActors();
250 
251  protected:
254 
255  QWidget*
256  GetRenderWidget();
257 
258  // Generic event bindings must be overridden in subclasses
259  virtual void OnMouseMove (int ctrl, int shift, int x, int y);
260  virtual void OnLeftButtonDown(int ctrl, int shift, int x, int y);
261  virtual void OnLeftButtonUp (int ctrl, int shift, int x, int y);
262  virtual void OnMiddleButtonDown(int ctrl, int shift, int x, int y);
263  virtual void OnMiddleButtonUp (int ctrl, int shift, int x, int y);
264  virtual void OnRightButtonDown(int ctrl, int shift, int x, int y);
265  virtual void OnRightButtonUp (int ctrl, int shift, int x, int y);
266 
267  void RotateXY(int dx, int dy);
268  void PanXY(int x, int y, int oldX, int oldY);
269  void DollyXY(int dx, int dy);
270  void SpinXY(int dx, int dy, int oldX, int oldY);
271  void fitRect(const int left, const int top, const int right, const int bottom);
272  void Place(const int theX, const int theY);
273  void TranslateView(int toX, int toY, int fromX, int fromY);
274 
275  void
276  IncrementalPan( const int incrX, const int incrY );
277 
278  void
279  IncrementalZoom( const int incr );
280 
281  void
282  IncrementalRotate( const int incrX, const int incrY );
283 
284  // Main process event method (reimplemented from #vtkInteractorStyle)
285  static
286  void
287  ProcessEvents(vtkObject* object,
288  unsigned long event,
289  void* clientData,
290  void* callData );
291 
293  float RadianToDegree; // constant: for conv from deg to rad
294  double myScale;
295 
296  protected:
297  void startZoom();
298  void startPan();
299  void startGlobalPan();
300  void startRotate();
301  void startFitArea();
302  void startSpin();
303 
304  void startPointSelection();
305  void startFocalPointSelection();
306 
307  protected:
308  void loadCursors();
309  void startOperation(int operation);
310  void onStartOperation();
311  virtual void onFinishOperation();
312  void onOperation(QPoint mousePos);
313  void onCursorMove(QPoint mousePos);
314  void setCursor(const int operation);
315 
316  void onSpaceMouseMove( double* data );
317  virtual void onSpaceMouseButton( int button );
318 
319  void DominantCombinedSwitch();
320 
321  void drawRect();
322  void endDrawRect();
323  void drawPolygon();
324  void endDrawPolygon();
325 
326  protected:
327  QCursor myDefCursor;
328  QCursor myPanCursor;
329  QCursor myZoomCursor;
330  QCursor myRotateCursor;
331  QCursor mySpinCursor;
332  QCursor myHandCursor;
334  QPoint myPoint;
335  QPoint myOtherPoint;
339 
340  vtkSmartPointer<SALOME_Actor> myLastHighlitedActor;
341  vtkSmartPointer<SALOME_Actor> myLastPreHighlitedActor;
342 
344  vtkSmartPointer<SVTK_ControllerIncrement> myControllerIncrement;
345 
347  vtkSmartPointer<SVTK_ControllerOnKeyDown> myControllerOnKeyDown;
348 
349  // SpaceMouse short cuts
353 
354  vtkSmartPointer<SVTK_GenericRenderWindowInteractor> myInteractor;
355 
357 
358  unsigned long myCurrRotationPointType;
359  unsigned long myPrevRotationPointType;
360 
361  unsigned long myCurrFocalPointType;
362  unsigned long myPrevFocalPointType;
363 
367 
368  vtkSmartPointer<SVTK_Actor> myHighlightSelectionPointActor;
369  vtkSmartPointer<vtkPointPicker> myPointPicker;
370 
371  double myBBCenter[3];
373 
376  QVector<QPoint> myPolygonPoints;
378 
380 };
381 
382 #ifdef WIN32
383 #pragma warning ( default:4251 )
384 #endif
385 
386 #endif