Cleanup: remove window manager argument for paint cursor API
[blender.git] / source / blender / freestyle / intern / python / UnaryFunction0D / BPy_UnaryFunction0DDouble.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_UnaryFunction0DDouble.h"
22
23 #include "../BPy_Convert.h"
24 #include "../Iterator/BPy_Interface0DIterator.h"
25
26 #include "UnaryFunction0D_double/BPy_Curvature2DAngleF0D.h"
27 #include "UnaryFunction0D_double/BPy_DensityF0D.h"
28 #include "UnaryFunction0D_double/BPy_GetProjectedXF0D.h"
29 #include "UnaryFunction0D_double/BPy_GetProjectedYF0D.h"
30 #include "UnaryFunction0D_double/BPy_GetProjectedZF0D.h"
31 #include "UnaryFunction0D_double/BPy_GetXF0D.h"
32 #include "UnaryFunction0D_double/BPy_GetYF0D.h"
33 #include "UnaryFunction0D_double/BPy_GetZF0D.h"
34 #include "UnaryFunction0D_double/BPy_LocalAverageDepthF0D.h"
35 #include "UnaryFunction0D_double/BPy_ZDiscontinuityF0D.h"
36
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40
41 ///////////////////////////////////////////////////////////////////////////////////////////
42
43 //-------------------MODULE INITIALIZATION--------------------------------
44
45 int UnaryFunction0DDouble_Init(PyObject *module)
46 {
47   if (module == NULL) {
48     return -1;
49   }
50
51   if (PyType_Ready(&UnaryFunction0DDouble_Type) < 0) {
52     return -1;
53   }
54   Py_INCREF(&UnaryFunction0DDouble_Type);
55   PyModule_AddObject(module, "UnaryFunction0DDouble", (PyObject *)&UnaryFunction0DDouble_Type);
56
57   if (PyType_Ready(&DensityF0D_Type) < 0) {
58     return -1;
59   }
60   Py_INCREF(&DensityF0D_Type);
61   PyModule_AddObject(module, "DensityF0D", (PyObject *)&DensityF0D_Type);
62
63   if (PyType_Ready(&LocalAverageDepthF0D_Type) < 0) {
64     return -1;
65   }
66   Py_INCREF(&LocalAverageDepthF0D_Type);
67   PyModule_AddObject(module, "LocalAverageDepthF0D", (PyObject *)&LocalAverageDepthF0D_Type);
68
69   if (PyType_Ready(&Curvature2DAngleF0D_Type) < 0) {
70     return -1;
71   }
72   Py_INCREF(&Curvature2DAngleF0D_Type);
73   PyModule_AddObject(module, "Curvature2DAngleF0D", (PyObject *)&Curvature2DAngleF0D_Type);
74
75   if (PyType_Ready(&GetProjectedXF0D_Type) < 0) {
76     return -1;
77   }
78   Py_INCREF(&GetProjectedXF0D_Type);
79   PyModule_AddObject(module, "GetProjectedXF0D", (PyObject *)&GetProjectedXF0D_Type);
80
81   if (PyType_Ready(&GetProjectedYF0D_Type) < 0) {
82     return -1;
83   }
84   Py_INCREF(&GetProjectedYF0D_Type);
85   PyModule_AddObject(module, "GetProjectedYF0D", (PyObject *)&GetProjectedYF0D_Type);
86
87   if (PyType_Ready(&GetProjectedZF0D_Type) < 0) {
88     return -1;
89   }
90   Py_INCREF(&GetProjectedZF0D_Type);
91   PyModule_AddObject(module, "GetProjectedZF0D", (PyObject *)&GetProjectedZF0D_Type);
92
93   if (PyType_Ready(&GetXF0D_Type) < 0) {
94     return -1;
95   }
96   Py_INCREF(&GetXF0D_Type);
97   PyModule_AddObject(module, "GetXF0D", (PyObject *)&GetXF0D_Type);
98
99   if (PyType_Ready(&GetYF0D_Type) < 0) {
100     return -1;
101   }
102   Py_INCREF(&GetYF0D_Type);
103   PyModule_AddObject(module, "GetYF0D", (PyObject *)&GetYF0D_Type);
104
105   if (PyType_Ready(&GetZF0D_Type) < 0) {
106     return -1;
107   }
108   Py_INCREF(&GetZF0D_Type);
109   PyModule_AddObject(module, "GetZF0D", (PyObject *)&GetZF0D_Type);
110
111   if (PyType_Ready(&ZDiscontinuityF0D_Type) < 0) {
112     return -1;
113   }
114   Py_INCREF(&ZDiscontinuityF0D_Type);
115   PyModule_AddObject(module, "ZDiscontinuityF0D", (PyObject *)&ZDiscontinuityF0D_Type);
116
117   return 0;
118 }
119
120 //------------------------INSTANCE METHODS ----------------------------------
121
122 static char UnaryFunction0DDouble___doc__[] =
123     "Class hierarchy: :class:`UnaryFunction0D` > :class:`UnaryFunction0DDouble`\n"
124     "\n"
125     "Base class for unary functions (functors) that work on\n"
126     ":class:`Interface0DIterator` and return a float value.\n"
127     "\n"
128     ".. method:: __init__()\n"
129     "\n"
130     "   Default constructor.\n";
131
132 static int UnaryFunction0DDouble___init__(BPy_UnaryFunction0DDouble *self,
133                                           PyObject *args,
134                                           PyObject *kwds)
135 {
136   static const char *kwlist[] = {NULL};
137
138   if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) {
139     return -1;
140   }
141   self->uf0D_double = new UnaryFunction0D<double>();
142   self->uf0D_double->py_uf0D = (PyObject *)self;
143   return 0;
144 }
145
146 static void UnaryFunction0DDouble___dealloc__(BPy_UnaryFunction0DDouble *self)
147 {
148   if (self->uf0D_double) {
149     delete self->uf0D_double;
150   }
151   UnaryFunction0D_Type.tp_dealloc((PyObject *)self);
152 }
153
154 static PyObject *UnaryFunction0DDouble___repr__(BPy_UnaryFunction0DDouble *self)
155 {
156   return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf0D_double);
157 }
158
159 static PyObject *UnaryFunction0DDouble___call__(BPy_UnaryFunction0DDouble *self,
160                                                 PyObject *args,
161                                                 PyObject *kwds)
162 {
163   static const char *kwlist[] = {"it", NULL};
164   PyObject *obj;
165
166   if (!PyArg_ParseTupleAndKeywords(
167           args, kwds, "O!", (char **)kwlist, &Interface0DIterator_Type, &obj)) {
168     return NULL;
169   }
170
171   if (typeid(*(self->uf0D_double)) == typeid(UnaryFunction0D<double>)) {
172     PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden");
173     return NULL;
174   }
175   if (self->uf0D_double->operator()(*(((BPy_Interface0DIterator *)obj)->if0D_it)) < 0) {
176     if (!PyErr_Occurred()) {
177       string class_name(Py_TYPE(self)->tp_name);
178       PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str());
179     }
180     return NULL;
181   }
182   return PyFloat_FromDouble(self->uf0D_double->result);
183 }
184
185 /*-----------------------BPy_UnaryFunction0DDouble type definition ------------------------------*/
186
187 PyTypeObject UnaryFunction0DDouble_Type = {
188     PyVarObject_HEAD_INIT(NULL, 0) "UnaryFunction0DDouble", /* tp_name */
189     sizeof(BPy_UnaryFunction0DDouble),                      /* tp_basicsize */
190     0,                                                      /* tp_itemsize */
191     (destructor)UnaryFunction0DDouble___dealloc__,          /* tp_dealloc */
192     0,                                                      /* tp_print */
193     0,                                                      /* tp_getattr */
194     0,                                                      /* tp_setattr */
195     0,                                                      /* tp_reserved */
196     (reprfunc)UnaryFunction0DDouble___repr__,               /* tp_repr */
197     0,                                                      /* tp_as_number */
198     0,                                                      /* tp_as_sequence */
199     0,                                                      /* tp_as_mapping */
200     0,                                                      /* tp_hash  */
201     (ternaryfunc)UnaryFunction0DDouble___call__,            /* tp_call */
202     0,                                                      /* tp_str */
203     0,                                                      /* tp_getattro */
204     0,                                                      /* tp_setattro */
205     0,                                                      /* tp_as_buffer */
206     Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,               /* tp_flags */
207     UnaryFunction0DDouble___doc__,                          /* tp_doc */
208     0,                                                      /* tp_traverse */
209     0,                                                      /* tp_clear */
210     0,                                                      /* tp_richcompare */
211     0,                                                      /* tp_weaklistoffset */
212     0,                                                      /* tp_iter */
213     0,                                                      /* tp_iternext */
214     0,                                                      /* tp_methods */
215     0,                                                      /* tp_members */
216     0,                                                      /* tp_getset */
217     &UnaryFunction0D_Type,                                  /* tp_base */
218     0,                                                      /* tp_dict */
219     0,                                                      /* tp_descr_get */
220     0,                                                      /* tp_descr_set */
221     0,                                                      /* tp_dictoffset */
222     (initproc)UnaryFunction0DDouble___init__,               /* tp_init */
223     0,                                                      /* tp_alloc */
224     0,                                                      /* tp_new */
225 };
226
227 ///////////////////////////////////////////////////////////////////////////////////////////
228
229 #ifdef __cplusplus
230 }
231 #endif