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