AGX Dynamics  2.37.2.0
ReactiveScript.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 #pragma once
18 #ifndef AGXPYTHON_REACTIVECRIPT_H
19 #define AGXPYTHON_REACTIVECRIPT_H 1
20 
21 #include <agx/config/AGX_USE_PYTHON.h>
22 
23 #if AGX_USE_PYTHON()
24 
25 #include <agxPython/export.h>
26 
27 #include <agx/Name.h>
28 #include <agx/Uuid.h>
32 #include <vector>
33 
34 namespace agxSDK
35 {
36  class Simulation;
37 }
38 
97 namespace agxPython
98 {
99 
100  //class ScriptConsole;
101  //class ScriptRuntimeListener;
119  class AGXPYTHON_EXPORT ReactiveScript : public agxSDK::StepEventListener
120  {
121 
122  public:
123 
124  friend class ScriptManager;
125 
126  ReactiveScript(const agx::Name& name);
127 
128  ~ReactiveScript();
129 
130  void setSource(const agx::String& source);
131 
132  bool setSourceFromFile(const agx::String& path);
133 
134  const agx::String& getSource() const;
135 
136  void setScriptConsole(ScriptConsole* scriptConsole);
137 
138  ScriptConsole* getScriptConsole();
139 
140  void setScriptRuntimeListener(ScriptRuntimeListener* scriptRuntimeListener);
141 
142  ScriptRuntimeListener* getScriptRuntimeListener();
143 
144  void resetError();
145 
146  const agx::String& getLastErrorMessage() const;
147 
148  long getLastErrorLine() const;
149 
150  bool errorOccurred() const;
151 
152  const agx::Name& getName() const;
153 
154  const agx::Uuid& getUuid() const;
155 
156  void setPriority(agx::UInt32 priority);
157 
158  bool isReadOnly();
159 
160  void setReadOnly(bool readOnly);
161 
162  virtual void post(const agx::TimeStamp& timeStamp) override;
163 
164  virtual void onStart(const agx::TimeStamp& timeStamp);
165 
166  virtual void onStop(const agx::TimeStamp& timeStamp);
167 
168  virtual void addNotification() override;
169 
170  virtual void removeNotification() override;
171 
172  void update();
173 
174 #ifndef SWIG
175  struct Runtime
176  {
177  Runtime();
178  ~Runtime();
181  void* compiled;
182  void* cbStep;
183  void* cbStart;
184  void* cbStop;
185  };
186 
187  enum Action
188  {
189  ActionSimulationRemove = 1,
190  ActionStateInitialize,
191  ActionStateClear,
192  };
193 #endif
194 
195  protected:
196 
197  void pushAction(Action action, void* param = nullptr);
198 
199  void setLastErrorMessage(const agx::String &lastErrorMessage);
200 
201  void setLastErrorLine(long lastErrorLine);
202 
203  private:
204 
205  std::vector<std::pair<Action, void*> > m_pendingActions;
206 
207  agx::Name m_name;
208 
209  agx::Uuid m_uuid;
210 
211  agx::String m_source;
212 
213  agx::String m_lastErrorMessage;
214 
215  long m_lastErrorLine;
216 
217  Runtime m_runtime;
218 
219  bool m_readOnly;
220 
221  };
222 
223 
224 }
225 
226 
227 
228 #endif
229 
230 
231 
232 #endif
Derive from this class to implement a listener for simulation step events.
Representation of a name string.
Definition: Name.h:32
agx::Real TimeStamp
Definition: TimeStamp.h:26
Smart pointer for handling referenced counted objects.
Definition: ref_ptr.h:29
A UUID, or Universally unique identifier, is intended to uniquely identify information in a distribut...
Definition: Uuid.h:41
#define AGXPYTHON_EXPORT
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition: Constraint.h:30
uint32_t UInt32
Definition: Integer.h:40