Blender V5.3
BPy_UnaryFunction1DVoid.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
19using namespace Freestyle;
20
22
23//-------------------MODULE INITIALIZATION--------------------------------
24
25int UnaryFunction1DVoid_Init(PyObject *module)
26{
27 if (module == nullptr) {
28 return -1;
29 }
30
31 if (PyType_Ready(&UnaryFunction1DVoid_Type) < 0) {
32 return -1;
33 }
34 PyModule_AddObjectRef(module, "UnaryFunction1DVoid", (PyObject *)&UnaryFunction1DVoid_Type);
35
36 if (PyType_Ready(&ChainingTimeStampF1D_Type) < 0) {
37 return -1;
38 }
39 PyModule_AddObjectRef(module, "ChainingTimeStampF1D", (PyObject *)&ChainingTimeStampF1D_Type);
40
41 if (PyType_Ready(&IncrementChainingTimeStampF1D_Type) < 0) {
42 return -1;
43 }
44 PyModule_AddObjectRef(
45 module, "IncrementChainingTimeStampF1D", (PyObject *)&IncrementChainingTimeStampF1D_Type);
46
47 if (PyType_Ready(&TimeStampF1D_Type) < 0) {
48 return -1;
49 }
50 PyModule_AddObjectRef(module, "TimeStampF1D", (PyObject *)&TimeStampF1D_Type);
51
52 return 0;
53}
54
55//------------------------INSTANCE METHODS ----------------------------------
56
58 /* Wrap. */
59 UnaryFunction1DVoid___doc__,
60 "Class hierarchy: :class:`UnaryFunction1D` > :class:`UnaryFunction1DVoid`\n"
61 "\n"
62 "Base class for unary functions (functors) working on\n"
63 ":class:`Interface1D`.\n"
64 "\n"
65 ".. method:: __init__(*args)\n"
66 "\n"
67 " Accepted call signatures:\n"
68 "\n"
69 " - ``__init__()``\n"
70 " - ``__init__(integration_type)``\n"
71 "\n"
72 " Builds a unary 1D function using either a default constructor\n"
73 " or the integration method given as an argument.\n"
74 "\n"
75 " :param integration_type: An integration method.\n"
76 " :type integration_type: :class:`IntegrationType`\n");
78 PyObject *args,
79 PyObject *kwds)
80{
81 static const char *kwlist[] = {"integration", nullptr};
82 PyObject *obj = nullptr;
83
84 if (!PyArg_ParseTupleAndKeywords(args,
85 kwds,
86 "|" /* Optional arguments. */
87 "O!" /* `integration` */
88 ":__init__",
89 (char **)kwlist,
91 &obj))
92 {
93 return -1;
94 }
95
96 if (!obj) {
97 self->uf1D_void = new UnaryFunction1D_void();
98 }
99 else {
101 }
102
103 self->uf1D_void->py_uf1D = (PyObject *)self;
104
105 return 0;
106}
107
109{
110 delete self->uf1D_void;
111 UnaryFunction1D_Type.tp_dealloc((PyObject *)self);
112}
113
115{
116 return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf1D_void);
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,
127 kwds,
128 "O!" /* `inter` */
129 ":__call__",
130 (char **)kwlist,
132 &obj))
133 {
134 return nullptr;
135 }
136
137 if (typeid(*(self->uf1D_void)) == typeid(UnaryFunction1D_void)) {
138 PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden");
139 return nullptr;
140 }
141 if (self->uf1D_void->operator()(*(((BPy_Interface1D *)obj)->if1D)) < 0) {
142 if (!PyErr_Occurred()) {
143 string class_name(Py_TYPE(self)->tp_name);
144 PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str());
145 }
146 return nullptr;
147 }
148 Py_RETURN_NONE;
149}
150
151/*----------------------UnaryFunction1DVoid get/setters ----------------------------*/
152
154 /* Wrap. */
155 integration_type_doc,
156 "The integration method.\n"
157 "\n"
158 ":type: :class:`IntegrationType`\n");
159static PyObject *integration_type_get(BPy_UnaryFunction1DVoid *self, void * /*closure*/)
160{
162}
163
164static int integration_type_set(BPy_UnaryFunction1DVoid *self, PyObject *value, void * /*closure*/)
165{
166 if (!BPy_IntegrationType_Check(value)) {
167 PyErr_SetString(PyExc_TypeError, "value must be an IntegrationType");
168 return -1;
169 }
171 return 0;
172}
173
174static PyGetSetDef BPy_UnaryFunction1DVoid_getseters[] = {
175 {"integration_type",
176 (getter)integration_type_get,
177 (setter)integration_type_set,
178 integration_type_doc,
179 nullptr},
180 {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
181};
182
183/*-----------------------BPy_UnaryFunction1DVoid type definition ------------------------------*/
184
186 /*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
187 /*tp_name*/ "UnaryFunction1DVoid",
188 /*tp_basicsize*/ sizeof(BPy_UnaryFunction1DVoid),
189 /*tp_itemsize*/ 0,
190 /*tp_dealloc*/ (destructor)UnaryFunction1DVoid___dealloc__,
191 /*tp_vectorcall_offset*/ 0,
192 /*tp_getattr*/ nullptr,
193 /*tp_setattr*/ nullptr,
194 /*tp_as_async*/ nullptr,
195 /*tp_repr*/ (reprfunc)UnaryFunction1DVoid___repr__,
196 /*tp_as_number*/ nullptr,
197 /*tp_as_sequence*/ nullptr,
198 /*tp_as_mapping*/ nullptr,
199 /*tp_hash*/ nullptr,
200 /*tp_call*/ (ternaryfunc)UnaryFunction1DVoid___call__,
201 /*tp_str*/ nullptr,
202 /*tp_getattro*/ nullptr,
203 /*tp_setattro*/ nullptr,
204 /*tp_as_buffer*/ nullptr,
205 /*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
206 /*tp_doc*/ UnaryFunction1DVoid___doc__,
207 /*tp_traverse*/ nullptr,
208 /*tp_clear*/ nullptr,
209 /*tp_richcompare*/ nullptr,
210 /*tp_weaklistoffset*/ 0,
211 /*tp_iter*/ nullptr,
212 /*tp_iternext*/ nullptr,
213 /*tp_methods*/ nullptr,
214 /*tp_members*/ nullptr,
216 /*tp_base*/ &UnaryFunction1D_Type,
217 /*tp_dict*/ nullptr,
218 /*tp_descr_get*/ nullptr,
219 /*tp_descr_set*/ nullptr,
220 /*tp_dictoffset*/ 0,
221 /*tp_init*/ (initproc)UnaryFunction1DVoid___init__,
222 /*tp_alloc*/ nullptr,
223 /*tp_new*/ nullptr,
224};
225
PyTypeObject ChainingTimeStampF1D_Type
IntegrationType IntegrationType_from_BPy_IntegrationType(PyObject *obj)
PyObject * BPy_IntegrationType_from_IntegrationType(IntegrationType i)
PyDoc_STRVAR(FalseBP1D___doc__, "Class hierarchy: :class:`freestyle.types.BinaryPredicate1D` > :class:`FalseBP1D`\n" "\n" ".. method:: __call__(inter1, inter2)\n" "\n" " Always returns false.\n" "\n" " :param inter1: The first Interface1D object.\n" " :type inter1: :class:`freestyle.types.Interface1D`\n" " :param inter2: The second Interface1D object.\n" " :type inter2: :class:`freestyle.types.Interface1D`\n" " :return: False.\n" " :rtype: bool\n")
PyTypeObject IncrementChainingTimeStampF1D_Type
PyTypeObject IntegrationType_Type
#define BPy_IntegrationType_Check(v)
PyTypeObject Interface1D_Type
PyTypeObject TimeStampF1D_Type
static int integration_type_set(BPy_UnaryFunction1DVoid *self, PyObject *value, void *)
static PyObject * UnaryFunction1DVoid___call__(BPy_UnaryFunction1DVoid *self, PyObject *args, PyObject *kwds)
int UnaryFunction1DVoid_Init(PyObject *module)
PyTypeObject UnaryFunction1DVoid_Type
static PyObject * integration_type_get(BPy_UnaryFunction1DVoid *self, void *)
static int UnaryFunction1DVoid___init__(BPy_UnaryFunction1DVoid *self, PyObject *args, PyObject *kwds)
static void UnaryFunction1DVoid___dealloc__(BPy_UnaryFunction1DVoid *self)
static PyGetSetDef BPy_UnaryFunction1DVoid_getseters[]
static PyObject * UnaryFunction1DVoid___repr__(BPy_UnaryFunction1DVoid *self)
PyTypeObject UnaryFunction1D_Type
void setIntegrationType(IntegrationType integration)
IntegrationType getIntegrationType() const
inherits from class Rep
Definition AppCanvas.cpp:20
Freestyle::UnaryFunction1D_void * uf1D_void