Back to index

salome-gui  6.5.0
SVTK_RenderWindowInteractor.h
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  SALOME VTKViewer : build VTK viewer into Salome desktop
00024 //  File   : 
00025 //  Author : 
00026 
00027 #ifndef SVTK_RenderWindowInteractor_h
00028 #define SVTK_RenderWindowInteractor_h
00029 
00030 #include "SVTK.h"
00031 #include "SVTK_Selection.h"
00032 
00033 #include <vtkSmartPointer.h>
00034 #include <QWidget>
00035 
00036 // undefining min and max because CASCADE's defines them and
00037 // it clashes with std::min(), std::max()
00038 #undef min
00039 #undef max
00040 
00041 #include <stack>
00042 
00043 class vtkGenericRenderWindowInteractor;
00044 class vtkInteractorStyle;
00045 class vtkCallbackCommand;
00046 class vtkRenderWindow;
00047 class vtkRenderer;
00048 class vtkObject;
00049 
00050 class SVTK_Selector;
00051 class SVTK_Renderer;
00052 
00053 #ifdef WIN32
00054 #pragma warning ( disable:4251 )
00055 #endif
00056 
00064 class SVTK_EXPORT QVTK_RenderWindowInteractor: public QWidget
00065 {
00066   Q_OBJECT;
00067 
00068  public:
00069   QVTK_RenderWindowInteractor(QWidget* theParent, 
00070                               const char* theName);
00071 
00072   ~QVTK_RenderWindowInteractor();
00073 
00075   virtual
00076   void
00077   Initialize(vtkGenericRenderWindowInteractor* theDevice);
00078 
00079   vtkGenericRenderWindowInteractor* 
00080   GetDevice();
00081 
00082   vtkRenderWindow*
00083   getRenderWindow();
00084 
00086   virtual
00087   void
00088   InvokeEvent(unsigned long theEvent, void* theCallData);
00089 
00091   virtual QPaintEngine* paintEngine() const;
00092 
00093  public slots:
00095   virtual void show();
00096 
00098   virtual void polish();
00099 
00101   virtual void resize(int w, int h);
00102 
00103  protected:
00104   virtual void paintEvent( QPaintEvent* );
00105   virtual void resizeEvent( QResizeEvent* );
00106 
00107   virtual void mouseMoveEvent( QMouseEvent* );
00108   virtual void mousePressEvent( QMouseEvent* );
00109   virtual void mouseReleaseEvent( QMouseEvent* );
00110   virtual void mouseDoubleClickEvent( QMouseEvent* );
00111   virtual void wheelEvent( QWheelEvent* );
00112   virtual void keyPressEvent( QKeyEvent* );
00113   virtual void keyReleaseEvent( QKeyEvent* );
00114   virtual void enterEvent( QEvent * );
00115   virtual void leaveEvent( QEvent * );
00116 
00117   virtual void contextMenuEvent( QContextMenuEvent * e );
00118 
00119   // reimplemented from QWidget in order to set window - receiver
00120   // of space mouse events. 
00121   virtual void focusInEvent( QFocusEvent* );
00122   virtual void focusOutEvent( QFocusEvent* );
00123 
00125 #ifdef WIN32
00126   virtual bool winEvent( MSG*, long* );
00127 #else
00128   virtual bool x11Event( XEvent *e );
00129 #endif
00130 
00131   vtkSmartPointer<vtkRenderWindow> myRenderWindow;
00132   vtkSmartPointer<vtkGenericRenderWindowInteractor> myDevice;
00133 };
00134 
00135 
00137 
00145 class SVTK_EXPORT SVTK_RenderWindowInteractor: public QVTK_RenderWindowInteractor
00146 {
00147   Q_OBJECT;
00148 
00149  public:
00150   SVTK_RenderWindowInteractor(QWidget* theParent, 
00151                               const char* theName);
00152 
00153   ~SVTK_RenderWindowInteractor();
00154 
00156   virtual
00157   void
00158   Initialize(vtkGenericRenderWindowInteractor* theDevice,
00159              SVTK_Renderer* theRenderer,
00160              SVTK_Selector* theSelector);
00161 
00162   //----------------------------------------------------------------------------
00164   SVTK_Renderer* 
00165   GetRenderer();
00166 
00168   vtkRenderer* 
00169   getRenderer();
00170 
00171   //----------------------------------------------------------------------------
00173   vtkInteractorStyle* 
00174   GetInteractorStyle();
00175 
00177   void
00178   PushInteractorStyle(vtkInteractorStyle* theStyle);
00179 
00181   void
00182   PopInteractorStyle();
00183 
00184   //----------------------------------------------------------------------------
00186   SVTK_Selector* 
00187   GetSelector();
00188 
00190   Selection_Mode 
00191   SelectionMode() const;
00192 
00194   void 
00195   SetSelectionMode(Selection_Mode theMode);
00196 
00197  public:
00199   void
00200   onEmitSelectionChanged();
00201 
00202  public:
00203  signals:
00204   void MouseMove( QMouseEvent* );
00205   void MouseButtonPressed( QMouseEvent* );
00206   void MouseButtonReleased( QMouseEvent* );
00207   void MouseDoubleClicked( QMouseEvent* );
00208   void ButtonPressed(const QMouseEvent *event);
00209   void ButtonReleased(const QMouseEvent *event);
00210   void WheelMoved( QWheelEvent* );
00211   void KeyPressed( QKeyEvent* );
00212   void KeyReleased( QKeyEvent* );
00213   void contextMenuRequested( QContextMenuEvent *e );
00214 
00215   void selectionChanged();
00216 
00217  protected:
00218   virtual void mouseMoveEvent( QMouseEvent* );
00219   virtual void mousePressEvent( QMouseEvent* );
00220   virtual void mouseReleaseEvent( QMouseEvent* );
00221   virtual void mouseDoubleClickEvent( QMouseEvent* );
00222   virtual void wheelEvent( QWheelEvent* );
00223   virtual void keyPressEvent( QKeyEvent* );
00224   virtual void keyReleaseEvent( QKeyEvent* );
00225 
00226   void
00227   SetRenderer(SVTK_Renderer *theRenderer);
00228 
00229   void
00230   SetSelector(SVTK_Selector* theSelector);
00231 
00232   void
00233   InitInteractorStyle(vtkInteractorStyle* theStyle);
00234 
00235   //----------------------------------------------------------------
00236   // Main process VTK event method
00237   static
00238   void
00239   ProcessEvents(vtkObject* theObject, 
00240                 unsigned long theEvent,
00241                 void* theClientData, 
00242                 void* theCallData);
00243 
00244   // Used to process VTK events
00245   vtkSmartPointer<vtkCallbackCommand> myEventCallbackCommand;
00246 
00247   // Priority at which events are processed
00248   float myPriority;
00249 
00250   //----------------------------------------------------------------
00251   vtkSmartPointer<SVTK_Selector> mySelector;
00252 
00253   vtkSmartPointer<SVTK_Renderer> myRenderer;
00254 
00255   typedef vtkSmartPointer<vtkInteractorStyle> PInteractorStyle;
00256   typedef std::stack<PInteractorStyle> TInteractorStyles;
00257   TInteractorStyles myInteractorStyles;
00258 };
00259 
00260 #ifdef WIN32
00261 #pragma warning ( default:4251 )
00262 #endif
00263 
00264 #endif