Blender V5.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
8
10
11#include "BPy_Convert.h"
12#include "BPy_Interface1D.h"
13
24
25using namespace Freestyle;
26
28
29//-------------------MODULE INITIALIZATION--------------------------------
30int UnaryPredicate1D_Init(PyObject *module)
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 " :param 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,
152 kwds,
153 "O!" /* `inter` */
154 ":__call__",
155 (char **)kwlist,
157 &py_if1D))
158 {
159 return nullptr;
160 }
161
162 Interface1D *if1D = ((BPy_Interface1D *)py_if1D)->if1D;
163
164 if (!if1D) {
165 string class_name(Py_TYPE(self)->tp_name);
166 PyErr_SetString(PyExc_RuntimeError, (class_name + " has no Interface1D").c_str());
167 return nullptr;
168 }
169 if (typeid(*(self->up1D)) == typeid(UnaryPredicate1D)) {
170 PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden");
171 return nullptr;
172 }
173 if (self->up1D->operator()(*if1D) < 0) {
174 if (!PyErr_Occurred()) {
175 string class_name(Py_TYPE(self)->tp_name);
176 PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str());
177 }
178 return nullptr;
179 }
180 return PyBool_from_bool(self->up1D->result);
181}
182
183/*----------------------UnaryPredicate1D get/setters ----------------------------*/
184
186 /* Wrap. */
187 UnaryPredicate1D_name_doc,
188 "The name of the unary 1D predicate.\n"
189 "\n"
190 ":type: str\n");
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
PyTypeObject ContourUP1D_Type
PyObject * PyBool_from_bool(bool b)
PyTypeObject DensityLowerThanUP1D_Type
PyTypeObject EqualToChainingTimeStampUP1D_Type
PyTypeObject EqualToTimeStampUP1D_Type
PyTypeObject ExternalContourUP1D_Type
PyDoc_STRVAR(FalseBP1D___doc__, "Class hierarchy: :class:`freestyle.types.BinaryPredicate1D` > :class:`FalseBP1D`\n" "\n" ".. method:: __call__(inter1, inter2)\n" "\n" " Always returns false.\n" "\n" " :param inter1: The first Interface1D object.\n" " :type inter1: :class:`freestyle.types.Interface1D`\n" " :param inter2: The second Interface1D object.\n" " :type inter2: :class:`freestyle.types.Interface1D`\n" " :return: False.\n" " :rtype: bool\n")
PyTypeObject FalseUP1D_Type
PyTypeObject Interface1D_Type
PyTypeObject QuantitativeInvisibilityUP1D_Type
PyTypeObject ShapeUP1D_Type
PyTypeObject TrueUP1D_Type
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
inherits from class Rep
Definition AppCanvas.cpp:20
PyObject_HEAD Freestyle::UnaryPredicate1D * up1D