Cleanup of Auto-Keyframing code:
authorJoshua Leung <aligorith@gmail.com>
Thu, 30 Sep 2010 11:56:39 +0000 (11:56 +0000)
committerJoshua Leung <aligorith@gmail.com>
Thu, 30 Sep 2010 11:56:39 +0000 (11:56 +0000)
Moved duplicated code out to a special new function so that this doesn't need to be copied all over for each transform op that needs this.

source/blender/editors/animation/anim_channels_edit.c
source/blender/editors/animation/keyingsets.c
source/blender/editors/armature/editarmature.c
source/blender/editors/armature/poselib.c
source/blender/editors/armature/poseobject.c
source/blender/editors/include/ED_keyframing.h
source/blender/editors/object/object_transform.c

index e229de4..a698176 100644 (file)
@@ -155,6 +155,7 @@ void ANIM_set_active_channel (bAnimContext *ac, void *data, short datatype, int
                        case ANIMTYPE_DSMESH:
                        {
                                /* need to verify that this data is valid for now */
+                               // XXX: ale may be null!
                                if (ale->adt)
                                        ale->adt->flag |= ADT_UI_ACTIVE;
                        }
@@ -462,7 +463,7 @@ void ANIM_flush_setting_anim_channels (bAnimContext *ac, ListBase *anim_data, bA
                                break;
                        
                        /* store this level as the 'old' level now */
-                       prevLevel= level;
+                       prevLevel= level; // XXX: prevLevel is unused
                }
        }
 }
@@ -1899,7 +1900,6 @@ static int animchannels_mouseclick_invoke(bContext *C, wmOperator *op, wmEvent *
                return OPERATOR_CANCELLED;
                
        /* get useful pointers from animation context data */
-       scene= ac.scene;
        ar= ac.ar;
        v2d= &ar->v2d;
        
index d80ccf2..77e0c84 100644 (file)
@@ -676,6 +676,21 @@ int ANIM_scene_get_keyingset_index (Scene *scene, KeyingSet *ks)
                return 0;
 }
 
+/* Get Keying Set to use for Auto-Keyframing some transforms */
+KeyingSet *ANIM_get_keyingset_for_autokeying(Scene *scene, const char *tranformKSName)
+{
+       /* get KeyingSet to use 
+        *      - use the active KeyingSet if defined (and user wants to use it for all autokeying), 
+        *        or otherwise key transforms only
+        */
+       if (IS_AUTOKEY_FLAG(ONLYKEYINGSET) && (scene->active_keyingset))
+               return ANIM_scene_get_active_keyingset(scene);
+       else if (IS_AUTOKEY_FLAG(INSERTAVAIL))
+               return ANIM_builtin_keyingset_get_named(NULL, "Available");
+       else 
+               return ANIM_builtin_keyingset_get_named(NULL, tranformKSName);
+}
+
 /* Menu of All Keying Sets ----------------------------- */
 
 /* Create (and show) a menu containing all the Keying Sets which can be used in the current context */
index f5396b7..ead5d44 100644 (file)
@@ -4948,18 +4948,8 @@ static int pose_clear_scale_exec(bContext *C, wmOperator *op)
        
        /* perform autokeying on the bones if needed */
        if (autokey) {
-               KeyingSet *ks;
-               
-               /* get KeyingSet to use 
-                *      - use the active KeyingSet if defined (and user wants to use it for all autokeying), 
-                *        or otherwise key transforms only
-                */
-               if (IS_AUTOKEY_FLAG(ONLYKEYINGSET) && (scene->active_keyingset))
-                       ks = ANIM_scene_get_active_keyingset(scene);
-               else if (IS_AUTOKEY_FLAG(INSERTAVAIL))
-                       ks = ANIM_builtin_keyingset_get_named(NULL, "Available");
-               else 
-                       ks = ANIM_builtin_keyingset_get_named(NULL, "Scaling");
+               /* get KeyingSet to use */
+               KeyingSet *ks = ANIM_get_keyingset_for_autokeying(scene, "Scaling");
                
                /* insert keyframes */
                ANIM_apply_keyingset(C, NULL, NULL, ks, MODIFYKEY_MODE_INSERT, (float)CFRA);
@@ -5027,18 +5017,8 @@ static int pose_clear_loc_exec(bContext *C, wmOperator *op)
        
        /* perform autokeying on the bones if needed */
        if (autokey) {
-               KeyingSet *ks;
-               
-               /* get KeyingSet to use 
-                *      - use the active KeyingSet if defined (and user wants to use it for all autokeying), 
-                *        or otherwise key transforms only
-                */
-               if (IS_AUTOKEY_FLAG(ONLYKEYINGSET) && (scene->active_keyingset))
-                       ks = ANIM_scene_get_active_keyingset(scene);
-               else if (IS_AUTOKEY_FLAG(INSERTAVAIL))
-                       ks = ANIM_builtin_keyingset_get_named(NULL, "Available");
-               else 
-                       ks = ANIM_builtin_keyingset_get_named(NULL, "Location");
+               /* get KeyingSet to use */
+               KeyingSet *ks = ANIM_get_keyingset_for_autokeying(scene, "Location");
                
                /* insert keyframes */
                ANIM_apply_keyingset(C, NULL, NULL, ks, MODIFYKEY_MODE_INSERT, (float)CFRA);
@@ -5190,18 +5170,8 @@ static int pose_clear_rot_exec(bContext *C, wmOperator *op)
        
        /* perform autokeying on the bones if needed */
        if (autokey) {
-               KeyingSet *ks;
-               
-               /* get KeyingSet to use 
-                *      - use the active KeyingSet if defined (and user wants to use it for all autokeying), 
-                *        or otherwise key transforms only
-                */
-               if (IS_AUTOKEY_FLAG(ONLYKEYINGSET) && (scene->active_keyingset))
-                       ks = ANIM_scene_get_active_keyingset(scene);
-               else if (IS_AUTOKEY_FLAG(INSERTAVAIL))
-                       ks = ANIM_builtin_keyingset_get_named(NULL, "Available");
-               else 
-                       ks = ANIM_builtin_keyingset_get_named(NULL, "Rotation");
+               /* get KeyingSet to use */
+               KeyingSet *ks = ANIM_get_keyingset_for_autokeying(scene, "Rotation");
                
                /* insert keyframes */
                ANIM_apply_keyingset(C, NULL, NULL, ks, MODIFYKEY_MODE_INSERT, (float)CFRA);
index 5ead0d4..6083616 100644 (file)
@@ -773,21 +773,9 @@ static void poselib_keytag_pose (bContext *C, Scene *scene, tPoseLib_PreviewData
                        if (pchan) {
                                if (autokeyframe_cfra_can_key(scene, &pld->ob->id)) {
                                        ListBase dsources = {NULL, NULL};
-                                       KeyingSet *ks = NULL;
                                        
-                                       /* get KeyingSet to use 
-                                        *      - use the active KeyingSet if defined (and user wants to use it for all autokeying), 
-                                        *        or otherwise key transforms only
-                                        */
-                                       if (poselib_ks_locrotscale == NULL)
-                                               poselib_ks_locrotscale= ANIM_builtin_keyingset_get_named(NULL, "LocRotScale");
-                                        
-                                       if (IS_AUTOKEY_FLAG(ONLYKEYINGSET) && (scene->active_keyingset))
-                                               ks = ANIM_scene_get_active_keyingset(scene);
-                                       else if (IS_AUTOKEY_FLAG(INSERTAVAIL))
-                                               ks = ANIM_builtin_keyingset_get_named(NULL, "Available");
-                                       else 
-                                               ks = ANIM_builtin_keyingset_get_named(NULL, "LocRotScale");
+                                       /* get KeyingSet to use */
+                                       KeyingSet *ks = ANIM_get_keyingset_for_autokeying(scene, "LocRotScale");
                                        
                                        /* now insert the keyframe(s) using the Keying Set
                                         *      1) add datasource override for the PoseChannel
index e2cf587..b94b3e6 100644 (file)
@@ -1012,18 +1012,9 @@ static int pose_paste_exec (bContext *C, wmOperator *op)
                                /* keyframing tagging */
                                if (autokeyframe_cfra_can_key(scene, &ob->id)) {
                                        ListBase dsources = {NULL, NULL};
-                                       KeyingSet *ks = NULL;
                                        
-                                       /* get KeyingSet to use 
-                                        *      - use the active KeyingSet if defined (and user wants to use it for all autokeying), 
-                                        *        or otherwise key transforms only
-                                        */
-                                       if (IS_AUTOKEY_FLAG(ONLYKEYINGSET) && (scene->active_keyingset))
-                                               ks = ANIM_scene_get_active_keyingset(scene);
-                                       else if (IS_AUTOKEY_FLAG(INSERTAVAIL))
-                                               ks = ANIM_builtin_keyingset_get_named(NULL, "Available");
-                                       else 
-                                               ks = ANIM_builtin_keyingset_get_named(NULL, "LocRotScale");
+                                       /* get KeyingSet to use */
+                                       KeyingSet *ks = ANIM_get_keyingset_for_autokeying(scene, "LocRotScale");
                                        
                                        /* now insert the keyframe(s) using the Keying Set
                                         *      1) add datasource override for the PoseChannel
index fc5e3a4..8718d39 100644 (file)
@@ -193,6 +193,9 @@ struct KeyingSet *ANIM_scene_get_active_keyingset(struct Scene *scene);
 /* Get the index of the Keying Set provided, for the given Scene */
 int ANIM_scene_get_keyingset_index(struct Scene *scene, struct KeyingSet *ks);
 
+/* Get Keying Set to use for Auto-Keyframing some transforms */
+struct KeyingSet *ANIM_get_keyingset_for_autokeying(struct Scene *scene, const char *tranformKSName);
+
 /* Create (and show) a menu containing all the Keying Sets which can be used in the current context */
 void ANIM_keying_sets_menu_setup(struct bContext *C, char title[], char op_name[]);
 
index aa19ae2..d464484 100644 (file)
@@ -68,18 +68,9 @@ static int object_location_clear_exec(bContext *C, wmOperator *op)
 {
        Main *bmain = CTX_data_main(C);
        Scene *scene = CTX_data_scene(C);
-       KeyingSet *ks;
        
-       /* get KeyingSet to use 
-        *      - use the active KeyingSet if defined (and user wants to use it for all autokeying), 
-        *        or otherwise key transforms only
-        */
-       if (IS_AUTOKEY_FLAG(ONLYKEYINGSET) && (scene->active_keyingset))
-               ks = ANIM_scene_get_active_keyingset(scene);
-       else if (IS_AUTOKEY_FLAG(INSERTAVAIL))
-               ks = ANIM_builtin_keyingset_get_named(NULL, "Available");
-       else 
-               ks = ANIM_builtin_keyingset_get_named(NULL, "Location");
+       /* get KeyingSet to use */
+       KeyingSet *ks = ANIM_get_keyingset_for_autokeying(scene, "Location");
        
        /* clear location of selected objects if not in weight-paint mode */
        CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
@@ -138,18 +129,9 @@ static int object_rotation_clear_exec(bContext *C, wmOperator *op)
 {
        Main *bmain= CTX_data_main(C);
        Scene *scene= CTX_data_scene(C);
-       KeyingSet *ks;
        
-       /* get KeyingSet to use 
-        *      - use the active KeyingSet if defined (and user wants to use it for all autokeying), 
-        *        or otherwise key transforms only
-        */
-       if (IS_AUTOKEY_FLAG(ONLYKEYINGSET) && (scene->active_keyingset))
-               ks = ANIM_scene_get_active_keyingset(scene);
-       else if (IS_AUTOKEY_FLAG(INSERTAVAIL))
-               ks = ANIM_builtin_keyingset_get_named(NULL, "Available");
-       else 
-               ks = ANIM_builtin_keyingset_get_named(NULL, "Rotation");
+       /* get KeyingSet to use */
+       KeyingSet *ks = ANIM_get_keyingset_for_autokeying(scene, "Rotation");
        
        /* clear rotation of selected objects if not in weight-paint mode */
        CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
@@ -292,18 +274,9 @@ static int object_scale_clear_exec(bContext *C, wmOperator *op)
 {
        Main *bmain= CTX_data_main(C);
        Scene *scene= CTX_data_scene(C);
-       KeyingSet *ks;
        
-       /* get KeyingSet to use 
-        *      - use the active KeyingSet if defined (and user wants to use it for all autokeying), 
-        *        or otherwise key transforms only
-        */
-       if (IS_AUTOKEY_FLAG(ONLYKEYINGSET) && (scene->active_keyingset))
-               ks = ANIM_scene_get_active_keyingset(scene);
-       else if (IS_AUTOKEY_FLAG(INSERTAVAIL))
-               ks = ANIM_builtin_keyingset_get_named(NULL, "Available");
-       else 
-               ks = ANIM_builtin_keyingset_get_named(NULL, "Scaling");
+       /* get KeyingSet to use */
+       KeyingSet *ks = ANIM_get_keyingset_for_autokeying(scene, "Scaling");
        
        /* clear scales of selected objects if not in weight-paint mode */
        CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {