fix [#28850] With "Auto-keyframe" on, the "Selection to Cursor" option doesn't create...
authorCampbell Barton <ideasman42@gmail.com>
Mon, 10 Oct 2011 12:56:21 +0000 (12:56 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 10 Oct 2011 12:56:21 +0000 (12:56 +0000)
source/blender/editors/animation/keyframing.c
source/blender/editors/armature/poseobject.c
source/blender/editors/include/ED_keyframing.h
source/blender/editors/object/object_transform.c
source/blender/editors/space_view3d/view3d_snap.c

index b52550832c38b282807cf96cf0e085e2ae17460c..fb34245d3385eef5f09e640152af9a1836872a37 100644 (file)
@@ -1748,3 +1748,56 @@ short id_frame_has_keyframe (ID *id, float frame, short filter)
 }
 
 /* ************************************************** */
+
+int ED_autokeyframe_object(bContext *C, Scene *scene, Object *ob, KeyingSet *ks)
+{
+       /* auto keyframing */
+       if (autokeyframe_cfra_can_key(scene, &ob->id)) {
+               ListBase dsources = {NULL, NULL};
+
+               /* now insert the keyframe(s) using the Keying Set
+                *      1) add datasource override for the Object
+                *      2) insert keyframes
+                *      3) free the extra info
+                */
+               ANIM_relative_keyingset_add_source(&dsources, &ob->id, NULL, NULL);
+               ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, (float)CFRA);
+               BLI_freelistN(&dsources);
+
+               return TRUE;
+       }
+       else {
+               return FALSE;
+       }
+}
+
+int ED_autokeyframe_pchan(bContext *C, Scene *scene, Object *ob, bPoseChannel *pchan, KeyingSet *ks)
+{
+       if (autokeyframe_cfra_can_key(scene, &ob->id)) {
+               ListBase dsources = {NULL, NULL};
+
+               /* now insert the keyframe(s) using the Keying Set
+                *      1) add datasource override for the PoseChannel
+                *      2) insert keyframes
+                *      3) free the extra info
+                */
+               ANIM_relative_keyingset_add_source(&dsources, &ob->id, &RNA_PoseBone, pchan);
+               ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, (float)CFRA);
+               BLI_freelistN(&dsources);
+
+               /* clear any unkeyed tags */
+               if (pchan->bone) {
+                       pchan->bone->flag &= ~BONE_UNKEYED;
+               }
+
+               return TRUE;
+       }
+       else {
+               /* add unkeyed tags */
+               if (pchan->bone) {
+                       pchan->bone->flag |= BONE_UNKEYED;
+               }
+
+               return FALSE;
+       }
+}
index 43122ea08d33bfef72c356c3f60c34df43d934c6..61935aa72ca64d4c09c20c5e27e390263c9d2dc2 100644 (file)
@@ -1149,7 +1149,10 @@ static int pose_paste_exec (bContext *C, wmOperator *op)
        bPoseChannel *chan;
        int flip= RNA_boolean_get(op->ptr, "flipped");
        int selOnly= RNA_boolean_get(op->ptr, "selected_mask");
-       
+
+       /* get KeyingSet to use */
+       KeyingSet *ks = ANIM_get_keyingset_for_autokeying(scene, "LocRotScale");
+
        /* sanity checks */
        if ELEM(NULL, ob, ob->pose)
                return OPERATOR_CANCELLED;
@@ -1166,7 +1169,7 @@ static int pose_paste_exec (bContext *C, wmOperator *op)
                if (CTX_DATA_COUNT(C, selected_pose_bones) == 0)
                        selOnly = 0;
        }
-       
+
        /* Safely merge all of the channels in the buffer pose into any existing pose */
        for (chan= g_posebuf->chanbase.first; chan; chan=chan->next) {
                if (chan->flag & POSE_KEY) {
@@ -1175,30 +1178,7 @@ static int pose_paste_exec (bContext *C, wmOperator *op)
                        
                        if (pchan) {
                                /* keyframing tagging for successful paste */
-                               if (autokeyframe_cfra_can_key(scene, &ob->id)) {
-                                       ListBase dsources = {NULL, NULL};
-                                       
-                                       /* 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
-                                        *      2) insert keyframes
-                                        *      3) free the extra info 
-                                        */
-                                       ANIM_relative_keyingset_add_source(&dsources, &ob->id, &RNA_PoseBone, pchan); 
-                                       ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, (float)CFRA);
-                                       BLI_freelistN(&dsources);
-                                       
-                                       /* clear any unkeyed tags */
-                                       if (chan->bone)
-                                               chan->bone->flag &= ~BONE_UNKEYED;
-                               }
-                               else {
-                                       /* add unkeyed tags */
-                                       if (chan->bone)
-                                               chan->bone->flag |= BONE_UNKEYED;
-                               }
+                               ED_autokeyframe_pchan(C, scene, ob, pchan, ks);
                        }
                }
        }
@@ -2194,29 +2174,8 @@ static int pose_flip_quats_exec (bContext *C, wmOperator *UNUSED(op))
                if (pchan->rotmode == ROT_MODE_QUAT) {
                        /* quaternions have 720 degree range */
                        negate_v4(pchan->quat);
-                       
-                       /* tagging */
-                       if (autokeyframe_cfra_can_key(scene, &ob->id)) {
-                               ListBase dsources = {NULL, NULL};
-                               
-                               /* now insert the keyframe(s) using the Keying Set
-                                *      1) add datasource override for the PoseChannel
-                                *      2) insert keyframes
-                                *      3) free the extra info 
-                                */
-                               ANIM_relative_keyingset_add_source(&dsources, &ob->id, &RNA_PoseBone, pchan); 
-                               ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, (float)CFRA);
-                               BLI_freelistN(&dsources);
-                               
-                               /* clear any unkeyed tags */
-                               if (pchan->bone)
-                                       pchan->bone->flag &= ~BONE_UNKEYED;
-                       }
-                       else {
-                               /* add unkeyed tags */
-                               if (pchan->bone)
-                                       pchan->bone->flag |= BONE_UNKEYED;
-                       }
+
+                       ED_autokeyframe_pchan(C, scene, ob, pchan, ks);
                }
        }
        CTX_DATA_END;
index cda3c4f3e71e508a6c8c1efe5479f62499562b75..8dd543d8f63a7126d49935a6e85074d064b5dd9b 100644 (file)
@@ -313,6 +313,11 @@ typedef enum eAnimFilterFlags {
        ANIMFILTER_KEYS_NOSKEY          = (1<<10),              /* don't include shape keys (for geometry) */
 } eAnimFilterFlags;
 
+/* utility funcs for auto keyframe */
+int ED_autokeyframe_object(struct bContext *C, struct Scene *scene, struct Object *ob, struct KeyingSet *ks);
+int ED_autokeyframe_pchan(struct bContext *C, struct Scene *scene, struct Object *ob, struct bPoseChannel *pchan, struct KeyingSet *ks);
+
+
 #ifdef __cplusplus
 }
 #endif
index 4c29490b0f08521a43c153210813bc0d6be7eec9..4ca7d27250365bd6e12482e5f1c3e42dc6d5dd25 100644 (file)
@@ -230,21 +230,9 @@ static int object_clear_transform_generic_exec(bContext *C, wmOperator *op,
                if (!(ob->mode & OB_MODE_WEIGHT_PAINT)) {
                        /* run provided clearing function */
                        clear_func(ob);
-                       
-                       /* auto keyframing */
-                       if (autokeyframe_cfra_can_key(scene, &ob->id)) {
-                               ListBase dsources = {NULL, NULL};
-                               
-                               /* now insert the keyframe(s) using the Keying Set
-                                *      1) add datasource override for the Object
-                                *      2) insert keyframes
-                                *      3) free the extra info 
-                                */
-                               ANIM_relative_keyingset_add_source(&dsources, &ob->id, NULL, NULL); 
-                               ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, (float)CFRA);
-                               BLI_freelistN(&dsources);
-                       }
-                       
+
+                       ED_autokeyframe_object(C, scene, ob, ks);
+
                        /* tag for updates */
                        DAG_id_tag_update(&ob->id, OB_RECALC_OB);
                }
index 1ed65f7875f96eb5bbb1ae48dec03e3664bf0f35..fa3007d2fb7e39eb87b831a6bf771e8b80f33401 100644 (file)
@@ -65,6 +65,7 @@
 
 #include "ED_armature.h"
 #include "ED_mesh.h"
+#include "ED_keyframing.h"
 #include "ED_screen.h"
 #include "ED_curve.h" /* for curve_editnurbs */
 
@@ -494,6 +495,7 @@ static int snap_sel_to_grid(bContext *C, wmOperator *UNUSED(op))
        
        }
        else {
+               struct KeyingSet *ks = ANIM_get_keyingset_for_autokeying(scene, "Location");
 
                CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
                        if(ob->mode & OB_MODE_POSE) {
@@ -522,6 +524,9 @@ static int snap_sel_to_grid(bContext *C, wmOperator *UNUSED(op))
                                                                        pchan->loc[0]= vecN[1];
                                                                if ((pchan->protectflag & OB_LOCK_LOCZ)==0)     
                                                                        pchan->loc[0]= vecN[2];
+
+                                                               /* auto-keyframing */
+                                                               ED_autokeyframe_pchan(C, scene, ob, pchan, ks);
                                                        }
                                                        /* if the bone has a parent and is connected to the parent, 
                                                         * don't do anything - will break chain unless we do auto-ik. 
@@ -531,8 +536,6 @@ static int snap_sel_to_grid(bContext *C, wmOperator *UNUSED(op))
                                }
                                ob->pose->flag |= (POSE_LOCKED|POSE_DO_UNLOCK);
                                
-                               /* auto-keyframing */
-// XXX                         autokeyframe_pose_cb_func(ob, TFM_TRANSLATION, 0);
                                DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
                        }
                        else {
@@ -556,7 +559,7 @@ static int snap_sel_to_grid(bContext *C, wmOperator *UNUSED(op))
                                        ob->loc[2]+= vec[2];
                                
                                /* auto-keyframing */
-// XXX                         autokeyframe_ob_cb_func(ob, TFM_TRANSLATION);
+                               ED_autokeyframe_object(C, scene, ob, ks);
                        }
                }
                CTX_DATA_END;
@@ -622,6 +625,8 @@ static int snap_sel_to_curs(bContext *C, wmOperator *UNUSED(op))
                
        }
        else {
+               struct KeyingSet *ks = ANIM_get_keyingset_for_autokeying(scene, "Location");
+
                CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
                        if(ob->mode & OB_MODE_POSE) {
                                bPoseChannel *pchan;
@@ -648,6 +653,9 @@ static int snap_sel_to_curs(bContext *C, wmOperator *UNUSED(op))
                                                                        pchan->loc[1]= curspn[1];
                                                                if ((pchan->protectflag & OB_LOCK_LOCZ)==0)     
                                                                        pchan->loc[2]= curspn[2];
+
+                                                               /* auto-keyframing */
+                                                               ED_autokeyframe_pchan(C, scene, ob, pchan, ks);
                                                        }
                                                        /* if the bone has a parent and is connected to the parent, 
                                                         * don't do anything - will break chain unless we do auto-ik. 
@@ -657,8 +665,6 @@ static int snap_sel_to_curs(bContext *C, wmOperator *UNUSED(op))
                                }
                                ob->pose->flag |= (POSE_LOCKED|POSE_DO_UNLOCK);
                                
-                               /* auto-keyframing */
-// XXX                         autokeyframe_pose_cb_func(ob, TFM_TRANSLATION, 0);
                                DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
                        }
                        else {
@@ -680,9 +686,9 @@ static int snap_sel_to_curs(bContext *C, wmOperator *UNUSED(op))
                                        ob->loc[1]+= vec[1];
                                if ((ob->protectflag & OB_LOCK_LOCZ)==0)
                                        ob->loc[2]+= vec[2];
-                               
+
                                /* auto-keyframing */
-// XXX                         autokeyframe_ob_cb_func(ob, TFM_TRANSLATION);
+                               ED_autokeyframe_object(C, scene, ob, ks);
                        }
                }
                CTX_DATA_END;