// }
// }
//}
-
+
// check all attributes for validity
// Validity of data is checked by "Model_FeatureValidator" (kDefaultId)
// if (!aData || !aData->isValid())
// Try to get the value
QString aStateMsg;
- std::string anErrorMessage = myFeature->error();
+ std::string anErrorMessage = myFeature->string("ExpressionError")->value();
if (anErrorMessage.empty()) {
ResultParameterPtr aParam =
std::dynamic_pointer_cast<ModelAPI_ResultParameter>(myFeature->firstResult());
}
}
} else {
- aStateMsg = QString::fromStdString(anErrorMessage);
+ aStateMsg = "Error: " + QString::fromStdString(anErrorMessage);
}
myResultLabel->setText(aStateMsg);
return true;
for ( ; it != anExprParams.end(); it++) {
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;
std::ostringstream sstream;
{
data()->addAttribute(VARIABLE_ID(), ModelAPI_AttributeString::typeId());
data()->addAttribute(EXPRESSION_ID(), ModelAPI_AttributeString::typeId());
+
+ data()->addAttribute(EXPRESSION_ERROR_ID(), ModelAPI_AttributeString::typeId());
+ data()->string(EXPRESSION_ERROR_ID())->setIsArgument(false);
+ ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), EXPRESSION_ERROR_ID());
+
data()->addAttribute(ARGUMENTS_ID(), ModelAPI_AttributeRefList::typeId());
data()->reflist(ARGUMENTS_ID())->setIsArgument(false);
ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), ARGUMENTS_ID());
void ParametersPlugin_Parameter::updateExpression()
{
std::string anExpression = string(EXPRESSION_ID())->value();
- if(anExpression.empty()) {
- // clear error/result if the expression is empty
- setError("", false);
- return;
- }
+
std::string outErrorMessage;
double aValue = evaluate(anExpression, outErrorMessage);
- std::ostringstream sstream;
- sstream << aValue;
- std::string aParamValue = sstream.str();
- // Error
+
+ data()->string(EXPRESSION_ERROR_ID())->setValue(outErrorMessage);
if (!outErrorMessage.empty()) {
- std::string aStateMsg("Error: " + outErrorMessage);
+ setError("Expression error.", false);
data()->execState(ModelAPI_StateExecFailed);
- setError(aStateMsg, false);
- } else {
- static const std::string anEmptyMsg(""); // it is checked in the validator by the empty message
- setError(anEmptyMsg, false);
- data()->execState(ModelAPI_StateDone);
+ return;
}
+ setError("", false);
+ data()->execState(ModelAPI_StateDone);
+
ResultParameterPtr aParam = document()->createParameter(data());
AttributeDoublePtr aValueAttribute = aParam->data()->real(ModelAPI_ResultParameter::VALUE());
aValueAttribute->setValue(aValue);
std::list<std::string>::iterator it = anExprParams.begin();
std::list<ResultParameterPtr> aParamsList;
for ( ; it != anExprParams.end(); it++) {
+ std::string& aVariableName = *it;
+
double aValue;
ResultParameterPtr aParamRes;
- if (!ModelAPI_Tools::findVariable(*it, aValue, aParamRes, document())) continue;
+ if (!ModelAPI_Tools::findVariable(aVariableName, aValue, aParamRes, document())) continue;
aParamsList.push_back(aParamRes);
std::ostringstream sstream;
return MY_EXPRESSION_ID;
}
+ /// attribute name of extrusion size
+ inline static const std::string& EXPRESSION_ERROR_ID()
+ {
+ static const std::string MY_EXPRESSION_ERROR_ID("ExpressionError");
+ return MY_EXPRESSION_ERROR_ID;
+ }
+
/// list of references to the arguments of this expression
inline static const std::string& ARGUMENTS_ID()
{
- static const std::string MY_VARIABLE_ID("arguments");
- return MY_VARIABLE_ID;
+ static const std::string MY_ARGUMENTS_ID("arguments");
+ return MY_ARGUMENTS_ID;
}
/// Returns the kind of a feature
#include <ParametersPlugin_Validators.h>
+#include <ParametersPlugin_Parameter.h>
+
#include <ModelAPI_AttributeString.h>
#include <ModelAPI_Feature.h>
#include <ModelAPI_ResultParameter.h>
AttributeStringPtr aStrAttr =
std::dynamic_pointer_cast<ModelAPI_AttributeString>(theAttribute);
bool isEmptyExpr = aStrAttr->value().empty();
- if(isEmptyExpr) {
+ if (isEmptyExpr) {
theError = "Expression is empty.";
return false;
}
- if(!aParam.get()) {
+ if (!aParam.get()) {
theError = "Result is empty.";
return false;
}
- theError = aFeature->error();
- return aFeature->error().empty();
+ theError = aFeature->string(ParametersPlugin_Parameter::EXPRESSION_ERROR_ID())->value();
+ return theError.empty();
}
--- /dev/null
+def main():
+ source(findFile("scripts", "common.py"))
+
+ startApplication("salome_run.sh")
+
+ activate_newgeom()
+
+ #[step] Click menu Part->Parameter
+ activateItem(waitForObjectItem(":SALOME*_QMenuBar", "Part"))
+ activateItem(waitForObjectItem(":Part_QMenu", "Parameter"))
+ mouseClick(waitForObject(":Parameter_QLineEdit"), 79, 8, 0, Qt.LeftButton)
+ #[step] Check that feature ToolTip is: Model_FeatureValidator: Attribute "expression" is not initialized.
+ waitFor("object.exists(':Parameter_QFrame')", 20000)
+ test.compare(str(findObject(":Parameter_QFrame").toolTip), "Model_FeatureValidator: Attribute \"expression\" is not initialized.")
+ #[step] Check that name tooltip is: Errors:\nvariable - Parameters_VariableValidator: Incorrect variable name.
+ waitFor("object.exists(':Parameter_QLineEdit')", 20000)
+ test.compare(str(findObject(":Parameter_QLineEdit").toolTip), "Errors:\nvariable - Parameters_VariableValidator: Incorrect variable name.")
+ #[step] Check that expression tooltip is: Errors:\nexpression - Parameters_ExpressionValidator: Expression is empty.
+ waitFor("object.exists(':Parameter_ExpressionEditor')", 20000)
+ test.compare(str(findObject(":Parameter_ExpressionEditor").toolTip), "Errors:\nexpression - Parameters_ExpressionValidator: Expression is empty.")
+
+ #[step] Enter variable name 'a'
+ type(waitForObject(":Parameter_QLineEdit"), "a")
+ mouseClick(waitForObject(":Parameter_ExpressionEditor"), 97, 31, 0, Qt.LeftButton)
+
+ #[step] Enter variable expression '100+b'
+ type(waitForObject(":Parameter_ExpressionEditor"), "100+b")
+
+ #[step] Check that expression tooltip is: Errors:\nexpression - Parameters_ExpressionValidator: name 'b' is not defined
+ waitFor("object.exists(':Parameter_ExpressionEditor')", 20000)
+ test.compare(str(findObject(":Parameter_ExpressionEditor").toolTip), "Errors:\nexpression - Parameters_ExpressionValidator: name 'b' is not defined")
+ #[step] Check that result message is: Error: unexpected EOF while parsing (<string>, line 0)
+ waitFor("object.exists(':Parameter.Result_QLabel')", 20000)
+ test.compare(str(findObject(":Parameter.Result_QLabel").text), "Error: name 'b' is not defined")
+
+ #[step] Check that feature ToolTip is: expression - Parameters_ExpressionValidator: name 'b' is not defined
+ waitFor("object.exists(':Parameter_QFrame')", 20000)
+ test.compare(str(findObject(":Parameter_QFrame").toolTip), "expression - Parameters_ExpressionValidator: name 'b' is not defined")
+
+ #[step] Check that apply button is disabled
+ waitFor("object.exists(':Parameter.property_panel_ok_QToolButton')", 20000)
+ test.compare(findObject(":Parameter.property_panel_ok_QToolButton").enabled, False)
+
+ close_application()