Blender V5.0
BPy_ChainPredicateIterator.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
12#include "../BPy_Convert.h"
15
16using namespace Freestyle;
17
19
20//------------------------INSTANCE METHODS ----------------------------------
21
23 /* Wrap. */
24 ChainPredicateIterator_doc,
25
26 "Class hierarchy: :class:`freestyle.types.Iterator` >\n"
27 ":class:`freestyle.types.ViewEdgeIterator` >\n"
28 ":class:`freestyle.types.ChainingIterator` >\n"
29 ":class:`ChainPredicateIterator`\n"
30 "\n"
31 "A \"generic\" user-controlled ViewEdge iterator. This iterator is in\n"
32 "particular built from a unary predicate and a binary predicate.\n"
33 "First, the unary predicate is evaluated for all potential next\n"
34 "ViewEdges in order to only keep the ones respecting a certain\n"
35 "constraint. Then, the binary predicate is evaluated on the current\n"
36 "ViewEdge together with each ViewEdge of the previous selection. The\n"
37 "first ViewEdge respecting both the unary predicate and the binary\n"
38 "predicate is kept as the next one. If none of the potential next\n"
39 "ViewEdge respects these two predicates, None is returned.\n"
40 "\n"
41 ".. method:: __init__(upred, bpred, restrict_to_selection=True, "
42 " restrict_to_unvisited=True, begin=None, "
43 " orientation=True)\n"
44 " __init__(brother)\n"
45 "\n"
46 " Builds a ChainPredicateIterator from a unary predicate, a binary\n"
47 " predicate, a starting ViewEdge and its orientation or using the copy constructor.\n"
48 "\n"
49 " :arg upred: The unary predicate that the next ViewEdge must satisfy.\n"
50 " :type upred: :class:`freestyle.types.UnaryPredicate1D`\n"
51 " :arg bpred: The binary predicate that the next ViewEdge must\n"
52 " satisfy together with the actual pointed ViewEdge.\n"
53 " :type bpred: :class:`freestyle.types.BinaryPredicate1D`\n"
54 " :arg restrict_to_selection: Indicates whether to force the chaining\n"
55 " to stay within the set of selected ViewEdges or not.\n"
56 " :type restrict_to_selection: bool\n"
57 " :arg restrict_to_unvisited: Indicates whether a ViewEdge that has\n"
58 " already been chained must be ignored ot not.\n"
59 " :type restrict_to_unvisited: bool\n"
60 " :arg begin: The ViewEdge from where to start the iteration.\n"
61 " :type begin: :class:`freestyle.types.ViewEdge` | None\n"
62 " :arg orientation: If true, we'll look for the next ViewEdge among\n"
63 " the ViewEdges that surround the ending ViewVertex of begin. If\n"
64 " false, we'll search over the ViewEdges surrounding the ending\n"
65 " ViewVertex of begin.\n"
66 " :type orientation: bool\n"
67 " :arg brother: A ChainPredicateIterator object.\n"
68 " :type brother: :class:`ChainPredicateIterator`\n");
69static int check_begin(PyObject *obj, void *v)
70{
71 if (obj != nullptr && obj != Py_None && !BPy_ViewEdge_Check(obj)) {
72 return 0;
73 }
74 *((PyObject **)v) = obj;
75 return 1;
76}
77
79 PyObject *args,
80 PyObject *kwds)
81{
82 static const char *kwlist_1[] = {"brother", nullptr};
83 static const char *kwlist_2[] = {"upred",
84 "bpred",
85 "restrict_to_selection",
86 "restrict_to_unvisited",
87 "begin",
88 "orientation",
89 nullptr};
90 PyObject *obj1 = nullptr, *obj2 = nullptr, *obj3 = nullptr, *obj4 = nullptr, *obj5 = nullptr,
91 *obj6 = nullptr;
92
93 if (PyArg_ParseTupleAndKeywords(
94 args, kwds, "O!", (char **)kwlist_1, &ChainPredicateIterator_Type, &obj1))
95 {
96 self->cp_it = new ChainPredicateIterator(*(((BPy_ChainPredicateIterator *)obj1)->cp_it));
97 self->upred = ((BPy_ChainPredicateIterator *)obj1)->upred;
98 self->bpred = ((BPy_ChainPredicateIterator *)obj1)->bpred;
99 Py_INCREF(self->upred);
100 Py_INCREF(self->bpred);
101 }
102 else if ((void)PyErr_Clear(),
103 (void)(obj3 = obj4 = obj5 = obj6 = nullptr),
104 PyArg_ParseTupleAndKeywords(args,
105 kwds,
106 "O!O!|O!O!O&O!",
107 (char **)kwlist_2,
109 &obj1,
111 &obj2,
112 &PyBool_Type,
113 &obj3,
114 &PyBool_Type,
115 &obj4,
117 &obj5,
118 &PyBool_Type,
119 &obj6))
120 {
121 UnaryPredicate1D *up1D = ((BPy_UnaryPredicate1D *)obj1)->up1D;
122 BinaryPredicate1D *bp1D = ((BPy_BinaryPredicate1D *)obj2)->bp1D;
123 bool restrict_to_selection = (!obj3) ? true : bool_from_PyBool(obj3);
124 bool restrict_to_unvisited = (!obj4) ? true : bool_from_PyBool(obj4);
125 ViewEdge *begin = (!obj5 || obj5 == Py_None) ? nullptr : ((BPy_ViewEdge *)obj5)->ve;
126 bool orientation = (!obj6) ? true : bool_from_PyBool(obj6);
127 self->cp_it = new ChainPredicateIterator(
128 *up1D, *bp1D, restrict_to_selection, restrict_to_unvisited, begin, orientation);
129 self->upred = obj1;
130 self->bpred = obj2;
131 Py_INCREF(self->upred);
132 Py_INCREF(self->bpred);
133 }
134 else {
135 PyErr_SetString(PyExc_TypeError, "invalid argument(s)");
136 return -1;
137 }
138 self->py_c_it.c_it = self->cp_it;
139 self->py_c_it.py_ve_it.ve_it = self->cp_it;
140 self->py_c_it.py_ve_it.py_it.it = self->cp_it;
141 return 0;
142}
143
145{
146 Py_XDECREF(self->upred);
147 Py_XDECREF(self->bpred);
148 ChainingIterator_Type.tp_dealloc((PyObject *)self);
149}
150
151/*-----------------------BPy_ChainPredicateIterator type definition ----------------------------*/
152
154 /*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
155 /*tp_name*/ "ChainPredicateIterator",
156 /*tp_basicsize*/ sizeof(BPy_ChainPredicateIterator),
157 /*tp_itemsize*/ 0,
158 /*tp_dealloc*/ (destructor)ChainPredicateIterator_dealloc,
159 /*tp_vectorcall_offset*/ 0,
160 /*tp_getattr*/ nullptr,
161 /*tp_setattr*/ nullptr,
162 /*tp_as_async*/ nullptr,
163 /*tp_repr*/ nullptr,
164 /*tp_as_number*/ nullptr,
165 /*tp_as_sequence*/ nullptr,
166 /*tp_as_mapping*/ nullptr,
167 /*tp_hash*/ nullptr,
168 /*tp_call*/ nullptr,
169 /*tp_str*/ nullptr,
170 /*tp_getattro*/ nullptr,
171 /*tp_setattro*/ nullptr,
172 /*tp_as_buffer*/ nullptr,
173 /*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
174 /*tp_doc*/ ChainPredicateIterator_doc,
175 /*tp_traverse*/ nullptr,
176 /*tp_clear*/ nullptr,
177 /*tp_richcompare*/ nullptr,
178 /*tp_weaklistoffset*/ 0,
179 /*tp_iter*/ nullptr,
180 /*tp_iternext*/ nullptr,
181 /*tp_methods*/ nullptr,
182 /*tp_members*/ nullptr,
183 /*tp_getset*/ nullptr,
184 /*tp_base*/ &ChainingIterator_Type,
185 /*tp_dict*/ nullptr,
186 /*tp_descr_get*/ nullptr,
187 /*tp_descr_set*/ nullptr,
188 /*tp_dictoffset*/ 0,
189 /*tp_init*/ (initproc)ChainPredicateIterator_init,
190 /*tp_alloc*/ nullptr,
191 /*tp_new*/ nullptr,
192};
193
PyTypeObject BinaryPredicate1D_Type
static int check_begin(PyObject *obj, void *v)
PyTypeObject ChainPredicateIterator_Type
static int ChainPredicateIterator_init(BPy_ChainPredicateIterator *self, PyObject *args, PyObject *kwds)
PyDoc_STRVAR(ChainPredicateIterator_doc, "Class hierarchy: :class:`freestyle.types.Iterator` >\n" ":class:`freestyle.types.ViewEdgeIterator` >\n" ":class:`freestyle.types.ChainingIterator` >\n" ":class:`ChainPredicateIterator`\n" "\n" "A \"generic\" user-controlled ViewEdge iterator. This iterator is in\n" "particular built from a unary predicate and a binary predicate.\n" "First, the unary predicate is evaluated for all potential next\n" "ViewEdges in order to only keep the ones respecting a certain\n" "constraint. Then, the binary predicate is evaluated on the current\n" "ViewEdge together with each ViewEdge of the previous selection. The\n" "first ViewEdge respecting both the unary predicate and the binary\n" "predicate is kept as the next one. If none of the potential next\n" "ViewEdge respects these two predicates, None is returned.\n" "\n" ".. method:: __init__(upred, bpred, restrict_to_selection=True, " " restrict_to_unvisited=True, begin=None, " " orientation=True)\n" " __init__(brother)\n" "\n" " Builds a ChainPredicateIterator from a unary predicate, a binary\n" " predicate, a starting ViewEdge and its orientation or using the copy constructor.\n" "\n" " :arg upred: The unary predicate that the next ViewEdge must satisfy.\n" " :type upred: :class:`freestyle.types.UnaryPredicate1D`\n" " :arg bpred: The binary predicate that the next ViewEdge must\n" " satisfy together with the actual pointed ViewEdge.\n" " :type bpred: :class:`freestyle.types.BinaryPredicate1D`\n" " :arg restrict_to_selection: Indicates whether to force the chaining\n" " to stay within the set of selected ViewEdges or not.\n" " :type restrict_to_selection: bool\n" " :arg restrict_to_unvisited: Indicates whether a ViewEdge that has\n" " already been chained must be ignored ot not.\n" " :type restrict_to_unvisited: bool\n" " :arg begin: The ViewEdge from where to start the iteration.\n" " :type begin: :class:`freestyle.types.ViewEdge` | None\n" " :arg orientation: If true, we'll look for the next ViewEdge among\n" " the ViewEdges that surround the ending ViewVertex of begin. If\n" " false, we'll search over the ViewEdges surrounding the ending\n" " ViewVertex of begin.\n" " :type orientation: bool\n" " :arg brother: A ChainPredicateIterator object.\n" " :type brother: :class:`ChainPredicateIterator`\n")
static void ChainPredicateIterator_dealloc(BPy_ChainPredicateIterator *self)
static int check_begin(PyObject *obj, void *v)
PyTypeObject ChainingIterator_Type
bool bool_from_PyBool(PyObject *b)
PyTypeObject UnaryPredicate1D_Type
#define BPy_ViewEdge_Check(v)
iter begin(iter)
ATTR_WARN_UNUSED_RESULT const BMVert * v
PyObject * self
inherits from class Rep
Definition AppCanvas.cpp:20