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;
#include <BOPAlgo_CheckerSI.hxx>
#include <BOPDS_DS.hxx>
+#include <BOPTools_AlgoTools.hxx>
#include <sstream>
#include <algorithm> // for std::transform
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>();
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;