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