Salome HOME
ed3f08d99fd1ec5bcd8d30b5c0de6b3996f6ece2
[modules/gui.git] / src / VTKViewer / VTKViewer_InteractorStyle.h
1 //  SALOME VTKViewer : build VTK viewer into Salome desktop
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : VTKViewer_InteractorStyle.h
25 //  Author : Christophe ATTANASIO
26 //  Module : SALOME
27
28 #ifndef __VTKViewer_InteractorStyle_h
29 #define __VTKViewer_InteractorStyle_h
30
31 #include <vtkInteractorStyle.h>
32
33 class vtkCell;
34 class vtkRenderWindowInteractor;
35
36 #include <qobject.h>
37 #include <qcursor.h>
38
39 #include <map>
40
41 #include "VTKViewer.h"
42
43 #include "VTKViewer_Filter.h"
44
45 class VTKViewer_Actor;
46 class VTKViewer_Trihedron;
47 class VTKViewer_ViewWindow;
48 class VTKViewer_RenderWindowInteractor;
49
50 #define VTK_INTERACTOR_STYLE_CAMERA_NONE    0
51 #define VTK_INTERACTOR_STYLE_CAMERA_ROTATE  1
52 #define VTK_INTERACTOR_STYLE_CAMERA_PAN     2
53 #define VTK_INTERACTOR_STYLE_CAMERA_ZOOM    3
54 #define VTK_INTERACTOR_STYLE_CAMERA_SPIN    4
55 #define VTK_INTERACTOR_STYLE_CAMERA_FIT        5
56 #define VTK_INTERACTOR_STYLE_CAMERA_SELECT     6
57 #define VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN 7
58
59 /*! Description:\n
60  * This class must be supplied with a vtkRenderWindowInteractor wrapper or\n
61  * parent. This class should not normally be instantiated by application\n
62  * programmers.
63  */
64 class VTKVIEWER_EXPORT VTKViewer_InteractorStyle : public QObject, public vtkInteractorStyle
65 {
66  public:
67   static VTKViewer_InteractorStyle *New();
68   vtkTypeMacro(VTKViewer_InteractorStyle, vtkInteractorStyle);
69
70   virtual void SetInteractor(vtkRenderWindowInteractor *theInteractor);
71   void setViewWnd(VTKViewer_ViewWindow* theViewWnd);
72   void setGUIWindow(QWidget* theWindow);
73
74   void setTriedron(VTKViewer_Trihedron* theTrihedron);
75   void setPreselectionProp(const double& theRed = 0, const double& theGreen = 1,
76                            const double& theBlue = 1, const int& theWidth = 5);
77
78   // Generic event bindings must be overridden in subclasses
79   void OnMouseMove  (int ctrl, int shift, int x, int y);
80   void OnLeftButtonDown(int ctrl, int shift, int x, int y);
81   void OnLeftButtonUp  (int ctrl, int shift, int x, int y);
82   void OnMiddleButtonDown(int ctrl, int shift, int x, int y);
83   void OnMiddleButtonUp  (int ctrl, int shift, int x, int y);
84   void OnRightButtonDown(int ctrl, int shift, int x, int y);
85   void OnRightButtonUp  (int ctrl, int shift, int x, int y);
86
87   void OnSelectionModeChanged();
88
89   void  ViewFitAll();
90
91   void                     SetFilter( const Handle( VTKViewer_Filter)& );
92   Handle(VTKViewer_Filter) GetFilter( const int );  
93   bool                     IsFilterPresent( const int );
94   void                     RemoveFilter( const int );
95   bool                     IsValid( VTKViewer_Actor* theActor,
96                                     const int     theId,
97                                     const bool    theIsNode = false );
98
99   void                     IncrementalPan   ( const int incrX, const int incrY );
100   void                     IncrementalZoom  ( const int incr );
101   void                     IncrementalRotate( const int incrX, const int incrY );
102
103   int                      CurrentState() const { return State; }
104
105  protected:
106   VTKViewer_InteractorStyle();
107   ~VTKViewer_InteractorStyle();
108   VTKViewer_InteractorStyle(const VTKViewer_InteractorStyle&) {};
109   void operator=(const VTKViewer_InteractorStyle&) {};
110
111   void RotateXY(int dx, int dy);
112   void PanXY(int x, int y, int oldX, int oldY);
113   void DollyXY(int dx, int dy);
114   void SpinXY(int dx, int dy, int oldX, int oldY);
115   void fitRect(const int left, const int top, const int right, const int bottom);
116   void Place(const int theX, const int theY);
117   void TranslateView(int toX, int toY, int fromX, int fromY);
118   bool IsInRect(vtkActor* theActor, 
119                 const int left, const int top, 
120                 const int right, const int bottom);
121   bool IsInRect(vtkCell* theCell, 
122                 const int left, const int top, 
123                 const int right, const int bottom);
124   bool IsInRect(float* thePoint, 
125                 const int left, const int top, 
126                 const int right, const int bottom);
127
128   int State;
129   float MotionFactor;
130   float RadianToDegree;                 // constant: for conv from deg to rad
131   double myScale;
132
133   VTKViewer_Actor *myPreViewActor, *myPreSelectionActor, *mySelectedActor;
134
135   int myElemId;
136   int myEdgeId;
137   int myNodeId;
138
139  public:
140   bool eventFilter(QObject* object, QEvent* event);
141   void startZoom();
142   void startPan();
143   void startGlobalPan();
144   void startRotate();
145   void startFitArea();
146   void startSpin();
147   bool needsRedrawing();
148
149  protected:
150   void loadCursors();
151   void startOperation(int operation);
152   virtual void onStartOperation();
153   virtual void onFinishOperation();
154   virtual void onOperation(QPoint mousePos);
155   virtual void onCursorMove(QPoint mousePos);
156   virtual void setCursor(const int operation);
157
158
159  protected:
160   QCursor                   myDefCursor;
161   QCursor                   myPanCursor;
162   QCursor                   myZoomCursor;
163   QCursor                   myRotateCursor;
164   QCursor                   mySpinCursor;
165   QCursor                   myHandCursor;
166   QCursor                   myGlobalPanCursor;
167   QPoint                    myPoint;
168   QPoint                    myOtherPoint;
169   bool                      myCursorState;
170   bool                      myShiftState;
171   int                       ForcedState;
172   
173   VTKViewer_RenderWindowInteractor* m_Interactor;
174   VTKViewer_ViewWindow*     m_ViewWnd;
175   VTKViewer_Trihedron*      m_Trihedron;
176   QWidget*                  myGUIWindow;
177   
178   std::map<int, Handle(VTKViewer_Filter) > myFilters;
179
180   /**  @name members from old version*/
181   //@{
182   double                    DeltaElevation;
183   double                    DeltaAzimuth;
184   int                       LastPos[2];
185   //@}
186 };
187
188 #endif