Salome HOME
Fix for the issue #3195 : The groups built by "Group Addtion" are not in ShaperResults
authormpv <mikhail.ponikarov@opencascade.com>
Mon, 30 Mar 2020 14:09:37 +0000 (17:09 +0300)
committermpv <mikhail.ponikarov@opencascade.com>
Mon, 30 Mar 2020 14:09:37 +0000 (17:09 +0300)
src/ConnectorAPI/Test/Test3195.py [new file with mode: 0644]
src/ConnectorAPI/Test/tests.set
src/ModelAPI/ModelAPI_Tools.cpp

diff --git a/src/ConnectorAPI/Test/Test3195.py b/src/ConnectorAPI/Test/Test3195.py
new file mode 100644 (file)
index 0000000..301c3d6
--- /dev/null
@@ -0,0 +1,52 @@
+# Copyright (C) 2014-2019  CEA/DEN, EDF R&D
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
+import sys
+import salome
+
+salome.salome_init()
+###
+### SHAPER component
+###
+from salome.shaper import model
+model.begin()
+partSet = model.moduleDocument()
+Part_1 = model.addPart(partSet)
+Part_1_doc = Part_1.document()
+Box_1 = model.addBox(Part_1_doc, 10, 10, 10)
+Group_1 = model.addGroup(Part_1_doc, "Faces", [model.selection("FACE", "Box_1_1/Left")])
+Group_2 = model.addGroup(Part_1_doc, "Faces", [model.selection("FACE", "Box_1_1/Front")])
+GroupAddition_1 = model.addGroupAddition(Part_1_doc, [model.selection("COMPOUND", "Group_1"), model.selection("COMPOUND", "Group_2")])
+model.end()
+
+###
+### SHAPERSTUDY component
+###
+
+model.publishToShaperStudy()
+# check that addition is in the SHAPERSTUDY
+
+from SHAPERSTUDY_utils import findOrCreateComponent, getStudy
+c = findOrCreateComponent()
+aSOIter = getStudy().NewChildIterator(c)
+aSO = aSOIter.Value()
+aSOIter = getStudy().NewChildIterator(aSO)
+aSOIter.Next()
+aSOIter.Next()
+aSOIter.Next()
+assert(aSOIter.Value().GetName() == GroupAddition_1.name())
index 6e74d99607d72c6d9ea515c333efb76381e57c4e..9d58214e5f090ddf54ecee413a69d0f041fddcc9 100644 (file)
@@ -26,4 +26,5 @@ SET(TEST_NAMES
   Test2882
   Test17917
   Test18887
+  Test3195
 )
index 3b0cd3701e77b1c0bac20a7dea49d2cb8a8bf7cc..8a19702d6251e081c972b5bfa117532237c17887 100644 (file)
@@ -27,6 +27,7 @@
 #include <ModelAPI_ResultBody.h>
 #include <ModelAPI_ResultParameter.h>
 #include <ModelAPI_ResultPart.h>
+#include <ModelAPI_ResultGroup.h>
 #include <ModelAPI_AttributeDocRef.h>
 #include <ModelAPI_Validator.h>
 #include <ModelAPI_AttributeIntArray.h>
@@ -41,6 +42,7 @@
 #include <ModelAPI_Events.h>
 
 #include <GeomAPI_ShapeHierarchy.h>
+#include <GeomAPI_ShapeIterator.h>
 
 #define RECURSE_TOP_LEVEL 50
 
@@ -1034,6 +1036,52 @@ std::list<FeaturePtr> referencedFeatures(
     if (aFeat.get() && (theFeatureKind.empty() || aFeat->getKind() == theFeatureKind))
       aResSet.insert(aFeat);
   }
+  // check also Group-operations that may refer to groups - add them for theFeatureKind "Group"
+  if (theFeatureKind == "Group") {
+    std::set<FeaturePtr> aGroupOperations;
+    for(bool aNeedIterate = true; aNeedIterate; ) {
+      std::set<FeaturePtr>::iterator aResIter = aResSet.begin();
+      for(; aResIter != aResSet.end(); aResIter++) {
+        std::list<ResultPtr>::const_iterator aGroupRes = (*aResIter)->results().cbegin();
+        for(; aGroupRes != (*aResIter)->results().cend(); aGroupRes++) {
+          const std::set<AttributePtr>& aRefs = (*aGroupRes)->data()->refsToMe();
+          std::set<AttributePtr>::const_iterator aRef = aRefs.cbegin();
+          for(; aRef != aRefs.cend(); aRef++) {
+            FeaturePtr aFeat = std::dynamic_pointer_cast<ModelAPI_Feature>((*aRef)->owner());
+            if (aFeat.get() && !aGroupOperations.count(aFeat) && !aFeat->results().empty() &&
+                aFeat->firstResult()->groupName() == ModelAPI_ResultGroup::group()) {
+              // iterate results of this group operation because it may be without theTarget shape
+              GeomShapePtr aTargetShape = theTarget->shape();
+              bool anIsIn = false;
+              std::list<ResultPtr>::const_iterator anOpRes = aFeat->results().cbegin();
+              for(; anOpRes != aFeat->results().cend() && !anIsIn; anOpRes++) {
+                GeomShapePtr anOpShape = (*anOpRes)->shape();
+                if (!anOpShape.get() || anOpShape->isNull())
+                  continue;
+                for(GeomAPI_ShapeIterator aSubIt(anOpShape); aSubIt.more(); aSubIt.next()) {
+                  if (aTargetShape->isSubShape(aSubIt.current(), false)) {
+                    anIsIn = true;
+                    break;
+                  }
+                }
+              }
+              if (anIsIn)
+                aGroupOperations.insert(aFeat);
+            }
+          }
+        }
+      }
+      // insert all new group operations into result and if they are, check for next dependencies
+      aNeedIterate = false;
+      std::set<FeaturePtr>::iterator aGroupOpIter = aGroupOperations.begin();
+      for(; aGroupOpIter != aGroupOperations.end(); aGroupOpIter++) {
+        if (aResSet.find(*aGroupOpIter) == aResSet.end()) {
+          aResSet.insert(*aGroupOpIter);
+          aNeedIterate = true;
+        }
+      }
+    }
+  }
 
   std::list<FeaturePtr> aResList;
   std::set<FeaturePtr>::iterator aResIter = aResSet.begin();