Blender V4.5
BPy_ViewEdgeIterator.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 ViewEdgeIterator_doc,
23 "Class hierarchy: :class:`Iterator` > :class:`ViewEdgeIterator`\n"
24 "\n"
25 "Base class for iterators over ViewEdges of the :class:`ViewMap` Graph.\n"
26 "Basically the increment() operator of this class should be able to\n"
27 "take the decision of \"where\" (on which ViewEdge) to go when pointing\n"
28 "on a given ViewEdge.\n"
29 "\n"
30 ".. method:: __init__(begin=None, orientation=True)\n"
31 " __init__(brother)\n"
32 "\n"
33 " Builds a ViewEdgeIterator from a starting ViewEdge and its\n"
34 " orientation or the copy constructor.\n"
35 "\n"
36 " :arg begin: The ViewEdge from where to start the iteration.\n"
37 " :type begin: :class:`ViewEdge` | None\n"
38 " :arg orientation: If true, we'll look for the next ViewEdge among\n"
39 " the ViewEdges that surround the ending ViewVertex of begin. If\n"
40 " false, we'll search over the ViewEdges surrounding the ending\n"
41 " ViewVertex of begin.\n"
42 " :type orientation: bool\n"
43 " :arg brother: A ViewEdgeIterator object.\n"
44 " :type brother: :class:`ViewEdgeIterator`");
45
46static int check_begin(PyObject *obj, void *v)
47{
48 if (obj != nullptr && obj != Py_None && !BPy_ViewEdge_Check(obj)) {
49 return 0;
50 }
51 *((PyObject **)v) = obj;
52 return 1;
53}
54
55static int ViewEdgeIterator_init(BPy_ViewEdgeIterator *self, PyObject *args, PyObject *kwds)
56{
57 static const char *kwlist_1[] = {"brother", nullptr};
58 static const char *kwlist_2[] = {"begin", "orientation", nullptr};
59 PyObject *obj1 = nullptr, *obj2 = nullptr;
60
61 if (PyArg_ParseTupleAndKeywords(
62 args, kwds, "O!", (char **)kwlist_1, &ViewEdgeIterator_Type, &obj1))
63 {
64 self->ve_it = new ViewEdgeInternal::ViewEdgeIterator(*(((BPy_ViewEdgeIterator *)obj1)->ve_it));
65 }
66 else if ((void)PyErr_Clear(),
67 (void)(obj1 = obj2 = nullptr),
68 PyArg_ParseTupleAndKeywords(
69 args, kwds, "|O&O!", (char **)kwlist_2, check_begin, &obj1, &PyBool_Type, &obj2))
70 {
71 ViewEdge *begin = (!obj1 || obj1 == Py_None) ? nullptr : ((BPy_ViewEdge *)obj1)->ve;
72 bool orientation = (!obj2) ? true : bool_from_PyBool(obj2);
73 self->ve_it = new ViewEdgeInternal::ViewEdgeIterator(begin, orientation);
74 }
75 else {
76 PyErr_SetString(PyExc_TypeError, "invalid argument(s)");
77 return -1;
78 }
79 self->py_it.it = self->ve_it;
80 return 0;
81}
82
84 /* Wrap. */
85 ViewEdgeIterator_change_orientation_doc,
86 ".. method:: change_orientation()\n"
87 "\n"
88 " Changes the current orientation.");
89
91{
92 self->ve_it->changeOrientation();
93 Py_RETURN_NONE;
94}
95
96#ifdef __GNUC__
97# ifdef __clang__
98# pragma clang diagnostic push
99# pragma clang diagnostic ignored "-Wcast-function-type"
100# else
101# pragma GCC diagnostic push
102# pragma GCC diagnostic ignored "-Wcast-function-type"
103# endif
104#endif
105
106static PyMethodDef BPy_ViewEdgeIterator_methods[] = {
107 {"change_orientation",
109 METH_NOARGS,
110 ViewEdgeIterator_change_orientation_doc},
111 {nullptr, nullptr, 0, nullptr},
112};
113
114#ifdef __GNUC__
115# ifdef __clang__
116# pragma clang diagnostic pop
117# else
118# pragma GCC diagnostic pop
119# endif
120#endif
121
122/*----------------------ViewEdgeIterator get/setters ----------------------------*/
123
125 /* Wrap. */
126 ViewEdgeIterator_object_doc,
127 "The ViewEdge object currently pointed by this iterator.\n"
128 "\n"
129 ":type: :class:`ViewEdge`");
130
131static PyObject *ViewEdgeIterator_object_get(BPy_ViewEdgeIterator *self, void * /*closure*/)
132{
133 if (!self->ve_it->isEnd()) {
134 PyErr_SetString(PyExc_RuntimeError, "iteration has stopped");
135 return nullptr;
136 }
137 ViewEdge *ve = self->ve_it->operator*();
138 if (ve) {
139 return BPy_ViewEdge_from_ViewEdge(*ve);
140 }
141 Py_RETURN_NONE;
142}
143
145 /* Wrap. */
146 ViewEdgeIterator_current_edge_doc,
147 "The ViewEdge object currently pointed by this iterator.\n"
148 "\n"
149 ":type: :class:`ViewEdge`");
150
151static PyObject *ViewEdgeIterator_current_edge_get(BPy_ViewEdgeIterator *self, void * /*closure*/)
152{
153 ViewEdge *ve = self->ve_it->getCurrentEdge();
154 if (ve) {
155 return BPy_ViewEdge_from_ViewEdge(*ve);
156 }
157 Py_RETURN_NONE;
158}
159
161 PyObject *value,
162 void * /*closure*/)
163{
164 if (!BPy_ViewEdge_Check(value)) {
165 PyErr_SetString(PyExc_TypeError, "value must be a ViewEdge");
166 return -1;
167 }
168 self->ve_it->setCurrentEdge(((BPy_ViewEdge *)value)->ve);
169 return 0;
170}
171
173 /* Wrap. */
174 ViewEdgeIterator_orientation_doc,
175 "The orientation of the pointed ViewEdge in the iteration.\n"
176 "If true, the iterator looks for the next ViewEdge among those ViewEdges\n"
177 "that surround the ending ViewVertex of the \"begin\" ViewEdge. If false,\n"
178 "the iterator searches over the ViewEdges surrounding the ending ViewVertex\n"
179 "of the \"begin\" ViewEdge.\n"
180 "\n"
181 ":type: bool");
182
183static PyObject *ViewEdgeIterator_orientation_get(BPy_ViewEdgeIterator *self, void * /*closure*/)
184{
185 return PyBool_from_bool(self->ve_it->getOrientation());
186}
187
189 PyObject *value,
190 void * /*closure*/)
191{
192 if (!PyBool_Check(value)) {
193 PyErr_SetString(PyExc_TypeError, "value must be a boolean");
194 return -1;
195 }
196 self->ve_it->setOrientation(bool_from_PyBool(value));
197 return 0;
198}
199
201 /* Wrap. */
202 ViewEdgeIterator_begin_doc,
203 "The first ViewEdge used for the iteration.\n"
204 "\n"
205 ":type: :class:`ViewEdge`");
206
207static PyObject *ViewEdgeIterator_begin_get(BPy_ViewEdgeIterator *self, void * /*closure*/)
208{
209 ViewEdge *ve = self->ve_it->getBegin();
210 if (ve) {
211 return BPy_ViewEdge_from_ViewEdge(*ve);
212 }
213 Py_RETURN_NONE;
214}
215
217 PyObject *value,
218 void * /*closure*/)
219{
220 if (!BPy_ViewEdge_Check(value)) {
221 PyErr_SetString(PyExc_TypeError, "value must be a ViewEdge");
222 return -1;
223 }
224 self->ve_it->setBegin(((BPy_ViewEdge *)value)->ve);
225 return 0;
226}
227
228static PyGetSetDef BPy_ViewEdgeIterator_getseters[] = {
229 {"object",
231 (setter) nullptr,
232 ViewEdgeIterator_object_doc,
233 nullptr},
234 {"current_edge",
237 ViewEdgeIterator_current_edge_doc,
238 nullptr},
239 {"orientation",
242 ViewEdgeIterator_orientation_doc,
243 nullptr},
244 {"begin",
247 ViewEdgeIterator_begin_doc,
248 nullptr},
249 {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
250};
251
252/*-----------------------BPy_ViewEdgeIterator type definition ------------------------------*/
253
254PyTypeObject ViewEdgeIterator_Type = {
255 /*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
256 /*tp_name*/ "ViewEdgeIterator",
257 /*tp_basicsize*/ sizeof(BPy_ViewEdgeIterator),
258 /*tp_itemsize*/ 0,
259 /*tp_dealloc*/ nullptr,
260 /*tp_vectorcall_offset*/ 0,
261 /*tp_getattr*/ nullptr,
262 /*tp_setattr*/ nullptr,
263 /*tp_as_async*/ nullptr,
264 /*tp_repr*/ nullptr,
265 /*tp_as_number*/ nullptr,
266 /*tp_as_sequence*/ nullptr,
267 /*tp_as_mapping*/ nullptr,
268 /*tp_hash*/ nullptr,
269 /*tp_call*/ nullptr,
270 /*tp_str*/ nullptr,
271 /*tp_getattro*/ nullptr,
272 /*tp_setattro*/ nullptr,
273 /*tp_as_buffer*/ nullptr,
274 /*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
275 /*tp_doc*/ ViewEdgeIterator_doc,
276 /*tp_traverse*/ nullptr,
277 /*tp_clear*/ nullptr,
278 /*tp_richcompare*/ nullptr,
279 /*tp_weaklistoffset*/ 0,
280 /*tp_iter*/ nullptr,
281 /*tp_iternext*/ nullptr,
282 /*tp_methods*/ BPy_ViewEdgeIterator_methods,
283 /*tp_members*/ nullptr,
284 /*tp_getset*/ BPy_ViewEdgeIterator_getseters,
285 /*tp_base*/ &Iterator_Type,
286 /*tp_dict*/ nullptr,
287 /*tp_descr_get*/ nullptr,
288 /*tp_descr_set*/ nullptr,
289 /*tp_dictoffset*/ 0,
290 /*tp_init*/ (initproc)ViewEdgeIterator_init,
291 /*tp_alloc*/ nullptr,
292 /*tp_new*/ nullptr,
293};
294
static int check_begin(PyObject *obj, void *v)
bool bool_from_PyBool(PyObject *b)
PyObject * BPy_ViewEdge_from_ViewEdge(ViewEdge &ve)
PyObject * PyBool_from_bool(bool b)
PyTypeObject Iterator_Type
static int check_begin(PyObject *obj, void *v)
static PyObject * ViewEdgeIterator_orientation_get(BPy_ViewEdgeIterator *self, void *)
static int ViewEdgeIterator_current_edge_set(BPy_ViewEdgeIterator *self, PyObject *value, void *)
PyDoc_STRVAR(ViewEdgeIterator_doc, "Class hierarchy: :class:`Iterator` > :class:`ViewEdgeIterator`\n" "\n" "Base class for iterators over ViewEdges of the :class:`ViewMap` Graph.\n" "Basically the increment() operator of this class should be able to\n" "take the decision of \"where\" (on which ViewEdge) to go when pointing\n" "on a given ViewEdge.\n" "\n" ".. method:: __init__(begin=None, orientation=True)\n" " __init__(brother)\n" "\n" " Builds a ViewEdgeIterator from a starting ViewEdge and its\n" " orientation or the copy constructor.\n" "\n" " :arg begin: The ViewEdge from where to start the iteration.\n" " :type begin: :class:`ViewEdge` | None\n" " :arg orientation: If true, we'll look for the next ViewEdge among\n" " the ViewEdges that surround the ending ViewVertex of begin. If\n" " false, we'll search over the ViewEdges surrounding the ending\n" " ViewVertex of begin.\n" " :type orientation: bool\n" " :arg brother: A ViewEdgeIterator object.\n" " :type brother: :class:`ViewEdgeIterator`")
static PyObject * ViewEdgeIterator_change_orientation(BPy_ViewEdgeIterator *self)
static int ViewEdgeIterator_init(BPy_ViewEdgeIterator *self, PyObject *args, PyObject *kwds)
static PyMethodDef BPy_ViewEdgeIterator_methods[]
static PyObject * ViewEdgeIterator_current_edge_get(BPy_ViewEdgeIterator *self, void *)
PyTypeObject ViewEdgeIterator_Type
static PyGetSetDef BPy_ViewEdgeIterator_getseters[]
static int ViewEdgeIterator_orientation_set(BPy_ViewEdgeIterator *self, PyObject *value, void *)
static int ViewEdgeIterator_begin_set(BPy_ViewEdgeIterator *self, PyObject *value, void *)
static PyObject * ViewEdgeIterator_begin_get(BPy_ViewEdgeIterator *self, void *)
static PyObject * ViewEdgeIterator_object_get(BPy_ViewEdgeIterator *self, void *)
#define BPy_ViewEdge_Check(v)
iter begin(iter)
ATTR_WARN_UNUSED_RESULT const BMVert * v
PyObject * self
inherits from class Rep
Definition AppCanvas.cpp:20