]> SALOME platform Git repositories - modules/kernel.git/blob - src/VTKViewer/VTKViewer_RenderWindowInteractor.h
Salome HOME
Initialisation de la base KERNEL avec la version operationnelle de KERNEL_SRC issue...
[modules/kernel.git] / src / VTKViewer / VTKViewer_RenderWindowInteractor.h
1 //  File      : VTKViewer_RenderWindowInteractor.h
2 //  Created   : Wed Mar 20 11:31:36 2002
3 //  Author    : Nicolas REJNERI
4 //  Project   : SALOME
5 //  Module    : VTKViewer
6 //  Copyright : Open CASCADE 2002
7 //  $Header$
8
9 #ifndef VTKViewer_RenderWindowInteractor_h
10 #define VTKViewer_RenderWindowInteractor_h
11
12 //===========================================================
13 // now we define the C++ class
14
15 #include "SALOME_InteractiveObject.hxx"
16 #include "SALOME_Actor.h"
17
18 // QT Includes
19 #include <qobject.h>
20 #include <qtimer.h>
21
22 // VTK Includes
23 #include <vtkVersion.h>
24 #include <vtkRenderWindowInteractor.h>
25 #include <vtkUnstructuredGrid.h>
26
27 // Open CASCADE Includes
28 #include <TColStd_MapOfInteger.hxx>
29 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
30
31 class VTKViewer_RenderWindow ;
32
33 // ------------------------------------------------------------
34 // :TRICKY: Fri Apr 21 22:19:27 2000 Pagey
35 // The Signal/Slot mechanism used by Qt requires that QObject 
36 // appear as the first class when using multiple inheritance. 
37 // Hence the order of the two classes QObject and vtkRenderWindowInteractor
38 // matters here. Be careful not to change it by accident. 
39 // ------------------------------------------------------------
40 class VTK_EXPORT VTKViewer_RenderWindowInteractor : 
41   public QObject, public vtkRenderWindowInteractor
42 {
43   Q_OBJECT 
44 public:
45
46   static VTKViewer_RenderWindowInteractor *New() ; 
47
48   vtkTypeMacro(vtkRenderWindowInteractor,vtkObject);
49
50   void PrintSelf(ostream& os, vtkIndent indent);
51
52   // Description:
53   // Initializes the event handlers without an XtAppContext.  This is
54   // good for when you don`t have a user interface, but you still
55   // want to have mouse interaction.
56   virtual void Initialize();
57
58   // Description:
59   // This will start up the X event loop and never return. If you
60   // call this method it will loop processing X events until the
61   // application is exited.
62   virtual void Start();
63   
64   // Description:
65   // Enable/Disable interactions.  By default interactors are enabled when
66   // initialized.  Initialize() must be called prior to enabling/disabling
67   // interaction. These methods are used when a window/widget is being
68   // shared by multiple renderers and interactors.  This allows a "modal"
69   // display where one interactor is active when its data is to be displayed
70   // and all other interactors associated with the widget are disabled
71   // when their data is not displayed.
72   virtual void Enable();
73   virtual void Disable();
74
75   // Description:
76   // Event loop notification member for Window size change
77   virtual void UpdateSize(int x,int y);
78
79   // Description:
80   // Timer methods must be overridden by platform dependent subclasses.
81   // flag is passed to indicate if this is first timer set or an update
82   // as Win32 uses repeating timers, whereas X uses One shot more timer
83   // if flag==VTKXI_TIMER_FIRST Win32 and X should createtimer
84   // otherwise Win32 should exit and X should perform AddTimeOut()
85   virtual int CreateTimer(int ) ; 
86   virtual int DestroyTimer() ; 
87   
88   // Description:
89   // This function is called on 'q','e' keypress if exitmethod is not
90   // specified and should be overidden by platform dependent subclasses
91   // to provide a termination procedure if one is required.
92   virtual void TerminateApp(void) { /* empty */ }
93   
94   // Description:
95   // These methods correspond to the the Exit, User and Pick
96   // callbacks. They allow for the Style to invoke them.
97   //virtual void ExitCallback();
98   //virtual void UserCallback();
99   //virtual void StartPickCallback();
100   //virtual void EndPickCallback();
101   
102   /* Selection Management */
103   bool highlightCell(const Handle(SALOME_InteractiveObject)& IObject, bool hilight, 
104                      const TColStd_MapOfInteger& MapIndex, bool immediatly = true );
105   bool highlightEdge(const Handle(SALOME_InteractiveObject)& IObject, bool hilight, 
106                      const TColStd_MapOfInteger& MapIndex, bool immediatly = true ); //NB
107   bool highlightPoint(const Handle(SALOME_InteractiveObject)& IObject, bool hilight, 
108                       const TColStd_MapOfInteger& MapIndex, bool immediatly = true );
109
110   bool highlight(const Handle(SALOME_InteractiveObject)& IObject, bool hiligth, bool immediatly = true );
111   bool unHighlightAll();
112   bool isInViewer( const Handle(SALOME_InteractiveObject)& IObject);
113   bool isVisible( const Handle(SALOME_InteractiveObject)& IObject);
114   void rename(const Handle(SALOME_InteractiveObject)& IObject, QString newName);
115
116
117   void SetSelectionMode(int mode);
118
119   // Displaymode management
120   int GetDisplayMode();
121   void SetDisplayMode(int);
122
123   // Switch representation wireframe/shading
124   void SwitchRepresentation(const Handle(SALOME_InteractiveObject)& IObject, bool update = true);
125
126   // Change all actors to wireframe or surface
127   void ChangeRepresentationToWireframe();
128   void ChangeRepresentationToSurface();
129
130   // Change to wireframe or surface a list of vtkactor
131   void ChangeRepresentationToWireframe(vtkActorCollection* ListofActors);
132   void ChangeRepresentationToSurface(vtkActorCollection* ListofActors);
133
134   // Erase Display functions
135   void EraseAll();
136   void DisplayAll();
137   void Erase(const Handle(SALOME_InteractiveObject)& IObject, bool immediatly=true);
138   void Remove(const Handle(SALOME_InteractiveObject)& IObject, bool immediatly=true);
139   void Display(const Handle(SALOME_InteractiveObject)& IObject, bool immediatly=true);
140
141   void Display( SALOME_Actor* SActor, bool immediatly = true );
142
143   // Transparency
144   void SetTransparency(const Handle(SALOME_InteractiveObject)& IObject,float trans);
145   float GetTransparency(const Handle(SALOME_InteractiveObject)& IObject);
146
147   // Color
148   void SetColor(const Handle(SALOME_InteractiveObject)& IObject,QColor thecolor);
149   QColor GetColor(const Handle(SALOME_InteractiveObject)& IObject);
150
151   void Update();
152
153   vtkRenderer* GetRenderer();
154
155  protected:
156
157   VTKViewer_RenderWindowInteractor();
158   ~VTKViewer_RenderWindowInteractor();
159   //
160   // Timer used during various mouse events to figure 
161   // out mouse movements. 
162   //
163   QTimer *mTimer ;
164
165   //CAI: Display mode
166   int displaymode;
167
168   //NRI: Selection mode
169   int selectionmode;
170   vtkActor* Point_Actor;
171   vtkActor* Edge_Actor; //NB
172   vtkActor* Cell_Actor;
173   
174   //
175   // User for switching to stereo mode.
176   //
177   int PositionBeforeStereo[2];
178   //
179   // Connect/disconnect all slots which allow events on the
180   // render window to be passed to the interactor. 
181   //
182   void ConnectSlots() ;
183   void DisconnectSlots() ;
184   void ProcessSlotConnections(bool conn) ;
185
186  public slots:
187   void MouseMove(const QMouseEvent *event) ;
188   void LeftButtonPressed(const QMouseEvent *event) ;
189   void LeftButtonReleased(const QMouseEvent *event) ;
190   void MiddleButtonPressed(const QMouseEvent *event) ;
191   void MiddleButtonReleased(const QMouseEvent *event) ;
192   void RightButtonPressed(const QMouseEvent *event) ;
193   void RightButtonReleased(const QMouseEvent *event) ;
194   void ButtonPressed(const QMouseEvent *event) ;
195   void ButtonReleased(const QMouseEvent *event) ;
196   void KeyPressed(QKeyEvent *event) ;
197
198   private slots:
199     //
200     // Not all of these slots are needed in VTK_MAJOR_VERSION=3,
201     // but moc does not understand "#if VTK_MAJOR_VERSION". Hence, 
202     // we have to include all of these for the time being. Once,
203     // this bug in MOC is fixed, we can separate these. 
204     //
205     void TimerFunc() ;
206  signals:
207   void RenderWindowModified() ;
208 };
209
210 #endif
211