Blender V5.0
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");
61 PyObject *args,
62 PyObject *kwds)
63{
64 static const char *kwlist[] = {"integration", nullptr};
65 PyObject *obj = nullptr;
66
67 if (!PyArg_ParseTupleAndKeywords(
68 args, kwds, "|O!", (char **)kwlist, &IntegrationType_Type, &obj))
69 {
70 return -1;
71 }
72
73 if (!obj) {
74 self->uf1D_vec3f = new UnaryFunction1D<Vec3f>();
75 }
76 else {
78 }
79
80 self->uf1D_vec3f->py_uf1D = (PyObject *)self;
81
82 return 0;
83}
84
86{
87 delete self->uf1D_vec3f;
88 UnaryFunction1D_Type.tp_dealloc((PyObject *)self);
89}
90
92{
93 return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf1D_vec3f);
94}
95
97 PyObject *args,
98 PyObject *kwds)
99{
100 static const char *kwlist[] = {"inter", nullptr};
101 PyObject *obj = nullptr;
102
103 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &Interface1D_Type, &obj)) {
104 return nullptr;
105 }
106
107 if (typeid(*(self->uf1D_vec3f)) == typeid(UnaryFunction1D<Vec3f>)) {
108 PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden");
109 return nullptr;
110 }
111 if (self->uf1D_vec3f->operator()(*(((BPy_Interface1D *)obj)->if1D)) < 0) {
112 if (!PyErr_Occurred()) {
113 string class_name(Py_TYPE(self)->tp_name);
114 PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str());
115 }
116 return nullptr;
117 }
118 return Vector_from_Vec3f(self->uf1D_vec3f->result);
119}
120
121/*----------------------UnaryFunction1DVec3f get/setters ----------------------------*/
122
124 /* Wrap. */
125 integration_type_doc,
126 "The integration method.\n"
127 "\n"
128 ":type: :class:`IntegrationType`\n");
129static PyObject *integration_type_get(BPy_UnaryFunction1DVec3f *self, void * /*closure*/)
130{
131 return BPy_IntegrationType_from_IntegrationType(self->uf1D_vec3f->getIntegrationType());
132}
133
135 PyObject *value,
136 void * /*closure*/)
137{
138 if (!BPy_IntegrationType_Check(value)) {
139 PyErr_SetString(PyExc_TypeError, "value must be an IntegrationType");
140 return -1;
141 }
142 self->uf1D_vec3f->setIntegrationType(IntegrationType_from_BPy_IntegrationType(value));
143 return 0;
144}
145
147 {"integration_type",
148 (getter)integration_type_get,
149 (setter)integration_type_set,
150 integration_type_doc,
151 nullptr},
152 {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
153};
154
155/*-----------------------BPy_UnaryFunction1DVec3f type definition ------------------------------*/
156
158 /*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
159 /*tp_name*/ "UnaryFunction1DVec3f",
160 /*tp_basicsize*/ sizeof(BPy_UnaryFunction1DVec3f),
161 /*tp_itemsize*/ 0,
162 /*tp_dealloc*/ (destructor)UnaryFunction1DVec3f___dealloc__,
163 /*tp_vectorcall_offset*/ 0,
164 /*tp_getattr*/ nullptr,
165 /*tp_setattr*/ nullptr,
166 /*tp_as_async*/ nullptr,
167 /*tp_repr*/ (reprfunc)UnaryFunction1DVec3f___repr__,
168 /*tp_as_number*/ nullptr,
169 /*tp_as_sequence*/ nullptr,
170 /*tp_as_mapping*/ nullptr,
171 /*tp_hash*/ nullptr,
172 /*tp_call*/ (ternaryfunc)UnaryFunction1DVec3f___call__,
173 /*tp_str*/ nullptr,
174 /*tp_getattro*/ nullptr,
175 /*tp_setattro*/ nullptr,
176 /*tp_as_buffer*/ nullptr,
177 /*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
178 /*tp_doc*/ UnaryFunction1DVec3f___doc__,
179 /*tp_traverse*/ nullptr,
180 /*tp_clear*/ nullptr,
181 /*tp_richcompare*/ nullptr,
182 /*tp_weaklistoffset*/ 0,
183 /*tp_iter*/ nullptr,
184 /*tp_iternext*/ nullptr,
185 /*tp_methods*/ nullptr,
186 /*tp_members*/ nullptr,
188 /*tp_base*/ &UnaryFunction1D_Type,
189 /*tp_dict*/ nullptr,
190 /*tp_descr_get*/ nullptr,
191 /*tp_descr_set*/ nullptr,
192 /*tp_dictoffset*/ 0,
193 /*tp_init*/ (initproc)UnaryFunction1DVec3f___init__,
194 /*tp_alloc*/ nullptr,
195 /*tp_new*/ nullptr,
196};
197
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