14 auto numberOfArguments = PyTuple_Size(_args);
15 const int expectedNumberOfArguments = 2;
16 if (numberOfArguments != expectedNumberOfArguments) {
17 throw std::exception(
"OT_GetPropertyValue expects two arguments");
28 auto numberOfArguments = PyTuple_Size(_args);
29 const int expectedNumberOfArguments = 1;
30 if (numberOfArguments != expectedNumberOfArguments) {
31 throw std::exception(
"OT_GetScript expects one argument");
38 ot::EntityInformation entityInfo(baseEntity.get());
42 if (!moduleName.has_value()) {
43 EntityFile* script =
dynamic_cast<EntityFile*
>(baseEntity.get());
44 if (script ==
nullptr) {
45 throw std::exception(
"Requested script execution cannot be done, since the entity is not a python script.");
51 auto plainData = script->getData()->getData();
52 std::string execution(plainData.begin(), plainData.end());
54 moduleImported = PyImport_ImportModule(moduleName.value().c_str());
57 CPythonObjectNew result(PyRun_String(execution.c_str(), Py_file_input, globalDictionary, globalDictionary));
64 moduleImported = PyImport_ImportModule(moduleName.value().c_str());
68 return PyObject_GetAttrString(moduleImported, entryPoint.c_str());
72 auto numberOfArguments = PyTuple_Size(_args);
73 const int expectedNumberOfArguments = 3;
74 if (numberOfArguments != expectedNumberOfArguments) {
75 throw std::exception(
"OT_SetPropertyValue expects three arguments");
84 return PyBool_FromLong(
true);
88 if (_args !=
nullptr) {
89 throw std::exception(
"OT_Flush expects zero arguments");
94 return PyBool_FromLong(
true);
98 auto numberOfArguments = PyTuple_Size(_args);
99 const int expectedNumberOfArguments = 1;
100 if (numberOfArguments != expectedNumberOfArguments) {
101 throw std::exception(
"OT_FlushEntity expects one argument");
105 return pyObBuilder.
setBool(
true);
109 auto numberOfArguments = PyTuple_Size(_args);
110 const int expectedNumberOfArguments = 3;
111 if (numberOfArguments != expectedNumberOfArguments) {
112 throw std::exception(
"OT_GetTableCell expects three arguments");
119 if (row < 0 || column < 0)
121 throw std::exception(
"OT_GetTableCell requires positive indices");
129 auto numberOfArguments = PyTuple_Size(_args);
130 const int expectedNumberOfArguments = 1;
131 if (numberOfArguments != expectedNumberOfArguments) {
132 throw std::exception(
"OT_GetPortData expects one arguments");
141 auto numberOfArguments = PyTuple_Size(_args);
142 const int expectedNumberOfArguments = 2;
143 if (numberOfArguments != expectedNumberOfArguments) {
144 throw std::exception(
"OT_GetPortData expects two argument");
151 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:11
std::shared_ptr< EntityBase > getEntity(const std::string &_absoluteEntityName)
Definition EntityBuffer.cpp:97
PyObject * getEntityPropertyValue(const std::string &_absoluteEntityName, const std::string &_propertyName)
Definition EntityBuffer.cpp:16
void saveChangedEntities()
Definition EntityBuffer.cpp:55
PyObject * getTableCellValue(const std::string &_absoluteEntityName, uint32_t _row, uint32_t _column)
Definition EntityBuffer.cpp:23
void updateEntityPropertyValue(const std::string &_absoluteEntityName, const std::string &_propertyName, const CPythonObject &_values)
Definition EntityBuffer.cpp:48
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:220
std::string getStringValueFromTuple(const CPythonObject &pValue, int position, const std::string &varName)
Definition PythonObjectBuilder.cpp:240
CPythonObjectBorrowed getTupleItem(const CPythonObject &pValue, int position, const std::string &varName)
Definition PythonObjectBuilder.cpp:210
CPythonObjectNew setBool(const bool value)
Definition PythonObjectBuilder.cpp:527
ot::GenericDataStructList getGenericDataStructList(CPythonObject &pValue)
Definition PythonObjectBuilder.cpp:346
static PyObject * OT_GetTableCell(PyObject *_self, PyObject *_args)
Definition PythonExtension.hpp:108
static PyObject * OT_GetPropertyValue(PyObject *_self, PyObject *_args)
Definition PythonExtension.hpp:13
static PyObject * OT_Flush(PyObject *_self, PyObject *_args)
Definition PythonExtension.hpp:87
static PyObject * OT_GetPortData(PyObject *_self, PyObject *_args)
Definition PythonExtension.hpp:128
static PyObject * OT_SetPropertyValue(PyObject *_self, PyObject *_args)
Definition PythonExtension.hpp:71
static PyObject * OT_GetScript(PyObject *_self, PyObject *_args)
Definition PythonExtension.hpp:27
static PyObject * OT_FlushEntity(PyObject *_self, PyObject *_args)
Definition PythonExtension.hpp:97
static PyObject * OT_SetPortData(PyObject *_self, PyObject *_args)
Definition PythonExtension.hpp:140