Salome HOME
Merge branch 'master' into cgt/devCEA
[modules/shaper.git] / src / Model / Model_AttributeDouble.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        ModelAPI_AttributeDouble.cxx
4 // Created:     2 Apr 2014
5 // Author:      Mikhail PONIKAROV
6
7 #include "Model_AttributeDouble.h"
8
9 #include <ModelAPI_Data.h>
10 #include <ModelAPI_Events.h>
11 #include <Model_Expression.h>
12 #include <ModelAPI_Object.h>
13
14 Model_AttributeDouble::Model_AttributeDouble(TDF_Label& theLabel)
15 {
16   TDF_Label anExpressionLab = theLabel.FindChild(1);
17   myExpression.reset(new Model_ExpressionDouble(anExpressionLab));
18   myIsInitialized = myExpression->isInitialized();
19 }
20
21 void Model_AttributeDouble::reinit()
22 {
23   myExpression->reinit();
24   myIsInitialized = myExpression->isInitialized();
25 }
26
27 void Model_AttributeDouble::reset()
28 {
29   myExpression->reset();
30   myIsInitialized = false;
31 }
32
33 void Model_AttributeDouble::setCalculatedValue(const double theValue)
34 {
35   if (!myIsInitialized || value() != theValue) {
36     myExpression->setValue(theValue);
37     owner()->data()->sendAttributeUpdated(this);
38   }
39 }
40
41 void Model_AttributeDouble::setValue(const double theValue)
42 {
43   setCalculatedValue(text().empty() ? theValue : value());
44 }
45
46 double Model_AttributeDouble::value()
47 {
48   return myExpression->value();
49 }
50
51 void Model_AttributeDouble::setText(const std::string& theValue)
52 {
53   if (text() != theValue) {
54     myExpression->setText(theValue);
55     // Send it to evaluator to convert text to double and store in the attribute
56     ModelAPI_AttributeEvalMessage::send(owner()->data()->attribute(id()), this);
57     owner()->data()->sendAttributeUpdated(this);
58   }
59 }
60
61 std::string Model_AttributeDouble::text()
62 {
63   return myExpression->text();
64 }
65
66 void Model_AttributeDouble::setExpressionInvalid(const bool theFlag)
67 {
68   myExpression->setInvalid(theFlag);
69 }
70
71 bool Model_AttributeDouble::expressionInvalid()
72 {
73   return myExpression->isInvalid();
74 }
75
76 void Model_AttributeDouble::setExpressionError(const std::string& theError)
77 {
78   if (expressionError() != theError)
79     myExpression->setError(theError);
80 }
81
82 std::string Model_AttributeDouble::expressionError()
83 {
84   return myExpression->error();
85 }
86
87 void Model_AttributeDouble::setUsedParameters(const std::set<std::string>& theUsedParameters)
88 {
89   myExpression->setUsedParameters(theUsedParameters);
90 }
91
92 std::set<std::string> Model_AttributeDouble::usedParameters() const
93 {
94   return myExpression->usedParameters();
95 }