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.salome-platform.org/ or email : webmaster.salome@opencascade.com
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;
56 #pragma warning ( disable:4251 )
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.
66 class SVTK_EXPORT QVTK_RenderWindowInteractor: public QWidget
71 QVTK_RenderWindowInteractor(QWidget* theParent,
74 ~QVTK_RenderWindowInteractor();
76 //! To initialize by #vtkGenericRenderWindowInteractor instance
79 Initialize(vtkGenericRenderWindowInteractor* theDevice);
81 vtkGenericRenderWindowInteractor*
87 //! Just to simplify usage of its device (#vtkGenericRenderWindowInteractor)
90 InvokeEvent(unsigned long theEvent, void* theCallData);
93 //! Need for initial contents display on Win32
96 //! To implement final initialization, just before the widget is displayed
97 virtual void polish();
99 //! To adjust widget and vtkRenderWindow size
100 virtual void resize(int w, int h);
103 virtual void paintEvent( QPaintEvent* );
104 virtual void resizeEvent( QResizeEvent* );
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 * );
116 virtual void contextMenuEvent( QContextMenuEvent * e );
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* );
123 //! To handle native events (from such devices as SpaceMouse)
125 virtual bool winEvent( MSG* );
127 virtual bool x11Event( XEvent *e );
130 vtkSmartPointer<vtkRenderWindow> myRenderWindow;
131 vtkSmartPointer<vtkGenericRenderWindowInteractor> myDevice;
135 //! Extends QVTK_RenderWindowInteractor functionality.
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.
144 class SVTK_EXPORT SVTK_RenderWindowInteractor: public QVTK_RenderWindowInteractor
149 SVTK_RenderWindowInteractor(QWidget* theParent,
150 const char* theName);
152 ~SVTK_RenderWindowInteractor();
154 //! To initialize properly the class
157 Initialize(vtkGenericRenderWindowInteractor* theDevice,
158 SVTK_Renderer* theRenderer,
159 SVTK_Selector* theSelector);
161 //----------------------------------------------------------------------------
162 //! To get corresponding SVTK_Renderer instance
166 //! To get corresponding SVTK_Renderer device (just to simplify collobaration with SVTK_Renderer)
170 //----------------------------------------------------------------------------
171 //! To get current interactor style
173 GetInteractorStyle();
175 //! To change current interactor style by pushing the new one into the container
177 PushInteractorStyle(vtkInteractorStyle* theStyle);
179 //! To restore previous interactor style
181 PopInteractorStyle();
183 //----------------------------------------------------------------------------
184 //! To get corresponding SVTK_Selector
188 //! To get current selection mode (just to simplify collobaration with SVTK_Selector)
190 SelectionMode() const;
192 //! To change selection mode (just to simplify collobaration with SVTK_Selector)
194 SetSelectionMode(Selection_Mode theMode);
197 //! To transform vtkCommand::EndPickEvent to Qt selectionChanged signal
199 onEmitSelectionChanged();
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 );
214 void selectionChanged();
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 );
227 SetRenderer(SVTK_Renderer *theRenderer);
230 SetSelector(SVTK_Selector* theSelector);
233 InitInteractorStyle(vtkInteractorStyle* theStyle);
235 //----------------------------------------------------------------
236 // Main process VTK event method
239 ProcessEvents(vtkObject* theObject,
240 unsigned long theEvent,
244 // Used to process VTK events
245 vtkSmartPointer<vtkCallbackCommand> myEventCallbackCommand;
247 // Priority at which events are processed
250 //----------------------------------------------------------------
251 vtkSmartPointer<SVTK_Selector> mySelector;
253 vtkSmartPointer<SVTK_Renderer> myRenderer;
255 typedef vtkSmartPointer<vtkInteractorStyle> PInteractorStyle;
256 typedef std::stack<PInteractorStyle> TInteractorStyles;
257 TInteractorStyles myInteractorStyles;
261 #pragma warning ( default:4251 )