Blender V4.3
BPy_UnaryPredicate1D.cpp
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2004-2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10
11#include "BPy_Convert.h"
12#include "BPy_Interface1D.h"
13
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
29using namespace Freestyle;
30
32
33//-------------------MODULE INITIALIZATION--------------------------------
35{
36 if (module == nullptr) {
37 return -1;
38 }
39
40 if (PyType_Ready(&UnaryPredicate1D_Type) < 0) {
41 return -1;
42 }
43 PyModule_AddObjectRef(module, "UnaryPredicate1D", (PyObject *)&UnaryPredicate1D_Type);
44
45 if (PyType_Ready(&ContourUP1D_Type) < 0) {
46 return -1;
47 }
48 PyModule_AddObjectRef(module, "ContourUP1D", (PyObject *)&ContourUP1D_Type);
49
50 if (PyType_Ready(&DensityLowerThanUP1D_Type) < 0) {
51 return -1;
52 }
53 PyModule_AddObjectRef(module, "DensityLowerThanUP1D", (PyObject *)&DensityLowerThanUP1D_Type);
54
55 if (PyType_Ready(&EqualToChainingTimeStampUP1D_Type) < 0) {
56 return -1;
57 }
58 PyModule_AddObjectRef(
59 module, "EqualToChainingTimeStampUP1D", (PyObject *)&EqualToChainingTimeStampUP1D_Type);
60
61 if (PyType_Ready(&EqualToTimeStampUP1D_Type) < 0) {
62 return -1;
63 }
64 PyModule_AddObjectRef(module, "EqualToTimeStampUP1D", (PyObject *)&EqualToTimeStampUP1D_Type);
65
66 if (PyType_Ready(&ExternalContourUP1D_Type) < 0) {
67 return -1;
68 }
69 PyModule_AddObjectRef(module, "ExternalContourUP1D", (PyObject *)&ExternalContourUP1D_Type);
70
71 if (PyType_Ready(&FalseUP1D_Type) < 0) {
72 return -1;
73 }
74 PyModule_AddObjectRef(module, "FalseUP1D", (PyObject *)&FalseUP1D_Type);
75
76 if (PyType_Ready(&QuantitativeInvisibilityUP1D_Type) < 0) {
77 return -1;
78 }
79 PyModule_AddObjectRef(
80 module, "QuantitativeInvisibilityUP1D", (PyObject *)&QuantitativeInvisibilityUP1D_Type);
81
82 if (PyType_Ready(&ShapeUP1D_Type) < 0) {
83 return -1;
84 }
85 PyModule_AddObjectRef(module, "ShapeUP1D", (PyObject *)&ShapeUP1D_Type);
86
87 if (PyType_Ready(&TrueUP1D_Type) < 0) {
88 return -1;
89 }
90 PyModule_AddObjectRef(module, "TrueUP1D", (PyObject *)&TrueUP1D_Type);
91
92 if (PyType_Ready(&WithinImageBoundaryUP1D_Type) < 0) {
93 return -1;
94 }
95 PyModule_AddObjectRef(
96 module, "WithinImageBoundaryUP1D", (PyObject *)&WithinImageBoundaryUP1D_Type);
97
98 return 0;
99}
100
101//------------------------INSTANCE METHODS ----------------------------------
102
104 /* Wrap. */
105 UnaryPredicate1D___doc__,
106 "Base class for unary predicates that work on :class:`Interface1D`. A\n"
107 "UnaryPredicate1D is a functor that evaluates a condition on a\n"
108 "Interface1D and returns true or false depending on whether this\n"
109 "condition is satisfied or not. The UnaryPredicate1D is used by\n"
110 "invoking its __call__() method. Any inherited class must overload the\n"
111 "__call__() method.\n"
112 "\n"
113 ".. method:: __init__()\n"
114 "\n"
115 " Default constructor.\n"
116 "\n"
117 ".. method:: __call__(inter)\n"
118 "\n"
119 " Must be overload by inherited classes.\n"
120 "\n"
121 " :arg inter: The Interface1D on which we wish to evaluate the predicate.\n"
122 " :type inter: :class:`Interface1D`\n"
123 " :return: True if the condition is satisfied, false otherwise.\n"
124 " :rtype: bool\n");
125
126static int UnaryPredicate1D___init__(BPy_UnaryPredicate1D *self, PyObject *args, PyObject *kwds)
127{
128 static const char *kwlist[] = {nullptr};
129
130 if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) {
131 return -1;
132 }
133 self->up1D = new UnaryPredicate1D();
134 self->up1D->py_up1D = (PyObject *)self;
135 return 0;
136}
137
139{
140 delete self->up1D;
141 Py_TYPE(self)->tp_free((PyObject *)self);
142}
143
145{
146 return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->up1D);
147}
148
150 PyObject *args,
151 PyObject *kwds)
152{
153 static const char *kwlist[] = {"inter", nullptr};
154 PyObject *py_if1D;
155
156 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &Interface1D_Type, &py_if1D))
157 {
158 return nullptr;
159 }
160
161 Interface1D *if1D = ((BPy_Interface1D *)py_if1D)->if1D;
162
163 if (!if1D) {
164 string class_name(Py_TYPE(self)->tp_name);
165 PyErr_SetString(PyExc_RuntimeError, (class_name + " has no Interface1D").c_str());
166 return nullptr;
167 }
168 if (typeid(*(self->up1D)) == typeid(UnaryPredicate1D)) {
169 PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden");
170 return nullptr;
171 }
172 if (self->up1D->operator()(*if1D) < 0) {
173 if (!PyErr_Occurred()) {
174 string class_name(Py_TYPE(self)->tp_name);
175 PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str());
176 }
177 return nullptr;
178 }
179 return PyBool_from_bool(self->up1D->result);
180}
181
182/*----------------------UnaryPredicate1D get/setters ----------------------------*/
183
185 /* Wrap. */
186 UnaryPredicate1D_name_doc,
187 "The name of the unary 1D predicate.\n"
188 "\n"
189 ":type: str");
190
191static PyObject *UnaryPredicate1D_name_get(BPy_UnaryPredicate1D *self, void * /*closure*/)
192{
193 return PyUnicode_FromString(Py_TYPE(self)->tp_name);
194}
195
196static PyGetSetDef BPy_UnaryPredicate1D_getseters[] = {
197 {"name",
199 (setter) nullptr,
200 UnaryPredicate1D_name_doc,
201 nullptr},
202 {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
203};
204
205/*-----------------------BPy_UnaryPredicate1D type definition ------------------------------*/
206
207PyTypeObject UnaryPredicate1D_Type = {
208 /*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
209 /*tp_name*/ "UnaryPredicate1D",
210 /*tp_basicsize*/ sizeof(BPy_UnaryPredicate1D),
211 /*tp_itemsize*/ 0,
212 /*tp_dealloc*/ (destructor)UnaryPredicate1D___dealloc__,
213 /*tp_vectorcall_offset*/ 0,
214 /*tp_getattr*/ nullptr,
215 /*tp_setattr*/ nullptr,
216 /*tp_as_async*/ nullptr,
217 /*tp_repr*/ (reprfunc)UnaryPredicate1D___repr__,
218 /*tp_as_number*/ nullptr,
219 /*tp_as_sequence*/ nullptr,
220 /*tp_as_mapping*/ nullptr,
221 /*tp_hash*/ nullptr,
222 /*tp_call*/ (ternaryfunc)UnaryPredicate1D___call__,
223 /*tp_str*/ nullptr,
224 /*tp_getattro*/ nullptr,
225 /*tp_setattro*/ nullptr,
226 /*tp_as_buffer*/ nullptr,
227 /*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
228 /*tp_doc*/ UnaryPredicate1D___doc__,
229 /*tp_traverse*/ nullptr,
230 /*tp_clear*/ nullptr,
231 /*tp_richcompare*/ nullptr,
232 /*tp_weaklistoffset*/ 0,
233 /*tp_iter*/ nullptr,
234 /*tp_iternext*/ nullptr,
235 /*tp_methods*/ nullptr,
236 /*tp_members*/ nullptr,
237 /*tp_getset*/ BPy_UnaryPredicate1D_getseters,
238 /*tp_base*/ nullptr,
239 /*tp_dict*/ nullptr,
240 /*tp_descr_get*/ nullptr,
241 /*tp_descr_set*/ nullptr,
242 /*tp_dictoffset*/ 0,
243 /*tp_init*/ (initproc)UnaryPredicate1D___init__,
244 /*tp_alloc*/ nullptr,
245 /*tp_new*/ PyType_GenericNew,
246};
247
249
250#ifdef __cplusplus
251}
252#endif
PyTypeObject ContourUP1D_Type
PyObject * PyBool_from_bool(bool b)
PyTypeObject DensityLowerThanUP1D_Type
PyTypeObject EqualToChainingTimeStampUP1D_Type
PyTypeObject EqualToTimeStampUP1D_Type
PyTypeObject ExternalContourUP1D_Type
PyTypeObject FalseUP1D_Type
PyTypeObject Interface1D_Type
PyTypeObject QuantitativeInvisibilityUP1D_Type
PyTypeObject ShapeUP1D_Type
PyTypeObject TrueUP1D_Type
PyDoc_STRVAR(UnaryPredicate1D___doc__, "Base class for unary predicates that work on :class:`Interface1D`. A\n" "UnaryPredicate1D is a functor that evaluates a condition on a\n" "Interface1D and returns true or false depending on whether this\n" "condition is satisfied or not. The UnaryPredicate1D is used by\n" "invoking its __call__() method. Any inherited class must overload the\n" "__call__() method.\n" "\n" ".. method:: __init__()\n" "\n" " Default constructor.\n" "\n" ".. method:: __call__(inter)\n" "\n" " Must be overload by inherited classes.\n" "\n" " :arg inter: The Interface1D on which we wish to evaluate the predicate.\n" " :type inter: :class:`Interface1D`\n" " :return: True if the condition is satisfied, false otherwise.\n" " :rtype: bool\n")
static PyObject * UnaryPredicate1D___repr__(BPy_UnaryPredicate1D *self)
static PyObject * UnaryPredicate1D___call__(BPy_UnaryPredicate1D *self, PyObject *args, PyObject *kwds)
static PyObject * UnaryPredicate1D_name_get(BPy_UnaryPredicate1D *self, void *)
PyTypeObject UnaryPredicate1D_Type
static PyGetSetDef BPy_UnaryPredicate1D_getseters[]
int UnaryPredicate1D_Init(PyObject *module)
static void UnaryPredicate1D___dealloc__(BPy_UnaryPredicate1D *self)
static int UnaryPredicate1D___init__(BPy_UnaryPredicate1D *self, PyObject *args, PyObject *kwds)
PyTypeObject WithinImageBoundaryUP1D_Type
PyObject * self
inherits from class Rep
Definition AppCanvas.cpp:20
static struct PyModuleDef module
Definition python.cpp:991