Made the Freestyle Python API compatible with Python 3.
[blender.git] / source / blender / freestyle / intern / python / Interface0D / BPy_ViewVertex.cpp
1 #include "BPy_ViewVertex.h"
2
3 #include "../BPy_Convert.h"
4 #include "../Interface1D/BPy_ViewEdge.h"
5 #include "../BPy_Nature.h"
6
7 #ifdef __cplusplus
8 extern "C" {
9 #endif
10
11 ///////////////////////////////////////////////////////////////////////////////////////////
12
13 /*---------------  Python API function prototypes for ViewVertex instance  -----------*/
14 static int ViewVertex___init__( BPy_ViewVertex *self, PyObject *args, PyObject *kwds );
15 static PyObject * ViewVertex_setNature( BPy_ViewVertex *self, PyObject *args );
16 static PyObject * ViewVertex_edgesBegin( BPy_ViewVertex *self );
17 static PyObject * ViewVertex_edgesEnd( BPy_ViewVertex *self );
18 static PyObject * ViewVertex_edgesIterator( BPy_ViewVertex *self, PyObject *args );
19
20 /*----------------------ViewVertex instance definitions ----------------------------*/
21 static PyMethodDef BPy_ViewVertex_methods[] = {
22         {"setNature", ( PyCFunction ) ViewVertex_setNature, METH_VARARGS, "(Nature n) Sets the nature of the vertex."},
23         {"edgesBegin", ( PyCFunction ) ViewVertex_edgesBegin, METH_NOARGS, "() Returns an iterator over the ViewEdges that goes to or comes from this ViewVertex pointing to the first ViewEdge of the list. The orientedViewEdgeIterator allows to iterate in CCW order over these ViewEdges and to get the orientation for each ViewEdge (incoming/outgoing). "},
24         {"edgesEnd", ( PyCFunction ) ViewVertex_edgesEnd, METH_NOARGS, "() Returns an orientedViewEdgeIterator over the ViewEdges around this ViewVertex, pointing after the last ViewEdge."},
25         {"edgesIterator", ( PyCFunction ) ViewVertex_edgesIterator, METH_VARARGS, "(ViewEdge ve) Returns an orientedViewEdgeIterator pointing to the ViewEdge given as argument. "},
26         {NULL, NULL, 0, NULL}
27 };
28
29 /*-----------------------BPy_ViewVertex type definition ------------------------------*/
30
31 PyTypeObject ViewVertex_Type = {
32         PyObject_HEAD_INIT(NULL)
33         "ViewVertex",                   /* tp_name */
34         sizeof(BPy_ViewVertex),         /* tp_basicsize */
35         0,                              /* tp_itemsize */
36         0,                              /* tp_dealloc */
37         0,                              /* tp_print */
38         0,                              /* tp_getattr */
39         0,                              /* tp_setattr */
40         0,                              /* tp_reserved */
41         0,                              /* tp_repr */
42         0,                              /* tp_as_number */
43         0,                              /* tp_as_sequence */
44         0,                              /* tp_as_mapping */
45         0,                              /* tp_hash  */
46         0,                              /* tp_call */
47         0,                              /* tp_str */
48         0,                              /* tp_getattro */
49         0,                              /* tp_setattro */
50         0,                              /* tp_as_buffer */
51         Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
52         "ViewVertex objects",           /* tp_doc */
53         0,                              /* tp_traverse */
54         0,                              /* tp_clear */
55         0,                              /* tp_richcompare */
56         0,                              /* tp_weaklistoffset */
57         0,                              /* tp_iter */
58         0,                              /* tp_iternext */
59         BPy_ViewVertex_methods,         /* tp_methods */
60         0,                              /* tp_members */
61         0,                              /* tp_getset */
62         &Interface0D_Type,              /* tp_base */
63         0,                              /* tp_dict */
64         0,                              /* tp_descr_get */
65         0,                              /* tp_descr_set */
66         0,                              /* tp_dictoffset */
67         (initproc)ViewVertex___init__,  /* tp_init */
68         0,                              /* tp_alloc */
69         0,                              /* tp_new */
70 };
71
72 //------------------------INSTANCE METHODS ----------------------------------
73
74 int ViewVertex___init__( BPy_ViewVertex *self, PyObject *args, PyObject *kwds )
75 {       
76     if( !PyArg_ParseTuple(args, "") )
77         return -1;
78         self->vv = 0; // ViewVertex is abstract
79         self->py_if0D.if0D = self->vv;
80         self->py_if0D.borrowed = 0;
81         return 0;
82 }
83
84
85
86 PyObject * ViewVertex_setNature( BPy_ViewVertex *self, PyObject *args ) {
87         PyObject *py_n;
88
89         if( !self->vv )
90                 Py_RETURN_NONE;
91                 
92         if(!( PyArg_ParseTuple(args, "O!", &Nature_Type, &py_n) ))
93                 return NULL;
94         
95         PyObject *i = (PyObject *) &( ((BPy_Nature *) py_n)->i );
96         ((ViewVertex *) self->py_if0D.if0D)->setNature( PyLong_AsLong(i) );
97
98         Py_RETURN_NONE;
99 }
100
101 PyObject * ViewVertex_edgesBegin( BPy_ViewVertex *self ) {
102         if( !self->vv )
103                 Py_RETURN_NONE;
104                 
105         ViewVertexInternal::orientedViewEdgeIterator ove_it( self->vv->edgesBegin() );
106         return BPy_orientedViewEdgeIterator_from_orientedViewEdgeIterator( ove_it, 0 );
107 }
108
109 PyObject * ViewVertex_edgesEnd( BPy_ViewVertex *self ) {
110 #if 0
111         if( !self->vv )
112                 Py_RETURN_NONE;
113                 
114         ViewVertexInternal::orientedViewEdgeIterator ove_it( self->vv->edgesEnd() );
115         return BPy_orientedViewEdgeIterator_from_orientedViewEdgeIterator( ove_it, 1 );
116 #else
117         PyErr_SetString(PyExc_NotImplementedError, "edgesEnd method currently disabled");
118         return NULL;
119 #endif
120 }
121
122
123 PyObject * ViewVertex_edgesIterator( BPy_ViewVertex *self, PyObject *args ) {
124         PyObject *py_ve;
125
126         if( !self->vv )
127                 Py_RETURN_NONE;
128
129         if(!( PyArg_ParseTuple(args, "O!", &ViewEdge_Type, &py_ve) ))
130                 return NULL;
131         
132         ViewEdge *ve = ((BPy_ViewEdge *) py_ve)->ve;
133         ViewVertexInternal::orientedViewEdgeIterator ove_it( self->vv->edgesIterator( ve ) );
134         return BPy_orientedViewEdgeIterator_from_orientedViewEdgeIterator( ove_it, 0 );
135 }
136
137
138 ///////////////////////////////////////////////////////////////////////////////////////////
139
140 #ifdef __cplusplus
141 }
142 #endif
143