Blender V5.0
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");
77 PyObject *args,
78 PyObject *kwds)
79{
80 static const char *kwlist[] = {"integration", nullptr};
81 PyObject *obj = nullptr;
82
83 if (!PyArg_ParseTupleAndKeywords(
84 args, kwds, "|O!", (char **)kwlist, &IntegrationType_Type, &obj))
85 {
86 return -1;
87 }
88
89 if (!obj) {
90 self->uf1D_vectorviewshape = new UnaryFunction1D<std::vector<ViewShape *>>();
91 }
92 else {
93 self->uf1D_vectorviewshape = new UnaryFunction1D<std::vector<ViewShape *>>(
95 }
96
97 self->uf1D_vectorviewshape->py_uf1D = (PyObject *)self;
98
99 return 0;
100}
101
103{
104 delete self->uf1D_vectorviewshape;
105 UnaryFunction1D_Type.tp_dealloc((PyObject *)self);
106}
107
109{
110 return PyUnicode_FromFormat(
111 "type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf1D_vectorviewshape);
112}
113
115 PyObject *args,
116 PyObject *kwds)
117{
118 static const char *kwlist[] = {"inter", nullptr};
119 PyObject *obj = nullptr;
120
121 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &Interface1D_Type, &obj)) {
122 return nullptr;
123 }
124
125 if (typeid(*(self->uf1D_vectorviewshape)) == typeid(UnaryFunction1D<std::vector<ViewShape *>>)) {
126 PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden");
127 return nullptr;
128 }
129 if (self->uf1D_vectorviewshape->operator()(*(((BPy_Interface1D *)obj)->if1D)) < 0) {
130 if (!PyErr_Occurred()) {
131 string class_name(Py_TYPE(self)->tp_name);
132 PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str());
133 }
134 return nullptr;
135 }
136
137 const uint list_len = self->uf1D_vectorviewshape->result.size();
138 PyObject *list = PyList_New(list_len);
139 for (uint i = 0; i < list_len; i++) {
140 ViewShape *v = self->uf1D_vectorviewshape->result[i];
141 PyList_SET_ITEM(list, i, v ? BPy_ViewShape_from_ViewShape(*v) : (Py_INCREF(Py_None), Py_None));
142 }
143
144 return list;
145}
146
147/*----------------------UnaryFunction1DVectorViewShape get/setters ----------------------------*/
148
150 /* Wrap. */
151 integration_type_doc,
152 "The integration method.\n"
153 "\n"
154 ":type: :class:`IntegrationType`\n");
156{
158 self->uf1D_vectorviewshape->getIntegrationType());
159}
160
162 PyObject *value,
163 void * /*closure*/)
164{
165 if (!BPy_IntegrationType_Check(value)) {
166 PyErr_SetString(PyExc_TypeError, "value must be an IntegrationType");
167 return -1;
168 }
169 self->uf1D_vectorviewshape->setIntegrationType(IntegrationType_from_BPy_IntegrationType(value));
170 return 0;
171}
172
174 {"integration_type",
175 (getter)integration_type_get,
176 (setter)integration_type_set,
177 integration_type_doc,
178 nullptr},
179 {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
180};
181
182/*-----------------------BPy_UnaryFunction1DVectorViewShape type definition ---------------------*/
183
185 /*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
186 /*tp_name*/ "UnaryFunction1DVectorViewShape",
187 /*tp_basicsize*/ sizeof(BPy_UnaryFunction1DVectorViewShape),
188 /*tp_itemsize*/ 0,
189 /*tp_dealloc*/ (destructor)UnaryFunction1DVectorViewShape___dealloc__,
190 /*tp_vectorcall_offset*/ 0,
191 /*tp_getattr*/ nullptr,
192 /*tp_setattr*/ nullptr,
193 /*tp_as_async*/ nullptr,
194 /*tp_repr*/ (reprfunc)UnaryFunction1DVectorViewShape___repr__,
195 /*tp_as_number*/ nullptr,
196 /*tp_as_sequence*/ nullptr,
197 /*tp_as_mapping*/ nullptr,
198 /*tp_hash*/ nullptr,
199 /*tp_call*/ (ternaryfunc)UnaryFunction1DVectorViewShape___call__,
200 /*tp_str*/ nullptr,
201 /*tp_getattro*/ nullptr,
202 /*tp_setattro*/ nullptr,
203 /*tp_as_buffer*/ nullptr,
204 /*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
205 /*tp_doc*/ UnaryFunction1DVectorViewShape___doc__,
206 /*tp_traverse*/ nullptr,
207 /*tp_clear*/ nullptr,
208 /*tp_richcompare*/ nullptr,
209 /*tp_weaklistoffset*/ 0,
210 /*tp_iter*/ nullptr,
211 /*tp_iternext*/ nullptr,
212 /*tp_methods*/ nullptr,
213 /*tp_members*/ nullptr,
215 /*tp_base*/ &UnaryFunction1D_Type,
216 /*tp_dict*/ nullptr,
217 /*tp_descr_get*/ nullptr,
218 /*tp_descr_set*/ nullptr,
219 /*tp_dictoffset*/ 0,
220 /*tp_init*/ (initproc)UnaryFunction1DVectorViewShape___init__,
221 /*tp_alloc*/ nullptr,
222 /*tp_new*/ nullptr,
223};
224
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