Made the Freestyle Python API compatible with Python 3.
[blender.git] / source / blender / freestyle / intern / python / UnaryFunction0D / BPy_UnaryFunction0DFloat.cpp
1 #include "BPy_UnaryFunction0DFloat.h"
2
3 #include "../BPy_Convert.h"
4 #include "../Iterator/BPy_Interface0DIterator.h"
5
6 #include "UnaryFunction0D_float/BPy_GetCurvilinearAbscissaF0D.h"
7 #include "UnaryFunction0D_float/BPy_GetParameterF0D.h"
8 #include "UnaryFunction0D_float/BPy_GetViewMapGradientNormF0D.h"
9 #include "UnaryFunction0D_float/BPy_ReadCompleteViewMapPixelF0D.h"
10 #include "UnaryFunction0D_float/BPy_ReadMapPixelF0D.h"
11 #include "UnaryFunction0D_float/BPy_ReadSteerableViewMapPixelF0D.h"
12
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16
17 ///////////////////////////////////////////////////////////////////////////////////////////
18
19 /*---------------  Python API function prototypes for UnaryFunction0DFloat instance  -----------*/
20 static int UnaryFunction0DFloat___init__(BPy_UnaryFunction0DFloat* self, PyObject *args, PyObject *kwds);
21 static void UnaryFunction0DFloat___dealloc__(BPy_UnaryFunction0DFloat* self);
22 static PyObject * UnaryFunction0DFloat___repr__(BPy_UnaryFunction0DFloat* self);
23
24 static PyObject * UnaryFunction0DFloat_getName( BPy_UnaryFunction0DFloat *self);
25 static PyObject * UnaryFunction0DFloat___call__( BPy_UnaryFunction0DFloat *self, PyObject *args, PyObject *kwds);
26
27 /*----------------------UnaryFunction0DFloat instance definitions ----------------------------*/
28 static PyMethodDef BPy_UnaryFunction0DFloat_methods[] = {
29         {"getName", ( PyCFunction ) UnaryFunction0DFloat_getName, METH_NOARGS, "() Returns the string of the name of the unary 0D function."},
30         {NULL, NULL, 0, NULL}
31 };
32
33 /*-----------------------BPy_UnaryFunction0DFloat type definition ------------------------------*/
34
35 PyTypeObject UnaryFunction0DFloat_Type = {
36         PyVarObject_HEAD_INIT(NULL, 0)
37         "UnaryFunction0DFloat",         /* tp_name */
38         sizeof(BPy_UnaryFunction0DFloat), /* tp_basicsize */
39         0,                              /* tp_itemsize */
40         (destructor)UnaryFunction0DFloat___dealloc__, /* tp_dealloc */
41         0,                              /* tp_print */
42         0,                              /* tp_getattr */
43         0,                              /* tp_setattr */
44         0,                              /* tp_reserved */
45         (reprfunc)UnaryFunction0DFloat___repr__, /* tp_repr */
46         0,                              /* tp_as_number */
47         0,                              /* tp_as_sequence */
48         0,                              /* tp_as_mapping */
49         0,                              /* tp_hash  */
50         (ternaryfunc)UnaryFunction0DFloat___call__, /* tp_call */
51         0,                              /* tp_str */
52         0,                              /* tp_getattro */
53         0,                              /* tp_setattro */
54         0,                              /* tp_as_buffer */
55         Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
56         "UnaryFunction0DFloat objects", /* tp_doc */
57         0,                              /* tp_traverse */
58         0,                              /* tp_clear */
59         0,                              /* tp_richcompare */
60         0,                              /* tp_weaklistoffset */
61         0,                              /* tp_iter */
62         0,                              /* tp_iternext */
63         BPy_UnaryFunction0DFloat_methods, /* tp_methods */
64         0,                              /* tp_members */
65         0,                              /* tp_getset */
66         &UnaryFunction0D_Type,          /* tp_base */
67         0,                              /* tp_dict */
68         0,                              /* tp_descr_get */
69         0,                              /* tp_descr_set */
70         0,                              /* tp_dictoffset */
71         (initproc)UnaryFunction0DFloat___init__, /* tp_init */
72         0,                              /* tp_alloc */
73         0,                              /* tp_new */
74 };
75
76 //-------------------MODULE INITIALIZATION--------------------------------
77
78 int UnaryFunction0DFloat_Init( PyObject *module ) {
79
80         if( module == NULL )
81                 return -1;
82
83         if( PyType_Ready( &UnaryFunction0DFloat_Type ) < 0 )
84                 return -1;
85         Py_INCREF( &UnaryFunction0DFloat_Type );
86         PyModule_AddObject(module, "UnaryFunction0DFloat", (PyObject *)&UnaryFunction0DFloat_Type);
87         
88         if( PyType_Ready( &GetCurvilinearAbscissaF0D_Type ) < 0 )
89                 return -1;
90         Py_INCREF( &GetCurvilinearAbscissaF0D_Type );
91         PyModule_AddObject(module, "GetCurvilinearAbscissaF0D", (PyObject *)&GetCurvilinearAbscissaF0D_Type);
92         
93         if( PyType_Ready( &GetParameterF0D_Type ) < 0 )
94                 return -1;
95         Py_INCREF( &GetParameterF0D_Type );
96         PyModule_AddObject(module, "GetParameterF0D", (PyObject *)&GetParameterF0D_Type);
97                 
98         if( PyType_Ready( &GetViewMapGradientNormF0D_Type ) < 0 )
99                 return -1;
100         Py_INCREF( &GetViewMapGradientNormF0D_Type );
101         PyModule_AddObject(module, "GetViewMapGradientNormF0D", (PyObject *)&GetViewMapGradientNormF0D_Type);
102         
103         if( PyType_Ready( &ReadCompleteViewMapPixelF0D_Type ) < 0 )
104                 return -1;
105         Py_INCREF( &ReadCompleteViewMapPixelF0D_Type );
106         PyModule_AddObject(module, "ReadCompleteViewMapPixelF0D", (PyObject *)&ReadCompleteViewMapPixelF0D_Type);
107         
108         if( PyType_Ready( &ReadMapPixelF0D_Type ) < 0 )
109                 return -1;
110         Py_INCREF( &ReadMapPixelF0D_Type );
111         PyModule_AddObject(module, "ReadMapPixelF0D", (PyObject *)&ReadMapPixelF0D_Type);
112         
113         if( PyType_Ready( &ReadSteerableViewMapPixelF0D_Type ) < 0 )
114                 return -1;
115         Py_INCREF( &ReadSteerableViewMapPixelF0D_Type );
116         PyModule_AddObject(module, "ReadSteerableViewMapPixelF0D", (PyObject *)&ReadSteerableViewMapPixelF0D_Type);
117
118         return 0;
119 }
120
121 //------------------------INSTANCE METHODS ----------------------------------
122
123 int UnaryFunction0DFloat___init__(BPy_UnaryFunction0DFloat* self, PyObject *args, PyObject *kwds)
124 {
125     if ( !PyArg_ParseTuple(args, "") )
126         return -1;
127         self->uf0D_float = new UnaryFunction0D<float>();
128         self->uf0D_float->py_uf0D = (PyObject *)self;
129         return 0;
130 }
131
132 void UnaryFunction0DFloat___dealloc__(BPy_UnaryFunction0DFloat* self)
133 {
134         if (self->uf0D_float)
135                 delete self->uf0D_float;
136         UnaryFunction0D_Type.tp_dealloc((PyObject*)self);
137 }
138
139
140 PyObject * UnaryFunction0DFloat___repr__(BPy_UnaryFunction0DFloat* self)
141 {
142         return PyUnicode_FromFormat("type: %s - address: %p", self->uf0D_float->getName().c_str(), self->uf0D_float );
143 }
144
145 PyObject * UnaryFunction0DFloat_getName( BPy_UnaryFunction0DFloat *self )
146 {
147         return PyUnicode_FromFormat( self->uf0D_float->getName().c_str() );
148 }
149
150 PyObject * UnaryFunction0DFloat___call__( BPy_UnaryFunction0DFloat *self, PyObject *args, PyObject *kwds)
151 {
152         PyObject *obj;
153
154         if( kwds != NULL ) {
155                 PyErr_SetString(PyExc_TypeError, "keyword argument(s) not supported");
156                 return NULL;
157         }
158         if(!PyArg_ParseTuple(args, "O!", &Interface0DIterator_Type, &obj))
159                 return NULL;
160         
161         if( typeid(*(self->uf0D_float)) == typeid(UnaryFunction0D<float>) ) {
162                 PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden");
163                 return NULL;
164         }
165         if (self->uf0D_float->operator()(*( ((BPy_Interface0DIterator *) obj)->if0D_it )) < 0) {
166                 if (!PyErr_Occurred()) {
167                         string msg(self->uf0D_float->getName() + " __call__ method failed");
168                         PyErr_SetString(PyExc_RuntimeError, msg.c_str());
169                 }
170                 return NULL;
171         }
172         return PyFloat_FromDouble( self->uf0D_float->result );
173
174 }
175
176 ///////////////////////////////////////////////////////////////////////////////////////////
177
178 #ifdef __cplusplus
179 }
180 #endif