Salome HOME
Issue #2614: Implement point 2: optimization of selection synchronization
[modules/shaper.git] / src / ModelAPI / ModelAPI_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 ModelAPI_Expression_H_
22 #define ModelAPI_Expression_H_
23
24 #include "ModelAPI.h"
25
26 #include <memory>
27 #include <set>
28 #include <string>
29
30 /**\class ModelAPI_Expression
31  * \ingroup DataModel
32  * \brief Expression for calculated values.
33  */
34 class ModelAPI_Expression
35 {
36  public:
37   /// To virtually destroy the fields of successors
38   MODELAPI_EXPORT virtual ~ModelAPI_Expression();
39
40   /// Returns true if attribute was initialized by some value
41   MODELAPI_EXPORT virtual bool isInitialized();
42
43   /// Makes attribute initialized
44   MODELAPI_EXPORT virtual void setInitialized();
45
46   /// Sets the text of this Expression
47   MODELAPI_EXPORT virtual void setText(const std::string& theText) = 0;
48
49   /// Returns the text of this Expression
50   MODELAPI_EXPORT virtual std::string text() const = 0;
51
52   /// Allows to set expression (text) as invalid (by the parameters listener)
53   MODELAPI_EXPORT virtual void setInvalid(const bool theFlag) = 0;
54
55   /// Returns true if text is invalid
56   MODELAPI_EXPORT virtual bool isInvalid() = 0;
57
58   /// Allows to set expression (text) error (by the parameters listener)
59   MODELAPI_EXPORT virtual void setError(const std::string& theError) = 0;
60
61   /// Returns an expression error
62   MODELAPI_EXPORT virtual std::string error() = 0;
63
64   /// Defines the used parameters (by the parameters listener)
65   MODELAPI_EXPORT virtual
66     void setUsedParameters(const std::set<std::string>& theUsedParameters) = 0;
67
68   /// Returns the used parameters
69   MODELAPI_EXPORT virtual std::set<std::string> usedParameters() const = 0;
70
71   /// Returns True if the given string can be defined as a name of an expression variable
72   MODELAPI_EXPORT static bool isVariable(const std::string& theString);
73
74  protected:
75   /// Objects are created for features automatically
76   MODELAPI_EXPORT ModelAPI_Expression();
77   /// Reinitializes the internal state of the attribute (may be needed on undo/redo, abort, etc)
78   MODELAPI_EXPORT virtual void reinit() = 0;
79   /// Resets attribute to deafult state.
80   MODELAPI_EXPORT virtual void reset() {
81     myIsInitialized = false;
82   };
83
84   bool myIsInitialized; ///< is some value assigned to this attribute
85
86   friend class Model_Data;
87   friend class Model_AttributeDouble;
88   friend class Model_AttributeInteger;
89   friend class GeomData_Point;
90   friend class GeomData_Point2D;
91 };
92
93
94 /**\class ModelAPI_ExpressionDouble
95  * \ingroup DataModel
96  * \brief Expression for calculated double values.
97  */
98 class ModelAPI_ExpressionDouble : public virtual ModelAPI_Expression
99 {
100  public:
101   /// Defines the double value
102   MODELAPI_EXPORT virtual void setValue(const double theValue) = 0;
103
104   /// Returns the double value
105   MODELAPI_EXPORT virtual double value() = 0;
106
107  protected:
108   /// Objects are created for features automatically
109   MODELAPI_EXPORT ModelAPI_ExpressionDouble();
110
111   friend class Model_Data;
112 };
113
114
115 /**\class ModelAPI_ExpressionInteger
116  * \ingroup DataModel
117  * \brief Expression for calculated integer values.
118  */
119 class ModelAPI_ExpressionInteger : public virtual ModelAPI_Expression
120 {
121  public:
122   /// Defines the integer value
123   MODELAPI_EXPORT virtual void setValue(const int theValue) = 0;
124
125   /// Returns the integer value
126   MODELAPI_EXPORT virtual int value() = 0;
127
128  protected:
129   /// Objects are created for features automatically
130   MODELAPI_EXPORT ModelAPI_ExpressionInteger();
131
132   friend class Model_Data;
133 };
134
135
136 //! Smart pointers for objects
137 typedef std::shared_ptr<ModelAPI_Expression> ExpressionPtr;
138 typedef std::shared_ptr<ModelAPI_ExpressionDouble> ExpressionDoublePtr;
139 typedef std::shared_ptr<ModelAPI_ExpressionInteger> ExpressionIntegerPtr;
140
141 #endif