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_Curve_HeaderFile
16 #define _ShapePersistent_Geom_Curve_HeaderFile
17 
18 #include <StdObjMgt_TransientPersistentMap.hxx>
19 
20 #include <ShapePersistent_Geom.hxx>
21 #include <ShapePersistent_HArray1.hxx>
22 #include <StdLPersistent_HArray1.hxx>
23 
24 #include <Geom_Line.hxx>
25 #include <Geom_Circle.hxx>
26 #include <Geom_Ellipse.hxx>
27 #include <Geom_Hyperbola.hxx>
28 #include <Geom_Parabola.hxx>
29 #include <Geom_BezierCurve.hxx>
30 #include <Geom_BSplineCurve.hxx>
31 #include <Geom_TrimmedCurve.hxx>
32 #include <Geom_OffsetCurve.hxx>
33 
34 #include <gp_Circ.hxx>
35 #include <gp_Elips.hxx>
36 #include <gp_Hypr.hxx>
37 #include <gp_Parab.hxx>
38 
39 class gp_Dir;
40 
41 class ShapePersistent_Geom_Curve : private ShapePersistent_Geom
42 {
43   typedef Curve::PersistentBase pBase;
44 
45   typedef pBase pBounded;
46 
47   class pBezier : public pBounded
48   {
49     friend class ShapePersistent_Geom_Curve;
50 
51   public:
Read(StdObjMgt_ReadData & theReadData)52     inline void Read (StdObjMgt_ReadData& theReadData)
53       { theReadData >> myRational >> myPoles >> myWeights; }
Write(StdObjMgt_WriteData & theWriteData)54     inline void Write(StdObjMgt_WriteData& theWriteData)
55       { theWriteData << myRational << myPoles << myWeights; }
PChildren(StdObjMgt_Persistent::SequenceOfPersistent & theChildren) const56     inline void PChildren(StdObjMgt_Persistent::SequenceOfPersistent& theChildren) const
57     {
58       theChildren.Append(myPoles);
59       theChildren.Append(myWeights);
60     }
PName() const61     inline Standard_CString PName() const { return "PGeom_BezierCurve"; }
62 
63     virtual Handle(Geom_Curve) Import() const;
64 
65   private:
66     Standard_Boolean                     myRational;
67     Handle(ShapePersistent_HArray1::Pnt) myPoles;
68     Handle(StdLPersistent_HArray1::Real) myWeights;
69   };
70 
71   class pBSpline : public pBounded
72   {
73     friend class ShapePersistent_Geom_Curve;
74 
75   public:
Read(StdObjMgt_ReadData & theReadData)76     inline void Read (StdObjMgt_ReadData& theReadData)
77     {
78       theReadData >> myRational >> myPeriodic >> mySpineDegree;
79       theReadData >> myPoles >> myWeights >> myKnots >> myMultiplicities;
80     }
Write(StdObjMgt_WriteData & theWriteData) const81     inline void Write (StdObjMgt_WriteData& theWriteData) const
82     {
83       theWriteData << myRational << myPeriodic << mySpineDegree;
84       theWriteData << myPoles << myWeights << myKnots << myMultiplicities;
85     }
PChildren(StdObjMgt_Persistent::SequenceOfPersistent & theChildren) const86     inline void PChildren(StdObjMgt_Persistent::SequenceOfPersistent& theChildren) const
87     {
88       theChildren.Append(myPoles);
89       theChildren.Append(myWeights);
90       theChildren.Append(myKnots);
91       theChildren.Append(myMultiplicities);
92     }
PName() const93     inline Standard_CString PName() const { return "PGeom_BSplineCurve"; }
94 
95     virtual Handle(Geom_Curve) Import() const;
96 
97   private:
98     Standard_Boolean                        myRational;
99     Standard_Boolean                        myPeriodic;
100     Standard_Integer                        mySpineDegree;
101     Handle(ShapePersistent_HArray1::Pnt)    myPoles;
102     Handle(StdLPersistent_HArray1::Real)    myWeights;
103     Handle(StdLPersistent_HArray1::Real)    myKnots;
104     Handle(StdLPersistent_HArray1::Integer) myMultiplicities;
105   };
106 
107   class pTrimmed : public pBounded
108   {
109     friend class ShapePersistent_Geom_Curve;
110 
111   public:
Read(StdObjMgt_ReadData & theReadData)112     inline void Read (StdObjMgt_ReadData& theReadData)
113       { theReadData >> myBasisCurve >> myFirstU >> myLastU; }
Write(StdObjMgt_WriteData & theWriteData) const114     inline void Write (StdObjMgt_WriteData& theWriteData) const
115       { theWriteData << myBasisCurve << myFirstU << myLastU; }
PChildren(StdObjMgt_Persistent::SequenceOfPersistent & theChildren) const116     inline void PChildren(StdObjMgt_Persistent::SequenceOfPersistent& theChildren) const
117       { theChildren.Append(myBasisCurve); }
PName() const118     inline Standard_CString PName() const { return "PGeom_TrimmedCurve"; }
119 
120     virtual Handle(Geom_Curve) Import() const;
121 
122   private:
123     Handle(Curve) myBasisCurve;
124     Standard_Real myFirstU;
125     Standard_Real myLastU;
126   };
127 
128   class pOffset : public pBase
129   {
130     friend class ShapePersistent_Geom_Curve;
131 
132   public:
Read(StdObjMgt_ReadData & theReadData)133     inline void Read (StdObjMgt_ReadData& theReadData)
134       { theReadData >> myBasisCurve >> myOffsetDirection >> myOffsetValue; }
Write(StdObjMgt_WriteData & theWriteData) const135     inline void Write (StdObjMgt_WriteData& theWriteData) const
136       { theWriteData << myBasisCurve << myOffsetDirection << myOffsetValue; }
PChildren(StdObjMgt_Persistent::SequenceOfPersistent & theChildren) const137     inline void PChildren(StdObjMgt_Persistent::SequenceOfPersistent& theChildren) const
138       { theChildren.Append(myBasisCurve); }
PName() const139     inline Standard_CString PName() const { return "PGeom_OffsetCurve"; }
140 
141     virtual Handle(Geom_Curve) Import() const;
142 
143   private:
144     Handle(Curve) myBasisCurve;
145     gp_Dir        myOffsetDirection;
146     Standard_Real myOffsetValue;
147   };
148 
149 public:
150   typedef instance<Curve, Geom_Line, gp_Ax1>        Line;
151 
152   typedef subBase_gp<Curve, gp_Ax2>                 Conic;
153   typedef instance<Conic, Geom_Circle   , gp_Circ > Circle;
154   typedef instance<Conic, Geom_Ellipse  , gp_Elips> Ellipse;
155   typedef instance<Conic, Geom_Hyperbola, gp_Hypr > Hyperbola;
156   typedef instance<Conic, Geom_Parabola , gp_Parab> Parabola;
157 
158   typedef subBase_empty<Curve>                      Bounded;
159   typedef Delayed<Bounded, pBezier>                 Bezier;
160   typedef Delayed<Bounded, pBSpline>                BSpline;
161   typedef Delayed<Bounded, pTrimmed>                Trimmed;
162 
163   typedef Delayed<Curve, pOffset>                   Offset;
164 
165 public:
166   //! Create a persistent object for a line
167   Standard_EXPORT static Handle(Curve) Translate (const Handle(Geom_Line)& theCurve,
168                                                   StdObjMgt_TransientPersistentMap& theMap);
169   //! Create a persistent object for a circle
170   Standard_EXPORT static Handle(Curve) Translate (const Handle(Geom_Circle)& theCurve,
171                                                   StdObjMgt_TransientPersistentMap& theMap);
172   //! Create a persistent object for a ellipse
173   Standard_EXPORT static Handle(Curve) Translate (const Handle(Geom_Ellipse)& theCurve,
174                                                   StdObjMgt_TransientPersistentMap& theMap);
175   //! Create a persistent object for a hyperbola
176   Standard_EXPORT static Handle(Curve) Translate (const Handle(Geom_Hyperbola)& theCurve,
177                                                   StdObjMgt_TransientPersistentMap& theMap);
178   //! Create a persistent object for a parabola
179   Standard_EXPORT static Handle(Curve) Translate (const Handle(Geom_Parabola)& theCurve,
180                                                   StdObjMgt_TransientPersistentMap& theMap);
181   //! Create a persistent object for a Bezier curve
182   Standard_EXPORT static Handle(Curve) Translate (const Handle(Geom_BezierCurve)& theCurve,
183                                                   StdObjMgt_TransientPersistentMap& theMap);
184   //! Create a persistent object for a BSpline curve
185   Standard_EXPORT static Handle(Curve) Translate (const Handle(Geom_BSplineCurve)& theCurve,
186                                                   StdObjMgt_TransientPersistentMap& theMap);
187   //! Create a persistent object for a trimmed curve
188   Standard_EXPORT static Handle(Curve) Translate (const Handle(Geom_TrimmedCurve)& theCurve,
189                                                   StdObjMgt_TransientPersistentMap& theMap);
190   //! Create a persistent object for an offset curve
191   Standard_EXPORT static Handle(Curve) Translate (const Handle(Geom_OffsetCurve)& theCurve,
192                                                   StdObjMgt_TransientPersistentMap& theMap);
193 };
194 
195 //=======================================================================
196 // Line
197 //=======================================================================
198 template<>
199 Standard_CString ShapePersistent_Geom::instance<ShapePersistent_Geom::Curve,
200                                                 Geom_Line,
201                                                 gp_Ax1>
202   ::PName() const;
203 
204 template<>
205 void ShapePersistent_Geom::instance<ShapePersistent_Geom::Curve,
206                                     Geom_Line,
207                                     gp_Ax1>
208   ::Write(StdObjMgt_WriteData& theWriteData) const;
209 
210 //=======================================================================
211 // Conic
212 //=======================================================================
213 template<>
214 Standard_CString ShapePersistent_Geom::subBase_gp<ShapePersistent_Geom::Curve,
215                                                   gp_Ax2>
216   ::PName() const;
217 
218 //=======================================================================
219 // Circle
220 //=======================================================================
221 template<>
222 Standard_CString ShapePersistent_Geom::instance<ShapePersistent_Geom_Curve::Conic,
223                                                 Geom_Circle,
224                                                 gp_Circ>
225   ::PName() const;
226 
227 template<>
228 void ShapePersistent_Geom::instance<ShapePersistent_Geom_Curve::Conic,
229                                     Geom_Circle,
230                                     gp_Circ>
231   ::Write(StdObjMgt_WriteData& theWriteData) const;
232 
233 //=======================================================================
234 // Ellipse
235 //=======================================================================
236 template<>
237 Standard_CString ShapePersistent_Geom::instance<ShapePersistent_Geom_Curve::Conic,
238                                                 Geom_Ellipse,
239                                                 gp_Elips>
240   ::PName() const;
241 
242 template<>
243 void ShapePersistent_Geom::instance<ShapePersistent_Geom_Curve::Conic,
244                                     Geom_Ellipse,
245                                     gp_Elips>
246   ::Write(StdObjMgt_WriteData& theWriteData) const;
247 
248 //=======================================================================
249 // Hyperbola
250 //=======================================================================
251 template<>
252 Standard_CString ShapePersistent_Geom::instance<ShapePersistent_Geom_Curve::Conic,
253                                                 Geom_Hyperbola,
254                                                 gp_Hypr>
255   ::PName() const;
256 
257 template<>
258 void ShapePersistent_Geom::instance<ShapePersistent_Geom_Curve::Conic,
259                                     Geom_Hyperbola,
260                                     gp_Hypr>
261   ::Write(StdObjMgt_WriteData& theWriteData) const;
262 
263 //=======================================================================
264 // Parabola
265 //=======================================================================
266 template<>
267 Standard_CString ShapePersistent_Geom::instance<ShapePersistent_Geom_Curve::Conic,
268                                                 Geom_Parabola,
269                                                 gp_Parab>
270   ::PName() const;
271 
272 template<>
273 void ShapePersistent_Geom::instance<ShapePersistent_Geom_Curve::Conic,
274                                     Geom_Parabola,
275                                     gp_Parab>
276   ::Write(StdObjMgt_WriteData& theWriteData) const;
277 
278 #endif
279