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