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