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

« back to all changes in this revision

Viewing changes to source/blender/freestyle/intern/python/BPy_ViewShape.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/BPy_ViewShape.cpp
 
22
 *  \ingroup freestyle
 
23
 */
 
24
 
 
25
#include "BPy_ViewShape.h"
 
26
 
 
27
#include "BPy_Convert.h"
 
28
#include "Interface0D/BPy_ViewVertex.h"
 
29
#include "Interface1D/BPy_ViewEdge.h"
 
30
#include "BPy_SShape.h"
 
31
 
 
32
#ifdef __cplusplus
 
33
extern "C" {
 
34
#endif
 
35
 
 
36
///////////////////////////////////////////////////////////////////////////////////////////
 
37
 
 
38
//-------------------MODULE INITIALIZATION--------------------------------
 
39
 
 
40
int ViewShape_Init(PyObject *module)
 
41
{
 
42
        if (module == NULL)
 
43
                return -1;
 
44
 
 
45
        if (PyType_Ready(&ViewShape_Type) < 0)
 
46
                return -1;
 
47
        Py_INCREF(&ViewShape_Type);
 
48
        PyModule_AddObject(module, "ViewShape", (PyObject *)&ViewShape_Type);
 
49
 
 
50
        return 0;
 
51
}
 
52
 
 
53
/*----------------------ViewShape methods ----------------------------*/
 
54
 
 
55
PyDoc_STRVAR(ViewShape_doc,
 
56
"Class gathering the elements of the ViewMap (i.e., :class:`ViewVertex`\n"
 
57
"and :class:`ViewEdge`) that are issued from the same input shape.\n"
 
58
"\n"
 
59
".. method:: __init__()\n"
 
60
"\n"
 
61
"   Default constructor.\n"
 
62
"\n"
 
63
".. method:: __init__(brother)\n"
 
64
"\n"
 
65
"   Copy constructor.\n"
 
66
"\n"
 
67
"   :arg brother: A ViewShape object.\n"
 
68
"   :type brother: :class:`ViewShape`\n"
 
69
"\n"
 
70
".. method:: __init__(sshape)\n"
 
71
"\n"
 
72
"   Builds a ViewShape from an SShape.\n"
 
73
"\n"
 
74
"   :arg sshape: An SShape object.\n"
 
75
"   :type sshape: :class:`SShape`");
 
76
 
 
77
static int ViewShape_init(BPy_ViewShape *self, PyObject *args, PyObject *kwds)
 
78
{
 
79
        static const char *kwlist_1[] = {"brother", NULL};
 
80
        static const char *kwlist_2[] = {"sshape", NULL};
 
81
        PyObject *obj = 0;
 
82
 
 
83
        if (PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist_1, &ViewShape_Type, &obj)) {
 
84
                if (!obj) {
 
85
                        self->vs = new ViewShape();
 
86
                        self->py_ss = NULL;
 
87
                }
 
88
                else {
 
89
                        self->vs = new ViewShape(*(((BPy_ViewShape *)obj)->vs));
 
90
                        self->py_ss = ((BPy_ViewShape *)obj)->py_ss;
 
91
                }
 
92
        }
 
93
        else if (PyErr_Clear(),
 
94
                 PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist_2, &SShape_Type, &obj))
 
95
        {
 
96
                BPy_SShape *py_ss = (BPy_SShape *)obj;
 
97
                self->vs = new ViewShape(py_ss->ss);
 
98
                self->py_ss = (!py_ss->borrowed) ? py_ss : NULL;
 
99
        }
 
100
        else {
 
101
                PyErr_SetString(PyExc_TypeError, "invalid argument(s)");
 
102
                return -1;
 
103
        }
 
104
        self->borrowed = 0;
 
105
        Py_XINCREF(self->py_ss);
 
106
        return 0;
 
107
}
 
108
 
 
109
static void ViewShape_dealloc(BPy_ViewShape *self)
 
110
{
 
111
        if (self->py_ss) {
 
112
                self->vs->setSShape((SShape *)NULL);
 
113
                Py_DECREF(self->py_ss);
 
114
        }
 
115
        if (self->vs && !self->borrowed)
 
116
                delete self->vs;
 
117
        Py_TYPE(self)->tp_free((PyObject *)self);
 
118
}
 
119
 
 
120
static PyObject *ViewShape_repr(BPy_ViewShape *self)
 
121
{
 
122
        return PyUnicode_FromFormat("ViewShape - address: %p", self->vs);
 
123
}
 
124
 
 
125
PyDoc_STRVAR(ViewShape_add_edge_doc,
 
126
".. method:: add_edge(edge)\n"
 
127
"\n"
 
128
"   Adds a ViewEdge to the list of ViewEdge objects.\n"
 
129
"\n"
 
130
"   :arg edge: A ViewEdge object.\n"
 
131
"   :type edge: :class:`ViewEdge`\n");
 
132
 
 
133
static PyObject *ViewShape_add_edge(BPy_ViewShape *self, PyObject *args, PyObject *kwds)
 
134
{
 
135
        static const char *kwlist[] = {"edge", NULL};
 
136
        PyObject *py_ve = 0;
 
137
 
 
138
        if (PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &ViewEdge_Type, &py_ve))
 
139
                return NULL;
 
140
        self->vs->AddEdge(((BPy_ViewEdge *)py_ve)->ve);
 
141
        Py_RETURN_NONE;
 
142
}
 
143
 
 
144
PyDoc_STRVAR(ViewShape_add_vertex_doc,
 
145
".. method:: add_vertex(vertex)\n"
 
146
"\n"
 
147
"   Adds a ViewVertex to the list of the ViewVertex objects.\n"
 
148
"\n"
 
149
"   :arg vertex: A ViewVertex object.\n"
 
150
"   :type vertex: :class:`ViewVertex`");
 
151
 
 
152
static PyObject *ViewShape_add_vertex(BPy_ViewShape *self, PyObject *args, PyObject *kwds)
 
153
{
 
154
        static const char *kwlist[] = {"vertex", NULL};
 
155
        PyObject *py_vv = 0;
 
156
 
 
157
        if (PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &ViewVertex_Type, &py_vv))
 
158
                return NULL;
 
159
        self->vs->AddVertex(((BPy_ViewVertex *)py_vv)->vv);
 
160
        Py_RETURN_NONE;
 
161
}
 
162
 
 
163
// virtual ViewShape *duplicate()
 
164
 
 
165
static PyMethodDef BPy_ViewShape_methods[] = {
 
166
        {"add_edge", (PyCFunction)ViewShape_add_edge, METH_VARARGS | METH_KEYWORDS, ViewShape_add_edge_doc},
 
167
        {"add_vertex", (PyCFunction)ViewShape_add_vertex, METH_VARARGS | METH_KEYWORDS, ViewShape_add_vertex_doc},
 
168
        {NULL, NULL, 0, NULL}
 
169
};
 
170
 
 
171
/*----------------------ViewShape get/setters ----------------------------*/
 
172
 
 
173
PyDoc_STRVAR(ViewShape_sshape_doc,
 
174
"The SShape on top of which this ViewShape is built.\n"
 
175
"\n"
 
176
":type: :class:`SShape`");
 
177
 
 
178
static PyObject *ViewShape_sshape_get(BPy_ViewShape *self, void *UNUSED(closure))
 
179
{
 
180
        SShape *ss = self->vs->sshape();
 
181
        if (!ss)
 
182
                Py_RETURN_NONE;
 
183
        return BPy_SShape_from_SShape(*ss);
 
184
}
 
185
 
 
186
static int ViewShape_sshape_set(BPy_ViewShape *self, PyObject *value, void *UNUSED(closure))
 
187
{
 
188
        if (!BPy_SShape_Check(value)) {
 
189
                PyErr_SetString(PyExc_TypeError, "value must be an SShape");
 
190
                return -1;
 
191
        }
 
192
        BPy_SShape *py_ss = (BPy_SShape *)value;
 
193
        self->vs->setSShape(py_ss->ss);
 
194
        if (self->py_ss)
 
195
                Py_DECREF(self->py_ss);
 
196
        if (!py_ss->borrowed) {
 
197
                self->py_ss = py_ss;
 
198
                Py_INCREF(self->py_ss);
 
199
        }
 
200
        return 0;
 
201
}
 
202
 
 
203
PyDoc_STRVAR(ViewShape_vertices_doc,
 
204
"The list of ViewVertex objects contained in this ViewShape.\n"
 
205
"\n"
 
206
":type: List of :class:`ViewVertex` objects");
 
207
 
 
208
static PyObject *ViewShape_vertices_get(BPy_ViewShape *self, void *UNUSED(closure))
 
209
{
 
210
        PyObject *py_vertices = PyList_New(0);
 
211
 
 
212
        vector<ViewVertex *> vertices = self->vs->vertices();
 
213
        vector<ViewVertex *>::iterator it;
 
214
        for (it = vertices.begin(); it != vertices.end(); it++) {
 
215
                PyList_Append( py_vertices, Any_BPy_ViewVertex_from_ViewVertex(*(*it)));
 
216
        }
 
217
        return py_vertices;
 
218
}
 
219
 
 
220
static int ViewShape_vertices_set(BPy_ViewShape *self, PyObject *value, void *UNUSED(closure))
 
221
{
 
222
        PyObject *list = 0;
 
223
        PyObject *item;
 
224
        vector< ViewVertex *> v;
 
225
        
 
226
        if (!PyList_Check(value)) {
 
227
                PyErr_SetString(PyExc_TypeError, "value must be a list of ViewVertex objects");
 
228
                return -1;
 
229
        }
 
230
        for (int i = 0; i < PyList_Size(list); i++) {
 
231
                item = PyList_GetItem(list, i);
 
232
                if (BPy_ViewVertex_Check(item)) {
 
233
                        v.push_back(((BPy_ViewVertex *)item)->vv);
 
234
                }
 
235
                else {
 
236
                        PyErr_SetString(PyExc_TypeError, "value must be a list of ViewVertex objects");
 
237
                        return -1;
 
238
                }
 
239
        }
 
240
        self->vs->setVertices(v);
 
241
        return 0;
 
242
}
 
243
 
 
244
PyDoc_STRVAR(ViewShape_edges_doc,
 
245
"The list of ViewEdge objects contained in this ViewShape.\n"
 
246
"\n"
 
247
":type: List of :class:`ViewEdge` objects");
 
248
 
 
249
static PyObject *ViewShape_edges_get(BPy_ViewShape *self, void *UNUSED(closure))
 
250
{
 
251
        PyObject *py_edges = PyList_New(0);
 
252
 
 
253
        vector<ViewEdge *> edges = self->vs->edges();
 
254
        vector<ViewEdge *>::iterator it;
 
255
 
 
256
        for (it = edges.begin(); it != edges.end(); it++) {
 
257
                PyList_Append(py_edges, BPy_ViewEdge_from_ViewEdge(*(*it)));
 
258
        }
 
259
        return py_edges;
 
260
}
 
261
 
 
262
static int ViewShape_edges_set(BPy_ViewShape *self, PyObject *value, void *UNUSED(closure))
 
263
{
 
264
        PyObject *list = 0;
 
265
        PyObject *item;
 
266
        vector<ViewEdge *> v;
 
267
 
 
268
        if (!PyList_Check(value)) {
 
269
                PyErr_SetString(PyExc_TypeError, "value must be a list of ViewEdge objects");
 
270
                return -1;
 
271
        }
 
272
        for (int i = 0; i < PyList_Size(list); i++) {
 
273
                item = PyList_GetItem(list, i);
 
274
                if (BPy_ViewEdge_Check(item)) {
 
275
                        v.push_back(((BPy_ViewEdge *)item)->ve);
 
276
                }
 
277
                else {
 
278
                        PyErr_SetString(PyExc_TypeError, "argument must be list of ViewEdge objects");
 
279
                        return -1;
 
280
                }
 
281
        }
 
282
        self->vs->setEdges(v);
 
283
        return 0;
 
284
}
 
285
 
 
286
PyDoc_STRVAR(ViewShape_name_doc,
 
287
"The name of the ViewShape.\n"
 
288
"\n"
 
289
":type: str");
 
290
 
 
291
static PyObject *ViewShape_name_get(BPy_ViewShape *self, void *UNUSED(closure))
 
292
{
 
293
        return PyUnicode_FromString(self->vs->getName().c_str());
 
294
}
 
295
 
 
296
PyDoc_STRVAR(ViewShape_id_doc,
 
297
"The Id of this ViewShape.\n"
 
298
"\n"
 
299
":type: :class:`Id`");
 
300
 
 
301
static PyObject *ViewShape_id_get(BPy_ViewShape *self, void *UNUSED(closure))
 
302
{
 
303
        Id id(self->vs->getId());
 
304
        return BPy_Id_from_Id(id); // return a copy
 
305
}
 
306
 
 
307
static PyGetSetDef BPy_ViewShape_getseters[] = {
 
308
        {(char *)"sshape", (getter)ViewShape_sshape_get, (setter)ViewShape_sshape_set, (char *)ViewShape_sshape_doc, NULL},
 
309
        {(char *)"vertices", (getter)ViewShape_vertices_get, (setter)ViewShape_vertices_set,
 
310
                             (char *)ViewShape_vertices_doc, NULL},
 
311
        {(char *)"edges", (getter)ViewShape_edges_get, (setter)ViewShape_edges_set, (char *)ViewShape_edges_doc, NULL},
 
312
        {(char *)"name", (getter)ViewShape_name_get, (setter)NULL, (char *)ViewShape_name_doc, NULL},
 
313
        {(char *)"id", (getter)ViewShape_id_get, (setter)NULL, (char *)ViewShape_id_doc, NULL},
 
314
        {NULL, NULL, NULL, NULL, NULL}  /* Sentinel */
 
315
};
 
316
 
 
317
/*-----------------------BPy_ViewShape type definition ------------------------------*/
 
318
 
 
319
PyTypeObject ViewShape_Type = {
 
320
        PyVarObject_HEAD_INIT(NULL, 0)
 
321
        "ViewShape",                    /* tp_name */
 
322
        sizeof(BPy_ViewShape),          /* tp_basicsize */
 
323
        0,                              /* tp_itemsize */
 
324
        (destructor)ViewShape_dealloc,  /* tp_dealloc */
 
325
        0,                              /* tp_print */
 
326
        0,                              /* tp_getattr */
 
327
        0,                              /* tp_setattr */
 
328
        0,                              /* tp_reserved */
 
329
        (reprfunc)ViewShape_repr,       /* tp_repr */
 
330
        0,                              /* tp_as_number */
 
331
        0,                              /* tp_as_sequence */
 
332
        0,                              /* tp_as_mapping */
 
333
        0,                              /* tp_hash  */
 
334
        0,                              /* tp_call */
 
335
        0,                              /* tp_str */
 
336
        0,                              /* tp_getattro */
 
337
        0,                              /* tp_setattro */
 
338
        0,                              /* tp_as_buffer */
 
339
        Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
 
340
        ViewShape_doc,              /* tp_doc */
 
341
        0,                              /* tp_traverse */
 
342
        0,                              /* tp_clear */
 
343
        0,                              /* tp_richcompare */
 
344
        0,                              /* tp_weaklistoffset */
 
345
        0,                              /* tp_iter */
 
346
        0,                              /* tp_iternext */
 
347
        BPy_ViewShape_methods,          /* tp_methods */
 
348
        0,                              /* tp_members */
 
349
        BPy_ViewShape_getseters,        /* tp_getset */
 
350
        0,                              /* tp_base */
 
351
        0,                              /* tp_dict */
 
352
        0,                              /* tp_descr_get */
 
353
        0,                              /* tp_descr_set */
 
354
        0,                              /* tp_dictoffset */
 
355
        (initproc)ViewShape_init,       /* tp_init */
 
356
        0,                              /* tp_alloc */
 
357
        PyType_GenericNew,              /* tp_new */
 
358
};
 
359
 
 
360
///////////////////////////////////////////////////////////////////////////////////////////
 
361
 
 
362
#ifdef __cplusplus
 
363
}
 
364
#endif