fixes for euler order setting when the rotation mode is not euler.
authorCampbell Barton <ideasman42@gmail.com>
Tue, 27 Apr 2010 07:50:31 +0000 (07:50 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 27 Apr 2010 07:50:31 +0000 (07:50 +0000)
source/blender/python/intern/bpy_rna.c

index 77657f35a1586b30fd15f448caa44b460e5cd4f2..ffe3b083d3ec8d7f7c395eb434d4266f48a2d5b5 100644 (file)
@@ -56,8 +56,8 @@
 
 static PyObject *pyrna_prop_array_subscript_slice(BPy_PropertyRNA *self, PointerRNA *ptr, PropertyRNA *prop, int start, int stop, int length);
 static Py_ssize_t pyrna_prop_array_length(BPy_PropertyRNA *self);
-static Py_ssize_t pyrna_prop_collection_length( BPy_PropertyRNA *self );
-
+static Py_ssize_t pyrna_prop_collection_length(BPy_PropertyRNA *self);
+static short pyrna_rotation_euler_order_get(PointerRNA *ptr, PropertyRNA **prop_eul_order, short order_fallback);
 
 /* bpyrna vector/euler/quat callbacks */
 static int mathutils_rna_array_cb_index= -1; /* index for our callbacks */
@@ -84,10 +84,9 @@ static int mathutils_rna_vector_get(BaseMathObject *bmo, int subtype, float *vec
        
        /* Euler order exception */
        if(subtype==MATHUTILS_CB_SUBTYPE_EUL) {
-               PropertyRNA *prop_eul_order= RNA_struct_find_property(&self->ptr, "rotation_mode");
-               if(prop_eul_order) {
-                       ((EulerObject *)bmo)->order= RNA_property_enum_get(&self->ptr, prop_eul_order);
-               }               
+               EulerObject *eul= (EulerObject *)bmo;
+               PropertyRNA *prop_eul_order= NULL;
+               eul->order= pyrna_rotation_euler_order_get(&self->ptr, &prop_eul_order, eul->order);
        }
        
        return 1;
@@ -110,17 +109,18 @@ static int mathutils_rna_vector_set(BaseMathObject *bmo, int subtype, float *vec
        }
 
        RNA_property_float_set_array(&self->ptr, self->prop, vec_to);
-       
+       RNA_property_update(BPy_GetContext(), &self->ptr, self->prop);
+
        /* Euler order exception */
        if(subtype==MATHUTILS_CB_SUBTYPE_EUL) {
-               PropertyRNA *prop_eul_order= RNA_struct_find_property(&self->ptr, "rotation_mode");
-               if(prop_eul_order) {
-                       RNA_property_enum_set(&self->ptr, prop_eul_order, ((EulerObject *)bmo)->order);
+               EulerObject *eul= (EulerObject *)bmo;
+               PropertyRNA *prop_eul_order= NULL;
+               short order= pyrna_rotation_euler_order_get(&self->ptr, &prop_eul_order, eul->order);
+               if(order != eul->order) {
+                       RNA_property_enum_set(&self->ptr, prop_eul_order, eul->order);
                        RNA_property_update(BPy_GetContext(), &self->ptr, prop_eul_order);
-               }               
+               }
        }
-
-       RNA_property_update(BPy_GetContext(), &self->ptr, self->prop);
        return 1;
 }
 
@@ -271,22 +271,17 @@ PyObject *pyrna_math_object_from_array(PointerRNA *ptr, PropertyRNA *prop)
                case PROP_EULER:
                case PROP_QUATERNION:
                        if(len==3) { /* euler */
-                               /* attempt to get order */
-                               /* TODO, keep order in sync */
-                               short order= ROT_MODE_XYZ;
-                               PropertyRNA *prop_eul_order= RNA_struct_find_property(ptr, "rotation_mode");
-                               if(prop_eul_order) {
-                                       order = RNA_property_enum_get(ptr, prop_eul_order);
-                                       if (order < ROT_MODE_XYZ || order > ROT_MODE_ZYX) /* could be quat or axisangle */
-                                               order= ROT_MODE_XYZ;
-                               }
-
                                if(is_thick) {
+                                       /* attempt to get order, only needed for thixk types since wrapped with update via callbacks */
+                                       PropertyRNA *prop_eul_order= NULL;
+                                       short order= pyrna_rotation_euler_order_get(ptr, &prop_eul_order, ROT_MODE_XYZ);
+
                                        ret= newEulerObject(NULL, order, Py_NEW, NULL); // TODO, get order from RNA
                                        RNA_property_float_get_array(ptr, prop, ((EulerObject *)ret)->eul);
                                }
                                else {
-                                       PyObject *eul_cb= newEulerObject_cb(ret, order, mathutils_rna_array_cb_index, MATHUTILS_CB_SUBTYPE_EUL); // TODO, get order from RNA
+                                       /* order will be updated from callback on use */
+                                       PyObject *eul_cb= newEulerObject_cb(ret, ROT_MODE_XYZ, mathutils_rna_array_cb_index, MATHUTILS_CB_SUBTYPE_EUL); // TODO, get order from RNA
                                        Py_DECREF(ret); /* the euler owns now */
                                        ret= eul_cb; /* return the euler instead */
                                }
@@ -337,6 +332,21 @@ PyObject *pyrna_math_object_from_array(PointerRNA *ptr, PropertyRNA *prop)
 
 #endif
 
+static short pyrna_rotation_euler_order_get(PointerRNA *ptr, PropertyRNA **prop_eul_order, short order_fallback)
+{
+       /* attempt to get order */
+       if(*prop_eul_order==NULL)
+               *prop_eul_order= RNA_struct_find_property(ptr, "rotation_mode");
+
+       if(*prop_eul_order) {
+               short order= RNA_property_enum_get(ptr, *prop_eul_order);
+               if (order >= ROT_MODE_XYZ && order <= ROT_MODE_ZYX) /* could be quat or axisangle */
+                       return order;
+       }
+
+       return order_fallback;
+}
+
 static int pyrna_struct_compare( BPy_StructRNA * a, BPy_StructRNA * b )
 {
        return (a->ptr.data==b->ptr.data) ? 0 : -1;