1 // SALOME VTKViewer : build VTK viewer into Salome desktop
3 // Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
29 #ifndef SVTK_RenderWindowInteractor_h
30 #define SVTK_RenderWindowInteractor_h
33 #include "SVTK_Selection.h"
35 #include <vtkSmartPointer.h>
38 // undefining min and max because CASCADE's defines them and
39 // it clashes with std::min(), std::max()
45 class vtkGenericRenderWindowInteractor;
46 class vtkInteractorStyle;
47 class vtkCallbackCommand;
48 class vtkRenderWindow;
55 //============================================================================
56 //! Implemements 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.
62 class SVTK_EXPORT QVTK_RenderWindowInteractor: public QWidget
67 QVTK_RenderWindowInteractor(QWidget* theParent,
70 ~QVTK_RenderWindowInteractor();
72 //! To initialize by #vtkGenericRenderWindowInteractor instance
75 Initialize(vtkGenericRenderWindowInteractor* theDevice);
77 vtkGenericRenderWindowInteractor*
83 //! Just to simplify usage of its device (#vtkGenericRenderWindowInteractor)
86 InvokeEvent(unsigned long theEvent, void* theCallData);
89 //! Need for initial contents display on Win32
92 //! To implement final initialization, just before the widget is displayed
93 virtual void polish();
95 //! To adjust widget and vtkRenderWindow size
96 virtual void resize(int w, int h);
99 virtual void paintEvent( QPaintEvent* );
100 virtual void resizeEvent( QResizeEvent* );
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 * );
112 virtual void contextMenuEvent( QContextMenuEvent * e );
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* );
119 //! To handle native X11 events (from such devices as SpaceMouse)
120 virtual bool x11Event( XEvent *e );
122 vtkSmartPointer<vtkRenderWindow> myRenderWindow;
123 vtkSmartPointer<vtkGenericRenderWindowInteractor> myDevice;
127 //============================================================================
128 //! Extends QVTK_RenderWindowInteractor functionality.
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.
136 class SVTK_EXPORT SVTK_RenderWindowInteractor: public QVTK_RenderWindowInteractor
141 SVTK_RenderWindowInteractor(QWidget* theParent,
142 const char* theName);
144 ~SVTK_RenderWindowInteractor();
146 //! To initialize properly the class
149 Initialize(vtkGenericRenderWindowInteractor* theDevice,
150 SVTK_Renderer* theRenderer,
151 SVTK_Selector* theSelector);
153 //----------------------------------------------------------------------------
154 //! To get corresponding SVTK_Renderer instance
158 //! To get corresponding SVTK_Renderer device (just to simplify collobaration with SVTK_Renderer)
162 //----------------------------------------------------------------------------
163 //! To get current interactor style
165 GetInteractorStyle();
167 //! To change current interactor style by pushing the new one into the container
169 PushInteractorStyle(vtkInteractorStyle* theStyle);
171 //! To restore previous interactor style
173 PopInteractorStyle();
175 //----------------------------------------------------------------------------
176 //! To get corresponding SVTK_Selector
180 //! To get current selection mode (just to simplify collobaration with SVTK_Selector)
182 SelectionMode() const;
184 //! To change selection mode (just to simplify collobaration with SVTK_Selector)
186 SetSelectionMode(Selection_Mode theMode);
189 //! To transform vtkCommand::EndPickEvent to Qt selectionChanged signal
191 onEmitSelectionChanged();
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 );
206 void selectionChanged();
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 );
219 SetRenderer(SVTK_Renderer *theRenderer);
222 SetSelector(SVTK_Selector* theSelector);
225 InitInteractorStyle(vtkInteractorStyle* theStyle);
227 //----------------------------------------------------------------
228 // Main process VTK event method
231 ProcessEvents(vtkObject* theObject,
232 unsigned long theEvent,
236 // Used to process VTK events
237 vtkSmartPointer<vtkCallbackCommand> myEventCallbackCommand;
239 // Priority at which events are processed
242 //----------------------------------------------------------------
243 vtkSmartPointer<SVTK_Selector> mySelector;
245 vtkSmartPointer<SVTK_Renderer> myRenderer;
247 typedef vtkSmartPointer<vtkInteractorStyle> PInteractorStyle;
248 typedef std::stack<PInteractorStyle> TInteractorStyles;
249 TInteractorStyles myInteractorStyles;