From f3091c70ae80771d3bf86f8b0efcd529934e0442 Mon Sep 17 00:00:00 2001 From: mpv Date: Tue, 9 Apr 2019 14:50:36 +0300 Subject: [PATCH] Fix for the issue #2903 : Crash when creating a group on all faces Prevent user from selection of features and results used in other features and both with concealment ability. --- src/Model/Model_AttributeValidator.cpp | 67 ++++++++++++++++++++++++++ src/ModelAPI/CMakeLists.txt | 1 + src/ModelAPI/Test/Test2903.py | 41 ++++++++++++++++ 3 files changed, 109 insertions(+) create mode 100644 src/ModelAPI/Test/Test2903.py diff --git a/src/Model/Model_AttributeValidator.cpp b/src/Model/Model_AttributeValidator.cpp index cef720290..659082b05 100644 --- a/src/Model/Model_AttributeValidator.cpp +++ b/src/Model/Model_AttributeValidator.cpp @@ -23,6 +23,10 @@ #include #include +#include +#include +#include +#include #include #include @@ -82,6 +86,69 @@ 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() && + aRefd->groupName() != ModelAPI_ResultPart::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())) { + theError = "Reference to concealed object %1"; + theError.arg(aRefd->data()->name()); + return false; + } + } + if (aCheckFeature) + aRefRes++; + } + } + } + } + } } return true; } diff --git a/src/ModelAPI/CMakeLists.txt b/src/ModelAPI/CMakeLists.txt index dbb19965c..27bf50712 100644 --- a/src/ModelAPI/CMakeLists.txt +++ b/src/ModelAPI/CMakeLists.txt @@ -245,4 +245,5 @@ ADD_UNIT_TESTS(TestConstants.py Test2859.py Test2873.py Test2901.py + Test2903.py ) diff --git a/src/ModelAPI/Test/Test2903.py b/src/ModelAPI/Test/Test2903.py new file mode 100644 index 000000000..b97b1e6c1 --- /dev/null +++ b/src/ModelAPI/Test/Test2903.py @@ -0,0 +1,41 @@ +# 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 +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# 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 +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +from salome.shaper import model +from ModelAPI import * + +model.begin() +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() +Box_1 = model.addBox(Part_1_doc, 10, 10, 10) +Cylinder_1 = model.addCylinder(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "PartSet/OZ"), 5, 10) +Sphere_1 = model.addSphere(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), 10) +Fuse_1 = model.addFuse(Part_1_doc, [model.selection("COMPOUND", "all-in-Box_1"), model.selection("COMPOUND", "all-in-Cylinder_1")], True) +Partition_1 = model.addPartition(Part_1_doc, [model.selection("COMPOUND", "all-in-Fuse_1"), model.selection("COMPOUND", "all-in-Sphere_1")]) +model.do() +aFactory = ModelAPI_Session.get().validators() +assert(aFactory.validate(Fuse_1.feature())) +assert(aFactory.validate(Partition_1.feature())) +# Modify Fuse to add sphere thatwas used in Partition +Fuse_1.setMainObjects([model.selection("COMPOUND", "all-in-Box_1"), model.selection("COMPOUND", "all-in-Cylinder_1"), model.selection("COMPOUND", "all-in-Sphere_1")]) +model.end() +# both fuse and partition must become invalid because both refer to the same object +assert(not aFactory.validate(Fuse_1.feature())) +assert(not aFactory.validate(Partition_1.feature())) -- 2.39.2