2
* ***** BEGIN GPL LICENSE BLOCK *****
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License
6
* as published by the Free Software Foundation; either version 2
7
* of the License, or (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software Foundation,
16
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
* ***** END GPL LICENSE BLOCK *****
21
/** \file source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DVec2f.cpp
25
#include "BPy_UnaryFunction0DVec2f.h"
27
#include "../BPy_Convert.h"
28
#include "../Iterator/BPy_Interface0DIterator.h"
30
#include "UnaryFunction0D_Vec2f/BPy_Normal2DF0D.h"
31
#include "UnaryFunction0D_Vec2f/BPy_VertexOrientation2DF0D.h"
37
///////////////////////////////////////////////////////////////////////////////////////////
39
//-------------------MODULE INITIALIZATION--------------------------------
41
int UnaryFunction0DVec2f_Init(PyObject *module)
46
if (PyType_Ready(&UnaryFunction0DVec2f_Type) < 0)
48
Py_INCREF(&UnaryFunction0DVec2f_Type);
49
PyModule_AddObject(module, "UnaryFunction0DVec2f", (PyObject *)&UnaryFunction0DVec2f_Type);
51
if (PyType_Ready(&Normal2DF0D_Type) < 0)
53
Py_INCREF(&Normal2DF0D_Type);
54
PyModule_AddObject(module, "Normal2DF0D", (PyObject *)&Normal2DF0D_Type);
56
if (PyType_Ready(&VertexOrientation2DF0D_Type) < 0)
58
Py_INCREF(&VertexOrientation2DF0D_Type);
59
PyModule_AddObject(module, "VertexOrientation2DF0D", (PyObject *)&VertexOrientation2DF0D_Type);
64
//------------------------INSTANCE METHODS ----------------------------------
66
static char UnaryFunction0DVec2f___doc__[] =
67
"Class hierarchy: :class:`UnaryFunction0D` > :class:`UnaryFunction0DVec2f`\n"
69
"Base class for unary functions (functors) that work on\n"
70
":class:`Interface0DIterator` and return a 2D vector.\n"
72
".. method:: __init__()\n"
74
" Default constructor.\n";
76
static int UnaryFunction0DVec2f___init__(BPy_UnaryFunction0DVec2f *self, PyObject *args, PyObject *kwds)
78
static const char *kwlist[] = {NULL};
80
if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist))
82
self->uf0D_vec2f = new UnaryFunction0D<Vec2f>();
83
self->uf0D_vec2f->py_uf0D = (PyObject *)self;
87
static void UnaryFunction0DVec2f___dealloc__(BPy_UnaryFunction0DVec2f *self)
90
delete self->uf0D_vec2f;
91
UnaryFunction0D_Type.tp_dealloc((PyObject *)self);
94
static PyObject *UnaryFunction0DVec2f___repr__(BPy_UnaryFunction0DVec2f *self)
96
return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf0D_vec2f);
99
static PyObject *UnaryFunction0DVec2f___call__(BPy_UnaryFunction0DVec2f *self, PyObject *args, PyObject *kwds)
101
static const char *kwlist[] = {"it", NULL};
104
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &Interface0DIterator_Type, &obj))
107
if (typeid(*(self->uf0D_vec2f)) == typeid(UnaryFunction0D<Vec2f>)) {
108
PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden");
111
if (self->uf0D_vec2f->operator()(*(((BPy_Interface0DIterator *)obj)->if0D_it)) < 0) {
112
if (!PyErr_Occurred()) {
113
string class_name(Py_TYPE(self)->tp_name);
114
PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str());
118
return Vector_from_Vec2f(self->uf0D_vec2f->result);
121
/*-----------------------BPy_UnaryFunction0DVec2f type definition ------------------------------*/
123
PyTypeObject UnaryFunction0DVec2f_Type = {
124
PyVarObject_HEAD_INIT(NULL, 0)
125
"UnaryFunction0DVec2f", /* tp_name */
126
sizeof(BPy_UnaryFunction0DVec2f), /* tp_basicsize */
128
(destructor)UnaryFunction0DVec2f___dealloc__, /* tp_dealloc */
133
(reprfunc)UnaryFunction0DVec2f___repr__, /* tp_repr */
134
0, /* tp_as_number */
135
0, /* tp_as_sequence */
136
0, /* tp_as_mapping */
138
(ternaryfunc)UnaryFunction0DVec2f___call__, /* tp_call */
142
0, /* tp_as_buffer */
143
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
144
UnaryFunction0DVec2f___doc__, /* tp_doc */
147
0, /* tp_richcompare */
148
0, /* tp_weaklistoffset */
154
&UnaryFunction0D_Type, /* tp_base */
156
0, /* tp_descr_get */
157
0, /* tp_descr_set */
158
0, /* tp_dictoffset */
159
(initproc)UnaryFunction0DVec2f___init__, /* tp_init */
164
///////////////////////////////////////////////////////////////////////////////////////////