From: azv Date: Mon, 27 Feb 2017 10:22:49 +0000 (+0300) Subject: Method intersect for GeomAPI_Shape X-Git-Tag: V_2.7.0~259^2~1^2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=4c08a88fd7aa24e370cf07db16d768f7e9719501;p=modules%2Fshaper.git Method intersect for GeomAPI_Shape --- 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