5c609d8961fea5d51682aaafab5f37a442567fb9
[blender.git] / source / blender / python / mathutils / 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 #define EULER_SIZE 3
42
43 //----------------------------------mathutils.Euler() -------------------
44 //makes a new euler for you to play with
45 static PyObject *Euler_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
46 {
47         PyObject *seq= NULL;
48         const char *order_str= NULL;
49
50         float eul[EULER_SIZE]= {0.0f, 0.0f, 0.0f};
51         short order= EULER_ORDER_XYZ;
52
53         if(kwds && PyDict_Size(kwds)) {
54                 PyErr_SetString(PyExc_TypeError,
55                                 "mathutils.Euler(): "
56                                 "takes no keyword args");
57                 return NULL;
58         }
59
60         if(!PyArg_ParseTuple(args, "|Os:mathutils.Euler", &seq, &order_str))
61                 return NULL;
62
63         switch(PyTuple_GET_SIZE(args)) {
64         case 0:
65                 break;
66         case 2:
67                 if((order=euler_order_from_string(order_str, "mathutils.Euler()")) == -1)
68                         return NULL;
69                 /* intentionally pass through */
70         case 1:
71                 if (mathutils_array_parse(eul, EULER_SIZE, EULER_SIZE, seq, "mathutils.Euler()") == -1)
72                         return NULL;
73                 break;
74         }
75         return newEulerObject(eul, order, Py_NEW, type);
76 }
77
78 /* internal use, assuem read callback is done */
79 static const char *euler_order_str(EulerObject *self)
80 {
81         static const char order[][4] = {"XYZ", "XZY", "YXZ", "YZX", "ZXY", "ZYX"};
82         return order[self->order-EULER_ORDER_XYZ];
83 }
84
85 short euler_order_from_string(const char *str, const char *error_prefix)
86 {
87         if((str[0] && str[1] && str[2] && str[3]=='\0')) {
88                 switch(*((PY_INT32_T *)str)) {
89                         case 'X'|'Y'<<8|'Z'<<16:        return EULER_ORDER_XYZ;
90                         case 'X'|'Z'<<8|'Y'<<16:        return EULER_ORDER_XZY;
91                         case 'Y'|'X'<<8|'Z'<<16:        return EULER_ORDER_YXZ;
92                         case 'Y'|'Z'<<8|'X'<<16:        return EULER_ORDER_YZX;
93                         case 'Z'|'X'<<8|'Y'<<16:        return EULER_ORDER_ZXY;
94                         case 'Z'|'Y'<<8|'X'<<16:        return EULER_ORDER_ZYX;
95                 }
96         }
97
98         PyErr_Format(PyExc_ValueError,
99                      "%s: invalid euler order '%s'",
100                      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\n"
189 "   (no 720 degree pitches).\n"
190 "\n"
191 "   :arg axis: single character in ['X, 'Y', 'Z'].\n"
192 "   :type axis: string\n"
193 "   :arg angle: angle in radians.\n"
194 "   :type angle: float\n"
195 );
196 static PyObject *Euler_rotate_axis(EulerObject * self, PyObject *args)
197 {
198         float angle = 0.0f;
199         const char *axis;
200
201         if(!PyArg_ParseTuple(args, "sf:rotate", &axis, &angle)){
202                 PyErr_SetString(PyExc_TypeError,
203                                 "euler.rotate(): "
204                                 "expected angle (float) and axis (x, y, z)");
205                 return NULL;
206         }
207         if(!(ELEM3(*axis, 'X', 'Y', 'Z') && axis[1]=='\0')){
208                 PyErr_SetString(PyExc_ValueError, "euler.rotate(): "
209                                 "expected axis to be 'X', 'Y' or 'Z'");
210                 return NULL;
211         }
212
213         if(BaseMath_ReadCallback(self) == -1)
214                 return NULL;
215
216
217         rotate_eulO(self->eul, self->order, *axis, angle);
218
219         (void)BaseMath_WriteCallback(self);
220
221         Py_RETURN_NONE;
222 }
223
224 PyDoc_STRVAR(Euler_rotate_doc,
225 ".. method:: rotate(other)\n"
226 "\n"
227 "   Rotates the euler a by another mathutils value.\n"
228 "\n"
229 "   :arg other: rotation component of mathutils value\n"
230 "   :type other: :class:`Euler`, :class:`Quaternion` or :class:`Matrix`\n"
231 );
232 static PyObject *Euler_rotate(EulerObject * self, PyObject *value)
233 {
234         float self_rmat[3][3], other_rmat[3][3], rmat[3][3];
235
236         if(BaseMath_ReadCallback(self) == -1)
237                 return NULL;
238
239         if(mathutils_any_to_rotmat(other_rmat, value, "euler.rotate(value)") == -1)
240                 return NULL;
241
242         eulO_to_mat3(self_rmat, self->eul, self->order);
243         mul_m3_m3m3(rmat, self_rmat, other_rmat);
244
245         mat3_to_compatible_eulO(self->eul, self->eul, self->order, rmat);
246
247         (void)BaseMath_WriteCallback(self);
248         Py_RETURN_NONE;
249 }
250
251 PyDoc_STRVAR(Euler_make_compatible_doc,
252 ".. method:: make_compatible(other)\n"
253 "\n"
254 "   Make this euler compatible with another,\n"
255 "   so interpolating between them works as intended.\n"
256 "\n"
257 "   .. note:: the rotation order is not taken into account for this function.\n"
258 );
259 static PyObject *Euler_make_compatible(EulerObject * self, PyObject *value)
260 {
261         float teul[EULER_SIZE];
262
263         if(BaseMath_ReadCallback(self) == -1)
264                 return NULL;
265
266         if(mathutils_array_parse(teul, EULER_SIZE, EULER_SIZE, value, "euler.make_compatible(other), invalid 'other' arg") == -1)
267                 return NULL;
268
269         compatible_eul(self->eul, teul);
270
271         (void)BaseMath_WriteCallback(self);
272
273         Py_RETURN_NONE;
274 }
275
276 //----------------------------Euler.rotate()-----------------------
277 // return a copy of the euler
278
279 PyDoc_STRVAR(Euler_copy_doc,
280 ".. function:: copy()\n"
281 "\n"
282 "   Returns a copy of this euler.\n"
283 "\n"
284 "   :return: A copy of the euler.\n"
285 "   :rtype: :class:`Euler`\n"
286 "\n"
287 "   .. note:: use this to get a copy of a wrapped euler with\n"
288 "      no reference to the original data.\n"
289 );
290 static PyObject *Euler_copy(EulerObject *self)
291 {
292         if(BaseMath_ReadCallback(self) == -1)
293                 return NULL;
294
295         return newEulerObject(self->eul, self->order, Py_NEW, Py_TYPE(self));
296 }
297
298 //----------------------------print object (internal)--------------
299 //print the object to screen
300
301 static PyObject *Euler_repr(EulerObject * self)
302 {
303         PyObject *ret, *tuple;
304
305         if(BaseMath_ReadCallback(self) == -1)
306                 return NULL;
307
308         tuple= Euler_ToTupleExt(self, -1);
309
310         ret= PyUnicode_FromFormat("Euler(%R, '%s')", tuple, euler_order_str(self));
311
312         Py_DECREF(tuple);
313         return ret;
314 }
315
316 static PyObject* Euler_richcmpr(PyObject *a, PyObject *b, int op)
317 {
318         PyObject *res;
319         int ok= -1; /* zero is true */
320
321         if (EulerObject_Check(a) && EulerObject_Check(b)) {
322                 EulerObject *eulA= (EulerObject*)a;
323                 EulerObject *eulB= (EulerObject*)b;
324
325                 if(BaseMath_ReadCallback(eulA) == -1 || BaseMath_ReadCallback(eulB) == -1)
326                         return NULL;
327
328                 ok= ((eulA->order == eulB->order) && EXPP_VectorsAreEqual(eulA->eul, eulB->eul, EULER_SIZE, 1)) ? 0 : -1;
329         }
330
331         switch (op) {
332         case Py_NE:
333                 ok = !ok; /* pass through */
334         case Py_EQ:
335                 res = ok ? Py_False : Py_True;
336                 break;
337
338         case Py_LT:
339         case Py_LE:
340         case Py_GT:
341         case Py_GE:
342                 res = Py_NotImplemented;
343                 break;
344         default:
345                 PyErr_BadArgument();
346                 return NULL;
347         }
348
349         return Py_INCREF(res), res;
350 }
351
352 //---------------------SEQUENCE PROTOCOLS------------------------
353 //----------------------------len(object)------------------------
354 //sequence length
355 static int Euler_len(EulerObject *UNUSED(self))
356 {
357         return EULER_SIZE;
358 }
359 //----------------------------object[]---------------------------
360 //sequence accessor (get)
361 static PyObject *Euler_item(EulerObject * self, int i)
362 {
363         if(i<0) i= EULER_SIZE-i;
364
365         if(i < 0 || i >= EULER_SIZE) {
366                 PyErr_SetString(PyExc_IndexError,
367                                 "euler[attribute]: "
368                                 "array index out of range");
369                 return NULL;
370         }
371
372         if(BaseMath_ReadIndexCallback(self, i) == -1)
373                 return NULL;
374
375         return PyFloat_FromDouble(self->eul[i]);
376
377 }
378 //----------------------------object[]-------------------------
379 //sequence accessor (set)
380 static int Euler_ass_item(EulerObject * self, int i, PyObject *value)
381 {
382         float f = PyFloat_AsDouble(value);
383
384         if(f == -1 && PyErr_Occurred()) { // parsed item not a number
385                 PyErr_SetString(PyExc_TypeError,
386                                 "euler[attribute] = x: "
387                                 "argument not a number");
388                 return -1;
389         }
390
391         if(i<0) i= EULER_SIZE-i;
392
393         if(i < 0 || i >= EULER_SIZE){
394                 PyErr_SetString(PyExc_IndexError,
395                                 "euler[attribute] = x: "
396                                 "array assignment index out of range");
397                 return -1;
398         }
399
400         self->eul[i] = f;
401
402         if(BaseMath_WriteIndexCallback(self, i) == -1)
403                 return -1;
404
405         return 0;
406 }
407 //----------------------------object[z:y]------------------------
408 //sequence slice (get)
409 static PyObject *Euler_slice(EulerObject * self, int begin, int end)
410 {
411         PyObject *tuple;
412         int count;
413
414         if(BaseMath_ReadCallback(self) == -1)
415                 return NULL;
416
417         CLAMP(begin, 0, EULER_SIZE);
418         if (end<0) end= (EULER_SIZE + 1) + end;
419         CLAMP(end, 0, EULER_SIZE);
420         begin= MIN2(begin, end);
421
422         tuple= PyTuple_New(end - begin);
423         for(count = begin; count < end; count++) {
424                 PyTuple_SET_ITEM(tuple, count - begin, PyFloat_FromDouble(self->eul[count]));
425         }
426
427         return tuple;
428 }
429 //----------------------------object[z:y]------------------------
430 //sequence slice (set)
431 static int Euler_ass_slice(EulerObject *self, int begin, int end, PyObject *seq)
432 {
433         int i, size;
434         float eul[EULER_SIZE];
435
436         if(BaseMath_ReadCallback(self) == -1)
437                 return -1;
438
439         CLAMP(begin, 0, EULER_SIZE);
440         if (end<0) end= (EULER_SIZE + 1) + end;
441         CLAMP(end, 0, EULER_SIZE);
442         begin = MIN2(begin, end);
443
444         if((size=mathutils_array_parse(eul, 0, EULER_SIZE, seq, "mathutils.Euler[begin:end] = []")) == -1)
445                 return -1;
446
447         if(size != (end - begin)){
448                 PyErr_SetString(PyExc_ValueError,
449                                 "euler[begin:end] = []: "
450                                 "size mismatch in slice assignment");
451                 return -1;
452         }
453
454         for(i= 0; i < EULER_SIZE; i++)
455                 self->eul[begin + i] = eul[i];
456
457         (void)BaseMath_WriteCallback(self);
458         return 0;
459 }
460
461 static PyObject *Euler_subscript(EulerObject *self, PyObject *item)
462 {
463         if (PyIndex_Check(item)) {
464                 Py_ssize_t i;
465                 i = PyNumber_AsSsize_t(item, PyExc_IndexError);
466                 if (i == -1 && PyErr_Occurred())
467                         return NULL;
468                 if (i < 0)
469                         i += EULER_SIZE;
470                 return Euler_item(self, i);
471         }
472         else if (PySlice_Check(item)) {
473                 Py_ssize_t start, stop, step, slicelength;
474
475                 if (PySlice_GetIndicesEx((void *)item, EULER_SIZE, &start, &stop, &step, &slicelength) < 0)
476                         return NULL;
477
478                 if (slicelength <= 0) {
479                         return PyTuple_New(0);
480                 }
481                 else if (step == 1) {
482                         return Euler_slice(self, start, stop);
483                 }
484                 else {
485                         PyErr_SetString(PyExc_IndexError,
486                                         "slice steps not supported with eulers");
487                         return NULL;
488                 }
489         }
490         else {
491                 PyErr_Format(PyExc_TypeError,
492                              "euler indices must be integers, not %.200s",
493                              Py_TYPE(item)->tp_name);
494                 return NULL;
495         }
496 }
497
498
499 static int Euler_ass_subscript(EulerObject *self, PyObject *item, PyObject *value)
500 {
501         if (PyIndex_Check(item)) {
502                 Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError);
503                 if (i == -1 && PyErr_Occurred())
504                         return -1;
505                 if (i < 0)
506                         i += EULER_SIZE;
507                 return Euler_ass_item(self, i, value);
508         }
509         else if (PySlice_Check(item)) {
510                 Py_ssize_t start, stop, step, slicelength;
511
512                 if (PySlice_GetIndicesEx((void *)item, EULER_SIZE, &start, &stop, &step, &slicelength) < 0)
513                         return -1;
514
515                 if (step == 1)
516                         return Euler_ass_slice(self, start, stop, value);
517                 else {
518                         PyErr_SetString(PyExc_IndexError,
519                                         "slice steps not supported with euler");
520                         return -1;
521                 }
522         }
523         else {
524                 PyErr_Format(PyExc_TypeError,
525                              "euler indices must be integers, not %.200s",
526                              Py_TYPE(item)->tp_name);
527                 return -1;
528         }
529 }
530
531 //-----------------PROTCOL DECLARATIONS--------------------------
532 static PySequenceMethods Euler_SeqMethods = {
533         (lenfunc) Euler_len,                                    /* sq_length */
534         (binaryfunc) NULL,                                              /* sq_concat */
535         (ssizeargfunc) NULL,                                    /* sq_repeat */
536         (ssizeargfunc) Euler_item,                              /* sq_item */
537         (ssizessizeargfunc) NULL,                               /* sq_slice, deprecated  */
538         (ssizeobjargproc) Euler_ass_item,               /* sq_ass_item */
539         (ssizessizeobjargproc) NULL,                    /* sq_ass_slice, deprecated */
540         (objobjproc) NULL,                                              /* sq_contains */
541         (binaryfunc) NULL,                                              /* sq_inplace_concat */
542         (ssizeargfunc) NULL,                                    /* sq_inplace_repeat */
543 };
544
545 static PyMappingMethods Euler_AsMapping = {
546         (lenfunc)Euler_len,
547         (binaryfunc)Euler_subscript,
548         (objobjargproc)Euler_ass_subscript
549 };
550
551 /*
552  * euler axis, euler.x/y/z
553  */
554 static PyObject *Euler_getAxis(EulerObject *self, void *type)
555 {
556         return Euler_item(self, GET_INT_FROM_POINTER(type));
557 }
558
559 static int Euler_setAxis(EulerObject *self, PyObject *value, void *type)
560 {
561         return Euler_ass_item(self, GET_INT_FROM_POINTER(type), value);
562 }
563
564 /* rotation order */
565 static PyObject *Euler_getOrder(EulerObject *self, void *UNUSED(closure))
566 {
567         if(BaseMath_ReadCallback(self) == -1) /* can read order too */
568                 return NULL;
569
570         return PyUnicode_FromString(euler_order_str(self));
571 }
572
573 static int Euler_setOrder(EulerObject *self, PyObject *value, void *UNUSED(closure))
574 {
575         const char *order_str= _PyUnicode_AsString(value);
576         short order= euler_order_from_string(order_str, "euler.order");
577
578         if(order == -1)
579                 return -1;
580
581         self->order= order;
582         (void)BaseMath_WriteCallback(self); /* order can be written back */
583         return 0;
584 }
585
586 /*****************************************************************************/
587 /* Python attributes get/set structure:                                      */
588 /*****************************************************************************/
589 static PyGetSetDef Euler_getseters[] = {
590         {(char *)"x", (getter)Euler_getAxis, (setter)Euler_setAxis, (char *)"Euler X axis in radians.\n\n:type: float", (void *)0},
591         {(char *)"y", (getter)Euler_getAxis, (setter)Euler_setAxis, (char *)"Euler Y axis in radians.\n\n:type: float", (void *)1},
592         {(char *)"z", (getter)Euler_getAxis, (setter)Euler_setAxis, (char *)"Euler Z axis in radians.\n\n:type: float", (void *)2},
593         {(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},
594
595         {(char *)"is_wrapped", (getter)BaseMathObject_getWrapped, (setter)NULL, (char *)BaseMathObject_Wrapped_doc, NULL},
596         {(char *)"owner", (getter)BaseMathObject_getOwner, (setter)NULL, (char *)BaseMathObject_Owner_doc, NULL},
597         {NULL, NULL, NULL, NULL, NULL}  /* Sentinel */
598 };
599
600
601 //-----------------------METHOD DEFINITIONS ----------------------
602 static struct PyMethodDef Euler_methods[] = {
603         {"zero", (PyCFunction) Euler_zero, METH_NOARGS, Euler_zero_doc},
604         {"to_matrix", (PyCFunction) Euler_to_matrix, METH_NOARGS, Euler_to_matrix_doc},
605         {"to_quaternion", (PyCFunction) Euler_to_quaternion, METH_NOARGS, Euler_to_quaternion_doc},
606         {"rotate_axis", (PyCFunction) Euler_rotate_axis, METH_VARARGS, Euler_rotate_axis_doc},
607         {"rotate", (PyCFunction) Euler_rotate, METH_O, Euler_rotate_doc},
608         {"make_compatible", (PyCFunction) Euler_make_compatible, METH_O, Euler_make_compatible_doc},
609         {"__copy__", (PyCFunction) Euler_copy, METH_NOARGS, Euler_copy_doc},
610         {"copy", (PyCFunction) Euler_copy, METH_NOARGS, Euler_copy_doc},
611         {NULL, NULL, 0, NULL}
612 };
613
614 //------------------PY_OBECT DEFINITION--------------------------
615 PyDoc_STRVAR(euler_doc,
616 "This object gives access to Eulers in Blender."
617 );
618 PyTypeObject euler_Type = {
619         PyVarObject_HEAD_INIT(NULL, 0)
620         "mathutils.Euler",                              //tp_name
621         sizeof(EulerObject),                    //tp_basicsize
622         0,                                                              //tp_itemsize
623         (destructor)BaseMathObject_dealloc,             //tp_dealloc
624         NULL,                                                   //tp_print
625         NULL,                                                   //tp_getattr
626         NULL,                                                   //tp_setattr
627         NULL,                                                   //tp_compare
628         (reprfunc) Euler_repr,                  //tp_repr
629         NULL,                                                   //tp_as_number
630         &Euler_SeqMethods,                              //tp_as_sequence
631         &Euler_AsMapping,                               //tp_as_mapping
632         NULL,                                                   //tp_hash
633         NULL,                                                   //tp_call
634         NULL,                                                   //tp_str
635         NULL,                                                   //tp_getattro
636         NULL,                                                   //tp_setattro
637         NULL,                                                   //tp_as_buffer
638         Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, //tp_flags
639         euler_doc, //tp_doc
640         (traverseproc)BaseMathObject_traverse,  //tp_traverse
641         (inquiry)BaseMathObject_clear,  //tp_clear
642         (richcmpfunc)Euler_richcmpr,    //tp_richcompare
643         0,                                                              //tp_weaklistoffset
644         NULL,                                                   //tp_iter
645         NULL,                                                   //tp_iternext
646         Euler_methods,                                  //tp_methods
647         NULL,                                                   //tp_members
648         Euler_getseters,                                //tp_getset
649         NULL,                                                   //tp_base
650         NULL,                                                   //tp_dict
651         NULL,                                                   //tp_descr_get
652         NULL,                                                   //tp_descr_set
653         0,                                                              //tp_dictoffset
654         NULL,                                                   //tp_init
655         NULL,                                                   //tp_alloc
656         Euler_new,                                              //tp_new
657         NULL,                                                   //tp_free
658         NULL,                                                   //tp_is_gc
659         NULL,                                                   //tp_bases
660         NULL,                                                   //tp_mro
661         NULL,                                                   //tp_cache
662         NULL,                                                   //tp_subclasses
663         NULL,                                                   //tp_weaklist
664         NULL                                                    //tp_del
665 };
666 //------------------------newEulerObject (internal)-------------
667 //creates a new euler object
668 /*pass Py_WRAP - if vector is a WRAPPER for data allocated by BLENDER
669  (i.e. it was allocated elsewhere by MEM_mallocN())
670   pass Py_NEW - if vector is not a WRAPPER and managed by PYTHON
671  (i.e. it must be created here with PyMEM_malloc())*/
672 PyObject *newEulerObject(float *eul, short order, int type, PyTypeObject *base_type)
673 {
674         EulerObject *self;
675
676         self= base_type ?       (EulerObject *)base_type->tp_alloc(base_type, 0) :
677                                                 (EulerObject *)PyObject_GC_New(EulerObject, &euler_Type);
678
679         if(self) {
680                 /* init callbacks as NULL */
681                 self->cb_user= NULL;
682                 self->cb_type= self->cb_subtype= 0;
683
684                 if(type == Py_WRAP) {
685                         self->eul = eul;
686                         self->wrapped = Py_WRAP;
687                 }
688                 else if (type == Py_NEW) {
689                         self->eul = PyMem_Malloc(EULER_SIZE * sizeof(float));
690                         if(eul) {
691                                 copy_v3_v3(self->eul, eul);
692                         }
693                         else {
694                                 zero_v3(self->eul);
695                         }
696
697                         self->wrapped = Py_NEW;
698                 }
699                 else {
700                         Py_FatalError("Euler(): invalid type!");
701                 }
702
703                 self->order= order;
704         }
705
706         return (PyObject *)self;
707 }
708
709 PyObject *newEulerObject_cb(PyObject *cb_user, short order, int cb_type, int cb_subtype)
710 {
711         EulerObject *self= (EulerObject *)newEulerObject(NULL, order, Py_NEW, NULL);
712         if(self) {
713                 Py_INCREF(cb_user);
714                 self->cb_user=                  cb_user;
715                 self->cb_type=                  (unsigned char)cb_type;
716                 self->cb_subtype=               (unsigned char)cb_subtype;
717                 PyObject_GC_Track(self);
718         }
719
720         return (PyObject *)self;
721 }