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