Cleanup: unused variable warning
[blender.git] / source / blender / freestyle / intern / python / UnaryFunction0D / BPy_UnaryFunction0DVec2f.cpp
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16
17 /** \file
18  * \ingroup freestyle
19  */
20
21 #include "BPy_UnaryFunction0DVec2f.h"
22
23 #include "../BPy_Convert.h"
24 #include "../Iterator/BPy_Interface0DIterator.h"
25
26 #include "UnaryFunction0D_Vec2f/BPy_Normal2DF0D.h"
27 #include "UnaryFunction0D_Vec2f/BPy_VertexOrientation2DF0D.h"
28
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32
33 ///////////////////////////////////////////////////////////////////////////////////////////
34
35 //-------------------MODULE INITIALIZATION--------------------------------
36
37 int UnaryFunction0DVec2f_Init(PyObject *module)
38 {
39   if (module == NULL) {
40     return -1;
41   }
42
43   if (PyType_Ready(&UnaryFunction0DVec2f_Type) < 0) {
44     return -1;
45   }
46   Py_INCREF(&UnaryFunction0DVec2f_Type);
47   PyModule_AddObject(module, "UnaryFunction0DVec2f", (PyObject *)&UnaryFunction0DVec2f_Type);
48
49   if (PyType_Ready(&Normal2DF0D_Type) < 0) {
50     return -1;
51   }
52   Py_INCREF(&Normal2DF0D_Type);
53   PyModule_AddObject(module, "Normal2DF0D", (PyObject *)&Normal2DF0D_Type);
54
55   if (PyType_Ready(&VertexOrientation2DF0D_Type) < 0) {
56     return -1;
57   }
58   Py_INCREF(&VertexOrientation2DF0D_Type);
59   PyModule_AddObject(module, "VertexOrientation2DF0D", (PyObject *)&VertexOrientation2DF0D_Type);
60
61   return 0;
62 }
63
64 //------------------------INSTANCE METHODS ----------------------------------
65
66 static char UnaryFunction0DVec2f___doc__[] =
67     "Class hierarchy: :class:`UnaryFunction0D` > :class:`UnaryFunction0DVec2f`\n"
68     "\n"
69     "Base class for unary functions (functors) that work on\n"
70     ":class:`Interface0DIterator` and return a 2D vector.\n"
71     "\n"
72     ".. method:: __init__()\n"
73     "\n"
74     "   Default constructor.\n";
75
76 static int UnaryFunction0DVec2f___init__(BPy_UnaryFunction0DVec2f *self,
77                                          PyObject *args,
78                                          PyObject *kwds)
79 {
80   static const char *kwlist[] = {NULL};
81
82   if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) {
83     return -1;
84   }
85   self->uf0D_vec2f = new UnaryFunction0D<Vec2f>();
86   self->uf0D_vec2f->py_uf0D = (PyObject *)self;
87   return 0;
88 }
89
90 static void UnaryFunction0DVec2f___dealloc__(BPy_UnaryFunction0DVec2f *self)
91 {
92   if (self->uf0D_vec2f) {
93     delete self->uf0D_vec2f;
94   }
95   UnaryFunction0D_Type.tp_dealloc((PyObject *)self);
96 }
97
98 static PyObject *UnaryFunction0DVec2f___repr__(BPy_UnaryFunction0DVec2f *self)
99 {
100   return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf0D_vec2f);
101 }
102
103 static PyObject *UnaryFunction0DVec2f___call__(BPy_UnaryFunction0DVec2f *self,
104                                                PyObject *args,
105                                                PyObject *kwds)
106 {
107   static const char *kwlist[] = {"it", NULL};
108   PyObject *obj;
109
110   if (!PyArg_ParseTupleAndKeywords(
111           args, kwds, "O!", (char **)kwlist, &Interface0DIterator_Type, &obj)) {
112     return NULL;
113   }
114
115   if (typeid(*(self->uf0D_vec2f)) == typeid(UnaryFunction0D<Vec2f>)) {
116     PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden");
117     return NULL;
118   }
119   if (self->uf0D_vec2f->operator()(*(((BPy_Interface0DIterator *)obj)->if0D_it)) < 0) {
120     if (!PyErr_Occurred()) {
121       string class_name(Py_TYPE(self)->tp_name);
122       PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str());
123     }
124     return NULL;
125   }
126   return Vector_from_Vec2f(self->uf0D_vec2f->result);
127 }
128
129 /*-----------------------BPy_UnaryFunction0DVec2f type definition ------------------------------*/
130
131 PyTypeObject UnaryFunction0DVec2f_Type = {
132     PyVarObject_HEAD_INIT(NULL, 0) "UnaryFunction0DVec2f", /* tp_name */
133     sizeof(BPy_UnaryFunction0DVec2f),                      /* tp_basicsize */
134     0,                                                     /* tp_itemsize */
135     (destructor)UnaryFunction0DVec2f___dealloc__,          /* tp_dealloc */
136     0,                                                     /* tp_print */
137     0,                                                     /* tp_getattr */
138     0,                                                     /* tp_setattr */
139     0,                                                     /* tp_reserved */
140     (reprfunc)UnaryFunction0DVec2f___repr__,               /* tp_repr */
141     0,                                                     /* tp_as_number */
142     0,                                                     /* tp_as_sequence */
143     0,                                                     /* tp_as_mapping */
144     0,                                                     /* tp_hash  */
145     (ternaryfunc)UnaryFunction0DVec2f___call__,            /* tp_call */
146     0,                                                     /* tp_str */
147     0,                                                     /* tp_getattro */
148     0,                                                     /* tp_setattro */
149     0,                                                     /* tp_as_buffer */
150     Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,              /* tp_flags */
151     UnaryFunction0DVec2f___doc__,                          /* tp_doc */
152     0,                                                     /* tp_traverse */
153     0,                                                     /* tp_clear */
154     0,                                                     /* tp_richcompare */
155     0,                                                     /* tp_weaklistoffset */
156     0,                                                     /* tp_iter */
157     0,                                                     /* tp_iternext */
158     0,                                                     /* tp_methods */
159     0,                                                     /* tp_members */
160     0,                                                     /* tp_getset */
161     &UnaryFunction0D_Type,                                 /* tp_base */
162     0,                                                     /* tp_dict */
163     0,                                                     /* tp_descr_get */
164     0,                                                     /* tp_descr_set */
165     0,                                                     /* tp_dictoffset */
166     (initproc)UnaryFunction0DVec2f___init__,               /* tp_init */
167     0,                                                     /* tp_alloc */
168     0,                                                     /* tp_new */
169 };
170
171 ///////////////////////////////////////////////////////////////////////////////////////////
172
173 #ifdef __cplusplus
174 }
175 #endif