use PyDoc_STRVAR macro, so its possible to build without docstrings.
[blender-staging.git] / source / blender / python / generic / mathutils_Euler.c
1 /*
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *
20  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21  * All rights reserved.
22  *
23  *
24  * Contributor(s): Joseph Gilbert
25  *
26  * ***** END GPL LICENSE BLOCK *****
27  */
28
29 /** \file blender/python/generic/mathutils_Euler.c
30  *  \ingroup pygen
31  */
32
33
34 #include <Python.h>
35
36 #include "mathutils.h"
37
38 #include "BLI_math.h"
39 #include "BLI_utildefines.h"
40
41 #ifndef int32_t
42 #include "BLO_sys_types.h"
43 #endif
44
45 #define EULER_SIZE 3
46
47 //----------------------------------mathutils.Euler() -------------------
48 //makes a new euler for you to play with
49 static PyObject *Euler_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
50 {
51         PyObject *seq= NULL;
52         const char *order_str= NULL;
53
54         float eul[EULER_SIZE]= {0.0f, 0.0f, 0.0f};
55         short order= EULER_ORDER_XYZ;
56
57         if(kwds && PyDict_Size(kwds)) {
58                 PyErr_SetString(PyExc_TypeError, "mathutils.Euler(): takes no keyword args");
59                 return NULL;
60         }
61
62         if(!PyArg_ParseTuple(args, "|Os:mathutils.Euler", &seq, &order_str))
63                 return NULL;
64
65         switch(PyTuple_GET_SIZE(args)) {
66         case 0:
67                 break;
68         case 2:
69                 if((order=euler_order_from_string(order_str, "mathutils.Euler()")) == -1)
70                         return NULL;
71                 /* intentionally pass through */
72         case 1:
73                 if (mathutils_array_parse(eul, EULER_SIZE, EULER_SIZE, seq, "mathutils.Euler()") == -1)
74                         return NULL;
75                 break;
76         }
77         return newEulerObject(eul, order, Py_NEW, type);
78 }
79
80 /* internal use, assuem read callback is done */
81 static const char *euler_order_str(EulerObject *self)
82 {
83         static const char order[][4] = {"XYZ", "XZY", "YXZ", "YZX", "ZXY", "ZYX"};
84         return order[self->order-EULER_ORDER_XYZ];
85 }
86
87 short euler_order_from_string(const char *str, const char *error_prefix)
88 {
89         if((str[0] && str[1] && str[2] && str[3]=='\0')) {
90                 switch(*((int32_t *)str)) {
91                         case 'X'|'Y'<<8|'Z'<<16:        return EULER_ORDER_XYZ;
92                         case 'X'|'Z'<<8|'Y'<<16:        return EULER_ORDER_XZY;
93                         case 'Y'|'X'<<8|'Z'<<16:        return EULER_ORDER_YXZ;
94                         case 'Y'|'Z'<<8|'X'<<16:        return EULER_ORDER_YZX;
95                         case 'Z'|'X'<<8|'Y'<<16:        return EULER_ORDER_ZXY;
96                         case 'Z'|'Y'<<8|'X'<<16:        return EULER_ORDER_ZYX;
97                 }
98         }
99
100         PyErr_Format(PyExc_TypeError, "%s: invalid euler order '%s'", error_prefix, str);
101         return -1;
102 }
103
104 /* note: BaseMath_ReadCallback must be called beforehand */
105 static PyObject *Euler_ToTupleExt(EulerObject *self, int ndigits)
106 {
107         PyObject *ret;
108         int i;
109
110         ret= PyTuple_New(EULER_SIZE);
111
112         if(ndigits >= 0) {
113                 for(i= 0; i < EULER_SIZE; i++) {
114                         PyTuple_SET_ITEM(ret, i, PyFloat_FromDouble(double_round((double)self->eul[i], ndigits)));
115                 }
116         }
117         else {
118                 for(i= 0; i < EULER_SIZE; i++) {
119                         PyTuple_SET_ITEM(ret, i, PyFloat_FromDouble(self->eul[i]));
120                 }
121         }
122
123         return ret;
124 }
125
126 //-----------------------------METHODS----------------------------
127 //return a quaternion representation of the euler
128
129 PyDoc_STRVAR(Euler_to_quaternion_doc,
130 ".. method:: to_quaternion()\n"
131 "\n"
132 "   Return a quaternion representation of the euler.\n"
133 "\n"
134 "   :return: Quaternion representation of the euler.\n"
135 "   :rtype: :class:`Quaternion`\n"
136 );
137 static PyObject *Euler_to_quaternion(EulerObject * self)
138 {
139         float quat[4];
140
141         if(BaseMath_ReadCallback(self) == -1)
142                 return NULL;
143
144         eulO_to_quat(quat, self->eul, self->order);
145
146         return newQuaternionObject(quat, Py_NEW, NULL);
147 }
148
149 //return a matrix representation of the euler
150 PyDoc_STRVAR(Euler_to_matrix_doc,
151 ".. method:: to_matrix()\n"
152 "\n"
153 "   Return a matrix representation of the euler.\n"
154 "\n"
155 "   :return: A 3x3 roation matrix representation of the euler.\n"
156 "   :rtype: :class:`Matrix`\n"
157 );
158 static PyObject *Euler_to_matrix(EulerObject * self)
159 {
160         float mat[9];
161
162         if(BaseMath_ReadCallback(self) == -1)
163                 return NULL;
164
165         eulO_to_mat3((float (*)[3])mat, self->eul, self->order);
166
167         return newMatrixObject(mat, 3, 3 , Py_NEW, NULL);
168 }
169
170 PyDoc_STRVAR(Euler_zero_doc,
171 ".. method:: zero()\n"
172 "\n"
173 "   Set all values to zero.\n"
174 );
175 static PyObject *Euler_zero(EulerObject * self)
176 {
177         zero_v3(self->eul);
178
179         if(BaseMath_WriteCallback(self) == -1)
180                 return NULL;
181
182         Py_RETURN_NONE;
183 }
184
185 PyDoc_STRVAR(Euler_rotate_axis_doc,
186 ".. method:: rotate_axis(axis, angle)\n"
187 "\n"
188 "   Rotates the euler a certain amount and returning a unique euler rotation (no 720 degree pitches).\n"
189 "\n"
190 "   :arg axis: single character in ['X, 'Y', 'Z'].\n"
191 "   :type axis: string\n"
192 "   :arg angle: angle in radians.\n"
193 "   :type angle: float\n"
194 );
195 static PyObject *Euler_rotate_axis(EulerObject * self, PyObject *args)
196 {
197         float angle = 0.0f;
198         const char *axis;
199
200         if(!PyArg_ParseTuple(args, "sf:rotate", &axis, &angle)){
201                 PyErr_SetString(PyExc_TypeError, "euler.rotate(): expected angle (float) and axis (x, y, z)");
202                 return NULL;
203         }
204         if(!(ELEM3(*axis, 'X', 'Y', 'Z') && axis[1]=='\0')){
205                 PyErr_SetString(PyExc_TypeError, "euler.rotate(): expected axis to be 'X', 'Y' or 'Z'");
206                 return NULL;
207         }
208
209         if(BaseMath_ReadCallback(self) == -1)
210                 return NULL;
211
212
213         rotate_eulO(self->eul, self->order, *axis, angle);
214
215         (void)BaseMath_WriteCallback(self);
216
217         Py_RETURN_NONE;
218 }
219
220 PyDoc_STRVAR(Euler_rotate_doc,
221 ".. method:: rotate(other)\n"
222 "\n"
223 "   Rotates the euler a by another mathutils value.\n"
224 "\n"
225 "   :arg other: rotation component of mathutils value\n"
226 "   :type other: :class:`Euler`, :class:`Quaternion` or :class:`Matrix`\n"
227 );
228 static PyObject *Euler_rotate(EulerObject * self, PyObject *value)
229 {
230         float self_rmat[3][3], other_rmat[3][3], rmat[3][3];
231
232         if(BaseMath_ReadCallback(self) == -1)
233                 return NULL;
234
235         if(mathutils_any_to_rotmat(other_rmat, value, "euler.rotate(value)") == -1)
236                 return NULL;
237
238         eulO_to_mat3(self_rmat, self->eul, self->order);
239         mul_m3_m3m3(rmat, self_rmat, other_rmat);
240
241         mat3_to_compatible_eulO(self->eul, self->eul, self->order, rmat);
242
243         (void)BaseMath_WriteCallback(self);
244         Py_RETURN_NONE;
245 }
246
247 PyDoc_STRVAR(Euler_make_compatible_doc,
248 ".. method:: make_compatible(other)\n"
249 "\n"
250 "   Make this euler compatible with another, so interpolating between them works as intended.\n"
251 "\n"
252 "   .. note:: the rotation order is not taken into account for this function.\n"
253 );
254 static PyObject *Euler_make_compatible(EulerObject * self, PyObject *value)
255 {
256         float teul[EULER_SIZE];
257
258         if(BaseMath_ReadCallback(self) == -1)
259                 return NULL;
260
261         if(mathutils_array_parse(teul, EULER_SIZE, EULER_SIZE, value, "euler.make_compatible(other), invalid 'other' arg") == -1)
262                 return NULL;
263
264         compatible_eul(self->eul, teul);
265
266         (void)BaseMath_WriteCallback(self);
267
268         Py_RETURN_NONE;
269 }
270
271 //----------------------------Euler.rotate()-----------------------
272 // return a copy of the euler
273
274 PyDoc_STRVAR(Euler_copy_doc,
275 ".. function:: copy()\n"
276 "\n"
277 "   Returns a copy of this euler.\n"
278 "\n"
279 "   :return: A copy of the euler.\n"
280 "   :rtype: :class:`Euler`\n"
281 "\n"
282 "   .. note:: use this to get a copy of a wrapped euler with no reference to the original data.\n"
283 );
284 static PyObject *Euler_copy(EulerObject *self)
285 {
286         if(BaseMath_ReadCallback(self) == -1)
287                 return NULL;
288
289         return newEulerObject(self->eul, self->order, Py_NEW, Py_TYPE(self));
290 }
291
292 //----------------------------print object (internal)--------------
293 //print the object to screen
294
295 static PyObject *Euler_repr(EulerObject * self)
296 {
297         PyObject *ret, *tuple;
298
299         if(BaseMath_ReadCallback(self) == -1)
300                 return NULL;
301
302         tuple= Euler_ToTupleExt(self, -1);
303
304         ret= PyUnicode_FromFormat("Euler(%R, '%s')", tuple, euler_order_str(self));
305
306         Py_DECREF(tuple);
307         return ret;
308 }
309
310 static PyObject* Euler_richcmpr(PyObject *a, PyObject *b, int op)
311 {
312         PyObject *res;
313         int ok= -1; /* zero is true */
314
315         if (EulerObject_Check(a) && EulerObject_Check(b)) {
316                 EulerObject *eulA= (EulerObject*)a;
317                 EulerObject *eulB= (EulerObject*)b;
318
319                 if(BaseMath_ReadCallback(eulA) == -1 || BaseMath_ReadCallback(eulB) == -1)
320                         return NULL;
321
322                 ok= ((eulA->order == eulB->order) && EXPP_VectorsAreEqual(eulA->eul, eulB->eul, EULER_SIZE, 1)) ? 0 : -1;
323         }
324
325         switch (op) {
326         case Py_NE:
327                 ok = !ok; /* pass through */
328         case Py_EQ:
329                 res = ok ? Py_False : Py_True;
330                 break;
331
332         case Py_LT:
333         case Py_LE:
334         case Py_GT:
335         case Py_GE:
336                 res = Py_NotImplemented;
337                 break;
338         default:
339                 PyErr_BadArgument();
340                 return NULL;
341         }
342
343         return Py_INCREF(res), res;
344 }
345
346 //---------------------SEQUENCE PROTOCOLS------------------------
347 //----------------------------len(object)------------------------
348 //sequence length
349 static int Euler_len(EulerObject *UNUSED(self))
350 {
351         return EULER_SIZE;
352 }
353 //----------------------------object[]---------------------------
354 //sequence accessor (get)
355 static PyObject *Euler_item(EulerObject * self, int i)
356 {
357         if(i<0) i= EULER_SIZE-i;
358
359         if(i < 0 || i >= EULER_SIZE) {
360                 PyErr_SetString(PyExc_IndexError, "euler[attribute]: array index out of range");
361                 return NULL;
362         }
363
364         if(BaseMath_ReadIndexCallback(self, i) == -1)
365                 return NULL;
366
367         return PyFloat_FromDouble(self->eul[i]);
368
369 }
370 //----------------------------object[]-------------------------
371 //sequence accessor (set)
372 static int Euler_ass_item(EulerObject * self, int i, PyObject *value)
373 {
374         float f = PyFloat_AsDouble(value);
375
376         if(f == -1 && PyErr_Occurred()) { // parsed item not a number
377                 PyErr_SetString(PyExc_TypeError, "euler[attribute] = x: argument not a number");
378                 return -1;
379         }
380
381         if(i<0) i= EULER_SIZE-i;
382
383         if(i < 0 || i >= EULER_SIZE){
384                 PyErr_SetString(PyExc_IndexError, "euler[attribute] = x: array assignment index out of range");
385                 return -1;
386         }
387
388         self->eul[i] = f;
389
390         if(BaseMath_WriteIndexCallback(self, i) == -1)
391                 return -1;
392
393         return 0;
394 }
395 //----------------------------object[z:y]------------------------
396 //sequence slice (get)
397 static PyObject *Euler_slice(EulerObject * self, int begin, int end)
398 {
399         PyObject *tuple;
400         int count;
401
402         if(BaseMath_ReadCallback(self) == -1)
403                 return NULL;
404
405         CLAMP(begin, 0, EULER_SIZE);
406         if (end<0) end= (EULER_SIZE + 1) + end;
407         CLAMP(end, 0, EULER_SIZE);
408         begin= MIN2(begin, end);
409
410         tuple= PyTuple_New(end - begin);
411         for(count = begin; count < end; count++) {
412                 PyTuple_SET_ITEM(tuple, count - begin, PyFloat_FromDouble(self->eul[count]));
413         }
414
415         return tuple;
416 }
417 //----------------------------object[z:y]------------------------
418 //sequence slice (set)
419 static int Euler_ass_slice(EulerObject * self, int begin, int end, PyObject * seq)
420 {
421         int i, size;
422         float eul[EULER_SIZE];
423
424         if(BaseMath_ReadCallback(self) == -1)
425                 return -1;
426
427         CLAMP(begin, 0, EULER_SIZE);
428         if (end<0) end= (EULER_SIZE + 1) + end;
429         CLAMP(end, 0, EULER_SIZE);
430         begin = MIN2(begin, end);
431
432         if((size=mathutils_array_parse(eul, 0, EULER_SIZE, seq, "mathutils.Euler[begin:end] = []")) == -1)
433                 return -1;
434
435         if(size != (end - begin)){
436                 PyErr_SetString(PyExc_TypeError, "euler[begin:end] = []: size mismatch in slice assignment");
437                 return -1;
438         }
439
440         for(i= 0; i < EULER_SIZE; i++)
441                 self->eul[begin + i] = eul[i];
442
443         (void)BaseMath_WriteCallback(self);
444         return 0;
445 }
446
447 static PyObject *Euler_subscript(EulerObject *self, PyObject *item)
448 {
449         if (PyIndex_Check(item)) {
450                 Py_ssize_t i;
451                 i = PyNumber_AsSsize_t(item, PyExc_IndexError);
452                 if (i == -1 && PyErr_Occurred())
453                         return NULL;
454                 if (i < 0)
455                         i += EULER_SIZE;
456                 return Euler_item(self, i);
457         }
458         else if (PySlice_Check(item)) {
459                 Py_ssize_t start, stop, step, slicelength;
460
461                 if (PySlice_GetIndicesEx((void *)item, EULER_SIZE, &start, &stop, &step, &slicelength) < 0)
462                         return NULL;
463
464                 if (slicelength <= 0) {
465                         return PyTuple_New(0);
466                 }
467                 else if (step == 1) {
468                         return Euler_slice(self, start, stop);
469                 }
470                 else {
471                         PyErr_SetString(PyExc_TypeError, "slice steps not supported with eulers");
472                         return NULL;
473                 }
474         }
475         else {
476                 PyErr_Format(PyExc_TypeError, "euler indices must be integers, not %.200s", Py_TYPE(item)->tp_name);
477                 return NULL;
478         }
479 }
480
481
482 static int Euler_ass_subscript(EulerObject *self, PyObject *item, PyObject *value)
483 {
484         if (PyIndex_Check(item)) {
485                 Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError);
486                 if (i == -1 && PyErr_Occurred())
487                         return -1;
488                 if (i < 0)
489                         i += EULER_SIZE;
490                 return Euler_ass_item(self, i, value);
491         }
492         else if (PySlice_Check(item)) {
493                 Py_ssize_t start, stop, step, slicelength;
494
495                 if (PySlice_GetIndicesEx((void *)item, EULER_SIZE, &start, &stop, &step, &slicelength) < 0)
496                         return -1;
497
498                 if (step == 1)
499                         return Euler_ass_slice(self, start, stop, value);
500                 else {
501                         PyErr_SetString(PyExc_TypeError, "slice steps not supported with euler");
502                         return -1;
503                 }
504         }
505         else {
506                 PyErr_Format(PyExc_TypeError, "euler indices must be integers, not %.200s", Py_TYPE(item)->tp_name);
507                 return -1;
508         }
509 }
510
511 //-----------------PROTCOL DECLARATIONS--------------------------
512 static PySequenceMethods Euler_SeqMethods = {
513         (lenfunc) Euler_len,                                    /* sq_length */
514         (binaryfunc) NULL,                                              /* sq_concat */
515         (ssizeargfunc) NULL,                                    /* sq_repeat */
516         (ssizeargfunc) Euler_item,                              /* sq_item */
517         (ssizessizeargfunc) NULL,                               /* sq_slice, deprecated  */
518         (ssizeobjargproc) Euler_ass_item,               /* sq_ass_item */
519         (ssizessizeobjargproc) NULL,                    /* sq_ass_slice, deprecated */
520         (objobjproc) NULL,                                              /* sq_contains */
521         (binaryfunc) NULL,                                              /* sq_inplace_concat */
522         (ssizeargfunc) NULL,                                    /* sq_inplace_repeat */
523 };
524
525 static PyMappingMethods Euler_AsMapping = {
526         (lenfunc)Euler_len,
527         (binaryfunc)Euler_subscript,
528         (objobjargproc)Euler_ass_subscript
529 };
530
531 /*
532  * euler axis, euler.x/y/z
533  */
534 static PyObject *Euler_getAxis(EulerObject *self, void *type)
535 {
536         return Euler_item(self, GET_INT_FROM_POINTER(type));
537 }
538
539 static int Euler_setAxis(EulerObject *self, PyObject *value, void *type)
540 {
541         return Euler_ass_item(self, GET_INT_FROM_POINTER(type), value);
542 }
543
544 /* rotation order */
545 static PyObject *Euler_getOrder(EulerObject *self, void *UNUSED(closure))
546 {
547         if(BaseMath_ReadCallback(self) == -1) /* can read order too */
548                 return NULL;
549
550         return PyUnicode_FromString(euler_order_str(self));
551 }
552
553 static int Euler_setOrder(EulerObject *self, PyObject *value, void *UNUSED(closure))
554 {
555         const char *order_str= _PyUnicode_AsString(value);
556         short order= euler_order_from_string(order_str, "euler.order");
557
558         if(order == -1)
559                 return -1;
560
561         self->order= order;
562         (void)BaseMath_WriteCallback(self); /* order can be written back */
563         return 0;
564 }
565
566 /*****************************************************************************/
567 /* Python attributes get/set structure:                                      */
568 /*****************************************************************************/
569 static PyGetSetDef Euler_getseters[] = {
570         {(char *)"x", (getter)Euler_getAxis, (setter)Euler_setAxis, (char *)"Euler X axis in radians.\n\n:type: float", (void *)0},
571         {(char *)"y", (getter)Euler_getAxis, (setter)Euler_setAxis, (char *)"Euler Y axis in radians.\n\n:type: float", (void *)1},
572         {(char *)"z", (getter)Euler_getAxis, (setter)Euler_setAxis, (char *)"Euler Z axis in radians.\n\n:type: float", (void *)2},
573         {(char *)"order", (getter)Euler_getOrder, (setter)Euler_setOrder, (char *)"Euler rotation order.\n\n:type: string in ['XYZ', 'XZY', 'YXZ', 'YZX', 'ZXY', 'ZYX']", (void *)NULL},
574
575         {(char *)"is_wrapped", (getter)BaseMathObject_getWrapped, (setter)NULL, (char *)BaseMathObject_Wrapped_doc, NULL},
576         {(char *)"owner", (getter)BaseMathObject_getOwner, (setter)NULL, (char *)BaseMathObject_Owner_doc, NULL},
577         {NULL, NULL, NULL, NULL, NULL}  /* Sentinel */
578 };
579
580
581 //-----------------------METHOD DEFINITIONS ----------------------
582 static struct PyMethodDef Euler_methods[] = {
583         {"zero", (PyCFunction) Euler_zero, METH_NOARGS, Euler_zero_doc},
584         {"to_matrix", (PyCFunction) Euler_to_matrix, METH_NOARGS, Euler_to_matrix_doc},
585         {"to_quaternion", (PyCFunction) Euler_to_quaternion, METH_NOARGS, Euler_to_quaternion_doc},
586         {"rotate_axis", (PyCFunction) Euler_rotate_axis, METH_VARARGS, Euler_rotate_axis_doc},
587         {"rotate", (PyCFunction) Euler_rotate, METH_O, Euler_rotate_doc},
588         {"make_compatible", (PyCFunction) Euler_make_compatible, METH_O, Euler_make_compatible_doc},
589         {"__copy__", (PyCFunction) Euler_copy, METH_NOARGS, Euler_copy_doc},
590         {"copy", (PyCFunction) Euler_copy, METH_NOARGS, Euler_copy_doc},
591         {NULL, NULL, 0, NULL}
592 };
593
594 //------------------PY_OBECT DEFINITION--------------------------
595 PyDoc_STRVAR(euler_doc,
596 "This object gives access to Eulers in Blender."
597 );
598 PyTypeObject euler_Type = {
599         PyVarObject_HEAD_INIT(NULL, 0)
600         "mathutils.Euler",                              //tp_name
601         sizeof(EulerObject),                    //tp_basicsize
602         0,                                                              //tp_itemsize
603         (destructor)BaseMathObject_dealloc,             //tp_dealloc
604         NULL,                                                   //tp_print
605         NULL,                                                   //tp_getattr
606         NULL,                                                   //tp_setattr
607         NULL,                                                   //tp_compare
608         (reprfunc) Euler_repr,                  //tp_repr
609         NULL,                                                   //tp_as_number
610         &Euler_SeqMethods,                              //tp_as_sequence
611         &Euler_AsMapping,                               //tp_as_mapping
612         NULL,                                                   //tp_hash
613         NULL,                                                   //tp_call
614         NULL,                                                   //tp_str
615         NULL,                                                   //tp_getattro
616         NULL,                                                   //tp_setattro
617         NULL,                                                   //tp_as_buffer
618         Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, //tp_flags
619         euler_doc, //tp_doc
620         (traverseproc)BaseMathObject_traverse,  //tp_traverse
621         (inquiry)BaseMathObject_clear,  //tp_clear
622         (richcmpfunc)Euler_richcmpr,    //tp_richcompare
623         0,                                                              //tp_weaklistoffset
624         NULL,                                                   //tp_iter
625         NULL,                                                   //tp_iternext
626         Euler_methods,                                  //tp_methods
627         NULL,                                                   //tp_members
628         Euler_getseters,                                //tp_getset
629         NULL,                                                   //tp_base
630         NULL,                                                   //tp_dict
631         NULL,                                                   //tp_descr_get
632         NULL,                                                   //tp_descr_set
633         0,                                                              //tp_dictoffset
634         NULL,                                                   //tp_init
635         NULL,                                                   //tp_alloc
636         Euler_new,                                              //tp_new
637         NULL,                                                   //tp_free
638         NULL,                                                   //tp_is_gc
639         NULL,                                                   //tp_bases
640         NULL,                                                   //tp_mro
641         NULL,                                                   //tp_cache
642         NULL,                                                   //tp_subclasses
643         NULL,                                                   //tp_weaklist
644         NULL                                                    //tp_del
645 };
646 //------------------------newEulerObject (internal)-------------
647 //creates a new euler object
648 /*pass Py_WRAP - if vector is a WRAPPER for data allocated by BLENDER
649  (i.e. it was allocated elsewhere by MEM_mallocN())
650   pass Py_NEW - if vector is not a WRAPPER and managed by PYTHON
651  (i.e. it must be created here with PyMEM_malloc())*/
652 PyObject *newEulerObject(float *eul, short order, int type, PyTypeObject *base_type)
653 {
654         EulerObject *self;
655
656         self= base_type ?       (EulerObject *)base_type->tp_alloc(base_type, 0) :
657                                                 (EulerObject *)PyObject_GC_New(EulerObject, &euler_Type);
658
659         if(self) {
660                 /* init callbacks as NULL */
661                 self->cb_user= NULL;
662                 self->cb_type= self->cb_subtype= 0;
663
664                 if(type == Py_WRAP) {
665                         self->eul = eul;
666                         self->wrapped = Py_WRAP;
667                 }
668                 else if (type == Py_NEW) {
669                         self->eul = PyMem_Malloc(EULER_SIZE * sizeof(float));
670                         if(eul) {
671                                 copy_v3_v3(self->eul, eul);
672                         }
673                         else {
674                                 zero_v3(self->eul);
675                         }
676
677                         self->wrapped = Py_NEW;
678                 }
679                 else {
680                         PyErr_SetString(PyExc_RuntimeError, "Euler(): invalid type");
681                         return NULL;
682                 }
683
684                 self->order= order;
685         }
686
687         return (PyObject *)self;
688 }
689
690 PyObject *newEulerObject_cb(PyObject *cb_user, short order, int cb_type, int cb_subtype)
691 {
692         EulerObject *self= (EulerObject *)newEulerObject(NULL, order, Py_NEW, NULL);
693         if(self) {
694                 Py_INCREF(cb_user);
695                 self->cb_user=                  cb_user;
696                 self->cb_type=                  (unsigned char)cb_type;
697                 self->cb_subtype=               (unsigned char)cb_subtype;
698                 PyObject_GC_Track(self);
699         }
700
701         return (PyObject *)self;
702 }