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