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