Blender V4.3
BPy_UnaryFunction1DFloat.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
15#ifdef __cplusplus
16extern "C" {
17#endif
18
19using namespace Freestyle;
20
22
23//-------------------MODULE INITIALIZATION--------------------------------
24
26{
27 if (module == nullptr) {
28 return -1;
29 }
30
31 if (PyType_Ready(&UnaryFunction1DFloat_Type) < 0) {
32 return -1;
33 }
34 PyModule_AddObjectRef(module, "UnaryFunction1DFloat", (PyObject *)&UnaryFunction1DFloat_Type);
35
36 return 0;
37}
38
39//------------------------INSTANCE METHODS ----------------------------------
40
42 /* Wrap. */
43 UnaryFunction1DFloat___doc__,
44 "Class hierarchy: :class:`UnaryFunction1D` > :class:`UnaryFunction1DFloat`\n"
45 "\n"
46 "Base class for unary functions (functors) that work on\n"
47 ":class:`Interface1D` and return a float value.\n"
48 "\n"
49 ".. method:: __init__()\n"
50 " __init__(integration_type)\n"
51 "\n"
52 " Builds a unary 1D function using the default constructor\n"
53 " or the integration method given as an argument.\n"
54 "\n"
55 " :arg integration_type: An integration method.\n"
56 " :type integration_type: :class:`IntegrationType`\n");
57
59 PyObject *args,
60 PyObject *kwds)
61{
62 static const char *kwlist[] = {"integration", nullptr};
63 PyObject *obj = nullptr;
64
65 if (!PyArg_ParseTupleAndKeywords(
66 args, kwds, "|O!", (char **)kwlist, &IntegrationType_Type, &obj))
67 {
68 return -1;
69 }
70
71 if (!obj) {
72 self->uf1D_float = new UnaryFunction1D<float>();
73 }
74 else {
76 }
77
78 self->uf1D_float->py_uf1D = (PyObject *)self;
79
80 return 0;
81}
82
84{
85 delete self->uf1D_float;
86 UnaryFunction1D_Type.tp_dealloc((PyObject *)self);
87}
88
90{
91 return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf1D_float);
92}
93
95 PyObject *args,
96 PyObject *kwds)
97{
98 static const char *kwlist[] = {"inter", nullptr};
99 PyObject *obj = nullptr;
100
101 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &Interface1D_Type, &obj)) {
102 return nullptr;
103 }
104
105 if (typeid(*(self->uf1D_float)) == typeid(UnaryFunction1D<float>)) {
106 PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden");
107 return nullptr;
108 }
109 if (self->uf1D_float->operator()(*(((BPy_Interface1D *)obj)->if1D)) < 0) {
110 if (!PyErr_Occurred()) {
111 string class_name(Py_TYPE(self)->tp_name);
112 PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str());
113 }
114 return nullptr;
115 }
116 return PyFloat_FromDouble(self->uf1D_float->result);
117}
118
119/*----------------------UnaryFunction1DFloat get/setters ----------------------------*/
120
122 /* Wrap. */
123 integration_type_doc,
124 "The integration method.\n"
125 "\n"
126 ":type: :class:`IntegrationType`");
127
128static PyObject *integration_type_get(BPy_UnaryFunction1DFloat *self, void * /*closure*/)
129{
130 return BPy_IntegrationType_from_IntegrationType(self->uf1D_float->getIntegrationType());
131}
132
134 PyObject *value,
135 void * /*closure*/)
136{
137 if (!BPy_IntegrationType_Check(value)) {
138 PyErr_SetString(PyExc_TypeError, "value must be an IntegrationType");
139 return -1;
140 }
141 self->uf1D_float->setIntegrationType(IntegrationType_from_BPy_IntegrationType(value));
142 return 0;
143}
144
146 {"integration_type",
147 (getter)integration_type_get,
148 (setter)integration_type_set,
149 integration_type_doc,
150 nullptr},
151 {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
152};
153
154/*-----------------------BPy_UnaryFunction1DFloat type definition ------------------------------*/
155
157 /*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
158 /*tp_name*/ "UnaryFunction1DFloat",
159 /*tp_basicsize*/ sizeof(BPy_UnaryFunction1DFloat),
160 /*tp_itemsize*/ 0,
161 /*tp_dealloc*/ (destructor)UnaryFunction1DFloat___dealloc__,
162 /*tp_vectorcall_offset*/ 0,
163 /*tp_getattr*/ nullptr,
164 /*tp_setattr*/ nullptr,
165 /*tp_as_async*/ nullptr,
166 /*tp_repr*/ (reprfunc)UnaryFunction1DFloat___repr__,
167 /*tp_as_number*/ nullptr,
168 /*tp_as_sequence*/ nullptr,
169 /*tp_as_mapping*/ nullptr,
170 /*tp_hash*/ nullptr,
171 /*tp_call*/ (ternaryfunc)UnaryFunction1DFloat___call__,
172 /*tp_str*/ nullptr,
173 /*tp_getattro*/ nullptr,
174 /*tp_setattro*/ nullptr,
175 /*tp_as_buffer*/ nullptr,
176 /*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
177 /*tp_doc*/ UnaryFunction1DFloat___doc__,
178 /*tp_traverse*/ nullptr,
179 /*tp_clear*/ nullptr,
180 /*tp_richcompare*/ nullptr,
181 /*tp_weaklistoffset*/ 0,
182 /*tp_iter*/ nullptr,
183 /*tp_iternext*/ nullptr,
184 /*tp_methods*/ nullptr,
185 /*tp_members*/ nullptr,
187 /*tp_base*/ &UnaryFunction1D_Type,
188 /*tp_dict*/ nullptr,
189 /*tp_descr_get*/ nullptr,
190 /*tp_descr_set*/ nullptr,
191 /*tp_dictoffset*/ 0,
192 /*tp_init*/ (initproc)UnaryFunction1DFloat___init__,
193 /*tp_alloc*/ nullptr,
194 /*tp_new*/ nullptr,
195};
196
198
199#ifdef __cplusplus
200}
201#endif
IntegrationType IntegrationType_from_BPy_IntegrationType(PyObject *obj)
PyObject * BPy_IntegrationType_from_IntegrationType(IntegrationType i)
PyTypeObject IntegrationType_Type
#define BPy_IntegrationType_Check(v)
PyTypeObject Interface1D_Type
PyTypeObject UnaryFunction1DFloat_Type
static int UnaryFunction1DFloat___init__(BPy_UnaryFunction1DFloat *self, PyObject *args, PyObject *kwds)
int UnaryFunction1DFloat_Init(PyObject *module)
static PyObject * UnaryFunction1DFloat___call__(BPy_UnaryFunction1DFloat *self, PyObject *args, PyObject *kwds)
static PyGetSetDef BPy_UnaryFunction1DFloat_getseters[]
PyDoc_STRVAR(UnaryFunction1DFloat___doc__, "Class hierarchy: :class:`UnaryFunction1D` > :class:`UnaryFunction1DFloat`\n" "\n" "Base class for unary functions (functors) that work on\n" ":class:`Interface1D` and return a float value.\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 void UnaryFunction1DFloat___dealloc__(BPy_UnaryFunction1DFloat *self)
static PyObject * UnaryFunction1DFloat___repr__(BPy_UnaryFunction1DFloat *self)
static PyObject * integration_type_get(BPy_UnaryFunction1DFloat *self, void *)
static int integration_type_set(BPy_UnaryFunction1DFloat *self, PyObject *value, void *)
PyTypeObject UnaryFunction1D_Type
PyObject * self
inherits from class Rep
Definition AppCanvas.cpp:20
static struct PyModuleDef module
Definition python.cpp:991