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