Salome HOME
31e1404d66ed81078d4d87b5012da9b53f3fd4ca
[modules/gui.git] / src / SVTK / SVTK_View.h
1 // Copyright (C) 2007-2022  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  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, or (at your option) any later version.
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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #ifndef SVTK_VIEW_H
24 #define SVTK_VIEW_H
25
26 #ifdef WIN32
27 #pragma warning( disable:4251 )
28 #endif
29
30 #include "SVTK.h"
31
32 #include <SALOME_InteractiveObject.hxx>
33 #include <SALOME_ListIO.hxx>
34
35 #include <QObject>
36
37 class vtkActorCollection;
38 class vtkRenderer;
39 class vtkProperty;
40
41 class SVTK_ViewWindow;
42 class SVTK_Renderer;
43
44 class SALOME_Actor;
45
46 class QMouseEvent;
47 class QWheelEvent;
48 class QKeyEvent;
49 class QContextMenuEvent;
50 class QColor;
51
52
53 //! Main purpose of the class is to provide a way to customize #SVTK_ViewWindow.
54 /*!
55   This class is initialized by #SVTK_ViewWindow and just pass Qt signals from 
56   corresponding #SVTK_RenderWindowInteractor of the #SVTK_ViewWindow.
57   Its main purpose is to provide a simple and flexible way to customize the #SVTK_ViewWindow.
58   So, in your own viewer it is possible to derive new #SVTK_ViewWindow and 
59   use existing functionality without any modifications.
60  */
61 class SVTK_EXPORT SVTK_SignalHandler : public QObject
62 {
63   Q_OBJECT
64
65 public:
66   SVTK_SignalHandler(SVTK_ViewWindow* theMainWindow);
67
68   virtual
69   ~SVTK_SignalHandler();
70
71   //! Get reference to its #SVTK_ViewWindow
72   SVTK_ViewWindow*
73   GetMainWindow();
74
75   //----------------------------------------------------------------------------
76   //! Redirect the request to #SVTK_ViewWindow::Repaint (just for flexibility)
77   void
78   Repaint(bool theUpdateTrihedron = true);
79
80   //----------------------------------------------------------------------------
81   //! Redirect the request to #SVTK_ViewWindow::GetRenderer (just for flexibility)
82   SVTK_Renderer* 
83   GetRenderer();
84
85   //! Redirect the request to #SVTK_ViewWindow::getRenderer (just for flexibility)
86   vtkRenderer* 
87   getRenderer();
88
89   //----------------------------------------------------------------------------
90  public slots:
91   void onSelectionChanged();
92
93  public:
94  signals:
95   void MouseMove( QMouseEvent* );
96   void MouseButtonPressed( QMouseEvent* );
97   void MouseButtonReleased( QMouseEvent* );
98   void MouseDoubleClicked( QMouseEvent* );
99   void ButtonPressed(const QMouseEvent *event);
100   void ButtonReleased(const QMouseEvent *event);
101   void WheelMoved( QWheelEvent* );
102   void KeyPressed( QKeyEvent* );
103   void KeyReleased( QKeyEvent* );
104   void contextMenuRequested( QContextMenuEvent *e );
105   void selectionChanged();
106
107  protected:
108   SVTK_ViewWindow* myMainWindow;
109 };
110
111
112 //! This class is introduced just for compatibility with old code.
113 /*!
114   This class contains frequantly used functionality in old code.
115   Now, you are supposed to extend existing functionality through
116   writing corresponding functors (see SVTK_Functor.h for example).
117  */
118 class SVTK_EXPORT SVTK_View : public SVTK_SignalHandler
119 {
120   Q_OBJECT
121
122 public:
123   SVTK_View(SVTK_ViewWindow* theMainWindow);
124
125   virtual
126   ~SVTK_View();
127   
128   /*  interactive object management */
129   //! To highlight a VTK presentation with the same #SALOME_InteractiveObject
130   void
131   highlight(const Handle(SALOME_InteractiveObject)& IObject, 
132             bool highlight, 
133             bool immediatly = true);
134
135   //! To unhighlight all VTK presentations
136   void
137   unHighlightAll();
138
139   //! Try to find a SALOME_InteractiveObject in the view that corresponds to the entry
140   Handle(SALOME_InteractiveObject) 
141   FindIObject(const char* Entry);
142
143   //! Check, if the viewer contains a presentatin with defined #SALOME_InteractiveObject
144   bool
145   isInViewer(const Handle(SALOME_InteractiveObject)& IObject);
146
147   //! Check, if a presentatin with defined #SALOME_InteractiveObject is visible
148   bool
149   isVisible(const Handle(SALOME_InteractiveObject)& IObject);
150
151   void
152   rename(const Handle(SALOME_InteractiveObject)& IObject, 
153          const QString& newName);
154   
155   //----------------------------------------------------------------------------
156   // Displaymode management
157   //! Get current display mode (obsolete)
158   int 
159   GetDisplayMode();
160
161   //! Set current display mode
162   void
163   SetDisplayMode(int);
164
165   //! Switch representation wireframe/shading
166   void
167   SetDisplayMode(const Handle(SALOME_InteractiveObject)& IObject, 
168                  int theMode);
169
170   //! Change all actors to wireframe
171   void 
172   ChangeRepresentationToWireframe();
173
174   //! Change all actors to surface
175   void
176   ChangeRepresentationToSurface();
177
178   //! Change all actors to surface with edges
179   void
180   ChangeRepresentationToSurfaceWithEdges();
181
182   //! Change to wireframe a list of vtkactor
183   void
184   ChangeRepresentationToWireframe(vtkActorCollection* theListofActors);
185
186   //! Change to surface a list of vtkactor
187   void
188   ChangeRepresentationToSurface(vtkActorCollection* theListofActors);
189
190   //! Change to surface with edges a list of vtkactor
191   void
192   ChangeRepresentationToSurfaceWithEdges(vtkActorCollection* theListofActors);
193
194   //! Change transparency
195   void
196   SetTransparency(const Handle(SALOME_InteractiveObject)& theIObject,
197                   float trans);
198
199   //! Get current transparency
200   float 
201   GetTransparency(const Handle(SALOME_InteractiveObject)& theIObject);
202
203   //! Change color
204   void
205   SetColor(const Handle(SALOME_InteractiveObject)& theIObject,
206            const QColor& theColor);
207
208   //! Get current color
209   QColor
210   GetColor(const Handle(SALOME_InteractiveObject)& theIObject);
211
212   //! Change material
213   void
214   SetMaterial(const Handle(SALOME_InteractiveObject)& theIObject,
215               vtkProperty* thePropF, vtkProperty* thePropB);
216
217   //! Get current front material
218   vtkProperty* 
219   GetFrontMaterial(const Handle(SALOME_InteractiveObject)& theIObject);
220
221   //! Get current back material
222   vtkProperty* 
223   GetBackMaterial(const Handle(SALOME_InteractiveObject)& theIObject);
224
225   //----------------------------------------------------------------------------
226   // Erase Display functions
227   //! To erase all existing VTK presentations
228   void
229   EraseAll();
230
231   //! To display all existing VTK presentations
232   void
233   DisplayAll();
234
235   //! To remove from the view all existing VTK presentations
236   void
237   RemoveAll( const bool immediatly );
238
239   //! To erase VTK presentation with defined #SALOME_InteractiveObject
240   void
241   Erase(const Handle(SALOME_InteractiveObject)& IObject, 
242         bool immediatly = true);
243   void
244   Remove(const Handle(SALOME_InteractiveObject)& IObject, 
245          bool immediatly = true);
246
247   //! To display VTK presentation with defined #SALOME_InteractiveObject
248   void
249   Display(const Handle(SALOME_InteractiveObject)& IObject, 
250           bool immediatly = true);
251
252   //! To display VTK presentation with defined #SALOME_InteractiveObject and erase all anothers
253   void
254   DisplayOnly(const Handle(SALOME_InteractiveObject)& IObject);
255
256   //! To display the VTK presentation
257   void
258   Display(SALOME_Actor* SActor, 
259           bool immediatly = true);
260
261   //! To erase the VTK presentation
262   void
263   Erase(SALOME_Actor* SActor, 
264         bool immediatly = true);
265
266   //! To remove the VTK presentation
267   void
268   Remove(SALOME_Actor* SActor, 
269          bool updateViewer = true);
270
271   //! Collect objects visible in viewer
272   void
273   GetVisible( SALOME_ListIO& theList );
274
275   //----------------------------------------------------------------------------
276   //! Redirect the request to #SVTK_Renderer::SetPreselectionProp
277   void
278   SetSelectionProp(const double& theRed = 1, 
279                    const double& theGreen = 1,
280                    const double& theBlue = 0, 
281                    const int& theWidth = 5);
282
283   //! Redirect the request to #SVTK_Renderer::SetPreselectionProp
284   void
285   SetPreselectionProp(const double& theRed = 0, 
286                       const double& theGreen = 1,
287                       const double& theBlue = 1, 
288                       const int& theWidth = 5);
289
290   //! Redirect the request to #SVTK_Renderer::SetPreselectionProp
291   void
292   SetSelectionTolerance(const double& theTolNodes = 0.025, 
293                         const double& theTolCell = 0.001,
294                         const double& theTolObjects = 0.025);
295
296  protected:  
297   int myDisplayMode;
298 };
299
300 #ifdef WIN32
301 #pragma warning( default:4251 )
302 #endif
303
304 #endif