Salome HOME
Improve the copy feature: make initialized attributes and internal content due in...
[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 <ModelAPI_Expression.h>
12 #include <ModelAPI_Object.h>
13
14 Model_AttributeDouble::Model_AttributeDouble()
15 {
16   myIsInitialized = false;
17 }
18
19 void Model_AttributeDouble::setCalculatedValue(const double theValue)
20 {
21   if (!myIsInitialized || value() != theValue) {
22     myExpression->setValue(theValue);
23     owner()->data()->sendAttributeUpdated(this);
24   }
25 }
26
27 void Model_AttributeDouble::setValue(const double theValue)
28 {
29   setCalculatedValue(text().empty() ? theValue : value());
30 }
31
32 double Model_AttributeDouble::value()
33 {
34   return myExpression->value();
35 }
36
37 void Model_AttributeDouble::setText(const std::string& theValue)
38 {
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);
44   }
45 }
46
47 std::string Model_AttributeDouble::text()
48 {
49   return myExpression->text();
50 }
51
52 void Model_AttributeDouble::setExpressionInvalid(const bool theFlag)
53 {
54   myExpression->setInvalid(theFlag);
55 }
56
57 bool Model_AttributeDouble::expressionInvalid()
58 {
59   return myExpression->isInvalid();
60 }
61
62 void Model_AttributeDouble::setExpressionError(const std::string& theError)
63 {
64   if (expressionError() != theError)
65     myExpression->setError(theError);
66 }
67
68 std::string Model_AttributeDouble::expressionError()
69 {
70   return myExpression->error();
71 }
72
73 void Model_AttributeDouble::setUsedParameters(const std::set<std::string>& theUsedParameters)
74 {
75   myExpression->setUsedParameters(theUsedParameters);
76 }
77
78 std::set<std::string> Model_AttributeDouble::usedParameters() const
79 {
80   return myExpression->usedParameters();
81 }