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