Salome HOME
cac4c4aa6fada2edad5f22d43790f5be3a7a9779
[modules/shaper.git] / src / Model / Model_Expression.h
1 // Copyright (C) 2014-2023  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 #ifndef Model_Expression_H_
21 #define Model_Expression_H_
22
23 #include "Model.h"
24 #include "ModelAPI_Expression.h"
25
26 #include <TDataStd_Comment.hxx>
27 #include <TDataStd_ExtStringList.hxx>
28 #include <TDataStd_Integer.hxx>
29 #include <TDataStd_Name.hxx>
30 #include <TDataStd_Real.hxx>
31
32 #include <TDF_Label.hxx>
33
34 /**\class Model_Expression
35  * \ingroup DataModel
36  * \brief Implementation of ModelAPI_Expression.
37  */
38 class Model_Expression : public virtual ModelAPI_Expression
39 {
40  public:
41   /// Sets the text of this Expression
42   MODEL_EXPORT virtual void setText(const std::wstring& theText);
43
44   /// Returns the text of this Expression
45   MODEL_EXPORT virtual std::wstring text() const;
46
47   /// Allows to set expression (text) error (by the parameters listener)
48   MODEL_EXPORT virtual void setError(const std::string& theError);
49
50   /// Returns an expression error
51   MODEL_EXPORT virtual std::string error();
52
53   /// Defines the used parameters (by the parameters listener)
54   MODEL_EXPORT virtual void setUsedParameters(const std::set<std::wstring>& theUsedParameters);
55
56   /// Returns the used parameters
57   MODEL_EXPORT virtual std::set<std::wstring> usedParameters() const;
58
59  protected:
60   /// Initializes attributes
61   Model_Expression(TDF_Label& theLabel);
62
63   Handle_TDataStd_Name myText; ///< Text representation of the attribute (may differ for parameters)
64   Handle_TDataStd_Comment myError; ///< Error of expression of the text attribute
65   Handle_TDataStd_ExtStringList myUsedParameters; ///< Parameters used in expression
66   TDF_Label myLab; ///< if attribute is not initialized, store label here
67 };
68
69
70 /**\class Model_ExpressionDouble
71  * \ingroup DataModel
72  * \brief Implementation of ModelAPI_ExpressionDouble.
73  */
74 class Model_ExpressionDouble :
75     public Model_Expression, // implementation inheritance
76     public ModelAPI_ExpressionDouble
77 {
78  public:
79   /// Sets the text of this Expression
80   MODEL_EXPORT virtual void setText(const std::wstring& theText) {
81     Model_Expression::setText(theText);
82   };
83
84   /// Returns the text of this Expression
85   MODEL_EXPORT virtual std::wstring text() const {
86     return Model_Expression::text();
87   };
88
89   /// Allows to set expression (text) error (by the parameters listener)
90   MODEL_EXPORT virtual void setError(const std::string& theError) {
91     Model_Expression::setError(theError);
92   };
93
94   /// Returns an expression error
95   MODEL_EXPORT virtual std::string error() {
96     return Model_Expression::error();
97   };
98
99   /// Defines the used parameters (by the parameters listener)
100   MODEL_EXPORT virtual void setUsedParameters(const std::set<std::wstring>& theUsedParameters) {
101     Model_Expression::setUsedParameters(theUsedParameters);
102   };
103
104   /// Returns the used parameters
105   MODEL_EXPORT virtual std::set<std::wstring> usedParameters() const {
106     return Model_Expression::usedParameters();
107   };
108
109   /// Defines the double value
110   MODEL_EXPORT virtual void setValue(const double theValue);
111
112   /// Returns the double value
113   MODEL_EXPORT virtual double value();
114
115   /// Allows to set expression (text) as invalid (by the parameters listener)
116   MODEL_EXPORT virtual void setInvalid(const bool theFlag);
117
118   /// Returns true if text is invalid
119   MODEL_EXPORT virtual bool isInvalid();
120
121  protected:
122   /// Initializes attributes
123   Model_ExpressionDouble(TDF_Label& theLabel);
124   /// Reinitializes the internal state of the attribute (may be needed on undo/redo, abort, etc)
125   virtual void reinit();
126
127   friend class Model_AttributeDouble;
128   friend class Model_Data;
129
130  private:
131   Handle_TDataStd_Real myReal; ///< double is Real attribute
132 };
133
134
135 /**\class Model_ExpressionInteger
136  * \ingroup DataModel
137  * \brief Implementation of ModelAPI_ExpressionInteger.
138  */
139 class Model_ExpressionInteger :
140     public Model_Expression, // implementation inheritance
141     public ModelAPI_ExpressionInteger
142 {
143  public:
144   /// Sets the text of this Expression
145   MODEL_EXPORT virtual void setText(const std::wstring& theText) {
146     Model_Expression::setText(theText);
147   };
148
149   /// Returns the text of this Expression
150   MODEL_EXPORT virtual std::wstring text() const {
151     return Model_Expression::text();
152   };
153
154   /// Allows to set expression (text) error (by the parameters listener)
155   MODEL_EXPORT virtual void setError(const std::string& theError) {
156     Model_Expression::setError(theError);
157   };
158
159   /// Returns an expression error
160   MODEL_EXPORT virtual std::string error() {
161     return Model_Expression::error();
162   };
163
164   /// Defines the used parameters (by the parameters listener)
165   MODEL_EXPORT virtual void setUsedParameters(const std::set<std::wstring>& theUsedParameters) {
166     Model_Expression::setUsedParameters(theUsedParameters);
167   };
168
169   /// Returns the used parameters
170   MODEL_EXPORT virtual std::set<std::wstring> usedParameters() const {
171     return Model_Expression::usedParameters();
172   };
173
174   /// Defines the integer value
175   MODEL_EXPORT virtual void setValue(const int theValue);
176
177   /// Returns the integer value
178   MODEL_EXPORT virtual int value();
179
180   /// Allows to set expression (text) as invalid (by the parameters listener)
181   MODEL_EXPORT virtual void setInvalid(const bool theFlag);
182
183   /// Returns true if text is invalid
184   MODEL_EXPORT virtual bool isInvalid();
185
186  protected:
187   /// Initializes attributes
188   Model_ExpressionInteger(TDF_Label& theLabel);
189   /// Reinitializes the internal state of the attribute (may be needed on undo/redo, abort, etc)
190   virtual void reinit();
191
192   friend class Model_AttributeInteger;
193
194  private:
195   Handle_TDataStd_Integer myInteger;
196 };
197
198 #endif // Model_Expression_H_