]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Fix for the issue #2753 : error when dump/load script
authormpv <mpv@opencascade.com>
Wed, 28 Nov 2018 07:25:16 +0000 (10:25 +0300)
committermpv <mpv@opencascade.com>
Wed, 28 Nov 2018 07:25:16 +0000 (10:25 +0300)
src/Model/Model_AttributeSelection.cpp
src/XGUI/XGUI_Tools.cpp

index 58ba6921bba8b64c266b33443e67fbc1f142bd8f..fd20f15660e9dd16c6288850f053670bc808d291 100644 (file)
@@ -1703,14 +1703,44 @@ ResultPtr Model_AttributeSelection::newestContext(
             aResults.push_back(aBody);
         }
         std::list<std::shared_ptr<ModelAPI_Result> >::iterator aResIter = aResults.begin();
-        for (; aResIter != aResults.end(); aResIter++) {
-          if (!aResIter->get() || !(*aResIter)->data()->isValid() || (*aResIter)->isDisabled())
-            continue;
-          GeomShapePtr aShape = (*aResIter)->shape();
-          if (aShape.get() && (theAnyValue || aShape->isSubShape(aSelectedShape, false))) {
-            aResult = *aResIter; // found new context (produced from this) with same subshape
-            aFindNewContext = true; // continue searching further
-            break;
+
+        if (theAnyValue) { // searching the best sub-result by maximum number of references to orig
+          int aReferencesCount = 0;
+          ResultPtr aBestResult;
+          for (; aResIter != aResults.end(); aResIter++) {
+            if (!aResIter->get() || !(*aResIter)->data()->isValid() || (*aResIter)->isDisabled())
+              continue;
+            TDF_Label aCandidateLab =
+              std::dynamic_pointer_cast<Model_Data>((*aResIter)->data())->shapeLab();
+            Handle(TDF_Reference) aRef;
+            if (aCandidateLab.FindAttribute(TDF_Reference::GetID(), aRef)) {
+              TDF_Label aRefLab = aRef->Get();
+              ResultPtr aRefRes = aDoc->resultByLab(aRefLab);
+              if (aRefRes.get() && aRefRes->shape().get() &&
+                  aRefRes->shape()->isEqual(aResult->shape())) {// it directly references to result
+                aResult = *aResIter; // found new context (produced from this) with same subshape
+                aFindNewContext = true; // continue searching further
+                break;
+              }
+            } else {
+              if (!aBestResult.get())
+                aBestResult = *aResIter;
+            }
+          }
+          if (aBestResult.get() && !aFindNewContext) { // the first good result for now
+            aResult = aBestResult; // found new context
+            aFindNewContext = true;
+          }
+        } else { // searching by sub-shape
+          for (; aResIter != aResults.end(); aResIter++) {
+            if (!aResIter->get() || !(*aResIter)->data()->isValid() || (*aResIter)->isDisabled())
+              continue;
+            GeomShapePtr aShape = (*aResIter)->shape();
+            if (aShape.get() && (theAnyValue || aShape->isSubShape(aSelectedShape, false))) {
+              aResult = *aResIter; // found new context (produced from this) with same subshape
+              aFindNewContext = true; // continue searching further
+              break;
+            }
           }
         }
       }
index 3f5ba6636018090950eca9e39bb6d42903786278..aafafbfce01a3fc3916387ac4122e507cedc0c1e 100644 (file)
@@ -166,9 +166,11 @@ bool canRename(const ObjectPtr& theObject, const QString& theName)
       return false;
     }
   }
-  else if ((aType == ModelAPI_ResultConstruction::group()) || (aType == ModelAPI_ResultBody::group())) {
+  else if ((aType == ModelAPI_ResultConstruction::group()) ||
+           (aType == ModelAPI_ResultBody::group())) {
     DocumentPtr aDoc = theObject->document();
-    ObjectPtr aObj = aDoc->objectByName(ModelAPI_ResultConstruction::group(), theName.toStdString());
+    ObjectPtr aObj =
+      aDoc->objectByName(ModelAPI_ResultConstruction::group(), theName.toStdString());
     if (!aObj.get())
       aObj = aDoc->objectByName(ModelAPI_ResultBody::group(), theName.toStdString());