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