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