From: jfa Date: Thu, 23 Dec 2021 15:48:27 +0000 (+0300) Subject: [bos #26800] EDF 24492 - Pb with defeaturing X-Git-Tag: V9_9_0a1~14 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=264b53a6292f1a50fbe94ffc62b931c4a047c256;p=modules%2Fshaper.git [bos #26800] EDF 24492 - Pb with defeaturing --- diff --git a/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp b/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp index 828b4bdd8..b5aa56afe 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp @@ -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; diff --git a/src/GeomAPI/GeomAPI_Shape.cpp b/src/GeomAPI/GeomAPI_Shape.cpp index 1d3f99fcb..7168ccdb5 100644 --- a/src/GeomAPI/GeomAPI_Shape.cpp +++ b/src/GeomAPI/GeomAPI_Shape.cpp @@ -55,6 +55,7 @@ #include #include +#include #include #include // 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(this)->impl(); + 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(this)->impl(); diff --git a/src/GeomAPI/GeomAPI_Shape.h b/src/GeomAPI/GeomAPI_Shape.h index 3dfed0f86..fad3425c0 100644 --- a/src/GeomAPI/GeomAPI_Shape.h +++ b/src/GeomAPI/GeomAPI_Shape.h @@ -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;