X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FParametersPlugin%2FParametersPlugin_Parameter.cpp;h=d5aab74d2ccf4efbef286519c1e2988bb0c29532;hb=fc72d43b677baa05ae7fd317346fd8b723b799ed;hp=4428be15b7f949ef5dcd3d17adfadf7fc2173b89;hpb=88e6607f0b144ea77928192796a18f64fc75ee09;p=modules%2Fshaper.git diff --git a/src/ParametersPlugin/ParametersPlugin_Parameter.cpp b/src/ParametersPlugin/ParametersPlugin_Parameter.cpp index 4428be15b..d5aab74d2 100644 --- a/src/ParametersPlugin/ParametersPlugin_Parameter.cpp +++ b/src/ParametersPlugin/ParametersPlugin_Parameter.cpp @@ -1,13 +1,27 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> - -// File: ParametersPlugin_Parameter.cpp -// Created: 23 MArch 2015 -// Author: sbh +// Copyright (C) 2014-2023 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 +// #include #include "ParametersPlugin_Parameter.h" -#include + +#include #include #include @@ -16,14 +30,13 @@ #include #include #include +#include #include #include ParametersPlugin_Parameter::ParametersPlugin_Parameter() { - myInterp = std::shared_ptr(new ParametersPlugin_PyInterp()); - myInterp->initialize(); } ParametersPlugin_Parameter::~ParametersPlugin_Parameter() @@ -62,17 +75,51 @@ void ParametersPlugin_Parameter::attributeChanged(const std::string& theID) void ParametersPlugin_Parameter::updateName() { - std::string aName = string(VARIABLE_ID())->value(); + std::wstring aName = string(VARIABLE_ID())->isUValue() ? + Locale::Convert::toWString(string(VARIABLE_ID())->valueU()) : + Locale::Convert::toWString(string(VARIABLE_ID())->value()); data()->setName(aName); ResultParameterPtr aParam = document()->createParameter(data()); + std::wstring anOldName = aParam->data()->name(); aParam->data()->setName(aName); setResult(aParam); + + + // #2474 : if parameter name now hides/shows the higher level parameter name, + // update the depended expressions + DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); + if (aParam->document() != aRootDoc) { + std::list aNames; // collect names in the root document that must be checked + aNames.push_back(aName); + if (anOldName != aName) { + aNames.push_back(anOldName); + } + std::list::iterator aNIter = aNames.begin(); + for (; aNIter != aNames.end(); aNIter++) { + double aValue; + ResultParameterPtr aRootParam; + FeaturePtr aThis = + std::dynamic_pointer_cast(string(VARIABLE_ID())->owner()); + if (ModelAPI_Tools::findVariable(aThis, *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); + } + } + } + } } bool ParametersPlugin_Parameter::updateExpression() { - std::string anExpression = string(EXPRESSION_ID())->value(); + std::wstring anExpression = string(EXPRESSION_ID())->isUValue() ? + Locale::Convert::toWString(string(EXPRESSION_ID())->valueU()) : + Locale::Convert::toWString(string(EXPRESSION_ID())->value()); std::string outErrorMessage; double aValue = evaluate(anExpression, outErrorMessage); @@ -85,6 +132,7 @@ bool ParametersPlugin_Parameter::updateExpression() AttributeDoublePtr aValueAttribute = aParam->data()->real(ModelAPI_ResultParameter::VALUE()); aValueAttribute->setValue(aValue); setResult(aParam); + return true; } @@ -95,65 +143,41 @@ void ParametersPlugin_Parameter::execute() setError("Expression error.", false); } -double ParametersPlugin_Parameter::evaluate(const std::string& theExpression, std::string& theError) +double ParametersPlugin_Parameter::evaluate(const std::wstring& /*theExpression*/, + std::string& theError) { - std::list anExprParams = myInterp->compile(theExpression); - // find expression's params in the model - std::list aContext; - std::list::iterator it = anExprParams.begin(); - std::list aParamsList; - for ( ; it != anExprParams.end(); it++) { - std::string& aVariableName = *it; - - // Parameter with the same name should be searched in the parent document. - // For the PartSet assume that the parameter is absent. - // Currently there is no way to get parent document, so we get PartSet for all. - DocumentPtr aDocument = document(); - if (data()->name() == aVariableName) { - if (aDocument == ModelAPI_Session::get()->moduleDocument()) - continue; - aDocument = ModelAPI_Session::get()->moduleDocument(); - } - - double aValue; - ResultParameterPtr aParamRes; - if (!ModelAPI_Tools::findVariable(std::dynamic_pointer_cast(data()->owner()), - aVariableName, aValue, aParamRes, aDocument)) continue; - aParamsList.push_back(aParamRes); - - std::ostringstream sstream; - sstream << aValue; - std::string aParamValue = sstream.str(); - size_t aPos = aParamValue.find("."); - std::string aPnt = ""; - if (aPos == std::string::npos) - aPnt = "."; - aContext.push_back(*it + "=" + aParamValue + aPnt); - } - // compare the list of parameters to store if changed - AttributeRefListPtr aParams = reflist(ARGUMENTS_ID()); - bool aDifferent = aParams->size() != aParamsList.size(); - if (!aDifferent) { - std::list::iterator aNewIter = aParamsList.begin(); - std::list anOldList = aParams->list(); - std::list::iterator anOldIter = anOldList.begin(); - for(; !aDifferent && aNewIter != aParamsList.end(); aNewIter++, anOldIter++) { - if (*aNewIter != *anOldIter) - aDifferent = true; + FeaturePtr aMyPtr = std::dynamic_pointer_cast(data()->owner()); + std::shared_ptr aProcessMessage = + ModelAPI_ParameterEvalMessage::send(aMyPtr, this); + + double aResult = 0; + if (aProcessMessage->isProcessed()) { + const std::list& aParamsList = aProcessMessage->params(); + aResult = aProcessMessage->result(); + theError = aProcessMessage->error(); + // compare the list of parameters to store if changed + AttributeRefListPtr aParams = reflist(ARGUMENTS_ID()); + bool aDifferent = aParams->size() != (int)aParamsList.size(); + if (!aDifferent) { + std::list::const_iterator aNewIter = aParamsList.begin(); + std::list anOldList = aParams->list(); + std::list::const_iterator anOldIter = anOldList.begin(); + for(; !aDifferent && aNewIter != aParamsList.end(); aNewIter++, anOldIter++) { + if (*aNewIter != *anOldIter) + aDifferent = true; + } } - } - if (aDifferent) { - aParams->clear(); - std::list::iterator aNewIter = aParamsList.begin(); - for(; aNewIter != aParamsList.end(); aNewIter++) { - aParams->append(*aNewIter); + if (aDifferent) { + aParams->clear(); + std::list::const_iterator aNewIter = aParamsList.begin(); + for(; aNewIter != aParamsList.end(); aNewIter++) { + aParams->append(*aNewIter); + } } + } else { // error: python interpreter is not active + theError = "Python interpreter is not available"; } - - myInterp->extendLocalContext(aContext); - double result = myInterp->evaluate(theExpression, theError); - myInterp->clearLocalContext(); - return result; + return aResult; } bool ParametersPlugin_Parameter::isPreviewNeeded() const