4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21 * All rights reserved.
23 * The Original Code is: all of this file.
25 * Contributor(s): Joshua Leung
27 * ***** END GPL LICENSE BLOCK *****
30 /** \file blender/editors/space_action/action_edit.c
41 #include "BLI_blenlib.h"
43 #include "BLI_utildefines.h"
45 #include "DNA_anim_types.h"
46 #include "DNA_gpencil_types.h"
47 #include "DNA_object_types.h"
48 #include "DNA_scene_types.h"
50 #include "RNA_access.h"
51 #include "RNA_define.h"
52 #include "RNA_enum_types.h"
54 #include "BKE_action.h"
55 #include "BKE_fcurve.h"
57 #include "BKE_context.h"
58 #include "BKE_report.h"
60 #include "UI_view2d.h"
62 #include "ED_anim_api.h"
63 #include "ED_gpencil.h"
64 #include "ED_keyframing.h"
65 #include "ED_keyframes_edit.h"
66 #include "ED_screen.h"
67 #include "ED_transform.h"
68 #include "ED_markers.h"
73 #include "UI_interface.h"
75 #include "action_intern.h"
77 /* ************************************************************************** */
78 /* ACTION MANAGEMENT */
80 /* ******************** New Action Operator *********************** */
82 static int act_new_exec(bContext *C, wmOperator *UNUSED(op))
84 PointerRNA ptr, idptr;
88 uiIDContextProperty(C, &ptr, &prop);
91 bAction *action=NULL, *oldact=NULL;
94 /* create action - the way to do this depends on whether we've got an
95 * existing one there already, in which case we make a copy of it
96 * (which is useful for "versioning" actions within the same file)
98 oldptr = RNA_property_pointer_get(&ptr, prop);
99 oldact = (bAction *)oldptr.id.data;
101 if (oldact && GS(oldact->id.name)==ID_AC) {
102 /* make a copy of the existing action */
103 action= copy_action(oldact);
106 /* just make a new (empty) action */
107 action= add_empty_action("Action");
110 /* when creating new ID blocks, use is already 1 (fake user),
111 * but RNA pointer use also increases user, so this compensates it
115 RNA_id_pointer_create(&action->id, &idptr);
116 RNA_property_pointer_set(&ptr, prop, idptr);
117 RNA_property_update(C, &ptr, prop);
120 /* set notifier that keyframes have changed */
121 WM_event_add_notifier(C, NC_ANIMATION|ND_KEYFRAME|NA_EDITED, NULL);
123 return OPERATOR_FINISHED;
126 void ACTION_OT_new (wmOperatorType *ot)
129 ot->name= "New Action";
130 ot->idname= "ACTION_OT_new";
131 ot->description= "Create new action";
134 ot->exec= act_new_exec;
135 // NOTE: this is used in the NLA too...
136 //ot->poll= ED_operator_action_active;
139 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
142 /* ************************************************************************** */
143 /* POSE MARKERS STUFF */
145 /* *************************** Localise Markers ***************************** */
147 /* ensure that there is:
148 * 1) an active action editor
149 * 2) that the mode will have an active action available
150 * 3) that the set of markers being shown are the scene markers, not the list we're merging
151 * 4) that there are some selected markers
153 static int act_markers_make_local_poll(bContext *C)
155 SpaceAction *sact = CTX_wm_space_action(C);
162 if (ELEM(sact->mode, SACTCONT_ACTION, SACTCONT_SHAPEKEY) == 0)
164 if (sact->action == NULL)
168 if (sact->flag & SACTION_POSEMARKERS_SHOW)
172 return ED_markers_get_first_selected(ED_context_get_markers(C)) != NULL;
175 static int act_markers_make_local_exec (bContext *C, wmOperator *UNUSED(op))
177 ListBase *markers = ED_context_get_markers(C);
179 SpaceAction *sact = CTX_wm_space_action(C);
180 bAction *act = (sact)? sact->action : NULL;
182 TimeMarker *marker, *markern=NULL;
185 if (ELEM(NULL, markers, act))
186 return OPERATOR_CANCELLED;
188 /* migrate markers */
189 for (marker = markers->first; marker; marker = markern) {
190 markern = marker->next;
192 /* move if marker is selected */
193 if (marker->flag & SELECT) {
194 BLI_remlink(markers, marker);
195 BLI_addtail(&act->markers, marker);
199 /* now enable the "show posemarkers only" setting, so that we can see that something did happen */
200 sact->flag |= SACTION_POSEMARKERS_SHOW;
202 /* notifiers - both sets, as this change affects both */
203 WM_event_add_notifier(C, NC_SCENE|ND_MARKERS, NULL);
204 WM_event_add_notifier(C, NC_ANIMATION|ND_MARKERS, NULL);
206 return OPERATOR_FINISHED;
209 void ACTION_OT_markers_make_local (wmOperatorType *ot)
212 ot->name= "Make Markers Local";
213 ot->idname= "ACTION_OT_markers_make_local";
214 ot->description= "Move selected scene markers to the active Action as local 'pose' markers";
217 ot->exec = act_markers_make_local_exec;
218 ot->poll = act_markers_make_local_poll;
221 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
224 /* ************************************************************************** */
225 /* KEYFRAME-RANGE STUFF */
227 /* *************************** Calculate Range ************************** */
229 /* Get the min/max keyframes*/
230 static void get_keyframe_extents (bAnimContext *ac, float *min, float *max, const short onlySel)
232 ListBase anim_data = {NULL, NULL};
236 /* get data to filter, from Action or Dopesheet */
237 // XXX: what is sel doing here?!
238 filter= (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_SEL /*| ANIMFILTER_CURVESONLY*/ | ANIMFILTER_NODUPLIS);
239 ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
241 /* set large values to try to override */
245 /* check if any channels to set range with */
246 if (anim_data.first) {
247 /* go through channels, finding max extents */
248 for (ale= anim_data.first; ale; ale= ale->next) {
249 AnimData *adt= ANIM_nla_mapping_get(ac, ale);
250 FCurve *fcu= (FCurve *)ale->key_data;
253 /* get range and apply necessary scaling before processing */
254 calc_fcurve_range(fcu, &tmin, &tmax, onlySel);
257 tmin= BKE_nla_tweakedit_remap(adt, tmin, NLATIME_CONVERT_MAP);
258 tmax= BKE_nla_tweakedit_remap(adt, tmax, NLATIME_CONVERT_MAP);
261 /* try to set cur using these values, if they're more extreme than previously set values */
262 *min= MIN2(*min, tmin);
263 *max= MAX2(*max, tmax);
267 BLI_freelistN(&anim_data);
270 /* set default range */
272 *min= (float)ac->scene->r.sfra;
273 *max= (float)ac->scene->r.efra;
282 /* ****************** Automatic Preview-Range Operator ****************** */
284 static int actkeys_previewrange_exec(bContext *C, wmOperator *UNUSED(op))
290 /* get editor data */
291 if (ANIM_animdata_get_context(C, &ac) == 0)
292 return OPERATOR_CANCELLED;
293 if (ac.scene == NULL)
294 return OPERATOR_CANCELLED;
298 /* set the range directly */
299 get_keyframe_extents(&ac, &min, &max, FALSE);
300 scene->r.flag |= SCER_PRV_RANGE;
301 scene->r.psfra= (int)floor(min + 0.5f);
302 scene->r.pefra= (int)floor(max + 0.5f);
304 /* set notifier that things have changed */
305 // XXX err... there's nothing for frame ranges yet, but this should do fine too
306 WM_event_add_notifier(C, NC_SCENE|ND_FRAME, ac.scene);
308 return OPERATOR_FINISHED;
311 void ACTION_OT_previewrange_set (wmOperatorType *ot)
314 ot->name= "Auto-Set Preview Range";
315 ot->idname= "ACTION_OT_previewrange_set";
316 ot->description= "Set Preview Range based on extents of selected Keyframes";
319 ot->exec= actkeys_previewrange_exec;
320 ot->poll= ED_operator_action_active;
323 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
326 /* ****************** View-All Operator ****************** */
328 static int actkeys_viewall(bContext *C, const short onlySel)
334 /* get editor data */
335 if (ANIM_animdata_get_context(C, &ac) == 0)
336 return OPERATOR_CANCELLED;
339 /* set the horizontal range, with an extra offset so that the extreme keys will be in view */
340 get_keyframe_extents(&ac, &v2d->cur.xmin, &v2d->cur.xmax, onlySel);
342 extra= 0.1f * (v2d->cur.xmax - v2d->cur.xmin);
343 v2d->cur.xmin -= extra;
344 v2d->cur.xmax += extra;
346 /* set vertical range */
348 v2d->cur.ymin= (float)-(v2d->mask.ymax - v2d->mask.ymin);
350 /* do View2D syncing */
351 UI_view2d_sync(CTX_wm_screen(C), CTX_wm_area(C), v2d, V2D_LOCK_COPY);
353 /* just redraw this view */
354 ED_area_tag_redraw(CTX_wm_area(C));
356 return OPERATOR_FINISHED;
361 static int actkeys_viewall_exec(bContext *C, wmOperator *UNUSED(op))
364 return actkeys_viewall(C, FALSE);
367 static int actkeys_viewsel_exec(bContext *C, wmOperator *UNUSED(op))
370 return actkeys_viewall(C, TRUE);
373 void ACTION_OT_view_all (wmOperatorType *ot)
376 ot->name= "View All";
377 ot->idname= "ACTION_OT_view_all";
378 ot->description= "Reset viewable area to show full keyframe range";
381 ot->exec= actkeys_viewall_exec;
382 ot->poll= ED_operator_action_active;
385 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
388 void ACTION_OT_view_selected (wmOperatorType *ot)
391 ot->name= "View Selected";
392 ot->idname= "ACTION_OT_view_selected";
393 ot->description= "Reset viewable area to show selected keyframes range";
396 ot->exec= actkeys_viewsel_exec;
397 ot->poll= ED_operator_action_active;
400 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
403 /* ************************************************************************** */
406 /* ******************** Copy/Paste Keyframes Operator ************************* */
407 /* NOTE: the backend code for this is shared with the graph editor */
409 static short copy_action_keys (bAnimContext *ac)
411 ListBase anim_data = {NULL, NULL};
414 /* clear buffer first */
418 filter= (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE /*| ANIMFILTER_CURVESONLY*/ | ANIMFILTER_NODUPLIS);
419 ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
422 ok= copy_animedit_keys(ac, &anim_data);
425 BLI_freelistN(&anim_data);
431 static short paste_action_keys (bAnimContext *ac,
432 const eKeyPasteOffset offset_mode, const eKeyMergeMode merge_mode)
434 ListBase anim_data = {NULL, NULL};
438 filter= (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_SEL | ANIMFILTER_FOREDIT /*| ANIMFILTER_CURVESONLY*/ | ANIMFILTER_NODUPLIS);
439 ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
441 /* paste keyframes */
442 ok= paste_animedit_keys(ac, &anim_data, offset_mode, merge_mode);
445 BLI_freelistN(&anim_data);
450 /* ------------------- */
452 static int actkeys_copy_exec(bContext *C, wmOperator *op)
456 /* get editor data */
457 if (ANIM_animdata_get_context(C, &ac) == 0)
458 return OPERATOR_CANCELLED;
461 if (ac.datatype == ANIMCONT_GPENCIL) {
465 if (copy_action_keys(&ac)) {
466 BKE_report(op->reports, RPT_ERROR, "No keyframes copied to keyframes copy/paste buffer");
467 return OPERATOR_CANCELLED;
471 return OPERATOR_FINISHED;
474 void ACTION_OT_copy (wmOperatorType *ot)
477 ot->name= "Copy Keyframes";
478 ot->idname= "ACTION_OT_copy";
479 ot->description= "Copy selected keyframes to the copy/paste buffer";
482 // ot->invoke= WM_operator_props_popup; // better wait for graph redo panel
483 ot->exec= actkeys_copy_exec;
484 ot->poll= ED_operator_action_active;
487 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
490 static int actkeys_paste_exec(bContext *C, wmOperator *op)
494 const eKeyPasteOffset offset_mode= RNA_enum_get(op->ptr, "offset");
495 const eKeyMergeMode merge_mode= RNA_enum_get(op->ptr, "merge");
497 /* get editor data */
498 if (ANIM_animdata_get_context(C, &ac) == 0)
499 return OPERATOR_CANCELLED;
501 if(ac.reports==NULL) {
502 ac.reports= op->reports;
505 /* paste keyframes */
506 if (ac.datatype == ANIMCONT_GPENCIL) {
510 if (paste_action_keys(&ac, offset_mode, merge_mode)) {
511 BKE_report(op->reports, RPT_ERROR, "No keyframes to paste");
512 return OPERATOR_CANCELLED;
516 /* validate keyframes after editing */
517 ANIM_editkeyframes_refresh(&ac);
519 /* set notifier that keyframes have changed */
520 WM_event_add_notifier(C, NC_ANIMATION|ND_KEYFRAME|NA_EDITED, NULL);
522 return OPERATOR_FINISHED;
525 void ACTION_OT_paste (wmOperatorType *ot)
528 ot->name= "Paste Keyframes";
529 ot->idname= "ACTION_OT_paste";
530 ot->description= "Paste keyframes from copy/paste buffer for the selected channels, starting on the current frame";
533 ot->exec= actkeys_paste_exec;
534 ot->poll= ED_operator_action_active;
537 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
539 RNA_def_enum(ot->srna, "offset", keyframe_paste_offset_items, KEYFRAME_PASTE_OFFSET_CFRA_START, "Offset", "Paste time offset of keys");
540 RNA_def_enum(ot->srna, "merge", keyframe_paste_merge_items, KEYFRAME_PASTE_MERGE_MIX, "Type", "Method of merking pasted keys and existing");
543 /* ******************** Insert Keyframes Operator ************************* */
545 /* defines for insert keyframes tool */
546 static EnumPropertyItem prop_actkeys_insertkey_types[] = {
547 {1, "ALL", 0, "All Channels", ""},
548 {2, "SEL", 0, "Only Selected Channels", ""},
549 {3, "GROUP", 0, "In Active Group", ""}, // xxx not in all cases
550 {0, NULL, 0, NULL, NULL}
553 /* this function is responsible for snapping keyframes to frame-times */
554 static void insert_action_keys(bAnimContext *ac, short mode)
556 ListBase anim_data = {NULL, NULL};
560 ReportList *reports = ac->reports;
561 Scene *scene= ac->scene;
565 filter= (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_FOREDIT /*| ANIMFILTER_CURVESONLY*/ | ANIMFILTER_NODUPLIS);
566 if (mode == 2) filter |= ANIMFILTER_SEL;
567 else if (mode == 3) filter |= ANIMFILTER_ACTGROUPED;
569 ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
571 /* init keyframing flag */
572 flag = ANIM_get_keyframing_flags(scene, 1);
574 /* insert keyframes */
575 for (ale= anim_data.first; ale; ale= ale->next) {
576 AnimData *adt= ANIM_nla_mapping_get(ac, ale);
577 FCurve *fcu= (FCurve *)ale->key_data;
580 /* adjust current frame for NLA-scaling */
582 cfra= BKE_nla_tweakedit_remap(adt, (float)CFRA, NLATIME_CONVERT_UNMAP);
586 /* if there's an id */
588 insert_keyframe(reports, ale->id, NULL, ((fcu->grp)?(fcu->grp->name):(NULL)), fcu->rna_path, fcu->array_index, cfra, flag);
590 insert_vert_fcurve(fcu, cfra, fcu->curval, 0);
593 BLI_freelistN(&anim_data);
596 /* ------------------- */
598 static int actkeys_insertkey_exec(bContext *C, wmOperator *op)
603 /* get editor data */
604 if (ANIM_animdata_get_context(C, &ac) == 0)
605 return OPERATOR_CANCELLED;
606 if (ac.datatype == ANIMCONT_GPENCIL)
607 return OPERATOR_CANCELLED;
609 /* what channels to affect? */
610 mode= RNA_enum_get(op->ptr, "type");
612 /* insert keyframes */
613 insert_action_keys(&ac, mode);
615 /* validate keyframes after editing */
616 ANIM_editkeyframes_refresh(&ac);
618 /* set notifier that keyframes have changed */
619 WM_event_add_notifier(C, NC_ANIMATION|ND_KEYFRAME|NA_EDITED, NULL);
621 return OPERATOR_FINISHED;
624 void ACTION_OT_keyframe_insert (wmOperatorType *ot)
627 ot->name= "Insert Keyframes";
628 ot->idname= "ACTION_OT_keyframe_insert";
629 ot->description= "Insert keyframes for the specified channels";
632 ot->invoke= WM_menu_invoke;
633 ot->exec= actkeys_insertkey_exec;
634 ot->poll= ED_operator_action_active;
637 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
640 ot->prop= RNA_def_enum(ot->srna, "type", prop_actkeys_insertkey_types, 0, "Type", "");
643 /* ******************** Duplicate Keyframes Operator ************************* */
645 static void duplicate_action_keys (bAnimContext *ac)
647 ListBase anim_data = {NULL, NULL};
652 if (ac->datatype == ANIMCONT_GPENCIL)
653 filter= (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_FOREDIT | ANIMFILTER_NODUPLIS);
655 filter= (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_FOREDIT /*| ANIMFILTER_CURVESONLY*/ | ANIMFILTER_NODUPLIS);
656 ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
658 /* loop through filtered data and delete selected keys */
659 for (ale= anim_data.first; ale; ale= ale->next) {
660 if (ale->type == ANIMTYPE_FCURVE)
661 duplicate_fcurve_keys((FCurve *)ale->key_data);
663 duplicate_gplayer_frames((bGPDlayer *)ale->data);
666 /* free filtered list */
667 BLI_freelistN(&anim_data);
670 /* ------------------- */
672 static int actkeys_duplicate_exec(bContext *C, wmOperator *UNUSED(op))
676 /* get editor data */
677 if (ANIM_animdata_get_context(C, &ac) == 0)
678 return OPERATOR_CANCELLED;
680 /* duplicate keyframes */
681 duplicate_action_keys(&ac);
683 /* validate keyframes after editing */
684 ANIM_editkeyframes_refresh(&ac);
686 /* set notifier that keyframes have changed */
687 WM_event_add_notifier(C, NC_ANIMATION|ND_KEYFRAME|NA_EDITED, NULL);
689 return OPERATOR_FINISHED; // xxx - start transform
692 static int actkeys_duplicate_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
694 actkeys_duplicate_exec(C, op);
696 return OPERATOR_FINISHED;
699 void ACTION_OT_duplicate (wmOperatorType *ot)
702 ot->name= "Duplicate Keyframes";
703 ot->idname= "ACTION_OT_duplicate";
704 ot->description= "Make a copy of all selected keyframes";
707 ot->invoke= actkeys_duplicate_invoke;
708 ot->exec= actkeys_duplicate_exec;
709 ot->poll= ED_operator_action_active;
712 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
714 /* to give to transform */
715 RNA_def_enum(ot->srna, "mode", transform_mode_types, TFM_TRANSLATION, "Mode", "");
718 /* ******************** Delete Keyframes Operator ************************* */
720 static void delete_action_keys (bAnimContext *ac)
722 ListBase anim_data = {NULL, NULL};
727 if (ac->datatype == ANIMCONT_GPENCIL)
728 filter= (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_FOREDIT | ANIMFILTER_NODUPLIS);
730 filter= (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_FOREDIT /*| ANIMFILTER_CURVESONLY*/ | ANIMFILTER_NODUPLIS);
731 ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
733 /* loop through filtered data and delete selected keys */
734 for (ale= anim_data.first; ale; ale= ale->next) {
735 if (ale->type != ANIMTYPE_GPLAYER) {
736 FCurve *fcu= (FCurve *)ale->key_data;
737 AnimData *adt= ale->adt;
739 /* delete selected keyframes only */
740 delete_fcurve_keys(fcu);
742 /* Only delete curve too if it won't be doing anything anymore */
743 if ((fcu->totvert == 0) && (list_has_suitable_fmodifier(&fcu->modifiers, 0, FMI_TYPE_GENERATE_CURVE) == 0))
744 ANIM_fcurve_delete_from_animdata(ac, adt, fcu);
747 delete_gplayer_frames((bGPDlayer *)ale->data);
750 /* free filtered list */
751 BLI_freelistN(&anim_data);
754 /* ------------------- */
756 static int actkeys_delete_exec(bContext *C, wmOperator *UNUSED(op))
760 /* get editor data */
761 if (ANIM_animdata_get_context(C, &ac) == 0)
762 return OPERATOR_CANCELLED;
764 /* delete keyframes */
765 delete_action_keys(&ac);
767 /* validate keyframes after editing */
768 ANIM_editkeyframes_refresh(&ac);
770 /* set notifier that keyframes have changed */
771 WM_event_add_notifier(C, NC_ANIMATION|ND_KEYFRAME|NA_EDITED, NULL);
773 return OPERATOR_FINISHED;
776 void ACTION_OT_delete (wmOperatorType *ot)
779 ot->name= "Delete Keyframes";
780 ot->idname= "ACTION_OT_delete";
781 ot->description= "Remove all selected keyframes";
784 ot->invoke= WM_operator_confirm;
785 ot->exec= actkeys_delete_exec;
786 ot->poll= ED_operator_action_active;
789 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
792 /* ******************** Clean Keyframes Operator ************************* */
794 static void clean_action_keys (bAnimContext *ac, float thresh)
796 ListBase anim_data = {NULL, NULL};
801 filter= (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_FOREDIT | ANIMFILTER_SEL /*| ANIMFILTER_CURVESONLY*/ | ANIMFILTER_NODUPLIS);
802 ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
804 /* loop through filtered data and clean curves */
805 for (ale= anim_data.first; ale; ale= ale->next)
806 clean_fcurve((FCurve *)ale->key_data, thresh);
809 BLI_freelistN(&anim_data);
812 /* ------------------- */
814 static int actkeys_clean_exec(bContext *C, wmOperator *op)
819 /* get editor data */
820 if (ANIM_animdata_get_context(C, &ac) == 0)
821 return OPERATOR_CANCELLED;
822 if (ac.datatype == ANIMCONT_GPENCIL)
823 return OPERATOR_PASS_THROUGH;
825 /* get cleaning threshold */
826 thresh= RNA_float_get(op->ptr, "threshold");
828 /* clean keyframes */
829 clean_action_keys(&ac, thresh);
831 /* validate keyframes after editing */
832 ANIM_editkeyframes_refresh(&ac);
834 /* set notifier that keyframes have changed */
835 WM_event_add_notifier(C, NC_ANIMATION|ND_KEYFRAME|NA_EDITED, NULL);
837 return OPERATOR_FINISHED;
840 void ACTION_OT_clean (wmOperatorType *ot)
843 ot->name= "Clean Keyframes";
844 ot->idname= "ACTION_OT_clean";
845 ot->description= "Simplify F-Curves by removing closely spaced keyframes";
848 //ot->invoke= // XXX we need that number popup for this!
849 ot->exec= actkeys_clean_exec;
850 ot->poll= ED_operator_action_active;
853 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
856 ot->prop= RNA_def_float(ot->srna, "threshold", 0.001f, 0.0f, FLT_MAX, "Threshold", "", 0.0f, 1000.0f);
859 /* ******************** Sample Keyframes Operator *********************** */
861 /* Evaluates the curves between each selected keyframe on each frame, and keys the value */
862 static void sample_action_keys (bAnimContext *ac)
864 ListBase anim_data = {NULL, NULL};
869 filter= (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_FOREDIT /*| ANIMFILTER_CURVESONLY*/ | ANIMFILTER_NODUPLIS);
870 ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
872 /* loop through filtered data and add keys between selected keyframes on every frame */
873 for (ale= anim_data.first; ale; ale= ale->next)
874 sample_fcurve((FCurve *)ale->key_data);
876 /* admin and redraws */
877 BLI_freelistN(&anim_data);
880 /* ------------------- */
882 static int actkeys_sample_exec(bContext *C, wmOperator *UNUSED(op))
886 /* get editor data */
887 if (ANIM_animdata_get_context(C, &ac) == 0)
888 return OPERATOR_CANCELLED;
889 if (ac.datatype == ANIMCONT_GPENCIL)
890 return OPERATOR_PASS_THROUGH;
892 /* sample keyframes */
893 sample_action_keys(&ac);
895 /* validate keyframes after editing */
896 ANIM_editkeyframes_refresh(&ac);
898 /* set notifier that keyframes have changed */
899 WM_event_add_notifier(C, NC_ANIMATION|ND_KEYFRAME|NA_EDITED, NULL);
901 return OPERATOR_FINISHED;
904 void ACTION_OT_sample (wmOperatorType *ot)
907 ot->name= "Sample Keyframes";
908 ot->idname= "ACTION_OT_sample";
909 ot->description= "Add keyframes on every frame between the selected keyframes";
912 ot->exec= actkeys_sample_exec;
913 ot->poll= ED_operator_action_active;
916 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
919 /* ************************************************************************** */
922 /* ******************** Set Extrapolation-Type Operator *********************** */
924 /* defines for make/clear cyclic extrapolation tools */
925 #define MAKE_CYCLIC_EXPO -1
926 #define CLEAR_CYCLIC_EXPO -2
928 /* defines for set extrapolation-type for selected keyframes tool */
929 static EnumPropertyItem prop_actkeys_expo_types[] = {
930 {FCURVE_EXTRAPOLATE_CONSTANT, "CONSTANT", 0, "Constant Extrapolation", ""},
931 {FCURVE_EXTRAPOLATE_LINEAR, "LINEAR", 0, "Linear Extrapolation", ""},
933 {MAKE_CYCLIC_EXPO, "MAKE_CYCLIC", 0, "Make Cyclic (F-Modifier)", "Add Cycles F-Modifier if one doesn't exist already"},
934 {CLEAR_CYCLIC_EXPO, "CLEAR_CYCLIC", 0, "Clear Cyclic (F-Modifier)", "Remove Cycles F-Modifier if not needed anymore"},
935 {0, NULL, 0, NULL, NULL}
938 /* this function is responsible for setting extrapolation mode for keyframes */
939 static void setexpo_action_keys(bAnimContext *ac, short mode)
941 ListBase anim_data = {NULL, NULL};
946 filter= (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_FOREDIT | ANIMFILTER_SEL /*| ANIMFILTER_CURVESONLY*/ | ANIMFILTER_NODUPLIS);
947 ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
949 /* loop through setting mode per F-Curve */
950 for (ale= anim_data.first; ale; ale= ale->next) {
951 FCurve *fcu= (FCurve *)ale->data;
954 /* just set mode setting */
958 /* shortcuts for managing Cycles F-Modifiers to make it easier to toggle cyclic animation
959 * without having to go through FModifier UI in Graph Editor to do so
961 if (mode == MAKE_CYCLIC_EXPO) {
962 /* only add if one doesn't exist */
963 if (list_has_suitable_fmodifier(&fcu->modifiers, FMODIFIER_TYPE_CYCLES, -1) == 0) {
964 // TODO: add some more preset versions which set different extrapolation options?
965 add_fmodifier(&fcu->modifiers, FMODIFIER_TYPE_CYCLES);
968 else if (mode == CLEAR_CYCLIC_EXPO) {
969 /* remove all the modifiers fitting this description */
970 FModifier *fcm, *fcn=NULL;
972 for (fcm = fcu->modifiers.first; fcm; fcm = fcn) {
975 if (fcm->type == FMODIFIER_TYPE_CYCLES)
976 remove_fmodifier(&fcu->modifiers, fcm);
983 BLI_freelistN(&anim_data);
986 /* ------------------- */
988 static int actkeys_expo_exec(bContext *C, wmOperator *op)
993 /* get editor data */
994 if (ANIM_animdata_get_context(C, &ac) == 0)
995 return OPERATOR_CANCELLED;
996 if (ac.datatype == ANIMCONT_GPENCIL)
997 return OPERATOR_PASS_THROUGH;
999 /* get handle setting mode */
1000 mode= RNA_enum_get(op->ptr, "type");
1002 /* set handle type */
1003 setexpo_action_keys(&ac, mode);
1005 /* validate keyframes after editing */
1006 ANIM_editkeyframes_refresh(&ac);
1008 /* set notifier that keyframe properties have changed */
1009 WM_event_add_notifier(C, NC_ANIMATION|ND_KEYFRAME_PROP, NULL);
1011 return OPERATOR_FINISHED;
1014 void ACTION_OT_extrapolation_type (wmOperatorType *ot)
1017 ot->name= "Set Keyframe Extrapolation";
1018 ot->idname= "ACTION_OT_extrapolation_type";
1019 ot->description= "Set extrapolation mode for selected F-Curves";
1022 ot->invoke= WM_menu_invoke;
1023 ot->exec= actkeys_expo_exec;
1024 ot->poll= ED_operator_action_active;
1027 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1030 ot->prop= RNA_def_enum(ot->srna, "type", prop_actkeys_expo_types, 0, "Type", "");
1033 /* ******************** Set Interpolation-Type Operator *********************** */
1035 /* this function is responsible for setting interpolation mode for keyframes */
1036 static void setipo_action_keys(bAnimContext *ac, short mode)
1038 ListBase anim_data = {NULL, NULL};
1041 KeyframeEditFunc set_cb= ANIM_editkeyframes_ipo(mode);
1044 filter= (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_FOREDIT /*| ANIMFILTER_CURVESONLY*/ | ANIMFILTER_NODUPLIS);
1045 ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
1047 /* loop through setting BezTriple interpolation
1048 * Note: we do not supply KeyframeEditData to the looper yet. Currently that's not necessary here...
1050 for (ale= anim_data.first; ale; ale= ale->next)
1051 ANIM_fcurve_keyframes_loop(NULL, ale->key_data, NULL, set_cb, calchandles_fcurve);
1054 BLI_freelistN(&anim_data);
1057 /* ------------------- */
1059 static int actkeys_ipo_exec(bContext *C, wmOperator *op)
1064 /* get editor data */
1065 if (ANIM_animdata_get_context(C, &ac) == 0)
1066 return OPERATOR_CANCELLED;
1067 if (ac.datatype == ANIMCONT_GPENCIL)
1068 return OPERATOR_PASS_THROUGH;
1070 /* get handle setting mode */
1071 mode= RNA_enum_get(op->ptr, "type");
1073 /* set handle type */
1074 setipo_action_keys(&ac, mode);
1076 /* validate keyframes after editing */
1077 ANIM_editkeyframes_refresh(&ac);
1079 /* set notifier that keyframe properties have changed */
1080 WM_event_add_notifier(C, NC_ANIMATION|ND_KEYFRAME_PROP, NULL);
1082 return OPERATOR_FINISHED;
1085 void ACTION_OT_interpolation_type (wmOperatorType *ot)
1088 ot->name= "Set Keyframe Interpolation";
1089 ot->idname= "ACTION_OT_interpolation_type";
1090 ot->description= "Set interpolation mode for the F-Curve segments starting from the selected keyframes";
1093 ot->invoke= WM_menu_invoke;
1094 ot->exec= actkeys_ipo_exec;
1095 ot->poll= ED_operator_action_active;
1098 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1101 ot->prop= RNA_def_enum(ot->srna, "type", beztriple_interpolation_mode_items, 0, "Type", "");
1104 /* ******************** Set Handle-Type Operator *********************** */
1106 static EnumPropertyItem actkeys_handle_type_items[] = {
1107 {HD_FREE, "FREE", 0, "Free", ""},
1108 {HD_VECT, "VECTOR", 0, "Vector", ""},
1109 {HD_ALIGN, "ALIGNED", 0, "Aligned", ""},
1111 {HD_AUTO, "AUTO", 0, "Auto", "Handles that are automatically adjusted upon moving the keyframe"},
1112 {HD_AUTO_ANIM, "ANIM_CLAMPED", 0, "Auto Clamped", "Auto handles clamped to not overshoot"},
1113 {0, NULL, 0, NULL, NULL}};
1115 /* ------------------- */
1117 /* this function is responsible for setting handle-type of selected keyframes */
1118 static void sethandles_action_keys(bAnimContext *ac, short mode)
1120 ListBase anim_data = {NULL, NULL};
1124 KeyframeEditFunc edit_cb= ANIM_editkeyframes_handles(mode);
1125 KeyframeEditFunc sel_cb= ANIM_editkeyframes_ok(BEZT_OK_SELECTED);
1128 filter= (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_FOREDIT /*| ANIMFILTER_CURVESONLY*/ | ANIMFILTER_NODUPLIS);
1129 ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
1131 /* loop through setting flags for handles
1132 * Note: we do not supply KeyframeEditData to the looper yet. Currently that's not necessary here...
1134 for (ale= anim_data.first; ale; ale= ale->next) {
1135 FCurve *fcu= (FCurve *)ale->key_data;
1137 /* any selected keyframes for editing? */
1138 if (ANIM_fcurve_keyframes_loop(NULL, fcu, NULL, sel_cb, NULL)) {
1139 /* for auto/auto-clamped, toggle the auto-handles flag on the F-Curve */
1140 if (mode == HD_AUTO_ANIM)
1141 fcu->flag |= FCURVE_AUTO_HANDLES;
1142 else if (mode == HD_AUTO)
1143 fcu->flag &= ~FCURVE_AUTO_HANDLES;
1145 /* change type of selected handles */
1146 ANIM_fcurve_keyframes_loop(NULL, fcu, NULL, edit_cb, calchandles_fcurve);
1151 BLI_freelistN(&anim_data);
1154 /* ------------------- */
1156 static int actkeys_handletype_exec(bContext *C, wmOperator *op)
1161 /* get editor data */
1162 if (ANIM_animdata_get_context(C, &ac) == 0)
1163 return OPERATOR_CANCELLED;
1164 if (ac.datatype == ANIMCONT_GPENCIL)
1165 return OPERATOR_PASS_THROUGH;
1167 /* get handle setting mode */
1168 mode= RNA_enum_get(op->ptr, "type");
1170 /* set handle type */
1171 sethandles_action_keys(&ac, mode);
1173 /* validate keyframes after editing */
1174 ANIM_editkeyframes_refresh(&ac);
1176 /* set notifier that keyframe properties have changed */
1177 WM_event_add_notifier(C, NC_ANIMATION|ND_KEYFRAME_PROP, NULL);
1179 return OPERATOR_FINISHED;
1182 void ACTION_OT_handle_type (wmOperatorType *ot)
1185 ot->name= "Set Keyframe Handle Type";
1186 ot->idname= "ACTION_OT_handle_type";
1187 ot->description= "Set type of handle for selected keyframes";
1190 ot->invoke= WM_menu_invoke;
1191 ot->exec= actkeys_handletype_exec;
1192 ot->poll= ED_operator_action_active;
1195 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1198 ot->prop= RNA_def_enum(ot->srna, "type", actkeys_handle_type_items, 0, "Type", "");
1201 /* ******************** Set Keyframe-Type Operator *********************** */
1203 /* this function is responsible for setting interpolation mode for keyframes */
1204 static void setkeytype_action_keys(bAnimContext *ac, short mode)
1206 ListBase anim_data = {NULL, NULL};
1209 KeyframeEditFunc set_cb= ANIM_editkeyframes_keytype(mode);
1212 filter= (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_FOREDIT /*| ANIMFILTER_CURVESONLY*/ | ANIMFILTER_NODUPLIS);
1213 ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
1215 /* loop through setting BezTriple interpolation
1216 * Note: we do not supply KeyframeEditData to the looper yet. Currently that's not necessary here...
1218 for (ale= anim_data.first; ale; ale= ale->next)
1219 ANIM_fcurve_keyframes_loop(NULL, ale->key_data, NULL, set_cb, NULL);
1222 BLI_freelistN(&anim_data);
1225 /* ------------------- */
1227 static int actkeys_keytype_exec(bContext *C, wmOperator *op)
1232 /* get editor data */
1233 if (ANIM_animdata_get_context(C, &ac) == 0)
1234 return OPERATOR_CANCELLED;
1235 if (ac.datatype == ANIMCONT_GPENCIL)
1236 return OPERATOR_PASS_THROUGH;
1238 /* get handle setting mode */
1239 mode= RNA_enum_get(op->ptr, "type");
1241 /* set handle type */
1242 setkeytype_action_keys(&ac, mode);
1244 /* validate keyframes after editing */
1245 ANIM_editkeyframes_refresh(&ac);
1247 /* set notifier that keyframe properties have changed */
1248 WM_event_add_notifier(C, NC_ANIMATION|ND_KEYFRAME_PROP, NULL);
1250 return OPERATOR_FINISHED;
1253 void ACTION_OT_keyframe_type (wmOperatorType *ot)
1256 ot->name= "Set Keyframe Type";
1257 ot->idname= "ACTION_OT_keyframe_type";
1258 ot->description= "Set type of keyframe for the selected keyframes";
1261 ot->invoke= WM_menu_invoke;
1262 ot->exec= actkeys_keytype_exec;
1263 ot->poll= ED_operator_action_active;
1266 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1269 ot->prop= RNA_def_enum(ot->srna, "type", beztriple_keyframe_type_items, 0, "Type", "");
1272 /* ************************************************************************** */
1273 /* TRANSFORM STUFF */
1275 /* ***************** Jump to Selected Frames Operator *********************** */
1277 /* snap current-frame indicator to 'average time' of selected keyframe */
1278 static int actkeys_framejump_exec(bContext *C, wmOperator *UNUSED(op))
1281 ListBase anim_data= {NULL, NULL};
1284 KeyframeEditData ked= {{NULL}};
1286 /* get editor data */
1287 if (ANIM_animdata_get_context(C, &ac) == 0)
1288 return OPERATOR_CANCELLED;
1290 /* init edit data */
1291 /* loop over action data, averaging values */
1292 filter= (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE /*| ANIMFILTER_CURVESONLY */ | ANIMFILTER_NODUPLIS);
1293 ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
1295 for (ale= anim_data.first; ale; ale= ale->next) {
1296 AnimData *adt= ANIM_nla_mapping_get(&ac, ale);
1298 ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 0, 1);
1299 ANIM_fcurve_keyframes_loop(&ked, ale->key_data, NULL, bezt_calc_average, NULL);
1300 ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 1, 1);
1303 ANIM_fcurve_keyframes_loop(&ked, ale->key_data, NULL, bezt_calc_average, NULL);
1306 BLI_freelistN(&anim_data);
1308 /* set the new current frame value, based on the average time */
1310 Scene *scene= ac.scene;
1311 CFRA= (int)floor((ked.f1 / ked.i1) + 0.5f);
1315 /* set notifier that things have changed */
1316 WM_event_add_notifier(C, NC_SCENE|ND_FRAME, ac.scene);
1318 return OPERATOR_FINISHED;
1321 void ACTION_OT_frame_jump (wmOperatorType *ot)
1324 ot->name= "Jump to Frame";
1325 ot->idname= "ACTION_OT_frame_jump";
1326 ot->description= "Set the current frame to the average frame of the selected keyframes";
1329 ot->exec= actkeys_framejump_exec;
1330 ot->poll= ED_operator_action_active;
1333 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1336 /* ******************** Snap Keyframes Operator *********************** */
1338 /* defines for snap keyframes tool */
1339 static EnumPropertyItem prop_actkeys_snap_types[] = {
1340 {ACTKEYS_SNAP_CFRA, "CFRA", 0, "Current frame", ""},
1341 {ACTKEYS_SNAP_NEAREST_FRAME, "NEAREST_FRAME", 0, "Nearest Frame", ""}, // XXX as single entry?
1342 {ACTKEYS_SNAP_NEAREST_SECOND, "NEAREST_SECOND", 0, "Nearest Second", ""}, // XXX as single entry?
1343 {ACTKEYS_SNAP_NEAREST_MARKER, "NEAREST_MARKER", 0, "Nearest Marker", ""},
1344 {0, NULL, 0, NULL, NULL}
1347 /* this function is responsible for snapping keyframes to frame-times */
1348 static void snap_action_keys(bAnimContext *ac, short mode)
1350 ListBase anim_data = {NULL, NULL};
1354 KeyframeEditData ked= {{NULL}};
1355 KeyframeEditFunc edit_cb;
1358 if (ac->datatype == ANIMCONT_GPENCIL)
1359 filter= (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_FOREDIT);
1361 filter= (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_FOREDIT /*| ANIMFILTER_CURVESONLY*/ | ANIMFILTER_NODUPLIS);
1362 ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
1364 /* get beztriple editing callbacks */
1365 edit_cb= ANIM_editkeyframes_snap(mode);
1367 ked.scene= ac->scene;
1368 if (mode == ACTKEYS_SNAP_NEAREST_MARKER) {
1369 ked.list.first= (ac->markers) ? ac->markers->first : NULL;
1370 ked.list.last= (ac->markers) ? ac->markers->last : NULL;
1373 /* snap keyframes */
1374 for (ale= anim_data.first; ale; ale= ale->next) {
1375 AnimData *adt= ANIM_nla_mapping_get(ac, ale);
1378 ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 0, 1);
1379 ANIM_fcurve_keyframes_loop(&ked, ale->key_data, NULL, edit_cb, calchandles_fcurve);
1380 ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 1, 1);
1382 //else if (ale->type == ACTTYPE_GPLAYER)
1383 // snap_gplayer_frames(ale->data, mode);
1385 ANIM_fcurve_keyframes_loop(&ked, ale->key_data, NULL, edit_cb, calchandles_fcurve);
1388 BLI_freelistN(&anim_data);
1391 /* ------------------- */
1393 static int actkeys_snap_exec(bContext *C, wmOperator *op)
1398 /* get editor data */
1399 if (ANIM_animdata_get_context(C, &ac) == 0)
1400 return OPERATOR_CANCELLED;
1402 /* get snapping mode */
1403 mode= RNA_enum_get(op->ptr, "type");
1405 /* snap keyframes */
1406 snap_action_keys(&ac, mode);
1408 /* validate keyframes after editing */
1409 ANIM_editkeyframes_refresh(&ac);
1411 /* set notifier that keyframes have changed */
1412 WM_event_add_notifier(C, NC_ANIMATION|ND_KEYFRAME|NA_EDITED, NULL);
1414 return OPERATOR_FINISHED;
1417 void ACTION_OT_snap (wmOperatorType *ot)
1420 ot->name= "Snap Keys";
1421 ot->idname= "ACTION_OT_snap";
1422 ot->description= "Snap selected keyframes to the times specified";
1425 ot->invoke= WM_menu_invoke;
1426 ot->exec= actkeys_snap_exec;
1427 ot->poll= ED_operator_action_active;
1430 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1433 ot->prop= RNA_def_enum(ot->srna, "type", prop_actkeys_snap_types, 0, "Type", "");
1436 /* ******************** Mirror Keyframes Operator *********************** */
1438 /* defines for mirror keyframes tool */
1439 static EnumPropertyItem prop_actkeys_mirror_types[] = {
1440 {ACTKEYS_MIRROR_CFRA, "CFRA", 0, "By Times over Current frame", ""},
1441 {ACTKEYS_MIRROR_XAXIS, "XAXIS", 0, "By Values over Value=0", ""},
1442 {ACTKEYS_MIRROR_MARKER, "MARKER", 0, "By Times over First Selected Marker", ""},
1443 {0, NULL, 0, NULL, NULL}
1446 /* this function is responsible for mirroring keyframes */
1447 static void mirror_action_keys(bAnimContext *ac, short mode)
1449 ListBase anim_data = {NULL, NULL};
1453 KeyframeEditData ked= {{NULL}};
1454 KeyframeEditFunc edit_cb;
1456 /* get beztriple editing callbacks */
1457 edit_cb= ANIM_editkeyframes_mirror(mode);
1459 ked.scene= ac->scene;
1461 /* for 'first selected marker' mode, need to find first selected marker first! */
1462 // XXX should this be made into a helper func in the API?
1463 if (mode == ACTKEYS_MIRROR_MARKER) {
1464 TimeMarker *marker= NULL;
1466 /* find first selected marker */
1467 marker= ED_markers_get_first_selected(ac->markers);
1469 /* store marker's time (if available) */
1471 ked.f1= (float)marker->frame;
1477 if (ac->datatype == ANIMCONT_GPENCIL)
1478 filter= (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_FOREDIT | ANIMFILTER_NODUPLIS);
1480 filter= (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_FOREDIT /*| ANIMFILTER_CURVESONLY*/ | ANIMFILTER_NODUPLIS);
1481 ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
1483 /* mirror keyframes */
1484 for (ale= anim_data.first; ale; ale= ale->next) {
1485 AnimData *adt= ANIM_nla_mapping_get(ac, ale);
1488 ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 0, 1);
1489 ANIM_fcurve_keyframes_loop(&ked, ale->key_data, NULL, edit_cb, calchandles_fcurve);
1490 ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 1, 1);
1492 //else if (ale->type == ACTTYPE_GPLAYER)
1493 // snap_gplayer_frames(ale->data, mode);
1495 ANIM_fcurve_keyframes_loop(&ked, ale->key_data, NULL, edit_cb, calchandles_fcurve);
1498 BLI_freelistN(&anim_data);
1501 /* ------------------- */
1503 static int actkeys_mirror_exec(bContext *C, wmOperator *op)
1508 /* get editor data */
1509 if (ANIM_animdata_get_context(C, &ac) == 0)
1510 return OPERATOR_CANCELLED;
1512 /* get mirroring mode */
1513 mode= RNA_enum_get(op->ptr, "type");
1515 /* mirror keyframes */
1516 mirror_action_keys(&ac, mode);
1518 /* validate keyframes after editing */
1519 ANIM_editkeyframes_refresh(&ac);
1521 /* set notifier that keyframes have changed */
1522 WM_event_add_notifier(C, NC_ANIMATION|ND_KEYFRAME|NA_EDITED, NULL);
1524 return OPERATOR_FINISHED;
1527 void ACTION_OT_mirror (wmOperatorType *ot)
1530 ot->name= "Mirror Keys";
1531 ot->idname= "ACTION_OT_mirror";
1532 ot->description= "Flip selected keyframes over the selected mirror line";
1535 ot->invoke= WM_menu_invoke;
1536 ot->exec= actkeys_mirror_exec;
1537 ot->poll= ED_operator_action_active;
1540 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1543 ot->prop= RNA_def_enum(ot->srna, "type", prop_actkeys_mirror_types, 0, "Type", "");
1546 /* ************************************************************************** */