Blender V5.0
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");
62 PyObject *args,
63 PyObject *kwds)
64{
65 static const char *kwlist[] = {"integration", nullptr};
66 PyObject *obj = nullptr;
67
68 if (!PyArg_ParseTupleAndKeywords(
69 args, kwds, "|O!", (char **)kwlist, &IntegrationType_Type, &obj))
70 {
71 return -1;
72 }
73
74 if (!obj) {
75 self->uf1D_edgenature = new UnaryFunction1D<Nature::EdgeNature>();
76 }
77 else {
78 self->uf1D_edgenature = new UnaryFunction1D<Nature::EdgeNature>(
80 }
81
82 self->uf1D_edgenature->py_uf1D = (PyObject *)self;
83
84 return 0;
85}
86
88{
89 delete self->uf1D_edgenature;
90 UnaryFunction1D_Type.tp_dealloc((PyObject *)self);
91}
92
94{
95 return PyUnicode_FromFormat(
96 "type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf1D_edgenature);
97}
98
100 PyObject *args,
101 PyObject *kwds)
102{
103 static const char *kwlist[] = {"inter", nullptr};
104 PyObject *obj = nullptr;
105
106 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &Interface1D_Type, &obj)) {
107 return nullptr;
108 }
109
110 if (typeid(*(self->uf1D_edgenature)) == typeid(UnaryFunction1D<Nature::EdgeNature>)) {
111 PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden");
112 return nullptr;
113 }
114 if (self->uf1D_edgenature->operator()(*(((BPy_Interface1D *)obj)->if1D)) < 0) {
115 if (!PyErr_Occurred()) {
116 string class_name(Py_TYPE(self)->tp_name);
117 PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str());
118 }
119 return nullptr;
120 }
121 return BPy_Nature_from_Nature(self->uf1D_edgenature->result);
122}
123
124/*----------------------UnaryFunction1DEdgeNature get/setters ----------------------------*/
125
127 /* Wrap. */
128 integration_type_doc,
129 "The integration method.\n"
130 "\n"
131 ":type: :class:`IntegrationType`\n");
132static PyObject *integration_type_get(BPy_UnaryFunction1DEdgeNature *self, void * /*closure*/)
133{
134 return BPy_IntegrationType_from_IntegrationType(self->uf1D_edgenature->getIntegrationType());
135}
136
138 PyObject *value,
139 void * /*closure*/)
140{
141 if (!BPy_IntegrationType_Check(value)) {
142 PyErr_SetString(PyExc_TypeError, "value must be an IntegrationType");
143 return -1;
144 }
145 self->uf1D_edgenature->setIntegrationType(IntegrationType_from_BPy_IntegrationType(value));
146 return 0;
147}
148
150 {"integration_type",
151 (getter)integration_type_get,
152 (setter)integration_type_set,
153 integration_type_doc,
154 nullptr},
155 {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
156};
157
158/*-----------------------BPy_UnaryFunction1DEdgeNature type definition --------------------------*/
159
161 /*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
162 /*tp_name*/ "UnaryFunction1DEdgeNature",
163 /*tp_basicsize*/ sizeof(BPy_UnaryFunction1DEdgeNature),
164 /*tp_itemsize*/ 0,
165 /*tp_dealloc*/ (destructor)UnaryFunction1DEdgeNature___dealloc__,
166 /*tp_vectorcall_offset*/ 0,
167 /*tp_getattr*/ nullptr,
168 /*tp_setattr*/ nullptr,
169 /*tp_as_async*/ nullptr,
170 /*tp_repr*/ (reprfunc)UnaryFunction1DEdgeNature___repr__,
171 /*tp_as_number*/ nullptr,
172 /*tp_as_sequence*/ nullptr,
173 /*tp_as_mapping*/ nullptr,
174 /*tp_hash*/ nullptr,
175 /*tp_call*/ (ternaryfunc)UnaryFunction1DEdgeNature___call__,
176 /*tp_str*/ nullptr,
177 /*tp_getattro*/ nullptr,
178 /*tp_setattro*/ nullptr,
179 /*tp_as_buffer*/ nullptr,
180 /*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
181 /*tp_doc*/ UnaryFunction1DEdgeNature___doc__,
182 /*tp_traverse*/ nullptr,
183 /*tp_clear*/ nullptr,
184 /*tp_richcompare*/ nullptr,
185 /*tp_weaklistoffset*/ 0,
186 /*tp_iter*/ nullptr,
187 /*tp_iternext*/ nullptr,
188 /*tp_methods*/ nullptr,
189 /*tp_members*/ nullptr,
191 /*tp_base*/ &UnaryFunction1D_Type,
192 /*tp_dict*/ nullptr,
193 /*tp_descr_get*/ nullptr,
194 /*tp_descr_set*/ nullptr,
195 /*tp_dictoffset*/ 0,
196 /*tp_init*/ (initproc)UnaryFunction1DEdgeNature___init__,
197 /*tp_alloc*/ nullptr,
198 /*tp_new*/ nullptr,
199};
200
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