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