]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
[bos #26800] EDF 24492 - Pb with defeaturing
authorjfa <jfa@opencascade.com>
Thu, 23 Dec 2021 15:48:27 +0000 (18:48 +0300)
committerjfa <jfa@opencascade.com>
Thu, 23 Dec 2021 15:48:27 +0000 (18:48 +0300)
src/FeaturesPlugin/FeaturesPlugin_Validators.cpp
src/GeomAPI/GeomAPI_Shape.cpp
src/GeomAPI/GeomAPI_Shape.h

index 828b4bdd8be11a16e42b47681b24bc382442d431..b5aa56afed87a137bedd12518c300f045c37f966 100644 (file)
@@ -2019,6 +2019,14 @@ bool FeaturesPlugin_ValidatorDefeaturingSelection::isValid(
       theError = "Error: Not all selected shapes are sub-shapes of solids.";
       return false;
     }
+
+    ResultBodyPtr aResRootPtr = ModelAPI_Tools::bodyOwner(aContext, true);
+    if (aResRootPtr.get() && aResRootPtr->shape().get()) {
+      if (!aResRootPtr->shape()->isCollectionOfSolids()) {
+        theError = "Error: The main shape should be a collection of solids";
+        return false;
+      }
+    }
   }
 
   return true;
index 1d3f99fcb203147736a42229c9756ecb9e609a5c..7168ccdb5ac04c8bfc87a3aec94ac45d3a7b6a2b 100644 (file)
@@ -55,6 +55,7 @@
 
 #include <BOPAlgo_CheckerSI.hxx>
 #include <BOPDS_DS.hxx>
+#include <BOPTools_AlgoTools.hxx>
 
 #include <sstream>
 #include <algorithm> // for std::transform
@@ -148,6 +149,32 @@ bool GeomAPI_Shape::isCompound() const
   return !aShape.IsNull() && aShape.ShapeType() == TopAbs_COMPOUND;
 }
 
+bool GeomAPI_Shape::isCollectionOfSolids() const
+{
+  const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
+  if (aShape.IsNull())
+    return false;
+
+  if (aShape.ShapeType() == TopAbs_SOLID ||
+      aShape.ShapeType() == TopAbs_COMPSOLID)
+    return true;
+
+  if (aShape.ShapeType() != TopAbs_COMPOUND)
+    return false;
+
+  TopTools_ListOfShape aLS;
+  TopTools_MapOfShape aMFence;
+  BOPTools_AlgoTools::TreatCompound(aShape, aLS, &aMFence);
+  TopTools_ListOfShape::Iterator it(aLS);
+  for (; it.More(); it.Next()) {
+    const TopoDS_Shape& aSx = it.Value();
+    if (aSx.ShapeType() != TopAbs_SOLID &&
+        aSx.ShapeType() != TopAbs_COMPSOLID)
+      return false;
+  }
+  return true;
+}
+
 bool GeomAPI_Shape::isCompoundOfSolids() const
 {
   const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
index 3dfed0f86756fb8394b8b3d78ecefe2600f67712..fad3425c05e15990e474458e8ac76494d1e075be 100644 (file)
@@ -110,6 +110,11 @@ public:
   GEOMAPI_EXPORT
   virtual bool isCompoundOfSolids() const;
 
+  /// Returns true, if the shape contains only solids, compsolids
+  /// and compounds of solids and compsolids of any nesting depth
+  GEOMAPI_EXPORT
+  virtual bool isCollectionOfSolids() const;
+
   /// Returns whether the shape is a compound where all elements are topologically connected
   GEOMAPI_EXPORT
   virtual bool isConnectedTopology() const;