Made the Freestyle Python API compatible with Python 3.
[blender.git] / source / blender / freestyle / intern / python / Iterator / BPy_ViewEdgeIterator.cpp
1 #include "BPy_ViewEdgeIterator.h"
2
3 #include "../BPy_Convert.h"
4 #include "../Interface1D/BPy_ViewEdge.h"
5
6
7 #ifdef __cplusplus
8 extern "C" {
9 #endif
10
11 ///////////////////////////////////////////////////////////////////////////////////////////
12
13 /*---------------  Python API function prototypes for ViewEdgeIterator instance  -----------*/
14 static int ViewEdgeIterator___init__(BPy_ViewEdgeIterator *self, PyObject *args);
15
16 static PyObject * ViewEdgeIterator_getCurrentEdge( BPy_ViewEdgeIterator *self );
17 static PyObject * ViewEdgeIterator_setCurrentEdge( BPy_ViewEdgeIterator *self, PyObject *args );
18 static PyObject * ViewEdgeIterator_getBegin( BPy_ViewEdgeIterator *self );
19 static PyObject * ViewEdgeIterator_setBegin( BPy_ViewEdgeIterator *self, PyObject *args );
20 static PyObject * ViewEdgeIterator_getOrientation( BPy_ViewEdgeIterator *self );
21 static PyObject * ViewEdgeIterator_setOrientation( BPy_ViewEdgeIterator *self, PyObject *args );
22 static PyObject * ViewEdgeIterator_changeOrientation( BPy_ViewEdgeIterator *self );
23
24 static PyObject * ViewEdgeIterator_getObject(BPy_ViewEdgeIterator *self);
25
26
27 /*----------------------ViewEdgeIterator instance definitions ----------------------------*/
28 static PyMethodDef BPy_ViewEdgeIterator_methods[] = {
29         {"getCurrentEdge", ( PyCFunction ) ViewEdgeIterator_getCurrentEdge, METH_NOARGS, "() Returns the current pointed ViewEdge."},
30         {"setCurrentEdge", ( PyCFunction ) ViewEdgeIterator_setCurrentEdge, METH_VARARGS, "(ViewEdge ve) Sets the current pointed ViewEdge. "}, 
31         {"getBegin", ( PyCFunction ) ViewEdgeIterator_getBegin, METH_NOARGS, "() Returns the first ViewEdge used for the iteration."},
32         {"setBegin", ( PyCFunction ) ViewEdgeIterator_setBegin, METH_VARARGS, "(ViewEdge ve) Sets the first ViewEdge used for the iteration."},
33         {"getOrientation", ( PyCFunction ) ViewEdgeIterator_getOrientation, METH_NOARGS, "() Gets the orientation of the pointed ViewEdge in the iteration. "},
34         {"setOrientation", ( PyCFunction ) ViewEdgeIterator_setOrientation, METH_VARARGS, "(bool b) Sets the orientation of the pointed ViewEdge in the iteration. "},
35         {"changeOrientation", ( PyCFunction ) ViewEdgeIterator_changeOrientation, METH_NOARGS, "() Changes the current orientation."},
36         {"getObject", ( PyCFunction ) ViewEdgeIterator_getObject, METH_NOARGS, "() Get object referenced by the iterator"},
37         {NULL, NULL, 0, NULL}
38 };
39
40 /*-----------------------BPy_ViewEdgeIterator type definition ------------------------------*/
41
42 PyTypeObject ViewEdgeIterator_Type = {
43         PyObject_HEAD_INIT(NULL)
44         "ViewEdgeIterator",             /* tp_name */
45         sizeof(BPy_ViewEdgeIterator),   /* tp_basicsize */
46         0,                              /* tp_itemsize */
47         0,                              /* tp_dealloc */
48         0,                              /* tp_print */
49         0,                              /* tp_getattr */
50         0,                              /* tp_setattr */
51         0,                              /* tp_reserved */
52         0,                              /* tp_repr */
53         0,                              /* tp_as_number */
54         0,                              /* tp_as_sequence */
55         0,                              /* tp_as_mapping */
56         0,                              /* tp_hash  */
57         0,                              /* tp_call */
58         0,                              /* tp_str */
59         0,                              /* tp_getattro */
60         0,                              /* tp_setattro */
61         0,                              /* tp_as_buffer */
62         Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
63         "ViewEdgeIterator objects",     /* tp_doc */
64         0,                              /* tp_traverse */
65         0,                              /* tp_clear */
66         0,                              /* tp_richcompare */
67         0,                              /* tp_weaklistoffset */
68         0,                              /* tp_iter */
69         0,                              /* tp_iternext */
70         BPy_ViewEdgeIterator_methods,   /* tp_methods */
71         0,                              /* tp_members */
72         0,                              /* tp_getset */
73         &Iterator_Type,                 /* tp_base */
74         0,                              /* tp_dict */
75         0,                              /* tp_descr_get */
76         0,                              /* tp_descr_set */
77         0,                              /* tp_dictoffset */
78         (initproc)ViewEdgeIterator___init__, /* tp_init */
79         0,                              /* tp_alloc */
80         0,                              /* tp_new */
81 };
82
83 //------------------------INSTANCE METHODS ----------------------------------
84
85 int ViewEdgeIterator___init__(BPy_ViewEdgeIterator *self, PyObject *args )
86 {       
87         PyObject *obj1 = 0, *obj2 = 0;
88
89         if (!( PyArg_ParseTuple(args, "O|O", &obj1, &obj2) ))
90             return -1;
91
92         if( obj1 && BPy_ViewEdgeIterator_Check(obj1)  ) {
93                 self->ve_it = new ViewEdgeInternal::ViewEdgeIterator(*( ((BPy_ViewEdgeIterator *) obj1)->ve_it ));
94         
95         } else {
96                 ViewEdge *begin;
97                 if ( !obj1 || obj1 == Py_None )
98                         begin = NULL;
99                 else if ( BPy_ViewEdge_Check(obj1) )
100                         begin = ((BPy_ViewEdge *) obj1)->ve;
101                 else {
102                         PyErr_SetString(PyExc_TypeError, "1st argument must be either a ViewEdge object or None");
103                         return -1;
104                 }
105                 bool orientation = ( obj2 ) ? bool_from_PyBool(obj2) : true;
106                 
107                 self->ve_it = new ViewEdgeInternal::ViewEdgeIterator( begin, orientation);
108                 
109         }
110                 
111         self->py_it.it = self->ve_it;
112
113         return 0;
114 }
115
116
117 PyObject *ViewEdgeIterator_getCurrentEdge( BPy_ViewEdgeIterator *self ) {
118         ViewEdge *ve = self->ve_it->getCurrentEdge();
119         if( ve )
120                 return BPy_ViewEdge_from_ViewEdge( *ve );
121                 
122         Py_RETURN_NONE;
123 }
124
125 PyObject *ViewEdgeIterator_setCurrentEdge( BPy_ViewEdgeIterator *self, PyObject *args ) {
126         PyObject *py_ve;
127
128         if(!( PyArg_ParseTuple(args, "O!", &ViewEdge_Type, &py_ve) ))
129                 return NULL;
130
131         self->ve_it->setCurrentEdge( ((BPy_ViewEdge *) py_ve)->ve );
132                 
133         Py_RETURN_NONE;
134 }
135
136
137 PyObject *ViewEdgeIterator_getBegin( BPy_ViewEdgeIterator *self ) {
138         ViewEdge *ve = self->ve_it->getBegin();
139         if( ve )
140                 return BPy_ViewEdge_from_ViewEdge( *ve );
141                 
142         Py_RETURN_NONE;
143 }
144
145 PyObject *ViewEdgeIterator_setBegin( BPy_ViewEdgeIterator *self, PyObject *args ) {
146         PyObject *py_ve;
147
148         if(!( PyArg_ParseTuple(args, "O!", &ViewEdge_Type, &py_ve) ))
149                 return NULL;
150
151         self->ve_it->setBegin( ((BPy_ViewEdge *) py_ve)->ve );
152                 
153         Py_RETURN_NONE;
154 }
155
156 PyObject *ViewEdgeIterator_getOrientation( BPy_ViewEdgeIterator *self ) {
157         return PyBool_from_bool( self->ve_it->getOrientation() );
158 }
159
160 PyObject *ViewEdgeIterator_setOrientation( BPy_ViewEdgeIterator *self, PyObject *args ) {
161         PyObject *py_b;
162
163         if(!( PyArg_ParseTuple(args, "O", &py_b) ))
164                 return NULL;
165
166         self->ve_it->setOrientation( bool_from_PyBool(py_b) );
167                 
168         Py_RETURN_NONE;
169 }
170
171 PyObject *ViewEdgeIterator_changeOrientation( BPy_ViewEdgeIterator *self ) {
172         self->ve_it->changeOrientation();
173         
174         Py_RETURN_NONE;
175 }
176
177 PyObject * ViewEdgeIterator_getObject( BPy_ViewEdgeIterator *self) {
178
179         ViewEdge *ve = self->ve_it->operator*();
180         if( ve )
181                 return BPy_ViewEdge_from_ViewEdge( *ve );
182
183         Py_RETURN_NONE;
184 }
185
186
187 ///////////////////////////////////////////////////////////////////////////////////////////
188
189 #ifdef __cplusplus
190 }
191 #endif