Back to index

salome-gui  6.5.0
VTKViewer_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 #ifndef VTKVIEWER_RENDERWINDOWINTERACTOR_H
00024 #define VTKVIEWER_RENDERWINDOWINTERACTOR_H
00025 
00026 #include "VTKViewer.h"
00027 #include "VTKViewer_Actor.h"
00028 
00029 #include <QObject>
00030 
00031 class QTimer;
00032 class QMouseEvent;
00033 class QKeyEvent;
00034 class QContextMenuEvent;
00035 
00036 // Open CASCADE Includes
00037 #include <TColStd_MapOfInteger.hxx>
00038 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
00039 #include <TColStd_IndexedMapOfInteger.hxx>
00040 
00041 class vtkPicker;
00042 class vtkCellPicker;
00043 class vtkPointPicker;
00044 class vtkActorCollection;
00045 
00046 class VTKViewer_Actor;
00047 class VTKViewer_ViewWindow;
00048 class VTKViewer_RenderWindow;
00049 class VTKViewer_InteractorStyle;
00050 
00051 #include "VTKViewer_Algorithm.h"
00052 
00053 #include <vtkActor.h>
00054 #include <vtkVersion.h>
00055 #include <vtkRenderWindowInteractor.h>
00056 
00057 class VTKVIEWER_EXPORT VTKViewer_RenderWindowInteractor : public QObject, public vtkRenderWindowInteractor
00058 {
00059   Q_OBJECT
00060 
00061 public:
00062   static VTKViewer_RenderWindowInteractor *New();
00063 
00064   vtkTypeMacro(VTKViewer_RenderWindowInteractor,vtkRenderWindowInteractor);
00065 
00066   void PrintSelf(ostream& os, vtkIndent indent);
00067 
00068   virtual void Initialize();
00069 
00070   virtual void               SetInteractorStyle(vtkInteractorObserver *);
00072   VTKViewer_InteractorStyle* GetInteractorStyle() const
00073   {
00074     return myInteractorStyle;
00075   }
00076 
00077   virtual void Start();
00078   
00079   virtual void Enable();
00080   virtual void Disable();
00081 
00082   virtual void UpdateSize(int x,int y);
00083 
00086   virtual int CreateTimer(int ) ;
00087   virtual int DestroyTimer() ; 
00089   
00095   virtual void TerminateApp(void) { /* empty */ }
00096   
00097   // Description:
00098   // These methods correspond to the the Exit, User and Pick
00099   // callbacks. They allow for the Style to invoke them.
00100   //virtual void ExitCallback();
00101   //virtual void UserCallback();
00102   //virtual void StartPickCallback();
00103   //virtual void EndPickCallback();
00104   
00107   bool highlightCell(const TColStd_IndexedMapOfInteger& MapIndex,
00108                      VTKViewer_Actor* theMapActor,
00109                      bool hilight,
00110                      bool update = true );
00111   bool highlightEdge(const TColStd_IndexedMapOfInteger& MapIndex,
00112                      VTKViewer_Actor* theMapActor,
00113                      bool hilight,
00114                      bool update = true );
00115   bool highlightPoint(const TColStd_IndexedMapOfInteger& MapIndex,
00116                       VTKViewer_Actor* theMapActor,
00117                       bool hilight,
00118                       bool update = true );
00119 
00120   void unHighlightSubSelection();
00121   bool unHighlightAll();
00122 
00123   //void SetSelectionMode(Selection_Mode mode);
00124   void SetSelectionProp(const double& theRed = 1, const double& theGreen = 1,
00125                         const double& theBlue = 0, const int& theWidth = 5);
00126   void SetSelectionTolerance(const double& theTolNodes = 0.025, const double& theTolCell = 0.001);
00128 
00131   int GetDisplayMode();
00132   void SetDisplayMode(int);
00134 
00137   void ChangeRepresentationToWireframe();
00138   void ChangeRepresentationToSurface();
00139   void ChangeRepresentationToSurfaceWithEdges();
00141 
00144   void ChangeRepresentationToWireframe(vtkActorCollection* ListofActors);
00145   void ChangeRepresentationToSurface(vtkActorCollection* ListofActors);
00146   void ChangeRepresentationToSurfaceWithEdges(vtkActorCollection* ListofActors);
00148 
00151   void EraseAll();
00152   void DisplayAll();
00153   void RemoveAll( const bool immediatly );
00154 
00155   void Display( VTKViewer_Actor* SActor, bool immediatly = true );
00156   void Erase( VTKViewer_Actor* SActor, bool immediatly = true );
00157   void Remove( VTKViewer_Actor* SActor, bool updateViewer = true );
00159 
00160   void Update();
00161 
00162   vtkRenderer* GetRenderer();
00163 
00164   void setViewWindow( VTKViewer_ViewWindow* theViewWnd );
00165 
00166   void setCellData(const int& theIndex,
00167                    VTKViewer_Actor* theMapActor,
00168                    VTKViewer_Actor* theActor) {}
00169   void setEdgeData(const int& theCellIndex,
00170                    VTKViewer_Actor* theMapActor,
00171                    const int& theEdgeIndex,
00172                    VTKViewer_Actor* theActor ) {} //NB
00173   void setPointData(const int& theIndex,
00174                     VTKViewer_Actor* theMapActor,
00175                     VTKViewer_Actor* theActor) {}
00176 
00177   typedef void (*TUpdateActor)(const TColStd_IndexedMapOfInteger& theMapIndex,
00178                                VTKViewer_Actor* theMapActor,
00179                                VTKViewer_Actor* theActor);
00180  protected:
00181 
00182   VTKViewer_RenderWindowInteractor();
00183   ~VTKViewer_RenderWindowInteractor();
00184 
00185   VTKViewer_InteractorStyle* myInteractorStyle;
00186 
00187   bool highlight(const TColStd_IndexedMapOfInteger& theMapIndex,
00188                  VTKViewer_Actor* theMapActor, VTKViewer_Actor* theActor,
00189                  TUpdateActor theFun, bool hilight, bool update);
00190   void setActorData(const TColStd_IndexedMapOfInteger& theMapIndex,
00191                     VTKViewer_Actor* theMapActor,
00192                     VTKViewer_Actor *theActor,
00193                     TUpdateActor theFun);
00194 
00198   QTimer *mTimer ;
00199 
00200   int myDisplayMode;
00201 
00202   //NRI: Selection mode
00203   VTKViewer_Actor* myPointActor;
00204   VTKViewer_Actor* myEdgeActor;
00205   VTKViewer_Actor* myCellActor;
00206   void MoveInternalActors();
00207 
00208   vtkPicker* myBasicPicker;
00209   vtkCellPicker* myCellPicker;
00210   vtkPointPicker* myPointPicker;
00211   
00213   int PositionBeforeStereo[2];
00214 
00215  public slots:
00216   void MouseMove(QMouseEvent *event) ;
00217   void LeftButtonPressed(const QMouseEvent *event) ;
00218   void LeftButtonReleased(const QMouseEvent *event) ;
00219   void MiddleButtonPressed(const QMouseEvent *event) ;
00220   void MiddleButtonReleased(const QMouseEvent *event) ;
00221   void RightButtonPressed(const QMouseEvent *event) ;
00222   void RightButtonReleased(const QMouseEvent *event) ;
00223   void ButtonPressed(const QMouseEvent *event) ;
00224   void ButtonReleased(const QMouseEvent *event) ;
00225   void KeyPressed(QKeyEvent *event) ;
00226 
00227   private slots:
00228     void TimerFunc() ;
00229 
00230 signals:
00231   void RenderWindowModified() ;
00232   void contextMenuRequested( QContextMenuEvent *e );
00233 
00234 private:
00235   friend class VTKViewer_ViewWindow;
00236 
00237   VTKViewer_ViewWindow* myViewWnd;
00239   double       myTolNodes;
00241   double       myTolItems;
00242 };
00243 
00244 #endif