+ updateName();
+ if (!updateExpression())
+ setError("Expression error.", false);
+}
+
+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();
+ std::list<ResultParameterPtr> 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(aVariableName, aValue, aParamRes, aDocument)) continue;
+ aParamsList.push_back(aParamRes);
+
+ std::ostringstream sstream;
+ sstream << aValue;
+ std::string aParamValue = sstream.str();
+ aContext.push_back(*it + "=" + aParamValue);
+ }
+ // compare the list of parameters to store if changed
+ AttributeRefListPtr aParams = reflist(ARGUMENTS_ID());
+ bool aDifferent = aParams->size() != aParamsList.size();
+ if (!aDifferent) {
+ std::list<ResultParameterPtr>::iterator aNewIter = aParamsList.begin();
+ std::list<ObjectPtr> anOldList = aParams->list();
+ std::list<ObjectPtr>::iterator anOldIter = anOldList.begin();
+ for(; !aDifferent && aNewIter != aParamsList.end(); aNewIter++, anOldIter++) {
+ if (*aNewIter != *anOldIter)
+ aDifferent = true;
+ }
+ }
+ if (aDifferent) {
+ aParams->clear();
+ std::list<ResultParameterPtr>::iterator aNewIter = aParamsList.begin();
+ for(; aNewIter != aParamsList.end(); aNewIter++) {
+ aParams->append(*aNewIter);
+ }
+ }
+
+ myInterp->extendLocalContext(aContext);
+ double result = myInterp->evaluate(theExpression, theError);
+ myInterp->clearLocalContext();
+ return result;
+}
+
+bool ParametersPlugin_Parameter::isPreviewNeeded() const
+{
+ return false;