~ubuntu-branches/ubuntu/trusty/blender/trusty-proposed

« back to all changes in this revision

Viewing changes to source/blender/freestyle/intern/python/Iterator/BPy_ViewEdgeIterator.cpp

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2013-08-14 10:43:49 UTC
  • mfrom: (14.2.19 sid)
  • Revision ID: package-import@ubuntu.com-20130814104349-t1d5mtwkphp12dyj
Tags: 2.68a-3
* Upload to unstable
* debian/: python3.3 Depends simplified
  - debian/control: python3.3 Depends dropped
    for blender-data package
  - 0001-blender_thumbnailer.patch refreshed
* debian/control: libavcodec b-dep versioning dropped

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * ***** BEGIN GPL LICENSE BLOCK *****
 
3
 *
 
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.
 
8
 *
 
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.
 
13
 *
 
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.
 
17
 *
 
18
 * ***** END GPL LICENSE BLOCK *****
 
19
 */
 
20
 
 
21
/** \file source/blender/freestyle/intern/python/Iterator/BPy_ViewEdgeIterator.cpp
 
22
 *  \ingroup freestyle
 
23
 */
 
24
 
 
25
#include "BPy_ViewEdgeIterator.h"
 
26
 
 
27
#include "../BPy_Convert.h"
 
28
#include "../Interface1D/BPy_ViewEdge.h"
 
29
 
 
30
#ifdef __cplusplus
 
31
extern "C" {
 
32
#endif
 
33
 
 
34
///////////////////////////////////////////////////////////////////////////////////////////
 
35
 
 
36
//------------------------INSTANCE METHODS ----------------------------------
 
37
 
 
38
PyDoc_STRVAR(ViewEdgeIterator_doc,
 
39
"Class hierarchy: :class:`Iterator` > :class:`ViewEdgeIterator`\n"
 
40
"\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"
 
45
"\n"
 
46
".. method:: __init__(begin=None, orientation=True)\n"
 
47
"\n"
 
48
"   Builds a ViewEdgeIterator from a starting ViewEdge and its\n"
 
49
"   orientation.\n"
 
50
"\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"
 
58
"\n"
 
59
".. method:: __init__(brother)\n"
 
60
"\n"
 
61
"   Copy constructor.\n"
 
62
"\n"
 
63
"   :arg brother: A ViewEdgeIterator object.\n"
 
64
"   :type brother: :class:`ViewEdgeIterator`");
 
65
 
 
66
static int check_begin(PyObject *obj, void *v)
 
67
{
 
68
        if (obj != 0 && obj != Py_None && !BPy_ViewEdge_Check(obj))
 
69
                return 0;
 
70
        *((PyObject **)v) = obj;
 
71
        return 1;
 
72
}
 
73
 
 
74
static int ViewEdgeIterator_init(BPy_ViewEdgeIterator *self, PyObject *args, PyObject *kwds)
 
75
{
 
76
        static const char *kwlist_1[] = {"brother", NULL};
 
77
        static const char *kwlist_2[] = {"begin", "orientation", NULL};
 
78
        PyObject *obj1 = 0, *obj2 = 0;
 
79
 
 
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));
 
82
        }
 
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))
 
86
        {
 
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);
 
90
        }
 
91
        else {
 
92
                PyErr_SetString(PyExc_TypeError, "invalid argument(s)");
 
93
                return -1;
 
94
        }
 
95
        self->py_it.it = self->ve_it;
 
96
        return 0;
 
97
}
 
98
 
 
99
PyDoc_STRVAR(ViewEdgeIterator_change_orientation_doc,
 
100
".. method:: change_orientation()\n"
 
101
"\n"
 
102
"   Changes the current orientation.");
 
103
 
 
104
static PyObject *ViewEdgeIterator_change_orientation(BPy_ViewEdgeIterator *self)
 
105
{
 
106
        self->ve_it->changeOrientation();
 
107
        Py_RETURN_NONE;
 
108
}
 
109
 
 
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}
 
114
};
 
115
 
 
116
/*----------------------ViewEdgeIterator get/setters ----------------------------*/
 
117
 
 
118
PyDoc_STRVAR(ViewEdgeIterator_object_doc,
 
119
"The ViewEdge object currently pointed by this iterator.\n"
 
120
"\n"
 
121
":type: :class:`ViewEdge`");
 
122
 
 
123
static PyObject *ViewEdgeIterator_object_get(BPy_ViewEdgeIterator *self, void *UNUSED(closure))
 
124
{
 
125
        ViewEdge *ve = self->ve_it->operator*();
 
126
        if (ve)
 
127
                return BPy_ViewEdge_from_ViewEdge(*ve);
 
128
        Py_RETURN_NONE;
 
129
}
 
130
 
 
131
PyDoc_STRVAR(ViewEdgeIterator_current_edge_doc,
 
132
"The ViewEdge object currently pointed by this iterator.\n"
 
133
"\n"
 
134
":type: :class:`ViewEdge`");
 
135
 
 
136
static PyObject *ViewEdgeIterator_current_edge_get(BPy_ViewEdgeIterator *self, void *UNUSED(closure))
 
137
{
 
138
        ViewEdge *ve = self->ve_it->getCurrentEdge();
 
139
        if (ve)
 
140
                return BPy_ViewEdge_from_ViewEdge(*ve);
 
141
        Py_RETURN_NONE;}
 
142
 
 
143
static int ViewEdgeIterator_current_edge_set(BPy_ViewEdgeIterator *self, PyObject *value, void *UNUSED(closure))
 
144
{
 
145
        if (!BPy_ViewEdge_Check(value)) {
 
146
                PyErr_SetString(PyExc_TypeError, "value must be a ViewEdge");
 
147
                return -1;
 
148
        }
 
149
        self->ve_it->setCurrentEdge(((BPy_ViewEdge *)value)->ve);
 
150
        return 0;
 
151
}
 
152
 
 
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"
 
159
"\n"
 
160
":type: bool");
 
161
 
 
162
static PyObject *ViewEdgeIterator_orientation_get(BPy_ViewEdgeIterator *self, void *UNUSED(closure))
 
163
{
 
164
        return PyBool_from_bool(self->ve_it->getOrientation());
 
165
}
 
166
 
 
167
static int ViewEdgeIterator_orientation_set(BPy_ViewEdgeIterator *self, PyObject *value, void *UNUSED(closure))
 
168
{
 
169
        if (!PyBool_Check(value)) {
 
170
                PyErr_SetString(PyExc_TypeError, "value must be a boolean");
 
171
                return -1;
 
172
        }
 
173
        self->ve_it->setOrientation(bool_from_PyBool(value));
 
174
        return 0;
 
175
}
 
176
 
 
177
PyDoc_STRVAR(ViewEdgeIterator_begin_doc,
 
178
"The first ViewEdge used for the iteration.\n"
 
179
"\n"
 
180
":type: :class:`ViewEdge`");
 
181
 
 
182
static PyObject *ViewEdgeIterator_begin_get(BPy_ViewEdgeIterator *self, void *UNUSED(closure))
 
183
{
 
184
        ViewEdge *ve = self->ve_it->getBegin();
 
185
        if (ve)
 
186
                return BPy_ViewEdge_from_ViewEdge(*ve);
 
187
        Py_RETURN_NONE;
 
188
}
 
189
 
 
190
static int ViewEdgeIterator_begin_set(BPy_ViewEdgeIterator *self, PyObject *value, void *UNUSED(closure))
 
191
{
 
192
        if (!BPy_ViewEdge_Check(value)) {
 
193
                PyErr_SetString(PyExc_TypeError, "value must be a ViewEdge");
 
194
                return -1;
 
195
        }
 
196
        self->ve_it->setBegin(((BPy_ViewEdge *)value)->ve);
 
197
        return 0;
 
198
}
 
199
 
 
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 */
 
209
};
 
210
 
 
211
/*-----------------------BPy_ViewEdgeIterator type definition ------------------------------*/
 
212
 
 
213
PyTypeObject ViewEdgeIterator_Type = {
 
214
        PyVarObject_HEAD_INIT(NULL, 0)
 
215
        "ViewEdgeIterator",             /* tp_name */
 
216
        sizeof(BPy_ViewEdgeIterator),   /* tp_basicsize */
 
217
        0,                              /* tp_itemsize */
 
218
        0,                              /* tp_dealloc */
 
219
        0,                              /* tp_print */
 
220
        0,                              /* tp_getattr */
 
221
        0,                              /* tp_setattr */
 
222
        0,                              /* tp_reserved */
 
223
        0,                              /* tp_repr */
 
224
        0,                              /* tp_as_number */
 
225
        0,                              /* tp_as_sequence */
 
226
        0,                              /* tp_as_mapping */
 
227
        0,                              /* tp_hash  */
 
228
        0,                              /* tp_call */
 
229
        0,                              /* tp_str */
 
230
        0,                              /* tp_getattro */
 
231
        0,                              /* tp_setattro */
 
232
        0,                              /* tp_as_buffer */
 
233
        Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
 
234
        ViewEdgeIterator_doc,           /* tp_doc */
 
235
        0,                              /* tp_traverse */
 
236
        0,                              /* tp_clear */
 
237
        0,                              /* tp_richcompare */
 
238
        0,                              /* tp_weaklistoffset */
 
239
        0,                              /* tp_iter */
 
240
        0,                              /* tp_iternext */
 
241
        BPy_ViewEdgeIterator_methods,   /* tp_methods */
 
242
        0,                              /* tp_members */
 
243
        BPy_ViewEdgeIterator_getseters, /* tp_getset */
 
244
        &Iterator_Type,                 /* tp_base */
 
245
        0,                              /* tp_dict */
 
246
        0,                              /* tp_descr_get */
 
247
        0,                              /* tp_descr_set */
 
248
        0,                              /* tp_dictoffset */
 
249
        (initproc)ViewEdgeIterator_init, /* tp_init */
 
250
        0,                              /* tp_alloc */
 
251
        0,                              /* tp_new */
 
252
};
 
253
 
 
254
///////////////////////////////////////////////////////////////////////////////////////////
 
255
 
 
256
#ifdef __cplusplus
 
257
}
 
258
#endif