Made the Freestyle Python API compatible with Python 3.
[blender.git] / source / blender / freestyle / intern / python / UnaryFunction1D / BPy_UnaryFunction1DVectorViewShape.cpp
1 #include "BPy_UnaryFunction1DVectorViewShape.h"
2
3 #include "../BPy_Convert.h"
4 #include "../BPy_Interface1D.h"
5 #include "../BPy_IntegrationType.h"
6
7 #include "UnaryFunction1D_vector_ViewShape/BPy_GetOccludeeF1D.h"
8 #include "UnaryFunction1D_vector_ViewShape/BPy_GetOccludersF1D.h"
9 #include "UnaryFunction1D_vector_ViewShape/BPy_GetShapeF1D.h"
10
11 #ifdef __cplusplus
12 extern "C" {
13 #endif
14
15 ///////////////////////////////////////////////////////////////////////////////////////////
16
17 /*---------------  Python API function prototypes for UnaryFunction1DVectorViewShape instance  -----------*/
18 static int UnaryFunction1DVectorViewShape___init__(BPy_UnaryFunction1DVectorViewShape* self, PyObject *args);
19 static void UnaryFunction1DVectorViewShape___dealloc__(BPy_UnaryFunction1DVectorViewShape* self);
20 static PyObject * UnaryFunction1DVectorViewShape___repr__(BPy_UnaryFunction1DVectorViewShape* self);
21
22 static PyObject * UnaryFunction1DVectorViewShape_getName( BPy_UnaryFunction1DVectorViewShape *self);
23 static PyObject * UnaryFunction1DVectorViewShape___call__( BPy_UnaryFunction1DVectorViewShape *self, PyObject *args, PyObject *kwds);
24 static PyObject * UnaryFunction1DVectorViewShape_setIntegrationType(BPy_UnaryFunction1DVectorViewShape* self, PyObject *args);
25 static PyObject * UnaryFunction1DVectorViewShape_getIntegrationType(BPy_UnaryFunction1DVectorViewShape* self);
26
27 /*----------------------UnaryFunction1DVectorViewShape instance definitions ----------------------------*/
28 static PyMethodDef BPy_UnaryFunction1DVectorViewShape_methods[] = {
29         {"getName", ( PyCFunction ) UnaryFunction1DVectorViewShape_getName, METH_NOARGS, "() Returns the string of the name of the unary 1D function."},
30         {"setIntegrationType", ( PyCFunction ) UnaryFunction1DVectorViewShape_setIntegrationType, METH_VARARGS, "(IntegrationType i) Sets the integration method" },
31         {"getIntegrationType", ( PyCFunction ) UnaryFunction1DVectorViewShape_getIntegrationType, METH_NOARGS, "() Returns the integration method." },
32         {NULL, NULL, 0, NULL}
33 };
34
35 /*-----------------------BPy_UnaryFunction1DVectorViewShape type definition ------------------------------*/
36
37 PyTypeObject UnaryFunction1DVectorViewShape_Type = {
38         PyObject_HEAD_INIT(NULL)
39         "UnaryFunction1DVectorViewShape", /* tp_name */
40         sizeof(BPy_UnaryFunction1DVectorViewShape), /* tp_basicsize */
41         0,                              /* tp_itemsize */
42         (destructor)UnaryFunction1DVectorViewShape___dealloc__, /* tp_dealloc */
43         0,                              /* tp_print */
44         0,                              /* tp_getattr */
45         0,                              /* tp_setattr */
46         0,                              /* tp_reserved */
47         (reprfunc)UnaryFunction1DVectorViewShape___repr__, /* tp_repr */
48         0,                              /* tp_as_number */
49         0,                              /* tp_as_sequence */
50         0,                              /* tp_as_mapping */
51         0,                              /* tp_hash  */
52         (ternaryfunc)UnaryFunction1DVectorViewShape___call__, /* tp_call */
53         0,                              /* tp_str */
54         0,                              /* tp_getattro */
55         0,                              /* tp_setattro */
56         0,                              /* tp_as_buffer */
57         Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
58         "UnaryFunction1DVectorViewShape objects", /* tp_doc */
59         0,                              /* tp_traverse */
60         0,                              /* tp_clear */
61         0,                              /* tp_richcompare */
62         0,                              /* tp_weaklistoffset */
63         0,                              /* tp_iter */
64         0,                              /* tp_iternext */
65         BPy_UnaryFunction1DVectorViewShape_methods, /* tp_methods */
66         0,                              /* tp_members */
67         0,                              /* tp_getset */
68         &UnaryFunction1D_Type,          /* tp_base */
69         0,                              /* tp_dict */
70         0,                              /* tp_descr_get */
71         0,                              /* tp_descr_set */
72         0,                              /* tp_dictoffset */
73         (initproc)UnaryFunction1DVectorViewShape___init__, /* tp_init */
74         0,                              /* tp_alloc */
75         0,                              /* tp_new */
76 };
77
78 //-------------------MODULE INITIALIZATION--------------------------------
79
80 int UnaryFunction1DVectorViewShape_Init( PyObject *module ) {
81
82         if( module == NULL )
83                 return -1;
84
85         if( PyType_Ready( &UnaryFunction1DVectorViewShape_Type ) < 0 )
86                 return -1;
87         Py_INCREF( &UnaryFunction1DVectorViewShape_Type );
88         PyModule_AddObject(module, "UnaryFunction1DVectorViewShape", (PyObject *)&UnaryFunction1DVectorViewShape_Type);
89         
90         if( PyType_Ready( &GetOccludeeF1D_Type ) < 0 )
91                 return -1;
92         Py_INCREF( &GetOccludeeF1D_Type );
93         PyModule_AddObject(module, "GetOccludeeF1D", (PyObject *)&GetOccludeeF1D_Type);
94
95         if( PyType_Ready( &GetOccludersF1D_Type ) < 0 )
96                 return -1;
97         Py_INCREF( &GetOccludersF1D_Type );
98         PyModule_AddObject(module, "GetOccludersF1D", (PyObject *)&GetOccludersF1D_Type);
99         
100         if( PyType_Ready( &GetShapeF1D_Type ) < 0 )
101                 return -1;
102         Py_INCREF( &GetShapeF1D_Type );
103         PyModule_AddObject(module, "GetShapeF1D", (PyObject *)&GetShapeF1D_Type);
104
105         return 0;
106 }
107
108
109 //------------------------INSTANCE METHODS ----------------------------------
110
111 int UnaryFunction1DVectorViewShape___init__(BPy_UnaryFunction1DVectorViewShape* self, PyObject *args)
112 {
113         PyObject *obj = 0;
114
115         if( !PyArg_ParseTuple(args, "|O!", &IntegrationType_Type, &obj) )
116                 return -1;
117         
118         if( !obj )
119                 self->uf1D_vectorviewshape = new UnaryFunction1D< std::vector<ViewShape*> >();
120         else {
121                 self->uf1D_vectorviewshape = new UnaryFunction1D< std::vector<ViewShape*> >( IntegrationType_from_BPy_IntegrationType(obj) );
122         }
123         
124         self->uf1D_vectorviewshape->py_uf1D = (PyObject *)self;
125         
126         return 0;
127 }
128
129 void UnaryFunction1DVectorViewShape___dealloc__(BPy_UnaryFunction1DVectorViewShape* self)
130 {
131         if (self->uf1D_vectorviewshape)
132                 delete self->uf1D_vectorviewshape;
133         UnaryFunction1D_Type.tp_dealloc((PyObject*)self);
134 }
135
136
137 PyObject * UnaryFunction1DVectorViewShape___repr__(BPy_UnaryFunction1DVectorViewShape* self)
138 {
139         return PyUnicode_FromFormat("type: %s - address: %p", self->uf1D_vectorviewshape->getName().c_str(), self->uf1D_vectorviewshape );
140 }
141
142 PyObject * UnaryFunction1DVectorViewShape_getName( BPy_UnaryFunction1DVectorViewShape *self )
143 {
144         return PyUnicode_FromFormat( self->uf1D_vectorviewshape->getName().c_str() );
145 }
146
147 PyObject * UnaryFunction1DVectorViewShape___call__( BPy_UnaryFunction1DVectorViewShape *self, PyObject *args, PyObject *kwds)
148 {
149         PyObject *obj;
150
151         if( kwds != NULL ) {
152                 PyErr_SetString(PyExc_TypeError, "keyword argument(s) not supported");
153                 return NULL;
154         }
155         if( !PyArg_ParseTuple(args, "O!", &Interface1D_Type, &obj) )
156                 return NULL;
157         
158         if( typeid(*(self->uf1D_vectorviewshape)) == typeid(UnaryFunction1D< std::vector<ViewShape*> >) ) {
159                 PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden");
160                 return NULL;
161         }
162         if (self->uf1D_vectorviewshape->operator()(*( ((BPy_Interface1D *) obj)->if1D )) < 0) {
163                 if (!PyErr_Occurred()) {
164                         string msg(self->uf1D_vectorviewshape->getName() + " __call__ method failed");
165                         PyErr_SetString(PyExc_RuntimeError, msg.c_str());
166                 }
167                 return NULL;
168         }
169         PyObject *list = PyList_New(NULL);
170         
171         for( unsigned int i = 0; i < self->uf1D_vectorviewshape->result.size(); i++)
172                 PyList_Append(list, BPy_ViewShape_from_ViewShape(*( self->uf1D_vectorviewshape->result[i] )) );
173         
174         return list;
175 }
176
177 PyObject * UnaryFunction1DVectorViewShape_setIntegrationType(BPy_UnaryFunction1DVectorViewShape* self, PyObject *args)
178 {
179         PyObject *obj;
180
181         if( !PyArg_ParseTuple(args, "O!", &IntegrationType_Type, &obj) )
182                 return NULL;
183         
184         self->uf1D_vectorviewshape->setIntegrationType( IntegrationType_from_BPy_IntegrationType(obj) );
185         Py_RETURN_NONE;
186 }
187
188 PyObject * UnaryFunction1DVectorViewShape_getIntegrationType(BPy_UnaryFunction1DVectorViewShape* self) {
189         return BPy_IntegrationType_from_IntegrationType( self->uf1D_vectorviewshape->getIntegrationType() );
190 }
191
192 ///////////////////////////////////////////////////////////////////////////////////////////
193
194 #ifdef __cplusplus
195 }
196 #endif