Made the Freestyle Python API compatible with Python 3.
[blender.git] / source / blender / freestyle / intern / python / Interface1D / Curve / BPy_Chain.cpp
1 #include "BPy_Chain.h"
2
3 #include "../../BPy_Convert.h"
4 #include "../../BPy_Id.h"
5 #include "../BPy_ViewEdge.h"
6
7 #ifdef __cplusplus
8 extern "C" {
9 #endif
10
11 ///////////////////////////////////////////////////////////////////////////////////////////
12
13 /*---------------  Python API function prototypes for Chain instance  -----------*/
14 static int Chain___init__(BPy_Chain *self, PyObject *args, PyObject *kwds);
15 static PyObject * Chain_push_viewedge_back( BPy_Chain *self, PyObject *args );
16 static PyObject * Chain_push_viewedge_front( BPy_Chain *self, PyObject *args );
17
18
19 /*----------------------Chain instance definitions ----------------------------*/
20 static PyMethodDef BPy_Chain_methods[] = {      
21         {"push_viewedge_back", ( PyCFunction ) Chain_push_viewedge_back, METH_VARARGS, "(ViewEdge ve, bool orientation) Adds a ViewEdge at the end of the chain."},
22         {"push_viewedge_front", ( PyCFunction ) Chain_push_viewedge_front, METH_VARARGS, "(ViewEdge ve, bool orientation) Adds a ViewEdge at the beginning of the chain."},
23         {NULL, NULL, 0, NULL}
24 };
25
26 /*-----------------------BPy_Chain type definition ------------------------------*/
27
28 PyTypeObject Chain_Type = {
29         PyObject_HEAD_INIT(NULL)
30         "Chain",                        /* tp_name */
31         sizeof(BPy_Chain),              /* tp_basicsize */
32         0,                              /* tp_itemsize */
33         0,                              /* tp_dealloc */
34         0,                              /* tp_print */
35         0,                              /* tp_getattr */
36         0,                              /* tp_setattr */
37         0,                              /* tp_reserved */
38         0,                              /* tp_repr */
39         0,                              /* tp_as_number */
40         0,                              /* tp_as_sequence */
41         0,                              /* tp_as_mapping */
42         0,                              /* tp_hash  */
43         0,                              /* tp_call */
44         0,                              /* tp_str */
45         0,                              /* tp_getattro */
46         0,                              /* tp_setattro */
47         0,                              /* tp_as_buffer */
48         Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
49         "Chain objects",                /* tp_doc */
50         0,                              /* tp_traverse */
51         0,                              /* tp_clear */
52         0,                              /* tp_richcompare */
53         0,                              /* tp_weaklistoffset */
54         0,                              /* tp_iter */
55         0,                              /* tp_iternext */
56         BPy_Chain_methods,              /* tp_methods */
57         0,                              /* tp_members */
58         0,                              /* tp_getset */
59         &FrsCurve_Type,                 /* tp_base */
60         0,                              /* tp_dict */
61         0,                              /* tp_descr_get */
62         0,                              /* tp_descr_set */
63         0,                              /* tp_dictoffset */
64         (initproc)Chain___init__,       /* tp_init */
65         0,                              /* tp_alloc */
66         0,                              /* tp_new */
67 };
68
69 //------------------------INSTANCE METHODS ----------------------------------
70
71 int Chain___init__(BPy_Chain *self, PyObject *args, PyObject *kwds)
72 {
73
74         PyObject *obj = 0;
75
76     if (! PyArg_ParseTuple(args, "|O", &obj) )
77         return -1;
78
79         if( !obj ){
80                 self->c = new Chain();
81                 
82         } else if( BPy_Chain_Check(obj) ) {
83                 self->c = new Chain(*( ((BPy_Chain *) obj)->c ));
84                 
85         } else if( BPy_Id_Check(obj) ) {
86                 self->c = new Chain(*( ((BPy_Id *) obj)->id ));
87                         
88         } else {
89                 PyErr_SetString(PyExc_TypeError, "invalid argument");
90                 return -1;
91         }
92
93         self->py_c.c = self->c;
94         self->py_c.py_if1D.if1D = self->c;
95         self->py_c.py_if1D.borrowed = 0;
96
97         return 0;
98 }
99
100
101 PyObject * Chain_push_viewedge_back( BPy_Chain *self, PyObject *args ) {
102         PyObject *obj1 = 0, *obj2 = 0;
103
104         if(!( PyArg_ParseTuple(args, "O!O", &ViewEdge_Type, &obj1, &obj2) ))
105                 return NULL;
106
107         ViewEdge *ve = ((BPy_ViewEdge *) obj1)->ve;
108         bool orientation = bool_from_PyBool( obj2 );
109         self->c->push_viewedge_back( ve, orientation);
110
111         Py_RETURN_NONE;
112 }
113
114 PyObject * Chain_push_viewedge_front( BPy_Chain *self, PyObject *args ) {
115         PyObject *obj1 = 0, *obj2 = 0;
116
117         if(!( PyArg_ParseTuple(args, "O!O", &ViewEdge_Type, &obj1, &obj2) ))
118                 return NULL;
119
120         ViewEdge *ve = ((BPy_ViewEdge *) obj1)->ve;
121         bool orientation = bool_from_PyBool( obj2 );
122         self->c->push_viewedge_front(ve, orientation);
123
124         Py_RETURN_NONE;
125 }
126
127
128
129
130
131 ///////////////////////////////////////////////////////////////////////////////////////////
132
133 #ifdef __cplusplus
134 }
135 #endif