Blender  V2.93
BPy_BinaryPredicate0D.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_BinaryPredicate0D.h"
22 
23 #include "BPy_Convert.h"
24 #include "BPy_Interface0D.h"
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 using namespace Freestyle;
31 
33 
34 //-------------------MODULE INITIALIZATION--------------------------------
36 {
37  if (module == nullptr) {
38  return -1;
39  }
40 
41  if (PyType_Ready(&BinaryPredicate0D_Type) < 0) {
42  return -1;
43  }
44  Py_INCREF(&BinaryPredicate0D_Type);
45  PyModule_AddObject(module, "BinaryPredicate0D", (PyObject *)&BinaryPredicate0D_Type);
46 
47  return 0;
48 }
49 
50 //------------------------INSTANCE METHODS ----------------------------------
51 
53  "Base class for binary predicates working on :class:`Interface0D`\n"
54  "objects. A BinaryPredicate0D is typically an ordering relation\n"
55  "between two Interface0D objects. The predicate evaluates a relation\n"
56  "between the two Interface0D instances and returns a boolean value (true\n"
57  "or false). It is used by invoking the __call__() method.\n"
58  "\n"
59  ".. method:: __init__()\n"
60  "\n"
61  " Default constructor.\n"
62  "\n"
63  ".. method:: __call__(inter1, inter2)\n"
64  "\n"
65  " Must be overload by inherited classes. It evaluates a relation\n"
66  " between two Interface0D objects.\n"
67  "\n"
68  " :arg inter1: The first Interface0D object.\n"
69  " :type inter1: :class:`Interface0D`\n"
70  " :arg inter2: The second Interface0D object.\n"
71  " :type inter2: :class:`Interface0D`\n"
72  " :return: True or false.\n"
73  " :rtype: bool\n";
74 
75 static int BinaryPredicate0D___init__(BPy_BinaryPredicate0D *self, PyObject *args, PyObject *kwds)
76 {
77  static const char *kwlist[] = {nullptr};
78 
79  if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) {
80  return -1;
81  }
82  self->bp0D = new BinaryPredicate0D();
83  self->bp0D->py_bp0D = (PyObject *)self;
84  return 0;
85 }
86 
88 {
89  delete self->bp0D;
90 
91  Py_TYPE(self)->tp_free((PyObject *)self);
92 }
93 
95 {
96  return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->bp0D);
97 }
98 
100  PyObject *args,
101  PyObject *kwds)
102 {
103  static const char *kwlist[] = {"inter1", "inter2", nullptr};
104  BPy_Interface0D *obj1, *obj2;
105 
106  if (!PyArg_ParseTupleAndKeywords(args,
107  kwds,
108  "O!O!",
109  (char **)kwlist,
111  &obj1,
113  &obj2)) {
114  return nullptr;
115  }
116  if (typeid(*(self->bp0D)) == typeid(BinaryPredicate0D)) {
117  PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden");
118  return nullptr;
119  }
120  if (self->bp0D->operator()(*(obj1->if0D), *(obj2->if0D)) < 0) {
121  if (!PyErr_Occurred()) {
122  string class_name(Py_TYPE(self)->tp_name);
123  PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str());
124  }
125  return nullptr;
126  }
127  return PyBool_from_bool(self->bp0D->result);
128 }
129 
130 /*----------------------BinaryPredicate0D get/setters ----------------------------*/
131 
132 PyDoc_STRVAR(BinaryPredicate0D_name_doc,
133  "The name of the binary 0D predicate.\n"
134  "\n"
135  ":type: str");
136 
137 static PyObject *BinaryPredicate0D_name_get(BPy_BinaryPredicate0D *self, void *UNUSED(closure))
138 {
139  return PyUnicode_FromString(Py_TYPE(self)->tp_name);
140 }
141 
142 static PyGetSetDef BPy_BinaryPredicate0D_getseters[] = {
143  {"name",
145  (setter) nullptr,
146  BinaryPredicate0D_name_doc,
147  nullptr},
148  {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
149 };
150 
151 /*-----------------------BPy_BinaryPredicate0D type definition ------------------------------*/
152 
153 PyTypeObject BinaryPredicate0D_Type = {
154  PyVarObject_HEAD_INIT(nullptr, 0) "BinaryPredicate0D", /* tp_name */
155  sizeof(BPy_BinaryPredicate0D), /* tp_basicsize */
156  0, /* tp_itemsize */
157  (destructor)BinaryPredicate0D___dealloc__, /* tp_dealloc */
158  0, /* tp_vectorcall_offset */
159  nullptr, /* tp_getattr */
160  nullptr, /* tp_setattr */
161  nullptr, /* tp_reserved */
162  (reprfunc)BinaryPredicate0D___repr__, /* tp_repr */
163  nullptr, /* tp_as_number */
164  nullptr, /* tp_as_sequence */
165  nullptr, /* tp_as_mapping */
166  nullptr, /* tp_hash */
167  (ternaryfunc)BinaryPredicate0D___call__, /* tp_call */
168  nullptr, /* tp_str */
169  nullptr, /* tp_getattro */
170  nullptr, /* tp_setattro */
171  nullptr, /* tp_as_buffer */
172  Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
173  BinaryPredicate0D___doc__, /* tp_doc */
174  nullptr, /* tp_traverse */
175  nullptr, /* tp_clear */
176  nullptr, /* tp_richcompare */
177  0, /* tp_weaklistoffset */
178  nullptr, /* tp_iter */
179  nullptr, /* tp_iternext */
180  nullptr, /* tp_methods */
181  nullptr, /* tp_members */
182  BPy_BinaryPredicate0D_getseters, /* tp_getset */
183  nullptr, /* tp_base */
184  nullptr, /* tp_dict */
185  nullptr, /* tp_descr_get */
186  nullptr, /* tp_descr_set */
187  0, /* tp_dictoffset */
188  (initproc)BinaryPredicate0D___init__, /* tp_init */
189  nullptr, /* tp_alloc */
190  PyType_GenericNew, /* tp_new */
191 };
192 
194 
195 #ifdef __cplusplus
196 }
197 #endif
#define UNUSED(x)
static PyObject * BinaryPredicate0D___repr__(BPy_BinaryPredicate0D *self)
PyTypeObject BinaryPredicate0D_Type
PyDoc_STRVAR(BinaryPredicate0D_name_doc, "The name of the binary 0D predicate.\n" "\n" ":type: str")
static void BinaryPredicate0D___dealloc__(BPy_BinaryPredicate0D *self)
static int BinaryPredicate0D___init__(BPy_BinaryPredicate0D *self, PyObject *args, PyObject *kwds)
static PyGetSetDef BPy_BinaryPredicate0D_getseters[]
static char BinaryPredicate0D___doc__[]
static PyObject * BinaryPredicate0D_name_get(BPy_BinaryPredicate0D *self, void *UNUSED(closure))
static PyObject * BinaryPredicate0D___call__(BPy_BinaryPredicate0D *self, PyObject *args, PyObject *kwds)
int BinaryPredicate0D_Init(PyObject *module)
PyObject * PyBool_from_bool(bool b)
Definition: BPy_Convert.cpp:73
PyTypeObject Interface0D_Type
static struct PyModuleDef module
PyObject * self
Definition: bpy_driver.c:185
inherits from class Rep
Definition: AppCanvas.cpp:32
PyObject_HEAD Freestyle::Interface0D * if0D