From 290bde5bb43b763565df916f484612e3bd7e6dba Mon Sep 17 00:00:00 2001 From: mpv Date: Fri, 11 Jan 2019 16:16:29 +0300 Subject: [PATCH] Fix for the issue #2826 : generate error in group while the move-to-the-end is not implemented. --- src/Model/Model_AttributeSelection.cpp | 67 +++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/src/Model/Model_AttributeSelection.cpp b/src/Model/Model_AttributeSelection.cpp index f370d4873..5a1bdec60 100644 --- a/src/Model/Model_AttributeSelection.cpp +++ b/src/Model/Model_AttributeSelection.cpp @@ -1372,12 +1372,77 @@ void Model_AttributeSelection::updateInHistory() if (aListShapeType != GeomAPI_Shape::SHAPE && aListShapeType != aShapeShapeType) { continue; } + + ResultPtr aSetContext; + AttributeSelectionPtr aSetAttr; if (aFirst) { setValue(*aNewCont, aValueShape); - aFirst = false; + aSetContext = context(); } else if (myParent) { myParent->append(*aNewCont, aValueShape); + aSetContext = myParent->value(myParent->size() - 1)->context(); + } + + // #2826 : error if context is concealed by new context where the value is not presented + if (aSetContext.get()) { + bool anError = false; + std::list allRes; + ResultPtr aCompContext; + ResultBodyPtr aCompBody = ModelAPI_Tools::bodyOwner(aSetContext, true); + if (aCompBody.get()) { + ModelAPI_Tools::allSubs(aCompBody, allRes); + allRes.push_back(aCompBody); + aCompContext = aCompBody; + } + if (allRes.empty()) + allRes.push_back(aSetContext); + + std::list::iterator aSub = allRes.begin(); + for (; !anError && aSub != allRes.end(); aSub++) { + ResultPtr aResCont = *aSub; + ResultBodyPtr aResBody = std::dynamic_pointer_cast(aResCont); + const std::set& aRefs = aResCont->data()->refsToMe(); + std::set::const_iterator aRef = aRefs.begin(); + for (; aRef != aRefs.end(); aRef++) { + if (!aRef->get() || !(*aRef)->owner().get()) + continue; + // concealed attribute only + FeaturePtr aRefFeat = std::dynamic_pointer_cast((*aRef)->owner()); + if (!aRefFeat.get()) + continue; + if (!ModelAPI_Session::get()->validators()->isConcealed( + aRefFeat->getKind(), (*aRef)->id())) + continue; + // check the found feature is older than this attribute + if (aRefFeat == aThisFeature || aDoc->isLaterByDep(aRefFeat, aThisFeature)) + continue; + // check the found feature don't have the value-shape + GeomShapePtr aValue = aFirst ? value() : myParent->value(myParent->size() - 1)->value(); + if (aValue.get()) { + std::list::const_iterator aRefResults = aRefFeat->results().cbegin(); + for(; aRefResults != aRefFeat->results().cend(); aRefResults++) { + if ((*aRefResults)->shape().get() && + !(*aRefResults)->shape()->isSubShape(aValue, false)) { // set error + ResultPtr anEmptyContext; + std::shared_ptr anEmptyShape; + if (aFirst) { + setValue(anEmptyContext, anEmptyShape); // nullify the selection + } else { + myParent->value(myParent->size() - 1)->setValue(anEmptyContext, anEmptyShape); + } + Events_InfoMessage("Model_AttributeSelection", + "Selection of sub-shape of already modified result").send(); + anError = true; + break; + } + } + if (anError) + break; + } + } + } } + aFirst = false; } if (aFirst) { // nothing was added, all results were deleted ResultPtr anEmptyContext; -- 2.39.2