AGXDynamics  2.31.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
export/Variable.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2021. 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 <external/fmi/2.0/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 
50  AGX_DECLARE_POINTER_TYPES(InputVariable);
51  AGX_DECLARE_POINTER_TYPES(OutputVariable);
52 
53 
55 
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>
108  {
109  public:
110 
111 #ifndef SWIG
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 
152 
154 
158  template <typename T>
160  {
161  public:
162 
163 #ifndef SWIG
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:
198  };
199 
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:42
FMI export module.
Definition: export/Module.h:74
AGX_DECLARE_VECTOR_TYPES(Variable)
agx::Callback1< T > CallbackType
#define AGXFMI_EXPORT
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:248
void setCallback(T2 callback)
Convenience method for getting the current value.
Representation of a name string.
Definition: Name.h:32
OutputVariableT< fmi2Real > OutputVariable_Real
InputVariableT< fmi2Integer > InputVariable_Int
OutputVariableT< fmi2Integer > OutputVariable_Int
OutputVariableT< fmi2String > OutputVariable_String
InputVariableT< fmi2String > InputVariable_String
typedef void(GLAD_API_PTR *GLDEBUGPROC)(GLenum source
InputVariableT< fmi2Boolean > InputVariable_Bool
InputVariableT< fmi2Real > InputVariable_Real
FMI export variable wrapper.
FMI export input variable wrapper.
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:121
FMI variable wrapper.
Definition: Variable.h:35
OutputVariableT< fmi2Boolean > OutputVariable_Bool
FMI export output variable wrapper.
GLenum type
Definition: gl.h:5539