0026961: Recover possibility to read files in old persistence format
[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 <ShapePersistent_Geom.hxx>
19 #include <ShapePersistent_HArray2.hxx>
20 #include <StdLPersistent_HArray1.hxx>
21 #include <StdLPersistent_HArray2.hxx>
22
23 #include <Geom_Plane.hxx>
24 #include <Geom_ConicalSurface.hxx>
25 #include <Geom_CylindricalSurface.hxx>
26 #include <Geom_SphericalSurface.hxx>
27 #include <Geom_ToroidalSurface.hxx>
28
29 #include <gp_Ax3.hxx>
30 #include <gp_Cone.hxx>
31 #include <gp_Cylinder.hxx>
32 #include <gp_Sphere.hxx>
33 #include <gp_Torus.hxx>
34
35 class gp_Dir;
36 class gp_Pnt;
37
38
39 class ShapePersistent_Geom_Surface : private ShapePersistent_Geom
40 {
41   typedef Surface::PersistentBase pBase;
42
43   class pSweptData : protected StdObjMgt_ContentTypes
44   {
45   public:
46     inline void Read (StdObjMgt_ReadData& theReadData)
47       { theReadData >> myBasisCurve >> myDirection; }
48
49   protected:
50     Reference            <Curve>  myBasisCurve;
51     StdObject_gp::Object <gp_Dir> myDirection;
52   };
53
54   struct pSwept : pBase, pSweptData {};
55
56   class pLinearExtrusion : public pSwept
57   {
58   public:
59     virtual Handle(Geom_Surface) Import() const;
60   };
61
62   class pRevolution : public pSwept
63   {
64   public:
65     inline void Read (StdObjMgt_ReadData& theReadData)
66     {
67       pSwept::Read (theReadData);
68       theReadData >> myLocation;
69     }
70
71     virtual Handle(Geom_Surface) Import() const;
72
73   private:
74     StdObject_gp::Object<gp_Pnt> myLocation;
75   };
76
77   typedef pBase pBounded;
78
79   class pBezier : public pBounded
80   {
81   public:
82     inline void Read (StdObjMgt_ReadData& theReadData)
83       { theReadData >> myURational >> myVRational >> myPoles >> myWeights; }
84
85     virtual Handle(Geom_Surface) Import() const;
86
87   private:
88     Value     <Standard_Boolean>             myURational;
89     Value     <Standard_Boolean>             myVRational;
90     Reference <ShapePersistent_HArray2::Pnt> myPoles;
91     Reference <StdLPersistent_HArray2::Real> myWeights;
92   };
93
94   class pBSpline : public pBounded
95   {
96   public:
97     inline void Read (StdObjMgt_ReadData& theReadData)
98     {
99       theReadData >> myURational >> myVRational;
100       theReadData >> myUPeriodic >> myVPeriodic;
101       theReadData >> myUSpineDegree >> myVSpineDegree;
102       theReadData >> myPoles;
103       theReadData >> myWeights;
104       theReadData >> myUKnots >> myVKnots;
105       theReadData >> myUMultiplicities >> myVMultiplicities;
106     }
107
108     virtual Handle(Geom_Surface) Import() const;
109
110   private:
111     Value     <Standard_Boolean>                myURational;
112     Value     <Standard_Boolean>                myVRational;
113     Value     <Standard_Boolean>                myUPeriodic;
114     Value     <Standard_Boolean>                myVPeriodic;
115     Value     <Standard_Integer>                myUSpineDegree;
116     Value     <Standard_Integer>                myVSpineDegree;
117     Reference <ShapePersistent_HArray2::Pnt>    myPoles;
118     Reference <StdLPersistent_HArray2::Real>    myWeights;
119     Reference <StdLPersistent_HArray1::Real>    myUKnots;
120     Reference <StdLPersistent_HArray1::Real>    myVKnots;
121     Reference <StdLPersistent_HArray1::Integer> myUMultiplicities;
122     Reference <StdLPersistent_HArray1::Integer> myVMultiplicities;
123   };
124
125   class pRectangularTrimmed : public pBounded
126   {
127   public:
128     inline void Read (StdObjMgt_ReadData& theReadData)
129     {
130       theReadData >> myBasisSurface;
131       theReadData >> myFirstU >> myLastU >> myFirstV >> myLastV;
132     }
133
134     virtual Handle(Geom_Surface) Import() const;
135
136   private:
137     Reference<Surface>   myBasisSurface;
138     Value<Standard_Real> myFirstU;
139     Value<Standard_Real> myLastU;
140     Value<Standard_Real> myFirstV;
141     Value<Standard_Real> myLastV;
142   };
143
144   class pOffset : public pBase
145   {
146   public:
147     inline void Read (StdObjMgt_ReadData& theReadData)
148       { theReadData >> myBasisSurface >> myOffsetValue; }
149
150     virtual Handle(Geom_Surface) Import() const;
151
152   private:
153     Reference<Surface>   myBasisSurface;
154     Value<Standard_Real> myOffsetValue;
155   };
156
157 public:
158   typedef subBase_gp<Surface, gp_Ax3>                                Elementary;
159   typedef instance<Elementary, Geom_Plane             , gp_Ax3>      Plane;
160   typedef instance<Elementary, Geom_ConicalSurface    , gp_Cone>     Conical;
161   typedef instance<Elementary, Geom_CylindricalSurface, gp_Cylinder> Cylindrical;
162   typedef instance<Elementary, Geom_SphericalSurface  , gp_Sphere>   Spherical;
163   typedef instance<Elementary, Geom_ToroidalSurface   , gp_Torus>    Toroidal;
164
165   typedef subBase<Surface, pSweptData>                               Swept;
166   typedef Delayed<Swept, pLinearExtrusion>                           LinearExtrusion;
167   typedef Delayed<Swept, pRevolution>                                Revolution;
168
169   typedef subBase_empty<Surface>                                     Bounded;
170   typedef Delayed<Bounded, pBezier>                                  Bezier;
171   typedef Delayed<Bounded, pBSpline>                                 BSpline;
172   typedef Delayed<Bounded, pRectangularTrimmed>                      RectangularTrimmed;
173
174   typedef Delayed<Surface, pOffset>                                  Offset;
175 };
176
177 #endif