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 <Model_Expression.h>
12 #include <ModelAPI_Object.h>
14 Model_AttributeDouble::Model_AttributeDouble(TDF_Label& theLabel)
16 TDF_Label anExpressionLab = theLabel.FindChild(1);
17 myExpression.reset(new Model_ExpressionDouble(anExpressionLab));
18 myIsInitialized = myExpression->isInitialized();
21 void Model_AttributeDouble::reinit()
23 myExpression->reinit();
24 myIsInitialized = myExpression->isInitialized();
27 void Model_AttributeDouble::setCalculatedValue(const double theValue)
29 if (!myIsInitialized || value() != theValue) {
30 myExpression->setValue(theValue);
31 owner()->data()->sendAttributeUpdated(this);
35 void Model_AttributeDouble::setValue(const double theValue)
37 setCalculatedValue(text().empty() ? theValue : value());
40 double Model_AttributeDouble::value()
42 return myExpression->value();
45 void Model_AttributeDouble::setText(const std::string& theValue)
47 if (text() != theValue) {
48 myExpression->setText(theValue);
49 // Send it to evaluator to convert text to double and store in the attribute
50 ModelAPI_AttributeEvalMessage::send(owner()->data()->attribute(id()), this);
51 owner()->data()->sendAttributeUpdated(this);
55 std::string Model_AttributeDouble::text()
57 return myExpression->text();
60 void Model_AttributeDouble::setExpressionInvalid(const bool theFlag)
62 myExpression->setInvalid(theFlag);
65 bool Model_AttributeDouble::expressionInvalid()
67 return myExpression->isInvalid();
70 void Model_AttributeDouble::setExpressionError(const std::string& theError)
72 if (expressionError() != theError)
73 myExpression->setError(theError);
76 std::string Model_AttributeDouble::expressionError()
78 return myExpression->error();
81 void Model_AttributeDouble::setUsedParameters(const std::set<std::string>& theUsedParameters)
83 myExpression->setUsedParameters(theUsedParameters);
86 std::set<std::string> Model_AttributeDouble::usedParameters() const
88 return myExpression->usedParameters();