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