Salome HOME
Merge branch 'Dev_1.1.0' of newgeom:newgeom.git into Dev_1.1.0
[modules/shaper.git] / src / ParametersPlugin / ParametersPlugin_Parameter.cpp
index 413e7dc9bcacf220e88d7737843b866cdf1cde7f..48f5d731236e99c4d008b66a7bccb0206c73d53f 100644 (file)
@@ -10,6 +10,7 @@
 #include <ModelAPI_AttributeString.h>
 #include <ModelAPI_ResultParameter.h>
 #include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_Tools.h>
 
 #include <string>
 #include <sstream>
@@ -22,7 +23,6 @@ ParametersPlugin_Parameter::ParametersPlugin_Parameter()
 
 ParametersPlugin_Parameter::~ParametersPlugin_Parameter()
 {
-  myInterp->destroy();
   delete myInterp;
 }
 
@@ -56,7 +56,7 @@ void ParametersPlugin_Parameter::attributeChanged(const std::string&)
   std::ostringstream sstream;
   sstream << aValue;
   std::string aParamValue = sstream.str();
-  data()->setName(aName + " ("+ aParamValue + ")");
+  data()->setName(aName);
   aParam->data()->setName(aName);
   // Error
   std::string aStateMsg;
@@ -77,21 +77,22 @@ void ParametersPlugin_Parameter::execute()
 
 double ParametersPlugin_Parameter::evaluate(const std::string& theExpression, std::string& theError)
 {
+
   std::list<std::string> anExprParams = myInterp->compile(theExpression);
   // find expression's params in the model
   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());
+    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->clearLocalContext();
+  return result;
 }