From 69078c562b8a483d607f5d6e37fa697989c2a173 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me?= Date: Wed, 18 Nov 2020 19:23:26 +0100 Subject: [PATCH] Fix issue with interp Python --- .../InitializationPlugin_EvalListener.cpp | 86 +++++++++++-------- 1 file changed, 48 insertions(+), 38 deletions(-) diff --git a/src/InitializationPlugin/InitializationPlugin_EvalListener.cpp b/src/InitializationPlugin/InitializationPlugin_EvalListener.cpp index 67de035b1..4699cc1bd 100644 --- a/src/InitializationPlugin/InitializationPlugin_EvalListener.cpp +++ b/src/InitializationPlugin/InitializationPlugin_EvalListener.cpp @@ -127,48 +127,54 @@ void InitializationPlugin_EvalListener::processEvent( AttributeStringPtr anExprAttr; ModelAPI_AttributeTables::Value aVal; bool anIsFirstTime = true; + anExprAttr = aParam->string(BuildPlugin_Interpolation::XT_ID()); + std::wstring anExpX = anExprAttr->isUValue() ? + Locale::Convert::toWString(anExprAttr->valueU()) : + Locale::Convert::toWString(anExprAttr->value()); + anExpX.erase(std::remove(anExpX.begin(), anExpX.end(), ' '), anExpX.end()); + anExprAttr = aParam->string(BuildPlugin_Interpolation::YT_ID()); + std::wstring anExpY = anExprAttr->isUValue() ? + Locale::Convert::toWString(anExprAttr->valueU()) : + Locale::Convert::toWString(anExprAttr->value()); + anExpY.erase(std::remove(anExpY.begin(), anExpY.end(), ' '), anExpY.end()); + anExprAttr = aParam->string(BuildPlugin_Interpolation::ZT_ID()); + std::wstring anExpZ = anExprAttr->isUValue() ? + Locale::Convert::toWString(anExprAttr->valueU()) : + Locale::Convert::toWString(anExprAttr->value()); + anExpZ.erase(std::remove(anExpZ.begin(),anExpZ.end(), ' '), anExpZ.end()); + for(int step =0; step < anValueAttr->rows(); step++ ){ - anExprAttr = aParam->string(BuildPlugin_Interpolation::XT_ID()); - std::wstring anExp = anExprAttr->isUValue() ? - Locale::Convert::toWString(anExprAttr->valueU()) : - Locale::Convert::toWString(anExprAttr->value()); - aVal.myDouble = evaluate(anVar, - anValueAttr->value(step,0).myDouble, - aParam, - anExp, - anError, - aParamsList, - anIsFirstTime); - if(!anError.empty()) break; - anValueAttr->setValue(aVal,step,1); - anExprAttr = aParam->string(BuildPlugin_Interpolation::YT_ID()); - anExp = anExprAttr->isUValue() ? - Locale::Convert::toWString(anExprAttr->valueU()) : - Locale::Convert::toWString(anExprAttr->value()); - aVal.myDouble = evaluate(anVar, + aVal.myDouble = evaluate(anVar, anValueAttr->value(step,0).myDouble, aParam, - anExp, + anExpX, anError, aParamsList, anIsFirstTime); - if(!anError.empty()) break; - anValueAttr->setValue(aVal,step,2); - anExprAttr = aParam->string(BuildPlugin_Interpolation::ZT_ID()); - anExp = anExprAttr->isUValue() ? - Locale::Convert::toWString(anExprAttr->valueU()) : - Locale::Convert::toWString(anExprAttr->value()); - aVal.myDouble = evaluate(anVar, - anValueAttr->value(step,0).myDouble, - aParam, - anExp, - anError, - aParamsList, - anIsFirstTime); - if(!anError.empty()) break; - anValueAttr->setValue(aVal,step,3); - if ( anIsFirstTime ) - anIsFirstTime = false; + if(!anError.empty()) break; + anValueAttr->setValue(aVal,step,1); + + aVal.myDouble = evaluate(anVar, + anValueAttr->value(step,0).myDouble, + aParam, + anExpY, + anError, + aParamsList, + anIsFirstTime); + if(!anError.empty()) break; + anValueAttr->setValue(aVal,step,2); + + aVal.myDouble = evaluate(anVar, + anValueAttr->value(step,0).myDouble, + aParam, + anExpZ, + anError, + aParamsList, + anIsFirstTime); + if(!anError.empty()) break; + anValueAttr->setValue(aVal,step,3); + if ( anIsFirstTime ) + anIsFirstTime = false; } aMsg->setResults(aParamsList, anError); @@ -184,9 +190,14 @@ double InitializationPlugin_EvalListener::evaluate( std::list >& theParamsList, bool theIsFirstTime) { + std::list aContext; + aContext.push_back(theVariable + L"=" + toString(theValueVariable)); + myInterp->extendLocalContext(aContext); + aContext.clear(); + 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++) { double aValue; @@ -206,7 +217,6 @@ double InitializationPlugin_EvalListener::evaluate( aContext.push_back(*it + L"=" + toString(aValue)); } - aContext.push_back(theVariable + L"=" + toString(theValueVariable)); myInterp->extendLocalContext(aContext); double result = myInterp->evaluate(theExpression, theError); myInterp->clearLocalContext(); -- 2.39.2