X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FParametersPlugin%2FParametersPlugin_EvalListener.cpp;h=029800afa4e2dcf7315b865d1cf863d20045f0b2;hb=853e0eec6016120b641efa6adf427a239cf203cf;hp=13dfc182a7d00a108b82df06cf04446b034dbb84;hpb=35b830d561822bfa66c686af78d75ce431fdf707;p=modules%2Fshaper.git diff --git a/src/ParametersPlugin/ParametersPlugin_EvalListener.cpp b/src/ParametersPlugin/ParametersPlugin_EvalListener.cpp index 13dfc182a..029800afa 100644 --- a/src/ParametersPlugin/ParametersPlugin_EvalListener.cpp +++ b/src/ParametersPlugin/ParametersPlugin_EvalListener.cpp @@ -13,18 +13,20 @@ #include +#include #include +#include #include #include #include #include -#include #include #include #include #include +#include #include ParametersPlugin_EvalListener::ParametersPlugin_EvalListener() @@ -61,8 +63,8 @@ void ParametersPlugin_EvalListener::processEvent( } } -double ParametersPlugin_EvalListener::evaluate(const std::string& theExpression, - std::string& theError) +double ParametersPlugin_EvalListener::evaluate(const std::string& theExpression, std::string& theError, + const std::shared_ptr& theDocument) { std::list anExprParams = myInterp->compile(theExpression); // find expression's params in the model @@ -71,7 +73,8 @@ double ParametersPlugin_EvalListener::evaluate(const std::string& theExpression, for ( ; it != anExprParams.end(); it++) { double aValue; ResultParameterPtr aParamRes; - if (!ModelAPI_Tools::findVariable(*it, aValue, aParamRes)) continue; + // If variable does not exist python interpreter will generate an error. It is OK. + if (!ModelAPI_Tools::findVariable(*it, aValue, aParamRes, theDocument)) continue; std::ostringstream sstream; sstream << aValue; @@ -84,6 +87,11 @@ double ParametersPlugin_EvalListener::evaluate(const std::string& theExpression, return result; } +std::set toSet(const std::list& theContainer) +{ + return std::set(theContainer.begin(), theContainer.end()); +} + void ParametersPlugin_EvalListener::processEvaluationEvent( const std::shared_ptr& theMessage) { @@ -94,10 +102,11 @@ void ParametersPlugin_EvalListener::processEvaluationEvent( AttributeDoublePtr anAttribute = std::dynamic_pointer_cast(aMessage->attribute()); std::string anError; - double aValue = evaluate(anAttribute->text(), anError); + double aValue = evaluate(anAttribute->text(), anError, anAttribute->owner()->document()); bool isValid = anError.empty(); if (isValid) anAttribute->setCalculatedValue(aValue); + anAttribute->setUsedParameters(isValid ? toSet(myInterp->compile(anAttribute->text())) : std::set()); anAttribute->setExpressionInvalid(!isValid); anAttribute->setExpressionError(anAttribute->text().empty() ? "" : anError); } else @@ -116,9 +125,10 @@ void ParametersPlugin_EvalListener::processEvaluationEvent( }; for (int i = 0; i < 3; ++i) { std::string anError; - double aValue = evaluate(aText[i], anError); + double aValue = evaluate(aText[i], anError, anAttribute->owner()->document()); bool isValid = anError.empty(); if (isValid) aCalculatedValue[i] = aValue; + anAttribute->setUsedParameters(i, isValid ? toSet(myInterp->compile(aText[i])) : std::set()); anAttribute->setExpressionInvalid(i, !isValid); anAttribute->setExpressionError(i, aText[i].empty() ? "" : anError); } @@ -139,9 +149,10 @@ void ParametersPlugin_EvalListener::processEvaluationEvent( }; for (int i = 0; i < 2; ++i) { std::string anError; - double aValue = evaluate(aText[i], anError); + double aValue = evaluate(aText[i], anError, anAttribute->owner()->document()); bool isValid = anError.empty(); if (isValid) aCalculatedValue[i] = aValue; + anAttribute->setUsedParameters(i, isValid ? toSet(myInterp->compile(aText[i])) : std::set()); anAttribute->setExpressionInvalid(i, !isValid); anAttribute->setExpressionError(i, aText[i].empty() ? "" : anError); } @@ -278,7 +289,9 @@ void ParametersPlugin_EvalListener::processObjectRenamedEvent( std::shared_ptr aMessage = std::dynamic_pointer_cast(theMessage); - if (!aMessage.get() || aMessage->oldName().empty() || aMessage->newName().empty()) + // Empty new name is not available too but it will be rejected by + // name validator in isValidAttribute. + if (!aMessage.get() || aMessage->oldName().empty()) return; // check if the renamed object is a result parameter @@ -304,44 +317,24 @@ void ParametersPlugin_EvalListener::processObjectRenamedEvent( return; } - // List of documents to process - std::list aDocList; - SessionPtr aSession = ModelAPI_Session::get(); - DocumentPtr aDocument = aSession->activeDocument(); - DocumentPtr aRootDocument = aSession->moduleDocument(); - aDocList.push_back(aDocument); - if (aDocument != aRootDocument) { - aDocList.push_back(aRootDocument); - } - - // Find all features - for (std::list::const_iterator aDicumentIt = aDocList.begin(); - aDicumentIt != aDocList.end(); ++aDicumentIt) { - const DocumentPtr& aDocument = *aDicumentIt; - std::list aFeatures = aDocument->allFeatures(); - std::list::iterator aFeatureIt = aFeatures.begin(); - for (; aFeatureIt != aFeatures.end(); ++aFeatureIt) { - const FeaturePtr& aFeature = *aFeatureIt; - - // If Parameter feature then rename its expression + std::set > anAttributes = + aResultParameter->data()->refsToMe(); + std::set >::const_iterator anAttributeIt = + anAttributes.cbegin(); + for (; anAttributeIt != anAttributes.cend(); ++anAttributeIt) { + const AttributePtr& anAttribute = *anAttributeIt; + AttributeRefListPtr anAttributeRefList = + std::dynamic_pointer_cast(anAttribute); + if (anAttributeRefList.get()) { std::shared_ptr aParameter = - std::dynamic_pointer_cast(aFeature); - if (aParameter.get()) { + std::dynamic_pointer_cast( + anAttributeRefList->owner()); + if (aParameter.get()) // Rename renameInParameter(aParameter, aMessage->oldName(), aMessage->newName()); - continue; - } - - // Find all attributes - std::list anAttributes = aFeature->data()->attributes(std::string()); - std::list::const_iterator anAttributeIt = anAttributes.begin(); - for (; anAttributeIt != anAttributes.end(); ++anAttributeIt) { - const AttributePtr& anAttribute = *anAttributeIt; - + } else // Rename renameInAttribute(anAttribute, aMessage->oldName(), aMessage->newName()); - } - } } }