From 3170cb411285df0bc16a9b411ab65b89ee1878a3 Mon Sep 17 00:00:00 2001 From: mpv Date: Wed, 4 May 2016 17:13:43 +0300 Subject: [PATCH] Support of connected topology icon for issue #1332 --- src/GeomAPI/GeomAPI_Shape.cpp | 63 +++++++++++++++++++++++++++++ src/GeomAPI/GeomAPI_Shape.h | 4 ++ src/PartSet/PartSet_IconFactory.cpp | 3 +- 3 files changed, 69 insertions(+), 1 deletion(-) diff --git a/src/GeomAPI/GeomAPI_Shape.cpp b/src/GeomAPI/GeomAPI_Shape.cpp index 1c97ef8b4..3b85b2dcf 100644 --- a/src/GeomAPI/GeomAPI_Shape.cpp +++ b/src/GeomAPI/GeomAPI_Shape.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include @@ -90,6 +91,68 @@ bool GeomAPI_Shape::isCompoundOfSolids() const return isAtLeastOne; } +// adds the nopt-compound elements recursively to the list +static void addSimpleToList(const TopoDS_Shape& theShape, NCollection_List& theList) +{ + if (!theShape.IsNull()) { + if (theShape.ShapeType() == TopAbs_COMPOUND) { + for(TopoDS_Iterator aSubs(theShape); aSubs.More(); aSubs.Next()) { + addSimpleToList(aSubs.Value(), theList); + } + } else { + theList.Append(theShape); + } + } +} + +bool GeomAPI_Shape::isConnectedTopology() const +{ + const TopoDS_Shape& aShape = const_cast(this)->impl(); + if (aShape.IsNull() || aShape.ShapeType() != TopAbs_COMPOUND) + return false; + NCollection_List aNotConnected; // list of simple elements that are not detected in connection to others + addSimpleToList(aShape, aNotConnected); + if (aNotConnected.IsEmpty()) // an empty compound + return false; + + // collect here the group of connected subs, starting with one first element + NCollection_List aNewConnected; + aNewConnected.Append(aNotConnected.First()); + aNotConnected.RemoveFirst(); + // iterate until some new element become connected + while(!aNewConnected.IsEmpty() && !aNotConnected.IsEmpty()) { + NCollection_List aNew; // very new connected to new connected + NCollection_List::Iterator aNotIter(aNotConnected); + while(aNotIter.More()) { + bool aConnected = false; + NCollection_List::Iterator aNewIter(aNewConnected); + for(; !aConnected && aNewIter.More(); aNewIter.Next()) { + // checking topological connecion of aNotIter and aNewIter (if shapes are connected, vertices are connected for sure) + TopExp_Explorer anExp1(aNotIter.Value(), TopAbs_VERTEX); + for(; !aConnected && anExp1.More(); anExp1.Next()) { + TopExp_Explorer anExp2(aNewIter.Value(), TopAbs_VERTEX); + for(; anExp2.More(); anExp2.Next()) { + if (anExp1.Current().IsSame(anExp2.Current())) { + aConnected = true; + break; + } + } + } + } + if (aConnected) { + aNew.Append(aNotIter.Value()); + aNotConnected.Remove(aNotIter); + } else { + aNotIter.Next(); + } + } + // remove all new connected and put to this list very new connected + aNewConnected.Clear(); + aNewConnected.Append(aNew); + } + return aNotConnected.IsEmpty() == Standard_True; +} + bool GeomAPI_Shape::isSolid() const { const TopoDS_Shape& aShape = const_cast(this)->impl(); diff --git a/src/GeomAPI/GeomAPI_Shape.h b/src/GeomAPI/GeomAPI_Shape.h index 1ed86db9c..098245119 100644 --- a/src/GeomAPI/GeomAPI_Shape.h +++ b/src/GeomAPI/GeomAPI_Shape.h @@ -58,6 +58,10 @@ public: GEOMAPI_EXPORT virtual bool isCompoundOfSolids() const; + /// Returns whether the shape is a compound where all elements are topologically connected + GEOMAPI_EXPORT + virtual bool isConnectedTopology() const; + /// Returns whether the shape is a solid GEOMAPI_EXPORT virtual bool isSolid() const; diff --git a/src/PartSet/PartSet_IconFactory.cpp b/src/PartSet/PartSet_IconFactory.cpp index 45b5f19e3..2beae8cc1 100644 --- a/src/PartSet/PartSet_IconFactory.cpp +++ b/src/PartSet/PartSet_IconFactory.cpp @@ -79,7 +79,8 @@ QIcon PartSet_IconFactory::getIcon(ObjectPtr theObj) GeomShapePtr aShape = aResult->shape(); if(aShape.get()) { switch(aShape->shapeType()) { - case GeomAPI_Shape::COMPOUND: return QIcon(":pictures/compound.png"); + case GeomAPI_Shape::COMPOUND: return aShape->isConnectedTopology() ? + QIcon(":pictures/compoundofsolids.png") : QIcon(":pictures/compound.png"); case GeomAPI_Shape::COMPSOLID: return QIcon(":pictures/compsolid.png"); case GeomAPI_Shape::SOLID: return QIcon(":pictures/solid.png"); case GeomAPI_Shape::SHELL: return QIcon(":pictures/shell.png"); -- 2.39.2