Blender V5.0
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
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__()\n"
66 " __init__(integration_type)\n"
67 "\n"
68 " Builds a unary 1D function using either a default constructor\n"
69 " or the integration method given as an argument.\n"
70 "\n"
71 " :arg integration_type: An integration method.\n"
72 " :type integration_type: :class:`IntegrationType`\n");
74 PyObject *args,
75 PyObject *kwds)
76{
77 static const char *kwlist[] = {"integration", nullptr};
78 PyObject *obj = nullptr;
79
80 if (!PyArg_ParseTupleAndKeywords(
81 args, kwds, "|O!", (char **)kwlist, &IntegrationType_Type, &obj))
82 {
83 return -1;
84 }
85
86 if (!obj) {
87 self->uf1D_void = new UnaryFunction1D_void();
88 }
89 else {
91 }
92
93 self->uf1D_void->py_uf1D = (PyObject *)self;
94
95 return 0;
96}
97
99{
100 delete self->uf1D_void;
101 UnaryFunction1D_Type.tp_dealloc((PyObject *)self);
102}
103
105{
106 return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf1D_void);
107}
108
110 PyObject *args,
111 PyObject *kwds)
112{
113 static const char *kwlist[] = {"inter", nullptr};
114 PyObject *obj = nullptr;
115
116 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &Interface1D_Type, &obj)) {
117 return nullptr;
118 }
119
120 if (typeid(*(self->uf1D_void)) == typeid(UnaryFunction1D_void)) {
121 PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden");
122 return nullptr;
123 }
124 if (self->uf1D_void->operator()(*(((BPy_Interface1D *)obj)->if1D)) < 0) {
125 if (!PyErr_Occurred()) {
126 string class_name(Py_TYPE(self)->tp_name);
127 PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str());
128 }
129 return nullptr;
130 }
131 Py_RETURN_NONE;
132}
133
134/*----------------------UnaryFunction1DVoid get/setters ----------------------------*/
135
137 /* Wrap. */
138 integration_type_doc,
139 "The integration method.\n"
140 "\n"
141 ":type: :class:`IntegrationType`\n");
142static PyObject *integration_type_get(BPy_UnaryFunction1DVoid *self, void * /*closure*/)
143{
144 return BPy_IntegrationType_from_IntegrationType(self->uf1D_void->getIntegrationType());
145}
146
147static int integration_type_set(BPy_UnaryFunction1DVoid *self, PyObject *value, void * /*closure*/)
148{
149 if (!BPy_IntegrationType_Check(value)) {
150 PyErr_SetString(PyExc_TypeError, "value must be an IntegrationType");
151 return -1;
152 }
153 self->uf1D_void->setIntegrationType(IntegrationType_from_BPy_IntegrationType(value));
154 return 0;
155}
156
157static PyGetSetDef BPy_UnaryFunction1DVoid_getseters[] = {
158 {"integration_type",
159 (getter)integration_type_get,
160 (setter)integration_type_set,
161 integration_type_doc,
162 nullptr},
163 {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
164};
165
166/*-----------------------BPy_UnaryFunction1DVoid type definition ------------------------------*/
167
169 /*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
170 /*tp_name*/ "UnaryFunction1DVoid",
171 /*tp_basicsize*/ sizeof(BPy_UnaryFunction1DVoid),
172 /*tp_itemsize*/ 0,
173 /*tp_dealloc*/ (destructor)UnaryFunction1DVoid___dealloc__,
174 /*tp_vectorcall_offset*/ 0,
175 /*tp_getattr*/ nullptr,
176 /*tp_setattr*/ nullptr,
177 /*tp_as_async*/ nullptr,
178 /*tp_repr*/ (reprfunc)UnaryFunction1DVoid___repr__,
179 /*tp_as_number*/ nullptr,
180 /*tp_as_sequence*/ nullptr,
181 /*tp_as_mapping*/ nullptr,
182 /*tp_hash*/ nullptr,
183 /*tp_call*/ (ternaryfunc)UnaryFunction1DVoid___call__,
184 /*tp_str*/ nullptr,
185 /*tp_getattro*/ nullptr,
186 /*tp_setattro*/ nullptr,
187 /*tp_as_buffer*/ nullptr,
188 /*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
189 /*tp_doc*/ UnaryFunction1DVoid___doc__,
190 /*tp_traverse*/ nullptr,
191 /*tp_clear*/ nullptr,
192 /*tp_richcompare*/ nullptr,
193 /*tp_weaklistoffset*/ 0,
194 /*tp_iter*/ nullptr,
195 /*tp_iternext*/ nullptr,
196 /*tp_methods*/ nullptr,
197 /*tp_members*/ nullptr,
199 /*tp_base*/ &UnaryFunction1D_Type,
200 /*tp_dict*/ nullptr,
201 /*tp_descr_get*/ nullptr,
202 /*tp_descr_set*/ nullptr,
203 /*tp_dictoffset*/ 0,
204 /*tp_init*/ (initproc)UnaryFunction1DVoid___init__,
205 /*tp_alloc*/ nullptr,
206 /*tp_new*/ nullptr,
207};
208
PyTypeObject ChainingTimeStampF1D_Type
IntegrationType IntegrationType_from_BPy_IntegrationType(PyObject *obj)
PyObject * BPy_IntegrationType_from_IntegrationType(IntegrationType i)
PyTypeObject IncrementChainingTimeStampF1D_Type
PyTypeObject IntegrationType_Type
#define BPy_IntegrationType_Check(v)
PyTypeObject Interface1D_Type
PyTypeObject TimeStampF1D_Type
static PyObject * integration_type_get(BPy_UnaryFunction1DDouble *self, void *)
static int integration_type_set(BPy_UnaryFunction1DDouble *self, PyObject *value, void *)
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)
PyDoc_STRVAR(UnaryFunction1DVoid___doc__, "Class hierarchy: :class:`UnaryFunction1D` > :class:`UnaryFunction1DVoid`\n" "\n" "Base class for unary functions (functors) working on\n" ":class:`Interface1D`.\n" "\n" ".. method:: __init__()\n" " __init__(integration_type)\n" "\n" " Builds a unary 1D function using either a 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")
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
PyObject * self
inherits from class Rep
Definition AppCanvas.cpp:20
static struct PyModuleDef module
Definition python.cpp:796