--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: ModelAPI_ResultParameter.h
+// Created: 07 Jul 2014
+// Author: Vitaly SMETANNIKOV
+
+#include "ModelAPI_ResultParameter.h"
+#include <ModelAPI_AttributeDouble.h>
+
+void ModelAPI_ResultParameter::initAttributes()
+{
+ data()->addAttribute(ModelAPI_ResultParameter::VALUE(),
+ ModelAPI_AttributeDouble::typeId());
+}
#include <ModelAPI_ResultParameter.h>
#include <ModelAPI_AttributeDouble.h>
+#include <string>
+#include <sstream>
ParametersPlugin_Parameter::ParametersPlugin_Parameter()
{
std::string anExpression = string(ParametersPlugin_Parameter::EXPRESSION_ID())->value();
if(anExpression.empty())
return;
- ResultParameterPtr aParameterResult = document()->createParameter(data());
- //AttributeDoublePtr anAttr = aParameterResult->data()->real(ModelAPI_ResultParameter::VALUE());
+ ResultParameterPtr aParameterResult = document()->createParameter(data());
+ // Value
+ AttributeDoublePtr aValueAttribute = aParameterResult->data()->real(ModelAPI_ResultParameter::VALUE());
double aValue = evaluate(anExpression);
- //anAttr->setValue(aValue);
+ aValueAttribute->setValue(aValue);
setResult(aParameterResult);
-
+ // Name
+ std::string aName = string(ParametersPlugin_Parameter::VARIABLE_ID())->value();
+ std::ostringstream sstream;
+ sstream << aValue;
+ std::string aParamValue = sstream.str();
+ data()->setName(aName + " ("+ aParamValue + ")");
+ aParameterResult->data()->setName(aName);
}
double ParametersPlugin_Parameter::evaluate(std::string theExpression)
{
std::list<std::string> anExprParams = myInterp->compile(theExpression);
// find expression's params in the model
- // todo
- // myInterp->extendLocalContext();
+ std::list<std::string> aContext;
+ std::list<std::string>::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<ModelAPI_ResultParameter>(aParamObj);
+ if(!aParam.get()) continue;
+ AttributeDoublePtr aValueAttribute = aParam->data()->real(ModelAPI_ResultParameter::VALUE());
+ std::ostringstream sstream;
+ sstream << aValueAttribute->value();
+ std::string aParamValue = sstream.str();
+ aContext.push_back(aParamName + "=" + aParamValue);
+ }
+ myInterp->extendLocalContext(aContext);
std::string outError;
return myInterp->evaluate(theExpression, outError);
{
if (theParameters.empty())
return;
+ std::list<std::string>::const_iterator it = theParameters.begin();
+ for ( ; it != theParameters.cend(); it++) {
+ std::string aParamValue = *it;
+ simpleRun(aParamValue.c_str(), false);
+ }
}
PyObject* anEvalStrObj = PyObject_Str(anEvalResult);
std::string anEvalStr(PyString_AsString(anEvalStrObj));
- double result = std::stod(anEvalStr);
-
- return result;
+ Py_XDECREF(anExprCode);
+ Py_XDECREF(anEvalResult);
+ Py_XDECREF(anEvalStrObj);
+ return std::stod(anEvalStr);
}
std::string ParametersPlugin_PyInterp::errorMessage()