2 * Parameters_VariableValidator.cpp
4 * Created on: Apr 9, 2015
8 #include <ParametersPlugin_Validators.h>
10 #include <ModelAPI_AttributeString.h>
11 #include <ModelAPI_Feature.h>
12 #include <ModelAPI_ResultParameter.h>
14 ParametersPlugin_VariableValidator::ParametersPlugin_VariableValidator()
16 myPyVariableRegex = std::regex("[_a-zA-Z][a-zA-Z0-9_]*");
19 ParametersPlugin_VariableValidator::~ParametersPlugin_VariableValidator()
23 bool ParametersPlugin_VariableValidator::isValid(const AttributePtr& theAttribute,
24 const std::list<std::string>& theArguments) const
26 AttributeStringPtr aStrAttr = std::dynamic_pointer_cast<ModelAPI_AttributeString>(theAttribute);
27 bool result = std::regex_match(aStrAttr->value(), myPyVariableRegex);
31 ParametersPlugin_ExpressionValidator::ParametersPlugin_ExpressionValidator()
36 ParametersPlugin_ExpressionValidator::~ParametersPlugin_ExpressionValidator()
41 bool ParametersPlugin_ExpressionValidator::isValid(const AttributePtr& theAttribute,
42 const std::list<std::string>& theArguments) const
44 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
45 ResultParameterPtr aParam =
46 std::dynamic_pointer_cast<ModelAPI_ResultParameter>(aFeature->firstResult());
48 AttributeStringPtr aStrAttr =
49 std::dynamic_pointer_cast<ModelAPI_AttributeString>(theAttribute);
50 bool isEmptyExpr = aStrAttr->value().empty();
57 return aFeature->error().empty();