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