0031687: Draw Harness, ViewerTest - extend command vrenderparams with option updating...
[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   if (myPoints)
648     myPoints->Import (aTVertex->ChangePoints());
649
650   return aTVertex;
651 }
652
653 //=======================================================================
654 //function : createTShape
655 //purpose  : Create transient TShape object
656 //=======================================================================
657 Handle(TopoDS_TShape) ShapePersistent_BRep::pTEdge::createTShape() const
658 {
659   Handle(BRep_TEdge) aTEdge = new BRep_TEdge;
660
661   aTEdge->Tolerance     (myTolerance);
662   aTEdge->SameParameter ((myFlags & ParameterMask)   != 0);
663   aTEdge->SameRange     ((myFlags & RangeMask)       != 0);
664   aTEdge->Degenerated   ((myFlags & DegeneratedMask) != 0);
665
666   if (myCurves)
667     myCurves->Import (aTEdge->ChangeCurves());
668
669   return aTEdge;
670 }
671
672 //=======================================================================
673 //function : createTShape
674 //purpose  : Create transient TShape object
675 //=======================================================================
676 Handle(TopoDS_TShape) ShapePersistent_BRep::pTFace::createTShape() const
677 {
678   Handle(BRep_TFace) aTFace = new BRep_TFace;
679
680   aTFace->NaturalRestriction (myNaturalRestriction);
681   aTFace->Tolerance          (myTolerance);
682   aTFace->Location           (myLocation.Import());
683
684   if (mySurface)
685     aTFace->Surface (mySurface->Import());
686
687   if (myTriangulation)
688     aTFace->Triangulation (myTriangulation->Import());
689
690   return aTFace;
691 }
692
693 //=======================================================================
694 //function : Translate
695 //purpose  : Translates a shape to its persistent avatar
696 //=======================================================================
697 Handle(ShapePersistent_BRep::TVertex::pTObjectT)
698 ShapePersistent_BRep::Translate (const TopoDS_Vertex& theVertex,
699                                  StdObjMgt_TransientPersistentMap& theMap)
700 {
701   Handle(BRep_TVertex) TTV = Handle(BRep_TVertex)::DownCast (theVertex.TShape());
702
703   Handle(TVertex::pTObjectT) PTV = new TVertex::pTObjectT;
704
705   PTV->myPnt = TTV->Pnt();
706   PTV->myTolerance = TTV->Tolerance();
707
708   BRep_ListIteratorOfListOfPointRepresentation anItPR(TTV->Points());
709
710   Handle(PointRepresentation) PPR, CPPR;
711   while (anItPR.More())
712   {
713     const Handle(BRep_PointRepresentation)& PR = anItPR.Value();
714     if (PR->IsPointOnCurve()) {
715       Handle(PointOnCurve) POC = Translate(PR->Parameter(), 
716                                            PR->Curve(), 
717                                            PR->Location(), 
718                                            theMap);
719       CPPR = POC;
720     }
721     else if (PR->IsPointOnCurveOnSurface()) {
722       Handle(PointOnCurveOnSurface) POCS = Translate(PR->Parameter(), 
723                                                      PR->PCurve(), 
724                                                      PR->Surface(), 
725                                                      PR->Location(), 
726                                                      theMap);
727       CPPR = POCS;
728     }
729     else if (PR->IsPointOnSurface()) {
730       Handle(PointOnSurface) POS = Translate(PR->Parameter(), 
731                                              PR->Parameter2(), 
732                                              PR->Surface(), 
733                                              PR->Location(), 
734                                              theMap);
735       CPPR = POS;
736     }
737
738     CPPR->myNext = PPR;
739     PPR = CPPR;
740     anItPR.Next();
741   }
742
743   PTV->myPoints = PPR;
744
745   return PTV;
746 }
747
748 //=======================================================================
749 //function : Translate
750 //purpose  : Translates a shape to its persistent avatar
751 //=======================================================================
752 Handle(ShapePersistent_BRep::TEdge::pTObjectT)
753 ShapePersistent_BRep::Translate (const TopoDS_Edge& theEdge,
754                                  StdObjMgt_TransientPersistentMap& theMap,
755                                  ShapePersistent_TriangleMode theTriangleMode)
756 {
757   Handle(BRep_TEdge) TTE = Handle(BRep_TEdge)::DownCast (theEdge.TShape());
758
759   Handle(TEdge::pTObjectT) PTE = new TEdge::pTObjectT;
760
761   PTE->myTolerance = TTE->Tolerance();
762   if (TTE->SameParameter()) PTE->myFlags |= ParameterMask;
763   if (TTE->SameRange())     PTE->myFlags |= RangeMask;
764   if (TTE->Degenerated())   PTE->myFlags |= DegeneratedMask;
765
766   // Representations
767   BRep_ListIteratorOfListOfCurveRepresentation itcr(TTE->Curves());
768
769   Handle(CurveRepresentation) PCR, CPCR;
770   Handle(BRep_GCurve) GC;
771   Standard_Real f, l;
772
773   while (itcr.More()) 
774   {
775     const Handle(BRep_CurveRepresentation)& CR = itcr.Value();
776     GC = Handle(BRep_GCurve)::DownCast(CR);
777     if (!GC.IsNull()) 
778     {
779       GC->Range(f, l);
780       // CurveRepresentation is Curve3D
781       if (CR->IsCurve3D()) {
782         Handle(Curve3D) C3D = Translate(CR->Curve3D(), f, l, CR->Location(), theMap);
783         CPCR = C3D;
784       }
785       // CurveRepresentation is CurveOnSurface
786       else if (CR->IsCurveOnSurface()) 
787       {
788         Handle(BRep_CurveOnSurface)& theCOS = (Handle(BRep_CurveOnSurface)&) CR;
789         Handle(CurveOnSurface) COS;
790         // CurveRepresentation is CurveOnSurface
791         if (!CR->IsCurveOnClosedSurface()) 
792         {
793           COS = Translate(CR->PCurve(), f, l, CR->Surface(), CR->Location(), theMap);
794         }
795         // CurveRepresentation is CurveOnClosedSurface
796         else 
797         {
798           // get UVPoints for the CurveOnClosedSurface definition.
799           Handle(BRep_CurveOnClosedSurface)& theCOCS =
800             (Handle(BRep_CurveOnClosedSurface)&) CR;
801           gp_Pnt2d Pnt21, Pnt22;
802           theCOCS->UVPoints2(Pnt21, Pnt22);
803           Handle(CurveOnClosedSurface) COCS = Translate(CR->PCurve(), CR->PCurve2(), 
804                                                         f, l, CR->Surface(), 
805                                                         CR->Location(), CR->Continuity(), 
806                                                         theMap);
807           COCS->myUV21 = Pnt21;
808           COCS->myUV22 = Pnt22;
809           COS = COCS;
810         }
811
812         // get UVPoints for the CurveOnSurface definition.
813         gp_Pnt2d Pnt1, Pnt2;
814         theCOS->UVPoints(Pnt1, Pnt2);
815         COS->myUV1 = Pnt1;
816         COS->myUV2 = Pnt2;
817         CPCR = COS;
818       }
819     }
820     // CurveRepresentation is CurveOn2Surfaces
821     else if (CR->IsRegularity()) 
822     {
823       Handle(CurveOn2Surfaces) R = Translate(CR->Surface(), CR->Surface2(), 
824                                              CR->Location(), CR->Location2(), 
825                                              CR->Continuity(), 
826                                              theMap);
827       CPCR = R;
828     }
829     // CurveRepresentation is Polygon or Triangulation
830     else if (theTriangleMode == ShapePersistent_WithTriangle) {
831       // CurveRepresentation is Polygon3D
832       if (CR->IsPolygon3D()) {
833         Handle(Polygon3D) P3D = Translate(CR->Polygon3D(), CR->Location(), theMap);
834         CPCR = P3D;
835       }
836       // CurveRepresentation is PolygonOnSurface
837       else if (CR->IsPolygonOnSurface()) 
838       {
839         // CurveRepresentation is PolygonOnClosedSurface
840         if (CR->IsPolygonOnClosedSurface()) {
841           Handle(PolygonOnClosedSurface) PolOCS = Translate(CR->Polygon(), CR->Polygon2(), 
842                                                             CR->Surface(), CR->Location(), 
843                                                             theMap);
844           CPCR = PolOCS;
845         }
846         // CurveRepresentation is PolygonOnSurface
847         else 
848         {
849           Handle(PolygonOnSurface) PolOS = Translate(CR->Polygon(), CR->Surface(), 
850                                                      CR->Location(), theMap);
851           CPCR = PolOS;
852         }
853       }
854       // CurveRepresentation is PolygonOnTriangulation
855       else if (CR->IsPolygonOnTriangulation()) 
856       {
857         // CurveRepresentation is PolygonOnClosedTriangulation
858         if (CR->IsPolygonOnClosedTriangulation()) 
859         {
860           Handle(PolygonOnClosedTriangulation) PolOCT = Translate(CR->PolygonOnTriangulation(), 
861                                                                   CR->PolygonOnTriangulation2(), 
862                                                                   CR->Triangulation(), 
863                                                                   CR->Location(), 
864                                                                   theMap);
865           CPCR = PolOCT;
866         }
867         // CurveRepresentation is PolygonOnTriangulation
868         else 
869         {
870           Handle(PolygonOnTriangulation) PolOT = Translate(CR->PolygonOnTriangulation(), 
871                                                            CR->Triangulation(), 
872                                                            CR->Location(), 
873                                                            theMap);
874           CPCR = PolOT;
875         }
876       }
877     }
878     else 
879     {
880       // jumps the curve representation
881       itcr.Next();
882       continue;
883     }
884
885     Standard_NullObject_Raise_if(CPCR.IsNull(), "Null CurveRepresentation");
886
887     CPCR->myNext = PCR;
888     PCR = CPCR;
889     itcr.Next();
890   }
891
892   // set
893   PTE->myCurves = PCR;
894
895   return PTE;
896 }
897
898 //=======================================================================
899 //function : Translate
900 //purpose  : Translates a shape to its persistent avatar
901 //=======================================================================
902 Handle(ShapePersistent_BRep::TFace::pTObjectT)
903 ShapePersistent_BRep::Translate (const TopoDS_Face& theFace,
904                                  StdObjMgt_TransientPersistentMap& theMap,
905                                  ShapePersistent_TriangleMode theTriangleMode)
906 {
907   Handle(BRep_TFace) TTF = Handle(BRep_TFace)::DownCast (theFace.TShape());
908
909   Handle(TFace::pTObjectT) PTF = new TFace::pTObjectT;
910
911   PTF->myTolerance = TTF->Tolerance();
912   PTF->myLocation = StdObject_Location::Translate(TTF->Location(), theMap);
913   PTF->myNaturalRestriction = TTF->NaturalRestriction();
914
915   // Surface
916   PTF->mySurface = ShapePersistent_Geom::Translate(TTF->Surface(), theMap);
917
918   // Triangulation
919   if (theTriangleMode == ShapePersistent_WithTriangle) {
920     PTF->myTriangulation = ShapePersistent_Poly::Translate(TTF->Triangulation(), theMap);
921   }
922
923   return PTF;
924 }
925
926 //=======================================================================
927 //function : Translate
928 //purpose  : Translates a shape to its persistent avatar
929 //=======================================================================
930 Handle(ShapePersistent_BRep::PointOnCurve)
931 ShapePersistent_BRep::Translate (Standard_Real theParam,
932                                  const Handle(Geom_Curve)& theCurve,
933                                  const TopLoc_Location& theLoc,
934                                  StdObjMgt_TransientPersistentMap& theMap)
935 {
936   Handle(PointOnCurve) aPPonC = new PointOnCurve;
937   aPPonC->myParameter = theParam;
938   aPPonC->myCurve = ShapePersistent_Geom::Translate(theCurve, theMap);
939   aPPonC->myLocation = StdObject_Location::Translate(theLoc, theMap);
940   return aPPonC;
941 }
942
943 //=======================================================================
944 //function : Translate
945 //purpose  : Translates a shape to its persistent avatar
946 //=======================================================================
947 Handle(ShapePersistent_BRep::PointOnCurveOnSurface)
948 ShapePersistent_BRep::Translate(Standard_Real theParam,
949                                 const Handle(Geom2d_Curve)& theCurve,
950                                 const Handle(Geom_Surface)& theSurf,
951                                 const TopLoc_Location& theLoc,
952                                 StdObjMgt_TransientPersistentMap& theMap)
953 {
954   Handle(PointOnCurveOnSurface) aPPonConS = new PointOnCurveOnSurface;
955   aPPonConS->myParameter = theParam;
956   aPPonConS->myPCurve = ShapePersistent_Geom2d::Translate(theCurve, theMap);
957   aPPonConS->mySurface = ShapePersistent_Geom::Translate(theSurf, theMap);
958   aPPonConS->myLocation = StdObject_Location::Translate(theLoc, theMap);
959   return aPPonConS;
960 }
961
962 //=======================================================================
963 //function : Translate
964 //purpose  : Translates a shape to its persistent avatar
965 //=======================================================================
966 Handle(ShapePersistent_BRep::PointOnSurface)
967 ShapePersistent_BRep::Translate(Standard_Real theParam,
968                                 Standard_Real theParam2,
969                                 const Handle(Geom_Surface)& theSurf,
970                                 const TopLoc_Location& theLoc,
971                                 StdObjMgt_TransientPersistentMap& theMap)
972 {
973   Handle(PointOnSurface) aPonS = new PointOnSurface;
974   aPonS->myParameter = theParam;
975   aPonS->myParameter2 = theParam2;
976   aPonS->mySurface = ShapePersistent_Geom::Translate(theSurf, theMap);
977   aPonS->myLocation = StdObject_Location::Translate(theLoc, theMap);
978   return aPonS;
979 }
980
981 //=======================================================================
982 //function : Translate
983 //purpose  : Translates a shape to its persistent avatar
984 //=======================================================================
985 Handle(ShapePersistent_BRep::CurveOnSurface)
986 ShapePersistent_BRep::Translate(const Handle(Geom2d_Curve)& theCurve,
987                                 const Standard_Real theFirstParam,
988                                 const Standard_Real theLastParam,
989                                 const Handle(Geom_Surface)& theSurf,
990                                 const TopLoc_Location& theLoc,
991                                 StdObjMgt_TransientPersistentMap& theMap)
992 {
993   Handle(CurveOnSurface) aPConS = new CurveOnSurface;
994   aPConS->myPCurve = ShapePersistent_Geom2d::Translate(theCurve, theMap);
995   aPConS->myFirst = theFirstParam;
996   aPConS->myLast = theLastParam;
997   aPConS->mySurface = ShapePersistent_Geom::Translate(theSurf, theMap);
998   aPConS->myLocation = StdObject_Location::Translate(theLoc, theMap);
999   return aPConS;
1000 }
1001
1002 //=======================================================================
1003 //function : Translate
1004 //purpose  : Translates a shape to its persistent avatar
1005 //=======================================================================
1006 Handle(ShapePersistent_BRep::CurveOnClosedSurface)
1007 ShapePersistent_BRep::Translate(const Handle(Geom2d_Curve)& theCurve,
1008                                 const Handle(Geom2d_Curve)& theCurve2,
1009                                 const Standard_Real theFirstParam,
1010                                 const Standard_Real theLastParam,
1011                                 const Handle(Geom_Surface)& theSurf,
1012                                 const TopLoc_Location& theLoc,
1013                                 const GeomAbs_Shape theContinuity,
1014                                 StdObjMgt_TransientPersistentMap& theMap)
1015 {
1016   Handle(CurveOnClosedSurface) aPConCS = new CurveOnClosedSurface;
1017   aPConCS->myPCurve = ShapePersistent_Geom2d::Translate(theCurve, theMap);
1018   aPConCS->myPCurve2 = ShapePersistent_Geom2d::Translate(theCurve2, theMap);
1019   aPConCS->myFirst = theFirstParam;
1020   aPConCS->myLast = theLastParam;
1021   aPConCS->mySurface = ShapePersistent_Geom::Translate(theSurf, theMap);
1022   aPConCS->myLocation = StdObject_Location::Translate(theLoc, theMap);
1023   aPConCS->myContinuity = theContinuity;
1024   return aPConCS;
1025 }
1026
1027 //=======================================================================
1028 //function : Translate
1029 //purpose  : Translates a shape to its persistent avatar
1030 //=======================================================================
1031 Handle(ShapePersistent_BRep::CurveOn2Surfaces)
1032 ShapePersistent_BRep::Translate(const Handle(Geom_Surface)& theSurf,
1033                                 const Handle(Geom_Surface)& theSurf2,
1034                                 const TopLoc_Location& theLoc, 
1035                                 const TopLoc_Location& theLoc2,
1036                                 const GeomAbs_Shape theContinuity,
1037                                 StdObjMgt_TransientPersistentMap& theMap)
1038 {
1039   Handle(CurveOn2Surfaces) aPCon2S = new CurveOn2Surfaces;
1040   aPCon2S->mySurface = ShapePersistent_Geom::Translate(theSurf, theMap);
1041   aPCon2S->mySurface2 = ShapePersistent_Geom::Translate(theSurf2, theMap);
1042   aPCon2S->myLocation = StdObject_Location::Translate(theLoc, theMap);
1043   aPCon2S->myLocation2 = StdObject_Location::Translate(theLoc2, theMap);
1044   aPCon2S->myContinuity = theContinuity;
1045   return aPCon2S;
1046 }
1047
1048 //=======================================================================
1049 //function : Translate
1050 //purpose  : Translates a shape to its persistent avatar
1051 //=======================================================================
1052 Handle(ShapePersistent_BRep::Curve3D)
1053 ShapePersistent_BRep::Translate (const Handle(Geom_Curve)& theCurve,
1054                                  const Standard_Real theFirstParam,
1055                                  const Standard_Real theLastParam,
1056                                  const TopLoc_Location& theLoc,
1057                                  StdObjMgt_TransientPersistentMap& theMap)
1058 {
1059   Handle(Curve3D) aPCurve3D = new Curve3D;
1060   aPCurve3D->myCurve3D = ShapePersistent_Geom::Translate(theCurve, theMap);
1061   aPCurve3D->myLocation = StdObject_Location::Translate(theLoc, theMap);
1062   aPCurve3D->myFirst = theFirstParam;
1063   aPCurve3D->myLast = theLastParam;
1064   return aPCurve3D;
1065 }
1066
1067 //=======================================================================
1068 //function : Translate
1069 //purpose  : Translates a shape to its persistent avatar
1070 //=======================================================================
1071 Handle(ShapePersistent_BRep::Polygon3D)
1072 ShapePersistent_BRep::Translate(const Handle(Poly_Polygon3D)& thePoly,
1073                                 const TopLoc_Location& theLoc,
1074                                 StdObjMgt_TransientPersistentMap& theMap)
1075 {
1076   Handle(Polygon3D) aPPoly = new Polygon3D;
1077   aPPoly->myPolygon3D = ShapePersistent_Poly::Translate(thePoly, theMap);
1078   aPPoly->myLocation = StdObject_Location::Translate(theLoc, theMap);
1079   return aPPoly;
1080 }
1081
1082 //=======================================================================
1083 //function : Translate
1084 //purpose  : Translates a shape to its persistent avatar
1085 //=======================================================================
1086 Handle(ShapePersistent_BRep::PolygonOnClosedSurface)
1087 ShapePersistent_BRep::Translate(const Handle(Poly_Polygon2D)& thePoly,
1088                                 const Handle(Poly_Polygon2D)& thePoly2,
1089                                 const Handle(Geom_Surface)& theSurf,
1090                                 const TopLoc_Location& theLoc,
1091                                 StdObjMgt_TransientPersistentMap& theMap)
1092 {
1093   Handle(PolygonOnClosedSurface) aPPonCS = new PolygonOnClosedSurface;
1094   aPPonCS->myPolygon2D = ShapePersistent_Poly::Translate(thePoly, theMap);
1095   aPPonCS->myPolygon2 = ShapePersistent_Poly::Translate(thePoly2, theMap);
1096   aPPonCS->mySurface = ShapePersistent_Geom::Translate(theSurf, theMap);
1097   aPPonCS->myLocation = StdObject_Location::Translate(theLoc, theMap);
1098   return aPPonCS;
1099 }
1100
1101 //=======================================================================
1102 //function : Translate
1103 //purpose  : Translates a shape to its persistent avatar
1104 //=======================================================================
1105 Handle(ShapePersistent_BRep::PolygonOnSurface)
1106 ShapePersistent_BRep::Translate(const Handle(Poly_Polygon2D)& thePoly,
1107                                 const Handle(Geom_Surface)& theSurf,
1108                                 const TopLoc_Location& theLoc,
1109                                 StdObjMgt_TransientPersistentMap& theMap)
1110 {
1111   Handle(PolygonOnSurface) aPPonS = new PolygonOnSurface;
1112   aPPonS->myPolygon2D = ShapePersistent_Poly::Translate(thePoly, theMap);
1113   aPPonS->mySurface = ShapePersistent_Geom::Translate(theSurf, theMap);
1114   aPPonS->myLocation = StdObject_Location::Translate(theLoc, theMap);
1115   return aPPonS;
1116 }
1117
1118 //=======================================================================
1119 //function : Translate
1120 //purpose  : Translates a shape to its persistent avatar
1121 //=======================================================================
1122 Handle(ShapePersistent_BRep::PolygonOnClosedTriangulation)
1123 ShapePersistent_BRep::Translate(const Handle(Poly_PolygonOnTriangulation)& thePolyOnTriang,
1124                                 const Handle(Poly_PolygonOnTriangulation)& thePolyOnTriang2,
1125                                 const Handle(Poly_Triangulation)& thePolyTriang,
1126                                 const TopLoc_Location& theLoc,
1127                                 StdObjMgt_TransientPersistentMap& theMap)
1128 {
1129   Handle(PolygonOnClosedTriangulation) aPPonCS = new PolygonOnClosedTriangulation;
1130   aPPonCS->myPolygon = ShapePersistent_Poly::Translate(thePolyOnTriang, theMap);
1131   aPPonCS->myPolygon2 = ShapePersistent_Poly::Translate(thePolyOnTriang2, theMap);
1132   aPPonCS->myTriangulation = ShapePersistent_Poly::Translate(thePolyTriang, theMap);
1133   aPPonCS->myLocation = StdObject_Location::Translate(theLoc, theMap);
1134   return aPPonCS;
1135 }
1136
1137 //=======================================================================
1138 //function : Translate
1139 //purpose  : Translates a shape to its persistent avatar
1140 //=======================================================================
1141 Handle(ShapePersistent_BRep::PolygonOnTriangulation)
1142 ShapePersistent_BRep::Translate(const Handle(Poly_PolygonOnTriangulation)& thePolyOnTriang,
1143                                 const Handle(Poly_Triangulation)& thePolyTriang,
1144                                 const TopLoc_Location& theLoc,
1145                                 StdObjMgt_TransientPersistentMap& theMap)
1146 {
1147   Handle(PolygonOnTriangulation) aPPonT = new PolygonOnTriangulation;
1148   aPPonT->myPolygon = ShapePersistent_Poly::Translate(thePolyOnTriang, theMap);
1149   aPPonT->myTriangulation = ShapePersistent_Poly::Translate(thePolyTriang, theMap);
1150   aPPonT->myLocation = StdObject_Location::Translate(theLoc, theMap);
1151   return aPPonT;
1152 }