1 // Copyright (C) 2007-2016 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, or (at your option) any later version.
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
23 // SALOME VTKViewer : build VTK viewer into Salome desktop
27 #ifndef SVTK_RenderWindowInteractor_h
28 #define SVTK_RenderWindowInteractor_h
31 #include "SVTK_Selection.h"
33 #include <vtkSmartPointer.h>
36 // undefining min and max because CASCADE's defines them and
37 // it clashes with std::min(), std::max()
43 class vtkGenericRenderWindowInteractor;
44 class vtkInteractorStyle;
45 class vtkCallbackCommand;
46 class vtkRenderWindow;
54 #pragma warning ( disable:4251 )
58 \class QVTK_RenderWindowInteractor
59 Implements Qt based vtkRenderWindowInteractor.
60 The class inherits #QWidget class in order to be possible process Qt events.
61 It invokes corresponding VTK events through usage of its device - a #vtkGenericRenderWindowInteractor.
62 Also, it creates, initialize and holds vtkRenderWindow instance.
64 class SVTK_EXPORT QVTK_RenderWindowInteractor: public QWidget
69 QVTK_RenderWindowInteractor(QWidget* theParent,
72 ~QVTK_RenderWindowInteractor();
74 //! To initialize by #vtkGenericRenderWindowInteractor instance
77 Initialize(vtkGenericRenderWindowInteractor* theDevice);
79 vtkGenericRenderWindowInteractor*
85 //! Just to simplify usage of its device (#vtkGenericRenderWindowInteractor)
88 InvokeEvent(unsigned long theEvent, void* theCallData);
90 //! Get paint engine for the scene
91 virtual QPaintEngine* paintEngine() const;
94 //! Need for initial contents display on Win32
97 //! To implement final initialization, just before the widget is displayed
98 virtual void polish();
100 //! To adjust widget and vtkRenderWindow size
101 virtual void resize(int w, int h);
104 virtual void paintEvent( QPaintEvent* );
105 virtual void resizeEvent( QResizeEvent* );
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 * );
117 virtual void contextMenuEvent( QContextMenuEvent * e );
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* );
124 //! To handle native events (from such devices as SpaceMouse)
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)
128 virtual bool winEvent( MSG*, long* );
129 #elif !defined(__APPLE__)
130 virtual bool x11Event( XEvent *e );
133 virtual bool nativeEvent( const QByteArray&, void*, long* );
135 vtkSmartPointer<vtkRenderWindow> myRenderWindow;
136 vtkSmartPointer<vtkGenericRenderWindowInteractor> myDevice;
140 //! Extends QVTK_RenderWindowInteractor functionality.
142 \class SVTK_RenderWindowInteractor
143 Implements such features as
144 support of selection,
145 run-time interactor style management,
146 one render window per one renderer collaboration and
147 SUIT_ViewWindow events invocation.
149 class SVTK_EXPORT SVTK_RenderWindowInteractor: public QVTK_RenderWindowInteractor
154 SVTK_RenderWindowInteractor(QWidget* theParent,
155 const char* theName);
157 ~SVTK_RenderWindowInteractor();
159 //! To initialize properly the class
162 Initialize(vtkGenericRenderWindowInteractor* theDevice,
163 SVTK_Renderer* theRenderer,
164 SVTK_Selector* theSelector);
166 //----------------------------------------------------------------------------
167 //! To get corresponding SVTK_Renderer instance
171 //! To get corresponding SVTK_Renderer device (just to simplify collobaration with SVTK_Renderer)
175 //----------------------------------------------------------------------------
176 //! To get current interactor style
178 GetInteractorStyle();
180 //! To change current interactor style by pushing the new one into the container
182 PushInteractorStyle(vtkInteractorStyle* theStyle);
184 //! To restore previous interactor style
186 PopInteractorStyle();
188 //----------------------------------------------------------------------------
189 //! To get corresponding SVTK_Selector
193 //! To get current selection mode (just to simplify collobaration with SVTK_Selector)
195 SelectionMode() const;
197 //! To change selection mode (just to simplify collobaration with SVTK_Selector)
199 SetSelectionMode(Selection_Mode theMode);
202 //! To transform vtkCommand::EndPickEvent to Qt selectionChanged signal
204 onEmitSelectionChanged();
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 );
219 void selectionChanged();
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* );
231 SetRenderer(SVTK_Renderer *theRenderer);
234 SetSelector(SVTK_Selector* theSelector);
237 InitInteractorStyle(vtkInteractorStyle* theStyle);
239 //----------------------------------------------------------------
240 // Main process VTK event method
243 ProcessEvents(vtkObject* theObject,
244 unsigned long theEvent,
248 // Used to process VTK events
249 vtkSmartPointer<vtkCallbackCommand> myEventCallbackCommand;
251 // Priority at which events are processed
254 //----------------------------------------------------------------
255 vtkSmartPointer<SVTK_Selector> mySelector;
257 vtkSmartPointer<SVTK_Renderer> myRenderer;
259 typedef vtkSmartPointer<vtkInteractorStyle> PInteractorStyle;
260 typedef std::stack<PInteractorStyle> TInteractorStyles;
261 TInteractorStyles myInteractorStyles;
265 #pragma warning ( default:4251 )