remove unused includes
[blender.git] / source / blender / python / generic / euler.c
index e78a57393477f1bd9e1f8c9a3e62495be6de4254..3c018333b39d97b70360999875dafa944093959f 100644 (file)
@@ -15,7 +15,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
  * All rights reserved.
 
 #include "Mathutils.h"
 
-#include "BLI_arithb.h"
+#include "BLI_math.h"
 #include "BKE_utildefines.h"
-#include "BLI_blenlib.h"
-
-
-//-------------------------DOC STRINGS ---------------------------
-static char Euler_Zero_doc[] = "() - set all values in the euler to 0";
-static char Euler_Unique_doc[] ="() - sets the euler rotation a unique shortest arc rotation - tests for gimbal lock";
-static char Euler_ToMatrix_doc[] =     "() - returns a rotation matrix representing the euler rotation";
-static char Euler_ToQuat_doc[] = "() - returns a quaternion representing the euler rotation";
-static char Euler_Rotate_doc[] = "() - rotate a euler by certain amount around an axis of rotation";
-static char Euler_copy_doc[] = "() - returns a copy of the euler.";
-static char Euler_MakeCompatible_doc[] = "(euler) - Make this user compatible with another (no axis flipping).";
-
-static PyObject *Euler_Zero( EulerObject * self );
-static PyObject *Euler_Unique( EulerObject * self );
-static PyObject *Euler_ToMatrix( EulerObject * self );
-static PyObject *Euler_ToQuat( EulerObject * self );
-static PyObject *Euler_Rotate( EulerObject * self, PyObject *args );
-static PyObject *Euler_MakeCompatible( EulerObject * self, EulerObject *value );
-static PyObject *Euler_copy( EulerObject * self, PyObject *args );
-
-//-----------------------METHOD DEFINITIONS ----------------------
-static struct PyMethodDef Euler_methods[] = {
-       {"zero", (PyCFunction) Euler_Zero, METH_NOARGS, Euler_Zero_doc},
-       {"unique", (PyCFunction) Euler_Unique, METH_NOARGS, Euler_Unique_doc},
-       {"toMatrix", (PyCFunction) Euler_ToMatrix, METH_NOARGS, Euler_ToMatrix_doc},
-       {"toQuat", (PyCFunction) Euler_ToQuat, METH_NOARGS, Euler_ToQuat_doc},
-       {"rotate", (PyCFunction) Euler_Rotate, METH_VARARGS, Euler_Rotate_doc},
-       {"makeCompatible", (PyCFunction) Euler_MakeCompatible, METH_O, Euler_MakeCompatible_doc},
-       {"__copy__", (PyCFunction) Euler_copy, METH_VARARGS, Euler_copy_doc},
-       {"copy", (PyCFunction) Euler_copy, METH_VARARGS, Euler_copy_doc},
-       {NULL, NULL, 0, NULL}
-};
 
 //----------------------------------Mathutils.Euler() -------------------
 //makes a new euler for you to play with
-static PyObject *Euler_new(PyObject * self, PyObject * args)
+static PyObject *Euler_new(PyTypeObject * type, PyObject * args, PyObject * kwargs)
 {
-
        PyObject *listObject = NULL;
        int size, i;
-       float eul[3], scalar;
+       float eul[3];
        PyObject *e;
+       short order= 0;  // TODO, add order option
 
        size = PyTuple_GET_SIZE(args);
        if (size == 1) {
@@ -84,7 +52,7 @@ static PyObject *Euler_new(PyObject * self, PyObject * args)
                }
        } else if (size == 0) {
                //returns a new empty 3d euler
-               return newEulerObject(NULL, Py_NEW); 
+               return newEulerObject(NULL, order, Py_NEW, NULL);
        } else {
                listObject = args;
        }
@@ -102,106 +70,156 @@ static PyObject *Euler_new(PyObject * self, PyObject * args)
                        return NULL;
                }
 
-               scalar= (float)PyFloat_AsDouble(e);
+               eul[i]= (float)PyFloat_AsDouble(e);
                Py_DECREF(e);
                
-               if(scalar==-1 && PyErr_Occurred()) { // parsed item is not a number
+               if(eul[i]==-1 && PyErr_Occurred()) { // parsed item is not a number
                        PyErr_SetString(PyExc_TypeError, "Mathutils.Euler(): 3d numeric sequence expected\n");
                        return NULL;
                }
+       }
+       return newEulerObject(eul, order, Py_NEW, NULL);
+}
 
-               eul[i]= scalar;
+short euler_order_from_string(const char *str, const char *error_prefix)
+{
+       if((str[0] && str[1] && str[2] && str[3]=='\0')) {
+               switch(*((int32_t *)str)) {
+                       case 'X'|'Y'<<8|'Z'<<16:        return 0;
+                       case 'X'|'Z'<<8|'Y'<<16:        return 1;
+                       case 'Y'|'X'<<8|'Z'<<16:        return 2;
+                       case 'Y'|'Z'<<8|'X'<<16:        return 3;
+                       case 'Z'|'X'<<8|'Y'<<16:        return 4;
+                       case 'Z'|'Y'<<8|'X'<<16:        return 5;
+               }
        }
-       return newEulerObject(eul, Py_NEW);
+
+       PyErr_Format(PyExc_TypeError, "%s: invalid euler order '%s'", error_prefix, str);
+       return -1;
 }
 
 //-----------------------------METHODS----------------------------
 //----------------------------Euler.toQuat()----------------------
 //return a quaternion representation of the euler
+
+static char Euler_ToQuat_doc[] =
+".. method:: to_quat()\n"
+"\n"
+"   Return a quaternion representation of the euler.\n"
+"\n"
+"   :return: Quaternion representation of the euler.\n"
+"   :rtype: :class:`Quaternion`\n";
+
 static PyObject *Euler_ToQuat(EulerObject * self)
 {
-       float eul[3], quat[4];
-       int x;
+       float quat[4];
 
-       for(x = 0; x < 3; x++) {
-               eul[x] = self->eul[x] * ((float)Py_PI / 180);
-       }
-       EulToQuat(eul, quat);
-       return newQuaternionObject(quat, Py_NEW);
+       if(!BaseMath_ReadCallback(self))
+               return NULL;
+
+       if(self->order==0)      eul_to_quat(quat, self->eul);
+       else                            eulO_to_quat(quat, self->eul, self->order);
+
+       return newQuaternionObject(quat, Py_NEW, NULL);
 }
 //----------------------------Euler.toMatrix()---------------------
 //return a matrix representation of the euler
+static char Euler_ToMatrix_doc[] =
+".. method:: to_matrix()\n"
+"\n"
+"   Return a matrix representation of the euler.\n"
+"\n"
+"   :return: A 3x3 roation matrix representation of the euler.\n"
+"   :rtype: :class:`Matrix`\n";
+
 static PyObject *Euler_ToMatrix(EulerObject * self)
 {
-       float eul[3];
        float mat[9] = {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f};
-       int x;
 
-       for(x = 0; x < 3; x++) {
-               eul[x] = self->eul[x] * ((float)Py_PI / 180);
-       }
-       EulToMat3(eul, (float (*)[3]) mat);
-       return newMatrixObject(mat, 3, 3 , Py_NEW);
+       if(!BaseMath_ReadCallback(self))
+               return NULL;
+
+       if(self->order==0)      eul_to_mat3((float (*)[3])mat, self->eul);
+       else                            eulO_to_mat3((float (*)[3])mat, self->eul, self->order);
+
+       return newMatrixObject(mat, 3, 3 , Py_NEW, NULL);
 }
 //----------------------------Euler.unique()-----------------------
 //sets the x,y,z values to a unique euler rotation
+// TODO, check if this works with rotation order!!!
+static char Euler_Unique_doc[] =
+".. method:: unique()\n"
+"\n"
+"   Calculate a unique rotation for this euler. Avoids gimble lock.\n"
+"\n"
+"   :return: an instance of itself\n"
+"   :rtype: :class:`Euler`\n";
+
 static PyObject *Euler_Unique(EulerObject * self)
 {
+#define PI_2           (Py_PI * 2.0)
+#define PI_HALF                (Py_PI / 2.0)
+#define PI_INV         (1.0 / Py_PI)
+
        double heading, pitch, bank;
-       double pi2 =  Py_PI * 2.0f;
-       double piO2 = Py_PI / 2.0f;
-       double Opi2 = 1.0f / pi2;
 
-       //radians
-       heading = self->eul[0] * (float)Py_PI / 180;
-       pitch = self->eul[1] * (float)Py_PI / 180;
-       bank = self->eul[2] * (float)Py_PI / 180;
+       if(!BaseMath_ReadCallback(self))
+               return NULL;
+
+       heading = self->eul[0];
+       pitch = self->eul[1];
+       bank = self->eul[2];
 
        //wrap heading in +180 / -180
        pitch += Py_PI;
-       pitch -= floor(pitch * Opi2) * pi2;
+       pitch -= floor(pitch * PI_INV) * PI_2;
        pitch -= Py_PI;
 
 
-       if(pitch < -piO2) {
+       if(pitch < -PI_HALF) {
                pitch = -Py_PI - pitch;
                heading += Py_PI;
                bank += Py_PI;
-       } else if(pitch > piO2) {
+       } else if(pitch > PI_HALF) {
                pitch = Py_PI - pitch;
                heading += Py_PI;
                bank += Py_PI;
        }
        //gimbal lock test
-       if(fabs(pitch) > piO2 - 1e-4) {
+       if(fabs(pitch) > PI_HALF - 1e-4) {
                heading += bank;
                bank = 0.0f;
        } else {
                bank += Py_PI;
-               bank -= (floor(bank * Opi2)) * pi2;
+               bank -= (floor(bank * PI_INV)) * PI_2;
                bank -= Py_PI;
        }
 
        heading += Py_PI;
-       heading -= (floor(heading * Opi2)) * pi2;
+       heading -= (floor(heading * PI_INV)) * PI_2;
        heading -= Py_PI;
 
-       //back to degrees
-       self->eul[0] = (float)(heading * 180 / (float)Py_PI);
-       self->eul[1] = (float)(pitch * 180 / (float)Py_PI);
-       self->eul[2] = (float)(bank * 180 / (float)Py_PI);
-
+       BaseMath_WriteCallback(self);
        Py_INCREF(self);
        return (PyObject *)self;
 }
 //----------------------------Euler.zero()-------------------------
 //sets the euler to 0,0,0
+static char Euler_Zero_doc[] =
+".. method:: zero()\n"
+"\n"
+"   Set all values to zero.\n"
+"\n"
+"   :return: an instance of itself\n"
+"   :rtype: :class:`Euler`\n";
+
 static PyObject *Euler_Zero(EulerObject * self)
 {
        self->eul[0] = 0.0;
        self->eul[1] = 0.0;
        self->eul[2] = 0.0;
 
+       BaseMath_WriteCallback(self);
        Py_INCREF(self);
        return (PyObject *)self;
 }
@@ -212,74 +230,80 @@ static PyObject *Euler_Rotate(EulerObject * self, PyObject *args)
 {
        float angle = 0.0f;
        char *axis;
-       int x;
 
        if(!PyArg_ParseTuple(args, "fs", &angle, &axis)){
                PyErr_SetString(PyExc_TypeError, "euler.rotate():expected angle (float) and axis (x,y,z)");
                return NULL;
        }
-       if(!STREQ3(axis,"x","y","z")){
+       if(ELEM3(*axis, 'x', 'y', 'z') && axis[1]=='\0'){
                PyErr_SetString(PyExc_TypeError, "euler.rotate(): expected axis to be 'x', 'y' or 'z'");
                return NULL;
        }
 
-       //covert to radians
-       angle *= ((float)Py_PI / 180);
-       for(x = 0; x < 3; x++) {
-               self->eul[x] *= ((float)Py_PI / 180);
-       }
-       euler_rot(self->eul, angle, *axis);
-       //convert back from radians
-       for(x = 0; x < 3; x++) {
-               self->eul[x] *= (180 / (float)Py_PI);
-       }
+       if(!BaseMath_ReadCallback(self))
+               return NULL;
 
+       if(self->order == 0)    rotate_eul(self->eul, *axis, angle);
+       else                                    rotate_eulO(self->eul, self->order, *axis, angle);
+
+       BaseMath_WriteCallback(self);
        Py_INCREF(self);
        return (PyObject *)self;
 }
 
+static char Euler_MakeCompatible_doc[] =
+".. method:: make_compatible(other)\n"
+"\n"
+"   Make this euler compatible with another, so interpolating between them works as intended.\n"
+"\n"
+"   :arg other: make compatible with this rotation.\n"
+"   :type other: :class:`Euler`\n"
+"   :return: an instance of itself.\n"
+"   :rtype: :class:`Euler`\n"
+"\n"
+"   .. note:: the order of eulers must match or an exception is raised.\n";
+
 static PyObject *Euler_MakeCompatible(EulerObject * self, EulerObject *value)
 {
-       float eul_from_rad[3];
-       int x;
-       
        if(!EulerObject_Check(value)) {
-               PyErr_SetString(PyExc_TypeError, "euler.makeCompatible(euler):expected a single euler argument.");
+               PyErr_SetString(PyExc_TypeError, "euler.make_compatible(euler): expected a single euler argument.");
                return NULL;
        }
        
-       //covert to radians
-       for(x = 0; x < 3; x++) {
-               self->eul[x] = self->eul[x] * ((float)Py_PI / 180);
-               eul_from_rad[x] = value->eul[x] * ((float)Py_PI / 180);
-       }
-       compatible_eul(self->eul, eul_from_rad);
-       //convert back from radians
-       for(x = 0; x < 3; x++) {
-               self->eul[x] *= (180 / (float)Py_PI);
+       if(!BaseMath_ReadCallback(self) || !BaseMath_ReadCallback(value))
+               return NULL;
+
+       if(self->order != value->order) {
+               PyErr_SetString(PyExc_ValueError, "euler.make_compatible(euler): rotation orders don't match\n");
+               return NULL;
        }
-       
+
+       compatible_eul(self->eul, value->eul);
+
+       BaseMath_WriteCallback(self);
        Py_INCREF(self);
        return (PyObject *)self;
 }
 
 //----------------------------Euler.rotate()-----------------------
 // return a copy of the euler
-static PyObject *Euler_copy(EulerObject * self, PyObject *args)
-{
-       return newEulerObject(self->eul, Py_NEW);
-}
 
+static char Euler_copy_doc[] =
+".. function:: copy()\n"
+"\n"
+"   Returns a copy of this euler.\n"
+"\n"
+"   :return: A copy of the euler.\n"
+"   :rtype: :class:`Euler`\n"
+"\n"
+"   .. note:: use this to get a copy of a wrapped euler with no reference to the original data.\n";
 
-//----------------------------dealloc()(internal) ------------------
-//free the py_object
-static void Euler_dealloc(EulerObject * self)
+static PyObject *Euler_copy(EulerObject * self, PyObject *args)
 {
-       //only free py_data
-       if(self->data.py_data){
-               PyMem_Free(self->data.py_data);
-       }
-       PyObject_DEL(self);
+       if(!BaseMath_ReadCallback(self))
+               return NULL;
+
+       return newEulerObject(self->eul, self->order, Py_NEW, Py_TYPE(self));
 }
 
 //----------------------------print object (internal)--------------
@@ -287,6 +311,10 @@ static void Euler_dealloc(EulerObject * self)
 static PyObject *Euler_repr(EulerObject * self)
 {
        char str[64];
+
+       if(!BaseMath_ReadCallback(self))
+               return NULL;
+
        sprintf(str, "[%.6f, %.6f, %.6f](euler)", self->eul[0], self->eul[1], self->eul[2]);
        return PyUnicode_FromString(str);
 }
@@ -297,7 +325,18 @@ static PyObject* Euler_richcmpr(PyObject *objectA, PyObject *objectB, int compar
        EulerObject *eulA = NULL, *eulB = NULL;
        int result = 0;
 
-       if (!EulerObject_Check(objectA) || !EulerObject_Check(objectB)){
+       if(EulerObject_Check(objectA)) {
+               eulA = (EulerObject*)objectA;
+               if(!BaseMath_ReadCallback(eulA))
+                       return NULL;
+       }
+       if(EulerObject_Check(objectB)) {
+               eulB = (EulerObject*)objectB;
+               if(!BaseMath_ReadCallback(eulB))
+                       return NULL;
+       }
+
+       if (!eulA || !eulB){
                if (comparison_type == Py_NE){
                        Py_RETURN_TRUE;
                }else{
@@ -312,12 +351,7 @@ static PyObject* Euler_richcmpr(PyObject *objectA, PyObject *objectB, int compar
                        result = EXPP_VectorsAreEqual(eulA->eul, eulB->eul, 3, 1);
                        break;
                case Py_NE:
-                       result = EXPP_VectorsAreEqual(eulA->eul, eulB->eul, 3, 1);
-                       if (result == 0){
-                               result = 1;
-                       }else{
-                               result = 0;
-                       }
+                       result = !EXPP_VectorsAreEqual(eulA->eul, eulB->eul, 3, 1);
                        break;
                default:
                        printf("The result of the comparison could not be evaluated");
@@ -329,8 +363,7 @@ static PyObject* Euler_richcmpr(PyObject *objectA, PyObject *objectB, int compar
                Py_RETURN_FALSE;
        }
 }
-//------------------------tp_doc
-static char EulerObject_doc[] = "This is a wrapper for euler objects.";
+
 //---------------------SEQUENCE PROTOCOLS------------------------
 //----------------------------len(object)------------------------
 //sequence length
@@ -342,13 +375,16 @@ static int Euler_len(EulerObject * self)
 //sequence accessor (get)
 static PyObject *Euler_item(EulerObject * self, int i)
 {
-       if(i<0)
-               i= 3-i;
+       if(i<0) i= 3-i;
        
        if(i < 0 || i >= 3) {
                PyErr_SetString(PyExc_IndexError, "euler[attribute]: array index out of range");
                return NULL;
        }
+
+       if(!BaseMath_ReadIndexCallback(self, i))
+               return NULL;
+
        return PyFloat_FromDouble(self->eul[i]);
 
 }
@@ -363,8 +399,7 @@ static int Euler_ass_item(EulerObject * self, int i, PyObject * value)
                return -1;
        }
 
-       if(i<0)
-               i= 3-i;
+       if(i<0) i= 3-i;
        
        if(i < 0 || i >= 3){
                PyErr_SetString(PyExc_IndexError, "euler[attribute] = x: array assignment index out of range\n");
@@ -372,6 +407,10 @@ static int Euler_ass_item(EulerObject * self, int i, PyObject * value)
        }
        
        self->eul[i] = f;
+
+       if(!BaseMath_WriteIndexCallback(self, i))
+               return -1;
+
        return 0;
 }
 //----------------------------object[z:y]------------------------
@@ -381,6 +420,9 @@ static PyObject *Euler_slice(EulerObject * self, int begin, int end)
        PyObject *list = NULL;
        int count;
 
+       if(!BaseMath_ReadCallback(self))
+               return NULL;
+
        CLAMP(begin, 0, 3);
        if (end<0) end= 4+end;
        CLAMP(end, 0, 3);
@@ -401,7 +443,10 @@ static int Euler_ass_slice(EulerObject * self, int begin, int end,
 {
        int i, y, size = 0;
        float eul[3];
-       PyObject *e, *f;
+       PyObject *e;
+
+       if(!BaseMath_ReadCallback(self))
+               return -1;
 
        CLAMP(begin, 0, 3);
        if (end<0) end= 4+end;
@@ -421,26 +466,25 @@ static int Euler_ass_slice(EulerObject * self, int begin, int end,
                        return -1;
                }
 
-               f = PyNumber_Float(e);
-               if(f == NULL) { // parsed item not a number
-                       Py_DECREF(e);
+               eul[i] = (float)PyFloat_AsDouble(e);
+               Py_DECREF(e);
+
+               if(eul[i]==-1 && PyErr_Occurred()) { // parsed item not a number
                        PyErr_SetString(PyExc_TypeError, "euler[begin:end] = []: sequence argument not a number");
                        return -1;
                }
-
-               eul[i] = (float)PyFloat_AS_DOUBLE(f);
-               Py_DECREF(f);
-               Py_DECREF(e);
        }
        //parsed well - now set in vector
        for(y = 0; y < 3; y++){
                self->eul[begin + y] = eul[y];
        }
+
+       BaseMath_WriteCallback(self);
        return 0;
 }
 //-----------------PROTCOL DECLARATIONS--------------------------
 static PySequenceMethods Euler_SeqMethods = {
-       (inquiry) Euler_len,                                            /* sq_length */
+       (lenfunc) Euler_len,                                            /* sq_length */
        (binaryfunc) 0,                                                         /* sq_concat */
        (ssizeargfunc) 0,                                                               /* sq_repeat */
        (ssizeargfunc) Euler_item,                                      /* sq_item */
@@ -450,95 +494,81 @@ static PySequenceMethods Euler_SeqMethods = {
 };
 
 
-
 /*
  * vector axis, vector.x/y/z/w
  */
-       
 static PyObject *Euler_getAxis( EulerObject * self, void *type )
 {
-       switch( (long)type ) {
-    case 'X':  /* these are backwards, but that how it works */
-               return PyFloat_FromDouble(self->eul[0]);
-    case 'Y':
-               return PyFloat_FromDouble(self->eul[1]);
-    case 'Z':
-               return PyFloat_FromDouble(self->eul[2]);
-       }
-       
-       PyErr_SetString(PyExc_SystemError, "corrupt euler, cannot get axis");
-       return NULL;
+       return Euler_item(self, GET_INT_FROM_POINTER(type));
 }
 
 static int Euler_setAxis( EulerObject * self, PyObject * value, void * type )
 {
-       float param= (float)PyFloat_AsDouble( value );
-       
-       if (param==-1 && PyErr_Occurred()) {
-               PyErr_SetString(PyExc_TypeError, "expected a number for the vector axis");
-               return -1;
-       }
-       
-       switch( (long)type ) {
-    case 'X':  /* these are backwards, but that how it works */
-               self->eul[0]= param;
-               break;
-    case 'Y':
-               self->eul[1]= param;
-               break;
-    case 'Z':
-               self->eul[2]= param;
-               break;
-       }
-
-       return 0;
+       return Euler_ass_item(self, GET_INT_FROM_POINTER(type), value);
 }
 
-static PyObject *Euler_getWrapped( VectorObject * self, void *type )
+/* rotation order */
+static PyObject *Euler_getOrder(EulerObject *self, void *type)
 {
-       if (self->wrapped == Py_WRAP)
-               Py_RETURN_TRUE;
-       else
-               Py_RETURN_FALSE;
+       static char order[][4] = {"XYZ", "XZY", "YXZ", "YZX", "ZXY", "ZYX"};
+       return PyUnicode_FromString(order[self->order]);
 }
 
+static int Euler_setOrder( EulerObject * self, PyObject * value, void * type )
+{
+       char *order_str= _PyUnicode_AsString(value);
+       short order= euler_order_from_string(order_str, "euler.order");
+
+       if(order < 0)
+               return -1;
+
+       if(self->cb_user) {
+               PyErr_SetString(PyExc_TypeError, "euler.order: assignment is not allowed on eulers with an owner");
+               return -1;
+       }
+
+       self->order= order;
+       return 0;
+}
 
 /*****************************************************************************/
 /* Python attributes get/set structure:                                      */
 /*****************************************************************************/
 static PyGetSetDef Euler_getseters[] = {
-       {"x",
-        (getter)Euler_getAxis, (setter)Euler_setAxis,
-        "Euler X axis",
-        (void *)'X'},
-       {"y",
-        (getter)Euler_getAxis, (setter)Euler_setAxis,
-        "Euler Y axis",
-        (void *)'Y'},
-       {"z",
-        (getter)Euler_getAxis, (setter)Euler_setAxis,
-        "Euler Z axis",
-        (void *)'Z'},
-       {"wrapped",
-        (getter)Euler_getWrapped, (setter)NULL,
-        "True when this wraps blenders internal data",
-        NULL},
+       {"x", (getter)Euler_getAxis, (setter)Euler_setAxis, "Euler X axis in radians. **type** float", (void *)0},
+       {"y", (getter)Euler_getAxis, (setter)Euler_setAxis, "Euler Y axis in radians. **type** float", (void *)1},
+       {"z", (getter)Euler_getAxis, (setter)Euler_setAxis, "Euler Z axis in radians. **type** float", (void *)2},
+       {"order", (getter)Euler_getOrder, (setter)Euler_setOrder, "Euler rotation order. **type** string in ['XYZ', 'XZY', 'YXZ', 'YZX', 'ZXY', 'ZYX']", (void *)NULL},
+
+       {"is_wrapped", (getter)BaseMathObject_getWrapped, (setter)NULL, BaseMathObject_Wrapped_doc, NULL},
+       {"_owner", (getter)BaseMathObject_getOwner, (setter)NULL, BaseMathObject_Owner_doc, NULL},
        {NULL,NULL,NULL,NULL,NULL}  /* Sentinel */
 };
 
+
+//-----------------------METHOD DEFINITIONS ----------------------
+static struct PyMethodDef Euler_methods[] = {
+       {"zero", (PyCFunction) Euler_Zero, METH_NOARGS, Euler_Zero_doc},
+       {"unique", (PyCFunction) Euler_Unique, METH_NOARGS, Euler_Unique_doc},
+       {"to_matrix", (PyCFunction) Euler_ToMatrix, METH_NOARGS, Euler_ToMatrix_doc},
+       {"to_quat", (PyCFunction) Euler_ToQuat, METH_NOARGS, Euler_ToQuat_doc},
+       {"rotate", (PyCFunction) Euler_Rotate, METH_VARARGS, NULL},
+       {"make_compatible", (PyCFunction) Euler_MakeCompatible, METH_O, Euler_MakeCompatible_doc},
+       {"__copy__", (PyCFunction) Euler_copy, METH_VARARGS, Euler_copy_doc},
+       {"copy", (PyCFunction) Euler_copy, METH_VARARGS, Euler_copy_doc},
+       {NULL, NULL, 0, NULL}
+};
+
 //------------------PY_OBECT DEFINITION--------------------------
+static char euler_doc[] =
+"This object gives access to Eulers in Blender.";
+
 PyTypeObject euler_Type = {
-#if (PY_VERSION_HEX >= 0x02060000)
        PyVarObject_HEAD_INIT(NULL, 0)
-#else
-       /* python 2.5 and below */
-       PyObject_HEAD_INIT( NULL )  /* required py macro */
-       0,                          /* ob_size */
-#endif
        "euler",                                                //tp_name
        sizeof(EulerObject),                    //tp_basicsize
        0,                                                              //tp_itemsize
-       (destructor)Euler_dealloc,              //tp_dealloc
+       (destructor)BaseMathObject_dealloc,             //tp_dealloc
        0,                                                              //tp_print
        0,                                                              //tp_getattr
        0,                                                              //tp_setattr
@@ -553,8 +583,8 @@ PyTypeObject euler_Type = {
        0,                                                              //tp_getattro
        0,                                                              //tp_setattro
        0,                                                              //tp_as_buffer
-       Py_TPFLAGS_DEFAULT,                             //tp_flags
-       EulerObject_doc,                                //tp_doc
+       Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, //tp_flags
+       euler_doc, //tp_doc
        0,                                                              //tp_traverse
        0,                                                              //tp_clear
        (richcmpfunc)Euler_richcmpr,    //tp_richcompare
@@ -587,34 +617,48 @@ PyTypeObject euler_Type = {
  (i.e. it was allocated elsewhere by MEM_mallocN())
   pass Py_NEW - if vector is not a WRAPPER and managed by PYTHON
  (i.e. it must be created here with PyMEM_malloc())*/
-PyObject *newEulerObject(float *eul, int type)
+PyObject *newEulerObject(float *eul, short order, int type, PyTypeObject *base_type)
 {
        EulerObject *self;
        int x;
 
-       self = PyObject_NEW(EulerObject, &euler_Type);
-       self->data.blend_data = NULL;
-       self->data.py_data = NULL;
+       if(base_type)   self = (EulerObject *)base_type->tp_alloc(base_type, 0);
+       else                    self = PyObject_NEW(EulerObject, &euler_Type);
+
+       /* init callbacks as NULL */
+       self->cb_user= NULL;
+       self->cb_type= self->cb_subtype= 0;
 
        if(type == Py_WRAP){
-               self->data.blend_data = eul;
-               self->eul = self->data.blend_data;
+               self->eul = eul;
                self->wrapped = Py_WRAP;
        }else if (type == Py_NEW){
-               self->data.py_data = PyMem_Malloc(3 * sizeof(float));
-               self->eul = self->data.py_data;
+               self->eul = PyMem_Malloc(3 * sizeof(float));
                if(!eul) { //new empty
                        for(x = 0; x < 3; x++) {
                                self->eul[x] = 0.0f;
                        }
                }else{
-                       for(x = 0; x < 3; x++){
-                               self->eul[x] = eul[x];
-                       }
+                       VECCOPY(self->eul, eul);
                }
                self->wrapped = Py_NEW;
        }else{ //bad type
                return NULL;
        }
+
+       self->order= order;
+       return (PyObject *)self;
+}
+
+PyObject *newEulerObject_cb(PyObject *cb_user, short order, int cb_type, int cb_subtype)
+{
+       EulerObject *self= (EulerObject *)newEulerObject(NULL, order, Py_NEW, NULL);
+       if(self) {
+               Py_INCREF(cb_user);
+               self->cb_user=                  cb_user;
+               self->cb_type=                  (unsigned char)cb_type;
+               self->cb_subtype=               (unsigned char)cb_subtype;
+       }
+
        return (PyObject *)self;
 }