Salome HOME
16aa877fd69a15183edec389f6d2ce1b0f1c4f27
[modules/gui.git] / src / VTKViewer / VTKViewer_RenderWindowInteractor.h
1 #ifndef VTKVIEWER_RENDERWINDOWINTERACTOR_H
2 #define VTKVIEWER_RENDERWINDOWINTERACTOR_H
3
4 #include "VTKViewer.h"
5 #include "VTKViewer_Actor.h"
6
7 #include <qtimer.h>
8 #include <qobject.h>
9
10 // Open CASCADE Includes
11 #include <TColStd_MapOfInteger.hxx>
12 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
13 #include <TColStd_IndexedMapOfInteger.hxx>
14
15 class vtkPicker;
16 class vtkCellPicker;
17 class vtkPointPicker;
18 class vtkActorCollection;
19
20 class VTKViewer_Actor;
21 class VTKViewer_ViewWindow;
22 class VTKViewer_RenderWindow;
23 class VTKViewer_InteractorStyle;
24
25 #include "VTKViewer_Algorithm.h"
26
27 #include <vtkActor.h>
28 #include <vtkVersion.h>
29 #include <vtkRenderWindowInteractor.h>
30
31 class VTKVIEWER_EXPORT VTKViewer_RenderWindowInteractor : public QObject, public vtkRenderWindowInteractor
32 {
33   Q_OBJECT
34
35 public:
36   static VTKViewer_RenderWindowInteractor *New();
37
38   vtkTypeMacro(VTKViewer_RenderWindowInteractor,vtkRenderWindowInteractor);
39
40   void PrintSelf(ostream& os, vtkIndent indent);
41
42   virtual void Initialize();
43
44   virtual void               SetInteractorStyle(vtkInteractorObserver *);
45   /*!Return interactor style pointer.*/
46   VTKViewer_InteractorStyle* GetInteractorStyle() const
47   {
48     return myInteractorStyle;
49   }
50
51   virtual void Start();
52   
53   virtual void Enable();
54   virtual void Disable();
55
56   virtual void UpdateSize(int x,int y);
57
58   /** @name Timer options*/
59   //@{
60   virtual int CreateTimer(int ) ;
61   virtual int DestroyTimer() ; 
62   //@}
63   
64   /*! Description:\n
65    * This function is called on 'q','e' keypress if exitmethod is not\n
66    * specified and should be overidden by platform dependent subclasses\n
67    * to provide a termination procedure if one is required.
68    */
69   virtual void TerminateApp(void) { /* empty */ }
70   
71   // Description:
72   // These methods correspond to the the Exit, User and Pick
73   // callbacks. They allow for the Style to invoke them.
74   //virtual void ExitCallback();
75   //virtual void UserCallback();
76   //virtual void StartPickCallback();
77   //virtual void EndPickCallback();
78   
79   /** @name Selection Management */
80   //@{
81   bool highlightCell(const TColStd_IndexedMapOfInteger& MapIndex,
82                      VTKViewer_Actor* theMapActor,
83                      bool hilight,
84                      bool update = true );
85   bool highlightEdge(const TColStd_IndexedMapOfInteger& MapIndex,
86                      VTKViewer_Actor* theMapActor,
87                      bool hilight,
88                      bool update = true );
89   bool highlightPoint(const TColStd_IndexedMapOfInteger& MapIndex,
90                       VTKViewer_Actor* theMapActor,
91                       bool hilight,
92                       bool update = true );
93
94   void unHighlightSubSelection();
95   bool unHighlightAll();
96
97   //void SetSelectionMode(Selection_Mode mode);
98   void SetSelectionProp(const double& theRed = 1, const double& theGreen = 1,
99                         const double& theBlue = 0, const int& theWidth = 5);
100   void SetSelectionTolerance(const double& theTolNodes = 0.025, const double& theTolCell = 0.001);
101   //@}
102
103   /** @name Displaymode management*/
104   //@{
105   int GetDisplayMode();
106   void SetDisplayMode(int);
107   //@}
108
109   /** @name Change all actors to wireframe or surface*/
110   //@{
111   void ChangeRepresentationToWireframe();
112   void ChangeRepresentationToSurface();
113   //@}
114
115   /** @name Change to wireframe or surface a list of vtkactor*/
116   //@{
117   void ChangeRepresentationToWireframe(vtkActorCollection* ListofActors);
118   void ChangeRepresentationToSurface(vtkActorCollection* ListofActors);
119   //@}
120
121   /** @name Erase Display functions*/
122   //@{
123   void EraseAll();
124   void DisplayAll();
125   void RemoveAll( const bool immediatly );
126
127   void Display( VTKViewer_Actor* SActor, bool immediatly = true );
128   void Erase( VTKViewer_Actor* SActor, bool immediatly = true );
129   void Remove( VTKViewer_Actor* SActor, bool updateViewer = true );
130   //@}
131
132   void Update();
133
134   vtkRenderer* GetRenderer();
135
136   void setViewWindow( VTKViewer_ViewWindow* theViewWnd );
137
138   void setCellData(const int& theIndex,
139                    VTKViewer_Actor* theMapActor,
140                    VTKViewer_Actor* theActor) {}
141   void setEdgeData(const int& theCellIndex,
142                    VTKViewer_Actor* theMapActor,
143                    const int& theEdgeIndex,
144                    VTKViewer_Actor* theActor ) {} //NB
145   void setPointData(const int& theIndex,
146                     VTKViewer_Actor* theMapActor,
147                     VTKViewer_Actor* theActor) {}
148
149   typedef void (*TUpdateActor)(const TColStd_IndexedMapOfInteger& theMapIndex,
150                                VTKViewer_Actor* theMapActor,
151                                VTKViewer_Actor* theActor);
152  protected:
153
154   VTKViewer_RenderWindowInteractor();
155   ~VTKViewer_RenderWindowInteractor();
156
157   VTKViewer_InteractorStyle* myInteractorStyle;
158
159   bool highlight(const TColStd_IndexedMapOfInteger& theMapIndex,
160                  VTKViewer_Actor* theMapActor, VTKViewer_Actor* theActor,
161                  TUpdateActor theFun, bool hilight, bool update);
162   void setActorData(const TColStd_IndexedMapOfInteger& theMapIndex,
163                     VTKViewer_Actor* theMapActor,
164                     VTKViewer_Actor *theActor,
165                     TUpdateActor theFun);
166
167   /*! Timer used during various mouse events to figure 
168    * out mouse movements.
169    */
170   QTimer *mTimer ;
171
172   int myDisplayMode;
173
174   //NRI: Selection mode
175   VTKViewer_Actor* myPointActor;
176   VTKViewer_Actor* myEdgeActor;
177   VTKViewer_Actor* myCellActor;
178   void MoveInternalActors();
179
180   vtkPicker* myBasicPicker;
181   vtkCellPicker* myCellPicker;
182   vtkPointPicker* myPointPicker;
183   
184   /*! User for switching to stereo mode.*/
185   int PositionBeforeStereo[2];
186
187  public slots:
188   void MouseMove(QMouseEvent *event) ;
189   void LeftButtonPressed(const QMouseEvent *event) ;
190   void LeftButtonReleased(const QMouseEvent *event) ;
191   void MiddleButtonPressed(const QMouseEvent *event) ;
192   void MiddleButtonReleased(const QMouseEvent *event) ;
193   void RightButtonPressed(const QMouseEvent *event) ;
194   void RightButtonReleased(const QMouseEvent *event) ;
195   void ButtonPressed(const QMouseEvent *event) ;
196   void ButtonReleased(const QMouseEvent *event) ;
197   void KeyPressed(QKeyEvent *event) ;
198
199   private slots:
200     void TimerFunc() ;
201
202 signals:
203   void RenderWindowModified() ;
204   void contextMenuRequested( QContextMenuEvent *e );
205
206 private:
207   friend class VTKViewer_ViewWindow;
208
209   VTKViewer_ViewWindow* myViewWnd;
210   /** Selection node tolerance.*/
211   double       myTolNodes;
212   /** Selection cell tolerance.*/
213   double       myTolItems;
214 };
215
216 #endif