]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Method intersect for GeomAPI_Shape
authorazv <azv@opencascade.com>
Mon, 27 Feb 2017 10:22:49 +0000 (13:22 +0300)
committerazv <azv@opencascade.com>
Mon, 27 Feb 2017 10:22:49 +0000 (13:22 +0300)
src/GeomAPI/GeomAPI_Shape.cpp
src/GeomAPI/GeomAPI_Shape.h

index 6c0c7f27af4498c208f01eda6ac269b77f435288..d79e365b42b00b502f6c65a26294212cb89b55de 100644 (file)
@@ -7,6 +7,7 @@
 #include "GeomAPI_Shape.h"
 
 #include <BRep_Tool.hxx>
+#include <BRepAlgoAPI_Common.hxx>
 #include <BRepBndLib.hxx>
 #include <BRepBuilderAPI_FindPlane.hxx>
 #include <BRepTools.hxx>
@@ -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<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
+  const TopoDS_Shape& aShape2 = theShape->impl<TopoDS_Shape>();
+
+  BRepAlgoAPI_Common aCommon(aShape1, aShape2);
+  if (!aCommon.IsDone())
+    return GeomShapePtr();
+
+  TopoDS_Shape aResult = aCommon.Shape();
+  if (aResult.ShapeType() == TopAbs_COMPOUND) {
+    NCollection_List<TopoDS_Shape> aSubs;
+    addSimpleToList(aResult, aSubs);
+    if (aSubs.Size() == 1)
+      aResult = aSubs.First();
+  }
+
+  GeomShapePtr aResShape(new GeomAPI_Shape);
+  aResShape->setImpl(new TopoDS_Shape(aResult));
+  return aResShape;
+}
index 093779c7b2fc5b5142d9c53b7904f3ec8dc006ca..1c7f2c7f849e06a1ff6fa0640224799a82434ad7 100644 (file)
@@ -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<GeomAPI_Shape> intersect(const std::shared_ptr<GeomAPI_Shape> theShape) const;
 };
 
 //! Pointer on list of shapes