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