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