0024023: Revamp the OCCT Handle -- ambiguity
[occt.git] / src / BRep / BRep_Builder.cxx
1 // Created on: 1991-07-02
2 // Created by: Remi LEQUETTE
3 // Copyright (c) 1991-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 <BRep_Builder.ixx>
18
19 #include <BRep_TEdge.hxx>
20 #include <BRep_Curve3D.hxx>
21 #include <BRep_GCurve.hxx>
22 #include <BRep_CurveOnClosedSurface.hxx>
23 #include <BRep_CurveOn2Surfaces.hxx>
24 #include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
25
26 #include <BRep_PointOnCurve.hxx>
27 #include <BRep_PointOnCurveOnSurface.hxx>
28 #include <BRep_PointOnSurface.hxx>
29 #include <BRep_ListIteratorOfListOfPointRepresentation.hxx>
30
31 #include <TopoDS.hxx>
32 #include <TopoDS_Iterator.hxx>
33 #include <TopoDS_LockedShape.hxx>
34
35 #include <Precision.hxx>
36
37 #include <BRep_Polygon3D.hxx>
38 #include <BRep_PolygonOnSurface.hxx>
39 #include <BRep_PolygonOnClosedSurface.hxx>
40 #include <BRep_PolygonOnTriangulation.hxx>
41 #include <BRep_PolygonOnClosedTriangulation.hxx>
42
43 #include <Standard_NullObject.hxx>
44
45 //=======================================================================
46 //function : Auxiliary methods
47 //purpose  : 
48 //=======================================================================
49
50 //=======================================================================
51 //function : UpdateCurves
52 //purpose  : Insert a 3d curve <C> with location <L> 
53 //           in a list of curve representations <lcr>
54 //=======================================================================
55
56 static void UpdateCurves(BRep_ListOfCurveRepresentation& lcr,
57                          const Handle(Geom_Curve)&       C,
58                          const TopLoc_Location&          L)
59 {
60   BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
61   Handle(BRep_GCurve) GC;
62   Standard_Real f = 0.,l = 0.;
63
64   while (itcr.More()) {
65     GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
66     if (!GC.IsNull()) {
67       GC->Range(f, l);
68       if (GC->IsCurve3D()) break;
69
70     }
71     itcr.Next();
72   }
73
74   if (itcr.More()) {
75     itcr.Value()->Curve3D(C);
76     itcr.Value()->Location(L);
77   }
78   else {
79     Handle(BRep_Curve3D) C3d = new BRep_Curve3D(C,L);
80     // test if there is already a range
81     if (!GC.IsNull()) {
82       C3d->SetRange(f,l);
83     }
84     lcr.Append(C3d);
85   }
86   
87 }
88
89 //=======================================================================
90 //function : UpdateCurves
91 //purpose  : Insert a pcurve <C> on surface <S> with location <L> 
92 //           in a list of curve representations <lcr>
93 //           Remove the pcurve on <S> from <lcr> if <C> is null
94 //=======================================================================
95
96 static void UpdateCurves(BRep_ListOfCurveRepresentation& lcr,
97                          const Handle(Geom2d_Curve)& C,
98                          const Handle(Geom_Surface)& S,
99                          const TopLoc_Location& L)
100 {
101   BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
102   Handle(BRep_CurveRepresentation) cr;
103   Handle(BRep_GCurve) GC;
104   Standard_Real f = 0.,l = 0.;
105   Standard_Boolean rangeFound = Standard_False;
106
107   // search the range of the 3d curve
108   // and remove any existing representation
109
110   while (itcr.More()) {
111     GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
112     if (!GC.IsNull()) {
113       if (GC->IsCurve3D()) {
114 //      if (!C.IsNull()) { //xpu031198, edge degeneree
115
116         // xpu151298 : parameters can be setted for null curves
117         //             see lbo & flo, to determine whether range is defined
118         //             compare first and last parameters with default values.
119         GC->Range(f, l);
120         //lvt 15/6/99: On enleve la comparaison de reels infinis.
121         Standard_Boolean undefined = (Precision::IsPositiveInfinite(l) ||
122                                       Precision::IsNegativeInfinite(f));
123         
124         if (!undefined) {
125           rangeFound = Standard_True;
126         }
127       }
128       if (GC->IsCurveOnSurface(S,L)) {
129         // remove existing curve on surface
130         // cr is used to keep a reference on the curve representation
131         // this avoid deleting it as its content may be referenced by C or S
132         cr = itcr.Value();
133         lcr.Remove(itcr);
134       }
135       else {
136         itcr.Next();
137       }
138     }
139     else {
140       itcr.Next();
141     }
142   }
143
144   if (! C.IsNull()) {
145     Handle(BRep_CurveOnSurface) COS = new BRep_CurveOnSurface(C,S,L);
146     // test if there is already a range
147     if (rangeFound) {
148       COS->SetRange(f,l);
149     }
150     lcr.Append(COS);
151   }
152 }
153
154 //=======================================================================
155 //function : UpdateCurves
156 //purpose  : Insert a pcurve <C> on surface <S> with location <L> 
157 //           in a list of curve representations <lcr>
158 //           Remove the pcurve on <S> from <lcr> if <C> is null
159 //=======================================================================
160 static void UpdateCurves(BRep_ListOfCurveRepresentation& lcr,
161                          const Handle(Geom2d_Curve)& C,
162                          const Handle(Geom_Surface)& S,
163                          const TopLoc_Location& L,
164                          const gp_Pnt2d& Pf,
165                          const gp_Pnt2d& Pl)
166 {
167   BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
168   Handle(BRep_CurveRepresentation) cr;
169   Handle(BRep_GCurve) GC;
170   Standard_Real f = 0.,l = 0.;
171   Standard_Boolean rangeFound = Standard_False;
172
173   // search the range of the 3d curve
174   // and remove any existing representation
175
176   while (itcr.More()) {
177     GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
178     if (!GC.IsNull()) {
179       if (GC->IsCurve3D()) {
180 //      if (!C.IsNull()) { //xpu031198, edge degeneree
181
182         // xpu151298 : parameters can be setted for null curves
183         //             see lbo & flo, to determine whether range is defined
184         //             compare first and last parameters with default values.
185         GC->Range(f, l);
186         //lvt 15/6/99: On enleve la comparaison de reels infinis.
187         Standard_Boolean undefined = (Precision::IsPositiveInfinite(l) ||
188                                       Precision::IsNegativeInfinite(f));
189         
190         if (!undefined) {
191           rangeFound = Standard_True;
192         }
193       }
194       if (GC->IsCurveOnSurface(S,L)) {
195         // remove existing curve on surface
196         // cr is used to keep a reference on the curve representation
197         // this avoid deleting it as its content may be referenced by C or S
198         cr = itcr.Value();
199         lcr.Remove(itcr);
200       }
201       else {
202         itcr.Next();
203       }
204     }
205     else {
206       itcr.Next();
207     }
208   }
209
210   if (! C.IsNull()) {
211     Handle(BRep_CurveOnSurface) COS = new BRep_CurveOnSurface(C,S,L);
212     // test if there is already a range
213     if (rangeFound) {
214       COS->SetRange(f,l);
215     }
216     COS->SetUVPoints(Pf,Pl);
217     lcr.Append(COS);
218   }
219 }
220
221 //=======================================================================
222 //function : UpdateCurves
223 //purpose  : Insert two pcurves <C1,C2> on surface <S> with location <L> 
224 //           in a list of curve representations <lcr>
225 //           Remove the pcurves on <S> from <lcr> if <C1> or <C2> is null
226 //=======================================================================
227
228 static void UpdateCurves(BRep_ListOfCurveRepresentation& lcr,
229                          const Handle(Geom2d_Curve)& C1,
230                          const Handle(Geom2d_Curve)& C2,
231                          const Handle(Geom_Surface)& S,
232                          const TopLoc_Location& L)
233 {
234   BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
235   Handle(BRep_CurveRepresentation) cr;
236   Handle(BRep_GCurve) GC;
237   Standard_Real f = 0.,l = 0.;
238   Standard_Boolean rangeFound = Standard_False;
239
240   while (itcr.More()) {
241     GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
242     if ( !GC.IsNull() ) {
243       if (GC->IsCurve3D()) {
244         GC->Range(f,l);
245         Standard_Boolean undefined = (Precision::IsPositiveInfinite(l) ||
246                                       Precision::IsNegativeInfinite(f));
247           
248         if (!undefined) {
249           rangeFound = Standard_True;
250         }
251       }
252       Standard_Boolean iscos = GC->IsCurveOnSurface(S,L);
253       if (iscos) break;
254     }
255     itcr.Next();
256   }
257
258   if (itcr.More())  {
259     // cr is used to keep a reference on the curve representation
260     // this avoid deleting it as its content may be referenced by C or S
261     cr = itcr.Value();
262     lcr.Remove(itcr);
263   }
264
265   if ( !C1.IsNull() && !C2.IsNull() ) {
266     Handle(BRep_CurveOnClosedSurface) COS =
267       new BRep_CurveOnClosedSurface(C1,C2,S,L,GeomAbs_C0);
268     // test if there is already a range
269     if (rangeFound) {
270       COS->SetRange(f,l);
271     }
272     lcr.Append(COS);
273   }
274 }
275
276 //=======================================================================
277 //function : UpdateCurves
278 //purpose  : Insert two pcurves <C1,C2> on surface <S> with location <L> 
279 //           in a list of curve representations <lcr>
280 //           Remove the pcurves on <S> from <lcr> if <C1> or <C2> is null
281 //=======================================================================
282 static void UpdateCurves(BRep_ListOfCurveRepresentation& lcr,
283                          const Handle(Geom2d_Curve)& C1,
284                          const Handle(Geom2d_Curve)& C2,
285                          const Handle(Geom_Surface)& S,
286                          const TopLoc_Location& L,
287                          const gp_Pnt2d& Pf,
288                          const gp_Pnt2d& Pl)
289 {
290   BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
291   Handle(BRep_CurveRepresentation) cr;
292   Handle(BRep_GCurve) GC;
293   Standard_Real f = 0.,l = 0.;
294   Standard_Boolean rangeFound = Standard_False;
295
296   while (itcr.More()) {
297     GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
298     if ( !GC.IsNull() ) {
299       if (GC->IsCurve3D()) {
300         GC->Range(f,l);
301         Standard_Boolean undefined = (Precision::IsPositiveInfinite(l) ||
302                                       Precision::IsNegativeInfinite(f));
303           
304         if (!undefined) {
305           rangeFound = Standard_True;
306         }
307       }
308       Standard_Boolean iscos = GC->IsCurveOnSurface(S,L);
309       if (iscos) break;
310     }
311     itcr.Next();
312   }
313
314   if (itcr.More())  {
315     // cr is used to keep a reference on the curve representation
316     // this avoid deleting it as its content may be referenced by C or S
317     cr = itcr.Value();
318     lcr.Remove(itcr);
319   }
320
321   if ( !C1.IsNull() && !C2.IsNull() ) {
322     Handle(BRep_CurveOnClosedSurface) COS =
323       new BRep_CurveOnClosedSurface(C1,C2,S,L,GeomAbs_C0);
324     // test if there is already a range
325     if (rangeFound) {
326       COS->SetRange(f,l);
327     }
328     COS->SetUVPoints2(Pf,Pl);
329     lcr.Append(COS);
330   }
331 }
332
333
334 static void UpdateCurves(BRep_ListOfCurveRepresentation& lcr,
335                          const Handle(Geom_Surface)& S1,
336                          const Handle(Geom_Surface)& S2,
337                          const TopLoc_Location& L1,
338                          const TopLoc_Location& L2,
339                          const GeomAbs_Shape C)
340 {
341   BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
342   while (itcr.More()) {
343     const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
344     Standard_Boolean isregu = cr->IsRegularity(S1,S2,L1,L2);
345     if (isregu) break;
346     itcr.Next();
347   }
348   
349   if (itcr.More()) {
350     Handle(BRep_CurveRepresentation)& cr = itcr.Value();
351     cr->Continuity(C);
352   }
353   else {
354     Handle(BRep_CurveOn2Surfaces) COS = new BRep_CurveOn2Surfaces
355       (S1,S2,L1,L2,C);
356     lcr.Append(COS);
357   }
358 }
359
360 static void UpdatePoints(BRep_ListOfPointRepresentation& lpr,
361                          Standard_Real p,
362                          const Handle(Geom_Curve)& C,
363                          const TopLoc_Location& L)
364 {
365   BRep_ListIteratorOfListOfPointRepresentation itpr(lpr);
366   while (itpr.More()) {
367     const Handle(BRep_PointRepresentation)& pr = itpr.Value();
368     Standard_Boolean isponc = pr->IsPointOnCurve(C,L);
369     if (isponc) break;
370     itpr.Next();
371   }
372
373   if (itpr.More()) {
374     Handle(BRep_PointRepresentation)& pr = itpr.Value();
375     pr->Parameter(p);
376   }
377   else {
378     Handle(BRep_PointOnCurve) POC = new BRep_PointOnCurve(p,C,L);
379     lpr.Append(POC);
380   }
381 }
382
383 static void UpdatePoints(BRep_ListOfPointRepresentation& lpr,
384                          Standard_Real p,
385                          const Handle(Geom2d_Curve)& PC,
386                          const Handle(Geom_Surface)& S,
387                          const TopLoc_Location& L)
388 {
389   BRep_ListIteratorOfListOfPointRepresentation itpr(lpr);
390   while (itpr.More()) {
391     const Handle(BRep_PointRepresentation)& pr = itpr.Value();
392     Standard_Boolean isponcons = pr->IsPointOnCurveOnSurface(PC,S,L);
393     if (isponcons) break;
394     itpr.Next();
395   }
396
397   if (itpr.More()) {
398     Handle(BRep_PointRepresentation)& pr = itpr.Value();
399     pr->Parameter(p);
400   }
401   else {
402     Handle(BRep_PointOnCurveOnSurface) POCS = 
403       new BRep_PointOnCurveOnSurface(p,PC,S,L);
404     lpr.Append(POCS);
405   }
406 }
407
408
409 static void UpdatePoints(BRep_ListOfPointRepresentation& lpr,
410                          Standard_Real p1,
411                          Standard_Real p2,
412                          const Handle(Geom_Surface)& S,
413                          const TopLoc_Location& L)
414 {
415   BRep_ListIteratorOfListOfPointRepresentation itpr(lpr);
416   while (itpr.More()) {
417     const Handle(BRep_PointRepresentation)& pr = itpr.Value();
418     Standard_Boolean ispons = pr->IsPointOnSurface(S,L);
419     if (ispons) break;
420     itpr.Next();
421   }
422
423   if (itpr.More()) {
424     Handle(BRep_PointRepresentation)& pr = itpr.Value();
425     pr->Parameter(p1);
426 //    pr->Parameter(p2); // skv
427     pr->Parameter2(p2); // skv
428   }
429   else {
430     Handle(BRep_PointOnSurface) POS = new BRep_PointOnSurface(p1,p2,S,L);
431     lpr.Append(POS);
432   }
433 }
434
435
436 //=======================================================================
437 //function : MakeFace
438 //purpose  : 
439 //=======================================================================
440
441 void  BRep_Builder::MakeFace(TopoDS_Face& F,
442                              const Handle(Geom_Surface)& S,
443                              const Standard_Real Tol) const 
444 {
445   Handle(BRep_TFace) TF = new BRep_TFace();
446   if(!F.IsNull() && F.Locked())
447   {
448     TopoDS_LockedShape::Raise("BRep_Builder::MakeFace");
449   }
450   TF->Surface(S);
451   TF->Tolerance(Tol);
452   MakeShape(F,TF);
453 }
454
455
456 //=======================================================================
457 //function : MakeFace
458 //purpose  : 
459 //=======================================================================
460
461 void  BRep_Builder::MakeFace(TopoDS_Face&                      F,
462                              const Handle(Poly_Triangulation)& T) const
463 {
464   Handle(BRep_TFace) TF = new BRep_TFace();
465   if(!F.IsNull() && F.Locked())
466   {
467     TopoDS_LockedShape::Raise("BRep_Builder::MakeFace");
468   }
469   TF->Triangulation(T);
470   MakeShape(F, TF);
471 }
472
473
474 //=======================================================================
475 //function : MakeFace
476 //purpose  : 
477 //=======================================================================
478
479 void  BRep_Builder::MakeFace(TopoDS_Face& F,
480                              const Handle(Geom_Surface)& S,
481                              const TopLoc_Location& L,
482                              const Standard_Real Tol) const 
483 {
484   Handle(BRep_TFace) TF = new BRep_TFace();
485   if(!F.IsNull() && F.Locked())
486   {
487     TopoDS_LockedShape::Raise("BRep_Builder::MakeFace");
488   }
489   TF->Surface(S);
490   TF->Tolerance(Tol);
491   TF->Location(L);
492   MakeShape(F,TF);
493 }
494
495
496 //=======================================================================
497 //function : UpdateFace
498 //purpose  : 
499 //=======================================================================
500
501 void  BRep_Builder::UpdateFace(const TopoDS_Face& F,
502                                const Handle(Geom_Surface)& S,
503                                const TopLoc_Location& L,
504                                const Standard_Real Tol) const
505 {
506   const Handle(BRep_TFace)& TF = *((Handle(BRep_TFace)*) &F.TShape());
507   if(TF->Locked())
508   {
509     TopoDS_LockedShape::Raise("BRep_Builder::UpdateFace");
510   }
511   TF->Surface(S);
512   TF->Tolerance(Tol);
513   TF->Location(L.Predivided(F.Location()));
514   F.TShape()->Modified(Standard_True);
515 }
516
517
518 //=======================================================================
519 //function : UpdateFace
520 //purpose  : 
521 //=======================================================================
522
523 void  BRep_Builder::UpdateFace(const TopoDS_Face& F,
524                                const Handle(Poly_Triangulation)& T) const
525 {
526   const Handle(BRep_TFace)& TF = *((Handle(BRep_TFace)*) &F.TShape());
527   if(TF->Locked())
528   {
529     TopoDS_LockedShape::Raise("BRep_Builder::UpdateFace");
530   }
531   TF->Triangulation(T);
532   F.TShape()->Modified(Standard_True);
533 }
534
535
536 //=======================================================================
537 //function : UpdateFace
538 //purpose  : 
539 //=======================================================================
540
541 void  BRep_Builder::UpdateFace(const TopoDS_Face& F,
542                                const Standard_Real Tol) const 
543 {
544   const Handle(BRep_TFace)& TF = *((Handle(BRep_TFace)*) &F.TShape());
545   if(TF->Locked())
546   {
547     TopoDS_LockedShape::Raise("BRep_Builder::UpdateFace");
548   }
549   TF->Tolerance(Tol);
550   F.TShape()->Modified(Standard_True);
551 }
552
553
554 //=======================================================================
555 //function : NaturalRestriction
556 //purpose  : 
557 //=======================================================================
558
559 void  BRep_Builder::NaturalRestriction(const TopoDS_Face& F,
560                                        const Standard_Boolean N) const 
561 {
562   const Handle(BRep_TFace)& TF = (*((Handle(BRep_TFace)*) &F.TShape()));
563   if(TF->Locked())
564   {
565     TopoDS_LockedShape::Raise("BRep_Builder::NaturalRestriction");
566   }
567   TF->NaturalRestriction(N);
568   F.TShape()->Modified(Standard_True);
569 }
570
571
572 //=======================================================================
573 //function : MakeEdge
574 //purpose  : make undefined edge
575 //=======================================================================
576
577 void  BRep_Builder::MakeEdge(TopoDS_Edge& E) const
578 {
579   Handle(BRep_TEdge) TE = new BRep_TEdge();
580   if(!E.IsNull() && E.Locked())
581   {
582     TopoDS_LockedShape::Raise("BRep_Builder::MakeEdge");
583   }
584   MakeShape(E,TE);
585 }
586
587
588 //=======================================================================
589 //function : UpdateEdge
590 //purpose  : 
591 //=======================================================================
592
593 void  BRep_Builder::UpdateEdge(const TopoDS_Edge& E, 
594                                const Handle(Geom_Curve)& C, 
595                                const TopLoc_Location& L,
596                                const Standard_Real Tol) const
597 {
598   const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
599   if(TE->Locked())
600   {
601     TopoDS_LockedShape::Raise("BRep_Builder::UpdateEdge");
602   }
603   const TopLoc_Location l = L.Predivided(E.Location());
604
605   UpdateCurves(TE->ChangeCurves(),C,l);
606
607   TE->UpdateTolerance(Tol);
608   TE->Modified(Standard_True);
609 }
610
611
612 //=======================================================================
613 //function : UpdateEdge
614 //purpose  : 
615 //=======================================================================
616
617 void  BRep_Builder::UpdateEdge(const TopoDS_Edge& E, 
618                                const Handle(Geom2d_Curve)& C, 
619                                const Handle(Geom_Surface)& S, 
620                                const TopLoc_Location& L,
621                                const Standard_Real Tol) const
622 {
623   const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
624   if(TE->Locked())
625   {
626     TopoDS_LockedShape::Raise("BRep_Builder::UpdateEdge");
627   }
628   const TopLoc_Location l = L.Predivided(E.Location());
629
630   UpdateCurves(TE->ChangeCurves(),C,S,l);
631   
632   TE->UpdateTolerance(Tol);
633   TE->Modified(Standard_True);
634 }
635
636
637 //=======================================================================
638 //function : UpdateEdge
639 //purpose  : for the second format (for XML Persistence)
640 //=======================================================================
641
642 void  BRep_Builder::UpdateEdge(const TopoDS_Edge& E, 
643                                const Handle(Geom2d_Curve)& C, 
644                                const Handle(Geom_Surface)& S, 
645                                const TopLoc_Location& L,
646                                const Standard_Real Tol,
647                                const gp_Pnt2d& Pf,
648                                const gp_Pnt2d& Pl) const
649 {
650   const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
651   if(TE->Locked())
652   {
653     TopoDS_LockedShape::Raise("BRep_Builder::UpdateEdge");
654   }
655   const TopLoc_Location l = L.Predivided(E.Location());
656
657   UpdateCurves(TE->ChangeCurves(),C,S,l,Pf,Pl);
658   
659   TE->UpdateTolerance(Tol);
660   TE->Modified(Standard_True);
661 }
662
663
664 //=======================================================================
665 //function : UpdateEdge
666 //purpose  : 
667 //=======================================================================
668
669 void  BRep_Builder::UpdateEdge(const TopoDS_Edge& E, 
670                                const Handle(Geom2d_Curve)& C1, 
671                                const Handle(Geom2d_Curve)& C2, 
672                                const Handle(Geom_Surface)& S, 
673                                const TopLoc_Location& L, 
674                                const Standard_Real Tol) const
675 {
676   const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
677   if(TE->Locked())
678   {
679     TopoDS_LockedShape::Raise("BRep_Builder::UpdateEdge");
680   }
681   const TopLoc_Location l = L.Predivided(E.Location());
682
683   UpdateCurves(TE->ChangeCurves(),C1,C2,S,l);
684
685   TE->UpdateTolerance(Tol);
686   TE->Modified(Standard_True);
687 }
688
689
690 //=======================================================================
691 //function : UpdateEdge
692 //purpose  : for the second format (for XML Persistence)
693 //=======================================================================
694
695 void  BRep_Builder::UpdateEdge(const TopoDS_Edge& E, 
696                                const Handle(Geom2d_Curve)& C1, 
697                                const Handle(Geom2d_Curve)& C2, 
698                                const Handle(Geom_Surface)& S, 
699                                const TopLoc_Location& L, 
700                                const Standard_Real Tol,
701                                const gp_Pnt2d& Pf,
702                                const gp_Pnt2d& Pl) const
703 {
704   const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
705   if(TE->Locked())
706   {
707     TopoDS_LockedShape::Raise("BRep_Builder::UpdateEdge");
708   }
709   const TopLoc_Location l = L.Predivided(E.Location());
710
711   UpdateCurves(TE->ChangeCurves(),C1,C2,S,l,Pf,Pl);
712
713   TE->UpdateTolerance(Tol);
714   TE->Modified(Standard_True);
715 }
716
717
718 //=======================================================================
719 //function : UpdateEdge
720 //purpose  : 
721 //=======================================================================
722
723 void  BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
724                                const Handle(Poly_Polygon3D)& P,
725                                const TopLoc_Location& L) const
726 {
727   const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
728   if(TE->Locked())
729   {
730     TopoDS_LockedShape::Raise("BRep_Builder::UpdateEdge");
731   }
732   BRep_ListOfCurveRepresentation& lcr = TE->ChangeCurves();
733   BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
734
735   while (itcr.More())
736   {
737     if (itcr.Value()->IsPolygon3D())
738     {
739       if (P.IsNull())
740         lcr.Remove(itcr);
741       else
742         itcr.Value()->Polygon3D(P);
743       TE->Modified(Standard_True);
744       return;
745     }
746     itcr.Next();
747   }
748
749   const TopLoc_Location l = L.Predivided(E.Location());
750   Handle(BRep_Polygon3D) P3d = new BRep_Polygon3D(P,l);
751   lcr.Append(P3d);
752
753   TE->Modified(Standard_True);
754 }
755
756
757 //=======================================================================
758 //function : UpdateEdge
759 //purpose  : 
760 //=======================================================================
761
762 void  BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
763                                const Handle(Poly_PolygonOnTriangulation)& P,
764                                const Handle(Poly_Triangulation)& T,
765                                const TopLoc_Location& L) const
766 {
767   const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
768   if(TE->Locked())
769   {
770     TopoDS_LockedShape::Raise("BRep_Builder::UpdateEdge");
771   }
772   const TopLoc_Location l = L.Predivided(E.Location());
773
774   Standard_Boolean isModified = Standard_False;
775
776   BRep_ListOfCurveRepresentation& lcr = TE->ChangeCurves();
777   BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
778   Handle(BRep_CurveRepresentation) cr;
779
780   while (itcr.More())
781   {
782     if (itcr.Value()->IsPolygonOnTriangulation(T,l))
783     {
784       // cr is used to keep a reference on the curve representation
785       // this avoid deleting it as its content may be referenced by T
786       cr = itcr.Value();
787       lcr.Remove(itcr);
788       isModified = Standard_True;
789       break;
790     }
791     itcr.Next();
792   }
793
794   if (!P.IsNull())
795   {
796     Handle(BRep_PolygonOnTriangulation) PT =
797       new BRep_PolygonOnTriangulation(P,T,l);
798     lcr.Append(PT);
799     isModified = Standard_True;
800   }
801   
802   if (isModified)
803     TE->Modified(Standard_True);
804 }
805
806
807 //=======================================================================
808 //function : UpdateEdge
809 //purpose  : 
810 //=======================================================================
811
812 void  BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
813                                const Handle(Poly_PolygonOnTriangulation)& P1,
814                                const Handle(Poly_PolygonOnTriangulation)& P2,
815                                const Handle(Poly_Triangulation)& T,
816                                const TopLoc_Location& L) const
817 {
818   const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
819   if(TE->Locked())
820   {
821     TopoDS_LockedShape::Raise("BRep_Builder::UpdateEdge");
822   }
823   const TopLoc_Location l = L.Predivided(E.Location());
824
825   Standard_Boolean isModified = Standard_False;
826
827   BRep_ListOfCurveRepresentation& lcr = TE->ChangeCurves();
828   BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
829   Handle(BRep_CurveRepresentation) cr;
830
831   while (itcr.More())
832   {
833     if (itcr.Value()->IsPolygonOnTriangulation(T,l)) //szv:was L
834     {
835       // cr is used to keep a reference on the curve representation
836       // this avoid deleting it as its content may be referenced by T
837       cr = itcr.Value();
838       lcr.Remove(itcr);
839       isModified = Standard_True;
840       break;
841     }
842     itcr.Next();
843   }
844
845   if (!P1.IsNull() && !P2.IsNull())
846   {
847     Handle(BRep_PolygonOnClosedTriangulation) PT =
848       new BRep_PolygonOnClosedTriangulation(P1,P2,T,l);
849     lcr.Append(PT);
850     isModified = Standard_True;
851   }
852
853   if (isModified)
854     TE->Modified(Standard_True);
855 }
856
857 //=======================================================================
858 //function : UpdateEdge
859 //purpose  : 
860 //=======================================================================
861
862 void  BRep_Builder::UpdateEdge(const TopoDS_Edge&            E,
863                                const Handle(Poly_Polygon2D)& P,
864                                const TopoDS_Face&            F) const
865 {
866   TopLoc_Location l;
867   const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,l);
868   UpdateEdge(E, P, S, l);
869 }
870
871 //=======================================================================
872 //function : UpdateEdge
873 //purpose  : 
874 //=======================================================================
875
876 void  BRep_Builder::UpdateEdge(const TopoDS_Edge&            E,
877                                const Handle(Poly_Polygon2D)& P,
878                                const Handle(Geom_Surface)&   S,
879                                const TopLoc_Location&        L) const
880 {
881   const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
882   if(TE->Locked())
883   {
884     TopoDS_LockedShape::Raise("BRep_Builder::UpdateEdge");
885   }
886   TopLoc_Location l = L.Predivided(E.Location());
887
888   BRep_ListOfCurveRepresentation& lcr = TE->ChangeCurves();
889   Handle(BRep_CurveRepresentation) cr;
890
891   BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
892   while (itcr.More()) {
893     if (itcr.Value()->IsPolygonOnSurface(S, l)) break;
894     itcr.Next();
895   }
896
897   if (itcr.More()) {
898     // cr is used to keep a reference on the curve representation
899     // this avoid deleting it as its content may be referenced by T
900     cr = itcr.Value();
901     lcr.Remove(itcr);
902   }
903
904   if (!P.IsNull()) {
905     Handle(BRep_PolygonOnSurface) PS =
906       new BRep_PolygonOnSurface(P, S, l);
907     lcr.Append(PS);
908   }
909
910   TE->Modified(Standard_True);
911 }
912
913 //=======================================================================
914 //function : UpdateEdge
915 //purpose  : 
916 //=======================================================================
917
918 void  BRep_Builder::UpdateEdge(const TopoDS_Edge&            E,
919                                const Handle(Poly_Polygon2D)& P1,
920                                const Handle(Poly_Polygon2D)& P2,
921                                const TopoDS_Face&            F) const
922 {
923   TopLoc_Location l;
924   const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,l);
925   UpdateEdge(E, P1, P2, S, l);
926 }
927
928 //=======================================================================
929 //function : UpdateEdge
930 //purpose  : 
931 //=======================================================================
932
933 void  BRep_Builder::UpdateEdge(const TopoDS_Edge&            E,
934                                const Handle(Poly_Polygon2D)& P1,
935                                const Handle(Poly_Polygon2D)& P2,
936                                const Handle(Geom_Surface)&   S,
937                                const TopLoc_Location&        L) const
938 {
939   const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
940   if(TE->Locked())
941   {
942     TopoDS_LockedShape::Raise("BRep_Builder::UpdateEdge");
943   }
944   TopLoc_Location l = L.Predivided(E.Location());
945   
946   BRep_ListOfCurveRepresentation& lcr = TE->ChangeCurves();
947   Handle(BRep_CurveRepresentation) cr;
948
949   BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
950   while (itcr.More()) {
951     if (itcr.Value()->IsPolygonOnSurface(S, l)) break;
952     itcr.Next();
953   }
954
955   if (itcr.More()) {
956     // cr is used to keep a reference on the curve representation
957     // this avoid deleting it as its content may be referenced by T
958     cr = itcr.Value();
959     lcr.Remove(itcr);
960   }
961
962   if (!P1.IsNull() && !P2.IsNull()) {
963     Handle(BRep_PolygonOnClosedSurface) PS =
964       new BRep_PolygonOnClosedSurface(P1, P2, S, TopLoc_Location());
965     lcr.Append(PS);
966   }
967   
968   TE->Modified(Standard_True);
969 }
970
971 //=======================================================================
972 //function : UpdateEdge
973 //purpose  : 
974 //=======================================================================
975
976 void  BRep_Builder::UpdateEdge(const TopoDS_Edge& E, 
977                                const Standard_Real Tol) const
978 {
979   const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
980   if(TE->Locked())
981   {
982     TopoDS_LockedShape::Raise("BRep_Builder::UpdateEdge");
983   }
984   TE->UpdateTolerance(Tol);
985   TE->Modified(Standard_True);
986 }
987
988
989 //=======================================================================
990 //function : Continuity
991 //purpose  : 
992 //=======================================================================
993
994 void  BRep_Builder::Continuity(const TopoDS_Edge& E, 
995                                const TopoDS_Face& F1, 
996                                const TopoDS_Face& F2, 
997                                const GeomAbs_Shape C) const 
998 {
999   TopLoc_Location l1,l2;
1000   const Handle(Geom_Surface)& S1 = BRep_Tool::Surface(F1,l1);
1001   const Handle(Geom_Surface)& S2 = BRep_Tool::Surface(F2,l2);
1002   Continuity(E,S1,S2,l1,l2,C);
1003 }
1004
1005 //=======================================================================
1006 //function : Continuity
1007 //purpose  : 
1008 //=======================================================================
1009
1010 void  BRep_Builder::Continuity(const TopoDS_Edge& E, 
1011                                const Handle(Geom_Surface)& S1,
1012                                const Handle(Geom_Surface)& S2, 
1013                                const TopLoc_Location& L1,
1014                                const TopLoc_Location& L2, 
1015                                const GeomAbs_Shape C)const 
1016 {
1017   const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
1018   if(TE->Locked())
1019   {
1020     TopoDS_LockedShape::Raise("BRep_Builder::Continuity");
1021   }
1022   const TopLoc_Location l1 = L1.Predivided(E.Location());
1023   const TopLoc_Location l2 = L2.Predivided(E.Location());
1024
1025   UpdateCurves(TE->ChangeCurves(),S1,S2,l1,l2,C);
1026   
1027   TE->Modified(Standard_True);
1028 }
1029
1030 //=======================================================================
1031 //function : SameParameter
1032 //purpose  : 
1033 //=======================================================================
1034
1035 void  BRep_Builder::SameParameter(const TopoDS_Edge& E, 
1036                                   const Standard_Boolean S) const 
1037 {
1038   const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
1039   if(TE->Locked())
1040   {
1041     TopoDS_LockedShape::Raise("BRep_Builder::SameParameter");
1042   }
1043   TE->SameParameter(S);
1044   TE->Modified(Standard_True);
1045 }
1046
1047 //=======================================================================
1048 //function : SameRange
1049 //purpose  : 
1050 //=======================================================================
1051
1052 void  BRep_Builder::SameRange(const TopoDS_Edge& E, 
1053                               const Standard_Boolean S) const 
1054 {
1055   const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
1056   if(TE->Locked())
1057   {
1058     TopoDS_LockedShape::Raise("BRep_Builder::SameRange");
1059   }
1060   TE->SameRange(S);
1061   TE->Modified(Standard_True);
1062 }
1063
1064 //=======================================================================
1065 //function : Degenerated
1066 //purpose  : 
1067 //=======================================================================
1068
1069 void  BRep_Builder::Degenerated(const TopoDS_Edge& E, 
1070                                 const Standard_Boolean D) const 
1071 {
1072   const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
1073   if(TE->Locked())
1074   {
1075     TopoDS_LockedShape::Raise("BRep_Builder::Degenerated");
1076   }
1077   TE->Degenerated(D);
1078   if (D) {
1079     // set a null 3d curve
1080     UpdateCurves(TE->ChangeCurves(),Handle(Geom_Curve)(),E.Location());
1081   }
1082   TE->Modified(Standard_True);
1083 }
1084
1085
1086 //=======================================================================
1087 //function : Range
1088 //purpose  : 
1089 //=======================================================================
1090
1091 void  BRep_Builder::Range(const TopoDS_Edge&  E, 
1092                           const Standard_Real First, 
1093                           const Standard_Real Last,
1094                           const Standard_Boolean Only3d) const
1095 {
1096   //  set the range to all the representations if Only3d=FALSE
1097   const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
1098   if(TE->Locked())
1099   {
1100     TopoDS_LockedShape::Raise("BRep_Builder::Range");
1101   }
1102   BRep_ListOfCurveRepresentation& lcr = TE->ChangeCurves();
1103   BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
1104   Handle(BRep_GCurve) GC;
1105   
1106   while (itcr.More()) {
1107     GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
1108     if (!GC.IsNull() && (!Only3d || GC->IsCurve3D()))
1109       GC->SetRange(First,Last);
1110     itcr.Next();
1111   }
1112   
1113   TE->Modified(Standard_True);
1114 }
1115
1116
1117 //=======================================================================
1118 //function : Range
1119 //purpose  : 
1120 //=======================================================================
1121
1122 void  BRep_Builder::Range(const TopoDS_Edge& E, 
1123                           const Handle(Geom_Surface)& S,
1124                           const TopLoc_Location& L,
1125                           const Standard_Real First, 
1126                           const Standard_Real Last) const
1127 {
1128   const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
1129   if(TE->Locked())
1130   {
1131     TopoDS_LockedShape::Raise("BRep_Builder::Range");
1132   }
1133   const TopLoc_Location l = L.Predivided(E.Location());
1134
1135   BRep_ListOfCurveRepresentation& lcr = TE->ChangeCurves();
1136   BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
1137   Handle(BRep_GCurve) GC;
1138
1139   while (itcr.More()) {
1140     GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
1141     if (!GC.IsNull() && GC->IsCurveOnSurface(S,l))
1142     {
1143       GC->SetRange(First,Last);
1144       break;
1145     }
1146     itcr.Next();
1147   }
1148   
1149   if (!itcr.More())
1150     Standard_DomainError::Raise("BRep_Builder::Range, no pcurve");
1151   
1152   TE->Modified(Standard_True);
1153 }
1154
1155
1156 //=======================================================================
1157 //function : Transfert
1158 //purpose  : 
1159 //=======================================================================
1160
1161 void  BRep_Builder::Transfert(const TopoDS_Edge& Ein, 
1162                               const TopoDS_Edge& Eout) const
1163 {
1164   const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &Ein.TShape());
1165   if(TE->Locked())
1166   {
1167     TopoDS_LockedShape::Raise("BRep_Builder::Transfert");
1168   }
1169   const Standard_Real tol = TE->Tolerance();
1170
1171   BRep_ListOfCurveRepresentation& lcr = TE->ChangeCurves();
1172   BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
1173   
1174   while (itcr.More()) {
1175     
1176     const Handle(BRep_CurveRepresentation)& CR = itcr.Value();
1177     
1178     if (CR->IsCurveOnSurface()) {
1179       UpdateEdge(Eout,
1180                  CR->PCurve(),
1181                  CR->Surface(),
1182                  Ein.Location() * CR->Location(),tol);
1183     }
1184
1185     else if (CR->IsCurveOnClosedSurface()) {
1186       UpdateEdge(Eout,
1187                  CR->PCurve(),
1188                  CR->PCurve2(),
1189                  CR->Surface(),
1190                  Ein.Location() * CR->Location(),tol);
1191     }
1192     
1193     if (CR->IsRegularity()) {
1194       Continuity(Eout,
1195                  CR->Surface(),
1196                  CR->Surface2(),
1197                  Ein.Location() * CR->Location(),
1198                  Ein.Location() * CR->Location2(),
1199                  CR->Continuity());
1200     }
1201     
1202     itcr.Next();
1203   }
1204 }
1205
1206
1207 //=======================================================================
1208 //function : UpdateVertex
1209 //purpose  : update vertex with 3d point
1210 //=======================================================================
1211
1212 void  BRep_Builder::UpdateVertex(const TopoDS_Vertex& V, 
1213                                  const gp_Pnt& P, 
1214                                  const Standard_Real Tol) const 
1215 {
1216   const Handle(BRep_TVertex)& TV = *((Handle(BRep_TVertex)*) &V.TShape());
1217   if(TV->Locked())
1218   {
1219     TopoDS_LockedShape::Raise("BRep_Builder::UpdateVertex");
1220   }
1221   TV->Pnt(P.Transformed(V.Location().Inverted().Transformation()));
1222   TV->UpdateTolerance(Tol);
1223   TV->Modified(Standard_True);
1224 }
1225
1226
1227 //=======================================================================
1228 //function : UpdateVertex
1229 //purpose  : update vertex with parameter on edge
1230 //=======================================================================
1231
1232 void  BRep_Builder::UpdateVertex(const TopoDS_Vertex& V, 
1233                                  const Standard_Real Par, 
1234                                  const TopoDS_Edge& E,
1235                                  const Standard_Real Tol) const
1236 {
1237   if (Precision::IsPositiveInfinite(Par) ||
1238       Precision::IsNegativeInfinite(Par))
1239     Standard_DomainError::Raise("BRep_Builder::Infinite parameter");
1240   
1241   const Handle(BRep_TVertex)& TV = *((Handle(BRep_TVertex)*) &V.TShape());
1242   const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
1243
1244   if(TV->Locked() || TE->Locked())
1245   {
1246     TopoDS_LockedShape::Raise("BRep_Builder::UpdateVertex");
1247   }
1248
1249   TopLoc_Location L = E.Location().Predivided(V.Location());
1250
1251   // Search the vertex in the edge
1252   TopAbs_Orientation ori = TopAbs_INTERNAL;
1253
1254   TopoDS_Iterator itv(E.Oriented(TopAbs_FORWARD));
1255
1256   // if the edge has no vertices
1257   // and is degenerated use the vertex orientation
1258   // RLE, june 94
1259
1260   if (!itv.More() && TE->Degenerated())
1261     ori = V.Orientation();
1262
1263   while (itv.More()) {
1264     const TopoDS_Shape& Vcur = itv.Value();
1265     if (V.IsSame(Vcur)) {
1266       ori = Vcur.Orientation();
1267       if (ori == V.Orientation()) break;
1268     }
1269     itv.Next();
1270   }
1271
1272   BRep_ListOfCurveRepresentation& lcr = TE->ChangeCurves();
1273   BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
1274   Handle(BRep_GCurve) GC;
1275
1276   while (itcr.More()) {
1277     GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
1278     if (!GC.IsNull()) {
1279       if (ori == TopAbs_FORWARD) 
1280         GC->First(Par);
1281       else if (ori == TopAbs_REVERSED)
1282         GC->Last(Par);
1283       else {
1284         BRep_ListOfPointRepresentation& lpr = TV->ChangePoints();
1285         const TopLoc_Location& GCloc = GC->Location();
1286         TopLoc_Location LGCloc = L*GCloc; 
1287         if (GC->IsCurve3D()) {
1288           const Handle(Geom_Curve)& GC3d = GC->Curve3D();
1289           UpdatePoints(lpr,Par,GC3d,LGCloc);
1290         }
1291         else if (GC->IsCurveOnSurface()) {
1292           const Handle(Geom2d_Curve)& GCpc = GC->PCurve();
1293           const Handle(Geom_Surface)& GCsu = GC->Surface();
1294           UpdatePoints(lpr,Par,GCpc,GCsu,LGCloc);
1295         }
1296       }
1297     }
1298     itcr.Next();
1299   }
1300
1301   if ((ori != TopAbs_FORWARD) && (ori != TopAbs_REVERSED))
1302     TV->Modified(Standard_True);
1303   TV->UpdateTolerance(Tol);
1304   TE->Modified(Standard_True);
1305 }
1306
1307
1308 //=======================================================================
1309 //function : UpdateVertex
1310 //purpose  : update vertex with parameter on edge on face
1311 //=======================================================================
1312
1313 void  BRep_Builder::UpdateVertex(const TopoDS_Vertex& V,
1314                                  const Standard_Real  Par,
1315                                  const TopoDS_Edge&   E,
1316                                  const Handle(Geom_Surface)& S,
1317                                  const TopLoc_Location& L,
1318                                  const Standard_Real  Tol) const
1319 {
1320   if (Precision::IsPositiveInfinite(Par) ||
1321       Precision::IsNegativeInfinite(Par))
1322     Standard_DomainError::Raise("BRep_Builder::Infinite parameter");
1323   
1324   // Find the curve representation
1325   TopLoc_Location l = L.Predivided(V.Location());
1326   
1327   const Handle(BRep_TVertex)& TV = *((Handle(BRep_TVertex)*) &V.TShape());
1328   const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
1329   
1330   if(TV->Locked() || TE->Locked())
1331   {
1332     TopoDS_LockedShape::Raise("BRep_Builder::UpdateVertex");
1333   }
1334   
1335   // Search the vertex in the edge
1336   TopAbs_Orientation ori = TopAbs_INTERNAL;
1337   
1338   TopoDS_Iterator itv(E.Oriented(TopAbs_FORWARD));
1339
1340   // if the edge has no vertices
1341   // and is degenerated use the vertex orientation
1342   // RLE, june 94
1343
1344   if (!itv.More() && TE->Degenerated())
1345     ori = V.Orientation();
1346
1347   while (itv.More()) {
1348     const TopoDS_Shape& Vcur = itv.Value();
1349     if (V.IsSame(Vcur)) {
1350       ori = Vcur.Orientation();
1351       if (ori == V.Orientation()) break;
1352     }
1353     itv.Next();
1354   }
1355
1356   BRep_ListOfCurveRepresentation& lcr = TE->ChangeCurves();
1357   BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
1358   Handle(BRep_GCurve) GC;
1359
1360   while (itcr.More()) {
1361     GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
1362     if (!GC.IsNull()) {
1363 //      if (GC->IsCurveOnSurface(S,l)) {
1364       if (GC->IsCurveOnSurface(S,L)) { //xpu020198 : BUC60407
1365         if (ori == TopAbs_FORWARD) 
1366           GC->First(Par);
1367         else if (ori == TopAbs_REVERSED)
1368           GC->Last(Par);
1369         else {
1370           BRep_ListOfPointRepresentation& lpr = TV->ChangePoints();
1371           const Handle(Geom2d_Curve)& GCpc = GC->PCurve();
1372           UpdatePoints(lpr,Par,GCpc,S,l);
1373           TV->Modified(Standard_True);
1374         }
1375         break;
1376       }
1377     }
1378     itcr.Next();
1379   }
1380   
1381   if (!itcr.More())
1382     Standard_DomainError::Raise("BRep_Builder:: no pcurve");
1383   
1384   TV->UpdateTolerance(Tol);
1385   TE->Modified(Standard_True);
1386 }
1387
1388 //=======================================================================
1389 //function : UpdateVertex
1390 //purpose  : update vertex with parameters on face
1391 //=======================================================================
1392
1393 void  BRep_Builder::UpdateVertex(const TopoDS_Vertex& Ve, 
1394                                  const Standard_Real U, 
1395                                  const Standard_Real V,
1396                                  const TopoDS_Face& F, 
1397                                  const Standard_Real Tol) const
1398 {
1399   const Handle(BRep_TVertex)& TV = *((Handle(BRep_TVertex)*) &Ve.TShape());
1400   
1401   if(TV->Locked())
1402   {
1403     TopoDS_LockedShape::Raise("BRep_Builder::UpdateVertex");
1404   }
1405   
1406   TopLoc_Location L;
1407   const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,L);
1408   L = L.Predivided(Ve.Location());
1409   BRep_ListOfPointRepresentation& lpr = TV->ChangePoints(); 
1410   UpdatePoints(lpr,U,V,S,L);
1411   
1412   TV->UpdateTolerance(Tol);
1413   TV->Modified(Standard_True);
1414 }
1415
1416 //=======================================================================
1417 //function : UpdateVertex
1418 //purpose  : update vertex with 3d point
1419 //=======================================================================
1420
1421 void  BRep_Builder::UpdateVertex(const TopoDS_Vertex& V, 
1422                                  const Standard_Real Tol) const
1423 {
1424   const Handle(BRep_TVertex)& TV = *((Handle(BRep_TVertex)*) &V.TShape());
1425     
1426   if(TV->Locked())
1427   {
1428     TopoDS_LockedShape::Raise("BRep_Builder::UpdateVertex");
1429   }
1430   
1431   TV->UpdateTolerance(Tol);
1432   TV->Modified(Standard_True);
1433 }
1434
1435
1436 //=======================================================================
1437 //function : Transfert
1438 //purpose  : 
1439 //=======================================================================
1440
1441 void  BRep_Builder::Transfert(const TopoDS_Edge& Ein,
1442                               const TopoDS_Edge& Eout,
1443                               const TopoDS_Vertex& Vin,
1444                               const TopoDS_Vertex& Vout) const
1445 {
1446   const Standard_Real tol = BRep_Tool::Tolerance(Vin);
1447   const Standard_Real parin = BRep_Tool::Parameter(Vin,Ein);
1448   UpdateVertex(Vout,parin,Eout,tol);
1449 }