X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModel%2FModel_AttributeValidator.cpp;h=ff4272667f2e7ae29ae80f9b27e60bd92c08580d;hb=d2e4b71d0d31626556b47f21bfbdd759b86ba85d;hp=cef7202906378c2136bb1aebb90f1f25ae632976;hpb=6e421e939851e0de46554ae45a3ca0e1f67cd91d;p=modules%2Fshaper.git diff --git a/src/Model/Model_AttributeValidator.cpp b/src/Model/Model_AttributeValidator.cpp index cef720290..ff4272667 100644 --- a/src/Model/Model_AttributeValidator.cpp +++ b/src/Model/Model_AttributeValidator.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2019 CEA/DEN, EDF R&D +// Copyright (C) 2014-2021 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -23,12 +23,16 @@ #include #include +#include +#include +#include +#include #include #include bool Model_AttributeValidator::isValid(const AttributePtr& theAttribute, - const std::list& theArguments, + const std::list& /*theArguments*/, Events_InfoMessage& theError) const { if (theAttribute->attributeType() == ModelAPI_AttributeInteger::typeId()) { @@ -82,6 +86,90 @@ bool Model_AttributeValidator::isValid(const AttributePtr& theAttribute, theError.arg(anErrorMessage); return false; } + } else { // #2903 : check that concealed attribute refers to already concealed result + FeaturePtr aFeat = std::dynamic_pointer_cast(theAttribute->owner()); + + std::set alreadyProcessed; // optimization + if (aFeat.get() && + ModelAPI_Session::get()->validators()->isConcealed(aFeat->getKind(), theAttribute->id())) { + std::list > > allRefs; + aFeat->data()->referencesToObjects(allRefs); + std::list > >::iterator anIter = allRefs.begin(); + for(; anIter != allRefs.end(); anIter++) { + if (anIter->first == theAttribute->id()) { + const std::list& aReferencedList = anIter->second; + std::list::const_iterator aRefIter = aReferencedList.cbegin(); + for(; aRefIter != aReferencedList.cend(); aRefIter++) { + const ObjectPtr& aReferenced = *aRefIter; + if (!aReferenced.get()) + continue; + // get all results and feature that is referenced to see all references to them + FeaturePtr aReferencedFeature; + if (aReferenced->groupName() == ModelAPI_Feature::group()) { + aReferencedFeature = std::dynamic_pointer_cast(aReferenced); + } else { + aReferencedFeature = aReferenced->document()->feature( + std::dynamic_pointer_cast(aReferenced)); + } + if (alreadyProcessed.count(aReferencedFeature)) + continue; + alreadyProcessed.insert(aReferencedFeature); + /* it takes all results, not only concealed + std::list aReferencedResults; + ModelAPI_Tools::allResults(aReferencedFeature, aReferencedResults); + */ + std::list aReferencedResults; + ResultBodyPtr aRefBody = std::dynamic_pointer_cast(aReferenced); + if (aRefBody.get()) { // take only sub-results of this result or sub-result + ResultBodyPtr aRoot = ModelAPI_Tools::bodyOwner(aRefBody, true); + if (aRoot.get()) { + ModelAPI_Tools::allSubs(aRoot, aReferencedResults, false); + aReferencedResults.push_back(aRoot); + } else + aReferencedResults.push_back(aRefBody); + } + + std::list::iterator aRefRes = aReferencedResults.begin(); + bool aCheckFeature = true; // the last iteration to check the feature + while(aRefRes != aReferencedResults.end() || aCheckFeature) { + ObjectPtr aRefd; + if (aRefRes == aReferencedResults.end()) { + aRefd = aReferencedFeature; + aCheckFeature = false; + if (!aReferencedFeature->results().empty() && + aReferencedFeature->firstResult()->groupName() != ModelAPI_ResultBody::group()) + break; + } else { + aRefd = *aRefRes; + if (aRefd->groupName() != ModelAPI_ResultBody::group()) + break; + } + if (!aRefd->data().get() || !aRefd->data()->isValid()) + continue; + const std::set& aRefsToRef = aRefd->data()->refsToMe(); + std::set::const_iterator aRR = aRefsToRef.cbegin(); + for(; aRR != aRefsToRef.cend(); aRR++) { + FeaturePtr aRefFeat = std::dynamic_pointer_cast((*aRR)->owner()); + if (!aRefFeat.get() || aRefFeat == aFeat) + continue; + if (ModelAPI_Session::get()->validators()->isConcealed( + aRefFeat->getKind(), (*aRR)->id())) { + // check this feature is later than another referenced to make unit tests working + //because of Test1757 and others: allow to move selection context of this to next + if (aFeat->document()->isLater(aFeat, aRefFeat)) { + theError = "Reference to concealed object %1"; + theError.arg(aRefd->data()->name()); + return false; + } + } + } + if (aCheckFeature) + aRefRes++; + } + } + } + } + } } return true; }