1 // Created on: 1993-07-07
2 // Created by: Remi LEQUETTE
3 // Copyright (c) 1993-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_Curve3D.hxx>
19 #include <BRep_CurveOnClosedSurface.hxx>
20 #include <BRep_CurveOnSurface.hxx>
21 #include <BRep_CurveRepresentation.hxx>
22 #include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
23 #include <BRep_ListIteratorOfListOfPointRepresentation.hxx>
24 #include <BRep_PointRepresentation.hxx>
25 #include <BRep_Polygon3D.hxx>
26 #include <BRep_PolygonOnClosedSurface.hxx>
27 #include <BRep_PolygonOnClosedTriangulation.hxx>
28 #include <BRep_PolygonOnSurface.hxx>
29 #include <BRep_PolygonOnTriangulation.hxx>
30 #include <BRep_TEdge.hxx>
31 #include <BRep_TFace.hxx>
32 #include <BRep_Tool.hxx>
33 #include <BRep_TVertex.hxx>
35 #include <Geom2d_Curve.hxx>
36 #include <Geom2d_TrimmedCurve.hxx>
37 #include <Geom2dAdaptor.hxx>
38 #include <Geom_Curve.hxx>
39 #include <Geom_OffsetSurface.hxx>
40 #include <Geom_Plane.hxx>
41 #include <Geom_RectangularTrimmedSurface.hxx>
42 #include <Geom_Surface.hxx>
43 #include <Geom_TrimmedCurve.hxx>
44 #include <GeomAdaptor_HCurve.hxx>
45 #include <GeomAdaptor_HSurface.hxx>
46 #include <GeomProjLib.hxx>
48 #include <gp_Pnt2d.hxx>
49 #include <NCollection_IncAllocator.hxx>
50 #include <NCollection_Map.hxx>
51 #include <Poly_Polygon2D.hxx>
52 #include <Poly_Polygon3D.hxx>
53 #include <Poly_PolygonOnTriangulation.hxx>
54 #include <Poly_Triangulation.hxx>
55 #include <Precision.hxx>
56 #include <ProjLib_ProjectedCurve.hxx>
57 #include <Standard_NoSuchObject.hxx>
58 #include <Standard_NullObject.hxx>
60 #include <TopExp_Explorer.hxx>
61 #include <TopLoc_Location.hxx>
63 #include <TopoDS_Edge.hxx>
64 #include <TopoDS_Face.hxx>
65 #include <TopoDS_Iterator.hxx>
66 #include <TopoDS_Shape.hxx>
67 #include <TopoDS_Vertex.hxx>
68 #include <TopoDS_Wire.hxx>
69 #include <TopTools_MapOfShape.hxx>
70 #include <TopTools_ShapeMapHasher.hxx>
71 #include <BRep_GCurve.hxx>
73 //modified by NIZNHY-PKV Fri Oct 17 14:13:29 2008f
75 Standard_Boolean IsPlane(const Handle(Geom_Surface)& aS);
76 //modified by NIZNHY-PKV Fri Oct 17 14:13:33 2008t
78 //=======================================================================
80 //purpose : Returns the geometric surface of the face. Returns
81 // in <L> the location for the surface.
82 //=======================================================================
84 const Handle(Geom_Surface)& BRep_Tool::Surface(const TopoDS_Face& F,
87 const BRep_TFace* TF = static_cast<const BRep_TFace*>(F.TShape().get());
88 L = F.Location() * TF->Location();
92 //=======================================================================
94 //purpose : Returns the geometric surface of the face. It can
95 // be a copy if there is a Location.
96 //=======================================================================
98 Handle(Geom_Surface) BRep_Tool::Surface(const TopoDS_Face& F)
100 const BRep_TFace* TF = static_cast<const BRep_TFace*>(F.TShape().get());
101 const Handle(Geom_Surface)& S = TF->Surface();
103 if(S.IsNull()) return S;
105 TopLoc_Location L = F.Location() * TF->Location();
106 if (!L.IsIdentity()) {
107 Handle(Geom_Geometry) aCopy = S->Transformed(L.Transformation());
108 Geom_Surface* aGS = static_cast<Geom_Surface*>(aCopy.get());
109 return Handle(Geom_Surface)(aGS);
114 //=======================================================================
115 //function : Triangulation
116 //purpose : Returns the Triangulation of the face. It is a
117 // null handle if there is no triangulation.
118 //=======================================================================
120 const Handle(Poly_Triangulation)& BRep_Tool::Triangulation(const TopoDS_Face& F,
124 const BRep_TFace* TF = static_cast<const BRep_TFace*>(F.TShape().get());
125 return TF->Triangulation();
128 //=======================================================================
129 //function : Tolerance
130 //purpose : Returns the tolerance of the face.
131 //=======================================================================
133 Standard_Real BRep_Tool::Tolerance(const TopoDS_Face& F)
135 const BRep_TFace* TF = static_cast<const BRep_TFace*>(F.TShape().get());
136 Standard_Real p = TF->Tolerance();
137 Standard_Real pMin = Precision::Confusion();
138 if (p > pMin) return p;
142 //=======================================================================
143 //function : NaturalRestriction
144 //purpose : Returns the NaturalRestriction flag of the face.
145 //=======================================================================
147 Standard_Boolean BRep_Tool::NaturalRestriction(const TopoDS_Face& F)
149 const BRep_TFace* TF = static_cast<const BRep_TFace*>(F.TShape().get());
150 return TF->NaturalRestriction();
153 //=======================================================================
155 //purpose : Returns the 3D curve of the edge. May be a Null
156 // handle. Returns in <L> the location for the curve.
157 // In <First> and <Last> the parameter range.
158 //=======================================================================
160 static const Handle(Geom_Curve) nullCurve;
162 const Handle(Geom_Curve)& BRep_Tool::Curve(const TopoDS_Edge& E,
164 Standard_Real& First,
167 // find the representation
168 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
169 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
171 while (itcr.More()) {
172 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
173 if (cr->IsCurve3D()) {
174 const BRep_Curve3D* GC = static_cast<const BRep_Curve3D*>(cr.get());
175 L = E.Location() * GC->Location();
176 GC->Range(First,Last);
177 return GC->Curve3D();
186 //=======================================================================
188 //purpose : Returns the 3D curve of the edge. May be a Null handle.
189 // In <First> and <Last> the parameter range.
190 // It can be a copy if there is a Location.
191 //=======================================================================
193 Handle(Geom_Curve) BRep_Tool::Curve(const TopoDS_Edge& E,
194 Standard_Real& First,
198 const Handle(Geom_Curve)& C = Curve(E,L,First,Last);
200 if ( !L.IsIdentity() ) {
201 Handle(Geom_Geometry) aCopy = C->Transformed(L.Transformation());
202 Geom_Curve* aGC = static_cast<Geom_Curve*>(aCopy.get());
203 return Handle(Geom_Curve)(aGC);
209 //=======================================================================
210 //function : IsGeometric
211 //purpose : Returns True if <E> is a 3d curve or a curve on
213 //=======================================================================
215 Standard_Boolean BRep_Tool::IsGeometric(const TopoDS_Edge& E)
217 // find the representation
218 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
219 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
221 while (itcr.More()) {
222 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
223 if (cr->IsCurve3D()) {
224 Handle(BRep_Curve3D) GC (Handle(BRep_Curve3D)::DownCast (cr));
225 if (! GC.IsNull() && ! GC->Curve3D().IsNull())
226 return Standard_True;
228 else if (cr->IsCurveOnSurface()) return Standard_True;
231 return Standard_False;
234 //=======================================================================
235 //function : Polygon3D
236 //purpose : Returns the 3D polygon of the edge. May be a Null
237 // handle. Returns in <L> the location for the polygon.
238 //=======================================================================
240 static const Handle(Poly_Polygon3D) nullPolygon3D;
242 const Handle(Poly_Polygon3D)& BRep_Tool::Polygon3D(const TopoDS_Edge& E,
245 // find the representation
246 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
247 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
249 while (itcr.More()) {
250 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
251 if (cr->IsPolygon3D()) {
252 const BRep_Polygon3D* GC = static_cast<const BRep_Polygon3D*>(cr.get());
253 L = E.Location() * GC->Location();
254 return GC->Polygon3D();
259 return nullPolygon3D;
262 //=======================================================================
263 //function : CurveOnSurface
264 //purpose : Returns the curve associated to the edge in the
265 // parametric space of the face. Returns a NULL
266 // handle if this curve does not exist. Returns in
267 // <First> and <Last> the parameter range.
268 //=======================================================================
270 Handle(Geom2d_Curve) BRep_Tool::CurveOnSurface(const TopoDS_Edge& E,
271 const TopoDS_Face& F,
272 Standard_Real& First,
276 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,l);
277 TopoDS_Edge aLocalEdge = E;
278 if (F.Orientation() == TopAbs_REVERSED) {
279 aLocalEdge.Reverse();
280 // return CurveOnSurface(E,S,l,First,Last);
282 // return CurveOnSurface(TopoDS::Edge(E.Reversed()),S,l,First,Last);
284 // return CurveOnSurface(E,S,l,First,Last);
285 return CurveOnSurface(aLocalEdge,S,l,First,Last);
288 //=======================================================================
289 //function : CurveOnSurface
290 //purpose : Returns the curve associated to the edge in the
291 // parametric space of the surface. Returns a NULL
292 // handle if this curve does not exist. Returns in
293 // <First> and <Last> the parameter range.
294 //=======================================================================
296 static const Handle(Geom2d_Curve) nullPCurve;
298 Handle(Geom2d_Curve) BRep_Tool::CurveOnSurface(const TopoDS_Edge& E,
299 const Handle(Geom_Surface)& S,
300 const TopLoc_Location& L,
301 Standard_Real& First,
304 TopLoc_Location loc = L.Predivided(E.Location());
305 Standard_Boolean Eisreversed = (E.Orientation() == TopAbs_REVERSED);
307 // find the representation
308 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
309 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
311 while (itcr.More()) {
312 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
313 if (cr->IsCurveOnSurface(S,loc)) {
314 const BRep_GCurve* GC = static_cast<const BRep_GCurve*>(cr.get());
315 GC->Range(First,Last);
316 if (GC->IsCurveOnClosedSurface() && Eisreversed)
317 return GC->PCurve2();
324 // for planar surface and 3d curve try a projection
325 // modif 21-05-97 : for RectangularTrimmedSurface, try a projection
326 Handle(Geom_Plane) GP;
327 Handle(Geom_RectangularTrimmedSurface) GRTS;
328 GRTS = Handle(Geom_RectangularTrimmedSurface)::DownCast(S);
330 GP = Handle(Geom_Plane)::DownCast(GRTS->BasisSurface());
332 GP = Handle(Geom_Plane)::DownCast(S);
333 //fin modif du 21-05-97
337 Handle(GeomAdaptor_HCurve) HC;
338 Handle(GeomAdaptor_HSurface) HS;
340 HC = new GeomAdaptor_HCurve();
341 HS = new GeomAdaptor_HSurface();
343 TopLoc_Location aCurveLocation;
345 Standard_Real f, l;// for those who call with (u,u).
346 Handle(Geom_Curve) C3d = BRep_Tool::Curve(E, aCurveLocation, f, l);
354 aCurveLocation = aCurveLocation.Predivided(L);
355 First = f; Last = l; //Range of edge must not be modified
357 if (!aCurveLocation.IsIdentity())
359 const gp_Trsf& T = aCurveLocation.Transformation();
360 Handle(Geom_Geometry) GC3d = C3d->Transformed(T);
361 C3d = Handle(Geom_Curve)::DownCast (GC3d);
362 f = C3d->TransformedParameter(f, T);
363 l = C3d->TransformedParameter(l, T);
365 GeomAdaptor_Surface& GAS = HS->ChangeSurface();
368 Handle(Geom_Curve) ProjOnPlane =
369 GeomProjLib::ProjectOnPlane(new Geom_TrimmedCurve(C3d,f,l,Standard_True,Standard_False),
371 GP->Position().Direction(),
374 GeomAdaptor_Curve& GAC = HC->ChangeCurve();
375 GAC.Load(ProjOnPlane);
377 ProjLib_ProjectedCurve Proj(HS,HC);
378 Handle(Geom2d_Curve) pc = Geom2dAdaptor::MakeCurve(Proj);
380 if (pc->DynamicType() == STANDARD_TYPE(Geom2d_TrimmedCurve)) {
381 Handle(Geom2d_TrimmedCurve) TC =
382 Handle(Geom2d_TrimmedCurve)::DownCast (pc);
383 pc = TC->BasisCurve();
393 //=======================================================================
394 //function : CurveOnSurface
396 //=======================================================================
398 void BRep_Tool::CurveOnSurface(const TopoDS_Edge& E,
399 Handle(Geom2d_Curve)& C,
400 Handle(Geom_Surface)& S,
402 Standard_Real& First,
405 // find the representation
406 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
407 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
409 while (itcr.More()) {
410 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
411 if (cr->IsCurveOnSurface()) {
412 const BRep_GCurve* GC = static_cast<const BRep_GCurve*>(cr.get());
415 L = E.Location() * GC->Location();
416 GC->Range(First,Last);
428 //=======================================================================
429 //function : CurveOnSurface
431 //=======================================================================
433 void BRep_Tool::CurveOnSurface(const TopoDS_Edge& E,
434 Handle(Geom2d_Curve)& C,
435 Handle(Geom_Surface)& S,
437 Standard_Real& First,
439 const Standard_Integer Index)
441 Standard_Integer i = 0;
442 Standard_Boolean Eisreversed = (E.Orientation() == TopAbs_REVERSED);
444 // find the representation
445 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
446 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
448 while (itcr.More()) {
449 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
450 if (cr->IsCurveOnSurface()) {
451 const BRep_GCurve* GC = static_cast<const BRep_GCurve*>(cr.get());
453 if (i > Index) break;
455 // JMB le 21 Mai 1999
456 // it is done as in the other CurveOnSurface methods, ie. take into account
457 // the orientation in case of cut edges (return PCurve2)
458 // otherwise there is a risk to loop curves or to not get the prover one.
459 if (GC->IsCurveOnClosedSurface() && Eisreversed)
464 L = E.Location() * GC->Location();
465 GC->Range(First,Last);
478 //=======================================================================
479 //function : PolygonOnSurface
480 //purpose : Returns the polygon associated to the edge in the
481 // parametric space of the face. Returns a NULL
482 // handle if this polygon does not exist.
483 //=======================================================================
485 Handle(Poly_Polygon2D) BRep_Tool::PolygonOnSurface(const TopoDS_Edge& E,
486 const TopoDS_Face& F)
489 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,l);
490 TopoDS_Edge aLocalEdge = E;
491 if (F.Orientation() == TopAbs_REVERSED) {
492 aLocalEdge.Reverse();
493 // return PolygonOnSurface(E,S,l);
495 // return PolygonOnSurface(TopoDS::Edge(E.Reversed()),S,l);
497 // return PolygonOnSurface(E,S,l);
498 return PolygonOnSurface(aLocalEdge,S,l);
501 //=======================================================================
502 //function : PolygonOnSurface
503 //purpose : Returns the polygon associated to the edge in the
504 // parametric space of the surface. Returns a NULL
505 // handle if this polygon does not exist.
506 //=======================================================================
508 static const Handle(Poly_Polygon2D) nullPolygon2D;
510 Handle(Poly_Polygon2D) BRep_Tool::PolygonOnSurface(const TopoDS_Edge& E,
511 const Handle(Geom_Surface)& S,
512 const TopLoc_Location& L)
514 TopLoc_Location l = L.Predivided(E.Location());
515 Standard_Boolean Eisreversed = (E.Orientation() == TopAbs_REVERSED);
517 // find the representation
518 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
519 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
521 while (itcr.More()) {
522 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
523 if (cr->IsPolygonOnSurface(S,l)) {
524 if (cr->IsPolygonOnClosedSurface() && Eisreversed )
525 return cr->Polygon2();
527 return cr->Polygon();
532 return nullPolygon2D;
535 //=======================================================================
536 //function : PolygonOnSurface
538 //=======================================================================
540 void BRep_Tool::PolygonOnSurface(const TopoDS_Edge& E,
541 Handle(Poly_Polygon2D)& P,
542 Handle(Geom_Surface)& S,
545 // find the representation
546 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
547 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
549 while (itcr.More()) {
550 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
551 if (cr->IsPolygonOnSurface()) {
552 const BRep_PolygonOnSurface* PS = static_cast<const BRep_PolygonOnSurface*>(cr.get());
555 L = E.Location() * PS->Location();
566 //=======================================================================
567 //function : PolygonOnSurface
569 //=======================================================================
571 void BRep_Tool::PolygonOnSurface(const TopoDS_Edge& E,
572 Handle(Poly_Polygon2D)& P,
573 Handle(Geom_Surface)& S,
575 const Standard_Integer Index)
577 Standard_Integer i = 0;
579 // find the representation
580 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
581 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
583 while (itcr.More()) {
584 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
585 if (cr->IsPolygonOnSurface()) {
586 const BRep_PolygonOnSurface* PS = static_cast<const BRep_PolygonOnSurface*>(cr.get());
588 if (i > Index) break;
592 L = E.Location() * PS->Location();
604 //=======================================================================
605 //function : PolygonOnTriangulation
606 //purpose : Returns the polygon associated to the edge in the
607 // parametric space of the face. Returns a NULL
608 // handle if this polygon does not exist.
609 //=======================================================================
611 static const Handle(Poly_PolygonOnTriangulation) nullArray;
613 const Handle(Poly_PolygonOnTriangulation)&
614 BRep_Tool::PolygonOnTriangulation(const TopoDS_Edge& E,
615 const Handle(Poly_Triangulation)& T,
616 const TopLoc_Location& L)
618 TopLoc_Location l = L.Predivided(E.Location());
619 Standard_Boolean Eisreversed = (E.Orientation() == TopAbs_REVERSED);
621 // find the representation
622 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
623 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
625 while (itcr.More()) {
626 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
627 if ( cr->IsPolygonOnTriangulation(T,l)) {
628 if ( cr->IsPolygonOnClosedTriangulation() && Eisreversed )
629 return cr->PolygonOnTriangulation2();
631 return cr->PolygonOnTriangulation();
639 //=======================================================================
640 //function : PolygonOnTriangulation
642 //=======================================================================
645 BRep_Tool::PolygonOnTriangulation(const TopoDS_Edge& E,
646 Handle(Poly_PolygonOnTriangulation)& P,
647 Handle(Poly_Triangulation)& T,
650 // find the representation
651 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
652 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
654 while (itcr.More()) {
655 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
656 if (cr->IsPolygonOnTriangulation()) {
657 const BRep_PolygonOnTriangulation* PT =
658 static_cast<const BRep_PolygonOnTriangulation*>(cr.get());
659 P = PT->PolygonOnTriangulation();
660 T = PT->Triangulation();
661 L = E.Location() * PT->Location();
672 //=======================================================================
673 //function : PolygonOnTriangulation
675 //=======================================================================
678 BRep_Tool::PolygonOnTriangulation(const TopoDS_Edge& E,
679 Handle(Poly_PolygonOnTriangulation)& P,
680 Handle(Poly_Triangulation)& T,
682 const Standard_Integer Index)
684 Standard_Integer i = 0;
686 // find the representation
687 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
688 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
690 while (itcr.More()) {
691 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
692 if (cr->IsPolygonOnTriangulation()) {
693 const BRep_PolygonOnTriangulation* PT =
694 static_cast<const BRep_PolygonOnTriangulation*>(cr.get());
696 if (i > Index) break;
698 T = PT->Triangulation();
699 P = PT->PolygonOnTriangulation();
700 L = E.Location() * PT->Location();
712 //=======================================================================
713 //function : IsClosed
714 //purpose : Returns True if <E> has two PCurves in the
715 // parametric space of <F>. i.e. <F> is on a closed
716 // surface and <E> is on the closing curve.
717 //=======================================================================
719 Standard_Boolean BRep_Tool::IsClosed(const TopoDS_Edge& E,
720 const TopoDS_Face& F)
723 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,l);
724 if (IsClosed(E,S,l)) return Standard_True;
725 const Handle(Poly_Triangulation)& T = BRep_Tool::Triangulation(F,l);
726 return IsClosed(E, T, l);
729 //=======================================================================
730 //function : IsClosed
731 //purpose : Returns True if <E> has two PCurves in the
732 // parametric space of <S>. i.e. <S> is a closed
733 // surface and <E> is on the closing curve.
734 //=======================================================================
736 Standard_Boolean BRep_Tool::IsClosed(const TopoDS_Edge& E,
737 const Handle(Geom_Surface)& S,
738 const TopLoc_Location& L)
740 //modified by NIZNHY-PKV Fri Oct 17 12:16:58 2008f
742 return Standard_False;
744 //modified by NIZNHY-PKV Fri Oct 17 12:16:54 2008t
746 TopLoc_Location l = L.Predivided(E.Location());
748 // find the representation
749 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
750 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
752 while (itcr.More()) {
753 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
754 if (cr->IsCurveOnSurface(S,l) &&
755 cr->IsCurveOnClosedSurface())
756 return Standard_True;
759 return Standard_False;
762 //=======================================================================
763 //function : IsClosed
764 //purpose : Returns True if <E> has two arrays of indices in
765 // the triangulation <T>.
766 //=======================================================================
768 Standard_Boolean BRep_Tool::IsClosed(const TopoDS_Edge& E,
769 const Handle(Poly_Triangulation)& T,
770 const TopLoc_Location& L)
772 TopLoc_Location l = L.Predivided(E.Location());
774 // find the representation
775 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
776 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
778 while (itcr.More()) {
779 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
780 if (cr->IsPolygonOnTriangulation(T,l) &&
781 cr->IsPolygonOnClosedTriangulation())
782 return Standard_True;
785 return Standard_False;
788 //=======================================================================
789 //function : Tolerance
790 //purpose : Returns the tolerance for <E>.
791 //=======================================================================
793 Standard_Real BRep_Tool::Tolerance(const TopoDS_Edge& E)
795 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
796 Standard_Real p = TE->Tolerance();
797 Standard_Real pMin = Precision::Confusion();
798 if (p > pMin) return p;
802 //=======================================================================
803 //function : SameParameter
804 //purpose : Returns the SameParameter flag for the edge.
805 //=======================================================================
807 Standard_Boolean BRep_Tool::SameParameter(const TopoDS_Edge& E)
809 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
810 return TE->SameParameter();
813 //=======================================================================
814 //function : SameRange
815 //purpose : Returns the SameRange flag for the edge.
816 //=======================================================================
818 Standard_Boolean BRep_Tool::SameRange(const TopoDS_Edge& E)
820 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
821 return TE->SameRange();
824 //=======================================================================
825 //function : Degenerated
826 //purpose : Returns True if the edge is degenerated.
827 //=======================================================================
829 Standard_Boolean BRep_Tool::Degenerated(const TopoDS_Edge& E)
831 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
832 return TE->Degenerated();
835 //=======================================================================
838 //=======================================================================
840 void BRep_Tool::Range(const TopoDS_Edge& E,
841 Standard_Real& First,
844 // set the range to all the representations
845 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
846 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
848 while (itcr.More()) {
849 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
850 if (cr->IsCurve3D()) {
851 const BRep_Curve3D* CR = static_cast<const BRep_Curve3D*>(cr.get());
852 if (!CR->Curve3D().IsNull()) {
858 else if (cr->IsCurveOnSurface()) {
859 const BRep_GCurve* CR = static_cast<const BRep_GCurve*>(cr.get());
869 //=======================================================================
872 //=======================================================================
874 void BRep_Tool::Range(const TopoDS_Edge& E,
875 const Handle(Geom_Surface)& S,
876 const TopLoc_Location& L,
877 Standard_Real& First,
880 TopLoc_Location l = L.Predivided(E.Location());
882 // find the representation
883 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
884 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
886 while (itcr.More()) {
887 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
888 if (cr->IsCurveOnSurface(S,l)) {
889 const BRep_CurveOnSurface* CR = static_cast<const BRep_CurveOnSurface*>(cr.get());
890 CR->Range(First,Last);
898 E.TShape()->Modified(Standard_True);
901 //=======================================================================
904 //=======================================================================
906 void BRep_Tool::Range(const TopoDS_Edge& E,
907 const TopoDS_Face& F,
908 Standard_Real& First,
912 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,L);
913 Range(E,S,L,First,Last);
916 //=======================================================================
917 //function : UVPoints
919 //=======================================================================
921 void BRep_Tool::UVPoints(const TopoDS_Edge& E,
922 const Handle(Geom_Surface)& S,
923 const TopLoc_Location& L,
927 TopLoc_Location l = L.Predivided(E.Location());
928 Standard_Boolean Eisreversed = (E.Orientation() == TopAbs_REVERSED);
930 // find the representation
931 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
932 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
934 while (itcr.More()) {
935 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
936 if (cr->IsCurveOnSurface(S,l)) {
937 if (cr->IsCurveOnClosedSurface() && Eisreversed)
939 const BRep_CurveOnClosedSurface* CR =
940 static_cast<const BRep_CurveOnClosedSurface*>(cr.get());
941 CR->UVPoints2(PFirst, PLast);
945 const BRep_CurveOnSurface* CR =
946 static_cast<const BRep_CurveOnSurface*>(cr.get());
947 CR->UVPoints(PFirst, PLast);
954 // for planar surface project the vertices
955 // modif 21-05-97 : for RectangularTrimmedSurface, project the vertices
956 Handle(Geom_Plane) GP;
957 Handle(Geom_RectangularTrimmedSurface) GRTS;
958 GRTS = Handle(Geom_RectangularTrimmedSurface)::DownCast(S);
960 GP = Handle(Geom_Plane)::DownCast(GRTS->BasisSurface());
962 GP = Handle(Geom_Plane)::DownCast(S);
963 //fin modif du 21-05-97
965 // get the two vertices
967 TopExp::Vertices(E,Vf,Vl);
969 TopLoc_Location Linverted = L.Inverted();
973 gp_Pln pln = GP->Pln();
977 gp_Pnt PF = BRep_Tool::Pnt(Vf);
978 ElSLib::Parameters(pln,PF,u,v);
980 PFirst.SetCoord(u,v);
984 gp_Pnt PL = BRep_Tool::Pnt(Vl);
985 ElSLib::Parameters(pln,PL,u,v);
991 PFirst.SetCoord (0., 0.);
992 PLast.SetCoord (0., 0.);
996 //=======================================================================
997 //function : UVPoints
999 //=======================================================================
1001 void BRep_Tool::UVPoints(const TopoDS_Edge& E,
1002 const TopoDS_Face& F,
1007 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,L);
1008 TopoDS_Edge aLocalEdge = E;
1009 if (F.Orientation() == TopAbs_REVERSED) {
1010 aLocalEdge.Reverse();
1011 // UVPoints(E,S,L,PFirst,PLast);
1013 // UVPoints(TopoDS::Edge(E.Reversed()),S,L,PFirst,PLast);
1015 // UVPoints(E,S,L,PFirst,PLast);
1016 UVPoints(aLocalEdge,S,L,PFirst,PLast);
1019 //=======================================================================
1020 //function : SetUVPoints
1022 //=======================================================================
1024 void BRep_Tool::SetUVPoints(const TopoDS_Edge& E,
1025 const Handle(Geom_Surface)& S,
1026 const TopLoc_Location& L,
1027 const gp_Pnt2d& PFirst,
1028 const gp_Pnt2d& PLast)
1030 TopLoc_Location l = L.Predivided(E.Location());
1031 Standard_Boolean Eisreversed = (E.Orientation() == TopAbs_REVERSED);
1033 // find the representation
1034 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
1035 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
1037 while (itcr.More()) {
1038 Handle(BRep_CurveRepresentation)& cr = itcr.Value();
1039 if (cr->IsCurveOnSurface(S,l)) {
1040 if (cr->IsCurveOnClosedSurface() && Eisreversed)
1042 BRep_CurveOnClosedSurface* CS = static_cast<BRep_CurveOnClosedSurface*>(cr.get());
1043 CS->SetUVPoints2(PFirst, PLast);
1047 BRep_CurveOnSurface* CS = static_cast<BRep_CurveOnSurface*>(cr.get());
1048 CS->SetUVPoints(PFirst, PLast);
1055 //=======================================================================
1056 //function : SetUVPoints
1058 //=======================================================================
1060 void BRep_Tool::SetUVPoints(const TopoDS_Edge& E,
1061 const TopoDS_Face& F,
1062 const gp_Pnt2d& PFirst,
1063 const gp_Pnt2d& PLast)
1066 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,L);
1067 TopoDS_Edge aLocalEdge = E;
1068 if (F.Orientation() == TopAbs_REVERSED) {
1069 aLocalEdge.Reverse();
1070 // SetUVPoints(TopoDS::Edge(E.Reversed()),S,L,PFirst,PLast);
1073 // SetUVPoints(E,S,L,PFirst,PLast);
1074 SetUVPoints(aLocalEdge,S,L,PFirst,PLast);
1077 //=======================================================================
1078 //function : HasContinuity
1079 //purpose : Returns True if the edge is on the surfaces of the
1081 //=======================================================================
1083 Standard_Boolean BRep_Tool::HasContinuity(const TopoDS_Edge& E,
1084 const TopoDS_Face& F1,
1085 const TopoDS_Face& F2)
1087 TopLoc_Location l1,l2;
1088 const Handle(Geom_Surface)& S1 = BRep_Tool::Surface(F1,l1);
1089 const Handle(Geom_Surface)& S2 = BRep_Tool::Surface(F2,l2);
1090 return HasContinuity(E,S1,S2,l1,l2);
1093 //=======================================================================
1094 //function : Continuity
1095 //purpose : Returns the continuity.
1096 //=======================================================================
1098 GeomAbs_Shape BRep_Tool::Continuity(const TopoDS_Edge& E,
1099 const TopoDS_Face& F1,
1100 const TopoDS_Face& F2)
1102 TopLoc_Location l1,l2;
1103 const Handle(Geom_Surface)& S1 = BRep_Tool::Surface(F1,l1);
1104 const Handle(Geom_Surface)& S2 = BRep_Tool::Surface(F2,l2);
1105 return Continuity(E,S1,S2,l1,l2);
1108 //=======================================================================
1109 //function : HasContinuity
1110 //purpose : Returns True if the edge is on the surfaces.
1111 //=======================================================================
1113 Standard_Boolean BRep_Tool::HasContinuity(const TopoDS_Edge& E,
1114 const Handle(Geom_Surface)& S1,
1115 const Handle(Geom_Surface)& S2,
1116 const TopLoc_Location& L1,
1117 const TopLoc_Location& L2)
1119 const TopLoc_Location& Eloc = E.Location();
1120 TopLoc_Location l1 = L1.Predivided(Eloc);
1121 TopLoc_Location l2 = L2.Predivided(Eloc);
1123 // find the representation
1124 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
1125 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
1127 while (itcr.More()) {
1128 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
1129 if (cr->IsRegularity(S1,S2,l1,l2))
1130 return Standard_True;
1133 return Standard_False;
1136 //=======================================================================
1137 //function : Continuity
1138 //purpose : Returns the continuity.
1139 //=======================================================================
1141 GeomAbs_Shape BRep_Tool::Continuity(const TopoDS_Edge& E,
1142 const Handle(Geom_Surface)& S1,
1143 const Handle(Geom_Surface)& S2,
1144 const TopLoc_Location& L1,
1145 const TopLoc_Location& L2)
1147 TopLoc_Location l1 = L1.Predivided(E.Location());
1148 TopLoc_Location l2 = L2.Predivided(E.Location());
1150 // find the representation
1151 BRep_ListIteratorOfListOfCurveRepresentation itcr
1152 ((*((Handle(BRep_TEdge)*)&E.TShape()))->ChangeCurves());
1154 while (itcr.More()) {
1155 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
1156 if (cr->IsRegularity(S1,S2,l1,l2))
1157 return cr->Continuity();
1163 //=======================================================================
1164 //function : HasContinuity
1165 //purpose : Returns True if the edge is on some two surfaces.
1166 //=======================================================================
1168 Standard_Boolean BRep_Tool::HasContinuity(const TopoDS_Edge& E)
1170 const BRep_TEdge* TE = static_cast<const BRep_TEdge*>(E.TShape().get());
1171 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
1173 for (; itcr.More(); itcr.Next())
1175 const Handle(BRep_CurveRepresentation)& CR = itcr.Value();
1176 if (CR->IsRegularity())
1177 return Standard_True;
1179 return Standard_False;
1182 //=======================================================================
1184 //purpose : Returns the 3d point.
1185 //=======================================================================
1187 gp_Pnt BRep_Tool::Pnt(const TopoDS_Vertex& V)
1189 const BRep_TVertex* TV = static_cast<const BRep_TVertex*>(V.TShape().get());
1193 throw Standard_NullObject("BRep_Tool:: TopoDS_Vertex hasn't gp_Pnt");
1196 const gp_Pnt& P = TV->Pnt();
1197 if (V.Location().IsIdentity())
1202 return P.Transformed(V.Location().Transformation());
1205 //=======================================================================
1206 //function : Tolerance
1207 //purpose : Returns the tolerance.
1208 //=======================================================================
1210 Standard_Real BRep_Tool::Tolerance(const TopoDS_Vertex& V)
1212 const BRep_TVertex* aTVert = static_cast<const BRep_TVertex*>(V.TShape().get());
1216 throw Standard_NullObject("BRep_Tool:: TopoDS_Vertex hasn't gp_Pnt");
1219 Standard_Real p = aTVert->Tolerance();
1220 Standard_Real pMin = Precision::Confusion();
1221 if (p > pMin) return p;
1225 //=======================================================================
1226 //function : Parameter
1227 //purpose : Returns the parameter of <V> on <E>.
1228 //=======================================================================
1230 Standard_Real BRep_Tool::Parameter(const TopoDS_Vertex& V,
1231 const TopoDS_Edge& E)
1234 // Search the vertex in the edge
1236 Standard_Boolean rev = Standard_False;
1238 TopAbs_Orientation orient = TopAbs_INTERNAL;
1240 TopoDS_Iterator itv(E.Oriented(TopAbs_FORWARD));
1242 // if the edge has no vertices
1243 // and is degenerated use the vertex orientation
1246 if (!itv.More() && Degenerated(E)) {
1247 orient = V.Orientation();
1250 while (itv.More()) {
1251 const TopoDS_Shape& Vcur = itv.Value();
1252 if (V.IsSame(Vcur)) {
1257 rev = E.Orientation() == TopAbs_REVERSED;
1258 if (Vcur.Orientation() == V.Orientation()) {
1266 if (!VF.IsNull()) orient = VF.Orientation();
1270 if (orient == TopAbs_FORWARD) {
1271 BRep_Tool::Range(E,f,l);
1272 return (rev) ? l : f;
1275 else if (orient == TopAbs_REVERSED) {
1276 BRep_Tool::Range(E,f,l);
1277 return (rev) ? f : l;
1282 const Handle(Geom_Curve)& C = BRep_Tool::Curve(E,L,f,l);
1283 L = L.Predivided(V.Location());
1284 if (!C.IsNull() || Degenerated(E)) {
1285 const BRep_TVertex* TV = static_cast<const BRep_TVertex*>(V.TShape().get());
1286 BRep_ListIteratorOfListOfPointRepresentation itpr(TV->Points());
1288 while (itpr.More()) {
1289 const Handle(BRep_PointRepresentation)& pr = itpr.Value();
1290 if (pr->IsPointOnCurve(C,L)) {
1291 Standard_Real p = pr->Parameter();
1292 Standard_Real res = p;// SVV 4 nov 99 - to avoid warnings on Linux
1294 // Closed curves RLE 16 june 94
1295 if (Precision::IsNegativeInfinite(f)) return pr->Parameter();//p;
1296 if (Precision::IsPositiveInfinite(l)) return pr->Parameter();//p;
1297 gp_Pnt Pf = C->Value(f).Transformed(L.Transformation());
1298 gp_Pnt Pl = C->Value(l).Transformed(L.Transformation());
1299 Standard_Real tol = BRep_Tool::Tolerance(V);
1300 if (Pf.Distance(Pl) < tol) {
1301 if (Pf.Distance(BRep_Tool::Pnt(V)) < tol) {
1302 if (V.Orientation() == TopAbs_FORWARD) res = f;//p = f;
1303 else res = l;//p = l;
1314 // let us try with the first pcurve
1315 Handle(Geom2d_Curve) PC;
1316 Handle(Geom_Surface) S;
1317 BRep_Tool::CurveOnSurface(E,PC,S,L,f,l);
1318 L = L.Predivided(V.Location());
1319 const BRep_TVertex* TV = static_cast<const BRep_TVertex*>(V.TShape().get());
1320 BRep_ListIteratorOfListOfPointRepresentation itpr(TV->Points());
1322 while (itpr.More()) {
1323 const Handle(BRep_PointRepresentation)& pr = itpr.Value();
1324 if (pr->IsPointOnCurveOnSurface(PC,S,L)) {
1325 Standard_Real p = pr->Parameter();
1326 // Closed curves RLE 16 june 94
1327 if (PC->IsClosed()) {
1328 if ((p == PC->FirstParameter()) ||
1329 (p == PC->LastParameter())) {
1330 if (V.Orientation() == TopAbs_FORWARD) p = PC->FirstParameter();
1331 else p = PC->LastParameter();
1341 throw Standard_NoSuchObject("BRep_Tool:: no parameter on edge");
1344 //=======================================================================
1345 //function : Parameter
1346 //purpose : Returns the parameters of the vertex on the
1347 // pcurve of the edge on the face.
1348 //=======================================================================
1350 Standard_Real BRep_Tool::Parameter(const TopoDS_Vertex& V,
1351 const TopoDS_Edge& E,
1352 const TopoDS_Face& F)
1355 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,L);
1356 return BRep_Tool::Parameter(V,E,S,L);
1359 //=======================================================================
1360 //function : Parameter
1361 //purpose : Returns the parameters of the vertex on the
1362 // pcurve of the edge on the surface.
1363 //=======================================================================
1365 Standard_Real BRep_Tool::Parameter(const TopoDS_Vertex& V,
1366 const TopoDS_Edge& E,
1367 const Handle(Geom_Surface)& S,
1368 const TopLoc_Location& L)
1370 // Search the vertex in the edge
1372 Standard_Boolean rev = Standard_False;
1374 TopoDS_Iterator itv(E.Oriented(TopAbs_FORWARD));
1376 while (itv.More()) {
1377 if (V.IsSame(itv.Value())) {
1378 if (VF.IsNull()) VF = itv.Value();
1380 rev = E.Orientation() == TopAbs_REVERSED;
1381 if (itv.Value().Orientation() == V.Orientation())
1388 TopAbs_Orientation orient = TopAbs_INTERNAL;
1389 if (!VF.IsNull()) orient = VF.Orientation();
1393 if (orient == TopAbs_FORWARD) {
1394 BRep_Tool::Range(E,S,L,f,l);
1395 return (rev) ? l : f;
1398 else if (orient == TopAbs_REVERSED) {
1399 BRep_Tool::Range(E,S,L,f,l);
1400 return (rev) ? f : l;
1404 Handle(Geom2d_Curve) PC = BRep_Tool::CurveOnSurface(E,S,L,f,l);
1405 const BRep_TVertex* TV = static_cast<const BRep_TVertex*>(V.TShape().get());
1406 BRep_ListIteratorOfListOfPointRepresentation itpr(TV->Points());
1408 while (itpr.More()) {
1409 if (itpr.Value()->IsPointOnCurveOnSurface(PC,S,L))
1410 return itpr.Value()->Parameter();
1415 //----------------------------------------------------------
1418 const Handle(Geom_Curve)& C = BRep_Tool::Curve(E,L1,f,l);
1419 L1 = L1.Predivided(V.Location());
1420 if (!C.IsNull() || Degenerated(E)) {
1421 const BRep_TVertex* TV = static_cast<const BRep_TVertex*>(V.TShape().get());
1422 BRep_ListIteratorOfListOfPointRepresentation itpr(TV->Points());
1424 while (itpr.More()) {
1425 const Handle(BRep_PointRepresentation)& pr = itpr.Value();
1426 if (pr->IsPointOnCurve(C,L1)) {
1427 Standard_Real p = pr->Parameter();
1428 Standard_Real res = p;
1430 // Closed curves RLE 16 june 94
1431 if (Precision::IsNegativeInfinite(f)) return res;
1432 if (Precision::IsPositiveInfinite(l)) return res;
1433 gp_Pnt Pf = C->Value(f).Transformed(L1.Transformation());
1434 gp_Pnt Pl = C->Value(l).Transformed(L1.Transformation());
1435 Standard_Real tol = BRep_Tool::Tolerance(V);
1436 if (Pf.Distance(Pl) < tol) {
1437 if (Pf.Distance(BRep_Tool::Pnt(V)) < tol) {
1438 if (V.Orientation() == TopAbs_FORWARD) res = f;
1449 //----------------------------------------------------------
1451 throw Standard_NoSuchObject("BRep_Tool:: no parameter on edge");
1454 //=======================================================================
1455 //function : Parameters
1456 //purpose : Returns the parameters of the vertex on the face.
1457 //=======================================================================
1459 gp_Pnt2d BRep_Tool::Parameters(const TopoDS_Vertex& V,
1460 const TopoDS_Face& F)
1463 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,L);
1464 L = L.Predivided(V.Location());
1465 const BRep_TVertex* TV = static_cast<const BRep_TVertex*>(V.TShape().get());
1466 BRep_ListIteratorOfListOfPointRepresentation itpr(TV->Points());
1468 // It is checked if there is PointRepresentation (case non Manifold)
1469 while (itpr.More()) {
1470 if (itpr.Value()->IsPointOnSurface(S,L)) {
1471 return gp_Pnt2d(itpr.Value()->Parameter(),
1472 itpr.Value()->Parameter2());
1477 TopoDS_Vertex Vf,Vl;
1479 // Otherwise the edges are searched (PMN 4/06/97) It is not possible to succeed 999/1000!
1480 // even if often there is a way to make more economically than above...
1481 TopExp_Explorer exp;
1482 for (exp.Init(F, TopAbs_EDGE); exp.More(); exp.Next()) {
1483 E = TopoDS::Edge(exp.Current());
1484 TopExp::Vertices(E, Vf, Vl);
1485 if ((V.IsSame(Vf)) || (V.IsSame(Vl))) {
1487 UVPoints(E, F, Pf, Pl);
1488 if (V.IsSame(Vf)) return Pf;
1489 else return Pl;//Ambiguity (natural) for degenerated edges.
1492 throw Standard_NoSuchObject("BRep_Tool:: no parameters on surface");
1494 //=======================================================================
1495 //function : IsClosed
1497 //=======================================================================
1498 Standard_Boolean BRep_Tool::IsClosed (const TopoDS_Shape& theShape)
1500 if (theShape.ShapeType() == TopAbs_SHELL)
1502 NCollection_Map<TopoDS_Shape, TopTools_ShapeMapHasher> aMap (101, new NCollection_IncAllocator);
1503 TopExp_Explorer exp (theShape.Oriented(TopAbs_FORWARD), TopAbs_EDGE);
1504 Standard_Boolean hasBound = Standard_False;
1505 for (; exp.More(); exp.Next())
1507 const TopoDS_Edge& E = TopoDS::Edge(exp.Current());
1508 if (BRep_Tool::Degenerated(E) || E.Orientation() == TopAbs_INTERNAL || E.Orientation() == TopAbs_EXTERNAL)
1510 hasBound = Standard_True;
1514 return hasBound && aMap.IsEmpty();
1516 else if (theShape.ShapeType() == TopAbs_WIRE)
1518 NCollection_Map<TopoDS_Shape, TopTools_ShapeMapHasher> aMap (101, new NCollection_IncAllocator);
1519 TopExp_Explorer exp (theShape.Oriented(TopAbs_FORWARD), TopAbs_VERTEX);
1520 Standard_Boolean hasBound = Standard_False;
1521 for (; exp.More(); exp.Next())
1523 const TopoDS_Shape& V = exp.Current();
1524 if (V.Orientation() == TopAbs_INTERNAL || V.Orientation() == TopAbs_EXTERNAL)
1526 hasBound = Standard_True;
1530 return hasBound && aMap.IsEmpty();
1532 else if (theShape.ShapeType() == TopAbs_EDGE)
1534 TopoDS_Vertex aVFirst, aVLast;
1535 TopExp::Vertices(TopoDS::Edge(theShape), aVFirst, aVLast);
1536 return !aVFirst.IsNull() && aVFirst.IsSame(aVLast);
1538 return theShape.Closed();
1541 //modified by NIZNHY-PKV Fri Oct 17 14:09:58 2008 f
1542 //=======================================================================
1543 //function : IsPlane
1545 //=======================================================================
1546 Standard_Boolean IsPlane(const Handle(Geom_Surface)& aS)
1548 Standard_Boolean bRet;
1549 Handle(Geom_Plane) aGP;
1550 Handle(Geom_RectangularTrimmedSurface) aGRTS;
1551 Handle(Geom_OffsetSurface) aGOFS;
1553 aGRTS=Handle(Geom_RectangularTrimmedSurface)::DownCast(aS);
1554 aGOFS=Handle(Geom_OffsetSurface)::DownCast(aS);
1556 if(!aGOFS.IsNull()) {
1557 aGP=Handle(Geom_Plane)::DownCast(aGOFS->BasisSurface());
1559 else if(!aGRTS.IsNull()) {
1560 aGP=Handle(Geom_Plane)::DownCast(aGRTS->BasisSurface());
1563 aGP=Handle(Geom_Plane)::DownCast(aS);
1571 //=======================================================================
1572 //function : MaxTolerance
1574 //=======================================================================
1575 Standard_Real BRep_Tool::MaxTolerance (const TopoDS_Shape& theShape,
1576 const TopAbs_ShapeEnum theSubShape)
1578 Standard_Real aTol = 0.0;
1580 // Explorer Shape-Subshape.
1581 TopExp_Explorer anExpSS(theShape, theSubShape);
1582 if (theSubShape == TopAbs_FACE)
1584 for( ; anExpSS.More() ; anExpSS.Next() )
1586 const TopoDS_Shape& aCurrentSubShape = anExpSS.Current();
1587 aTol = Max(aTol, Tolerance(TopoDS::Face(aCurrentSubShape)));
1590 else if (theSubShape == TopAbs_EDGE)
1592 for( ; anExpSS.More() ; anExpSS.Next() )
1594 const TopoDS_Shape& aCurrentSubShape = anExpSS.Current();
1595 aTol = Max(aTol, Tolerance(TopoDS::Edge(aCurrentSubShape)));
1598 else if (theSubShape == TopAbs_VERTEX)
1600 for( ; anExpSS.More() ; anExpSS.Next() )
1602 const TopoDS_Shape& aCurrentSubShape = anExpSS.Current();
1603 aTol = Max(aTol, Tolerance(TopoDS::Vertex(aCurrentSubShape)));