0028564: Support of applications using old persistence (ShapeSchema)
[occt.git] / src / ShapePersistent / ShapePersistent_Geom_Surface.hxx
1 // Copyright (c) 2015 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14
15 #ifndef _ShapePersistent_Geom_Surface_HeaderFile
16 #define _ShapePersistent_Geom_Surface_HeaderFile
17
18 #include <StdObjMgt_TransientPersistentMap.hxx>
19
20 #include <ShapePersistent_Geom.hxx>
21 #include <ShapePersistent_HArray2.hxx>
22 #include <StdLPersistent_HArray1.hxx>
23 #include <StdLPersistent_HArray2.hxx>
24
25 #include <Geom_Plane.hxx>
26 #include <Geom_ConicalSurface.hxx>
27 #include <Geom_CylindricalSurface.hxx>
28 #include <Geom_SphericalSurface.hxx>
29 #include <Geom_ToroidalSurface.hxx>
30 #include <Geom_SurfaceOfLinearExtrusion.hxx>
31 #include <Geom_SurfaceOfRevolution.hxx>
32 #include <Geom_BezierSurface.hxx>
33 #include <Geom_BSplineSurface.hxx>
34 #include <Geom_RectangularTrimmedSurface.hxx>
35 #include <Geom_OffsetSurface.hxx>
36
37 #include <gp_Ax3.hxx>
38 #include <gp_Cone.hxx>
39 #include <gp_Cylinder.hxx>
40 #include <gp_Sphere.hxx>
41 #include <gp_Torus.hxx>
42
43 class gp_Dir;
44 class gp_Pnt;
45
46
47 class ShapePersistent_Geom_Surface : private ShapePersistent_Geom
48 {
49   typedef Surface::PersistentBase pBase;
50
51   class pSweptData
52   {
53     friend class ShapePersistent_Geom_Surface;
54
55   public:
56     inline void Read (StdObjMgt_ReadData& theReadData)
57       { theReadData >> myBasisCurve >> myDirection; }
58     inline void Write (StdObjMgt_WriteData& theWriteData) const
59       { theWriteData << myBasisCurve << myDirection; }
60     inline void PChildren(StdObjMgt_Persistent::SequenceOfPersistent& theChildren) const
61       { theChildren.Append(myBasisCurve); }
62
63   protected:
64     Handle(Curve) myBasisCurve;
65     gp_Dir        myDirection;
66   };
67
68   struct pSwept : pBase, pSweptData 
69   {
70     inline Standard_CString PName() const 
71       { return "PGeom_SweptSurface"; }
72   };
73
74   class pLinearExtrusion : public pSwept
75   {
76     friend class ShapePersistent_Geom_Surface;
77
78   public:
79     virtual Handle(Geom_Surface) Import() const;
80     inline Standard_CString PName() const 
81       { return "PGeom_SurfaceOfLinearExtrusion"; }
82   };
83
84   class pRevolution : public pSwept
85   {
86     friend class ShapePersistent_Geom_Surface;
87
88   public:
89     inline void Read (StdObjMgt_ReadData& theReadData)
90     {
91       pSwept::Read (theReadData);
92       theReadData >> myLocation;
93     }
94     inline void Write (StdObjMgt_WriteData& theWriteData) const
95     {
96       pSwept::Write(theWriteData);
97       theWriteData << myLocation;
98     }
99     inline Standard_CString PName() const 
100       { return "PGeom_SurfaceOfRevolution"; }
101
102     virtual Handle(Geom_Surface) Import() const;
103
104   private:
105     gp_Pnt myLocation;
106   };
107
108   typedef pBase pBounded;
109
110   class pBezier : public pBounded
111   {
112     friend class ShapePersistent_Geom_Surface;
113
114   public:
115     inline void Read (StdObjMgt_ReadData& theReadData)
116       { theReadData >> myURational >> myVRational >> myPoles >> myWeights; }
117     inline void Write (StdObjMgt_WriteData& theWriteData) const
118       { theWriteData << myURational << myVRational << myPoles << myWeights; }
119     inline void PChildren(StdObjMgt_Persistent::SequenceOfPersistent& theChildren) const
120     {
121       theChildren.Append(myPoles);
122       theChildren.Append(myWeights);
123     }
124     inline Standard_CString PName() const 
125       { return "PGeom_BezierSurface"; }
126
127     virtual Handle(Geom_Surface) Import() const;
128
129   private:
130     Standard_Boolean                     myURational;
131     Standard_Boolean                     myVRational;
132     Handle(ShapePersistent_HArray2::Pnt) myPoles;
133     Handle(StdLPersistent_HArray2::Real) myWeights;
134   };
135
136   class pBSpline : public pBounded
137   {
138     friend class ShapePersistent_Geom_Surface;
139
140   public:
141     inline void Read (StdObjMgt_ReadData& theReadData)
142     {
143       theReadData >> myURational >> myVRational;
144       theReadData >> myUPeriodic >> myVPeriodic;
145       theReadData >> myUSpineDegree >> myVSpineDegree;
146       theReadData >> myPoles;
147       theReadData >> myWeights;
148       theReadData >> myUKnots >> myVKnots;
149       theReadData >> myUMultiplicities >> myVMultiplicities;
150     }
151     inline void Write (StdObjMgt_WriteData& theWriteData) const
152     {
153       theWriteData << myURational << myVRational;
154       theWriteData << myUPeriodic << myVPeriodic;
155       theWriteData << myUSpineDegree << myVSpineDegree;
156       theWriteData << myPoles;
157       theWriteData << myWeights;
158       theWriteData << myUKnots << myVKnots;
159       theWriteData << myUMultiplicities << myVMultiplicities;
160     }
161     inline void PChildren(StdObjMgt_Persistent::SequenceOfPersistent& theChildren) const
162     {
163       theChildren.Append(myPoles);
164       theChildren.Append(myWeights);
165       theChildren.Append(myUKnots);
166       theChildren.Append(myVKnots);
167       theChildren.Append(myUMultiplicities);
168       theChildren.Append(myVMultiplicities);
169     }
170     inline Standard_CString PName() const 
171       { return "PGeom_BSplineSurface"; }
172
173     virtual Handle(Geom_Surface) Import() const;
174
175   private:
176     Standard_Boolean                        myURational;
177     Standard_Boolean                        myVRational;
178     Standard_Boolean                        myUPeriodic;
179     Standard_Boolean                        myVPeriodic;
180     Standard_Integer                        myUSpineDegree;
181     Standard_Integer                        myVSpineDegree;
182     Handle(ShapePersistent_HArray2::Pnt)    myPoles;
183     Handle(StdLPersistent_HArray2::Real)    myWeights;
184     Handle(StdLPersistent_HArray1::Real)    myUKnots;
185     Handle(StdLPersistent_HArray1::Real)    myVKnots;
186     Handle(StdLPersistent_HArray1::Integer) myUMultiplicities;
187     Handle(StdLPersistent_HArray1::Integer) myVMultiplicities;
188   };
189
190   class pRectangularTrimmed : public pBounded
191   {
192     friend class ShapePersistent_Geom_Surface;
193
194   public:
195     inline void Read (StdObjMgt_ReadData& theReadData)
196     {
197       theReadData >> myBasisSurface;
198       theReadData >> myFirstU >> myLastU >> myFirstV >> myLastV;
199     }
200     inline void Write (StdObjMgt_WriteData& theWriteData) const
201     {
202       theWriteData << myBasisSurface;
203       theWriteData << myFirstU << myLastU << myFirstV << myLastV;
204     }
205     inline void PChildren(StdObjMgt_Persistent::SequenceOfPersistent& theChildren) const
206       { theChildren.Append(myBasisSurface); }
207     inline Standard_CString PName() const 
208       { return "PGeom_RectangularTrimmedSurface"; }
209
210     virtual Handle(Geom_Surface) Import() const;
211
212   private:
213     Handle(Surface) myBasisSurface;
214     Standard_Real   myFirstU;
215     Standard_Real   myLastU;
216     Standard_Real   myFirstV;
217     Standard_Real   myLastV;
218   };
219
220   class pOffset : public pBase
221   {
222     friend class ShapePersistent_Geom_Surface;
223
224   public:
225     inline void Read (StdObjMgt_ReadData& theReadData)
226       { theReadData >> myBasisSurface >> myOffsetValue; }
227     inline void Write (StdObjMgt_WriteData& theWriteData) const
228       { theWriteData << myBasisSurface << myOffsetValue; }
229     inline void PChildren(StdObjMgt_Persistent::SequenceOfPersistent& theChildren) const
230       { theChildren.Append(myBasisSurface); }
231     inline Standard_CString PName() const 
232       { return "PGeom_OffsetSurface"; }
233
234     virtual Handle(Geom_Surface) Import() const;
235
236   private:
237     Handle(Surface) myBasisSurface;
238     Standard_Real   myOffsetValue;
239   };
240
241 public:
242   typedef subBase_gp<Surface, gp_Ax3>                                Elementary;
243   typedef instance<Elementary, Geom_Plane             , gp_Ax3>      Plane;
244   typedef instance<Elementary, Geom_ConicalSurface    , gp_Cone>     Conical;
245   typedef instance<Elementary, Geom_CylindricalSurface, gp_Cylinder> Cylindrical;
246   typedef instance<Elementary, Geom_SphericalSurface  , gp_Sphere>   Spherical;
247   typedef instance<Elementary, Geom_ToroidalSurface   , gp_Torus>    Toroidal;
248
249   typedef subBase<Surface, pSweptData>                               Swept;
250   typedef Delayed<Swept, pLinearExtrusion>                           LinearExtrusion;
251   typedef Delayed<Swept, pRevolution>                                Revolution;
252
253   typedef subBase_empty<Surface>                                     Bounded;
254   typedef Delayed<Bounded, pBezier>                                  Bezier;
255   typedef Delayed<Bounded, pBSpline>                                 BSpline;
256   typedef Delayed<Bounded, pRectangularTrimmed>                      RectangularTrimmed;
257
258   typedef Delayed<Surface, pOffset>                                  Offset;
259
260 public:
261   //! Create a persistent object for a plane
262   Standard_EXPORT static Handle(Surface) Translate (const Handle(Geom_Plane)& theSurf,
263                                                     StdObjMgt_TransientPersistentMap& theMap);
264   //! Create a persistent object for a cylinder
265   Standard_EXPORT static Handle(Surface) Translate (const Handle(Geom_CylindricalSurface)& theSurf,
266                                                     StdObjMgt_TransientPersistentMap& theMap);
267   //! Create a persistent object for a cone
268   Standard_EXPORT static Handle(Surface) Translate (const Handle(Geom_ConicalSurface)& theSurf,
269                                                     StdObjMgt_TransientPersistentMap& theMap);
270   //! Create a persistent object for a sphere
271   Standard_EXPORT static Handle(Surface) Translate (const Handle(Geom_SphericalSurface)& theSurf,
272                                                     StdObjMgt_TransientPersistentMap& theMap);
273   //! Create a persistent object for a torus
274   Standard_EXPORT static Handle(Surface) Translate (const Handle(Geom_ToroidalSurface)& theSurf,
275                                                     StdObjMgt_TransientPersistentMap& theMap);
276   //! Create a persistent object for a surface of linear extrusion
277   Standard_EXPORT static Handle(Surface) Translate (const Handle(Geom_SurfaceOfLinearExtrusion)& theSurf,
278                                                     StdObjMgt_TransientPersistentMap& theMap);
279   //! Create a persistent object for a surface of evolution
280   Standard_EXPORT static Handle(Surface) Translate (const Handle(Geom_SurfaceOfRevolution)& theSurf,
281                                                     StdObjMgt_TransientPersistentMap& theMap);
282   //! Create a persistent object for a Bezier surface
283   Standard_EXPORT static Handle(Surface) Translate (const Handle(Geom_BezierSurface)& theSurf,
284                                                     StdObjMgt_TransientPersistentMap& theMap);
285   //! Create a persistent object for a BSpline surface
286   Standard_EXPORT static Handle(Surface) Translate (const Handle(Geom_BSplineSurface)& theSurf,
287                                                     StdObjMgt_TransientPersistentMap& theMap);
288   //! Create a persistent object for a rectangylar trimmed surface
289   Standard_EXPORT static Handle(Surface) Translate (const Handle(Geom_RectangularTrimmedSurface)& theSurf,
290                                                     StdObjMgt_TransientPersistentMap& theMap);
291   //! Create a persistent object for an offset surface 
292   Standard_EXPORT static Handle(Surface) Translate (const Handle(Geom_OffsetSurface)& theSurf,
293                                                     StdObjMgt_TransientPersistentMap& theMap);
294 };
295
296 //=======================================================================
297 // Elementary
298 //=======================================================================
299 template<>
300 Standard_CString ShapePersistent_Geom::subBase_gp<ShapePersistent_Geom::Surface, 
301                                                   gp_Ax3>
302   ::PName() const;
303
304 //=======================================================================
305 // Plane
306 //=======================================================================
307 template<>
308 Standard_CString ShapePersistent_Geom::instance<ShapePersistent_Geom::subBase_gp<ShapePersistent_Geom::Surface, gp_Ax3>, 
309                                                 Geom_Plane, 
310                                                 gp_Ax3>
311   ::PName() const;
312
313 template<>
314 void ShapePersistent_Geom::instance<ShapePersistent_Geom::subBase_gp<ShapePersistent_Geom::Surface, gp_Ax3>,
315                                     Geom_Plane,
316                                     gp_Ax3>
317   ::Write(StdObjMgt_WriteData& theWriteData) const;
318
319 //=======================================================================
320 // Conical
321 //=======================================================================
322 template<>
323 Standard_CString ShapePersistent_Geom::instance<ShapePersistent_Geom::subBase_gp<ShapePersistent_Geom::Surface, gp_Ax3>,
324                                                 Geom_ConicalSurface,
325                                                 gp_Cone>
326   ::PName() const;
327
328 template<>
329 void ShapePersistent_Geom::instance<ShapePersistent_Geom::subBase_gp<ShapePersistent_Geom::Surface, gp_Ax3>,
330                                     Geom_ConicalSurface,
331                                     gp_Cone>
332   ::Write(StdObjMgt_WriteData& theWriteData) const;
333
334 //=======================================================================
335 // Cylindrical
336 //=======================================================================
337 template<>
338 Standard_CString ShapePersistent_Geom::instance<ShapePersistent_Geom::subBase_gp<ShapePersistent_Geom::Surface, gp_Ax3>,
339                                                 Geom_CylindricalSurface,
340                                                 gp_Cylinder>
341   ::PName() const;
342
343 template<>
344 void ShapePersistent_Geom::instance<ShapePersistent_Geom::subBase_gp<ShapePersistent_Geom::Surface, gp_Ax3>,
345                                     Geom_CylindricalSurface,
346                                     gp_Cylinder>
347   ::Write(StdObjMgt_WriteData& theWriteData) const;
348
349 //=======================================================================
350 // Spherical
351 //=======================================================================
352 template<>
353 Standard_CString ShapePersistent_Geom::instance<ShapePersistent_Geom::subBase_gp<ShapePersistent_Geom::Surface, gp_Ax3>,
354                                                 Geom_SphericalSurface,
355                                                 gp_Sphere>
356   ::PName() const;
357
358 template<>
359 void ShapePersistent_Geom::instance<ShapePersistent_Geom::subBase_gp<ShapePersistent_Geom::Surface, gp_Ax3>,
360                                     Geom_SphericalSurface,
361                                     gp_Sphere>
362   ::Write(StdObjMgt_WriteData& theWriteData) const;
363
364 //=======================================================================
365 // Toroidal
366 //=======================================================================
367 template<>
368 Standard_CString ShapePersistent_Geom::instance<ShapePersistent_Geom::subBase_gp<ShapePersistent_Geom::Surface, gp_Ax3>,
369                                                 Geom_ToroidalSurface,
370                                                 gp_Torus>
371   ::PName() const;
372
373 template<>
374 void ShapePersistent_Geom::instance<ShapePersistent_Geom::subBase_gp<ShapePersistent_Geom::Surface, gp_Ax3>,
375                                     Geom_ToroidalSurface,
376                                     gp_Torus>
377   ::Write(StdObjMgt_WriteData& theWriteData) const;
378
379 #endif