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