1 // Copyright (C) 2014-2022 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "GeomAlgoAPI_ShapeTools.h"
22 #include "GeomAlgoAPI_SketchBuilder.h"
24 #include <Basics_OCCTVersion.hxx>
26 #include <GeomAPI_Ax1.h>
27 #include <GeomAPI_Edge.h>
28 #include <GeomAPI_Dir.h>
29 #include <GeomAPI_Face.h>
30 #include <GeomAPI_Pln.h>
31 #include <GeomAPI_Pnt.h>
32 #include <GeomAPI_Wire.h>
34 #include <Approx_CurvilinearParameter.hxx>
36 #include <Bnd_Box.hxx>
38 #include <BRep_Tool.hxx>
39 #include <BRep_Builder.hxx>
40 #include <BRepAlgo.hxx>
41 #include <BRepAlgo_FaceRestrictor.hxx>
42 #include <BRepAdaptor_Curve.hxx>
43 #include <BRepBndLib.hxx>
44 #include <BRepBuilderAPI_Copy.hxx>
45 #include <BRepBuilderAPI_FindPlane.hxx>
46 #include <BRepBuilderAPI_MakeEdge.hxx>
47 #include <BRepBuilderAPI_MakeFace.hxx>
48 #include <BRepBuilderAPI_MakeVertex.hxx>
49 #include <BRepBuilderAPI_MakeWire.hxx>
50 #include <BRepCheck_Analyzer.hxx>
51 #include <BRepExtrema_DistShapeShape.hxx>
52 #include <BRepExtrema_ExtCF.hxx>
53 #include <BRepExtrema_ShapeProximity.hxx>
54 #include <BRepGProp.hxx>
55 #include <BRepMesh_IncrementalMesh.hxx>
56 #include <BRepTools.hxx>
57 #include <BRepTools_WireExplorer.hxx>
58 #include <BRepTopAdaptor_FClass2d.hxx>
59 #include <BRepClass_FaceClassifier.hxx>
60 #include <BRepLib_CheckCurveOnSurface.hxx>
61 #include <BRepLProp.hxx>
63 #include <BOPAlgo_Builder.hxx>
65 #include <Extrema_GenLocateExtCS.hxx>
66 #include <Extrema_GenLocateExtSS.hxx>
67 #include <Extrema_GenLocateExtPS.hxx>
68 #include <Extrema_LocateExtCC.hxx>
69 #include <Extrema_LocateExtPC.hxx>
71 #include <Geom2d_Curve.hxx>
72 #include <Geom2d_Curve.hxx>
74 #include <Geom_BSplineCurve.hxx>
75 #include <Geom_CylindricalSurface.hxx>
76 #include <Geom_Line.hxx>
77 #include <Geom_Plane.hxx>
78 #include <Geom_RectangularTrimmedSurface.hxx>
80 #if OCC_VERSION_LARGE < 0x07070000
81 #include <GeomAdaptor_HCurve.hxx>
83 #include <GeomAdaptor_Curve.hxx>
86 #include <GeomAPI_ProjectPointOnCurve.hxx>
87 #include <GeomAPI_ShapeIterator.h>
89 #include <GeomLib_IsPlanarSurface.hxx>
90 #include <GeomLib_Tool.hxx>
91 #include <GeomAPI_IntCS.hxx>
94 #include <GProp_GProps.hxx>
96 #include <IntAna_IntConicQuad.hxx>
97 #include <IntAna_Quadric.hxx>
99 #include <ShapeAnalysis.hxx>
100 #include <ShapeAnalysis_Surface.hxx>
102 #include <TopoDS.hxx>
103 #include <TopoDS_Edge.hxx>
104 #include <TopoDS_Face.hxx>
105 #include <TopoDS_Shape.hxx>
106 #include <TopoDS_Shell.hxx>
107 #include <TopoDS_Vertex.hxx>
108 #include <TopoDS_Builder.hxx>
110 #include <TopExp.hxx>
111 #include <TopExp_Explorer.hxx>
113 #include <TopTools_ListIteratorOfListOfShape.hxx>
115 #include <NCollection_Vector.hxx>
117 #include <LocalAnalysis_SurfaceContinuity.hxx>
120 //==================================================================================================
121 static GProp_GProps props(const TopoDS_Shape& theShape)
123 GProp_GProps aGProps;
125 if (theShape.ShapeType() == TopAbs_EDGE || theShape.ShapeType() == TopAbs_WIRE)
127 BRepGProp::LinearProperties(theShape, aGProps);
129 else if (theShape.ShapeType() == TopAbs_FACE || theShape.ShapeType() == TopAbs_SHELL)
131 const Standard_Real anEps = 1.e-6;
132 BRepGProp::SurfaceProperties(theShape, aGProps, anEps);
134 else if (theShape.ShapeType() == TopAbs_SOLID || theShape.ShapeType() == TopAbs_COMPSOLID)
136 BRepGProp::VolumeProperties(theShape, aGProps);
138 else if (theShape.ShapeType() == TopAbs_COMPOUND)
140 for (TopoDS_Iterator anIt(theShape); anIt.More(); anIt.Next())
142 aGProps.Add(props(anIt.Value()));
149 //==================================================================================================
150 double GeomAlgoAPI_ShapeTools::length(const std::shared_ptr<GeomAPI_Shape> theShape)
152 GProp_GProps aGProps;
153 if (!theShape.get()) {
156 const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>();
157 if (aShape.IsNull()) {
161 BRepGProp::LinearProperties(aShape, aGProps, Standard_True);
162 return aGProps.Mass();
165 //==================================================================================================
166 double GeomAlgoAPI_ShapeTools::volume(const std::shared_ptr<GeomAPI_Shape> theShape)
168 if (!theShape.get()) {
171 const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>();
172 if (aShape.IsNull()) {
175 const Standard_Real anEps = 1.e-6;
176 double aVolume = 0.0;
177 for (TopExp_Explorer anExp(aShape, TopAbs_SOLID); anExp.More(); anExp.Next()) {
178 GProp_GProps aGProps;
179 BRepGProp::VolumeProperties(anExp.Current(), aGProps, anEps);
180 aVolume += aGProps.Mass();
185 //==================================================================================================
186 double GeomAlgoAPI_ShapeTools::area (const std::shared_ptr<GeomAPI_Shape> theShape)
188 GProp_GProps aGProps;
189 if (!theShape.get()) {
192 const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>();
193 if (aShape.IsNull()) {
196 const Standard_Real anEps = 1.e-6;
198 BRepGProp::SurfaceProperties(aShape, aGProps, anEps);
199 return aGProps.Mass();
202 //==================================================================================================
203 bool GeomAlgoAPI_ShapeTools::isContinuousFaces(const GeomShapePtr& theFace1,
204 const GeomShapePtr& theFace2,
205 const GeomPointPtr& thePoint,
206 const double & theAngle,
207 std::string& theError)
211 std::cout << "isContinuousFaces " << std::endl;
214 if (!thePoint.get()) {
215 theError = "isContinuousFaces : An invalid argument";
218 const gp_Pnt& aPoint = thePoint->impl<gp_Pnt>();
220 // Getting base shape.
221 if (!theFace1.get()) {
222 theError = "isContinuousFaces : An invalid argument";
226 TopoDS_Shape aShape1 = theFace1->impl<TopoDS_Shape>();
228 if (aShape1.IsNull()) {
229 theError = "isContinuousFaces : An invalid argument";
233 // Getting base shape.
234 if (!theFace2.get()) {
235 theError = "isContinuousFaces : An invalid argument";
239 TopoDS_Shape aShape2 = theFace2->impl<TopoDS_Shape>();
241 if (aShape2.IsNull()) {
242 theError = "isContinuousFaces : An invalid argument";
246 TopoDS_Face aFace1 = TopoDS::Face(aShape1);
247 if (aFace1.IsNull()) {
248 theError = "isContinuousFaces : An invalid argument";
252 Handle(Geom_Surface) aSurf1 = BRep_Tool::Surface(aFace1);
253 if (aSurf1.IsNull()) {
254 theError = "isContinuousFaces : An invalid surface";
258 ShapeAnalysis_Surface aSAS1(aSurf1);
259 gp_Pnt2d aPointOnFace1 = aSAS1.ValueOfUV(aPoint, Precision::Confusion());
261 TopoDS_Face aFace2 = TopoDS::Face(aShape2);
262 if (aFace2.IsNull()) {
263 theError = "isContinuousFaces : An invalid argument";
267 Handle(Geom_Surface) aSurf2 = BRep_Tool::Surface(aFace2);
268 if (aSurf2.IsNull()) {
269 theError = "isContinuousFaces : An invalid surface";
273 ShapeAnalysis_Surface aSAS2(aSurf2);
274 gp_Pnt2d aPointOnFace2= aSAS2.ValueOfUV(aPoint, Precision::Confusion());
279 LocalAnalysis_SurfaceContinuity aLocAnal(aSurf1,
285 GeomAbs_Shape::GeomAbs_G1, // Order
290 theAngle * M_PI / 180.0); //EpsG1
291 aRes = aLocAnal.IsG1();
293 catch (Standard_Failure const& anException) {
294 theError = "LocalAnalysis_SurfaceContinuity error :";
295 theError += anException.GetMessageString();
301 //==================================================================================================
302 std::shared_ptr<GeomAPI_Pnt>
303 GeomAlgoAPI_ShapeTools::centreOfMass(const std::shared_ptr<GeomAPI_Shape> theShape)
305 GProp_GProps aGProps;
307 return std::shared_ptr<GeomAPI_Pnt>();
309 const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>();
310 if (aShape.IsNull()) {
311 return std::shared_ptr<GeomAPI_Pnt>();
314 if (aShape.ShapeType() == TopAbs_VERTEX) {
315 aCentre = BRep_Tool::Pnt(TopoDS::Vertex(aShape));
317 aGProps = props(aShape);
318 aCentre = aGProps.CentreOfMass();
321 return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aCentre.X(), aCentre.Y(), aCentre.Z()));
324 //==================================================================================================
325 double GeomAlgoAPI_ShapeTools::radius(const std::shared_ptr<GeomAPI_Face>& theCylinder)
327 double aRadius = -1.0;
328 if (theCylinder->isCylindrical()) {
329 const TopoDS_Shape& aShape = theCylinder->impl<TopoDS_Shape>();
330 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(TopoDS::Face(aShape));
331 Handle(Geom_CylindricalSurface) aCyl = Handle(Geom_CylindricalSurface)::DownCast(aSurf);
333 aRadius = aCyl->Radius();
338 //==================================================================================================
341 auto getExtemaDistShape = [](const GeomShapePtr& theShape1,
342 const GeomShapePtr& theShape2) -> BRepExtrema_DistShapeShape
344 const TopoDS_Shape& aShape1 = theShape1->impl<TopoDS_Shape>();
345 const TopoDS_Shape& aShape2 = theShape2->impl<TopoDS_Shape>();
347 BRepExtrema_DistShapeShape aDist(aShape1, aShape2);
352 static void tessellateShape(const TopoDS_Shape& theShape)
354 Standard_Boolean isTessellate = Standard_False;
355 TopLoc_Location aLoc;
356 for (TopExp_Explorer anExp(theShape, TopAbs_FACE); anExp.More() && !isTessellate; anExp.Next()) {
357 Handle(Poly_Triangulation) aTria = BRep_Tool::Triangulation(TopoDS::Face(anExp.Value()), aLoc);
358 isTessellate = aTria.IsNull();
360 for (TopExp_Explorer anExp(theShape, TopAbs_EDGE); anExp.More() && !isTessellate; anExp.Next()) {
361 Handle(Poly_Polygon3D) aPoly = BRep_Tool::Polygon3D(TopoDS::Edge(anExp.Value()), aLoc);
362 isTessellate = aPoly.IsNull();
366 BRepMesh_IncrementalMesh aMesher(theShape, 0.1);
367 Standard_ProgramError_Raise_if(!aMesher.IsDone(), "Meshing failed");
371 static Standard_Real paramOnCurve(const BRepAdaptor_Curve& theCurve,
372 const gp_Pnt& thePoint,
373 const Standard_Real theTol)
375 Extrema_ExtPC aParamSearch(thePoint,
377 theCurve.FirstParameter(),
378 theCurve.LastParameter());
379 if (aParamSearch.IsDone()) {
380 Standard_Integer anIndMin = 0, aNbExt = aParamSearch.NbExt();
381 Standard_Real aSqDistMin = RealLast();
382 for (Standard_Integer i = 1; i <= aNbExt; ++i) {
383 if (aParamSearch.SquareDistance(i) < aSqDistMin) {
385 aSqDistMin = aParamSearch.SquareDistance(i);
388 if (anIndMin != 0 && aSqDistMin <= theTol * theTol)
389 return aParamSearch.Point(anIndMin).Parameter();
391 return 0.5 * (theCurve.FirstParameter() + theCurve.LastParameter());
394 static void paramsOnSurf(const BRepAdaptor_Surface& theSurf,
395 const gp_Pnt& thePoint,
396 const Standard_Real theTol,
400 Extrema_ExtPS aParamSearch(thePoint, theSurf, Precision::PConfusion(), Precision::PConfusion());
401 if (aParamSearch.IsDone()) {
402 Standard_Integer anIndMin = 0, aNbExt = aParamSearch.NbExt();
403 Standard_Real aSqDistMin = RealLast();
404 for (Standard_Integer i = 1; i <= aNbExt; ++i) {
405 if (aParamSearch.SquareDistance(i) < aSqDistMin) {
407 aSqDistMin = aParamSearch.SquareDistance(i);
410 if (anIndMin != 0 && aSqDistMin <= theTol * theTol)
411 return aParamSearch.Point(anIndMin).Parameter(theU, theV);
413 theU = 0.5 * (theSurf.FirstUParameter() + theSurf.LastUParameter());
414 theV = 0.5 * (theSurf.FirstVParameter() + theSurf.LastVParameter());
417 static Standard_Real extremaEE(const TopoDS_Edge& theEdge1,
418 const TopoDS_Edge& theEdge2,
419 const gp_Pnt& thePoint1,
420 const gp_Pnt& thePoint2)
422 BRepAdaptor_Curve aCurve1(theEdge1);
423 BRepAdaptor_Curve aCurve2(theEdge2);
425 Standard_Real aU1 = paramOnCurve(aCurve1, thePoint1, BRep_Tool::Tolerance(theEdge1));
426 Standard_Real aU2 = paramOnCurve(aCurve2, thePoint2, BRep_Tool::Tolerance(theEdge2));
428 Standard_Real aValue = -1.0;
429 Extrema_LocateExtCC anExtr(aCurve1, aCurve2, aU1, aU2);
430 if (anExtr.IsDone() && aValue > Precision::Confusion())
431 aValue = Sqrt(anExtr.SquareDistance());
435 static Standard_Real extremaPE(const gp_Pnt& thePoint,
436 const TopoDS_Edge& theEdge,
437 gp_Pnt& thePointOnEdge)
439 BRepAdaptor_Curve aCurve (theEdge);
441 TopLoc_Location aLoc;
442 Standard_Real aTol = BRep_Tool::Tolerance(theEdge);
443 Handle(Poly_Polygon3D) aPoly = BRep_Tool::Polygon3D (theEdge, aLoc);
445 aTol = Max (aTol, aPoly->Deflection());
447 Standard_Real aParam = paramOnCurve (aCurve, thePointOnEdge, 2*aTol);
449 Standard_Real aValue = -1.0;
450 Extrema_LocateExtPC anExtr (thePoint, aCurve, aParam, Precision::PConfusion());
453 aValue = Sqrt(anExtr.SquareDistance());
455 Extrema_POnCurv aPointOnCurve = anExtr.Point();
456 thePointOnEdge = aPointOnCurve.Value();
461 static Standard_Real extremaPF(const gp_Pnt& thePoint,
462 const TopoDS_Face& theFace,
463 gp_Pnt& thePointOnFace)
465 BRepAdaptor_Surface aSurf (theFace);
467 TopLoc_Location aLoc;
468 Standard_Real aTol = BRep_Tool::Tolerance(theFace);
469 Handle(Poly_Triangulation) aTria = BRep_Tool::Triangulation (theFace, aLoc);
471 aTol = Max (aTol, aTria->Deflection());
473 Standard_Real aU, aV;
474 paramsOnSurf(aSurf, thePointOnFace, 2*aTol, aU, aV);
476 Standard_Real aValue = -1.0;
477 Extrema_GenLocateExtPS anExtr (aSurf);
478 anExtr.Perform (thePoint, aU, aV);
481 aValue = Sqrt(anExtr.SquareDistance());
483 Extrema_POnSurf aPointOnSurf = anExtr.Point();
484 thePointOnFace = aPointOnSurf.Value();
489 static Standard_Real extremaEF(const TopoDS_Edge& theEdge,
490 const TopoDS_Face& theFace,
491 const gp_Pnt& thePonE,
492 const gp_Pnt& thePonF)
494 BRepAdaptor_Curve aCurve(theEdge);
495 BRepAdaptor_Surface aSurf(theFace);
497 Standard_Real aP = paramOnCurve(aCurve, thePonE, BRep_Tool::Tolerance(theEdge));
498 Standard_Real aU, aV;
499 paramsOnSurf(aSurf, thePonF, BRep_Tool::Tolerance(theFace), aU, aV);
501 Standard_Real aValue = -1.0;
502 Extrema_GenLocateExtCS anExtr(aCurve, aSurf, aP, aU, aV, Precision::PConfusion(), Precision::PConfusion());
503 if (anExtr.IsDone() && aValue > Precision::Confusion())
504 aValue = Sqrt(anExtr.SquareDistance());
508 static Standard_Real extremaFF(const TopoDS_Face& theFace1,
509 const TopoDS_Face& theFace2,
510 const gp_Pnt& thePoint1,
511 const gp_Pnt& thePoint2)
513 BRepAdaptor_Surface aSurf1(theFace1);
514 BRepAdaptor_Surface aSurf2(theFace2);
516 Standard_Real aU1, aV1;
517 paramsOnSurf(aSurf1, thePoint1, BRep_Tool::Tolerance(theFace1), aU1, aV1);
518 Standard_Real aU2, aV2;
519 paramsOnSurf(aSurf2, thePoint2, BRep_Tool::Tolerance(theFace2), aU2, aV2);
521 Standard_Real aValue = -1.0;
522 Extrema_GenLocateExtSS anExtr(aSurf1, aSurf2, aU1, aV1, aU2, aV2, Precision::PConfusion(), Precision::PConfusion());
523 if (anExtr.IsDone() && aValue > Precision::Confusion())
524 aValue = Sqrt(anExtr.SquareDistance());
530 double GeomAlgoAPI_ShapeTools::minimalDistance(const GeomShapePtr& theShape1,
531 const GeomShapePtr& theShape2)
533 BRepExtrema_DistShapeShape aDist = getExtemaDistShape(theShape1, theShape2);
534 return aDist.IsDone() ? aDist.Value() : Precision::Infinite();
537 double GeomAlgoAPI_ShapeTools::minimalDistance(const GeomShapePtr& theShape1,
538 const GeomShapePtr& theShape2,
539 std::array<double, 3> & fromShape1To2)
541 BRepExtrema_DistShapeShape aDist = getExtemaDistShape(theShape1, theShape2);
542 const auto & pt1 = aDist.PointOnShape1(1);
543 const auto & pt2 = aDist.PointOnShape2(1) ;
544 fromShape1To2[0] = pt2.X() - pt1.X();
545 fromShape1To2[1] = pt2.Y() - pt1.Y();
546 fromShape1To2[2] = pt2.Z() - pt1.Z();
547 return aDist.IsDone() ? aDist.Value() : Precision::Infinite();
550 //==================================================================================================
551 double GeomAlgoAPI_ShapeTools::shapeProximity(const GeomShapePtr& theShape1,
552 const GeomShapePtr& theShape2)
554 double aResult = -1.0;
555 if (!theShape1.get() || !theShape2.get())
558 const TopoDS_Shape& aShape1 = theShape1->impl<TopoDS_Shape>();
559 const TopoDS_Shape& aShape2 = theShape2->impl<TopoDS_Shape>();
561 TopAbs_ShapeEnum aType1 = aShape1.ShapeType();
562 TopAbs_ShapeEnum aType2 = aShape2.ShapeType();
564 // tessellate shapes if there is no mesh exists
565 tessellateShape(aShape1);
566 tessellateShape(aShape2);
568 BRepExtrema_ShapeProximity aDist (aShape1, aShape2);
570 if (aDist.IsDone()) {
571 aResult = aDist.Proximity();
574 gp_Pnt aPnt1 = aDist.ProximityPoint1();
575 gp_Pnt aPnt2 = aDist.ProximityPoint2();
577 BRepExtrema_ProximityDistTool::ProxPnt_Status aStatus1 = aDist.ProxPntStatus1();
578 BRepExtrema_ProximityDistTool::ProxPnt_Status aStatus2 = aDist.ProxPntStatus2();
580 double aValue = -1.0;
582 if (aType1 == TopAbs_EDGE)
584 if (aType2 == TopAbs_EDGE)
586 if (aStatus1 == BRepExtrema_ProximityDistTool::ProxPnt_Status_MIDDLE &&
587 aStatus2 == BRepExtrema_ProximityDistTool::ProxPnt_Status_MIDDLE)
589 aValue = extremaEE(TopoDS::Edge(aShape1), TopoDS::Edge(aShape2), aPnt1, aPnt2);
591 else if (aStatus1 == BRepExtrema_ProximityDistTool::ProxPnt_Status_BORDER &&
592 aStatus2 == BRepExtrema_ProximityDistTool::ProxPnt_Status_MIDDLE)
594 aValue = extremaPE(aPnt1, TopoDS::Edge(aShape2), aPnt2);
596 else if (aStatus1 == BRepExtrema_ProximityDistTool::ProxPnt_Status_MIDDLE &&
597 aStatus2 == BRepExtrema_ProximityDistTool::ProxPnt_Status_BORDER)
599 aValue = extremaPE(aPnt2, TopoDS::Edge(aShape1), aPnt1);
602 else if (aType2 == TopAbs_FACE)
604 if (aStatus1 == BRepExtrema_ProximityDistTool::ProxPnt_Status_MIDDLE &&
605 aStatus2 == BRepExtrema_ProximityDistTool::ProxPnt_Status_MIDDLE)
607 aValue = extremaEF(TopoDS::Edge(aShape1), TopoDS::Face(aShape2), aPnt1, aPnt2);
609 else if (aStatus1 == BRepExtrema_ProximityDistTool::ProxPnt_Status_BORDER &&
610 aStatus2 == BRepExtrema_ProximityDistTool::ProxPnt_Status_MIDDLE)
612 aValue = extremaPF(aPnt1, TopoDS::Face(aShape2), aPnt2);
614 else if (aStatus1 == BRepExtrema_ProximityDistTool::ProxPnt_Status_MIDDLE &&
615 aStatus2 == BRepExtrema_ProximityDistTool::ProxPnt_Status_BORDER)
617 aValue = extremaPE(aPnt2, TopoDS::Edge(aShape1), aPnt1);
621 else if (aType1 == TopAbs_FACE)
623 if (aType2 == TopAbs_EDGE)
625 if (aStatus1 == BRepExtrema_ProximityDistTool::ProxPnt_Status_MIDDLE &&
626 aStatus2 == BRepExtrema_ProximityDistTool::ProxPnt_Status_MIDDLE)
628 aValue = extremaEF(TopoDS::Edge(aShape2), TopoDS::Face(aShape1), aPnt2, aPnt1);
630 else if (aStatus1 == BRepExtrema_ProximityDistTool::ProxPnt_Status_BORDER &&
631 aStatus2 == BRepExtrema_ProximityDistTool::ProxPnt_Status_MIDDLE)
633 aValue = extremaPE(aPnt1, TopoDS::Edge(aShape2), aPnt2);
635 else if (aStatus1 == BRepExtrema_ProximityDistTool::ProxPnt_Status_MIDDLE &&
636 aStatus2 == BRepExtrema_ProximityDistTool::ProxPnt_Status_BORDER)
638 aValue = extremaPF(aPnt2, TopoDS::Face(aShape1), aPnt1);
641 else if (aType2 == TopAbs_FACE)
643 if (aStatus1 == BRepExtrema_ProximityDistTool::ProxPnt_Status_MIDDLE &&
644 aStatus2 == BRepExtrema_ProximityDistTool::ProxPnt_Status_MIDDLE)
646 aValue = extremaFF(TopoDS::Face(aShape1), TopoDS::Face(aShape2), aPnt1, aPnt2);
648 else if (aStatus1 == BRepExtrema_ProximityDistTool::ProxPnt_Status_BORDER &&
649 aStatus2 == BRepExtrema_ProximityDistTool::ProxPnt_Status_MIDDLE)
651 aValue = extremaPF(aPnt1, TopoDS::Face(aShape2), aPnt2);
653 else if (aStatus1 == BRepExtrema_ProximityDistTool::ProxPnt_Status_MIDDLE &&
654 aStatus2 == BRepExtrema_ProximityDistTool::ProxPnt_Status_BORDER)
656 aValue = extremaPF(aPnt2, TopoDS::Face(aShape1), aPnt1);
667 //==================================================================================================
668 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeTools::combineShapes(
669 const std::shared_ptr<GeomAPI_Shape> theCompound,
670 const GeomAPI_Shape::ShapeType theType,
671 ListOfShape& theResuts)
674 ListOfShape aResCombinedShapes;
675 ListOfShape aResFreeShapes;
677 GeomShapePtr aResult = theCompound;
679 if (!theCompound.get()) {
683 if (theType != GeomAPI_Shape::SHELL && theType != GeomAPI_Shape::COMPSOLID) {
687 TopAbs_ShapeEnum aTS = TopAbs_EDGE;
688 TopAbs_ShapeEnum aTA = TopAbs_FACE;
689 if (theType == GeomAPI_Shape::COMPSOLID) {
694 // map from the resulting shapes to minimal index of the used shape from theCompound list
695 std::map<GeomShapePtr, int> anInputOrder;
696 // map from ancestors-shapes to the index of shapes in theCompound
697 NCollection_DataMap<TopoDS_Shape, int> anAncestorsOrder;
701 const TopoDS_Shape& aShapesComp = theCompound->impl<TopoDS_Shape>();
702 for (TopoDS_Iterator anIter(aShapesComp); anIter.More(); anIter.Next(), anOrder++) {
703 const TopoDS_Shape& aShape = anIter.Value();
704 if (aShape.ShapeType() > aTA) {
705 std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
706 aGeomShape->setImpl<TopoDS_Shape>(new TopoDS_Shape(aShape));
707 aResFreeShapes.push_back(aGeomShape);
708 anInputOrder[aGeomShape] = anOrder;
710 for (TopExp_Explorer anExp(aShape, aTA); anExp.More(); anExp.Next()) {
711 anAncestorsOrder.Bind(anExp.Current(), anOrder);
716 // Map sub-shapes and shapes.
717 TopTools_IndexedDataMapOfShapeListOfShape aMapSA;
718 TopExp::MapShapesAndAncestors(aShapesComp, aTS, aTA, aMapSA);
719 if (aMapSA.IsEmpty()) {
724 // Get all shapes with common sub-shapes and free shapes.
725 NCollection_Map<TopoDS_Shape> aFreeShapes;
726 NCollection_Vector<NCollection_Map<TopoDS_Shape>> aShapesWithCommonSubshapes;
727 for (TopTools_IndexedDataMapOfShapeListOfShape::Iterator
728 anIter(aMapSA); anIter.More(); anIter.Next()) {
729 TopTools_ListOfShape& aListOfShape = anIter.ChangeValue();
730 if (aListOfShape.IsEmpty()) {
733 else if (aListOfShape.Size() == 1) {
734 const TopoDS_Shape& aF = aListOfShape.First();
736 aListOfShape.Clear();
738 NCollection_List<TopoDS_Shape> aTempList;
739 NCollection_Map<TopoDS_Shape> aTempMap;
740 for (TopTools_ListOfShape::Iterator aListIt(aListOfShape); aListIt.More(); aListIt.Next()) {
741 aTempList.Append(aListIt.Value());
742 aTempMap.Add(aListIt.Value());
743 aFreeShapes.Remove(aListIt.Value());
745 aListOfShape.Clear();
746 for (NCollection_List<TopoDS_Shape>::Iterator
747 aTempIter(aTempList); aTempIter.More(); aTempIter.Next()) {
748 const TopoDS_Shape& aTempShape = aTempIter.Value();
749 for (TopTools_IndexedDataMapOfShapeListOfShape::Iterator
750 anIter2(aMapSA); anIter2.More(); anIter2.Next()) {
751 TopTools_ListOfShape& aTempListOfShape = anIter2.ChangeValue();
752 if (aTempListOfShape.IsEmpty()) {
754 } else if (aTempListOfShape.Size() == 1 && aTempListOfShape.First() == aTempShape) {
755 aTempListOfShape.Clear();
756 } else if (aTempListOfShape.Size() > 1) {
757 TopTools_ListOfShape::Iterator anIt1(aTempListOfShape);
758 for (; anIt1.More(); anIt1.Next()) {
759 if (anIt1.Value() == aTempShape) {
760 TopTools_ListOfShape::Iterator anIt2(aTempListOfShape);
761 for (; anIt2.More(); anIt2.Next())
763 if (anIt2.Value() != anIt1.Value()) {
764 if (aTempMap.Add(anIt2.Value())) {
765 aTempList.Append(anIt2.Value());
766 aFreeShapes.Remove(anIt2.Value());
770 aTempListOfShape.Clear();
777 aShapesWithCommonSubshapes.Append(aTempMap);
781 // Combine shapes with common sub-shapes.
782 for (NCollection_Vector<NCollection_Map<TopoDS_Shape>>::Iterator
783 anIter(aShapesWithCommonSubshapes); anIter.More(); anIter.Next()) {
785 TopoDS_CompSolid aCSolid;
786 TopoDS_Builder aBuilder;
789 GeomAPI_Shape::COMPSOLID ? aBuilder.MakeCompSolid(aCSolid) : aBuilder.MakeShell(aShell);
790 NCollection_Map<TopoDS_Shape>& aShapesMap = anIter.ChangeValue();
791 for (TopExp_Explorer anExp(aShapesComp, aTA); anExp.More(); anExp.Next()) {
792 const TopoDS_Shape& aShape = anExp.Current();
793 if (aShapesMap.Contains(aShape)) {
795 GeomAPI_Shape::COMPSOLID ? aBuilder.Add(aCSolid, aShape) : aBuilder.Add(aShell, aShape);
796 aShapesMap.Remove(aShape);
797 int aThisOrder = anAncestorsOrder.Find(aShape);
798 if (anOrder == -1 || aThisOrder < anOrder)
799 anOrder = aThisOrder; // take the minimum order position
802 std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
803 TopoDS_Shape* aSh = theType == GeomAPI_Shape::COMPSOLID ? new TopoDS_Shape(aCSolid) :
804 new TopoDS_Shape(aShell);
805 aGeomShape->setImpl<TopoDS_Shape>(aSh);
806 aResCombinedShapes.push_back(aGeomShape);
807 anInputOrder[aGeomShape] = anOrder;
810 // Adding free shapes.
811 for (TopExp_Explorer anExp(aShapesComp, aTA); anExp.More(); anExp.Next()) {
812 const TopoDS_Shape& aShape = anExp.Current();
813 if (aFreeShapes.Contains(aShape)) {
814 std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
815 aGeomShape->setImpl<TopoDS_Shape>(new TopoDS_Shape(aShape));
816 aResFreeShapes.push_back(aGeomShape);
817 anInputOrder[aGeomShape] = anAncestorsOrder.Find(aShape);
821 if (aResCombinedShapes.size() == 1 && aResFreeShapes.size() == 0) {
822 aResult = aResCombinedShapes.front();
823 theResuts.push_back(aResult);
824 } else if (aResCombinedShapes.size() == 0 && aResFreeShapes.size() == 1) {
825 aResult = aResFreeShapes.front();
826 theResuts.push_back(aResult);
828 TopoDS_Compound aResultComp;
829 TopoDS_Builder aBuilder;
830 aBuilder.MakeCompound(aResultComp);
831 // put to result compound and result list in accordance to the order numbers
832 std::map<GeomShapePtr, int>::iterator anInputIter = anInputOrder.begin();
833 std::map<int, GeomShapePtr> aNums;
834 for (; anInputIter != anInputOrder.end(); anInputIter++)
835 aNums[anInputIter->second] = anInputIter->first;
836 std::map<int, GeomShapePtr>::iterator aNumsIter = aNums.begin();
837 for (; aNumsIter != aNums.end(); aNumsIter++) {
838 aBuilder.Add(aResultComp, (aNumsIter->second)->impl<TopoDS_Shape>());
839 theResuts.push_back(aNumsIter->second);
841 aResult->setImpl(new TopoDS_Shape(aResultComp));
847 //==================================================================================================
848 static void addSimpleShapeToList(const TopoDS_Shape& theShape,
849 NCollection_List<TopoDS_Shape>& theList)
851 if (theShape.IsNull()) {
855 if (theShape.ShapeType() == TopAbs_COMPOUND) {
856 for (TopoDS_Iterator anIt(theShape); anIt.More(); anIt.Next()) {
857 addSimpleShapeToList(anIt.Value(), theList);
860 theList.Append(theShape);
864 //==================================================================================================
865 static TopoDS_Compound makeCompound(const NCollection_List<TopoDS_Shape> theShapes)
867 TopoDS_Compound aCompound;
869 BRep_Builder aBuilder;
870 aBuilder.MakeCompound(aCompound);
872 for (NCollection_List<TopoDS_Shape>::Iterator anIt(theShapes); anIt.More(); anIt.Next()) {
873 aBuilder.Add(aCompound, anIt.Value());
879 //==================================================================================================
880 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeTools::groupSharedTopology(
881 const std::shared_ptr<GeomAPI_Shape> theCompound)
883 GeomShapePtr aResult = theCompound;
885 if (!theCompound.get()) {
889 TopoDS_Shape anInShape = aResult->impl<TopoDS_Shape>();
890 NCollection_List<TopoDS_Shape> anUngroupedShapes, aStillUngroupedShapes;
891 addSimpleShapeToList(anInShape, anUngroupedShapes);
893 // Iterate over all shapes and find shapes with shared vertices.
894 TopTools_ListOfShape allVertices;
895 TopTools_DataMapOfShapeListOfShape aVertexShapesMap;
896 for (NCollection_List<TopoDS_Shape>::Iterator aShapesIt(anUngroupedShapes);
899 const TopoDS_Shape& aShape = aShapesIt.Value();
900 for (TopExp_Explorer aShapeExp(aShape, TopAbs_VERTEX);
903 const TopoDS_Shape& aVertex = aShapeExp.Current();
904 if (!aVertexShapesMap.IsBound(aVertex)) {
905 NCollection_List<TopoDS_Shape> aList;
906 aList.Append(aShape);
907 allVertices.Append(aVertex);
908 aVertexShapesMap.Bind(aVertex, aList);
911 if (!aVertexShapesMap.ChangeFind(aVertex).Contains(aShape)) {
912 aVertexShapesMap.ChangeFind(aVertex).Append(aShape);
918 // Iterate over the map and group shapes.
919 NCollection_Vector<TopTools_MapOfShape> aGroups; // groups of shapes connected by vertices
920 while (!allVertices.IsEmpty()) {
921 // Get first group of shapes in map, and then unbind it.
922 const TopoDS_Shape& aKey = allVertices.First();
923 TopTools_ListOfShape aConnectedShapes = aVertexShapesMap.Find(aKey);
924 aVertexShapesMap.UnBind(aKey);
925 allVertices.Remove(aKey);
926 // Iterate over shapes in this group and add to it shapes from groups in map.
927 for (TopTools_ListOfShape::Iterator aConnectedIt(aConnectedShapes);
928 aConnectedIt.More(); aConnectedIt.Next()) {
929 const TopoDS_Shape& aConnected = aConnectedIt.Value();
930 TopTools_ListOfShape aKeysToUnbind;
931 for (TopTools_ListOfShape::Iterator aKeysIt(allVertices);
934 const TopTools_ListOfShape& anOtherConnected = aVertexShapesMap(aKeysIt.Value());
935 if (!anOtherConnected.Contains(aConnected)) {
936 // Other connected group does not contain shape from our connected group
939 // Other is connected to our, so add them to our connected
940 for (TopTools_ListOfShape::Iterator anOtherIt(anOtherConnected);
943 const TopoDS_Shape& aShape = anOtherIt.Value();
944 if (!aConnectedShapes.Contains(aShape)) {
945 aConnectedShapes.Append(aShape);
948 // Save key to unbind from this map.
949 aKeysToUnbind.Append(aKeysIt.Value());
951 // Unbind groups from map that we added to our group.
952 for (TopTools_ListOfShape::Iterator aKeysIt(aKeysToUnbind);
955 aVertexShapesMap.UnBind(aKeysIt.Value());
956 allVertices.Remove(aKeysIt.Value());
959 // Sort shapes from the most complicated to the simplest ones
960 TopTools_MapOfShape aSortedGroup;
961 for (int aST = TopAbs_COMPOUND; aST <= TopAbs_SHAPE; ++aST) {
962 TopTools_ListOfShape::Iterator anIt(aConnectedShapes);
963 while (anIt.More()) {
964 if (anIt.Value().ShapeType() == aST) {
965 aSortedGroup.Add(anIt.Value());
966 aConnectedShapes.Remove(anIt);
973 aGroups.Append(aSortedGroup);
976 TopoDS_Compound aCompound;
977 BRep_Builder aBuilder;
978 aBuilder.MakeCompound(aCompound);
980 for (NCollection_Vector<TopTools_MapOfShape>::Iterator anIt(aGroups); anIt.More(); anIt.Next()) {
981 const TopTools_MapOfShape& aGroup = anIt.ChangeValue();
982 GeomShapePtr aGeomShape(new GeomAPI_Shape());
983 if (aGroup.Size() == 1) {
984 TopTools_MapOfShape::Iterator aOneShapeIter(aGroup);
985 aGeomShape->setImpl(new TopoDS_Shape(aOneShapeIter.Value()));
987 // make sub-shapes in the group have order same as in original shape
988 TopTools_ListOfShape anOrderedGoup;
989 NCollection_List<TopoDS_Shape>::Iterator anUngrouped(anUngroupedShapes);
990 for (; anUngrouped.More(); anUngrouped.Next()) {
991 if (aGroup.Contains(anUngrouped.Value()))
992 anOrderedGoup.Append(anUngrouped.Value());
994 aGeomShape->setImpl(new TopoDS_Shape(makeCompound(anOrderedGoup)));
995 aGeomShape = GeomAlgoAPI_ShapeTools::combineShapes(aGeomShape,
996 GeomAPI_Shape::COMPSOLID,
999 aBuilder.Add(aCompound, aGeomShape->impl<TopoDS_Shape>());
1002 if (!aCompound.IsNull()) {
1003 aResult->setImpl(new TopoDS_Shape(aCompound));
1009 //==================================================================================================
1010 bool GeomAlgoAPI_ShapeTools::hasSharedTopology(const ListOfShape& theShapes,
1011 const GeomAPI_Shape::ShapeType theShapeType)
1013 TopTools_IndexedMapOfShape aSubs;
1014 for (ListOfShape::const_iterator anIt = theShapes.begin(); anIt != theShapes.end(); ++anIt) {
1015 TopTools_IndexedMapOfShape aCurSubs;
1016 TopExp::MapShapes((*anIt)->impl<TopoDS_Shape>(), (TopAbs_ShapeEnum)theShapeType, aCurSubs);
1017 for (TopTools_IndexedMapOfShape::Iterator aSubIt(aCurSubs); aSubIt.More(); aSubIt.Next()) {
1018 if (aSubs.Contains(aSubIt.Value()))
1021 aSubs.Add(aSubIt.Value());
1027 //==================================================================================================
1028 std::list<std::shared_ptr<GeomAPI_Pnt> >
1029 GeomAlgoAPI_ShapeTools::getBoundingBox(const ListOfShape& theShapes, const double theEnlarge)
1031 // Bounding box of all objects.
1035 for (ListOfShape::const_iterator
1036 anObjectsIt = theShapes.begin(); anObjectsIt != theShapes.end(); anObjectsIt++) {
1037 const TopoDS_Shape& aShape = (*anObjectsIt)->impl<TopoDS_Shape>();
1038 BRepBndLib::Add(aShape, aBndBox);
1041 if (theEnlarge != 0.0) {
1042 // We enlarge bounding box just to be sure that plane will be large enough to cut all objects.
1043 aBndBox.Enlarge(theEnlarge);
1046 Standard_Real aXArr[2] = {aBndBox.CornerMin().X(), aBndBox.CornerMax().X()};
1047 Standard_Real aYArr[2] = {aBndBox.CornerMin().Y(), aBndBox.CornerMax().Y()};
1048 Standard_Real aZArr[2] = {aBndBox.CornerMin().Z(), aBndBox.CornerMax().Z()};
1049 std::list<std::shared_ptr<GeomAPI_Pnt> > aResultPoints;
1050 for (int i = 0; i < 2; i++) {
1051 for (int j = 0; j < 2; j++) {
1052 for (int k = 0; k < 2; k++) {
1053 std::shared_ptr<GeomAPI_Pnt> aPnt(new GeomAPI_Pnt(aXArr[i], aYArr[j], aZArr[k]));
1054 aResultPoints.push_back(aPnt);
1059 return aResultPoints;
1062 //==================================================================================================
1063 std::shared_ptr<GeomAPI_Face> GeomAlgoAPI_ShapeTools::fitPlaneToBox(
1064 const std::shared_ptr<GeomAPI_Shape> thePlane,
1065 const std::list<std::shared_ptr<GeomAPI_Pnt> >& thePoints)
1067 std::shared_ptr<GeomAPI_Face> aResultFace;
1069 if (!thePlane.get()) {
1073 const TopoDS_Shape& aShape = thePlane->impl<TopoDS_Shape>();
1074 if (aShape.ShapeType() != TopAbs_FACE) {
1078 TopoDS_Face aFace = TopoDS::Face(aShape);
1079 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
1080 if (aSurf.IsNull()) {
1084 GeomLib_IsPlanarSurface isPlanar(aSurf);
1085 if (!isPlanar.IsPlanar()) {
1089 if (thePoints.size() != 8) {
1093 const gp_Pln& aFacePln = isPlanar.Plan();
1094 Handle(Geom_Plane) aFacePlane = new Geom_Plane(aFacePln);
1095 IntAna_Quadric aQuadric(aFacePln);
1096 Standard_Real UMin, UMax, VMin, VMax;
1097 UMin = UMax = VMin = VMax = 0;
1098 for (std::list<std::shared_ptr<GeomAPI_Pnt> >::const_iterator
1099 aPointsIt = thePoints.begin(); aPointsIt != thePoints.end(); aPointsIt++) {
1100 const gp_Pnt& aPnt = (*aPointsIt)->impl<gp_Pnt>();
1101 gp_Lin aLin(aPnt, aFacePln.Axis().Direction());
1102 IntAna_IntConicQuad anIntAna(aLin, aQuadric);
1103 const gp_Pnt& aPntOnFace = anIntAna.Point(1);
1104 Standard_Real aPntU(0), aPntV(0);
1105 GeomLib_Tool::Parameters(aFacePlane, aPntOnFace, Precision::Confusion(), aPntU, aPntV);
1106 if (aPntU < UMin) UMin = aPntU;
1107 if (aPntU > UMax) UMax = aPntU;
1108 if (aPntV < VMin) VMin = aPntV;
1109 if (aPntV > VMax) VMax = aPntV;
1111 aResultFace.reset(new GeomAPI_Face());
1112 aResultFace->setImpl(new TopoDS_Face(BRepLib_MakeFace(aFacePln, UMin, UMax, VMin, VMax).Face()));
1117 //==================================================================================================
1118 void GeomAlgoAPI_ShapeTools::findBounds(const std::shared_ptr<GeomAPI_Shape> theShape,
1119 std::shared_ptr<GeomAPI_Vertex>& theV1,
1120 std::shared_ptr<GeomAPI_Vertex>& theV2)
1122 static GeomVertexPtr aVertex;
1124 aVertex = GeomVertexPtr(new GeomAPI_Vertex);
1125 aVertex->setImpl(new TopoDS_Vertex());
1132 const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>();
1133 TopoDS_Vertex aV1, aV2;
1134 ShapeAnalysis::FindBounds(aShape, aV1, aV2);
1136 std::shared_ptr<GeomAPI_Vertex> aGeomV1(new GeomAPI_Vertex()), aGeomV2(new GeomAPI_Vertex());
1137 aGeomV1->setImpl(new TopoDS_Vertex(aV1));
1138 aGeomV2->setImpl(new TopoDS_Vertex(aV2));
1144 //==================================================================================================
1145 void GeomAlgoAPI_ShapeTools::makeFacesWithHoles(const std::shared_ptr<GeomAPI_Pnt> theOrigin,
1146 const std::shared_ptr<GeomAPI_Dir> theDirection,
1147 const ListOfShape& theWires,
1148 ListOfShape& theFaces)
1150 BRepBuilderAPI_MakeFace aMKFace(gp_Pln(theOrigin->impl<gp_Pnt>(),
1151 theDirection->impl<gp_Dir>()));
1152 TopoDS_Face aFace = aMKFace.Face();
1154 BRepAlgo_FaceRestrictor aFRestrictor;
1155 aFRestrictor.Init(aFace, Standard_False, Standard_True);
1156 for (ListOfShape::const_iterator anIt = theWires.cbegin();
1157 anIt != theWires.cend();
1159 TopoDS_Wire aWire = TopoDS::Wire((*anIt)->impl<TopoDS_Shape>());
1160 aFRestrictor.Add(aWire);
1163 aFRestrictor.Perform();
1165 if (!aFRestrictor.IsDone()) {
1169 for (; aFRestrictor.More(); aFRestrictor.Next()) {
1170 GeomShapePtr aShape(new GeomAPI_Shape());
1171 aShape->setImpl(new TopoDS_Shape(aFRestrictor.Current()));
1172 theFaces.push_back(aShape);
1176 //==================================================================================================
1177 std::shared_ptr<GeomAPI_Pln> GeomAlgoAPI_ShapeTools::findPlane(const ListOfShape& theShapes)
1179 TopoDS_Compound aCompound;
1180 BRep_Builder aBuilder;
1181 aBuilder.MakeCompound(aCompound);
1183 for (ListOfShape::const_iterator anIt = theShapes.cbegin(); anIt != theShapes.cend(); ++anIt) {
1184 aBuilder.Add(aCompound, (*anIt)->impl<TopoDS_Shape>());
1186 BRepBuilderAPI_FindPlane aFindPlane(aCompound);
1188 if (aFindPlane.Found() != Standard_True) {
1189 return std::shared_ptr<GeomAPI_Pln>();
1192 Handle(Geom_Plane) aPlane = aFindPlane.Plane();
1193 gp_Pnt aLoc = aPlane->Location();
1194 gp_Dir aDir = aPlane->Axis().Direction();
1196 std::shared_ptr<GeomAPI_Pnt> aGeomPnt(new GeomAPI_Pnt(aLoc.X(), aLoc.Y(), aLoc.Z()));
1197 std::shared_ptr<GeomAPI_Dir> aGeomDir(new GeomAPI_Dir(aDir.X(), aDir.Y(), aDir.Z()));
1199 std::shared_ptr<GeomAPI_Pln> aPln(new GeomAPI_Pln(aGeomPnt, aGeomDir));
1204 //==================================================================================================
1205 bool GeomAlgoAPI_ShapeTools::isSubShapeInsideShape(
1206 const std::shared_ptr<GeomAPI_Shape> theSubShape,
1207 const std::shared_ptr<GeomAPI_Shape> theBaseShape)
1209 if (!theSubShape.get() || !theBaseShape.get()) {
1213 const TopoDS_Shape& aSubShape = theSubShape->impl<TopoDS_Shape>();
1214 const TopoDS_Shape& aBaseShape = theBaseShape->impl<TopoDS_Shape>();
1216 if (aSubShape.ShapeType() == TopAbs_VERTEX) {
1217 // If sub-shape is a vertex check distance to shape. If it is <= Precision::Confusion() then OK.
1218 BRepExtrema_DistShapeShape aDist(aBaseShape, aSubShape);
1220 if (!aDist.IsDone() || aDist.Value() > Precision::Confusion()) {
1223 } else if (aSubShape.ShapeType() == TopAbs_EDGE) {
1224 if (aBaseShape.ShapeType() == TopAbs_FACE) {
1225 // Check that edge is on face surface.
1226 TopoDS_Face aFace = TopoDS::Face(aBaseShape);
1227 TopoDS_Edge anEdge = TopoDS::Edge(aSubShape);
1228 BRepLib_CheckCurveOnSurface aCheck(anEdge, aFace);
1230 if (!aCheck.IsDone() || aCheck.MaxDistance() > Precision::Confusion()) {
1234 // Check intersections.
1235 TopoDS_Vertex aV1, aV2;
1236 ShapeAnalysis::FindBounds(anEdge, aV1, aV2);
1237 gp_Pnt aPnt1 = BRep_Tool::Pnt(aV1);
1238 gp_Pnt aPnt2 = BRep_Tool::Pnt(aV2);
1239 for (TopExp_Explorer anExp(aBaseShape, TopAbs_EDGE); anExp.More(); anExp.Next()) {
1240 const TopoDS_Shape& anEdgeOnFace = anExp.Current();
1241 BRepExtrema_DistShapeShape aDist(anEdgeOnFace, anEdge);
1243 if (aDist.IsDone() && aDist.Value() <= Precision::Confusion()) {
1244 // Edge intersect face bound. Check that it is not on edge begin or end.
1245 for (Standard_Integer anIndex = 1; anIndex <= aDist.NbSolution(); ++anIndex) {
1246 gp_Pnt aPntOnSubShape = aDist.PointOnShape2(anIndex);
1247 if (aPntOnSubShape.Distance(aPnt1) > Precision::Confusion()
1248 && aPntOnSubShape.Distance(aPnt2) > Precision::Confusion()) {
1255 // No intersections found. Edge is inside or outside face. Check it.
1256 BRepAdaptor_Curve aCurveAdaptor(anEdge);
1257 gp_Pnt aPointToCheck =
1258 aCurveAdaptor.Value((aCurveAdaptor.FirstParameter() +
1259 aCurveAdaptor.LastParameter()) / 2.0);
1260 Handle(Geom_Surface) aSurface = BRep_Tool::Surface(aFace);
1261 ShapeAnalysis_Surface aSAS(aSurface);
1262 gp_Pnt2d aPointOnFace = aSAS.ValueOfUV(aPointToCheck, Precision::Confusion());
1263 BRepTopAdaptor_FClass2d aFClass2d(aFace, Precision::Confusion());
1264 if (aFClass2d.Perform(aPointOnFace) == TopAbs_OUT) {
1278 //==================================================================================================
1279 bool GeomAlgoAPI_ShapeTools::isShapeValid(const std::shared_ptr<GeomAPI_Shape> theShape)
1281 if (!theShape.get()) {
1285 BRepCheck_Analyzer aChecker(theShape->impl<TopoDS_Shape>());
1286 return (aChecker.IsValid() == Standard_True);
1289 //==================================================================================================
1290 std::shared_ptr<GeomAPI_Shape>
1291 GeomAlgoAPI_ShapeTools::getFaceOuterWire(const std::shared_ptr<GeomAPI_Shape> theFace)
1293 GeomShapePtr anOuterWire;
1295 if (!theFace.get() || !theFace->isFace()) {
1299 TopoDS_Face aFace = TopoDS::Face(theFace->impl<TopoDS_Shape>());
1300 TopoDS_Wire aWire = BRepTools::OuterWire(aFace);
1302 anOuterWire.reset(new GeomAPI_Shape());
1303 anOuterWire->setImpl(new TopoDS_Shape(aWire));
1308 //==================================================================================================
1309 static bool boundaryOfEdge(const std::shared_ptr<GeomAPI_Edge> theEdge,
1310 const std::shared_ptr<GeomAPI_Vertex> theVertex,
1313 GeomPointPtr aPoint = theVertex->point();
1314 GeomPointPtr aFirstPnt = theEdge->firstPoint();
1315 double aFirstPntTol = theEdge->firstPointTolerance();
1316 GeomPointPtr aLastPnt = theEdge->lastPoint();
1317 double aLastPntTol = theEdge->lastPointTolerance();
1319 double aFirst, aLast;
1320 theEdge->getRange(aFirst, aLast);
1322 bool isFirst = aPoint->distance(aFirstPnt) <= aFirstPntTol;
1323 bool isLast = aPoint->distance(aLastPnt) <= aLastPntTol;
1329 return isFirst != isLast;
1332 bool GeomAlgoAPI_ShapeTools::isTangent(const std::shared_ptr<GeomAPI_Edge> theEdge1,
1333 const std::shared_ptr<GeomAPI_Edge> theEdge2,
1334 const std::shared_ptr<GeomAPI_Vertex> theTgPoint)
1336 double aParE1 = 0, aParE2 = 0;
1337 if (!boundaryOfEdge(theEdge1, theTgPoint, aParE1) ||
1338 !boundaryOfEdge(theEdge2, theTgPoint, aParE2))
1341 BRepAdaptor_Curve aC1(theEdge1->impl<TopoDS_Edge>());
1342 BRepAdaptor_Curve aC2(theEdge2->impl<TopoDS_Edge>());
1343 return BRepLProp::Continuity(aC1, aC2, aParE1, aParE2) >= GeomAbs_G1;
1346 //==================================================================================================
1347 bool GeomAlgoAPI_ShapeTools::isParallel(const std::shared_ptr<GeomAPI_Edge> theEdge,
1348 const std::shared_ptr<GeomAPI_Face> theFace)
1350 if (!theEdge.get() || !theFace.get()) {
1354 TopoDS_Edge anEdge = TopoDS::Edge(theEdge->impl<TopoDS_Shape>());
1355 TopoDS_Face aFace = TopoDS::Face(theFace->impl<TopoDS_Shape>());
1357 BRepExtrema_ExtCF anExt(anEdge, aFace);
1358 return anExt.IsParallel() == Standard_True;
1361 //==================================================================================================
1362 std::list<std::shared_ptr<GeomAPI_Vertex> > GeomAlgoAPI_ShapeTools::intersect(
1363 const std::shared_ptr<GeomAPI_Edge> theEdge, const std::shared_ptr<GeomAPI_Face> theFace)
1365 std::list<std::shared_ptr<GeomAPI_Vertex> > aResult;
1366 if (!theEdge.get() || !theFace.get()) {
1370 TopoDS_Edge anEdge = TopoDS::Edge(theEdge->impl<TopoDS_Shape>());
1371 double aFirstOnCurve, aLastOnCurve;
1372 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFirstOnCurve, aLastOnCurve);
1374 TopoDS_Face aFace = TopoDS::Face(theFace->impl<TopoDS_Shape>());
1375 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
1377 GeomAPI_IntCS anIntAlgo(aCurve, aSurf);
1378 if (!anIntAlgo.IsDone())
1380 // searching for points-intersection
1381 for (int anIntNum = 1; anIntNum <= anIntAlgo.NbPoints() + anIntAlgo.NbSegments(); anIntNum++) {
1383 if (anIntNum <= anIntAlgo.NbPoints()) {
1384 anInt = anIntAlgo.Point(anIntNum);
1385 } else { // take the middle point on the segment of the intersection
1386 Handle(Geom_Curve) anIntCurve = anIntAlgo.Segment(anIntNum - anIntAlgo.NbPoints());
1387 anIntCurve->D0((anIntCurve->FirstParameter() + anIntCurve->LastParameter()) / 2., anInt);
1389 aResult.push_back(std::shared_ptr<GeomAPI_Vertex>(
1390 new GeomAPI_Vertex(anInt.X(), anInt.Y(), anInt.Z())));
1395 //==================================================================================================
1396 void GeomAlgoAPI_ShapeTools::splitShape(const std::shared_ptr<GeomAPI_Shape>& theBaseShape,
1397 const GeomAlgoAPI_ShapeTools::PointToRefsMap& thePointsInfo,
1398 std::set<std::shared_ptr<GeomAPI_Shape> >& theShapes)
1400 // to split shape at least one point should be presented in the points container
1401 if (thePointsInfo.empty())
1404 // General Fuse to split edge by vertices
1405 BOPAlgo_Builder aBOP;
1406 TopoDS_Edge aBaseEdge = theBaseShape->impl<TopoDS_Edge>();
1407 // Rebuild closed edge to place vertex to one of split points.
1408 // This will prevent edge to be split on same vertex.
1409 if (BRep_Tool::IsClosed(aBaseEdge))
1411 Standard_Real aFirst, aLast;
1412 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(aBaseEdge, aFirst, aLast);
1414 PointToRefsMap::const_iterator aPIt = thePointsInfo.begin();
1415 std::shared_ptr<GeomAPI_Pnt> aPnt = aPIt->first;
1416 gp_Pnt aPoint(aPnt->x(), aPnt->y(), aPnt->z());
1418 TopAbs_Orientation anOrientation = aBaseEdge.Orientation();
1419 aBaseEdge = BRepBuilderAPI_MakeEdge(aCurve, aPoint, aPoint).Edge();
1420 aBaseEdge.Orientation(anOrientation);
1422 aBOP.AddArgument(aBaseEdge);
1424 PointToRefsMap::const_iterator aPIt = thePointsInfo.begin();
1425 for (; aPIt != thePointsInfo.end(); ++aPIt) {
1426 std::shared_ptr<GeomAPI_Pnt> aPnt = aPIt->first;
1427 TopoDS_Vertex aV = BRepBuilderAPI_MakeVertex(gp_Pnt(aPnt->x(), aPnt->y(), aPnt->z()));
1428 aBOP.AddArgument(aV);
1432 if (aBOP.HasErrors())
1436 const TopTools_ListOfShape& aSplits = aBOP.Modified(aBaseEdge);
1437 TopTools_ListIteratorOfListOfShape anIt(aSplits);
1438 for (; anIt.More(); anIt.Next()) {
1439 std::shared_ptr<GeomAPI_Shape> anEdge(new GeomAPI_Shape);
1440 anEdge->setImpl(new TopoDS_Shape(anIt.Value()));
1441 theShapes.insert(anEdge);
1445 //==================================================================================================
1446 void GeomAlgoAPI_ShapeTools::splitShape_p(const std::shared_ptr<GeomAPI_Shape>& theBaseShape,
1447 const std::list<std::shared_ptr<GeomAPI_Pnt> >& thePoints,
1448 std::set<std::shared_ptr<GeomAPI_Shape> >& theShapes)
1450 // General Fuse to split edge by vertices
1451 BOPAlgo_Builder aBOP;
1452 TopoDS_Edge aBaseEdge = theBaseShape->impl<TopoDS_Edge>();
1453 // Rebuild closed edge to place vertex to one of split points.
1454 // This will prevent edge to be split on seam vertex.
1455 if (BRep_Tool::IsClosed(aBaseEdge))
1457 Standard_Real aFirst, aLast;
1458 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(aBaseEdge, aFirst, aLast);
1460 std::list<std::shared_ptr<GeomAPI_Pnt> >::const_iterator aPIt = thePoints.begin();
1461 gp_Pnt aPoint((*aPIt)->x(), (*aPIt)->y(), (*aPIt)->z());
1463 TopAbs_Orientation anOrientation = aBaseEdge.Orientation();
1464 aBaseEdge = BRepBuilderAPI_MakeEdge(aCurve, aPoint, aPoint).Edge();
1465 aBaseEdge.Orientation(anOrientation);
1467 aBOP.AddArgument(aBaseEdge);
1469 std::list<std::shared_ptr<GeomAPI_Pnt> >::const_iterator aPtIt = thePoints.begin();
1470 for (; aPtIt != thePoints.end(); ++aPtIt) {
1471 std::shared_ptr<GeomAPI_Pnt> aPnt = *aPtIt;
1472 TopoDS_Vertex aV = BRepBuilderAPI_MakeVertex(gp_Pnt(aPnt->x(), aPnt->y(), aPnt->z()));
1473 aBOP.AddArgument(aV);
1477 if (aBOP.HasErrors())
1481 const TopTools_ListOfShape& aSplits = aBOP.Modified(aBaseEdge);
1482 TopTools_ListIteratorOfListOfShape anIt(aSplits);
1483 for (; anIt.More(); anIt.Next()) {
1484 std::shared_ptr<GeomAPI_Shape> anEdge(new GeomAPI_Shape);
1485 anEdge->setImpl(new TopoDS_Shape(anIt.Value()));
1486 theShapes.insert(anEdge);
1490 //==================================================================================================
1491 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeTools::findShape(
1492 const std::list<std::shared_ptr<GeomAPI_Pnt> >& thePoints,
1493 const std::set<std::shared_ptr<GeomAPI_Shape> >& theShapes)
1495 std::shared_ptr<GeomAPI_Shape> aResultShape;
1497 if (thePoints.size() == 2) {
1498 std::list<std::shared_ptr<GeomAPI_Pnt> >::const_iterator aPntIt = thePoints.begin();
1499 std::shared_ptr<GeomAPI_Pnt> aFirstPoint = *aPntIt;
1501 std::shared_ptr<GeomAPI_Pnt> aLastPoint = *aPntIt;
1503 std::set<std::shared_ptr<GeomAPI_Shape> >::const_iterator anIt = theShapes.begin(),
1504 aLast = theShapes.end();
1505 for (; anIt != aLast; anIt++) {
1506 GeomShapePtr aShape = *anIt;
1507 std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(aShape));
1509 std::shared_ptr<GeomAPI_Pnt> anEdgeFirstPoint = anEdge->firstPoint();
1510 std::shared_ptr<GeomAPI_Pnt> anEdgeLastPoint = anEdge->lastPoint();
1511 if (anEdgeFirstPoint->isEqual(aFirstPoint) &&
1512 anEdgeLastPoint->isEqual(aLastPoint))
1513 aResultShape = aShape;
1518 return aResultShape;
1521 //==================================================================================================
1522 #ifdef FEATURE_MULTIROTATION_TWO_DIRECTIONS
1523 std::shared_ptr<GeomAPI_Dir> GeomAlgoAPI_ShapeTools::buildDirFromAxisAndShape(
1524 const std::shared_ptr<GeomAPI_Shape> theBaseShape,
1525 const std::shared_ptr<GeomAPI_Ax1> theAxis)
1527 gp_Pnt aCentreOfMassPoint =
1528 GeomAlgoAPI_ShapeTools::centreOfMass(theBaseShape)->impl<gp_Pnt>();
1529 Handle(Geom_Line) aLine = new Geom_Line(theAxis->impl<gp_Ax1>());
1530 GeomAPI_ProjectPointOnCurve aPrjTool(aCentreOfMassPoint, aLine);
1531 gp_Pnt aPoint = aPrjTool.NearestPoint();
1533 std::shared_ptr<GeomAPI_Dir> aDir(new GeomAPI_Dir(aCentreOfMassPoint.X()-aPoint.X(),
1534 aCentreOfMassPoint.Y()-aPoint.Y(),
1535 aCentreOfMassPoint.Z()-aPoint.Z()));
1540 //==================================================================================================
1541 static TopoDS_Wire fixParametricGaps(const TopoDS_Wire& theWire)
1543 TopoDS_Wire aFixedWire;
1544 Handle(Geom_Curve) aPrevCurve;
1545 double aPrevLastParam = -Precision::Infinite();
1547 BRep_Builder aBuilder;
1548 aBuilder.MakeWire(aFixedWire);
1550 BRepTools_WireExplorer aWExp(theWire);
1551 for (; aWExp.More(); aWExp.Next()) {
1552 TopoDS_Edge anEdge = aWExp.Current();
1553 double aFirst, aLast;
1554 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFirst, aLast);
1555 if (aCurve == aPrevCurve && Abs(aFirst - aPrevLastParam) > Precision::Confusion()) {
1556 // if parametric gap occurs, create new edge based on the copied curve
1557 aCurve = Handle(Geom_Curve)::DownCast(aCurve->Copy());
1558 TopoDS_Vertex aV1, aV2;
1559 TopExp::Vertices(anEdge, aV1, aV2);
1560 anEdge = TopoDS::Edge(anEdge.EmptyCopied());
1561 aBuilder.UpdateEdge(anEdge, aCurve, BRep_Tool::Tolerance(anEdge));
1562 aBuilder.Add(anEdge, aV1);
1563 aBuilder.Add(anEdge, aV2);
1566 aBuilder.Add(aFixedWire, anEdge);
1568 aPrevCurve = aCurve;
1569 aPrevLastParam = aLast;
1575 //==================================================================================================
1576 std::shared_ptr<GeomAPI_Edge> GeomAlgoAPI_ShapeTools::wireToEdge(
1577 const std::shared_ptr<GeomAPI_Wire>& theWire)
1581 TopoDS_Wire aWire = theWire->impl<TopoDS_Wire>();
1582 BRepTools_WireExplorer aWExp(aWire);
1583 TopoDS_Edge aNewEdge = aWExp.Current();
1586 // Workaround for the closed wire to avoid jumping of its start point:
1587 // split this wire for two parts, convert them to edges, then compose together
1588 if (BRep_Tool::IsClosed(aWire)) {
1589 aWire = TopoDS::Wire(BRepBuilderAPI_Copy(aWire).Shape());
1591 aNewEdge = aWExp.Current();
1593 BRep_Builder().Remove(aWire, aNewEdge);
1594 GeomWirePtr aSplitWire(new GeomAPI_Wire);
1595 aSplitWire->setImpl(new TopoDS_Wire(aWire));
1596 GeomEdgePtr aMergedEdge = wireToEdge(aSplitWire);
1598 aWire = BRepBuilderAPI_MakeWire(aNewEdge, aMergedEdge->impl<TopoDS_Edge>());
1601 // Workaround: when concatenate a wire consisting of two edges based on the same B-spline
1602 // curve (non-periodic, but having equal start and end points), first of which is placed
1603 // at the end on the curve and second is placed at the start, this workaround copies
1604 // second curve to avoid treating these edges as a single curve by setting trim parameters.
1605 aWire = fixParametricGaps(aWire);
1606 aWire = BRepAlgo::ConcatenateWire(aWire, GeomAbs_G1); // join smooth parts of wire
1607 aNewEdge = BRepAlgo::ConcatenateWireC0(aWire); // join C0 parts of wire
1609 // Reapproximate the result edge to have the parameter equal to curvilinear abscissa.
1610 static const int THE_MAX_DEGREE = 14;
1611 static const int THE_MAX_INTERVALS = 32;
1612 double aFirst, aLast;
1613 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(aNewEdge, aFirst, aLast);
1614 #if OCC_VERSION_LARGE < 0x07070000
1615 Handle(GeomAdaptor_HCurve) aHCurve = new GeomAdaptor_HCurve(aCurve);
1617 Handle(GeomAdaptor_Curve) aHCurve = new GeomAdaptor_Curve(aCurve);
1619 Approx_CurvilinearParameter anApprox(aHCurve, Precision::Confusion(), aCurve->Continuity(),
1620 THE_MAX_DEGREE, THE_MAX_INTERVALS);
1621 if (anApprox.HasResult()) {
1622 Handle(Geom_BSplineCurve) aNewCurve = anApprox.Curve3d();
1623 TColStd_Array1OfReal aKnots = aNewCurve->Knots();
1624 BSplCLib::Reparametrize(aFirst, aLast, aKnots);
1625 aNewCurve->SetKnots(aKnots);
1626 BRep_Builder().UpdateEdge(aNewEdge, aNewCurve, BRep_Tool::Tolerance(aNewEdge));
1629 anEdge = GeomEdgePtr(new GeomAPI_Edge);
1630 anEdge->setImpl(new TopoDS_Edge(aNewEdge));
1635 //==================================================================================================
1636 ListOfShape GeomAlgoAPI_ShapeTools::getLowLevelSubShapes(const GeomShapePtr& theShape)
1638 ListOfShape aSubShapes;
1640 if (!theShape->isCompound() && !theShape->isCompSolid() &&
1641 !theShape->isShell() && !theShape->isWire()) {
1645 for (GeomAPI_ShapeIterator anIt(theShape); anIt.more(); anIt.next()) {
1646 GeomShapePtr aSubShape = anIt.current();
1647 if (aSubShape->isVertex() || aSubShape->isEdge() ||
1648 aSubShape->isFace() || aSubShape->isSolid()) {
1649 aSubShapes.push_back(aSubShape);
1651 aSubShapes.splice(aSubShapes.end(), getLowLevelSubShapes(aSubShape));
1658 //==================================================================================================
1659 static void getMinMaxPointsOnLine(const std::list<std::shared_ptr<GeomAPI_Pnt> >& thePoints,
1660 const gp_Dir theDir,
1661 double& theMin, double& theMax)
1663 theMin = RealLast();
1664 theMax = RealFirst();
1665 // Project bounding points on theDir
1666 for (std::list<std::shared_ptr<GeomAPI_Pnt> >::const_iterator
1667 aPointsIt = thePoints.begin(); aPointsIt != thePoints.end(); aPointsIt++) {
1668 const gp_Pnt& aPnt = (*aPointsIt)->impl<gp_Pnt>();
1669 gp_Dir aPntDir (aPnt.XYZ());
1670 Standard_Real proj = (theDir*aPntDir) * aPnt.XYZ().Modulus();
1671 if (proj < theMin) theMin = proj;
1672 if (proj > theMax) theMax = proj;
1676 //==================================================================================================
1677 void GeomAlgoAPI_ShapeTools::computeThroughAll(const ListOfShape& theObjects,
1678 const ListOfShape& theBaseShapes,
1679 const std::shared_ptr<GeomAPI_Dir> theDir,
1680 double& theToSize, double& theFromSize)
1682 // Bounding box of objects
1683 std::list<std::shared_ptr<GeomAPI_Pnt> > aBndObjs =
1684 GeomAlgoAPI_ShapeTools::getBoundingBox(theObjects);
1685 if (aBndObjs.size() != 8) {
1689 // the value to enlarge the bounding box of each object to make the extruded shape
1690 // a little bit larger than overall objects to get the correct result of Boolean CUT operation
1691 double anEnlargement = 0.1 * aBndObjs.front()->distance(aBndObjs.back());
1695 // One direction for all prisms
1696 gp_Dir aDir = theDir->impl<gp_Dir>();
1698 // Bounding box of the base
1699 std::list<std::shared_ptr<GeomAPI_Pnt> > aBndBases =
1700 GeomAlgoAPI_ShapeTools::getBoundingBox(theBaseShapes);
1701 if (aBndBases.size() != 8) {
1706 Standard_Real lowBnd, upperBnd;
1707 getMinMaxPointsOnLine(aBndObjs, aDir, lowBnd, upperBnd);
1710 Standard_Real lowBase, upperBase;
1711 getMinMaxPointsOnLine(aBndBases, aDir, lowBase, upperBase);
1713 // ----------.-----.---------.--------------.-----------> theDir
1714 // lowBnd lowBase upperBase upperBnd
1716 theToSize = upperBnd - lowBase;
1717 theFromSize = upperBase - lowBnd;
1719 // Direction is a normal to each base shape (different normals to bases)
1720 // So we calculate own sizes for each base shape
1724 for (ListOfShape::const_iterator anIt = theBaseShapes.begin();
1725 anIt != theBaseShapes.end(); ++anIt) {
1726 const GeomShapePtr& aBaseShape_i = (*anIt);
1727 ListOfShape aBaseShapes_i;
1728 aBaseShapes_i.push_back(aBaseShape_i);
1730 // Bounding box of the base
1731 std::list<std::shared_ptr<GeomAPI_Pnt> > aBndBases =
1732 GeomAlgoAPI_ShapeTools::getBoundingBox(aBaseShapes_i, anEnlargement);
1733 if (aBndBases.size() != 8) {
1737 // Direction (normal to aBaseShapes_i)
1738 // Code like in GeomAlgoAPI_Prism
1740 const TopoDS_Shape& aBaseShape = aBaseShape_i->impl<TopoDS_Shape>();
1741 BRepBuilderAPI_FindPlane aFindPlane(aBaseShape);
1742 if (aFindPlane.Found() == Standard_True) {
1743 Handle(Geom_Plane) aPlane;
1744 if (aBaseShape.ShapeType() == TopAbs_FACE || aBaseShape.ShapeType() == TopAbs_SHELL) {
1745 TopExp_Explorer anExp(aBaseShape, TopAbs_FACE);
1746 const TopoDS_Shape& aFace = anExp.Current();
1747 Handle(Geom_Surface) aSurface = BRep_Tool::Surface(TopoDS::Face(aFace));
1748 if (aSurface->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
1749 Handle(Geom_RectangularTrimmedSurface) aTrimSurface =
1750 Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurface);
1751 aSurface = aTrimSurface->BasisSurface();
1753 if (aSurface->DynamicType() != STANDARD_TYPE(Geom_Plane)) {
1756 aPlane = Handle(Geom_Plane)::DownCast(aSurface);
1758 aPlane = aFindPlane.Plane();
1760 aDir = aPlane->Axis().Direction();
1766 Standard_Real lowBnd, upperBnd;
1767 getMinMaxPointsOnLine(aBndObjs, aDir, lowBnd, upperBnd);
1770 Standard_Real lowBase, upperBase;
1771 getMinMaxPointsOnLine(aBndBases, aDir, lowBase, upperBase);
1773 // ----------.-----.---------.--------------.-----------> theDir
1774 // lowBnd lowBase upperBase upperBnd
1776 double aToSize_i = upperBnd - lowBase;
1777 double aFromSize_i = upperBase - lowBnd;
1779 if (aToSize_i > theToSize) theToSize = aToSize_i;
1780 if (aFromSize_i > theFromSize) theFromSize = aFromSize_i;