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