Salome HOME
Copyright update 2021
[modules/shaper.git] / src / Model / Model_AttributeDouble.cpp
1 // Copyright (C) 2014-2021  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 email : webmaster.salome@opencascade.com
18 //
19
20 #include "Model_AttributeDouble.h"
21
22 #include <ModelAPI_Data.h>
23 #include <ModelAPI_Events.h>
24 #include <Model_Expression.h>
25 #include <ModelAPI_Object.h>
26
27 Model_AttributeDouble::Model_AttributeDouble(TDF_Label& theLabel)
28 {
29   TDF_Label anExpressionLab = theLabel.FindChild(1);
30   myExpression.reset(new Model_ExpressionDouble(anExpressionLab));
31   myIsInitialized = myExpression->isInitialized();
32 }
33
34 void Model_AttributeDouble::reinit()
35 {
36   myExpression->reinit();
37   myIsInitialized = myExpression->isInitialized();
38 }
39
40 void Model_AttributeDouble::reset()
41 {
42   myExpression->reset();
43   myIsInitialized = false;
44 }
45
46 void Model_AttributeDouble::setCalculatedValue(const double theValue)
47 {
48   if (!myIsInitialized || value() != theValue) {
49     myExpression->setValue(theValue);
50     owner()->data()->sendAttributeUpdated(this);
51   }
52 }
53
54 void Model_AttributeDouble::setValue(const double theValue)
55 {
56   setCalculatedValue(text().empty() ? theValue : value());
57 }
58
59 double Model_AttributeDouble::value()
60 {
61   return myExpression->value();
62 }
63
64 void Model_AttributeDouble::setText(const std::wstring& theValue)
65 {
66   if (text() != theValue) {
67     myExpression->setText(theValue);
68     // Send it to evaluator to convert text to double and store in the attribute
69     ModelAPI_AttributeEvalMessage::send(owner()->data()->attribute(id()), this);
70     owner()->data()->sendAttributeUpdated(this);
71   }
72 }
73
74 std::wstring Model_AttributeDouble::text()
75 {
76   return myExpression->text();
77 }
78
79 void Model_AttributeDouble::setExpressionInvalid(const bool theFlag)
80 {
81   myExpression->setInvalid(theFlag);
82 }
83
84 bool Model_AttributeDouble::expressionInvalid()
85 {
86   return myExpression->isInvalid();
87 }
88
89 void Model_AttributeDouble::setExpressionError(const std::string& theError)
90 {
91   if (expressionError() != theError)
92     myExpression->setError(theError);
93 }
94
95 std::string Model_AttributeDouble::expressionError()
96 {
97   return myExpression->error();
98 }
99
100 void Model_AttributeDouble::setUsedParameters(const std::set<std::wstring>& theUsedParameters)
101 {
102   myExpression->setUsedParameters(theUsedParameters);
103 }
104
105 std::set<std::wstring> Model_AttributeDouble::usedParameters() const
106 {
107   return myExpression->usedParameters();
108 }