Blender V5.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
8
10
11#include "BPy_Convert.h"
12#include "BPy_Interface1D.h"
13
19
20using namespace Freestyle;
21
23
24//-------------------MODULE INITIALIZATION--------------------------------
25int BinaryPredicate1D_Init(PyObject *module)
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 " :param inter1: The first Interface1D object.\n"
86 " :type inter1: :class:`Interface1D`\n"
87 " :param 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(args,
122 kwds,
123 "O!" /* `inter1` */
124 "O!" /* `inter2` */
125 ":__call__",
126 (char **)kwlist,
128 &obj1,
130 &obj2))
131 {
132 return nullptr;
133 }
134 if (typeid(*(self->bp1D)) == typeid(BinaryPredicate1D)) {
135 PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden");
136 return nullptr;
137 }
138 if (self->bp1D->operator()(*(obj1->if1D), *(obj2->if1D)) < 0) {
139 if (!PyErr_Occurred()) {
140 string class_name(Py_TYPE(self)->tp_name);
141 PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str());
142 }
143 return nullptr;
144 }
145 return PyBool_from_bool(self->bp1D->result);
146}
147
148/*----------------------BinaryPredicate0D get/setters ----------------------------*/
149
151 /* Wrap. */
152 BinaryPredicate1D_name_doc,
153 "The name of the binary 1D predicate.\n"
154 "\n"
155 ":type: str\n");
156static PyObject *BinaryPredicate1D_name_get(BPy_BinaryPredicate1D *self, void * /*closure*/)
157{
158 return PyUnicode_FromString(Py_TYPE(self)->tp_name);
159}
160
161static PyGetSetDef BPy_BinaryPredicate1D_getseters[] = {
162 {"name",
164 (setter) nullptr,
165 BinaryPredicate1D_name_doc,
166 nullptr},
167 {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
168};
169
170/*-----------------------BPy_BinaryPredicate1D type definition ------------------------------*/
171
173 /*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
174 /*tp_name*/ "BinaryPredicate1D",
175 /*tp_basicsize*/ sizeof(BPy_BinaryPredicate1D),
176 /*tp_itemsize*/ 0,
177 /*tp_dealloc*/ (destructor)BinaryPredicate1D___dealloc__,
178 /*tp_vectorcall_offset*/ 0,
179 /*tp_getattr*/ nullptr,
180 /*tp_setattr*/ nullptr,
181 /*tp_as_async*/ nullptr,
182 /*tp_repr*/ (reprfunc)BinaryPredicate1D___repr__,
183 /*tp_as_number*/ nullptr,
184 /*tp_as_sequence*/ nullptr,
185 /*tp_as_mapping*/ nullptr,
186 /*tp_hash*/ nullptr,
187 /*tp_call*/ (ternaryfunc)BinaryPredicate1D___call__,
188 /*tp_str*/ nullptr,
189 /*tp_getattro*/ nullptr,
190 /*tp_setattro*/ nullptr,
191 /*tp_as_buffer*/ nullptr,
192 /*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
193 /*tp_doc*/ BinaryPredicate1D___doc__,
194 /*tp_traverse*/ nullptr,
195 /*tp_clear*/ nullptr,
196 /*tp_richcompare*/ nullptr,
197 /*tp_weaklistoffset*/ 0,
198 /*tp_iter*/ nullptr,
199 /*tp_iternext*/ nullptr,
200 /*tp_methods*/ nullptr,
201 /*tp_members*/ nullptr,
203 /*tp_base*/ nullptr,
204 /*tp_dict*/ nullptr,
205 /*tp_descr_get*/ nullptr,
206 /*tp_descr_set*/ nullptr,
207 /*tp_dictoffset*/ 0,
208 /*tp_init*/ (initproc)BinaryPredicate1D___init__,
209 /*tp_alloc*/ nullptr,
210 /*tp_new*/ PyType_GenericNew,
211};
212
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
PyDoc_STRVAR(FalseBP1D___doc__, "Class hierarchy: :class:`freestyle.types.BinaryPredicate1D` > :class:`FalseBP1D`\n" "\n" ".. method:: __call__(inter1, inter2)\n" "\n" " Always returns false.\n" "\n" " :param inter1: The first Interface1D object.\n" " :type inter1: :class:`freestyle.types.Interface1D`\n" " :param inter2: The second Interface1D object.\n" " :type inter2: :class:`freestyle.types.Interface1D`\n" " :return: False.\n" " :rtype: bool\n")
PyTypeObject Interface1D_Type
PyTypeObject Length2DBP1D_Type
PyTypeObject SameShapeIdBP1D_Type
PyTypeObject TrueBP1D_Type
PyTypeObject ViewMapGradientNormBP1D_Type
inherits from class Rep
Definition AppCanvas.cpp:20
PyObject_HEAD Freestyle::BinaryPredicate1D * bp1D
PyObject_HEAD Freestyle::Interface1D * if1D