Blender V5.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
8
10
11#include "../BPy_Convert.h"
13#include "../BPy_Interface1D.h"
14
17
18using namespace Freestyle;
19
21
22//-------------------MODULE INITIALIZATION--------------------------------
23
24int UnaryFunction1DVec2f_Init(PyObject *module)
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__(*args)\n"
59 "\n"
60 " Accepted call signatures:\n"
61 "\n"
62 " - ``__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 " :param integration_type: An integration method.\n"
69 " :type integration_type: :class:`IntegrationType`\n");
71 PyObject *args,
72 PyObject *kwds)
73{
74 static const char *kwlist[] = {"integration", nullptr};
75 PyObject *obj = nullptr;
76
77 if (!PyArg_ParseTupleAndKeywords(args,
78 kwds,
79 "|" /* Optional arguments. */
80 "O!" /* `integration` */
81 ":__init__",
82 (char **)kwlist,
84 &obj))
85 {
86 return -1;
87 }
88
89 if (!obj) {
91 }
92 else {
94 }
95
96 self->uf1D_vec2f->py_uf1D = (PyObject *)self;
97
98 return 0;
99}
100
102{
103 delete self->uf1D_vec2f;
104 UnaryFunction1D_Type.tp_dealloc((PyObject *)self);
105}
106
108{
109 return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf1D_vec2f);
110}
111
113 PyObject *args,
114 PyObject *kwds)
115{
116 static const char *kwlist[] = {"inter", nullptr};
117 PyObject *obj = nullptr;
118
119 if (!PyArg_ParseTupleAndKeywords(args,
120 kwds,
121 "O!" /* `inter` */
122 ":__call__",
123 (char **)kwlist,
125 &obj))
126 {
127 return nullptr;
128 }
129
130 if (typeid(*(self->uf1D_vec2f)) == typeid(UnaryFunction1D<Vec2f>)) {
131 PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden");
132 return nullptr;
133 }
134 if (self->uf1D_vec2f->operator()(*(((BPy_Interface1D *)obj)->if1D)) < 0) {
135 if (!PyErr_Occurred()) {
136 string class_name(Py_TYPE(self)->tp_name);
137 PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str());
138 }
139 return nullptr;
140 }
141 return Vector_from_Vec2f(self->uf1D_vec2f->result);
142}
143
144/*----------------------UnaryFunction1DVec2f get/setters ----------------------------*/
145
147 /* Wrap. */
148 integration_type_doc,
149 "The integration method.\n"
150 "\n"
151 ":type: :class:`IntegrationType`\n");
152static PyObject *integration_type_get(BPy_UnaryFunction1DVec2f *self, void * /*closure*/)
153{
154 return BPy_IntegrationType_from_IntegrationType(self->uf1D_vec2f->getIntegrationType());
155}
156
158 PyObject *value,
159 void * /*closure*/)
160{
161 if (!BPy_IntegrationType_Check(value)) {
162 PyErr_SetString(PyExc_TypeError, "value must be an IntegrationType");
163 return -1;
164 }
165 self->uf1D_vec2f->setIntegrationType(IntegrationType_from_BPy_IntegrationType(value));
166 return 0;
167}
168
170 {"integration_type",
171 (getter)integration_type_get,
172 (setter)integration_type_set,
173 integration_type_doc,
174 nullptr},
175 {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
176};
177
178/*-----------------------BPy_UnaryFunction1DVec2f type definition ------------------------------*/
179
181 /*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
182 /*tp_name*/ "UnaryFunction1DVec2f",
183 /*tp_basicsize*/ sizeof(BPy_UnaryFunction1DVec2f),
184 /*tp_itemsize*/ 0,
185 /*tp_dealloc*/ (destructor)UnaryFunction1DVec2f___dealloc__,
186 /*tp_vectorcall_offset*/ 0,
187 /*tp_getattr*/ nullptr,
188 /*tp_setattr*/ nullptr,
189 /*tp_as_async*/ nullptr,
190 /*tp_repr*/ (reprfunc)UnaryFunction1DVec2f___repr__,
191 /*tp_as_number*/ nullptr,
192 /*tp_as_sequence*/ nullptr,
193 /*tp_as_mapping*/ nullptr,
194 /*tp_hash*/ nullptr,
195 /*tp_call*/ (ternaryfunc)UnaryFunction1DVec2f___call__,
196 /*tp_str*/ nullptr,
197 /*tp_getattro*/ nullptr,
198 /*tp_setattro*/ nullptr,
199 /*tp_as_buffer*/ nullptr,
200 /*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
201 /*tp_doc*/ UnaryFunction1DVec2f___doc__,
202 /*tp_traverse*/ nullptr,
203 /*tp_clear*/ nullptr,
204 /*tp_richcompare*/ nullptr,
205 /*tp_weaklistoffset*/ 0,
206 /*tp_iter*/ nullptr,
207 /*tp_iternext*/ nullptr,
208 /*tp_methods*/ nullptr,
209 /*tp_members*/ nullptr,
211 /*tp_base*/ &UnaryFunction1D_Type,
212 /*tp_dict*/ nullptr,
213 /*tp_descr_get*/ nullptr,
214 /*tp_descr_set*/ nullptr,
215 /*tp_dictoffset*/ 0,
216 /*tp_init*/ (initproc)UnaryFunction1DVec2f___init__,
217 /*tp_alloc*/ nullptr,
218 /*tp_new*/ nullptr,
219};
220
IntegrationType IntegrationType_from_BPy_IntegrationType(PyObject *obj)
PyObject * Vector_from_Vec2f(Vec2f &vec)
PyObject * BPy_IntegrationType_from_IntegrationType(IntegrationType i)
PyDoc_STRVAR(FalseBP1D___doc__, "Class hierarchy: :class:`freestyle.types.BinaryPredicate1D` > :class:`FalseBP1D`\n" "\n" ".. method:: __call__(inter1, inter2)\n" "\n" " Always returns false.\n" "\n" " :param inter1: The first Interface1D object.\n" " :type inter1: :class:`freestyle.types.Interface1D`\n" " :param inter2: The second Interface1D object.\n" " :type inter2: :class:`freestyle.types.Interface1D`\n" " :return: False.\n" " :rtype: bool\n")
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 *)
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
inherits from class Rep
Definition AppCanvas.cpp:20
Freestyle::UnaryFunction1D< Freestyle::Geometry::Vec2f > * uf1D_vec2f