0024927: Getting rid of "Persistent" functionality -- Code
[occt.git] / src / MgtBRep / MgtBRep_TranslateTool.cxx
1 // Created on: 1993-06-14
2 // Created by: Remi LEQUETTE
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #include <MgtBRep_TranslateTool.ixx>
18 #include <MgtTopLoc.hxx>
19 #include <MgtGeom.hxx>
20 #include <MgtGeom2d.hxx>
21 #include <MgtPoly.hxx>
22
23 #include <TopoDS.hxx>
24
25 #include <BRep_Builder.hxx>
26 #include <BRep_TVertex.hxx>
27 #include <BRep_TEdge.hxx>
28 #include <BRep_TFace.hxx>
29
30 #include <BRep_Curve3D.hxx>
31 #include <BRep_CurveOnSurface.hxx>
32 #include <BRep_CurveOnClosedSurface.hxx>
33 #include <BRep_CurveOn2Surfaces.hxx>
34 #include <BRep_Polygon3D.hxx>
35 #include <BRep_PolygonOnSurface.hxx>
36 #include <BRep_PolygonOnClosedSurface.hxx>
37 #include <BRep_PolygonOnTriangulation.hxx>
38 #include <BRep_PolygonOnClosedTriangulation.hxx>
39 #include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
40
41 #include <BRep_PointOnCurve.hxx>
42 #include <BRep_PointOnCurveOnSurface.hxx>
43 #include <BRep_PointOnSurface.hxx>
44 #include <BRep_ListIteratorOfListOfPointRepresentation.hxx>
45
46 #include <PTopoDS_TWire.hxx>
47 #include <PTopoDS_TShell.hxx>
48 #include <PTopoDS_TSolid.hxx>
49 #include <PTopoDS_TCompSolid.hxx>
50 #include <PTopoDS_TCompound.hxx>
51
52 #include <PBRep_TVertex.hxx>
53 #include <PBRep_TEdge.hxx>
54 #include <PBRep_TFace.hxx>
55
56 #include <PBRep_Curve3D.hxx>
57 #include <PBRep_CurveOnSurface.hxx>
58 #include <PBRep_CurveOnClosedSurface.hxx>
59 #include <PBRep_CurveOn2Surfaces.hxx>
60
61 #include <PBRep_PointOnCurve.hxx>
62 #include <PBRep_PointOnCurveOnSurface.hxx>
63 #include <PBRep_PointOnSurface.hxx>
64 #include <PBRep_Polygon3D.hxx>
65 #include <PBRep_PolygonOnSurface.hxx>
66 #include <PBRep_PolygonOnClosedSurface.hxx>
67 #include <PBRep_PolygonOnTriangulation.hxx>
68 #include <PBRep_PolygonOnClosedTriangulation.hxx>
69
70 #include <Standard_NullObject.hxx>
71
72 // szy 23.01.2014 (bug 24565) correction for edge which has null 3d curve representation
73
74 // Used for testing DownCast time
75
76 #ifdef chrono
77 #include <OSD_Timer.hxx>
78 extern OSD_Timer CurveTimer;
79 extern OSD_Timer Curve2dTimer;
80 extern OSD_Timer SurfaceTimer;
81 #endif
82
83 // *****************************
84 // Auxiliary translation methods
85 // *****************************
86
87 //=======================================================================
88 //function : Translate
89 //purpose  : Curve T->P
90 //=======================================================================
91
92 Handle(PGeom_Curve) MgtBRep_TranslateTool::Translate
93 (const Handle(Geom_Curve)& TP,
94  PTColStd_TransientPersistentMap& aMap) const 
95 {
96   Handle(PGeom_Curve) PP;
97   if (!TP.IsNull()) {
98     if (aMap.IsBound(TP)) {
99       Handle(Standard_Persistent) aPers = aMap.Find(TP);
100       PP = (Handle(PGeom_Curve)&) aPers;
101     }
102     else {
103       PP = MgtGeom::Translate(TP);
104       aMap.Bind(TP,PP);
105     }
106   }
107   return PP;
108 }
109
110 //=======================================================================
111 //function : Translate
112 //purpose  : Curve P->T
113 //=======================================================================
114
115 Handle(Geom_Curve) MgtBRep_TranslateTool::Translate
116 (const Handle(PGeom_Curve)& PP,
117  PTColStd_PersistentTransientMap& aMap) const  
118 {
119 #ifdef chrono
120   CurveTimer.Start();
121 #endif
122   Handle(Geom_Curve) TP;
123   if (!PP.IsNull()) {
124     if (aMap.IsBound(PP)) {
125       Handle(Standard_Transient) aTrans = aMap.Find(PP);
126       TP = (Handle(Geom_Curve)&) aTrans;
127     }
128     else {
129       TP = MgtGeom::Translate(PP);
130       aMap.Bind(PP, TP);
131     }
132   }
133 #ifdef chrono
134   CurveTimer.Stop();
135 #endif
136   return TP;
137 }
138
139 //=======================================================================
140 //function : Translate
141 //purpose  : Curve2d T->P
142 //=======================================================================
143
144 Handle(PGeom2d_Curve) MgtBRep_TranslateTool::Translate
145 (const Handle(Geom2d_Curve)& TP,
146  PTColStd_TransientPersistentMap& aMap) const 
147 {
148   Handle(PGeom2d_Curve) PP;
149   if (!TP.IsNull()) {
150     if (aMap.IsBound(TP)) {
151       Handle(Standard_Persistent) aPers = aMap.Find(TP);
152       PP = (Handle(PGeom2d_Curve)&) aPers;
153     }
154     else {
155       PP = MgtGeom2d::Translate(TP);
156       aMap.Bind(TP,PP);
157     }
158   }
159   return PP;
160 }
161
162 //=======================================================================
163 //function : Translate
164 //purpose  : Curve2d P->T
165 //=======================================================================
166
167 Handle(Geom2d_Curve) MgtBRep_TranslateTool::Translate
168 (const Handle(PGeom2d_Curve)& PP,
169  PTColStd_PersistentTransientMap& aMap) const 
170 {
171 #ifdef chrono
172   Curve2dTimer.Start();
173 #endif
174   Handle(Geom2d_Curve) TP;
175   if (!PP.IsNull()) {
176     if (aMap.IsBound(PP)) {
177       Handle(Standard_Transient) aTrans = aMap.Find(PP);
178       TP = (Handle(Geom2d_Curve)&) aTrans;
179     }
180     else {
181       TP = MgtGeom2d::Translate(PP);
182       aMap.Bind(PP, TP);
183     }
184   }
185 #ifdef chrono
186   Curve2dTimer.Stop();
187 #endif
188   return TP;
189 }
190
191 //=======================================================================
192 //function : Translate
193 //purpose  : Surface T->P
194 //=======================================================================
195
196 Handle(PGeom_Surface) MgtBRep_TranslateTool::Translate
197 (const Handle(Geom_Surface)& TP,
198  PTColStd_TransientPersistentMap& aMap) const 
199 {
200   Handle(PGeom_Surface) PP;
201   if (!TP.IsNull()) {
202     if (aMap.IsBound(TP)) {
203       Handle(Standard_Persistent) aPers = aMap.Find(TP);
204       PP = (Handle(PGeom_Surface)&) aPers;
205     }
206     else {
207       PP = MgtGeom::Translate(TP);
208       aMap.Bind(TP,PP);
209     }
210   }
211   return PP;
212 }
213
214 //=======================================================================
215 //function : Translate
216 //purpose  : Surface P->T
217 //=======================================================================
218
219 Handle(Geom_Surface) MgtBRep_TranslateTool::Translate
220 (const Handle(PGeom_Surface)& PP,
221  PTColStd_PersistentTransientMap& aMap) const 
222 {
223 #ifdef chrono
224   SurfaceTimer.Start();
225 #endif
226   Handle(Geom_Surface) TP;
227   if (!PP.IsNull()) {
228     if (aMap.IsBound(PP)) {
229       Handle(Standard_Transient) aTrans = aMap.Find(PP);
230       TP = (Handle(Geom_Surface)&) aTrans;
231     }
232     else {
233       TP = MgtGeom::Translate(PP);
234       aMap.Bind(PP,TP);
235     }
236   }
237 #ifdef chrono
238   SurfaceTimer.Stop();
239 #endif
240   return TP;
241 }
242
243 //=======================================================================
244 //function : MgtBRep_TranslateTool
245 //purpose  : Constructor 
246 //=======================================================================
247
248 MgtBRep_TranslateTool::MgtBRep_TranslateTool
249 (const MgtBRep_TriangleMode aTriMode) : 
250 myTriangleMode(aTriMode)
251 {
252 }
253
254 //=======================================================================
255 //function : Add
256 //purpose  : 
257 //=======================================================================
258
259 void MgtBRep_TranslateTool::Add(TopoDS_Shape& S1,
260                                 const TopoDS_Shape& S2) const 
261 {
262   BRep_Builder B;
263   B.Add(S1,S2);
264 }
265
266 //=======================================================================
267 //function : MakeVertex
268 //purpose  : 
269 //=======================================================================
270
271 void  MgtBRep_TranslateTool::MakeVertex(TopoDS_Shape& S) const 
272 {
273   BRep_Builder B;
274   B.MakeVertex(TopoDS::Vertex(S));
275 }
276
277
278 //=======================================================================
279 //function : MakeVertex
280 //purpose  : 
281 //=======================================================================
282
283 void  MgtBRep_TranslateTool::MakeVertex(const Handle(PTopoDS_HShape)& S) const 
284 {
285   Handle(PBRep_TVertex) T = new PBRep_TVertex();
286   S->TShape(T);
287 }
288
289
290 //=======================================================================
291 //function : MakeEdge
292 //purpose  : 
293 //=======================================================================
294
295 void  MgtBRep_TranslateTool::MakeEdge(TopoDS_Shape& S) const 
296 {
297   BRep_Builder B;
298   B.MakeEdge(TopoDS::Edge(S));
299 }
300
301
302 //=======================================================================
303 //function : MakeEdge
304 //purpose  : 
305 //=======================================================================
306
307 void  MgtBRep_TranslateTool::MakeEdge(const Handle(PTopoDS_HShape)& S) const 
308 {
309   Handle(PBRep_TEdge) T = new PBRep_TEdge();
310   S->TShape(T);
311 }
312
313
314 //=======================================================================
315 //function : MakeWire
316 //purpose  : 
317 //=======================================================================
318
319 void  MgtBRep_TranslateTool::MakeWire(TopoDS_Shape& S) const 
320 {
321   BRep_Builder B;
322   B.MakeWire(TopoDS::Wire(S));
323 }
324
325
326 //=======================================================================
327 //function : MakeWire
328 //purpose  : 
329 //=======================================================================
330
331 void  MgtBRep_TranslateTool::MakeWire(const Handle(PTopoDS_HShape)& S) const 
332 {
333   Handle(PTopoDS_TWire) T = new PTopoDS_TWire();
334   S->TShape(T);
335 }
336
337
338 //=======================================================================
339 //function : MakeFace
340 //purpose  : 
341 //=======================================================================
342
343 void  MgtBRep_TranslateTool::MakeFace(TopoDS_Shape& S) const 
344 {
345   BRep_Builder B;
346   B.MakeFace(TopoDS::Face(S));
347 }
348
349
350 //=======================================================================
351 //function : MakeFace
352 //purpose  : 
353 //=======================================================================
354
355 void  MgtBRep_TranslateTool::MakeFace(const Handle(PTopoDS_HShape)& S) const 
356 {
357   Handle(PBRep_TFace) T = new PBRep_TFace();
358   S->TShape(T);
359 }
360
361
362 //=======================================================================
363 //function : MakeShell
364 //purpose  : 
365 //=======================================================================
366
367 void  MgtBRep_TranslateTool::MakeShell(TopoDS_Shape& S) const 
368 {
369   BRep_Builder B;
370   B.MakeShell(TopoDS::Shell(S));
371 }
372
373
374 //=======================================================================
375 //function : MakeShell
376 //purpose  : 
377 //=======================================================================
378
379 void  MgtBRep_TranslateTool::MakeShell(const Handle(PTopoDS_HShape)& S) const 
380 {
381   Handle(PTopoDS_TShell) T = new PTopoDS_TShell();
382   S->TShape(T);
383 }
384
385
386 //=======================================================================
387 //function : MakeSolid
388 //purpose  : 
389 //=======================================================================
390
391 void  MgtBRep_TranslateTool::MakeSolid(TopoDS_Shape& S) const 
392 {
393   BRep_Builder B;
394   B.MakeSolid(TopoDS::Solid(S));
395 }
396
397
398 //=======================================================================
399 //function : MakeSolid
400 //purpose  : 
401 //=======================================================================
402
403 void  MgtBRep_TranslateTool::MakeSolid(const Handle(PTopoDS_HShape)& S) const 
404 {
405   Handle(PTopoDS_TSolid) T = new PTopoDS_TSolid();
406   S->TShape(T);
407 }
408
409
410 //=======================================================================
411 //function : MakeCompSolid
412 //purpose  : 
413 //=======================================================================
414
415 void  MgtBRep_TranslateTool::MakeCompSolid(TopoDS_Shape& S) const 
416 {
417   BRep_Builder B;
418   B.MakeCompSolid(TopoDS::CompSolid(S));
419 }
420
421
422 //=======================================================================
423 //function : MakeCompSolid
424 //purpose  : 
425 //=======================================================================
426
427 void  
428 MgtBRep_TranslateTool::MakeCompSolid(const Handle(PTopoDS_HShape)& S) const 
429 {
430   Handle(PTopoDS_TCompSolid) T = new PTopoDS_TCompSolid();
431   S->TShape(T);
432 }
433
434
435 //=======================================================================
436 //function : MakeCompound
437 //purpose  : 
438 //=======================================================================
439
440 void  MgtBRep_TranslateTool::MakeCompound(TopoDS_Shape& S) const 
441 {
442   BRep_Builder B;
443   B.MakeCompound(TopoDS::Compound(S));
444 }
445
446
447 //=======================================================================
448 //function : MakeCompound
449 //purpose  : 
450 //=======================================================================
451
452 void  
453 MgtBRep_TranslateTool::MakeCompound(const Handle(PTopoDS_HShape)& S) const 
454 {
455   Handle(PTopoDS_TCompound) T = new PTopoDS_TCompound();
456   S->TShape(T);
457 }
458
459
460 //=======================================================================
461 //function : UpdateVertex
462 //purpose  : Transient->Persistent
463 //=======================================================================
464
465 void  MgtBRep_TranslateTool::UpdateVertex
466 (const TopoDS_Shape& S1,
467  const Handle(PTopoDS_HShape)& S2,
468  PTColStd_TransientPersistentMap& aMap) const 
469 {
470   Handle(TopoDS_TShape) aTransTShape = S1.TShape();
471   Handle(BRep_TVertex)& TTV = (Handle(BRep_TVertex)&) aTransTShape;
472   Handle(PTopoDS_TShape) aPersTShape = S2->TShape();
473   Handle(PBRep_TVertex)& PTV = (Handle(PBRep_TVertex)&) aPersTShape;
474
475   // Point
476   PTV->Pnt(TTV->Pnt());
477
478   // Tolerance
479   PTV->Tolerance(TTV->Tolerance());
480
481   // Representations
482   BRep_ListIteratorOfListOfPointRepresentation itpr(TTV->Points());
483
484   Handle(PBRep_PointRepresentation) PPR, CPPR;
485   while (itpr.More()) {
486
487     const Handle(BRep_PointRepresentation)& PR = itpr.Value();
488
489     if (PR->IsPointOnCurve()) {
490       Handle(PBRep_PointOnCurve) POC = new 
491         PBRep_PointOnCurve(PR->Parameter(),
492                            MgtBRep_TranslateTool::Translate(PR->Curve(), aMap),
493                            MgtTopLoc::Translate(PR->Location(), aMap));
494       CPPR = POC;
495     }
496
497     else if (PR->IsPointOnCurveOnSurface()) {
498       Handle(PBRep_PointOnCurveOnSurface) POCS = 
499         new PBRep_PointOnCurveOnSurface(PR->Parameter(),
500                                         MgtBRep_TranslateTool::Translate(PR->PCurve(), aMap),
501                                         MgtBRep_TranslateTool::Translate(PR->Surface(), aMap),
502                                         MgtTopLoc::Translate(PR->Location(), aMap));
503       CPPR = POCS;
504     }
505
506     else if (PR->IsPointOnSurface()) {
507       Handle(PBRep_PointOnSurface) POS = 
508         new PBRep_PointOnSurface(PR->Parameter(),
509                                  PR->Parameter2(),
510                                  MgtBRep_TranslateTool::Translate(PR->Surface(), aMap),
511                                  MgtTopLoc::Translate(PR->Location(), aMap));
512       CPPR = POS;
513     }
514     
515     CPPR->Next(PPR);
516     PPR = CPPR;
517     itpr.Next();
518   }
519   
520   PTV->Points(PPR);
521   
522   MgtTopoDS_TranslateTool::UpdateVertex(S1,S2, aMap);
523 }
524
525
526 //=======================================================================
527 //function : UpdateVertex
528 //purpose  : Persistent->Transient
529 //=======================================================================
530
531 void MgtBRep_TranslateTool::UpdateVertex
532 (const Handle(PTopoDS_HShape)& S1, 
533  TopoDS_Shape& S2,
534  PTColStd_PersistentTransientMap& aMap) const 
535 {
536   Handle(PTopoDS_TShape) aPersTShape = S1->TShape();
537   Handle(PBRep_TVertex)& PTV = (Handle(PBRep_TVertex)&) aPersTShape;
538
539   Handle(TopoDS_TShape) aTransTShape = S2.TShape();
540   Handle(BRep_TVertex)&  TTV = (Handle(BRep_TVertex)&) aTransTShape;
541
542   // Point
543   TTV->Pnt(PTV->Pnt());
544
545   // Tolerance
546   TTV->Tolerance(PTV->Tolerance());
547
548   // Representations
549   Handle(PBRep_PointRepresentation) PPR = PTV->Points();
550   BRep_ListOfPointRepresentation& lpr = TTV->ChangePoints();
551
552   lpr.Clear();
553
554   Handle(BRep_PointRepresentation) PR;
555
556   while (!PPR.IsNull()) {
557
558     if (PPR->IsPointOnCurve()) {
559       Handle(PBRep_PointOnCurve)& POC = (Handle(PBRep_PointOnCurve)&) PPR;
560       Handle(BRep_PointOnCurve) OC =
561         new BRep_PointOnCurve(POC->Parameter(),
562                               MgtBRep_TranslateTool::Translate(POC->Curve(), aMap),
563                               MgtTopLoc::Translate(POC->Location(), aMap));
564       PR = OC;
565     }
566     
567     else if (PPR->IsPointOnCurveOnSurface()) {
568       Handle(PBRep_PointOnCurveOnSurface)& POCS =
569         (Handle(PBRep_PointOnCurveOnSurface)&) PPR;
570       Handle(BRep_PointOnCurveOnSurface) OCS =
571         new BRep_PointOnCurveOnSurface(POCS->Parameter(),
572                                        MgtBRep_TranslateTool::Translate(POCS->PCurve(), aMap),
573                                        MgtBRep_TranslateTool::Translate(POCS->Surface(), aMap),
574                                        MgtTopLoc::Translate(POCS->Location(), aMap));
575       PR = OCS;
576     }
577     
578     else if (PPR->IsPointOnSurface()) {
579       Handle(PBRep_PointOnSurface)& POS = (Handle(PBRep_PointOnSurface)&) PPR;
580       Handle(BRep_PointOnSurface) OS =
581         new BRep_PointOnSurface(POS->Parameter(),
582                                 POS->Parameter2(),
583                                 MgtBRep_TranslateTool::Translate(POS->Surface(), aMap),
584                                 MgtTopLoc::Translate(POS->Location(), aMap));
585       PR = OS;
586     }
587     
588     lpr.Prepend(PR);
589     PPR = PPR->Next();
590   }
591   
592   MgtTopoDS_TranslateTool::UpdateVertex(S1,S2, aMap);
593 }
594
595
596 //=======================================================================
597 //function : UpdateEdge
598 //purpose  : Transient->Persistent
599 //=======================================================================
600
601 void  
602 MgtBRep_TranslateTool::UpdateEdge(const TopoDS_Shape& S1,
603                                   const Handle(PTopoDS_HShape)& S2,
604                                   PTColStd_TransientPersistentMap& aMap) const 
605 {
606   Handle(TopoDS_TShape) aTransTShape = S1.TShape();
607   Handle(BRep_TEdge)&  TTE = (Handle(BRep_TEdge)&) aTransTShape;
608
609   Handle(PTopoDS_TShape) aPersTShape = S2->TShape();
610   Handle(PBRep_TEdge)& PTE = (Handle(PBRep_TEdge)&) aPersTShape;
611
612   // tolerance
613   PTE->Tolerance(TTE->Tolerance());
614   
615   // same parameter
616   PTE->SameParameter(TTE->SameParameter());
617
618   // same range
619   PTE->SameRange(TTE->SameRange());
620
621   // Degenerated
622   PTE->Degenerated(TTE->Degenerated());
623   
624   // Representations
625   BRep_ListIteratorOfListOfCurveRepresentation itcr(TTE->Curves());
626
627   Handle(PBRep_CurveRepresentation) PCR, CPCR;
628   Handle(BRep_GCurve) GC;
629   Standard_Real f, l;
630
631   while (itcr.More()) {
632
633     const Handle(BRep_CurveRepresentation)& CR = itcr.Value();
634     
635     GC = Handle(BRep_GCurve)::DownCast(CR);
636     if (!GC.IsNull()) {
637       GC->Range(f, l);
638
639       // CurveRepresentation is Curve3D
640       if (CR->IsCurve3D()) {
641         Handle(PBRep_Curve3D) C3D = new 
642           PBRep_Curve3D(MgtBRep_TranslateTool::Translate(CR->Curve3D(),aMap),
643                         f, l, MgtTopLoc::Translate(CR->Location(), aMap));
644         CPCR = C3D;
645       }
646       
647       // CurveRepresentation is CurveOnSurface
648       else if (CR->IsCurveOnSurface()) {
649         
650         Handle(BRep_CurveOnSurface)& theCOS=(Handle(BRep_CurveOnSurface)&) CR;
651         Handle(PBRep_CurveOnSurface) COS;
652
653         // CurveRepresentation is CurveOnSurface
654         if (!CR->IsCurveOnClosedSurface()) {
655           COS =
656             new PBRep_CurveOnSurface
657               (MgtBRep_TranslateTool::Translate(CR->PCurve(), aMap),
658                f, l,
659                MgtBRep_TranslateTool::Translate(CR->Surface(), aMap),
660                MgtTopLoc::Translate(CR->Location(), aMap));
661         }
662         
663         // CurveRepresentation is CurveOnClosedSurface
664         else {
665           // get UVPoints for the CurveOnClosedSurface definition.
666           Handle(BRep_CurveOnClosedSurface)& theCOCS =
667             (Handle(BRep_CurveOnClosedSurface)&) CR;
668           gp_Pnt2d Pnt21, Pnt22;
669           theCOCS->UVPoints2(Pnt21, Pnt22);
670           Handle(PBRep_CurveOnClosedSurface) COCS =
671             new PBRep_CurveOnClosedSurface
672               (MgtBRep_TranslateTool::Translate(CR->PCurve(), aMap),
673                MgtBRep_TranslateTool::Translate(CR->PCurve2(), aMap),
674                f, l, 
675                MgtBRep_TranslateTool::Translate(CR->Surface(), aMap),
676                MgtTopLoc::Translate(CR->Location(), aMap),
677                CR->Continuity());
678           COCS->SetUVPoints2(Pnt21, Pnt22);
679           COS = COCS;
680         }
681
682         // get UVPoints for the CurveOnSurface definition.
683         gp_Pnt2d Pnt1, Pnt2;
684         theCOS->UVPoints(Pnt1, Pnt2);
685
686         // If we don't do that, there is anything (NAN: Not A Number) instead.
687         COS->SetUVPoints(Pnt1, Pnt2);
688         CPCR = COS;
689         
690       }
691     }
692     
693     // CurveRepresentation is CurveOn2Surfaces
694     else if (CR->IsRegularity()) {
695       
696       Handle(PBRep_CurveOn2Surfaces) R =
697         new PBRep_CurveOn2Surfaces
698           (MgtBRep_TranslateTool::Translate(CR->Surface(), aMap),
699            MgtBRep_TranslateTool::Translate(CR->Surface2(), aMap),
700            MgtTopLoc::Translate(CR->Location(), aMap),
701            MgtTopLoc::Translate(CR->Location2(), aMap),
702            CR->Continuity());
703       CPCR = R;
704     }
705     
706     // CurveRepresentation is Polygon or Triangulation
707     else if (myTriangleMode == MgtBRep_WithTriangle) {
708       
709       // CurveRepresentation is Polygon3D
710       if (CR->IsPolygon3D()) {
711         Handle(PBRep_Polygon3D) P3D = 
712           new PBRep_Polygon3D(MgtPoly::Translate(CR->Polygon3D(), aMap),
713                               MgtTopLoc::Translate(CR->Location(), aMap));
714         CPCR = P3D;
715       }
716
717       // CurveRepresentation is PolygonOnSurface
718       else if (CR->IsPolygonOnSurface()) {
719
720         // CurveRepresentation is PolygonOnClosedSurface
721         if (CR->IsPolygonOnClosedSurface()) {
722           Handle(PBRep_PolygonOnClosedSurface)  PolOCS = new 
723             PBRep_PolygonOnClosedSurface(MgtPoly::Translate(CR->Polygon(), aMap),
724                                          MgtPoly::Translate(CR->Polygon2(), aMap),
725                                          MgtBRep_TranslateTool::Translate(CR->Surface(), aMap),
726                                          MgtTopLoc::Translate(CR->Location(), aMap));
727           CPCR = PolOCS;
728         }
729
730         // CurveRepresentation is PolygonOnSurface
731         else {
732           Handle(PBRep_PolygonOnSurface) PolOS = new
733             PBRep_PolygonOnSurface(MgtPoly::Translate(CR->Polygon(), aMap),
734                                    MgtBRep_TranslateTool::Translate(CR->Surface(),aMap),
735                                    MgtTopLoc::Translate(CR->Location(), aMap));
736           CPCR = PolOS;
737         }
738       }
739
740       // CurveRepresentation is PolygonOnTriangulation
741       else if (CR->IsPolygonOnTriangulation()) {
742
743         // CurveRepresentation is PolygonOnClosedTriangulation
744         if (CR->IsPolygonOnClosedTriangulation()) {
745
746           Handle(PBRep_PolygonOnClosedTriangulation) PolOCT= new
747             PBRep_PolygonOnClosedTriangulation
748               (MgtPoly::Translate(CR->PolygonOnTriangulation(), aMap),
749                MgtPoly::Translate(CR->PolygonOnTriangulation2(), aMap),
750                MgtPoly::Translate(CR->Triangulation(), aMap),
751                MgtTopLoc::Translate(CR->Location(), aMap));
752           CPCR = PolOCT;
753         }
754
755         // CurveRepresentation is PolygonOnTriangulation
756         else {
757           Handle(PBRep_PolygonOnTriangulation) PolOT = new
758             PBRep_PolygonOnTriangulation
759               (MgtPoly::Translate(CR->PolygonOnTriangulation(), aMap),
760                MgtPoly::Translate(CR->Triangulation(), aMap),
761                MgtTopLoc::Translate(CR->Location(), aMap));
762           CPCR = PolOT;
763         }
764       }
765     }
766     else {
767       // jumps the curve representation
768       itcr.Next();
769       continue;
770     }
771     
772     Standard_NullObject_Raise_if (CPCR.IsNull(), "Null CurveRepresentation");
773     
774     CPCR->Next(PCR);
775     PCR = CPCR;
776     itcr.Next();
777   }
778   
779   // set
780   PTE->Curves(PCR);
781   
782   MgtTopoDS_TranslateTool::UpdateEdge(S1,S2, aMap);
783 }
784
785
786 //=======================================================================
787 //function : UpdateEdge
788 //purpose  : Persistent->Transient
789 //=======================================================================
790
791 void  
792 MgtBRep_TranslateTool::UpdateEdge(const Handle(PTopoDS_HShape)& S1,
793                                   TopoDS_Shape& S2,
794                                   PTColStd_PersistentTransientMap& aMap) const 
795 {
796   Handle(PTopoDS_TShape) aPersTShape = S1->TShape();
797   Handle(PBRep_TEdge)& PTE = (Handle(PBRep_TEdge)&) aPersTShape;
798
799   Handle(TopoDS_TShape) aTransTShape = S2.TShape();
800   Handle(BRep_TEdge)&  TTE = (Handle(BRep_TEdge)&) aTransTShape;
801
802   // tolerance
803   TTE->Tolerance(PTE->Tolerance());
804   
805   // same parameter
806   TTE->SameParameter(PTE->SameParameter());
807
808   // same range
809   TTE->SameRange(PTE->SameRange());
810
811   // Degenerated
812   TTE->Degenerated(PTE->Degenerated());
813   
814   // Representations
815   Handle(PBRep_CurveRepresentation) PCR = PTE->Curves();
816   BRep_ListOfCurveRepresentation& lcr = TTE->ChangeCurves();
817
818   lcr.Clear();
819   Handle(BRep_CurveRepresentation) CR;
820
821   while (!PCR.IsNull()) {
822     
823     if (PCR->IsGCurve()) {
824       Handle(PBRep_GCurve)& PGC = (Handle(PBRep_GCurve)&) PCR;
825       if (PCR->IsCurveOnSurface()) {
826         gp_Pnt2d Pnt1, Pnt2;
827         if (!PCR->IsCurveOnClosedSurface()) {
828           // CurveRepresentation is a PBRep_CurveOnSurface
829           Handle(PBRep_CurveOnSurface)& PCOS = (Handle(PBRep_CurveOnSurface)&) PCR;
830           Handle(BRep_CurveOnSurface) COS =
831             new BRep_CurveOnSurface
832               (MgtBRep_TranslateTool::Translate(PCOS->PCurve(), aMap),
833                MgtBRep_TranslateTool::Translate(PCOS->Surface(), aMap),
834                MgtTopLoc::Translate(PCOS->Location(), aMap));
835           Pnt1 = PCOS->FirstUV();
836           Pnt2 = PCOS->LastUV();
837           COS->SetUVPoints(Pnt1, Pnt2);
838           COS->SetRange(PGC->First(), PGC->Last());
839           CR = COS;
840         }
841         else {
842           // CurveRepresentation is a PBRep_CurveOnClosedSurface
843           gp_Pnt2d Pnt21, Pnt22;
844           Handle(PBRep_CurveOnClosedSurface)& PCOCS =
845             (Handle(PBRep_CurveOnClosedSurface)&) PCR;
846           Handle(BRep_CurveOnClosedSurface) COCS =
847             new BRep_CurveOnClosedSurface
848               (MgtBRep_TranslateTool::Translate(PCOCS->PCurve(), aMap),
849                MgtBRep_TranslateTool::Translate(PCOCS->PCurve2(), aMap),
850                MgtBRep_TranslateTool::Translate(PCOCS->Surface(), aMap),
851                MgtTopLoc::Translate(PCOCS->Location(), aMap),
852                PCOCS->Continuity());
853           Pnt21 = PCOCS->FirstUV2();
854           Pnt22 = PCOCS->LastUV2();
855           COCS->SetUVPoints(Pnt1, Pnt2); // Is it necessary?
856           COCS->SetUVPoints2(Pnt21, Pnt22);
857           COCS->SetRange(PGC->First(), PGC->Last());
858           CR = COCS;
859         }
860       }
861       else if (PCR->IsCurve3D()) {
862         Handle(PBRep_Curve3D)& PC3D = (Handle(PBRep_Curve3D)&) PCR;
863
864 // szy 23.01.2014: correction for edge which has null 3d curve representation
865         Handle(BRep_Curve3D) C3D =
866           new BRep_Curve3D(MgtBRep_TranslateTool::Translate(PC3D->Curve3D(), aMap),
867                              MgtTopLoc::Translate(PC3D->Location(), aMap));
868         C3D->SetRange(PGC->First(), PGC->Last());
869         CR = C3D;
870       }
871     }
872     else if (PCR->IsRegularity()) {
873       Handle(PBRep_CurveOn2Surfaces)& PR = 
874         (Handle(PBRep_CurveOn2Surfaces)&) PCR;
875       Handle(BRep_CurveOn2Surfaces) R =
876         new BRep_CurveOn2Surfaces
877           (MgtBRep_TranslateTool::Translate(PR->Surface(), aMap),
878            MgtBRep_TranslateTool::Translate(PR->Surface2(), aMap),
879            MgtTopLoc::Translate(PR->Location(), aMap),
880            MgtTopLoc::Translate(PR->Location2(), aMap),
881            PR->Continuity());
882       CR = R;
883     }
884     
885     else if (myTriangleMode == MgtBRep_WithTriangle) {
886       if (PCR->IsPolygon3D()) {
887         Handle(PBRep_Polygon3D)& PP3D = (Handle(PBRep_Polygon3D)&) PCR;
888         Handle(BRep_Polygon3D) P3D = new
889           BRep_Polygon3D(MgtPoly::Translate(PP3D->Polygon3D(), aMap),
890                          MgtTopLoc::Translate(PP3D->Location(), aMap));
891         CR = P3D;
892       }
893       else if (PCR->IsPolygonOnSurface()) {
894         if (PCR->IsPolygonOnClosedSurface()) {
895           Handle(PBRep_PolygonOnClosedSurface)& PPol = 
896             (Handle(PBRep_PolygonOnClosedSurface)&) PCR;
897           Handle(BRep_PolygonOnClosedSurface)  PolOCS = new 
898             BRep_PolygonOnClosedSurface
899               (MgtPoly::Translate(PPol->Polygon(), aMap),
900                MgtPoly::Translate(PPol->Polygon2(), aMap),
901                MgtBRep_TranslateTool::Translate(PPol->Surface(), aMap),
902                MgtTopLoc::Translate(PPol->Location(), aMap));
903           CR = PolOCS;
904         }
905         else {
906           Handle(PBRep_PolygonOnSurface)& PPol = 
907             (Handle(PBRep_PolygonOnSurface)&) PCR;
908           Handle(BRep_PolygonOnSurface) PolOS = new
909             BRep_PolygonOnSurface
910               (MgtPoly::Translate(PPol->Polygon(), aMap),
911                MgtBRep_TranslateTool::Translate(PPol->Surface(), aMap),
912                MgtTopLoc::Translate(PPol->Location(), aMap));
913           CR = PolOS;
914         }
915       }
916       // PCR is a PolygonOnTriangulation
917       else if (PCR->IsPolygonOnTriangulation()) {
918         
919         Handle(PBRep_PolygonOnTriangulation)& POT =
920           (Handle(PBRep_PolygonOnTriangulation)&) PCR;
921         
922         // PCR is a PolygonOnClosedTriangulation
923         if (PCR->IsPolygonOnClosedTriangulation()) {
924           Handle(PBRep_PolygonOnClosedTriangulation)& POCT =
925             (Handle(PBRep_PolygonOnClosedTriangulation)&) PCR;
926           
927           Handle(BRep_PolygonOnClosedTriangulation) PolOCT= new
928             BRep_PolygonOnClosedTriangulation
929               (MgtPoly::Translate(POCT->PolygonOnTriangulation(), aMap),
930                MgtPoly::Translate(POCT->PolygonOnTriangulation2(), aMap),
931                MgtPoly::Translate(POCT->Triangulation(), aMap),
932                MgtTopLoc::Translate(POCT->Location(), aMap));
933           CR = PolOCT;
934         }
935         // PCR is a PolygonOnTriangulation
936         else {
937           Handle(BRep_PolygonOnTriangulation) PolOT = new
938             BRep_PolygonOnTriangulation
939               (MgtPoly::Translate(POT->PolygonOnTriangulation(), aMap),
940                MgtPoly::Translate(POT->Triangulation(), aMap),
941                MgtTopLoc::Translate(POT->Location(), aMap));
942           CR = PolOT;
943         }
944       }
945     }
946     else {
947       // jumps the Curve Representation
948       PCR = PCR->Next();
949       continue;
950     }
951     
952     Standard_NullObject_Raise_if (CR.IsNull(), "Persistant CurveRep is Null");
953     
954     lcr.Prepend(CR); 
955     PCR = PCR->Next();
956   }
957   
958   MgtTopoDS_TranslateTool::UpdateEdge(S1,S2, aMap);
959 }
960
961
962 //=======================================================================
963 //function : UpdateFace
964 //purpose  : Transient->Persistent
965 //=======================================================================
966
967 void  
968 MgtBRep_TranslateTool::UpdateFace(const TopoDS_Shape& S1, 
969                                   const Handle(PTopoDS_HShape)& S2,
970                                   PTColStd_TransientPersistentMap& aMap) const 
971 {
972   Handle(TopoDS_TShape) aTransTShape = S1.TShape();
973   Handle(BRep_TFace)&  TTF = (Handle(BRep_TFace)&) aTransTShape;
974
975   Handle(PTopoDS_TShape) aPersTShape = S2->TShape();
976   Handle(PBRep_TFace)& PTF = (Handle(PBRep_TFace)&) aPersTShape;
977
978   // natural restriction
979   PTF->NaturalRestriction(TTF->NaturalRestriction());
980
981   // tolerance
982   PTF->Tolerance(TTF->Tolerance());
983
984   // location
985   PTF->Location(MgtTopLoc::Translate(TTF->Location(), aMap));
986
987   // surface
988   PTF->Surface(MgtBRep_TranslateTool::Translate(TTF->Surface(), aMap));
989
990   // Triangulation
991   if (myTriangleMode == MgtBRep_WithTriangle) {
992     PTF->Triangulation(MgtPoly::Translate(TTF->Triangulation(), aMap));
993   }
994   
995   MgtTopoDS_TranslateTool::UpdateFace(S1,S2, aMap);
996 }
997
998
999 //=======================================================================
1000 //function : UpdateFace
1001 //purpose  : Persistent->Transient
1002 //=======================================================================
1003
1004 void  
1005 MgtBRep_TranslateTool::UpdateFace(const Handle(PTopoDS_HShape)& S1, 
1006                                   TopoDS_Shape& S2,
1007                                   PTColStd_PersistentTransientMap& aMap) const 
1008 {
1009   Handle(PTopoDS_TShape) aPersTShape = S1->TShape();
1010   Handle(PBRep_TFace)& PTF = (Handle(PBRep_TFace)&) aPersTShape;
1011
1012   Handle(TopoDS_TShape) aTransTShape = S2.TShape();
1013   Handle(BRep_TFace)&  TTF = (Handle(BRep_TFace)&) aTransTShape;
1014
1015   // natural restriction
1016   TTF->NaturalRestriction(PTF->NaturalRestriction());
1017
1018   // tolerance
1019   TTF->Tolerance(PTF->Tolerance());
1020
1021   // location
1022   TTF->Location(MgtTopLoc::Translate(PTF->Location(), aMap));
1023
1024   // surface
1025   TTF->Surface(MgtBRep_TranslateTool::Translate(PTF->Surface(), aMap));
1026
1027   // Triangulation
1028   if ( myTriangleMode == MgtBRep_WithTriangle) {
1029     TTF->Triangulation(MgtPoly::Translate(PTF->Triangulation(), aMap));
1030   }
1031
1032   MgtTopoDS_TranslateTool::UpdateFace(S1,S2, aMap);
1033 }
1034