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