Blender  V3.3
BPy_orientedViewEdgeIterator.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 
11 #ifdef __cplusplus
12 extern "C" {
13 #endif
14 
15 using namespace Freestyle;
16 
18 
19 //------------------------INSTANCE METHODS ----------------------------------
20 
21 PyDoc_STRVAR(orientedViewEdgeIterator_doc,
22  "Class hierarchy: :class:`Iterator` > :class:`orientedViewEdgeIterator`\n"
23  "\n"
24  "Class representing an iterator over oriented ViewEdges around a\n"
25  ":class:`ViewVertex`. This iterator allows a CCW iteration (in the image\n"
26  "plane). An instance of an orientedViewEdgeIterator can only be\n"
27  "obtained from a ViewVertex by calling edges_begin() or edges_end().\n"
28  "\n"
29  ".. method:: __init__()\n"
30  " __init__(iBrother)\n"
31  "\n"
32  " Creates an :class:`orientedViewEdgeIterator` using either the\n"
33  " default constructor or the copy constructor.\n"
34  "\n"
35  " :arg iBrother: An orientedViewEdgeIterator object.\n"
36  " :type iBrother: :class:`orientedViewEdgeIterator`");
37 
39  PyObject *args,
40  PyObject *kwds)
41 {
42  static const char *kwlist[] = {"brother", nullptr};
43  PyObject *brother = nullptr;
44 
45  if (!PyArg_ParseTupleAndKeywords(
46  args, kwds, "|O!", (char **)kwlist, &orientedViewEdgeIterator_Type, &brother)) {
47  return -1;
48  }
49  if (!brother) {
51  self->at_start = true;
52  self->reversed = false;
53  }
54  else {
56  *(((BPy_orientedViewEdgeIterator *)brother)->ove_it));
57  self->at_start = ((BPy_orientedViewEdgeIterator *)brother)->at_start;
58  self->reversed = ((BPy_orientedViewEdgeIterator *)brother)->reversed;
59  }
60  self->py_it.it = self->ove_it;
61  return 0;
62 }
63 
65 {
66  Py_INCREF(self);
67  self->at_start = true;
68  return (PyObject *)self;
69 }
70 
72 {
73  if (self->reversed) {
74  if (self->ove_it->isBegin()) {
75  PyErr_SetNone(PyExc_StopIteration);
76  return nullptr;
77  }
78  self->ove_it->decrement();
79  }
80  else {
81  if (self->ove_it->isEnd()) {
82  PyErr_SetNone(PyExc_StopIteration);
83  return nullptr;
84  }
85  if (self->at_start) {
86  self->at_start = false;
87  }
88  else {
89  self->ove_it->increment();
90  if (self->ove_it->isEnd()) {
91  PyErr_SetNone(PyExc_StopIteration);
92  return nullptr;
93  }
94  }
95  }
96  ViewVertex::directedViewEdge *dve = self->ove_it->operator->();
98 }
99 
100 /*----------------------orientedViewEdgeIterator get/setters ----------------------------*/
101 
102 PyDoc_STRVAR(orientedViewEdgeIterator_object_doc,
103  "The oriented ViewEdge (i.e., a tuple of the pointed ViewEdge and a boolean\n"
104  "value) currently pointed to by this iterator. If the boolean value is true,\n"
105  "the ViewEdge is incoming.\n"
106  "\n"
107  ":type: (:class:`ViewEdge`, bool)");
108 
110  void *UNUSED(closure))
111 {
112  if (self->ove_it->isEnd()) {
113  PyErr_SetString(PyExc_RuntimeError, "iteration has stopped");
114  return nullptr;
115  }
116  return BPy_directedViewEdge_from_directedViewEdge(self->ove_it->operator*());
117 }
118 
120  {"object",
122  (setter) nullptr,
123  orientedViewEdgeIterator_object_doc,
124  nullptr},
125  {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
126 };
127 
128 /*-----------------------BPy_orientedViewEdgeIterator type definition ---------------------------*/
129 
131  PyVarObject_HEAD_INIT(nullptr, 0) "orientedViewEdgeIterator", /* tp_name */
132  sizeof(BPy_orientedViewEdgeIterator), /* tp_basicsize */
133  0, /* tp_itemsize */
134  nullptr, /* tp_dealloc */
135  0, /* tp_vectorcall_offset */
136  nullptr, /* tp_getattr */
137  nullptr, /* tp_setattr */
138  nullptr, /* tp_reserved */
139  nullptr, /* tp_repr */
140  nullptr, /* tp_as_number */
141  nullptr, /* tp_as_sequence */
142  nullptr, /* tp_as_mapping */
143  nullptr, /* tp_hash */
144  nullptr, /* tp_call */
145  nullptr, /* tp_str */
146  nullptr, /* tp_getattro */
147  nullptr, /* tp_setattro */
148  nullptr, /* tp_as_buffer */
149  Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
150  orientedViewEdgeIterator_doc, /* tp_doc */
151  nullptr, /* tp_traverse */
152  nullptr, /* tp_clear */
153  nullptr, /* tp_richcompare */
154  0, /* tp_weaklistoffset */
155  (getiterfunc)orientedViewEdgeIterator_iter, /* tp_iter */
156  (iternextfunc)orientedViewEdgeIterator_iternext, /* tp_iternext */
157  nullptr, /* tp_methods */
158  nullptr, /* tp_members */
160  &Iterator_Type, /* tp_base */
161  nullptr, /* tp_dict */
162  nullptr, /* tp_descr_get */
163  nullptr, /* tp_descr_set */
164  0, /* tp_dictoffset */
165  (initproc)orientedViewEdgeIterator_init, /* tp_init */
166  nullptr, /* tp_alloc */
167  nullptr, /* tp_new */
168 };
169 
171 
172 #ifdef __cplusplus
173 }
174 #endif
#define UNUSED(x)
PyObject * BPy_directedViewEdge_from_directedViewEdge(ViewVertex::directedViewEdge &dve)
PyTypeObject Iterator_Type
static int orientedViewEdgeIterator_init(BPy_orientedViewEdgeIterator *self, PyObject *args, PyObject *kwds)
static PyObject * orientedViewEdgeIterator_iternext(BPy_orientedViewEdgeIterator *self)
PyDoc_STRVAR(orientedViewEdgeIterator_doc, "Class hierarchy: :class:`Iterator` > :class:`orientedViewEdgeIterator`\n" "\n" "Class representing an iterator over oriented ViewEdges around a\n" ":class:`ViewVertex`. This iterator allows a CCW iteration (in the image\n" "plane). An instance of an orientedViewEdgeIterator can only be\n" "obtained from a ViewVertex by calling edges_begin() or edges_end().\n" "\n" ".. method:: __init__()\n" " __init__(iBrother)\n" "\n" " Creates an :class:`orientedViewEdgeIterator` using either the\n" " default constructor or the copy constructor.\n" "\n" " :arg iBrother: An orientedViewEdgeIterator object.\n" " :type iBrother: :class:`orientedViewEdgeIterator`")
static PyObject * orientedViewEdgeIterator_object_get(BPy_orientedViewEdgeIterator *self, void *UNUSED(closure))
static PyObject * orientedViewEdgeIterator_iter(BPy_orientedViewEdgeIterator *self)
PyTypeObject orientedViewEdgeIterator_Type
static PyGetSetDef BPy_orientedViewEdgeIterator_getseters[]
PyObject * self
Definition: bpy_driver.c:165
pair< ViewEdge *, bool > directedViewEdge
Definition: ViewMap.h:266
inherits from class Rep
Definition: AppCanvas.cpp:18