Made the Freestyle Python API compatible with Python 3.
[blender.git] / source / blender / freestyle / intern / python / UnaryFunction1D / BPy_UnaryFunction1DUnsigned.cpp
1 #include "BPy_UnaryFunction1DUnsigned.h"
2
3 #include "../BPy_Convert.h"
4 #include "../BPy_Interface1D.h"
5 #include "../BPy_IntegrationType.h"
6
7 #include "UnaryFunction1D_unsigned_int/BPy_QuantitativeInvisibilityF1D.h"
8
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12
13 ///////////////////////////////////////////////////////////////////////////////////////////
14
15 /*---------------  Python API function prototypes for UnaryFunction1DUnsigned instance  -----------*/
16 static int UnaryFunction1DUnsigned___init__(BPy_UnaryFunction1DUnsigned* self, PyObject *args);
17 static void UnaryFunction1DUnsigned___dealloc__(BPy_UnaryFunction1DUnsigned* self);
18 static PyObject * UnaryFunction1DUnsigned___repr__(BPy_UnaryFunction1DUnsigned* self);
19
20 static PyObject * UnaryFunction1DUnsigned_getName( BPy_UnaryFunction1DUnsigned *self);
21 static PyObject * UnaryFunction1DUnsigned___call__( BPy_UnaryFunction1DUnsigned *self, PyObject *args, PyObject *kwds);
22 static PyObject * UnaryFunction1DUnsigned_setIntegrationType(BPy_UnaryFunction1DUnsigned* self, PyObject *args);
23 static PyObject * UnaryFunction1DUnsigned_getIntegrationType(BPy_UnaryFunction1DUnsigned* self);
24
25 /*----------------------UnaryFunction1DUnsigned instance definitions ----------------------------*/
26 static PyMethodDef BPy_UnaryFunction1DUnsigned_methods[] = {
27         {"getName", ( PyCFunction ) UnaryFunction1DUnsigned_getName, METH_NOARGS, "() Returns the string of the name of the unary 1D function."},
28         {"setIntegrationType", ( PyCFunction ) UnaryFunction1DUnsigned_setIntegrationType, METH_VARARGS, "(IntegrationType i) Sets the integration method" },
29         {"getIntegrationType", ( PyCFunction ) UnaryFunction1DUnsigned_getIntegrationType, METH_NOARGS, "() Returns the integration method." },
30         {NULL, NULL, 0, NULL}
31 };
32
33 /*-----------------------BPy_UnaryFunction1DUnsigned type definition ------------------------------*/
34
35 PyTypeObject UnaryFunction1DUnsigned_Type = {
36         PyObject_HEAD_INIT(NULL)
37         "UnaryFunction1DUnsigned",      /* tp_name */
38         sizeof(BPy_UnaryFunction1DUnsigned), /* tp_basicsize */
39         0,                              /* tp_itemsize */
40         (destructor)UnaryFunction1DUnsigned___dealloc__, /* tp_dealloc */
41         0,                              /* tp_print */
42         0,                              /* tp_getattr */
43         0,                              /* tp_setattr */
44         0,                              /* tp_reserved */
45         (reprfunc)UnaryFunction1DUnsigned___repr__, /* tp_repr */
46         0,                              /* tp_as_number */
47         0,                              /* tp_as_sequence */
48         0,                              /* tp_as_mapping */
49         0,                              /* tp_hash  */
50         (ternaryfunc)UnaryFunction1DUnsigned___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         "UnaryFunction1DUnsigned 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_UnaryFunction1DUnsigned_methods, /* tp_methods */
64         0,                              /* tp_members */
65         0,                              /* tp_getset */
66         &UnaryFunction1D_Type,          /* tp_base */
67         0,                              /* tp_dict */
68         0,                              /* tp_descr_get */
69         0,                              /* tp_descr_set */
70         0,                              /* tp_dictoffset */
71         (initproc)UnaryFunction1DUnsigned___init__, /* tp_init */
72         0,                              /* tp_alloc */
73         0,                              /* tp_new */
74 };
75
76 //-------------------MODULE INITIALIZATION--------------------------------
77
78 int UnaryFunction1DUnsigned_Init( PyObject *module ) {
79
80         if( module == NULL )
81                 return -1;
82
83         if( PyType_Ready( &UnaryFunction1DUnsigned_Type ) < 0 )
84                 return -1;
85         Py_INCREF( &UnaryFunction1DUnsigned_Type );
86         PyModule_AddObject(module, "UnaryFunction1DUnsigned", (PyObject *)&UnaryFunction1DUnsigned_Type);
87         
88         if( PyType_Ready( &QuantitativeInvisibilityF1D_Type ) < 0 )
89                 return -1;
90         Py_INCREF( &QuantitativeInvisibilityF1D_Type );
91         PyModule_AddObject(module, "QuantitativeInvisibilityF1D", (PyObject *)&QuantitativeInvisibilityF1D_Type);
92
93         return 0;
94 }
95
96 //------------------------INSTANCE METHODS ----------------------------------
97
98 int UnaryFunction1DUnsigned___init__(BPy_UnaryFunction1DUnsigned* self, PyObject *args)
99 {
100         PyObject *obj = 0;
101
102         if( !PyArg_ParseTuple(args, "|O!", &IntegrationType_Type, &obj) )       
103                 return -1;
104         
105         if( !obj )
106                 self->uf1D_unsigned = new UnaryFunction1D<unsigned int>();
107         else {
108                 self->uf1D_unsigned = new UnaryFunction1D<unsigned int>( IntegrationType_from_BPy_IntegrationType(obj) );
109         }
110         
111         self->uf1D_unsigned->py_uf1D = (PyObject *)self;
112         
113         return 0;
114 }
115 void UnaryFunction1DUnsigned___dealloc__(BPy_UnaryFunction1DUnsigned* self)
116 {
117         if (self->uf1D_unsigned)
118                 delete self->uf1D_unsigned;
119         UnaryFunction1D_Type.tp_dealloc((PyObject*)self);
120 }
121
122
123 PyObject * UnaryFunction1DUnsigned___repr__(BPy_UnaryFunction1DUnsigned* self)
124 {
125         return PyUnicode_FromFormat("type: %s - address: %p", self->uf1D_unsigned->getName().c_str(), self->uf1D_unsigned );
126 }
127
128 PyObject * UnaryFunction1DUnsigned_getName( BPy_UnaryFunction1DUnsigned *self )
129 {
130         return PyUnicode_FromFormat( self->uf1D_unsigned->getName().c_str() );
131 }
132
133 PyObject * UnaryFunction1DUnsigned___call__( BPy_UnaryFunction1DUnsigned *self, PyObject *args, PyObject *kwds)
134 {
135         PyObject *obj;
136
137         if( kwds != NULL ) {
138                 PyErr_SetString(PyExc_TypeError, "keyword argument(s) not supported");
139                 return NULL;
140         }
141         if( !PyArg_ParseTuple(args, "O!", &Interface1D_Type, &obj) )
142                 return NULL;
143         
144         if( typeid(*(self->uf1D_unsigned)) == typeid(UnaryFunction1D<unsigned int>) ) {
145                 PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden");
146                 return NULL;
147         }
148         if (self->uf1D_unsigned->operator()(*( ((BPy_Interface1D *) obj)->if1D )) < 0) {
149                 if (!PyErr_Occurred()) {
150                         string msg(self->uf1D_unsigned->getName() + " __call__ method failed");
151                         PyErr_SetString(PyExc_RuntimeError, msg.c_str());
152                 }
153                 return NULL;
154         }
155         return PyLong_FromLong( self->uf1D_unsigned->result );
156
157 }
158
159 PyObject * UnaryFunction1DUnsigned_setIntegrationType(BPy_UnaryFunction1DUnsigned* self, PyObject *args)
160 {
161         PyObject *obj;
162
163         if( !PyArg_ParseTuple(args, "O!", &IntegrationType_Type, &obj) )
164                 return NULL;
165         
166         self->uf1D_unsigned->setIntegrationType( IntegrationType_from_BPy_IntegrationType(obj) );
167         Py_RETURN_NONE;
168 }
169
170 PyObject * UnaryFunction1DUnsigned_getIntegrationType(BPy_UnaryFunction1DUnsigned* self) {
171         return BPy_IntegrationType_from_IntegrationType( self->uf1D_unsigned->getIntegrationType() );
172 }
173
174 ///////////////////////////////////////////////////////////////////////////////////////////
175
176 #ifdef __cplusplus
177 }
178 #endif