From 5e5cf940e4f1d733e98bb008f02648be4a90133a Mon Sep 17 00:00:00 2001 From: mpv Date: Wed, 28 Nov 2018 10:25:16 +0300 Subject: [PATCH] Fix for the issue #2753 : error when dump/load script --- src/Model/Model_AttributeSelection.cpp | 46 +++++++++++++++++++++----- src/XGUI/XGUI_Tools.cpp | 6 ++-- 2 files changed, 42 insertions(+), 10 deletions(-) diff --git a/src/Model/Model_AttributeSelection.cpp b/src/Model/Model_AttributeSelection.cpp index 58ba6921b..fd20f1566 100644 --- a/src/Model/Model_AttributeSelection.cpp +++ b/src/Model/Model_AttributeSelection.cpp @@ -1703,14 +1703,44 @@ ResultPtr Model_AttributeSelection::newestContext( aResults.push_back(aBody); } std::list >::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((*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; + } } } } diff --git a/src/XGUI/XGUI_Tools.cpp b/src/XGUI/XGUI_Tools.cpp index 3f5ba6636..aafafbfce 100644 --- a/src/XGUI/XGUI_Tools.cpp +++ b/src/XGUI/XGUI_Tools.cpp @@ -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()); -- 2.39.2