Salome HOME
Fix for the issue #2892 : Group in error when loading dump from Test2241.py
authormpv <mpv@opencascade.com>
Fri, 22 Mar 2019 05:11:40 +0000 (08:11 +0300)
committermpv <mpv@opencascade.com>
Fri, 22 Mar 2019 05:11:40 +0000 (08:11 +0300)
src/Model/Model_AttributeSelection.cpp
src/ModelAPI/ModelAPI_Tools.cpp
src/ModelAPI/ModelAPI_Tools.h

index c60f41ca246d240be23bd3f8793ccd633b7dd8a8..2aa1f2ee9e51759c3a21738fb7ded23946672d4f 100644 (file)
@@ -1522,14 +1522,32 @@ void Model_AttributeSelection::updateInHistory(bool& theRemove)
         continue;
       }
 
+      ResultPtr aNewContext = *aNewCont;
+      if (aValueShape.get()) { // #2892 if context is higher level result, search this sub in lower
+        ResultBodyPtr aBodyContext = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aNewContext);
+        if (aBodyContext.get() && aBodyContext->numberOfSubs() != 0) {
+          std::list<ResultPtr> aLower;
+          ModelAPI_Tools::allSubs(aBodyContext, aLower, true);
+          for(std::list<ResultPtr>::iterator aL = aLower.begin(); aL != aLower.end(); aL++) {
+            GeomShapePtr aLShape = (*aL)->shape();
+            if (aLShape.get() && !aLShape->isNull()) {
+              if (aLShape->isSubShape(aValueShape, false)) {
+                aNewContext = *aL;
+                break;
+              }
+            }
+          }
+        }
+      }
+
       if (aFirst) {
-        if (!myParent || !myParent->isInList(*aNewCont, aValueShape)) { // avoid duplicates
-          setValue(*aNewCont, aValueShape);
+        if (!myParent || !myParent->isInList(aNewContext, aValueShape)) { // avoid duplicates
+          setValue(aNewContext, aValueShape);
           aFirst = false;
         }
       } else if (myParent) {
-        if (!myParent->isInList(*aNewCont, aValueShape)) // avoid addition of duplicates
-          myParent->append(*aNewCont, aValueShape);
+        if (!myParent->isInList(aNewContext, aValueShape)) // avoid addition of duplicates
+          myParent->append(aNewContext, aValueShape);
       }
     }
     if (aFirst) { // nothing was added, all results were deleted
index a5cd808fda611c026c4e1ba0bbc66c22c9358c79..d09d215eb7729fcf8e80cf7c43d57c06be0530ee 100644 (file)
@@ -301,14 +301,16 @@ bool hasSubResults(const ResultPtr& theResult)
   return aCompSolid.get() && aCompSolid->numberOfSubs() > 0;
 }
 
-void allSubs(const ResultBodyPtr& theResult, std::list<ResultPtr>& theResults) {
+void allSubs(const ResultBodyPtr& theResult, std::list<ResultPtr>& theResults,
+             const bool theLowerOnly) {
   // iterate sub-bodies of compsolid
   ResultBodyPtr aComp = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theResult);
   if (aComp.get()) {
     int aNumSub = aComp->numberOfSubs();
     for (int a = 0; a < aNumSub; a++) {
       ResultBodyPtr aSub = aComp->subResult(a);
-      theResults.push_back(aSub);
+      if (!theLowerOnly || aSub->numberOfSubs() == 0)
+        theResults.push_back(aSub);
       allSubs(aSub, theResults);
     }
   }
index d566822df56b918ece999d8f116198a485c1304b..1b239535179594aab68399328cba08be6c9c5709 100644 (file)
@@ -125,7 +125,8 @@ MODELAPI_EXPORT bool hasSubResults(const std::shared_ptr<ModelAPI_Result>& theRe
 *  collects recursively all subs of the given result
 */
 MODELAPI_EXPORT void allSubs(const std::shared_ptr<ModelAPI_ResultBody>& theResult,
-                             std::list<std::shared_ptr<ModelAPI_Result> >& theResults);
+                             std::list<std::shared_ptr<ModelAPI_Result> >& theResults,
+                             const bool theLowerOnly = false);
 
 /*!
 * Adds the results of the given feature to theResults list: including disabled and sub-results