From 27aa5163d068dbfa35119bedf2b45c9f52396af3 Mon Sep 17 00:00:00 2001 From: mpv Date: Tue, 8 May 2018 11:45:24 +0300 Subject: [PATCH] Fix for the issue #2474 : part parameter has higher priority than partset parameter with the same name --- src/ParametersPlugin/CMakeLists.txt | 1 + .../ParametersPlugin_EvalListener.cpp | 27 +++++++++++ src/ParametersPlugin/Test/Test2474.py | 48 +++++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100644 src/ParametersPlugin/Test/Test2474.py diff --git a/src/ParametersPlugin/CMakeLists.txt b/src/ParametersPlugin/CMakeLists.txt index a5aae8923..b37fe03f2 100644 --- a/src/ParametersPlugin/CMakeLists.txt +++ b/src/ParametersPlugin/CMakeLists.txt @@ -118,4 +118,5 @@ ADD_UNIT_TESTS(TestParameterCreation.py TestParameterChangeValue.py Test1806.py Test2392.py + Test2474.py ) diff --git a/src/ParametersPlugin/ParametersPlugin_EvalListener.cpp b/src/ParametersPlugin/ParametersPlugin_EvalListener.cpp index c485dffde..d2481ebdd 100644 --- a/src/ParametersPlugin/ParametersPlugin_EvalListener.cpp +++ b/src/ParametersPlugin/ParametersPlugin_EvalListener.cpp @@ -250,10 +250,37 @@ void setParameterName(ResultParameterPtr theResultParameter, const std::string& std::dynamic_pointer_cast( ModelAPI_Feature::feature(theResultParameter)); + std::string anOldName = aParameter->name(); aWasBlocked = aParameter->data()->blockSendAttributeUpdated(true); aParameter->data()->setName(theName); aParameter->string(ParametersPlugin_Parameter::VARIABLE_ID())->setValue(theName); aParameter->data()->blockSendAttributeUpdated(aWasBlocked); + + // #2474 : if parameter name now hides/shows the higher level parameter name, + // update the depended expressions + DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); + if (theResultParameter->document() != aRootDoc) { + std::list aNames; // collect names in the root document that must be checked + aNames.push_back(theName); + if (anOldName != theName) { + aNames.push_back(anOldName); + } + std::list::iterator aNIter = aNames.begin(); + for (; aNIter != aNames.end(); aNIter++) { + double aValue; + ResultParameterPtr aRootParam; + if (ModelAPI_Tools::findVariable(aParameter, *aNIter, aValue, aRootParam, aRootDoc)) { + std::set > anAttributes = + aRootParam->data()->refsToMe(); + std::set >::const_iterator anAttributeIt = + anAttributes.cbegin(); + for (; anAttributeIt != anAttributes.cend(); ++anAttributeIt) { + const AttributePtr& anAttribute = *anAttributeIt; + ModelAPI_AttributeEvalMessage::send(anAttribute, NULL); + } + } + } + } } void ParametersPlugin_EvalListener::processObjectRenamedEvent( diff --git a/src/ParametersPlugin/Test/Test2474.py b/src/ParametersPlugin/Test/Test2474.py new file mode 100644 index 000000000..bd2b659b0 --- /dev/null +++ b/src/ParametersPlugin/Test/Test2474.py @@ -0,0 +1,48 @@ +## Copyright (C) 2014-2017 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 + +model.begin() +partSet = model.moduleDocument() +model.addParameter(partSet, "l", "200") +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() +Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY")) +SketchLine_1 = Sketch_1.addLine(138.3632494179343, 48.5641040948674, -61.63675058206567, 48.5641040948674) +SketchLine_2 = Sketch_1.addLine(-61.63675058206567, 48.5641040948674, -61.63675058206567, -46.51114810194107) +SketchLine_3 = Sketch_1.addLine(-61.63675058206567, -46.51114810194107, 138.3632494179343, -46.51114810194107) +SketchLine_4 = Sketch_1.addLine(138.3632494179343, -46.51114810194107, 138.3632494179343, 48.5641040948674) +SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_4.endPoint(), SketchLine_1.startPoint()) +SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint()) +SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint()) +SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint()) +SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_1.result()) +SketchConstraintVertical_1 = Sketch_1.setVertical(SketchLine_2.result()) +SketchConstraintHorizontal_2 = Sketch_1.setHorizontal(SketchLine_3.result()) +SketchConstraintVertical_2 = Sketch_1.setVertical(SketchLine_4.result()) +SketchConstraintLength_1 = Sketch_1.setLength(SketchLine_1.result(), "l") +model.do() +model.addParameter(Part_1_doc, "l", "300") +model.end() + +# Check that after substitution of module document "l" by part document "l" the value is updated +aValue = SketchConstraintLength_1.feature().real("ConstraintValue").value() +assert(aValue == 300) -- 2.39.2