0029590: Coding - avoid usage of Standard_EXPORT attribute for inline methods
[occt.git] / src / ShapePersistent / ShapePersistent_Geom_Curve.cxx
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 #include <Standard_NullObject.hxx>
15
16 #include <ShapePersistent_Geom.hxx>
17 #include <ShapePersistent_Geom_Curve.hxx>
18
19 #include <Geom_BezierCurve.hxx>
20 #include <Geom_BSplineCurve.hxx>
21 #include <Geom_TrimmedCurve.hxx>
22 #include <Geom_OffsetCurve.hxx>
23
24
25 Handle(Geom_Curve) ShapePersistent_Geom_Curve::pBezier::Import() const
26 {
27   if (myPoles.IsNull())
28     return NULL;
29
30   if (myRational)
31   {
32     if (myWeights.IsNull())
33       return NULL;
34     return new Geom_BezierCurve (*myPoles->Array(), *myWeights->Array());
35   }
36   else
37     return new Geom_BezierCurve (*myPoles->Array());
38 }
39
40 Handle(Geom_Curve) ShapePersistent_Geom_Curve::pBSpline::Import() const
41 {
42   if (myPoles.IsNull() || myKnots.IsNull() || myMultiplicities.IsNull())
43     return NULL;
44
45   if (myRational)
46   {
47     if (myWeights.IsNull())
48       return NULL;
49
50     return new Geom_BSplineCurve (*myPoles->Array(),
51                                   *myWeights->Array(),
52                                   *myKnots->Array(),
53                                   *myMultiplicities->Array(),
54                                   mySpineDegree,
55                                   myPeriodic);
56   }
57   else
58     return new Geom_BSplineCurve (*myPoles->Array(),
59                                   *myKnots->Array(),
60                                   *myMultiplicities->Array(),
61                                   mySpineDegree,
62                                   myPeriodic);
63 }
64
65 Handle(Geom_Curve) ShapePersistent_Geom_Curve::pTrimmed::Import() const
66 {
67   if (myBasisCurve.IsNull())
68     return NULL;
69
70   return new Geom_TrimmedCurve (myBasisCurve->Import(), myFirstU, myLastU);
71 }
72
73 Handle(Geom_Curve) ShapePersistent_Geom_Curve::pOffset::Import() const
74 {
75   if (myBasisCurve.IsNull())
76     return NULL;
77
78   return new Geom_OffsetCurve
79     (myBasisCurve->Import(), myOffsetValue, myOffsetDirection);
80 }
81
82 //=======================================================================
83 // Line
84 //=======================================================================
85 template<>
86 Standard_CString ShapePersistent_Geom::instance<ShapePersistent_Geom::Curve,
87                                                 Geom_Line,
88                                                 gp_Ax1>
89   ::PName() const { return "PGeom_Line"; }
90
91 template<>
92 void ShapePersistent_Geom::instance<ShapePersistent_Geom::Curve,
93                                     Geom_Line,
94                                     gp_Ax1>
95   ::Write(StdObjMgt_WriteData& theWriteData) const
96 {
97   Handle(Geom_Line) aMyGeom =
98     Handle(Geom_Line)::DownCast(myTransient);
99   write(theWriteData, aMyGeom->Position());
100 }
101
102 Handle(ShapePersistent_Geom::Curve)
103 ShapePersistent_Geom_Curve::Translate(const Handle(Geom_Line)& theCurve,
104                                       StdObjMgt_TransientPersistentMap& theMap)
105 {
106   Handle(ShapePersistent_Geom::Curve) aPC;
107   if (!theCurve.IsNull())
108   {
109     if (theMap.IsBound(theCurve))
110       aPC = Handle(ShapePersistent_Geom::Curve)::DownCast(theMap.Find(theCurve));
111     else {
112       Handle(Line) aPT = new Line;
113       aPT->myTransient = theCurve;
114       aPC = aPT;
115     }
116   }
117   return aPC;
118 }
119
120 //=======================================================================
121 // Conic
122 //=======================================================================
123 template<>
124 Standard_CString ShapePersistent_Geom::subBase_gp<ShapePersistent_Geom::Curve,
125                                                   gp_Ax2>
126   ::PName() const { return "PGeom_Conic"; }
127
128 //=======================================================================
129 // Circle
130 //=======================================================================
131 template<>
132 Standard_CString ShapePersistent_Geom::instance<ShapePersistent_Geom_Curve::Conic,
133                                                 Geom_Circle,
134                                                 gp_Circ>
135   ::PName() const { return "PGeom_Circle"; }
136
137 template<>
138 void ShapePersistent_Geom::instance<ShapePersistent_Geom_Curve::Conic,
139                                     Geom_Circle,
140                                     gp_Circ>
141   ::Write(StdObjMgt_WriteData& theWriteData) const
142 {
143   Handle(Geom_Circle) aMyGeom =
144     Handle(Geom_Circle)::DownCast(myTransient);
145   theWriteData << aMyGeom->Circ();
146 }
147
148 Handle(ShapePersistent_Geom::Curve)
149 ShapePersistent_Geom_Curve::Translate(const Handle(Geom_Circle)& theCurve,
150                                       StdObjMgt_TransientPersistentMap& theMap)
151 {
152   Handle(ShapePersistent_Geom::Curve) aPC;
153   if (!theCurve.IsNull())
154   {
155     if (theMap.IsBound(theCurve))
156       aPC = Handle(ShapePersistent_Geom::Curve)::DownCast(theMap.Find(theCurve));
157     else {
158       Handle(Circle) aPT = new Circle;
159       aPT->myTransient = theCurve;
160       aPC = aPT;
161     }
162   }
163   return aPC;
164 }
165
166 //=======================================================================
167 // Ellipse
168 //=======================================================================
169 template<>
170 Standard_CString ShapePersistent_Geom::instance<ShapePersistent_Geom_Curve::Conic,
171                                                 Geom_Ellipse,
172                                                 gp_Elips>
173   ::PName() const { return "PGeom_Ellipse"; }
174
175 template<>
176 void ShapePersistent_Geom::instance<ShapePersistent_Geom_Curve::Conic,
177                                     Geom_Ellipse,
178                                     gp_Elips>
179   ::Write(StdObjMgt_WriteData& theWriteData) const
180 {
181   Handle(Geom_Ellipse) aMyGeom =
182     Handle(Geom_Ellipse)::DownCast(myTransient);
183   theWriteData << aMyGeom->Elips();
184 }
185
186 Handle(ShapePersistent_Geom::Curve)
187 ShapePersistent_Geom_Curve::Translate(const Handle(Geom_Ellipse)& theCurve,
188                                       StdObjMgt_TransientPersistentMap& theMap)
189 {
190   Handle(ShapePersistent_Geom::Curve) aPC;
191   if (!theCurve.IsNull())
192   {
193     if (theMap.IsBound(theCurve))
194       aPC = Handle(ShapePersistent_Geom::Curve)::DownCast(theMap.Find(theCurve));
195     else {
196       Handle(Ellipse) aPT = new Ellipse;
197       aPT->myTransient = theCurve;
198       aPC = aPT;
199     }
200   }
201   return aPC;
202 }
203
204 //=======================================================================
205 // Hyperbola
206 //=======================================================================
207 template<>
208 Standard_CString ShapePersistent_Geom::instance<ShapePersistent_Geom_Curve::Conic,
209                                                 Geom_Hyperbola,
210                                                 gp_Hypr>
211   ::PName() const { return "PGeom_Hyperbola"; }
212
213 template<>
214 void ShapePersistent_Geom::instance<ShapePersistent_Geom_Curve::Conic,
215                                     Geom_Hyperbola,
216                                     gp_Hypr>
217   ::Write(StdObjMgt_WriteData& theWriteData) const
218 {
219   Handle(Geom_Hyperbola) aMyGeom =
220     Handle(Geom_Hyperbola)::DownCast(myTransient);
221   theWriteData << aMyGeom->Hypr();
222 }
223
224 Handle(ShapePersistent_Geom::Curve)
225 ShapePersistent_Geom_Curve::Translate(const Handle(Geom_Hyperbola)& theCurve,
226                                       StdObjMgt_TransientPersistentMap& theMap)
227 {
228   Handle(ShapePersistent_Geom::Curve) aPC;
229   if (!theCurve.IsNull())
230   {
231     if (theMap.IsBound(theCurve))
232       aPC = Handle(ShapePersistent_Geom::Curve)::DownCast(theMap.Find(theCurve));
233     else {
234       Handle(Hyperbola) aPT = new Hyperbola;
235       aPT->myTransient = theCurve;
236       aPC = aPT;
237     }
238   }
239   return aPC;
240 }
241
242 //=======================================================================
243 // Parabola
244 //=======================================================================
245 template<>
246 Standard_CString ShapePersistent_Geom::instance<ShapePersistent_Geom_Curve::Conic,
247                                                 Geom_Parabola,
248                                                 gp_Parab>
249   ::PName() const { return "PGeom_Parabola"; }
250
251 template<>
252 void ShapePersistent_Geom::instance<ShapePersistent_Geom_Curve::Conic,
253                                     Geom_Parabola,
254                                     gp_Parab>
255   ::Write(StdObjMgt_WriteData& theWriteData) const
256 {
257   Handle(Geom_Parabola) aMyGeom =
258     Handle(Geom_Parabola)::DownCast(myTransient);
259   theWriteData << aMyGeom->Parab();
260 }
261
262 Handle(ShapePersistent_Geom::Curve) 
263 ShapePersistent_Geom_Curve::Translate(const Handle(Geom_Parabola)& theCurve,
264                                       StdObjMgt_TransientPersistentMap& theMap)
265 {
266   Handle(ShapePersistent_Geom::Curve) aPC;
267   if (!theCurve.IsNull())
268   {
269     if (theMap.IsBound(theCurve))
270       aPC = Handle(ShapePersistent_Geom::Curve)::DownCast(theMap.Find(theCurve));
271     else {
272       Handle(Parabola) aPT = new Parabola;
273       aPT->myTransient = theCurve;
274       aPC = aPT;
275     }
276   }
277   return aPC;
278 }
279
280 //=======================================================================
281 // BezierCurve
282 //=======================================================================
283 Handle(ShapePersistent_Geom::Curve)
284 ShapePersistent_Geom_Curve::Translate(const Handle(Geom_BezierCurve)& theCurve,
285                                       StdObjMgt_TransientPersistentMap& theMap)
286 {
287   Handle(ShapePersistent_Geom::Curve) aPC;
288   if (!theCurve.IsNull())
289   {
290     if (theMap.IsBound(theCurve))
291       aPC = Handle(ShapePersistent_Geom::Curve)::DownCast(theMap.Find(theCurve));
292     else {
293       Handle(Bezier) aPBC = new Bezier;
294       Handle(pBezier) aPpBC = new pBezier;
295       aPpBC->myRational = theCurve->IsRational();
296       aPpBC->myPoles = StdLPersistent_HArray1::Translate<TColgp_HArray1OfPnt>("PColgp_HArray1OfPnt", theCurve->Poles());
297       if (theCurve->IsRational()) {
298         aPpBC->myWeights = StdLPersistent_HArray1::Translate<TColStd_HArray1OfReal>(*theCurve->Weights());
299       }
300       aPBC->myPersistent = aPpBC;
301       aPC = aPBC;
302     }
303   }
304   return aPC;
305 }
306
307 //=======================================================================
308 // BSplineCurve
309 //=======================================================================
310 Handle(ShapePersistent_Geom::Curve)
311 ShapePersistent_Geom_Curve::Translate(const Handle(Geom_BSplineCurve)& theCurve,
312                                       StdObjMgt_TransientPersistentMap& theMap)
313 {
314   Handle(ShapePersistent_Geom::Curve) aPC;
315   if (!theCurve.IsNull())
316   {
317     if (theMap.IsBound(theCurve))
318       aPC = Handle(ShapePersistent_Geom::Curve)::DownCast(theMap.Find(theCurve));
319     else {
320       Handle(BSpline) aPBSC = new BSpline;
321       Handle(pBSpline) aPpBSC = new pBSpline;
322       aPpBSC->myRational = theCurve->IsRational();
323       aPpBSC->myPeriodic = theCurve->IsPeriodic();
324       aPpBSC->mySpineDegree = theCurve->Degree();
325       aPpBSC->myPoles = StdLPersistent_HArray1::Translate<TColgp_HArray1OfPnt>("PColgp_HArray1OfPnt", theCurve->Poles());
326       if (theCurve->IsRational()) {
327         aPpBSC->myWeights = StdLPersistent_HArray1::Translate<TColStd_HArray1OfReal>(*theCurve->Weights());
328       }
329       aPpBSC->myKnots = StdLPersistent_HArray1::Translate<TColStd_HArray1OfReal>(theCurve->Knots());
330       aPpBSC->myMultiplicities = StdLPersistent_HArray1::Translate<TColStd_HArray1OfInteger>(theCurve->Multiplicities());
331       aPBSC->myPersistent = aPpBSC;
332       aPC = aPBSC;
333     }
334   }
335   return aPC;
336 }
337
338 //=======================================================================
339 // TrimmedCurve
340 //=======================================================================
341 Handle(ShapePersistent_Geom::Curve)
342 ShapePersistent_Geom_Curve::Translate(const Handle(Geom_TrimmedCurve)& theCurve,
343                                       StdObjMgt_TransientPersistentMap& theMap)
344 {
345   Handle(ShapePersistent_Geom::Curve) aPC;
346   if (!theCurve.IsNull())
347   {
348     if (theMap.IsBound(theCurve))
349       aPC = Handle(ShapePersistent_Geom::Curve)::DownCast(theMap.Find(theCurve));
350     else {
351       Handle(Trimmed) aPTC = new Trimmed;
352       Handle(pTrimmed) aPpTC = new pTrimmed;
353       aPpTC->myFirstU = theCurve->FirstParameter();
354       aPpTC->myLastU = theCurve->LastParameter();
355       aPpTC->myBasisCurve = ShapePersistent_Geom::Translate(theCurve->BasisCurve(), theMap);
356       aPTC->myPersistent = aPpTC;
357       aPC = aPTC;
358     }
359   }
360   return aPC;
361 }
362
363 //=======================================================================
364 // OffsetCurve
365 //=======================================================================
366 Handle(ShapePersistent_Geom::Curve)
367 ShapePersistent_Geom_Curve::Translate(const Handle(Geom_OffsetCurve)& theCurve,
368                                       StdObjMgt_TransientPersistentMap& theMap)
369 {
370   Handle(ShapePersistent_Geom::Curve) aPC;
371   if (!theCurve.IsNull())
372   {
373     if (theMap.IsBound(theCurve))
374       aPC = Handle(ShapePersistent_Geom::Curve)::DownCast(theMap.Find(theCurve));
375     else {
376       Handle(Offset) aPOC = new Offset;
377       Handle(pOffset) aPpOC = new pOffset;
378       aPpOC->myOffsetDirection = theCurve->Direction();
379       aPpOC->myOffsetValue = theCurve->Offset();
380       aPpOC->myBasisCurve = ShapePersistent_Geom::Translate(theCurve->BasisCurve(), theMap);
381       aPOC->myPersistent = aPpOC;
382       aPC = aPOC;
383     }
384   }
385   return aPC;
386 }