1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // SALOME VTKViewer : build VTK viewer into Salome desktop
28 #ifndef SVTK_RenderWindowInteractor_h
29 #define SVTK_RenderWindowInteractor_h
32 #include "SVTK_Selection.h"
34 #include <vtkSmartPointer.h>
37 // undefining min and max because CASCADE's defines them and
38 // it clashes with std::min(), std::max()
44 class vtkGenericRenderWindowInteractor;
45 class vtkInteractorStyle;
46 class vtkCallbackCommand;
47 class vtkRenderWindow;
55 #pragma warning ( disable:4251 )
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.
65 class SVTK_EXPORT QVTK_RenderWindowInteractor: public QWidget
70 QVTK_RenderWindowInteractor(QWidget* theParent,
73 ~QVTK_RenderWindowInteractor();
75 //! To initialize by #vtkGenericRenderWindowInteractor instance
78 Initialize(vtkGenericRenderWindowInteractor* theDevice);
80 vtkGenericRenderWindowInteractor*
86 //! Just to simplify usage of its device (#vtkGenericRenderWindowInteractor)
89 InvokeEvent(unsigned long theEvent, void* theCallData);
92 //! Need for initial contents display on Win32
95 //! To implement final initialization, just before the widget is displayed
96 virtual void polish();
98 //! To adjust widget and vtkRenderWindow size
99 virtual void resize(int w, int h);
102 virtual void paintEvent( QPaintEvent* );
103 virtual void resizeEvent( QResizeEvent* );
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 * );
115 virtual void contextMenuEvent( QContextMenuEvent * e );
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* );
122 //! To handle native events (from such devices as SpaceMouse)
124 virtual bool winEvent( MSG*, long* );
126 virtual bool x11Event( XEvent *e );
129 vtkSmartPointer<vtkRenderWindow> myRenderWindow;
130 vtkSmartPointer<vtkGenericRenderWindowInteractor> myDevice;
134 //! Extends QVTK_RenderWindowInteractor functionality.
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.
143 class SVTK_EXPORT SVTK_RenderWindowInteractor: public QVTK_RenderWindowInteractor
148 SVTK_RenderWindowInteractor(QWidget* theParent,
149 const char* theName);
151 ~SVTK_RenderWindowInteractor();
153 //! To initialize properly the class
156 Initialize(vtkGenericRenderWindowInteractor* theDevice,
157 SVTK_Renderer* theRenderer,
158 SVTK_Selector* theSelector);
160 //----------------------------------------------------------------------------
161 //! To get corresponding SVTK_Renderer instance
165 //! To get corresponding SVTK_Renderer device (just to simplify collobaration with SVTK_Renderer)
169 //----------------------------------------------------------------------------
170 //! To get current interactor style
172 GetInteractorStyle();
174 //! To change current interactor style by pushing the new one into the container
176 PushInteractorStyle(vtkInteractorStyle* theStyle);
178 //! To restore previous interactor style
180 PopInteractorStyle();
182 //----------------------------------------------------------------------------
183 //! To get corresponding SVTK_Selector
187 //! To get current selection mode (just to simplify collobaration with SVTK_Selector)
189 SelectionMode() const;
191 //! To change selection mode (just to simplify collobaration with SVTK_Selector)
193 SetSelectionMode(Selection_Mode theMode);
196 //! To transform vtkCommand::EndPickEvent to Qt selectionChanged signal
198 onEmitSelectionChanged();
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 );
213 void selectionChanged();
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* );
225 SetRenderer(SVTK_Renderer *theRenderer);
228 SetSelector(SVTK_Selector* theSelector);
231 InitInteractorStyle(vtkInteractorStyle* theStyle);
233 //----------------------------------------------------------------
234 // Main process VTK event method
237 ProcessEvents(vtkObject* theObject,
238 unsigned long theEvent,
242 // Used to process VTK events
243 vtkSmartPointer<vtkCallbackCommand> myEventCallbackCommand;
245 // Priority at which events are processed
248 //----------------------------------------------------------------
249 vtkSmartPointer<SVTK_Selector> mySelector;
251 vtkSmartPointer<SVTK_Renderer> myRenderer;
253 typedef vtkSmartPointer<vtkInteractorStyle> PInteractorStyle;
254 typedef std::stack<PInteractorStyle> TInteractorStyles;
255 TInteractorStyles myInteractorStyles;
259 #pragma warning ( default:4251 )