Version: 8.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SVTK_RenderWindowInteractor.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 :
25 // Author :
26 
27 #ifndef SVTK_RenderWindowInteractor_h
28 #define SVTK_RenderWindowInteractor_h
29 
30 #include "SVTK.h"
31 #include "SVTK_Selection.h"
32 
33 #include <vtkSmartPointer.h>
34 #include <QWidget>
35 
36 // undefining min and max because CASCADE's defines them and
37 // it clashes with std::min(), std::max()
38 #undef min
39 #undef max
40 
41 #include <stack>
42 
44 class vtkInteractorStyle;
45 class vtkCallbackCommand;
46 class vtkRenderWindow;
47 class vtkRenderer;
48 class vtkObject;
49 
50 class SVTK_Selector;
51 class SVTK_Renderer;
52 
53 #ifdef WIN32
54 #pragma warning ( disable:4251 )
55 #endif
56 
65 {
66  Q_OBJECT;
67 
68  public:
70  const char* theName);
71 
73 
75  virtual
76  void
77  Initialize(vtkGenericRenderWindowInteractor* theDevice);
78 
80  GetDevice();
81 
82  vtkRenderWindow*
83  getRenderWindow();
84 
86  virtual
87  void
88  InvokeEvent(unsigned long theEvent, void* theCallData);
89 
91  virtual QPaintEngine* paintEngine() const;
92 
93  public slots:
95  virtual void show();
96 
98  virtual void polish();
99 
101  virtual void resize(int w, int h);
102 
103  protected:
104  virtual void paintEvent( QPaintEvent* );
105  virtual void resizeEvent( QResizeEvent* );
106 
107  virtual void mouseMoveEvent( QMouseEvent* );
108  virtual void mousePressEvent( QMouseEvent* );
109  virtual void mouseReleaseEvent( QMouseEvent* );
110  virtual void mouseDoubleClickEvent( QMouseEvent* );
111  virtual void wheelEvent( QWheelEvent* );
112  virtual void keyPressEvent( QKeyEvent* );
113  virtual void keyReleaseEvent( QKeyEvent* );
114  virtual void enterEvent( QEvent * );
115  virtual void leaveEvent( QEvent * );
116 
117  virtual void contextMenuEvent( QContextMenuEvent * e );
118 
119  // reimplemented from QWidget in order to set window - receiver
120  // of space mouse events.
121  virtual void focusInEvent( QFocusEvent* );
122  virtual void focusOutEvent( QFocusEvent* );
123 
125 // TODO (QT5 PORTING) Below is a temporary solution, to allow compiling with Qt 5
126 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
127 #if defined(WIN32)
128  virtual bool winEvent( MSG*, long* );
129 #elif !defined(__APPLE__)
130  virtual bool x11Event( XEvent *e );
131 #endif
132 #else
133  virtual bool nativeEvent( const QByteArray&, void*, long* );
134 #endif
135  vtkSmartPointer<vtkRenderWindow> myRenderWindow;
136  vtkSmartPointer<vtkGenericRenderWindowInteractor> myDevice;
137 };
138 
139 
141 
150 {
151  Q_OBJECT;
152 
153  public:
155  const char* theName);
156 
158 
160  virtual
161  void
163  SVTK_Renderer* theRenderer,
164  SVTK_Selector* theSelector);
165 
166  //----------------------------------------------------------------------------
168  SVTK_Renderer*
169  GetRenderer();
170 
172  vtkRenderer*
173  getRenderer();
174 
175  //----------------------------------------------------------------------------
178  GetInteractorStyle();
179 
181  void
182  PushInteractorStyle(vtkInteractorStyle* theStyle);
183 
185  void
186  PopInteractorStyle();
187 
188  //----------------------------------------------------------------------------
190  SVTK_Selector*
191  GetSelector();
192 
195  SelectionMode() const;
196 
198  void
199  SetSelectionMode(Selection_Mode theMode);
200 
201  public:
203  void
204  onEmitSelectionChanged();
205 
206  public:
207  signals:
208  void MouseMove( QMouseEvent* );
209  void MouseButtonPressed( QMouseEvent* );
210  void MouseButtonReleased( QMouseEvent* );
211  void MouseDoubleClicked( QMouseEvent* );
212  void ButtonPressed(const QMouseEvent *event);
213  void ButtonReleased(const QMouseEvent *event);
214  void WheelMoved( QWheelEvent* );
215  void KeyPressed( QKeyEvent* );
216  void KeyReleased( QKeyEvent* );
217  void contextMenuRequested( QContextMenuEvent *e );
218 
219  void selectionChanged();
220 
221  protected:
222  virtual void mouseMoveEvent( QMouseEvent* );
223  virtual void mousePressEvent( QMouseEvent* );
224  virtual void mouseReleaseEvent( QMouseEvent* );
225  virtual void mouseDoubleClickEvent( QMouseEvent* );
226  virtual void wheelEvent( QWheelEvent* );
227  virtual void keyPressEvent( QKeyEvent* );
228  virtual void keyReleaseEvent( QKeyEvent* );
229 
230  void
231  SetRenderer(SVTK_Renderer *theRenderer);
232 
233  void
234  SetSelector(SVTK_Selector* theSelector);
235 
236  void
237  InitInteractorStyle(vtkInteractorStyle* theStyle);
238 
239  //----------------------------------------------------------------
240  // Main process VTK event method
241  static
242  void
243  ProcessEvents(vtkObject* theObject,
244  unsigned long theEvent,
245  void* theClientData,
246  void* theCallData);
247 
248  // Used to process VTK events
249  vtkSmartPointer<vtkCallbackCommand> myEventCallbackCommand;
250 
251  // Priority at which events are processed
252  float myPriority;
253 
254  //----------------------------------------------------------------
255  vtkSmartPointer<SVTK_Selector> mySelector;
256 
257  vtkSmartPointer<SVTK_Renderer> myRenderer;
258 
259  typedef vtkSmartPointer<vtkInteractorStyle> PInteractorStyle;
260  typedef std::stack<PInteractorStyle> TInteractorStyles;
262 };
263 
264 #ifdef WIN32
265 #pragma warning ( default:4251 )
266 #endif
267 
268 #endif