soc-2008-mxcurioni: made considerable changes to support cross-language polymorphism...
[blender-staging.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);
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);
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         {"__call__", ( PyCFunction ) UnaryFunction0DMaterial___call__, METH_VARARGS, "(Interface0DIterator it )Executes the operator ()     on the iterator it pointing onto the point at which we wish to evaluate the function." },
26         {NULL, NULL, 0, NULL}
27 };
28
29 /*-----------------------BPy_UnaryFunction0DMaterial type definition ------------------------------*/
30
31 PyTypeObject UnaryFunction0DMaterial_Type = {
32         PyObject_HEAD_INIT( NULL ) 
33         0,                                                      /* ob_size */
34         "UnaryFunction0DMaterial",                              /* tp_name */
35         sizeof( BPy_UnaryFunction0DMaterial ),  /* tp_basicsize */
36         0,                                                      /* tp_itemsize */
37         
38         /* methods */
39         (destructor)UnaryFunction0DMaterial___dealloc__,        /* tp_dealloc */
40         NULL,                                                   /* printfunc tp_print; */
41         NULL,                                                   /* getattrfunc tp_getattr; */
42         NULL,                                                   /* setattrfunc tp_setattr; */
43         NULL,                                                                           /* tp_compare */
44         (reprfunc)UnaryFunction0DMaterial___repr__,                                     /* tp_repr */
45
46         /* Method suites for standard classes */
47
48         NULL,                       /* PyNumberMethods *tp_as_number; */
49         NULL,                       /* PySequenceMethods *tp_as_sequence; */
50         NULL,                       /* PyMappingMethods *tp_as_mapping; */
51
52         /* More standard operations (here for binary compatibility) */
53
54         NULL,                                           /* hashfunc tp_hash; */
55         NULL,                       /* ternaryfunc tp_call; */
56         NULL,                       /* reprfunc tp_str; */
57         NULL,                       /* getattrofunc tp_getattro; */
58         NULL,                       /* setattrofunc tp_setattro; */
59
60         /* Functions to access object as input/output buffer */
61         NULL,                       /* PyBufferProcs *tp_as_buffer; */
62
63   /*** Flags to define presence of optional/expanded features ***/
64         Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,               /* long tp_flags; */
65
66         NULL,                       /*  char *tp_doc;  Documentation string */
67   /*** Assigned meaning in release 2.0 ***/
68         /* call function for all accessible objects */
69         NULL,                       /* traverseproc tp_traverse; */
70
71         /* delete references to contained objects */
72         NULL,                       /* inquiry tp_clear; */
73
74   /***  Assigned meaning in release 2.1 ***/
75   /*** rich comparisons ***/
76         NULL,                       /* richcmpfunc tp_richcompare; */
77
78   /***  weak reference enabler ***/
79         0,                          /* long tp_weaklistoffset; */
80
81   /*** Added in release 2.2 ***/
82         /*   Iterators */
83         NULL,                       /* getiterfunc tp_iter; */
84         NULL,                       /* iternextfunc tp_iternext; */
85
86   /*** Attribute descriptor and subclassing stuff ***/
87         BPy_UnaryFunction0DMaterial_methods,    /* struct PyMethodDef *tp_methods; */
88         NULL,                           /* struct PyMemberDef *tp_members; */
89         NULL,                                           /* struct PyGetSetDef *tp_getset; */
90         &UnaryFunction0D_Type,                                                  /* struct _typeobject *tp_base; */
91         NULL,                                                   /* PyObject *tp_dict; */
92         NULL,                                                   /* descrgetfunc tp_descr_get; */
93         NULL,                                                   /* descrsetfunc tp_descr_set; */
94         0,                              /* long tp_dictoffset; */
95         (initproc)UnaryFunction0DMaterial___init__, /* initproc tp_init; */
96         NULL,                                                   /* allocfunc tp_alloc; */
97         NULL,           /* newfunc tp_new; */
98         
99         /*  Low-level free-memory routine */
100         NULL,                       /* freefunc tp_free;  */
101         
102         /* For PyObject_IS_GC */
103         NULL,                       /* inquiry tp_is_gc;  */
104         NULL,                       /* PyObject *tp_bases; */
105         
106         /* method resolution order */
107         NULL,                       /* PyObject *tp_mro;  */
108         NULL,                       /* PyObject *tp_cache; */
109         NULL,                       /* PyObject *tp_subclasses; */
110         NULL,                       /* PyObject *tp_weaklist; */
111         NULL
112 };
113
114 //-------------------MODULE INITIALIZATION--------------------------------
115
116 PyMODINIT_FUNC UnaryFunction0DMaterial_Init( PyObject *module ) {
117
118         if( module == NULL )
119                 return;
120
121         if( PyType_Ready( &UnaryFunction0DMaterial_Type ) < 0 )
122                 return;
123         Py_INCREF( &UnaryFunction0DMaterial_Type );
124         PyModule_AddObject(module, "UnaryFunction0DMaterial", (PyObject *)&UnaryFunction0DMaterial_Type);
125         
126         if( PyType_Ready( &MaterialF0D_Type ) < 0 )
127                 return;
128         Py_INCREF( &MaterialF0D_Type );
129         PyModule_AddObject(module, "MaterialF0D", (PyObject *)&MaterialF0D_Type);
130                 
131 }
132
133 //------------------------INSTANCE METHODS ----------------------------------
134
135 int UnaryFunction0DMaterial___init__(BPy_UnaryFunction0DMaterial* self)
136 {
137         self->uf0D_material = new UnaryFunction0D<Material>();
138         self->uf0D_material->py_uf0D = (PyObject *)self;
139         return 0;
140 }
141
142 void UnaryFunction0DMaterial___dealloc__(BPy_UnaryFunction0DMaterial* self)
143 {
144         delete self->uf0D_material;
145         UnaryFunction0D_Type.tp_dealloc((PyObject*)self);
146 }
147
148
149 PyObject * UnaryFunction0DMaterial___repr__(BPy_UnaryFunction0DMaterial* self)
150 {
151         return PyString_FromFormat("type: %s - address: %p", self->uf0D_material->getName().c_str(), self->uf0D_material );
152 }
153
154 PyObject * UnaryFunction0DMaterial_getName( BPy_UnaryFunction0DMaterial *self )
155 {
156         return PyString_FromString( self->uf0D_material->getName().c_str() );
157 }
158
159 PyObject * UnaryFunction0DMaterial___call__( BPy_UnaryFunction0DMaterial *self, PyObject *args)
160 {
161         PyObject *obj;
162
163         if( !PyArg_ParseTuple(args, "O", &obj) && BPy_Interface0DIterator_Check(obj) ) {
164                 cout << "ERROR: UnaryFunction0DMaterial___call__ " << endl;             
165                 return NULL;
166         }
167         
168         Material m( self->uf0D_material->operator()(*( ((BPy_Interface0DIterator *) obj)->if0D_it )) );
169         return BPy_FrsMaterial_from_Material( m );
170
171 }
172
173 ///////////////////////////////////////////////////////////////////////////////////////////
174
175 #ifdef __cplusplus
176 }
177 #endif