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