Blender V5.0
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");
67 PyObject *args,
68 PyObject *kwds)
69{
70 static const char *kwlist[] = {"integration", nullptr};
71 PyObject *obj = nullptr;
72
73 if (!PyArg_ParseTupleAndKeywords(
74 args, kwds, "|O!", (char **)kwlist, &IntegrationType_Type, &obj))
75 {
76 return -1;
77 }
78
79 if (!obj) {
80 self->uf1D_vec2f = new UnaryFunction1D<Vec2f>();
81 }
82 else {
84 }
85
86 self->uf1D_vec2f->py_uf1D = (PyObject *)self;
87
88 return 0;
89}
90
92{
93 delete self->uf1D_vec2f;
94 UnaryFunction1D_Type.tp_dealloc((PyObject *)self);
95}
96
98{
99 return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf1D_vec2f);
100}
101
103 PyObject *args,
104 PyObject *kwds)
105{
106 static const char *kwlist[] = {"inter", nullptr};
107 PyObject *obj = nullptr;
108
109 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &Interface1D_Type, &obj)) {
110 return nullptr;
111 }
112
113 if (typeid(*(self->uf1D_vec2f)) == typeid(UnaryFunction1D<Vec2f>)) {
114 PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden");
115 return nullptr;
116 }
117 if (self->uf1D_vec2f->operator()(*(((BPy_Interface1D *)obj)->if1D)) < 0) {
118 if (!PyErr_Occurred()) {
119 string class_name(Py_TYPE(self)->tp_name);
120 PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str());
121 }
122 return nullptr;
123 }
124 return Vector_from_Vec2f(self->uf1D_vec2f->result);
125}
126
127/*----------------------UnaryFunction1DVec2f get/setters ----------------------------*/
128
130 /* Wrap. */
131 integration_type_doc,
132 "The integration method.\n"
133 "\n"
134 ":type: :class:`IntegrationType`\n");
135static PyObject *integration_type_get(BPy_UnaryFunction1DVec2f *self, void * /*closure*/)
136{
137 return BPy_IntegrationType_from_IntegrationType(self->uf1D_vec2f->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_vec2f->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_UnaryFunction1DVec2f type definition ------------------------------*/
162
164 /*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
165 /*tp_name*/ "UnaryFunction1DVec2f",
166 /*tp_basicsize*/ sizeof(BPy_UnaryFunction1DVec2f),
167 /*tp_itemsize*/ 0,
168 /*tp_dealloc*/ (destructor)UnaryFunction1DVec2f___dealloc__,
169 /*tp_vectorcall_offset*/ 0,
170 /*tp_getattr*/ nullptr,
171 /*tp_setattr*/ nullptr,
172 /*tp_as_async*/ nullptr,
173 /*tp_repr*/ (reprfunc)UnaryFunction1DVec2f___repr__,
174 /*tp_as_number*/ nullptr,
175 /*tp_as_sequence*/ nullptr,
176 /*tp_as_mapping*/ nullptr,
177 /*tp_hash*/ nullptr,
178 /*tp_call*/ (ternaryfunc)UnaryFunction1DVec2f___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*/ UnaryFunction1DVec2f___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)UnaryFunction1DVec2f___init__,
200 /*tp_alloc*/ nullptr,
201 /*tp_new*/ nullptr,
202};
203
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