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