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_ListIteratorOfListOfCurveRepresentation.hxx>
24 #include <BRep_ListIteratorOfListOfPointRepresentation.hxx>
25 #include <BRep_PointOnCurve.hxx>
26 #include <BRep_PointOnCurveOnSurface.hxx>
27 #include <BRep_PointOnSurface.hxx>
28 #include <BRep_Polygon3D.hxx>
29 #include <BRep_PolygonOnClosedSurface.hxx>
30 #include <BRep_PolygonOnClosedTriangulation.hxx>
31 #include <BRep_PolygonOnSurface.hxx>
32 #include <BRep_PolygonOnTriangulation.hxx>
33 #include <BRep_TEdge.hxx>
34 #include <Geom2d_Curve.hxx>
35 #include <Geom_Curve.hxx>
36 #include <Geom_Surface.hxx>
38 #include <gp_Pnt2d.hxx>
39 #include <Poly_Polygon2D.hxx>
40 #include <Poly_Polygon3D.hxx>
41 #include <Poly_PolygonOnTriangulation.hxx>
42 #include <Poly_Triangulation.hxx>
43 #include <Precision.hxx>
44 #include <Standard_DomainError.hxx>
45 #include <Standard_NullObject.hxx>
46 #include <TopLoc_Location.hxx>
48 #include <TopoDS_Edge.hxx>
49 #include <TopoDS_Face.hxx>
50 #include <TopoDS_Iterator.hxx>
51 #include <TopoDS_LockedShape.hxx>
52 #include <TopoDS_Vertex.hxx>
54 //=======================================================================
55 //function : Auxiliary methods
57 //=======================================================================
58 //=======================================================================
59 //function : UpdateCurves
60 //purpose : Insert a 3d curve <C> with location <L>
61 // in a list of curve representations <lcr>
62 //=======================================================================
63 static void UpdateCurves(BRep_ListOfCurveRepresentation& lcr,
64 const Handle(Geom_Curve)& C,
65 const TopLoc_Location& L)
67 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
68 Handle(BRep_GCurve) GC;
69 Standard_Real f = 0.,l = 0.;
72 GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
75 if (GC->IsCurve3D()) break;
82 itcr.Value()->Curve3D(C);
83 itcr.Value()->Location(L);
86 Handle(BRep_Curve3D) C3d = new BRep_Curve3D(C,L);
87 // test if there is already a range
96 //=======================================================================
97 //function : UpdateCurves
98 //purpose : Insert a pcurve <C> on surface <S> with location <L>
99 // in a list of curve representations <lcr>
100 // Remove the pcurve on <S> from <lcr> if <C> is null
101 //=======================================================================
103 static void UpdateCurves(BRep_ListOfCurveRepresentation& lcr,
104 const Handle(Geom2d_Curve)& C,
105 const Handle(Geom_Surface)& S,
106 const TopLoc_Location& L)
108 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
109 Handle(BRep_CurveRepresentation) cr;
110 Handle(BRep_GCurve) GC;
111 Standard_Real f = -Precision::Infinite(), l = Precision::Infinite();
112 // search the range of the 3d curve
113 // and remove any existing representation
115 while (itcr.More()) {
116 GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
118 if (GC->IsCurve3D()) {
119 // if (!C.IsNull()) { //xpu031198, edge degeneree
121 // xpu151298 : parameters can be setted for null curves
122 // see lbo & flo, to determine whether range is defined
123 // compare first and last parameters with default values.
126 if (GC->IsCurveOnSurface(S,L)) {
127 // remove existing curve on surface
128 // cr is used to keep a reference on the curve representation
129 // this avoid deleting it as its content may be referenced by C or S
143 Handle(BRep_CurveOnSurface) COS = new BRep_CurveOnSurface(C, S, L);
144 Standard_Real aFCur = 0.0, aLCur = 0.0;
145 COS->Range(aFCur, aLCur);
146 if (!Precision::IsInfinite(f))
151 if (!Precision::IsInfinite(l))
156 COS->SetRange(aFCur, aLCur);
161 //=======================================================================
162 //function : UpdateCurves
163 //purpose : Insert a pcurve <C> on surface <S> with location <L>
164 // in a list of curve representations <lcr>
165 // Remove the pcurve on <S> from <lcr> if <C> is null
166 //=======================================================================
167 static void UpdateCurves(BRep_ListOfCurveRepresentation& lcr,
168 const Handle(Geom2d_Curve)& C,
169 const Handle(Geom_Surface)& S,
170 const TopLoc_Location& L,
174 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
175 Handle(BRep_CurveRepresentation) cr;
176 Handle(BRep_GCurve) GC;
177 Standard_Real f = -Precision::Infinite(), l = Precision::Infinite();
179 // search the range of the 3d curve
180 // and remove any existing representation
182 while (itcr.More()) {
183 GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
185 if (GC->IsCurve3D()) {
186 // if (!C.IsNull()) { //xpu031198, edge degeneree
188 // xpu151298 : parameters can be setted for null curves
189 // see lbo & flo, to determine whether range is defined
190 // compare first and last parameters with default values.
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 Standard_Real aFCur = 0.0, aLCur = 0.0;
212 COS->Range(aFCur, aLCur);
213 if (!Precision::IsInfinite(f))
218 if (!Precision::IsInfinite(l))
223 COS->SetRange(aFCur, aLCur);
224 COS->SetUVPoints(Pf, Pl);
229 //=======================================================================
230 //function : UpdateCurves
231 //purpose : Insert two pcurves <C1,C2> on surface <S> with location <L>
232 // in a list of curve representations <lcr>
233 // Remove the pcurves on <S> from <lcr> if <C1> or <C2> is null
234 //=======================================================================
236 static void UpdateCurves(BRep_ListOfCurveRepresentation& lcr,
237 const Handle(Geom2d_Curve)& C1,
238 const Handle(Geom2d_Curve)& C2,
239 const Handle(Geom_Surface)& S,
240 const TopLoc_Location& L)
242 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
243 Handle(BRep_CurveRepresentation) cr;
244 Handle(BRep_GCurve) GC;
245 Standard_Real f = -Precision::Infinite(), l = Precision::Infinite();
247 while (itcr.More()) {
248 GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
249 if ( !GC.IsNull() ) {
250 if (GC->IsCurve3D()) {
253 Standard_Boolean iscos = GC->IsCurveOnSurface(S,L);
260 // cr is used to keep a reference on the curve representation
261 // this avoid deleting it as its content may be referenced by C or S
266 if ( !C1.IsNull() && !C2.IsNull() ) {
267 Handle(BRep_CurveOnClosedSurface) COS = new
268 BRep_CurveOnClosedSurface(C1,C2,S,L,GeomAbs_C0);
269 Standard_Real aFCur = 0.0, aLCur = 0.0;
270 COS->Range(aFCur, aLCur);
271 if (!Precision::IsInfinite(f))
276 if (!Precision::IsInfinite(l))
281 COS->SetRange(aFCur, aLCur);
286 //=======================================================================
287 //function : UpdateCurves
288 //purpose : Insert two pcurves <C1,C2> on surface <S> with location <L>
289 // in a list of curve representations <lcr>
290 // Remove the pcurves on <S> from <lcr> if <C1> or <C2> is null
291 //=======================================================================
292 static void UpdateCurves(BRep_ListOfCurveRepresentation& lcr,
293 const Handle(Geom2d_Curve)& C1,
294 const Handle(Geom2d_Curve)& C2,
295 const Handle(Geom_Surface)& S,
296 const TopLoc_Location& L,
300 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
301 Handle(BRep_CurveRepresentation) cr;
302 Handle(BRep_GCurve) GC;
303 Standard_Real f = -Precision::Infinite(), l = Precision::Infinite();
305 while (itcr.More()) {
306 GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
307 if ( !GC.IsNull() ) {
308 if (GC->IsCurve3D()) {
311 Standard_Boolean iscos = GC->IsCurveOnSurface(S,L);
318 // cr is used to keep a reference on the curve representation
319 // this avoid deleting it as its content may be referenced by C or S
324 if ( !C1.IsNull() && !C2.IsNull() ) {
325 Handle(BRep_CurveOnClosedSurface) COS = new
326 BRep_CurveOnClosedSurface(C1,C2,S,L,GeomAbs_C0);
327 Standard_Real aFCur = 0.0, aLCur = 0.0;
328 COS->Range(aFCur, aLCur);
329 if (!Precision::IsInfinite(f))
334 if (!Precision::IsInfinite(l))
339 COS->SetRange(aFCur, aLCur);
340 COS->SetUVPoints2(Pf, Pl);
346 static void UpdateCurves(BRep_ListOfCurveRepresentation& lcr,
347 const Handle(Geom_Surface)& S1,
348 const Handle(Geom_Surface)& S2,
349 const TopLoc_Location& L1,
350 const TopLoc_Location& L2,
351 const GeomAbs_Shape C)
353 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
354 while (itcr.More()) {
355 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
356 Standard_Boolean isregu = cr->IsRegularity(S1,S2,L1,L2);
362 Handle(BRep_CurveRepresentation)& cr = itcr.Value();
366 Handle(BRep_CurveOn2Surfaces) COS = new BRep_CurveOn2Surfaces
372 static void UpdatePoints(BRep_ListOfPointRepresentation& lpr,
374 const Handle(Geom_Curve)& C,
375 const TopLoc_Location& L)
377 BRep_ListIteratorOfListOfPointRepresentation itpr(lpr);
378 while (itpr.More()) {
379 const Handle(BRep_PointRepresentation)& pr = itpr.Value();
380 Standard_Boolean isponc = pr->IsPointOnCurve(C,L);
386 Handle(BRep_PointRepresentation)& pr = itpr.Value();
390 Handle(BRep_PointOnCurve) POC = new BRep_PointOnCurve(p,C,L);
395 static void UpdatePoints(BRep_ListOfPointRepresentation& lpr,
397 const Handle(Geom2d_Curve)& PC,
398 const Handle(Geom_Surface)& S,
399 const TopLoc_Location& L)
401 BRep_ListIteratorOfListOfPointRepresentation itpr(lpr);
402 while (itpr.More()) {
403 const Handle(BRep_PointRepresentation)& pr = itpr.Value();
404 Standard_Boolean isponcons = pr->IsPointOnCurveOnSurface(PC,S,L);
405 if (isponcons) break;
410 Handle(BRep_PointRepresentation)& pr = itpr.Value();
414 Handle(BRep_PointOnCurveOnSurface) POCS =
415 new BRep_PointOnCurveOnSurface(p,PC,S,L);
421 static void UpdatePoints(BRep_ListOfPointRepresentation& lpr,
424 const Handle(Geom_Surface)& S,
425 const TopLoc_Location& L)
427 BRep_ListIteratorOfListOfPointRepresentation itpr(lpr);
428 while (itpr.More()) {
429 const Handle(BRep_PointRepresentation)& pr = itpr.Value();
430 Standard_Boolean ispons = pr->IsPointOnSurface(S,L);
436 Handle(BRep_PointRepresentation)& pr = itpr.Value();
438 // pr->Parameter(p2); // skv
439 pr->Parameter2(p2); // skv
442 Handle(BRep_PointOnSurface) POS = new BRep_PointOnSurface(p1,p2,S,L);
448 //=======================================================================
449 //function : MakeFace
451 //=======================================================================
453 void BRep_Builder::MakeFace(TopoDS_Face& F,
454 const Handle(Geom_Surface)& S,
455 const Standard_Real Tol) const
457 Handle(BRep_TFace) TF = new BRep_TFace();
458 if(!F.IsNull() && F.Locked())
460 throw TopoDS_LockedShape("BRep_Builder::MakeFace");
468 //=======================================================================
469 //function : MakeFace
471 //=======================================================================
473 void BRep_Builder::MakeFace(TopoDS_Face& F,
474 const Handle(Poly_Triangulation)& T) const
476 Handle(BRep_TFace) TF = new BRep_TFace();
477 if(!F.IsNull() && F.Locked())
479 throw TopoDS_LockedShape("BRep_Builder::MakeFace");
481 TF->Triangulation(T);
486 //=======================================================================
487 //function : MakeFace
489 //=======================================================================
491 void BRep_Builder::MakeFace(TopoDS_Face& F,
492 const Handle(Geom_Surface)& S,
493 const TopLoc_Location& L,
494 const Standard_Real Tol) const
496 Handle(BRep_TFace) TF = new BRep_TFace();
497 if(!F.IsNull() && F.Locked())
499 throw TopoDS_LockedShape("BRep_Builder::MakeFace");
508 //=======================================================================
509 //function : UpdateFace
511 //=======================================================================
513 void BRep_Builder::UpdateFace(const TopoDS_Face& F,
514 const Handle(Geom_Surface)& S,
515 const TopLoc_Location& L,
516 const Standard_Real Tol) const
518 const Handle(BRep_TFace)& TF = *((Handle(BRep_TFace)*) &F.TShape());
521 throw TopoDS_LockedShape("BRep_Builder::UpdateFace");
525 TF->Location(L.Predivided(F.Location()));
526 F.TShape()->Modified(Standard_True);
530 //=======================================================================
531 //function : UpdateFace
533 //=======================================================================
535 void BRep_Builder::UpdateFace(const TopoDS_Face& F,
536 const Handle(Poly_Triangulation)& T) const
538 const Handle(BRep_TFace)& TF = *((Handle(BRep_TFace)*) &F.TShape());
541 throw TopoDS_LockedShape("BRep_Builder::UpdateFace");
543 TF->Triangulation(T);
544 F.TShape()->Modified(Standard_True);
548 //=======================================================================
549 //function : UpdateFace
551 //=======================================================================
553 void BRep_Builder::UpdateFace(const TopoDS_Face& F,
554 const Standard_Real Tol) const
556 const Handle(BRep_TFace)& TF = *((Handle(BRep_TFace)*) &F.TShape());
559 throw TopoDS_LockedShape("BRep_Builder::UpdateFace");
562 F.TShape()->Modified(Standard_True);
566 //=======================================================================
567 //function : NaturalRestriction
569 //=======================================================================
571 void BRep_Builder::NaturalRestriction(const TopoDS_Face& F,
572 const Standard_Boolean N) const
574 const Handle(BRep_TFace)& TF = (*((Handle(BRep_TFace)*) &F.TShape()));
577 throw TopoDS_LockedShape("BRep_Builder::NaturalRestriction");
579 TF->NaturalRestriction(N);
580 F.TShape()->Modified(Standard_True);
584 //=======================================================================
585 //function : MakeEdge
586 //purpose : make undefined edge
587 //=======================================================================
589 void BRep_Builder::MakeEdge(TopoDS_Edge& E) const
591 Handle(BRep_TEdge) TE = new BRep_TEdge();
592 if(!E.IsNull() && E.Locked())
594 throw TopoDS_LockedShape("BRep_Builder::MakeEdge");
600 //=======================================================================
601 //function : UpdateEdge
603 //=======================================================================
605 void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
606 const Handle(Geom_Curve)& C,
607 const TopLoc_Location& L,
608 const Standard_Real Tol) const
610 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
613 throw TopoDS_LockedShape("BRep_Builder::UpdateEdge");
615 const TopLoc_Location l = L.Predivided(E.Location());
617 UpdateCurves(TE->ChangeCurves(),C,l);
619 TE->UpdateTolerance(Tol);
620 TE->Modified(Standard_True);
624 //=======================================================================
625 //function : UpdateEdge
627 //=======================================================================
629 void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
630 const Handle(Geom2d_Curve)& C,
631 const Handle(Geom_Surface)& S,
632 const TopLoc_Location& L,
633 const Standard_Real Tol) const
635 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
638 throw TopoDS_LockedShape("BRep_Builder::UpdateEdge");
640 const TopLoc_Location l = L.Predivided(E.Location());
642 UpdateCurves(TE->ChangeCurves(),C,S,l);
644 TE->UpdateTolerance(Tol);
645 TE->Modified(Standard_True);
649 //=======================================================================
650 //function : UpdateEdge
651 //purpose : for the second format (for XML Persistence)
652 //=======================================================================
654 void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
655 const Handle(Geom2d_Curve)& C,
656 const Handle(Geom_Surface)& S,
657 const TopLoc_Location& L,
658 const Standard_Real Tol,
660 const gp_Pnt2d& Pl) const
662 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
665 throw TopoDS_LockedShape("BRep_Builder::UpdateEdge");
667 const TopLoc_Location l = L.Predivided(E.Location());
669 UpdateCurves(TE->ChangeCurves(),C,S,l,Pf,Pl);
671 TE->UpdateTolerance(Tol);
672 TE->Modified(Standard_True);
676 //=======================================================================
677 //function : UpdateEdge
679 //=======================================================================
681 void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
682 const Handle(Geom2d_Curve)& C1,
683 const Handle(Geom2d_Curve)& C2,
684 const Handle(Geom_Surface)& S,
685 const TopLoc_Location& L,
686 const Standard_Real Tol) const
688 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
691 throw TopoDS_LockedShape("BRep_Builder::UpdateEdge");
693 const TopLoc_Location l = L.Predivided(E.Location());
695 UpdateCurves(TE->ChangeCurves(),C1,C2,S,l);
697 TE->UpdateTolerance(Tol);
698 TE->Modified(Standard_True);
702 //=======================================================================
703 //function : UpdateEdge
704 //purpose : for the second format (for XML Persistence)
705 //=======================================================================
707 void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
708 const Handle(Geom2d_Curve)& C1,
709 const Handle(Geom2d_Curve)& C2,
710 const Handle(Geom_Surface)& S,
711 const TopLoc_Location& L,
712 const Standard_Real Tol,
714 const gp_Pnt2d& Pl) const
716 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
719 throw TopoDS_LockedShape("BRep_Builder::UpdateEdge");
721 const TopLoc_Location l = L.Predivided(E.Location());
723 UpdateCurves(TE->ChangeCurves(),C1,C2,S,l,Pf,Pl);
725 TE->UpdateTolerance(Tol);
726 TE->Modified(Standard_True);
730 //=======================================================================
731 //function : UpdateEdge
733 //=======================================================================
735 void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
736 const Handle(Poly_Polygon3D)& P,
737 const TopLoc_Location& L) const
739 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
742 throw TopoDS_LockedShape("BRep_Builder::UpdateEdge");
744 BRep_ListOfCurveRepresentation& lcr = TE->ChangeCurves();
745 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
749 if (itcr.Value()->IsPolygon3D())
754 itcr.Value()->Polygon3D(P);
755 TE->Modified(Standard_True);
761 const TopLoc_Location l = L.Predivided(E.Location());
762 Handle(BRep_Polygon3D) P3d = new BRep_Polygon3D(P,l);
765 TE->Modified(Standard_True);
769 //=======================================================================
770 //function : UpdateEdge
772 //=======================================================================
774 void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
775 const Handle(Poly_PolygonOnTriangulation)& P,
776 const Handle(Poly_Triangulation)& T,
777 const TopLoc_Location& L) const
779 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
782 throw TopoDS_LockedShape("BRep_Builder::UpdateEdge");
784 const TopLoc_Location l = L.Predivided(E.Location());
786 Standard_Boolean isModified = Standard_False;
788 BRep_ListOfCurveRepresentation& lcr = TE->ChangeCurves();
789 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
790 Handle(BRep_CurveRepresentation) cr;
794 if (itcr.Value()->IsPolygonOnTriangulation(T,l))
796 // cr is used to keep a reference on the curve representation
797 // this avoid deleting it as its content may be referenced by T
800 isModified = Standard_True;
808 Handle(BRep_PolygonOnTriangulation) PT =
809 new BRep_PolygonOnTriangulation(P,T,l);
811 isModified = Standard_True;
815 TE->Modified(Standard_True);
819 //=======================================================================
820 //function : UpdateEdge
822 //=======================================================================
824 void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
825 const Handle(Poly_PolygonOnTriangulation)& P1,
826 const Handle(Poly_PolygonOnTriangulation)& P2,
827 const Handle(Poly_Triangulation)& T,
828 const TopLoc_Location& L) const
830 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
833 throw TopoDS_LockedShape("BRep_Builder::UpdateEdge");
835 const TopLoc_Location l = L.Predivided(E.Location());
837 Standard_Boolean isModified = Standard_False;
839 BRep_ListOfCurveRepresentation& lcr = TE->ChangeCurves();
840 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
841 Handle(BRep_CurveRepresentation) cr;
845 if (itcr.Value()->IsPolygonOnTriangulation(T,l)) //szv:was L
847 // cr is used to keep a reference on the curve representation
848 // this avoid deleting it as its content may be referenced by T
851 isModified = Standard_True;
857 if (!P1.IsNull() && !P2.IsNull())
859 Handle(BRep_PolygonOnClosedTriangulation) PT =
860 new BRep_PolygonOnClosedTriangulation(P1,P2,T,l);
862 isModified = Standard_True;
866 TE->Modified(Standard_True);
869 //=======================================================================
870 //function : UpdateEdge
872 //=======================================================================
874 void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
875 const Handle(Poly_Polygon2D)& P,
876 const TopoDS_Face& F) const
879 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,l);
880 UpdateEdge(E, P, S, l);
883 //=======================================================================
884 //function : UpdateEdge
886 //=======================================================================
888 void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
889 const Handle(Poly_Polygon2D)& P,
890 const Handle(Geom_Surface)& S,
891 const TopLoc_Location& L) const
893 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
896 throw TopoDS_LockedShape("BRep_Builder::UpdateEdge");
898 TopLoc_Location l = L.Predivided(E.Location());
900 BRep_ListOfCurveRepresentation& lcr = TE->ChangeCurves();
901 Handle(BRep_CurveRepresentation) cr;
903 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
904 while (itcr.More()) {
905 if (itcr.Value()->IsPolygonOnSurface(S, l)) break;
910 // cr is used to keep a reference on the curve representation
911 // this avoid deleting it as its content may be referenced by T
917 Handle(BRep_PolygonOnSurface) PS =
918 new BRep_PolygonOnSurface(P, S, l);
922 TE->Modified(Standard_True);
925 //=======================================================================
926 //function : UpdateEdge
928 //=======================================================================
930 void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
931 const Handle(Poly_Polygon2D)& P1,
932 const Handle(Poly_Polygon2D)& P2,
933 const TopoDS_Face& F) const
936 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,l);
937 UpdateEdge(E, P1, P2, S, l);
940 //=======================================================================
941 //function : UpdateEdge
943 //=======================================================================
945 void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
946 const Handle(Poly_Polygon2D)& P1,
947 const Handle(Poly_Polygon2D)& P2,
948 const Handle(Geom_Surface)& S,
949 const TopLoc_Location& L) const
951 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
954 throw TopoDS_LockedShape("BRep_Builder::UpdateEdge");
956 TopLoc_Location l = L.Predivided(E.Location());
958 BRep_ListOfCurveRepresentation& lcr = TE->ChangeCurves();
959 Handle(BRep_CurveRepresentation) cr;
961 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
962 while (itcr.More()) {
963 if (itcr.Value()->IsPolygonOnSurface(S, l)) break;
968 // cr is used to keep a reference on the curve representation
969 // this avoid deleting it as its content may be referenced by T
974 if (!P1.IsNull() && !P2.IsNull()) {
975 Handle(BRep_PolygonOnClosedSurface) PS =
976 new BRep_PolygonOnClosedSurface(P1, P2, S, TopLoc_Location());
980 TE->Modified(Standard_True);
983 //=======================================================================
984 //function : UpdateEdge
986 //=======================================================================
988 void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
989 const Standard_Real Tol) const
991 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
994 throw TopoDS_LockedShape("BRep_Builder::UpdateEdge");
996 TE->UpdateTolerance(Tol);
997 TE->Modified(Standard_True);
1001 //=======================================================================
1002 //function : Continuity
1004 //=======================================================================
1006 void BRep_Builder::Continuity(const TopoDS_Edge& E,
1007 const TopoDS_Face& F1,
1008 const TopoDS_Face& F2,
1009 const GeomAbs_Shape C) const
1011 TopLoc_Location l1,l2;
1012 const Handle(Geom_Surface)& S1 = BRep_Tool::Surface(F1,l1);
1013 const Handle(Geom_Surface)& S2 = BRep_Tool::Surface(F2,l2);
1014 Continuity(E,S1,S2,l1,l2,C);
1017 //=======================================================================
1018 //function : Continuity
1020 //=======================================================================
1022 void BRep_Builder::Continuity(const TopoDS_Edge& E,
1023 const Handle(Geom_Surface)& S1,
1024 const Handle(Geom_Surface)& S2,
1025 const TopLoc_Location& L1,
1026 const TopLoc_Location& L2,
1027 const GeomAbs_Shape C)const
1029 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
1032 throw TopoDS_LockedShape("BRep_Builder::Continuity");
1034 const TopLoc_Location l1 = L1.Predivided(E.Location());
1035 const TopLoc_Location l2 = L2.Predivided(E.Location());
1037 UpdateCurves(TE->ChangeCurves(),S1,S2,l1,l2,C);
1039 TE->Modified(Standard_True);
1042 //=======================================================================
1043 //function : SameParameter
1045 //=======================================================================
1047 void BRep_Builder::SameParameter(const TopoDS_Edge& E,
1048 const Standard_Boolean S) const
1050 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
1053 throw TopoDS_LockedShape("BRep_Builder::SameParameter");
1055 TE->SameParameter(S);
1056 TE->Modified(Standard_True);
1059 //=======================================================================
1060 //function : SameRange
1062 //=======================================================================
1064 void BRep_Builder::SameRange(const TopoDS_Edge& E,
1065 const Standard_Boolean S) const
1067 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
1070 throw TopoDS_LockedShape("BRep_Builder::SameRange");
1073 TE->Modified(Standard_True);
1076 //=======================================================================
1077 //function : Degenerated
1079 //=======================================================================
1081 void BRep_Builder::Degenerated(const TopoDS_Edge& E,
1082 const Standard_Boolean D) const
1084 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
1087 throw TopoDS_LockedShape("BRep_Builder::Degenerated");
1091 // set a null 3d curve
1092 UpdateCurves(TE->ChangeCurves(),Handle(Geom_Curve)(),E.Location());
1094 TE->Modified(Standard_True);
1098 //=======================================================================
1101 //=======================================================================
1103 void BRep_Builder::Range(const TopoDS_Edge& E,
1104 const Standard_Real First,
1105 const Standard_Real Last,
1106 const Standard_Boolean Only3d) const
1108 // set the range to all the representations if Only3d=FALSE
1109 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
1112 throw TopoDS_LockedShape("BRep_Builder::Range");
1114 BRep_ListOfCurveRepresentation& lcr = TE->ChangeCurves();
1115 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
1116 Handle(BRep_GCurve) GC;
1118 while (itcr.More()) {
1119 GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
1120 if (!GC.IsNull() && (!Only3d || GC->IsCurve3D()))
1121 GC->SetRange(First,Last);
1125 TE->Modified(Standard_True);
1129 //=======================================================================
1132 //=======================================================================
1134 void BRep_Builder::Range(const TopoDS_Edge& E,
1135 const Handle(Geom_Surface)& S,
1136 const TopLoc_Location& L,
1137 const Standard_Real First,
1138 const Standard_Real Last) const
1140 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
1143 throw TopoDS_LockedShape("BRep_Builder::Range");
1145 const TopLoc_Location l = L.Predivided(E.Location());
1147 BRep_ListOfCurveRepresentation& lcr = TE->ChangeCurves();
1148 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
1149 Handle(BRep_GCurve) GC;
1151 while (itcr.More()) {
1152 GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
1153 if (!GC.IsNull() && GC->IsCurveOnSurface(S,l))
1155 GC->SetRange(First,Last);
1162 throw Standard_DomainError("BRep_Builder::Range, no pcurve");
1164 TE->Modified(Standard_True);
1168 //=======================================================================
1169 //function : Transfert
1171 //=======================================================================
1173 void BRep_Builder::Transfert(const TopoDS_Edge& Ein,
1174 const TopoDS_Edge& Eout) const
1176 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &Ein.TShape());
1179 throw TopoDS_LockedShape("BRep_Builder::Transfert");
1181 const Standard_Real tol = TE->Tolerance();
1183 BRep_ListOfCurveRepresentation& lcr = TE->ChangeCurves();
1184 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
1186 while (itcr.More()) {
1188 const Handle(BRep_CurveRepresentation)& CR = itcr.Value();
1190 if (CR->IsCurveOnSurface()) {
1194 Ein.Location() * CR->Location(),tol);
1197 else if (CR->IsCurveOnClosedSurface()) {
1202 Ein.Location() * CR->Location(),tol);
1205 if (CR->IsRegularity()) {
1209 Ein.Location() * CR->Location(),
1210 Ein.Location() * CR->Location2(),
1219 //=======================================================================
1220 //function : UpdateVertex
1221 //purpose : update vertex with 3d point
1222 //=======================================================================
1224 void BRep_Builder::UpdateVertex(const TopoDS_Vertex& V,
1226 const Standard_Real Tol) const
1228 const Handle(BRep_TVertex)& TV = *((Handle(BRep_TVertex)*) &V.TShape());
1231 throw TopoDS_LockedShape("BRep_Builder::UpdateVertex");
1233 TV->Pnt(P.Transformed(V.Location().Inverted().Transformation()));
1234 TV->UpdateTolerance(Tol);
1235 TV->Modified(Standard_True);
1239 //=======================================================================
1240 //function : UpdateVertex
1241 //purpose : update vertex with parameter on edge
1242 //=======================================================================
1244 void BRep_Builder::UpdateVertex(const TopoDS_Vertex& V,
1245 const Standard_Real Par,
1246 const TopoDS_Edge& E,
1247 const Standard_Real Tol) const
1249 if (Precision::IsPositiveInfinite(Par) ||
1250 Precision::IsNegativeInfinite(Par))
1251 throw Standard_DomainError("BRep_Builder::Infinite parameter");
1253 const Handle(BRep_TVertex)& TV = *((Handle(BRep_TVertex)*) &V.TShape());
1254 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
1256 if(TV->Locked() || TE->Locked())
1258 throw TopoDS_LockedShape("BRep_Builder::UpdateVertex");
1261 TopLoc_Location L = E.Location().Predivided(V.Location());
1263 // Search the vertex in the edge
1264 TopAbs_Orientation ori = TopAbs_INTERNAL;
1266 TopoDS_Iterator itv(E.Oriented(TopAbs_FORWARD));
1268 // if the edge has no vertices
1269 // and is degenerated use the vertex orientation
1272 if (!itv.More() && TE->Degenerated())
1273 ori = V.Orientation();
1275 while (itv.More()) {
1276 const TopoDS_Shape& Vcur = itv.Value();
1277 if (V.IsSame(Vcur)) {
1278 ori = Vcur.Orientation();
1279 if (ori == V.Orientation()) break;
1284 BRep_ListOfCurveRepresentation& lcr = TE->ChangeCurves();
1285 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
1286 Handle(BRep_GCurve) GC;
1288 while (itcr.More()) {
1289 GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
1291 if (ori == TopAbs_FORWARD)
1293 else if (ori == TopAbs_REVERSED)
1296 BRep_ListOfPointRepresentation& lpr = TV->ChangePoints();
1297 const TopLoc_Location& GCloc = GC->Location();
1298 TopLoc_Location LGCloc = L*GCloc;
1299 if (GC->IsCurve3D()) {
1300 const Handle(Geom_Curve)& GC3d = GC->Curve3D();
1301 UpdatePoints(lpr,Par,GC3d,LGCloc);
1303 else if (GC->IsCurveOnSurface()) {
1304 const Handle(Geom2d_Curve)& GCpc = GC->PCurve();
1305 const Handle(Geom_Surface)& GCsu = GC->Surface();
1306 UpdatePoints(lpr,Par,GCpc,GCsu,LGCloc);
1313 if ((ori != TopAbs_FORWARD) && (ori != TopAbs_REVERSED))
1314 TV->Modified(Standard_True);
1315 TV->UpdateTolerance(Tol);
1316 TE->Modified(Standard_True);
1320 //=======================================================================
1321 //function : UpdateVertex
1322 //purpose : update vertex with parameter on edge on face
1323 //=======================================================================
1325 void BRep_Builder::UpdateVertex(const TopoDS_Vertex& V,
1326 const Standard_Real Par,
1327 const TopoDS_Edge& E,
1328 const Handle(Geom_Surface)& S,
1329 const TopLoc_Location& L,
1330 const Standard_Real Tol) const
1332 if (Precision::IsPositiveInfinite(Par) ||
1333 Precision::IsNegativeInfinite(Par))
1334 throw Standard_DomainError("BRep_Builder::Infinite parameter");
1336 // Find the curve representation
1337 TopLoc_Location l = L.Predivided(V.Location());
1339 const Handle(BRep_TVertex)& TV = *((Handle(BRep_TVertex)*) &V.TShape());
1340 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
1342 if(TV->Locked() || TE->Locked())
1344 throw TopoDS_LockedShape("BRep_Builder::UpdateVertex");
1347 // Search the vertex in the edge
1348 TopAbs_Orientation ori = TopAbs_INTERNAL;
1350 TopoDS_Iterator itv(E.Oriented(TopAbs_FORWARD));
1352 // if the edge has no vertices
1353 // and is degenerated use the vertex orientation
1356 if (!itv.More() && TE->Degenerated())
1357 ori = V.Orientation();
1359 while (itv.More()) {
1360 const TopoDS_Shape& Vcur = itv.Value();
1361 if (V.IsSame(Vcur)) {
1362 ori = Vcur.Orientation();
1363 if (ori == V.Orientation()) break;
1368 BRep_ListOfCurveRepresentation& lcr = TE->ChangeCurves();
1369 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
1370 Handle(BRep_GCurve) GC;
1372 while (itcr.More()) {
1373 GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
1375 // if (GC->IsCurveOnSurface(S,l)) {
1376 if (GC->IsCurveOnSurface(S,L)) { //xpu020198 : BUC60407
1377 if (ori == TopAbs_FORWARD)
1379 else if (ori == TopAbs_REVERSED)
1382 BRep_ListOfPointRepresentation& lpr = TV->ChangePoints();
1383 const Handle(Geom2d_Curve)& GCpc = GC->PCurve();
1384 UpdatePoints(lpr,Par,GCpc,S,l);
1385 TV->Modified(Standard_True);
1394 throw Standard_DomainError("BRep_Builder:: no pcurve");
1396 TV->UpdateTolerance(Tol);
1397 TE->Modified(Standard_True);
1400 //=======================================================================
1401 //function : UpdateVertex
1402 //purpose : update vertex with parameters on face
1403 //=======================================================================
1405 void BRep_Builder::UpdateVertex(const TopoDS_Vertex& Ve,
1406 const Standard_Real U,
1407 const Standard_Real V,
1408 const TopoDS_Face& F,
1409 const Standard_Real Tol) const
1411 const Handle(BRep_TVertex)& TV = *((Handle(BRep_TVertex)*) &Ve.TShape());
1415 throw TopoDS_LockedShape("BRep_Builder::UpdateVertex");
1419 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,L);
1420 L = L.Predivided(Ve.Location());
1421 BRep_ListOfPointRepresentation& lpr = TV->ChangePoints();
1422 UpdatePoints(lpr,U,V,S,L);
1424 TV->UpdateTolerance(Tol);
1425 TV->Modified(Standard_True);
1428 //=======================================================================
1429 //function : UpdateVertex
1430 //purpose : update vertex with 3d point
1431 //=======================================================================
1433 void BRep_Builder::UpdateVertex(const TopoDS_Vertex& V,
1434 const Standard_Real Tol) const
1436 const Handle(BRep_TVertex)& TV = *((Handle(BRep_TVertex)*) &V.TShape());
1440 throw TopoDS_LockedShape("BRep_Builder::UpdateVertex");
1443 TV->UpdateTolerance(Tol);
1444 TV->Modified(Standard_True);
1448 //=======================================================================
1449 //function : Transfert
1451 //=======================================================================
1453 void BRep_Builder::Transfert(const TopoDS_Edge& Ein,
1454 const TopoDS_Edge& Eout,
1455 const TopoDS_Vertex& Vin,
1456 const TopoDS_Vertex& Vout) const
1458 const Standard_Real tol = BRep_Tool::Tolerance(Vin);
1459 const Standard_Real parin = BRep_Tool::Parameter(Vin,Ein);
1460 UpdateVertex(Vout,parin,Eout,tol);