]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Support of connected topology icon for issue #1332
authormpv <mpv@opencascade.com>
Wed, 4 May 2016 14:13:43 +0000 (17:13 +0300)
committermpv <mpv@opencascade.com>
Wed, 4 May 2016 14:13:43 +0000 (17:13 +0300)
src/GeomAPI/GeomAPI_Shape.cpp
src/GeomAPI/GeomAPI_Shape.h
src/PartSet/PartSet_IconFactory.cpp

index 1c97ef8b42ec78f4211e03035d2212d0595e0ace..3b85b2dcf421425fa6f81f2220498bc4fa623321 100644 (file)
@@ -25,6 +25,7 @@
 #include <TopoDS.hxx>
 #include <TopoDS_Iterator.hxx>
 #include <TopoDS_Shape.hxx>
+#include <NCollection_List.hxx>
 
 #include <sstream>
 
@@ -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<TopoDS_Shape>& 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<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
+  if (aShape.IsNull() || aShape.ShapeType() != TopAbs_COMPOUND)
+    return false;
+  NCollection_List<TopoDS_Shape> 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<TopoDS_Shape> aNewConnected;
+  aNewConnected.Append(aNotConnected.First());
+  aNotConnected.RemoveFirst();
+  // iterate until some new element become connected
+  while(!aNewConnected.IsEmpty() && !aNotConnected.IsEmpty()) {
+    NCollection_List<TopoDS_Shape> aNew; // very new connected to new connected
+    NCollection_List<TopoDS_Shape>::Iterator aNotIter(aNotConnected);
+    while(aNotIter.More()) {
+      bool aConnected =  false;
+      NCollection_List<TopoDS_Shape>::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<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
index 1ed86db9c1059bf83a3acc89f098d11bc9382961..098245119c13aa28dc5775ad90170410d5ab714b 100644 (file)
@@ -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;
index 45b5f19e380a8408e2b717d98cdcf553b0472976..2beae8cc10aeb6646be0bc8fb87daefded454a96 100644 (file)
@@ -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");