2 * $Id: editaction.c 17746 2008-12-08 11:19:44Z aligorith $
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 *****
39 #include "MEM_guardedalloc.h"
41 #include "BLI_blenlib.h"
42 #include "BLI_arithb.h"
44 #include "DNA_listBase.h"
45 #include "DNA_action_types.h"
46 #include "DNA_armature_types.h"
47 #include "DNA_camera_types.h"
48 #include "DNA_curve_types.h"
49 #include "DNA_ipo_types.h"
50 #include "DNA_object_types.h"
51 #include "DNA_screen_types.h"
52 #include "DNA_scene_types.h"
53 #include "DNA_space_types.h"
54 #include "DNA_constraint_types.h"
55 #include "DNA_key_types.h"
56 #include "DNA_lamp_types.h"
57 #include "DNA_material_types.h"
58 #include "DNA_userdef_types.h"
59 #include "DNA_gpencil_types.h"
60 #include "DNA_windowmanager_types.h"
62 #include "RNA_access.h"
63 #include "RNA_define.h"
65 #include "BKE_action.h"
66 #include "BKE_depsgraph.h"
69 #include "BKE_material.h"
70 #include "BKE_object.h"
71 #include "BKE_context.h"
72 #include "BKE_utildefines.h"
74 #include "UI_view2d.h"
76 #include "ED_anim_api.h"
77 #include "ED_keyframing.h"
78 #include "ED_keyframes_draw.h"
79 #include "ED_keyframes_edit.h"
80 #include "ED_screen.h"
81 #include "ED_space_api.h"
86 #include "action_intern.h"
88 /* ************************************************************************** */
91 /* this function finds the channel that mouse is floating over */
92 void *get_nearest_act_channel (bAnimContext *ac, int mval[2], short *ret_type, void **owner)
94 ListBase anim_data = {NULL, NULL};
98 View2D *v2d= &ac->ar->v2d;
99 int clickmin, clickmax;
103 /* init 'owner' return val */
106 UI_view2d_region_to_view(v2d, mval[0], mval[1], &x, &y);
107 clickmin = (int) ((ACHANNEL_HEIGHT_HALF - y) / (ACHANNEL_STEP));
111 *ret_type= ANIMTYPE_NONE;
116 filter= (ANIMFILTER_FORDRAWING | ANIMFILTER_VISIBLE | ANIMFILTER_CHANNELS);
117 ANIM_animdata_filter(&anim_data, filter, ac->data, ac->datatype);
119 for (ale= anim_data.first; ale; ale= ale->next) {
124 *ret_type= ale->type;
127 /* if an 'ID' has been set, this takes presidence as owner (for dopesheet) */
128 if (ac->datatype == ANIMCONT_DOPESHEET) {
129 /* return pointer to ID as owner instead */
136 /* just use own owner */
140 BLI_freelistN(&anim_data);
149 BLI_freelistN(&anim_data);
151 *ret_type= ANIMTYPE_NONE;
156 /* used only by mouse_action. It is used to find the location of the nearest
157 * keyframe to where the mouse clicked,
159 static void *get_nearest_action_key (bAnimContext *ac, int mval[2], float *selx, short *sel, short *ret_type, bActionChannel **par)
161 ListBase anim_data = {NULL, NULL};
162 ListBase anim_keys = {NULL, NULL};
165 View2D *v2d= &ac->ar->v2d;
170 float xmin, xmax, x, y;
171 int clickmin, clickmax;
177 UI_view2d_region_to_view(v2d, mval[0], mval[1], &x, &y);
178 clickmin = (int) ((-y) / (ACHANNEL_STEP));
181 /* x-range to check is +/- 7 on either side of mouse click (size of keyframe icon) */
182 UI_view2d_region_to_view(v2d, mval[0]-7, mval[1], &rectf.xmin, &rectf.ymin);
183 UI_view2d_region_to_view(v2d, mval[0]+7, mval[1], &rectf.xmax, &rectf.ymax);
186 *ret_type= ANIMTYPE_NONE;
191 filter= (ANIMFILTER_FORDRAWING | ANIMFILTER_VISIBLE | ANIMFILTER_CHANNELS);
192 ANIM_animdata_filter(&anim_data, filter, ac->data, ac->datatype);
194 for (ale= anim_data.first; ale; ale= ale->next) {
198 /* found match - must return here... */
199 Object *nob= ANIM_nla_mapping_get(ac, ale);
201 /* apply NLA-scaling correction? */
203 xmin= get_action_frame(nob, rectf.xmin);
204 xmax= get_action_frame(nob, rectf.xmax);
211 /* make list of keyframes */
213 switch (ale->datatype) {
216 Object *ob= (Object *)ale->key_data;
217 ob_to_keylist(ob, &anim_keys, NULL, NULL);
222 bAction *act= (bAction *)ale->key_data;
223 action_to_keylist(act, &anim_keys, NULL, NULL);
228 Ipo *ipo= (Ipo *)ale->key_data;
229 ipo_to_keylist(ipo, &anim_keys, NULL, NULL);
234 IpoCurve *icu= (IpoCurve *)ale->key_data;
235 icu_to_keylist(icu, &anim_keys, NULL, NULL);
240 else if (ale->type == ANIMTYPE_GROUP) {
241 bActionGroup *agrp= (bActionGroup *)ale->data;
242 agroup_to_keylist(agrp, &anim_keys, NULL, NULL);
244 else if (ale->type == ANIMTYPE_GPDATABLOCK) {
246 BLI_freelistN(&anim_data);
248 /* this channel currently doens't have any keyframes... must ignore! */
249 *ret_type= ANIMTYPE_NONE;
252 else if (ale->type == ANIMTYPE_GPLAYER) {
253 bGPDlayer *gpl= (bGPDlayer *)ale->data;
254 gpl_to_keylist(gpl, &anim_keys, NULL, NULL);
257 /* loop through keyframes, finding one that was clicked on */
258 for (ak= anim_keys.first; ak; ak= ak->next) {
259 if (IN_RANGE(ak->cfra, xmin, xmax)) {
265 /* no matching keyframe found - set to mean frame value so it doesn't actually select anything */
267 *selx= ((xmax+xmin) / 2);
269 /* figure out what to return */
270 if (ac->datatype == ANIMCONT_ACTION) {
271 *par= ale->owner; /* assume that this is an action channel */
272 *ret_type= ale->type;
275 else if (ac->datatype == ANIMCONT_SHAPEKEY) {
276 data = ale->key_data;
277 *ret_type= ANIMTYPE_ICU;
279 else if (ac->datatype == ANIMCONT_DOPESHEET) {
281 *ret_type= ale->type;
283 else if (ac->datatype == ANIMCONT_GPENCIL) {
285 *ret_type= ANIMTYPE_GPLAYER;
288 /* cleanup tempolary lists */
289 BLI_freelistN(&anim_keys);
290 anim_keys.first = anim_keys.last = NULL;
292 BLI_freelistN(&anim_data);
301 BLI_freelistN(&anim_data);
303 *ret_type= ANIMTYPE_NONE;
307 /* ************************************************************************** */
310 /* ************************************************************************** */
311 /* KEYFRAMES STUFF */
313 /* ******************** Deselect All Operator ***************************** */
314 /* This operator works in one of three ways:
315 * 1) (de)select all (AKEY) - test if select all or deselect all
316 * 2) invert all (CTRL-IKEY) - invert selection of all keyframes
317 * 3) (de)select all - no testing is done; only for use internal tools as normal function...
320 /* Deselects keyframes in the action editor
321 * - This is called by the deselect all operator, as well as other ones!
323 * - test: check if select or deselect all
324 * - sel: how to select keyframes
329 static void deselect_action_keys (bAnimContext *ac, short test, short sel)
331 ListBase anim_data = {NULL, NULL};
335 /* determine type-based settings */
336 if (ac->datatype == ANIMCONT_GPENCIL)
337 filter= (ANIMFILTER_VISIBLE);
339 filter= (ANIMFILTER_VISIBLE | ANIMFILTER_IPOKEYS);
342 ANIM_animdata_filter(&anim_data, filter, ac->data, ac->datatype);
344 /* See if we should be selecting or deselecting */
346 for (ale= anim_data.first; ale; ale= ale->next) {
347 if (ale->type == ANIMTYPE_GPLAYER) {
348 //if (is_gplayer_frame_selected(ale->data)) {
354 if (is_ipo_key_selected(ale->key_data)) {
362 /* Now set the flags */
363 for (ale= anim_data.first; ale; ale= ale->next) {
364 //if (ale->type == ACTTYPE_GPLAYER)
365 // set_gplayer_frame_selection(ale->data, sel);
367 set_ipo_key_selection(ale->key_data, sel);
371 BLI_freelistN(&anim_data);
374 /* ------------------- */
376 static int actkeys_deselectall_exec(bContext *C, wmOperator *op)
380 /* get editor data */
381 if (ANIM_animdata_get_context(C, &ac) == 0)
382 return OPERATOR_CANCELLED;
384 /* 'standard' behaviour - check if selected, then apply relevant selection */
385 if (RNA_boolean_get(op->ptr, "invert"))
386 deselect_action_keys(&ac, 0, 2);
388 deselect_action_keys(&ac, 1, 1);
390 /* set notifier tha things have changed */
391 ED_area_tag_redraw(CTX_wm_area(C)); // FIXME... should be updating 'keyframes' data context or so instead!
393 return OPERATOR_FINISHED;
396 void ACT_OT_keyframes_deselectall (wmOperatorType *ot)
399 ot->name= "Select All";
400 ot->idname= "ACT_OT_keyframes_deselectall";
403 ot->exec= actkeys_deselectall_exec;
404 ot->poll= ED_operator_areaactive;
407 ot->flag= OPTYPE_REGISTER/*|OPTYPE_UNDO*/;
410 RNA_def_property(ot->srna, "invert", PROP_BOOLEAN, PROP_NONE);
413 /* ******************** Border Select Operator **************************** */
414 /* This operator currently works in one of three ways:
415 * -> BKEY - 1) all keyframes within region are selected (ACTKEYS_BORDERSEL_ALLKEYS)
416 * -> ALT-BKEY - depending on which axis of the region was larger...
417 * -> 2) x-axis, so select all frames within frame range (ACTKEYS_BORDERSEL_FRAMERANGE)
418 * -> 3) y-axis, so select all frames within channels that region included (ACTKEYS_BORDERSEL_CHANNELS)
421 /* defines for borderselect mode */
423 ACTKEYS_BORDERSEL_ALLKEYS = 0,
424 ACTKEYS_BORDERSEL_FRAMERANGE,
425 ACTKEYS_BORDERSEL_CHANNELS,
426 } eActKeys_BorderSelect_Mode;
429 static void borderselect_action (bAnimContext *ac, rcti rect, short mode, short selectmode)
431 ListBase anim_data = {NULL, NULL};
436 BeztEditFunc ok_cb, select_cb;
437 View2D *v2d= &ac->ar->v2d;
439 float ymin=0, ymax=(float)(-ACHANNEL_HEIGHT);
441 /* convert mouse coordinates to frame ranges and channel coordinates corrected for view pan/zoom */
442 UI_view2d_region_to_view(v2d, rect.xmin, rect.ymin+2, &rectf.xmin, &rectf.ymin);
443 UI_view2d_region_to_view(v2d, rect.xmax, rect.ymax-2, &rectf.xmax, &rectf.ymax);
446 filter= (ANIMFILTER_VISIBLE | ANIMFILTER_CHANNELS);
447 ANIM_animdata_filter(&anim_data, filter, ac->data, ac->datatype);
449 /* get beztriple editing/validation funcs */
450 select_cb= ANIM_editkeyframes_select(selectmode);
452 if (ELEM(mode, ACTKEYS_BORDERSEL_FRAMERANGE, ACTKEYS_BORDERSEL_ALLKEYS))
453 ok_cb= ANIM_editkeyframes_ok(BEZT_OK_FRAMERANGE);
457 /* init editing data */
458 memset(&bed, 0, sizeof(BeztEditData));
460 /* loop over data, doing border select */
461 for (ale= anim_data.first; ale; ale= ale->next) {
462 Object *nob= ANIM_nla_mapping_get(ac, ale);
464 /* get new vertical minimum extent of channel */
465 ymin= ymax - ACHANNEL_STEP;
467 /* set horizontal range (if applicable) */
468 if (ELEM(mode, ACTKEYS_BORDERSEL_FRAMERANGE, ACTKEYS_BORDERSEL_ALLKEYS)) {
469 /* if channel is mapped in NLA, apply correction */
471 bed.f1= get_action_frame(nob, rectf.xmin);
472 bed.f2= get_action_frame(nob, rectf.xmax);
480 /* perform vertical suitability check (if applicable) */
481 if ( (mode == ACTKEYS_BORDERSEL_FRAMERANGE) ||
482 !((ymax < rectf.ymin) || (ymin > rectf.ymax)) )
484 /* loop over data selecting */
486 if (ale->datatype == ALE_IPO)
487 ipo_keys_bezier_loop(&bed, ale->key_data, ok_cb, select_cb, NULL);
488 else if (ale->datatype == ALE_ICU)
489 icu_keys_bezier_loop(&bed, ale->key_data, ok_cb, select_cb, NULL);
491 else if (ale->type == ANIMTYPE_GROUP) {
492 bActionGroup *agrp= ale->data;
493 bActionChannel *achan;
494 bConstraintChannel *conchan;
496 for (achan= agrp->channels.first; achan && achan->grp==agrp; achan= achan->next) {
497 ipo_keys_bezier_loop(&bed, achan->ipo, ok_cb, select_cb, NULL);
499 for (conchan=achan->constraintChannels.first; conchan; conchan=conchan->next)
500 ipo_keys_bezier_loop(&bed, conchan->ipo, ok_cb, select_cb, NULL);
503 //else if (ale->type == ANIMTYPE_GPLAYER) {
504 // borderselect_gplayer_frames(ale->data, rectf.xmin, rectf.xmax, selectmode);
508 /* set minimum extent to be the maximum of the next channel */
513 BLI_freelistN(&anim_data);
516 /* ------------------- */
518 static int actkeys_borderselect_exec(bContext *C, wmOperator *op)
522 short mode=0, selectmode=0;
525 /* get editor data */
526 if (ANIM_animdata_get_context(C, &ac) == 0)
527 return OPERATOR_CANCELLED;
529 /* get settings from operator */
530 rect.xmin= RNA_int_get(op->ptr, "xmin");
531 rect.ymin= RNA_int_get(op->ptr, "ymin");
532 rect.xmax= RNA_int_get(op->ptr, "xmax");
533 rect.ymax= RNA_int_get(op->ptr, "ymax");
535 event= RNA_int_get(op->ptr, "event_type");
536 if (event == LEFTMOUSE) // FIXME... hardcoded
537 selectmode = SELECT_ADD;
539 selectmode = SELECT_SUBTRACT;
541 /* selection 'mode' depends on whether borderselect region only matters on one axis */
542 if (RNA_boolean_get(op->ptr, "axis_range")) {
543 /* mode depends on which axis of the range is larger to determine which axis to use
544 * - checking this in region-space is fine, as it's fundamentally still going to be a different rect size
545 * - the frame-range select option is favoured over the channel one (x over y), as frame-range one is often
546 * used for tweaking timing when "blocking", while channels is not that useful...
548 if ((rect.xmax - rect.xmin) >= (rect.ymax - rect.ymin))
549 mode= ACTKEYS_BORDERSEL_FRAMERANGE;
551 mode= ACTKEYS_BORDERSEL_CHANNELS;
554 mode= ACTKEYS_BORDERSEL_ALLKEYS;
556 /* apply borderselect action */
557 borderselect_action(&ac, rect, mode, selectmode);
559 return OPERATOR_FINISHED;
562 void ACT_OT_keyframes_borderselect(wmOperatorType *ot)
565 ot->name= "Border Select";
566 ot->idname= "ACT_OT_keyframes_borderselect";
569 ot->invoke= WM_border_select_invoke;
570 ot->exec= actkeys_borderselect_exec;
571 ot->modal= WM_border_select_modal;
573 ot->poll= ED_operator_areaactive;
577 ot->flag= OPTYPE_REGISTER/*|OPTYPE_UNDO*/;
580 RNA_def_property(ot->srna, "event_type", PROP_INT, PROP_NONE);
581 RNA_def_property(ot->srna, "xmin", PROP_INT, PROP_NONE);
582 RNA_def_property(ot->srna, "xmax", PROP_INT, PROP_NONE);
583 RNA_def_property(ot->srna, "ymin", PROP_INT, PROP_NONE);
584 RNA_def_property(ot->srna, "ymax", PROP_INT, PROP_NONE);
586 RNA_def_property(ot->srna, "axis_range", PROP_BOOLEAN, PROP_NONE);
589 /* ******************** Column Select Operator **************************** */
590 /* This operator works in one of four ways:
591 * - 1) select all keyframes in the same frame as a selected one (KKEY)
592 * - 2) select all keyframes in the same frame as the current frame marker (CTRL-KKEY)
593 * - 3) select all keyframes in the same frame as a selected markers (SHIFT-KKEY)
594 * - 4) select all keyframes that occur between selected markers (ALT-KKEY)
597 /* defines for column-select mode */
598 EnumPropertyItem prop_column_select_types[] = {
599 {ACTKEYS_COLUMNSEL_KEYS, "KEYS", "On Selected Keyframes", ""},
600 {ACTKEYS_COLUMNSEL_CFRA, "CFRA", "On Current Frame", ""},
601 {ACTKEYS_COLUMNSEL_MARKERS_COLUMN, "MARKERS_COLUMN", "On Selected Markers", ""},
602 {ACTKEYS_COLUMNSEL_MARKERS_BETWEEN, "MARKERS_BETWEEN", "Between Min/Max Selected Markers", ""},
603 {0, NULL, NULL, NULL}
606 /* ------------------- */
608 /* Selects all visible keyframes between the specified markers */
609 static void markers_selectkeys_between (bAnimContext *ac)
611 ListBase anim_data = {NULL, NULL};
615 BeztEditFunc select_cb;
619 /* get extreme markers */
620 //get_minmax_markers(1, &min, &max); // FIXME... add back markers api!
621 min= ac->scene->r.sfra; // xxx temp code
622 max= ac->scene->r.efra; // xxx temp code
624 if (min==max) return;
628 /* get editing funcs + data */
629 select_cb= ANIM_editkeyframes_select(SELECT_ADD);
630 memset(&bed, 0, sizeof(BeztEditData));
635 filter= (ANIMFILTER_VISIBLE | ANIMFILTER_IPOKEYS);
636 ANIM_animdata_filter(&anim_data, filter, ac->data, ac->datatype);
638 /* select keys in-between */
639 for (ale= anim_data.first; ale; ale= ale->next) {
640 Object *nob= ANIM_nla_mapping_get(ac, ale);
643 ANIM_nla_mapping_apply(nob, ale->key_data, 0, 1);
644 ipo_keys_bezier_loop(&bed, ale->key_data, NULL, select_cb, NULL);
645 ANIM_nla_mapping_apply(nob, ale->key_data, 1, 1);
648 ipo_keys_bezier_loop(&bed, ale->key_data, NULL, select_cb, NULL);
653 BLI_freelistN(&anim_data);
657 /* helper callback for columnselect_action_keys() -> populate list CfraElems with frame numbers from selected beztriples */
658 // TODO: if some other code somewhere needs this, it'll be time to port this over to keyframes_edit.c!!!
659 static short bezt_to_cfraelem(BeztEditData *bed, BezTriple *bezt)
661 /* only if selected */
662 if (bezt->f2 & SELECT) {
663 CfraElem *ce= MEM_callocN(sizeof(CfraElem), "cfraElem");
664 BLI_addtail(&bed->list, ce);
666 ce->cfra= bezt->vec[1][0];
672 /* Selects all visible keyframes in the same frames as the specified elements */
673 static void columnselect_action_keys (bAnimContext *ac, short mode)
675 ListBase anim_data= {NULL, NULL};
679 Scene *scene= ac->scene;
681 BeztEditFunc select_cb, ok_cb;
684 /* initialise keyframe editing data */
685 memset(&bed, 0, sizeof(BeztEditData));
687 /* build list of columns */
689 case ACTKEYS_COLUMNSEL_KEYS: /* list of selected keys */
690 if (ac->datatype == ANIMCONT_GPENCIL) {
691 filter= (ANIMFILTER_VISIBLE);
692 ANIM_animdata_filter(&anim_data, filter, ac->data, ac->datatype);
694 //for (ale= anim_data.first; ale; ale= ale->next)
695 // gplayer_make_cfra_list(ale->data, &elems, 1);
698 filter= (ANIMFILTER_VISIBLE | ANIMFILTER_IPOKEYS);
699 ANIM_animdata_filter(&anim_data, filter, ac->data, ac->datatype);
701 for (ale= anim_data.first; ale; ale= ale->next)
702 ipo_keys_bezier_loop(&bed, ale->key_data, NULL, bezt_to_cfraelem, NULL);
704 BLI_freelistN(&anim_data);
707 case ACTKEYS_COLUMNSEL_CFRA: /* current frame */
708 /* make a single CfraElem for storing this */
709 ce= MEM_callocN(sizeof(CfraElem), "cfraElem");
710 BLI_addtail(&bed.list, ce);
712 ce->cfra= (float)CFRA;
715 case ACTKEYS_COLUMNSEL_MARKERS_COLUMN: /* list of selected markers */
716 // FIXME: markers api needs to be improved for this first!
717 //make_marker_cfra_list(&elems, 1);
718 return; // XXX currently, this does nothing!
721 default: /* invalid option */
725 /* set up BezTriple edit callbacks */
726 select_cb= ANIM_editkeyframes_select(SELECT_ADD);
727 ok_cb= ANIM_editkeyframes_ok(BEZT_OK_FRAME);
729 /* loop through all of the keys and select additional keyframes
730 * based on the keys found to be selected above
732 if (ac->datatype == ANIMCONT_GPENCIL)
733 filter= (ANIMFILTER_VISIBLE);
735 filter= (ANIMFILTER_VISIBLE | ANIMFILTER_ONLYICU);
736 ANIM_animdata_filter(&anim_data, filter, ac->data, ac->datatype);
738 for (ale= anim_data.first; ale; ale= ale->next) {
739 Object *nob= ANIM_nla_mapping_get(ac, ale);
741 /* loop over cfraelems (stored in the BeztEditData->list)
742 * - we need to do this here, as we can apply fewer NLA-mapping conversions
744 for (ce= bed.list.first; ce; ce= ce->next) {
745 /* set frame for validation callback to refer to */
747 bed.f1= get_action_frame(nob, ce->cfra);
751 /* select elements with frame number matching cfraelem */
752 icu_keys_bezier_loop(&bed, ale->key_data, ok_cb, select_cb, NULL);
754 #if 0 // XXX reenable when Grease Pencil stuff is back
755 if (ale->type == ANIMTYPE_GPLAYER) {
756 bGPDlayer *gpl= (bGPDlayer *)ale->data;
759 for (gpf= gpl->frames.first; gpf; gpf= gpf->next) {
760 if (ecfra == gpf->framenum)
761 gpf->flag |= GP_FRAME_SELECT;
765 #endif // XXX reenable when Grease Pencil stuff is back
770 BLI_freelistN(&bed.list);
771 BLI_freelistN(&anim_data);
774 /* ------------------- */
776 static int actkeys_columnselect_exec(bContext *C, wmOperator *op)
781 /* get editor data */
782 if (ANIM_animdata_get_context(C, &ac) == 0)
783 return OPERATOR_CANCELLED;
785 /* action to take depends on the mode */
786 mode= RNA_enum_get(op->ptr, "mode");
788 if (mode == ACTKEYS_COLUMNSEL_MARKERS_BETWEEN)
789 markers_selectkeys_between(&ac);
791 columnselect_action_keys(&ac, mode);
793 /* set notifier tha things have changed */
794 ED_area_tag_redraw(CTX_wm_area(C)); // FIXME... should be updating 'keyframes' data context or so instead!
796 return OPERATOR_FINISHED;
799 void ACT_OT_keyframes_columnselect (wmOperatorType *ot)
804 ot->name= "Select All";
805 ot->idname= "ACT_OT_keyframes_columnselect";
808 ot->exec= actkeys_columnselect_exec;
809 ot->poll= ED_operator_areaactive;
812 ot->flag= OPTYPE_REGISTER/*|OPTYPE_UNDO*/;
815 prop= RNA_def_property(ot->srna, "mode", PROP_ENUM, PROP_NONE);
816 RNA_def_property_enum_items(prop, prop_column_select_types);
819 /* ******************** Mouse-Click Select Operator *********************** */
820 /* This operator works in one of three ways:
821 * - 1) keyframe under mouse - no special modifiers
822 * - 2) all keyframes on the same side of current frame indicator as mouse - ALT modifier
823 * - 3) column select all keyframes in frame under mouse - CTRL modifier
825 * In addition to these basic options, the SHIFT modifier can be used to toggle the
826 * selection mode between replacing the selection (without) and inverting the selection (with).
829 /* defines for left-right select tool */
830 EnumPropertyItem prop_leftright_select_types[] = {
831 {ACTKEYS_LRSEL_TEST, "CHECK", "Check if Select Left or Right", ""},
832 {ACTKEYS_LRSEL_NONE, "OFF", "Don't select", ""},
833 {ACTKEYS_LRSEL_LEFT, "LEFT", "Before current frame", ""},
834 {ACTKEYS_LRSEL_RIGHT, "RIGHT", "After current frame", ""},
835 {0, NULL, NULL, NULL}
838 /* ------------------- */
840 /* option 1) select keyframe directly under mouse */
841 static void mouse_action_keys (bAnimContext *ac, int mval[2], short selectmode)
844 bDopeSheet *ads= NULL;
846 bActionGroup *agrp= NULL;
847 bActionChannel *achan= NULL;
848 bConstraintChannel *conchan= NULL;
852 bGPDlayer *gpl = NULL;
855 BeztEditFunc select_cb, ok_cb;
857 short sel, chan_type = 0;
858 float selx = 0.0f, selxa;
860 /* determine what type of data we are operating on */
861 if (ac->datatype == ANIMCONT_ACTION)
862 act= (bAction *)ac->data;
863 else if (ac->datatype == ANIMCONT_DOPESHEET)
864 ads= (bDopeSheet *)ac->data;
865 else if (ac->datatype == ANIMCONT_GPENCIL)
866 gpd= (bGPdata *)ac->data;
868 /* get channel and selection info */
869 anim_channel= get_nearest_action_key(ac, mval, &selx, &sel, &chan_type, &achan);
870 if (anim_channel == NULL)
875 icu= (IpoCurve *)anim_channel;
877 case ANIMTYPE_CONCHAN:
878 conchan= (bConstraintChannel *)anim_channel;
881 achan= (bActionChannel *)anim_channel;
884 agrp= (bActionGroup *)anim_channel;
887 ipo= ((Material *)anim_channel)->ipo;
890 ipo= ((Lamp *)anim_channel)->ipo;
893 ipo= ((Camera *)anim_channel)->ipo;
896 ipo= ((Curve *)anim_channel)->ipo;
898 case ANIMTYPE_DSSKEY:
899 ipo= ((Key *)anim_channel)->ipo;
901 case ANIMTYPE_FILLACTD:
902 act= (bAction *)anim_channel;
904 case ANIMTYPE_FILLIPOD:
905 ipo= ((Object *)anim_channel)->ipo;
907 case ANIMTYPE_OBJECT:
908 ob= ((Base *)anim_channel)->object;
910 case ANIMTYPE_GPLAYER:
911 gpl= (bGPDlayer *)anim_channel;
917 /* for replacing selection, firstly need to clear existing selection */
918 if (selectmode == SELECT_REPLACE) {
919 selectmode = SELECT_ADD;
921 deselect_action_keys(ac, 0, 0);
923 if (ELEM(ac->datatype, ANIMCONT_ACTION, ANIMCONT_DOPESHEET)) {
924 //deselect_action_channels(0);
926 /* Highlight either an Action-Channel or Action-Group */
928 achan->flag |= ACHAN_SELECTED;
929 //hilight_channel(act, achan, 1);
930 //select_poseelement_by_name(achan->name, 2); /* 2 is activate */
933 agrp->flag |= AGRP_SELECTED;
934 //set_active_actiongroup(act, agrp, 1);
937 else if (ac->datatype == ANIMCONT_GPENCIL) {
938 //deselect_action_channels(0);
940 /* Highlight gpencil layer */
941 gpl->flag |= GP_LAYER_SELECT;
942 //gpencil_layer_setactive(gpd, gpl);
946 /* get functions for selecting keyframes */
947 select_cb= ANIM_editkeyframes_select(selectmode);
948 ok_cb= ANIM_editkeyframes_ok(BEZT_OK_FRAME);
949 memset(&bed, 0, sizeof(BeztEditData));
952 /* apply selection to keyframes */
954 icu_keys_bezier_loop(&bed, icu, ok_cb, select_cb, NULL);
956 ipo_keys_bezier_loop(&bed, ipo, ok_cb, select_cb, NULL);
958 ipo_keys_bezier_loop(&bed, conchan->ipo, ok_cb, select_cb, NULL);
960 ipo_keys_bezier_loop(&bed, achan->ipo, ok_cb, select_cb, NULL);
962 for (achan= agrp->channels.first; achan && achan->grp==agrp; achan= achan->next) {
963 ipo_keys_bezier_loop(&bed, achan->ipo, ok_cb, select_cb, NULL);
965 for (conchan=achan->constraintChannels.first; conchan; conchan=conchan->next)
966 ipo_keys_bezier_loop(&bed, conchan->ipo, ok_cb, select_cb, NULL);
970 for (achan= act->chanbase.first; achan; achan= achan->next) {
971 ipo_keys_bezier_loop(&bed, achan->ipo, ok_cb, select_cb, NULL);
973 for (conchan=achan->constraintChannels.first; conchan; conchan=conchan->next)
974 ipo_keys_bezier_loop(&bed, conchan->ipo, ok_cb, select_cb, NULL);
980 ipo_keys_bezier_loop(&bed, ob->ipo, ok_cb, select_cb, NULL);
984 selxa= get_action_frame(ob, selx);
987 for (achan= ob->action->chanbase.first; achan; achan= achan->next) {
988 ipo_keys_bezier_loop(&bed, achan->ipo, ok_cb, select_cb, NULL);
990 for (conchan=achan->constraintChannels.first; conchan; conchan=conchan->next)
991 ipo_keys_bezier_loop(&bed, conchan->ipo, ok_cb, select_cb, NULL);
995 if (ob->constraintChannels.first) {
998 for (conchan=ob->constraintChannels.first; conchan; conchan=conchan->next)
999 ipo_keys_bezier_loop(&bed, conchan->ipo, ok_cb, select_cb, NULL);
1003 // select_gpencil_frame(gpl, (int)selx, selectmode);
1006 /* Option 2) Selects all the keyframes on either side of the current frame (depends on which side the mouse is on) */
1007 static void selectkeys_leftright (bAnimContext *ac, short leftright, short select_mode)
1009 ListBase anim_data = {NULL, NULL};
1013 BeztEditFunc ok_cb, select_cb;
1015 Scene *scene= ac->scene;
1017 /* if select mode is replace, deselect all keyframes first */
1018 if (select_mode==SELECT_REPLACE) {
1019 select_mode=SELECT_ADD;
1020 deselect_action_keys(ac, 0, 0);
1023 /* set callbacks and editing data */
1024 ok_cb= ANIM_editkeyframes_ok(BEZT_OK_FRAMERANGE);
1025 select_cb= ANIM_editkeyframes_select(select_mode);
1027 memset(&bed, 0, sizeof(BeztEditFunc));
1028 if (leftright == ACTKEYS_LRSEL_LEFT) {
1029 bed.f1 = -MAXFRAMEF;
1030 bed.f2 = (float)(CFRA + 0.1f);
1033 bed.f1 = (float)(CFRA - 0.1f);
1038 if (ac->datatype == ANIMCONT_GPENCIL)
1039 filter= (ANIMFILTER_VISIBLE);
1041 filter= (ANIMFILTER_VISIBLE | ANIMFILTER_IPOKEYS);
1042 ANIM_animdata_filter(&anim_data, filter, ac->data, ac->datatype);
1044 /* select keys on the side where most data occurs */
1045 for (ale= anim_data.first; ale; ale= ale->next) {
1046 Object *nob= ANIM_nla_mapping_get(ac, ale);
1049 ANIM_nla_mapping_apply(nob, ale->key_data, 0, 1);
1050 ipo_keys_bezier_loop(&bed, ale->key_data, ok_cb, select_cb, NULL);
1051 ANIM_nla_mapping_apply(nob, ale->key_data, 1, 1);
1053 //else if (ale->type == ANIMTYPE_GPLAYER)
1054 // borderselect_gplayer_frames(ale->data, min, max, SELECT_ADD);
1056 ipo_keys_bezier_loop(&bed, ale->key_data, ok_cb, select_cb, NULL);
1060 BLI_freelistN(&anim_data);
1063 /* Option 3) Selects all visible keyframes in the same frame as the mouse click */
1064 static void mouse_columnselect_action_keys (bAnimContext *ac, float selx)
1066 ListBase anim_data= {NULL, NULL};
1070 BeztEditFunc select_cb, ok_cb;
1073 /* initialise keyframe editing data */
1074 memset(&bed, 0, sizeof(BeztEditData));
1076 /* set up BezTriple edit callbacks */
1077 select_cb= ANIM_editkeyframes_select(SELECT_ADD);
1078 ok_cb= ANIM_editkeyframes_ok(BEZT_OK_FRAME);
1080 /* loop through all of the keys and select additional keyframes
1081 * based on the keys found to be selected above
1083 if (ac->datatype == ANIMCONT_GPENCIL)
1084 filter= (ANIMFILTER_VISIBLE);
1086 filter= (ANIMFILTER_VISIBLE | ANIMFILTER_ONLYICU);
1087 ANIM_animdata_filter(&anim_data, filter, ac->data, ac->datatype);
1089 for (ale= anim_data.first; ale; ale= ale->next) {
1090 Object *nob= ANIM_nla_mapping_get(ac, ale);
1092 /* set frame for validation callback to refer to */
1094 bed.f1= get_action_frame(nob, selx);
1098 /* select elements with frame number matching cfraelem */
1099 icu_keys_bezier_loop(&bed, ale->key_data, ok_cb, select_cb, NULL);
1101 #if 0 // XXX reenable when Grease Pencil stuff is back
1102 if (ale->type == ANIMTYPE_GPLAYER) {
1103 bGPDlayer *gpl= (bGPDlayer *)ale->data;
1106 for (gpf= gpl->frames.first; gpf; gpf= gpf->next) {
1107 if (ecfra == gpf->framenum)
1108 gpf->flag |= GP_FRAME_SELECT;
1112 #endif // XXX reenable when Grease Pencil stuff is back
1116 BLI_freelistN(&bed.list);
1117 BLI_freelistN(&anim_data);
1120 /* ------------------- */
1122 /* handle clicking */
1123 static int actkeys_clickselect_invoke(bContext *C, wmOperator *op, wmEvent *event)
1132 /* get editor data */
1133 if (ANIM_animdata_get_context(C, &ac) == 0)
1134 return OPERATOR_CANCELLED;
1136 /* get useful pointers from animation context data */
1141 /* get mouse coordinates (in region coordinates) */
1142 mval[0]= (event->x - ar->winrct.xmin);
1143 mval[1]= (event->y - ar->winrct.ymin);
1145 /* select mode is either replace (deselect all, then add) or add/extend */
1146 // XXX this is currently only available for normal select only
1147 if (RNA_boolean_get(op->ptr, "extend_select"))
1148 selectmode= SELECT_INVERT;
1150 selectmode= SELECT_REPLACE;
1152 /* figure out action to take */
1153 if (RNA_enum_get(op->ptr, "left_right")) {
1154 /* select all keys on same side of current frame as mouse */
1157 UI_view2d_region_to_view(v2d, mval[0], mval[1], &x, NULL);
1159 RNA_int_set(op->ptr, "left_right", ACTKEYS_LRSEL_LEFT);
1161 RNA_int_set(op->ptr, "left_right", ACTKEYS_LRSEL_RIGHT);
1163 selectkeys_leftright(&ac, RNA_enum_get(op->ptr, "left_right"), selectmode);
1165 else if (RNA_boolean_get(op->ptr, "column_select")) {
1166 /* select all the keyframes that occur on the same frame as where the mouse clicked */
1169 /* figure out where (the frame) the mouse clicked, and set all keyframes in that frame */
1170 UI_view2d_region_to_view(v2d, mval[0], mval[1], &x, NULL);
1171 mouse_columnselect_action_keys(&ac, x);
1174 /* select keyframe under mouse */
1175 mouse_action_keys(&ac, mval, selectmode);
1176 // XXX activate transform...
1179 /* set notifier tha things have changed */
1180 ED_area_tag_redraw(CTX_wm_area(C)); // FIXME... should be updating 'keyframes' data context or so instead!
1182 return OPERATOR_FINISHED;
1185 void ACT_OT_keyframes_clickselect (wmOperatorType *ot)
1190 ot->name= "Mouse Select Keys";
1191 ot->idname= "ACT_OT_keyframes_clickselect";
1194 ot->invoke= actkeys_clickselect_invoke;
1195 ot->poll= ED_operator_areaactive;
1198 prop= RNA_def_property(ot->srna, "left_right", PROP_ENUM, PROP_NONE); // ALTKEY
1199 //RNA_def_property_enum_items(prop, prop_actkeys_clickselect_items);
1200 prop= RNA_def_property(ot->srna, "extend_select", PROP_BOOLEAN, PROP_NONE); // SHIFTKEY
1201 prop= RNA_def_property(ot->srna, "column_select", PROP_BOOLEAN, PROP_NONE); // CTRLKEY
1204 /* ************************************************************************** */