X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModel%2FModel_AttributeValidator.cpp;h=135a6a423332217dac18c91ccc0f5d0de5093205;hb=6a1577e598a99ab41c52ab59b9126de648208028;hp=f6a9307e5bd566c9b1204711635a762decc7fd37;hpb=87b6a30a3afb8fb32e7e43ade8d9c947d9eb1684;p=modules%2Fshaper.git diff --git a/src/Model/Model_AttributeValidator.cpp b/src/Model/Model_AttributeValidator.cpp index f6a9307e5..135a6a423 100644 --- a/src/Model/Model_AttributeValidator.cpp +++ b/src/Model/Model_AttributeValidator.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 CEA/DEN, EDF R&D +// Copyright (C) 2014-2019 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 @@ -12,10 +12,9 @@ // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// See http://www.salome-platform.org/ or -// email : webmaster.salome@opencascade.com +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // #include "Model_AttributeValidator.h" @@ -24,6 +23,10 @@ #include #include +#include +#include +#include +#include #include #include @@ -83,6 +86,72 @@ 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; + // 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); + std::list aReferencedResults; + ModelAPI_Tools::allResults(aReferencedFeature, aReferencedResults); + 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; + } 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; }