]> SALOME platform Git repositories - modules/gui.git/blob - src/VTKViewer/VTKViewer_InteractorStyle.h
Salome HOME
a3e36e0976d54ba93f4a7a240225375dd63bfb0f
[modules/gui.git] / src / VTKViewer / VTKViewer_InteractorStyle.h
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  SALOME VTKViewer : build VTK viewer into Salome desktop
23 //  File   : VTKViewer_InteractorStyle.h
24 //  Author : Christophe ATTANASIO
25 //  Module : SALOME
26 //
27 #ifndef __VTKViewer_InteractorStyle_h
28 #define __VTKViewer_InteractorStyle_h
29
30 #include <vtkInteractorStyle.h>
31
32 class vtkCell;
33 class vtkRenderWindowInteractor;
34
35 #include <QObject>
36 #include <QCursor>
37
38 class QRubberBand;
39
40 #include <map>
41
42 #include "VTKViewer.h"
43
44 #include "VTKViewer_Filter.h"
45
46 class VTKViewer_Actor;
47 class VTKViewer_Trihedron;
48 class VTKViewer_ViewWindow;
49 class VTKViewer_RenderWindowInteractor;
50
51 #define VTK_INTERACTOR_STYLE_CAMERA_NONE    0
52 #define VTK_INTERACTOR_STYLE_CAMERA_ROTATE  1
53 #define VTK_INTERACTOR_STYLE_CAMERA_PAN     2
54 #define VTK_INTERACTOR_STYLE_CAMERA_ZOOM    3
55 #define VTK_INTERACTOR_STYLE_CAMERA_SPIN    4
56 #define VTK_INTERACTOR_STYLE_CAMERA_FIT        5
57 #define VTK_INTERACTOR_STYLE_CAMERA_SELECT     6
58 #define VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN 7
59
60 #ifdef WIN32
61 #pragma warning ( disable:4251 )
62 #endif
63
64 /*! Description:\n
65  * This class must be supplied with a vtkRenderWindowInteractor wrapper or\n
66  * parent. This class should not normally be instantiated by application\n
67  * programmers.
68  */
69 class VTKVIEWER_EXPORT VTKViewer_InteractorStyle : public QObject, public vtkInteractorStyle
70 {
71  public:
72   static VTKViewer_InteractorStyle *New();
73   vtkTypeMacro(VTKViewer_InteractorStyle, vtkInteractorStyle);
74
75   virtual void SetInteractor(vtkRenderWindowInteractor *theInteractor);
76   void setViewWnd(VTKViewer_ViewWindow* theViewWnd);
77   void setGUIWindow(QWidget* theWindow);
78
79   void setTriedron(VTKViewer_Trihedron* theTrihedron);
80   void setPreselectionProp(const double& theRed = 0, const double& theGreen = 1,
81                            const double& theBlue = 1, const int& theWidth = 5);
82
83   // Generic event bindings must be overridden in subclasses
84   void OnMouseMove  (int ctrl, int shift, int x, int y);
85   void OnLeftButtonDown(int ctrl, int shift, int x, int y);
86   void OnLeftButtonUp  (int ctrl, int shift, int x, int y);
87   void OnMiddleButtonDown(int ctrl, int shift, int x, int y);
88   void OnMiddleButtonUp  (int ctrl, int shift, int x, int y);
89   void OnRightButtonDown(int ctrl, int shift, int x, int y);
90   void OnRightButtonUp  (int ctrl, int shift, int x, int y);
91
92   void OnSelectionModeChanged();
93
94   void  ViewFitAll();
95
96   void                     SetFilter( const Handle( VTKViewer_Filter)& );
97   Handle(VTKViewer_Filter) GetFilter( const int );  
98   bool                     IsFilterPresent( const int );
99   void                     RemoveFilter( const int );
100   bool                     IsValid( VTKViewer_Actor* theActor,
101                                     const int     theId,
102                                     const bool    theIsNode = false );
103
104   void                     IncrementalPan   ( const int incrX, const int incrY );
105   void                     IncrementalZoom  ( const int incr );
106   void                     IncrementalRotate( const int incrX, const int incrY );
107
108   int                      CurrentState() const { return State; }
109
110  protected:
111   VTKViewer_InteractorStyle();
112   ~VTKViewer_InteractorStyle();
113   VTKViewer_InteractorStyle(const VTKViewer_InteractorStyle&) {};
114   void operator=(const VTKViewer_InteractorStyle&) {};
115
116   void RotateXY(int dx, int dy);
117   void PanXY(int x, int y, int oldX, int oldY);
118   void DollyXY(int dx, int dy);
119   void SpinXY(int dx, int dy, int oldX, int oldY);
120   void fitRect(const int left, const int top, const int right, const int bottom);
121   void Place(const int theX, const int theY);
122   void TranslateView(int toX, int toY, int fromX, int fromY);
123   bool IsInRect(vtkActor* theActor, 
124                 const int left, const int top, 
125                 const int right, const int bottom);
126   bool IsInRect(vtkCell* theCell, 
127                 const int left, const int top, 
128                 const int right, const int bottom);
129   bool IsInRect(vtkFloatingPointType* thePoint, 
130                 const int left, const int top, 
131                 const int right, const int bottom);
132
133   int State;
134   vtkFloatingPointType MotionFactor;
135   vtkFloatingPointType RadianToDegree;                 // constant: for conv from deg to rad
136   double myScale;
137
138   VTKViewer_Actor *myPreViewActor, *myPreSelectionActor, *mySelectedActor;
139
140   int myElemId;
141   int myEdgeId;
142   int myNodeId;
143
144  public:
145   bool eventFilter(QObject* object, QEvent* event);
146   void startZoom();
147   void startPan();
148   void startGlobalPan();
149   void startRotate();
150   void startFitArea();
151   void startSpin();
152   bool needsRedrawing();
153
154  protected:
155   void loadCursors();
156   void startOperation(int operation);
157   virtual void onStartOperation();
158   virtual void onFinishOperation();
159   virtual void onOperation(QPoint mousePos);
160   virtual void onCursorMove(QPoint mousePos);
161   virtual void setCursor(const int operation);
162
163   void drawRect();
164   void endDrawRect();
165
166  protected:
167   QCursor                   myDefCursor;
168   QCursor                   myPanCursor;
169   QCursor                   myZoomCursor;
170   QCursor                   myRotateCursor;
171   QCursor                   mySpinCursor;
172   QCursor                   myHandCursor;
173   QCursor                   myGlobalPanCursor;
174   QPoint                    myPoint;
175   QPoint                    myOtherPoint;
176   bool                      myCursorState;
177   bool                      myShiftState;
178   int                       ForcedState;
179   
180   VTKViewer_RenderWindowInteractor* m_Interactor;
181   VTKViewer_ViewWindow*     m_ViewWnd;
182   VTKViewer_Trihedron*      m_Trihedron;
183   QWidget*                  myGUIWindow;
184   
185   std::map<int, Handle(VTKViewer_Filter) > myFilters;
186
187   QRubberBand* myRectBand; //!< selection rectangle rubber band
188
189   /**  @name members from old version*/
190   //@{
191   double                    DeltaElevation;
192   double                    DeltaAzimuth;
193   int                       LastPos[2];
194   //@}
195 };
196
197 #ifdef WIN32
198 #pragma warning ( default:4251 )
199 #endif
200
201 #endif