1 // Copyright (C) 2014-2019 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #ifndef ModelAPI_Expression_H_
21 #define ModelAPI_Expression_H_
29 /**\class ModelAPI_Expression
31 * \brief Expression for calculated values.
33 class ModelAPI_Expression
36 /// To virtually destroy the fields of successors
37 MODELAPI_EXPORT virtual ~ModelAPI_Expression();
39 /// Returns true if attribute was initialized by some value
40 MODELAPI_EXPORT virtual bool isInitialized();
42 /// Makes attribute initialized
43 MODELAPI_EXPORT virtual void setInitialized();
45 /// Sets the text of this Expression
46 MODELAPI_EXPORT virtual void setText(const std::string& theText) = 0;
48 /// Returns the text of this Expression
49 MODELAPI_EXPORT virtual std::string text() const = 0;
51 /// Allows to set expression (text) as invalid (by the parameters listener)
52 MODELAPI_EXPORT virtual void setInvalid(const bool theFlag) = 0;
54 /// Returns true if text is invalid
55 MODELAPI_EXPORT virtual bool isInvalid() = 0;
57 /// Allows to set expression (text) error (by the parameters listener)
58 MODELAPI_EXPORT virtual void setError(const std::string& theError) = 0;
60 /// Returns an expression error
61 MODELAPI_EXPORT virtual std::string error() = 0;
63 /// Defines the used parameters (by the parameters listener)
64 MODELAPI_EXPORT virtual
65 void setUsedParameters(const std::set<std::string>& theUsedParameters) = 0;
67 /// Returns the used parameters
68 MODELAPI_EXPORT virtual std::set<std::string> usedParameters() const = 0;
70 /// Returns True if the given string can be defined as a name of an expression variable
71 MODELAPI_EXPORT static bool isVariable(const std::string& theString);
74 /// Objects are created for features automatically
75 MODELAPI_EXPORT ModelAPI_Expression();
76 /// Reinitializes the internal state of the attribute (may be needed on undo/redo, abort, etc)
77 MODELAPI_EXPORT virtual void reinit() = 0;
78 /// Resets attribute to deafult state.
79 MODELAPI_EXPORT virtual void reset() {
80 myIsInitialized = false;
83 bool myIsInitialized; ///< is some value assigned to this attribute
85 friend class Model_Data;
86 friend class Model_AttributeDouble;
87 friend class Model_AttributeInteger;
88 friend class GeomData_Point;
89 friend class GeomData_Point2D;
93 /**\class ModelAPI_ExpressionDouble
95 * \brief Expression for calculated double values.
97 class ModelAPI_ExpressionDouble : public virtual ModelAPI_Expression
100 /// Defines the double value
101 MODELAPI_EXPORT virtual void setValue(const double theValue) = 0;
103 /// Returns the double value
104 MODELAPI_EXPORT virtual double value() = 0;
107 /// Objects are created for features automatically
108 MODELAPI_EXPORT ModelAPI_ExpressionDouble();
110 friend class Model_Data;
114 /**\class ModelAPI_ExpressionInteger
116 * \brief Expression for calculated integer values.
118 class ModelAPI_ExpressionInteger : public virtual ModelAPI_Expression
121 /// Defines the integer value
122 MODELAPI_EXPORT virtual void setValue(const int theValue) = 0;
124 /// Returns the integer value
125 MODELAPI_EXPORT virtual int value() = 0;
128 /// Objects are created for features automatically
129 MODELAPI_EXPORT ModelAPI_ExpressionInteger();
131 friend class Model_Data;
135 //! Smart pointers for objects
136 typedef std::shared_ptr<ModelAPI_Expression> ExpressionPtr;
137 typedef std::shared_ptr<ModelAPI_ExpressionDouble> ExpressionDoublePtr;
138 typedef std::shared_ptr<ModelAPI_ExpressionInteger> ExpressionIntegerPtr;