]> SALOME platform Git repositories - modules/shaper.git/blob - src/ParametersPlugin/ParametersPlugin_Validators.cpp
Salome HOME
Validators for Parameters values and expressions
[modules/shaper.git] / src / ParametersPlugin / ParametersPlugin_Validators.cpp
1 /*
2  * Parameters_VariableValidator.cpp
3  *
4  *  Created on: Apr 9, 2015
5  *      Author: sbh
6  */
7
8 #include <ParametersPlugin_Validators.h>
9
10 #include <ModelAPI_AttributeString.h>
11 #include <ModelAPI_Feature.h>
12 #include <ModelAPI_ResultParameter.h>
13
14 ParametersPlugin_VariableValidator::ParametersPlugin_VariableValidator()
15 {
16   myPyVariableRegex = std::regex("[_a-zA-Z][a-zA-Z0-9_]*");
17 }
18
19 ParametersPlugin_VariableValidator::~ParametersPlugin_VariableValidator()
20 {
21 }
22
23 bool ParametersPlugin_VariableValidator::isValid(const AttributePtr& theAttribute,
24                                                  const std::list<std::string>& theArguments) const
25 {
26   AttributeStringPtr aStrAttr = std::dynamic_pointer_cast<ModelAPI_AttributeString>(theAttribute);
27   bool result = std::regex_match(aStrAttr->value(), myPyVariableRegex);
28   return result;
29 }
30
31 ParametersPlugin_ExpressionValidator::ParametersPlugin_ExpressionValidator()
32 {
33
34 }
35
36 ParametersPlugin_ExpressionValidator::~ParametersPlugin_ExpressionValidator()
37 {
38
39 }
40
41 bool ParametersPlugin_ExpressionValidator::isValid(const AttributePtr& theAttribute,
42                                                   const std::list<std::string>& theArguments) const
43 {
44   FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
45   ResultParameterPtr aParam =
46       std::dynamic_pointer_cast<ModelAPI_ResultParameter>(aFeature->firstResult());
47
48   AttributeStringPtr aStrAttr =
49     std::dynamic_pointer_cast<ModelAPI_AttributeString>(theAttribute);
50   bool isEmptyExpr = aStrAttr->value().empty();
51   if(isEmptyExpr)
52     return false;
53
54   if(!aParam.get())
55     return false;
56
57   return aFeature->error().empty();
58 }