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