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