1 // Created on: 1991-07-02
2 // Created by: Remi LEQUETTE
3 // Copyright (c) 1991-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
22 #include <BRep_Builder.ixx>
24 #include <BRep_TEdge.hxx>
25 #include <BRep_Curve3D.hxx>
26 #include <BRep_GCurve.hxx>
27 #include <BRep_CurveOnClosedSurface.hxx>
28 #include <BRep_CurveOn2Surfaces.hxx>
29 #include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
31 #include <BRep_PointOnCurve.hxx>
32 #include <BRep_PointOnCurveOnSurface.hxx>
33 #include <BRep_PointOnSurface.hxx>
34 #include <BRep_ListIteratorOfListOfPointRepresentation.hxx>
37 #include <TopoDS_Iterator.hxx>
39 #include <Precision.hxx>
41 #include <BRep_Polygon3D.hxx>
42 #include <BRep_PolygonOnSurface.hxx>
43 #include <BRep_PolygonOnClosedSurface.hxx>
44 #include <BRep_PolygonOnTriangulation.hxx>
45 #include <BRep_PolygonOnClosedTriangulation.hxx>
47 #include <Standard_NullObject.hxx>
49 //=======================================================================
50 //function : Auxiliary methods
52 //=======================================================================
54 //=======================================================================
55 //function : UpdateCurves
56 //purpose : Insert a 3d curve <C> with location <L>
57 // in a list of curve representations <lcr>
58 //=======================================================================
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;
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;
109 Standard_Boolean rangeFound = Standard_False;
111 // search the range of the 3d curve
112 // and remove any existing representation
114 while (itcr.More()) {
115 GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
117 if (GC->IsCurve3D()) {
119 const Handle(Geom_Curve)& Crv =
122 // if (!C.IsNull()) { //xpu031198, edge degeneree
124 // xpu151298 : parameters can be setted for null curves
125 // see lbo & flo, to determine whether range is defined
126 // compare first and last parameters with default values.
128 //lvt 15/6/99: On enleve la comparaison de reels infinis.
129 Standard_Boolean undefined = (Precision::IsPositiveInfinite(l) ||
130 Precision::IsNegativeInfinite(f));
133 rangeFound = Standard_True;
136 if (GC->IsCurveOnSurface(S,L)) {
137 // remove existing curve on surface
138 // cr is used to keep a reference on the curve representation
139 // this avoid deleting it as its content may be referenced by C or S
153 Handle(BRep_CurveOnSurface) COS = new BRep_CurveOnSurface(C,S,L);
154 // test if there is already a range
162 //=======================================================================
163 //function : UpdateCurves
164 //purpose : Insert a pcurve <C> on surface <S> with location <L>
165 // in a list of curve representations <lcr>
166 // Remove the pcurve on <S> from <lcr> if <C> is null
167 //=======================================================================
168 static void UpdateCurves(BRep_ListOfCurveRepresentation& lcr,
169 const Handle(Geom2d_Curve)& C,
170 const Handle(Geom_Surface)& S,
171 const TopLoc_Location& L,
175 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
176 Handle(BRep_CurveRepresentation) cr;
177 Handle(BRep_GCurve) GC;
179 Standard_Boolean rangeFound = Standard_False;
181 // search the range of the 3d curve
182 // and remove any existing representation
184 while (itcr.More()) {
185 GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
187 if (GC->IsCurve3D()) {
189 const Handle(Geom_Curve)& Crv =
192 // if (!C.IsNull()) { //xpu031198, edge degeneree
194 // xpu151298 : parameters can be setted for null curves
195 // see lbo & flo, to determine whether range is defined
196 // compare first and last parameters with default values.
198 //lvt 15/6/99: On enleve la comparaison de reels infinis.
199 Standard_Boolean undefined = (Precision::IsPositiveInfinite(l) ||
200 Precision::IsNegativeInfinite(f));
203 rangeFound = Standard_True;
206 if (GC->IsCurveOnSurface(S,L)) {
207 // remove existing curve on surface
208 // cr is used to keep a reference on the curve representation
209 // this avoid deleting it as its content may be referenced by C or S
223 Handle(BRep_CurveOnSurface) COS = new BRep_CurveOnSurface(C,S,L);
224 // test if there is already a range
228 COS->SetUVPoints(Pf,Pl);
233 //=======================================================================
234 //function : UpdateCurves
235 //purpose : Insert two pcurves <C1,C2> on surface <S> with location <L>
236 // in a list of curve representations <lcr>
237 // Remove the pcurves on <S> from <lcr> if <C1> or <C2> is null
238 //=======================================================================
240 static void UpdateCurves(BRep_ListOfCurveRepresentation& lcr,
241 const Handle(Geom2d_Curve)& C1,
242 const Handle(Geom2d_Curve)& C2,
243 const Handle(Geom_Surface)& S,
244 const TopLoc_Location& L)
246 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
247 Handle(BRep_CurveRepresentation) cr;
248 Handle(BRep_GCurve) GC;
251 while (itcr.More()) {
252 GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
253 if ( !GC.IsNull() ) {
255 Standard_Boolean iscos = GC->IsCurveOnSurface(S,L);
262 // cr is used to keep a reference on the curve representation
263 // this avoid deleting it as its content may be referenced by C or S
268 if ( !C1.IsNull() && !C2.IsNull() ) {
269 Handle(BRep_CurveOnClosedSurface) COS =
270 new BRep_CurveOnClosedSurface(C1,C2,S,L,GeomAbs_C0);
271 // test if there is already a range
279 //=======================================================================
280 //function : UpdateCurves
281 //purpose : Insert two pcurves <C1,C2> on surface <S> with location <L>
282 // in a list of curve representations <lcr>
283 // Remove the pcurves on <S> from <lcr> if <C1> or <C2> is null
284 //=======================================================================
285 static void UpdateCurves(BRep_ListOfCurveRepresentation& lcr,
286 const Handle(Geom2d_Curve)& C1,
287 const Handle(Geom2d_Curve)& C2,
288 const Handle(Geom_Surface)& S,
289 const TopLoc_Location& L,
293 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
294 Handle(BRep_CurveRepresentation) cr;
295 Handle(BRep_GCurve) GC;
298 while (itcr.More()) {
299 GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
300 if ( !GC.IsNull() ) {
302 Standard_Boolean iscos = GC->IsCurveOnSurface(S,L);
309 // cr is used to keep a reference on the curve representation
310 // this avoid deleting it as its content may be referenced by C or S
315 if ( !C1.IsNull() && !C2.IsNull() ) {
316 Handle(BRep_CurveOnClosedSurface) COS =
317 new BRep_CurveOnClosedSurface(C1,C2,S,L,GeomAbs_C0);
318 // test if there is already a range
322 COS->SetUVPoints2(Pf,Pl);
328 static void UpdateCurves(BRep_ListOfCurveRepresentation& lcr,
329 const Handle(Geom_Surface)& S1,
330 const Handle(Geom_Surface)& S2,
331 const TopLoc_Location& L1,
332 const TopLoc_Location& L2,
333 const GeomAbs_Shape C)
335 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
336 while (itcr.More()) {
337 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
338 Standard_Boolean isregu = cr->IsRegularity(S1,S2,L1,L2);
344 Handle(BRep_CurveRepresentation)& cr = itcr.Value();
348 Handle(BRep_CurveOn2Surfaces) COS = new BRep_CurveOn2Surfaces
354 static void UpdatePoints(BRep_ListOfPointRepresentation& lpr,
356 const Handle(Geom_Curve)& C,
357 const TopLoc_Location& L)
359 BRep_ListIteratorOfListOfPointRepresentation itpr(lpr);
360 while (itpr.More()) {
361 const Handle(BRep_PointRepresentation)& pr = itpr.Value();
362 Standard_Boolean isponc = pr->IsPointOnCurve(C,L);
368 Handle(BRep_PointRepresentation)& pr = itpr.Value();
372 Handle(BRep_PointOnCurve) POC = new BRep_PointOnCurve(p,C,L);
377 static void UpdatePoints(BRep_ListOfPointRepresentation& lpr,
379 const Handle(Geom2d_Curve)& PC,
380 const Handle(Geom_Surface)& S,
381 const TopLoc_Location& L)
383 BRep_ListIteratorOfListOfPointRepresentation itpr(lpr);
384 while (itpr.More()) {
385 const Handle(BRep_PointRepresentation)& pr = itpr.Value();
386 Standard_Boolean isponcons = pr->IsPointOnCurveOnSurface(PC,S,L);
387 if (isponcons) break;
392 Handle(BRep_PointRepresentation)& pr = itpr.Value();
396 Handle(BRep_PointOnCurveOnSurface) POCS =
397 new BRep_PointOnCurveOnSurface(p,PC,S,L);
403 static void UpdatePoints(BRep_ListOfPointRepresentation& lpr,
406 const Handle(Geom_Surface)& S,
407 const TopLoc_Location& L)
409 BRep_ListIteratorOfListOfPointRepresentation itpr(lpr);
410 while (itpr.More()) {
411 const Handle(BRep_PointRepresentation)& pr = itpr.Value();
412 Standard_Boolean ispons = pr->IsPointOnSurface(S,L);
418 Handle(BRep_PointRepresentation)& pr = itpr.Value();
420 // pr->Parameter(p2); // skv
421 pr->Parameter2(p2); // skv
424 Handle(BRep_PointOnSurface) POS = new BRep_PointOnSurface(p1,p2,S,L);
430 //=======================================================================
431 //function : MakeFace
433 //=======================================================================
435 void BRep_Builder::MakeFace(TopoDS_Face& F,
436 const Handle(Geom_Surface)& S,
437 const Standard_Real Tol) const
439 Handle(BRep_TFace) TF = new BRep_TFace();
446 //=======================================================================
447 //function : MakeFace
449 //=======================================================================
451 void BRep_Builder::MakeFace(TopoDS_Face& F,
452 const Handle(Poly_Triangulation)& T) const
454 Handle(BRep_TFace) TF = new BRep_TFace();
455 TF->Triangulation(T);
460 //=======================================================================
461 //function : MakeFace
463 //=======================================================================
465 void BRep_Builder::MakeFace(TopoDS_Face& F,
466 const Handle(Geom_Surface)& S,
467 const TopLoc_Location& L,
468 const Standard_Real Tol) const
470 Handle(BRep_TFace) TF = new BRep_TFace();
478 //=======================================================================
479 //function : UpdateFace
481 //=======================================================================
483 void BRep_Builder::UpdateFace(const TopoDS_Face& F,
484 const Handle(Geom_Surface)& S,
485 const TopLoc_Location& L,
486 const Standard_Real Tol) const
488 const Handle(BRep_TFace)& TF = *((Handle(BRep_TFace)*) &F.TShape());
491 TF->Location(L.Predivided(F.Location()));
492 F.TShape()->Modified(Standard_True);
496 //=======================================================================
497 //function : UpdateFace
499 //=======================================================================
501 void BRep_Builder::UpdateFace(const TopoDS_Face& F,
502 const Handle(Poly_Triangulation)& T) const
504 (*((Handle(BRep_TFace)*) &F.TShape()))->Triangulation(T);
505 F.TShape()->Modified(Standard_True);
509 //=======================================================================
510 //function : UpdateFace
512 //=======================================================================
514 void BRep_Builder::UpdateFace(const TopoDS_Face& F,
515 const Standard_Real Tol) const
517 (*((Handle(BRep_TFace)*) &F.TShape()))->Tolerance(Tol);
518 F.TShape()->Modified(Standard_True);
522 //=======================================================================
523 //function : NaturalRestriction
525 //=======================================================================
527 void BRep_Builder::NaturalRestriction(const TopoDS_Face& F,
528 const Standard_Boolean N) const
530 (*((Handle(BRep_TFace)*) &F.TShape()))->NaturalRestriction(N);
531 F.TShape()->Modified(Standard_True);
535 //=======================================================================
536 //function : MakeEdge
537 //purpose : make undefined edge
538 //=======================================================================
540 void BRep_Builder::MakeEdge(TopoDS_Edge& E) const
542 Handle(BRep_TEdge) TE = new BRep_TEdge();
543 TE->Closed(Standard_False);
548 //=======================================================================
549 //function : UpdateEdge
551 //=======================================================================
553 void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
554 const Handle(Geom_Curve)& C,
555 const TopLoc_Location& L,
556 const Standard_Real Tol) const
558 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
559 const TopLoc_Location l = L.Predivided(E.Location());
561 UpdateCurves(TE->ChangeCurves(),C,l);
562 if (!C.IsNull()) TE->Closed(C->IsClosed());
564 TE->UpdateTolerance(Tol);
565 TE->Modified(Standard_True);
569 //=======================================================================
570 //function : UpdateEdge
572 //=======================================================================
574 void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
575 const Handle(Geom2d_Curve)& C,
576 const Handle(Geom_Surface)& S,
577 const TopLoc_Location& L,
578 const Standard_Real Tol) const
580 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
581 const TopLoc_Location l = L.Predivided(E.Location());
583 UpdateCurves(TE->ChangeCurves(),C,S,l);
585 TE->UpdateTolerance(Tol);
586 TE->Modified(Standard_True);
590 //=======================================================================
591 //function : UpdateEdge
592 //purpose : for the second format (for XML Persistence)
593 //=======================================================================
595 void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
596 const Handle(Geom2d_Curve)& C,
597 const Handle(Geom_Surface)& S,
598 const TopLoc_Location& L,
599 const Standard_Real Tol,
601 const gp_Pnt2d& Pl) const
603 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
604 const TopLoc_Location l = L.Predivided(E.Location());
606 UpdateCurves(TE->ChangeCurves(),C,S,l,Pf,Pl);
608 TE->UpdateTolerance(Tol);
609 TE->Modified(Standard_True);
613 //=======================================================================
614 //function : UpdateEdge
616 //=======================================================================
618 void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
619 const Handle(Geom2d_Curve)& C1,
620 const Handle(Geom2d_Curve)& C2,
621 const Handle(Geom_Surface)& S,
622 const TopLoc_Location& L,
623 const Standard_Real Tol) const
625 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
626 const TopLoc_Location l = L.Predivided(E.Location());
628 UpdateCurves(TE->ChangeCurves(),C1,C2,S,l);
629 if (!C1.IsNull() && !C2.IsNull())
630 TE->Closed(C1->IsClosed() && C2->IsClosed());
632 TE->UpdateTolerance(Tol);
633 TE->Modified(Standard_True);
637 //=======================================================================
638 //function : UpdateEdge
639 //purpose : for the second format (for XML Persistence)
640 //=======================================================================
642 void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
643 const Handle(Geom2d_Curve)& C1,
644 const Handle(Geom2d_Curve)& C2,
645 const Handle(Geom_Surface)& S,
646 const TopLoc_Location& L,
647 const Standard_Real Tol,
649 const gp_Pnt2d& Pl) const
651 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
652 const TopLoc_Location l = L.Predivided(E.Location());
654 UpdateCurves(TE->ChangeCurves(),C1,C2,S,l,Pf,Pl);
655 if (!C1.IsNull() && !C2.IsNull())
656 TE->Closed(C1->IsClosed() && C2->IsClosed());
658 TE->UpdateTolerance(Tol);
659 TE->Modified(Standard_True);
663 //=======================================================================
664 //function : UpdateEdge
666 //=======================================================================
668 void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
669 const Handle(Poly_Polygon3D)& P,
670 const TopLoc_Location& L) const
672 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
674 BRep_ListOfCurveRepresentation& lcr = TE->ChangeCurves();
675 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
679 if (itcr.Value()->IsPolygon3D())
684 itcr.Value()->Polygon3D(P);
685 TE->Modified(Standard_True);
691 const TopLoc_Location l = L.Predivided(E.Location());
692 Handle(BRep_Polygon3D) P3d = new BRep_Polygon3D(P,l);
695 TE->Modified(Standard_True);
699 //=======================================================================
700 //function : UpdateEdge
702 //=======================================================================
704 void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
705 const Handle(Poly_PolygonOnTriangulation)& P,
706 const Handle(Poly_Triangulation)& T,
707 const TopLoc_Location& L) const
709 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
710 const TopLoc_Location l = L.Predivided(E.Location());
712 Standard_Boolean isModified = Standard_False;
714 BRep_ListOfCurveRepresentation& lcr = TE->ChangeCurves();
715 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
716 Handle(BRep_CurveRepresentation) cr;
720 if (itcr.Value()->IsPolygonOnTriangulation(T,l))
722 // cr is used to keep a reference on the curve representation
723 // this avoid deleting it as its content may be referenced by T
726 isModified = Standard_True;
734 Handle(BRep_PolygonOnTriangulation) PT =
735 new BRep_PolygonOnTriangulation(P,T,l);
737 isModified = Standard_True;
741 TE->Modified(Standard_True);
745 //=======================================================================
746 //function : UpdateEdge
748 //=======================================================================
750 void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
751 const Handle(Poly_PolygonOnTriangulation)& P1,
752 const Handle(Poly_PolygonOnTriangulation)& P2,
753 const Handle(Poly_Triangulation)& T,
754 const TopLoc_Location& L) const
756 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
757 const TopLoc_Location l = L.Predivided(E.Location());
759 Standard_Boolean isModified = Standard_False;
761 BRep_ListOfCurveRepresentation& lcr = TE->ChangeCurves();
762 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
763 Handle(BRep_CurveRepresentation) cr;
767 if (itcr.Value()->IsPolygonOnTriangulation(T,l)) //szv:was L
769 // cr is used to keep a reference on the curve representation
770 // this avoid deleting it as its content may be referenced by T
773 isModified = Standard_True;
779 if (!P1.IsNull() && !P2.IsNull())
781 Handle(BRep_PolygonOnClosedTriangulation) PT =
782 new BRep_PolygonOnClosedTriangulation(P1,P2,T,l);
784 isModified = Standard_True;
788 TE->Modified(Standard_True);
791 //=======================================================================
792 //function : UpdateEdge
794 //=======================================================================
796 void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
797 const Handle(Poly_Polygon2D)& P,
798 const TopoDS_Face& F) const
801 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,l);
802 UpdateEdge(E, P, S, l);
805 //=======================================================================
806 //function : UpdateEdge
808 //=======================================================================
810 void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
811 const Handle(Poly_Polygon2D)& P,
812 const Handle(Geom_Surface)& S,
813 const TopLoc_Location& L) const
815 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
816 TopLoc_Location l = L.Predivided(E.Location());
818 BRep_ListOfCurveRepresentation& lcr = TE->ChangeCurves();
819 Handle(BRep_CurveRepresentation) cr;
821 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
822 while (itcr.More()) {
823 if (itcr.Value()->IsPolygonOnSurface(S, l)) break;
828 // cr is used to keep a reference on the curve representation
829 // this avoid deleting it as its content may be referenced by T
835 Handle(BRep_PolygonOnSurface) PS =
836 new BRep_PolygonOnSurface(P, S, l);
840 TE->Modified(Standard_True);
843 //=======================================================================
844 //function : UpdateEdge
846 //=======================================================================
848 void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
849 const Handle(Poly_Polygon2D)& P1,
850 const Handle(Poly_Polygon2D)& P2,
851 const TopoDS_Face& F) const
854 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,l);
855 UpdateEdge(E, P1, P2, S, l);
858 //=======================================================================
859 //function : UpdateEdge
861 //=======================================================================
863 void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
864 const Handle(Poly_Polygon2D)& P1,
865 const Handle(Poly_Polygon2D)& P2,
866 const Handle(Geom_Surface)& S,
867 const TopLoc_Location& L) const
869 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
870 TopLoc_Location l = L.Predivided(E.Location());
872 BRep_ListOfCurveRepresentation& lcr = TE->ChangeCurves();
873 Handle(BRep_CurveRepresentation) cr;
875 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
876 while (itcr.More()) {
877 if (itcr.Value()->IsPolygonOnSurface(S, l)) break;
882 // cr is used to keep a reference on the curve representation
883 // this avoid deleting it as its content may be referenced by T
888 if (!P1.IsNull() && !P2.IsNull()) {
889 Handle(BRep_PolygonOnClosedSurface) PS =
890 new BRep_PolygonOnClosedSurface(P1, P2, S, TopLoc_Location());
894 TE->Modified(Standard_True);
897 //=======================================================================
898 //function : UpdateEdge
900 //=======================================================================
902 void BRep_Builder::UpdateEdge(const TopoDS_Edge& E,
903 const Standard_Real Tol) const
905 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
906 TE->UpdateTolerance(Tol);
907 TE->Modified(Standard_True);
911 //=======================================================================
912 //function : Continuity
914 //=======================================================================
916 void BRep_Builder::Continuity(const TopoDS_Edge& E,
917 const TopoDS_Face& F1,
918 const TopoDS_Face& F2,
919 const GeomAbs_Shape C) const
921 TopLoc_Location l1,l2;
922 const Handle(Geom_Surface)& S1 = BRep_Tool::Surface(F1,l1);
923 const Handle(Geom_Surface)& S2 = BRep_Tool::Surface(F2,l2);
924 Continuity(E,S1,S2,l1,l2,C);
927 //=======================================================================
928 //function : Continuity
930 //=======================================================================
932 void BRep_Builder::Continuity(const TopoDS_Edge& E,
933 const Handle(Geom_Surface)& S1,
934 const Handle(Geom_Surface)& S2,
935 const TopLoc_Location& L1,
936 const TopLoc_Location& L2,
937 const GeomAbs_Shape C)const
939 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
941 const TopLoc_Location l1 = L1.Predivided(E.Location());
942 const TopLoc_Location l2 = L2.Predivided(E.Location());
944 UpdateCurves(TE->ChangeCurves(),S1,S2,l1,l2,C);
946 TE->Modified(Standard_True);
949 //=======================================================================
950 //function : SameParameter
952 //=======================================================================
954 void BRep_Builder::SameParameter(const TopoDS_Edge& E,
955 const Standard_Boolean S) const
957 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
958 TE->SameParameter(S);
959 TE->Modified(Standard_True);
962 //=======================================================================
963 //function : SameRange
965 //=======================================================================
967 void BRep_Builder::SameRange(const TopoDS_Edge& E,
968 const Standard_Boolean S) const
970 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
972 TE->Modified(Standard_True);
975 //=======================================================================
976 //function : Degenerated
978 //=======================================================================
980 void BRep_Builder::Degenerated(const TopoDS_Edge& E,
981 const Standard_Boolean D) const
983 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
986 // set a null 3d curve
987 UpdateCurves(TE->ChangeCurves(),Handle(Geom_Curve)(),E.Location());
989 TE->Modified(Standard_True);
993 //=======================================================================
996 //=======================================================================
998 void BRep_Builder::Range(const TopoDS_Edge& E,
999 const Standard_Real First,
1000 const Standard_Real Last,
1001 const Standard_Boolean Only3d) const
1003 // set the range to all the representations if Only3d=FALSE
1004 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
1006 BRep_ListOfCurveRepresentation& lcr = TE->ChangeCurves();
1007 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
1008 Handle(BRep_GCurve) GC;
1010 while (itcr.More()) {
1011 GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
1013 if (!Only3d || GC->IsCurve3D())
1014 GC->SetRange(First,Last);
1015 if (GC->IsCurve3D()) {
1016 // Set the closedness flag to the correct value.
1017 Handle(Geom_Curve) C = GC->Curve3D();
1019 //fixing a bug PRO18577 to avoid infinite values of First and Last
1021 !Precision::IsNegativeInfinite(First) &&
1022 !Precision::IsPositiveInfinite(Last) ) {
1023 Standard_Boolean closed =
1024 C->Value(First).IsEqual(C->Value(Last),BRep_Tool::Tolerance(E));
1032 TE->Modified(Standard_True);
1036 //=======================================================================
1039 //=======================================================================
1041 void BRep_Builder::Range(const TopoDS_Edge& E,
1042 const Handle(Geom_Surface)& S,
1043 const TopLoc_Location& L,
1044 const Standard_Real First,
1045 const Standard_Real Last) const
1047 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
1048 const TopLoc_Location l = L.Predivided(E.Location());
1050 BRep_ListOfCurveRepresentation& lcr = TE->ChangeCurves();
1051 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
1052 Handle(BRep_GCurve) GC;
1054 while (itcr.More()) {
1055 GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
1057 if (GC->IsCurveOnSurface(S,l)) {
1058 GC->SetRange(First,Last);
1060 // Set the closedness flag to the correct value.
1061 Handle(Geom2d_Curve) PC = GC->PCurve();
1062 gp_Pnt2d P1 = PC->Value(First);
1063 gp_Pnt2d P2 = PC->Value(Last);
1064 gp_Pnt PP1 = S->Value(P1.X(),P1.Y());
1065 gp_Pnt PP2 = S->Value(P2.X(),P2.Y());
1066 Standard_Boolean closed = PP1.IsEqual(PP2,BRep_Tool::Tolerance(E));
1075 Standard_DomainError::Raise("BRep_Builder::Range, no pcurve");
1077 TE->Modified(Standard_True);
1081 //=======================================================================
1082 //function : Transfert
1084 //=======================================================================
1086 void BRep_Builder::Transfert(const TopoDS_Edge& Ein,
1087 const TopoDS_Edge& Eout) const
1089 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &Ein.TShape());
1091 const Standard_Real tol = TE->Tolerance();
1093 BRep_ListOfCurveRepresentation& lcr = TE->ChangeCurves();
1094 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
1096 while (itcr.More()) {
1098 const Handle(BRep_CurveRepresentation)& CR = itcr.Value();
1100 if (CR->IsCurveOnSurface()) {
1104 Ein.Location() * CR->Location(),tol);
1107 else if (CR->IsCurveOnClosedSurface()) {
1112 Ein.Location() * CR->Location(),tol);
1115 if (CR->IsRegularity()) {
1119 Ein.Location() * CR->Location(),
1120 Ein.Location() * CR->Location2(),
1129 //=======================================================================
1130 //function : UpdateVertex
1131 //purpose : update vertex with 3d point
1132 //=======================================================================
1134 void BRep_Builder::UpdateVertex(const TopoDS_Vertex& V,
1136 const Standard_Real Tol) const
1138 const Handle(BRep_TVertex)& TV = *((Handle(BRep_TVertex)*) &V.TShape());
1140 TV->Pnt(P.Transformed(V.Location().Inverted().Transformation()));
1141 TV->UpdateTolerance(Tol);
1142 TV->Modified(Standard_True);
1146 //=======================================================================
1147 //function : UpdateVertex
1148 //purpose : update vertex with parameter on edge
1149 //=======================================================================
1151 void BRep_Builder::UpdateVertex(const TopoDS_Vertex& V,
1152 const Standard_Real Par,
1153 const TopoDS_Edge& E,
1154 const Standard_Real Tol) const
1156 if (Precision::IsPositiveInfinite(Par) ||
1157 Precision::IsNegativeInfinite(Par))
1158 Standard_DomainError::Raise("BRep_Builder::Infinite parameter");
1160 const Handle(BRep_TVertex)& TV = *((Handle(BRep_TVertex)*) &V.TShape());
1161 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
1163 TopLoc_Location L = E.Location().Predivided(V.Location());
1165 // Search the vertex in the edge
1166 TopAbs_Orientation ori = TopAbs_INTERNAL;
1168 TopoDS_Iterator itv(E.Oriented(TopAbs_FORWARD));
1170 // if the edge has no vertices
1171 // and is degenerated use the vertex orientation
1174 if (!itv.More() && TE->Degenerated())
1175 ori = V.Orientation();
1177 while (itv.More()) {
1178 const TopoDS_Shape& Vcur = itv.Value();
1179 if (V.IsSame(Vcur)) {
1180 ori = Vcur.Orientation();
1181 if (ori == V.Orientation()) break;
1186 BRep_ListOfCurveRepresentation& lcr = TE->ChangeCurves();
1187 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
1188 Handle(BRep_GCurve) GC;
1190 while (itcr.More()) {
1191 GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
1193 if (ori == TopAbs_FORWARD)
1195 else if (ori == TopAbs_REVERSED)
1198 BRep_ListOfPointRepresentation& lpr = TV->ChangePoints();
1199 const TopLoc_Location& GCloc = GC->Location();
1200 TopLoc_Location LGCloc = L*GCloc;
1201 if (GC->IsCurve3D()) {
1202 const Handle(Geom_Curve)& GC3d = GC->Curve3D();
1203 UpdatePoints(lpr,Par,GC3d,LGCloc);
1205 else if (GC->IsCurveOnSurface()) {
1206 const Handle(Geom2d_Curve)& GCpc = GC->PCurve();
1207 const Handle(Geom_Surface)& GCsu = GC->Surface();
1208 UpdatePoints(lpr,Par,GCpc,GCsu,LGCloc);
1215 if ((ori != TopAbs_FORWARD) && (ori != TopAbs_REVERSED))
1216 TV->Modified(Standard_True);
1217 TV->UpdateTolerance(Tol);
1218 TE->Modified(Standard_True);
1222 //=======================================================================
1223 //function : UpdateVertex
1224 //purpose : update vertex with parameter on edge on face
1225 //=======================================================================
1227 void BRep_Builder::UpdateVertex(const TopoDS_Vertex& V,
1228 const Standard_Real Par,
1229 const TopoDS_Edge& E,
1230 const Handle(Geom_Surface)& S,
1231 const TopLoc_Location& L,
1232 const Standard_Real Tol) const
1234 if (Precision::IsPositiveInfinite(Par) ||
1235 Precision::IsNegativeInfinite(Par))
1236 Standard_DomainError::Raise("BRep_Builder::Infinite parameter");
1238 // Find the curve representation
1239 TopLoc_Location l = L.Predivided(V.Location());
1241 const Handle(BRep_TVertex)& TV = *((Handle(BRep_TVertex)*) &V.TShape());
1242 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
1245 // Search the vertex in the edge
1246 TopAbs_Orientation ori = TopAbs_INTERNAL;
1248 TopoDS_Iterator itv(E.Oriented(TopAbs_FORWARD));
1250 // if the edge has no vertices
1251 // and is degenerated use the vertex orientation
1254 if (!itv.More() && TE->Degenerated())
1255 ori = V.Orientation();
1257 while (itv.More()) {
1258 const TopoDS_Shape& Vcur = itv.Value();
1259 if (V.IsSame(Vcur)) {
1260 ori = Vcur.Orientation();
1261 if (ori == V.Orientation()) break;
1266 BRep_ListOfCurveRepresentation& lcr = TE->ChangeCurves();
1267 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
1268 Handle(BRep_GCurve) GC;
1270 while (itcr.More()) {
1271 GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
1273 // if (GC->IsCurveOnSurface(S,l)) {
1274 if (GC->IsCurveOnSurface(S,L)) { //xpu020198 : BUC60407
1275 if (ori == TopAbs_FORWARD)
1277 else if (ori == TopAbs_REVERSED)
1280 BRep_ListOfPointRepresentation& lpr = TV->ChangePoints();
1281 const Handle(Geom2d_Curve)& GCpc = GC->PCurve();
1282 UpdatePoints(lpr,Par,GCpc,S,l);
1283 TV->Modified(Standard_True);
1292 Standard_DomainError::Raise("BRep_Builder:: no pcurve");
1294 TV->UpdateTolerance(Tol);
1295 TE->Modified(Standard_True);
1298 //=======================================================================
1299 //function : UpdateVertex
1300 //purpose : update vertex with parameters on face
1301 //=======================================================================
1303 void BRep_Builder::UpdateVertex(const TopoDS_Vertex& Ve,
1304 const Standard_Real U,
1305 const Standard_Real V,
1306 const TopoDS_Face& F,
1307 const Standard_Real Tol) const
1309 const Handle(BRep_TVertex)& TV = *((Handle(BRep_TVertex)*) &Ve.TShape());
1312 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,L);
1313 L = L.Predivided(Ve.Location());
1314 BRep_ListOfPointRepresentation& lpr = TV->ChangePoints();
1315 UpdatePoints(lpr,U,V,S,L);
1317 TV->UpdateTolerance(Tol);
1318 TV->Modified(Standard_True);
1321 //=======================================================================
1322 //function : UpdateVertex
1323 //purpose : update vertex with 3d point
1324 //=======================================================================
1326 void BRep_Builder::UpdateVertex(const TopoDS_Vertex& V,
1327 const Standard_Real Tol) const
1329 const Handle(BRep_TVertex)& TV = *((Handle(BRep_TVertex)*) &V.TShape());
1330 TV->UpdateTolerance(Tol);
1331 TV->Modified(Standard_True);
1335 //=======================================================================
1336 //function : Transfert
1338 //=======================================================================
1340 void BRep_Builder::Transfert(const TopoDS_Edge& Ein,
1341 const TopoDS_Edge& Eout,
1342 const TopoDS_Vertex& Vin,
1343 const TopoDS_Vertex& Vout) const
1345 const Standard_Real tol = BRep_Tool::Tolerance(Vin);
1346 const Standard_Real parin = BRep_Tool::Parameter(Vin,Ein);
1347 UpdateVertex(Vout,parin,Eout,tol);