Made the Freestyle Python API compatible with Python 3.
[blender.git] / source / blender / freestyle / intern / python / UnaryFunction0D / BPy_UnaryFunction0DMaterial.cpp
1 #include "BPy_UnaryFunction0DMaterial.h"
2
3 #include "../BPy_Convert.h"
4 #include "../Iterator/BPy_Interface0DIterator.h"
5
6 #include "UnaryFunction0D_Material/BPy_MaterialF0D.h"
7
8 #ifdef __cplusplus
9 extern "C" {
10 #endif
11
12 ///////////////////////////////////////////////////////////////////////////////////////////
13
14 /*---------------  Python API function prototypes for UnaryFunction0DMaterial instance  -----------*/
15 static int UnaryFunction0DMaterial___init__(BPy_UnaryFunction0DMaterial* self, PyObject *args, PyObject *kwds);
16 static void UnaryFunction0DMaterial___dealloc__(BPy_UnaryFunction0DMaterial* self);
17 static PyObject * UnaryFunction0DMaterial___repr__(BPy_UnaryFunction0DMaterial* self);
18
19 static PyObject * UnaryFunction0DMaterial_getName( BPy_UnaryFunction0DMaterial *self);
20 static PyObject * UnaryFunction0DMaterial___call__( BPy_UnaryFunction0DMaterial *self, PyObject *args, PyObject *kwds);
21
22 /*----------------------UnaryFunction0DMaterial instance definitions ----------------------------*/
23 static PyMethodDef BPy_UnaryFunction0DMaterial_methods[] = {
24         {"getName", ( PyCFunction ) UnaryFunction0DMaterial_getName, METH_NOARGS, "() Returns the string of the name of the unary 0D function."},
25         {NULL, NULL, 0, NULL}
26 };
27
28 /*-----------------------BPy_UnaryFunction0DMaterial type definition ------------------------------*/
29
30 PyTypeObject UnaryFunction0DMaterial_Type = {
31         PyVarObject_HEAD_INIT(NULL, 0)
32         "UnaryFunction0DMaterial",      /* tp_name */
33         sizeof(BPy_UnaryFunction0DMaterial), /* tp_basicsize */
34         0,                              /* tp_itemsize */
35         (destructor)UnaryFunction0DMaterial___dealloc__, /* tp_dealloc */
36         0,                              /* tp_print */
37         0,                              /* tp_getattr */
38         0,                              /* tp_setattr */
39         0,                              /* tp_reserved */
40         (reprfunc)UnaryFunction0DMaterial___repr__, /* tp_repr */
41         0,                              /* tp_as_number */
42         0,                              /* tp_as_sequence */
43         0,                              /* tp_as_mapping */
44         0,                              /* tp_hash  */
45         (ternaryfunc)UnaryFunction0DMaterial___call__, /* tp_call */
46         0,                              /* tp_str */
47         0,                              /* tp_getattro */
48         0,                              /* tp_setattro */
49         0,                              /* tp_as_buffer */
50         Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
51         "UnaryFunction0DMaterial objects", /* tp_doc */
52         0,                              /* tp_traverse */
53         0,                              /* tp_clear */
54         0,                              /* tp_richcompare */
55         0,                              /* tp_weaklistoffset */
56         0,                              /* tp_iter */
57         0,                              /* tp_iternext */
58         BPy_UnaryFunction0DMaterial_methods, /* tp_methods */
59         0,                              /* tp_members */
60         0,                              /* tp_getset */
61         &UnaryFunction0D_Type,          /* tp_base */
62         0,                              /* tp_dict */
63         0,                              /* tp_descr_get */
64         0,                              /* tp_descr_set */
65         0,                              /* tp_dictoffset */
66         (initproc)UnaryFunction0DMaterial___init__, /* tp_init */
67         0,                              /* tp_alloc */
68         0,                              /* tp_new */
69 };
70
71 //-------------------MODULE INITIALIZATION--------------------------------
72
73 int UnaryFunction0DMaterial_Init( PyObject *module ) {
74
75         if( module == NULL )
76                 return -1;
77
78         if( PyType_Ready( &UnaryFunction0DMaterial_Type ) < 0 )
79                 return -1;
80         Py_INCREF( &UnaryFunction0DMaterial_Type );
81         PyModule_AddObject(module, "UnaryFunction0DMaterial", (PyObject *)&UnaryFunction0DMaterial_Type);
82         
83         if( PyType_Ready( &MaterialF0D_Type ) < 0 )
84                 return -1;
85         Py_INCREF( &MaterialF0D_Type );
86         PyModule_AddObject(module, "MaterialF0D", (PyObject *)&MaterialF0D_Type);
87
88         return 0;
89 }
90
91 //------------------------INSTANCE METHODS ----------------------------------
92
93 int UnaryFunction0DMaterial___init__(BPy_UnaryFunction0DMaterial* self, PyObject *args, PyObject *kwds)
94 {
95     if ( !PyArg_ParseTuple(args, "") )
96         return -1;
97         self->uf0D_material = new UnaryFunction0D<FrsMaterial>();
98         self->uf0D_material->py_uf0D = (PyObject *)self;
99         return 0;
100 }
101
102 void UnaryFunction0DMaterial___dealloc__(BPy_UnaryFunction0DMaterial* self)
103 {
104         if (self->uf0D_material)
105                 delete self->uf0D_material;
106         UnaryFunction0D_Type.tp_dealloc((PyObject*)self);
107 }
108
109
110 PyObject * UnaryFunction0DMaterial___repr__(BPy_UnaryFunction0DMaterial* self)
111 {
112         return PyUnicode_FromFormat("type: %s - address: %p", self->uf0D_material->getName().c_str(), self->uf0D_material );
113 }
114
115 PyObject * UnaryFunction0DMaterial_getName( BPy_UnaryFunction0DMaterial *self )
116 {
117         return PyUnicode_FromFormat( self->uf0D_material->getName().c_str() );
118 }
119
120 PyObject * UnaryFunction0DMaterial___call__( BPy_UnaryFunction0DMaterial *self, PyObject *args, PyObject *kwds)
121 {
122         PyObject *obj;
123
124         if( kwds != NULL ) {
125                 PyErr_SetString(PyExc_TypeError, "keyword argument(s) not supported");
126                 return NULL;
127         }
128         if(!PyArg_ParseTuple(args, "O!", &Interface0DIterator_Type, &obj))
129                 return NULL;
130         
131         if( typeid(*(self->uf0D_material)) == typeid(UnaryFunction0D<FrsMaterial>) ) {
132                 PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden");
133                 return NULL;
134         }
135         if (self->uf0D_material->operator()(*( ((BPy_Interface0DIterator *) obj)->if0D_it )) < 0) {
136                 if (!PyErr_Occurred()) {
137                         string msg(self->uf0D_material->getName() + " __call__ method failed");
138                         PyErr_SetString(PyExc_RuntimeError, msg.c_str());
139                 }
140                 return NULL;
141         }
142         return BPy_FrsMaterial_from_FrsMaterial( self->uf0D_material->result );
143
144 }
145
146 ///////////////////////////////////////////////////////////////////////////////////////////
147
148 #ifdef __cplusplus
149 }
150 #endif