Salome HOME
updated copyright message
[modules/gui.git] / src / Prs / SALOME_Prs.h
1 // Copyright (C) 2007-2023  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 SALOME_PRS_H
24 #define SALOME_PRS_H
25
26 #ifdef WIN32
27 #if defined PRS_EXPORTS || defined SalomePrs_EXPORTS
28 #define PRS_EXPORT __declspec(dllexport)
29 #else
30 #define PRS_EXPORT __declspec(dllimport)
31 #endif
32 #else
33 #define PRS_EXPORT
34 #endif
35
36 #include <string>
37 #include <list>
38
39 #include <Standard_DefineHandle.hxx>
40
41 class SALOME_View;
42 class SALOME_Displayer;
43 class SALOME_ListIO;
44 class SALOME_InteractiveObject;
45
46 /*!
47  \class SALOME_Prs
48  Base class for SALOME graphic object wrappers - presentations.
49  Presentations are temporary objects, so they can be created on the stack.
50 */
51
52 class PRS_EXPORT SALOME_Prs
53 {
54 public:
55   //! Constructor
56   explicit SALOME_Prs( const char* );
57  
58   //! Destructor
59   virtual ~SALOME_Prs() {}
60
61   //! Get entry
62   const char* GetEntry() const;
63
64   //! Key method for double dispatch of display operation
65   virtual void DisplayIn( SALOME_View* ) const = 0;
66
67   //! Key method for double dispatch of erase operation
68   virtual void EraseIn( SALOME_View*, const bool = false ) const = 0;
69
70   //! Key method for double dispatch of pre-display operation
71   virtual void BeforeDisplayIn( SALOME_Displayer*, SALOME_View* ) const = 0;
72
73   //! Key method for double dispatch of post-display operation
74   virtual void AfterDisplayIn( SALOME_Displayer*, SALOME_View* ) const = 0;
75
76   //! Key method for double dispatch of pre-erase operation
77   virtual void BeforeEraseIn( SALOME_Displayer*, SALOME_View* ) const = 0;
78
79   //! Key method for double dispatch of post-erase operation
80   virtual void AfterEraseIn( SALOME_Displayer*, SALOME_View* ) const = 0;
81
82   //! Key method for double dispatch of update operation
83   virtual void Update( SALOME_Displayer* ) = 0;
84
85   //! Should return true, if this presentation contains a graphic object
86   virtual bool IsNull() const = 0;
87
88   //! Key method for double dispatch of activation of sub-shapes selection
89   virtual void LocalSelectionIn( SALOME_View*, const int ) const = 0;
90   virtual void LocalSelectionIn( SALOME_View*, const std::list<int> ) const;
91
92     // checks if shape is clippable
93   inline bool IsClippable() const
94   {
95     return myIsClippable;
96   }
97
98   // makes shape clippable/not clippable
99   inline void SetClippable (bool isClippable)
100   {
101     myIsClippable = isClippable;
102   }
103
104 protected:
105   std::string myEntry;
106   bool myIsClippable;
107 };
108
109 /*!
110  \class SALOME_OCCPrs
111  Base class for OpenCASCADE graphic object (AIS_InteractiveObject) wrappers.
112  This intermediate class is necessary to avoid dependencies from OCC libs.
113 */
114
115 class PRS_EXPORT SALOME_OCCPrs : public SALOME_Prs
116 {
117 public:
118   //! Constructor
119   explicit SALOME_OCCPrs(const char* e) : SALOME_Prs(e) {}
120
121   //! It uses double dispatch in order to
122   //! invoke Display() method corresponding to the actual type of presentation.
123   virtual void DisplayIn( SALOME_View* ) const;
124
125   //! It uses double dispatch in order to
126   //! invoke Erase() method corresponding to the actual type of presentation.
127   virtual void EraseIn( SALOME_View*, const bool = false ) const;
128
129   //! It uses double dispatch in order to
130   //! invoke BeforeDisplayIn() method corresponding to the actual type of presentation.
131   virtual void BeforeDisplayIn( SALOME_Displayer*, SALOME_View* ) const;
132
133   //! It uses double dispatch in order to
134   //! invoke AfterDisplayIn() method corresponding to the actual type of presentation.
135   virtual void AfterDisplayIn( SALOME_Displayer*, SALOME_View* ) const;
136
137   //! It uses double dispatch in order to
138   //! invoke BeforeEraseIn() method corresponding to the actual type of presentation.
139   virtual void BeforeEraseIn( SALOME_Displayer*, SALOME_View* ) const;
140
141   //! It uses double dispatch in order to
142   //! invoke AfterEraseIn() method corresponding to the actual type of presentation.
143   virtual void AfterEraseIn( SALOME_Displayer*, SALOME_View* ) const;
144
145   //! It uses double dispatch in order to
146   //! invoke Update() method corresponding to the actual type of presentation.
147   virtual void Update( SALOME_Displayer* );
148
149   //! Key method for double dispatch of activation of sub-shapes selection
150   virtual void LocalSelectionIn( SALOME_View*, const int ) const;
151   virtual void LocalSelectionIn( SALOME_View*, const std::list<int> ) const;
152 };
153
154 /*!
155  \class SALOME_VTKPrs
156  Base class for VTK graphic object (vtkActor) wrappers.
157  This intermediate class is necessary to avoid dependencies from VTK libs.
158 */
159 class PRS_EXPORT SALOME_VTKPrs : public SALOME_Prs
160 {
161 public:
162   //! Constructor
163   explicit SALOME_VTKPrs(const char* e) : SALOME_Prs(e) {}
164
165   //! It uses double dispatch in order to
166   //! invoke Display() method corresponding to the actual type of presentation.
167   virtual void DisplayIn( SALOME_View* ) const;
168
169   //! It uses double dispatch in order to
170   //! invoke Erase() method corresponding to the actual type of presentation.
171   virtual void EraseIn( SALOME_View*, const bool = false ) const;
172
173   //! It uses double dispatch in order to
174   //! invoke BeforeDisplayIn() method corresponding to the actual type of presentation.
175   virtual void BeforeDisplayIn( SALOME_Displayer*, SALOME_View* ) const;
176
177   //! It uses double dispatch in order to
178   //! invoke AfterDisplayIn() method corresponding to the actual type of presentation.
179   virtual void AfterDisplayIn( SALOME_Displayer*, SALOME_View* ) const;
180
181   //! It uses double dispatch in order to
182   //! invoke BeforeEraseIn() method corresponding to the actual type of presentation.
183   virtual void BeforeEraseIn( SALOME_Displayer*, SALOME_View* ) const;
184
185   //! It uses double dispatch in order to
186   //! invoke AfterEraseIn() method corresponding to the actual type of presentation.
187   virtual void AfterEraseIn( SALOME_Displayer*, SALOME_View* ) const;
188
189   //! It uses double dispatch in order to
190   //! invoke Update() method corresponding to the actual type of presentation.
191   virtual void Update( SALOME_Displayer* );
192
193   //! Key method for double dispatch of activation of sub-shapes selection
194   virtual void LocalSelectionIn( SALOME_View*, const int ) const;
195 };
196
197 /*!
198  \class SALOME_PV3DPrs
199  Base class for PV3D graphic object (pqPipelineSource) wrappers.
200  This intermediate class is necessary to avoid dependencies from ParaView libs.
201 */
202
203 class PRS_EXPORT SALOME_PV3DPrs : public SALOME_Prs
204 {
205 public:
206   //! Constructor
207   explicit SALOME_PV3DPrs(const char* e) : SALOME_Prs(e) {}
208
209   //! It uses double dispatch in order to
210   //! invoke Display() method corresponding to the actual type of presentation.
211   virtual void DisplayIn( SALOME_View* ) const;
212
213   //! It uses double dispatch in order to
214   //! invoke Erase() method corresponding to the actual type of presentation.
215   virtual void EraseIn( SALOME_View*, const bool = false ) const;
216
217   //! It uses double dispatch in order to
218   //! invoke BeforeDisplayIn() method corresponding to the actual type of presentation.
219   virtual void BeforeDisplayIn( SALOME_Displayer*, SALOME_View* ) const;
220
221   //! It uses double dispatch in order to
222   //! invoke AfterDisplayIn() method corresponding to the actual type of presentation.
223   virtual void AfterDisplayIn( SALOME_Displayer*, SALOME_View* ) const;
224
225   //! It uses double dispatch in order to
226   //! invoke BeforeEraseIn() method corresponding to the actual type of presentation.
227   virtual void BeforeEraseIn( SALOME_Displayer*, SALOME_View* ) const;
228
229   //! It uses double dispatch in order to
230   //! invoke AfterEraseIn() method corresponding to the actual type of presentation.
231   virtual void AfterEraseIn( SALOME_Displayer*, SALOME_View* ) const;
232
233   //! It uses double dispatch in order to
234   //! invoke Update() method corresponding to the actual type of presentation.
235   virtual void Update( SALOME_Displayer* );
236
237   //! Key method for double dispatch of activation of sub-shapes selection
238   virtual void LocalSelectionIn( SALOME_View*, const int ) const;
239   virtual void LocalSelectionIn( SALOME_View*, const std::list<int> ) const;
240 };
241
242 /*!
243  \class SALOME_Prs2d
244  Base class for Plot2d graphic object (Plot2d_Curve) wrappers.
245 */
246 class PRS_EXPORT SALOME_Prs2d : public SALOME_Prs
247 {
248 public:
249   //! Constructor
250   explicit SALOME_Prs2d(const char* e) : SALOME_Prs(e) {}
251
252   //! It uses double dispatch in order to
253   //! invoke Display() method corresponding to the actual type of presentation.
254   virtual void DisplayIn( SALOME_View* ) const;
255
256   //! It uses double dispatch in order to
257   //! invoke Erase() method corresponding to the actual type of presentation.
258   virtual void EraseIn( SALOME_View*, const bool = false ) const;
259
260   //! It uses double dispatch in order to
261   //! invoke BeforeDisplayIn() method corresponding to the actual type of presentation.
262   virtual void BeforeDisplayIn( SALOME_Displayer*, SALOME_View* ) const;
263
264   //! It uses double dispatch in order to
265   //! invoke AfterDisplayIn() method corresponding to the actual type of presentation.
266   virtual void AfterDisplayIn( SALOME_Displayer*, SALOME_View* ) const;
267
268   //! It uses double dispatch in order to
269   //! invoke BeforeEraseIn() method corresponding to the actual type of presentation.
270   virtual void BeforeEraseIn( SALOME_Displayer*, SALOME_View* ) const;
271
272   //! It uses double dispatch in order to
273   //! invoke AfterEraseIn() method corresponding to the actual type of presentation.
274   virtual void AfterEraseIn( SALOME_Displayer*, SALOME_View* ) const;
275
276   //! It uses double dispatch in order to
277   //! invoke Update() method corresponding to the actual type of presentation.
278   virtual void Update( SALOME_Displayer* );
279
280   //! Key method for double dispatch of activation of sub-shapes selection
281   virtual void LocalSelectionIn( SALOME_View*, const int ) const;
282 };
283
284 /*!
285   Base classes for object wrappers for any other visualization libraries should be added here!
286 */
287 /*!
288  \class SALOME_View
289  Base class for SALOME views (or view frames)
290 */
291 class PRS_EXPORT SALOME_View
292 {
293 public:
294   //! Destructor
295   virtual ~SALOME_View() {}
296
297   //! This Display() method should be called to display given presentation
298   //! created anywhere by anybody. It simply passes control to SALOME_Prs object
299   //! so that it could perform double dispatch.
300   void Display( SALOME_Displayer*, const SALOME_Prs* );
301
302   //! This Erase() method should be called to erase given presentation
303   //! created anywhere by anybody. It simply passes control to SALOME_Prs object
304   //! so that it could perform double dispatch.
305   void Erase( SALOME_Displayer*, const SALOME_Prs*, const bool = false );
306
307   //! This EraseAll() method should be called to erase all presentations
308   //! created anywhere by anybody.
309   virtual void EraseAll( SALOME_Displayer*, const bool = false );
310
311   //! This LocalSelection() method should be called to activate sub-shapes selection
312   //! created anywhere by anybody. It simply passes control to SALOME_Prs object
313   //! so that it could perform double dispatch.
314   void LocalSelection( const SALOME_Prs*, const int );
315   void LocalSelection( const SALOME_Prs*, const std::list<int> );
316
317   // Interface for derived views
318
319   // Display() methods for ALL kinds of presentation should appear here
320   virtual void Display( const SALOME_OCCPrs* );//!< Display SALOME_OCCPrs presentation.
321   virtual void Display( const SALOME_VTKPrs* );//!< Display SALOME_VTKPrs presentation.
322   virtual void Display( const SALOME_PV3DPrs* );//!< Display SALOME_PV3DPrs presentation.
323   virtual void Display( const SALOME_Prs2d*  );//!< Display SALOME_Prs2d  presentation.
324   // Add new Display() methods here...
325
326   // Erase() methods for ALL kinds of presentation should appear here
327   virtual void Erase( const SALOME_OCCPrs*, const bool = false );//!< Erase SALOME_OCCPrs
328   virtual void Erase( const SALOME_VTKPrs*, const bool = false );//!< Erase SALOME_VTKPrs
329   virtual void Erase( const SALOME_PV3DPrs*, const bool = false );//!< Erase SALOME_PV3DPrs
330   virtual void Erase( const SALOME_Prs2d*,  const bool = false );//!< Erase SALOME_Prs2d
331   // Add new Erase() methods here...
332
333   // LocalSelection() methods for ALL kinds of presentation should appear here
334   virtual void LocalSelection( const SALOME_OCCPrs*, const int );           //!< Local selection SALOME_OCCPrs
335   virtual void LocalSelection( const SALOME_OCCPrs*, const std::list<int> );//!< Multiple local selection SALOME_OCCPrs
336   virtual void LocalSelection( const SALOME_VTKPrs*, const int );           //!< Local selection SALOME_VTKPrs
337   virtual void LocalSelection( const SALOME_PV3DPrs*, const int );          //!< Local selection SALOME_PV3DPrs
338   virtual void LocalSelection( const SALOME_Prs2d* , const int );           //!< Local selection SALOME_Prs2d
339
340   //! Deactivates selection of sub-shapes (must be redefined with OCC viewer)
341   virtual void GlobalSelection( const bool = false ) const;
342
343   //! Creates empty presentation of corresponding type
344   virtual SALOME_Prs* CreatePrs( const char* /*entry*/ = 0 ) { return 0; }
345
346   // Axiluary methods called before and after displaying of objects
347   virtual void BeforeDisplay( SALOME_Displayer*, const SALOME_Prs* );
348   virtual void AfterDisplay ( SALOME_Displayer*, const SALOME_Prs* );
349
350   // Axiluary methods called before and after erasing of objects
351   virtual void BeforeErase( SALOME_Displayer*, const SALOME_Prs* );
352   virtual void AfterErase ( SALOME_Displayer*, const SALOME_Prs* );
353
354   // New methods (asv)
355   //! \retval Return false.
356   virtual bool isVisible( const Handle(SALOME_InteractiveObject)& ){ return false; }
357   virtual void Repaint() {} //!< Null body here.
358   virtual void GetVisible( SALOME_ListIO& /*theList*/ ) {}
359 };
360
361 /*!
362  \class SALOME_Displayer
363  Base class for SALOME displayers
364 */
365 class PRS_EXPORT SALOME_Displayer
366 {
367 public:
368   //! Destructor
369   virtual ~SALOME_Displayer() {/*! Null body here*/}
370
371   //! This Update() method should be called to update given presentation
372   //! created anywhere by anybody. It simply passes control to SALOME_Prs object
373   //! so that it could perform double dispatch.
374   void UpdatePrs( SALOME_Prs* );
375
376   // Interface for derived displayers
377
378   // Update() methods for ALL kinds of presentation should appear here
379   virtual void Update( SALOME_OCCPrs* );//!< Update SALOME_OCCPrs presentation.
380   virtual void Update( SALOME_VTKPrs* );//!< Update SALOME_VTKPrs presentation.
381   virtual void Update( SALOME_PV3DPrs* );//!< Update SALOME_PV3DPrs presentation.
382   virtual void Update( SALOME_Prs2d* );//!< Update SALOME_Prs2d presentation.
383   // Add new Update() methods here...
384
385   // Auxiliary methods called before and after displaying of objects
386   virtual void BeforeDisplay( SALOME_View*, const SALOME_OCCPrs* ) {} //! Null body here
387   virtual void AfterDisplay ( SALOME_View*, const SALOME_OCCPrs* ) {} //! Null body here
388   virtual void BeforeDisplay( SALOME_View*, const SALOME_VTKPrs* ) {} //! Null body here
389   virtual void AfterDisplay ( SALOME_View*, const SALOME_VTKPrs* ) {} //! Null body here
390   virtual void BeforeDisplay( SALOME_View*, const SALOME_PV3DPrs* ) {} //! Null body here
391   virtual void AfterDisplay ( SALOME_View*, const SALOME_PV3DPrs* ) {} //! Null body here
392   virtual void BeforeDisplay( SALOME_View*, const SALOME_Prs2d*  ) {} //! Null body here
393   virtual void AfterDisplay ( SALOME_View*, const SALOME_Prs2d*  ) {} //! Null body here
394
395   // Auxiliary methods called before and after erasing of objects
396   virtual void BeforeErase( SALOME_View*, const SALOME_OCCPrs* ) {} //! Null body here
397   virtual void AfterErase ( SALOME_View*, const SALOME_OCCPrs* ) {} //! Null body here
398   virtual void BeforeErase( SALOME_View*, const SALOME_VTKPrs* ) {} //! Null body here
399   virtual void AfterErase ( SALOME_View*, const SALOME_VTKPrs* ) {} //! Null body here
400   virtual void BeforeErase( SALOME_View*, const SALOME_PV3DPrs* ) {} //! Null body here
401   virtual void AfterErase ( SALOME_View*, const SALOME_PV3DPrs* ) {} //! Null body here
402   virtual void BeforeErase( SALOME_View*, const SALOME_Prs2d*  ) {} //! Null body here
403   virtual void AfterErase ( SALOME_View*, const SALOME_Prs2d*  ) {} //! Null body here
404
405   // Auxiliary method called to update visibility state of presentation
406   virtual void UpdateVisibility( SALOME_View*, const SALOME_Prs*, bool );
407 };
408
409 #endif