-// Copyright (C) 2014-2020 CEA/DEN, EDF R&D
+// Copyright (C) 2014-2024 CEA, EDF
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
#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>();
BRepBuilderAPI_FindPlane aFindPlane(aShape);
bool isFound = aFindPlane.Found() == Standard_True;
- if(!isFound && aShapeType == TopAbs_EDGE) {
- Standard_Real aFirst, aLast;
- Handle(Geom_Curve) aCurve = BRep_Tool::Curve(TopoDS::Edge(aShape), aFirst, aLast);
- Handle(Standard_Type) aType = aCurve->DynamicType();
+ if(!isFound) {
- if(aType == STANDARD_TYPE(Geom_TrimmedCurve)) {
- Handle(Geom_TrimmedCurve) aTrimCurve = Handle(Geom_TrimmedCurve)::DownCast(aCurve);
- aType = aTrimCurve->BasisCurve()->DynamicType();
- }
+ auto checkEdge = [](const TopoDS_Shape& theShape){
+ if(theShape.ShapeType()!= TopAbs_EDGE)
+ return false;
- if(aType == STANDARD_TYPE(Geom_Line)
- || aType == STANDARD_TYPE(Geom_Conic)
- || aType == STANDARD_TYPE(Geom_Circle)
- || aType == STANDARD_TYPE(Geom_Ellipse)
- || aType == STANDARD_TYPE(Geom_Hyperbola)
- || aType == STANDARD_TYPE(Geom_Parabola)) {
- isFound = true;
+ Standard_Real aFirst, aLast;
+ Handle(Geom_Curve) aCurve = BRep_Tool::Curve(TopoDS::Edge(theShape), aFirst, aLast);
+ Handle(Standard_Type) aType = aCurve->DynamicType();
+ if(aType == STANDARD_TYPE(Geom_TrimmedCurve)) {
+ Handle(Geom_TrimmedCurve) aTrimCurve = Handle(Geom_TrimmedCurve)::DownCast(aCurve);
+ aType = aTrimCurve->BasisCurve()->DynamicType();
+ }
+
+ if(aType == STANDARD_TYPE(Geom_Line)
+ || aType == STANDARD_TYPE(Geom_Conic)
+ || aType == STANDARD_TYPE(Geom_Circle)
+ || aType == STANDARD_TYPE(Geom_Ellipse)
+ || aType == STANDARD_TYPE(Geom_Hyperbola)
+ || aType == STANDARD_TYPE(Geom_Parabola)) {
+ return true;
+ }
+ return false;
+ };
+
+ if(aShapeType == TopAbs_WIRE){
+ //check if wire consist of only one edge
+ int aNbEdges = 0;
+ TopExp_Explorer anExp(aShape, TopAbs_EDGE);
+ for (TopExp_Explorer anExp(aShape, TopAbs_EDGE); anExp.More(); anExp.Next()) {
+ aNbEdges++;
+ if(aNbEdges == 1){
+ const TopoDS_Edge& anEdge = TopoDS::Edge(anExp.Current());
+ isFound = checkEdge(anEdge);
+ }
+ else{
+ //if more than one edge, check is not valid
+ isFound = false;
+ break;
+ }
+ }
+ }
+ else if(aShapeType == TopAbs_EDGE){
+ isFound = checkEdge(aShape);
}
}
}
std::list<std::shared_ptr<GeomAPI_Shape> >
-GeomAPI_Shape::subShapes(ShapeType theSubShapeType) const
+GeomAPI_Shape::subShapes(const ShapeType theSubShapeType, const bool theOnlyUnique) const
{
ListOfShape aSubs;
const TopoDS_Shape& aShape = impl<TopoDS_Shape>();
if (aShape.IsNull())
return aSubs;
+ TopTools_MapOfShape alreadyThere;
+
// process multi-level compounds
if (shapeType() == COMPOUND && theSubShapeType == COMPOUND) {
for (TopoDS_Iterator anIt(aShape); anIt.More(); anIt.Next()) {
const TopoDS_Shape& aCurrent = anIt.Value();
if (aCurrent.ShapeType() == TopAbs_COMPOUND) {
- GeomShapePtr aSub(new GeomAPI_Shape);
- aSub->setImpl(new TopoDS_Shape(aCurrent));
- aSubs.push_back(aSub);
+ if (!theOnlyUnique || alreadyThere.Add(aCurrent)) {
+ GeomShapePtr aSub(new GeomAPI_Shape);
+ aSub->setImpl(new TopoDS_Shape(aCurrent));
+ aSubs.push_back(aSub);
+ }
}
}
// add self
else {
for (TopExp_Explorer anExp(aShape, (TopAbs_ShapeEnum)theSubShapeType);
anExp.More(); anExp.Next()) {
- GeomShapePtr aSub(new GeomAPI_Shape);
- aSub->setImpl(new TopoDS_Shape(anExp.Current()));
- aSubs.push_back(aSub);
+ if (!theOnlyUnique || alreadyThere.Add(anExp.Current())) {
+ GeomShapePtr aSub(new GeomAPI_Shape);
+ aSub->setImpl(new TopoDS_Shape(anExp.Current()));
+ aSubs.push_back(aSub);
+ }
}
}
return aSubs;