Salome HOME
Porting to Mandrake 10.1 and new products:
[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   void                     IncrementalPan   ( const int incrX, const int incrY );
97   void                     IncrementalZoom  ( const int incr );
98   void                     IncrementalRotate( const int incrX, const int incrY );
99
100  protected:
101   VTKViewer_InteractorStyleSALOME();
102   ~VTKViewer_InteractorStyleSALOME();
103   VTKViewer_InteractorStyleSALOME(const VTKViewer_InteractorStyleSALOME&) {};
104   void operator=(const VTKViewer_InteractorStyleSALOME&) {};
105
106   void RotateXY(int dx, int dy);
107   void PanXY(int x, int y, int oldX, int oldY);
108   void DollyXY(int dx, int dy);
109   void SpinXY(int dx, int dy, int oldX, int oldY);
110   void fitRect(const int left, const int top, const int right, const int bottom);
111   void Place(const int theX, const int theY);
112   void TranslateView(int toX, int toY, int fromX, int fromY);
113   bool IsInRect(vtkActor* theActor, 
114                 const int left, const int top, 
115                 const int right, const int bottom);
116   bool IsInRect(vtkCell* theCell, 
117                 const int left, const int top, 
118                 const int right, const int bottom);
119   bool IsInRect(float* thePoint, 
120                 const int left, const int top, 
121                 const int right, const int bottom);
122
123   int State;
124   float MotionFactor;
125   float RadianToDegree;                 // constant: for conv from deg to rad
126   double myScale;
127
128   SALOME_Actor* myPreViewActor;
129
130   VTKViewer_Actor* myPreSelectionActor;
131   SALOME_Actor* mySelectedActor;
132   int myElemId;
133   int myEdgeId;
134   int myNodeId;
135
136  public:
137   bool eventFilter(QObject* object, QEvent* event);
138   void startZoom();
139   void startPan();
140   void startGlobalPan();
141   void startRotate();
142   void startFitArea();
143   void startSpin();
144   bool needsRedrawing();
145
146  protected:
147   void loadCursors();
148   void startOperation(int operation);
149   void onStartOperation();
150   void onFinishOperation();
151   void onOperation(QPoint mousePos);
152   void onCursorMove(QPoint mousePos);
153   void setCursor(const int operation);
154
155
156  protected:
157   QCursor                   myDefCursor;
158   QCursor                   myPanCursor;
159   QCursor                   myZoomCursor;
160   QCursor                   myRotateCursor;
161   QCursor                   mySpinCursor;
162   QCursor                   myHandCursor;
163   QCursor                   myGlobalPanCursor;
164   QPoint                    myPoint;
165   QPoint                    myOtherPoint;
166   bool                      myCursorState;
167   bool                      myShiftState;
168   int                       ForcedState;
169   
170   VTKViewer_RenderWindowInteractor* m_Interactor;
171   VTKViewer_ViewFrame*      m_ViewFrame;
172   VTKViewer_Trihedron*      m_Trihedron;
173   QWidget*                  myGUIWindow;
174   
175   std::map<int, Handle(VTKViewer_Filter)> myFilters;
176
177   //  members from old version
178   double                    DeltaElevation;
179   double                    DeltaAzimuth;
180   int                       LastPos[2];
181 };
182
183 #endif