From 99c58ea100c94938c5c4e6654a2bc3960f0f0c96 Mon Sep 17 00:00:00 2001 From: mpv Date: Fri, 22 Mar 2019 08:11:40 +0300 Subject: [PATCH] Fix for the issue #2892 : Group in error when loading dump from Test2241.py --- src/Model/Model_AttributeSelection.cpp | 26 ++++++++++++++++++++++---- src/ModelAPI/ModelAPI_Tools.cpp | 6 ++++-- src/ModelAPI/ModelAPI_Tools.h | 3 ++- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/Model/Model_AttributeSelection.cpp b/src/Model/Model_AttributeSelection.cpp index c60f41ca2..2aa1f2ee9 100644 --- a/src/Model/Model_AttributeSelection.cpp +++ b/src/Model/Model_AttributeSelection.cpp @@ -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(aNewContext); + if (aBodyContext.get() && aBodyContext->numberOfSubs() != 0) { + std::list aLower; + ModelAPI_Tools::allSubs(aBodyContext, aLower, true); + for(std::list::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 diff --git a/src/ModelAPI/ModelAPI_Tools.cpp b/src/ModelAPI/ModelAPI_Tools.cpp index a5cd808fd..d09d215eb 100644 --- a/src/ModelAPI/ModelAPI_Tools.cpp +++ b/src/ModelAPI/ModelAPI_Tools.cpp @@ -301,14 +301,16 @@ bool hasSubResults(const ResultPtr& theResult) return aCompSolid.get() && aCompSolid->numberOfSubs() > 0; } -void allSubs(const ResultBodyPtr& theResult, std::list& theResults) { +void allSubs(const ResultBodyPtr& theResult, std::list& theResults, + const bool theLowerOnly) { // iterate sub-bodies of compsolid ResultBodyPtr aComp = std::dynamic_pointer_cast(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); } } diff --git a/src/ModelAPI/ModelAPI_Tools.h b/src/ModelAPI/ModelAPI_Tools.h index d566822df..1b2395351 100644 --- a/src/ModelAPI/ModelAPI_Tools.h +++ b/src/ModelAPI/ModelAPI_Tools.h @@ -125,7 +125,8 @@ MODELAPI_EXPORT bool hasSubResults(const std::shared_ptr& theRe * collects recursively all subs of the given result */ MODELAPI_EXPORT void allSubs(const std::shared_ptr& theResult, - std::list >& theResults); + std::list >& theResults, + const bool theLowerOnly = false); /*! * Adds the results of the given feature to theResults list: including disabled and sub-results -- 2.39.2