SHAPER  9.12.0
ModelAPI_Expression.h
1 // Copyright (C) 2014-2023 CEA, EDF
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 email : webmaster.salome@opencascade.com
18 //
19 
20 #ifndef ModelAPI_Expression_H_
21 #define ModelAPI_Expression_H_
22 
23 #include "ModelAPI.h"
24 
25 #include <memory>
26 #include <set>
27 #include <string>
28 
34 {
35  public:
37  MODELAPI_EXPORT virtual ~ModelAPI_Expression();
38 
40  MODELAPI_EXPORT virtual bool isInitialized();
41 
43  MODELAPI_EXPORT virtual void setInitialized();
44 
46  MODELAPI_EXPORT virtual void setText(const std::wstring& theText) = 0;
47 
49  MODELAPI_EXPORT virtual std::wstring text() const = 0;
50 
52  MODELAPI_EXPORT virtual void setInvalid(const bool theFlag) = 0;
53 
55  MODELAPI_EXPORT virtual bool isInvalid() = 0;
56 
58  MODELAPI_EXPORT virtual void setError(const std::string& theError) = 0;
59 
61  MODELAPI_EXPORT virtual std::string error() = 0;
62 
64  MODELAPI_EXPORT virtual
65  void setUsedParameters(const std::set<std::wstring>& theUsedParameters) = 0;
66 
68  MODELAPI_EXPORT virtual std::set<std::wstring> usedParameters() const = 0;
69 
71  MODELAPI_EXPORT static bool isVariable(const std::string& theString);
72 
74  MODELAPI_EXPORT static bool isVariable(const std::wstring& theString);
75 
76  protected:
78  MODELAPI_EXPORT ModelAPI_Expression();
80  MODELAPI_EXPORT virtual void reinit() = 0;
82  MODELAPI_EXPORT virtual void reset() {
83  myIsInitialized = false;
84  };
85 
87 
88  friend class Model_Data;
89  friend class Model_AttributeDouble;
90  friend class Model_AttributeInteger;
91  friend class GeomData_Point;
92  friend class GeomData_Point2D;
93 };
94 
95 
101 {
102  public:
104  MODELAPI_EXPORT virtual void setValue(const double theValue) = 0;
105 
107  MODELAPI_EXPORT virtual double value() = 0;
108 
109  protected:
111  MODELAPI_EXPORT ModelAPI_ExpressionDouble();
112 
113  friend class Model_Data;
114 };
115 
116 
122 {
123  public:
125  MODELAPI_EXPORT virtual void setValue(const int theValue) = 0;
126 
128  MODELAPI_EXPORT virtual int value() = 0;
129 
130  protected:
132  MODELAPI_EXPORT ModelAPI_ExpressionInteger();
133 
134  friend class Model_Data;
135 };
136 
137 
139 typedef std::shared_ptr<ModelAPI_Expression> ExpressionPtr;
140 typedef std::shared_ptr<ModelAPI_ExpressionDouble> ExpressionDoublePtr;
141 typedef std::shared_ptr<ModelAPI_ExpressionInteger> ExpressionIntegerPtr;
142 
143 #endif
Attribute that contains 2D point.
Definition: GeomData_Point2D.h:36
Attribute that contains 3D point.
Definition: GeomData_Point.h:35
Expression for calculated double values.
Definition: ModelAPI_Expression.h:101
virtual void setValue(const double theValue)=0
Defines the double value.
ModelAPI_ExpressionDouble()
Objects are created for features automatically.
Definition: ModelAPI_Expression.cpp:46
virtual double value()=0
Returns the double value.
Expression for calculated integer values.
Definition: ModelAPI_Expression.h:122
virtual void setValue(const int theValue)=0
Defines the integer value.
virtual int value()=0
Returns the integer value.
ModelAPI_ExpressionInteger()
Objects are created for features automatically.
Definition: ModelAPI_Expression.cpp:51
Expression for calculated values.
Definition: ModelAPI_Expression.h:34
virtual std::set< std::wstring > usedParameters() const =0
Returns the used parameters.
virtual void setError(const std::string &theError)=0
Allows to set expression (text) error (by the parameters listener)
virtual std::wstring text() const =0
Returns the text of this Expression.
virtual ~ModelAPI_Expression()
To virtually destroy the fields of successors.
Definition: ModelAPI_Expression.cpp:31
ModelAPI_Expression()
Objects are created for features automatically.
Definition: ModelAPI_Expression.cpp:26
virtual void setText(const std::wstring &theText)=0
Sets the text of this Expression.
virtual bool isInitialized()
Returns true if attribute was initialized by some value.
Definition: ModelAPI_Expression.cpp:36
virtual void setInitialized()
Makes attribute initialized.
Definition: ModelAPI_Expression.cpp:41
virtual void reset()
Resets attribute to deafult state.
Definition: ModelAPI_Expression.h:82
virtual bool isInvalid()=0
Returns true if text is invalid.
virtual std::string error()=0
Returns an expression error.
virtual void setUsedParameters(const std::set< std::wstring > &theUsedParameters)=0
Defines the used parameters (by the parameters listener)
virtual void reinit()=0
Reinitializes the internal state of the attribute (may be needed on undo/redo, abort,...
virtual void setInvalid(const bool theFlag)=0
Allows to set expression (text) as invalid (by the parameters listener)
static bool isVariable(const std::string &theString)
Returns True if the given string can be defined as a name of an expression variable.
Definition: ModelAPI_Expression.cpp:57
bool myIsInitialized
is some value assigned to this attribute
Definition: ModelAPI_Expression.h:84
Attribute that contains real value with double precision.
Definition: Model_AttributeDouble.h:36
Attribute that contains integer.
Definition: Model_AttributeInteger.h:36
General object of the application that allows to get/set attributes from the document and compute res...
Definition: Model_Data.h:61