0030675: Visualization - remove redundant proxy classes in hierarchy of PrsMgr_Presen...
[occt.git] / src / ShapePersistent / ShapePersistent_Geom2d_Curve.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_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:
51     inline void Read (StdObjMgt_ReadData& theReadData)
52       { theReadData >> myRational >> myPoles >> myWeights; }
53     inline void Write (StdObjMgt_WriteData& theWriteData) const
54       { theWriteData << myRational << myPoles << myWeights; }
55     inline void PChildren(StdObjMgt_Persistent::SequenceOfPersistent& theChildren) const
56     {
57       theChildren.Append(myPoles);
58       theChildren.Append(myWeights);
59     }
60     inline Standard_CString PName() const
61       { return "PGeom2d_BezierCurve"; }
62
63     virtual Handle(Geom2d_Curve) Import() const;
64
65   private:
66     Standard_Boolean                       myRational;
67     Handle(ShapePersistent_HArray1::Pnt2d) myPoles;
68     Handle(StdLPersistent_HArray1::Real)   myWeights;
69   };
70
71   class pBSpline : public pBounded
72   {
73     friend class ShapePersistent_Geom2d_Curve;
74
75   public:
76     inline void Read (StdObjMgt_ReadData& theReadData)
77     {
78       theReadData >> myRational >> myPeriodic >> mySpineDegree;
79       theReadData >> myPoles >> myWeights >> myKnots >> myMultiplicities;
80     }
81     inline void Write (StdObjMgt_WriteData& theWriteData) const
82     {
83       theWriteData << myRational << myPeriodic << mySpineDegree;
84       theWriteData << myPoles << myWeights << myKnots << myMultiplicities;
85     }
86     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     }
93     inline Standard_CString PName() const 
94       { return "PGeom2d_BSplineCurve"; }
95
96     virtual Handle(Geom2d_Curve) Import() const;
97
98   private:
99     Standard_Boolean                        myRational;
100     Standard_Boolean                        myPeriodic;
101     Standard_Integer                        mySpineDegree;
102     Handle(ShapePersistent_HArray1::Pnt2d)  myPoles;
103     Handle(StdLPersistent_HArray1::Real)    myWeights;
104     Handle(StdLPersistent_HArray1::Real)    myKnots;
105     Handle(StdLPersistent_HArray1::Integer) myMultiplicities;
106   };
107
108   class pTrimmed : public pBounded
109   {
110     friend class ShapePersistent_Geom2d_Curve;
111
112   public:
113     inline void Read (StdObjMgt_ReadData& theReadData)
114       { theReadData >> myBasisCurve >> myFirstU >> myLastU; }
115     inline void Write (StdObjMgt_WriteData& theWriteData) const
116       { theWriteData << myBasisCurve << myFirstU << myLastU; }
117     inline void PChildren(StdObjMgt_Persistent::SequenceOfPersistent& theChildren) const
118       { theChildren.Append(myBasisCurve); }
119     inline Standard_CString PName() const
120       { return "PGeom2d_TrimmedCurve"; }
121
122     virtual Handle(Geom2d_Curve) Import() const;
123
124   private:
125     Handle(Curve) myBasisCurve;
126     Standard_Real myFirstU;
127     Standard_Real myLastU;
128   };
129
130   class pOffset : public pBase
131   {
132     friend class ShapePersistent_Geom2d_Curve;
133
134   public:
135     inline void Read (StdObjMgt_ReadData& theReadData)
136       { theReadData >> myBasisCurve >> myOffsetValue; }
137     inline void Write (StdObjMgt_WriteData& theWriteData) const
138       { theWriteData << myBasisCurve << myOffsetValue; }
139     inline void PChildren(StdObjMgt_Persistent::SequenceOfPersistent& theChildren) const
140       { theChildren.Append(myBasisCurve); }
141     inline Standard_CString PName() const
142       { return "PGeom2d_OffsetCurve"; }
143
144     virtual Handle(Geom2d_Curve) Import() const;
145
146   private:
147     Handle(Curve) myBasisCurve;
148     Standard_Real myOffsetValue;
149   };
150
151 public:
152   typedef instance<Curve, Geom2d_Line, gp_Ax2d>         Line;
153
154   typedef subBase_gp<Curve, gp_Ax22d>                   Conic;
155   typedef instance<Conic, Geom2d_Circle   , gp_Circ2d > Circle;
156   typedef instance<Conic, Geom2d_Ellipse  , gp_Elips2d> Ellipse;
157   typedef instance<Conic, Geom2d_Hyperbola, gp_Hypr2d > Hyperbola;
158   typedef instance<Conic, Geom2d_Parabola , gp_Parab2d> Parabola;
159
160   typedef subBase_empty<Curve>                          Bounded;
161   typedef Delayed<Bounded, pBezier>                     Bezier;
162   typedef Delayed<Bounded, pBSpline>                    BSpline;
163   typedef Delayed<Bounded, pTrimmed>                    Trimmed;
164
165   typedef Delayed<Curve, pOffset>                       Offset;
166
167 public:
168   //! Create a persistent object for a line
169   Standard_EXPORT static Handle(Curve) Translate (const Handle(Geom2d_Line)& theCurve,
170                                                   StdObjMgt_TransientPersistentMap& theMap);
171   //! Create a persistent object for a circle
172   Standard_EXPORT static Handle(Curve) Translate (const Handle(Geom2d_Circle)& theCurve,
173                                                   StdObjMgt_TransientPersistentMap& theMap);
174   //! Create a persistent object for a ellipse
175   Standard_EXPORT static Handle(Curve) Translate (const Handle(Geom2d_Ellipse)& theCurve,
176                                                   StdObjMgt_TransientPersistentMap& theMap);
177   //! Create a persistent object for a hyperbola
178   Standard_EXPORT static Handle(Curve) Translate (const Handle(Geom2d_Hyperbola)& theCurve,
179                                                   StdObjMgt_TransientPersistentMap& theMap);
180   //! Create a persistent object for a parabola
181   Standard_EXPORT static Handle(Curve) Translate (const Handle(Geom2d_Parabola)& theCurve,
182                                                   StdObjMgt_TransientPersistentMap& theMap);
183   //! Create a persistent object for a Bezier curve
184   Standard_EXPORT static Handle(Curve) Translate (const Handle(Geom2d_BezierCurve)& theCurve,
185                                                   StdObjMgt_TransientPersistentMap& theMap);
186   //! Create a persistent object for a BSpline curve
187   Standard_EXPORT static Handle(Curve) Translate (const Handle(Geom2d_BSplineCurve)& theCurve,
188                                                   StdObjMgt_TransientPersistentMap& theMap);
189   //! Create a persistent object for a trimmed curve
190   Standard_EXPORT static Handle(Curve) Translate (const Handle(Geom2d_TrimmedCurve)& theCurve,
191                                                   StdObjMgt_TransientPersistentMap& theMap);
192   //! Create a persistent object for an offset curve 
193   Standard_EXPORT static Handle(Curve) Translate (const Handle(Geom2d_OffsetCurve)& theCurve,
194                                                   StdObjMgt_TransientPersistentMap& theMap);
195 };
196
197 //=======================================================================
198 // Line
199 //=======================================================================
200 template<>
201 Standard_CString ShapePersistent_Geom2d_Curve::instance<ShapePersistent_Geom2d::Curve,
202                                                         Geom2d_Line,
203                                                         gp_Ax2d>
204   ::PName() const;
205
206 template<>
207 void ShapePersistent_Geom2d_Curve::instance<ShapePersistent_Geom2d::Curve,
208                                             Geom2d_Line,
209                                             gp_Ax2d>
210   ::Write(StdObjMgt_WriteData& theWriteData) const;
211
212 //=======================================================================
213 // Conic
214 //=======================================================================
215 template<>
216 Standard_CString ShapePersistent_Geom2d_Curve::subBase_gp<ShapePersistent_Geom2d::Curve,
217                                                           gp_Ax22d>
218   ::PName() const;
219
220 //=======================================================================
221 // Circle
222 //=======================================================================
223 template<>
224 Standard_CString ShapePersistent_Geom2d_Curve::instance<ShapePersistent_Geom2d_Curve::Conic,
225                                                         Geom2d_Circle,
226                                                         gp_Circ2d>
227   ::PName() const;
228
229 template<>
230 void ShapePersistent_Geom2d_Curve::instance<ShapePersistent_Geom2d_Curve::Conic,
231                                             Geom2d_Circle,
232                                             gp_Circ2d>
233   ::Write(StdObjMgt_WriteData& theWriteData) const;
234
235 //=======================================================================
236 // Ellipse
237 //=======================================================================
238 template<>
239 Standard_CString ShapePersistent_Geom2d_Curve::instance<ShapePersistent_Geom2d_Curve::Conic,
240                                                         Geom2d_Ellipse,
241                                                         gp_Elips2d>
242   ::PName() const;
243
244 template<>
245 void ShapePersistent_Geom2d_Curve::instance<ShapePersistent_Geom2d_Curve::Conic,
246                                             Geom2d_Ellipse,
247                                             gp_Elips2d>
248   ::Write(StdObjMgt_WriteData& theWriteData) const;
249
250 //=======================================================================
251 // Hyperbola
252 //=======================================================================
253 template<>
254 Standard_CString ShapePersistent_Geom2d_Curve::instance<ShapePersistent_Geom2d_Curve::Conic,
255                                                         Geom2d_Hyperbola,
256                                                         gp_Hypr2d>
257   ::PName() const;
258
259 template<>
260 void ShapePersistent_Geom2d_Curve::instance<ShapePersistent_Geom2d_Curve::Conic,
261                                             Geom2d_Hyperbola,
262                                             gp_Hypr2d>
263   ::Write(StdObjMgt_WriteData& theWriteData) const;
264
265 //=======================================================================
266 // Parabola
267 //=======================================================================
268 template<>
269 Standard_CString ShapePersistent_Geom2d_Curve::instance<ShapePersistent_Geom2d_Curve::Conic,
270                                                         Geom2d_Parabola,
271                                                         gp_Parab2d>
272   ::PName() const;
273
274 template<>
275 void ShapePersistent_Geom2d_Curve::instance<ShapePersistent_Geom2d_Curve::Conic,
276                                             Geom2d_Parabola,
277                                             gp_Parab2d>
278   ::Write(StdObjMgt_WriteData& theWriteData) const;
279
280 #endif