AGX Dynamics 2.38.0.2
Loading...
Searching...
No Matches
ScriptContext.h
Go to the documentation of this file.
1/*
2Copyright 2007-2024. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx Simulation AB.
15*/
16
17#ifndef AGXPYTHON_SCRIPTCONTEXT_H
18#define AGXPYTHON_SCRIPTCONTEXT_H
19
20
21#include <agx/config/AGX_USE_PYTHON.h>
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
30namespace agxSDK
31{
32 AGX_DECLARE_POINTER_TYPES(Simulation);
33}
34
35namespace agxOSG
36{
37 class Group;
38 class ExampleApplication;
39 class SceneDecorator;
40}
41
42#include <agxPython/export.h>
43
44#include <agx/Timer.h>
46
47#include <map>
48#include <functional>
49
50namespace osg
51{
52 class Group;
53}
54
55
56namespace agxFMI2
57{
58 namespace Export
59 {
60 class Module;
61 }
62}
63
64namespace agxPython
65{
66
67 class ScriptContext;
68 class ScriptContextInterface;
69
70 AGX_DECLARE_POINTER_TYPES(ScriptSimulationParameter);
71
78 class AGXPYTHON_EXPORT ScriptContext_environment : public agx::Referenced
79 {
80 public:
81
82 friend class ScriptContext;
83 friend class ScriptContextInterface;
84
85 agxSDK::Simulation* getSimulation();
86 osg::Group* getSceneRoot();
87 agxOSG::ExampleApplication* getApplication();
88 agxOSG::SceneDecorator* getSceneDecorator();
89
90 agx::String getName();
91
92#if AGX_USE_FMI()
93 agxFMI2::Export::Module* getFMI2Module();
94 int getFMIVersion();
95#endif
96
97 protected:
98
99 ScriptContext_environment();
100 ~ScriptContext_environment();
101
102 private:
103 agxSDK::Simulation *m_simulation;
104 osg::Group *m_group;
105 agxOSG::ExampleApplication *m_exampleApplication;
106 agx::String m_name;
107#if AGX_USE_FMI()
108 int m_fmiVersion;
109 void *m_fmiModule;
110#endif
111 agxOSG::SceneDecorator *m_sceneDecorator;
112
113 };
114
115
116
117
122 class AGXPYTHON_EXPORT ScriptContext : public agx::Referenced
123 {
124
125 public:
126
127 friend class ScriptManager;
128 friend class ScriptContextInterface;
129
130 agxPython::ScriptContextInterface *getInterface();
131
132 void setInterface(agxPython::ScriptContextInterface *i);
133
134 ScriptContext_environment* environment; // See m_environment
135 protected:
136
137 ScriptContext(int contextType);
138 virtual ~ScriptContext();
139
140 void setEnvironment(ScriptContext_environment *e);
141
142 private:
143 static bool verify_apply_destroy(ScriptContext *scriptContext, agxPython::ScriptContextInterface *scriptContextInterface);
144
145 int m_contextType;
146
148
149 /*
150 We have both environment and m_environment holding the same value.
151 m_environment is needed to hold the reference and environment likely
152 existed first (and clearly was not enough).
153 The public variable is used in python boiler plate code in tutorials
154 and other snippets:
155
156 agxPython.getContext().environment.getSimulation()
157
158 */
160 };
161
167 class AGXPYTHON_EXPORT ScriptContextInterface : public agx::Referenced
168 {
169
170 public:
171
172 friend class ScriptManager;
173 friend class ScriptContext;
174
175 ScriptContextInterface() =delete;
176
177 void setSimulation(agxSDK::Simulation* simulation) const;
178 void setApplication(agxOSG::ExampleApplication* application) const;
179 void setSceneRoot(osg::Group* group) const;
180 osg::Group* getSceneRoot() const;
181 void setSceneDecorator(agxOSG::SceneDecorator* decorator) const;
182 void setName(const agx::String& name) const;
183
184#if AGX_USE_FMI()
185 void setFMI2Module(agxFMI2::Export::Module *module) const;
186#endif
187
188 int getType() const;
189
193 bool verifyAndApply();
194
195 agxPython::ScriptContext* getContext();
196 protected:
197
198 ScriptContextInterface(ScriptContext *scriptContext);
199 virtual ~ScriptContextInterface();
200
201 private:
202
203 agx::observer_ptr<ScriptContext> m_scriptContext;
204
205 };
206
207}
208
209#endif
210
211#endif
#define AGX_DECLARE_POINTER_TYPES(type)
Definition Referenced.h:254
#define AGXPYTHON_EXPORT
Class that encapsulates rendering and simulation using OpenSceneGraph.
Decorates a scene with a specific AGX Rendering Style.
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition Simulation.h:126
Base class providing referencing counted objects.
Definition Referenced.h:120
Smart pointer for observed objects, that automatically set pointers to them to null when they deleted...
Smart pointer for handling referenced counted objects.
Definition ref_ptr.h:30
AGXCORE_EXPORT Type * getType(const agx::String &name)
This namespace contains functionality for using AGX together with version 2 of the Functional Mockup ...
The agxOSG namespace provides functionality for visualizing AGX simulations with OpenSceneGraph.
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition Constraint.h:31