Blender V4.3
BPy_UnaryFunction1DVectorViewShape.cpp
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2008-2022 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10
11#include "../BPy_Convert.h"
13#include "../BPy_Interface1D.h"
14
18
19#include "BLI_sys_types.h"
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
25using namespace Freestyle;
26
28
29//-------------------MODULE INITIALIZATION--------------------------------
30
32{
33 if (module == nullptr) {
34 return -1;
35 }
36
37 if (PyType_Ready(&UnaryFunction1DVectorViewShape_Type) < 0) {
38 return -1;
39 }
40 PyModule_AddObjectRef(
41 module, "UnaryFunction1DVectorViewShape", (PyObject *)&UnaryFunction1DVectorViewShape_Type);
42
43 if (PyType_Ready(&GetOccludeeF1D_Type) < 0) {
44 return -1;
45 }
46 PyModule_AddObjectRef(module, "GetOccludeeF1D", (PyObject *)&GetOccludeeF1D_Type);
47
48 if (PyType_Ready(&GetOccludersF1D_Type) < 0) {
49 return -1;
50 }
51 PyModule_AddObjectRef(module, "GetOccludersF1D", (PyObject *)&GetOccludersF1D_Type);
52
53 if (PyType_Ready(&GetShapeF1D_Type) < 0) {
54 return -1;
55 }
56 PyModule_AddObjectRef(module, "GetShapeF1D", (PyObject *)&GetShapeF1D_Type);
57
58 return 0;
59}
60
61//------------------------INSTANCE METHODS ----------------------------------
62
64 /* Wrap. */
65 UnaryFunction1DVectorViewShape___doc__,
66 "Class hierarchy: :class:`UnaryFunction1D` > :class:`UnaryFunction1DVectorViewShape`\n"
67 "\n"
68 "Base class for unary functions (functors) that work on\n"
69 ":class:`Interface1D` and return a list of :class:`ViewShape`\n"
70 "objects.\n"
71 "\n"
72 ".. method:: __init__()\n"
73 " __init__(integration_type)\n"
74 "\n"
75 " Builds a unary 1D function using the default constructor\n"
76 " or the integration method given as an argument.\n"
77 "\n"
78 " :arg integration_type: An integration method.\n"
79 " :type integration_type: :class:`IntegrationType`\n");
80
82 PyObject *args,
83 PyObject *kwds)
84{
85 static const char *kwlist[] = {"integration", nullptr};
86 PyObject *obj = nullptr;
87
88 if (!PyArg_ParseTupleAndKeywords(
89 args, kwds, "|O!", (char **)kwlist, &IntegrationType_Type, &obj))
90 {
91 return -1;
92 }
93
94 if (!obj) {
95 self->uf1D_vectorviewshape = new UnaryFunction1D<std::vector<ViewShape *>>();
96 }
97 else {
98 self->uf1D_vectorviewshape = new UnaryFunction1D<std::vector<ViewShape *>>(
100 }
101
102 self->uf1D_vectorviewshape->py_uf1D = (PyObject *)self;
103
104 return 0;
105}
106
108{
109 delete self->uf1D_vectorviewshape;
110 UnaryFunction1D_Type.tp_dealloc((PyObject *)self);
111}
112
114{
115 return PyUnicode_FromFormat(
116 "type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf1D_vectorviewshape);
117}
118
120 PyObject *args,
121 PyObject *kwds)
122{
123 static const char *kwlist[] = {"inter", nullptr};
124 PyObject *obj = nullptr;
125
126 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &Interface1D_Type, &obj)) {
127 return nullptr;
128 }
129
130 if (typeid(*(self->uf1D_vectorviewshape)) == typeid(UnaryFunction1D<std::vector<ViewShape *>>)) {
131 PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden");
132 return nullptr;
133 }
134 if (self->uf1D_vectorviewshape->operator()(*(((BPy_Interface1D *)obj)->if1D)) < 0) {
135 if (!PyErr_Occurred()) {
136 string class_name(Py_TYPE(self)->tp_name);
137 PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str());
138 }
139 return nullptr;
140 }
141
142 const uint list_len = self->uf1D_vectorviewshape->result.size();
143 PyObject *list = PyList_New(list_len);
144 for (uint i = 0; i < list_len; i++) {
145 ViewShape *v = self->uf1D_vectorviewshape->result[i];
146 PyList_SET_ITEM(list, i, v ? BPy_ViewShape_from_ViewShape(*v) : (Py_INCREF(Py_None), Py_None));
147 }
148
149 return list;
150}
151
152/*----------------------UnaryFunction1DVectorViewShape get/setters ----------------------------*/
153
155 /* Wrap. */
156 integration_type_doc,
157 "The integration method.\n"
158 "\n"
159 ":type: :class:`IntegrationType`");
160
162{
164 self->uf1D_vectorviewshape->getIntegrationType());
165}
166
168 PyObject *value,
169 void * /*closure*/)
170{
171 if (!BPy_IntegrationType_Check(value)) {
172 PyErr_SetString(PyExc_TypeError, "value must be an IntegrationType");
173 return -1;
174 }
175 self->uf1D_vectorviewshape->setIntegrationType(IntegrationType_from_BPy_IntegrationType(value));
176 return 0;
177}
178
180 {"integration_type",
181 (getter)integration_type_get,
182 (setter)integration_type_set,
183 integration_type_doc,
184 nullptr},
185 {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
186};
187
188/*-----------------------BPy_UnaryFunction1DVectorViewShape type definition ---------------------*/
189
191 /*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
192 /*tp_name*/ "UnaryFunction1DVectorViewShape",
193 /*tp_basicsize*/ sizeof(BPy_UnaryFunction1DVectorViewShape),
194 /*tp_itemsize*/ 0,
195 /*tp_dealloc*/ (destructor)UnaryFunction1DVectorViewShape___dealloc__,
196 /*tp_vectorcall_offset*/ 0,
197 /*tp_getattr*/ nullptr,
198 /*tp_setattr*/ nullptr,
199 /*tp_as_async*/ nullptr,
200 /*tp_repr*/ (reprfunc)UnaryFunction1DVectorViewShape___repr__,
201 /*tp_as_number*/ nullptr,
202 /*tp_as_sequence*/ nullptr,
203 /*tp_as_mapping*/ nullptr,
204 /*tp_hash*/ nullptr,
205 /*tp_call*/ (ternaryfunc)UnaryFunction1DVectorViewShape___call__,
206 /*tp_str*/ nullptr,
207 /*tp_getattro*/ nullptr,
208 /*tp_setattro*/ nullptr,
209 /*tp_as_buffer*/ nullptr,
210 /*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
211 /*tp_doc*/ UnaryFunction1DVectorViewShape___doc__,
212 /*tp_traverse*/ nullptr,
213 /*tp_clear*/ nullptr,
214 /*tp_richcompare*/ nullptr,
215 /*tp_weaklistoffset*/ 0,
216 /*tp_iter*/ nullptr,
217 /*tp_iternext*/ nullptr,
218 /*tp_methods*/ nullptr,
219 /*tp_members*/ nullptr,
221 /*tp_base*/ &UnaryFunction1D_Type,
222 /*tp_dict*/ nullptr,
223 /*tp_descr_get*/ nullptr,
224 /*tp_descr_set*/ nullptr,
225 /*tp_dictoffset*/ 0,
226 /*tp_init*/ (initproc)UnaryFunction1DVectorViewShape___init__,
227 /*tp_alloc*/ nullptr,
228 /*tp_new*/ nullptr,
229};
230
232
233#ifdef __cplusplus
234}
235#endif
unsigned int uint
IntegrationType IntegrationType_from_BPy_IntegrationType(PyObject *obj)
PyObject * BPy_IntegrationType_from_IntegrationType(IntegrationType i)
PyObject * BPy_ViewShape_from_ViewShape(ViewShape &vs)
PyTypeObject GetOccludeeF1D_Type
PyTypeObject GetOccludersF1D_Type
PyTypeObject GetShapeF1D_Type
PyTypeObject IntegrationType_Type
#define BPy_IntegrationType_Check(v)
PyTypeObject Interface1D_Type
PyDoc_STRVAR(UnaryFunction1DVectorViewShape___doc__, "Class hierarchy: :class:`UnaryFunction1D` > :class:`UnaryFunction1DVectorViewShape`\n" "\n" "Base class for unary functions (functors) that work on\n" ":class:`Interface1D` and return a list of :class:`ViewShape`\n" "objects.\n" "\n" ".. method:: __init__()\n" " __init__(integration_type)\n" "\n" " Builds a unary 1D function using the default constructor\n" " or the integration method given as an argument.\n" "\n" " :arg integration_type: An integration method.\n" " :type integration_type: :class:`IntegrationType`\n")
static int UnaryFunction1DVectorViewShape___init__(BPy_UnaryFunction1DVectorViewShape *self, PyObject *args, PyObject *kwds)
static int integration_type_set(BPy_UnaryFunction1DVectorViewShape *self, PyObject *value, void *)
static PyObject * UnaryFunction1DVectorViewShape___repr__(BPy_UnaryFunction1DVectorViewShape *self)
static PyGetSetDef BPy_UnaryFunction1DVectorViewShape_getseters[]
static PyObject * UnaryFunction1DVectorViewShape___call__(BPy_UnaryFunction1DVectorViewShape *self, PyObject *args, PyObject *kwds)
PyTypeObject UnaryFunction1DVectorViewShape_Type
int UnaryFunction1DVectorViewShape_Init(PyObject *module)
static void UnaryFunction1DVectorViewShape___dealloc__(BPy_UnaryFunction1DVectorViewShape *self)
static PyObject * integration_type_get(BPy_UnaryFunction1DVectorViewShape *self, void *)
PyTypeObject UnaryFunction1D_Type
ATTR_WARN_UNUSED_RESULT const BMVert * v
PyObject * self
inherits from class Rep
Definition AppCanvas.cpp:20
static struct PyModuleDef module
Definition python.cpp:991