67a7955f0d58ca6e9132eba5668498aa035db515
[blender.git] / source / blender / freestyle / intern / python / UnaryFunction1D / BPy_UnaryFunction1DVec3f.cpp
1 #include "BPy_UnaryFunction1DVec3f.h"
2
3 #include "../BPy_Convert.h"
4 #include "../BPy_Interface1D.h"
5 #include "../BPy_IntegrationType.h"
6
7 #include "UnaryFunction1D_Vec3f/BPy_Orientation3DF1D.h"
8
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12
13 ///////////////////////////////////////////////////////////////////////////////////////////
14
15 //-------------------MODULE INITIALIZATION--------------------------------
16
17 int UnaryFunction1DVec3f_Init( PyObject *module ) {
18
19         if( module == NULL )
20                 return -1;
21
22         if( PyType_Ready( &UnaryFunction1DVec3f_Type ) < 0 )
23                 return -1;
24         Py_INCREF( &UnaryFunction1DVec3f_Type );
25         PyModule_AddObject(module, "UnaryFunction1DVec3f", (PyObject *)&UnaryFunction1DVec3f_Type);
26         
27         if( PyType_Ready( &Orientation3DF1D_Type ) < 0 )
28                 return -1;
29         Py_INCREF( &Orientation3DF1D_Type );
30         PyModule_AddObject(module, "Orientation3DF1D", (PyObject *)&Orientation3DF1D_Type);
31
32         return 0;
33 }
34
35 //------------------------INSTANCE METHODS ----------------------------------
36
37 static char UnaryFunction1DVec3f___doc__[] =
38 "Class hierarchy: :class:`UnaryFunction1D` > :class:`UnaryFunction1DVec3f`\n"
39 "\n"
40 "Base class for unary functions (functors) that work on\n"
41 ":class:`Interface1D` and return a 3D vector.\n"
42 "\n"
43 ".. method:: __init__()\n"
44 "\n"
45 "   Default constructor.\n"
46 "\n"
47 ".. method:: __init__(integration)\n"
48 "\n"
49 "   Builds a unary 1D function using the integration method given as\n"
50 "   argument.\n"
51 "\n"
52 "   :arg integration: An integration method.\n"
53 "   :type integration: :class:`IntegrationType`\n";
54
55 int UnaryFunction1DVec3f___init__(BPy_UnaryFunction1DVec3f* self, PyObject *args)
56 {
57         PyObject *obj = 0;
58
59         if( !PyArg_ParseTuple(args, "|O!", &IntegrationType_Type, &obj) )       
60                 return -1;
61         
62         if( !obj )
63                 self->uf1D_vec3f = new UnaryFunction1D<Vec3f>();
64         else {
65                 self->uf1D_vec3f = new UnaryFunction1D<Vec3f>( IntegrationType_from_BPy_IntegrationType(obj) );
66         }
67         
68         self->uf1D_vec3f->py_uf1D = (PyObject *)self;
69         
70         return 0;
71 }
72 void UnaryFunction1DVec3f___dealloc__(BPy_UnaryFunction1DVec3f* self)
73 {
74         if (self->uf1D_vec3f)
75                 delete self->uf1D_vec3f;
76         UnaryFunction1D_Type.tp_dealloc((PyObject*)self);
77 }
78
79
80 PyObject * UnaryFunction1DVec3f___repr__(BPy_UnaryFunction1DVec3f* self)
81 {
82         return PyUnicode_FromFormat("type: %s - address: %p", self->uf1D_vec3f->getName().c_str(), self->uf1D_vec3f );
83 }
84
85 static char UnaryFunction1DVec3f_getName___doc__[] =
86 ".. method:: getName()\n"
87 "\n"
88 "   Returns the name of the unary 1D function.\n"
89 "\n"
90 "   :return: The name of the unary 1D function.\n"
91 "   :rtype: str\n";
92
93 PyObject * UnaryFunction1DVec3f_getName( BPy_UnaryFunction1DVec3f *self )
94 {
95         return PyUnicode_FromString( self->uf1D_vec3f->getName().c_str() );
96 }
97
98 PyObject * UnaryFunction1DVec3f___call__( BPy_UnaryFunction1DVec3f *self, PyObject *args, PyObject *kwds)
99 {
100         PyObject *obj;
101
102         if( kwds != NULL ) {
103                 PyErr_SetString(PyExc_TypeError, "keyword argument(s) not supported");
104                 return NULL;
105         }
106         if( !PyArg_ParseTuple(args, "O!", &Interface1D_Type, &obj) )
107                 return NULL;
108         
109         if( typeid(*(self->uf1D_vec3f)) == typeid(UnaryFunction1D<Vec3f>) ) {
110                 PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden");
111                 return NULL;
112         }
113         if (self->uf1D_vec3f->operator()(*( ((BPy_Interface1D *) obj)->if1D )) < 0) {
114                 if (!PyErr_Occurred()) {
115                         string msg(self->uf1D_vec3f->getName() + " __call__ method failed");
116                         PyErr_SetString(PyExc_RuntimeError, msg.c_str());
117                 }
118                 return NULL;
119         }
120         return Vector_from_Vec3f( self->uf1D_vec3f->result );
121
122 }
123
124 static char UnaryFunction1DVec3f_setIntegrationType___doc__[] =
125 ".. method:: setIntegrationType(integration)\n"
126 "\n"
127 "   Sets the integration method.\n"
128 "\n"
129 "   :arg integration: An integration method.\n"
130 "   :type integration: :class:`IntegrationType`\n";
131
132 PyObject * UnaryFunction1DVec3f_setIntegrationType(BPy_UnaryFunction1DVec3f* self, PyObject *args)
133 {
134         PyObject *obj;
135
136         if( !PyArg_ParseTuple(args, "O!", &IntegrationType_Type, &obj) )
137                 return NULL;
138         
139         self->uf1D_vec3f->setIntegrationType( IntegrationType_from_BPy_IntegrationType(obj) );
140         Py_RETURN_NONE;
141 }
142
143 static char UnaryFunction1DVec3f_getIntegrationType___doc__[] =
144 ".. method:: getIntegrationType(integration)\n"
145 "\n"
146 "   Returns the integration method.\n"
147 "\n"
148 "   :return: The integration method.\n"
149 "   :rtype: :class:`IntegrationType`\n";
150
151 PyObject * UnaryFunction1DVec3f_getIntegrationType(BPy_UnaryFunction1DVec3f* self) {
152         return BPy_IntegrationType_from_IntegrationType( self->uf1D_vec3f->getIntegrationType() );
153 }
154
155 /*----------------------UnaryFunction1DVec3f instance definitions ----------------------------*/
156 static PyMethodDef BPy_UnaryFunction1DVec3f_methods[] = {
157         {"getName", ( PyCFunction ) UnaryFunction1DVec3f_getName, METH_NOARGS, UnaryFunction1DVec3f_getName___doc__},
158         {"setIntegrationType", ( PyCFunction ) UnaryFunction1DVec3f_setIntegrationType, METH_VARARGS, UnaryFunction1DVec3f_setIntegrationType___doc__},
159         {"getIntegrationType", ( PyCFunction ) UnaryFunction1DVec3f_getIntegrationType, METH_NOARGS, UnaryFunction1DVec3f_getIntegrationType___doc__},
160         {NULL, NULL, 0, NULL}
161 };
162
163 /*-----------------------BPy_UnaryFunction1DVec3f type definition ------------------------------*/
164
165 PyTypeObject UnaryFunction1DVec3f_Type = {
166         PyVarObject_HEAD_INIT(NULL, 0)
167         "UnaryFunction1DVec3f",         /* tp_name */
168         sizeof(BPy_UnaryFunction1DVec3f), /* tp_basicsize */
169         0,                              /* tp_itemsize */
170         (destructor)UnaryFunction1DVec3f___dealloc__, /* tp_dealloc */
171         0,                              /* tp_print */
172         0,                              /* tp_getattr */
173         0,                              /* tp_setattr */
174         0,                              /* tp_reserved */
175         (reprfunc)UnaryFunction1DVec3f___repr__, /* tp_repr */
176         0,                              /* tp_as_number */
177         0,                              /* tp_as_sequence */
178         0,                              /* tp_as_mapping */
179         0,                              /* tp_hash  */
180         (ternaryfunc)UnaryFunction1DVec3f___call__, /* tp_call */
181         0,                              /* tp_str */
182         0,                              /* tp_getattro */
183         0,                              /* tp_setattro */
184         0,                              /* tp_as_buffer */
185         Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
186         UnaryFunction1DVec3f___doc__,   /* tp_doc */
187         0,                              /* tp_traverse */
188         0,                              /* tp_clear */
189         0,                              /* tp_richcompare */
190         0,                              /* tp_weaklistoffset */
191         0,                              /* tp_iter */
192         0,                              /* tp_iternext */
193         BPy_UnaryFunction1DVec3f_methods, /* tp_methods */
194         0,                              /* tp_members */
195         0,                              /* tp_getset */
196         &UnaryFunction1D_Type,          /* tp_base */
197         0,                              /* tp_dict */
198         0,                              /* tp_descr_get */
199         0,                              /* tp_descr_set */
200         0,                              /* tp_dictoffset */
201         (initproc)UnaryFunction1DVec3f___init__, /* tp_init */
202         0,                              /* tp_alloc */
203         0,                              /* tp_new */
204 };
205
206 ///////////////////////////////////////////////////////////////////////////////////////////
207
208 #ifdef __cplusplus
209 }
210 #endif