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