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