Merge branch 'blender-v2.83-release'
[blender.git] / source / blender / freestyle / intern / python / UnaryFunction0D / BPy_UnaryFunction0DViewShape.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_UnaryFunction0DViewShape.h"
22
23 #include "../BPy_Convert.h"
24 #include "../Iterator/BPy_Interface0DIterator.h"
25
26 #include "UnaryFunction0D_ViewShape/BPy_GetOccludeeF0D.h"
27 #include "UnaryFunction0D_ViewShape/BPy_GetShapeF0D.h"
28
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32
33 ///////////////////////////////////////////////////////////////////////////////////////////
34
35 //-------------------MODULE INITIALIZATION--------------------------------
36
37 int UnaryFunction0DViewShape_Init(PyObject *module)
38 {
39   if (module == NULL) {
40     return -1;
41   }
42
43   if (PyType_Ready(&UnaryFunction0DViewShape_Type) < 0) {
44     return -1;
45   }
46   Py_INCREF(&UnaryFunction0DViewShape_Type);
47   PyModule_AddObject(
48       module, "UnaryFunction0DViewShape", (PyObject *)&UnaryFunction0DViewShape_Type);
49
50   if (PyType_Ready(&GetOccludeeF0D_Type) < 0) {
51     return -1;
52   }
53   Py_INCREF(&GetOccludeeF0D_Type);
54   PyModule_AddObject(module, "GetOccludeeF0D", (PyObject *)&GetOccludeeF0D_Type);
55
56   if (PyType_Ready(&GetShapeF0D_Type) < 0) {
57     return -1;
58   }
59   Py_INCREF(&GetShapeF0D_Type);
60   PyModule_AddObject(module, "GetShapeF0D", (PyObject *)&GetShapeF0D_Type);
61
62   return 0;
63 }
64
65 //------------------------INSTANCE METHODS ----------------------------------
66
67 static char UnaryFunction0DViewShape___doc__[] =
68     "Class hierarchy: :class:`UnaryFunction0D` > :class:`UnaryFunction0DViewShape`\n"
69     "\n"
70     "Base class for unary functions (functors) that work on\n"
71     ":class:`Interface0DIterator` and return a :class:`ViewShape` object.\n"
72     "\n"
73     ".. method:: __init__()\n"
74     "\n"
75     "   Default constructor.\n";
76
77 static int UnaryFunction0DViewShape___init__(BPy_UnaryFunction0DViewShape *self,
78                                              PyObject *args,
79                                              PyObject *kwds)
80 {
81   static const char *kwlist[] = {NULL};
82
83   if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) {
84     return -1;
85   }
86   self->uf0D_viewshape = new UnaryFunction0D<ViewShape *>();
87   self->uf0D_viewshape->py_uf0D = (PyObject *)self;
88   return 0;
89 }
90
91 static void UnaryFunction0DViewShape___dealloc__(BPy_UnaryFunction0DViewShape *self)
92 {
93   if (self->uf0D_viewshape) {
94     delete self->uf0D_viewshape;
95   }
96   UnaryFunction0D_Type.tp_dealloc((PyObject *)self);
97 }
98
99 static PyObject *UnaryFunction0DViewShape___repr__(BPy_UnaryFunction0DViewShape *self)
100 {
101   return PyUnicode_FromFormat(
102       "type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf0D_viewshape);
103 }
104
105 static PyObject *UnaryFunction0DViewShape___call__(BPy_UnaryFunction0DViewShape *self,
106                                                    PyObject *args,
107                                                    PyObject *kwds)
108 {
109   static const char *kwlist[] = {"it", NULL};
110   PyObject *obj;
111
112   if (!PyArg_ParseTupleAndKeywords(
113           args, kwds, "O!", (char **)kwlist, &Interface0DIterator_Type, &obj)) {
114     return NULL;
115   }
116
117   if (typeid(*(self->uf0D_viewshape)) == typeid(UnaryFunction0D<ViewShape *>)) {
118     PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden");
119     return NULL;
120   }
121   if (self->uf0D_viewshape->operator()(*(((BPy_Interface0DIterator *)obj)->if0D_it)) < 0) {
122     if (!PyErr_Occurred()) {
123       string class_name(Py_TYPE(self)->tp_name);
124       PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str());
125     }
126     return NULL;
127   }
128   return BPy_ViewShape_from_ViewShape(*(self->uf0D_viewshape->result));
129 }
130
131 /*-----------------------BPy_UnaryFunction0DViewShape type definition ---------------------------*/
132
133 PyTypeObject UnaryFunction0DViewShape_Type = {
134     PyVarObject_HEAD_INIT(NULL, 0) "UnaryFunction0DViewShape", /* tp_name */
135     sizeof(BPy_UnaryFunction0DViewShape),                      /* tp_basicsize */
136     0,                                                         /* tp_itemsize */
137     (destructor)UnaryFunction0DViewShape___dealloc__,          /* tp_dealloc */
138     0,                                                         /* tp_print */
139     0,                                                         /* tp_getattr */
140     0,                                                         /* tp_setattr */
141     0,                                                         /* tp_reserved */
142     (reprfunc)UnaryFunction0DViewShape___repr__,               /* tp_repr */
143     0,                                                         /* tp_as_number */
144     0,                                                         /* tp_as_sequence */
145     0,                                                         /* tp_as_mapping */
146     0,                                                         /* tp_hash  */
147     (ternaryfunc)UnaryFunction0DViewShape___call__,            /* tp_call */
148     0,                                                         /* tp_str */
149     0,                                                         /* tp_getattro */
150     0,                                                         /* tp_setattro */
151     0,                                                         /* tp_as_buffer */
152     Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,                  /* tp_flags */
153     UnaryFunction0DViewShape___doc__,                          /* tp_doc */
154     0,                                                         /* tp_traverse */
155     0,                                                         /* tp_clear */
156     0,                                                         /* tp_richcompare */
157     0,                                                         /* tp_weaklistoffset */
158     0,                                                         /* tp_iter */
159     0,                                                         /* tp_iternext */
160     0,                                                         /* tp_methods */
161     0,                                                         /* tp_members */
162     0,                                                         /* tp_getset */
163     &UnaryFunction0D_Type,                                     /* tp_base */
164     0,                                                         /* tp_dict */
165     0,                                                         /* tp_descr_get */
166     0,                                                         /* tp_descr_set */
167     0,                                                         /* tp_dictoffset */
168     (initproc)UnaryFunction0DViewShape___init__,               /* tp_init */
169     0,                                                         /* tp_alloc */
170     0,                                                         /* tp_new */
171 };
172
173 ///////////////////////////////////////////////////////////////////////////////////////////
174
175 #ifdef __cplusplus
176 }
177 #endif