Salome HOME
Added the system of reinitialization of attributes instead of re-creation of them...
[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::setCalculatedValue(const double theValue)
28 {
29   if (!myIsInitialized || value() != theValue) {
30     myExpression->setValue(theValue);
31     owner()->data()->sendAttributeUpdated(this);
32   }
33 }
34
35 void Model_AttributeDouble::setValue(const double theValue)
36 {
37   setCalculatedValue(text().empty() ? theValue : value());
38 }
39
40 double Model_AttributeDouble::value()
41 {
42   return myExpression->value();
43 }
44
45 void Model_AttributeDouble::setText(const std::string& theValue)
46 {
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);
52   }
53 }
54
55 std::string Model_AttributeDouble::text()
56 {
57   return myExpression->text();
58 }
59
60 void Model_AttributeDouble::setExpressionInvalid(const bool theFlag)
61 {
62   myExpression->setInvalid(theFlag);
63 }
64
65 bool Model_AttributeDouble::expressionInvalid()
66 {
67   return myExpression->isInvalid();
68 }
69
70 void Model_AttributeDouble::setExpressionError(const std::string& theError)
71 {
72   if (expressionError() != theError)
73     myExpression->setError(theError);
74 }
75
76 std::string Model_AttributeDouble::expressionError()
77 {
78   return myExpression->error();
79 }
80
81 void Model_AttributeDouble::setUsedParameters(const std::set<std::string>& theUsedParameters)
82 {
83   myExpression->setUsedParameters(theUsedParameters);
84 }
85
86 std::set<std::string> Model_AttributeDouble::usedParameters() const
87 {
88   return myExpression->usedParameters();
89 }