Blender  V2.93
BPy_BinaryPredicate1D.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_BinaryPredicate1D.h"
22 
23 #include "BPy_Convert.h"
24 #include "BPy_Interface1D.h"
25 
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 using namespace Freestyle;
37 
39 
40 //-------------------MODULE INITIALIZATION--------------------------------
42 {
43  if (module == nullptr) {
44  return -1;
45  }
46 
47  if (PyType_Ready(&BinaryPredicate1D_Type) < 0) {
48  return -1;
49  }
50  Py_INCREF(&BinaryPredicate1D_Type);
51  PyModule_AddObject(module, "BinaryPredicate1D", (PyObject *)&BinaryPredicate1D_Type);
52 
53  if (PyType_Ready(&FalseBP1D_Type) < 0) {
54  return -1;
55  }
56  Py_INCREF(&FalseBP1D_Type);
57  PyModule_AddObject(module, "FalseBP1D", (PyObject *)&FalseBP1D_Type);
58 
59  if (PyType_Ready(&Length2DBP1D_Type) < 0) {
60  return -1;
61  }
62  Py_INCREF(&Length2DBP1D_Type);
63  PyModule_AddObject(module, "Length2DBP1D", (PyObject *)&Length2DBP1D_Type);
64 
65  if (PyType_Ready(&SameShapeIdBP1D_Type) < 0) {
66  return -1;
67  }
68  Py_INCREF(&SameShapeIdBP1D_Type);
69  PyModule_AddObject(module, "SameShapeIdBP1D", (PyObject *)&SameShapeIdBP1D_Type);
70 
71  if (PyType_Ready(&TrueBP1D_Type) < 0) {
72  return -1;
73  }
74  Py_INCREF(&TrueBP1D_Type);
75  PyModule_AddObject(module, "TrueBP1D", (PyObject *)&TrueBP1D_Type);
76 
77  if (PyType_Ready(&ViewMapGradientNormBP1D_Type) < 0) {
78  return -1;
79  }
80  Py_INCREF(&ViewMapGradientNormBP1D_Type);
81  PyModule_AddObject(module, "ViewMapGradientNormBP1D", (PyObject *)&ViewMapGradientNormBP1D_Type);
82 
83  return 0;
84 }
85 
86 //------------------------INSTANCE METHODS ----------------------------------
87 
89  "Base class for binary predicates working on :class:`Interface1D`\n"
90  "objects. A BinaryPredicate1D is typically an ordering relation\n"
91  "between two Interface1D objects. The predicate evaluates a relation\n"
92  "between the two Interface1D instances and returns a boolean value (true\n"
93  "or false). It is used by invoking the __call__() method.\n"
94  "\n"
95  ".. method:: __init__()\n"
96  "\n"
97  " Default constructor.\n"
98  "\n"
99  ".. method:: __call__(inter1, inter2)\n"
100  "\n"
101  " Must be overload by inherited classes. It evaluates a relation\n"
102  " between two Interface1D objects.\n"
103  "\n"
104  " :arg inter1: The first Interface1D object.\n"
105  " :type inter1: :class:`Interface1D`\n"
106  " :arg inter2: The second Interface1D object.\n"
107  " :type inter2: :class:`Interface1D`\n"
108  " :return: True or false.\n"
109  " :rtype: bool\n";
110 
111 static int BinaryPredicate1D___init__(BPy_BinaryPredicate1D *self, PyObject *args, PyObject *kwds)
112 {
113  static const char *kwlist[] = {nullptr};
114 
115  if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) {
116  return -1;
117  }
118  self->bp1D = new BinaryPredicate1D();
119  self->bp1D->py_bp1D = (PyObject *)self;
120  return 0;
121 }
122 
124 {
125  delete self->bp1D;
126  Py_TYPE(self)->tp_free((PyObject *)self);
127 }
128 
130 {
131  return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->bp1D);
132 }
133 
135  PyObject *args,
136  PyObject *kwds)
137 {
138  static const char *kwlist[] = {"inter1", "inter2", nullptr};
139  BPy_Interface1D *obj1, *obj2;
140 
141  if (!PyArg_ParseTupleAndKeywords(args,
142  kwds,
143  "O!O!",
144  (char **)kwlist,
146  &obj1,
148  &obj2)) {
149  return nullptr;
150  }
151  if (typeid(*(self->bp1D)) == typeid(BinaryPredicate1D)) {
152  PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden");
153  return nullptr;
154  }
155  if (self->bp1D->operator()(*(obj1->if1D), *(obj2->if1D)) < 0) {
156  if (!PyErr_Occurred()) {
157  string class_name(Py_TYPE(self)->tp_name);
158  PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str());
159  }
160  return nullptr;
161  }
162  return PyBool_from_bool(self->bp1D->result);
163 }
164 
165 /*----------------------BinaryPredicate0D get/setters ----------------------------*/
166 
167 PyDoc_STRVAR(BinaryPredicate1D_name_doc,
168  "The name of the binary 1D predicate.\n"
169  "\n"
170  ":type: str");
171 
172 static PyObject *BinaryPredicate1D_name_get(BPy_BinaryPredicate1D *self, void *UNUSED(closure))
173 {
174  return PyUnicode_FromString(Py_TYPE(self)->tp_name);
175 }
176 
177 static PyGetSetDef BPy_BinaryPredicate1D_getseters[] = {
178  {"name",
180  (setter) nullptr,
181  BinaryPredicate1D_name_doc,
182  nullptr},
183  {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
184 };
185 
186 /*-----------------------BPy_BinaryPredicate1D type definition ------------------------------*/
187 PyTypeObject BinaryPredicate1D_Type = {
188  PyVarObject_HEAD_INIT(nullptr, 0) "BinaryPredicate1D", /* tp_name */
189  sizeof(BPy_BinaryPredicate1D), /* tp_basicsize */
190  0, /* tp_itemsize */
191  (destructor)BinaryPredicate1D___dealloc__, /* tp_dealloc */
192  0, /* tp_vectorcall_offset */
193  nullptr, /* tp_getattr */
194  nullptr, /* tp_setattr */
195  nullptr, /* tp_reserved */
196  (reprfunc)BinaryPredicate1D___repr__, /* tp_repr */
197  nullptr, /* tp_as_number */
198  nullptr, /* tp_as_sequence */
199  nullptr, /* tp_as_mapping */
200  nullptr, /* tp_hash */
201  (ternaryfunc)BinaryPredicate1D___call__, /* tp_call */
202  nullptr, /* tp_str */
203  nullptr, /* tp_getattro */
204  nullptr, /* tp_setattro */
205  nullptr, /* tp_as_buffer */
206  Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
207  BinaryPredicate1D___doc__, /* tp_doc */
208  nullptr, /* tp_traverse */
209  nullptr, /* tp_clear */
210  nullptr, /* tp_richcompare */
211  0, /* tp_weaklistoffset */
212  nullptr, /* tp_iter */
213  nullptr, /* tp_iternext */
214  nullptr, /* tp_methods */
215  nullptr, /* tp_members */
216  BPy_BinaryPredicate1D_getseters, /* tp_getset */
217  nullptr, /* tp_base */
218  nullptr, /* tp_dict */
219  nullptr, /* tp_descr_get */
220  nullptr, /* tp_descr_set */
221  0, /* tp_dictoffset */
222  (initproc)BinaryPredicate1D___init__, /* tp_init */
223  nullptr, /* tp_alloc */
224  PyType_GenericNew, /* tp_new */
225 };
226 
228 
229 #ifdef __cplusplus
230 }
231 #endif
#define UNUSED(x)
static PyGetSetDef BPy_BinaryPredicate1D_getseters[]
static char BinaryPredicate1D___doc__[]
int BinaryPredicate1D_Init(PyObject *module)
PyTypeObject BinaryPredicate1D_Type
static PyObject * BinaryPredicate1D___repr__(BPy_BinaryPredicate1D *self)
static PyObject * BinaryPredicate1D_name_get(BPy_BinaryPredicate1D *self, void *UNUSED(closure))
PyDoc_STRVAR(BinaryPredicate1D_name_doc, "The name of the binary 1D predicate.\n" "\n" ":type: str")
static int BinaryPredicate1D___init__(BPy_BinaryPredicate1D *self, PyObject *args, PyObject *kwds)
static PyObject * BinaryPredicate1D___call__(BPy_BinaryPredicate1D *self, PyObject *args, PyObject *kwds)
static void BinaryPredicate1D___dealloc__(BPy_BinaryPredicate1D *self)
PyObject * PyBool_from_bool(bool b)
Definition: BPy_Convert.cpp:73
PyTypeObject FalseBP1D_Type
PyTypeObject Interface1D_Type
PyTypeObject Length2DBP1D_Type
PyTypeObject SameShapeIdBP1D_Type
PyTypeObject TrueBP1D_Type
PyTypeObject ViewMapGradientNormBP1D_Type
static struct PyModuleDef module
PyObject * self
Definition: bpy_driver.c:185
inherits from class Rep
Definition: AppCanvas.cpp:32
PyObject_HEAD Freestyle::Interface1D * if1D