From: sbh Date: Wed, 15 Apr 2015 11:51:58 +0000 (+0300) Subject: Issue 452: PartSet variable namespace is partent for the part's namespace. X-Git-Tag: V_1.1.0~28 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=9e462078514fa851d1a9194356566f41afb38988;p=modules%2Fshaper.git Issue 452: PartSet variable namespace is partent for the part's namespace. --- diff --git a/src/ModelAPI/ModelAPI_Tools.cpp b/src/ModelAPI/ModelAPI_Tools.cpp index 27a5fdde2..1d8e0bf10 100644 --- a/src/ModelAPI/ModelAPI_Tools.cpp +++ b/src/ModelAPI/ModelAPI_Tools.cpp @@ -5,29 +5,56 @@ // Author: Vitaly Smetannikov #include "ModelAPI_Tools.h" -#include -#include -#include +#include +#include +#include +#include +#include + +#include namespace ModelAPI_Tools { - std::shared_ptr shape(const ResultPtr& theResult) - { +std::shared_ptr shape(const ResultPtr& theResult) +{ /* - ResultBodyPtr aBody = std::dynamic_pointer_cast(theResult); - if (aBody) - return aBody->shape(); - - ResultConstructionPtr aConstruct = std::dynamic_pointer_cast( - theResult); - if (aConstruct) - return aConstruct->shape(); - - ResultGroupPtr aGroup = std::dynamic_pointer_cast(theResult); - if (aGroup) - return aGroup->shape(); - return std::shared_ptr(); - */ - return theResult->shape(); + ResultBodyPtr aBody = std::dynamic_pointer_cast(theResult); + if (aBody) + return aBody->shape(); + + ResultConstructionPtr aConstruct = std::dynamic_pointer_cast( + theResult); + if (aConstruct) + return aConstruct->shape(); + + ResultGroupPtr aGroup = std::dynamic_pointer_cast(theResult); + if (aGroup) + return aGroup->shape(); + return std::shared_ptr(); + */ + return theResult->shape(); +} + +bool findVariable(const std::string& theName, double& outValue) +{ + SessionPtr aSession = ModelAPI_Session::get(); + std::list aDocList; + DocumentPtr aDocument = aSession->activeDocument(); + DocumentPtr aRootDocument = aSession->moduleDocument(); + aDocList.push_back(aDocument); + if (aDocument != aRootDocument) { + aDocList.push_back(aRootDocument); + } + for(std::list::const_iterator it = aDocList.begin(); it != aDocList.end(); ++it) { + ObjectPtr aParamObj = (*it)->objectByName(ModelAPI_ResultParameter::group(), theName); + ResultParameterPtr aParam = std::dynamic_pointer_cast(aParamObj); + if(!aParam.get()) + continue; + AttributeDoublePtr aValueAttribute = aParam->data()->real(ModelAPI_ResultParameter::VALUE()); + outValue = aValueAttribute->value(); + return true; } + return false; } + +} // namespace ModelAPI_Tools diff --git a/src/ModelAPI/ModelAPI_Tools.h b/src/ModelAPI/ModelAPI_Tools.h index 3804c3c06..9d63757ea 100644 --- a/src/ModelAPI/ModelAPI_Tools.h +++ b/src/ModelAPI/ModelAPI_Tools.h @@ -14,7 +14,14 @@ namespace ModelAPI_Tools { /// Returns shape from the given Result object MODELAPI_EXPORT std::shared_ptr shape(const ResultPtr& theResult); + +/*! + * Searches for variable with name \param theName in the active document (Part), when + * in the root document (PartSet). If found, set it value in the \param outValue + * and returns true. + */ +MODELAPI_EXPORT bool findVariable(const std::string& theName, double& outValue); + } -; #endif diff --git a/src/ModuleBase/ModuleBase_DoubleSpinBox.h b/src/ModuleBase/ModuleBase_DoubleSpinBox.h index 347af2f49..555cafc36 100644 --- a/src/ModuleBase/ModuleBase_DoubleSpinBox.h +++ b/src/ModuleBase/ModuleBase_DoubleSpinBox.h @@ -1,7 +1,7 @@ // Copyright (C) 2014-20xx CEA/DEN, EDF R&D // File: ModuleBase_DoubleSpinBox.h -// Author: Sergey TELKOV +// Author: Sergey BELASH // #ifndef MODULEBASE_DOUBLESPINBOX_H_ #define MODULEBASE_DOUBLESPINBOX_H_ diff --git a/src/ModuleBase/ModuleBase_ParamSpinBox.cpp b/src/ModuleBase/ModuleBase_ParamSpinBox.cpp index af554aa84..57e21b80b 100644 --- a/src/ModuleBase/ModuleBase_ParamSpinBox.cpp +++ b/src/ModuleBase/ModuleBase_ParamSpinBox.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -234,16 +235,7 @@ bool ModuleBase_ParamSpinBox::findVariable(const QString& theName, double& outValue) const { - SessionPtr aSession = ModelAPI_Session::get(); - DocumentPtr aDocument = aSession->activeDocument(); - ObjectPtr aParamObj = aDocument->objectByName(ModelAPI_ResultParameter::group(), - theName.toStdString()); - ResultParameterPtr aParam = std::dynamic_pointer_cast(aParamObj); - if(!aParam.get()) - return false; - AttributeDoublePtr aValueAttribute = aParam->data()->real(ModelAPI_ResultParameter::VALUE()); - outValue = aValueAttribute->value(); - return true; + return ModelAPI_Tools::findVariable(theName.toStdString(), outValue); } /*! diff --git a/src/ParametersPlugin/ParametersPlugin_Parameter.cpp b/src/ParametersPlugin/ParametersPlugin_Parameter.cpp index 413e7dc9b..e3bc55ebb 100644 --- a/src/ParametersPlugin/ParametersPlugin_Parameter.cpp +++ b/src/ParametersPlugin/ParametersPlugin_Parameter.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -17,12 +18,10 @@ ParametersPlugin_Parameter::ParametersPlugin_Parameter() { myInterp = new ParametersPlugin_PyInterp(); - myInterp->initialize(); } ParametersPlugin_Parameter::~ParametersPlugin_Parameter() { - myInterp->destroy(); delete myInterp; } @@ -77,21 +76,22 @@ void ParametersPlugin_Parameter::execute() double ParametersPlugin_Parameter::evaluate(const std::string& theExpression, std::string& theError) { + myInterp->initialize(); std::list anExprParams = myInterp->compile(theExpression); // find expression's params in the model std::list aContext; std::list::iterator it = anExprParams.begin(); for ( ; it != anExprParams.end(); it++) { - std::string aParamName = *it; - ObjectPtr aParamObj = document()->objectByName(ModelAPI_ResultParameter::group(), aParamName); - ResultParameterPtr aParam = std::dynamic_pointer_cast(aParamObj); - if(!aParam.get()) continue; - AttributeDoublePtr aValueAttribute = aParam->data()->real(ModelAPI_ResultParameter::VALUE()); + double aValue; + if (!ModelAPI_Tools::findVariable(*it, aValue)) continue; + std::ostringstream sstream; - sstream << aValueAttribute->value(); + sstream << aValue; std::string aParamValue = sstream.str(); - aContext.push_back(aParamName + "=" + aParamValue); + aContext.push_back(*it + "=" + aParamValue); } myInterp->extendLocalContext(aContext); - return myInterp->evaluate(theExpression, theError); + double result = myInterp->evaluate(theExpression, theError); + myInterp->destroy(); + return result; }