AGXDynamics  2.31.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ScriptContext.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 AGXPYTHON_SCRIPTCONTEXT_H
18 #define AGXPYTHON_SCRIPTCONTEXT_H
19 
20 
22 #include <agx/config.h>
23 
24 #if AGX_USE_PYTHON()
25 
26 #include <agx/config/AGX_USE_FMI.h>
27 #include <agx/Referenced.h>
28 #include <agx/ref_ptr.h>
29 
30 namespace agxSDK
31 {
32  AGX_DECLARE_POINTER_TYPES(Simulation);
33 }
34 
35 namespace agxOSG
36 {
37  class Group;
38  class ExampleApplication;
39  class SceneDecorator;
40 }
41 
42 #include <agxPython/export.h>
43 
44 #include <agx/Timer.h>
45 #include <agx/agx_vector_types.h>
46 
47 #include <map>
48 #include <functional>
49 
50 namespace osg
51 {
52  class Group;
53 }
54 
55 namespace agxFMI
56 {
57  namespace Export
58  {
59  class Module;
60  }
61 }
62 
63 namespace agxFMI2
64 {
65  namespace Export
66  {
67  class Module;
68  }
69 }
70 
71 namespace agxPython
72 {
73 
74  class ScriptContext;
75  class ScriptContextInterface;
76 
78 
86  {
87  public:
88 
89  friend class ScriptContext;
90  friend class ScriptContextInterface;
91 
92  agxSDK::Simulation* getSimulation();
93  osg::Group* getSceneRoot();
94  agxOSG::ExampleApplication* getApplication();
95  agxOSG::SceneDecorator* getSceneDecorator();
96 
97  agx::String getName();
98 
99 #if AGX_USE_FMI()
100  agxFMI2::Export::Module* getFMI2Module();
101  int getFMIVersion();
102 #endif
103 
104  protected:
105 
108 
109  private:
110  agxSDK::Simulation *m_simulation;
111  osg::Group *m_group;
112  agxOSG::ExampleApplication *m_exampleApplication;
113  agx::String m_name;
114 #if AGX_USE_FMI()
115  int m_fmiVersion;
116  void *m_fmiModule;
117 #endif
118  agxOSG::SceneDecorator *m_sceneDecorator;
119 
120  };
121 
122 
123 
124 
130  {
131 
132  public:
133 
134  friend class ScriptManager;
136 
137  agxPython::ScriptContextInterface *getInterface();
138 
139  void setInterface(agxPython::ScriptContextInterface *i);
140 
141  ScriptContext_environment* environment; // See m_environment
142  protected:
143 
144  ScriptContext(int contextType);
145  virtual ~ScriptContext();
146 
147  void setEnvironment(ScriptContext_environment *e);
148 
149  private:
150  static bool verify_apply_destroy(ScriptContext *scriptContext, agxPython::ScriptContextInterface *scriptContextInterface);
151 
152  int m_contextType;
153 
155 
156  /*
157  We have both environment and m_environment holding the same value.
158  m_environment is needed to hold the reference and environment likely
159  existed first (and clearly was not enough).
160  The public variable is used in python boiler plate code in tutorials
161  and other snippets:
162 
163  agxPython.getContext().environment.getSimulation()
164 
165  */
167  };
168 
175  {
176 
177  public:
178 
179  friend class ScriptManager;
180  friend class ScriptContext;
181 
182  ScriptContextInterface() =delete;
183 
184  void setSimulation(agxSDK::Simulation* simulation) const;
185  void setApplication(agxOSG::ExampleApplication* application) const;
186  void setSceneRoot(osg::Group* group) const;
187  osg::Group* getSceneRoot() const;
188  void setSceneDecorator(agxOSG::SceneDecorator* decorator) const;
189  void setName(const agx::String& name) const;
190 
191 #if AGX_USE_FMI()
192  void setFMI2Module(agxFMI2::Export::Module *module) const;
193 #endif
194 
195  int getType() const;
196 
200  bool verifyAndApply();
201 
203  protected:
204 
205  ScriptContextInterface(ScriptContext *scriptContext);
206  virtual ~ScriptContextInterface();
207 
208  private:
209 
210  agx::observer_ptr<ScriptContext> m_scriptContext;
211 
212  };
213 
214 }
215 
216 #endif
217 
218 #endif
Class that encapsulates rendering and simulation using OpenSceneGraph.
AGXCORE_EXPORT Type * getType(const agx::String &name)
Class that manages the embedded Python interpreter and a script context.
Smart pointer for observed objects, that automatically set pointers to them to null when they deleted...
Definition: observer_ptr.h:60
FMI export module.
Definition: export/Module.h:74
AGXPYTHON_EXPORT ScriptContext * getContext()
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:248
Internal class which interfaces to a ScriptContext in an abstract and safe manner.
Decorates a scene with a specific AGX Rendering Style.
Base class providing referencing counted objects.
Definition: Referenced.h:113
Smart pointer for handling referenced counted objects.
Definition: ref_ptr.h:29
Class which manages a runtime bridge between a script and the Python ScriptManager.
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:121
ScriptContext_environment * environment
#define AGXPYTHON_EXPORT
Class describing the contextual environment in which a script is run.
Definition: ScriptContext.h:85