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