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_Geom2d_Curve_HeaderFile
16 #define _ShapePersistent_Geom2d_Curve_HeaderFile
17 
18 #include <StdObjMgt_TransientPersistentMap.hxx>
19 
20 #include <ShapePersistent_Geom2d.hxx>
21 #include <ShapePersistent_HArray1.hxx>
22 #include <StdLPersistent_HArray1.hxx>
23 
24 #include <Geom2d_Line.hxx>
25 #include <Geom2d_Circle.hxx>
26 #include <Geom2d_Ellipse.hxx>
27 #include <Geom2d_Hyperbola.hxx>
28 #include <Geom2d_Parabola.hxx>
29 #include <Geom2d_BezierCurve.hxx>
30 #include <Geom2d_BSplineCurve.hxx>
31 #include <Geom2d_TrimmedCurve.hxx>
32 #include <Geom2d_OffsetCurve.hxx>
33 
34 #include <gp_Circ2d.hxx>
35 #include <gp_Elips2d.hxx>
36 #include <gp_Hypr2d.hxx>
37 #include <gp_Parab2d.hxx>
38 
39 
40 class ShapePersistent_Geom2d_Curve : public ShapePersistent_Geom2d
41 {
42   typedef Curve::PersistentBase pBase;
43 
44   typedef pBase pBounded;
45 
46   class pBezier : public pBounded
47   {
48     friend class ShapePersistent_Geom2d_Curve;
49 
50   public:
pBezier()51     pBezier()
52     : myRational(Standard_False)
53     {
54     }
Read(StdObjMgt_ReadData & theReadData)55     inline void Read (StdObjMgt_ReadData& theReadData)
56       { theReadData >> myRational >> myPoles >> myWeights; }
Write(StdObjMgt_WriteData & theWriteData) const57     inline void Write (StdObjMgt_WriteData& theWriteData) const
58       { theWriteData << myRational << myPoles << myWeights; }
PChildren(StdObjMgt_Persistent::SequenceOfPersistent & theChildren) const59     inline void PChildren(StdObjMgt_Persistent::SequenceOfPersistent& theChildren) const
60     {
61       theChildren.Append(myPoles);
62       theChildren.Append(myWeights);
63     }
PName() const64     inline Standard_CString PName() const
65       { return "PGeom2d_BezierCurve"; }
66 
67     virtual Handle(Geom2d_Curve) Import() const;
68 
69   private:
70     Standard_Boolean                       myRational;
71     Handle(ShapePersistent_HArray1::Pnt2d) myPoles;
72     Handle(StdLPersistent_HArray1::Real)   myWeights;
73   };
74 
75   class pBSpline : public pBounded
76   {
77     friend class ShapePersistent_Geom2d_Curve;
78 
79   public:
pBSpline()80     pBSpline()
81     : myRational(Standard_False),
82       myPeriodic(Standard_False),
83       mySpineDegree(0)
84     {
85     }
Read(StdObjMgt_ReadData & theReadData)86     inline void Read (StdObjMgt_ReadData& theReadData)
87     {
88       theReadData >> myRational >> myPeriodic >> mySpineDegree;
89       theReadData >> myPoles >> myWeights >> myKnots >> myMultiplicities;
90     }
Write(StdObjMgt_WriteData & theWriteData) const91     inline void Write (StdObjMgt_WriteData& theWriteData) const
92     {
93       theWriteData << myRational << myPeriodic << mySpineDegree;
94       theWriteData << myPoles << myWeights << myKnots << myMultiplicities;
95     }
PChildren(StdObjMgt_Persistent::SequenceOfPersistent & theChildren) const96     inline void PChildren(StdObjMgt_Persistent::SequenceOfPersistent& theChildren) const
97     {
98       theChildren.Append(myPoles);
99       theChildren.Append(myWeights);
100       theChildren.Append(myKnots);
101       theChildren.Append(myMultiplicities);
102     }
PName() const103     inline Standard_CString PName() const
104       { return "PGeom2d_BSplineCurve"; }
105 
106     virtual Handle(Geom2d_Curve) Import() const;
107 
108   private:
109     Standard_Boolean                        myRational;
110     Standard_Boolean                        myPeriodic;
111     Standard_Integer                        mySpineDegree;
112     Handle(ShapePersistent_HArray1::Pnt2d)  myPoles;
113     Handle(StdLPersistent_HArray1::Real)    myWeights;
114     Handle(StdLPersistent_HArray1::Real)    myKnots;
115     Handle(StdLPersistent_HArray1::Integer) myMultiplicities;
116   };
117 
118   class pTrimmed : public pBounded
119   {
120     friend class ShapePersistent_Geom2d_Curve;
121 
122   public:
pTrimmed()123     pTrimmed()
124     : myFirstU(0.0),
125       myLastU(0.0)
126     {
127     }
Read(StdObjMgt_ReadData & theReadData)128     inline void Read (StdObjMgt_ReadData& theReadData)
129       { theReadData >> myBasisCurve >> myFirstU >> myLastU; }
Write(StdObjMgt_WriteData & theWriteData) const130     inline void Write (StdObjMgt_WriteData& theWriteData) const
131       { theWriteData << myBasisCurve << myFirstU << myLastU; }
PChildren(StdObjMgt_Persistent::SequenceOfPersistent & theChildren) const132     inline void PChildren(StdObjMgt_Persistent::SequenceOfPersistent& theChildren) const
133       { theChildren.Append(myBasisCurve); }
PName() const134     inline Standard_CString PName() const
135       { return "PGeom2d_TrimmedCurve"; }
136 
137     virtual Handle(Geom2d_Curve) Import() const;
138 
139   private:
140     Handle(Curve) myBasisCurve;
141     Standard_Real myFirstU;
142     Standard_Real myLastU;
143   };
144 
145   class pOffset : public pBase
146   {
147     friend class ShapePersistent_Geom2d_Curve;
148 
149   public:
pOffset()150     pOffset()
151     : myOffsetValue(0.0)
152     {
153     }
Read(StdObjMgt_ReadData & theReadData)154     inline void Read (StdObjMgt_ReadData& theReadData)
155       { theReadData >> myBasisCurve >> myOffsetValue; }
Write(StdObjMgt_WriteData & theWriteData) const156     inline void Write (StdObjMgt_WriteData& theWriteData) const
157       { theWriteData << myBasisCurve << myOffsetValue; }
PChildren(StdObjMgt_Persistent::SequenceOfPersistent & theChildren) const158     inline void PChildren(StdObjMgt_Persistent::SequenceOfPersistent& theChildren) const
159       { theChildren.Append(myBasisCurve); }
PName() const160     inline Standard_CString PName() const
161       { return "PGeom2d_OffsetCurve"; }
162 
163     virtual Handle(Geom2d_Curve) Import() const;
164 
165   private:
166     Handle(Curve) myBasisCurve;
167     Standard_Real myOffsetValue;
168   };
169 
170 public:
171   typedef instance<Curve, Geom2d_Line, gp_Ax2d>         Line;
172 
173   typedef subBase_gp<Curve, gp_Ax22d>                   Conic;
174   typedef instance<Conic, Geom2d_Circle   , gp_Circ2d > Circle;
175   typedef instance<Conic, Geom2d_Ellipse  , gp_Elips2d> Ellipse;
176   typedef instance<Conic, Geom2d_Hyperbola, gp_Hypr2d > Hyperbola;
177   typedef instance<Conic, Geom2d_Parabola , gp_Parab2d> Parabola;
178 
179   typedef subBase_empty<Curve>                          Bounded;
180   typedef Delayed<Bounded, pBezier>                     Bezier;
181   typedef Delayed<Bounded, pBSpline>                    BSpline;
182   typedef Delayed<Bounded, pTrimmed>                    Trimmed;
183 
184   typedef Delayed<Curve, pOffset>                       Offset;
185 
186 public:
187   //! Create a persistent object for a line
188   Standard_EXPORT static Handle(Curve) Translate (const Handle(Geom2d_Line)& theCurve,
189                                                   StdObjMgt_TransientPersistentMap& theMap);
190   //! Create a persistent object for a circle
191   Standard_EXPORT static Handle(Curve) Translate (const Handle(Geom2d_Circle)& theCurve,
192                                                   StdObjMgt_TransientPersistentMap& theMap);
193   //! Create a persistent object for a ellipse
194   Standard_EXPORT static Handle(Curve) Translate (const Handle(Geom2d_Ellipse)& theCurve,
195                                                   StdObjMgt_TransientPersistentMap& theMap);
196   //! Create a persistent object for a hyperbola
197   Standard_EXPORT static Handle(Curve) Translate (const Handle(Geom2d_Hyperbola)& theCurve,
198                                                   StdObjMgt_TransientPersistentMap& theMap);
199   //! Create a persistent object for a parabola
200   Standard_EXPORT static Handle(Curve) Translate (const Handle(Geom2d_Parabola)& theCurve,
201                                                   StdObjMgt_TransientPersistentMap& theMap);
202   //! Create a persistent object for a Bezier curve
203   Standard_EXPORT static Handle(Curve) Translate (const Handle(Geom2d_BezierCurve)& theCurve,
204                                                   StdObjMgt_TransientPersistentMap& theMap);
205   //! Create a persistent object for a BSpline curve
206   Standard_EXPORT static Handle(Curve) Translate (const Handle(Geom2d_BSplineCurve)& theCurve,
207                                                   StdObjMgt_TransientPersistentMap& theMap);
208   //! Create a persistent object for a trimmed curve
209   Standard_EXPORT static Handle(Curve) Translate (const Handle(Geom2d_TrimmedCurve)& theCurve,
210                                                   StdObjMgt_TransientPersistentMap& theMap);
211   //! Create a persistent object for an offset curve
212   Standard_EXPORT static Handle(Curve) Translate (const Handle(Geom2d_OffsetCurve)& theCurve,
213                                                   StdObjMgt_TransientPersistentMap& theMap);
214 };
215 
216 //=======================================================================
217 // Line
218 //=======================================================================
219 template<>
220 Standard_CString ShapePersistent_Geom2d_Curve::instance<ShapePersistent_Geom2d::Curve,
221                                                         Geom2d_Line,
222                                                         gp_Ax2d>
223   ::PName() const;
224 
225 template<>
226 void ShapePersistent_Geom2d_Curve::instance<ShapePersistent_Geom2d::Curve,
227                                             Geom2d_Line,
228                                             gp_Ax2d>
229   ::Write(StdObjMgt_WriteData& theWriteData) const;
230 
231 //=======================================================================
232 // Conic
233 //=======================================================================
234 template<>
235 Standard_CString ShapePersistent_Geom2d_Curve::subBase_gp<ShapePersistent_Geom2d::Curve,
236                                                           gp_Ax22d>
237   ::PName() const;
238 
239 //=======================================================================
240 // Circle
241 //=======================================================================
242 template<>
243 Standard_CString ShapePersistent_Geom2d_Curve::instance<ShapePersistent_Geom2d_Curve::Conic,
244                                                         Geom2d_Circle,
245                                                         gp_Circ2d>
246   ::PName() const;
247 
248 template<>
249 void ShapePersistent_Geom2d_Curve::instance<ShapePersistent_Geom2d_Curve::Conic,
250                                             Geom2d_Circle,
251                                             gp_Circ2d>
252   ::Write(StdObjMgt_WriteData& theWriteData) const;
253 
254 //=======================================================================
255 // Ellipse
256 //=======================================================================
257 template<>
258 Standard_CString ShapePersistent_Geom2d_Curve::instance<ShapePersistent_Geom2d_Curve::Conic,
259                                                         Geom2d_Ellipse,
260                                                         gp_Elips2d>
261   ::PName() const;
262 
263 template<>
264 void ShapePersistent_Geom2d_Curve::instance<ShapePersistent_Geom2d_Curve::Conic,
265                                             Geom2d_Ellipse,
266                                             gp_Elips2d>
267   ::Write(StdObjMgt_WriteData& theWriteData) const;
268 
269 //=======================================================================
270 // Hyperbola
271 //=======================================================================
272 template<>
273 Standard_CString ShapePersistent_Geom2d_Curve::instance<ShapePersistent_Geom2d_Curve::Conic,
274                                                         Geom2d_Hyperbola,
275                                                         gp_Hypr2d>
276   ::PName() const;
277 
278 template<>
279 void ShapePersistent_Geom2d_Curve::instance<ShapePersistent_Geom2d_Curve::Conic,
280                                             Geom2d_Hyperbola,
281                                             gp_Hypr2d>
282   ::Write(StdObjMgt_WriteData& theWriteData) const;
283 
284 //=======================================================================
285 // Parabola
286 //=======================================================================
287 template<>
288 Standard_CString ShapePersistent_Geom2d_Curve::instance<ShapePersistent_Geom2d_Curve::Conic,
289                                                         Geom2d_Parabola,
290                                                         gp_Parab2d>
291   ::PName() const;
292 
293 template<>
294 void ShapePersistent_Geom2d_Curve::instance<ShapePersistent_Geom2d_Curve::Conic,
295                                             Geom2d_Parabola,
296                                             gp_Parab2d>
297   ::Write(StdObjMgt_WriteData& theWriteData) const;
298 
299 #endif
300