Salome HOME
Merge branch 'master' into cgt/devCEA
[modules/shaper.git] / src / Model / Model_AttributeDouble.cpp
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #include "Model_AttributeDouble.h"
22
23 #include <ModelAPI_Data.h>
24 #include <ModelAPI_Events.h>
25 #include <Model_Expression.h>
26 #include <ModelAPI_Object.h>
27
28 Model_AttributeDouble::Model_AttributeDouble(TDF_Label& theLabel)
29 {
30   TDF_Label anExpressionLab = theLabel.FindChild(1);
31   myExpression.reset(new Model_ExpressionDouble(anExpressionLab));
32   myIsInitialized = myExpression->isInitialized();
33 }
34
35 void Model_AttributeDouble::reinit()
36 {
37   myExpression->reinit();
38   myIsInitialized = myExpression->isInitialized();
39 }
40
41 void Model_AttributeDouble::reset()
42 {
43   myExpression->reset();
44   myIsInitialized = false;
45 }
46
47 void Model_AttributeDouble::setCalculatedValue(const double theValue)
48 {
49   if (!myIsInitialized || value() != theValue) {
50     myExpression->setValue(theValue);
51     owner()->data()->sendAttributeUpdated(this);
52   }
53 }
54
55 void Model_AttributeDouble::setValue(const double theValue)
56 {
57   setCalculatedValue(text().empty() ? theValue : value());
58 }
59
60 double Model_AttributeDouble::value()
61 {
62   return myExpression->value();
63 }
64
65 void Model_AttributeDouble::setText(const std::string& theValue)
66 {
67   if (text() != theValue) {
68     myExpression->setText(theValue);
69     // Send it to evaluator to convert text to double and store in the attribute
70     ModelAPI_AttributeEvalMessage::send(owner()->data()->attribute(id()), this);
71     owner()->data()->sendAttributeUpdated(this);
72   }
73 }
74
75 std::string Model_AttributeDouble::text()
76 {
77   return myExpression->text();
78 }
79
80 void Model_AttributeDouble::setExpressionInvalid(const bool theFlag)
81 {
82   myExpression->setInvalid(theFlag);
83 }
84
85 bool Model_AttributeDouble::expressionInvalid()
86 {
87   return myExpression->isInvalid();
88 }
89
90 void Model_AttributeDouble::setExpressionError(const std::string& theError)
91 {
92   if (expressionError() != theError)
93     myExpression->setError(theError);
94 }
95
96 std::string Model_AttributeDouble::expressionError()
97 {
98   return myExpression->error();
99 }
100
101 void Model_AttributeDouble::setUsedParameters(const std::set<std::string>& theUsedParameters)
102 {
103   myExpression->setUsedParameters(theUsedParameters);
104 }
105
106 std::set<std::string> Model_AttributeDouble::usedParameters() const
107 {
108   return myExpression->usedParameters();
109 }