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 <ShapePersistent_BRep.hxx>
16 #include <BRep_PointOnCurve.hxx>
17 #include <BRep_PointOnCurveOnSurface.hxx>
18 #include <BRep_PointOnSurface.hxx>
19 #include <BRep_Curve3D.hxx>
20 #include <BRep_CurveOnSurface.hxx>
21 #include <BRep_CurveOnClosedSurface.hxx>
22 #include <BRep_Polygon3D.hxx>
23 #include <BRep_PolygonOnTriangulation.hxx>
24 #include <BRep_PolygonOnClosedTriangulation.hxx>
25 #include <BRep_PolygonOnSurface.hxx>
26 #include <BRep_PolygonOnClosedSurface.hxx>
27 #include <BRep_CurveOn2Surfaces.hxx>
29 #include <BRep_TVertex.hxx>
30 #include <BRep_TEdge.hxx>
31 #include <BRep_TFace.hxx>
42 //=======================================================================
44 //purpose : Read persistent data from a file
45 //=======================================================================
46 void ShapePersistent_BRep::PointRepresentation::Read
47 (StdObjMgt_ReadData& theReadData)
48 { theReadData >> myLocation >> myParameter >> myNext; }
50 //=======================================================================
52 //purpose : Import transient object from the persistent data
53 //=======================================================================
54 void ShapePersistent_BRep::PointRepresentation::Import
55 (BRep_ListOfPointRepresentation& thePoints) const
58 Handle(PointRepresentation) aPoint = this;
59 for (; aPoint; aPoint = aPoint->myNext)
60 thePoints.Prepend (aPoint->import());
63 Handle(BRep_PointRepresentation)
64 ShapePersistent_BRep::PointRepresentation::import() const
67 void ShapePersistent_BRep::PointOnCurve::Read
68 (StdObjMgt_ReadData& theReadData)
70 PointRepresentation::Read (theReadData);
71 theReadData >> myCurve;
74 Handle(BRep_PointRepresentation)
75 ShapePersistent_BRep::PointOnCurve::import() const
80 return new BRep_PointOnCurve
81 (myParameter, myCurve->Import(), myLocation.Import());
84 void ShapePersistent_BRep::PointsOnSurface::Read
85 (StdObjMgt_ReadData& theReadData)
87 PointRepresentation::Read (theReadData);
88 theReadData >> mySurface;
91 void ShapePersistent_BRep::PointOnCurveOnSurface::Read
92 (StdObjMgt_ReadData& theReadData)
94 PointsOnSurface::Read (theReadData);
95 theReadData >> myPCurve;
98 Handle(BRep_PointRepresentation)
99 ShapePersistent_BRep::PointOnCurveOnSurface::import() const
101 if (mySurface.IsNull() || myPCurve.IsNull())
104 return new BRep_PointOnCurveOnSurface
105 (myParameter, myPCurve->Import(), mySurface->Import(), myLocation.Import());
108 void ShapePersistent_BRep::PointOnSurface::Read
109 (StdObjMgt_ReadData& theReadData)
111 PointsOnSurface::Read (theReadData);
112 theReadData >> myParameter2;
115 Handle(BRep_PointRepresentation)
116 ShapePersistent_BRep::PointOnSurface::import() const
118 if (mySurface.IsNull())
121 return new BRep_PointOnSurface
122 (myParameter, myParameter2, mySurface->Import(), myLocation.Import());
125 //=======================================================================
127 //purpose : Read persistent data from a file
128 //=======================================================================
129 void ShapePersistent_BRep::CurveRepresentation::Read
130 (StdObjMgt_ReadData& theReadData)
131 { theReadData >> myLocation >> myNext; }
133 //=======================================================================
135 //purpose : Import transient object from the persistent data
136 //=======================================================================
137 void ShapePersistent_BRep::CurveRepresentation::Import
138 (BRep_ListOfCurveRepresentation& theCurves) const
141 Handle(CurveRepresentation) aCurve = this;
142 for (; aCurve; aCurve = aCurve->myNext)
143 theCurves.Prepend (aCurve->import());
146 Handle(BRep_CurveRepresentation)
147 ShapePersistent_BRep::CurveRepresentation::import() const
150 void ShapePersistent_BRep::GCurve::Read
151 (StdObjMgt_ReadData& theReadData)
153 CurveRepresentation::Read (theReadData);
154 theReadData >> myFirst >> myLast;
157 void ShapePersistent_BRep::Curve3D::Read
158 (StdObjMgt_ReadData& theReadData)
160 GCurve::Read (theReadData);
161 theReadData >> myCurve3D;
164 Handle(BRep_CurveRepresentation)
165 ShapePersistent_BRep::Curve3D::import() const
167 Handle(Geom_Curve) aCurve;
169 aCurve = myCurve3D->Import();
171 Handle(BRep_Curve3D) aRepresentation =
172 new BRep_Curve3D (aCurve, myLocation.Import());
174 aRepresentation->SetRange (myFirst, myLast);
175 return aRepresentation;
178 void ShapePersistent_BRep::CurveOnSurface::Read
179 (StdObjMgt_ReadData& theReadData)
181 GCurve::Read (theReadData);
182 theReadData >> myPCurve >> mySurface >> myUV1 >> myUV2;
185 Handle(BRep_CurveRepresentation)
186 ShapePersistent_BRep::CurveOnSurface::import() const
188 if (myPCurve.IsNull() || mySurface.IsNull())
191 Handle(BRep_CurveOnSurface) aCurve =
192 new BRep_CurveOnSurface (myPCurve->Import(),
194 myLocation.Import());
196 aCurve->SetUVPoints (myUV1, myUV2);
197 aCurve->SetRange (myFirst, myLast);
202 void ShapePersistent_BRep::CurveOnClosedSurface::Read
203 (StdObjMgt_ReadData& theReadData)
205 CurveOnSurface::Read (theReadData);
206 theReadData >> myPCurve2 >> myContinuity >> myUV21 >> myUV22;
209 Handle(BRep_CurveRepresentation)
210 ShapePersistent_BRep::CurveOnClosedSurface::import() const
212 if (myPCurve.IsNull() || mySurface.IsNull() || myPCurve2.IsNull())
215 Handle(BRep_CurveOnClosedSurface) aCurve =
216 new BRep_CurveOnClosedSurface (myPCurve->Import(),
222 aCurve->SetUVPoints (myUV1 , myUV2 );
223 aCurve->SetUVPoints2 (myUV21 , myUV22);
224 aCurve->SetRange (myFirst, myLast);
229 void ShapePersistent_BRep::Polygon3D::Read
230 (StdObjMgt_ReadData& theReadData)
232 CurveRepresentation::Read (theReadData);
233 theReadData >> myPolygon3D;
236 Handle(BRep_CurveRepresentation)
237 ShapePersistent_BRep::Polygon3D::import() const
239 if (myPolygon3D.IsNull())
242 return new BRep_Polygon3D (myPolygon3D->Import(), myLocation.Import());
245 void ShapePersistent_BRep::PolygonOnTriangulation::Read
246 (StdObjMgt_ReadData& theReadData)
248 CurveRepresentation::Read (theReadData);
249 theReadData >> myPolygon >> myTriangulation;
252 Handle(BRep_CurveRepresentation)
253 ShapePersistent_BRep::PolygonOnTriangulation::import() const
255 if (myPolygon.IsNull() || myTriangulation.IsNull())
258 return new BRep_PolygonOnTriangulation (myPolygon->Import(),
259 myTriangulation->Import(),
260 myLocation.Import());
263 void ShapePersistent_BRep::PolygonOnClosedTriangulation::Read
264 (StdObjMgt_ReadData& theReadData)
266 PolygonOnTriangulation::Read (theReadData);
267 theReadData >> myPolygon2;
270 Handle(BRep_CurveRepresentation)
271 ShapePersistent_BRep::PolygonOnClosedTriangulation::import() const
273 if (myPolygon.IsNull() || myTriangulation.IsNull() || myPolygon2.IsNull())
276 return new BRep_PolygonOnClosedTriangulation (myPolygon->Import(),
277 myPolygon2->Import(),
278 myTriangulation->Import(),
279 myLocation.Import());
282 void ShapePersistent_BRep::PolygonOnSurface::Read
283 (StdObjMgt_ReadData& theReadData)
285 CurveRepresentation::Read (theReadData);
286 theReadData >> myPolygon2D >> mySurface;
289 Handle(BRep_CurveRepresentation)
290 ShapePersistent_BRep::PolygonOnSurface::import() const
292 if (myPolygon2D.IsNull() || mySurface.IsNull())
295 return new BRep_PolygonOnSurface (myPolygon2D->Import(),
297 myLocation.Import());
300 void ShapePersistent_BRep::PolygonOnClosedSurface::Read
301 (StdObjMgt_ReadData& theReadData)
303 PolygonOnSurface::Read (theReadData);
304 theReadData >> myPolygon2;
307 Handle(BRep_CurveRepresentation)
308 ShapePersistent_BRep::PolygonOnClosedSurface::import() const
310 if (myPolygon2D.IsNull() || mySurface.IsNull() || myPolygon2.IsNull())
313 return new BRep_PolygonOnClosedSurface (myPolygon2D->Import(),
314 myPolygon2->Import(),
316 myLocation.Import());
319 void ShapePersistent_BRep::CurveOn2Surfaces::Read
320 (StdObjMgt_ReadData& theReadData)
322 CurveRepresentation::Read (theReadData);
323 theReadData >> mySurface >> mySurface2 >> myLocation2 >> myContinuity;
326 Handle(BRep_CurveRepresentation)
327 ShapePersistent_BRep::CurveOn2Surfaces::import() const
329 if (mySurface.IsNull() || mySurface2.IsNull())
332 return new BRep_CurveOn2Surfaces (mySurface->Import(),
333 mySurface2->Import(),
335 myLocation2.Import(),
339 //=======================================================================
340 //function : createTShape
341 //purpose : Create transient TShape object
342 //=======================================================================
343 Handle(TopoDS_TShape) ShapePersistent_BRep::pTVertex::createTShape() const
345 Handle(BRep_TVertex) aTVertex = new BRep_TVertex;
347 aTVertex->Tolerance (myTolerance);
348 aTVertex->Pnt (myPnt);
350 myPoints->Import (aTVertex->ChangePoints());
355 //=======================================================================
356 //function : createTShape
357 //purpose : Create transient TShape object
358 //=======================================================================
359 Handle(TopoDS_TShape) ShapePersistent_BRep::pTEdge::createTShape() const
361 Handle(BRep_TEdge) aTEdge = new BRep_TEdge;
363 aTEdge->Tolerance (myTolerance);
364 aTEdge->SameParameter (myFlags & ParameterMask);
365 aTEdge->SameRange (myFlags & RangeMask);
366 aTEdge->Degenerated (myFlags & DegeneratedMask);
368 myCurves->Import (aTEdge->ChangeCurves());
373 //=======================================================================
374 //function : createTShape
375 //purpose : Create transient TShape object
376 //=======================================================================
377 Handle(TopoDS_TShape) ShapePersistent_BRep::pTFace::createTShape() const
379 Handle(BRep_TFace) aTFace = new BRep_TFace;
381 aTFace->NaturalRestriction (myNaturalRestriction);
382 aTFace->Tolerance (myTolerance);
383 aTFace->Location (myLocation.Import());
386 aTFace->Surface (mySurface->Import());
389 aTFace->Triangulation (myTriangulation->Import());