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