1 // Copyright (c) 2015 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 #include <Standard_NullObject.hxx>
16 #include <ShapePersistent_Geom.hxx>
17 #include <ShapePersistent_Geom_Curve.hxx>
19 #include <Geom_BezierCurve.hxx>
20 #include <Geom_BSplineCurve.hxx>
21 #include <Geom_TrimmedCurve.hxx>
22 #include <Geom_OffsetCurve.hxx>
25 Handle(Geom_Curve) ShapePersistent_Geom_Curve::pBezier::Import() const
32 if (myWeights.IsNull())
34 return new Geom_BezierCurve (*myPoles->Array(), *myWeights->Array());
37 return new Geom_BezierCurve (*myPoles->Array());
40 Handle(Geom_Curve) ShapePersistent_Geom_Curve::pBSpline::Import() const
42 if (myPoles.IsNull() || myKnots.IsNull() || myMultiplicities.IsNull())
47 if (myWeights.IsNull())
50 return new Geom_BSplineCurve (*myPoles->Array(),
53 *myMultiplicities->Array(),
58 return new Geom_BSplineCurve (*myPoles->Array(),
60 *myMultiplicities->Array(),
65 Handle(Geom_Curve) ShapePersistent_Geom_Curve::pTrimmed::Import() const
67 if (myBasisCurve.IsNull())
70 return new Geom_TrimmedCurve (myBasisCurve->Import(), myFirstU, myLastU);
73 Handle(Geom_Curve) ShapePersistent_Geom_Curve::pOffset::Import() const
75 if (myBasisCurve.IsNull())
78 return new Geom_OffsetCurve
79 (myBasisCurve->Import(), myOffsetValue, myOffsetDirection);
82 //=======================================================================
84 //=======================================================================
86 Standard_CString ShapePersistent_Geom::instance<ShapePersistent_Geom::Curve,
89 ::PName() const { return "PGeom_Line"; }
92 void ShapePersistent_Geom::instance<ShapePersistent_Geom::Curve,
95 ::Write(StdObjMgt_WriteData& theWriteData) const
97 Handle(Geom_Line) aMyGeom =
98 Handle(Geom_Line)::DownCast(myTransient);
99 write(theWriteData, aMyGeom->Position());
102 Handle(ShapePersistent_Geom::Curve)
103 ShapePersistent_Geom_Curve::Translate(const Handle(Geom_Line)& theCurve,
104 StdObjMgt_TransientPersistentMap& theMap)
106 Handle(ShapePersistent_Geom::Curve) aPC;
107 if (!theCurve.IsNull())
109 if (theMap.IsBound(theCurve))
110 aPC = Handle(ShapePersistent_Geom::Curve)::DownCast(theMap.Find(theCurve));
112 Handle(Line) aPT = new Line;
113 aPT->myTransient = theCurve;
120 //=======================================================================
122 //=======================================================================
124 Standard_CString ShapePersistent_Geom::subBase_gp<ShapePersistent_Geom::Curve,
126 ::PName() const { return "PGeom_Conic"; }
128 //=======================================================================
130 //=======================================================================
132 Standard_CString ShapePersistent_Geom::instance<ShapePersistent_Geom_Curve::Conic,
135 ::PName() const { return "PGeom_Circle"; }
138 void ShapePersistent_Geom::instance<ShapePersistent_Geom_Curve::Conic,
141 ::Write(StdObjMgt_WriteData& theWriteData) const
143 Handle(Geom_Circle) aMyGeom =
144 Handle(Geom_Circle)::DownCast(myTransient);
145 theWriteData << aMyGeom->Circ();
148 Handle(ShapePersistent_Geom::Curve)
149 ShapePersistent_Geom_Curve::Translate(const Handle(Geom_Circle)& theCurve,
150 StdObjMgt_TransientPersistentMap& theMap)
152 Handle(ShapePersistent_Geom::Curve) aPC;
153 if (!theCurve.IsNull())
155 if (theMap.IsBound(theCurve))
156 aPC = Handle(ShapePersistent_Geom::Curve)::DownCast(theMap.Find(theCurve));
158 Handle(Circle) aPT = new Circle;
159 aPT->myTransient = theCurve;
166 //=======================================================================
168 //=======================================================================
170 Standard_CString ShapePersistent_Geom::instance<ShapePersistent_Geom_Curve::Conic,
173 ::PName() const { return "PGeom_Ellipse"; }
176 void ShapePersistent_Geom::instance<ShapePersistent_Geom_Curve::Conic,
179 ::Write(StdObjMgt_WriteData& theWriteData) const
181 Handle(Geom_Ellipse) aMyGeom =
182 Handle(Geom_Ellipse)::DownCast(myTransient);
183 theWriteData << aMyGeom->Elips();
186 Handle(ShapePersistent_Geom::Curve)
187 ShapePersistent_Geom_Curve::Translate(const Handle(Geom_Ellipse)& theCurve,
188 StdObjMgt_TransientPersistentMap& theMap)
190 Handle(ShapePersistent_Geom::Curve) aPC;
191 if (!theCurve.IsNull())
193 if (theMap.IsBound(theCurve))
194 aPC = Handle(ShapePersistent_Geom::Curve)::DownCast(theMap.Find(theCurve));
196 Handle(Ellipse) aPT = new Ellipse;
197 aPT->myTransient = theCurve;
204 //=======================================================================
206 //=======================================================================
208 Standard_CString ShapePersistent_Geom::instance<ShapePersistent_Geom_Curve::Conic,
211 ::PName() const { return "PGeom_Hyperbola"; }
214 void ShapePersistent_Geom::instance<ShapePersistent_Geom_Curve::Conic,
217 ::Write(StdObjMgt_WriteData& theWriteData) const
219 Handle(Geom_Hyperbola) aMyGeom =
220 Handle(Geom_Hyperbola)::DownCast(myTransient);
221 theWriteData << aMyGeom->Hypr();
224 Handle(ShapePersistent_Geom::Curve)
225 ShapePersistent_Geom_Curve::Translate(const Handle(Geom_Hyperbola)& theCurve,
226 StdObjMgt_TransientPersistentMap& theMap)
228 Handle(ShapePersistent_Geom::Curve) aPC;
229 if (!theCurve.IsNull())
231 if (theMap.IsBound(theCurve))
232 aPC = Handle(ShapePersistent_Geom::Curve)::DownCast(theMap.Find(theCurve));
234 Handle(Hyperbola) aPT = new Hyperbola;
235 aPT->myTransient = theCurve;
242 //=======================================================================
244 //=======================================================================
246 Standard_CString ShapePersistent_Geom::instance<ShapePersistent_Geom_Curve::Conic,
249 ::PName() const { return "PGeom_Parabola"; }
252 void ShapePersistent_Geom::instance<ShapePersistent_Geom_Curve::Conic,
255 ::Write(StdObjMgt_WriteData& theWriteData) const
257 Handle(Geom_Parabola) aMyGeom =
258 Handle(Geom_Parabola)::DownCast(myTransient);
259 theWriteData << aMyGeom->Parab();
262 Handle(ShapePersistent_Geom::Curve)
263 ShapePersistent_Geom_Curve::Translate(const Handle(Geom_Parabola)& theCurve,
264 StdObjMgt_TransientPersistentMap& theMap)
266 Handle(ShapePersistent_Geom::Curve) aPC;
267 if (!theCurve.IsNull())
269 if (theMap.IsBound(theCurve))
270 aPC = Handle(ShapePersistent_Geom::Curve)::DownCast(theMap.Find(theCurve));
272 Handle(Parabola) aPT = new Parabola;
273 aPT->myTransient = theCurve;
280 //=======================================================================
282 //=======================================================================
283 Handle(ShapePersistent_Geom::Curve)
284 ShapePersistent_Geom_Curve::Translate(const Handle(Geom_BezierCurve)& theCurve,
285 StdObjMgt_TransientPersistentMap& theMap)
287 Handle(ShapePersistent_Geom::Curve) aPC;
288 if (!theCurve.IsNull())
290 if (theMap.IsBound(theCurve))
291 aPC = Handle(ShapePersistent_Geom::Curve)::DownCast(theMap.Find(theCurve));
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());
300 aPBC->myPersistent = aPpBC;
307 //=======================================================================
309 //=======================================================================
310 Handle(ShapePersistent_Geom::Curve)
311 ShapePersistent_Geom_Curve::Translate(const Handle(Geom_BSplineCurve)& theCurve,
312 StdObjMgt_TransientPersistentMap& theMap)
314 Handle(ShapePersistent_Geom::Curve) aPC;
315 if (!theCurve.IsNull())
317 if (theMap.IsBound(theCurve))
318 aPC = Handle(ShapePersistent_Geom::Curve)::DownCast(theMap.Find(theCurve));
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());
329 aPpBSC->myKnots = StdLPersistent_HArray1::Translate<TColStd_HArray1OfReal>(theCurve->Knots());
330 aPpBSC->myMultiplicities = StdLPersistent_HArray1::Translate<TColStd_HArray1OfInteger>(theCurve->Multiplicities());
331 aPBSC->myPersistent = aPpBSC;
338 //=======================================================================
340 //=======================================================================
341 Handle(ShapePersistent_Geom::Curve)
342 ShapePersistent_Geom_Curve::Translate(const Handle(Geom_TrimmedCurve)& theCurve,
343 StdObjMgt_TransientPersistentMap& theMap)
345 Handle(ShapePersistent_Geom::Curve) aPC;
346 if (!theCurve.IsNull())
348 if (theMap.IsBound(theCurve))
349 aPC = Handle(ShapePersistent_Geom::Curve)::DownCast(theMap.Find(theCurve));
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;
363 //=======================================================================
365 //=======================================================================
366 Handle(ShapePersistent_Geom::Curve)
367 ShapePersistent_Geom_Curve::Translate(const Handle(Geom_OffsetCurve)& theCurve,
368 StdObjMgt_TransientPersistentMap& theMap)
370 Handle(ShapePersistent_Geom::Curve) aPC;
371 if (!theCurve.IsNull())
373 if (theMap.IsBound(theCurve))
374 aPC = Handle(ShapePersistent_Geom::Curve)::DownCast(theMap.Find(theCurve));
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;