Salome HOME
Check name of a new parameter defined by user
[modules/shaper.git] / src / ModelAPI / ModelAPI_Expression.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        ModelAPI_Expression.h
4 // Created:     5 Aug 2015
5 // Author:      Sergey POKHODENKO
6
7 #ifndef ModelAPI_Expression_H_
8 #define ModelAPI_Expression_H_
9
10 #include "ModelAPI.h"
11
12 #include <memory>
13 #include <set>
14 #include <string>
15
16 /**\class ModelAPI_Expression
17  * \ingroup DataModel
18  * \brief Expression for calculated values.
19  */
20 class ModelAPI_Expression
21 {
22  public:
23   /// To virtually destroy the fields of successors
24   MODELAPI_EXPORT virtual ~ModelAPI_Expression();
25
26   /// Returns true if attribute was initialized by some value
27   MODELAPI_EXPORT virtual bool isInitialized();
28
29   /// Makes attribute initialized
30   MODELAPI_EXPORT virtual void setInitialized();
31
32   /// Sets the text of this Expression
33   MODELAPI_EXPORT virtual void setText(const std::string& theText) = 0;
34
35   /// Returns the text of this Expression
36   MODELAPI_EXPORT virtual std::string text() const = 0;
37
38   /// Allows to set expression (text) as invalid (by the parameters listener)
39   MODELAPI_EXPORT virtual void setInvalid(const bool theFlag) = 0;
40
41   /// Returns true if text is invalid
42   MODELAPI_EXPORT virtual bool isInvalid() = 0;
43
44   /// Allows to set expression (text) error (by the parameters listener)
45   MODELAPI_EXPORT virtual void setError(const std::string& theError) = 0;
46
47   /// Returns an expression error
48   MODELAPI_EXPORT virtual std::string error() = 0;
49
50   /// Defines the used parameters (by the parameters listener)
51   MODELAPI_EXPORT virtual void setUsedParameters(const std::set<std::string>& theUsedParameters) = 0;
52
53   /// Returns the used parameters
54   MODELAPI_EXPORT virtual std::set<std::string> usedParameters() const = 0;
55
56   /// Returns True if the given string can be defined as a name of an expression variable
57   MODELAPI_EXPORT static bool isVariable(const std::string& theString);
58
59  protected:
60   /// Objects are created for features automatically
61   MODELAPI_EXPORT ModelAPI_Expression();
62   /// Reinitializes the internal state of the attribute (may be needed on undo/redo, abort, etc)
63   MODELAPI_EXPORT virtual void reinit() = 0;
64
65   bool myIsInitialized; ///< is some value assigned to this attribute
66
67   friend class Model_Data;
68   friend class Model_AttributeDouble;
69   friend class Model_AttributeInteger;
70   friend class GeomData_Point;
71   friend class GeomData_Point2D;
72 };
73
74
75 /**\class ModelAPI_ExpressionDouble
76  * \ingroup DataModel
77  * \brief Expression for calculated double values.
78  */
79 class ModelAPI_ExpressionDouble : public virtual ModelAPI_Expression
80 {
81  public:
82   /// Defines the double value
83   MODELAPI_EXPORT virtual void setValue(const double theValue) = 0;
84
85   /// Returns the double value
86   MODELAPI_EXPORT virtual double value() = 0;
87
88  protected:
89   /// Objects are created for features automatically
90   MODELAPI_EXPORT ModelAPI_ExpressionDouble();
91
92   friend class Model_Data;
93 };
94
95
96 /**\class ModelAPI_ExpressionInteger
97  * \ingroup DataModel
98  * \brief Expression for calculated integer values.
99  */
100 class ModelAPI_ExpressionInteger : public virtual ModelAPI_Expression
101 {
102  public:
103   /// Defines the integer value
104   MODELAPI_EXPORT virtual void setValue(const int theValue) = 0;
105
106   /// Returns the integer value
107   MODELAPI_EXPORT virtual int value() = 0;
108
109  protected:
110   /// Objects are created for features automatically
111   MODELAPI_EXPORT ModelAPI_ExpressionInteger();
112
113   friend class Model_Data;
114 };
115
116
117 //! Smart pointers for objects
118 typedef std::shared_ptr<ModelAPI_Expression> ExpressionPtr;
119 typedef std::shared_ptr<ModelAPI_ExpressionDouble> ExpressionDoublePtr;
120 typedef std::shared_ptr<ModelAPI_ExpressionInteger> ExpressionIntegerPtr;
121
122 #endif