Salome HOME
Issue #1063: Problem of dynamic cast on Linux for Selection validators is solved
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_ShapeTools.cpp
index 54835f857cccdaef0bd32fda7b64d5b399b1924a..3a4f577ac27be670f7974e4f6a8d88c477b5c35f 100644 (file)
@@ -8,15 +8,24 @@
 
 #include <GeomAlgoAPI_CompoundBuilder.h>
 
+#include <gp_Pln.hxx>
+
 #include <BOPTools.hxx>
+#include <BRepBuilderAPI_MakeFace.hxx>
 #include <BRepGProp.hxx>
 #include <BRepTools.hxx>
+#include <BRep_Tool.hxx>
+#include <Geom_Plane.hxx>
 #include <GProp_GProps.hxx>
 #include <NCollection_Vector.hxx>
 #include <TCollection_AsciiString.hxx>
 #include <TopoDS_Builder.hxx>
+#include <TopoDS_Face.hxx>
 #include <TopoDS_Shape.hxx>
 #include <TopoDS_Shell.hxx>
+#include <TopoDS.hxx>
+#include <TopExp_Explorer.hxx>
+
 
 //=================================================================================================
 double GeomAlgoAPI_ShapeTools::volume(std::shared_ptr<GeomAPI_Shape> theShape)
@@ -140,10 +149,13 @@ void GeomAlgoAPI_ShapeTools::combineShapes(const std::shared_ptr<GeomAPI_Shape>
     TopoDS_CompSolid aCSolid;
     TopoDS_Builder aBuilder;
     theType == GeomAPI_Shape::COMPSOLID ? aBuilder.MakeCompSolid(aCSolid) : aBuilder.MakeShell(aShell);
-    const NCollection_Map<TopoDS_Shape>& aShapesMap = anIter.Value();
-    for(NCollection_Map<TopoDS_Shape>::Iterator aShIter(aShapesMap); aShIter.More(); aShIter.Next()) {
-      const TopoDS_Shape& aShape = aShIter.Value();
-      theType == GeomAPI_Shape::COMPSOLID ? aBuilder.Add(aCSolid, aShape) : aBuilder.Add(aShell, aShape);
+    NCollection_Map<TopoDS_Shape>& aShapesMap = anIter.ChangeValue();
+    for(TopExp_Explorer anExp(aShapesComp, aTA); anExp.More(); anExp.Next()) {
+      const TopoDS_Shape& aShape = anExp.Current();
+      if(aShapesMap.Contains(aShape)) {
+        theType == GeomAPI_Shape::COMPSOLID ? aBuilder.Add(aCSolid, aShape) : aBuilder.Add(aShell, aShape);
+        aShapesMap.Remove(aShape);
+      }
     }
     std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
     TopoDS_Shape* aSh = theType == GeomAPI_Shape::COMPSOLID ? new TopoDS_Shape(aCSolid) : new TopoDS_Shape(aShell);
@@ -152,10 +164,34 @@ void GeomAlgoAPI_ShapeTools::combineShapes(const std::shared_ptr<GeomAPI_Shape>
   }
 
   // Adding free shapes.
-  for(NCollection_Map<TopoDS_Shape>::Iterator aShIter(aFreeShapes); aShIter.More(); aShIter.Next()) {
-    const TopoDS_Shape& aShape = aShIter.Value();
-    std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
-    aGeomShape->setImpl<TopoDS_Shape>(new TopoDS_Shape(aShape));
-    theFreeShapes.push_back(aGeomShape);
+  for(TopExp_Explorer anExp(aShapesComp, aTA); anExp.More(); anExp.Next()) {
+    const TopoDS_Shape& aShape = anExp.Current();
+    if(aFreeShapes.Contains(aShape)) {
+      std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
+      aGeomShape->setImpl<TopoDS_Shape>(new TopoDS_Shape(aShape));
+      theFreeShapes.push_back(aGeomShape);
+    }
   }
 }
+
+//=================================================================================================
+std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeTools::faceToInfinitePlane(const std::shared_ptr<GeomAPI_Shape>& theFace)
+{
+  if (!theFace.get())
+    return std::shared_ptr<GeomAPI_Shape>();
+
+  TopoDS_Face aPlaneFace = TopoDS::Face(theFace->impl<TopoDS_Shape>());
+  if (aPlaneFace.IsNull())
+    return std::shared_ptr<GeomAPI_Shape>();
+
+  Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast(BRep_Tool::Surface(aPlaneFace));
+  if (aPlane.IsNull())
+    return std::shared_ptr<GeomAPI_Shape>();
+
+  // make an infinity face on the plane
+  TopoDS_Shape anInfiniteFace = BRepBuilderAPI_MakeFace(aPlane->Pln()).Shape();
+
+  std::shared_ptr<GeomAPI_Shape> aResult(new GeomAPI_Shape);
+  aResult->setImpl(new TopoDS_Shape(anInfiniteFace));
+  return aResult;
+}