Salome HOME
PROJECT: POST-PROCESSOR 2005 TASK: T 1.5
[modules/kernel.git] / src / VTKViewer / VTKViewer_InteractorStyleSALOME.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_InteractorStyleSALOME.h
25 //  Author : Christophe ATTANASIO
26 //  Module : SALOME
27 //  $Header$
28
29 #ifndef __VTKViewer_InteractorStyleSALOME_h
30 #define __VTKViewer_InteractorStyleSALOME_h
31
32 #include <vtkInteractorStyle.h>
33
34 class vtkCell;
35 class vtkRenderWindowInteractor;
36
37 #include <qobject.h>
38 #include <qcursor.h>
39
40 #include "VTKViewer_Filter.h"
41
42 class SALOME_Actor;
43 class SALOME_CubeAxesActor2D;
44 class VTKViewer_Actor;
45 class VTKViewer_Trihedron;
46 class VTKViewer_ViewFrame;
47 class VTKViewer_RenderWindowInteractor;
48
49 #define VTK_INTERACTOR_STYLE_CAMERA_NONE    0
50 #define VTK_INTERACTOR_STYLE_CAMERA_ROTATE  1
51 #define VTK_INTERACTOR_STYLE_CAMERA_PAN     2
52 #define VTK_INTERACTOR_STYLE_CAMERA_ZOOM    3
53 #define VTK_INTERACTOR_STYLE_CAMERA_SPIN    4
54 #define VTK_INTERACTOR_STYLE_CAMERA_FIT        5
55 #define VTK_INTERACTOR_STYLE_CAMERA_SELECT     6
56 #define VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN 7
57
58 class VTKViewer_InteractorStyleSALOME : public QObject, public vtkInteractorStyle
59 {
60  public:
61   // Description:
62   // This class must be supplied with a vtkRenderWindowInteractor wrapper or
63   // parent. This class should not normally be instantiated by application
64   // programmers.
65   static VTKViewer_InteractorStyleSALOME *New();
66   vtkTypeMacro(VTKViewer_InteractorStyleSALOME, vtkInteractorStyle);
67
68   virtual void SetInteractor(vtkRenderWindowInteractor *theInteractor);
69   void setViewFrame(VTKViewer_ViewFrame* theViewFrame);
70   void setGUIWindow(QWidget* theWindow);
71
72   void setTriedron(VTKViewer_Trihedron* theTrihedron);
73   void setCubeAxes(SALOME_CubeAxesActor2D* theCubeAxes);
74   
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( SALOME_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  protected:
104   VTKViewer_InteractorStyleSALOME();
105   ~VTKViewer_InteractorStyleSALOME();
106   VTKViewer_InteractorStyleSALOME(const VTKViewer_InteractorStyleSALOME&) {};
107   void operator=(const VTKViewer_InteractorStyleSALOME&) {};
108
109   void RotateXY(int dx, int dy);
110   void PanXY(int x, int y, int oldX, int oldY);
111   void DollyXY(int dx, int dy);
112   void SpinXY(int dx, int dy, int oldX, int oldY);
113   void fitRect(const int left, const int top, const int right, const int bottom);
114   void Place(const int theX, const int theY);
115   void TranslateView(int toX, int toY, int fromX, int fromY);
116   bool IsInRect(vtkActor* theActor, 
117                 const int left, const int top, 
118                 const int right, const int bottom);
119   bool IsInRect(vtkCell* theCell, 
120                 const int left, const int top, 
121                 const int right, const int bottom);
122   bool IsInRect(float* thePoint, 
123                 const int left, const int top, 
124                 const int right, const int bottom);
125
126   int State;
127   float MotionFactor;
128   float RadianToDegree;                 // constant: for conv from deg to rad
129   double myScale;
130
131   SALOME_Actor* myPreViewActor;
132
133   VTKViewer_Actor* myPreSelectionActor;
134   SALOME_Actor* mySelectedActor;
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   void onStartOperation();
153   void onFinishOperation();
154   void onOperation(QPoint mousePos);
155   void onCursorMove(QPoint mousePos);
156   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_ViewFrame*      m_ViewFrame;
175   VTKViewer_Trihedron*      m_Trihedron;
176   SALOME_CubeAxesActor2D*   m_CubeAxes;
177   QWidget*                  myGUIWindow;
178   
179   std::map<int, Handle(VTKViewer_Filter)> myFilters;
180
181   //  members from old version
182   double                    DeltaElevation;
183   double                    DeltaAzimuth;
184   int                       LastPos[2];
185 };
186
187 #endif