1 // SALOME VTKViewer : build VTK viewer into Salome desktop
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : VTKViewer_InteractorStyle.h
25 // Author : Christophe ATTANASIO
28 #ifndef __VTKViewer_InteractorStyle_h
29 #define __VTKViewer_InteractorStyle_h
31 #include <vtkInteractorStyle.h>
34 class vtkRenderWindowInteractor;
41 #include "VTKViewer.h"
43 #include "VTKViewer_Filter.h"
45 class VTKViewer_Actor;
46 class VTKViewer_Trihedron;
47 class VTKViewer_ViewWindow;
48 class VTKViewer_RenderWindowInteractor;
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
59 class VTKVIEWER_EXPORT VTKViewer_InteractorStyle : public QObject, public vtkInteractorStyle
63 // This class must be supplied with a vtkRenderWindowInteractor wrapper or
64 // parent. This class should not normally be instantiated by application
66 static VTKViewer_InteractorStyle *New();
67 vtkTypeMacro(VTKViewer_InteractorStyle, vtkInteractorStyle);
69 virtual void SetInteractor(vtkRenderWindowInteractor *theInteractor);
70 void setViewWnd(VTKViewer_ViewWindow* theViewWnd);
71 void setGUIWindow(QWidget* theWindow);
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);
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);
86 void OnSelectionModeChanged();
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,
96 const bool theIsNode = false );
98 void IncrementalPan ( const int incrX, const int incrY );
99 void IncrementalZoom ( const int incr );
100 void IncrementalRotate( const int incrX, const int incrY );
102 int CurrentState() const { return State; }
105 VTKViewer_InteractorStyle();
106 ~VTKViewer_InteractorStyle();
107 VTKViewer_InteractorStyle(const VTKViewer_InteractorStyle&) {};
108 void operator=(const VTKViewer_InteractorStyle&) {};
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);
129 float RadianToDegree; // constant: for conv from deg to rad
132 VTKViewer_Actor *myPreViewActor, *myPreSelectionActor, *mySelectedActor;
139 bool eventFilter(QObject* object, QEvent* event);
142 void startGlobalPan();
146 bool needsRedrawing();
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);
161 QCursor myZoomCursor;
162 QCursor myRotateCursor;
163 QCursor mySpinCursor;
164 QCursor myHandCursor;
165 QCursor myGlobalPanCursor;
172 VTKViewer_RenderWindowInteractor* m_Interactor;
173 VTKViewer_ViewWindow* m_ViewWnd;
174 VTKViewer_Trihedron* m_Trihedron;
175 QWidget* myGUIWindow;
177 std::map<int, Handle(VTKViewer_Filter) > myFilters;
179 // members from old version
180 double DeltaElevation;