]> SALOME platform Git repositories - modules/gui.git/blob - src/SVTK/SVTK_RenderWindowInteractor.h
Salome HOME
53aabeb2e1c211afcbf8d878ba665df037c9f54b
[modules/gui.git] / src / SVTK / SVTK_RenderWindowInteractor.h
1 //  Copyright (C) 2007-2008  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.
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 //  SALOME VTKViewer : build VTK viewer into Salome desktop
23 //  File   : 
24 //  Author : 
25 //  Module : SALOME
26 //  $Header$
27 //
28 #ifndef SVTK_RenderWindowInteractor_h
29 #define SVTK_RenderWindowInteractor_h
30
31 #include "SVTK.h"
32 #include "SVTK_Selection.h"
33
34 #include <vtkSmartPointer.h>
35 #include <QWidget>
36
37 // undefining min and max because CASCADE's defines them and
38 // it clashes with std::min(), std::max()
39 #undef min
40 #undef max
41
42 #include <stack>
43
44 class vtkGenericRenderWindowInteractor;
45 class vtkInteractorStyle;
46 class vtkCallbackCommand;
47 class vtkRenderWindow;
48 class vtkRenderer;
49 class vtkObject;
50
51 class SVTK_Selector;
52 class SVTK_Renderer;
53
54 #ifdef WIN32
55 #pragma warning ( disable:4251 )
56 #endif
57
58 /*!
59   \class QVTK_RenderWindowInteractor
60   Implements Qt based vtkRenderWindowInteractor.
61   The class inherits #QWidget class in order to be possible process Qt events.
62   It invokes corresponding VTK events through usage of its device - a #vtkGenericRenderWindowInteractor.
63   Also, it creates, initialize and holds vtkRenderWindow instance.
64 */
65 class SVTK_EXPORT QVTK_RenderWindowInteractor: public QWidget
66 {
67   Q_OBJECT;
68
69  public:
70   QVTK_RenderWindowInteractor(QWidget* theParent, 
71                               const char* theName);
72
73   ~QVTK_RenderWindowInteractor();
74
75   //! To initialize by #vtkGenericRenderWindowInteractor instance
76   virtual
77   void
78   Initialize(vtkGenericRenderWindowInteractor* theDevice);
79
80   vtkGenericRenderWindowInteractor* 
81   GetDevice();
82
83   vtkRenderWindow*
84   getRenderWindow();
85
86   //! Just to simplify usage of its device (#vtkGenericRenderWindowInteractor)
87   virtual
88   void
89   InvokeEvent(unsigned long theEvent, void* theCallData);
90
91  public slots:
92    //! Need for initial contents display on Win32
93   virtual void show();
94
95   //! To implement final initialization, just before the widget is displayed
96   virtual void polish();
97
98   //! To adjust widget and vtkRenderWindow size
99   virtual void resize(int w, int h);
100
101  protected:
102   virtual void paintEvent( QPaintEvent* );
103   virtual void resizeEvent( QResizeEvent* );
104
105   virtual void mouseMoveEvent( QMouseEvent* );
106   virtual void mousePressEvent( QMouseEvent* );
107   virtual void mouseReleaseEvent( QMouseEvent* );
108   virtual void mouseDoubleClickEvent( QMouseEvent* );
109   virtual void wheelEvent( QWheelEvent* );
110   virtual void keyPressEvent( QKeyEvent* );
111   virtual void keyReleaseEvent( QKeyEvent* );
112   virtual void enterEvent( QEvent * );
113   virtual void leaveEvent( QEvent * );
114
115   virtual void contextMenuEvent( QContextMenuEvent * e );
116
117   // reimplemented from QWidget in order to set window - receiver
118   // of space mouse events. 
119   virtual void focusInEvent( QFocusEvent* );
120   virtual void focusOutEvent( QFocusEvent* );
121
122   //! To handle native events (from such devices as SpaceMouse)
123 #ifdef WIN32
124   virtual bool winEvent( MSG*, long* );
125 #else
126   virtual bool x11Event( XEvent *e );
127 #endif
128
129   vtkSmartPointer<vtkRenderWindow> myRenderWindow;
130   vtkSmartPointer<vtkGenericRenderWindowInteractor> myDevice;
131 };
132
133
134 //! Extends QVTK_RenderWindowInteractor functionality.
135 /*!
136   \class SVTK_RenderWindowInteractor
137   Implements such features as 
138   support of selection, 
139   run-time interactor style management,
140   one render window per one renderer collaboration and
141   SUIT_ViewWindow events invocation.
142 */
143 class SVTK_EXPORT SVTK_RenderWindowInteractor: public QVTK_RenderWindowInteractor
144 {
145   Q_OBJECT;
146
147  public:
148   SVTK_RenderWindowInteractor(QWidget* theParent, 
149                               const char* theName);
150
151   ~SVTK_RenderWindowInteractor();
152
153   //! To initialize properly the class
154   virtual
155   void
156   Initialize(vtkGenericRenderWindowInteractor* theDevice,
157              SVTK_Renderer* theRenderer,
158              SVTK_Selector* theSelector);
159
160   //----------------------------------------------------------------------------
161   //! To get corresponding SVTK_Renderer instance
162   SVTK_Renderer* 
163   GetRenderer();
164
165   //! To get corresponding SVTK_Renderer device (just to simplify collobaration with SVTK_Renderer)
166   vtkRenderer* 
167   getRenderer();
168
169   //----------------------------------------------------------------------------
170   //! To get current interactor style
171   vtkInteractorStyle* 
172   GetInteractorStyle();
173
174   //! To change current interactor style by pushing the new one into the container
175   void
176   PushInteractorStyle(vtkInteractorStyle* theStyle);
177
178   //! To restore previous interactor style
179   void
180   PopInteractorStyle();
181
182   //----------------------------------------------------------------------------
183   //! To get corresponding SVTK_Selector
184   SVTK_Selector* 
185   GetSelector();
186
187   //! To get current selection mode (just to simplify collobaration with SVTK_Selector)
188   Selection_Mode 
189   SelectionMode() const;
190
191   //! To change selection mode (just to simplify collobaration with SVTK_Selector)
192   void 
193   SetSelectionMode(Selection_Mode theMode);
194
195  public:
196   //! To transform vtkCommand::EndPickEvent to Qt selectionChanged signal
197   void
198   onEmitSelectionChanged();
199
200  public:
201  signals:
202   void MouseMove( QMouseEvent* );
203   void MouseButtonPressed( QMouseEvent* );
204   void MouseButtonReleased( QMouseEvent* );
205   void MouseDoubleClicked( QMouseEvent* );
206   void ButtonPressed(const QMouseEvent *event);
207   void ButtonReleased(const QMouseEvent *event);
208   void WheelMoved( QWheelEvent* );
209   void KeyPressed( QKeyEvent* );
210   void KeyReleased( QKeyEvent* );
211   void contextMenuRequested( QContextMenuEvent *e );
212
213   void selectionChanged();
214
215  protected:
216   virtual void mouseMoveEvent( QMouseEvent* );
217   virtual void mousePressEvent( QMouseEvent* );
218   virtual void mouseReleaseEvent( QMouseEvent* );
219   virtual void mouseDoubleClickEvent( QMouseEvent* );
220   virtual void wheelEvent( QWheelEvent* );
221   virtual void keyPressEvent( QKeyEvent* );
222   virtual void keyReleaseEvent( QKeyEvent* );
223
224   void
225   SetRenderer(SVTK_Renderer *theRenderer);
226
227   void
228   SetSelector(SVTK_Selector* theSelector);
229
230   void
231   InitInteractorStyle(vtkInteractorStyle* theStyle);
232
233   //----------------------------------------------------------------
234   // Main process VTK event method
235   static
236   void
237   ProcessEvents(vtkObject* theObject, 
238                 unsigned long theEvent,
239                 void* theClientData, 
240                 void* theCallData);
241
242   // Used to process VTK events
243   vtkSmartPointer<vtkCallbackCommand> myEventCallbackCommand;
244
245   // Priority at which events are processed
246   float myPriority;
247
248   //----------------------------------------------------------------
249   vtkSmartPointer<SVTK_Selector> mySelector;
250
251   vtkSmartPointer<SVTK_Renderer> myRenderer;
252
253   typedef vtkSmartPointer<vtkInteractorStyle> PInteractorStyle;
254   typedef std::stack<PInteractorStyle> TInteractorStyles;
255   TInteractorStyles myInteractorStyles;
256 };
257
258 #ifdef WIN32
259 #pragma warning ( default:4251 )
260 #endif
261
262 #endif