0028564: Support of applications using old persistence (ShapeSchema)
[occt.git] / src / ShapePersistent / ShapePersistent_BRep.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_BRep.hxx>
17
18 #include <BRep_PointOnCurve.hxx>
19 #include <BRep_PointOnCurveOnSurface.hxx>
20 #include <BRep_PointOnSurface.hxx>
21 #include <BRep_Curve3D.hxx>
22 #include <BRep_CurveOnSurface.hxx>
23 #include <BRep_CurveOnClosedSurface.hxx>
24 #include <BRep_Polygon3D.hxx>
25 #include <BRep_PolygonOnTriangulation.hxx>
26 #include <BRep_PolygonOnClosedTriangulation.hxx>
27 #include <BRep_PolygonOnSurface.hxx>
28 #include <BRep_PolygonOnClosedSurface.hxx>
29 #include <BRep_CurveOn2Surfaces.hxx>
30
31 #include <BRep_TVertex.hxx>
32 #include <BRep_TEdge.hxx>
33 #include <BRep_TFace.hxx>
34
35 #include <Geom_Surface.hxx>
36
37 #include <TopoDS_Vertex.hxx>
38 #include <TopoDS_Edge.hxx>
39 #include <TopoDS_Face.hxx>
40
41 #include <Poly_Polygon2D.hxx>
42 #include <Poly_Polygon3D.hxx>
43 #include <Poly_PolygonOnTriangulation.hxx>
44 #include <Poly_Triangulation.hxx>
45
46 enum
47 {
48   ParameterMask   = 1,
49   RangeMask       = 2,
50   DegeneratedMask = 4
51 };
52
53
54 //=======================================================================
55 // PointRepresentation
56 //=======================================================================
57 void ShapePersistent_BRep::PointRepresentation::Read
58   (StdObjMgt_ReadData& theReadData)
59     { theReadData >> myLocation >> myParameter >> myNext; }
60
61 void ShapePersistent_BRep::PointRepresentation::Write
62   (StdObjMgt_WriteData& theWriteData) const
63     { theWriteData << myLocation << myParameter << myNext; }
64
65 void ShapePersistent_BRep::PointRepresentation::PChildren
66   (StdObjMgt_Persistent::SequenceOfPersistent& theChildren) const
67 {
68   myLocation.PChildren(theChildren);
69   theChildren.Append(myNext);
70 }
71
72 void ShapePersistent_BRep::PointRepresentation::Import
73   (BRep_ListOfPointRepresentation& thePoints) const
74 {
75   thePoints.Clear();
76   Handle(PointRepresentation) aPoint = this;
77   for (; aPoint; aPoint = aPoint->myNext)
78     thePoints.Prepend (aPoint->import());
79 }
80
81 Handle(BRep_PointRepresentation)
82   ShapePersistent_BRep::PointRepresentation::import() const
83     { return NULL; }
84
85 //=======================================================================
86 // PointOnCurve
87 //=======================================================================
88 void ShapePersistent_BRep::PointOnCurve::Read
89   (StdObjMgt_ReadData& theReadData)
90 {
91   PointRepresentation::Read (theReadData);
92   theReadData >> myCurve;
93 }
94
95 void ShapePersistent_BRep::PointOnCurve::Write
96   (StdObjMgt_WriteData& theWriteData) const
97 {
98   PointRepresentation::Write (theWriteData);
99   theWriteData << myCurve;
100 }
101
102 void ShapePersistent_BRep::PointOnCurve::PChildren
103   (StdObjMgt_Persistent::SequenceOfPersistent& theChildren) const
104 {
105   PointRepresentation::PChildren(theChildren);
106   theChildren.Append(myCurve);
107 }
108
109 Handle(BRep_PointRepresentation)
110   ShapePersistent_BRep::PointOnCurve::import() const
111 {
112   Handle(Geom_Curve) aCurve;
113   if (myCurve)
114     aCurve = myCurve->Import();
115
116   return new BRep_PointOnCurve
117     (myParameter, aCurve, myLocation.Import());
118 }
119
120 //=======================================================================
121 // PointsOnSurface
122 //=======================================================================
123 void ShapePersistent_BRep::PointsOnSurface::Read
124   (StdObjMgt_ReadData& theReadData)
125 {
126   PointRepresentation::Read (theReadData);
127   theReadData >> mySurface;
128 }
129
130 void ShapePersistent_BRep::PointsOnSurface::Write
131   (StdObjMgt_WriteData& theWriteData) const
132 {
133   PointRepresentation::Write (theWriteData);
134   theWriteData << mySurface;
135 }
136
137 void ShapePersistent_BRep::PointsOnSurface::PChildren
138   (StdObjMgt_Persistent::SequenceOfPersistent& theChildren) const
139 {
140   PointRepresentation::PChildren(theChildren);
141   theChildren.Append(mySurface);
142 }
143
144 //=======================================================================
145 // PointOnCurveOnSurface
146 //=======================================================================
147 void ShapePersistent_BRep::PointOnCurveOnSurface::Read
148   (StdObjMgt_ReadData& theReadData)
149 {
150   PointsOnSurface::Read (theReadData);
151   theReadData >> myPCurve;
152 }
153
154 void ShapePersistent_BRep::PointOnCurveOnSurface::Write
155   (StdObjMgt_WriteData& theWriteData) const
156 {
157   PointsOnSurface::Write (theWriteData);
158   theWriteData << myPCurve;
159 }
160
161 void ShapePersistent_BRep::PointOnCurveOnSurface::PChildren
162   (StdObjMgt_Persistent::SequenceOfPersistent& theChildren) const
163 {
164   PointRepresentation::PChildren(theChildren);
165   theChildren.Append(myPCurve);
166 }
167
168 Handle(BRep_PointRepresentation)
169   ShapePersistent_BRep::PointOnCurveOnSurface::import() const
170 {
171   Handle(Geom2d_Curve) aPCurve;
172   if (myPCurve)
173     aPCurve = myPCurve->Import();
174
175   Handle(Geom_Surface) aSurface;
176   if (mySurface)
177     aSurface = mySurface->Import();
178
179   return new BRep_PointOnCurveOnSurface
180     (myParameter, aPCurve, aSurface, myLocation.Import());
181 }
182
183 //=======================================================================
184 // PointOnSurface
185 //=======================================================================
186 void ShapePersistent_BRep::PointOnSurface::Read
187   (StdObjMgt_ReadData& theReadData)
188 {
189   PointsOnSurface::Read (theReadData);
190   theReadData >> myParameter2;
191 }
192
193 void ShapePersistent_BRep::PointOnSurface::Write
194   (StdObjMgt_WriteData& theWriteData) const
195 {
196   PointsOnSurface::Write(theWriteData);
197   theWriteData << myParameter2;
198 }
199
200 Handle(BRep_PointRepresentation)
201   ShapePersistent_BRep::PointOnSurface::import() const
202 {
203   Handle(Geom_Surface) aSurface;
204   if (mySurface)
205     aSurface = mySurface->Import();
206
207   return new BRep_PointOnSurface
208     (myParameter, myParameter2, aSurface, myLocation.Import());
209 }
210
211 //=======================================================================
212 // CurveRepresentation
213 //=======================================================================
214 void ShapePersistent_BRep::CurveRepresentation::Read
215   (StdObjMgt_ReadData& theReadData)
216     { theReadData >> myLocation >> myNext; }
217
218 void ShapePersistent_BRep::CurveRepresentation::Write
219   (StdObjMgt_WriteData& theWriteData) const
220     { theWriteData << myLocation << myNext; }
221
222 void ShapePersistent_BRep::CurveRepresentation::PChildren
223   (StdObjMgt_Persistent::SequenceOfPersistent& theChildren) const
224 {
225   myLocation.PChildren(theChildren);
226   theChildren.Append(myNext);
227 }
228
229 void ShapePersistent_BRep::CurveRepresentation::Import
230   (BRep_ListOfCurveRepresentation& theCurves) const
231 {
232   theCurves.Clear();
233   Handle(CurveRepresentation) aCurve = this;
234   for (; aCurve; aCurve = aCurve->myNext)
235     theCurves.Prepend (aCurve->import());
236 }
237
238 Handle(BRep_CurveRepresentation)
239   ShapePersistent_BRep::CurveRepresentation::import() const
240     { return NULL; }
241
242 //=======================================================================
243 // GCurve
244 //=======================================================================
245 void ShapePersistent_BRep::GCurve::Read
246   (StdObjMgt_ReadData& theReadData)
247 {
248   CurveRepresentation::Read (theReadData);
249   theReadData >> myFirst >> myLast;
250 }
251
252 void ShapePersistent_BRep::GCurve::Write
253   (StdObjMgt_WriteData& theWriteData) const
254 {
255   CurveRepresentation::Write(theWriteData);
256   theWriteData << myFirst << myLast;
257 }
258
259 //=======================================================================
260 // Curve3D
261 //=======================================================================
262 void ShapePersistent_BRep::Curve3D::Read
263   (StdObjMgt_ReadData& theReadData)
264 {
265   GCurve::Read (theReadData);
266   theReadData >> myCurve3D;
267 }
268
269 void ShapePersistent_BRep::Curve3D::Write
270   (StdObjMgt_WriteData& theWriteData) const
271 {
272   GCurve::Write (theWriteData);
273   theWriteData << myCurve3D;
274 }
275
276 void ShapePersistent_BRep::Curve3D::PChildren
277   (StdObjMgt_Persistent::SequenceOfPersistent& theChildren) const
278 {
279   GCurve::PChildren(theChildren);
280   theChildren.Append(myCurve3D);
281 }
282
283 Handle(BRep_CurveRepresentation)
284   ShapePersistent_BRep::Curve3D::import() const
285 {
286   Handle(Geom_Curve) aCurve3D;
287   if (myCurve3D)
288     aCurve3D = myCurve3D->Import();
289
290   Handle(BRep_Curve3D) aRepresentation =
291     new BRep_Curve3D (aCurve3D, myLocation.Import());
292
293   aRepresentation->SetRange (myFirst, myLast);
294   return aRepresentation;
295 }
296
297 //=======================================================================
298 // CurveOnSurface
299 //=======================================================================
300 void ShapePersistent_BRep::CurveOnSurface::Read
301   (StdObjMgt_ReadData& theReadData)
302 {
303   GCurve::Read (theReadData);
304   theReadData >> myPCurve >> mySurface >> myUV1 >> myUV2;
305 }
306
307 void ShapePersistent_BRep::CurveOnSurface::Write
308   (StdObjMgt_WriteData& theWriteData) const
309 {
310   GCurve::Write (theWriteData);
311   theWriteData << myPCurve << mySurface << myUV1 << myUV2;
312 }
313
314 void ShapePersistent_BRep::CurveOnSurface::PChildren
315   (StdObjMgt_Persistent::SequenceOfPersistent& theChildren) const
316 {
317   GCurve::PChildren(theChildren);
318   theChildren.Append(myPCurve);
319   theChildren.Append(mySurface);
320 }
321
322 Handle(BRep_CurveRepresentation)
323   ShapePersistent_BRep::CurveOnSurface::import() const
324 {
325   Handle(Geom2d_Curve) aPCurve;
326   if (myPCurve)
327     aPCurve = myPCurve->Import();
328
329   Handle(Geom_Surface) aSurface;
330   if (mySurface)
331     aSurface = mySurface->Import();
332
333   Handle(BRep_CurveOnSurface) aRepresentation =
334     new BRep_CurveOnSurface (aPCurve, aSurface, myLocation.Import());
335
336   aRepresentation->SetUVPoints (myUV1, myUV2);
337   aRepresentation->SetRange (myFirst, myLast);
338
339   return aRepresentation;
340 }
341
342 //=======================================================================
343 // CurveOnClosedSurface
344 //=======================================================================
345 void ShapePersistent_BRep::CurveOnClosedSurface::Read
346   (StdObjMgt_ReadData& theReadData)
347 {
348   CurveOnSurface::Read (theReadData);
349   theReadData >> myPCurve2 >> myContinuity >> myUV21 >> myUV22;
350 }
351
352 void ShapePersistent_BRep::CurveOnClosedSurface::Write
353   (StdObjMgt_WriteData& theWriteData) const
354 {
355   CurveOnSurface::Write (theWriteData);
356   theWriteData << myPCurve2 << myContinuity << myUV21 << myUV22;
357 }
358
359 void ShapePersistent_BRep::CurveOnClosedSurface::PChildren
360   (StdObjMgt_Persistent::SequenceOfPersistent& theChildren) const
361 {
362   CurveOnSurface::PChildren(theChildren);
363   theChildren.Append(myPCurve2);
364 }
365
366 Handle(BRep_CurveRepresentation)
367   ShapePersistent_BRep::CurveOnClosedSurface::import() const
368 {
369   Handle(Geom2d_Curve) aPCurve;
370   if (myPCurve)
371     aPCurve = myPCurve->Import();
372
373   Handle(Geom2d_Curve) aPCurve2;
374   if (myPCurve2)
375     aPCurve2 = myPCurve2->Import();
376
377   Handle(Geom_Surface) aSurface;
378   if (mySurface)
379     aSurface = mySurface->Import();
380
381   GeomAbs_Shape aContinuity = static_cast<GeomAbs_Shape> (myContinuity);
382
383   Handle(BRep_CurveOnClosedSurface) aRepresentation =
384     new BRep_CurveOnClosedSurface
385       (aPCurve, aPCurve2, aSurface, myLocation.Import(), aContinuity);
386
387   aRepresentation->SetUVPoints  (myUV1  , myUV2 );
388   aRepresentation->SetUVPoints2 (myUV21 , myUV22);
389   aRepresentation->SetRange     (myFirst, myLast);
390
391   return aRepresentation;
392 }
393
394 //=======================================================================
395 // Polygon3D
396 //=======================================================================
397 void ShapePersistent_BRep::Polygon3D::Read
398   (StdObjMgt_ReadData& theReadData)
399 {
400   CurveRepresentation::Read (theReadData);
401   theReadData >> myPolygon3D;
402 }
403
404 void ShapePersistent_BRep::Polygon3D::Write
405   (StdObjMgt_WriteData& theWriteData) const
406 {
407   CurveRepresentation::Write (theWriteData);
408   theWriteData << myPolygon3D;
409 }
410
411 void ShapePersistent_BRep::Polygon3D::PChildren
412   (StdObjMgt_Persistent::SequenceOfPersistent& theChildren) const
413 {
414   CurveRepresentation::PChildren(theChildren);
415   theChildren.Append(myPolygon3D);
416 }
417
418 Handle(BRep_CurveRepresentation)
419   ShapePersistent_BRep::Polygon3D::import() const
420 {
421   Handle(Poly_Polygon3D) aPolygon3D;
422   if (myPolygon3D)
423     aPolygon3D = myPolygon3D->Import();
424
425   return new BRep_Polygon3D (aPolygon3D, myLocation.Import());
426 }
427
428 //=======================================================================
429 // PolygonOnTriangulation
430 //=======================================================================
431 void ShapePersistent_BRep::PolygonOnTriangulation::Read
432   (StdObjMgt_ReadData& theReadData)
433 {
434   CurveRepresentation::Read (theReadData);
435   theReadData >> myPolygon >> myTriangulation;
436 }
437
438 void ShapePersistent_BRep::PolygonOnTriangulation::Write
439   (StdObjMgt_WriteData& theWriteData) const
440 {
441   CurveRepresentation::Write (theWriteData);
442   theWriteData << myPolygon << myTriangulation;
443 }
444
445 void ShapePersistent_BRep::PolygonOnTriangulation::PChildren
446   (StdObjMgt_Persistent::SequenceOfPersistent& theChildren) const
447 {
448   CurveRepresentation::PChildren(theChildren);
449   theChildren.Append(myPolygon);
450   theChildren.Append(myTriangulation);
451 }
452
453 Handle(BRep_CurveRepresentation)
454   ShapePersistent_BRep::PolygonOnTriangulation::import() const
455 {
456   Handle(Poly_PolygonOnTriangulation) aPolygon;
457   if (myPolygon)
458     aPolygon = myPolygon->Import();
459
460   Handle(Poly_Triangulation) aTriangulation;
461   if (myTriangulation)
462     aTriangulation = myTriangulation->Import();
463
464   return new BRep_PolygonOnTriangulation
465     (aPolygon, aTriangulation, myLocation.Import());
466 }
467
468 //=======================================================================
469 // PolygonOnClosedTriangulation
470 //=======================================================================
471 void ShapePersistent_BRep::PolygonOnClosedTriangulation::Read
472   (StdObjMgt_ReadData& theReadData)
473 {
474   PolygonOnTriangulation::Read (theReadData);
475   theReadData >> myPolygon2;
476 }
477
478 void ShapePersistent_BRep::PolygonOnClosedTriangulation::Write
479   (StdObjMgt_WriteData& theWriteData) const
480 {
481   PolygonOnTriangulation::Write (theWriteData);
482   theWriteData << myPolygon2;
483 }
484
485 void ShapePersistent_BRep::PolygonOnClosedTriangulation::PChildren
486   (StdObjMgt_Persistent::SequenceOfPersistent& theChildren) const
487 {
488   PolygonOnTriangulation::PChildren(theChildren);
489   theChildren.Append(myPolygon2);
490 }
491
492 Handle(BRep_CurveRepresentation)
493   ShapePersistent_BRep::PolygonOnClosedTriangulation::import() const
494 {
495   Handle(Poly_PolygonOnTriangulation) aPolygon;
496   if (myPolygon)
497     aPolygon = myPolygon->Import();
498
499   Handle(Poly_PolygonOnTriangulation) aPolygon2;
500   if (myPolygon2)
501     aPolygon2 = myPolygon2->Import();
502
503   Handle(Poly_Triangulation) aTriangulation;
504   if (myTriangulation)
505     aTriangulation = myTriangulation->Import();
506
507   return new BRep_PolygonOnClosedTriangulation
508     (aPolygon, aPolygon2, aTriangulation, myLocation.Import());
509 }
510
511 //=======================================================================
512 // PolygonOnSurface
513 //=======================================================================
514 void ShapePersistent_BRep::PolygonOnSurface::Read
515   (StdObjMgt_ReadData& theReadData)
516 {
517   CurveRepresentation::Read (theReadData);
518   theReadData >> myPolygon2D >> mySurface;
519 }
520
521 void ShapePersistent_BRep::PolygonOnSurface::Write
522   (StdObjMgt_WriteData& theWriteData) const
523 {
524   CurveRepresentation::Write (theWriteData);
525   theWriteData << myPolygon2D << mySurface;
526 }
527
528 void ShapePersistent_BRep::PolygonOnSurface::PChildren
529   (StdObjMgt_Persistent::SequenceOfPersistent& theChildren) const
530 {
531   CurveRepresentation::PChildren(theChildren);
532   theChildren.Append(myPolygon2D);
533   theChildren.Append(mySurface);
534 }
535
536 Handle(BRep_CurveRepresentation)
537   ShapePersistent_BRep::PolygonOnSurface::import() const
538 {
539   Handle(Poly_Polygon2D) aPolygon2D;
540   if (myPolygon2D)
541     aPolygon2D = myPolygon2D->Import();
542
543   Handle(Geom_Surface) aSurface;
544   if (mySurface)
545     aSurface = mySurface->Import();
546
547   return new BRep_PolygonOnSurface (aPolygon2D, aSurface, myLocation.Import());
548 }
549
550 //=======================================================================
551 // PolygonOnClosedSurface
552 //=======================================================================
553 void ShapePersistent_BRep::PolygonOnClosedSurface::Read
554   (StdObjMgt_ReadData& theReadData)
555 {
556   PolygonOnSurface::Read (theReadData);
557   theReadData >> myPolygon2;
558 }
559
560 void ShapePersistent_BRep::PolygonOnClosedSurface::Write
561   (StdObjMgt_WriteData& theWriteData) const
562 {
563   PolygonOnSurface::Write (theWriteData);
564   theWriteData << myPolygon2;
565 }
566
567 void ShapePersistent_BRep::PolygonOnClosedSurface::PChildren
568   (StdObjMgt_Persistent::SequenceOfPersistent& theChildren) const
569 {
570   PolygonOnSurface::PChildren(theChildren);
571   theChildren.Append(myPolygon2);
572 }
573
574 Handle(BRep_CurveRepresentation)
575   ShapePersistent_BRep::PolygonOnClosedSurface::import() const
576 {
577   Handle(Poly_Polygon2D) aPolygon2D;
578   if (myPolygon2D)
579     aPolygon2D = myPolygon2D->Import();
580
581   Handle(Poly_Polygon2D) aPolygon2;
582   if (myPolygon2)
583     aPolygon2 = myPolygon2->Import();
584
585   Handle(Geom_Surface) aSurface;
586   if (mySurface)
587     aSurface = mySurface->Import();
588
589   return new BRep_PolygonOnClosedSurface
590     (aPolygon2D, aPolygon2, aSurface, myLocation.Import());
591 }
592
593 //=======================================================================
594 // CurveOn2Surfaces
595 //=======================================================================
596 void ShapePersistent_BRep::CurveOn2Surfaces::Read
597   (StdObjMgt_ReadData& theReadData)
598 {
599   CurveRepresentation::Read (theReadData);
600   theReadData >> mySurface >> mySurface2 >> myLocation2 >> myContinuity;
601 }
602
603 void ShapePersistent_BRep::CurveOn2Surfaces::Write
604   (StdObjMgt_WriteData& theWriteData) const
605 {
606   CurveRepresentation::Write (theWriteData);
607   theWriteData << mySurface << mySurface2 << myLocation2 << myContinuity;
608 }
609
610 void ShapePersistent_BRep::CurveOn2Surfaces::PChildren
611   (StdObjMgt_Persistent::SequenceOfPersistent& theChildren) const
612 {
613   CurveRepresentation::PChildren(theChildren);
614   theChildren.Append(mySurface);
615   theChildren.Append(mySurface2);
616   myLocation2.PChildren(theChildren);
617 }
618
619 Handle(BRep_CurveRepresentation)
620   ShapePersistent_BRep::CurveOn2Surfaces::import() const
621 {
622   Handle(Geom_Surface) aSurface;
623   if (mySurface)
624     aSurface = mySurface->Import();
625
626   Handle(Geom_Surface) aSurface2;
627   if (mySurface2)
628     aSurface2 = mySurface2->Import();
629
630   GeomAbs_Shape aContinuity = static_cast<GeomAbs_Shape> (myContinuity);
631
632   return new BRep_CurveOn2Surfaces
633     (aSurface, aSurface2, myLocation.Import(), myLocation2.Import(), aContinuity);
634 }
635
636 //=======================================================================
637 //function : createTShape
638 //purpose  : Create transient TShape object
639 //=======================================================================
640 Handle(TopoDS_TShape) ShapePersistent_BRep::pTVertex::createTShape() const
641 {
642   Handle(BRep_TVertex) aTVertex = new BRep_TVertex;
643
644   aTVertex->Tolerance (myTolerance);
645   aTVertex->Pnt       (myPnt);
646
647   myPoints->Import (aTVertex->ChangePoints());
648
649   return aTVertex;
650 }
651
652 //=======================================================================
653 //function : createTShape
654 //purpose  : Create transient TShape object
655 //=======================================================================
656 Handle(TopoDS_TShape) ShapePersistent_BRep::pTEdge::createTShape() const
657 {
658   Handle(BRep_TEdge) aTEdge = new BRep_TEdge;
659
660   aTEdge->Tolerance     (myTolerance);
661   aTEdge->SameParameter ((myFlags & ParameterMask)   != 0);
662   aTEdge->SameRange     ((myFlags & RangeMask)       != 0);
663   aTEdge->Degenerated   ((myFlags & DegeneratedMask) != 0);
664
665   myCurves->Import (aTEdge->ChangeCurves());
666
667   return aTEdge;
668 }
669
670 //=======================================================================
671 //function : createTShape
672 //purpose  : Create transient TShape object
673 //=======================================================================
674 Handle(TopoDS_TShape) ShapePersistent_BRep::pTFace::createTShape() const
675 {
676   Handle(BRep_TFace) aTFace = new BRep_TFace;
677
678   aTFace->NaturalRestriction (myNaturalRestriction);
679   aTFace->Tolerance          (myTolerance);
680   aTFace->Location           (myLocation.Import());
681
682   if (mySurface)
683     aTFace->Surface (mySurface->Import());
684
685   if (myTriangulation)
686     aTFace->Triangulation (myTriangulation->Import());
687
688   return aTFace;
689 }
690
691 //=======================================================================
692 //function : Translate
693 //purpose  : Translates a shape to its persistent avatar
694 //=======================================================================
695 Handle(ShapePersistent_BRep::TVertex::pTObjectT)
696 ShapePersistent_BRep::Translate (const TopoDS_Vertex& theVertex,
697                                  StdObjMgt_TransientPersistentMap& theMap)
698 {
699   Handle(BRep_TVertex) TTV = Handle(BRep_TVertex)::DownCast (theVertex.TShape());
700
701   Handle(TVertex::pTObjectT) PTV = new TVertex::pTObjectT;
702
703   PTV->myPnt = TTV->Pnt();
704   PTV->myTolerance = TTV->Tolerance();
705
706   BRep_ListIteratorOfListOfPointRepresentation anItPR(TTV->Points());
707
708   Handle(PointRepresentation) PPR, CPPR;
709   while (anItPR.More())
710   {
711     const Handle(BRep_PointRepresentation)& PR = anItPR.Value();
712     if (PR->IsPointOnCurve()) {
713       Handle(PointOnCurve) POC = Translate(PR->Parameter(), 
714                                            PR->Curve(), 
715                                            PR->Location(), 
716                                            theMap);
717       CPPR = POC;
718     }
719     else if (PR->IsPointOnCurveOnSurface()) {
720       Handle(PointOnCurveOnSurface) POCS = Translate(PR->Parameter(), 
721                                                      PR->PCurve(), 
722                                                      PR->Surface(), 
723                                                      PR->Location(), 
724                                                      theMap);
725       CPPR = POCS;
726     }
727     else if (PR->IsPointOnSurface()) {
728       Handle(PointOnSurface) POS = Translate(PR->Parameter(), 
729                                              PR->Parameter2(), 
730                                              PR->Surface(), 
731                                              PR->Location(), 
732                                              theMap);
733       CPPR = POS;
734     }
735
736     CPPR->myNext = PPR;
737     PPR = CPPR;
738     anItPR.Next();
739   }
740
741   PTV->myPoints = PPR;
742
743   return PTV;
744 }
745
746 //=======================================================================
747 //function : Translate
748 //purpose  : Translates a shape to its persistent avatar
749 //=======================================================================
750 Handle(ShapePersistent_BRep::TEdge::pTObjectT)
751 ShapePersistent_BRep::Translate (const TopoDS_Edge& theEdge,
752                                  StdObjMgt_TransientPersistentMap& theMap,
753                                  ShapePersistent_TriangleMode theTriangleMode)
754 {
755   Handle(BRep_TEdge) TTE = Handle(BRep_TEdge)::DownCast (theEdge.TShape());
756
757   Handle(TEdge::pTObjectT) PTE = new TEdge::pTObjectT;
758
759   PTE->myTolerance = TTE->Tolerance();
760   if (TTE->SameParameter()) PTE->myFlags |= ParameterMask;
761   if (TTE->SameRange())     PTE->myFlags |= RangeMask;
762   if (TTE->Degenerated())   PTE->myFlags |= DegeneratedMask;
763
764   // Representations
765   BRep_ListIteratorOfListOfCurveRepresentation itcr(TTE->Curves());
766
767   Handle(CurveRepresentation) PCR, CPCR;
768   Handle(BRep_GCurve) GC;
769   Standard_Real f, l;
770
771   while (itcr.More()) 
772   {
773     const Handle(BRep_CurveRepresentation)& CR = itcr.Value();
774     GC = Handle(BRep_GCurve)::DownCast(CR);
775     if (!GC.IsNull()) 
776     {
777       GC->Range(f, l);
778       // CurveRepresentation is Curve3D
779       if (CR->IsCurve3D()) {
780         Handle(Curve3D) C3D = Translate(CR->Curve3D(), f, l, CR->Location(), theMap);
781         CPCR = C3D;
782       }
783       // CurveRepresentation is CurveOnSurface
784       else if (CR->IsCurveOnSurface()) 
785       {
786         Handle(BRep_CurveOnSurface)& theCOS = (Handle(BRep_CurveOnSurface)&) CR;
787         Handle(CurveOnSurface) COS;
788         // CurveRepresentation is CurveOnSurface
789         if (!CR->IsCurveOnClosedSurface()) 
790         {
791           COS = Translate(CR->PCurve(), f, l, CR->Surface(), CR->Location(), theMap);
792         }
793         // CurveRepresentation is CurveOnClosedSurface
794         else 
795         {
796           // get UVPoints for the CurveOnClosedSurface definition.
797           Handle(BRep_CurveOnClosedSurface)& theCOCS =
798             (Handle(BRep_CurveOnClosedSurface)&) CR;
799           gp_Pnt2d Pnt21, Pnt22;
800           theCOCS->UVPoints2(Pnt21, Pnt22);
801           Handle(CurveOnClosedSurface) COCS = Translate(CR->PCurve(), CR->PCurve2(), 
802                                                         f, l, CR->Surface(), 
803                                                         CR->Location(), CR->Continuity(), 
804                                                         theMap);
805           COCS->myUV21 = Pnt21;
806           COCS->myUV22 = Pnt22;
807           COS = COCS;
808         }
809
810         // get UVPoints for the CurveOnSurface definition.
811         gp_Pnt2d Pnt1, Pnt2;
812         theCOS->UVPoints(Pnt1, Pnt2);
813         COS->myUV1 = Pnt1;
814         COS->myUV2 = Pnt2;
815         CPCR = COS;
816       }
817     }
818     // CurveRepresentation is CurveOn2Surfaces
819     else if (CR->IsRegularity()) 
820     {
821       Handle(CurveOn2Surfaces) R = Translate(CR->Surface(), CR->Surface2(), 
822                                              CR->Location(), CR->Location2(), 
823                                              CR->Continuity(), 
824                                              theMap);
825       CPCR = R;
826     }
827     // CurveRepresentation is Polygon or Triangulation
828     else if (theTriangleMode == ShapePersistent_WithTriangle) {
829       // CurveRepresentation is Polygon3D
830       if (CR->IsPolygon3D()) {
831         Handle(Polygon3D) P3D = Translate(CR->Polygon3D(), CR->Location(), theMap);
832         CPCR = P3D;
833       }
834       // CurveRepresentation is PolygonOnSurface
835       else if (CR->IsPolygonOnSurface()) 
836       {
837         // CurveRepresentation is PolygonOnClosedSurface
838         if (CR->IsPolygonOnClosedSurface()) {
839           Handle(PolygonOnClosedSurface) PolOCS = Translate(CR->Polygon(), CR->Polygon2(), 
840                                                             CR->Surface(), CR->Location(), 
841                                                             theMap);
842           CPCR = PolOCS;
843         }
844         // CurveRepresentation is PolygonOnSurface
845         else 
846         {
847           Handle(PolygonOnSurface) PolOS = Translate(CR->Polygon(), CR->Surface(), 
848                                                      CR->Location(), theMap);
849           CPCR = PolOS;
850         }
851       }
852       // CurveRepresentation is PolygonOnTriangulation
853       else if (CR->IsPolygonOnTriangulation()) 
854       {
855         // CurveRepresentation is PolygonOnClosedTriangulation
856         if (CR->IsPolygonOnClosedTriangulation()) 
857         {
858           Handle(PolygonOnClosedTriangulation) PolOCT = Translate(CR->PolygonOnTriangulation(), 
859                                                                   CR->PolygonOnTriangulation2(), 
860                                                                   CR->Triangulation(), 
861                                                                   CR->Location(), 
862                                                                   theMap);
863           CPCR = PolOCT;
864         }
865         // CurveRepresentation is PolygonOnTriangulation
866         else 
867         {
868           Handle(PolygonOnTriangulation) PolOT = Translate(CR->PolygonOnTriangulation(), 
869                                                            CR->Triangulation(), 
870                                                            CR->Location(), 
871                                                            theMap);
872           CPCR = PolOT;
873         }
874       }
875     }
876     else 
877     {
878       // jumps the curve representation
879       itcr.Next();
880       continue;
881     }
882
883     Standard_NullObject_Raise_if(CPCR.IsNull(), "Null CurveRepresentation");
884
885     CPCR->myNext = PCR;
886     PCR = CPCR;
887     itcr.Next();
888   }
889
890   // set
891   PTE->myCurves = PCR;
892
893   return PTE;
894 }
895
896 //=======================================================================
897 //function : Translate
898 //purpose  : Translates a shape to its persistent avatar
899 //=======================================================================
900 Handle(ShapePersistent_BRep::TFace::pTObjectT)
901 ShapePersistent_BRep::Translate (const TopoDS_Face& theFace,
902                                  StdObjMgt_TransientPersistentMap& theMap,
903                                  ShapePersistent_TriangleMode theTriangleMode)
904 {
905   Handle(BRep_TFace) TTF = Handle(BRep_TFace)::DownCast (theFace.TShape());
906
907   Handle(TFace::pTObjectT) PTF = new TFace::pTObjectT;
908
909   PTF->myTolerance = TTF->Tolerance();
910   PTF->myLocation = StdObject_Location::Translate(TTF->Location(), theMap);
911   PTF->myNaturalRestriction = TTF->NaturalRestriction();
912
913   // Surface
914   PTF->mySurface = ShapePersistent_Geom::Translate(TTF->Surface(), theMap);
915
916   // Triangulation
917   if (theTriangleMode == ShapePersistent_WithTriangle) {
918     PTF->myTriangulation = ShapePersistent_Poly::Translate(TTF->Triangulation(), theMap);
919   }
920
921   return PTF;
922 }
923
924 //=======================================================================
925 //function : Translate
926 //purpose  : Translates a shape to its persistent avatar
927 //=======================================================================
928 Handle(ShapePersistent_BRep::PointOnCurve)
929 ShapePersistent_BRep::Translate (Standard_Real theParam,
930                                  const Handle(Geom_Curve)& theCurve,
931                                  const TopLoc_Location& theLoc,
932                                  StdObjMgt_TransientPersistentMap& theMap)
933 {
934   Handle(PointOnCurve) aPPonC = new PointOnCurve;
935   aPPonC->myParameter = theParam;
936   aPPonC->myCurve = ShapePersistent_Geom::Translate(theCurve, theMap);
937   aPPonC->myLocation = StdObject_Location::Translate(theLoc, theMap);
938   return aPPonC;
939 }
940
941 //=======================================================================
942 //function : Translate
943 //purpose  : Translates a shape to its persistent avatar
944 //=======================================================================
945 Handle(ShapePersistent_BRep::PointOnCurveOnSurface)
946 ShapePersistent_BRep::Translate(Standard_Real theParam,
947                                 const Handle(Geom2d_Curve)& theCurve,
948                                 const Handle(Geom_Surface)& theSurf,
949                                 const TopLoc_Location& theLoc,
950                                 StdObjMgt_TransientPersistentMap& theMap)
951 {
952   Handle(PointOnCurveOnSurface) aPPonConS = new PointOnCurveOnSurface;
953   aPPonConS->myParameter = theParam;
954   aPPonConS->myPCurve = ShapePersistent_Geom2d::Translate(theCurve, theMap);
955   aPPonConS->mySurface = ShapePersistent_Geom::Translate(theSurf, theMap);
956   aPPonConS->myLocation = StdObject_Location::Translate(theLoc, theMap);
957   return aPPonConS;
958 }
959
960 //=======================================================================
961 //function : Translate
962 //purpose  : Translates a shape to its persistent avatar
963 //=======================================================================
964 Handle(ShapePersistent_BRep::PointOnSurface)
965 ShapePersistent_BRep::Translate(Standard_Real theParam,
966                                 Standard_Real theParam2,
967                                 const Handle(Geom_Surface)& theSurf,
968                                 const TopLoc_Location& theLoc,
969                                 StdObjMgt_TransientPersistentMap& theMap)
970 {
971   Handle(PointOnSurface) aPonS = new PointOnSurface;
972   aPonS->myParameter = theParam;
973   aPonS->myParameter2 = theParam2;
974   aPonS->mySurface = ShapePersistent_Geom::Translate(theSurf, theMap);
975   aPonS->myLocation = StdObject_Location::Translate(theLoc, theMap);
976   return aPonS;
977 }
978
979 //=======================================================================
980 //function : Translate
981 //purpose  : Translates a shape to its persistent avatar
982 //=======================================================================
983 Handle(ShapePersistent_BRep::CurveOnSurface)
984 ShapePersistent_BRep::Translate(const Handle(Geom2d_Curve)& theCurve,
985                                 const Standard_Real theFirstParam,
986                                 const Standard_Real theLastParam,
987                                 const Handle(Geom_Surface)& theSurf,
988                                 const TopLoc_Location& theLoc,
989                                 StdObjMgt_TransientPersistentMap& theMap)
990 {
991   Handle(CurveOnSurface) aPConS = new CurveOnSurface;
992   aPConS->myPCurve = ShapePersistent_Geom2d::Translate(theCurve, theMap);
993   aPConS->myFirst = theFirstParam;
994   aPConS->myLast = theLastParam;
995   aPConS->mySurface = ShapePersistent_Geom::Translate(theSurf, theMap);
996   aPConS->myLocation = StdObject_Location::Translate(theLoc, theMap);
997   return aPConS;
998 }
999
1000 //=======================================================================
1001 //function : Translate
1002 //purpose  : Translates a shape to its persistent avatar
1003 //=======================================================================
1004 Handle(ShapePersistent_BRep::CurveOnClosedSurface)
1005 ShapePersistent_BRep::Translate(const Handle(Geom2d_Curve)& theCurve,
1006                                 const Handle(Geom2d_Curve)& theCurve2,
1007                                 const Standard_Real theFirstParam,
1008                                 const Standard_Real theLastParam,
1009                                 const Handle(Geom_Surface)& theSurf,
1010                                 const TopLoc_Location& theLoc,
1011                                 const GeomAbs_Shape theContinuity,
1012                                 StdObjMgt_TransientPersistentMap& theMap)
1013 {
1014   Handle(CurveOnClosedSurface) aPConCS = new CurveOnClosedSurface;
1015   aPConCS->myPCurve = ShapePersistent_Geom2d::Translate(theCurve, theMap);
1016   aPConCS->myPCurve2 = ShapePersistent_Geom2d::Translate(theCurve2, theMap);
1017   aPConCS->myFirst = theFirstParam;
1018   aPConCS->myLast = theLastParam;
1019   aPConCS->mySurface = ShapePersistent_Geom::Translate(theSurf, theMap);
1020   aPConCS->myLocation = StdObject_Location::Translate(theLoc, theMap);
1021   aPConCS->myContinuity = theContinuity;
1022   return aPConCS;
1023 }
1024
1025 //=======================================================================
1026 //function : Translate
1027 //purpose  : Translates a shape to its persistent avatar
1028 //=======================================================================
1029 Handle(ShapePersistent_BRep::CurveOn2Surfaces)
1030 ShapePersistent_BRep::Translate(const Handle(Geom_Surface)& theSurf,
1031                                 const Handle(Geom_Surface)& theSurf2,
1032                                 const TopLoc_Location& theLoc, 
1033                                 const TopLoc_Location& theLoc2,
1034                                 const GeomAbs_Shape theContinuity,
1035                                 StdObjMgt_TransientPersistentMap& theMap)
1036 {
1037   Handle(CurveOn2Surfaces) aPCon2S = new CurveOn2Surfaces;
1038   aPCon2S->mySurface = ShapePersistent_Geom::Translate(theSurf, theMap);
1039   aPCon2S->mySurface2 = ShapePersistent_Geom::Translate(theSurf2, theMap);
1040   aPCon2S->myLocation = StdObject_Location::Translate(theLoc, theMap);
1041   aPCon2S->myLocation2 = StdObject_Location::Translate(theLoc2, theMap);
1042   aPCon2S->myContinuity = theContinuity;
1043   return aPCon2S;
1044 }
1045
1046 //=======================================================================
1047 //function : Translate
1048 //purpose  : Translates a shape to its persistent avatar
1049 //=======================================================================
1050 Handle(ShapePersistent_BRep::Curve3D)
1051 ShapePersistent_BRep::Translate (const Handle(Geom_Curve)& theCurve,
1052                                  const Standard_Real theFirstParam,
1053                                  const Standard_Real theLastParam,
1054                                  const TopLoc_Location& theLoc,
1055                                  StdObjMgt_TransientPersistentMap& theMap)
1056 {
1057   Handle(Curve3D) aPCurve3D = new Curve3D;
1058   aPCurve3D->myCurve3D = ShapePersistent_Geom::Translate(theCurve, theMap);
1059   aPCurve3D->myLocation = StdObject_Location::Translate(theLoc, theMap);
1060   aPCurve3D->myFirst = theFirstParam;
1061   aPCurve3D->myLast = theLastParam;
1062   return aPCurve3D;
1063 }
1064
1065 //=======================================================================
1066 //function : Translate
1067 //purpose  : Translates a shape to its persistent avatar
1068 //=======================================================================
1069 Handle(ShapePersistent_BRep::Polygon3D)
1070 ShapePersistent_BRep::Translate(const Handle(Poly_Polygon3D)& thePoly,
1071                                 const TopLoc_Location& theLoc,
1072                                 StdObjMgt_TransientPersistentMap& theMap)
1073 {
1074   Handle(Polygon3D) aPPoly = new Polygon3D;
1075   aPPoly->myPolygon3D = ShapePersistent_Poly::Translate(thePoly, theMap);
1076   aPPoly->myLocation = StdObject_Location::Translate(theLoc, theMap);
1077   return aPPoly;
1078 }
1079
1080 //=======================================================================
1081 //function : Translate
1082 //purpose  : Translates a shape to its persistent avatar
1083 //=======================================================================
1084 Handle(ShapePersistent_BRep::PolygonOnClosedSurface)
1085 ShapePersistent_BRep::Translate(const Handle(Poly_Polygon2D)& thePoly,
1086                                 const Handle(Poly_Polygon2D)& thePoly2,
1087                                 const Handle(Geom_Surface)& theSurf,
1088                                 const TopLoc_Location& theLoc,
1089                                 StdObjMgt_TransientPersistentMap& theMap)
1090 {
1091   Handle(PolygonOnClosedSurface) aPPonCS = new PolygonOnClosedSurface;
1092   aPPonCS->myPolygon2D = ShapePersistent_Poly::Translate(thePoly, theMap);
1093   aPPonCS->myPolygon2 = ShapePersistent_Poly::Translate(thePoly2, theMap);
1094   aPPonCS->mySurface = ShapePersistent_Geom::Translate(theSurf, theMap);
1095   aPPonCS->myLocation = StdObject_Location::Translate(theLoc, theMap);
1096   return aPPonCS;
1097 }
1098
1099 //=======================================================================
1100 //function : Translate
1101 //purpose  : Translates a shape to its persistent avatar
1102 //=======================================================================
1103 Handle(ShapePersistent_BRep::PolygonOnSurface)
1104 ShapePersistent_BRep::Translate(const Handle(Poly_Polygon2D)& thePoly,
1105                                 const Handle(Geom_Surface)& theSurf,
1106                                 const TopLoc_Location& theLoc,
1107                                 StdObjMgt_TransientPersistentMap& theMap)
1108 {
1109   Handle(PolygonOnSurface) aPPonS = new PolygonOnSurface;
1110   aPPonS->myPolygon2D = ShapePersistent_Poly::Translate(thePoly, theMap);
1111   aPPonS->mySurface = ShapePersistent_Geom::Translate(theSurf, theMap);
1112   aPPonS->myLocation = StdObject_Location::Translate(theLoc, theMap);
1113   return aPPonS;
1114 }
1115
1116 //=======================================================================
1117 //function : Translate
1118 //purpose  : Translates a shape to its persistent avatar
1119 //=======================================================================
1120 Handle(ShapePersistent_BRep::PolygonOnClosedTriangulation)
1121 ShapePersistent_BRep::Translate(const Handle(Poly_PolygonOnTriangulation)& thePolyOnTriang,
1122                                 const Handle(Poly_PolygonOnTriangulation)& thePolyOnTriang2,
1123                                 const Handle(Poly_Triangulation)& thePolyTriang,
1124                                 const TopLoc_Location& theLoc,
1125                                 StdObjMgt_TransientPersistentMap& theMap)
1126 {
1127   Handle(PolygonOnClosedTriangulation) aPPonCS = new PolygonOnClosedTriangulation;
1128   aPPonCS->myPolygon = ShapePersistent_Poly::Translate(thePolyOnTriang, theMap);
1129   aPPonCS->myPolygon2 = ShapePersistent_Poly::Translate(thePolyOnTriang2, theMap);
1130   aPPonCS->myTriangulation = ShapePersistent_Poly::Translate(thePolyTriang, theMap);
1131   aPPonCS->myLocation = StdObject_Location::Translate(theLoc, theMap);
1132   return aPPonCS;
1133 }
1134
1135 //=======================================================================
1136 //function : Translate
1137 //purpose  : Translates a shape to its persistent avatar
1138 //=======================================================================
1139 Handle(ShapePersistent_BRep::PolygonOnTriangulation)
1140 ShapePersistent_BRep::Translate(const Handle(Poly_PolygonOnTriangulation)& thePolyOnTriang,
1141                                 const Handle(Poly_Triangulation)& thePolyTriang,
1142                                 const TopLoc_Location& theLoc,
1143                                 StdObjMgt_TransientPersistentMap& theMap)
1144 {
1145   Handle(PolygonOnTriangulation) aPPonT = new PolygonOnTriangulation;
1146   aPPonT->myPolygon = ShapePersistent_Poly::Translate(thePolyOnTriang, theMap);
1147   aPPonT->myTriangulation = ShapePersistent_Poly::Translate(thePolyTriang, theMap);
1148   aPPonT->myLocation = StdObject_Location::Translate(theLoc, theMap);
1149   return aPPonT;
1150 }