From 4c08a88fd7aa24e370cf07db16d768f7e9719501 Mon Sep 17 00:00:00 2001 From: azv Date: Mon, 27 Feb 2017 13:22:49 +0300 Subject: [PATCH] Method intersect for GeomAPI_Shape --- src/GeomAPI/GeomAPI_Shape.cpp | 23 +++++++++++++++++++++++ src/GeomAPI/GeomAPI_Shape.h | 4 ++++ 2 files changed, 27 insertions(+) diff --git a/src/GeomAPI/GeomAPI_Shape.cpp b/src/GeomAPI/GeomAPI_Shape.cpp index 6c0c7f27a..d79e365b4 100644 --- a/src/GeomAPI/GeomAPI_Shape.cpp +++ b/src/GeomAPI/GeomAPI_Shape.cpp @@ -7,6 +7,7 @@ #include "GeomAPI_Shape.h" #include +#include #include #include #include @@ -429,3 +430,25 @@ std::string GeomAPI_Shape::getShapeStream() const BRepTools::Write(aShape, aStream); return aStream.str(); } + +GeomShapePtr GeomAPI_Shape::intersect(const GeomShapePtr theShape) const +{ + const TopoDS_Shape& aShape1 = const_cast(this)->impl(); + const TopoDS_Shape& aShape2 = theShape->impl(); + + BRepAlgoAPI_Common aCommon(aShape1, aShape2); + if (!aCommon.IsDone()) + return GeomShapePtr(); + + TopoDS_Shape aResult = aCommon.Shape(); + if (aResult.ShapeType() == TopAbs_COMPOUND) { + NCollection_List aSubs; + addSimpleToList(aResult, aSubs); + if (aSubs.Size() == 1) + aResult = aSubs.First(); + } + + GeomShapePtr aResShape(new GeomAPI_Shape); + aResShape->setImpl(new TopoDS_Shape(aResult)); + return aResShape; +} diff --git a/src/GeomAPI/GeomAPI_Shape.h b/src/GeomAPI/GeomAPI_Shape.h index 093779c7b..1c7f2c7f8 100644 --- a/src/GeomAPI/GeomAPI_Shape.h +++ b/src/GeomAPI/GeomAPI_Shape.h @@ -120,6 +120,10 @@ public: /// Returns the shape as BRep stream GEOMAPI_EXPORT std::string getShapeStream() const; + + /// Returns intersection of shapes + GEOMAPI_EXPORT + std::shared_ptr intersect(const std::shared_ptr theShape) const; }; //! Pointer on list of shapes -- 2.39.2