12 auto numberOfArguments = PyTuple_Size(_args);
13 const int expectedNumberOfArguments = 2;
14 if (numberOfArguments != expectedNumberOfArguments) {
15 throw std::exception(
"OT_GetPropertyValue expects two arguments");
26 auto numberOfArguments = PyTuple_Size(_args);
27 const int expectedNumberOfArguments = 1;
28 if (numberOfArguments != expectedNumberOfArguments) {
29 throw std::exception(
"OT_GetScript expects one argument");
40 if (!moduleName.has_value()) {
41 EntityFile* script =
dynamic_cast<EntityFile*
>(baseEntity.get());
42 if (script ==
nullptr) {
43 throw std::exception(
"Requested script execution cannot be done, since the entity is not a python script.");
49 auto plainData = script->getData()->getData();
50 std::string execution(plainData.begin(), plainData.end());
52 moduleImported = PyImport_ImportModule(moduleName.value().c_str());
55 CPythonObjectNew result(PyRun_String(execution.c_str(), Py_file_input, globalDictionary, globalDictionary));
62 moduleImported = PyImport_ImportModule(moduleName.value().c_str());
66 return PyObject_GetAttrString(moduleImported, entryPoint.c_str());
70 auto numberOfArguments = PyTuple_Size(_args);
71 const int expectedNumberOfArguments = 3;
72 if (numberOfArguments != expectedNumberOfArguments) {
73 throw std::exception(
"OT_SetPropertyValue expects three arguments");
82 return PyBool_FromLong(
true);
86 if (_args !=
nullptr) {
87 throw std::exception(
"OT_Flush expects zero arguments");
92 return PyBool_FromLong(
true);
96 auto numberOfArguments = PyTuple_Size(_args);
97 const int expectedNumberOfArguments = 1;
98 if (numberOfArguments != expectedNumberOfArguments) {
99 throw std::exception(
"OT_FlushEntity expects one argument");
103 return pyObBuilder.
setBool(
true);
107 auto numberOfArguments = PyTuple_Size(_args);
108 const int expectedNumberOfArguments = 3;
109 if (numberOfArguments != expectedNumberOfArguments) {
110 throw std::exception(
"OT_GetTableCell expects three arguments");
117 if (row < 0 || column < 0)
119 throw std::exception(
"OT_GetTableCell requires positive indices");
127 auto numberOfArguments = PyTuple_Size(_args);
128 const int expectedNumberOfArguments = 1;
129 if (numberOfArguments != expectedNumberOfArguments) {
130 throw std::exception(
"OT_GetPortData expects one arguments");
139 auto numberOfArguments = PyTuple_Size(_args);
140 const int expectedNumberOfArguments = 2;
141 if (numberOfArguments != expectedNumberOfArguments) {
142 throw std::exception(
"OT_GetPortData expects two argument");
149 return PyBool_FromLong(
true);
Meyer' singleton that buffers all entities and their properties that were used so far.
Entity that holds a binary representation of a file. Any type of file should be supported.
Embedded python functions don't throw exceptions. If the return value holds an error code that says t...
C Python Extension that hold functions for OpenTwin that can be called from a python script.
Meyer's singleton that holds a map of all modules that were loaded in the python interpreter,...
Builder to transfer typically used PyObjects to c++ types and vice versa.
int result
Definition dllmain.cpp:82
Definition CPythonObjectBorrowed.h:15
Definition CPythonObjectNew.h:14
static EntityBuffer & instance()
Definition EntityBuffer.cpp:10
std::shared_ptr< EntityBase > getEntity(const std::string &_absoluteEntityName)
Definition EntityBuffer.cpp:101
PyObject * getEntityPropertyValue(const std::string &_absoluteEntityName, const std::string &_propertyName)
Definition EntityBuffer.cpp:20
void saveChangedEntities()
Definition EntityBuffer.cpp:59
PyObject * getTableCellValue(const std::string &_absoluteEntityName, uint32_t _row, uint32_t _column)
Definition EntityBuffer.cpp:27
void updateEntityPropertyValue(const std::string &_absoluteEntityName, const std::string &_propertyName, const CPythonObject &_values)
Definition EntityBuffer.cpp:52
static PortDataBuffer & instance(void)
Definition PortDataBuffer.cpp:5
PyObject * getPortData(const std::string &_portName)
Definition PortDataBuffer.cpp:32
void overridePortData(const std::string &_portName, const ot::GenericDataStructList &_data)
Definition PortDataBuffer.cpp:16
Definition PythonException.h:15
std::optional< std::string > getModuleName(const ot::EntityInformation &_scriptEntityInfos)
Definition PythonLoadedModules.cpp:8
std::string addModuleForEntity(const ot::EntityInformation &_scriptEntityInfo)
Definition PythonLoadedModules.cpp:24
static PythonLoadedModules & instance(void)
Definition PythonLoadedModules.cpp:3
std::string getModuleEntryPoint(const std::string &_moduleName) const
Definition PythonModuleAPI.cpp:10
static const PythonModuleAPI & instance(void)
Definition PythonModuleAPI.cpp:5
PyObjects don't distingiush between float and double and int32 and int64. All floating point values a...
Definition PythonObjectBuilder.h:28
int32_t getInt32ValueFromTuple(const CPythonObject &pValue, int position, const std::string &varName)
Definition PythonObjectBuilder.cpp:219
std::string getStringValueFromTuple(const CPythonObject &pValue, int position, const std::string &varName)
Definition PythonObjectBuilder.cpp:239
CPythonObjectBorrowed getTupleItem(const CPythonObject &pValue, int position, const std::string &varName)
Definition PythonObjectBuilder.cpp:209
CPythonObjectNew setBool(const bool value)
Definition PythonObjectBuilder.cpp:526
ot::GenericDataStructList getGenericDataStructList(CPythonObject &pValue)
Definition PythonObjectBuilder.cpp:345
static PyObject * OT_GetTableCell(PyObject *_self, PyObject *_args)
Definition PythonExtension.hpp:106
static PyObject * OT_GetPropertyValue(PyObject *_self, PyObject *_args)
Definition PythonExtension.hpp:11
static PyObject * OT_Flush(PyObject *_self, PyObject *_args)
Definition PythonExtension.hpp:85
static PyObject * OT_GetPortData(PyObject *_self, PyObject *_args)
Definition PythonExtension.hpp:126
static PyObject * OT_SetPropertyValue(PyObject *_self, PyObject *_args)
Definition PythonExtension.hpp:69
static PyObject * OT_GetScript(PyObject *_self, PyObject *_args)
Definition PythonExtension.hpp:25
static PyObject * OT_FlushEntity(PyObject *_self, PyObject *_args)
Definition PythonExtension.hpp:95
static PyObject * OT_SetPortData(PyObject *_self, PyObject *_args)
Definition PythonExtension.hpp:138