Blender V4.3
BPy_AdjacencyIterator.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"
13
14#ifdef __cplusplus
15extern "C" {
16#endif
17
18using namespace Freestyle;
19
21
22//------------------------INSTANCE METHODS ----------------------------------
23
25 /* Wrap. */
26 AdjacencyIterator_doc,
27 "Class hierarchy: :class:`Iterator` > :class:`AdjacencyIterator`\n"
28 "\n"
29 "Class for representing adjacency iterators used in the chaining\n"
30 "process. An AdjacencyIterator is created in the increment() and\n"
31 "decrement() methods of a :class:`ChainingIterator` and passed to the\n"
32 "traverse() method of the ChainingIterator.\n"
33 "\n"
34 ".. method:: __init__()\n"
35 " __init__(brother)\n"
36 " __init__(vertex, restrict_to_selection=True, restrict_to_unvisited=True)\n"
37 "\n"
38 " Builds an :class:`AdjacencyIterator` using the default constructor,\n"
39 " copy constructor or the overloaded constructor.\n"
40 "\n"
41 " :arg brother: An AdjacencyIterator object.\n"
42 " :type brother: :class:`AdjacencyIterator`\n"
43 " :arg vertex: The vertex which is the next crossing.\n"
44 " :type vertex: :class:`ViewVertex`\n"
45 " :arg restrict_to_selection: Indicates whether to force the chaining\n"
46 " to stay within the set of selected ViewEdges or not.\n"
47 " :type restrict_to_selection: bool\n"
48 " :arg restrict_to_unvisited: Indicates whether a ViewEdge that has\n"
49 " already been chained must be ignored ot not.\n"
50 " :type restrict_to_unvisited: bool");
51
52static int AdjacencyIterator_init(BPy_AdjacencyIterator *self, PyObject *args, PyObject *kwds)
53{
54 static const char *kwlist_1[] = {"brother", nullptr};
55 static const char *kwlist_2[] = {
56 "vertex", "restrict_to_selection", "restrict_to_unvisited", nullptr};
57 PyObject *obj1 = nullptr, *obj2 = nullptr, *obj3 = nullptr;
58
59 if (PyArg_ParseTupleAndKeywords(
60 args, kwds, "|O!", (char **)kwlist_1, &AdjacencyIterator_Type, &obj1))
61 {
62 if (!obj1) {
63 self->a_it = new AdjacencyIterator();
64 self->at_start = true;
65 }
66 else {
67 self->a_it = new AdjacencyIterator(*(((BPy_AdjacencyIterator *)obj1)->a_it));
68 self->at_start = ((BPy_AdjacencyIterator *)obj1)->at_start;
69 }
70 }
71 else if ((void)PyErr_Clear(),
72 (void)(obj2 = obj3 = nullptr),
73 PyArg_ParseTupleAndKeywords(args,
74 kwds,
75 "O!|O!O!",
76 (char **)kwlist_2,
78 &obj1,
79 &PyBool_Type,
80 &obj2,
81 &PyBool_Type,
82 &obj3))
83 {
84 bool restrictToSelection = (!obj2) ? true : bool_from_PyBool(obj2);
85 bool restrictToUnvisited = (!obj3) ? true : bool_from_PyBool(obj3);
86 self->a_it = new AdjacencyIterator(
87 ((BPy_ViewVertex *)obj1)->vv, restrictToSelection, restrictToUnvisited);
88 self->at_start = ((BPy_AdjacencyIterator *)obj1)->at_start;
89 }
90 else {
91 PyErr_SetString(PyExc_TypeError, "invalid argument(s)");
92 return -1;
93 }
94 self->py_it.it = self->a_it;
95 return 0;
96}
97
99{
100 Py_INCREF(self);
101 self->at_start = true;
102 return (PyObject *)self;
103}
104
106{
107 if (self->a_it->isEnd()) {
108 PyErr_SetNone(PyExc_StopIteration);
109 return nullptr;
110 }
111 if (self->at_start) {
112 self->at_start = false;
113 }
114 else {
115 self->a_it->increment();
116 if (self->a_it->isEnd()) {
117 PyErr_SetNone(PyExc_StopIteration);
118 return nullptr;
119 }
120 }
121 ViewEdge *ve = self->a_it->operator->();
122 return BPy_ViewEdge_from_ViewEdge(*ve);
123}
124
125/*----------------------AdjacencyIterator get/setters ----------------------------*/
126
128 /* Wrap. */
129 AdjacencyIterator_object_doc,
130 "The ViewEdge object currently pointed to by this iterator.\n"
131 "\n"
132 ":type: :class:`ViewEdge`");
133
134static PyObject *AdjacencyIterator_object_get(BPy_AdjacencyIterator *self, void * /*closure*/)
135{
136 if (self->a_it->isEnd()) {
137 PyErr_SetString(PyExc_RuntimeError, "iteration has stopped");
138 return nullptr;
139 }
140 ViewEdge *ve = self->a_it->operator*();
141 if (ve) {
142 return BPy_ViewEdge_from_ViewEdge(*ve);
143 }
144 Py_RETURN_NONE;
145}
146
148 /* Wrap. */
149 AdjacencyIterator_is_incoming_doc,
150 "True if the current ViewEdge is coming towards the iteration vertex, and\n"
151 "False otherwise.\n"
152 "\n"
153 ":type: bool");
154
156{
157 if (self->a_it->isEnd()) {
158 PyErr_SetString(PyExc_RuntimeError, "iteration has stopped");
159 return nullptr;
160 }
161 return PyBool_from_bool(self->a_it->isIncoming());
162}
163
164static PyGetSetDef BPy_AdjacencyIterator_getseters[] = {
165 {"is_incoming",
167 (setter) nullptr,
168 AdjacencyIterator_is_incoming_doc,
169 nullptr},
170 {"object",
172 (setter) nullptr,
173 AdjacencyIterator_object_doc,
174 nullptr},
175 {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
176};
177
178/*-----------------------BPy_AdjacencyIterator type definition ------------------------------*/
179
181 /*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
182 /*tp_name*/ "AdjacencyIterator",
183 /*tp_basicsize*/ sizeof(BPy_AdjacencyIterator),
184 /*tp_itemsize*/ 0,
185 /*tp_dealloc*/ nullptr,
186 /*tp_vectorcall_offset*/ 0,
187 /*tp_getattr*/ nullptr,
188 /*tp_setattr*/ nullptr,
189 /*tp_as_async*/ nullptr,
190 /*tp_repr*/ nullptr,
191 /*tp_as_number*/ nullptr,
192 /*tp_as_sequence*/ nullptr,
193 /*tp_as_mapping*/ nullptr,
194 /*tp_hash*/ nullptr,
195 /*tp_call*/ nullptr,
196 /*tp_str*/ nullptr,
197 /*tp_getattro*/ nullptr,
198 /*tp_setattro*/ nullptr,
199 /*tp_as_buffer*/ nullptr,
200 /*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
201 /*tp_doc*/ AdjacencyIterator_doc,
202 /*tp_traverse*/ nullptr,
203 /*tp_clear*/ nullptr,
204 /*tp_richcompare*/ nullptr,
205 /*tp_weaklistoffset*/ 0,
206 /*tp_iter*/ (getiterfunc)AdjacencyIterator_iter,
207 /*tp_iternext*/ (iternextfunc)AdjacencyIterator_iternext,
208 /*tp_methods*/ nullptr,
209 /*tp_members*/ nullptr,
211 /*tp_base*/ &Iterator_Type,
212 /*tp_dict*/ nullptr,
213 /*tp_descr_get*/ nullptr,
214 /*tp_descr_set*/ nullptr,
215 /*tp_dictoffset*/ 0,
216 /*tp_init*/ (initproc)AdjacencyIterator_init,
217 /*tp_alloc*/ nullptr,
218 /*tp_new*/ nullptr,
219};
220
222
223#ifdef __cplusplus
224}
225#endif
PyDoc_STRVAR(AdjacencyIterator_doc, "Class hierarchy: :class:`Iterator` > :class:`AdjacencyIterator`\n" "\n" "Class for representing adjacency iterators used in the chaining\n" "process. An AdjacencyIterator is created in the increment() and\n" "decrement() methods of a :class:`ChainingIterator` and passed to the\n" "traverse() method of the ChainingIterator.\n" "\n" ".. method:: __init__()\n" " __init__(brother)\n" " __init__(vertex, restrict_to_selection=True, restrict_to_unvisited=True)\n" "\n" " Builds an :class:`AdjacencyIterator` using the default constructor,\n" " copy constructor or the overloaded constructor.\n" "\n" " :arg brother: An AdjacencyIterator object.\n" " :type brother: :class:`AdjacencyIterator`\n" " :arg vertex: The vertex which is the next crossing.\n" " :type vertex: :class:`ViewVertex`\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")
static PyObject * AdjacencyIterator_iternext(BPy_AdjacencyIterator *self)
static PyObject * AdjacencyIterator_iter(BPy_AdjacencyIterator *self)
PyTypeObject AdjacencyIterator_Type
static int AdjacencyIterator_init(BPy_AdjacencyIterator *self, PyObject *args, PyObject *kwds)
static PyObject * AdjacencyIterator_is_incoming_get(BPy_AdjacencyIterator *self, void *)
static PyObject * AdjacencyIterator_object_get(BPy_AdjacencyIterator *self, void *)
static PyGetSetDef BPy_AdjacencyIterator_getseters[]
bool bool_from_PyBool(PyObject *b)
PyObject * BPy_ViewEdge_from_ViewEdge(ViewEdge &ve)
PyObject * PyBool_from_bool(bool b)
PyTypeObject Iterator_Type
PyTypeObject ViewVertex_Type
PyObject * self
inherits from class Rep
Definition AppCanvas.cpp:20