plugins: python renderer: Add GdsPoint object type definition to gds_render module. This is still playing around as I don't really know what I'm doing at the moment.

This commit is contained in:
Mario Hüttel 2019-11-18 20:27:46 +01:00
parent dd2f21c5cd
commit 2420b80c9e
2 changed files with 69 additions and 6 deletions

View File

@ -33,6 +33,11 @@
#include <Python.h> #include <Python.h>
/**
* @brief The gds_render python module name as string
*/
#define GDS_RENDER_MOD_NAME "gds_render"
/** /**
* @brief Set up the gds_render python module * @brief Set up the gds_render python module
* @return New module reference * @return New module reference

View File

@ -24,6 +24,22 @@
*/ */
#include <python-renderer/gds-render-module.h> #include <python-renderer/gds-render-module.h>
#include <gds-render/gds-utils/gds-types.h>
typedef struct {
PyObject_HEAD
/* TODO: Fill in type specific fields */
} GdsPointObject;
static PyTypeObject GdsPointType = {
PyVarObject_HEAD_INIT(NULL, 0)
.tp_name = GDS_RENDER_MOD_NAME ".GdsPoint",
.tp_doc = "2D Gds Database Point",
.tp_basicsize = sizeof(GdsPointObject),
.tp_itemsize = 0,
.tp_flags = Py_TPFLAGS_DEFAULT,
.tp_new = PyType_GenericNew,
};
static PyObject *test(PyObject *self, PyObject *args) static PyObject *test(PyObject *self, PyObject *args)
{ {
@ -32,7 +48,7 @@ static PyObject *test(PyObject *self, PyObject *args)
if(!PyArg_ParseTuple(args, "l:get_number", &i)) if(!PyArg_ParseTuple(args, "l:get_number", &i))
return NULL; return NULL;
i *= 2; i *= i;
return PyLong_FromLong(i); return PyLong_FromLong(i);
} }
@ -42,15 +58,57 @@ static PyMethodDef gds_render_methods[] = {
{NULL, NULL, 0, NULL} {NULL, NULL, 0, NULL}
}; };
static PyModuleDef gds_render_module = { static PyModuleDef gds_render_module_def = {
PyModuleDef_HEAD_INIT, "gds_render", NULL, -1, gds_render_methods, PyModuleDef_HEAD_INIT,
.m_name = GDS_RENDER_MOD_NAME,
.m_doc = "GDS Render Base App Module",
.m_size = -1,
.m_methods = gds_render_methods,
NULL, NULL, NULL, NULL NULL, NULL, NULL, NULL
}; };
static int gds_render_module_check_types_ready()
{
if (PyType_Ready(&GdsPointType) < 0)
return -1;
return 0;
}
static int gds_render_module_add_types(PyObject *module)
{
int err;
Py_INCREF(&GdsPointType);
err = PyModule_AddObject(module, "GdsPoint", (PyObject *)&GdsPointType);
if (err < 0) {
goto decref_gds_point;
}
return 0;
decref_gds_point:
Py_DECREF(&GdsPointType);
return -1;
}
PyObject *init_gds_render_module(void) PyObject *init_gds_render_module(void)
{ {
PyObject *this_module; int err;
PyObject *gds_render_module;
this_module = PyModule_Create(&gds_render_module); if (gds_render_module_check_types_ready())
return this_module; return NULL;
gds_render_module = PyModule_Create(&gds_render_module_def);
err = gds_render_module_add_types(gds_render_module);
if (err) {
Py_DECREF(gds_render_module);
gds_render_module = NULL;
goto return_module;
}
return_module:
return gds_render_module;
} }