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