17 #ifndef AGXPYTHON_SCRIPTMANAGER_H
18 #define AGXPYTHON_SCRIPTMANAGER_H
35 #if AGX_USE_WEBSOCKETS()
45 # pragma warning( push )
46 # pragma warning( disable: 4512 ) // Disable warning about assignment operator could not be generated due to reference members.
47 # pragma warning( disable: 4275 ) // Disable non dll-interface class std::exception used as base for dll-interface class agxPython::ScriptError
57 #if AGX_USE_WEBSOCKETS()
60 class SimulationController;
92 ScriptError(std::string scriptError, std::string scriptFile);
105 #if AGX_USE_WEBSOCKETS()
163 class ReactiveScript;
175 friend class ReactiveInitializer;
182 static bool hasInstance();
188 static ScriptManager* instance(
const std::string& requestor =
"",
const std::string& pythonPaths=
"",
const std::string& pythonHome=
"",
bool ignoreEnvironment =
false);
197 void registerError(
const std::string& prefix =
"");
207 void reportError(
const std::string& errorReport)
const;
231 bool unregisterReactiveScript(
const agx::Uuid& uuid);
232 bool isRegisteredReactiveScript(
const agx::Uuid& uuid)
const;
233 void clearReactiveScripts();
234 void acquireReactiveScriptContext(
const agx::Uuid& scriptId,
const char* func);
235 void releaseReactiveScriptContext(
const agx::Uuid& scriptId,
bool unlock =
true);
238 #if AGX_USE_WEBSOCKETS()
241 void updateReactiveScripts();
243 void onStartPlaybackReactiveScripts(
agx::Real value);
244 void onStartRecordingReactiveScripts(
agx::Real value);
245 void onStopPlaybackReactiveScripts(
agx::Real value);
246 void onStopRecordingReactiveScripts(
agx::Real value);
253 std::string getLastErrorMessage()
const;
259 int getLastErrorLine()
const;
265 bool receivedErrorMessage()
const;
275 void setLastErrorMessage(
const std::string& errorMessage);
276 void setLastErrorLine(
int line);
293 #if AGX_USE_WEBSOCKETS()
299 void destroyMainModule(
const agx::Uuid& scriptId);
301 #if !defined(SWIGJAVA)
303 void enableEmbeddedMode(
const std::string& programName);
306 void init(
const std::string& pythonPaths=
"");
320 void createMainModule(
const agx::Uuid& scriptId);
323 void swapMainModule(
const agx::Uuid& scriptId);
326 void restoreGlobalMainModule(
bool unlock =
true);
328 bool hasMainModule(
const agx::Uuid& uuid)
const;
330 void* getMainModule();
337 bool hasReactiveScriptErrors(
bool printWarnings =
true );
344 bool doFile(
const std::string& path);
351 bool doString(
const std::string& code,
const std::string& origin);
360 bool doCompiledScript(
void* compiled);
361 void* doCompiledFunction(
void* funcObject,
void **args,
int numArgs);
369 bool doFunction(
const std::string&
function,
void* args =
nullptr);
375 #if AGX_USE_WEBSOCKETS()
385 bool hasFunction(
const std::string&
function);
387 bool getTreatInvalidAsErrors()
const;
388 void setTreatInvalidAsErrors(
const bool treatInvalidAsErrors);
413 std::string getProgramName();
420 PythonDefMap dumpGlobals(
void* globals, std::ostream* logStream =
nullptr);
427 static void startProfiling(
void* obj,
const char* decl);
429 static void endProfiling(
void* obj,
const char* decl);
431 static void abortProfiling(
void* obj,
const char* decl);
436 SINGLETON_CLASSNAME_METHOD();
442 ScriptManager(
const std::string& program,
const std::string& pythonPaths,
const std::string& pythonHome,
bool ignoreEnvironment);
446 std::map<agx::Uuid, agx::ref_ptr<ReactiveScript> > m_reactiveScripts;
447 std::map<agx::Uuid, void*> m_reactiveScriptMainModules;
449 void* m_globalMainModule;
450 void* m_currentMainModule;
457 std::string m_programName;
458 std::set<std::string> m_pythonPath;
459 wchar_t* m_pythonHome;
460 bool m_shutdownInProgress;
461 bool m_treatInvalidAsErrors;
462 std::string m_lastErrorMessage;
464 std::string m_scriptPath;
465 bool m_ignoreEnvironment;
470 #if AGX_USE_WEBSOCKETS()
487 const char*
const MOMENTUM_PROGRAM_NAME =
"AlgoryxMomentum";
502 #define g_pythonScriptManager agxPython::ScriptManager::instance("")
503 #define g_pythonScriptManagerForProgram(PROGRAM) agxPython::ScriptManager::instance(PROGRAM)
504 #define AGXPYTHON_REPORT_ERROR(errorMessage) \
505 if (g_pythonScriptManager->getTreatInvalidAsErrors() || agxUnit::isUnittestingEnabled()) \
507 LOGGER_ERROR() << (errorMessage) << std::endl << LOGGER_END(); \
511 LOGGER_WARNING() << (errorMessage) << std::endl << LOGGER_END(); \
518 # pragma warning(pop)
void AGXPHYSICS_EXPORT init()
Initialize agx.
virtual ~StopPlaybackSignalCallback()
void AGXPHYSICS_EXPORT shutdown()
Shutdown agx.
StopPlaybackSignalCallback()
virtual ~StartPlaybackSignalCallback()
Class that manages the embedded Python interpreter and a script context.
StartPlaybackSignalCallback()
AGXPYTHON_EXPORT ScriptContext * getContext()
AGXLUA_EXPORT int doString(lua_State *L)
AGXPYTHON_EXPORT bool scriptIsAttached()
#define AGX_DECLARE_POINTER_TYPES(type)
Representation of a name string.
Internal class which interfaces to a ScriptContext in an abstract and safe manner.
std::map< std::string, std::string > PythonDefMap
The ReactiveScript class is derived from the agxSDK::StepEventListener class and require an agxSDK::S...
Exception base class for all fatal runtime errors caused by Python scripts.
virtual ~StopRecordingSignalCallback()
StopRecordingSignalCallback()
Smart pointer for handling referenced counted objects.
StartRecordingSignalCallback()
Class which manages a runtime bridge between a script and the Python ScriptManager.
AGXPYTHON_EXPORT bool doFile(const std::string &path)
A UUID, or Universally unique identifier, is intended to uniquely identify information in a distribut...
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
virtual ~StartRecordingSignalCallback()
Base class for Singletons that should have its shutdown called explicitly before exit of the applicat...