1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: Model_AttributeInteger.cpp
4 // Created: 03 sep 2014
7 #include <Model_AttributeInteger.h>
9 #include <ModelAPI_Data.h>
10 #include <ModelAPI_Events.h>
11 #include <ModelAPI_Expression.h>
12 #include <ModelAPI_Object.h>
14 Model_AttributeInteger::Model_AttributeInteger()
16 myIsInitialized = false;
19 void Model_AttributeInteger::setCalculatedValue(const int theValue)
21 if (!myIsInitialized || value() != theValue) {
22 myExpression->setValue(theValue);
23 owner()->data()->sendAttributeUpdated(this);
27 void Model_AttributeInteger::setValue(const int theValue)
29 setCalculatedValue(text().empty() ? theValue : value());
32 int Model_AttributeInteger::value()
34 return myExpression->value();
37 void Model_AttributeInteger::setText(const std::string& theValue)
39 if (text() != theValue) {
40 myExpression->setText(theValue);
41 // Send it to evaluator to convert text to integer and store in the attribute
42 ModelAPI_AttributeEvalMessage::send(owner()->data()->attribute(id()), this);
43 owner()->data()->sendAttributeUpdated(this);
47 std::string Model_AttributeInteger::text()
49 return myExpression->text();
52 void Model_AttributeInteger::setExpressionInvalid(const bool theFlag)
54 myExpression->setInvalid(theFlag);
57 bool Model_AttributeInteger::expressionInvalid()
59 return myExpression->isInvalid();
62 void Model_AttributeInteger::setExpressionError(const std::string& theError)
64 if (expressionError() != theError)
65 myExpression->setError(theError);
68 std::string Model_AttributeInteger::expressionError()
70 return myExpression->error();
73 void Model_AttributeInteger::setUsedParameters(const std::set<std::string>& theUsedParameters)
75 myExpression->setUsedParameters(theUsedParameters);
78 std::set<std::string> Model_AttributeInteger::usedParameters() const
80 return myExpression->usedParameters();