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 = 0.,l = 0.;
112 Standard_Boolean rangeFound = Standard_False;
114 // search the range of the 3d curve
115 // and remove any existing representation
117 while (itcr.More()) {
118 GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
120 if (GC->IsCurve3D()) {
121 // if (!C.IsNull()) { //xpu031198, edge degeneree
123 // xpu151298 : parameters can be setted for null curves
124 // see lbo & flo, to determine whether range is defined
125 // compare first and last parameters with default values.
127 //lvt 15/6/99: On enleve la comparaison de reels infinis.
128 Standard_Boolean undefined = (Precision::IsPositiveInfinite(l) ||
129 Precision::IsNegativeInfinite(f));
132 rangeFound = Standard_True;
135 if (GC->IsCurveOnSurface(S,L)) {
136 // remove existing curve on surface
137 // cr is used to keep a reference on the curve representation
138 // this avoid deleting it as its content may be referenced by C or S
152 Handle(BRep_CurveOnSurface) COS = new BRep_CurveOnSurface(C,S,L);
153 // test if there is already a range
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 = 0.,l = 0.;
178 Standard_Boolean rangeFound = Standard_False;
180 // search the range of the 3d curve
181 // and remove any existing representation
183 while (itcr.More()) {
184 GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
186 if (GC->IsCurve3D()) {
187 // if (!C.IsNull()) { //xpu031198, edge degeneree
189 // xpu151298 : parameters can be setted for null curves
190 // see lbo & flo, to determine whether range is defined
191 // compare first and last parameters with default values.
193 //lvt 15/6/99: On enleve la comparaison de reels infinis.
194 Standard_Boolean undefined = (Precision::IsPositiveInfinite(l) ||
195 Precision::IsNegativeInfinite(f));
198 rangeFound = Standard_True;
201 if (GC->IsCurveOnSurface(S,L)) {
202 // remove existing curve on surface
203 // cr is used to keep a reference on the curve representation
204 // this avoid deleting it as its content may be referenced by C or S
218 Handle(BRep_CurveOnSurface) COS = new BRep_CurveOnSurface(C,S,L);
219 // test if there is already a range
223 COS->SetUVPoints(Pf,Pl);
228 //=======================================================================
229 //function : UpdateCurves
230 //purpose : Insert two pcurves <C1,C2> on surface <S> with location <L>
231 // in a list of curve representations <lcr>
232 // Remove the pcurves on <S> from <lcr> if <C1> or <C2> is null
233 //=======================================================================
235 static void UpdateCurves(BRep_ListOfCurveRepresentation& lcr,
236 const Handle(Geom2d_Curve)& C1,
237 const Handle(Geom2d_Curve)& C2,
238 const Handle(Geom_Surface)& S,
239 const TopLoc_Location& L)
241 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
242 Handle(BRep_CurveRepresentation) cr;
243 Handle(BRep_GCurve) GC;
244 Standard_Real f = 0.,l = 0.;
245 Standard_Boolean rangeFound = Standard_False;
247 while (itcr.More()) {
248 GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
249 if ( !GC.IsNull() ) {
250 if (GC->IsCurve3D()) {
252 Standard_Boolean undefined = (Precision::IsPositiveInfinite(l) ||
253 Precision::IsNegativeInfinite(f));
256 rangeFound = Standard_True;
259 Standard_Boolean iscos = GC->IsCurveOnSurface(S,L);
266 // cr is used to keep a reference on the curve representation
267 // this avoid deleting it as its content may be referenced by C or S
272 if ( !C1.IsNull() && !C2.IsNull() ) {
273 Handle(BRep_CurveOnClosedSurface) COS =
274 new BRep_CurveOnClosedSurface(C1,C2,S,L,GeomAbs_C0);
275 // test if there is already a range
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 = 0.,l = 0.;
301 Standard_Boolean rangeFound = Standard_False;
303 while (itcr.More()) {
304 GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
305 if ( !GC.IsNull() ) {
306 if (GC->IsCurve3D()) {
308 Standard_Boolean undefined = (Precision::IsPositiveInfinite(l) ||
309 Precision::IsNegativeInfinite(f));
312 rangeFound = Standard_True;
315 Standard_Boolean iscos = GC->IsCurveOnSurface(S,L);
322 // cr is used to keep a reference on the curve representation
323 // this avoid deleting it as its content may be referenced by C or S
328 if ( !C1.IsNull() && !C2.IsNull() ) {
329 Handle(BRep_CurveOnClosedSurface) COS =
330 new BRep_CurveOnClosedSurface(C1,C2,S,L,GeomAbs_C0);
331 // test if there is already a range
335 COS->SetUVPoints2(Pf,Pl);
341 static void UpdateCurves(BRep_ListOfCurveRepresentation& lcr,
342 const Handle(Geom_Surface)& S1,
343 const Handle(Geom_Surface)& S2,
344 const TopLoc_Location& L1,
345 const TopLoc_Location& L2,
346 const GeomAbs_Shape C)
348 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
349 while (itcr.More()) {
350 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
351 Standard_Boolean isregu = cr->IsRegularity(S1,S2,L1,L2);
357 Handle(BRep_CurveRepresentation)& cr = itcr.Value();
361 Handle(BRep_CurveOn2Surfaces) COS = new BRep_CurveOn2Surfaces
367 static void UpdatePoints(BRep_ListOfPointRepresentation& lpr,
369 const Handle(Geom_Curve)& C,
370 const TopLoc_Location& L)
372 BRep_ListIteratorOfListOfPointRepresentation itpr(lpr);
373 while (itpr.More()) {
374 const Handle(BRep_PointRepresentation)& pr = itpr.Value();
375 Standard_Boolean isponc = pr->IsPointOnCurve(C,L);
381 Handle(BRep_PointRepresentation)& pr = itpr.Value();
385 Handle(BRep_PointOnCurve) POC = new BRep_PointOnCurve(p,C,L);
390 static void UpdatePoints(BRep_ListOfPointRepresentation& lpr,
392 const Handle(Geom2d_Curve)& PC,
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 isponcons = pr->IsPointOnCurveOnSurface(PC,S,L);
400 if (isponcons) break;
405 Handle(BRep_PointRepresentation)& pr = itpr.Value();
409 Handle(BRep_PointOnCurveOnSurface) POCS =
410 new BRep_PointOnCurveOnSurface(p,PC,S,L);
416 static void UpdatePoints(BRep_ListOfPointRepresentation& lpr,
419 const Handle(Geom_Surface)& S,
420 const TopLoc_Location& L)
422 BRep_ListIteratorOfListOfPointRepresentation itpr(lpr);
423 while (itpr.More()) {
424 const Handle(BRep_PointRepresentation)& pr = itpr.Value();
425 Standard_Boolean ispons = pr->IsPointOnSurface(S,L);
431 Handle(BRep_PointRepresentation)& pr = itpr.Value();
433 // pr->Parameter(p2); // skv
434 pr->Parameter2(p2); // skv
437 Handle(BRep_PointOnSurface) POS = new BRep_PointOnSurface(p1,p2,S,L);
443 //=======================================================================
444 //function : MakeFace
446 //=======================================================================
448 void BRep_Builder::MakeFace(TopoDS_Face& F,
449 const Handle(Geom_Surface)& S,
450 const Standard_Real Tol) const
452 Handle(BRep_TFace) TF = new BRep_TFace();
453 if(!F.IsNull() && F.Locked())
455 TopoDS_LockedShape::Raise("BRep_Builder::MakeFace");
463 //=======================================================================
464 //function : MakeFace
466 //=======================================================================
468 void BRep_Builder::MakeFace(TopoDS_Face& F,
469 const Handle(Poly_Triangulation)& T) const
471 Handle(BRep_TFace) TF = new BRep_TFace();
472 if(!F.IsNull() && F.Locked())
474 TopoDS_LockedShape::Raise("BRep_Builder::MakeFace");
476 TF->Triangulation(T);
481 //=======================================================================
482 //function : MakeFace
484 //=======================================================================
486 void BRep_Builder::MakeFace(TopoDS_Face& F,
487 const Handle(Geom_Surface)& S,
488 const TopLoc_Location& L,
489 const Standard_Real Tol) const
491 Handle(BRep_TFace) TF = new BRep_TFace();
492 if(!F.IsNull() && F.Locked())
494 TopoDS_LockedShape::Raise("BRep_Builder::MakeFace");
503 //=======================================================================
504 //function : UpdateFace
506 //=======================================================================
508 void BRep_Builder::UpdateFace(const TopoDS_Face& F,
509 const Handle(Geom_Surface)& S,
510 const TopLoc_Location& L,
511 const Standard_Real Tol) const
513 const Handle(BRep_TFace)& TF = *((Handle(BRep_TFace)*) &F.TShape());
516 TopoDS_LockedShape::Raise("BRep_Builder::UpdateFace");
520 TF->Location(L.Predivided(F.Location()));
521 F.TShape()->Modified(Standard_True);
525 //=======================================================================
526 //function : UpdateFace
528 //=======================================================================
530 void BRep_Builder::UpdateFace(const TopoDS_Face& F,
531 const Handle(Poly_Triangulation)& T) const
533 const Handle(BRep_TFace)& TF = *((Handle(BRep_TFace)*) &F.TShape());
536 TopoDS_LockedShape::Raise("BRep_Builder::UpdateFace");
538 TF->Triangulation(T);
539 F.TShape()->Modified(Standard_True);
543 //=======================================================================
544 //function : UpdateFace
546 //=======================================================================
548 void BRep_Builder::UpdateFace(const TopoDS_Face& F,
549 const Standard_Real Tol) const
551 const Handle(BRep_TFace)& TF = *((Handle(BRep_TFace)*) &F.TShape());
554 TopoDS_LockedShape::Raise("BRep_Builder::UpdateFace");
557 F.TShape()->Modified(Standard_True);
561 //=======================================================================
562 //function : NaturalRestriction
564 //=======================================================================
566 void BRep_Builder::NaturalRestriction(const TopoDS_Face& F,
567 const Standard_Boolean N) const
569 const Handle(BRep_TFace)& TF = (*((Handle(BRep_TFace)*) &F.TShape()));
572 TopoDS_LockedShape::Raise("BRep_Builder::NaturalRestriction");
574 TF->NaturalRestriction(N);
575 F.TShape()->Modified(Standard_True);
579 //=======================================================================
580 //function : MakeEdge
581 //purpose : make undefined edge
582 //=======================================================================
584 void BRep_Builder::MakeEdge(TopoDS_Edge& E) const
586 Handle(BRep_TEdge) TE = new BRep_TEdge();
587 if(!E.IsNull() && E.Locked())
589 TopoDS_LockedShape::Raise("BRep_Builder::MakeEdge");
595 //=======================================================================
596 //function : UpdateEdge
598 //=======================================================================
600 void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
601 const Handle(Geom_Curve)& C,
602 const TopLoc_Location& L,
603 const Standard_Real Tol) const
605 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
608 TopoDS_LockedShape::Raise("BRep_Builder::UpdateEdge");
610 const TopLoc_Location l = L.Predivided(E.Location());
612 UpdateCurves(TE->ChangeCurves(),C,l);
614 TE->UpdateTolerance(Tol);
615 TE->Modified(Standard_True);
619 //=======================================================================
620 //function : UpdateEdge
622 //=======================================================================
624 void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
625 const Handle(Geom2d_Curve)& C,
626 const Handle(Geom_Surface)& S,
627 const TopLoc_Location& L,
628 const Standard_Real Tol) const
630 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
633 TopoDS_LockedShape::Raise("BRep_Builder::UpdateEdge");
635 const TopLoc_Location l = L.Predivided(E.Location());
637 UpdateCurves(TE->ChangeCurves(),C,S,l);
639 TE->UpdateTolerance(Tol);
640 TE->Modified(Standard_True);
644 //=======================================================================
645 //function : UpdateEdge
646 //purpose : for the second format (for XML Persistence)
647 //=======================================================================
649 void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
650 const Handle(Geom2d_Curve)& C,
651 const Handle(Geom_Surface)& S,
652 const TopLoc_Location& L,
653 const Standard_Real Tol,
655 const gp_Pnt2d& Pl) const
657 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
660 TopoDS_LockedShape::Raise("BRep_Builder::UpdateEdge");
662 const TopLoc_Location l = L.Predivided(E.Location());
664 UpdateCurves(TE->ChangeCurves(),C,S,l,Pf,Pl);
666 TE->UpdateTolerance(Tol);
667 TE->Modified(Standard_True);
671 //=======================================================================
672 //function : UpdateEdge
674 //=======================================================================
676 void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
677 const Handle(Geom2d_Curve)& C1,
678 const Handle(Geom2d_Curve)& C2,
679 const Handle(Geom_Surface)& S,
680 const TopLoc_Location& L,
681 const Standard_Real Tol) const
683 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
686 TopoDS_LockedShape::Raise("BRep_Builder::UpdateEdge");
688 const TopLoc_Location l = L.Predivided(E.Location());
690 UpdateCurves(TE->ChangeCurves(),C1,C2,S,l);
692 TE->UpdateTolerance(Tol);
693 TE->Modified(Standard_True);
697 //=======================================================================
698 //function : UpdateEdge
699 //purpose : for the second format (for XML Persistence)
700 //=======================================================================
702 void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
703 const Handle(Geom2d_Curve)& C1,
704 const Handle(Geom2d_Curve)& C2,
705 const Handle(Geom_Surface)& S,
706 const TopLoc_Location& L,
707 const Standard_Real Tol,
709 const gp_Pnt2d& Pl) const
711 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
714 TopoDS_LockedShape::Raise("BRep_Builder::UpdateEdge");
716 const TopLoc_Location l = L.Predivided(E.Location());
718 UpdateCurves(TE->ChangeCurves(),C1,C2,S,l,Pf,Pl);
720 TE->UpdateTolerance(Tol);
721 TE->Modified(Standard_True);
725 //=======================================================================
726 //function : UpdateEdge
728 //=======================================================================
730 void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
731 const Handle(Poly_Polygon3D)& P,
732 const TopLoc_Location& L) const
734 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
737 TopoDS_LockedShape::Raise("BRep_Builder::UpdateEdge");
739 BRep_ListOfCurveRepresentation& lcr = TE->ChangeCurves();
740 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
744 if (itcr.Value()->IsPolygon3D())
749 itcr.Value()->Polygon3D(P);
750 TE->Modified(Standard_True);
756 const TopLoc_Location l = L.Predivided(E.Location());
757 Handle(BRep_Polygon3D) P3d = new BRep_Polygon3D(P,l);
760 TE->Modified(Standard_True);
764 //=======================================================================
765 //function : UpdateEdge
767 //=======================================================================
769 void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
770 const Handle(Poly_PolygonOnTriangulation)& P,
771 const Handle(Poly_Triangulation)& T,
772 const TopLoc_Location& L) const
774 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
777 TopoDS_LockedShape::Raise("BRep_Builder::UpdateEdge");
779 const TopLoc_Location l = L.Predivided(E.Location());
781 Standard_Boolean isModified = Standard_False;
783 BRep_ListOfCurveRepresentation& lcr = TE->ChangeCurves();
784 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
785 Handle(BRep_CurveRepresentation) cr;
789 if (itcr.Value()->IsPolygonOnTriangulation(T,l))
791 // cr is used to keep a reference on the curve representation
792 // this avoid deleting it as its content may be referenced by T
795 isModified = Standard_True;
803 Handle(BRep_PolygonOnTriangulation) PT =
804 new BRep_PolygonOnTriangulation(P,T,l);
806 isModified = Standard_True;
810 TE->Modified(Standard_True);
814 //=======================================================================
815 //function : UpdateEdge
817 //=======================================================================
819 void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
820 const Handle(Poly_PolygonOnTriangulation)& P1,
821 const Handle(Poly_PolygonOnTriangulation)& P2,
822 const Handle(Poly_Triangulation)& T,
823 const TopLoc_Location& L) const
825 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
828 TopoDS_LockedShape::Raise("BRep_Builder::UpdateEdge");
830 const TopLoc_Location l = L.Predivided(E.Location());
832 Standard_Boolean isModified = Standard_False;
834 BRep_ListOfCurveRepresentation& lcr = TE->ChangeCurves();
835 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
836 Handle(BRep_CurveRepresentation) cr;
840 if (itcr.Value()->IsPolygonOnTriangulation(T,l)) //szv:was L
842 // cr is used to keep a reference on the curve representation
843 // this avoid deleting it as its content may be referenced by T
846 isModified = Standard_True;
852 if (!P1.IsNull() && !P2.IsNull())
854 Handle(BRep_PolygonOnClosedTriangulation) PT =
855 new BRep_PolygonOnClosedTriangulation(P1,P2,T,l);
857 isModified = Standard_True;
861 TE->Modified(Standard_True);
864 //=======================================================================
865 //function : UpdateEdge
867 //=======================================================================
869 void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
870 const Handle(Poly_Polygon2D)& P,
871 const TopoDS_Face& F) const
874 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,l);
875 UpdateEdge(E, P, S, l);
878 //=======================================================================
879 //function : UpdateEdge
881 //=======================================================================
883 void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
884 const Handle(Poly_Polygon2D)& P,
885 const Handle(Geom_Surface)& S,
886 const TopLoc_Location& L) const
888 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
891 TopoDS_LockedShape::Raise("BRep_Builder::UpdateEdge");
893 TopLoc_Location l = L.Predivided(E.Location());
895 BRep_ListOfCurveRepresentation& lcr = TE->ChangeCurves();
896 Handle(BRep_CurveRepresentation) cr;
898 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
899 while (itcr.More()) {
900 if (itcr.Value()->IsPolygonOnSurface(S, l)) break;
905 // cr is used to keep a reference on the curve representation
906 // this avoid deleting it as its content may be referenced by T
912 Handle(BRep_PolygonOnSurface) PS =
913 new BRep_PolygonOnSurface(P, S, l);
917 TE->Modified(Standard_True);
920 //=======================================================================
921 //function : UpdateEdge
923 //=======================================================================
925 void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
926 const Handle(Poly_Polygon2D)& P1,
927 const Handle(Poly_Polygon2D)& P2,
928 const TopoDS_Face& F) const
931 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,l);
932 UpdateEdge(E, P1, P2, S, l);
935 //=======================================================================
936 //function : UpdateEdge
938 //=======================================================================
940 void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
941 const Handle(Poly_Polygon2D)& P1,
942 const Handle(Poly_Polygon2D)& P2,
943 const Handle(Geom_Surface)& S,
944 const TopLoc_Location& L) const
946 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
949 TopoDS_LockedShape::Raise("BRep_Builder::UpdateEdge");
951 TopLoc_Location l = L.Predivided(E.Location());
953 BRep_ListOfCurveRepresentation& lcr = TE->ChangeCurves();
954 Handle(BRep_CurveRepresentation) cr;
956 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
957 while (itcr.More()) {
958 if (itcr.Value()->IsPolygonOnSurface(S, l)) break;
963 // cr is used to keep a reference on the curve representation
964 // this avoid deleting it as its content may be referenced by T
969 if (!P1.IsNull() && !P2.IsNull()) {
970 Handle(BRep_PolygonOnClosedSurface) PS =
971 new BRep_PolygonOnClosedSurface(P1, P2, S, TopLoc_Location());
975 TE->Modified(Standard_True);
978 //=======================================================================
979 //function : UpdateEdge
981 //=======================================================================
983 void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
984 const Standard_Real Tol) const
986 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
989 TopoDS_LockedShape::Raise("BRep_Builder::UpdateEdge");
991 TE->UpdateTolerance(Tol);
992 TE->Modified(Standard_True);
996 //=======================================================================
997 //function : Continuity
999 //=======================================================================
1001 void BRep_Builder::Continuity(const TopoDS_Edge& E,
1002 const TopoDS_Face& F1,
1003 const TopoDS_Face& F2,
1004 const GeomAbs_Shape C) const
1006 TopLoc_Location l1,l2;
1007 const Handle(Geom_Surface)& S1 = BRep_Tool::Surface(F1,l1);
1008 const Handle(Geom_Surface)& S2 = BRep_Tool::Surface(F2,l2);
1009 Continuity(E,S1,S2,l1,l2,C);
1012 //=======================================================================
1013 //function : Continuity
1015 //=======================================================================
1017 void BRep_Builder::Continuity(const TopoDS_Edge& E,
1018 const Handle(Geom_Surface)& S1,
1019 const Handle(Geom_Surface)& S2,
1020 const TopLoc_Location& L1,
1021 const TopLoc_Location& L2,
1022 const GeomAbs_Shape C)const
1024 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
1027 TopoDS_LockedShape::Raise("BRep_Builder::Continuity");
1029 const TopLoc_Location l1 = L1.Predivided(E.Location());
1030 const TopLoc_Location l2 = L2.Predivided(E.Location());
1032 UpdateCurves(TE->ChangeCurves(),S1,S2,l1,l2,C);
1034 TE->Modified(Standard_True);
1037 //=======================================================================
1038 //function : SameParameter
1040 //=======================================================================
1042 void BRep_Builder::SameParameter(const TopoDS_Edge& E,
1043 const Standard_Boolean S) const
1045 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
1048 TopoDS_LockedShape::Raise("BRep_Builder::SameParameter");
1050 TE->SameParameter(S);
1051 TE->Modified(Standard_True);
1054 //=======================================================================
1055 //function : SameRange
1057 //=======================================================================
1059 void BRep_Builder::SameRange(const TopoDS_Edge& E,
1060 const Standard_Boolean S) const
1062 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
1065 TopoDS_LockedShape::Raise("BRep_Builder::SameRange");
1068 TE->Modified(Standard_True);
1071 //=======================================================================
1072 //function : Degenerated
1074 //=======================================================================
1076 void BRep_Builder::Degenerated(const TopoDS_Edge& E,
1077 const Standard_Boolean D) const
1079 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
1082 TopoDS_LockedShape::Raise("BRep_Builder::Degenerated");
1086 // set a null 3d curve
1087 UpdateCurves(TE->ChangeCurves(),Handle(Geom_Curve)(),E.Location());
1089 TE->Modified(Standard_True);
1093 //=======================================================================
1096 //=======================================================================
1098 void BRep_Builder::Range(const TopoDS_Edge& E,
1099 const Standard_Real First,
1100 const Standard_Real Last,
1101 const Standard_Boolean Only3d) const
1103 // set the range to all the representations if Only3d=FALSE
1104 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
1107 TopoDS_LockedShape::Raise("BRep_Builder::Range");
1109 BRep_ListOfCurveRepresentation& lcr = TE->ChangeCurves();
1110 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
1111 Handle(BRep_GCurve) GC;
1113 while (itcr.More()) {
1114 GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
1115 if (!GC.IsNull() && (!Only3d || GC->IsCurve3D()))
1116 GC->SetRange(First,Last);
1120 TE->Modified(Standard_True);
1124 //=======================================================================
1127 //=======================================================================
1129 void BRep_Builder::Range(const TopoDS_Edge& E,
1130 const Handle(Geom_Surface)& S,
1131 const TopLoc_Location& L,
1132 const Standard_Real First,
1133 const Standard_Real Last) const
1135 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
1138 TopoDS_LockedShape::Raise("BRep_Builder::Range");
1140 const TopLoc_Location l = L.Predivided(E.Location());
1142 BRep_ListOfCurveRepresentation& lcr = TE->ChangeCurves();
1143 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
1144 Handle(BRep_GCurve) GC;
1146 while (itcr.More()) {
1147 GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
1148 if (!GC.IsNull() && GC->IsCurveOnSurface(S,l))
1150 GC->SetRange(First,Last);
1157 Standard_DomainError::Raise("BRep_Builder::Range, no pcurve");
1159 TE->Modified(Standard_True);
1163 //=======================================================================
1164 //function : Transfert
1166 //=======================================================================
1168 void BRep_Builder::Transfert(const TopoDS_Edge& Ein,
1169 const TopoDS_Edge& Eout) const
1171 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &Ein.TShape());
1174 TopoDS_LockedShape::Raise("BRep_Builder::Transfert");
1176 const Standard_Real tol = TE->Tolerance();
1178 BRep_ListOfCurveRepresentation& lcr = TE->ChangeCurves();
1179 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
1181 while (itcr.More()) {
1183 const Handle(BRep_CurveRepresentation)& CR = itcr.Value();
1185 if (CR->IsCurveOnSurface()) {
1189 Ein.Location() * CR->Location(),tol);
1192 else if (CR->IsCurveOnClosedSurface()) {
1197 Ein.Location() * CR->Location(),tol);
1200 if (CR->IsRegularity()) {
1204 Ein.Location() * CR->Location(),
1205 Ein.Location() * CR->Location2(),
1214 //=======================================================================
1215 //function : UpdateVertex
1216 //purpose : update vertex with 3d point
1217 //=======================================================================
1219 void BRep_Builder::UpdateVertex(const TopoDS_Vertex& V,
1221 const Standard_Real Tol) const
1223 const Handle(BRep_TVertex)& TV = *((Handle(BRep_TVertex)*) &V.TShape());
1226 TopoDS_LockedShape::Raise("BRep_Builder::UpdateVertex");
1228 TV->Pnt(P.Transformed(V.Location().Inverted().Transformation()));
1229 TV->UpdateTolerance(Tol);
1230 TV->Modified(Standard_True);
1234 //=======================================================================
1235 //function : UpdateVertex
1236 //purpose : update vertex with parameter on edge
1237 //=======================================================================
1239 void BRep_Builder::UpdateVertex(const TopoDS_Vertex& V,
1240 const Standard_Real Par,
1241 const TopoDS_Edge& E,
1242 const Standard_Real Tol) const
1244 if (Precision::IsPositiveInfinite(Par) ||
1245 Precision::IsNegativeInfinite(Par))
1246 Standard_DomainError::Raise("BRep_Builder::Infinite parameter");
1248 const Handle(BRep_TVertex)& TV = *((Handle(BRep_TVertex)*) &V.TShape());
1249 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
1251 if(TV->Locked() || TE->Locked())
1253 TopoDS_LockedShape::Raise("BRep_Builder::UpdateVertex");
1256 TopLoc_Location L = E.Location().Predivided(V.Location());
1258 // Search the vertex in the edge
1259 TopAbs_Orientation ori = TopAbs_INTERNAL;
1261 TopoDS_Iterator itv(E.Oriented(TopAbs_FORWARD));
1263 // if the edge has no vertices
1264 // and is degenerated use the vertex orientation
1267 if (!itv.More() && TE->Degenerated())
1268 ori = V.Orientation();
1270 while (itv.More()) {
1271 const TopoDS_Shape& Vcur = itv.Value();
1272 if (V.IsSame(Vcur)) {
1273 ori = Vcur.Orientation();
1274 if (ori == V.Orientation()) break;
1279 BRep_ListOfCurveRepresentation& lcr = TE->ChangeCurves();
1280 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
1281 Handle(BRep_GCurve) GC;
1283 while (itcr.More()) {
1284 GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
1286 if (ori == TopAbs_FORWARD)
1288 else if (ori == TopAbs_REVERSED)
1291 BRep_ListOfPointRepresentation& lpr = TV->ChangePoints();
1292 const TopLoc_Location& GCloc = GC->Location();
1293 TopLoc_Location LGCloc = L*GCloc;
1294 if (GC->IsCurve3D()) {
1295 const Handle(Geom_Curve)& GC3d = GC->Curve3D();
1296 UpdatePoints(lpr,Par,GC3d,LGCloc);
1298 else if (GC->IsCurveOnSurface()) {
1299 const Handle(Geom2d_Curve)& GCpc = GC->PCurve();
1300 const Handle(Geom_Surface)& GCsu = GC->Surface();
1301 UpdatePoints(lpr,Par,GCpc,GCsu,LGCloc);
1308 if ((ori != TopAbs_FORWARD) && (ori != TopAbs_REVERSED))
1309 TV->Modified(Standard_True);
1310 TV->UpdateTolerance(Tol);
1311 TE->Modified(Standard_True);
1315 //=======================================================================
1316 //function : UpdateVertex
1317 //purpose : update vertex with parameter on edge on face
1318 //=======================================================================
1320 void BRep_Builder::UpdateVertex(const TopoDS_Vertex& V,
1321 const Standard_Real Par,
1322 const TopoDS_Edge& E,
1323 const Handle(Geom_Surface)& S,
1324 const TopLoc_Location& L,
1325 const Standard_Real Tol) const
1327 if (Precision::IsPositiveInfinite(Par) ||
1328 Precision::IsNegativeInfinite(Par))
1329 Standard_DomainError::Raise("BRep_Builder::Infinite parameter");
1331 // Find the curve representation
1332 TopLoc_Location l = L.Predivided(V.Location());
1334 const Handle(BRep_TVertex)& TV = *((Handle(BRep_TVertex)*) &V.TShape());
1335 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
1337 if(TV->Locked() || TE->Locked())
1339 TopoDS_LockedShape::Raise("BRep_Builder::UpdateVertex");
1342 // Search the vertex in the edge
1343 TopAbs_Orientation ori = TopAbs_INTERNAL;
1345 TopoDS_Iterator itv(E.Oriented(TopAbs_FORWARD));
1347 // if the edge has no vertices
1348 // and is degenerated use the vertex orientation
1351 if (!itv.More() && TE->Degenerated())
1352 ori = V.Orientation();
1354 while (itv.More()) {
1355 const TopoDS_Shape& Vcur = itv.Value();
1356 if (V.IsSame(Vcur)) {
1357 ori = Vcur.Orientation();
1358 if (ori == V.Orientation()) break;
1363 BRep_ListOfCurveRepresentation& lcr = TE->ChangeCurves();
1364 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
1365 Handle(BRep_GCurve) GC;
1367 while (itcr.More()) {
1368 GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
1370 // if (GC->IsCurveOnSurface(S,l)) {
1371 if (GC->IsCurveOnSurface(S,L)) { //xpu020198 : BUC60407
1372 if (ori == TopAbs_FORWARD)
1374 else if (ori == TopAbs_REVERSED)
1377 BRep_ListOfPointRepresentation& lpr = TV->ChangePoints();
1378 const Handle(Geom2d_Curve)& GCpc = GC->PCurve();
1379 UpdatePoints(lpr,Par,GCpc,S,l);
1380 TV->Modified(Standard_True);
1389 Standard_DomainError::Raise("BRep_Builder:: no pcurve");
1391 TV->UpdateTolerance(Tol);
1392 TE->Modified(Standard_True);
1395 //=======================================================================
1396 //function : UpdateVertex
1397 //purpose : update vertex with parameters on face
1398 //=======================================================================
1400 void BRep_Builder::UpdateVertex(const TopoDS_Vertex& Ve,
1401 const Standard_Real U,
1402 const Standard_Real V,
1403 const TopoDS_Face& F,
1404 const Standard_Real Tol) const
1406 const Handle(BRep_TVertex)& TV = *((Handle(BRep_TVertex)*) &Ve.TShape());
1410 TopoDS_LockedShape::Raise("BRep_Builder::UpdateVertex");
1414 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,L);
1415 L = L.Predivided(Ve.Location());
1416 BRep_ListOfPointRepresentation& lpr = TV->ChangePoints();
1417 UpdatePoints(lpr,U,V,S,L);
1419 TV->UpdateTolerance(Tol);
1420 TV->Modified(Standard_True);
1423 //=======================================================================
1424 //function : UpdateVertex
1425 //purpose : update vertex with 3d point
1426 //=======================================================================
1428 void BRep_Builder::UpdateVertex(const TopoDS_Vertex& V,
1429 const Standard_Real Tol) const
1431 const Handle(BRep_TVertex)& TV = *((Handle(BRep_TVertex)*) &V.TShape());
1435 TopoDS_LockedShape::Raise("BRep_Builder::UpdateVertex");
1438 TV->UpdateTolerance(Tol);
1439 TV->Modified(Standard_True);
1443 //=======================================================================
1444 //function : Transfert
1446 //=======================================================================
1448 void BRep_Builder::Transfert(const TopoDS_Edge& Ein,
1449 const TopoDS_Edge& Eout,
1450 const TopoDS_Vertex& Vin,
1451 const TopoDS_Vertex& Vout) const
1453 const Standard_Real tol = BRep_Tool::Tolerance(Vin);
1454 const Standard_Real parin = BRep_Tool::Parameter(Vin,Ein);
1455 UpdateVertex(Vout,parin,Eout,tol);