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