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