Blender V5.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
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__(*args, **kwargs)\n"
31 "\n"
32 " Accepted call signatures:\n"
33 "\n"
34 " - ``__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 " :param brother: An AdjacencyIterator object.\n"
42 " :type brother: :class:`AdjacencyIterator`\n"
43 " :param vertex: The vertex which is the next crossing.\n"
44 " :type vertex: :class:`ViewVertex`\n"
45 " :param 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 " :param 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\n");
51static int AdjacencyIterator_init(BPy_AdjacencyIterator *self, PyObject *args, PyObject *kwds)
52{
53 static const char *kwlist_1[] = {"brother", nullptr};
54 static const char *kwlist_2[] = {
55 "vertex", "restrict_to_selection", "restrict_to_unvisited", nullptr};
56 PyObject *obj1 = nullptr, *obj2 = nullptr, *obj3 = nullptr;
57
58 if (PyArg_ParseTupleAndKeywords(args,
59 kwds,
60 "|" /* Optional arguments. */
61 "O!" /* `brother` */
62 ":__init__",
63 (char **)kwlist_1,
65 &obj1))
66 {
67 if (!obj1) {
68 self->a_it = new AdjacencyIterator();
69 self->at_start = true;
70 }
71 else {
72 self->a_it = new AdjacencyIterator(*(((BPy_AdjacencyIterator *)obj1)->a_it));
73 self->at_start = ((BPy_AdjacencyIterator *)obj1)->at_start;
74 }
75 }
76 else if ((void)PyErr_Clear(),
77 (void)(obj2 = obj3 = nullptr),
78 PyArg_ParseTupleAndKeywords(args,
79 kwds,
80 "O!" /* `vertex` */
81 "|" /* Optional arguments. */
82 "O!" /* `restrict_to_selection` */
83 "O!" /* `restrict_to_unvisited` */
84 ":__init__",
85 (char **)kwlist_2,
87 &obj1,
88 &PyBool_Type,
89 &obj2,
90 &PyBool_Type,
91 &obj3))
92 {
93 bool restrictToSelection = (!obj2) ? true : bool_from_PyBool(obj2);
94 bool restrictToUnvisited = (!obj3) ? true : bool_from_PyBool(obj3);
95 self->a_it = new AdjacencyIterator(
96 ((BPy_ViewVertex *)obj1)->vv, restrictToSelection, restrictToUnvisited);
97 self->at_start = ((BPy_AdjacencyIterator *)obj1)->at_start;
98 }
99 else {
100 PyErr_SetString(PyExc_TypeError, "invalid argument(s)");
101 return -1;
102 }
103 self->py_it.it = self->a_it;
104 return 0;
105}
106
108{
109 Py_INCREF(self);
110 self->at_start = true;
111 return (PyObject *)self;
112}
113
115{
116 if (self->a_it->isEnd()) {
117 PyErr_SetNone(PyExc_StopIteration);
118 return nullptr;
119 }
120 if (self->at_start) {
121 self->at_start = false;
122 }
123 else {
124 self->a_it->increment();
125 if (self->a_it->isEnd()) {
126 PyErr_SetNone(PyExc_StopIteration);
127 return nullptr;
128 }
129 }
130 ViewEdge *ve = self->a_it->operator->();
131 return BPy_ViewEdge_from_ViewEdge(*ve);
132}
133
134/*----------------------AdjacencyIterator get/setters ----------------------------*/
135
137 /* Wrap. */
138 AdjacencyIterator_object_doc,
139 "The ViewEdge object currently pointed to by this iterator.\n"
140 "\n"
141 ":type: :class:`ViewEdge`\n");
142static PyObject *AdjacencyIterator_object_get(BPy_AdjacencyIterator *self, void * /*closure*/)
143{
144 if (self->a_it->isEnd()) {
145 PyErr_SetString(PyExc_RuntimeError, "iteration has stopped");
146 return nullptr;
147 }
148 ViewEdge *ve = self->a_it->operator*();
149 if (ve) {
150 return BPy_ViewEdge_from_ViewEdge(*ve);
151 }
152 Py_RETURN_NONE;
153}
154
156 /* Wrap. */
157 AdjacencyIterator_is_incoming_doc,
158 "True if the current ViewEdge is coming towards the iteration vertex, and\n"
159 "False otherwise.\n"
160 "\n"
161 ":type: bool\n");
162static PyObject *AdjacencyIterator_is_incoming_get(BPy_AdjacencyIterator *self, void * /*closure*/)
163{
164 if (self->a_it->isEnd()) {
165 PyErr_SetString(PyExc_RuntimeError, "iteration has stopped");
166 return nullptr;
167 }
168 return PyBool_from_bool(self->a_it->isIncoming());
169}
170
171static PyGetSetDef BPy_AdjacencyIterator_getseters[] = {
172 {"is_incoming",
174 (setter) nullptr,
175 AdjacencyIterator_is_incoming_doc,
176 nullptr},
177 {"object",
179 (setter) nullptr,
180 AdjacencyIterator_object_doc,
181 nullptr},
182 {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
183};
184
185/*-----------------------BPy_AdjacencyIterator type definition ------------------------------*/
186
188 /*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
189 /*tp_name*/ "AdjacencyIterator",
190 /*tp_basicsize*/ sizeof(BPy_AdjacencyIterator),
191 /*tp_itemsize*/ 0,
192 /*tp_dealloc*/ nullptr,
193 /*tp_vectorcall_offset*/ 0,
194 /*tp_getattr*/ nullptr,
195 /*tp_setattr*/ nullptr,
196 /*tp_as_async*/ nullptr,
197 /*tp_repr*/ nullptr,
198 /*tp_as_number*/ nullptr,
199 /*tp_as_sequence*/ nullptr,
200 /*tp_as_mapping*/ nullptr,
201 /*tp_hash*/ nullptr,
202 /*tp_call*/ nullptr,
203 /*tp_str*/ nullptr,
204 /*tp_getattro*/ nullptr,
205 /*tp_setattro*/ nullptr,
206 /*tp_as_buffer*/ nullptr,
207 /*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
208 /*tp_doc*/ AdjacencyIterator_doc,
209 /*tp_traverse*/ nullptr,
210 /*tp_clear*/ nullptr,
211 /*tp_richcompare*/ nullptr,
212 /*tp_weaklistoffset*/ 0,
213 /*tp_iter*/ (getiterfunc)AdjacencyIterator_iter,
214 /*tp_iternext*/ (iternextfunc)AdjacencyIterator_iternext,
215 /*tp_methods*/ nullptr,
216 /*tp_members*/ nullptr,
218 /*tp_base*/ &Iterator_Type,
219 /*tp_dict*/ nullptr,
220 /*tp_descr_get*/ nullptr,
221 /*tp_descr_set*/ nullptr,
222 /*tp_dictoffset*/ 0,
223 /*tp_init*/ (initproc)AdjacencyIterator_init,
224 /*tp_alloc*/ nullptr,
225 /*tp_new*/ nullptr,
226};
227
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)
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 Iterator_Type
PyTypeObject ViewVertex_Type
inherits from class Rep
Definition AppCanvas.cpp:20
Freestyle::AdjacencyIterator * a_it
PyObject_HEAD Freestyle::Iterator * it