Back to index

salome-gui  6.5.0
SVTK_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   : SVTK_InteractorStyle.h
00025 //  Author : Christophe ATTANASIO
00026 
00027 #ifndef __SVTK_InteractorStyle_h
00028 #define __SVTK_InteractorStyle_h
00029 
00030 #include "SVTK.h"
00031 
00032 #include "SVTK_SelectionEvent.h"
00033 
00034 #include <boost/shared_ptr.hpp>
00035 
00036 #include <vtkInteractorStyle.h>
00037 #include <vtkSmartPointer.h>
00038 
00039 #include <QCursor>
00040 
00041 #include <map>
00042 
00043 #include <vtkObject.h>
00044 
00045 #ifdef WIN32
00046 #pragma warning ( disable:4251 )
00047 #endif
00048 
00049 //
00051 
00055 class SVTK_EXPORT SVTK_ControllerIncrement : public vtkObject{
00056  public:
00057   vtkTypeMacro(SVTK_ControllerIncrement, vtkObject);
00058   static SVTK_ControllerIncrement* New();
00059 
00061   void SetStartValue(const int );
00062 
00064   int Current()const;
00065 
00067   virtual int Increase();
00068 
00070   virtual int Decrease();
00071  protected:
00072   SVTK_ControllerIncrement();
00073   virtual ~SVTK_ControllerIncrement();
00074  protected:
00075   int  myIncrement;
00076  private:
00077   SVTK_ControllerIncrement(const SVTK_ControllerIncrement&);//Not implemented
00078   void operator=(const SVTK_ControllerIncrement&);          //Not implemented
00079 };
00080 
00081 //
00083 
00087 class SVTK_EXPORT SVTK_GeomControllerIncrement : public SVTK_ControllerIncrement{
00088  public:
00089   vtkTypeMacro(SVTK_GeomControllerIncrement, SVTK_ControllerIncrement);
00090   static SVTK_GeomControllerIncrement* New();
00091 
00093   virtual int Increase();
00094 
00096   virtual int Decrease();
00097  protected:
00098   SVTK_GeomControllerIncrement();
00099   virtual ~SVTK_GeomControllerIncrement();
00100  private:
00101   SVTK_GeomControllerIncrement(const SVTK_GeomControllerIncrement&);//Not implemented
00102   void operator=(const SVTK_GeomControllerIncrement&);              //Not implemented
00103 };
00104 //
00106 
00110 class SVTK_EXPORT SVTK_ControllerOnKeyDown : public vtkObject{
00111  public:
00112   vtkTypeMacro(SVTK_ControllerOnKeyDown, vtkObject);
00113   static SVTK_ControllerOnKeyDown* New();
00114 
00116   virtual bool OnKeyDown(vtkInteractorStyle* );
00117 
00118  protected:
00119   SVTK_ControllerOnKeyDown();
00120   virtual ~SVTK_ControllerOnKeyDown();
00121   
00122  private:
00123   SVTK_ControllerOnKeyDown(const SVTK_ControllerOnKeyDown&);//Not implemented
00124   void operator=(const SVTK_ControllerOnKeyDown&);          //Not implemented
00125 };
00126 
00127 class vtkPointPicker;
00128 class vtkTDxInteractorStyle;
00129 
00130 class SALOME_Actor;
00131 
00132 class SVTK_Selector;
00133 class SVTK_GenericRenderWindowInteractor;
00134 class SVTK_Actor;
00135 
00136 class QRubberBand;
00137 
00138 #define VTK_INTERACTOR_STYLE_CAMERA_NONE    0
00139 #define VTK_INTERACTOR_STYLE_CAMERA_ROTATE  1
00140 #define VTK_INTERACTOR_STYLE_CAMERA_PAN     2
00141 #define VTK_INTERACTOR_STYLE_CAMERA_ZOOM    3
00142 #define VTK_INTERACTOR_STYLE_CAMERA_SPIN    4
00143 #define VTK_INTERACTOR_STYLE_CAMERA_FIT        5
00144 #define VTK_INTERACTOR_STYLE_CAMERA_SELECT     6
00145 #define VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN 7
00146 #define VTK_INTERACTOR_STYLE_CAMERA_SELECT_ROTATION_POINT 8
00147 
00149 
00153 class SVTK_EXPORT SVTK_InteractorStyle: public vtkInteractorStyle
00154 {
00155  public:
00156   static SVTK_InteractorStyle *New();
00157   vtkTypeMacro(SVTK_InteractorStyle, vtkInteractorStyle);
00158 
00159   typedef boost::shared_ptr<SVTK_SelectionEvent> PSelectionEvent;
00160 
00161   void SetTDxStyle(vtkTDxInteractorStyle*){} 
00162 
00164   virtual SVTK_SelectionEvent* GetSelectionEvent();
00165 
00167   virtual SVTK_SelectionEvent* GetSelectionEventFlipY();
00168 
00170   virtual void SetInteractor( vtkRenderWindowInteractor* );
00171 
00173   virtual void Render();
00174 
00176   virtual void OnTimer();
00177 
00179   virtual void OnConfigure();
00180 
00182   virtual void OnMouseMove();
00183 
00185   virtual void OnLeftButtonDown();
00186 
00188   virtual void OnLeftButtonUp();
00189 
00191   virtual void OnMiddleButtonDown();
00192 
00194   virtual void OnMiddleButtonUp();
00195 
00197   virtual void OnRightButtonDown();
00198 
00200   virtual void OnRightButtonUp();
00201 
00203   virtual void OnMouseWheelForward();
00204 
00206   virtual void OnMouseWheelBackward();
00207 
00209   virtual void OnChar();
00210 
00212   void SetControllerIncrement(SVTK_ControllerIncrement*);
00213 
00215   void SetIncrementSpeed(const int, const int = 0);
00216 
00218   SVTK_ControllerIncrement* ControllerIncrement();
00219  
00221   virtual void OnKeyDown();
00222 
00224   void ActionPicking();
00225 
00227   void SetControllerOnKeyDown(SVTK_ControllerOnKeyDown*);
00228 
00230   SVTK_ControllerOnKeyDown* ControllerOnKeyDown();
00231   
00232   SVTK_Selector* GetSelector();
00233 
00234   int   CurrentState() const { return State; }
00235 
00236   void SetAdvancedZoomingEnabled( const bool theState ) { myIsAdvancedZoomingEnabled = theState; }
00237   bool IsAdvancedZoomingEnabled() const { return myIsAdvancedZoomingEnabled; }
00238 
00239   protected:
00240   SVTK_InteractorStyle();
00241   ~SVTK_InteractorStyle();
00242 
00243   QWidget*
00244   GetRenderWidget();
00245   
00246   // Generic event bindings must be overridden in subclasses
00247   virtual void OnMouseMove  (int ctrl, int shift, int x, int y);
00248   virtual void OnLeftButtonDown(int ctrl, int shift, int x, int y);
00249   virtual void OnLeftButtonUp  (int ctrl, int shift, int x, int y);
00250   virtual void OnMiddleButtonDown(int ctrl, int shift, int x, int y);
00251   virtual void OnMiddleButtonUp  (int ctrl, int shift, int x, int y);
00252   virtual void OnRightButtonDown(int ctrl, int shift, int x, int y);
00253   virtual void OnRightButtonUp  (int ctrl, int shift, int x, int y);
00254 
00255   void RotateXY(int dx, int dy);
00256   void PanXY(int x, int y, int oldX, int oldY);
00257   void DollyXY(int dx, int dy);
00258   void SpinXY(int dx, int dy, int oldX, int oldY);
00259   void fitRect(const int left, const int top, const int right, const int bottom);
00260   void Place(const int theX, const int theY);
00261   void TranslateView(int toX, int toY, int fromX, int fromY);
00262 
00263   void
00264   IncrementalPan( const int incrX, const int incrY );
00265 
00266   void
00267   IncrementalZoom( const int incr );
00268 
00269   void
00270   IncrementalRotate( const int incrX, const int incrY );
00271 
00272   // Main process event method (reimplemented from #vtkInteractorStyle)
00273   static 
00274   void
00275   ProcessEvents(vtkObject* object, 
00276                 unsigned long event,
00277                 void* clientData, 
00278                 void* callData );
00279 
00280   float MotionFactor;
00281   float RadianToDegree;                 // constant: for conv from deg to rad
00282   double myScale;
00283 
00284  protected:
00285   void startZoom();
00286   void startPan();
00287   void startGlobalPan();
00288   void startRotate();
00289   void startFitArea();
00290   void startSpin();
00291 
00292   void startPointSelection();
00293   void startFocalPointSelection();
00294 
00295  protected:
00296   void loadCursors();
00297   void startOperation(int operation);
00298   void onStartOperation();
00299   virtual void onFinishOperation();
00300   void onOperation(QPoint mousePos);
00301   void onCursorMove(QPoint mousePos);
00302   void setCursor(const int operation);
00303 
00304   void onSpaceMouseMove( double* data );
00305   virtual void onSpaceMouseButton( int button );
00306 
00307   void DominantCombinedSwitch();
00308   
00309   void drawRect();
00310   void endDrawRect();
00311 
00312  protected:
00313   QCursor                   myDefCursor;
00314   QCursor                   myPanCursor;
00315   QCursor                   myZoomCursor;
00316   QCursor                   myRotateCursor;
00317   QCursor                   mySpinCursor;
00318   QCursor                   myHandCursor;
00319   QCursor                   myGlobalPanCursor;
00320   QPoint                    myPoint;
00321   QPoint                    myOtherPoint;
00322   bool                      myCursorState;
00323   bool                      myShiftState;
00324   int                       ForcedState;
00325 
00326   vtkSmartPointer<SALOME_Actor> myLastHighlitedActor;
00327   vtkSmartPointer<SALOME_Actor> myLastPreHighlitedActor;
00328 
00330   vtkSmartPointer<SVTK_ControllerIncrement> myControllerIncrement;
00331 
00333   vtkSmartPointer<SVTK_ControllerOnKeyDown> myControllerOnKeyDown;
00334 
00335   // SpaceMouse short cuts
00336   int                       mySMDecreaseSpeedBtn;
00337   int                       mySMIncreaseSpeedBtn;
00338   int                       mySMDominantCombinedSwitchBtn;
00339   
00340   vtkSmartPointer<SVTK_GenericRenderWindowInteractor> myInteractor;
00341 
00342   PSelectionEvent mySelectionEvent;
00343 
00344   unsigned long                   myCurrRotationPointType;
00345   unsigned long                   myPrevRotationPointType;
00346 
00347   unsigned long                   myCurrFocalPointType;
00348   unsigned long                   myPrevFocalPointType;
00349 
00350   double                          myRotationPointX;
00351   double                          myRotationPointY;
00352   double                          myRotationPointZ;
00353 
00354   vtkSmartPointer<SVTK_Actor>     myHighlightSelectionPointActor;
00355   vtkSmartPointer<vtkPointPicker> myPointPicker;
00356   
00357   vtkFloatingPointType            myBBCenter[3];
00358   bool                            myBBFirstCheck;
00359 
00360   QRubberBand*                    myRectBand; 
00361 
00362   bool                            myIsAdvancedZoomingEnabled;
00363 };
00364 
00365 #ifdef WIN32
00366 #pragma warning ( default:4251 )
00367 #endif
00368 
00369 #endif