Add Glist wrapper to python renderer
This commit is contained in:
parent
22efe4f8ca
commit
b959f8282a
50
plugins/python-renderer/include/python-renderer/glist.h
Normal file
50
plugins/python-renderer/include/python-renderer/glist.h
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* GDSII-Converter Python Plugin
|
||||||
|
* Copyright (C) 2020 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 python-renderer/glist.c
|
||||||
|
* @author Mario Hüttel <mario.huettel@gmx.net>
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @defgroup python-plugin-glist GList wrapper for python
|
||||||
|
* @ingroup python-plugin
|
||||||
|
* This is a wrapping class for GLists
|
||||||
|
* @addtogroup python-plugin-glist
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __GLIST_H__
|
||||||
|
#define __GLIST_H__
|
||||||
|
|
||||||
|
#ifndef PY_SSIZE_T_CLEAN
|
||||||
|
#define PY_SSIZE_T_CLEAN
|
||||||
|
#endif
|
||||||
|
#include <Python.h>
|
||||||
|
#include <glib.h>
|
||||||
|
|
||||||
|
extern PyTypeObject GListType;
|
||||||
|
|
||||||
|
typedef struct _GListObject GListObject;
|
||||||
|
|
||||||
|
void glist_set_head_ptr(GListObject *self, GList *head);
|
||||||
|
|
||||||
|
#endif /* __GLIST_H__ */
|
||||||
|
|
||||||
|
/** @} */
|
@ -25,21 +25,7 @@
|
|||||||
|
|
||||||
#include <python-renderer/gds-render-module.h>
|
#include <python-renderer/gds-render-module.h>
|
||||||
#include <gds-render/gds-utils/gds-types.h>
|
#include <gds-render/gds-utils/gds-types.h>
|
||||||
|
#include <python-renderer/glist.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)
|
||||||
{
|
{
|
||||||
@ -69,7 +55,7 @@ static PyModuleDef gds_render_module_def = {
|
|||||||
|
|
||||||
static int gds_render_module_check_types_ready()
|
static int gds_render_module_check_types_ready()
|
||||||
{
|
{
|
||||||
if (PyType_Ready(&GdsPointType) < 0)
|
if (!PyType_Ready(&GListType))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -79,16 +65,16 @@ static int gds_render_module_add_types(PyObject *module)
|
|||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
Py_INCREF(&GdsPointType);
|
Py_INCREF(&GListType);
|
||||||
err = PyModule_AddObject(module, "GdsPoint", (PyObject *)&GdsPointType);
|
err = PyModule_AddObject(module, "GdsPoint", (PyObject *)&GListType);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
goto decref_gds_point;
|
goto decref_glist;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
decref_gds_point:
|
decref_glist:
|
||||||
Py_DECREF(&GdsPointType);
|
Py_DECREF(&GListType);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
72
plugins/python-renderer/src/glist.c
Normal file
72
plugins/python-renderer/src/glist.c
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
/*
|
||||||
|
* GDSII-Converter Python Plugin
|
||||||
|
* Copyright (C) 2020 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 python-renderer/glist.c
|
||||||
|
* @author Mario Hüttel <mario.huettel@gmx.net>
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @defgroup python-plugin-glist GList wrapper for python
|
||||||
|
* @ingroup python-plugin
|
||||||
|
* This is a wrapping class for GLists
|
||||||
|
* This wrpper acts as a read only access to the lists
|
||||||
|
*
|
||||||
|
* @addtogroup python-plugin-glist
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <python-renderer/glist.h>
|
||||||
|
|
||||||
|
struct _GListObject {
|
||||||
|
PyObject_HEAD
|
||||||
|
GList *head;
|
||||||
|
size_t len;
|
||||||
|
};
|
||||||
|
|
||||||
|
static PyObject *glist_to_list(GListObject *self, PyObject *Py_UNUSED(ignored))
|
||||||
|
{
|
||||||
|
return Py_BuildValue("");
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyMethodDef glist_methods[] = {
|
||||||
|
{"tolist", (PyCFunction)glist_to_list, METH_NOARGS, "Convert GList to editable list"}
|
||||||
|
};
|
||||||
|
|
||||||
|
void glist_set_head_ptr(GListObject *self, GList *head)
|
||||||
|
{
|
||||||
|
if (!self || !head)
|
||||||
|
return;
|
||||||
|
|
||||||
|
self->head = head;
|
||||||
|
self->len = g_list_length(self->head);
|
||||||
|
}
|
||||||
|
|
||||||
|
PyTypeObject GListType = {
|
||||||
|
PyVarObject_HEAD_INIT(NULL, 0)
|
||||||
|
.tp_name = "gds_render.GList",
|
||||||
|
.tp_doc = "Read only GList",
|
||||||
|
.tp_basicsize = sizeof(GListObject),
|
||||||
|
.tp_itemsize = 0,
|
||||||
|
.tp_flags = Py_TPFLAGS_DEFAULT,
|
||||||
|
.tp_new = PyType_GenericNew,
|
||||||
|
.tp_methods = glist_methods
|
||||||
|
};
|
||||||
|
|
||||||
|
/** @} */
|
Loading…
Reference in New Issue
Block a user