Salome HOME
updated copyright message
[modules/shaper.git] / src / Model / Model_AttributeInteger.cpp
1 // Copyright (C) 2014-2023  CEA, EDF
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_AttributeInteger.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_AttributeInteger::Model_AttributeInteger(TDF_Label& theLabel)
28 {
29   // to the same label to support the backward compatibility
30   myExpression.reset(new Model_ExpressionInteger(theLabel));
31   myIsInitialized = myExpression->isInitialized();
32 }
33
34 void Model_AttributeInteger::reinit()
35 {
36   myExpression->reinit();
37   myIsInitialized = myExpression->isInitialized();
38 }
39
40 void Model_AttributeInteger::setCalculatedValue(const int theValue)
41 {
42   if (!myIsInitialized || value() != theValue) {
43     myExpression->setValue(theValue);
44     owner()->data()->sendAttributeUpdated(this);
45   }
46 }
47
48 void Model_AttributeInteger::setValue(const int theValue)
49 {
50   setCalculatedValue(text().empty() ? theValue : value());
51 }
52
53 int Model_AttributeInteger::value()
54 {
55   return myExpression->value();
56 }
57
58 void Model_AttributeInteger::setText(const std::wstring& theValue)
59 {
60   if (text() != theValue) {
61     myExpression->setText(theValue);
62     // Send it to evaluator to convert text to integer and store in the attribute
63     ModelAPI_AttributeEvalMessage::send(owner()->data()->attribute(id()), this);
64     owner()->data()->sendAttributeUpdated(this);
65   }
66 }
67
68 std::wstring Model_AttributeInteger::text()
69 {
70   return myExpression->text();
71 }
72
73 void Model_AttributeInteger::setExpressionInvalid(const bool theFlag)
74 {
75   myExpression->setInvalid(theFlag);
76 }
77
78 bool Model_AttributeInteger::expressionInvalid()
79 {
80   return myExpression->isInvalid();
81 }
82
83 void Model_AttributeInteger::setExpressionError(const std::string& theError)
84 {
85   if (expressionError() != theError)
86     myExpression->setError(theError);
87 }
88
89 std::string Model_AttributeInteger::expressionError()
90 {
91   return myExpression->error();
92 }
93
94 void Model_AttributeInteger::setUsedParameters(const std::set<std::wstring>& theUsedParameters)
95 {
96   myExpression->setUsedParameters(theUsedParameters);
97 }
98
99 std::set<std::wstring> Model_AttributeInteger::usedParameters() const
100 {
101   return myExpression->usedParameters();
102 }