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