Undo revision 23130 which was a merge with 2.5, a messy one because I did something...
[blender.git] / source / blender / editors / space_action / action_edit.c
index 89633d0..d4709e9 100644 (file)
@@ -397,7 +397,7 @@ static void insert_action_keys(bAnimContext *ac, short mode)
        /* init keyframing flag */
        if (IS_AUTOKEY_FLAG(AUTOMATKEY)) flag |= INSERTKEY_MATRIX;
        if (IS_AUTOKEY_FLAG(INSERTNEEDED)) flag |= INSERTKEY_NEEDED;
-       if (IS_AUTOKEY_MODE(scene, EDITKEYS)) flag |= INSERTKEY_REPLACE;
+       // if (IS_AUTOKEY_MODE(EDITKEYS)) flag |= INSERTKEY_REPLACE;
        
        /* insert keyframes */
        for (ale= anim_data.first; ale; ale= ale->next) {
@@ -679,6 +679,11 @@ void ACT_OT_clean (wmOperatorType *ot)
 
 /* ******************** Sample Keyframes Operator *********************** */
 
+/* little cache for values... */
+typedef struct tempFrameValCache {
+       float frame, val;
+} tempFrameValCache;
+
 /* Evaluates the curves between each selected keyframe on each frame, and keys the value  */
 static void sample_action_keys (bAnimContext *ac)
 {      
@@ -691,8 +696,64 @@ static void sample_action_keys (bAnimContext *ac)
        ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
        
        /* loop through filtered data and add keys between selected keyframes on every frame  */
-       for (ale= anim_data.first; ale; ale= ale->next)
-               sample_fcurve((FCurve *)ale->key_data);
+       for (ale= anim_data.first; ale; ale= ale->next) {
+               FCurve *fcu= (FCurve *)ale->key_data;
+               BezTriple *bezt, *start=NULL, *end=NULL;
+               tempFrameValCache *value_cache, *fp;
+               int sfra, range;
+               int i, n;
+               
+               /* find selected keyframes... once pair has been found, add keyframes  */
+               for (i=0, bezt=fcu->bezt; i < fcu->totvert; i++, bezt++) {
+                       /* check if selected, and which end this is */
+                       if (BEZSELECTED(bezt)) {
+                               if (start) {
+                                       /* set end */
+                                       end= bezt;
+                                       
+                                       /* cache values then add keyframes using these values, as adding
+                                        * keyframes while sampling will affect the outcome...
+                                        */
+                                       range= (int)( ceil(end->vec[1][0] - start->vec[1][0]) );
+                                       sfra= (int)( floor(start->vec[1][0]) );
+                                       
+                                       if (range) {
+                                               value_cache= MEM_callocN(sizeof(tempFrameValCache)*range, "IcuFrameValCache");
+                                               
+                                               /*      sample values   */
+                                               for (n=0, fp=value_cache; n<range && fp; n++, fp++) {
+                                                       fp->frame= (float)(sfra + n);
+                                                       fp->val= evaluate_fcurve(fcu, fp->frame);
+                                               }
+                                               
+                                               /*      add keyframes with these        */
+                                               for (n=0, fp=value_cache; n<range && fp; n++, fp++) {
+                                                       insert_vert_fcurve(fcu, fp->frame, fp->val, 1);
+                                               }
+                                               
+                                               /* free temp cache */
+                                               MEM_freeN(value_cache);
+                                               
+                                               /* as we added keyframes, we need to compensate so that bezt is at the right place */
+                                               bezt = fcu->bezt + i + range - 1;
+                                               i += (range - 1);
+                                       }
+                                       
+                                       /* bezt was selected, so it now marks the start of a whole new chain to search */
+                                       start= bezt;
+                                       end= NULL;
+                               }
+                               else {
+                                       /* just set start keyframe */
+                                       start= bezt;
+                                       end= NULL;
+                               }
+                       }
+               }
+               
+               /* recalculate channel's handles? */
+               calchandles_fcurve(fcu);
+       }
        
        /* admin and redraws */
        BLI_freelistN(&anim_data);
@@ -977,77 +1038,6 @@ void ACT_OT_handle_type (wmOperatorType *ot)
        RNA_def_enum(ot->srna, "type", beztriple_handle_type_items, 0, "Type", "");
 }
 
-/* ******************** Set Keyframe-Type Operator *********************** */
-
-/* this function is responsible for setting interpolation mode for keyframes */
-static void setkeytype_action_keys(bAnimContext *ac, short mode) 
-{
-       ListBase anim_data = {NULL, NULL};
-       bAnimListElem *ale;
-       int filter;
-       BeztEditFunc set_cb= ANIM_editkeyframes_keytype(mode);
-       
-       /* filter data */
-       filter= (ANIMFILTER_VISIBLE | ANIMFILTER_FOREDIT | ANIMFILTER_CURVESONLY);
-       ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
-       
-       /* loop through setting BezTriple interpolation
-        * Note: we do not supply BeztEditData to the looper yet. Currently that's not necessary here...
-        */
-       for (ale= anim_data.first; ale; ale= ale->next)
-               ANIM_fcurve_keys_bezier_loop(NULL, ale->key_data, NULL, set_cb, NULL);
-       
-       /* cleanup */
-       BLI_freelistN(&anim_data);
-}
-
-/* ------------------- */
-
-static int actkeys_keytype_exec(bContext *C, wmOperator *op)
-{
-       bAnimContext ac;
-       short mode;
-       
-       /* get editor data */
-       if (ANIM_animdata_get_context(C, &ac) == 0)
-               return OPERATOR_CANCELLED;
-       if (ac.datatype == ANIMCONT_GPENCIL) 
-               return OPERATOR_PASS_THROUGH;
-               
-       /* get handle setting mode */
-       mode= RNA_enum_get(op->ptr, "type");
-       
-       /* set handle type */
-       setkeytype_action_keys(&ac, mode);
-       
-       /* validate keyframes after editing */
-       ANIM_editkeyframes_refresh(&ac);
-       
-       /* set notifier that keyframe properties have changed */
-       WM_event_add_notifier(C, NC_ANIMATION|ND_KEYFRAME_PROP, NULL);
-       
-       return OPERATOR_FINISHED;
-}
-void ACT_OT_keyframe_type (wmOperatorType *ot)
-{
-       /* identifiers */
-       ot->name= "Set Keyframe Type";
-       ot->idname= "ACT_OT_keyframe_type";
-       ot->description= "Set type of keyframe for the seleced keyframes.";
-       
-       /* api callbacks */
-       ot->invoke= WM_menu_invoke;
-       ot->exec= actkeys_keytype_exec;
-       ot->poll= ED_operator_action_active;
-       
-       /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-       
-       /* id-props */
-       RNA_def_enum(ot->srna, "type", beztriple_keyframe_type_items, 0, "Type", "");
-}
-
 /* ************************************************************************** */
 /* TRANSFORM STUFF */