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