AGX Dynamics  2.37.2.0
PythonVariable.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2024. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx Simulation AB.
15 */
16 
17 #ifndef AGXFMI_PYTHONVARIABLE_H
18 #define AGXFMI_PYTHONVARIABLE_H
19 
20 #include <agx/config/AGX_USE_FMI.h>
21 #include <agx/config/AGX_USE_PYTHON.h>
22 
23 #if AGX_USE_FMI()
24 
25 #include <agxFMI2/export.h>
26 #include <agxFMI2/Variable.h>
28 #include <agxFMI2/export/Module.h>
29 
30 #include <agx/debug.h>
31 
32 #include <csignal>
33 
34 #include <agx/PushDisableWarnings.h> // Disabling warnings. Include agx/PopDisableWarnings.h below!
35 #if AGX_USE_PYTHON()
36 #if defined(_DEBUG)
37 #undef _DEBUG
38 #include <Python.h>
39 #include <frameobject.h>
40 #define _DEBUG 1
41 #else
42 #include <Python.h>
43 #include <frameobject.h>
44 #endif
45 #endif
46 #include <agx/PopDisableWarnings.h> // End of disabled warnings.
47 
48 namespace agxFMI2
49 {
50 
51  namespace Export
52  {
53 
54  class AGXFMI_EXPORT PythonErrorSignal
55  {
56  public:
57  PythonErrorSignal();
58 
59  void signalError();
60 
61  fmi2Status getFmiStatus() const;
62 
63  protected:
64 
65  fmi2Status m_status;
66  };
67 
68 
70 
71  class AGXFMI_EXPORT OutputVariableBool : public OutputVariable_Bool, public PythonErrorSignal
72  {
73  public:
74  OutputVariableBool(const agx::Name& name);
75 
76  virtual bool getValue();
77 
78  void setStartValue(bool startValue);
79 
80  bool getStartValue();
81 
82 #ifndef SWIG
83  virtual fmi2Status get(fmi2Boolean& value) override;
84 #endif
85 
86  protected:
87  virtual ~OutputVariableBool();
88 
89  private:
90 
91  };
92 
94 
95  class AGXFMI_EXPORT OutputVariableInt : public OutputVariable_Int, public PythonErrorSignal
96  {
97  public:
98  OutputVariableInt(const agx::Name& name);
99 
100  virtual int getValue();
101 
102  void setStartValue(int startValue);
103 
104  int getStartValue();
105 
106 #ifndef SWIG
107  virtual fmi2Status get(fmi2Integer& value) override;
108 #endif
109 
110  protected:
111  virtual ~OutputVariableInt();
112 
113  private:
114 
115  };
116 
117  class AGXFMI_EXPORT OutputVariableReal : public OutputVariable_Real, public PythonErrorSignal
118  {
119  public:
120  OutputVariableReal(const agx::Name& name);
121 
122  virtual double getValue();
123 
124  void setStartValue(double startValue);
125 
126  double getStartValue();
127 
128 #ifndef SWIG
129  virtual fmi2Status get(fmi2Real& value) override;
130 #endif
131 
132  protected:
133  virtual ~OutputVariableReal();
134 
135  private:
136 
137  };
138 
139  class AGXFMI_EXPORT OutputVariableString : public OutputVariable_String, public PythonErrorSignal
140  {
141  public:
142 
143  OutputVariableString(const agx::Name& name);
144 
145  virtual std::string getValue();
146 
147  void setStartValue(std::string startValue)
148  {
149  OutputVariableT::setStartValue(startValue.c_str());
150  }
151 
152  std::string getStartValue();
153 
154 #ifndef SWIG
155  virtual fmi2Status get(fmi2String& value) override;
156 #endif
157 
158  protected:
159  virtual ~OutputVariableString();
160 
161  private:
162 
163  };
164 
166 
167  class AGXFMI_EXPORT InputVariableBool : public InputVariable_Bool, public PythonErrorSignal
168  {
169  public:
170  InputVariableBool(const agx::Name& name);
171 
172  void setStartValue(bool startValue);
173 
174  bool getStartValue() const;
175 
176  virtual bool setValue(bool value);
177 
178  virtual bool getValue();
179 
180 #ifndef SWIG
181  fmi2Status get(fmi2Boolean& value) override;
182  fmi2Status set(fmi2Boolean value) override;
183 #endif
184 
185  protected:
186  virtual ~InputVariableBool();
187 
188  fmi2Boolean& getCurrentValue();
189 
190  private:
191 
192  };
194 
195  class AGXFMI_EXPORT InputVariableInt : public InputVariable_Int, public PythonErrorSignal
196  {
197  public:
198  InputVariableInt(const agx::Name& name);
199 
200  void setStartValue(int startValue);
201 
202  int getStartValue() const;
203 
204  virtual bool setValue(int value);
205 
206  virtual int getValue();
207 
208 #ifndef SWIG
209  fmi2Status get(fmi2Integer& value) override;
210  fmi2Status set(fmi2Integer value) override;
211 #endif
212 
213  protected:
214  virtual ~InputVariableInt();
215 
216  fmi2Integer& getCurrentValue();
217 
218  private:
219 
220  };
221 
222  class AGXFMI_EXPORT InputVariableReal : public InputVariable_Real, public PythonErrorSignal
223  {
224  public:
225  InputVariableReal(const agx::Name& name);
226 
227  void setStartValue(double startValue);
228 
229  double getStartValue() const;
230 
231  virtual bool setValue(double value);
232 
233  virtual double getValue();
234 
235 #ifndef SWIG
236  fmi2Status get(fmi2Real& value) override;
237  fmi2Status set(fmi2Real value) override;
238 #endif
239 
240  protected:
241  virtual ~InputVariableReal();
242 
243  fmi2Real& getCurrentValue();
244 
245  private:
246 
247  };
248 
249  class AGXFMI_EXPORT InputVariableString : public InputVariable_String, public PythonErrorSignal
250  {
251  public:
252  InputVariableString(const agx::Name& name);
253 
254  void setStartValue(std::string startValue);
255 
256  std::string getStartValue() const;
257 
258  virtual bool setValue(const std::string& value);
259 
260  virtual std::string getValue();
261 
262 #ifndef SWIG
263  fmi2Status get(fmi2String& value) override;
264  fmi2Status set(fmi2String value) override;
265 #endif
266 
267  protected:
268  virtual ~InputVariableString();
269 
270  std::string m_value;
271 
272  private:
273 
274  };
275 
276  }
277 }
278 
279 
280 #endif // AGX_USE_FMI()
281 
282 #endif // AGXFMI_PYTHONVARIABLE_H
#define AGXFMI_EXPORT
Representation of a name string.
Definition: Name.h:32
This namespace contains functionality for using AGX together with version 2 of the Functional Mockup ...