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