Salome HOME
Increase sensitivity for vertexes selection
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_ShapeTools.cpp
index 6955720e2f46bd3cfcc165f2a03fb673414020af..39b06f92723b9cfe1ed4c8082a617234fd75ce5d 100644 (file)
@@ -8,15 +8,23 @@
 
 #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>
+
 
 //=================================================================================================
 double GeomAlgoAPI_ShapeTools::volume(std::shared_ptr<GeomAPI_Shape> theShape)
@@ -88,16 +96,22 @@ void GeomAlgoAPI_ShapeTools::combineShapes(const std::shared_ptr<GeomAPI_Shape>
       continue;
     }
     else if(aListOfShape.Size() == 1) {
-      aFreeShapes.Add(aListOfShape.First());
+      const TopoDS_Shape& aF = aListOfShape.First();
+      aFreeShapes.Add(aF);
       aListOfShape.Clear();
     } else {
+      NCollection_List<TopoDS_Shape> aTempList;
       NCollection_Map<TopoDS_Shape> aTempMap;
-      aTempMap.Add(aListOfShape.First());
-      aTempMap.Add(aListOfShape.Last());
-      aFreeShapes.Remove(aListOfShape.First());
-      aFreeShapes.Remove(aListOfShape.Last());
+      const TopoDS_Shape& aF = aListOfShape.First();
+      const TopoDS_Shape& aL = aListOfShape.Last();
+      aTempList.Append(aF);
+      aTempList.Append(aL);
+      aTempMap.Add(aF);
+      aTempMap.Add(aL);
+      aFreeShapes.Remove(aF);
+      aFreeShapes.Remove(aL);
       aListOfShape.Clear();
-      for(NCollection_Map<TopoDS_Shape>::Iterator aTempIter(aTempMap); aTempIter.More(); aTempIter.Next()) {
+      for(NCollection_List<TopoDS_Shape>::Iterator aTempIter(aTempList); aTempIter.More(); aTempIter.Next()) {
         const TopoDS_Shape& aTempShape = aTempIter.Value();
         for(BOPCol_IndexedDataMapOfShapeListOfShape::Iterator anIter(aMapEF); anIter.More(); anIter.Next()) {
           BOPCol_ListOfShape& aTempListOfShape = anIter.ChangeValue();
@@ -107,12 +121,18 @@ void GeomAlgoAPI_ShapeTools::combineShapes(const std::shared_ptr<GeomAPI_Shape>
             aTempListOfShape.Clear();
           } else if(aTempListOfShape.Size() > 1) {
             if(aTempListOfShape.First() == aTempShape) {
-              aTempMap.Add(aTempListOfShape.Last());
-              aFreeShapes.Remove(aTempListOfShape.Last());
+              const TopoDS_Shape& aTL = aTempListOfShape.Last();
+              if(aTempMap.Add(aTL)) {
+                aTempList.Append(aTL);
+                aFreeShapes.Remove(aTL);
+              }
               aTempListOfShape.Clear();
             } else if(aTempListOfShape.Last() == aTempShape) {
-              aTempMap.Add(aTempListOfShape.First());
-              aFreeShapes.Remove(aTempListOfShape.First());
+              const TopoDS_Shape& aTF = aTempListOfShape.First();
+              if(aTempMap.Add(aTF)) {
+                aTempList.Append(aTF);
+                aFreeShapes.Remove(aTF);
+              }
               aTempListOfShape.Clear();
             }
           }
@@ -147,3 +167,25 @@ void GeomAlgoAPI_ShapeTools::combineShapes(const std::shared_ptr<GeomAPI_Shape>
     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;
+}