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 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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <BRep_Builder.hxx>
19 #include <BRep_Curve3D.hxx>
20 #include <BRep_CurveOn2Surfaces.hxx>
21 #include <BRep_CurveOnClosedSurface.hxx>
22 #include <BRep_GCurve.hxx>
23 #include <BRep_ListIteratorOfListOfPointRepresentation.hxx>
24 #include <BRep_PointOnCurve.hxx>
25 #include <BRep_PointOnCurveOnSurface.hxx>
26 #include <BRep_PointOnSurface.hxx>
27 #include <BRep_Polygon3D.hxx>
28 #include <BRep_PolygonOnClosedSurface.hxx>
29 #include <BRep_PolygonOnClosedTriangulation.hxx>
30 #include <BRep_PolygonOnSurface.hxx>
31 #include <BRep_PolygonOnTriangulation.hxx>
32 #include <BRep_TEdge.hxx>
33 #include <Geom2d_Curve.hxx>
34 #include <Geom_Curve.hxx>
35 #include <Geom_Surface.hxx>
37 #include <gp_Pnt2d.hxx>
38 #include <Poly_Polygon2D.hxx>
39 #include <Poly_Polygon3D.hxx>
40 #include <Poly_PolygonOnTriangulation.hxx>
41 #include <Poly_Triangulation.hxx>
42 #include <Precision.hxx>
43 #include <Standard_DomainError.hxx>
44 #include <TopLoc_Location.hxx>
45 #include <TopoDS_Edge.hxx>
46 #include <TopoDS_Face.hxx>
47 #include <TopoDS_Iterator.hxx>
48 #include <TopoDS_LockedShape.hxx>
49 #include <TopoDS_Vertex.hxx>
51 //=======================================================================
52 //function : Auxiliary methods
54 //=======================================================================
55 //=======================================================================
56 //function : UpdateCurves
57 //purpose : Insert a 3d curve <C> with location <L>
58 // in a list of curve representations <lcr>
59 //=======================================================================
60 static void UpdateCurves(BRep_ListOfCurveRepresentation& lcr,
61 const Handle(Geom_Curve)& C,
62 const TopLoc_Location& L)
64 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
65 Handle(BRep_GCurve) GC;
66 Standard_Real f = 0.,l = 0.;
69 GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
72 if (GC->IsCurve3D()) break;
79 itcr.Value()->Curve3D(C);
80 itcr.Value()->Location(L);
83 Handle(BRep_Curve3D) C3d = new BRep_Curve3D(C,L);
84 // test if there is already a range
93 //=======================================================================
94 //function : UpdateCurves
95 //purpose : Insert a pcurve <C> on surface <S> with location <L>
96 // in a list of curve representations <lcr>
97 // Remove the pcurve on <S> from <lcr> if <C> is null
98 //=======================================================================
100 static void UpdateCurves(BRep_ListOfCurveRepresentation& lcr,
101 const Handle(Geom2d_Curve)& C,
102 const Handle(Geom_Surface)& S,
103 const TopLoc_Location& L)
105 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
106 Handle(BRep_CurveRepresentation) cr;
107 Handle(BRep_GCurve) GC;
108 Standard_Real f = -Precision::Infinite(), l = Precision::Infinite();
109 // search the range of the 3d curve
110 // and remove any existing representation
112 while (itcr.More()) {
113 GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
115 if (GC->IsCurve3D()) {
116 // if (!C.IsNull()) { //xpu031198, edge degeneree
118 // xpu151298 : parameters can be set for null curves
119 // see lbo & flo, to determine whether range is defined
120 // compare first and last parameters with default values.
123 if (GC->IsCurveOnSurface(S,L)) {
124 // remove existing curve on surface
125 // cr is used to keep a reference on the curve representation
126 // this avoid deleting it as its content may be referenced by C or S
140 Handle(BRep_CurveOnSurface) COS = new BRep_CurveOnSurface(C, S, L);
141 Standard_Real aFCur = 0.0, aLCur = 0.0;
142 COS->Range(aFCur, aLCur);
143 if (!Precision::IsInfinite(f))
148 if (!Precision::IsInfinite(l))
153 COS->SetRange(aFCur, aLCur);
158 //=======================================================================
159 //function : UpdateCurves
160 //purpose : Insert a pcurve <C> on surface <S> with location <L>
161 // in a list of curve representations <lcr>
162 // Remove the pcurve on <S> from <lcr> if <C> is null
163 //=======================================================================
164 static void UpdateCurves(BRep_ListOfCurveRepresentation& lcr,
165 const Handle(Geom2d_Curve)& C,
166 const Handle(Geom_Surface)& S,
167 const TopLoc_Location& L,
171 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
172 Handle(BRep_CurveRepresentation) cr;
173 Handle(BRep_GCurve) GC;
174 Standard_Real f = -Precision::Infinite(), l = Precision::Infinite();
176 // search the range of the 3d curve
177 // and remove any existing representation
179 while (itcr.More()) {
180 GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
182 if (GC->IsCurve3D()) {
183 // if (!C.IsNull()) { //xpu031198, edge degeneree
185 // xpu151298 : parameters can be set for null curves
186 // see lbo & flo, to determine whether range is defined
187 // compare first and last parameters with default values.
190 if (GC->IsCurveOnSurface(S,L)) {
191 // remove existing curve on surface
192 // cr is used to keep a reference on the curve representation
193 // this avoid deleting it as its content may be referenced by C or S
207 Handle(BRep_CurveOnSurface) COS = new BRep_CurveOnSurface(C,S,L);
208 Standard_Real aFCur = 0.0, aLCur = 0.0;
209 COS->Range(aFCur, aLCur);
210 if (!Precision::IsInfinite(f))
215 if (!Precision::IsInfinite(l))
220 COS->SetRange(aFCur, aLCur);
221 COS->SetUVPoints(Pf, Pl);
226 //=======================================================================
227 //function : UpdateCurves
228 //purpose : Insert two pcurves <C1,C2> on surface <S> with location <L>
229 // in a list of curve representations <lcr>
230 // Remove the pcurves on <S> from <lcr> if <C1> or <C2> is null
231 //=======================================================================
233 static void UpdateCurves(BRep_ListOfCurveRepresentation& lcr,
234 const Handle(Geom2d_Curve)& C1,
235 const Handle(Geom2d_Curve)& C2,
236 const Handle(Geom_Surface)& S,
237 const TopLoc_Location& L)
239 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
240 Handle(BRep_CurveRepresentation) cr;
241 Handle(BRep_GCurve) GC;
242 Standard_Real f = -Precision::Infinite(), l = Precision::Infinite();
244 while (itcr.More()) {
245 GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
246 if ( !GC.IsNull() ) {
247 if (GC->IsCurve3D()) {
250 Standard_Boolean iscos = GC->IsCurveOnSurface(S,L);
257 // cr is used to keep a reference on the curve representation
258 // this avoid deleting it as its content may be referenced by C or S
263 if ( !C1.IsNull() && !C2.IsNull() ) {
264 Handle(BRep_CurveOnClosedSurface) COS = new
265 BRep_CurveOnClosedSurface(C1,C2,S,L,GeomAbs_C0);
266 Standard_Real aFCur = 0.0, aLCur = 0.0;
267 COS->Range(aFCur, aLCur);
268 if (!Precision::IsInfinite(f))
273 if (!Precision::IsInfinite(l))
278 COS->SetRange(aFCur, aLCur);
283 //=======================================================================
284 //function : UpdateCurves
285 //purpose : Insert two pcurves <C1,C2> on surface <S> with location <L>
286 // in a list of curve representations <lcr>
287 // Remove the pcurves on <S> from <lcr> if <C1> or <C2> is null
288 //=======================================================================
289 static void UpdateCurves(BRep_ListOfCurveRepresentation& lcr,
290 const Handle(Geom2d_Curve)& C1,
291 const Handle(Geom2d_Curve)& C2,
292 const Handle(Geom_Surface)& S,
293 const TopLoc_Location& L,
297 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
298 Handle(BRep_CurveRepresentation) cr;
299 Handle(BRep_GCurve) GC;
300 Standard_Real f = -Precision::Infinite(), l = Precision::Infinite();
302 while (itcr.More()) {
303 GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
304 if ( !GC.IsNull() ) {
305 if (GC->IsCurve3D()) {
308 Standard_Boolean iscos = GC->IsCurveOnSurface(S,L);
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
321 if ( !C1.IsNull() && !C2.IsNull() ) {
322 Handle(BRep_CurveOnClosedSurface) COS = new
323 BRep_CurveOnClosedSurface(C1,C2,S,L,GeomAbs_C0);
324 Standard_Real aFCur = 0.0, aLCur = 0.0;
325 COS->Range(aFCur, aLCur);
326 if (!Precision::IsInfinite(f))
331 if (!Precision::IsInfinite(l))
336 COS->SetRange(aFCur, aLCur);
337 COS->SetUVPoints2(Pf, Pl);
343 static void UpdateCurves(BRep_ListOfCurveRepresentation& lcr,
344 const Handle(Geom_Surface)& S1,
345 const Handle(Geom_Surface)& S2,
346 const TopLoc_Location& L1,
347 const TopLoc_Location& L2,
348 const GeomAbs_Shape C)
350 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
351 while (itcr.More()) {
352 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
353 Standard_Boolean isregu = cr->IsRegularity(S1,S2,L1,L2);
359 Handle(BRep_CurveRepresentation)& cr = itcr.Value();
363 Handle(BRep_CurveOn2Surfaces) COS = new BRep_CurveOn2Surfaces
369 static void UpdatePoints(BRep_ListOfPointRepresentation& lpr,
371 const Handle(Geom_Curve)& C,
372 const TopLoc_Location& L)
374 BRep_ListIteratorOfListOfPointRepresentation itpr(lpr);
375 while (itpr.More()) {
376 const Handle(BRep_PointRepresentation)& pr = itpr.Value();
377 Standard_Boolean isponc = pr->IsPointOnCurve(C,L);
383 Handle(BRep_PointRepresentation)& pr = itpr.Value();
387 Handle(BRep_PointOnCurve) POC = new BRep_PointOnCurve(p,C,L);
392 static void UpdatePoints(BRep_ListOfPointRepresentation& lpr,
394 const Handle(Geom2d_Curve)& PC,
395 const Handle(Geom_Surface)& S,
396 const TopLoc_Location& L)
398 BRep_ListIteratorOfListOfPointRepresentation itpr(lpr);
399 while (itpr.More()) {
400 const Handle(BRep_PointRepresentation)& pr = itpr.Value();
401 Standard_Boolean isponcons = pr->IsPointOnCurveOnSurface(PC,S,L);
402 if (isponcons) break;
407 Handle(BRep_PointRepresentation)& pr = itpr.Value();
411 Handle(BRep_PointOnCurveOnSurface) POCS =
412 new BRep_PointOnCurveOnSurface(p,PC,S,L);
418 static void UpdatePoints(BRep_ListOfPointRepresentation& lpr,
421 const Handle(Geom_Surface)& S,
422 const TopLoc_Location& L)
424 BRep_ListIteratorOfListOfPointRepresentation itpr(lpr);
425 while (itpr.More()) {
426 const Handle(BRep_PointRepresentation)& pr = itpr.Value();
427 Standard_Boolean ispons = pr->IsPointOnSurface(S,L);
433 Handle(BRep_PointRepresentation)& pr = itpr.Value();
435 // pr->Parameter(p2); // skv
436 pr->Parameter2(p2); // skv
439 Handle(BRep_PointOnSurface) POS = new BRep_PointOnSurface(p1,p2,S,L);
445 //=======================================================================
446 //function : MakeFace
448 //=======================================================================
450 void BRep_Builder::MakeFace(TopoDS_Face& F,
451 const Handle(Geom_Surface)& S,
452 const Standard_Real Tol) const
454 Handle(BRep_TFace) TF = new BRep_TFace();
455 if(!F.IsNull() && F.Locked())
457 throw TopoDS_LockedShape("BRep_Builder::MakeFace");
465 //=======================================================================
466 //function : MakeFace
468 //=======================================================================
469 void BRep_Builder::MakeFace(TopoDS_Face& theFace,
470 const Handle(Poly_Triangulation)& theTriangulation) const
472 Handle(BRep_TFace) aTFace = new BRep_TFace();
473 if(!theFace.IsNull() && theFace.Locked())
475 throw TopoDS_LockedShape("BRep_Builder::MakeFace");
477 aTFace->Triangulation (theTriangulation);
478 MakeShape (theFace, aTFace);
481 //=======================================================================
482 //function : MakeFace
484 //=======================================================================
485 void BRep_Builder::MakeFace (TopoDS_Face& theFace,
486 const Poly_ListOfTriangulation& theTriangulations,
487 const Handle(Poly_Triangulation)& theActiveTriangulation) const
489 Handle(BRep_TFace) aTFace = new BRep_TFace();
490 if(!theFace.IsNull() && theFace.Locked())
492 throw TopoDS_LockedShape ("BRep_Builder::MakeFace");
494 aTFace->Triangulations (theTriangulations, theActiveTriangulation);
495 MakeShape (theFace, aTFace);
498 //=======================================================================
499 //function : MakeFace
501 //=======================================================================
503 void BRep_Builder::MakeFace(TopoDS_Face& F,
504 const Handle(Geom_Surface)& S,
505 const TopLoc_Location& L,
506 const Standard_Real Tol) const
508 Handle(BRep_TFace) TF = new BRep_TFace();
509 if(!F.IsNull() && F.Locked())
511 throw TopoDS_LockedShape("BRep_Builder::MakeFace");
520 //=======================================================================
521 //function : UpdateFace
523 //=======================================================================
525 void BRep_Builder::UpdateFace(const TopoDS_Face& F,
526 const Handle(Geom_Surface)& S,
527 const TopLoc_Location& L,
528 const Standard_Real Tol) const
530 const Handle(BRep_TFace)& TF = *((Handle(BRep_TFace)*) &F.TShape());
533 throw TopoDS_LockedShape("BRep_Builder::UpdateFace");
537 TF->Location(L.Predivided(F.Location()));
538 F.TShape()->Modified(Standard_True);
542 //=======================================================================
543 //function : UpdateFace
545 //=======================================================================
546 void BRep_Builder::UpdateFace (const TopoDS_Face& theFace,
547 const Handle(Poly_Triangulation)& theTriangulation,
548 const Standard_Boolean theToReset) const
550 const Handle(BRep_TFace)& aTFace = *((Handle(BRep_TFace)*) &theFace.TShape());
553 throw TopoDS_LockedShape("BRep_Builder::UpdateFace");
555 aTFace->Triangulation (theTriangulation, theToReset);
556 theFace.TShape()->Modified (Standard_True);
559 //=======================================================================
560 //function : UpdateFace
562 //=======================================================================
564 void BRep_Builder::UpdateFace(const TopoDS_Face& F,
565 const Standard_Real Tol) const
567 const Handle(BRep_TFace)& TF = *((Handle(BRep_TFace)*) &F.TShape());
570 throw TopoDS_LockedShape("BRep_Builder::UpdateFace");
573 F.TShape()->Modified(Standard_True);
577 //=======================================================================
578 //function : NaturalRestriction
580 //=======================================================================
582 void BRep_Builder::NaturalRestriction(const TopoDS_Face& F,
583 const Standard_Boolean N) const
585 const Handle(BRep_TFace)& TF = (*((Handle(BRep_TFace)*) &F.TShape()));
588 throw TopoDS_LockedShape("BRep_Builder::NaturalRestriction");
590 TF->NaturalRestriction(N);
591 F.TShape()->Modified(Standard_True);
595 //=======================================================================
596 //function : MakeEdge
597 //purpose : make undefined edge
598 //=======================================================================
600 void BRep_Builder::MakeEdge(TopoDS_Edge& E) const
602 Handle(BRep_TEdge) TE = new BRep_TEdge();
603 if(!E.IsNull() && E.Locked())
605 throw TopoDS_LockedShape("BRep_Builder::MakeEdge");
611 //=======================================================================
612 //function : UpdateEdge
614 //=======================================================================
616 void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
617 const Handle(Geom_Curve)& C,
618 const TopLoc_Location& L,
619 const Standard_Real Tol) const
621 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
624 throw TopoDS_LockedShape("BRep_Builder::UpdateEdge");
626 const TopLoc_Location l = L.Predivided(E.Location());
628 UpdateCurves(TE->ChangeCurves(),C,l);
630 TE->UpdateTolerance(Tol);
631 TE->Modified(Standard_True);
635 //=======================================================================
636 //function : UpdateEdge
638 //=======================================================================
640 void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
641 const Handle(Geom2d_Curve)& C,
642 const Handle(Geom_Surface)& S,
643 const TopLoc_Location& L,
644 const Standard_Real Tol) const
646 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
649 throw TopoDS_LockedShape("BRep_Builder::UpdateEdge");
651 const TopLoc_Location l = L.Predivided(E.Location());
653 UpdateCurves(TE->ChangeCurves(),C,S,l);
655 TE->UpdateTolerance(Tol);
656 TE->Modified(Standard_True);
660 //=======================================================================
661 //function : UpdateEdge
662 //purpose : for the second format (for XML Persistence)
663 //=======================================================================
665 void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
666 const Handle(Geom2d_Curve)& C,
667 const Handle(Geom_Surface)& S,
668 const TopLoc_Location& L,
669 const Standard_Real Tol,
671 const gp_Pnt2d& Pl) const
673 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
676 throw TopoDS_LockedShape("BRep_Builder::UpdateEdge");
678 const TopLoc_Location l = L.Predivided(E.Location());
680 UpdateCurves(TE->ChangeCurves(),C,S,l,Pf,Pl);
682 TE->UpdateTolerance(Tol);
683 TE->Modified(Standard_True);
687 //=======================================================================
688 //function : UpdateEdge
690 //=======================================================================
692 void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
693 const Handle(Geom2d_Curve)& C1,
694 const Handle(Geom2d_Curve)& C2,
695 const Handle(Geom_Surface)& S,
696 const TopLoc_Location& L,
697 const Standard_Real Tol) const
699 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
702 throw TopoDS_LockedShape("BRep_Builder::UpdateEdge");
704 const TopLoc_Location l = L.Predivided(E.Location());
706 UpdateCurves(TE->ChangeCurves(),C1,C2,S,l);
708 TE->UpdateTolerance(Tol);
709 TE->Modified(Standard_True);
713 //=======================================================================
714 //function : UpdateEdge
715 //purpose : for the second format (for XML Persistence)
716 //=======================================================================
718 void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
719 const Handle(Geom2d_Curve)& C1,
720 const Handle(Geom2d_Curve)& C2,
721 const Handle(Geom_Surface)& S,
722 const TopLoc_Location& L,
723 const Standard_Real Tol,
725 const gp_Pnt2d& Pl) const
727 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
730 throw TopoDS_LockedShape("BRep_Builder::UpdateEdge");
732 const TopLoc_Location l = L.Predivided(E.Location());
734 UpdateCurves(TE->ChangeCurves(),C1,C2,S,l,Pf,Pl);
736 TE->UpdateTolerance(Tol);
737 TE->Modified(Standard_True);
741 //=======================================================================
742 //function : UpdateEdge
744 //=======================================================================
746 void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
747 const Handle(Poly_Polygon3D)& P,
748 const TopLoc_Location& L) const
750 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
753 throw TopoDS_LockedShape("BRep_Builder::UpdateEdge");
755 BRep_ListOfCurveRepresentation& lcr = TE->ChangeCurves();
756 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
760 if (itcr.Value()->IsPolygon3D())
765 itcr.Value()->Polygon3D(P);
766 TE->Modified(Standard_True);
772 const TopLoc_Location l = L.Predivided(E.Location());
773 Handle(BRep_Polygon3D) P3d = new BRep_Polygon3D(P,l);
776 TE->Modified(Standard_True);
780 //=======================================================================
781 //function : UpdateEdge
783 //=======================================================================
785 void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
786 const Handle(Poly_PolygonOnTriangulation)& P,
787 const Handle(Poly_Triangulation)& T,
788 const TopLoc_Location& L) const
790 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
793 throw TopoDS_LockedShape("BRep_Builder::UpdateEdge");
795 const TopLoc_Location l = L.Predivided(E.Location());
797 Standard_Boolean isModified = Standard_False;
799 BRep_ListOfCurveRepresentation& lcr = TE->ChangeCurves();
800 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
801 Handle(BRep_CurveRepresentation) cr;
805 if (itcr.Value()->IsPolygonOnTriangulation(T,l))
807 // cr is used to keep a reference on the curve representation
808 // this avoid deleting it as its content may be referenced by T
811 isModified = Standard_True;
819 Handle(BRep_PolygonOnTriangulation) PT =
820 new BRep_PolygonOnTriangulation(P,T,l);
822 isModified = Standard_True;
826 TE->Modified(Standard_True);
830 //=======================================================================
831 //function : UpdateEdge
833 //=======================================================================
835 void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
836 const Handle(Poly_PolygonOnTriangulation)& P1,
837 const Handle(Poly_PolygonOnTriangulation)& P2,
838 const Handle(Poly_Triangulation)& T,
839 const TopLoc_Location& L) const
841 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
844 throw TopoDS_LockedShape("BRep_Builder::UpdateEdge");
846 const TopLoc_Location l = L.Predivided(E.Location());
848 Standard_Boolean isModified = Standard_False;
850 BRep_ListOfCurveRepresentation& lcr = TE->ChangeCurves();
851 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
852 Handle(BRep_CurveRepresentation) cr;
856 if (itcr.Value()->IsPolygonOnTriangulation(T,l)) //szv:was L
858 // cr is used to keep a reference on the curve representation
859 // this avoid deleting it as its content may be referenced by T
862 isModified = Standard_True;
868 if (!P1.IsNull() && !P2.IsNull())
870 Handle(BRep_PolygonOnClosedTriangulation) PT =
871 new BRep_PolygonOnClosedTriangulation(P1,P2,T,l);
873 isModified = Standard_True;
877 TE->Modified(Standard_True);
880 //=======================================================================
881 //function : UpdateEdge
883 //=======================================================================
885 void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
886 const Handle(Poly_Polygon2D)& P,
887 const TopoDS_Face& F) const
890 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,l);
891 UpdateEdge(E, P, S, l);
894 //=======================================================================
895 //function : UpdateEdge
897 //=======================================================================
899 void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
900 const Handle(Poly_Polygon2D)& P,
901 const Handle(Geom_Surface)& S,
902 const TopLoc_Location& L) const
904 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
907 throw TopoDS_LockedShape("BRep_Builder::UpdateEdge");
909 TopLoc_Location l = L.Predivided(E.Location());
911 BRep_ListOfCurveRepresentation& lcr = TE->ChangeCurves();
912 Handle(BRep_CurveRepresentation) cr;
914 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
915 while (itcr.More()) {
916 if (itcr.Value()->IsPolygonOnSurface(S, l)) break;
921 // cr is used to keep a reference on the curve representation
922 // this avoid deleting it as its content may be referenced by T
928 Handle(BRep_PolygonOnSurface) PS =
929 new BRep_PolygonOnSurface(P, S, l);
933 TE->Modified(Standard_True);
936 //=======================================================================
937 //function : UpdateEdge
939 //=======================================================================
941 void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
942 const Handle(Poly_Polygon2D)& P1,
943 const Handle(Poly_Polygon2D)& P2,
944 const TopoDS_Face& F) const
947 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,l);
948 UpdateEdge(E, P1, P2, S, l);
951 //=======================================================================
952 //function : UpdateEdge
954 //=======================================================================
956 void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
957 const Handle(Poly_Polygon2D)& P1,
958 const Handle(Poly_Polygon2D)& P2,
959 const Handle(Geom_Surface)& S,
960 const TopLoc_Location& L) const
962 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
965 throw TopoDS_LockedShape("BRep_Builder::UpdateEdge");
967 TopLoc_Location l = L.Predivided(E.Location());
969 BRep_ListOfCurveRepresentation& lcr = TE->ChangeCurves();
970 Handle(BRep_CurveRepresentation) cr;
972 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
973 while (itcr.More()) {
974 if (itcr.Value()->IsPolygonOnSurface(S, l)) break;
979 // cr is used to keep a reference on the curve representation
980 // this avoid deleting it as its content may be referenced by T
985 if (!P1.IsNull() && !P2.IsNull()) {
986 Handle(BRep_PolygonOnClosedSurface) PS =
987 new BRep_PolygonOnClosedSurface(P1, P2, S, TopLoc_Location());
991 TE->Modified(Standard_True);
994 //=======================================================================
995 //function : UpdateEdge
997 //=======================================================================
999 void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
1000 const Standard_Real Tol) const
1002 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
1005 throw TopoDS_LockedShape("BRep_Builder::UpdateEdge");
1007 TE->UpdateTolerance(Tol);
1008 TE->Modified(Standard_True);
1012 //=======================================================================
1013 //function : Continuity
1015 //=======================================================================
1017 void BRep_Builder::Continuity(const TopoDS_Edge& E,
1018 const TopoDS_Face& F1,
1019 const TopoDS_Face& F2,
1020 const GeomAbs_Shape C) const
1022 TopLoc_Location l1,l2;
1023 const Handle(Geom_Surface)& S1 = BRep_Tool::Surface(F1,l1);
1024 const Handle(Geom_Surface)& S2 = BRep_Tool::Surface(F2,l2);
1025 Continuity(E,S1,S2,l1,l2,C);
1028 //=======================================================================
1029 //function : Continuity
1031 //=======================================================================
1033 void BRep_Builder::Continuity(const TopoDS_Edge& E,
1034 const Handle(Geom_Surface)& S1,
1035 const Handle(Geom_Surface)& S2,
1036 const TopLoc_Location& L1,
1037 const TopLoc_Location& L2,
1038 const GeomAbs_Shape C)const
1040 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
1043 throw TopoDS_LockedShape("BRep_Builder::Continuity");
1045 const TopLoc_Location l1 = L1.Predivided(E.Location());
1046 const TopLoc_Location l2 = L2.Predivided(E.Location());
1048 UpdateCurves(TE->ChangeCurves(),S1,S2,l1,l2,C);
1050 TE->Modified(Standard_True);
1053 //=======================================================================
1054 //function : SameParameter
1056 //=======================================================================
1058 void BRep_Builder::SameParameter(const TopoDS_Edge& E,
1059 const Standard_Boolean S) const
1061 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
1064 throw TopoDS_LockedShape("BRep_Builder::SameParameter");
1066 TE->SameParameter(S);
1067 TE->Modified(Standard_True);
1070 //=======================================================================
1071 //function : SameRange
1073 //=======================================================================
1075 void BRep_Builder::SameRange(const TopoDS_Edge& E,
1076 const Standard_Boolean S) const
1078 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
1081 throw TopoDS_LockedShape("BRep_Builder::SameRange");
1084 TE->Modified(Standard_True);
1087 //=======================================================================
1088 //function : Degenerated
1090 //=======================================================================
1092 void BRep_Builder::Degenerated(const TopoDS_Edge& E,
1093 const Standard_Boolean D) const
1095 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
1098 throw TopoDS_LockedShape("BRep_Builder::Degenerated");
1102 // set a null 3d curve
1103 UpdateCurves(TE->ChangeCurves(),Handle(Geom_Curve)(),E.Location());
1105 TE->Modified(Standard_True);
1109 //=======================================================================
1112 //=======================================================================
1114 void BRep_Builder::Range(const TopoDS_Edge& E,
1115 const Standard_Real First,
1116 const Standard_Real Last,
1117 const Standard_Boolean Only3d) const
1119 // set the range to all the representations if Only3d=FALSE
1120 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
1123 throw TopoDS_LockedShape("BRep_Builder::Range");
1125 BRep_ListOfCurveRepresentation& lcr = TE->ChangeCurves();
1126 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
1127 Handle(BRep_GCurve) GC;
1129 while (itcr.More()) {
1130 GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
1131 if (!GC.IsNull() && (!Only3d || GC->IsCurve3D()))
1132 GC->SetRange(First,Last);
1136 TE->Modified(Standard_True);
1140 //=======================================================================
1143 //=======================================================================
1145 void BRep_Builder::Range(const TopoDS_Edge& E,
1146 const Handle(Geom_Surface)& S,
1147 const TopLoc_Location& L,
1148 const Standard_Real First,
1149 const Standard_Real Last) const
1151 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
1154 throw TopoDS_LockedShape("BRep_Builder::Range");
1156 const TopLoc_Location l = L.Predivided(E.Location());
1158 BRep_ListOfCurveRepresentation& lcr = TE->ChangeCurves();
1159 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
1160 Handle(BRep_GCurve) GC;
1162 while (itcr.More()) {
1163 GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
1164 if (!GC.IsNull() && GC->IsCurveOnSurface(S,l))
1166 GC->SetRange(First,Last);
1173 throw Standard_DomainError("BRep_Builder::Range, no pcurve");
1175 TE->Modified(Standard_True);
1179 //=======================================================================
1180 //function : Transfert
1182 //=======================================================================
1184 void BRep_Builder::Transfert(const TopoDS_Edge& Ein,
1185 const TopoDS_Edge& Eout) const
1187 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &Ein.TShape());
1188 const Standard_Real tol = TE->Tolerance();
1190 const BRep_ListOfCurveRepresentation& lcr = TE->Curves();
1191 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
1193 while (itcr.More()) {
1195 const Handle(BRep_CurveRepresentation)& CR = itcr.Value();
1197 if (CR->IsCurveOnSurface()) {
1201 Ein.Location() * CR->Location(),tol);
1204 else if (CR->IsCurveOnClosedSurface()) {
1209 Ein.Location() * CR->Location(),tol);
1212 if (CR->IsRegularity()) {
1216 Ein.Location() * CR->Location(),
1217 Ein.Location() * CR->Location2(),
1226 //=======================================================================
1227 //function : UpdateVertex
1228 //purpose : update vertex with 3d point
1229 //=======================================================================
1231 void BRep_Builder::UpdateVertex(const TopoDS_Vertex& V,
1233 const Standard_Real Tol) const
1235 const Handle(BRep_TVertex)& TV = *((Handle(BRep_TVertex)*) &V.TShape());
1238 throw TopoDS_LockedShape("BRep_Builder::UpdateVertex");
1240 TV->Pnt(P.Transformed(V.Location().Inverted().Transformation()));
1241 TV->UpdateTolerance(Tol);
1242 TV->Modified(Standard_True);
1246 //=======================================================================
1247 //function : UpdateVertex
1248 //purpose : update vertex with parameter on edge
1249 //=======================================================================
1251 void BRep_Builder::UpdateVertex(const TopoDS_Vertex& V,
1252 const Standard_Real Par,
1253 const TopoDS_Edge& E,
1254 const Standard_Real Tol) const
1256 if (Precision::IsPositiveInfinite(Par) ||
1257 Precision::IsNegativeInfinite(Par))
1258 throw Standard_DomainError("BRep_Builder::Infinite parameter");
1260 const Handle(BRep_TVertex)& TV = *((Handle(BRep_TVertex)*) &V.TShape());
1261 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
1263 if(TV->Locked() || TE->Locked())
1265 throw TopoDS_LockedShape("BRep_Builder::UpdateVertex");
1268 TopLoc_Location L = E.Location().Predivided(V.Location());
1270 // Search the vertex in the edge
1271 TopAbs_Orientation ori = TopAbs_INTERNAL;
1273 TopoDS_Iterator itv(E.Oriented(TopAbs_FORWARD));
1275 // if the edge has no vertices
1276 // and is degenerated use the vertex orientation
1279 if (!itv.More() && TE->Degenerated())
1280 ori = V.Orientation();
1282 while (itv.More()) {
1283 const TopoDS_Shape& Vcur = itv.Value();
1284 if (V.IsSame(Vcur)) {
1285 ori = Vcur.Orientation();
1286 if (ori == V.Orientation()) break;
1291 BRep_ListOfCurveRepresentation& lcr = TE->ChangeCurves();
1292 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
1293 Handle(BRep_GCurve) GC;
1295 while (itcr.More()) {
1296 GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
1298 if (ori == TopAbs_FORWARD)
1300 else if (ori == TopAbs_REVERSED)
1303 BRep_ListOfPointRepresentation& lpr = TV->ChangePoints();
1304 const TopLoc_Location& GCloc = GC->Location();
1305 TopLoc_Location LGCloc = L*GCloc;
1306 if (GC->IsCurve3D()) {
1307 const Handle(Geom_Curve)& GC3d = GC->Curve3D();
1308 UpdatePoints(lpr,Par,GC3d,LGCloc);
1310 else if (GC->IsCurveOnSurface()) {
1311 const Handle(Geom2d_Curve)& GCpc = GC->PCurve();
1312 const Handle(Geom_Surface)& GCsu = GC->Surface();
1313 UpdatePoints(lpr,Par,GCpc,GCsu,LGCloc);
1320 if ((ori != TopAbs_FORWARD) && (ori != TopAbs_REVERSED))
1321 TV->Modified(Standard_True);
1322 TV->UpdateTolerance(Tol);
1323 TE->Modified(Standard_True);
1327 //=======================================================================
1328 //function : UpdateVertex
1329 //purpose : update vertex with parameter on edge on face
1330 //=======================================================================
1332 void BRep_Builder::UpdateVertex(const TopoDS_Vertex& V,
1333 const Standard_Real Par,
1334 const TopoDS_Edge& E,
1335 const Handle(Geom_Surface)& S,
1336 const TopLoc_Location& L,
1337 const Standard_Real Tol) const
1339 if (Precision::IsPositiveInfinite(Par) ||
1340 Precision::IsNegativeInfinite(Par))
1341 throw Standard_DomainError("BRep_Builder::Infinite parameter");
1343 // Find the curve representation
1344 TopLoc_Location l = L.Predivided(V.Location());
1346 const Handle(BRep_TVertex)& TV = *((Handle(BRep_TVertex)*) &V.TShape());
1347 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
1349 if(TV->Locked() || TE->Locked())
1351 throw TopoDS_LockedShape("BRep_Builder::UpdateVertex");
1354 // Search the vertex in the edge
1355 TopAbs_Orientation ori = TopAbs_INTERNAL;
1357 TopoDS_Iterator itv(E.Oriented(TopAbs_FORWARD));
1359 // if the edge has no vertices
1360 // and is degenerated use the vertex orientation
1363 if (!itv.More() && TE->Degenerated())
1364 ori = V.Orientation();
1366 while (itv.More()) {
1367 const TopoDS_Shape& Vcur = itv.Value();
1368 if (V.IsSame(Vcur)) {
1369 ori = Vcur.Orientation();
1370 if (ori == V.Orientation()) break;
1375 BRep_ListOfCurveRepresentation& lcr = TE->ChangeCurves();
1376 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
1377 Handle(BRep_GCurve) GC;
1379 while (itcr.More()) {
1380 GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
1382 // if (GC->IsCurveOnSurface(S,l)) {
1383 if (GC->IsCurveOnSurface(S,L)) { //xpu020198 : BUC60407
1384 if (ori == TopAbs_FORWARD)
1386 else if (ori == TopAbs_REVERSED)
1389 BRep_ListOfPointRepresentation& lpr = TV->ChangePoints();
1390 const Handle(Geom2d_Curve)& GCpc = GC->PCurve();
1391 UpdatePoints(lpr,Par,GCpc,S,l);
1392 TV->Modified(Standard_True);
1401 throw Standard_DomainError("BRep_Builder:: no pcurve");
1403 TV->UpdateTolerance(Tol);
1404 TE->Modified(Standard_True);
1407 //=======================================================================
1408 //function : UpdateVertex
1409 //purpose : update vertex with parameters on face
1410 //=======================================================================
1412 void BRep_Builder::UpdateVertex(const TopoDS_Vertex& Ve,
1413 const Standard_Real U,
1414 const Standard_Real V,
1415 const TopoDS_Face& F,
1416 const Standard_Real Tol) const
1418 const Handle(BRep_TVertex)& TV = *((Handle(BRep_TVertex)*) &Ve.TShape());
1422 throw TopoDS_LockedShape("BRep_Builder::UpdateVertex");
1426 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,L);
1427 L = L.Predivided(Ve.Location());
1428 BRep_ListOfPointRepresentation& lpr = TV->ChangePoints();
1429 UpdatePoints(lpr,U,V,S,L);
1431 TV->UpdateTolerance(Tol);
1432 TV->Modified(Standard_True);
1435 //=======================================================================
1436 //function : UpdateVertex
1437 //purpose : update vertex with 3d point
1438 //=======================================================================
1440 void BRep_Builder::UpdateVertex(const TopoDS_Vertex& V,
1441 const Standard_Real Tol) const
1443 const Handle(BRep_TVertex)& TV = *((Handle(BRep_TVertex)*) &V.TShape());
1447 throw TopoDS_LockedShape("BRep_Builder::UpdateVertex");
1450 TV->UpdateTolerance(Tol);
1451 TV->Modified(Standard_True);
1455 //=======================================================================
1456 //function : Transfert
1458 //=======================================================================
1460 void BRep_Builder::Transfert(const TopoDS_Edge& Ein,
1461 const TopoDS_Edge& Eout,
1462 const TopoDS_Vertex& Vin,
1463 const TopoDS_Vertex& Vout) const
1465 const Standard_Real tol = BRep_Tool::Tolerance(Vin);
1466 const Standard_Real parin = BRep_Tool::Parameter(Vin,Ein);
1467 UpdateVertex(Vout,parin,Eout,tol);