Blender  V3.3
BPy_AdjacencyIterator.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
8 
9 #include "../BPy_Convert.h"
10 #include "../Interface0D/BPy_ViewVertex.h"
11 
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15 
16 using namespace Freestyle;
17 
19 
20 //------------------------INSTANCE METHODS ----------------------------------
21 
23  AdjacencyIterator_doc,
24  "Class hierarchy: :class:`Iterator` > :class:`AdjacencyIterator`\n"
25  "\n"
26  "Class for representing adjacency iterators used in the chaining\n"
27  "process. An AdjacencyIterator is created in the increment() and\n"
28  "decrement() methods of a :class:`ChainingIterator` and passed to the\n"
29  "traverse() method of the ChainingIterator.\n"
30  "\n"
31  ".. method:: __init__()\n"
32  " __init__(brother)\n"
33  " __init__(vertex, restrict_to_selection=True, restrict_to_unvisited=True)\n"
34  "\n"
35  " Builds an :class:`AdjacencyIterator` using the default constructor,\n"
36  " copy constructor or the overloaded constructor.\n"
37  "\n"
38  " :arg brother: An AdjacencyIterator object.\n"
39  " :type brother: :class:`AdjacencyIterator`\n"
40  " :arg vertex: The vertex which is the next crossing.\n"
41  " :type vertex: :class:`ViewVertex`\n"
42  " :arg restrict_to_selection: Indicates whether to force the chaining\n"
43  " to stay within the set of selected ViewEdges or not.\n"
44  " :type restrict_to_selection: bool\n"
45  " :arg restrict_to_unvisited: Indicates whether a ViewEdge that has\n"
46  " already been chained must be ignored ot not.\n"
47  " :type restrict_to_unvisited: bool");
48 
49 static int AdjacencyIterator_init(BPy_AdjacencyIterator *self, PyObject *args, PyObject *kwds)
50 {
51  static const char *kwlist_1[] = {"brother", nullptr};
52  static const char *kwlist_2[] = {
53  "vertex", "restrict_to_selection", "restrict_to_unvisited", nullptr};
54  PyObject *obj1 = nullptr, *obj2 = nullptr, *obj3 = nullptr;
55 
56  if (PyArg_ParseTupleAndKeywords(
57  args, kwds, "|O!", (char **)kwlist_1, &AdjacencyIterator_Type, &obj1)) {
58  if (!obj1) {
59  self->a_it = new AdjacencyIterator();
60  self->at_start = true;
61  }
62  else {
63  self->a_it = new AdjacencyIterator(*(((BPy_AdjacencyIterator *)obj1)->a_it));
64  self->at_start = ((BPy_AdjacencyIterator *)obj1)->at_start;
65  }
66  }
67  else if ((void)PyErr_Clear(),
68  (void)(obj2 = obj3 = nullptr),
69  PyArg_ParseTupleAndKeywords(args,
70  kwds,
71  "O!|O!O!",
72  (char **)kwlist_2,
74  &obj1,
75  &PyBool_Type,
76  &obj2,
77  &PyBool_Type,
78  &obj3)) {
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 
122 PyDoc_STRVAR(AdjacencyIterator_object_doc,
123  "The ViewEdge object currently pointed to by this iterator.\n"
124  "\n"
125  ":type: :class:`ViewEdge`");
126 
127 static PyObject *AdjacencyIterator_object_get(BPy_AdjacencyIterator *self, void *UNUSED(closure))
128 {
129  if (self->a_it->isEnd()) {
130  PyErr_SetString(PyExc_RuntimeError, "iteration has stopped");
131  return nullptr;
132  }
133  ViewEdge *ve = self->a_it->operator*();
134  if (ve) {
135  return BPy_ViewEdge_from_ViewEdge(*ve);
136  }
137  Py_RETURN_NONE;
138 }
139 
140 PyDoc_STRVAR(AdjacencyIterator_is_incoming_doc,
141  "True if the current ViewEdge is coming towards the iteration vertex, and\n"
142  "False otherwise.\n"
143  "\n"
144  ":type: bool");
145 
147  void *UNUSED(closure))
148 {
149  if (self->a_it->isEnd()) {
150  PyErr_SetString(PyExc_RuntimeError, "iteration has stopped");
151  return nullptr;
152  }
153  return PyBool_from_bool(self->a_it->isIncoming());
154 }
155 
156 static PyGetSetDef BPy_AdjacencyIterator_getseters[] = {
157  {"is_incoming",
159  (setter) nullptr,
160  AdjacencyIterator_is_incoming_doc,
161  nullptr},
162  {"object",
164  (setter) nullptr,
165  AdjacencyIterator_object_doc,
166  nullptr},
167  {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
168 };
169 
170 /*-----------------------BPy_AdjacencyIterator type definition ------------------------------*/
171 
172 PyTypeObject AdjacencyIterator_Type = {
173  PyVarObject_HEAD_INIT(nullptr, 0) "AdjacencyIterator", /* tp_name */
174  sizeof(BPy_AdjacencyIterator), /* tp_basicsize */
175  0, /* tp_itemsize */
176  nullptr, /* tp_dealloc */
177  0, /* tp_vectorcall_offset */
178  nullptr, /* tp_getattr */
179  nullptr, /* tp_setattr */
180  nullptr, /* tp_reserved */
181  nullptr, /* tp_repr */
182  nullptr, /* tp_as_number */
183  nullptr, /* tp_as_sequence */
184  nullptr, /* tp_as_mapping */
185  nullptr, /* tp_hash */
186  nullptr, /* tp_call */
187  nullptr, /* tp_str */
188  nullptr, /* tp_getattro */
189  nullptr, /* tp_setattro */
190  nullptr, /* tp_as_buffer */
191  Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
192  AdjacencyIterator_doc, /* tp_doc */
193  nullptr, /* tp_traverse */
194  nullptr, /* tp_clear */
195  nullptr, /* tp_richcompare */
196  0, /* tp_weaklistoffset */
197  (getiterfunc)AdjacencyIterator_iter, /* tp_iter */
198  (iternextfunc)AdjacencyIterator_iternext, /* tp_iternext */
199  nullptr, /* tp_methods */
200  nullptr, /* tp_members */
201  BPy_AdjacencyIterator_getseters, /* tp_getset */
202  &Iterator_Type, /* tp_base */
203  nullptr, /* tp_dict */
204  nullptr, /* tp_descr_get */
205  nullptr, /* tp_descr_set */
206  0, /* tp_dictoffset */
207  (initproc)AdjacencyIterator_init, /* tp_init */
208  nullptr, /* tp_alloc */
209  nullptr, /* tp_new */
210 };
211 
213 
214 #ifdef __cplusplus
215 }
216 #endif
#define UNUSED(x)
static PyObject * AdjacencyIterator_iter(BPy_AdjacencyIterator *self)
static PyObject * AdjacencyIterator_is_incoming_get(BPy_AdjacencyIterator *self, void *UNUSED(closure))
static PyObject * AdjacencyIterator_iternext(BPy_AdjacencyIterator *self)
static PyObject * AdjacencyIterator_object_get(BPy_AdjacencyIterator *self, void *UNUSED(closure))
PyTypeObject AdjacencyIterator_Type
static int AdjacencyIterator_init(BPy_AdjacencyIterator *self, PyObject *args, PyObject *kwds)
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 PyGetSetDef BPy_AdjacencyIterator_getseters[]
PyObject * PyBool_from_bool(bool b)
Definition: BPy_Convert.cpp:59
bool bool_from_PyBool(PyObject *b)
PyObject * BPy_ViewEdge_from_ViewEdge(ViewEdge &ve)
PyTypeObject Iterator_Type
PyTypeObject ViewVertex_Type
PyObject * self
Definition: bpy_driver.c:165
SyclQueue void void size_t num_bytes void
inherits from class Rep
Definition: AppCanvas.cpp:18