add 'idprop' module so we can document idprop.types.*, currently doc generator has...
[blender.git] / source / blender / python / mathutils / mathutils_Euler.c
1 /*
2  *
3  * ***** BEGIN GPL LICENSE BLOCK *****
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  *
19  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
20  * All rights reserved.
21  *
22  *
23  * Contributor(s): Joseph Gilbert
24  *
25  * ***** END GPL LICENSE BLOCK *****
26  */
27
28 /** \file blender/python/mathutils/mathutils_Euler.c
29  *  \ingroup pymathutils
30  */
31
32
33 #include <Python.h>
34
35 #include "mathutils.h"
36
37 #include "BLI_math.h"
38 #include "BLI_utildefines.h"
39 #include "BLI_dynstr.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 Euler_CreatePyObject(eul, order, Py_NEW, type);
76 }
77
78 /* internal use, assume 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 Quaternion_CreatePyObject(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 Matrix_CreatePyObject(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         int axis; /* actually a character */
200
201         if (!PyArg_ParseTuple(args, "Cf:rotate_axis", &axis, &angle)) {
202                 PyErr_SetString(PyExc_TypeError,
203                                 "Euler.rotate_axis(): "
204                                 "expected an axis 'X', 'Y', 'Z' and an angle (float)");
205                 return NULL;
206         }
207
208         if (!(ELEM3(axis, 'X', 'Y', 'Z'))) {
209                 PyErr_SetString(PyExc_ValueError,
210                                 "Euler.rotate_axis(): "
211                                 "expected axis to be 'X', 'Y' or 'Z'");
212                 return NULL;
213         }
214
215         if (BaseMath_ReadCallback(self) == -1)
216                 return NULL;
217
218
219         rotate_eulO(self->eul, self->order, (char)axis, angle);
220
221         (void)BaseMath_WriteCallback(self);
222
223         Py_RETURN_NONE;
224 }
225
226 PyDoc_STRVAR(Euler_rotate_doc,
227 ".. method:: rotate(other)\n"
228 "\n"
229 "   Rotates the euler a by another mathutils value.\n"
230 "\n"
231 "   :arg other: rotation component of mathutils value\n"
232 "   :type other: :class:`Euler`, :class:`Quaternion` or :class:`Matrix`\n"
233 );
234 static PyObject *Euler_rotate(EulerObject *self, PyObject *value)
235 {
236         float self_rmat[3][3], other_rmat[3][3], rmat[3][3];
237
238         if (BaseMath_ReadCallback(self) == -1)
239                 return NULL;
240
241         if (mathutils_any_to_rotmat(other_rmat, value, "euler.rotate(value)") == -1)
242                 return NULL;
243
244         eulO_to_mat3(self_rmat, self->eul, self->order);
245         mul_m3_m3m3(rmat, other_rmat, self_rmat);
246
247         mat3_to_compatible_eulO(self->eul, self->eul, self->order, rmat);
248
249         (void)BaseMath_WriteCallback(self);
250         Py_RETURN_NONE;
251 }
252
253 PyDoc_STRVAR(Euler_make_compatible_doc,
254 ".. method:: make_compatible(other)\n"
255 "\n"
256 "   Make this euler compatible with another,\n"
257 "   so interpolating between them works as intended.\n"
258 "\n"
259 "   .. note:: the rotation order is not taken into account for this function.\n"
260 );
261 static PyObject *Euler_make_compatible(EulerObject *self, PyObject *value)
262 {
263         float teul[EULER_SIZE];
264
265         if (BaseMath_ReadCallback(self) == -1)
266                 return NULL;
267
268         if (mathutils_array_parse(teul, EULER_SIZE, EULER_SIZE, value,
269                                   "euler.make_compatible(other), invalid 'other' arg") == -1)
270         {
271                 return NULL;
272         }
273
274         compatible_eul(self->eul, teul);
275
276         (void)BaseMath_WriteCallback(self);
277
278         Py_RETURN_NONE;
279 }
280
281 //----------------------------Euler.rotate()-----------------------
282 // return a copy of the euler
283
284 PyDoc_STRVAR(Euler_copy_doc,
285 ".. function:: copy()\n"
286 "\n"
287 "   Returns a copy of this euler.\n"
288 "\n"
289 "   :return: A copy of the euler.\n"
290 "   :rtype: :class:`Euler`\n"
291 "\n"
292 "   .. note:: use this to get a copy of a wrapped euler with\n"
293 "      no reference to the original data.\n"
294 );
295 static PyObject *Euler_copy(EulerObject *self)
296 {
297         if (BaseMath_ReadCallback(self) == -1)
298                 return NULL;
299
300         return Euler_CreatePyObject(self->eul, self->order, Py_NEW, Py_TYPE(self));
301 }
302 static PyObject *Euler_deepcopy(EulerObject *self, PyObject *args)
303 {
304         if (!mathutils_deepcopy_args_check(args))
305                 return NULL;
306         return Euler_copy(self);
307 }
308
309 //----------------------------print object (internal)--------------
310 //print the object to screen
311
312 static PyObject *Euler_repr(EulerObject *self)
313 {
314         PyObject *ret, *tuple;
315
316         if (BaseMath_ReadCallback(self) == -1)
317                 return NULL;
318
319         tuple = Euler_ToTupleExt(self, -1);
320
321         ret = PyUnicode_FromFormat("Euler(%R, '%s')", tuple, euler_order_str(self));
322
323         Py_DECREF(tuple);
324         return ret;
325 }
326
327 static PyObject *Euler_str(EulerObject *self)
328 {
329         DynStr *ds;
330
331         if (BaseMath_ReadCallback(self) == -1)
332                 return NULL;
333
334         ds = BLI_dynstr_new();
335
336         BLI_dynstr_appendf(ds, "<Euler (x=%.4f, y=%.4f, z=%.4f), order='%s'>",
337                            self->eul[0], self->eul[1], self->eul[2], euler_order_str(self));
338
339         return mathutils_dynstr_to_py(ds); /* frees ds */
340 }
341
342 static PyObject *Euler_richcmpr(PyObject *a, PyObject *b, int op)
343 {
344         PyObject *res;
345         int ok = -1; /* zero is true */
346
347         if (EulerObject_Check(a) && EulerObject_Check(b)) {
348                 EulerObject *eulA = (EulerObject *)a;
349                 EulerObject *eulB = (EulerObject *)b;
350
351                 if (BaseMath_ReadCallback(eulA) == -1 || BaseMath_ReadCallback(eulB) == -1)
352                         return NULL;
353
354                 ok = ((eulA->order == eulB->order) && EXPP_VectorsAreEqual(eulA->eul, eulB->eul, EULER_SIZE, 1)) ? 0 : -1;
355         }
356
357         switch (op) {
358                 case Py_NE:
359                         ok = !ok; /* pass through */
360                 case Py_EQ:
361                         res = ok ? Py_False : Py_True;
362                         break;
363
364                 case Py_LT:
365                 case Py_LE:
366                 case Py_GT:
367                 case Py_GE:
368                         res = Py_NotImplemented;
369                         break;
370                 default:
371                         PyErr_BadArgument();
372                         return NULL;
373         }
374
375         return Py_INCREF(res), res;
376 }
377
378 //---------------------SEQUENCE PROTOCOLS------------------------
379 //----------------------------len(object)------------------------
380 //sequence length
381 static int Euler_len(EulerObject *UNUSED(self))
382 {
383         return EULER_SIZE;
384 }
385 //----------------------------object[]---------------------------
386 //sequence accessor (get)
387 static PyObject *Euler_item(EulerObject *self, int i)
388 {
389         if (i < 0) i = EULER_SIZE - i;
390
391         if (i < 0 || i >= EULER_SIZE) {
392                 PyErr_SetString(PyExc_IndexError,
393                                 "euler[attribute]: "
394                                 "array index out of range");
395                 return NULL;
396         }
397
398         if (BaseMath_ReadIndexCallback(self, i) == -1)
399                 return NULL;
400
401         return PyFloat_FromDouble(self->eul[i]);
402
403 }
404 //----------------------------object[]-------------------------
405 //sequence accessor (set)
406 static int Euler_ass_item(EulerObject *self, int i, PyObject *value)
407 {
408         float f = PyFloat_AsDouble(value);
409
410         if (f == -1 && PyErr_Occurred()) { // parsed item not a number
411                 PyErr_SetString(PyExc_TypeError,
412                                 "euler[attribute] = x: "
413                                 "argument not a number");
414                 return -1;
415         }
416
417         if (i < 0) i = EULER_SIZE - i;
418
419         if (i < 0 || i >= EULER_SIZE) {
420                 PyErr_SetString(PyExc_IndexError,
421                                 "euler[attribute] = x: "
422                                 "array assignment index out of range");
423                 return -1;
424         }
425
426         self->eul[i] = f;
427
428         if (BaseMath_WriteIndexCallback(self, i) == -1)
429                 return -1;
430
431         return 0;
432 }
433 //----------------------------object[z:y]------------------------
434 //sequence slice (get)
435 static PyObject *Euler_slice(EulerObject *self, int begin, int end)
436 {
437         PyObject *tuple;
438         int count;
439
440         if (BaseMath_ReadCallback(self) == -1)
441                 return NULL;
442
443         CLAMP(begin, 0, EULER_SIZE);
444         if (end < 0) end = (EULER_SIZE + 1) + end;
445         CLAMP(end, 0, EULER_SIZE);
446         begin = MIN2(begin, end);
447
448         tuple = PyTuple_New(end - begin);
449         for (count = begin; count < end; count++) {
450                 PyTuple_SET_ITEM(tuple, count - begin, PyFloat_FromDouble(self->eul[count]));
451         }
452
453         return tuple;
454 }
455 //----------------------------object[z:y]------------------------
456 //sequence slice (set)
457 static int Euler_ass_slice(EulerObject *self, int begin, int end, PyObject *seq)
458 {
459         int i, size;
460         float eul[EULER_SIZE];
461
462         if (BaseMath_ReadCallback(self) == -1)
463                 return -1;
464
465         CLAMP(begin, 0, EULER_SIZE);
466         if (end < 0) end = (EULER_SIZE + 1) + end;
467         CLAMP(end, 0, EULER_SIZE);
468         begin = MIN2(begin, end);
469
470         if ((size = mathutils_array_parse(eul, 0, EULER_SIZE, seq, "mathutils.Euler[begin:end] = []")) == -1)
471                 return -1;
472
473         if (size != (end - begin)) {
474                 PyErr_SetString(PyExc_ValueError,
475                                 "euler[begin:end] = []: "
476                                 "size mismatch in slice assignment");
477                 return -1;
478         }
479
480         for (i = 0; i < EULER_SIZE; i++)
481                 self->eul[begin + i] = eul[i];
482
483         (void)BaseMath_WriteCallback(self);
484         return 0;
485 }
486
487 static PyObject *Euler_subscript(EulerObject *self, PyObject *item)
488 {
489         if (PyIndex_Check(item)) {
490                 Py_ssize_t i;
491                 i = PyNumber_AsSsize_t(item, PyExc_IndexError);
492                 if (i == -1 && PyErr_Occurred())
493                         return NULL;
494                 if (i < 0)
495                         i += EULER_SIZE;
496                 return Euler_item(self, i);
497         }
498         else if (PySlice_Check(item)) {
499                 Py_ssize_t start, stop, step, slicelength;
500
501                 if (PySlice_GetIndicesEx((void *)item, EULER_SIZE, &start, &stop, &step, &slicelength) < 0)
502                         return NULL;
503
504                 if (slicelength <= 0) {
505                         return PyTuple_New(0);
506                 }
507                 else if (step == 1) {
508                         return Euler_slice(self, start, stop);
509                 }
510                 else {
511                         PyErr_SetString(PyExc_IndexError,
512                                         "slice steps not supported with eulers");
513                         return NULL;
514                 }
515         }
516         else {
517                 PyErr_Format(PyExc_TypeError,
518                              "euler indices must be integers, not %.200s",
519                              Py_TYPE(item)->tp_name);
520                 return NULL;
521         }
522 }
523
524
525 static int Euler_ass_subscript(EulerObject *self, PyObject *item, PyObject *value)
526 {
527         if (PyIndex_Check(item)) {
528                 Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError);
529                 if (i == -1 && PyErr_Occurred())
530                         return -1;
531                 if (i < 0)
532                         i += EULER_SIZE;
533                 return Euler_ass_item(self, i, value);
534         }
535         else if (PySlice_Check(item)) {
536                 Py_ssize_t start, stop, step, slicelength;
537
538                 if (PySlice_GetIndicesEx((void *)item, EULER_SIZE, &start, &stop, &step, &slicelength) < 0)
539                         return -1;
540
541                 if (step == 1)
542                         return Euler_ass_slice(self, start, stop, value);
543                 else {
544                         PyErr_SetString(PyExc_IndexError,
545                                         "slice steps not supported with euler");
546                         return -1;
547                 }
548         }
549         else {
550                 PyErr_Format(PyExc_TypeError,
551                              "euler indices must be integers, not %.200s",
552                              Py_TYPE(item)->tp_name);
553                 return -1;
554         }
555 }
556
557 //-----------------PROTCOL DECLARATIONS--------------------------
558 static PySequenceMethods Euler_SeqMethods = {
559         (lenfunc) Euler_len,                    /* sq_length */
560         (binaryfunc) NULL,                      /* sq_concat */
561         (ssizeargfunc) NULL,                    /* sq_repeat */
562         (ssizeargfunc) Euler_item,              /* sq_item */
563         (ssizessizeargfunc) NULL,               /* sq_slice, deprecated  */
564         (ssizeobjargproc) Euler_ass_item,       /* sq_ass_item */
565         (ssizessizeobjargproc) NULL,            /* sq_ass_slice, deprecated */
566         (objobjproc) NULL,                      /* sq_contains */
567         (binaryfunc) NULL,                      /* sq_inplace_concat */
568         (ssizeargfunc) NULL,                    /* sq_inplace_repeat */
569 };
570
571 static PyMappingMethods Euler_AsMapping = {
572         (lenfunc)Euler_len,
573         (binaryfunc)Euler_subscript,
574         (objobjargproc)Euler_ass_subscript
575 };
576
577 /* euler axis, euler.x/y/z */
578
579 PyDoc_STRVAR(Euler_axis_doc,
580 "Euler axis angle in radians.\n\n:type: float"
581 );
582 static PyObject *Euler_axis_get(EulerObject *self, void *type)
583 {
584         return Euler_item(self, GET_INT_FROM_POINTER(type));
585 }
586
587 static int Euler_axis_set(EulerObject *self, PyObject *value, void *type)
588 {
589         return Euler_ass_item(self, GET_INT_FROM_POINTER(type), value);
590 }
591
592 /* rotation order */
593
594 PyDoc_STRVAR(Euler_order_doc,
595 "Euler rotation order.\n\n:type: string in ['XYZ', 'XZY', 'YXZ', 'YZX', 'ZXY', 'ZYX']"
596 );
597 static PyObject *Euler_order_get(EulerObject *self, void *UNUSED(closure))
598 {
599         if (BaseMath_ReadCallback(self) == -1) /* can read order too */
600                 return NULL;
601
602         return PyUnicode_FromString(euler_order_str(self));
603 }
604
605 static int Euler_order_set(EulerObject *self, PyObject *value, void *UNUSED(closure))
606 {
607         const char *order_str = _PyUnicode_AsString(value);
608         short order = euler_order_from_string(order_str, "euler.order");
609
610         if (order == -1)
611                 return -1;
612
613         self->order = order;
614         (void)BaseMath_WriteCallback(self); /* order can be written back */
615         return 0;
616 }
617
618 /*****************************************************************************/
619 /* Python attributes get/set structure:                                      */
620 /*****************************************************************************/
621 static PyGetSetDef Euler_getseters[] = {
622         {(char *)"x", (getter)Euler_axis_get, (setter)Euler_axis_set, Euler_axis_doc, (void *)0},
623         {(char *)"y", (getter)Euler_axis_get, (setter)Euler_axis_set, Euler_axis_doc, (void *)1},
624         {(char *)"z", (getter)Euler_axis_get, (setter)Euler_axis_set, Euler_axis_doc, (void *)2},
625         {(char *)"order", (getter)Euler_order_get, (setter)Euler_order_set, Euler_order_doc, (void *)NULL},
626
627         {(char *)"is_wrapped", (getter)BaseMathObject_is_wrapped_get, (setter)NULL, BaseMathObject_is_wrapped_doc, NULL},
628         {(char *)"owner", (getter)BaseMathObject_owner_get, (setter)NULL, BaseMathObject_owner_doc, NULL},
629         {NULL, NULL, NULL, NULL, NULL}  /* Sentinel */
630 };
631
632
633 //-----------------------METHOD DEFINITIONS ----------------------
634 static struct PyMethodDef Euler_methods[] = {
635         {"zero", (PyCFunction) Euler_zero, METH_NOARGS, Euler_zero_doc},
636         {"to_matrix", (PyCFunction) Euler_to_matrix, METH_NOARGS, Euler_to_matrix_doc},
637         {"to_quaternion", (PyCFunction) Euler_to_quaternion, METH_NOARGS, Euler_to_quaternion_doc},
638         {"rotate_axis", (PyCFunction) Euler_rotate_axis, METH_VARARGS, Euler_rotate_axis_doc},
639         {"rotate", (PyCFunction) Euler_rotate, METH_O, Euler_rotate_doc},
640         {"make_compatible", (PyCFunction) Euler_make_compatible, METH_O, Euler_make_compatible_doc},
641         {"copy", (PyCFunction) Euler_copy, METH_NOARGS, Euler_copy_doc},
642         {"__copy__", (PyCFunction) Euler_copy, METH_NOARGS, Euler_copy_doc},
643         {"__deepcopy__", (PyCFunction) Euler_deepcopy, METH_VARARGS, Euler_copy_doc},
644         {NULL, NULL, 0, NULL}
645 };
646
647 //------------------PY_OBECT DEFINITION--------------------------
648 PyDoc_STRVAR(euler_doc,
649 "This object gives access to Eulers in Blender."
650 );
651 PyTypeObject euler_Type = {
652         PyVarObject_HEAD_INIT(NULL, 0)
653         "Euler",                        //tp_name
654         sizeof(EulerObject),            //tp_basicsize
655         0,                              //tp_itemsize
656         (destructor)BaseMathObject_dealloc,     //tp_dealloc
657         NULL,                           //tp_print
658         NULL,                           //tp_getattr
659         NULL,                           //tp_setattr
660         NULL,                           //tp_compare
661         (reprfunc) Euler_repr,          //tp_repr
662         NULL,                           //tp_as_number
663         &Euler_SeqMethods,              //tp_as_sequence
664         &Euler_AsMapping,               //tp_as_mapping
665         NULL,                           //tp_hash
666         NULL,                           //tp_call
667         (reprfunc) Euler_str,           //tp_str
668         NULL,                           //tp_getattro
669         NULL,                           //tp_setattro
670         NULL,                           //tp_as_buffer
671         Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, //tp_flags
672         euler_doc, //tp_doc
673         (traverseproc)BaseMathObject_traverse,  //tp_traverse
674         (inquiry)BaseMathObject_clear,  //tp_clear
675         (richcmpfunc)Euler_richcmpr,    //tp_richcompare
676         0,                              //tp_weaklistoffset
677         NULL,                           //tp_iter
678         NULL,                           //tp_iternext
679         Euler_methods,                  //tp_methods
680         NULL,                           //tp_members
681         Euler_getseters,                //tp_getset
682         NULL,                           //tp_base
683         NULL,                           //tp_dict
684         NULL,                           //tp_descr_get
685         NULL,                           //tp_descr_set
686         0,                              //tp_dictoffset
687         NULL,                           //tp_init
688         NULL,                           //tp_alloc
689         Euler_new,                      //tp_new
690         NULL,                           //tp_free
691         NULL,                           //tp_is_gc
692         NULL,                           //tp_bases
693         NULL,                           //tp_mro
694         NULL,                           //tp_cache
695         NULL,                           //tp_subclasses
696         NULL,                           //tp_weaklist
697         NULL                            //tp_del
698 };
699 //------------------------Euler_CreatePyObject (internal)-------------
700 //creates a new euler object
701 /* pass Py_WRAP - if vector is a WRAPPER for data allocated by BLENDER
702  * (i.e. it was allocated elsewhere by MEM_mallocN())
703  * pass Py_NEW - if vector is not a WRAPPER and managed by PYTHON
704  * (i.e. it must be created here with PyMEM_malloc())*/
705 PyObject *Euler_CreatePyObject(float *eul, short order, int type, PyTypeObject *base_type)
706 {
707         EulerObject *self;
708
709         self = base_type ?  (EulerObject *)base_type->tp_alloc(base_type, 0) :
710                             (EulerObject *)PyObject_GC_New(EulerObject, &euler_Type);
711
712         if (self) {
713                 /* init callbacks as NULL */
714                 self->cb_user = NULL;
715                 self->cb_type = self->cb_subtype = 0;
716
717                 if (type == Py_WRAP) {
718                         self->eul = eul;
719                         self->wrapped = Py_WRAP;
720                 }
721                 else if (type == Py_NEW) {
722                         self->eul = PyMem_Malloc(EULER_SIZE * sizeof(float));
723                         if (eul) {
724                                 copy_v3_v3(self->eul, eul);
725                         }
726                         else {
727                                 zero_v3(self->eul);
728                         }
729
730                         self->wrapped = Py_NEW;
731                 }
732                 else {
733                         Py_FatalError("Euler(): invalid type!");
734                 }
735
736                 self->order = order;
737         }
738
739         return (PyObject *)self;
740 }
741
742 PyObject *Euler_CreatePyObject_cb(PyObject *cb_user, short order,
743                                   unsigned char cb_type, unsigned char cb_subtype)
744 {
745         EulerObject *self = (EulerObject *)Euler_CreatePyObject(NULL, order, Py_NEW, NULL);
746         if (self) {
747                 Py_INCREF(cb_user);
748                 self->cb_user         = cb_user;
749                 self->cb_type         = cb_type;
750                 self->cb_subtype      = cb_subtype;
751                 PyObject_GC_Track(self);
752         }
753
754         return (PyObject *)self;
755 }