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