X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FParametersPlugin%2FParametersPlugin_EvalListener.cpp;h=d63741c9fa606596f832c40bd95ddb6524d0b2ac;hb=471cc7b52168016a3b6fff7e64cdd800cd7d8f91;hp=126b0b0f0346ba509e2bfa9ff761066530d59eed;hpb=70f8434967195327040485995ca62b40d029e7ab;p=modules%2Fshaper.git diff --git a/src/ParametersPlugin/ParametersPlugin_EvalListener.cpp b/src/ParametersPlugin/ParametersPlugin_EvalListener.cpp index 126b0b0f0..d63741c9f 100644 --- a/src/ParametersPlugin/ParametersPlugin_EvalListener.cpp +++ b/src/ParametersPlugin/ParametersPlugin_EvalListener.cpp @@ -11,7 +11,7 @@ #include #include -#include +#include #include #include @@ -26,6 +26,8 @@ #include #include +#include + #include #include #include @@ -37,7 +39,11 @@ std::string toStdString(double theValue) { std::ostringstream sstream; sstream << theValue; - return sstream.str(); + size_t aPos = sstream.str().find("."); + std::string aPnt = ""; + if (aPos == std::string::npos) + aPnt = "."; + return sstream.str() + aPnt; } std::set toSet(const std::list& theContainer) @@ -85,13 +91,14 @@ void ParametersPlugin_EvalListener::processEvent( } else if (theMessage->eventID() == kReplaceParameterEvent) { processReplaceParameterEvent(theMessage); } else { - Events_Error::send(std::string("ParametersPlugin python interpreter, unhandled message caught: ") - + theMessage->eventID().eventText()); + Events_InfoMessage("ParametersPlugin_EvalListener", + "ParametersPlugin python interpreter, unhandled message caught: ") + .arg(theMessage->eventID().eventText()).send(); } } -double ParametersPlugin_EvalListener::evaluate(const std::string& theExpression, std::string& theError, - const std::shared_ptr& theDocument) +double ParametersPlugin_EvalListener::evaluate(FeaturePtr theParameter, + const std::string& theExpression, std::string& theError) { std::list anExprParams = myInterp->compile(theExpression); // find expression's params in the model @@ -101,7 +108,11 @@ double ParametersPlugin_EvalListener::evaluate(const std::string& theExpression, double aValue; ResultParameterPtr aParamRes; // If variable does not exist python interpreter will generate an error. It is OK. - if (!ModelAPI_Tools::findVariable(*it, aValue, aParamRes, theDocument)) continue; + // But due to the issue 1479 it should not check the history position of parameters relatively + // to feature that contains expression + if (!ModelAPI_Tools::findVariable(/*theParameter*/ FeaturePtr(), + *it, aValue, aParamRes, theParameter->document())) + continue; aContext.push_back(*it + "=" + toStdString(aValue)); } @@ -117,11 +128,13 @@ void ParametersPlugin_EvalListener::processEvaluationEvent( std::shared_ptr aMessage = std::dynamic_pointer_cast(theMessage); + FeaturePtr aParamFeature = + std::dynamic_pointer_cast(aMessage->attribute()->owner()); if (aMessage->attribute()->attributeType() == ModelAPI_AttributeInteger::typeId()) { AttributeIntegerPtr anAttribute = std::dynamic_pointer_cast(aMessage->attribute()); std::string anError; - int aValue = (int)evaluate(anAttribute->text(), anError, anAttribute->owner()->document()); + int aValue = (int)evaluate(aParamFeature, anAttribute->text(), anError); bool isValid = anError.empty(); if (isValid) anAttribute->setCalculatedValue(aValue); @@ -133,7 +146,7 @@ void ParametersPlugin_EvalListener::processEvaluationEvent( AttributeDoublePtr anAttribute = std::dynamic_pointer_cast(aMessage->attribute()); std::string anError; - double aValue = evaluate(anAttribute->text(), anError, anAttribute->owner()->document()); + double aValue = evaluate(aParamFeature, anAttribute->text(), anError); bool isValid = anError.empty(); if (isValid) anAttribute->setCalculatedValue(aValue); @@ -156,7 +169,7 @@ void ParametersPlugin_EvalListener::processEvaluationEvent( }; for (int i = 0; i < 3; ++i) { std::string anError; - double aValue = evaluate(aText[i], anError, anAttribute->owner()->document()); + double aValue = evaluate(aParamFeature, aText[i], anError); bool isValid = anError.empty(); if (isValid) aCalculatedValue[i] = aValue; anAttribute->setUsedParameters(i, isValid ? toSet(myInterp->compile(aText[i])) : std::set()); @@ -180,7 +193,7 @@ void ParametersPlugin_EvalListener::processEvaluationEvent( }; for (int i = 0; i < 2; ++i) { std::string anError; - double aValue = evaluate(aText[i], anError, anAttribute->owner()->document()); + double aValue = evaluate(aParamFeature, aText[i], anError); bool isValid = anError.empty(); if (isValid) aCalculatedValue[i] = aValue; anAttribute->setUsedParameters(i, isValid ? toSet(myInterp->compile(aText[i])) : std::set()); @@ -325,7 +338,8 @@ void ParametersPlugin_EvalListener::renameInDependents(std::shared_ptrvalidators()->validate(theAttribute, aValidator, anError); } @@ -333,7 +347,7 @@ void setParameterName(ResultParameterPtr theResultParameter, const std::string& { theResultParameter->data()->blockSendAttributeUpdated(true); theResultParameter->data()->setName(theName); - theResultParameter->data()->blockSendAttributeUpdated(false); + theResultParameter->data()->blockSendAttributeUpdated(false, false); std::shared_ptr aParameter = std::dynamic_pointer_cast( @@ -369,6 +383,18 @@ void ParametersPlugin_EvalListener::processObjectRenamedEvent( if (!aParameter.get()) return; + std::string aNotActivatedNames; + if (!ModelAPI_Tools::allDocumentsActivated(aNotActivatedNames)) { + QMessageBox::StandardButton aRes = QMessageBox::warning(0, QObject::tr("Warning"), + QObject::tr("Selected objects can be used in Part documents which are not loaded: \ +%1. Whould you like to continue?").arg(aNotActivatedNames.c_str()), + QMessageBox::No | QMessageBox::Yes, QMessageBox::No); + if (aRes != QMessageBox::Yes) { + setParameterName(aResultParameter, aMessage->oldName()); + return; + } + } + // try to update the parameter feature according the new name setParameterName(aResultParameter, aMessage->newName()); // TODO(spo): replace with ModelAPI_Session::get()->validators()->validate(aParameter, ParametersPlugin_Parameter::VARIABLE_ID())