Version: 6.3.1

src/SVTK/SVTK_RenderWindowInteractor.h

Go to the documentation of this file.
00001 // Copyright (C) 2007-2011  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 //  Module : SALOME
00027 //  $Header: /home/server/cvs/GUI/GUI_SRC/src/SVTK/SVTK_RenderWindowInteractor.h,v 1.6.2.2.8.1.12.1 2011-06-01 13:53:40 vsr Exp $
00028 //
00029 #ifndef SVTK_RenderWindowInteractor_h
00030 #define SVTK_RenderWindowInteractor_h
00031 
00032 #include "SVTK.h"
00033 #include "SVTK_Selection.h"
00034 
00035 #include <vtkSmartPointer.h>
00036 #include <QWidget>
00037 
00038 // undefining min and max because CASCADE's defines them and
00039 // it clashes with std::min(), std::max()
00040 #undef min
00041 #undef max
00042 
00043 #include <stack>
00044 
00045 class vtkGenericRenderWindowInteractor;
00046 class vtkInteractorStyle;
00047 class vtkCallbackCommand;
00048 class vtkRenderWindow;
00049 class vtkRenderer;
00050 class vtkObject;
00051 
00052 class SVTK_Selector;
00053 class SVTK_Renderer;
00054 
00055 #ifdef WIN32
00056 #pragma warning ( disable:4251 )
00057 #endif
00058 
00066 class SVTK_EXPORT QVTK_RenderWindowInteractor: public QWidget
00067 {
00068   Q_OBJECT;
00069 
00070  public:
00071   QVTK_RenderWindowInteractor(QWidget* theParent, 
00072                               const char* theName);
00073 
00074   ~QVTK_RenderWindowInteractor();
00075 
00077   virtual
00078   void
00079   Initialize(vtkGenericRenderWindowInteractor* theDevice);
00080 
00081   vtkGenericRenderWindowInteractor* 
00082   GetDevice();
00083 
00084   vtkRenderWindow*
00085   getRenderWindow();
00086 
00088   virtual
00089   void
00090   InvokeEvent(unsigned long theEvent, void* theCallData);
00091 
00093   virtual QPaintEngine* paintEngine() const;
00094 
00095  public slots:
00097   virtual void show();
00098 
00100   virtual void polish();
00101 
00103   virtual void resize(int w, int h);
00104 
00105  protected:
00106   virtual void paintEvent( QPaintEvent* );
00107   virtual void resizeEvent( QResizeEvent* );
00108 
00109   virtual void mouseMoveEvent( QMouseEvent* );
00110   virtual void mousePressEvent( QMouseEvent* );
00111   virtual void mouseReleaseEvent( QMouseEvent* );
00112   virtual void mouseDoubleClickEvent( QMouseEvent* );
00113   virtual void wheelEvent( QWheelEvent* );
00114   virtual void keyPressEvent( QKeyEvent* );
00115   virtual void keyReleaseEvent( QKeyEvent* );
00116   virtual void enterEvent( QEvent * );
00117   virtual void leaveEvent( QEvent * );
00118 
00119   virtual void contextMenuEvent( QContextMenuEvent * e );
00120 
00121   // reimplemented from QWidget in order to set window - receiver
00122   // of space mouse events. 
00123   virtual void focusInEvent( QFocusEvent* );
00124   virtual void focusOutEvent( QFocusEvent* );
00125 
00127 #ifdef WIN32
00128   virtual bool winEvent( MSG*, long* );
00129 #else
00130   virtual bool x11Event( XEvent *e );
00131 #endif
00132 
00133   vtkSmartPointer<vtkRenderWindow> myRenderWindow;
00134   vtkSmartPointer<vtkGenericRenderWindowInteractor> myDevice;
00135 };
00136 
00137 
00139 
00147 class SVTK_EXPORT SVTK_RenderWindowInteractor: public QVTK_RenderWindowInteractor
00148 {
00149   Q_OBJECT;
00150 
00151  public:
00152   SVTK_RenderWindowInteractor(QWidget* theParent, 
00153                               const char* theName);
00154 
00155   ~SVTK_RenderWindowInteractor();
00156 
00158   virtual
00159   void
00160   Initialize(vtkGenericRenderWindowInteractor* theDevice,
00161              SVTK_Renderer* theRenderer,
00162              SVTK_Selector* theSelector);
00163 
00164   //----------------------------------------------------------------------------
00166   SVTK_Renderer* 
00167   GetRenderer();
00168 
00170   vtkRenderer* 
00171   getRenderer();
00172 
00173   //----------------------------------------------------------------------------
00175   vtkInteractorStyle* 
00176   GetInteractorStyle();
00177 
00179   void
00180   PushInteractorStyle(vtkInteractorStyle* theStyle);
00181 
00183   void
00184   PopInteractorStyle();
00185 
00186   //----------------------------------------------------------------------------
00188   SVTK_Selector* 
00189   GetSelector();
00190 
00192   Selection_Mode 
00193   SelectionMode() const;
00194 
00196   void 
00197   SetSelectionMode(Selection_Mode theMode);
00198 
00199  public:
00201   void
00202   onEmitSelectionChanged();
00203 
00204  public:
00205  signals:
00206   void MouseMove( QMouseEvent* );
00207   void MouseButtonPressed( QMouseEvent* );
00208   void MouseButtonReleased( QMouseEvent* );
00209   void MouseDoubleClicked( QMouseEvent* );
00210   void ButtonPressed(const QMouseEvent *event);
00211   void ButtonReleased(const QMouseEvent *event);
00212   void WheelMoved( QWheelEvent* );
00213   void KeyPressed( QKeyEvent* );
00214   void KeyReleased( QKeyEvent* );
00215   void contextMenuRequested( QContextMenuEvent *e );
00216 
00217   void selectionChanged();
00218 
00219  protected:
00220   virtual void mouseMoveEvent( QMouseEvent* );
00221   virtual void mousePressEvent( QMouseEvent* );
00222   virtual void mouseReleaseEvent( QMouseEvent* );
00223   virtual void mouseDoubleClickEvent( QMouseEvent* );
00224   virtual void wheelEvent( QWheelEvent* );
00225   virtual void keyPressEvent( QKeyEvent* );
00226   virtual void keyReleaseEvent( QKeyEvent* );
00227 
00228   void
00229   SetRenderer(SVTK_Renderer *theRenderer);
00230 
00231   void
00232   SetSelector(SVTK_Selector* theSelector);
00233 
00234   void
00235   InitInteractorStyle(vtkInteractorStyle* theStyle);
00236 
00237   //----------------------------------------------------------------
00238   // Main process VTK event method
00239   static
00240   void
00241   ProcessEvents(vtkObject* theObject, 
00242                 unsigned long theEvent,
00243                 void* theClientData, 
00244                 void* theCallData);
00245 
00246   // Used to process VTK events
00247   vtkSmartPointer<vtkCallbackCommand> myEventCallbackCommand;
00248 
00249   // Priority at which events are processed
00250   float myPriority;
00251 
00252   //----------------------------------------------------------------
00253   vtkSmartPointer<SVTK_Selector> mySelector;
00254 
00255   vtkSmartPointer<SVTK_Renderer> myRenderer;
00256 
00257   typedef vtkSmartPointer<vtkInteractorStyle> PInteractorStyle;
00258   typedef std::stack<PInteractorStyle> TInteractorStyles;
00259   TInteractorStyles myInteractorStyles;
00260 };
00261 
00262 #ifdef WIN32
00263 #pragma warning ( default:4251 )
00264 #endif
00265 
00266 #endif
Copyright © 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
Copyright © 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS