2
* ***** BEGIN GPL LICENSE BLOCK *****
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License
6
* as published by the Free Software Foundation; either version 2
7
* of the License, or (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software Foundation,
16
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
* ***** END GPL LICENSE BLOCK *****
21
/** \file source/blender/freestyle/intern/python/Iterator/BPy_ViewEdgeIterator.cpp
25
#include "BPy_ViewEdgeIterator.h"
27
#include "../BPy_Convert.h"
28
#include "../Interface1D/BPy_ViewEdge.h"
34
///////////////////////////////////////////////////////////////////////////////////////////
36
//------------------------INSTANCE METHODS ----------------------------------
38
PyDoc_STRVAR(ViewEdgeIterator_doc,
39
"Class hierarchy: :class:`Iterator` > :class:`ViewEdgeIterator`\n"
41
"Base class for iterators over ViewEdges of the :class:`ViewMap` Graph.\n"
42
"Basically the increment() operator of this class should be able to\n"
43
"take the decision of \"where\" (on which ViewEdge) to go when pointing\n"
44
"on a given ViewEdge.\n"
46
".. method:: __init__(begin=None, orientation=True)\n"
48
" Builds a ViewEdgeIterator from a starting ViewEdge and its\n"
51
" :arg begin: The ViewEdge from where to start the iteration.\n"
52
" :type begin: :class:`ViewEdge` or None\n"
53
" :arg orientation: If true, we'll look for the next ViewEdge among\n"
54
" the ViewEdges that surround the ending ViewVertex of begin. If\n"
55
" false, we'll search over the ViewEdges surrounding the ending\n"
56
" ViewVertex of begin.\n"
57
" :type orientation: bool\n"
59
".. method:: __init__(brother)\n"
61
" Copy constructor.\n"
63
" :arg brother: A ViewEdgeIterator object.\n"
64
" :type brother: :class:`ViewEdgeIterator`");
66
static int check_begin(PyObject *obj, void *v)
68
if (obj != 0 && obj != Py_None && !BPy_ViewEdge_Check(obj))
70
*((PyObject **)v) = obj;
74
static int ViewEdgeIterator_init(BPy_ViewEdgeIterator *self, PyObject *args, PyObject *kwds)
76
static const char *kwlist_1[] = {"brother", NULL};
77
static const char *kwlist_2[] = {"begin", "orientation", NULL};
78
PyObject *obj1 = 0, *obj2 = 0;
80
if (PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist_1, &ViewEdgeIterator_Type, &obj1)) {
81
self->ve_it = new ViewEdgeInternal::ViewEdgeIterator(*(((BPy_ViewEdgeIterator *)obj1)->ve_it));
83
else if (PyErr_Clear(), (obj1 = obj2 = 0),
84
PyArg_ParseTupleAndKeywords(args, kwds, "|O&O!", (char **)kwlist_2,
85
check_begin, &obj1, &PyBool_Type, &obj2))
87
ViewEdge *begin = (!obj1 || obj1 == Py_None) ? NULL : ((BPy_ViewEdge *)obj1)->ve;
88
bool orientation = (!obj2) ? true : bool_from_PyBool(obj2);
89
self->ve_it = new ViewEdgeInternal::ViewEdgeIterator(begin, orientation);
92
PyErr_SetString(PyExc_TypeError, "invalid argument(s)");
95
self->py_it.it = self->ve_it;
99
PyDoc_STRVAR(ViewEdgeIterator_change_orientation_doc,
100
".. method:: change_orientation()\n"
102
" Changes the current orientation.");
104
static PyObject *ViewEdgeIterator_change_orientation(BPy_ViewEdgeIterator *self)
106
self->ve_it->changeOrientation();
110
static PyMethodDef BPy_ViewEdgeIterator_methods[] = {
111
{"change_orientation", (PyCFunction) ViewEdgeIterator_change_orientation, METH_NOARGS,
112
ViewEdgeIterator_change_orientation_doc},
113
{NULL, NULL, 0, NULL}
116
/*----------------------ViewEdgeIterator get/setters ----------------------------*/
118
PyDoc_STRVAR(ViewEdgeIterator_object_doc,
119
"The ViewEdge object currently pointed by this iterator.\n"
121
":type: :class:`ViewEdge`");
123
static PyObject *ViewEdgeIterator_object_get(BPy_ViewEdgeIterator *self, void *UNUSED(closure))
125
ViewEdge *ve = self->ve_it->operator*();
127
return BPy_ViewEdge_from_ViewEdge(*ve);
131
PyDoc_STRVAR(ViewEdgeIterator_current_edge_doc,
132
"The ViewEdge object currently pointed by this iterator.\n"
134
":type: :class:`ViewEdge`");
136
static PyObject *ViewEdgeIterator_current_edge_get(BPy_ViewEdgeIterator *self, void *UNUSED(closure))
138
ViewEdge *ve = self->ve_it->getCurrentEdge();
140
return BPy_ViewEdge_from_ViewEdge(*ve);
143
static int ViewEdgeIterator_current_edge_set(BPy_ViewEdgeIterator *self, PyObject *value, void *UNUSED(closure))
145
if (!BPy_ViewEdge_Check(value)) {
146
PyErr_SetString(PyExc_TypeError, "value must be a ViewEdge");
149
self->ve_it->setCurrentEdge(((BPy_ViewEdge *)value)->ve);
153
PyDoc_STRVAR(ViewEdgeIterator_orientation_doc,
154
"The orientation of the pointed ViewEdge in the iteration.\n"
155
"If true, the iterator looks for the next ViewEdge among those ViewEdges\n"
156
"that surround the ending ViewVertex of the \"begin\" ViewEdge. If false,\n"
157
"the iterator searches over the ViewEdges surrounding the ending ViewVertex\n"
158
"of the \"begin\" ViewEdge.\n"
162
static PyObject *ViewEdgeIterator_orientation_get(BPy_ViewEdgeIterator *self, void *UNUSED(closure))
164
return PyBool_from_bool(self->ve_it->getOrientation());
167
static int ViewEdgeIterator_orientation_set(BPy_ViewEdgeIterator *self, PyObject *value, void *UNUSED(closure))
169
if (!PyBool_Check(value)) {
170
PyErr_SetString(PyExc_TypeError, "value must be a boolean");
173
self->ve_it->setOrientation(bool_from_PyBool(value));
177
PyDoc_STRVAR(ViewEdgeIterator_begin_doc,
178
"The first ViewEdge used for the iteration.\n"
180
":type: :class:`ViewEdge`");
182
static PyObject *ViewEdgeIterator_begin_get(BPy_ViewEdgeIterator *self, void *UNUSED(closure))
184
ViewEdge *ve = self->ve_it->getBegin();
186
return BPy_ViewEdge_from_ViewEdge(*ve);
190
static int ViewEdgeIterator_begin_set(BPy_ViewEdgeIterator *self, PyObject *value, void *UNUSED(closure))
192
if (!BPy_ViewEdge_Check(value)) {
193
PyErr_SetString(PyExc_TypeError, "value must be a ViewEdge");
196
self->ve_it->setBegin(((BPy_ViewEdge *)value)->ve);
200
static PyGetSetDef BPy_ViewEdgeIterator_getseters[] = {
201
{(char *)"object", (getter)ViewEdgeIterator_object_get, (setter)NULL, (char *)ViewEdgeIterator_object_doc, NULL},
202
{(char *)"current_edge", (getter)ViewEdgeIterator_current_edge_get, (setter)ViewEdgeIterator_current_edge_set,
203
(char *)ViewEdgeIterator_current_edge_doc, NULL},
204
{(char *)"orientation", (getter)ViewEdgeIterator_orientation_get, (setter)ViewEdgeIterator_orientation_set,
205
(char *)ViewEdgeIterator_orientation_doc, NULL},
206
{(char *)"begin", (getter)ViewEdgeIterator_begin_get, (setter)ViewEdgeIterator_begin_set,
207
(char *)ViewEdgeIterator_begin_doc, NULL},
208
{NULL, NULL, NULL, NULL, NULL} /* Sentinel */
211
/*-----------------------BPy_ViewEdgeIterator type definition ------------------------------*/
213
PyTypeObject ViewEdgeIterator_Type = {
214
PyVarObject_HEAD_INIT(NULL, 0)
215
"ViewEdgeIterator", /* tp_name */
216
sizeof(BPy_ViewEdgeIterator), /* tp_basicsize */
224
0, /* tp_as_number */
225
0, /* tp_as_sequence */
226
0, /* tp_as_mapping */
232
0, /* tp_as_buffer */
233
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
234
ViewEdgeIterator_doc, /* tp_doc */
237
0, /* tp_richcompare */
238
0, /* tp_weaklistoffset */
241
BPy_ViewEdgeIterator_methods, /* tp_methods */
243
BPy_ViewEdgeIterator_getseters, /* tp_getset */
244
&Iterator_Type, /* tp_base */
246
0, /* tp_descr_get */
247
0, /* tp_descr_set */
248
0, /* tp_dictoffset */
249
(initproc)ViewEdgeIterator_init, /* tp_init */
254
///////////////////////////////////////////////////////////////////////////////////////////