Blender V5.3
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__(*args)\n"
42 "\n"
43 " Accepted call signatures:\n"
44 "\n"
45 " - ``__init__(upred, bpred, restrict_to_selection=True, restrict_to_unvisited=True, "
46 "begin=None, orientation=True)``\n"
47 " - ``__init__(brother)``\n"
48 "\n"
49 " Builds a ChainPredicateIterator from a unary predicate, a binary\n"
50 " predicate, a starting ViewEdge and its orientation or using the copy constructor.\n"
51 "\n"
52 " :param upred: The unary predicate that the next ViewEdge must satisfy.\n"
53 " :type upred: :class:`freestyle.types.UnaryPredicate1D`\n"
54 " :param bpred: The binary predicate that the next ViewEdge must\n"
55 " satisfy together with the actual pointed ViewEdge.\n"
56 " :type bpred: :class:`freestyle.types.BinaryPredicate1D`\n"
57 " :param restrict_to_selection: Indicates whether to force the chaining\n"
58 " to stay within the set of selected ViewEdges or not.\n"
59 " :type restrict_to_selection: bool\n"
60 " :param restrict_to_unvisited: Indicates whether a ViewEdge that has\n"
61 " already been chained must be ignored ot not.\n"
62 " :type restrict_to_unvisited: bool\n"
63 " :param begin: The ViewEdge from where to start the iteration.\n"
64 " :type begin: :class:`freestyle.types.ViewEdge` | None\n"
65 " :param orientation: If true, we'll look for the next ViewEdge among\n"
66 " the ViewEdges that surround the ending ViewVertex of begin. If\n"
67 " false, we'll search over the ViewEdges surrounding the ending\n"
68 " ViewVertex of begin.\n"
69 " :type orientation: bool\n"
70 " :param brother: A ChainPredicateIterator object.\n"
71 " :type brother: :class:`ChainPredicateIterator`\n");
72static int check_begin(PyObject *obj, void *v)
73{
74 if (obj != nullptr && obj != Py_None && !BPy_ViewEdge_Check(obj)) {
75 return 0;
76 }
77 *((PyObject **)v) = obj;
78 return 1;
79}
80
82 PyObject *args,
83 PyObject *kwds)
84{
85 static const char *kwlist_1[] = {"brother", nullptr};
86 static const char *kwlist_2[] = {"upred",
87 "bpred",
88 "restrict_to_selection",
89 "restrict_to_unvisited",
90 "begin",
91 "orientation",
92 nullptr};
93 PyObject *obj1 = nullptr, *obj2 = nullptr, *obj3 = nullptr, *obj4 = nullptr, *obj5 = nullptr,
94 *obj6 = nullptr;
95
96 if (PyArg_ParseTupleAndKeywords(args,
97 kwds,
98 "O!" /* `brother` */
99 ":__init__",
100 (char **)kwlist_1,
102 &obj1))
103 {
104 self->cp_it = new ChainPredicateIterator(*(((BPy_ChainPredicateIterator *)obj1)->cp_it));
105 self->upred = ((BPy_ChainPredicateIterator *)obj1)->upred;
106 self->bpred = ((BPy_ChainPredicateIterator *)obj1)->bpred;
107 Py_INCREF(self->upred);
108 Py_INCREF(self->bpred);
109 }
110 else if ((void)PyErr_Clear(),
111 (void)(obj3 = obj4 = obj5 = obj6 = nullptr),
112 PyArg_ParseTupleAndKeywords(args,
113 kwds,
114 "O!" /* `upred` */
115 "O!" /* `bpred` */
116 "|" /* Optional arguments. */
117 "O!" /* `restrict_to_selection` */
118 "O!" /* `restrict_to_unvisited` */
119 "O&" /* `begin` */
120 "O!" /* `orientation` */
121 ":__init__",
122 (char **)kwlist_2,
124 &obj1,
126 &obj2,
127 &PyBool_Type,
128 &obj3,
129 &PyBool_Type,
130 &obj4,
132 &obj5,
133 &PyBool_Type,
134 &obj6))
135 {
136 UnaryPredicate1D *up1D = ((BPy_UnaryPredicate1D *)obj1)->up1D;
137 BinaryPredicate1D *bp1D = ((BPy_BinaryPredicate1D *)obj2)->bp1D;
138 bool restrict_to_selection = (!obj3) ? true : bool_from_PyBool(obj3);
139 bool restrict_to_unvisited = (!obj4) ? true : bool_from_PyBool(obj4);
140 ViewEdge *begin = (!obj5 || obj5 == Py_None) ? nullptr : ((BPy_ViewEdge *)obj5)->ve;
141 bool orientation = (!obj6) ? true : bool_from_PyBool(obj6);
142 self->cp_it = new ChainPredicateIterator(
143 *up1D, *bp1D, restrict_to_selection, restrict_to_unvisited, begin, orientation);
144 self->upred = obj1;
145 self->bpred = obj2;
146 Py_INCREF(self->upred);
147 Py_INCREF(self->bpred);
148 }
149 else {
150 PyErr_SetString(PyExc_TypeError, "invalid argument(s)");
151 return -1;
152 }
153 self->py_c_it.c_it = self->cp_it;
154 self->py_c_it.py_ve_it.ve_it = self->cp_it;
155 self->py_c_it.py_ve_it.py_it.it = self->cp_it;
156 return 0;
157}
158
160{
161 Py_XDECREF(self->upred);
162 Py_XDECREF(self->bpred);
163 ChainingIterator_Type.tp_dealloc((PyObject *)self);
164}
165
166/*-----------------------BPy_ChainPredicateIterator type definition ----------------------------*/
167
169 /*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
170 /*tp_name*/ "ChainPredicateIterator",
171 /*tp_basicsize*/ sizeof(BPy_ChainPredicateIterator),
172 /*tp_itemsize*/ 0,
173 /*tp_dealloc*/ (destructor)ChainPredicateIterator_dealloc,
174 /*tp_vectorcall_offset*/ 0,
175 /*tp_getattr*/ nullptr,
176 /*tp_setattr*/ nullptr,
177 /*tp_as_async*/ nullptr,
178 /*tp_repr*/ nullptr,
179 /*tp_as_number*/ nullptr,
180 /*tp_as_sequence*/ nullptr,
181 /*tp_as_mapping*/ nullptr,
182 /*tp_hash*/ nullptr,
183 /*tp_call*/ nullptr,
184 /*tp_str*/ nullptr,
185 /*tp_getattro*/ nullptr,
186 /*tp_setattro*/ nullptr,
187 /*tp_as_buffer*/ nullptr,
188 /*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
189 /*tp_doc*/ ChainPredicateIterator_doc,
190 /*tp_traverse*/ nullptr,
191 /*tp_clear*/ nullptr,
192 /*tp_richcompare*/ nullptr,
193 /*tp_weaklistoffset*/ 0,
194 /*tp_iter*/ nullptr,
195 /*tp_iternext*/ nullptr,
196 /*tp_methods*/ nullptr,
197 /*tp_members*/ nullptr,
198 /*tp_getset*/ nullptr,
199 /*tp_base*/ &ChainingIterator_Type,
200 /*tp_dict*/ nullptr,
201 /*tp_descr_get*/ nullptr,
202 /*tp_descr_set*/ nullptr,
203 /*tp_dictoffset*/ 0,
204 /*tp_init*/ (initproc)ChainPredicateIterator_init,
205 /*tp_alloc*/ nullptr,
206 /*tp_new*/ nullptr,
207};
208
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)
static void ChainPredicateIterator_dealloc(BPy_ChainPredicateIterator *self)
PyTypeObject ChainingIterator_Type
bool bool_from_PyBool(PyObject *b)
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 UnaryPredicate1D_Type
#define BPy_ViewEdge_Check(v)
ChainPredicateIterator(bool iRestrictToSelection=true, bool iRestrictToUnvisited=true, ViewEdge *begin=nullptr, bool orientation=true)
inherits from class Rep
Definition AppCanvas.cpp:20
Freestyle::ChainPredicateIterator * cp_it
Freestyle::ChainingIterator * c_it
BPy_ViewEdgeIterator py_ve_it
PyObject_HEAD Freestyle::Iterator * it
Freestyle::ViewEdgeInternal::ViewEdgeIterator * ve_it