From: mpv Date: Wed, 10 Jan 2018 11:04:49 +0000 (+0300) Subject: Fix for the issue #2392 - to search variables start from the document of the feature... X-Git-Tag: V_3.0.0RC1~52 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=e7307ebbcdc9003d37882976eec941861487e17d;p=modules%2Fshaper.git Fix for the issue #2392 - to search variables start from the document of the feature (which uses parameters), not the active document. --- diff --git a/src/Model/Model_Data.cpp b/src/Model/Model_Data.cpp index 89c138892..a3f193f56 100644 --- a/src/Model/Model_Data.cpp +++ b/src/Model/Model_Data.cpp @@ -578,7 +578,8 @@ std::set usedParameters(const AttributePoint2DPtr& theAttribute) return anUsedParameters; } -std::list findVariables(const std::set& theParameters) +std::list findVariables(const std::set& theParameters, + const DocumentPtr& theDocument) { std::list aResult; std::set::const_iterator aParamIt = theParameters.cbegin(); @@ -588,7 +589,7 @@ std::list findVariables(const std::set& thePara ResultParameterPtr aParam; // theSearcher is not needed here: in expressions // of features the parameters history is not needed - if (ModelAPI_Tools::findVariable(FeaturePtr(), aName, aValue, aParam)) + if (ModelAPI_Tools::findVariable(FeaturePtr(), aName, aValue, aParam, theDocument)) aResult.push_back(aParam); } return aResult; @@ -649,25 +650,29 @@ void Model_Data::referencesToObjects( AttributeIntegerPtr anAttribute = std::dynamic_pointer_cast(anAttr); std::set anUsedParameters = anAttribute->usedParameters(); - std::list aParameters = findVariables(anUsedParameters); + std::list aParameters = + findVariables(anUsedParameters, owner()->document()); aReferenced.insert(aReferenced.end(), aParameters.begin(), aParameters.end()); } else if (aType == ModelAPI_AttributeDouble::typeId()) { // double attribute AttributeDoublePtr anAttribute = std::dynamic_pointer_cast(anAttr); std::set anUsedParameters = anAttribute->usedParameters(); - std::list aParameters = findVariables(anUsedParameters); + std::list aParameters = + findVariables(anUsedParameters, owner()->document()); aReferenced.insert(aReferenced.end(), aParameters.begin(), aParameters.end()); } else if (aType == GeomDataAPI_Point::typeId()) { // point attribute AttributePointPtr anAttribute = std::dynamic_pointer_cast(anAttr); std::set anUsedParameters = usedParameters(anAttribute); - std::list aParameters = findVariables(anUsedParameters); + std::list aParameters = + findVariables(anUsedParameters, owner()->document()); aReferenced.insert(aReferenced.end(), aParameters.begin(), aParameters.end()); } else if (aType == GeomDataAPI_Point2D::typeId()) { // point attribute AttributePoint2DPtr anAttribute = std::dynamic_pointer_cast(anAttr); std::set anUsedParameters = usedParameters(anAttribute); - std::list aParameters = findVariables(anUsedParameters); + std::list aParameters = + findVariables(anUsedParameters, owner()->document()); aReferenced.insert(aReferenced.end(), aParameters.begin(), aParameters.end()); } else continue; // nothing to do, not reference diff --git a/src/ModelAPI/Test/TestDocument.py b/src/ModelAPI/Test/TestDocument.py index 997de3b52..f197d2606 100644 --- a/src/ModelAPI/Test/TestDocument.py +++ b/src/ModelAPI/Test/TestDocument.py @@ -27,8 +27,6 @@ # Initialization of the test #========================================================================= from ModelAPI import * -# from GeomDataAPI import * -# from GeomAlgoAPI import * __updated__ = "2014-12-26" @@ -36,7 +34,6 @@ __updated__ = "2014-12-26" # Creation and activation of documents #========================================================================= aSession = ModelAPI_Session.get() -# TODO: enable this assertion: assert(aSession.moduleDocument()) assert(aSession.moduleDocument().id() == 0) assert(aSession.moduleDocument().kind() == "PartSet") diff --git a/src/ParametersPlugin/CMakeLists.txt b/src/ParametersPlugin/CMakeLists.txt index c0baa2be8..a5aae8923 100644 --- a/src/ParametersPlugin/CMakeLists.txt +++ b/src/ParametersPlugin/CMakeLists.txt @@ -117,4 +117,5 @@ ADD_UNIT_TESTS(TestParameterCreation.py TestParameterRename.py TestParameterChangeValue.py Test1806.py + Test2392.py ) diff --git a/src/ParametersPlugin/Test/Test2392.py b/src/ParametersPlugin/Test/Test2392.py new file mode 100644 index 000000000..280b62e99 --- /dev/null +++ b/src/ParametersPlugin/Test/Test2392.py @@ -0,0 +1,56 @@ +## 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() +param_d1 = model.addParameter(partSet, "d1", "5", "Chain roller diameter") +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() +model.addParameter(Part_1_doc, "z", "25", "Number of teeth of the asterisk") +model.addParameter(Part_1_doc, "Lambda", "1.8", "Engagement chracteristic") +model.addParameter(Part_1_doc, "K", "0.565", "Tooth height coefficient") +model.addParameter(Part_1_doc, "De", "d1*Lambda*(K+1./tan(pi/z))", "External diameter") +Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY")) +SketchProjection_1 = Sketch_1.addProjection(model.selection("VERTEX", "PartSet/Origin"), False) +SketchPoint_1 = SketchProjection_1.createdFeature() +SketchCircle_1 = Sketch_1.addCircle(0, 0, 38.16365) +SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchPoint_1.result(), SketchCircle_1.center()) +SketchConstraintRadius_1 = Sketch_1.setRadius(SketchCircle_1.results()[1], "De/2") +model.end() + +# due to the scenario, change the active document +model.begin() +from ModelAPI import * +aSession = ModelAPI_Session.get() +aSession.setActiveDocument(partSet, False) +model.do() +# change the parameter value +param_d1.setValue(8.51) +model.do() +# make the part document active back +aSession.setActiveDocument(Part_1_doc, False) +model.end() + +# check the circle radius value +assert(SketchCircle_1.radius().value() == 64.9545) + +assert(model.checkPythonDump())