Files
gds-render/plugins/python-renderer/src/gds-render-module.c

115 lines
2.6 KiB
C

/*
* GDSII-Converter Python Plugin
* Copyright (C) 2019 Mario Hüttel <mario.huettel@gmx.net>
*
* This file is part of GDSII-Converter.
*
* GDSII-Converter is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* GDSII-Converter is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GDSII-Converter. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @file gds-render-module.c
* @brief Gds-render python module implementation
* @author Mario Hüttel <mario.huettel@gmx.net>
*/
#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)
{
long int i;
if(!PyArg_ParseTuple(args, "l:get_number", &i))
return NULL;
i *= i;
return PyLong_FromLong(i);
}
static PyMethodDef gds_render_methods[] = {
{"get_number", test, METH_VARARGS, "Return the number of arguments received by the process."},
{NULL, NULL, 0, NULL}
};
static PyModuleDef gds_render_module_def = {
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
};
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)
{
int err;
PyObject *gds_render_module;
if (gds_render_module_check_types_ready())
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;
}