AGX Dynamics  2.37.3.2
export/Variable.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 AGXFMI2_EXPORT_VARIABLE_H
18 #define AGXFMI2_EXPORT_VARIABLE_H
19 
20 #include <agx/config/AGX_USE_FMI.h>
21 
22 #if AGX_USE_FMI()
23 
24 #include <agxFMI2/Variable.h>
25 #include <agx/Callback.h>
26 #include <agxData/Value.h>
27 #include <agx/Xml.h>
28 
29 #include <agx/PushDisableWarnings.h> // Disabling warnings. Include agx/PopDisableWarnings.h below!
30 extern "C"
31 {
32  #include <FMI2/fmi2Functions.h>
33 }
34 #include <agx/PopDisableWarnings.h> // End of disabled warnings.
35 
36 namespace agxSDK
37 {
38  class Simulation;
39 }
40 
41 
42 namespace agxFMI2
43 {
44  namespace Export
45  {
46  class Module;
47 
48  AGX_DECLARE_POINTER_TYPES(Variable);
49  AGX_DECLARE_VECTOR_TYPES(Variable);
50  AGX_DECLARE_POINTER_TYPES(InputVariable);
51  AGX_DECLARE_POINTER_TYPES(OutputVariable);
52 
53 
55 
59  class AGXFMI_EXPORT Variable : public agxFMI2::Variable
60  {
61  public:
62 
63 #ifndef SWIG
64  template <typename T>
65  struct TypMap;
66 #endif
67 
68  typedef fmi2Status StatusT;
69 
70  public:
71  Variable(const agx::Name& name = agx::Name());
72 
74  void setStartValue(agxData::Value *startValue);
75 
77  const agxData::Value *getStartValue() const;
78 
80  Module *getModule();
81 
83  agxSDK::Simulation *getSimulation();
84 
86  agx::TiXmlElement *exportDescription();
87 
88  protected:
89  virtual ~Variable();
90 
91  private:
92  friend class Module;
93  void setModule(Module *module);
94 
95  private:
96  Module *m_module;
97  agxData::ValueRef m_startValue;
98  };
99 
100 
102 
106  template <typename T>
107  class AGXFMI_EXPORT OutputVariableT : public Variable
108  {
109  public:
110 
111 #ifndef SWIG
112  using CallbackType = agx::Callback1<T&>;
113  using CallbackFn = void (*)(T&);
114  using Type = T;
115 #endif
116 
117  public:
118  OutputVariableT(const agx::Name& name = agx::Name());
119 
120 #ifndef SWIG
121  OutputVariableT(CallbackType callback);
122 #endif
123 
125  virtual fmi2Status get(T& value);
126 
128  void setStartValue(T startValue);
129 
131  T getStartValue() const;
132 
133 #ifndef SWIG
134  template <typename T2>
135  void setCallback(T2 callback)
136  {
137  m_callback = CallbackType(callback);
138  }
139 #endif
140 
141  protected:
142  virtual ~OutputVariableT();
143 
144  private:
145  CallbackType m_callback;
146  };
147 
148  typedef OutputVariableT<fmi2Real> OutputVariable_Real;
149  typedef OutputVariableT<fmi2Integer> OutputVariable_Int;
150  typedef OutputVariableT<fmi2Boolean> OutputVariable_Bool;
151  typedef OutputVariableT<fmi2String> OutputVariable_String;
152 
154 
158  template <typename T>
159  class AGXFMI_EXPORT InputVariableT : public OutputVariableT<T>
160  {
161  public:
162 
163 #ifndef SWIG
164  typedef agx::Callback1<T> CallbackType;
165  typedef void (*CallbackFn)(T);
166 #endif
167 
168  public:
169  InputVariableT(const agx::Name& name = agx::Name());
170 
171 #ifndef SWIG
172  InputVariableT(CallbackType callback);
173 #endif
174 
176  virtual fmi2Status set(T value);
177 
179  virtual fmi2Status get(T& value);
180 
181 #ifndef SWIG
182  //T get() const;
184 
185  template <typename T2>
186  void setCallback(T2 callback)
187  {
188  m_callback = CallbackType(callback);
189  }
190 #endif
191 
192  protected:
193  virtual ~InputVariableT();
194 
195  protected:
196  CallbackType m_callback;
197  T m_currentValue;
198  };
199 
200  typedef InputVariableT<fmi2Real> InputVariable_Real;
201  typedef InputVariableT<fmi2Integer> InputVariable_Int;
202  typedef InputVariableT<fmi2Boolean> InputVariable_Bool;
203  typedef InputVariableT<fmi2String> InputVariable_String;
204 
205 
207 
208  /* Implemenation */
209 
210  // template <> struct Variable::TypMap<TYPE_REAL> { typedef agx::Real Type; };
211  // template <> struct Variable::TypMap<TYPE_INT> { typedef agx::Int32 Type; };
212  // template <> struct Variable::TypMap<TYPE_BOOL> { typedef agx::Bool Type; };
213  // template <> struct Variable::TypMap<TYPE_STRING> { typedef agx::String Type; };
214 
215 #ifndef SWIG
216  template <> struct Variable::TypMap<fmi2Real> { static const Type type = TYPE_REAL; };
217  template <> struct Variable::TypMap<fmi2Integer> { static const Type type = TYPE_INT; };
218  // template <> struct Variable::TypMap<fmi2Boolean> { static const Type type = TYPE_BOOL; };
219  template <> struct Variable::TypMap<fmi2String> { static const Type type = TYPE_STRING; };
220 #endif
221 
222 
223  }
224 
225 
226 }
227 
228 #endif /* AGX_USE_FMI */
229 
230 #endif /* AGXFMI2_EXPORT_VARIABLE_H */
Abstract representation of a value.
Definition: Value.h:48
#define AGXFMI_EXPORT
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
Representation of a name string.
Definition: Name.h:32
Templated callback with one argument.
Definition: Callback.h:100
This namespace contains functionality for using AGX together with version 2 of the Functional Mockup ...
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:126
#define AGX_DECLARE_VECTOR_TYPES(type)
Definition: Vector.h:34
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition: Constraint.h:30