Back to index

salome-gui  6.5.0
VTKViewer_InteractorStyle.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   : VTKViewer_InteractorStyle.h
00025 //  Author : Christophe ATTANASIO
00026 //  Module : SALOME
00027 //
00028 #ifndef __VTKViewer_InteractorStyle_h
00029 #define __VTKViewer_InteractorStyle_h
00030 
00031 #include <vtkInteractorStyle.h>
00032 
00033 class vtkCell;
00034 class vtkRenderWindowInteractor;
00035 class vtkTDxInteractorStyle;
00036 
00037 #include <QObject>
00038 #include <QCursor>
00039 
00040 class QRubberBand;
00041 
00042 #include <map>
00043 
00044 #include "VTKViewer.h"
00045 
00046 #include "VTKViewer_Filter.h"
00047 
00048 class VTKViewer_Actor;
00049 class VTKViewer_Trihedron;
00050 class VTKViewer_ViewWindow;
00051 class VTKViewer_RenderWindowInteractor;
00052 
00053 #define VTK_INTERACTOR_STYLE_CAMERA_NONE    0
00054 #define VTK_INTERACTOR_STYLE_CAMERA_ROTATE  1
00055 #define VTK_INTERACTOR_STYLE_CAMERA_PAN     2
00056 #define VTK_INTERACTOR_STYLE_CAMERA_ZOOM    3
00057 #define VTK_INTERACTOR_STYLE_CAMERA_SPIN    4
00058 #define VTK_INTERACTOR_STYLE_CAMERA_FIT        5
00059 #define VTK_INTERACTOR_STYLE_CAMERA_SELECT     6
00060 #define VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN 7
00061 
00062 #ifdef WIN32
00063 #pragma warning ( disable:4251 )
00064 #endif
00065 
00071 class VTKVIEWER_EXPORT VTKViewer_InteractorStyle : public QObject, public vtkInteractorStyle
00072 {
00073  public:
00074   static VTKViewer_InteractorStyle *New();
00075   vtkTypeMacro(VTKViewer_InteractorStyle, vtkInteractorStyle);
00076 
00077   virtual void SetInteractor(vtkRenderWindowInteractor *theInteractor);
00078   void setViewWnd(VTKViewer_ViewWindow* theViewWnd);
00079   void setGUIWindow(QWidget* theWindow);
00080 
00081   void setTriedron(VTKViewer_Trihedron* theTrihedron);
00082   void setPreselectionProp(const double& theRed = 0, const double& theGreen = 1,
00083                            const double& theBlue = 1, const int& theWidth = 5);
00084 
00085   // Generic event bindings must be overridden in subclasses
00086   void OnMouseMove  (int ctrl, int shift, int x, int y);
00087   void OnLeftButtonDown(int ctrl, int shift, int x, int y);
00088   void OnLeftButtonUp  (int ctrl, int shift, int x, int y);
00089   void OnMiddleButtonDown(int ctrl, int shift, int x, int y);
00090   void OnMiddleButtonUp  (int ctrl, int shift, int x, int y);
00091   void OnRightButtonDown(int ctrl, int shift, int x, int y);
00092   void OnRightButtonUp  (int ctrl, int shift, int x, int y);
00093 
00094   void OnSelectionModeChanged();
00095 
00096   void  ViewFitAll();
00097 
00098   void                     SetFilter( const Handle( VTKViewer_Filter)& );
00099   Handle(VTKViewer_Filter) GetFilter( const int );  
00100   bool                     IsFilterPresent( const int );
00101   void                     RemoveFilter( const int );
00102   bool                     IsValid( VTKViewer_Actor* theActor,
00103                                     const int     theId,
00104                                     const bool    theIsNode = false );
00105 
00106   void                     IncrementalPan   ( const int incrX, const int incrY );
00107   void                     IncrementalZoom  ( const int incr );
00108   void                     IncrementalRotate( const int incrX, const int incrY );
00109 
00110   int                      CurrentState() const { return State; }
00111 
00112  protected:
00113   VTKViewer_InteractorStyle();
00114   ~VTKViewer_InteractorStyle();
00115   VTKViewer_InteractorStyle(const VTKViewer_InteractorStyle&) {};
00116   void operator=(const VTKViewer_InteractorStyle&) {};
00117 
00118   void RotateXY(int dx, int dy);
00119   void PanXY(int x, int y, int oldX, int oldY);
00120   void DollyXY(int dx, int dy);
00121   void SpinXY(int dx, int dy, int oldX, int oldY);
00122   void fitRect(const int left, const int top, const int right, const int bottom);
00123   void Place(const int theX, const int theY);
00124   void TranslateView(int toX, int toY, int fromX, int fromY);
00125   bool IsInRect(vtkActor* theActor, 
00126                 const int left, const int top, 
00127                 const int right, const int bottom);
00128   bool IsInRect(vtkCell* theCell, 
00129                 const int left, const int top, 
00130                 const int right, const int bottom);
00131   bool IsInRect(vtkFloatingPointType* thePoint, 
00132                 const int left, const int top, 
00133                 const int right, const int bottom);
00134 
00135   int State;
00136   vtkFloatingPointType MotionFactor;
00137   vtkFloatingPointType RadianToDegree;                 // constant: for conv from deg to rad
00138   double myScale;
00139 
00140   VTKViewer_Actor *myPreViewActor, *myPreSelectionActor, *mySelectedActor;
00141 
00142   int myElemId;
00143   int myEdgeId;
00144   int myNodeId;
00145 
00146  public:
00147   bool eventFilter(QObject* object, QEvent* event);
00148   void startZoom();
00149   void startPan();
00150   void startGlobalPan();
00151   void startRotate();
00152   void startFitArea();
00153   void startSpin();
00154   void SetTDxStyle(vtkTDxInteractorStyle *tdxStyle) {}
00155   bool needsRedrawing();
00156 
00157  protected:
00158   void loadCursors();
00159   void startOperation(int operation);
00160   virtual void onStartOperation();
00161   virtual void onFinishOperation();
00162   virtual void onOperation(QPoint mousePos);
00163   virtual void onCursorMove(QPoint mousePos);
00164   virtual void setCursor(const int operation);
00165 
00166   void drawRect();
00167   void endDrawRect();
00168 
00169  protected:
00170   QCursor                   myDefCursor;
00171   QCursor                   myPanCursor;
00172   QCursor                   myZoomCursor;
00173   QCursor                   myRotateCursor;
00174   QCursor                   mySpinCursor;
00175   QCursor                   myHandCursor;
00176   QCursor                   myGlobalPanCursor;
00177   QPoint                    myPoint;
00178   QPoint                    myOtherPoint;
00179   bool                      myCursorState;
00180   bool                      myShiftState;
00181   int                       ForcedState;
00182   
00183   VTKViewer_RenderWindowInteractor* m_Interactor;
00184   VTKViewer_ViewWindow*     m_ViewWnd;
00185   VTKViewer_Trihedron*      m_Trihedron;
00186   QWidget*                  myGUIWindow;
00187   
00188   std::map<int, Handle(VTKViewer_Filter) > myFilters;
00189 
00190   QRubberBand* myRectBand; 
00191 
00194   double                    DeltaElevation;
00195   double                    DeltaAzimuth;
00196   int                       LastPos[2];
00198 };
00199 
00200 #ifdef WIN32
00201 #pragma warning ( default:4251 )
00202 #endif
00203 
00204 #endif