Salome HOME
Make groups don't change the whole group-shape if sub-shapes are still the same.
authormpv <mikhail.ponikarov@opencascade.com>
Tue, 7 Apr 2020 15:36:43 +0000 (18:36 +0300)
committermpv <mikhail.ponikarov@opencascade.com>
Tue, 7 Apr 2020 15:36:43 +0000 (18:36 +0300)
src/PY/SHAPERSTUDY_Object.py
src/StudyData/StudyData_Object.cpp

index d0d2317eae418bd591344ce144410526e1b07f8c..b47e60721c6f6c331f89ba0054f7020552b38f68 100755 (executable)
@@ -366,7 +366,8 @@ class SHAPERSTUDY_Group(SHAPERSTUDY_ORB__POA.SHAPER_Group, SHAPERSTUDY_Object):
         """
         Sets what is returned in the GEOM_IGroupOperations::GetObjects
         """
-        self.data = None # nullify the cashed shape when selection is changed
+        #self.data = None # nullify the cashed shape when selection is changed
+        print("Set selection for the group " + str(self.entry) + " = " + str(theSelection))
         self.selection = theSelection
 
     def GetSelection(self):
index 380e1f4f4657e40b47be93110a2f54089eef0b99..1fcd754a7058d7abb0054bffd2206d6fd1cdfb89 100644 (file)
@@ -23,6 +23,7 @@
 #include "StudyData_Object.h"
 
 #include <TopExp.hxx>
+#include <TopoDS_Iterator.hxx>
 #include <BRep_Builder.hxx>
 #include <BRepTools.hxx>
 #include <BRepBuilderAPI_Copy.hxx>
@@ -118,6 +119,28 @@ long long StudyData_Object::groupShape(long long theMainShape, const std::list<l
       aBuilder.Add(aResult, aSel);
     }
     myShape = aResult;
+  } else { // check myShape equals to the new result
+    TopoDS_Shape* aShape = (TopoDS_Shape*)theMainShape;
+    TopTools_IndexedMapOfShape anIndices;
+    TopExp::MapShapes(*aShape, anIndices);
+    TopoDS_Iterator aMyIter(myShape);
+    std::list<long>::const_iterator aSelIter = theSelection.cbegin();
+    for(; aSelIter != theSelection.cend() && aMyIter.More(); aSelIter++, aMyIter.Next()) {
+      TopoDS_Shape aSel = anIndices.FindKey(*aSelIter);
+      if (!aSel.IsSame(aMyIter.Value()))
+        break;
+    }
+    if (aMyIter.More() || aSelIter != theSelection.cend()) { // recompute myShape
+      TopoDS_Compound aResult;
+      BRep_Builder aBuilder;
+      aBuilder.MakeCompound(aResult);
+      std::list<long>::const_iterator aSelIter = theSelection.cbegin();
+      for(; aSelIter != theSelection.cend(); aSelIter++) {
+        TopoDS_Shape aSel = anIndices.FindKey(*aSelIter);
+        aBuilder.Add(aResult, aSel);
+      }
+      myShape = aResult;
+    }
   }
   return (long long)(&myShape);
 }