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
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and / or modify it
9 // under the terms of the GNU Lesser General Public 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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <BRep_Builder.ixx>
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>
26 #include <BRep_PointOnCurve.hxx>
27 #include <BRep_PointOnCurveOnSurface.hxx>
28 #include <BRep_PointOnSurface.hxx>
29 #include <BRep_ListIteratorOfListOfPointRepresentation.hxx>
32 #include <TopoDS_Iterator.hxx>
34 #include <Precision.hxx>
36 #include <BRep_Polygon3D.hxx>
37 #include <BRep_PolygonOnSurface.hxx>
38 #include <BRep_PolygonOnClosedSurface.hxx>
39 #include <BRep_PolygonOnTriangulation.hxx>
40 #include <BRep_PolygonOnClosedTriangulation.hxx>
42 #include <Standard_NullObject.hxx>
44 //=======================================================================
45 //function : Auxiliary methods
47 //=======================================================================
49 //=======================================================================
50 //function : UpdateCurves
51 //purpose : Insert a 3d curve <C> with location <L>
52 // in a list of curve representations <lcr>
53 //=======================================================================
55 static void UpdateCurves(BRep_ListOfCurveRepresentation& lcr,
56 const Handle(Geom_Curve)& C,
57 const TopLoc_Location& L)
59 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
60 Handle(BRep_GCurve) GC;
61 Standard_Real f = 0.,l = 0.;
64 GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
67 if (GC->IsCurve3D()) break;
74 itcr.Value()->Curve3D(C);
75 itcr.Value()->Location(L);
78 Handle(BRep_Curve3D) C3d = new BRep_Curve3D(C,L);
79 // test if there is already a range
88 //=======================================================================
89 //function : UpdateCurves
90 //purpose : Insert a pcurve <C> on surface <S> with location <L>
91 // in a list of curve representations <lcr>
92 // Remove the pcurve on <S> from <lcr> if <C> is null
93 //=======================================================================
95 static void UpdateCurves(BRep_ListOfCurveRepresentation& lcr,
96 const Handle(Geom2d_Curve)& C,
97 const Handle(Geom_Surface)& S,
98 const TopLoc_Location& L)
100 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
101 Handle(BRep_CurveRepresentation) cr;
102 Handle(BRep_GCurve) GC;
103 Standard_Real f = 0.,l = 0.;
104 Standard_Boolean rangeFound = Standard_False;
106 // search the range of the 3d curve
107 // and remove any existing representation
109 while (itcr.More()) {
110 GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
112 if (GC->IsCurve3D()) {
113 // if (!C.IsNull()) { //xpu031198, edge degeneree
115 // xpu151298 : parameters can be setted for null curves
116 // see lbo & flo, to determine whether range is defined
117 // compare first and last parameters with default values.
119 //lvt 15/6/99: On enleve la comparaison de reels infinis.
120 Standard_Boolean undefined = (Precision::IsPositiveInfinite(l) ||
121 Precision::IsNegativeInfinite(f));
124 rangeFound = Standard_True;
127 if (GC->IsCurveOnSurface(S,L)) {
128 // remove existing curve on surface
129 // cr is used to keep a reference on the curve representation
130 // this avoid deleting it as its content may be referenced by C or S
144 Handle(BRep_CurveOnSurface) COS = new BRep_CurveOnSurface(C,S,L);
145 // test if there is already a range
153 //=======================================================================
154 //function : UpdateCurves
155 //purpose : Insert a pcurve <C> on surface <S> with location <L>
156 // in a list of curve representations <lcr>
157 // Remove the pcurve on <S> from <lcr> if <C> is null
158 //=======================================================================
159 static void UpdateCurves(BRep_ListOfCurveRepresentation& lcr,
160 const Handle(Geom2d_Curve)& C,
161 const Handle(Geom_Surface)& S,
162 const TopLoc_Location& L,
166 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
167 Handle(BRep_CurveRepresentation) cr;
168 Handle(BRep_GCurve) GC;
169 Standard_Real f = 0.,l = 0.;
170 Standard_Boolean rangeFound = Standard_False;
172 // search the range of the 3d curve
173 // and remove any existing representation
175 while (itcr.More()) {
176 GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
178 if (GC->IsCurve3D()) {
179 // if (!C.IsNull()) { //xpu031198, edge degeneree
181 // xpu151298 : parameters can be setted for null curves
182 // see lbo & flo, to determine whether range is defined
183 // compare first and last parameters with default values.
185 //lvt 15/6/99: On enleve la comparaison de reels infinis.
186 Standard_Boolean undefined = (Precision::IsPositiveInfinite(l) ||
187 Precision::IsNegativeInfinite(f));
190 rangeFound = Standard_True;
193 if (GC->IsCurveOnSurface(S,L)) {
194 // remove existing curve on surface
195 // cr is used to keep a reference on the curve representation
196 // this avoid deleting it as its content may be referenced by C or S
210 Handle(BRep_CurveOnSurface) COS = new BRep_CurveOnSurface(C,S,L);
211 // test if there is already a range
215 COS->SetUVPoints(Pf,Pl);
220 //=======================================================================
221 //function : UpdateCurves
222 //purpose : Insert two pcurves <C1,C2> on surface <S> with location <L>
223 // in a list of curve representations <lcr>
224 // Remove the pcurves on <S> from <lcr> if <C1> or <C2> is null
225 //=======================================================================
227 static void UpdateCurves(BRep_ListOfCurveRepresentation& lcr,
228 const Handle(Geom2d_Curve)& C1,
229 const Handle(Geom2d_Curve)& C2,
230 const Handle(Geom_Surface)& S,
231 const TopLoc_Location& L)
233 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
234 Handle(BRep_CurveRepresentation) cr;
235 Handle(BRep_GCurve) GC;
236 Standard_Real f = 0.,l = 0.;
238 while (itcr.More()) {
239 GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
240 if ( !GC.IsNull() ) {
242 Standard_Boolean iscos = GC->IsCurveOnSurface(S,L);
249 // cr is used to keep a reference on the curve representation
250 // this avoid deleting it as its content may be referenced by C or S
255 if ( !C1.IsNull() && !C2.IsNull() ) {
256 Handle(BRep_CurveOnClosedSurface) COS =
257 new BRep_CurveOnClosedSurface(C1,C2,S,L,GeomAbs_C0);
258 // test if there is already a range
266 //=======================================================================
267 //function : UpdateCurves
268 //purpose : Insert two pcurves <C1,C2> on surface <S> with location <L>
269 // in a list of curve representations <lcr>
270 // Remove the pcurves on <S> from <lcr> if <C1> or <C2> is null
271 //=======================================================================
272 static void UpdateCurves(BRep_ListOfCurveRepresentation& lcr,
273 const Handle(Geom2d_Curve)& C1,
274 const Handle(Geom2d_Curve)& C2,
275 const Handle(Geom_Surface)& S,
276 const TopLoc_Location& L,
280 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
281 Handle(BRep_CurveRepresentation) cr;
282 Handle(BRep_GCurve) GC;
283 Standard_Real f = 0.,l = 0.;
285 while (itcr.More()) {
286 GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
287 if ( !GC.IsNull() ) {
289 Standard_Boolean iscos = GC->IsCurveOnSurface(S,L);
296 // cr is used to keep a reference on the curve representation
297 // this avoid deleting it as its content may be referenced by C or S
302 if ( !C1.IsNull() && !C2.IsNull() ) {
303 Handle(BRep_CurveOnClosedSurface) COS =
304 new BRep_CurveOnClosedSurface(C1,C2,S,L,GeomAbs_C0);
305 // test if there is already a range
309 COS->SetUVPoints2(Pf,Pl);
315 static void UpdateCurves(BRep_ListOfCurveRepresentation& lcr,
316 const Handle(Geom_Surface)& S1,
317 const Handle(Geom_Surface)& S2,
318 const TopLoc_Location& L1,
319 const TopLoc_Location& L2,
320 const GeomAbs_Shape C)
322 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
323 while (itcr.More()) {
324 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
325 Standard_Boolean isregu = cr->IsRegularity(S1,S2,L1,L2);
331 Handle(BRep_CurveRepresentation)& cr = itcr.Value();
335 Handle(BRep_CurveOn2Surfaces) COS = new BRep_CurveOn2Surfaces
341 static void UpdatePoints(BRep_ListOfPointRepresentation& lpr,
343 const Handle(Geom_Curve)& C,
344 const TopLoc_Location& L)
346 BRep_ListIteratorOfListOfPointRepresentation itpr(lpr);
347 while (itpr.More()) {
348 const Handle(BRep_PointRepresentation)& pr = itpr.Value();
349 Standard_Boolean isponc = pr->IsPointOnCurve(C,L);
355 Handle(BRep_PointRepresentation)& pr = itpr.Value();
359 Handle(BRep_PointOnCurve) POC = new BRep_PointOnCurve(p,C,L);
364 static void UpdatePoints(BRep_ListOfPointRepresentation& lpr,
366 const Handle(Geom2d_Curve)& PC,
367 const Handle(Geom_Surface)& S,
368 const TopLoc_Location& L)
370 BRep_ListIteratorOfListOfPointRepresentation itpr(lpr);
371 while (itpr.More()) {
372 const Handle(BRep_PointRepresentation)& pr = itpr.Value();
373 Standard_Boolean isponcons = pr->IsPointOnCurveOnSurface(PC,S,L);
374 if (isponcons) break;
379 Handle(BRep_PointRepresentation)& pr = itpr.Value();
383 Handle(BRep_PointOnCurveOnSurface) POCS =
384 new BRep_PointOnCurveOnSurface(p,PC,S,L);
390 static void UpdatePoints(BRep_ListOfPointRepresentation& lpr,
393 const Handle(Geom_Surface)& S,
394 const TopLoc_Location& L)
396 BRep_ListIteratorOfListOfPointRepresentation itpr(lpr);
397 while (itpr.More()) {
398 const Handle(BRep_PointRepresentation)& pr = itpr.Value();
399 Standard_Boolean ispons = pr->IsPointOnSurface(S,L);
405 Handle(BRep_PointRepresentation)& pr = itpr.Value();
407 // pr->Parameter(p2); // skv
408 pr->Parameter2(p2); // skv
411 Handle(BRep_PointOnSurface) POS = new BRep_PointOnSurface(p1,p2,S,L);
417 //=======================================================================
418 //function : MakeFace
420 //=======================================================================
422 void BRep_Builder::MakeFace(TopoDS_Face& F,
423 const Handle(Geom_Surface)& S,
424 const Standard_Real Tol) const
426 Handle(BRep_TFace) TF = new BRep_TFace();
433 //=======================================================================
434 //function : MakeFace
436 //=======================================================================
438 void BRep_Builder::MakeFace(TopoDS_Face& F,
439 const Handle(Poly_Triangulation)& T) const
441 Handle(BRep_TFace) TF = new BRep_TFace();
442 TF->Triangulation(T);
447 //=======================================================================
448 //function : MakeFace
450 //=======================================================================
452 void BRep_Builder::MakeFace(TopoDS_Face& F,
453 const Handle(Geom_Surface)& S,
454 const TopLoc_Location& L,
455 const Standard_Real Tol) const
457 Handle(BRep_TFace) TF = new BRep_TFace();
465 //=======================================================================
466 //function : UpdateFace
468 //=======================================================================
470 void BRep_Builder::UpdateFace(const TopoDS_Face& F,
471 const Handle(Geom_Surface)& S,
472 const TopLoc_Location& L,
473 const Standard_Real Tol) const
475 const Handle(BRep_TFace)& TF = *((Handle(BRep_TFace)*) &F.TShape());
478 TF->Location(L.Predivided(F.Location()));
479 F.TShape()->Modified(Standard_True);
483 //=======================================================================
484 //function : UpdateFace
486 //=======================================================================
488 void BRep_Builder::UpdateFace(const TopoDS_Face& F,
489 const Handle(Poly_Triangulation)& T) const
491 (*((Handle(BRep_TFace)*) &F.TShape()))->Triangulation(T);
492 F.TShape()->Modified(Standard_True);
496 //=======================================================================
497 //function : UpdateFace
499 //=======================================================================
501 void BRep_Builder::UpdateFace(const TopoDS_Face& F,
502 const Standard_Real Tol) const
504 (*((Handle(BRep_TFace)*) &F.TShape()))->Tolerance(Tol);
505 F.TShape()->Modified(Standard_True);
509 //=======================================================================
510 //function : NaturalRestriction
512 //=======================================================================
514 void BRep_Builder::NaturalRestriction(const TopoDS_Face& F,
515 const Standard_Boolean N) const
517 (*((Handle(BRep_TFace)*) &F.TShape()))->NaturalRestriction(N);
518 F.TShape()->Modified(Standard_True);
522 //=======================================================================
523 //function : MakeEdge
524 //purpose : make undefined edge
525 //=======================================================================
527 void BRep_Builder::MakeEdge(TopoDS_Edge& E) const
529 Handle(BRep_TEdge) TE = new BRep_TEdge();
530 TE->Closed(Standard_False);
535 //=======================================================================
536 //function : UpdateEdge
538 //=======================================================================
540 void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
541 const Handle(Geom_Curve)& C,
542 const TopLoc_Location& L,
543 const Standard_Real Tol) const
545 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
546 const TopLoc_Location l = L.Predivided(E.Location());
548 UpdateCurves(TE->ChangeCurves(),C,l);
549 if (!C.IsNull()) TE->Closed(C->IsClosed());
551 TE->UpdateTolerance(Tol);
552 TE->Modified(Standard_True);
556 //=======================================================================
557 //function : UpdateEdge
559 //=======================================================================
561 void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
562 const Handle(Geom2d_Curve)& C,
563 const Handle(Geom_Surface)& S,
564 const TopLoc_Location& L,
565 const Standard_Real Tol) const
567 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
568 const TopLoc_Location l = L.Predivided(E.Location());
570 UpdateCurves(TE->ChangeCurves(),C,S,l);
572 TE->UpdateTolerance(Tol);
573 TE->Modified(Standard_True);
577 //=======================================================================
578 //function : UpdateEdge
579 //purpose : for the second format (for XML Persistence)
580 //=======================================================================
582 void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
583 const Handle(Geom2d_Curve)& C,
584 const Handle(Geom_Surface)& S,
585 const TopLoc_Location& L,
586 const Standard_Real Tol,
588 const gp_Pnt2d& Pl) const
590 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
591 const TopLoc_Location l = L.Predivided(E.Location());
593 UpdateCurves(TE->ChangeCurves(),C,S,l,Pf,Pl);
595 TE->UpdateTolerance(Tol);
596 TE->Modified(Standard_True);
600 //=======================================================================
601 //function : UpdateEdge
603 //=======================================================================
605 void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
606 const Handle(Geom2d_Curve)& C1,
607 const Handle(Geom2d_Curve)& C2,
608 const Handle(Geom_Surface)& S,
609 const TopLoc_Location& L,
610 const Standard_Real Tol) const
612 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
613 const TopLoc_Location l = L.Predivided(E.Location());
615 UpdateCurves(TE->ChangeCurves(),C1,C2,S,l);
616 if (!C1.IsNull() && !C2.IsNull())
617 TE->Closed(C1->IsClosed() && C2->IsClosed());
619 TE->UpdateTolerance(Tol);
620 TE->Modified(Standard_True);
624 //=======================================================================
625 //function : UpdateEdge
626 //purpose : for the second format (for XML Persistence)
627 //=======================================================================
629 void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
630 const Handle(Geom2d_Curve)& C1,
631 const Handle(Geom2d_Curve)& C2,
632 const Handle(Geom_Surface)& S,
633 const TopLoc_Location& L,
634 const Standard_Real Tol,
636 const gp_Pnt2d& Pl) const
638 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
639 const TopLoc_Location l = L.Predivided(E.Location());
641 UpdateCurves(TE->ChangeCurves(),C1,C2,S,l,Pf,Pl);
642 if (!C1.IsNull() && !C2.IsNull())
643 TE->Closed(C1->IsClosed() && C2->IsClosed());
645 TE->UpdateTolerance(Tol);
646 TE->Modified(Standard_True);
650 //=======================================================================
651 //function : UpdateEdge
653 //=======================================================================
655 void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
656 const Handle(Poly_Polygon3D)& P,
657 const TopLoc_Location& L) const
659 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
661 BRep_ListOfCurveRepresentation& lcr = TE->ChangeCurves();
662 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
666 if (itcr.Value()->IsPolygon3D())
671 itcr.Value()->Polygon3D(P);
672 TE->Modified(Standard_True);
678 const TopLoc_Location l = L.Predivided(E.Location());
679 Handle(BRep_Polygon3D) P3d = new BRep_Polygon3D(P,l);
682 TE->Modified(Standard_True);
686 //=======================================================================
687 //function : UpdateEdge
689 //=======================================================================
691 void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
692 const Handle(Poly_PolygonOnTriangulation)& P,
693 const Handle(Poly_Triangulation)& T,
694 const TopLoc_Location& L) const
696 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
697 const TopLoc_Location l = L.Predivided(E.Location());
699 Standard_Boolean isModified = Standard_False;
701 BRep_ListOfCurveRepresentation& lcr = TE->ChangeCurves();
702 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
703 Handle(BRep_CurveRepresentation) cr;
707 if (itcr.Value()->IsPolygonOnTriangulation(T,l))
709 // cr is used to keep a reference on the curve representation
710 // this avoid deleting it as its content may be referenced by T
713 isModified = Standard_True;
721 Handle(BRep_PolygonOnTriangulation) PT =
722 new BRep_PolygonOnTriangulation(P,T,l);
724 isModified = Standard_True;
728 TE->Modified(Standard_True);
732 //=======================================================================
733 //function : UpdateEdge
735 //=======================================================================
737 void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
738 const Handle(Poly_PolygonOnTriangulation)& P1,
739 const Handle(Poly_PolygonOnTriangulation)& P2,
740 const Handle(Poly_Triangulation)& T,
741 const TopLoc_Location& L) const
743 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
744 const TopLoc_Location l = L.Predivided(E.Location());
746 Standard_Boolean isModified = Standard_False;
748 BRep_ListOfCurveRepresentation& lcr = TE->ChangeCurves();
749 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
750 Handle(BRep_CurveRepresentation) cr;
754 if (itcr.Value()->IsPolygonOnTriangulation(T,l)) //szv:was L
756 // cr is used to keep a reference on the curve representation
757 // this avoid deleting it as its content may be referenced by T
760 isModified = Standard_True;
766 if (!P1.IsNull() && !P2.IsNull())
768 Handle(BRep_PolygonOnClosedTriangulation) PT =
769 new BRep_PolygonOnClosedTriangulation(P1,P2,T,l);
771 isModified = Standard_True;
775 TE->Modified(Standard_True);
778 //=======================================================================
779 //function : UpdateEdge
781 //=======================================================================
783 void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
784 const Handle(Poly_Polygon2D)& P,
785 const TopoDS_Face& F) const
788 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,l);
789 UpdateEdge(E, P, S, l);
792 //=======================================================================
793 //function : UpdateEdge
795 //=======================================================================
797 void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
798 const Handle(Poly_Polygon2D)& P,
799 const Handle(Geom_Surface)& S,
800 const TopLoc_Location& L) const
802 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
803 TopLoc_Location l = L.Predivided(E.Location());
805 BRep_ListOfCurveRepresentation& lcr = TE->ChangeCurves();
806 Handle(BRep_CurveRepresentation) cr;
808 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
809 while (itcr.More()) {
810 if (itcr.Value()->IsPolygonOnSurface(S, l)) break;
815 // cr is used to keep a reference on the curve representation
816 // this avoid deleting it as its content may be referenced by T
822 Handle(BRep_PolygonOnSurface) PS =
823 new BRep_PolygonOnSurface(P, S, l);
827 TE->Modified(Standard_True);
830 //=======================================================================
831 //function : UpdateEdge
833 //=======================================================================
835 void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
836 const Handle(Poly_Polygon2D)& P1,
837 const Handle(Poly_Polygon2D)& P2,
838 const TopoDS_Face& F) const
841 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,l);
842 UpdateEdge(E, P1, P2, S, l);
845 //=======================================================================
846 //function : UpdateEdge
848 //=======================================================================
850 void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
851 const Handle(Poly_Polygon2D)& P1,
852 const Handle(Poly_Polygon2D)& P2,
853 const Handle(Geom_Surface)& S,
854 const TopLoc_Location& L) const
856 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
857 TopLoc_Location l = L.Predivided(E.Location());
859 BRep_ListOfCurveRepresentation& lcr = TE->ChangeCurves();
860 Handle(BRep_CurveRepresentation) cr;
862 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
863 while (itcr.More()) {
864 if (itcr.Value()->IsPolygonOnSurface(S, l)) break;
869 // cr is used to keep a reference on the curve representation
870 // this avoid deleting it as its content may be referenced by T
875 if (!P1.IsNull() && !P2.IsNull()) {
876 Handle(BRep_PolygonOnClosedSurface) PS =
877 new BRep_PolygonOnClosedSurface(P1, P2, S, TopLoc_Location());
881 TE->Modified(Standard_True);
884 //=======================================================================
885 //function : UpdateEdge
887 //=======================================================================
889 void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
890 const Standard_Real Tol) const
892 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
893 TE->UpdateTolerance(Tol);
894 TE->Modified(Standard_True);
898 //=======================================================================
899 //function : Continuity
901 //=======================================================================
903 void BRep_Builder::Continuity(const TopoDS_Edge& E,
904 const TopoDS_Face& F1,
905 const TopoDS_Face& F2,
906 const GeomAbs_Shape C) const
908 TopLoc_Location l1,l2;
909 const Handle(Geom_Surface)& S1 = BRep_Tool::Surface(F1,l1);
910 const Handle(Geom_Surface)& S2 = BRep_Tool::Surface(F2,l2);
911 Continuity(E,S1,S2,l1,l2,C);
914 //=======================================================================
915 //function : Continuity
917 //=======================================================================
919 void BRep_Builder::Continuity(const TopoDS_Edge& E,
920 const Handle(Geom_Surface)& S1,
921 const Handle(Geom_Surface)& S2,
922 const TopLoc_Location& L1,
923 const TopLoc_Location& L2,
924 const GeomAbs_Shape C)const
926 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
928 const TopLoc_Location l1 = L1.Predivided(E.Location());
929 const TopLoc_Location l2 = L2.Predivided(E.Location());
931 UpdateCurves(TE->ChangeCurves(),S1,S2,l1,l2,C);
933 TE->Modified(Standard_True);
936 //=======================================================================
937 //function : SameParameter
939 //=======================================================================
941 void BRep_Builder::SameParameter(const TopoDS_Edge& E,
942 const Standard_Boolean S) const
944 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
945 TE->SameParameter(S);
946 TE->Modified(Standard_True);
949 //=======================================================================
950 //function : SameRange
952 //=======================================================================
954 void BRep_Builder::SameRange(const TopoDS_Edge& E,
955 const Standard_Boolean S) const
957 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
959 TE->Modified(Standard_True);
962 //=======================================================================
963 //function : Degenerated
965 //=======================================================================
967 void BRep_Builder::Degenerated(const TopoDS_Edge& E,
968 const Standard_Boolean D) const
970 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
973 // set a null 3d curve
974 UpdateCurves(TE->ChangeCurves(),Handle(Geom_Curve)(),E.Location());
976 TE->Modified(Standard_True);
980 //=======================================================================
983 //=======================================================================
985 void BRep_Builder::Range(const TopoDS_Edge& E,
986 const Standard_Real First,
987 const Standard_Real Last,
988 const Standard_Boolean Only3d) const
990 // set the range to all the representations if Only3d=FALSE
991 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
993 BRep_ListOfCurveRepresentation& lcr = TE->ChangeCurves();
994 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
995 Handle(BRep_GCurve) GC;
997 while (itcr.More()) {
998 GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
1000 if (!Only3d || GC->IsCurve3D())
1001 GC->SetRange(First,Last);
1002 if (GC->IsCurve3D()) {
1003 // Set the closedness flag to the correct value.
1004 Handle(Geom_Curve) C = GC->Curve3D();
1006 //fixing a bug PRO18577 to avoid infinite values of First and Last
1008 !Precision::IsNegativeInfinite(First) &&
1009 !Precision::IsPositiveInfinite(Last) ) {
1010 Standard_Boolean closed =
1011 C->Value(First).IsEqual(C->Value(Last),BRep_Tool::Tolerance(E));
1019 TE->Modified(Standard_True);
1023 //=======================================================================
1026 //=======================================================================
1028 void BRep_Builder::Range(const TopoDS_Edge& E,
1029 const Handle(Geom_Surface)& S,
1030 const TopLoc_Location& L,
1031 const Standard_Real First,
1032 const Standard_Real Last) const
1034 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
1035 const TopLoc_Location l = L.Predivided(E.Location());
1037 BRep_ListOfCurveRepresentation& lcr = TE->ChangeCurves();
1038 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
1039 Handle(BRep_GCurve) GC;
1041 while (itcr.More()) {
1042 GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
1044 if (GC->IsCurveOnSurface(S,l)) {
1045 GC->SetRange(First,Last);
1047 // Set the closedness flag to the correct value.
1048 Handle(Geom2d_Curve) PC = GC->PCurve();
1049 gp_Pnt2d P1 = PC->Value(First);
1050 gp_Pnt2d P2 = PC->Value(Last);
1051 gp_Pnt PP1 = S->Value(P1.X(),P1.Y());
1052 gp_Pnt PP2 = S->Value(P2.X(),P2.Y());
1053 Standard_Boolean closed = PP1.IsEqual(PP2,BRep_Tool::Tolerance(E));
1062 Standard_DomainError::Raise("BRep_Builder::Range, no pcurve");
1064 TE->Modified(Standard_True);
1068 //=======================================================================
1069 //function : Transfert
1071 //=======================================================================
1073 void BRep_Builder::Transfert(const TopoDS_Edge& Ein,
1074 const TopoDS_Edge& Eout) const
1076 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &Ein.TShape());
1078 const Standard_Real tol = TE->Tolerance();
1080 BRep_ListOfCurveRepresentation& lcr = TE->ChangeCurves();
1081 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
1083 while (itcr.More()) {
1085 const Handle(BRep_CurveRepresentation)& CR = itcr.Value();
1087 if (CR->IsCurveOnSurface()) {
1091 Ein.Location() * CR->Location(),tol);
1094 else if (CR->IsCurveOnClosedSurface()) {
1099 Ein.Location() * CR->Location(),tol);
1102 if (CR->IsRegularity()) {
1106 Ein.Location() * CR->Location(),
1107 Ein.Location() * CR->Location2(),
1116 //=======================================================================
1117 //function : UpdateVertex
1118 //purpose : update vertex with 3d point
1119 //=======================================================================
1121 void BRep_Builder::UpdateVertex(const TopoDS_Vertex& V,
1123 const Standard_Real Tol) const
1125 const Handle(BRep_TVertex)& TV = *((Handle(BRep_TVertex)*) &V.TShape());
1127 TV->Pnt(P.Transformed(V.Location().Inverted().Transformation()));
1128 TV->UpdateTolerance(Tol);
1129 TV->Modified(Standard_True);
1133 //=======================================================================
1134 //function : UpdateVertex
1135 //purpose : update vertex with parameter on edge
1136 //=======================================================================
1138 void BRep_Builder::UpdateVertex(const TopoDS_Vertex& V,
1139 const Standard_Real Par,
1140 const TopoDS_Edge& E,
1141 const Standard_Real Tol) const
1143 if (Precision::IsPositiveInfinite(Par) ||
1144 Precision::IsNegativeInfinite(Par))
1145 Standard_DomainError::Raise("BRep_Builder::Infinite parameter");
1147 const Handle(BRep_TVertex)& TV = *((Handle(BRep_TVertex)*) &V.TShape());
1148 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
1150 TopLoc_Location L = E.Location().Predivided(V.Location());
1152 // Search the vertex in the edge
1153 TopAbs_Orientation ori = TopAbs_INTERNAL;
1155 TopoDS_Iterator itv(E.Oriented(TopAbs_FORWARD));
1157 // if the edge has no vertices
1158 // and is degenerated use the vertex orientation
1161 if (!itv.More() && TE->Degenerated())
1162 ori = V.Orientation();
1164 while (itv.More()) {
1165 const TopoDS_Shape& Vcur = itv.Value();
1166 if (V.IsSame(Vcur)) {
1167 ori = Vcur.Orientation();
1168 if (ori == V.Orientation()) break;
1173 BRep_ListOfCurveRepresentation& lcr = TE->ChangeCurves();
1174 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
1175 Handle(BRep_GCurve) GC;
1177 while (itcr.More()) {
1178 GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
1180 if (ori == TopAbs_FORWARD)
1182 else if (ori == TopAbs_REVERSED)
1185 BRep_ListOfPointRepresentation& lpr = TV->ChangePoints();
1186 const TopLoc_Location& GCloc = GC->Location();
1187 TopLoc_Location LGCloc = L*GCloc;
1188 if (GC->IsCurve3D()) {
1189 const Handle(Geom_Curve)& GC3d = GC->Curve3D();
1190 UpdatePoints(lpr,Par,GC3d,LGCloc);
1192 else if (GC->IsCurveOnSurface()) {
1193 const Handle(Geom2d_Curve)& GCpc = GC->PCurve();
1194 const Handle(Geom_Surface)& GCsu = GC->Surface();
1195 UpdatePoints(lpr,Par,GCpc,GCsu,LGCloc);
1202 if ((ori != TopAbs_FORWARD) && (ori != TopAbs_REVERSED))
1203 TV->Modified(Standard_True);
1204 TV->UpdateTolerance(Tol);
1205 TE->Modified(Standard_True);
1209 //=======================================================================
1210 //function : UpdateVertex
1211 //purpose : update vertex with parameter on edge on face
1212 //=======================================================================
1214 void BRep_Builder::UpdateVertex(const TopoDS_Vertex& V,
1215 const Standard_Real Par,
1216 const TopoDS_Edge& E,
1217 const Handle(Geom_Surface)& S,
1218 const TopLoc_Location& L,
1219 const Standard_Real Tol) const
1221 if (Precision::IsPositiveInfinite(Par) ||
1222 Precision::IsNegativeInfinite(Par))
1223 Standard_DomainError::Raise("BRep_Builder::Infinite parameter");
1225 // Find the curve representation
1226 TopLoc_Location l = L.Predivided(V.Location());
1228 const Handle(BRep_TVertex)& TV = *((Handle(BRep_TVertex)*) &V.TShape());
1229 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
1232 // Search the vertex in the edge
1233 TopAbs_Orientation ori = TopAbs_INTERNAL;
1235 TopoDS_Iterator itv(E.Oriented(TopAbs_FORWARD));
1237 // if the edge has no vertices
1238 // and is degenerated use the vertex orientation
1241 if (!itv.More() && TE->Degenerated())
1242 ori = V.Orientation();
1244 while (itv.More()) {
1245 const TopoDS_Shape& Vcur = itv.Value();
1246 if (V.IsSame(Vcur)) {
1247 ori = Vcur.Orientation();
1248 if (ori == V.Orientation()) break;
1253 BRep_ListOfCurveRepresentation& lcr = TE->ChangeCurves();
1254 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
1255 Handle(BRep_GCurve) GC;
1257 while (itcr.More()) {
1258 GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
1260 // if (GC->IsCurveOnSurface(S,l)) {
1261 if (GC->IsCurveOnSurface(S,L)) { //xpu020198 : BUC60407
1262 if (ori == TopAbs_FORWARD)
1264 else if (ori == TopAbs_REVERSED)
1267 BRep_ListOfPointRepresentation& lpr = TV->ChangePoints();
1268 const Handle(Geom2d_Curve)& GCpc = GC->PCurve();
1269 UpdatePoints(lpr,Par,GCpc,S,l);
1270 TV->Modified(Standard_True);
1279 Standard_DomainError::Raise("BRep_Builder:: no pcurve");
1281 TV->UpdateTolerance(Tol);
1282 TE->Modified(Standard_True);
1285 //=======================================================================
1286 //function : UpdateVertex
1287 //purpose : update vertex with parameters on face
1288 //=======================================================================
1290 void BRep_Builder::UpdateVertex(const TopoDS_Vertex& Ve,
1291 const Standard_Real U,
1292 const Standard_Real V,
1293 const TopoDS_Face& F,
1294 const Standard_Real Tol) const
1296 const Handle(BRep_TVertex)& TV = *((Handle(BRep_TVertex)*) &Ve.TShape());
1299 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,L);
1300 L = L.Predivided(Ve.Location());
1301 BRep_ListOfPointRepresentation& lpr = TV->ChangePoints();
1302 UpdatePoints(lpr,U,V,S,L);
1304 TV->UpdateTolerance(Tol);
1305 TV->Modified(Standard_True);
1308 //=======================================================================
1309 //function : UpdateVertex
1310 //purpose : update vertex with 3d point
1311 //=======================================================================
1313 void BRep_Builder::UpdateVertex(const TopoDS_Vertex& V,
1314 const Standard_Real Tol) const
1316 const Handle(BRep_TVertex)& TV = *((Handle(BRep_TVertex)*) &V.TShape());
1317 TV->UpdateTolerance(Tol);
1318 TV->Modified(Standard_True);
1322 //=======================================================================
1323 //function : Transfert
1325 //=======================================================================
1327 void BRep_Builder::Transfert(const TopoDS_Edge& Ein,
1328 const TopoDS_Edge& Eout,
1329 const TopoDS_Vertex& Vin,
1330 const TopoDS_Vertex& Vout) const
1332 const Standard_Real tol = BRep_Tool::Tolerance(Vin);
1333 const Standard_Real parin = BRep_Tool::Parameter(Vin,Ein);
1334 UpdateVertex(Vout,parin,Eout,tol);