Blender V5.3
anim_channels_edit.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2009 Blender Authors, Joshua Leung. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <algorithm>
10#include <cstdio>
11#include <cstdlib>
12#include <cstring>
13
14#include "MEM_guardedalloc.h"
15
16#include "BLI_listbase.hh"
17#include "BLI_math_base_c.hh"
18#include "BLI_span.hh"
19#include "BLI_string_utf8.hh"
20#include "BLI_utildefines.hh"
21
22#include "DNA_anim_types.h"
24#include "DNA_key_types.h"
25#include "DNA_mask_types.h"
26#include "DNA_object_types.h"
27#include "DNA_scene_types.h"
28
29#include "RNA_access.hh"
30#include "RNA_define.hh"
31#include "RNA_path.hh"
32
33#include "BKE_action.hh"
34#include "BKE_anim_data.hh"
35#include "BKE_annotations.h"
36#include "BKE_context.hh"
37#include "BKE_fcurve.hh"
38#include "BKE_global.hh"
39#include "BKE_grease_pencil.hh"
40#include "BKE_layer.hh"
41#include "BKE_lib_id.hh"
42#include "BKE_library.hh"
43#include "BKE_mask.hh"
44#include "BKE_nla.hh"
45#include "BKE_report.hh"
46#include "BKE_scene.hh"
47#include "BKE_screen.hh"
48
49#include "ANIM_action.hh"
50#include "ANIM_action_legacy.hh"
51
52#include "DEG_depsgraph.hh"
54
55#include "UI_interface.hh"
56#include "UI_view2d.hh"
57
58#include "ED_armature.hh"
59#include "ED_keyframes_edit.hh" /* XXX move the select modes out of there! */
60#include "ED_markers.hh"
61#include "ED_object.hh"
62#include "ED_screen.hh"
63#include "ED_select_utils.hh"
64
65#include "ANIM_animdata.hh"
66#include "ANIM_fcurve.hh"
67
68#include "WM_api.hh"
69#include "WM_message.hh"
70#include "WM_types.hh"
71
72#include "BLT_translation.hh"
73
74namespace blender {
75
76/* -------------------------------------------------------------------- */
79
81 SpaceLink *space_link,
82 Scene *scene,
83 ID *id,
84 const bool include_handles,
85 const float range[2],
86 rctf *r_bounds)
87{
88 const bool fcu_selection_only = false;
89 const bool found_bounds = BKE_fcurve_calc_bounds(
90 fcu, fcu_selection_only, include_handles, range, r_bounds);
91
92 if (!found_bounds) {
93 return false;
94 }
95
96 const short mapping_flag = ANIM_get_normalization_flags(space_link);
97
98 float offset;
99 const float unit_fac = ANIM_unit_mapping_get_factor(scene, id, fcu, mapping_flag, &offset);
100
101 r_bounds->ymin = (r_bounds->ymin + offset) * unit_fac;
102 r_bounds->ymax = (r_bounds->ymax + offset) * unit_fac;
103
104 const float min_height = 0.01f;
105 const float height = BLI_rctf_size_y(r_bounds);
106 if (height < min_height) {
107 r_bounds->ymin -= (min_height - height) / 2;
108 r_bounds->ymax += (min_height - height) / 2;
109 }
110
111 return true;
112}
113
114static bool get_gpencil_bounds(bGPDlayer *gpl, const float range[2], rctf *r_bounds)
115{
116 bool found_start = false;
117 int start_frame = 0;
118 int end_frame = 1;
119 for (bGPDframe &gpf : gpl->frames) {
120 if (gpf.framenum < range[0]) {
121 continue;
122 }
123 if (gpf.framenum > range[1]) {
124 break;
125 }
126 if (!found_start) {
127 start_frame = gpf.framenum;
128 found_start = true;
129 }
130 end_frame = gpf.framenum;
131 }
132 r_bounds->xmin = start_frame;
133 r_bounds->xmax = end_frame;
134 r_bounds->ymin = 0;
135 r_bounds->ymax = 1;
136
137 return found_start;
138}
139
141 const float range[2],
142 rctf *r_bounds)
143{
144 using namespace blender::bke::greasepencil;
145 const Layer &layer = gplayer->wrap();
146
147 bool found_start = false;
148 int start_frame = 0;
149 int end_frame = 1;
150
151 for (const FramesMapKeyT key : layer.sorted_keys()) {
152 if (key < range[0]) {
153 continue;
154 }
155 if (key > range[1]) {
156 break;
157 }
158
159 if (!found_start) {
160 start_frame = key;
161 found_start = true;
162 }
163 end_frame = key;
164 }
165 r_bounds->xmin = start_frame;
166 r_bounds->xmax = end_frame;
167 r_bounds->ymin = 0;
168 r_bounds->ymax = 1;
169
170 return found_start;
171}
172
174 bAnimListElem *ale,
175 const float range[2],
176 const bool include_handles,
177 rctf *r_bounds)
178{
179 bool found_bounds = false;
180 switch (ale->datatype) {
181 case ALE_GPFRAME: {
182 bGPDlayer *gpl = static_cast<bGPDlayer *>(ale->data);
183 found_bounds = get_gpencil_bounds(gpl, range, r_bounds);
184 break;
185 }
187 found_bounds = get_grease_pencil_layer_bounds(
188 static_cast<const GreasePencilLayer *>(ale->data), range, r_bounds);
189 break;
190
191 case ALE_FCURVE: {
192 FCurve *fcu = static_cast<FCurve *>(ale->key_data);
193 found_bounds = get_normalized_fcurve_bounds(
194 fcu, ac->sl, ac->scene, ale->id, include_handles, range, r_bounds);
195 if (found_bounds) {
196 r_bounds->xmin = ANIM_nla_tweakedit_remap(ale, r_bounds->xmin, NLATIME_CONVERT_MAP);
197 r_bounds->xmax = ANIM_nla_tweakedit_remap(ale, r_bounds->xmax, NLATIME_CONVERT_MAP);
198 }
199 break;
200 }
201 case ALE_NONE:
202 case ALE_MASKLAY:
203 case ALE_NLASTRIP:
204 case ALE_ALL:
205 case ALE_SCE:
206 case ALE_OB:
207 case ALE_ACT:
208 case ALE_GROUP:
210 case ALE_ACTION_SLOT:
213 return false;
214 }
215 return found_bounds;
216}
217
218/* Pad the given rctf with regions that could block the view.
219 * For example Markers and Time Scrubbing. */
221{
222 BLI_rctf_scale(bounds, 1.1f);
223
224 const float pad_top = UI_TIME_SCRUB_MARGIN_Y;
225 const float pad_bottom = BLI_listbase_is_empty(ED_context_get_markers(C)) ?
228 BLI_rctf_pad_y(bounds, region->winy, pad_bottom, pad_top);
229}
230
232
233/* -------------------------------------------------------------------- */
236
238 void *data,
239 eAnimCont_Types datatype,
241 void *channel_data,
242 eAnim_ChannelType channel_type)
243{
244 /* TODO: extend for animdata types. */
245
246 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
247 bAnimListElem *ale;
248
249 /* try to build list of filtered items */
250 ANIM_animdata_filter(ac, &anim_data, filter, data, datatype);
251 if (anim_data.is_empty()) {
252 return;
253 }
254
255 /* only clear the 'active' flag for the channels of the same type */
256 for (ale = anim_data.first(); ale; ale = ale->next) {
257 /* skip if types don't match */
258 if (channel_type != ale->type) {
259 continue;
260 }
261
262 /* flag to set depends on type */
263 switch (ale->type) {
264 case ANIMTYPE_GROUP: {
265 bActionGroup *agrp = static_cast<bActionGroup *>(ale->data);
266
268 break;
269 }
270 case ANIMTYPE_FCURVE:
271 case ANIMTYPE_NLACURVE: {
272 FCurve *fcu = static_cast<FCurve *>(ale->data);
273
275 break;
276 }
277 case ANIMTYPE_NLATRACK: {
278 NlaTrack *nlt = static_cast<NlaTrack *>(ale->data);
279
281 break;
282 }
283 case ANIMTYPE_FILLACTD: /* Action Expander */
284 case ANIMTYPE_FILLACT_LAYERED: /* Animation Expander */
285 case ANIMTYPE_DSMAT: /* Datablock AnimData Expanders */
286 case ANIMTYPE_DSLAM:
287 case ANIMTYPE_DSCAM:
289 case ANIMTYPE_DSCUR:
290 case ANIMTYPE_DSSKEY:
291 case ANIMTYPE_DSWOR:
292 case ANIMTYPE_DSPART:
293 case ANIMTYPE_DSMBALL:
294 case ANIMTYPE_DSARM:
295 case ANIMTYPE_DSMESH:
296 case ANIMTYPE_DSTEX:
297 case ANIMTYPE_DSLAT:
299 case ANIMTYPE_DSSPK:
301 case ANIMTYPE_DSMCLIP:
302 case ANIMTYPE_DSHAIR:
306 case ANIMTYPE_NLAACTION: {
307 /* need to verify that this data is valid for now */
308 if (ale->adt) {
310 }
311 break;
312 }
313 case ANIMTYPE_GPLAYER: {
314 bGPDlayer *gpl = static_cast<bGPDlayer *>(ale->data);
315
317 break;
318 }
319 case ANIMTYPE_NONE:
322 case ANIMTYPE_SUMMARY:
323 case ANIMTYPE_SCENE:
324 case ANIMTYPE_OBJECT:
328 case ANIMTYPE_DSNTREE:
335 case ANIMTYPE_PALETTE:
337 break;
338 }
339 }
340
341 /* set active flag */
342 if (channel_data) {
343 switch (channel_type) {
344 case ANIMTYPE_GROUP: {
345 bActionGroup *agrp = static_cast<bActionGroup *>(channel_data);
346 agrp->flag |= AGRP_ACTIVE;
347 break;
348 }
349 case ANIMTYPE_FCURVE:
350 case ANIMTYPE_NLACURVE: {
351 FCurve *fcu = static_cast<FCurve *>(channel_data);
352 fcu->flag |= FCURVE_ACTIVE;
353 break;
354 }
355 case ANIMTYPE_NLATRACK: {
356 NlaTrack *nlt = static_cast<NlaTrack *>(channel_data);
357 nlt->flag |= NLATRACK_ACTIVE;
358 break;
359 }
361 /* ANIMTYPE_ACTION_SLOT is not supported by this function (because the to-be-activated
362 * bAnimListElement is not passed here, only sub-fields of it), just call
363 * Action::slot_active_set() directly. */
364 break;
365 case ANIMTYPE_FILLACTD: /* Action Expander */
366 case ANIMTYPE_FILLACT_LAYERED: /* Animation Expander */
367 case ANIMTYPE_DSMAT: /* Datablock AnimData Expanders */
368 case ANIMTYPE_DSLAM:
369 case ANIMTYPE_DSCAM:
371 case ANIMTYPE_DSCUR:
372 case ANIMTYPE_DSSKEY:
373 case ANIMTYPE_DSWOR:
374 case ANIMTYPE_DSPART:
375 case ANIMTYPE_DSMBALL:
376 case ANIMTYPE_DSARM:
377 case ANIMTYPE_DSMESH:
378 case ANIMTYPE_DSLAT:
380 case ANIMTYPE_DSSPK:
381 case ANIMTYPE_DSNTREE:
382 case ANIMTYPE_DSTEX:
384 case ANIMTYPE_DSMCLIP:
385 case ANIMTYPE_DSHAIR:
389 case ANIMTYPE_NLAACTION: {
390 /* need to verify that this data is valid for now */
391 if (ale && ale->adt) {
392 ale->adt->flag |= ADT_UI_ACTIVE;
393 }
394 break;
395 }
396
397 case ANIMTYPE_GPLAYER: {
398 bGPDlayer *gpl = static_cast<bGPDlayer *>(channel_data);
399 gpl->flag |= GP_LAYER_ACTIVE;
400 break;
401 }
402 /* unhandled currently, but may be interesting */
405 break;
406
407 /* other types */
408 default:
409 break;
410 }
411 }
412
413 /* clean up */
414 ANIM_animdata_freelist(&anim_data);
415}
416
418{
419 switch (ale->type) {
420 case ANIMTYPE_FILLACTD: /* Action Expander */
421 case ANIMTYPE_FILLACT_LAYERED: /* Animation Expander */
422 case ANIMTYPE_DSMAT: /* Datablock AnimData Expanders */
423 case ANIMTYPE_DSLAM:
424 case ANIMTYPE_DSCAM:
426 case ANIMTYPE_DSCUR:
427 case ANIMTYPE_DSSKEY:
428 case ANIMTYPE_DSWOR:
429 case ANIMTYPE_DSPART:
430 case ANIMTYPE_DSMBALL:
431 case ANIMTYPE_DSARM:
432 case ANIMTYPE_DSMESH:
433 case ANIMTYPE_DSNTREE:
434 case ANIMTYPE_DSTEX:
435 case ANIMTYPE_DSLAT:
437 case ANIMTYPE_DSSPK:
439 case ANIMTYPE_DSMCLIP:
440 case ANIMTYPE_DSHAIR:
444 case ANIMTYPE_NLAACTION: {
445 return ale->adt && (ale->adt->flag & ADT_UI_ACTIVE);
446 }
447 case ANIMTYPE_GROUP: {
448 bActionGroup *argp = static_cast<bActionGroup *>(ale->data);
449 return argp->flag & AGRP_ACTIVE;
450 }
451 case ANIMTYPE_FCURVE:
452 case ANIMTYPE_NLACURVE: {
453 FCurve *fcu = static_cast<FCurve *>(ale->data);
454 return fcu->flag & FCURVE_ACTIVE;
455 }
456 case ANIMTYPE_GPLAYER: {
457 bGPDlayer *gpl = static_cast<bGPDlayer *>(ale->data);
458 return gpl->flag & GP_LAYER_ACTIVE;
459 }
461 GreasePencil *grease_pencil = reinterpret_cast<GreasePencil *>(ale->id);
462 return grease_pencil->is_layer_active(static_cast<bke::greasepencil::Layer *>(ale->data));
463 }
465 animrig::Slot *slot = reinterpret_cast<animrig::Slot *>(ale->data);
466 return slot->is_active();
467 }
468 /* These channel types do not have active flags. */
469 case ANIMTYPE_NONE:
472 case ANIMTYPE_SUMMARY:
473 case ANIMTYPE_SCENE:
474 case ANIMTYPE_OBJECT:
483 case ANIMTYPE_PALETTE:
485 break;
486 }
487 return false;
488}
489
490/* change_active determines whether to change the active bone of the armature when selecting pose
491 * channels. It is false during range selection otherwise true. */
493 bActionGroup *agrp,
494 bAnimListElem *ale,
495 const bool change_active)
496{
497 /* Armatures-Specific Feature:
498 * See mouse_anim_channels() -> ANIMTYPE_GROUP case for more details (#38737)
499 */
500 if ((ac->filters.flag & ADS_FILTER_ONLYSEL) == 0) {
501 if ((ale->id) && (GS(ale->id->name) == ID_OB)) {
502 Object *ob = reinterpret_cast<Object *>(ale->id);
503 if (ob->type == OB_ARMATURE) {
504 /* Assume for now that any group with corresponding name is what we want
505 * (i.e. for an armature whose location is animated, things would break
506 * if the user were to add a bone named "Location").
507 *
508 * TODO: check the first F-Curve or so to be sure...
509 */
511
512 if (agrp->flag & AGRP_SELECTED) {
513 ED_pose_bone_select(ob, pchan, true, change_active);
514 }
515 else {
516 ED_pose_bone_select(ob, pchan, false, change_active);
517 }
518 }
519 }
520 }
521}
522
523static ListBaseT<bAnimListElem> anim_channels_for_selection(bAnimContext *ac)
524{
525 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
526
527 /* filter data */
528 /* NOTE: no list visible, otherwise, we get dangling */
531 ac, &anim_data, eAnimFilter_Flags(filter), ac->data, eAnimCont_Types(ac->datatype));
532
533 return anim_data;
534}
535
537 const ListBaseT<bAnimListElem> anim_data)
538{
539 /* See if we should be selecting or deselecting. */
540 for (bAnimListElem &ale : anim_data) {
541 switch (ale.type) {
542 case ANIMTYPE_SCENE:
543 if (ale.flag & SCE_DS_SELECTED) {
545 }
546 break;
547 case ANIMTYPE_OBJECT:
548#if 0 /* for now, do not take object selection into account, since it gets too annoying */
549 if (ale->flag & SELECT) {
551 }
552#endif
553 break;
554 case ANIMTYPE_GROUP:
555 if (ale.flag & AGRP_SELECTED) {
557 }
558 break;
559 case ANIMTYPE_FCURVE:
561 if (ale.flag & FCURVE_SELECTED) {
563 }
564 break;
566 if (ale.flag & KEYBLOCK_SEL) {
568 }
569 break;
571 if (ale.flag & NLATRACK_SELECTED) {
573 }
574 break;
576 using namespace blender::animrig;
577 if (static_cast<Slot *>(ale.data)->is_selected()) {
579 }
580 break;
581 }
582 case ANIMTYPE_FILLACTD: /* Action Expander */
583 case ANIMTYPE_FILLACT_LAYERED: /* Animation Expander */
584 case ANIMTYPE_DSMAT: /* Datablock AnimData Expanders */
585 case ANIMTYPE_DSLAM:
586 case ANIMTYPE_DSCAM:
588 case ANIMTYPE_DSCUR:
589 case ANIMTYPE_DSSKEY:
590 case ANIMTYPE_DSWOR:
591 case ANIMTYPE_DSPART:
592 case ANIMTYPE_DSMBALL:
593 case ANIMTYPE_DSARM:
594 case ANIMTYPE_DSMESH:
595 case ANIMTYPE_DSNTREE:
596 case ANIMTYPE_DSTEX:
597 case ANIMTYPE_DSLAT:
599 case ANIMTYPE_DSSPK:
601 case ANIMTYPE_DSMCLIP:
602 case ANIMTYPE_DSHAIR:
606 case ANIMTYPE_NLAACTION: {
607 if ((ale.adt) && (ale.adt->flag & ADT_UI_SELECTED)) {
609 }
610 break;
611 }
612 case ANIMTYPE_GPLAYER:
613 if (ale.flag & GP_LAYER_SELECT) {
615 }
616 break;
618 if (ale.flag & MASK_LAYERFLAG_SELECT) {
620 }
621 break;
622 case ANIMTYPE_NONE:
625 case ANIMTYPE_SUMMARY:
632 case ANIMTYPE_PALETTE:
634 break;
635 }
636 }
637
639}
640
651template<typename T>
652static void templated_selection_state_update(T &selectable_thing,
653 const eAnimChannels_SetFlag selectmode)
654{
655 switch (selectmode) {
657 selectable_thing.set_selected(!selectable_thing.is_selected());
658 break;
660 selectable_thing.set_selected(true);
661 break;
662 /* You would probably expect "extend range" to select rather than deselect,
663 * and "toggle" to behave the same as "invert", because that's what a sane
664 * system would do. However, this function is used in the same places as the
665 * `ACHANNEL_SET_FLAG` macro, and therefore reproduces its logic. Note that
666 * in the "extend range" case this is actually functionally important,
667 * because `anim_channels_select_set()` below uses that case to *deselect
668 * everything* before `animchannel_select_range()` later does the actual
669 * selection of the channels in the range. */
673 selectable_thing.set_selected(false);
674 break;
675 }
676}
677
679 const ListBaseT<bAnimListElem> anim_data,
681{
682 /* Boolean to keep active channel status during range selection. */
683 const bool change_active = (sel != ACHANNEL_SETFLAG_EXTEND_RANGE);
684
685 for (bAnimListElem &ale : anim_data) {
686 switch (ale.type) {
687 case ANIMTYPE_SCENE: {
688 if (change_active) {
689 break;
690 }
691 Scene *scene = static_cast<Scene *>(ale.data);
692
694
695 if (scene->adt) {
697 }
698 break;
699 }
700 case ANIMTYPE_OBJECT: {
701#if 0 /* for now, do not take object selection into account, since it gets too annoying */
702 Base *base = (Base *)ale->data;
703 Object *ob = base->object;
704
705 ACHANNEL_SET_FLAG(base, sel, SELECT);
706 ACHANNEL_SET_FLAG(ob, sel, SELECT);
707
708 if (ob->adt) {
710 }
711#endif
712 break;
713 }
714 case ANIMTYPE_GROUP: {
715 bActionGroup *agrp = static_cast<bActionGroup *>(ale.data);
717 select_pchan_for_action_group(ac, agrp, &ale, change_active);
718 if (change_active) {
719 agrp->flag &= ~AGRP_ACTIVE;
720 }
721 break;
722 }
723 case ANIMTYPE_FCURVE:
724 case ANIMTYPE_NLACURVE: {
725 FCurve *fcu = static_cast<FCurve *>(ale.data);
726
728 if (!(fcu->flag & FCURVE_SELECTED) && change_active) {
729 /* Only erase the ACTIVE flag when deselecting. This ensures that "select all curves"
730 * retains the currently active curve. */
731 fcu->flag &= ~FCURVE_ACTIVE;
732 }
733 break;
734 }
735 case ANIMTYPE_SHAPEKEY: {
736 KeyBlock *kb = static_cast<KeyBlock *>(ale.data);
737
739 break;
740 }
741 case ANIMTYPE_NLATRACK: {
742 NlaTrack *nlt = static_cast<NlaTrack *>(ale.data);
743
745 nlt->flag &= ~NLATRACK_ACTIVE;
746 break;
747 }
749 animrig::Slot *slot = static_cast<animrig::Slot *>(ale.data);
751 break;
752 }
753 case ANIMTYPE_FILLACTD: /* Action Expander */
754 case ANIMTYPE_FILLACT_LAYERED: /* Animation Expander */
755 case ANIMTYPE_DSMAT: /* Datablock AnimData Expanders */
756 case ANIMTYPE_DSLAM:
757 case ANIMTYPE_DSCAM:
759 case ANIMTYPE_DSCUR:
760 case ANIMTYPE_DSSKEY:
761 case ANIMTYPE_DSWOR:
762 case ANIMTYPE_DSPART:
763 case ANIMTYPE_DSMBALL:
764 case ANIMTYPE_DSARM:
765 case ANIMTYPE_DSMESH:
766 case ANIMTYPE_DSNTREE:
767 case ANIMTYPE_DSTEX:
768 case ANIMTYPE_DSLAT:
770 case ANIMTYPE_DSSPK:
772 case ANIMTYPE_DSMCLIP:
773 case ANIMTYPE_DSHAIR:
777 case ANIMTYPE_NLAACTION: {
778 /* need to verify that this data is valid for now */
779 if (ale.adt) {
780 ACHANNEL_SET_FLAG(ale.adt, sel, ADT_UI_SELECTED);
781 if (change_active) {
782 ale.adt->flag &= ~ADT_UI_ACTIVE;
783 }
784 }
785 break;
786 }
788 using namespace blender::bke::greasepencil;
789 Layer *layer = static_cast<Layer *>(ale.data);
791 break;
792 }
793 case ANIMTYPE_GPLAYER: {
794 bGPDlayer *gpl = static_cast<bGPDlayer *>(ale.data);
795
797 break;
798 }
799 case ANIMTYPE_MASKLAYER: {
800 MaskLayer *masklay = static_cast<MaskLayer *>(ale.data);
801
803 break;
804 }
805 case ANIMTYPE_NONE:
808 case ANIMTYPE_SUMMARY:
814 case ANIMTYPE_PALETTE:
816 break;
817 }
818 }
819}
820
822{
823 ListBaseT<bAnimListElem> anim_data = anim_channels_for_selection(ac);
824 anim_channels_select_set(ac, anim_data, sel);
825 ANIM_animdata_freelist(&anim_data);
826}
827
829{
830 ListBaseT<bAnimListElem> anim_data = anim_channels_for_selection(ac);
832 anim_channels_select_set(ac, anim_data, sel);
833 ANIM_animdata_freelist(&anim_data);
834}
835
837
838/* -------------------------------------------------------------------- */
841
842/* Copy a certain channel setting to parents of the modified channel. */
844 const eAnimChannel_Settings setting,
845 const eAnimChannels_SetFlag mode,
846 bAnimListElem *const match,
847 const int matchLevel)
848{
849 /* flush up?
850 *
851 * For Visibility:
852 * - only flush up if the current state is now enabled (positive 'on' state is default)
853 * (otherwise, it's too much work to force the parents to be inactive too)
854 *
855 * For everything else:
856 * - only flush up if the current state is now disabled (negative 'off' state is default)
857 * (otherwise, it's too much work to force the parents to be active too)
858 */
859 if (setting == ACHANNEL_SETTING_VISIBLE) {
860 if (mode == ACHANNEL_SETFLAG_CLEAR) {
861 return;
862 }
863 }
864 else {
865 if (mode != ACHANNEL_SETFLAG_CLEAR) {
866 return;
867 }
868 }
869
870 /* Go backwards in the list, until the highest-ranking element
871 * (by indentation has been covered). */
872 int prevLevel = matchLevel;
873 for (bAnimListElem *ale = match->prev; ale; ale = ale->prev) {
875
876 /* if no channel info was found, skip, since this type might not have any useful info */
877 if (acf == nullptr) {
878 continue;
879 }
880
881 /* Get the level of the current channel traversed
882 * - we define the level as simply being the offset for the start of the channel
883 */
884 const int level = (acf->get_offset) ? acf->get_offset(ac, ale) : 0;
885
886 if (level == prevLevel) {
887 /* Don't influence siblings. */
888 continue;
889 }
890
891 if (level > prevLevel) {
892 /* If previous level was a base-level (i.e. 0 offset / root of one hierarchy), stop here. */
893 if (prevLevel == 0) {
894 return;
895 }
896
897 /* Otherwise, this level weaves into another sibling hierarchy to the previous one just
898 * finished, so skip until we get to the parent of this level. */
899 continue;
900 }
901
902 /* The level is 'less than' (i.e. more important) the level we're matching but also 'less
903 * than' the level just tried (i.e. only the 1st group above grouped F-Curves, when toggling
904 * visibility of F-Curves, gets flushed, which should happen if we don't let prevLevel get
905 * updated below once the first 1st group is found). */
906 ANIM_channel_setting_set(ac, ale, setting, mode);
907
908 /* store this level as the 'old' level now */
909 prevLevel = level;
910 }
911}
912
913/* Copy a certain channel setting to children of the modified channel. */
915 const eAnimChannel_Settings setting,
916 const eAnimChannels_SetFlag mode,
917 bAnimListElem *const match,
918 const int matchLevel)
919{
920 /* go forwards in the list, until the lowest-ranking element (by indentation has been covered) */
921 for (bAnimListElem *ale = match->next; ale; ale = ale->next) {
923
924 /* if no channel info was found, skip, since this type might not have any useful info */
925 if (acf == nullptr) {
926 continue;
927 }
928
929 /* get the level of the current channel traversed
930 * - we define the level as simply being the offset for the start of the channel
931 */
932 const int level = (acf->get_offset) ? acf->get_offset(ac, ale) : 0;
933
934 /* if the level is 'greater than' (i.e. less important) the channel that was changed,
935 * flush the new status...
936 */
937 if (level > matchLevel) {
938 ANIM_channel_setting_set(ac, ale, setting, mode);
939 /* however, if the level is 'less than or equal to' the channel that was changed,
940 * (i.e. the current channel is as important if not more important than the changed
941 * channel) then we should stop, since we've found the last one of the children we should
942 * flush
943 */
944 }
945 else {
946 break;
947 }
948 }
949}
950
952 ListBaseT<bAnimListElem> *anim_data,
953 bAnimListElem *ale_setting,
954 eAnimChannel_Settings setting,
956{
957 bAnimListElem *match = nullptr;
958 int matchLevel = 0;
959
960 /* sanity check */
961 if (ELEM(nullptr, anim_data, anim_data->first())) {
962 return;
963 }
964
965 if (setting == ACHANNEL_SETTING_ALWAYS_VISIBLE) {
966 return;
967 }
968
969 /* find the channel that got changed */
970 for (bAnimListElem &ale : *anim_data) {
971 /* compare data, and type as main way of identifying the channel */
972 if ((ale.data == ale_setting->data) && (ale.type == ale_setting->type)) {
973 /* We also have to check the ID, this is assigned to,
974 * since a block may have multiple users. */
975 /* TODO: is the owner-data more revealing? */
976 if (ale.id == ale_setting->id) {
977 match = &ale;
978 break;
979 }
980 }
981 }
982 if (match == nullptr) {
983 printf("ERROR: no channel matching the one changed was found\n");
984 return;
985 }
986
987 {
988 const bAnimChannelType *acf = ANIM_channel_get_typeinfo(ale_setting);
989 if (acf == nullptr) {
990 printf("ERROR: no channel info for the changed channel\n");
991 return;
992 }
993
994 /* get the level of the channel that was affected
995 * - we define the level as simply being the offset for the start of the channel
996 */
997 matchLevel = (acf->get_offset) ? acf->get_offset(ac, ale_setting) : 0;
998 }
999
1000 anim_flush_channel_setting_up(ac, setting, mode, match, matchLevel);
1001 anim_flush_channel_setting_down(ac, setting, mode, match, matchLevel);
1002}
1003
1005{
1006
1008
1009 if (!window_region) {
1010 return;
1011 }
1012
1013 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
1017 ac, &anim_data, eAnimFilter_Flags(filter), ac->data, eAnimCont_Types(ac->datatype));
1018
1019 rctf bounds{};
1020 bounds.xmin = FLT_MAX;
1021 bounds.xmax = -FLT_MAX;
1022 bounds.ymin = FLT_MAX;
1023 bounds.ymax = -FLT_MAX;
1024 const bool include_handles = false;
1025 float frame_range[2] = {window_region->v2d.cur.xmin, window_region->v2d.cur.xmax};
1026 if (ac->scene->r.flag & SCER_PRV_RANGE) {
1027 frame_range[0] = ac->scene->r.psfra;
1028 frame_range[1] = ac->scene->r.pefra;
1029 }
1030
1031 for (bAnimListElem &ale : anim_data) {
1032 rctf channel_bounds;
1033 const bool found_bounds = get_channel_bounds(
1034 ac, &ale, frame_range, include_handles, &channel_bounds);
1035 if (found_bounds) {
1036 BLI_rctf_union(&bounds, &channel_bounds);
1037 }
1038 }
1039
1040 if (!BLI_rctf_is_valid(&bounds)) {
1041 ANIM_animdata_freelist(&anim_data);
1042 return;
1043 }
1044
1045 add_region_padding(C, window_region, &bounds);
1046
1047 window_region->v2d.cur.ymin = bounds.ymin;
1048 window_region->v2d.cur.ymax = bounds.ymax;
1049
1050 ANIM_animdata_freelist(&anim_data);
1051}
1052
1054
1055/* -------------------------------------------------------------------- */
1058
1059/* poll callback for being in an Animation Editor channels list region */
1061{
1062 ScrArea *area = CTX_wm_area(C);
1063
1064 /* channels region test */
1065 /* TODO: could enhance with actually testing if channels region? */
1066 if (ELEM(nullptr, area, CTX_wm_region(C))) {
1067 return false;
1068 }
1069 /* animation editor test */
1070 if (ELEM(area->spacetype, SPACE_ACTION, SPACE_GRAPH, SPACE_NLA) == 0) {
1071 return false;
1072 }
1073
1074 return true;
1075}
1076
1077/* Poll callback for Animation Editor channels list region + not in NLA-tweak-mode for NLA. */
1079{
1080 ScrArea *area = CTX_wm_area(C);
1081 Scene *scene = CTX_data_scene(C);
1082
1083 /* channels region test */
1084 /* TODO: could enhance with actually testing if channels region? */
1085 if (ELEM(nullptr, area, CTX_wm_region(C))) {
1086 return false;
1087 }
1088 /* animation editor test */
1089 if (ELEM(area->spacetype, SPACE_ACTION, SPACE_GRAPH, SPACE_NLA) == 0) {
1090 return false;
1091 }
1092
1093 /* NLA tweak-mode test. */
1094 if (area->spacetype == SPACE_NLA) {
1095 if ((scene == nullptr) || (scene->flag & SCE_NLA_EDIT_ON)) {
1096 return false;
1097 }
1098 }
1099
1100 return true;
1101}
1102
1104
1105/* -------------------------------------------------------------------- */
1108
1109/* constants for channel rearranging */
1110/* WARNING: don't change existing ones without modifying rearrange func accordingly */
1117
1118/* defines for rearranging channels */
1120 {REARRANGE_ANIMCHAN_TOP, "TOP", 0, "To Top", ""},
1121 {REARRANGE_ANIMCHAN_UP, "UP", 0, "Up", ""},
1122 {REARRANGE_ANIMCHAN_DOWN, "DOWN", 0, "Down", ""},
1123 {REARRANGE_ANIMCHAN_BOTTOM, "BOTTOM", 0, "To Bottom", ""},
1124 {0, nullptr, 0, nullptr, nullptr},
1125};
1126
1128
1129/* -------------------------------------------------------------------- */
1132
1133/* Island definition - just a listbase container */
1136
1137 ListBaseT<bAnimListElem> channels; /* channels within this region with the same state */
1138 int flag; /* eReorderIslandFlag */
1139};
1140
1141/* flags for channel reordering islands */
1143 REORDER_ISLAND_SELECTED = (1 << 0), /* island is selected */
1144 REORDER_ISLAND_UNTOUCHABLE = (1 << 1), /* island should be ignored */
1145 REORDER_ISLAND_MOVED = (1 << 2), /* island has already been moved */
1146 REORDER_ISLAND_HIDDEN = (1 << 3), /* island is not visible */
1147};
1148
1150
1151/* -------------------------------------------------------------------- */
1154
1156{
1157 /* island must not be untouchable */
1158 if (island->flag & REORDER_ISLAND_UNTOUCHABLE) {
1159 return false;
1160 }
1161
1162 /* island should be selected to be moved */
1163 return (island->flag & REORDER_ISLAND_SELECTED) && !(island->flag & REORDER_ISLAND_MOVED);
1164}
1165
1166/* ............................. */
1167
1168static bool rearrange_island_top(ListBaseT<tReorderChannelIsland> *list,
1169 tReorderChannelIsland *island)
1170{
1171 if (rearrange_island_ok(island)) {
1172 /* remove from current position */
1173 BLI_remlink(list, island);
1174
1175 /* make it first element */
1176 BLI_insertlinkbefore(list, list->first_, island);
1177
1178 return true;
1179 }
1180
1181 return false;
1182}
1183
1184static bool rearrange_island_up(ListBaseT<tReorderChannelIsland> *list,
1185 tReorderChannelIsland *island)
1186{
1187 if (rearrange_island_ok(island)) {
1188 /* moving up = moving before the previous island, otherwise we're in the same place */
1189 tReorderChannelIsland *prev = island->prev;
1190
1191 /* Skip hidden islands! */
1192 while (prev && prev->flag & REORDER_ISLAND_HIDDEN) {
1193 prev = prev->prev;
1194 }
1195
1196 if (prev) {
1197 /* remove from current position */
1198 BLI_remlink(list, island);
1199
1200 /* push it up */
1201 BLI_insertlinkbefore(list, prev, island);
1202
1203 return true;
1204 }
1205 }
1206
1207 return false;
1208}
1209
1210static bool rearrange_island_down(ListBaseT<tReorderChannelIsland> *list,
1211 tReorderChannelIsland *island)
1212{
1213 if (rearrange_island_ok(island)) {
1214 /* moving down = moving after the next island, otherwise we're in the same place */
1215 tReorderChannelIsland *next = island->next;
1216
1217 /* Skip hidden islands! */
1218 while (next && next->flag & REORDER_ISLAND_HIDDEN) {
1219 next = next->next;
1220 }
1221
1222 if (next) {
1223 /* can only move past if next is not untouchable (i.e. nothing can go after it) */
1224 if ((next->flag & REORDER_ISLAND_UNTOUCHABLE) == 0) {
1225 /* remove from current position */
1226 BLI_remlink(list, island);
1227
1228 /* push it down */
1229 BLI_insertlinkafter(list, next, island);
1230
1231 return true;
1232 }
1233 }
1234 /* else: no next channel, so we're at the bottom already, so can't move */
1235 }
1236
1237 return false;
1238}
1239
1240static bool rearrange_island_bottom(ListBaseT<tReorderChannelIsland> *list,
1241 tReorderChannelIsland *island)
1242{
1243 if (rearrange_island_ok(island)) {
1244 tReorderChannelIsland *last = list->last();
1245
1246 /* remove island from current position */
1247 BLI_remlink(list, island);
1248
1249 /* add before or after the last channel? */
1250 if ((last->flag & REORDER_ISLAND_UNTOUCHABLE) == 0) {
1251 /* can add after it */
1252 BLI_addtail(list, island);
1253 }
1254 else {
1255 /* can at most go just before it, since last cannot be moved */
1256 BLI_insertlinkbefore(list, last, island);
1257 }
1258
1259 return true;
1260 }
1261
1262 return false;
1263}
1264
1265/* ............................. */
1266
1274using AnimChanRearrangeFp = bool (*)(ListBaseT<tReorderChannelIsland> *list,
1275 tReorderChannelIsland *island);
1276
1277/* get rearranging function, given 'rearrange' mode */
1279{
1280 switch (mode) {
1282 return rearrange_island_top;
1284 return rearrange_island_up;
1286 return rearrange_island_down;
1289 default:
1290 return nullptr;
1291 }
1292}
1293
1294/* get rearranging function, given 'rearrange' mode (grease pencil is inverted) */
1296{
1297 switch (mode) {
1301 return rearrange_island_down;
1303 return rearrange_island_up;
1305 return rearrange_island_top;
1306 default:
1307 return nullptr;
1308 }
1309}
1310
1312
1313/* -------------------------------------------------------------------- */
1316
1317/* add channel into list of islands */
1318template<typename T>
1319static void rearrange_animchannel_add_to_islands(ListBaseT<tReorderChannelIsland> *islands,
1320 ListBaseT<T> *srcList,
1321 Link *channel,
1322 eAnim_ChannelType type,
1323 const bool is_hidden)
1324{
1325 /* always try to add to last island if possible */
1326 tReorderChannelIsland *island = islands->last();
1327 bool is_sel = false, is_untouchable = false;
1328
1329 /* get flags - selected and untouchable from the channel */
1330 switch (type) {
1331 case ANIMTYPE_GROUP: {
1332 bActionGroup *agrp = reinterpret_cast<bActionGroup *>(channel);
1333
1334 is_sel = SEL_AGRP(agrp);
1335 is_untouchable = (agrp->flag & AGRP_TEMP) != 0;
1336 break;
1337 }
1338 case ANIMTYPE_FCURVE:
1339 case ANIMTYPE_NLACURVE: {
1340 FCurve *fcu = reinterpret_cast<FCurve *>(channel);
1341
1342 is_sel = SEL_FCU(fcu);
1343 break;
1344 }
1345 case ANIMTYPE_NLATRACK: {
1346 NlaTrack *nlt = reinterpret_cast<NlaTrack *>(channel);
1347
1348 is_sel = SEL_NLT(nlt);
1349 break;
1350 }
1351 case ANIMTYPE_GPLAYER: {
1352 bGPDlayer *gpl = reinterpret_cast<bGPDlayer *>(channel);
1353
1354 is_sel = SEL_GPL(gpl);
1355 break;
1356 }
1357 default:
1358 printf(
1359 "rearrange_animchannel_add_to_islands(): don't know how to handle channels of type %d\n",
1360 type);
1361 return;
1362 }
1363
1364 /* do we need to add to a new island? */
1365 if (/* 1) no islands yet */
1366 (island == nullptr) ||
1367 /* 2) unselected islands have single channels only - to allow up/down movement */
1368 ((island->flag & REORDER_ISLAND_SELECTED) == 0) ||
1369 /* 3) if channel is unselected, stop existing island
1370 * (it was either wrong sel status, or full already) */
1371 (is_sel == 0) ||
1372 /* 4) hidden status changes */
1373 (bool(island->flag & REORDER_ISLAND_HIDDEN) != is_hidden))
1374 {
1375 /* create a new island now */
1376 island = MEM_new_zeroed<tReorderChannelIsland>("tReorderChannelIsland");
1377 BLI_addtail(islands, island);
1378
1379 if (is_sel) {
1380 island->flag |= REORDER_ISLAND_SELECTED;
1381 }
1382 if (is_untouchable) {
1384 }
1385 if (is_hidden) {
1386 island->flag |= REORDER_ISLAND_HIDDEN;
1387 }
1388 }
1389
1390 /* add channel to island - need to remove it from its existing list first though */
1391 BLI_remlink(srcList, channel);
1392 BLI_addtail(&island->channels, channel);
1393}
1394
1395/* flatten islands out into a single list again */
1396template<typename T>
1397static void rearrange_animchannel_flatten_islands(ListBaseT<tReorderChannelIsland> *islands,
1398 ListBaseT<T> *srcList)
1399{
1400 tReorderChannelIsland *island, *isn = nullptr;
1401
1402 /* make sure srcList is empty now */
1403 BLI_assert(srcList->is_empty());
1404
1405 /* go through merging islands */
1406 for (island = islands->first(); island; island = isn) {
1407 isn = island->next;
1408
1409 /* merge island channels back to main list, then delete the island */
1410 BLI_movelisttolist(srcList, &island->channels);
1411 BLI_freelinkN(islands, island);
1412 }
1413}
1414
1415/* ............................. */
1416
1417/* get a list of all bAnimListElem's of a certain type which are currently visible */
1419 ListBaseT<bAnimListElem> *anim_data_visible,
1420 bAnimContext *ac,
1421 const eAnim_ChannelType type,
1422 const eAnimFilter_Flags additional_filters = eAnimFilter_Flags{})
1423{
1424 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
1426 ANIMFILTER_LIST_CHANNELS | additional_filters);
1427
1428 /* get all visible channels */
1429 ANIM_animdata_filter(ac, &anim_data, filter, ac->data, eAnimCont_Types(ac->datatype));
1430
1431 /* now, only keep the ones that are of the types we are interested in */
1432 for (bAnimListElem &ale : anim_data.items_mutable()) {
1433 if (ale.type != type) {
1434 BLI_freelinkN(&anim_data, &ale);
1435 continue;
1436 }
1437
1438 if (type == ANIMTYPE_NLATRACK) {
1439 NlaTrack *nlt = static_cast<NlaTrack *>(ale.data);
1440
1441 if (BKE_nlatrack_is_nonlocal_in_liboverride(ale.id, nlt)) {
1442 /* No re-arrangement of non-local tracks of override data. */
1443 BLI_freelinkN(&anim_data, &ale);
1444 continue;
1445 }
1446 }
1447 }
1448
1449 /* return cleaned up list */
1450 *anim_data_visible = anim_data;
1451}
1452
1453/* performing rearranging of channels using islands */
1454template<typename T>
1455static bool rearrange_animchannel_islands(ListBaseT<T> *list,
1456 AnimChanRearrangeFp rearrange_func,
1458 eAnim_ChannelType type,
1459 ListBaseT<bAnimListElem> *anim_data_visible)
1460{
1461 ListBaseT<tReorderChannelIsland> islands = {nullptr, nullptr};
1462 Link *channel, *chanNext = nullptr;
1463 bool done = false;
1464
1465 /* don't waste effort on an empty list */
1466 if (list->is_empty()) {
1467 return false;
1468 }
1469
1470 /* group channels into islands */
1471 for (channel = list->template first_as<Link>(); channel; channel = chanNext) {
1472 /* find out whether this channel is present in anim_data_visible or not! */
1473 const bool is_hidden =
1474 (BLI_findptr(anim_data_visible, channel, offsetof(bAnimListElem, data)) == nullptr);
1475 chanNext = channel->next;
1476 rearrange_animchannel_add_to_islands(&islands, list, channel, type, is_hidden);
1477 }
1478
1479 /* Perform moving of selected islands now, but only if there is more than one of them
1480 * so that something will happen:
1481 *
1482 * - Scanning of the list is performed in the opposite direction
1483 * to the direction we're moving things,
1484 * so that we shouldn't need to encounter items we've moved already.
1485 */
1486 if (islands.first() != islands.last()) {
1487 tReorderChannelIsland *first = static_cast<tReorderChannelIsland *>(
1488 (mode > 0) ? islands.last() : islands.first());
1489 tReorderChannelIsland *island, *isn = nullptr;
1490
1491 for (island = first; island; island = isn) {
1492 isn = (mode > 0) ? island->prev : island->next;
1493
1494 /* perform rearranging */
1495 if (rearrange_func(&islands, island)) {
1496 island->flag |= REORDER_ISLAND_MOVED;
1497 done = true;
1498 }
1499 }
1500 }
1501
1502 /* ungroup islands */
1504
1505 /* did we do anything? */
1506 return done;
1507}
1508
1510
1511/* -------------------------------------------------------------------- */
1514
1515/* Change the order NLA Tracks within NLA Stack
1516 * ! NLA tracks are displayed in opposite order, so directions need care
1517 * mode: REARRANGE_ANIMCHAN_*
1518 */
1520{
1521 AnimChanRearrangeFp rearrange_func;
1522 ListBaseT<bAnimListElem> anim_data_visible = {nullptr, nullptr};
1523 const bool is_liboverride = (ac->obact != nullptr) ? ID_IS_OVERRIDE_LIBRARY(ac->obact) : false;
1524
1525 /* hack: invert mode so that functions will work in right order */
1526 mode = eRearrangeAnimChan_Mode(int(mode) * -1);
1527
1528 /* get rearranging function */
1529 rearrange_func = rearrange_get_mode_func(mode);
1530 if (rearrange_func == nullptr) {
1531 return;
1532 }
1533
1534 /* In liboverride case, we need to extract non-local NLA tracks from current anim data before we
1535 * can perform the move, and add then back afterwards. It's the only way to prevent them from
1536 * being affected by the reordering.
1537 *
1538 * Note that both override apply code for NLA tracks collection, and NLA editing code, are
1539 * responsible to ensure that non-local tracks always remain first in the list. */
1540 ListBaseT<NlaTrack> extracted_nonlocal_nla_tracks = {nullptr, nullptr};
1541 if (is_liboverride) {
1542 NlaTrack *nla_track;
1543 for (nla_track = adt->nla_tracks.first(); nla_track != nullptr; nla_track = nla_track->next) {
1544 if (!BKE_nlatrack_is_nonlocal_in_liboverride(&ac->obact->id, nla_track)) {
1545 break;
1546 }
1547 }
1548 if (nla_track != nullptr && nla_track->prev != nullptr) {
1549 extracted_nonlocal_nla_tracks.first_ = adt->nla_tracks.first_;
1550 extracted_nonlocal_nla_tracks.last_ = nla_track->prev;
1551 adt->nla_tracks.first_ = nla_track;
1552 nla_track->prev->next = nullptr;
1553 nla_track->prev = nullptr;
1554 }
1555 }
1556
1557 /* Filter visible data. */
1559
1560 /* perform rearranging on tracks list */
1562 &adt->nla_tracks, rearrange_func, mode, ANIMTYPE_NLATRACK, &anim_data_visible);
1563
1564 /* Add back non-local NLA tracks at the beginning of the animation data's list. */
1565 if (!extracted_nonlocal_nla_tracks.is_empty()) {
1566 BLI_assert(is_liboverride);
1567 extracted_nonlocal_nla_tracks.last()->next = adt->nla_tracks.first();
1568 adt->nla_tracks.first()->prev = extracted_nonlocal_nla_tracks.last();
1569 adt->nla_tracks.first_ = extracted_nonlocal_nla_tracks.first_;
1570 }
1571
1572 /* free temp data */
1573 anim_data_visible.free_no_destruct();
1574}
1575
1577
1578/* -------------------------------------------------------------------- */
1581
1582/* Change the order drivers within AnimData block
1583 * mode: REARRANGE_ANIMCHAN_*
1584 */
1586 AnimData *adt,
1588{
1589 /* get rearranging function */
1590 AnimChanRearrangeFp rearrange_func = rearrange_get_mode_func(mode);
1591 ListBaseT<bAnimListElem> anim_data_visible = {nullptr, nullptr};
1592
1593 if (rearrange_func == nullptr) {
1594 return;
1595 }
1596
1597 /* only consider drivers if they're accessible */
1598 if (EXPANDED_DRVD(adt) == 0) {
1599 return;
1600 }
1601
1602 /* Filter visible data. */
1604
1605 /* perform rearranging on drivers list (drivers are really just F-Curves) */
1607 &adt->drivers, rearrange_func, mode, ANIMTYPE_FCURVE, &anim_data_visible);
1608
1609 /* free temp data */
1610 anim_data_visible.free_no_destruct();
1611}
1612
1614
1615/* -------------------------------------------------------------------- */
1618
1625{
1626 /* TODO: the general structure of this function is basically the same as
1627 * `rearrange_layered_action_channel_groups()` and
1628 * `rearrange_layered_action_fcurves()`. It would be nice to DRY them at some
1629 * point if we can. */
1630
1631 ListBaseT<bAnimListElem> anim_data_selected_visible = {nullptr, nullptr};
1633 &anim_data_selected_visible, ac, ANIMTYPE_ACTION_SLOT, ANIMFILTER_SEL);
1634
1635 int total_moved = 0;
1636
1637 switch (mode) {
1638 case REARRANGE_ANIMCHAN_UP: {
1639 for (bAnimListElem &ale : anim_data_selected_visible) {
1640 BLI_assert(ale.type == ANIMTYPE_ACTION_SLOT);
1641 animrig::Slot &slot = static_cast<ActionSlot *>(ale.data)->wrap();
1642 animrig::Action &action = reinterpret_cast<bAction *>(ale.fcurve_owner_id)->wrap();
1643
1644 const int current_index = action.slots().first_index_try(&slot);
1645 const int to_index = current_index - 1;
1646 BLI_assert(current_index >= 0);
1647
1648 /* We skip moving when the destination is also selected because that
1649 * would swap two selected slots rather than moving them all in the
1650 * same direction. This happens when multiple selected slots are
1651 * already packed together at the top. */
1652 if (to_index < 0 || action.slot(to_index)->is_selected()) {
1653 continue;
1654 }
1655
1656 action.slot_move_to_index(slot, to_index);
1657 total_moved++;
1658 }
1659 break;
1660 }
1661
1663 for (bAnimListElem &ale : anim_data_selected_visible.items_reversed()) {
1664 BLI_assert(ale.type == ANIMTYPE_ACTION_SLOT);
1665 animrig::Slot &slot = static_cast<ActionSlot *>(ale.data)->wrap();
1666 animrig::Action &action = reinterpret_cast<bAction *>(ale.fcurve_owner_id)->wrap();
1667
1668 const int current_index = action.slots().first_index_try(&slot);
1669 const int to_index = 0;
1670 if (current_index != to_index) {
1671 action.slot_move_to_index(slot, to_index);
1672 total_moved++;
1673 }
1674 }
1675 break;
1676 }
1677
1679 for (bAnimListElem &ale : anim_data_selected_visible.items_reversed()) {
1680 BLI_assert(ale.type == ANIMTYPE_ACTION_SLOT);
1681 animrig::Slot &slot = static_cast<ActionSlot *>(ale.data)->wrap();
1682 animrig::Action &action = reinterpret_cast<bAction *>(ale.fcurve_owner_id)->wrap();
1683
1684 const int current_index = action.slots().first_index_try(&slot);
1685 const int to_index = current_index + 1;
1686 BLI_assert(current_index >= 0);
1687
1688 /* We skip moving when the destination is also selected because that
1689 * would swap two selected slots rather than moving them all in the
1690 * same direction. This happens when multiple selected slots are
1691 * already packed together at the bottom. */
1692 if (to_index >= action.slots().size() || action.slot(to_index)->is_selected()) {
1693 continue;
1694 }
1695
1696 action.slot_move_to_index(slot, to_index);
1697 total_moved++;
1698 }
1699 break;
1700 }
1701
1703 for (bAnimListElem &ale : anim_data_selected_visible) {
1704 BLI_assert(ale.type == ANIMTYPE_ACTION_SLOT);
1705 animrig::Slot &slot = static_cast<ActionSlot *>(ale.data)->wrap();
1706 animrig::Action &action = reinterpret_cast<bAction *>(ale.fcurve_owner_id)->wrap();
1707
1708 const int current_index = action.slots().first_index_try(&slot);
1709 const int to_index = action.slots().size() - 1;
1710 if (current_index != to_index) {
1711 action.slot_move_to_index(slot, to_index);
1712 total_moved++;
1713 }
1714 }
1715 break;
1716 }
1717 }
1718
1719 anim_data_selected_visible.free_no_destruct();
1720
1721 return total_moved > 0;
1722}
1723
1743 animrig::Action &action,
1744 const eRearrangeAnimChan_Mode mode)
1745{
1746 ListBaseT<bAnimListElem> anim_data_visible = {nullptr, nullptr};
1747
1748 /* We don't use `ANIMFILTER_SEL` here, and instead individually check on each
1749 * element whether it's selected or not in the code further below. This is
1750 * because it's what the legacy code does (see for example
1751 * `rearrange_animchannel_add_to_islands()`), and we're avoiding diverging
1752 * unnecessarily from that in case there was a reason for it. */
1754
1755 switch (mode) {
1756 case REARRANGE_ANIMCHAN_UP: {
1757 for (bAnimListElem &ale : anim_data_visible) {
1758 if (ale.adt && &ale.adt->action->wrap() != &action) {
1759 continue;
1760 }
1761 BLI_assert(ale.type == ANIMTYPE_GROUP);
1762 bActionGroup *group = static_cast<bActionGroup *>(ale.data);
1763 if (!SEL_AGRP(group)) {
1764 continue;
1765 }
1766 animrig::Channelbag &bag = group->channelbag->wrap();
1767 const int group_index = bag.channel_groups().first_index_try(group);
1768 const int to_index = group_index - 1;
1769 BLI_assert(group_index >= 0);
1770
1771 /* We skip moving when the destination is also selected because that
1772 * would swap two selected groups rather than moving them all in the
1773 * same direction. This happens when multiple selected groups are
1774 * already packed together at the top. */
1775 if (to_index < 0 || SEL_AGRP(bag.channel_group(to_index))) {
1776 continue;
1777 }
1778
1779 bag.channel_group_move_to_index(*group, to_index);
1780 }
1781 break;
1782 }
1783
1785 for (bAnimListElem &ale : anim_data_visible.items_reversed()) {
1786 if (ale.adt && &ale.adt->action->wrap() != &action) {
1787 continue;
1788 }
1789 BLI_assert(ale.type == ANIMTYPE_GROUP);
1790 bActionGroup *group = static_cast<bActionGroup *>(ale.data);
1791 if (!SEL_AGRP(group)) {
1792 continue;
1793 }
1794 animrig::Channelbag &bag = group->channelbag->wrap();
1795 bag.channel_group_move_to_index(*group, 0);
1796 }
1797 break;
1798 }
1799
1801 for (bAnimListElem &ale : anim_data_visible.items_reversed()) {
1802 if (ale.adt && &ale.adt->action->wrap() != &action) {
1803 continue;
1804 }
1805 BLI_assert(ale.type == ANIMTYPE_GROUP);
1806 bActionGroup *group = static_cast<bActionGroup *>(ale.data);
1807 if (!SEL_AGRP(group)) {
1808 continue;
1809 }
1810 animrig::Channelbag &bag = group->channelbag->wrap();
1811 const int group_index = bag.channel_groups().first_index_try(group);
1812 const int to_index = group_index + 1;
1813 BLI_assert(group_index >= 0);
1814
1815 /* We skip moving when the destination is also selected because that
1816 * would swap two selected groups rather than moving them all in the
1817 * same direction. This happens when multiple selected groups are
1818 * already packed together at the bottom. */
1819 if (to_index >= bag.channel_groups().size() || SEL_AGRP(bag.channel_group(to_index))) {
1820 continue;
1821 }
1822
1823 bag.channel_group_move_to_index(*group, to_index);
1824 }
1825 break;
1826 }
1827
1829 for (bAnimListElem &ale : anim_data_visible) {
1830 if (ale.adt && &ale.adt->action->wrap() != &action) {
1831 continue;
1832 }
1833 BLI_assert(ale.type == ANIMTYPE_GROUP);
1834 bActionGroup *group = static_cast<bActionGroup *>(ale.data);
1835 if (!SEL_AGRP(group)) {
1836 continue;
1837 }
1838 animrig::Channelbag &bag = group->channelbag->wrap();
1839 bag.channel_group_move_to_index(*group, bag.channel_groups().size() - 1);
1840 }
1841 break;
1842 }
1843 }
1844
1845 anim_data_visible.free_no_destruct();
1846}
1847
1866 animrig::Action &action,
1867 const eRearrangeAnimChan_Mode mode)
1868{
1869 ListBaseT<bAnimListElem> anim_data_visible = {nullptr, nullptr};
1870
1871 /* We don't use `ANIMFILTER_SEL` here, and instead individually check on each
1872 * element whether it's selected or not in the code further below. This is
1873 * because it's what the legacy code does (see for example
1874 * `rearrange_animchannel_add_to_islands()`), and we're avoiding diverging
1875 * unnecessarily from that in case there was a reason for it. */
1877
1878 /* Lambda to either fetch an fcurve's group if it has one, or otherwise
1879 * construct a fake one representing the ungrouped range at the end of the
1880 * fcurve array. This lets the code further below be much less of a special-case,
1881 * in exchange for a little data copying.
1882 *
1883 * NOTE: this returns a *copy* of the group, rather a pointer or reference, to
1884 * make it possible to return a fake group when needed. */
1885 auto get_group_or_make_fake = [&action](bAnimListElem *fcurve_ale) -> bActionGroup {
1886 FCurve *fcurve = static_cast<FCurve *>(fcurve_ale->data);
1887 if (fcurve->grp) {
1888 return *fcurve->grp;
1889 }
1890
1891 animrig::Channelbag *bag = channelbag_for_action_slot(action, fcurve_ale->slot_handle);
1892 BLI_assert(bag != nullptr);
1893
1894 bActionGroup group = {};
1895 group.channelbag = bag;
1896 group.fcurve_range_start = 0;
1897 if (!bag->channel_groups().is_empty()) {
1898 bActionGroup *last_group = bag->channel_groups().last();
1899 group.fcurve_range_start = last_group->fcurve_range_start + last_group->fcurve_range_length;
1900 }
1901 group.fcurve_range_length = bag->fcurves().size() - group.fcurve_range_start;
1902
1903 return group;
1904 };
1905
1906 /* Lambda to determine whether an fcurve should be skipped, given both the
1907 * fcurve and the group it belongs to. */
1908 auto should_skip = [](FCurve &fcurve, bActionGroup &group) {
1909 /* If the curve itself isn't selected, then it shouldn't be operated on. If
1910 * its group is selected then the group was moved so we don't move the
1911 * fcurve individually. */
1912 return !SEL_FCU(&fcurve) || SEL_AGRP(&group);
1913 };
1914
1915 switch (mode) {
1916 case REARRANGE_ANIMCHAN_UP: {
1917 for (bAnimListElem &ale : anim_data_visible) {
1918 if (ale.adt && &ale.adt->action->wrap() != &action) {
1919 continue;
1920 }
1921 BLI_assert(ale.type == ANIMTYPE_FCURVE);
1922 FCurve *fcurve = static_cast<FCurve *>(ale.data);
1923 bActionGroup group = get_group_or_make_fake(&ale);
1924
1925 if (should_skip(*fcurve, group)) {
1926 continue;
1927 }
1928
1929 animrig::Channelbag &bag = group.channelbag->wrap();
1930 const int fcurve_index = bag.fcurves().first_index_try(fcurve);
1931 const int to_index = fcurve_index - 1;
1932
1933 /* We skip moving when the destination is also selected because that
1934 * would swap two selected fcurves rather than moving them all in the
1935 * same direction. This happens when multiple selected fcurves are
1936 * already packed together at the top. */
1937 if (to_index < group.fcurve_range_start || SEL_FCU(bag.fcurve(to_index))) {
1938 continue;
1939 }
1940
1941 bag.fcurve_move_to_index(*fcurve, to_index);
1942 }
1943 break;
1944 }
1945
1947 for (bAnimListElem &ale : anim_data_visible.items_reversed()) {
1948 if (ale.adt && &ale.adt->action->wrap() != &action) {
1949 continue;
1950 }
1951 BLI_assert(ale.type == ANIMTYPE_FCURVE);
1952 FCurve *fcurve = static_cast<FCurve *>(ale.data);
1953 bActionGroup group = get_group_or_make_fake(&ale);
1954
1955 if (should_skip(*fcurve, group)) {
1956 continue;
1957 }
1958
1959 animrig::Channelbag &bag = group.channelbag->wrap();
1960 bag.fcurve_move_to_index(*fcurve, group.fcurve_range_start);
1961 }
1962 break;
1963 }
1964
1966 for (bAnimListElem &ale : anim_data_visible.items_reversed()) {
1967 if (ale.adt && &ale.adt->action->wrap() != &action) {
1968 continue;
1969 }
1970 BLI_assert(ale.type == ANIMTYPE_FCURVE);
1971 FCurve *fcurve = static_cast<FCurve *>(ale.data);
1972 bActionGroup group = get_group_or_make_fake(&ale);
1973
1974 if (should_skip(*fcurve, group)) {
1975 continue;
1976 }
1977
1978 animrig::Channelbag &bag = group.channelbag->wrap();
1979 const int fcurve_index = bag.fcurves().first_index_try(fcurve);
1980 const int to_index = fcurve_index + 1;
1981
1982 /* We skip moving when the destination is also selected because that
1983 * would swap two selected fcurves rather than moving them all in the
1984 * same direction. This happens when multiple selected fcurves are
1985 * already packed together at the bottom. */
1986 if (to_index >= group.fcurve_range_start + group.fcurve_range_length ||
1987 SEL_FCU(bag.fcurve(to_index)))
1988 {
1989 continue;
1990 }
1991
1992 bag.fcurve_move_to_index(*fcurve, to_index);
1993 }
1994 break;
1995 }
1996
1998 for (bAnimListElem &ale : anim_data_visible) {
1999 if (ale.adt && &ale.adt->action->wrap() != &action) {
2000 continue;
2001 }
2002 BLI_assert(ale.type == ANIMTYPE_FCURVE);
2003 FCurve *fcurve = static_cast<FCurve *>(ale.data);
2004 bActionGroup group = get_group_or_make_fake(&ale);
2005
2006 if (should_skip(*fcurve, group)) {
2007 continue;
2008 }
2009
2010 animrig::Channelbag &bag = group.channelbag->wrap();
2011 bag.fcurve_move_to_index(*fcurve,
2012 group.fcurve_range_start + group.fcurve_range_length - 1);
2013 }
2014 break;
2015 }
2016 }
2017 anim_data_visible.free_no_destruct();
2018}
2019
2020/* Change the order of anim-channels within action
2021 * mode: REARRANGE_ANIMCHAN_*
2022 */
2024{
2025 BLI_assert(act != nullptr);
2026
2027 if (rearrange_layered_action_slots(ac, mode)) {
2028 /* Only rearrange other channels if no slot rearranging happened. */
2029 return;
2030 }
2031 rearrange_layered_action_channel_groups(ac, act->wrap(), mode);
2032 rearrange_layered_action_fcurves(ac, act->wrap(), mode);
2033}
2034
2036
2037/* -------------------------------------------------------------------- */
2040
2042 AnimData *adt,
2044{
2045 ListBaseT<bAnimListElem> anim_data_visible = {nullptr, nullptr};
2046
2047 /* get rearranging function */
2048 AnimChanRearrangeFp rearrange_func = rearrange_get_mode_func(mode);
2049
2050 if (rearrange_func == nullptr) {
2051 return;
2052 }
2053
2054 /* skip if these curves aren't being shown */
2055 if (adt->flag & ADT_NLA_SKEYS_COLLAPSED) {
2056 return;
2057 }
2058
2059 /* Filter visible data. */
2061
2062 /* we cannot rearrange between strips, but within each strip, we can rearrange those curves */
2063 for (NlaTrack &nlt : adt->nla_tracks) {
2064 for (NlaStrip &strip : nlt.strips) {
2066 &strip.fcurves, rearrange_func, mode, ANIMTYPE_NLACURVE, &anim_data_visible);
2067 }
2068 }
2069
2070 /* free temp data */
2071 anim_data_visible.free_no_destruct();
2072}
2073
2075
2076/* -------------------------------------------------------------------- */
2079
2081{
2082 using namespace blender::bke::greasepencil;
2083 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
2084 Vector<Layer *> layer_list;
2086
2088 ac, &anim_data, eAnimFilter_Flags(filter), ac->data, eAnimCont_Types(ac->datatype));
2089
2090 if (mode == REARRANGE_ANIMCHAN_TOP) {
2091 for (bAnimListElem &ale : anim_data.items_reversed()) {
2092 GreasePencil &grease_pencil = *reinterpret_cast<GreasePencil *>(ale.id);
2093 Layer *layer = static_cast<Layer *>(ale.data);
2094 if (layer->is_selected()) {
2095 grease_pencil.move_node_top(layer->as_node());
2097 }
2098 }
2099 }
2100 else {
2101 for (bAnimListElem &ale : anim_data) {
2102 GreasePencil &grease_pencil = *reinterpret_cast<GreasePencil *>(ale.id);
2103 Layer *layer = static_cast<Layer *>(ale.data);
2104
2105 switch (mode) {
2106 case REARRANGE_ANIMCHAN_UP: {
2107 if (layer->is_selected()) {
2108 grease_pencil.move_node_up(layer->as_node());
2109 }
2110 break;
2111 }
2113 if (layer->is_selected()) {
2114 grease_pencil.move_node_down(layer->as_node());
2115 }
2116 break;
2117 }
2119 if (layer->is_selected()) {
2120 grease_pencil.move_node_bottom(layer->as_node());
2121 }
2122 break;
2123 }
2125 /* Handled separately before the switch case. */
2126 break;
2127 }
2129 }
2130 }
2131
2132 anim_data.free_no_destruct();
2133}
2134
2136{
2137 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
2138 int filter;
2139
2140 /* get rearranging function */
2142
2143 if (rearrange_func == nullptr) {
2144 return;
2145 }
2146
2147 /* get Grease Pencil datablocks */
2151 ac, &anim_data, eAnimFilter_Flags(filter), ac->data, eAnimCont_Types(ac->datatype));
2152
2153 for (bAnimListElem &ale : anim_data) {
2154 /* only consider grease pencil container channels */
2155 if (ale.type != ANIMTYPE_DSGPENCIL) {
2156 continue;
2157 }
2158
2159 ListBaseT<bAnimListElem> anim_data_visible = {nullptr, nullptr};
2160 bGPdata *gpd = static_cast<bGPdata *>(ale.data);
2161
2162 /* only consider layers if this datablock is open */
2163 if ((gpd->flag & GP_DATA_EXPAND) == 0) {
2164 continue;
2165 }
2166
2167 /* Filter visible data. */
2169
2170 /* Rearrange data-block's layers. */
2172 &gpd->layers, rearrange_func, mode, ANIMTYPE_GPLAYER, &anim_data_visible);
2173
2174 /* free visible layers data */
2175 anim_data_visible.free_no_destruct();
2176
2177 /* Tag to recalc geometry */
2179 }
2180
2181 /* free GPD channel data */
2182 ANIM_animdata_freelist(&anim_data);
2183
2185}
2186
2188
2189/* -------------------------------------------------------------------- */
2192
2194{
2195 bAnimContext ac;
2197
2198 /* get editor data */
2199 if (ANIM_animdata_get_context(C, &ac) == 0) {
2200 return OPERATOR_CANCELLED;
2201 }
2202
2203 /* get mode */
2204 mode = eRearrangeAnimChan_Mode(RNA_enum_get(op->ptr, "direction"));
2205
2206 /* method to move channels depends on the editor */
2207 if (ac.datatype == ANIMCONT_GPENCIL) {
2208 /* Grease Pencil channels */
2210 }
2211 else if (ac.datatype == ANIMCONT_MASK) {
2212 /* Grease Pencil channels */
2213 printf("Mask does not supported for moving yet\n");
2214 }
2215 else if (ac.datatype == ANIMCONT_ACTION) {
2216 /* Directly rearrange action's channels */
2217 rearrange_action_channels(&ac, static_cast<bAction *>(ac.data), mode);
2218 }
2219 else {
2220 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
2221 int filter;
2222
2224 rearrange_gpencil_channels(&ac, mode);
2225 }
2226
2227 /* get animdata blocks */
2231 &ac, &anim_data, eAnimFilter_Flags(filter), ac.data, eAnimCont_Types(ac.datatype));
2232
2233 /* Rearranging an Action should only happen once, as that inspects all the
2234 * selected & visible channels of that Action anyway. */
2235 Set<bAction *> visited_actions;
2236
2237 for (bAnimListElem &ale : anim_data) {
2238 AnimData *adt = static_cast<AnimData *>(ale.data);
2239
2240 switch (ac.datatype) {
2241 case ANIMCONT_NLA: /* NLA-tracks only */
2242 rearrange_nla_tracks(&ac, adt, mode);
2244 break;
2245
2246 case ANIMCONT_DRIVERS: /* Drivers list only */
2247 rearrange_driver_channels(&ac, adt, mode);
2248 break;
2249
2250 case ANIMCONT_ACTION: /* Single Action only... */
2251 case ANIMCONT_SHAPEKEY: /* DOUBLE CHECK ME... */
2252 {
2253 if (adt->action) {
2254 if (visited_actions.add(adt->action)) {
2255 rearrange_action_channels(&ac, adt->action, mode);
2256 }
2257 }
2258 else if (G.debug & G_DEBUG) {
2259 printf("Animdata has no action\n");
2260 }
2261 break;
2262 }
2263
2264 default: /* DopeSheet/Graph Editor - Some Actions + NLA Control Curves */
2265 {
2266 /* NLA Control Curves */
2267 if (adt->nla_tracks.first_) {
2268 rearrange_nla_control_channels(&ac, adt, mode);
2269 }
2270
2271 /* Action */
2272 if (adt->action) {
2273 if (visited_actions.add(adt->action)) {
2274 rearrange_action_channels(&ac, adt->action, mode);
2275 }
2276 }
2277 else if (G.debug & G_DEBUG) {
2278 printf("Animdata has no action\n");
2279 }
2280 break;
2281 }
2282 }
2283 }
2284
2285 /* free temp data */
2286 ANIM_animdata_freelist(&anim_data);
2287 }
2288
2289 /* send notifier that things have changed */
2292
2293 return OPERATOR_FINISHED;
2294}
2295
2297{
2298 /* identifiers */
2299 ot->name = "Move Channels";
2300 ot->idname = "ANIM_OT_channels_move";
2301 ot->description = "Rearrange selected animation channels";
2302
2303 /* API callbacks. */
2306
2307 /* flags */
2309
2310 /* props */
2311 ot->prop = RNA_def_enum(ot->srna,
2312 "direction",
2315 "Direction",
2316 "");
2317}
2318
2320
2321/* -------------------------------------------------------------------- */
2324
2326{
2327 ScrArea *area = CTX_wm_area(C);
2328 SpaceLink *sl;
2329
2330 /* channels region test */
2331 /* TODO: could enhance with actually testing if channels region? */
2332 if (ELEM(nullptr, area, CTX_wm_region(C))) {
2333 return false;
2334 }
2335
2336 /* animation editor test - must be suitable modes only */
2337 sl = CTX_wm_space_data(C);
2338
2339 switch (area->spacetype) {
2340 /* supported... */
2341 case SPACE_ACTION: {
2342 SpaceAction *saction = reinterpret_cast<SpaceAction *>(sl);
2343
2344 /* Dope-sheet and action only - all others are for other data-types or have no groups. */
2345 if (ELEM(saction->mode, SACTCONT_ACTION, SACTCONT_DOPESHEET) == 0) {
2346 return false;
2347 }
2348
2349 break;
2350 }
2351 case SPACE_GRAPH: {
2352 SpaceGraph *sipo = reinterpret_cast<SpaceGraph *>(sl);
2353
2354 /* drivers can't have groups... */
2355 if (sipo->mode != SIPO_MODE_ANIMATION) {
2356 return false;
2357 }
2358
2359 break;
2360 }
2361 /* unsupported... */
2362 default:
2363 return false;
2364 }
2365
2366 return true;
2367}
2368
2370 bAnimListElem *adt_ref,
2371 const char name[])
2372{
2373 AnimData *adt = adt_ref->adt;
2374 bAction *act = adt->action;
2375
2376 if (act == nullptr) {
2377 return;
2378 }
2379
2380 /* Get list of selected F-Curves to re-group. */
2381 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
2384 ANIM_animdata_filter(ac, &anim_data, filter, adt_ref, ANIMCONT_CHANNEL);
2385
2386 if (anim_data.first_ == nullptr) {
2387 return;
2388 }
2389
2390 /* Layered action.
2391 *
2392 * The anim-list doesn't explicitly group the channels by channel bag, so we
2393 * have to get a little clever here. We take advantage of the fact that the
2394 * fcurves are at least listed in order, and so all fcurves in the same
2395 * channel bag will be next to each other. So we keep track of the channel bag
2396 * from the last fcurve, and check it against the current fcurve to see if
2397 * we've progressed into a new channel bag, and then we create the new group
2398 * for that channel bag.
2399 *
2400 * It's a little messy, and also has quadratic performance due to handling
2401 * each fcurve individually (each of which is an O(N) operation), but it's
2402 * also the simplest thing we can do given the data we have. In the future we
2403 * can do something smarter, particularly if it becomes a performance issue. */
2404 animrig::Channelbag *last_channelbag = nullptr;
2405 bActionGroup *group = nullptr;
2406 for (bAnimListElem &ale : anim_data) {
2407 FCurve *fcu = static_cast<FCurve *>(ale.data);
2408 animrig::Channelbag *channelbag = channelbag_for_action_slot(act->wrap(), ale.slot_handle);
2409
2410 if (channelbag != last_channelbag) {
2411 last_channelbag = channelbag;
2412 group = &channelbag->channel_group_create(name);
2413 }
2414
2415 channelbag->fcurve_assign_to_channel_group(*fcu, *group);
2416 }
2417
2418 /* Cleanup. */
2419 ANIM_animdata_freelist(&anim_data);
2420}
2421
2423 wmOperator *op,
2424 const wmEvent *event)
2425{
2426 /* Choose default name for new group. */
2427 RNA_string_set(op->ptr, "name", DATA_("New Group"));
2428 return WM_operator_props_popup(C, op, event);
2429}
2430
2432{
2433 bAnimContext ac;
2434 char name[MAX_NAME];
2435
2436 /* get editor data */
2437 if (ANIM_animdata_get_context(C, &ac) == 0) {
2438 return OPERATOR_CANCELLED;
2439 }
2440
2441 /* get name for new group */
2442 RNA_string_get(op->ptr, "name", name);
2443
2444 /* XXX: name for group should never be empty... */
2445 if (name[0]) {
2446 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
2447 int filter;
2448
2449 /* Handle each animdata block separately, so that the regrouping doesn't flow into blocks. */
2453 &ac, &anim_data, eAnimFilter_Flags(filter), ac.data, eAnimCont_Types(ac.datatype));
2454
2455 for (bAnimListElem &ale : anim_data) {
2456 animchannels_group_channels(&ac, &ale, name);
2457 }
2458
2459 /* free temp data */
2460 ANIM_animdata_freelist(&anim_data);
2461
2462 /* Updates. */
2464 }
2465
2466 return OPERATOR_FINISHED;
2467}
2468
2470{
2471 /* identifiers */
2472 ot->name = "Group Channels";
2473 ot->idname = "ANIM_OT_channels_group";
2474 ot->description = "Add selected F-Curves to a new group";
2475
2476 /* callbacks */
2480
2481 /* flags */
2483
2484 /* props */
2485 ot->prop = RNA_def_string(ot->srna,
2486 "name",
2487 nullptr,
2488 sizeof(bActionGroup::name),
2489 "Name",
2490 "Name of newly created group");
2491 /* XXX: still not too sure about this - keeping same text is confusing... */
2492 // RNA_def_property_flag(ot->prop, PROP_SKIP_SAVE);
2493}
2494
2496
2497/* -------------------------------------------------------------------- */
2500
2502{
2503 bAnimContext ac;
2504
2505 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
2506 int filter;
2507
2508 /* get editor data */
2509 if (ANIM_animdata_get_context(C, &ac) == 0) {
2510 return OPERATOR_CANCELLED;
2511 }
2512
2513 /* just selected F-Curves... */
2517 &ac, &anim_data, eAnimFilter_Flags(filter), ac.data, eAnimCont_Types(ac.datatype));
2518
2519 for (bAnimListElem &ale : anim_data) {
2520
2521 FCurve *fcu = static_cast<FCurve *>(ale.data);
2522
2523 /* Already ungrouped, so skip. */
2524 if (fcu->grp == nullptr) {
2525 continue;
2526 }
2527
2528 /* find action for this F-Curve... */
2529 if (!ale.adt || !ale.adt->action) {
2530 continue;
2531 }
2532 fcu->grp->channelbag->wrap().fcurve_ungroup(*fcu);
2533 }
2534
2535 /* cleanup */
2536 ANIM_animdata_freelist(&anim_data);
2537
2538 /* updates */
2540
2541 return OPERATOR_FINISHED;
2542}
2543
2545{
2546 /* identifiers */
2547 ot->name = "Ungroup Channels";
2548 ot->idname = "ANIM_OT_channels_ungroup";
2549 ot->description = "Remove selected F-Curves from their current groups";
2550
2551 /* callbacks */
2554
2555 /* flags */
2557}
2558
2560
2561/* -------------------------------------------------------------------- */
2564
2566{
2567 ID *id = ale->id;
2568 AnimData *adt = BKE_animdata_from_id(id);
2569 /* TODO(sergey): Technically, if the animation element is being deleted
2570 * from a driver we don't have to tag action. This is something we can check
2571 * for in the future. For now just do most reliable tag which was always happening. */
2572 if (adt != nullptr) {
2574 if (adt->action != nullptr) {
2576 }
2577 }
2578 /* Deals with NLA and drivers.
2579 * Doesn't cause overhead for action updates, since object will receive
2580 * animation update after dependency graph flushes update from action to
2581 * all its users. */
2583}
2584
2595{
2599 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
2600 ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
2601
2602 bool must_skip_groups = false;
2603 bool has_skipped_group = false;
2604
2605 /* Delete selected container-like channels and their underlying data. */
2606 for (bAnimListElem &ale : anim_data) {
2607 switch (ale.type) {
2608 case ANIMTYPE_ACTION_SLOT: {
2609 BLI_assert(ale.fcurve_owner_id);
2610 BLI_assert(ale.data);
2611 BLI_assert_msg(GS(ale.fcurve_owner_id->name) == ID_AC,
2612 "fcurve_owner_id should be an Action");
2613
2614 animrig::Action &action = reinterpret_cast<bAction *>(ale.fcurve_owner_id)->wrap();
2615 animrig::Slot &slot_to_remove = static_cast<ActionSlot *>(ale.data)->wrap();
2616
2617 action.slot_remove(slot_to_remove);
2618
2620
2621 /* Subsequent groups should be skipped, and their deletion kept for
2622 * another run (if they even exist after this slot was deleted). */
2623 must_skip_groups = true;
2624 break;
2625 }
2626
2627 case ANIMTYPE_GROUP: {
2628 if (must_skip_groups) {
2629 /* Another run of this function is needed to see if this group still
2630 * exists, and thus still needs deleting. */
2631 has_skipped_group = true;
2632 break;
2633 }
2634
2635 bActionGroup *agrp = static_cast<bActionGroup *>(ale.data);
2636 AnimData *adt = ale.adt;
2637
2638 /* Groups should always be part of an action. */
2639 if (adt == nullptr || adt->action == nullptr) {
2641 continue;
2642 }
2643
2644 /* Layered actions.
2645 *
2646 * Note that the behavior here is different from deleting groups via
2647 * the Python API: in the Python API the fcurves that belonged to the
2648 * group remain, and just get ungrouped, whereas here they are deleted
2649 * along with the group. This difference in behavior is replicated
2650 * from legacy actions. */
2651
2652 animrig::Channelbag &channelbag = agrp->channelbag->wrap();
2653
2654 /* Remove all the fcurves in the group, which also automatically
2655 * deletes the group when the last fcurve is deleted. Since the group
2656 * is automatically deleted, we store the fcurve range ahead of time
2657 * so we don't have to worry about the memory disappearing out from
2658 * under us. */
2659 const int fcurve_range_start = agrp->fcurve_range_start;
2660 const int fcurve_range_length = agrp->fcurve_range_length;
2661 for (int i = 0; i < fcurve_range_length; i++) {
2662 channelbag.fcurve_remove(*channelbag.fcurve(fcurve_range_start));
2663 }
2664
2666
2667 break;
2668 }
2669
2670 case ANIMTYPE_NONE:
2671 case ANIMTYPE_ANIMDATA:
2673 case ANIMTYPE_SUMMARY:
2674 case ANIMTYPE_SCENE:
2675 case ANIMTYPE_OBJECT:
2676 case ANIMTYPE_FCURVE:
2678 case ANIMTYPE_NLACURVE:
2680 case ANIMTYPE_FILLACTD:
2682 case ANIMTYPE_DSMAT:
2683 case ANIMTYPE_DSLAM:
2684 case ANIMTYPE_DSCAM:
2686 case ANIMTYPE_DSCUR:
2687 case ANIMTYPE_DSSKEY:
2688 case ANIMTYPE_DSWOR:
2689 case ANIMTYPE_DSNTREE:
2690 case ANIMTYPE_DSPART:
2691 case ANIMTYPE_DSMBALL:
2692 case ANIMTYPE_DSARM:
2693 case ANIMTYPE_DSMESH:
2694 case ANIMTYPE_DSTEX:
2695 case ANIMTYPE_DSLAT:
2697 case ANIMTYPE_DSSPK:
2698 case ANIMTYPE_DSGPENCIL:
2699 case ANIMTYPE_DSMCLIP:
2700 case ANIMTYPE_DSHAIR:
2702 case ANIMTYPE_DSVOLUME:
2704 case ANIMTYPE_SHAPEKEY:
2705 case ANIMTYPE_GPLAYER:
2710 case ANIMTYPE_MASKLAYER:
2711 case ANIMTYPE_NLATRACK:
2712 case ANIMTYPE_NLAACTION:
2713 case ANIMTYPE_PALETTE:
2714 case ANIMTYPE_NUM_TYPES:
2715 break;
2716 }
2717 }
2718
2719 ANIM_animdata_freelist(&anim_data);
2720
2721 return has_skipped_group;
2722}
2723
2725{
2728
2729 switch (ale.type) {
2730 case ANIMTYPE_FCURVE: {
2731 AnimData *adt = ale.adt;
2732 FCurve *fcu = static_cast<FCurve *>(ale.data);
2733
2734 BLI_assert_msg((fcu->driver != nullptr) == (ac.datatype == ANIMCONT_DRIVERS),
2735 "Expecting only driver F-Curves in the drivers editor");
2736
2737 if (ale.fcurve_owner_id && GS(ale.fcurve_owner_id->name) == ID_AC) {
2738 /* F-Curves can be owned by Actions assigned to NLA strips, which
2739 * `animrig::animdata_fcurve_delete()` (below) cannot handle. */
2740 BLI_assert_msg(!fcu->driver, "Drivers are not expected to be owned by Actions");
2741 animrig::Action &action = reinterpret_cast<bAction *>(ale.fcurve_owner_id)->wrap();
2742 action_fcurve_remove(action, *fcu);
2743 }
2744 else if (fcu->driver || adt->action) {
2745 /* This function only works for drivers & directly-assigned Actions: */
2747 }
2748 else {
2750 }
2751 break;
2752 }
2753 case ANIMTYPE_NLACURVE: {
2754 /* NLA Control Curve. */
2755 NlaStrip *strip = static_cast<NlaStrip *>(ale.owner);
2756 FCurve *fcu = static_cast<FCurve *>(ale.data);
2757 if (!BKE_nlastrip_controlcurve_remove(strip, fcu)) {
2758 printf("ERROR: Trying to delete NLA Control Curve for unknown property '%s'\n",
2759 fcu->rna_path().c_str());
2760 }
2761 break;
2762 }
2763
2764 default:
2766 }
2767
2769}
2770
2772{
2773 bAnimContext ac;
2774 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
2775 int filter;
2776
2777 /* get editor data */
2778 if (ANIM_animdata_get_context(C, &ac) == 0) {
2779 return OPERATOR_CANCELLED;
2780 }
2781
2782 /* cannot delete in shapekey */
2783 if (ac.datatype == ANIMCONT_SHAPEKEY) {
2784 return OPERATOR_CANCELLED;
2785 }
2786
2787 /* Do groups and other "summary/expander" types first (unless in Drivers mode, where there are
2788 * none), because the following loop will not find those channels. Also deleting an entire group
2789 * or slot will delete the channels they contain as well, so better avoid looping over those in
2790 * the same loop. */
2791 if (ac.datatype != ANIMCONT_DRIVERS) {
2792 /* Keep deleting container-like channels until there are no more to delete. */
2793 while (animchannels_delete_containers(C, &ac)) {
2794 /* Pass. */
2795 }
2796 }
2797
2798 /* filter data */
2802 &ac, &anim_data, eAnimFilter_Flags(filter), ac.data, eAnimCont_Types(ac.datatype));
2803
2804 /* delete selected data channels */
2805 for (bAnimListElem &ale : anim_data) {
2806 switch (ale.type) {
2807 case ANIMTYPE_FCURVE:
2808 case ANIMTYPE_NLACURVE:
2810 break;
2811
2812 case ANIMTYPE_GPLAYER: {
2813 /* Grease Pencil layer */
2814 bGPdata *gpd = reinterpret_cast<bGPdata *>(ale.id);
2815 bGPDlayer *gpl = static_cast<bGPDlayer *>(ale.data);
2816
2817 /* try to delete the layer's data and the layer itself */
2819 ale.update = ANIM_UPDATE_DEPS;
2820
2821 /* Free Grease Pencil data block when last annotation layer is removed, see: #112683. */
2822 if (gpd->flag & GP_DATA_ANNOTATIONS && gpd->layers.first_ == nullptr) {
2823 BKE_annotations_free_data(gpd, true);
2824
2825 Scene *scene = CTX_data_scene(C);
2826 scene->gpd = nullptr;
2827
2828 Main *bmain = CTX_data_main(C);
2829 BKE_id_free_us(bmain, gpd);
2830 }
2831 break;
2832 }
2834 using namespace blender::bke::greasepencil;
2835 GreasePencil *grease_pencil = reinterpret_cast<GreasePencil *>(ale.id);
2836 Layer *layer = static_cast<Layer *>(ale.data);
2837 grease_pencil->remove_layer(*layer);
2839 break;
2840 }
2841 case ANIMTYPE_MASKLAYER: {
2842 /* Mask layer */
2843 Mask *mask = reinterpret_cast<Mask *>(ale.id);
2844 MaskLayer *masklay = static_cast<MaskLayer *>(ale.data);
2845
2846 /* try to delete the layer's data and the layer itself */
2847 BKE_mask_layer_remove(mask, masklay);
2848 break;
2849 }
2850 case ANIMTYPE_NONE:
2851 case ANIMTYPE_ANIMDATA:
2853 case ANIMTYPE_SUMMARY:
2854 case ANIMTYPE_SCENE:
2855 case ANIMTYPE_OBJECT:
2856 case ANIMTYPE_GROUP:
2860 case ANIMTYPE_FILLACTD:
2862 case ANIMTYPE_DSMAT:
2863 case ANIMTYPE_DSLAM:
2864 case ANIMTYPE_DSCAM:
2866 case ANIMTYPE_DSCUR:
2867 case ANIMTYPE_DSSKEY:
2868 case ANIMTYPE_DSWOR:
2869 case ANIMTYPE_DSNTREE:
2870 case ANIMTYPE_DSPART:
2871 case ANIMTYPE_DSMBALL:
2872 case ANIMTYPE_DSARM:
2873 case ANIMTYPE_DSMESH:
2874 case ANIMTYPE_DSTEX:
2875 case ANIMTYPE_DSLAT:
2877 case ANIMTYPE_DSSPK:
2878 case ANIMTYPE_DSGPENCIL:
2879 case ANIMTYPE_DSMCLIP:
2880 case ANIMTYPE_DSHAIR:
2882 case ANIMTYPE_DSVOLUME:
2884 case ANIMTYPE_SHAPEKEY:
2888 case ANIMTYPE_NLATRACK:
2889 case ANIMTYPE_NLAACTION:
2890 case ANIMTYPE_PALETTE:
2891 case ANIMTYPE_NUM_TYPES:
2892 break;
2893 }
2894 }
2895
2896 ANIM_animdata_update(&ac, &anim_data);
2897 ANIM_animdata_freelist(&anim_data);
2898
2899 /* send notifier that things have changed */
2903
2904 return OPERATOR_FINISHED;
2905}
2906
2908{
2909 /* identifiers */
2910 ot->name = "Delete Channels";
2911 ot->idname = "ANIM_OT_channels_delete";
2912 ot->description = "Delete all selected animation channels";
2913
2914 /* API callbacks. */
2917
2918 /* flags */
2920}
2921
2923
2924/* -------------------------------------------------------------------- */
2927
2928/* defines for setting animation-channel flags */
2930 {ACHANNEL_SETFLAG_TOGGLE, "TOGGLE", 0, "Toggle", ""},
2931 {ACHANNEL_SETFLAG_CLEAR, "DISABLE", 0, "Disable", ""},
2932 {ACHANNEL_SETFLAG_ADD, "ENABLE", 0, "Enable", ""},
2933 {ACHANNEL_SETFLAG_INVERT, "INVERT", 0, "Invert", ""},
2934 {0, nullptr, 0, nullptr, nullptr},
2935};
2936
2937/* defines for set animation-channel settings */
2938/* TODO: could add some more types, but those are really quite dependent on the mode... */
2940 {ACHANNEL_SETTING_PROTECT, "PROTECT", 0, "Protect", ""},
2941 {ACHANNEL_SETTING_MUTE, "MUTE", 0, "Mute", ""},
2942 {0, nullptr, 0, nullptr, nullptr},
2943};
2944
2954 eAnimChannel_Settings setting,
2956 bool onlysel,
2957 bool flush)
2958{
2959 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
2960 ListBaseT<bAnimListElem> all_data = {nullptr, nullptr};
2961 int filter;
2962
2963 /* filter data that we need if flush is on */
2964 if (flush) {
2965 /* get list of all channels that selection may need to be flushed to
2966 * - hierarchy visibility needs to be ignored so that settings can get flushed
2967 * "down" inside closed containers
2968 */
2971 ac, &all_data, eAnimFilter_Flags(filter), ac->data, eAnimCont_Types(ac->datatype));
2972 }
2973
2974 /* filter data that we're working on
2975 * - hierarchy matters if we're doing this from the channels region
2976 * since we only want to apply this to channels we can "see",
2977 * and have these affect their relatives
2978 * - but for Graph Editor, this gets used also from main region
2979 * where hierarchy doesn't apply #21276.
2980 */
2981 if ((ac->spacetype == SPACE_GRAPH) && (ac->regiontype != RGN_TYPE_CHANNELS)) {
2982 /* graph editor (case 2) */
2985 }
2986 else {
2987 /* standard case */
2990 }
2991 if (onlysel) {
2993 }
2995 ac, &anim_data, eAnimFilter_Flags(filter), ac->data, eAnimCont_Types(ac->datatype));
2996
2997 /* if toggling, check if disable or enable */
2998 if (mode == ACHANNEL_SETFLAG_TOGGLE) {
2999 /* default to turn all on, unless we encounter one that's on... */
3000 mode = ACHANNEL_SETFLAG_ADD;
3001
3002 /* see if we should turn off instead... */
3003 for (bAnimListElem &ale : anim_data) {
3004 /* set the setting in the appropriate way (if available) */
3005 if (ANIM_channel_setting_get(ac, &ale, setting) > 0) {
3007 break;
3008 }
3009 }
3010 }
3011
3012 /* apply the setting */
3013 for (bAnimListElem &ale : anim_data) {
3014 /* skip channel if setting is not available */
3015 if (ANIM_channel_setting_get(ac, &ale, setting) == -1) {
3016 continue;
3017 }
3018
3019 /* set the setting in the appropriate way */
3020 ANIM_channel_setting_set(ac, &ale, setting, mode);
3022
3023 /* if flush status... */
3024 if (flush) {
3025 ANIM_flush_setting_anim_channels(ac, &all_data, &ale, setting, mode);
3026 }
3027 }
3028
3029 ANIM_animdata_freelist(&anim_data);
3030 all_data.free_no_destruct();
3031}
3032
3034
3035/* -------------------------------------------------------------------- */
3038
3040{
3041 bAnimContext ac;
3042 eAnimChannel_Settings setting;
3044 bool flush = true;
3045
3046 /* get editor data */
3047 if (ANIM_animdata_get_context(C, &ac) == 0) {
3048 return OPERATOR_CANCELLED;
3049 }
3050
3051 /* mode (eAnimChannels_SetFlag), setting (eAnimChannel_Settings) */
3052 mode = eAnimChannels_SetFlag(RNA_enum_get(op->ptr, "mode"));
3053 setting = eAnimChannel_Settings(RNA_enum_get(op->ptr, "type"));
3054
3055 /* check if setting is flushable */
3056 if (setting == ACHANNEL_SETTING_EXPAND) {
3057 flush = false;
3058 }
3059
3060 /* modify setting
3061 * - only selected channels are affected
3062 */
3063 setflag_anim_channels(&ac, setting, mode, true, flush);
3064
3065 /* send notifier that things have changed */
3067
3068 return OPERATOR_FINISHED;
3069}
3070
3071/* Duplicate of `ANIM_OT_channels_setting_toggle` for menu title only, weak! */
3073{
3074 PropertyRNA *prop;
3075
3076 /* identifiers */
3077 ot->name = "Enable Channel Setting";
3078 ot->idname = "ANIM_OT_channels_setting_enable";
3079 ot->description = "Enable specified setting on all selected animation channels";
3080
3081 /* API callbacks. */
3082 ot->invoke = WM_menu_invoke;
3085
3086 /* flags */
3088
3089 /* props */
3090 /* flag-setting mode */
3091 prop = RNA_def_enum(
3092 ot->srna, "mode", prop_animchannel_setflag_types, ACHANNEL_SETFLAG_ADD, "Mode", "");
3094 /* setting to set */
3095 ot->prop = RNA_def_enum(ot->srna, "type", prop_animchannel_settings_types, 0, "Type", "");
3096}
3097/* Duplicate of `ANIM_OT_channels_setting_toggle` for menu title only, weak! */
3099{
3100 PropertyRNA *prop;
3101
3102 /* identifiers */
3103 ot->name = "Disable Channel Setting";
3104 ot->idname = "ANIM_OT_channels_setting_disable";
3105 ot->description = "Disable specified setting on all selected animation channels";
3106
3107 /* API callbacks. */
3108 ot->invoke = WM_menu_invoke;
3111
3112 /* flags */
3114
3115 /* props */
3116 /* flag-setting mode */
3117 prop = RNA_def_enum(
3119 RNA_def_property_flag(prop, PROP_HIDDEN); /* internal hack - don't expose */
3120 /* setting to set */
3121 ot->prop = RNA_def_enum(ot->srna, "type", prop_animchannel_settings_types, 0, "Type", "");
3122}
3123
3125{
3126 PropertyRNA *prop;
3127
3128 /* identifiers */
3129 ot->name = "Toggle Channel Setting";
3130 ot->idname = "ANIM_OT_channels_setting_toggle";
3131 ot->description = "Toggle specified setting on all selected animation channels";
3132
3133 /* API callbacks. */
3134 ot->invoke = WM_menu_invoke;
3137
3138 /* flags */
3140
3141 /* props */
3142 /* flag-setting mode */
3143 prop = RNA_def_enum(
3145 RNA_def_property_flag(prop, PROP_HIDDEN); /* internal hack - don't expose */
3146 /* setting to set */
3147 ot->prop = RNA_def_enum(ot->srna, "type", prop_animchannel_settings_types, 0, "Type", "");
3148}
3149
3151{
3152 PropertyRNA *prop;
3153
3154 /* identifiers */
3155 ot->name = "Toggle Channel Editability";
3156 ot->idname = "ANIM_OT_channels_editable_toggle";
3157 ot->description = "Toggle editability of selected channels";
3158
3159 /* API callbacks. */
3162
3163 /* flags */
3165
3166 /* props */
3167 /* flag-setting mode */
3170 /* setting to set */
3171 prop = RNA_def_enum(
3173 RNA_def_property_flag(prop, PROP_HIDDEN); /* internal hack - don't expose */
3174}
3175
3177
3178/* -------------------------------------------------------------------- */
3181
3183{
3184 bAnimContext ac;
3185 bool onlysel = true;
3186
3187 /* get editor data */
3188 if (ANIM_animdata_get_context(C, &ac) == 0) {
3189 return OPERATOR_CANCELLED;
3190 }
3191
3192 /* only affect selected channels? */
3193 if (RNA_boolean_get(op->ptr, "all")) {
3194 onlysel = false;
3195 }
3196
3197 /* modify setting */
3199
3200 /* send notifier that things have changed */
3202
3203 return OPERATOR_FINISHED;
3204}
3205
3207{
3208 /* identifiers */
3209 ot->name = "Expand Channels";
3210 ot->idname = "ANIM_OT_channels_expand";
3211 ot->description = "Expand (open) all selected expandable animation channels";
3212
3213 /* API callbacks. */
3216
3217 /* flags */
3219
3220 /* props */
3221 ot->prop = RNA_def_boolean(
3222 ot->srna, "all", true, "All", "Expand all channels (not just selected ones)");
3223}
3224
3226
3227/* -------------------------------------------------------------------- */
3230
3232{
3233 bAnimContext ac;
3234 bool onlysel = true;
3235
3236 /* get editor data */
3237 if (ANIM_animdata_get_context(C, &ac) == 0) {
3238 return OPERATOR_CANCELLED;
3239 }
3240
3241 /* only affect selected channels? */
3242 if (RNA_boolean_get(op->ptr, "all")) {
3243 onlysel = false;
3244 }
3245
3246 /* modify setting */
3248
3249 /* send notifier that things have changed */
3251
3252 return OPERATOR_FINISHED;
3253}
3254
3256{
3257 /* identifiers */
3258 ot->name = "Collapse Channels";
3259 ot->idname = "ANIM_OT_channels_collapse";
3260 ot->description = "Collapse (close) all selected expandable animation channels";
3261
3262 /* API callbacks. */
3265
3266 /* flags */
3268
3269 /* props */
3270 ot->prop = RNA_def_boolean(
3271 ot->srna, "all", true, "All", "Collapse all channels (not just selected ones)");
3272}
3273
3275
3276/* -------------------------------------------------------------------- */
3290
3292{
3293 bAnimContext ac;
3294
3295 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
3296 int filter;
3297
3298 /* get editor data */
3299 if (ANIM_animdata_get_context(C, &ac) == 0) {
3300 return OPERATOR_CANCELLED;
3301 }
3302
3303 /* get animdata blocks */
3307 &ac, &anim_data, eAnimFilter_Flags(filter), ac.data, eAnimCont_Types(ac.datatype));
3308
3309 for (bAnimListElem &ale : anim_data) {
3310 ID *id = ale.id;
3311 AnimData *adt = static_cast<AnimData *>(ale.data);
3312
3313 bool action_empty;
3314 bool nla_empty = false;
3315 bool drivers_empty = false;
3316
3317 /* sanity checks */
3318 BLI_assert((id != nullptr) && (adt != nullptr));
3319
3320 /* check if this is "empty" and can be deleted */
3321 /* (For now, there are only these 3 criteria) */
3322
3323 /* 1) Assigned Action is empty, at least when it comes to this data-block. */
3324 if (adt->action) {
3325 using namespace blender::animrig;
3326 const Action &action = adt->action->wrap();
3327 /* This should not be using action.is_empty(), as this operator is not about cleaning up the
3328 * Action itself, but rather disassociating it from the animated ID when that ID is not being
3329 * animated by it. */
3330 action_empty = fcurves_for_action_slot(action, adt->slot_handle).is_empty();
3331 }
3332 else {
3333 action_empty = true;
3334 }
3335
3336 /* 2) No NLA Tracks and/or NLA Strips */
3337 if (adt->nla_tracks.first_ == nullptr) {
3338 nla_empty = true;
3339 }
3340 else {
3341 /* empty tracks? */
3342 for (NlaTrack &nlt : adt->nla_tracks) {
3343 if (nlt.strips.first_) {
3344 /* stop searching, as we found one that actually had stuff we don't want lost
3345 * NOTE: nla_empty gets reset to false, as a previous track may have been empty
3346 */
3347 nla_empty = false;
3348 break;
3349 }
3350 if (nlt.strips.first_ == nullptr) {
3351 /* this track is empty, but another one may still have stuff in it, so can't break yet */
3352 nla_empty = true;
3353 }
3354 }
3355 }
3356
3357 /* 3) Drivers */
3358 drivers_empty = (adt->drivers.first_ == nullptr);
3359
3360 /* remove AnimData? */
3361 if (action_empty && nla_empty && drivers_empty) {
3362 BKE_animdata_free(id, true);
3363 }
3364 }
3365
3366 /* free temp data */
3367 ANIM_animdata_freelist(&anim_data);
3368
3369 /* send notifier that things have changed */
3372
3373 return OPERATOR_FINISHED;
3374}
3375
3377{
3378 /* identifiers */
3379 ot->name = "Remove Empty Animation Data";
3380 ot->idname = "ANIM_OT_channels_clean_empty";
3381 ot->description = "Delete all empty animation data containers from visible data-blocks";
3382
3383 /* API callbacks. */
3386
3387 /* flags */
3389}
3390
3392
3393/* -------------------------------------------------------------------- */
3396
3398{
3399 ScrArea *area = CTX_wm_area(C);
3400
3401 /* channels region test */
3402 /* TODO: could enhance with actually testing if channels region? */
3403 if (ELEM(nullptr, area, CTX_wm_region(C))) {
3404 return false;
3405 }
3406
3407 /* animation editor test - Action/Dope-sheet/etc. and Graph only */
3408 if (ELEM(area->spacetype, SPACE_ACTION, SPACE_GRAPH) == 0) {
3409 return false;
3410 }
3411
3412 return true;
3413}
3414
3416{
3417 bAnimContext ac;
3418
3419 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
3420 int filter;
3421
3422 /* get editor data */
3423 if (ANIM_animdata_get_context(C, &ac) == 0) {
3424 return OPERATOR_CANCELLED;
3425 }
3426
3427 /* filter data */
3430 &ac, &anim_data, eAnimFilter_Flags(filter), ac.data, eAnimCont_Types(ac.datatype));
3431
3432 /* loop through filtered data and clean curves */
3433 for (bAnimListElem &ale : anim_data) {
3434 FCurve *fcu = static_cast<FCurve *>(ale.data);
3435
3436 /* remove disabled flags from F-Curves */
3437 fcu->flag &= ~FCURVE_DISABLED;
3438
3439 /* for drivers, let's do the same too */
3440 if (fcu->driver) {
3442 }
3443
3444 /* tag everything for updates - in particular, this is needed to get drivers working again */
3445 ale.update |= ANIM_UPDATE_DEPS;
3446 }
3447
3448 ANIM_animdata_update(&ac, &anim_data);
3449 ANIM_animdata_freelist(&anim_data);
3450
3451 /* send notifier that things have changed */
3453
3454 return OPERATOR_FINISHED;
3455}
3456
3458{
3459 /* identifiers */
3460 ot->name = "Revive Disabled F-Curves";
3461 ot->idname = "ANIM_OT_channels_fcurves_enable";
3462 ot->description = "Clear 'disabled' tag from all F-Curves to get broken F-Curves working again";
3463
3464 /* API callbacks. */
3467
3468 /* flags */
3470}
3471
3473
3474/* -------------------------------------------------------------------- */
3477
3478/* XXX: make this generic? */
3480{
3481 ScrArea *area = CTX_wm_area(C);
3482
3483 if (area == nullptr) {
3484 return false;
3485 }
3486
3487 /* animation editor with dope-sheet */
3489}
3490
3492 wmOperator * /*op*/,
3493 const wmEvent * /*event*/)
3494{
3495 ScrArea *area = CTX_wm_area(C);
3496 ARegion *region_channels = BKE_area_find_region_type(area, RGN_TYPE_CHANNELS);
3497
3498 /* Show the channel region if it's hidden. This means that direct activation of the input field
3499 * is impossible, as it may not exist yet. For that reason, the actual activation is deferred to
3500 * the modal callback function; by the time it runs, the screen has been redrawn and the UI
3501 * element is there to activate. */
3502 if (region_channels->flag & RGN_FLAG_HIDDEN) {
3503 ED_region_toggle_hidden(C, region_channels);
3504 ED_region_tag_redraw(region_channels);
3505 }
3506 bAnimContext ac;
3507 if (ANIM_animdata_get_context(C, &ac) == 0) {
3508 return OPERATOR_CANCELLED;
3509 }
3510
3511 ED_region_activate_rna_prop(C, region_channels, ac.ads, "filter_text");
3512
3513 return OPERATOR_FINISHED;
3514}
3515
3517{
3518 /* identifiers */
3519 ot->name = "Filter Channels";
3520 ot->idname = "ANIM_OT_channels_select_filter";
3521 ot->description =
3522 "Start entering text which filters the set of channels shown to only include those with "
3523 "matching names";
3524
3525 /* callbacks */
3528}
3529
3531
3532/* -------------------------------------------------------------------- */
3535
3537{
3538 bAnimContext ac;
3539
3540 /* get editor data */
3541 if (ANIM_animdata_get_context(C, &ac) == 0) {
3542 return OPERATOR_CANCELLED;
3543 }
3544
3545 /* 'standard' behavior - check if selected, then apply relevant selection */
3546 const int action = RNA_enum_get(op->ptr, "action");
3547 switch (action) {
3548 case SEL_TOGGLE:
3550 break;
3551 case SEL_SELECT:
3553 break;
3554 case SEL_DESELECT:
3556 break;
3557 case SEL_INVERT:
3559 break;
3560 default:
3561 BLI_assert(0);
3562 break;
3563 }
3564
3565 /* send notifier that things have changed */
3567
3568 return OPERATOR_FINISHED;
3569}
3570
3572{
3573 /* identifiers */
3574 ot->name = "Select All";
3575 ot->idname = "ANIM_OT_channels_select_all";
3576 ot->description = "Toggle selection of all animation channels";
3577
3578 /* API callbacks. */
3581
3582 /* flags */
3584
3585 /* properties */
3587}
3588
3590
3591/* -------------------------------------------------------------------- */
3594
3595static void box_select_anim_channels(bAnimContext *ac, const rcti &rect, short selectmode)
3596{
3597 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
3598 int filter;
3599
3600 SpaceNla *snla = reinterpret_cast<SpaceNla *>(ac->sl);
3601 View2D *v2d = &ac->region->v2d;
3602 rctf rectf;
3603
3604 /* convert border-region to view coordinates */
3605 ui::view2d_region_to_view(v2d, rect.xmin, rect.ymin + 2, &rectf.xmin, &rectf.ymin);
3606 ui::view2d_region_to_view(v2d, rect.xmax, rect.ymax - 2, &rectf.xmax, &rectf.ymax);
3607
3608 /* filter data */
3610
3612 ac, &anim_data, eAnimFilter_Flags(filter), ac->data, eAnimCont_Types(ac->datatype));
3613
3614 float ymax;
3615 if (ac->datatype == ANIMCONT_NLA) {
3616 ymax = NLATRACK_FIRST_TOP(ac);
3617 }
3618 else {
3620 }
3621
3622 /* loop over data, doing box select */
3623 for (bAnimListElem &ale : anim_data) {
3624 float ymin;
3625
3626 if (ac->datatype == ANIMCONT_NLA) {
3627 ymin = ymax - NLATRACK_STEP(snla);
3628 }
3629 else {
3630 ymin = ymax - ANIM_UI_get_channel_step();
3631 }
3632
3633 /* if channel is within border-select region, alter it */
3634 if (ymax >= rectf.ymin && ymin <= rectf.ymax) {
3635 /* set selection flags only */
3637 ac, &ale, ACHANNEL_SETTING_SELECT, eAnimChannels_SetFlag(selectmode));
3638
3639 /* type specific actions */
3640 switch (ale.type) {
3641 case ANIMTYPE_GROUP: {
3642 bActionGroup *agrp = static_cast<bActionGroup *>(ale.data);
3643 select_pchan_for_action_group(ac, agrp, &ale, true);
3644 /* always clear active flag after doing this */
3645 agrp->flag &= ~AGRP_ACTIVE;
3646 break;
3647 }
3648 case ANIMTYPE_NLATRACK: {
3649 NlaTrack *nlt = static_cast<NlaTrack *>(ale.data);
3650
3651 /* for now, it's easier just to do this here manually, as defining a new type
3652 * currently adds complications when doing other stuff
3653 */
3654 ACHANNEL_SET_FLAG(nlt, selectmode, NLATRACK_SELECTED);
3655 break;
3656 }
3657 case ANIMTYPE_ACTION_SLOT: {
3658 using namespace blender::animrig;
3659 Slot *slot = static_cast<Slot *>(ale.data);
3661 break;
3662 }
3663 case ANIMTYPE_NONE:
3664 case ANIMTYPE_ANIMDATA:
3666 case ANIMTYPE_SUMMARY:
3667 case ANIMTYPE_SCENE:
3668 case ANIMTYPE_OBJECT:
3669 case ANIMTYPE_FCURVE:
3671 case ANIMTYPE_NLACURVE:
3673 case ANIMTYPE_FILLACTD:
3675 case ANIMTYPE_DSMAT:
3676 case ANIMTYPE_DSLAM:
3677 case ANIMTYPE_DSCAM:
3679 case ANIMTYPE_DSCUR:
3680 case ANIMTYPE_DSSKEY:
3681 case ANIMTYPE_DSWOR:
3682 case ANIMTYPE_DSNTREE:
3683 case ANIMTYPE_DSPART:
3684 case ANIMTYPE_DSMBALL:
3685 case ANIMTYPE_DSARM:
3686 case ANIMTYPE_DSMESH:
3687 case ANIMTYPE_DSTEX:
3688 case ANIMTYPE_DSLAT:
3690 case ANIMTYPE_DSSPK:
3691 case ANIMTYPE_DSGPENCIL:
3692 case ANIMTYPE_DSMCLIP:
3693 case ANIMTYPE_DSHAIR:
3695 case ANIMTYPE_DSVOLUME:
3697 case ANIMTYPE_SHAPEKEY:
3698 case ANIMTYPE_GPLAYER:
3703 case ANIMTYPE_MASKLAYER:
3704 case ANIMTYPE_NLAACTION:
3705 case ANIMTYPE_PALETTE:
3706 case ANIMTYPE_NUM_TYPES:
3707 break;
3708 }
3709 }
3710
3711 /* set minimum extent to be the maximum of the next channel */
3712 ymax = ymin;
3713 }
3714
3715 /* cleanup */
3716 ANIM_animdata_freelist(&anim_data);
3717}
3718
3720{
3721 bAnimContext ac;
3722 rcti rect;
3723 short selectmode = 0;
3724 const bool select = !RNA_boolean_get(op->ptr, "deselect");
3725 const bool extend = RNA_boolean_get(op->ptr, "extend");
3726
3727 /* get editor data */
3728 if (ANIM_animdata_get_context(C, &ac) == 0) {
3729 return OPERATOR_CANCELLED;
3730 }
3731
3732 /* get settings from operator */
3734
3735 if (!extend) {
3737 }
3738
3739 if (select) {
3740 selectmode = ACHANNEL_SETFLAG_ADD;
3741 }
3742 else {
3743 selectmode = ACHANNEL_SETFLAG_CLEAR;
3744 }
3745
3746 /* apply box_select animation channels */
3747 box_select_anim_channels(&ac, rect, selectmode);
3748
3749 /* send notifier that things have changed */
3751
3752 return OPERATOR_FINISHED;
3753}
3754
3756{
3757 /* identifiers */
3758 ot->name = "Box Select";
3759 ot->idname = "ANIM_OT_channels_select_box";
3760 ot->description = "Select all animation channels within the specified region";
3761
3762 /* API callbacks. */
3767
3769
3770 /* flags */
3772
3773 /* rna */
3775}
3776
3778
3779/* -------------------------------------------------------------------- */
3784
3785static bool rename_anim_channels(bAnimContext *ac, int channel_index)
3786{
3787 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
3788 const bAnimChannelType *acf;
3789 bAnimListElem *ale;
3790 int filter;
3791 bool success = false;
3792
3793 /* Filter relevant channels (note that grease-pencil/annotations are not displayed in Graph
3794 * Editor). */
3798 }
3800 ac, &anim_data, eAnimFilter_Flags(filter), ac->data, eAnimCont_Types(ac->datatype));
3801
3802 /* Get channel that was clicked on from index. */
3803 ale = static_cast<bAnimListElem *>(BLI_findlink(&anim_data, channel_index));
3804 if (ale == nullptr) {
3805 /* channel not found */
3806 if (G.debug & G_DEBUG) {
3807 printf("Error: animation channel (index = %d) not found in rename_anim_channels()\n",
3808 channel_index);
3809 }
3810
3811 ANIM_animdata_freelist(&anim_data);
3812 return false;
3813 }
3814
3815 /* Don't allow renaming linked/liboverride channels. */
3816 if (ale->fcurve_owner_id != nullptr &&
3818 {
3819 ANIM_animdata_freelist(&anim_data);
3820 return false;
3821 }
3822 if (ale->id != nullptr) {
3823 if (!ID_IS_EDITABLE(ale->id)) {
3824 ANIM_animdata_freelist(&anim_data);
3825 return false;
3826 }
3827 /* There is one exception to not allowing renaming on liboverride channels: locally-inserted
3828 * NLA tracks. */
3829 if (ID_IS_OVERRIDE_LIBRARY(ale->id)) {
3830 switch (ale->type) {
3831 case ANIMTYPE_NLATRACK: {
3832 NlaTrack *nlt = static_cast<NlaTrack *>(ale->data);
3833 if ((nlt->flag & NLATRACK_OVERRIDELIBRARY_LOCAL) == 0) {
3834 ANIM_animdata_freelist(&anim_data);
3835 return false;
3836 }
3837 break;
3838 }
3839 default:
3840 ANIM_animdata_freelist(&anim_data);
3841 return false;
3842 }
3843 }
3844 }
3845
3846 /* check that channel can be renamed */
3847 acf = ANIM_channel_get_typeinfo(ale);
3848 if (acf && acf->name_prop) {
3849 PointerRNA ptr;
3850 PropertyRNA *prop;
3851
3852 /* ok if we can get name property to edit from this channel */
3853 if (acf->name_prop(ale, &ptr, &prop)) {
3854 /* Actually showing the rename text-field is done on redraw,
3855 * so here we just store the index of this channel in the
3856 * dope-sheet data, which will get utilized when drawing the channel.
3857 *
3858 * +1 factor is for backwards compatibility issues. */
3859 if (ac->ads) {
3860 ac->ads->renameIndex = channel_index + 1;
3861 success = true;
3862 }
3863 }
3864 }
3865
3866 /* free temp data and tag for refresh */
3867 ANIM_animdata_freelist(&anim_data);
3869 return success;
3870}
3871
3872static int animchannels_channel_get(bAnimContext *ac, const int mval[2])
3873{
3874 ARegion *region;
3875 View2D *v2d;
3876 int channel_index;
3877 float x, y;
3878
3879 /* get useful pointers from animation context data */
3880 region = ac->region;
3881 v2d = &region->v2d;
3882
3883 /* Figure out which channel user clicked in. */
3884 ui::view2d_region_to_view(v2d, mval[0], mval[1], &x, &y);
3885
3886 if (ac->datatype == ANIMCONT_NLA) {
3887 SpaceNla *snla = reinterpret_cast<SpaceNla *>(ac->sl);
3889 NLATRACK_STEP(snla),
3890 0,
3892 x,
3893 y,
3894 nullptr,
3895 &channel_index);
3896 }
3897 else {
3900 0,
3902 x,
3903 y,
3904 nullptr,
3905 &channel_index);
3906 }
3907
3908 return channel_index;
3909}
3910
3912 wmOperator * /*op*/,
3913 const wmEvent *event)
3914{
3915 bAnimContext ac;
3916 int channel_index;
3917
3918 /* get editor data */
3919 if (ANIM_animdata_get_context(C, &ac) == 0) {
3920 return OPERATOR_CANCELLED;
3921 }
3922
3923 channel_index = animchannels_channel_get(&ac, event->mval);
3924
3925 /* handle click */
3926 if (rename_anim_channels(&ac, channel_index)) {
3928 return OPERATOR_FINISHED;
3929 }
3930
3931 /* allow event to be handled by selectall operator */
3932 return OPERATOR_PASS_THROUGH;
3933}
3934
3936{
3937 /* identifiers */
3938 ot->name = "Rename Channel";
3939 ot->idname = "ANIM_OT_channels_rename";
3940 ot->description = "Rename animation channel under mouse";
3941
3942 /* API callbacks. */
3945}
3946
3948
3949/* -------------------------------------------------------------------- */
3952
3953/* Handle selection changes due to clicking on channels. Settings will get caught by UI code... */
3954
3956 const short /* eEditKeyframes_Select or -1 */ selectmode)
3957{
3958 Scene *sce = static_cast<Scene *>(ale->data);
3959 AnimData *adt = sce->adt;
3960
3961 /* set selection status */
3962 if (selectmode == SELECT_INVERT) {
3963 /* swap select */
3964 sce->flag ^= SCE_DS_SELECTED;
3965 if (adt) {
3966 adt->flag ^= ADT_UI_SELECTED;
3967 }
3968 }
3969 else {
3970 sce->flag |= SCE_DS_SELECTED;
3971 if (adt) {
3972 adt->flag |= ADT_UI_SELECTED;
3973 }
3974 }
3975 return (ND_ANIMCHAN | NA_SELECTED);
3976}
3977
3978/* Return whether active channel of given type is present. */
3980{
3981 ListBaseT<bAnimListElem> anim_data = anim_channels_for_selection(ac);
3982 bool is_active_found = false;
3983
3984 for (bAnimListElem &ale : anim_data) {
3985 if (ale.type != type) {
3986 continue;
3987 }
3988 is_active_found = ANIM_is_active_channel(&ale);
3989 if (is_active_found) {
3990 break;
3991 }
3992 }
3993
3994 ANIM_animdata_freelist(&anim_data);
3995 return is_active_found;
3996}
3997
3998/* Select channels that lies between active channel and cursor_elem. */
4000{
4001 ListBaseT<bAnimListElem> anim_data = anim_channels_for_selection(ac);
4002 bool in_selection_range = false;
4003
4004 for (bAnimListElem &ale : anim_data) {
4005
4006 /* Allow selection when active channel and `cursor_elem` are of same type. */
4007 if (ale.type != cursor_elem->type) {
4008 continue;
4009 }
4010
4011 const bool is_cursor_elem = (ale.data == cursor_elem->data);
4012 const bool is_active_elem = ANIM_is_active_channel(&ale);
4013
4014 /* Restrict selection when active element is not found and group-channels are excluded from the
4015 * selection. */
4016 if (is_active_elem || is_cursor_elem) {
4017 /* Select first and last element from the range. Reverse selection status on extremes. */
4019 in_selection_range = !in_selection_range;
4020 if (ale.type == ANIMTYPE_GROUP) {
4021 select_pchan_for_action_group(ac, static_cast<bActionGroup *>(ale.data), &ale, false);
4022 }
4023 }
4024 else if (in_selection_range) {
4025 /* Select elements between the range. */
4027 if (ale.type == ANIMTYPE_GROUP) {
4028 select_pchan_for_action_group(ac, static_cast<bActionGroup *>(ale.data), &ale, false);
4029 }
4030 }
4031
4032 if (is_active_elem && is_cursor_elem) {
4033 /* Selection range is only one element when active channel and clicked channel are same. So
4034 * exit out of the loop when this condition is hit. */
4035 break;
4036 }
4037 }
4038
4039 ANIM_animdata_freelist(&anim_data);
4040}
4041
4043 bAnimContext *ac,
4044 bAnimListElem *ale,
4045 const short /* eEditKeyframes_Select or -1 */ selectmode)
4046{
4047 using namespace blender::ed;
4048 const Main *bmain = CTX_data_main(C);
4049 Scene *scene = ac->scene;
4050 ViewLayer *view_layer = ac->view_layer;
4051 Base *base = static_cast<Base *>(ale->data);
4052 Object *ob = base->object;
4053 AnimData *adt = ob->adt;
4054
4055 if ((base->flag & BASE_SELECTABLE) == 0) {
4056 return 0;
4057 }
4058
4059 if (selectmode == SELECT_INVERT) {
4060 /* swap select */
4062
4063 if (adt) {
4064 adt->flag ^= ADT_UI_SELECTED;
4065 }
4066 }
4067 else if (selectmode == SELECT_EXTEND_RANGE) {
4069 animchannel_select_range(ac, ale);
4070 }
4071 else {
4072 /* deselect all */
4074 BKE_view_layer_synced_ensure(*bmain, scene, view_layer);
4075 /* TODO: should this deselect all other types of channels too? */
4076 for (Base &b : *BKE_view_layer_object_bases_get(view_layer)) {
4078 if (b.object->adt) {
4079 b.object->adt->flag &= ~(ADT_UI_SELECTED | ADT_UI_ACTIVE);
4080 }
4081 }
4082
4083 /* select object now */
4085 if (adt) {
4086 adt->flag |= ADT_UI_SELECTED;
4087 }
4088 }
4089
4090 /* Change active object - regardless of whether it is now selected, see: #37883.
4091 *
4092 * Ensure we exit edit-mode on whatever object was active before
4093 * to avoid getting stuck there, see: #48747. */
4094 object::base_activate_with_mode_exit_if_needed(C, base); /* adds notifier */
4095
4096 /* Similar to outliner, do not change active element when selecting elements in range. */
4097 if ((adt) && (adt->flag & ADT_UI_SELECTED) && (selectmode != SELECT_EXTEND_RANGE)) {
4098 adt->flag |= ADT_UI_ACTIVE;
4099 }
4100
4101 return (ND_ANIMCHAN | NA_SELECTED);
4102}
4103
4105 bAnimListElem *ale,
4106 const short /* eEditKeyframes_Select or -1 */ selectmode)
4107{
4108 if (ale->adt == nullptr) {
4109 return 0;
4110 }
4111
4112 /* select/deselect */
4113 if (selectmode == SELECT_INVERT) {
4114 /* inverse selection status of this AnimData block only */
4115 ale->adt->flag ^= ADT_UI_SELECTED;
4116 }
4117 else if (selectmode == SELECT_EXTEND_RANGE) {
4119 animchannel_select_range(ac, ale);
4120 }
4121 else {
4122 /* select AnimData block by itself */
4124 ale->adt->flag |= ADT_UI_SELECTED;
4125 }
4126
4127 /* Similar to outliner, do not change active element when selecting elements in range. */
4128 if ((ale->adt->flag & ADT_UI_SELECTED) && (selectmode != SELECT_EXTEND_RANGE)) {
4129 ale->adt->flag |= ADT_UI_ACTIVE;
4130 }
4131
4132 return (ND_ANIMCHAN | NA_SELECTED);
4133}
4134
4136 bAnimListElem *ale,
4137 const short /* eEditKeyframes_Select or -1 */ selectmode,
4138 const int filter)
4139{
4140 bActionGroup *agrp = static_cast<bActionGroup *>(ale->data);
4141 Object *ob = nullptr;
4142 bPoseChannel *pchan = nullptr;
4143
4144 /* Armatures-Specific Feature:
4145 * Since groups are used to collect F-Curves of the same Bone by default
4146 * (via Keying Sets) so that they can be managed better, we try to make
4147 * things here easier for animators by mapping group selection to bone
4148 * selection.
4149 *
4150 * Only do this if "Only Selected" dope-sheet filter is not active, or else it
4151 * becomes too unpredictable/tricky to manage
4152 */
4153 if ((ac->filters.flag & ADS_FILTER_ONLYSEL) == 0) {
4154 if ((ale->id) && (GS(ale->id->name) == ID_OB)) {
4155 ob = reinterpret_cast<Object *>(ale->id);
4156
4157 if (ob->type == OB_ARMATURE) {
4158 /* Assume for now that any group with corresponding name is what we want
4159 * (i.e. for an armature whose location is animated, things would break
4160 * if the user were to add a bone named "Location").
4161 *
4162 * TODO: check the first F-Curve or so to be sure...
4163 */
4164 pchan = BKE_pose_channel_find_name(ob->pose, agrp->name);
4165 }
4166 }
4167 }
4168
4169 /* select/deselect group */
4170 if (selectmode == SELECT_INVERT) {
4171 /* inverse selection status of this group only */
4172 agrp->flag ^= AGRP_SELECTED;
4173 }
4174 else if (selectmode == SELECT_EXTEND_RANGE) {
4176 animchannel_select_range(ac, ale);
4177 }
4178 else if (selectmode == -1) {
4179 /* select all in group (and deselect everything else) */
4180 FCurve *fcu;
4181
4182 /* deselect all other channels */
4184 if (pchan) {
4186 }
4187
4188 /* only select channels in group and group itself */
4189 for (fcu = agrp->channels.first(); fcu && fcu->grp == agrp; fcu = fcu->next) {
4190 fcu->flag |= FCURVE_SELECTED;
4191 }
4192 agrp->flag |= AGRP_SELECTED;
4193 }
4194 else {
4195 /* select group by itself */
4197 if (pchan) {
4199 }
4200
4201 agrp->flag |= AGRP_SELECTED;
4202 }
4203
4204 /* if group is selected now, make group the 'active' one in the visible list.
4205 * Similar to outliner, do not change active element when selecting elements in range. */
4206 if (agrp->flag & AGRP_SELECTED) {
4207 if (selectmode != SELECT_EXTEND_RANGE) {
4209 ac->data,
4212 agrp,
4214 if (pchan) {
4215 ED_pose_bone_select(ob, pchan, true, true);
4216 }
4217 }
4218 }
4219 else {
4220 if (selectmode != SELECT_EXTEND_RANGE) {
4222 ac->data,
4225 nullptr,
4227 if (pchan) {
4228 ED_pose_bone_select(ob, pchan, false, true);
4229 }
4230 }
4231 }
4232
4233 return (ND_ANIMCHAN | NA_SELECTED);
4234}
4235
4237 bAnimListElem *ale,
4238 const short /* eEditKeyframes_Select or -1 */ selectmode,
4239 const int filter)
4240{
4241 FCurve *fcu = static_cast<FCurve *>(ale->data);
4242
4243 /* select/deselect */
4244 if (selectmode == SELECT_INVERT) {
4245 /* inverse selection status of this F-Curve only */
4246 fcu->flag ^= FCURVE_SELECTED;
4247 }
4248 else if (selectmode == SELECT_EXTEND_RANGE) {
4250 animchannel_select_range(ac, ale);
4251 }
4252 else {
4253 /* select F-Curve by itself */
4255 fcu->flag |= FCURVE_SELECTED;
4256 }
4257
4258 /* if F-Curve is selected now, make F-Curve the 'active' one in the visible list.
4259 * Similar to outliner, do not change active element when selecting elements in range. */
4260 if ((fcu->flag & FCURVE_SELECTED) && (selectmode != SELECT_EXTEND_RANGE)) {
4262 ac->data,
4265 fcu,
4266 eAnim_ChannelType(ale->type));
4267 }
4268
4269 return (ND_ANIMCHAN | NA_SELECTED);
4270}
4272 bAnimListElem *ale,
4273 short /* eEditKeyframes_Select or -1 */ selectmode)
4274{
4276 "fcurve_owner_id of an Action Slot should be an Action");
4277 animrig::Action *action = reinterpret_cast<animrig::Action *>(ale->fcurve_owner_id);
4278 animrig::Slot *slot = static_cast<animrig::Slot *>(ale->data);
4279
4280 if (selectmode == SELECT_INVERT) {
4281 selectmode = slot->is_selected() ? SELECT_SUBTRACT : SELECT_ADD;
4282 }
4283
4284 switch (selectmode) {
4285 case SELECT_REPLACE:
4288 case SELECT_ADD:
4289 slot->set_selected(true);
4290 action->slot_active_set(slot->handle);
4291 break;
4292 case SELECT_SUBTRACT:
4293 slot->set_selected(false);
4294 break;
4297 animchannel_select_range(ac, ale);
4298 break;
4299 case SELECT_INVERT:
4301 break;
4302 }
4303
4304 return (ND_ANIMCHAN | NA_SELECTED);
4305}
4306
4308 bAnimContext *ac,
4309 bAnimListElem *ale,
4310 const short /* eEditKeyframes_Select or -1 */ selectmode)
4311{
4312 KeyBlock *kb = static_cast<KeyBlock *>(ale->data);
4313 Key *key = reinterpret_cast<Key *>(ale->id);
4314 Object &ob = *ac->obact;
4315
4316 ob.shapenr = BLI_findindex(&key->block, kb) + 1;
4317
4318 /* select/deselect */
4319 if (selectmode == SELECT_INVERT) {
4320 /* inverse selection status of this ShapeKey only */
4321 kb->flag ^= KEYBLOCK_SEL;
4322 }
4323 else {
4324 /* select ShapeKey by itself */
4326 kb->flag |= KEYBLOCK_SEL;
4327 }
4328
4329 PointerRNA object_ptr = RNA_pointer_create_discrete(&ob.id, RNA_Object, &ob);
4330 PropertyRNA *prop = RNA_struct_find_property(&object_ptr, "active_shape_key_index");
4331 RNA_property_update(C, &object_ptr, prop);
4332
4333 return (ND_ANIMCHAN | NA_SELECTED);
4334}
4335
4337{
4338 AnimData *adt = static_cast<AnimData *>(ale->data);
4339
4340 /* Toggle expand:
4341 * - Although the triangle widget already allows this,
4342 * since there's nothing else that can be done here now,
4343 * let's just use it for easier expand/collapse for now.
4344 */
4346
4347 return (ND_ANIMCHAN | NA_EDITED);
4348}
4349
4351 bAnimContext *ac,
4352 bAnimListElem *ale,
4353 const short /* eEditKeyframes_Select or -1 */ selectmode,
4354 const int filter)
4355{
4356 bGPdata *gpd = reinterpret_cast<bGPdata *>(ale->id);
4357 bGPDlayer *gpl = static_cast<bGPDlayer *>(ale->data);
4358
4359 /* select/deselect */
4360 if (selectmode == SELECT_INVERT) {
4361 /* invert selection status of this layer only */
4362 gpl->flag ^= GP_LAYER_SELECT;
4363 }
4364 else if (selectmode == SELECT_EXTEND_RANGE) {
4366 animchannel_select_range(ac, ale);
4367 }
4368 else {
4369 /* select layer by itself */
4371 gpl->flag |= GP_LAYER_SELECT;
4372 }
4373
4374 /* change active layer, if this is selected (since we must always have an active layer).
4375 * Similar to outliner, do not change active element when selecting elements in range. */
4376 if ((gpl->flag & GP_LAYER_SELECT) && (selectmode != SELECT_EXTEND_RANGE)) {
4378 ac->data,
4381 gpl,
4383 /* update other layer status */
4386 }
4387
4388 /* Grease Pencil updates */
4390 return (ND_ANIMCHAN | NA_EDITED); /* Animation Editors updates */
4391}
4392
4394{
4395 GreasePencil *grease_pencil = static_cast<GreasePencil *>(ale->data);
4396
4397 /* Toggle expand:
4398 * - Although the triangle widget already allows this,
4399 * the whole channel can also be used for this purpose.
4400 */
4402
4403 return (ND_ANIMCHAN | NA_EDITED);
4404}
4405
4407{
4408 using namespace blender::bke::greasepencil;
4409 LayerGroup &layer_group = static_cast<GreasePencilLayerTreeGroup *>(ale->data)->wrap();
4410
4411 /* Toggle expand:
4412 * - Although the triangle widget already allows this,
4413 * the whole channel can also be used for this purpose.
4414 */
4415 layer_group.set_expanded(!layer_group.is_expanded());
4418 return (ND_ANIMCHAN | NA_EDITED);
4419}
4420
4422 bAnimContext *ac,
4423 bAnimListElem *ale,
4424 const short selectmode,
4425 const int /*filter*/)
4426{
4427 using namespace blender::bke::greasepencil;
4428 Layer *layer = static_cast<Layer *>(ale->data);
4429 GreasePencil *grease_pencil = reinterpret_cast<GreasePencil *>(ale->id);
4430
4431 if (selectmode == SELECT_INVERT) {
4432 layer->set_selected(!layer->is_selected());
4433 }
4434 else if (selectmode == SELECT_EXTEND_RANGE) {
4436 animchannel_select_range(ac, ale);
4437 }
4438 else {
4440 layer->set_selected(true);
4441 }
4442
4443 /* Active channel is not changed during range select. */
4444 if (layer->is_selected() && (selectmode != SELECT_EXTEND_RANGE)) {
4445 grease_pencil->set_active_layer(layer);
4447 CTX_wm_message_bus(C), &grease_pencil->id, grease_pencil, GreasePencilv3Layers, active);
4449 }
4450
4452 return (ND_ANIMCHAN | NA_EDITED);
4453}
4454
4456{
4457 Mask *mask = static_cast<Mask *>(ale->data);
4458
4459 /* Toggle expand
4460 * - Although the triangle widget already allows this,
4461 * the whole channel can also be used for this purpose.
4462 */
4463 mask->flag ^= MASK_ANIMF_EXPAND;
4464
4465 return (ND_ANIMCHAN | NA_EDITED);
4466}
4467
4469 bAnimListElem *ale,
4470 const short /* eEditKeyframes_Select or -1 */ selectmode)
4471{
4472 MaskLayer *masklay = static_cast<MaskLayer *>(ale->data);
4473
4474 /* select/deselect */
4475 if (selectmode == SELECT_INVERT) {
4476 /* invert selection status of this layer only */
4477 masklay->flag ^= MASK_LAYERFLAG_SELECT;
4478 }
4479 else {
4480 /* select layer by itself */
4482 masklay->flag |= MASK_LAYERFLAG_SELECT;
4483 }
4484
4485 return (ND_ANIMCHAN | NA_EDITED);
4486}
4487
4489 bAnimContext *ac,
4490 const int channel_index,
4491 short /* eEditKeyframes_Select or -1 */ selectmode)
4492{
4493 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
4494 bAnimListElem *ale;
4495 int filter;
4496 int notifierFlags = 0;
4497 ScrArea *area = CTX_wm_area(C);
4498
4499 /* get the channel that was clicked on */
4500 /* filter channels */
4502 if (ELEM(area->spacetype, SPACE_NLA, SPACE_GRAPH)) {
4504 }
4506 ac, &anim_data, eAnimFilter_Flags(filter), ac->data, eAnimCont_Types(ac->datatype));
4507
4508 /* get channel from index */
4509 ale = static_cast<bAnimListElem *>(BLI_findlink(&anim_data, channel_index));
4510 if (ale == nullptr) {
4511 /* channel not found */
4512 if (G.debug & G_DEBUG) {
4513 printf("Error: animation channel (index = %d) not found in mouse_anim_channels()\n",
4514 channel_index);
4515 }
4516
4517 ANIM_animdata_freelist(&anim_data);
4518 return 0;
4519 }
4520
4521 /* selectmode -1 is a special case for ActionGroups only,
4522 * which selects all of the channels underneath it only. */
4523 /* TODO: should this feature be extended to work with other channel types too? */
4524 if ((selectmode == -1) && (ale->type != ANIMTYPE_GROUP)) {
4525 /* normal channels should not behave normally in this case */
4526 ANIM_animdata_freelist(&anim_data);
4527 return 0;
4528 }
4529
4530 /* Change selection mode to single when no active element is found. */
4531 if ((selectmode == SELECT_EXTEND_RANGE) &&
4533 {
4534 selectmode = SELECT_INVERT;
4535 }
4536
4537 /* action to take depends on what channel we've got */
4538 /* WARNING: must keep this in sync with the equivalent function in `nla_tracks.cc`. */
4539 switch (ale->type) {
4540 case ANIMTYPE_SCENE:
4541 notifierFlags |= click_select_channel_scene(ale, selectmode);
4542 break;
4543 case ANIMTYPE_OBJECT:
4544 notifierFlags |= click_select_channel_object(C, ac, ale, selectmode);
4545 break;
4546 case ANIMTYPE_FILLACTD: /* Action Expander */
4547 case ANIMTYPE_FILLACT_LAYERED: /* Animation Expander */
4548 case ANIMTYPE_DSMAT: /* Datablock AnimData Expanders */
4549 case ANIMTYPE_DSLAM:
4550 case ANIMTYPE_DSCAM:
4552 case ANIMTYPE_DSCUR:
4553 case ANIMTYPE_DSSKEY:
4554 case ANIMTYPE_DSWOR:
4555 case ANIMTYPE_DSPART:
4556 case ANIMTYPE_DSMBALL:
4557 case ANIMTYPE_DSARM:
4558 case ANIMTYPE_DSMESH:
4559 case ANIMTYPE_DSNTREE:
4560 case ANIMTYPE_DSTEX:
4561 case ANIMTYPE_DSLAT:
4563 case ANIMTYPE_DSSPK:
4564 case ANIMTYPE_DSGPENCIL:
4565 case ANIMTYPE_DSMCLIP:
4566 case ANIMTYPE_DSHAIR:
4568 case ANIMTYPE_DSVOLUME:
4570 notifierFlags |= click_select_channel_dummy(ac, ale, selectmode);
4571 break;
4572 case ANIMTYPE_GROUP:
4573 notifierFlags |= click_select_channel_group(ac, ale, selectmode, filter);
4574 break;
4575 case ANIMTYPE_FCURVE:
4576 case ANIMTYPE_NLACURVE:
4577 notifierFlags |= click_select_channel_fcurve(ac, ale, selectmode, filter);
4578 break;
4580 notifierFlags |= click_select_channel_action_slot(ac, ale, selectmode);
4581 break;
4582 case ANIMTYPE_SHAPEKEY:
4583 notifierFlags |= click_select_channel_shapekey(C, ac, ale, selectmode);
4584 break;
4586 notifierFlags |= click_select_channel_nlacontrols(ale);
4587 break;
4588 case ANIMTYPE_GPLAYER:
4589 notifierFlags |= click_select_channel_gplayer(C, ac, ale, selectmode, filter);
4590 break;
4593 break;
4596 break;
4598 notifierFlags |= click_select_channel_grease_pencil_layer(C, ac, ale, selectmode, filter);
4599 break;
4601 notifierFlags |= click_select_channel_maskdatablock(ale);
4602 break;
4603 case ANIMTYPE_MASKLAYER:
4604 notifierFlags |= click_select_channel_masklayer(ac, ale, selectmode);
4605 break;
4606 default:
4607 if (G.debug & G_DEBUG) {
4608 printf("Error: Invalid channel type in mouse_anim_channels()\n");
4609 }
4610 break;
4611 }
4612
4613 /* free channels */
4614 ANIM_animdata_freelist(&anim_data);
4615
4616 /* return notifier flags */
4617 return notifierFlags;
4618}
4619
4621
4622/* -------------------------------------------------------------------- */
4625
4628 wmOperator *op,
4629 const wmEvent *event)
4630{
4631 bAnimContext ac;
4632 ARegion *region;
4633 View2D *v2d;
4634 int channel_index;
4635 int notifierFlags = 0;
4636 short selectmode;
4637 float x, y;
4638
4639 /* get editor data */
4640 if (ANIM_animdata_get_context(C, &ac) == 0) {
4641 return OPERATOR_CANCELLED;
4642 }
4643
4644 /* get useful pointers from animation context data */
4645 region = ac.region;
4646 v2d = &region->v2d;
4647
4648 /* select mode is either replace (deselect all, then add) or add/extend */
4649 if (RNA_boolean_get(op->ptr, "extend")) {
4650 selectmode = SELECT_INVERT;
4651 }
4652 else if (RNA_boolean_get(op->ptr, "extend_range")) {
4653 selectmode = SELECT_EXTEND_RANGE;
4654 }
4655 else if (RNA_boolean_get(op->ptr, "children_only")) {
4656 /* this is a bit of a special case for ActionGroups only...
4657 * should it be removed or extended to all instead? */
4658 selectmode = -1;
4659 }
4660 else {
4661 selectmode = SELECT_REPLACE;
4662 }
4663
4664 /* figure out which channel user clicked in */
4665 ui::view2d_region_to_view(v2d, event->mval[0], event->mval[1], &x, &y);
4668 0,
4670 x,
4671 y,
4672 nullptr,
4673 &channel_index);
4674
4675 /* handle mouse-click in the relevant channel then */
4676 notifierFlags = mouse_anim_channels(C, &ac, channel_index, selectmode);
4677
4678 /* set notifier that things have changed */
4679 WM_event_add_notifier(C, NC_ANIMATION | notifierFlags, nullptr);
4680
4682 event);
4683}
4684
4686{
4687 PropertyRNA *prop;
4688
4689 /* identifiers */
4690 ot->name = "Mouse Click on Channels";
4691 ot->idname = "ANIM_OT_channels_click";
4692 ot->description = "Handle mouse clicks over animation channels";
4693
4694 /* API callbacks. */
4697
4698 /* flags */
4699 ot->flag = OPTYPE_UNDO;
4700
4701 /* properties */
4702 /* NOTE: don't save settings, otherwise, can end up with some weird behavior (sticky extend)
4703 *
4704 * Key-map: Enable with `Shift`. */
4705 prop = RNA_def_boolean(ot->srna, "extend", false, "Extend Select", "");
4707
4708 prop = RNA_def_boolean(ot->srna,
4709 "extend_range",
4710 false,
4711 "Extend Range",
4712 "Selection of active channel to clicked channel");
4714
4715 /* Key-map: Enable with `Ctrl-Shift`. */
4716 prop = RNA_def_boolean(ot->srna, "children_only", false, "Select Children Only", "");
4718}
4719
4720static bool select_anim_channel_keys(bAnimContext *ac, int channel_index, bool extend)
4721{
4722 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
4723 bAnimListElem *ale;
4724 int filter;
4725 bool success = false;
4726 FCurve *fcu;
4727 int i;
4728
4729 /* get the channel that was clicked on */
4730 /* filter channels */
4734 ac, &anim_data, eAnimFilter_Flags(filter), ac->data, eAnimCont_Types(ac->datatype));
4735
4736 /* get channel from index */
4737 ale = static_cast<bAnimListElem *>(BLI_findlink(&anim_data, channel_index));
4738 if (ale == nullptr) {
4739 /* channel not found */
4740 if (G.debug & G_DEBUG) {
4741 printf("Error: animation channel (index = %d) not found in rename_anim_channels()\n",
4742 channel_index);
4743 }
4744
4745 ANIM_animdata_freelist(&anim_data);
4746 return false;
4747 }
4748
4749 /* Only FCurves can have their keys selected. */
4750 if (ale->datatype != ALE_FCURVE) {
4751 ANIM_animdata_freelist(&anim_data);
4752 return false;
4753 }
4754
4755 fcu = static_cast<FCurve *>(ale->key_data);
4756 success = (fcu != nullptr);
4757
4758 ANIM_animdata_freelist(&anim_data);
4759
4760 /* F-Curve may not have any keyframes */
4761 if (fcu && fcu->bezt) {
4762 BezTriple *bezt;
4763
4764 if (!extend) {
4767 ac, &anim_data, eAnimFilter_Flags(filter), ac->data, eAnimCont_Types(ac->datatype));
4768 for (bAnimListElem &ale : anim_data) {
4769 FCurve *fcu_inner = static_cast<FCurve *>(ale.key_data);
4770
4771 if (fcu_inner != nullptr && fcu_inner->bezt != nullptr) {
4772 for (i = 0, bezt = fcu_inner->bezt; i < fcu_inner->totvert; i++, bezt++) {
4773 bezt->f2 = bezt->f1 = bezt->f3 = eBezTriple_Flag{};
4774 }
4775 }
4776 }
4777
4778 ANIM_animdata_freelist(&anim_data);
4779 }
4780
4781 for (i = 0, bezt = fcu->bezt; i < fcu->totvert; i++, bezt++) {
4782 bezt->f2 = bezt->f1 = bezt->f3 = BEZT_FLAG_SELECT;
4783 }
4784 }
4785
4786 /* free temp data and tag for refresh */
4788 return success;
4789}
4790
4792 wmOperator *op,
4793 const wmEvent *event)
4794{
4795 bAnimContext ac;
4796 int channel_index;
4797 bool extend = RNA_boolean_get(op->ptr, "extend");
4798
4799 /* get editor data */
4800 if (ANIM_animdata_get_context(C, &ac) == 0) {
4801 return OPERATOR_CANCELLED;
4802 }
4803
4804 channel_index = animchannels_channel_get(&ac, event->mval);
4805
4806 /* handle click */
4807 if (select_anim_channel_keys(&ac, channel_index, extend)) {
4809 return OPERATOR_FINISHED;
4810 }
4811
4812 /* allow event to be handled by selectall operator */
4813 return OPERATOR_PASS_THROUGH;
4814}
4815
4817{
4818 PropertyRNA *prop;
4819
4820 /* identifiers */
4821 ot->name = "Select Channel Keyframes";
4822 ot->idname = "ANIM_OT_channel_select_keys";
4823 ot->description = "Select all keyframes of channel under mouse";
4824
4825 /* API callbacks. */
4828
4829 ot->flag = OPTYPE_UNDO;
4830
4831 prop = RNA_def_boolean(ot->srna, "extend", false, "Extend", "Extend selection");
4833}
4834
4836
4837/* -------------------------------------------------------------------- */
4840
4841static void get_view_range(Scene *scene, const bool use_preview_range, float r_range[2])
4842{
4843 if (use_preview_range && scene->r.flag & SCER_PRV_RANGE) {
4844 r_range[0] = scene->r.psfra;
4845 r_range[1] = scene->r.pefra;
4846 }
4847 else {
4848 r_range[0] = scene->r.sfra;
4849 r_range[1] = scene->r.efra;
4850 }
4851}
4852
4854{
4855 bAnimContext ac;
4856
4857 /* Get editor data. */
4858 if (ANIM_animdata_get_context(C, &ac) == 0) {
4859 return OPERATOR_CANCELLED;
4860 }
4862
4863 if (!window_region) {
4864 return OPERATOR_CANCELLED;
4865 }
4866
4867 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
4870 size_t anim_data_length = ANIM_animdata_filter(
4871 &ac, &anim_data, eAnimFilter_Flags(filter), ac.data, eAnimCont_Types(ac.datatype));
4872
4873 if (anim_data_length == 0) {
4874 BKE_report(op->reports, RPT_WARNING, "No channels to operate on");
4875 return OPERATOR_CANCELLED;
4876 }
4877
4878 float range[2];
4879 const bool use_preview_range = RNA_boolean_get(op->ptr, "use_preview_range");
4880 get_view_range(ac.scene, use_preview_range, range);
4881
4882 rctf bounds{};
4883 bounds.xmin = FLT_MAX;
4884 bounds.xmax = -FLT_MAX;
4885 bounds.ymin = FLT_MAX;
4886 bounds.ymax = -FLT_MAX;
4887
4888 const bool include_handles = RNA_boolean_get(op->ptr, "include_handles");
4889
4890 bool valid_bounds = false;
4891 for (bAnimListElem &ale : anim_data) {
4892 rctf channel_bounds;
4893 const bool found_bounds = get_channel_bounds(
4894 &ac, &ale, range, include_handles, &channel_bounds);
4895 if (found_bounds) {
4896 BLI_rctf_union(&bounds, &channel_bounds);
4897 valid_bounds = true;
4898 }
4899 }
4900
4901 if (!valid_bounds) {
4902 ANIM_animdata_freelist(&anim_data);
4903 BKE_report(op->reports, RPT_WARNING, "No keyframes to focus on");
4904 return OPERATOR_CANCELLED;
4905 }
4906
4907 add_region_padding(C, window_region, &bounds);
4908
4909 if (ac.spacetype == SPACE_ACTION) {
4910 bounds.ymin = window_region->v2d.cur.ymin;
4911 bounds.ymax = window_region->v2d.cur.ymax;
4912 }
4913
4914 const int smooth_viewtx = WM_operator_smooth_viewtx_get(op);
4915 ui::view2d_smooth_view(C, window_region, &bounds, smooth_viewtx);
4916
4917 ANIM_animdata_freelist(&anim_data);
4918
4919 return OPERATOR_FINISHED;
4920}
4921
4926
4928{
4929 /* Identifiers */
4930 ot->name = "Frame Selected Channels";
4931 ot->idname = "ANIM_OT_channels_view_selected";
4932 ot->description = "Reset viewable area to show the selected channels";
4933
4934 /* API callbacks */
4936 ot->poll = channel_view_poll;
4937
4938 ot->flag = 0;
4939
4940 ot->prop = RNA_def_boolean(ot->srna,
4941 "include_handles",
4942 true,
4943 "Include Handles",
4944 "Include handles of keyframes when calculating extents");
4945
4946 ot->prop = RNA_def_boolean(ot->srna,
4947 "use_preview_range",
4948 true,
4949 "Use Preview Range",
4950 "Ignore frames outside of the preview range");
4951}
4952
4954 wmOperator *op,
4955 const wmEvent *event)
4956{
4957 bAnimContext ac;
4958
4959 if (ANIM_animdata_get_context(C, &ac) == 0) {
4960 return OPERATOR_CANCELLED;
4961 }
4962
4964
4965 if (!window_region) {
4966 return OPERATOR_CANCELLED;
4967 }
4968
4969 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
4973 &ac, &anim_data, eAnimFilter_Flags(filter), ac.data, eAnimCont_Types(ac.datatype));
4974
4975 bAnimListElem *ale;
4976 const int channel_index = animchannels_channel_get(&ac, event->mval);
4977 ale = static_cast<bAnimListElem *>(BLI_findlink(&anim_data, channel_index));
4978 if (ale == nullptr) {
4979 ANIM_animdata_freelist(&anim_data);
4980 return OPERATOR_CANCELLED;
4981 }
4982
4983 float range[2];
4984 const bool use_preview_range = RNA_boolean_get(op->ptr, "use_preview_range");
4985
4986 get_view_range(ac.scene, use_preview_range, range);
4987
4988 rctf bounds;
4989 const bool include_handles = RNA_boolean_get(op->ptr, "include_handles");
4990 const bool found_bounds = get_channel_bounds(&ac, ale, range, include_handles, &bounds);
4991
4992 if (!found_bounds) {
4993 ANIM_animdata_freelist(&anim_data);
4994 BKE_report(op->reports, RPT_WARNING, "No keyframes to focus on");
4995 return OPERATOR_CANCELLED;
4996 }
4997
4998 add_region_padding(C, window_region, &bounds);
4999
5000 if (ac.spacetype == SPACE_ACTION) {
5001 bounds.ymin = window_region->v2d.cur.ymin;
5002 bounds.ymax = window_region->v2d.cur.ymax;
5003 }
5004
5005 const int smooth_viewtx = WM_operator_smooth_viewtx_get(op);
5006 ui::view2d_smooth_view(C, window_region, &bounds, smooth_viewtx);
5007
5008 ANIM_animdata_freelist(&anim_data);
5009
5010 return OPERATOR_FINISHED;
5011}
5012
5014{
5015 /* Identifiers */
5016 ot->name = "Frame Channel Under Cursor";
5017 ot->idname = "ANIM_OT_channel_view_pick";
5018 ot->description = "Reset viewable area to show the channel under the cursor";
5019
5020 /* API callbacks */
5022 ot->poll = channel_view_poll;
5023
5024 ot->flag = 0;
5025
5026 ot->prop = RNA_def_boolean(ot->srna,
5027 "include_handles",
5028 true,
5029 "Include Handles",
5030 "Include handles of keyframes when calculating extents");
5031
5032 ot->prop = RNA_def_boolean(ot->srna,
5033 "use_preview_range",
5034 true,
5035 "Use Preview Range",
5036 "Ignore frames outside of the preview range");
5037}
5038
5040
5041/* -------------------------------------------------------------------- */
5044
5046 {BEZT_IPO_BEZ, "BEZIER", 0, "Bézier", "New keys will be Bézier"},
5047 {BEZT_IPO_LIN, "LIN", 0, "Linear", "New keys will be linear"},
5048 {BEZT_IPO_CONST, "CONST", 0, "Constant", "New keys will be constant"},
5049 {0, nullptr, 0, nullptr, nullptr},
5050};
5051
5053{
5054 using namespace blender::animrig;
5055 bAnimContext ac;
5056
5057 /* Get editor data. */
5058 if (ANIM_animdata_get_context(C, &ac) == 0) {
5059 return OPERATOR_CANCELLED;
5060 }
5061
5062 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
5065 size_t anim_data_length = ANIM_animdata_filter(
5066 &ac, &anim_data, eAnimFilter_Flags(filter), ac.data, eAnimCont_Types(ac.datatype));
5067
5068 if (anim_data_length == 0) {
5069 BKE_report(op->reports, RPT_WARNING, "No channels to operate on");
5070 return OPERATOR_CANCELLED;
5071 }
5072
5073 Scene *scene = CTX_data_scene(C);
5074
5075 int2 frame_range;
5076 if (scene->r.flag & SCER_PRV_RANGE) {
5077 frame_range = {scene->r.psfra, scene->r.pefra};
5078 }
5079 else {
5080 frame_range = {scene->r.sfra, scene->r.efra};
5081 }
5082
5083 /* The range property will default to the scene or preview range, but only if it hasn't been set
5084 * before. */
5085 int2 rna_range;
5086 RNA_int_get_array(op->ptr, "range", rna_range);
5087 if (rna_range[0] == 0 && rna_range[1] == 0) {
5088 RNA_int_set_array(op->ptr, "range", frame_range);
5089 }
5090
5091 if (!RNA_boolean_get(op->ptr, "use_scene_range")) {
5092 frame_range = rna_range;
5093 }
5094
5095 frame_range[1] = std::max(frame_range[1], frame_range[0]);
5096
5097 const bool remove_outside_range = RNA_boolean_get(op->ptr, "remove_outside_range");
5098 const BakeCurveRemove remove_existing = remove_outside_range ? BakeCurveRemove::ALL :
5100 const eBezTriple_Interpolation interpolation_type = eBezTriple_Interpolation(
5101 RNA_enum_get(op->ptr, "interpolation_type"));
5102 const bool bake_modifiers = RNA_boolean_get(op->ptr, "bake_modifiers");
5103
5104 for (bAnimListElem &ale : anim_data) {
5105 FCurve *fcu = static_cast<FCurve *>(ale.data);
5106 if (!fcu->bezt) {
5107 continue;
5108 }
5109 int2 nla_mapped_range = {
5110 int(ANIM_nla_tweakedit_remap(&ale, frame_range[0], NLATIME_CONVERT_UNMAP)),
5111 int(ANIM_nla_tweakedit_remap(&ale, frame_range[1], NLATIME_CONVERT_UNMAP)),
5112 };
5113 /* Save current state of modifier flags so they can be reapplied after baking. */
5114 Vector<eFModifier_Flags> modifier_flags;
5115 if (!bake_modifiers) {
5116 for (FModifier &modifier : fcu->modifiers) {
5117 modifier_flags.append(modifier.flag);
5119 }
5120 }
5121
5122 bool replace;
5123 const int last_index = BKE_fcurve_bezt_binarysearch_index(
5124 fcu->bezt, nla_mapped_range[1], fcu->totvert, &replace);
5125
5126 /* Since the interpolation of a key defines the curve following it, the last key in the baked
5127 * segment needs to keep the interpolation mode that existed previously so the curve isn't
5128 * changed. */
5129 const eBezTriple_Interpolation segment_end_interpolation =
5130 fcu->bezt[min_ii(last_index, fcu->totvert - 1)].ipo;
5131
5132 const float step = RNA_float_get(op->ptr, "step");
5133 bake_fcurve(fcu, nla_mapped_range, step, remove_existing);
5134
5135 if (bake_modifiers) {
5137 }
5138 else {
5139 int modifier_index = 0;
5140 for (FModifier &modifier : fcu->modifiers) {
5141 modifier.flag = modifier_flags[modifier_index];
5142 modifier_index++;
5143 }
5144 }
5145
5146 for (int i = 0; i < fcu->totvert; i++) {
5147 BezTriple *key = &fcu->bezt[i];
5148 if (key->vec[1][0] < nla_mapped_range[0]) {
5149 continue;
5150 }
5151 if (key->vec[1][0] > nla_mapped_range[1]) {
5152 fcu->bezt[max_ii(i - 1, 0)].ipo = segment_end_interpolation;
5153 break;
5154 }
5155 key->ipo = interpolation_type;
5156 }
5157 }
5158
5159 ANIM_animdata_freelist(&anim_data);
5161
5162 return OPERATOR_FINISHED;
5163}
5164
5165static bool channels_bake_poll_property(const bContext * /* C */,
5166 wmOperator *op,
5167 const PropertyRNA *prop)
5168{
5169 const char *prop_id = RNA_property_identifier(prop);
5170 if (STREQ(prop_id, "range")) {
5171 return !RNA_boolean_get(op->ptr, "use_scene_range");
5172 }
5173 return true;
5174}
5175
5177{
5178 /* Identifiers */
5179 ot->name = "Bake Channels";
5180 ot->idname = "ANIM_OT_channels_bake";
5181 ot->description =
5182 "Create keyframes following the current shape of F-Curves of selected channels";
5183
5184 /* API callbacks */
5186 ot->poll = channel_view_poll;
5188
5191 ot->srna,
5192 "use_scene_range",
5193 true,
5194 "Use Scene Range",
5195 "If enabled, the scene start and end frame will be used to determine the bake range");
5196
5198 ot->srna,
5199 "range",
5200 2,
5201 nullptr,
5202 INT_MIN,
5203 INT_MAX,
5204 "Frame Range",
5205 "The custom range in which to create new keys. Only used when not using the scene range",
5206 0,
5207 INT_MAX);
5208
5209 RNA_def_float(ot->srna,
5210 "step",
5211 1.0f,
5212 0.01f,
5213 FLT_MAX,
5214 "Frame Step",
5215 "At which interval to add keys",
5216 1.0f,
5217 16.0f);
5218
5220 "remove_outside_range",
5221 false,
5222 "Remove Outside Range",
5223 "Removes keys outside the given range, leaving only the newly baked");
5224
5225 RNA_def_enum(ot->srna,
5226 "interpolation_type",
5229 "Interpolation Type",
5230 "Choose the interpolation type with which new keys will be added");
5231
5233 "bake_modifiers",
5234 true,
5235 "Bake Modifiers",
5236 "Bake Modifiers into keyframes and delete them after");
5237}
5238
5240
5241/* -------------------------------------------------------------------- */
5244
5246{
5247 using namespace blender::animrig;
5248 using animrig::Strip;
5249 bAnimContext ac;
5250
5251 /* Get editor data. */
5252 if (ANIM_animdata_get_context(C, &ac) == 0) {
5253 return OPERATOR_CANCELLED;
5254 }
5255
5256 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
5259
5260 size_t anim_data_length = ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
5261
5262 if (anim_data_length == 0) {
5263 BKE_report(op->reports, RPT_WARNING, "No channels to operate on");
5264 return OPERATOR_CANCELLED;
5265 }
5266
5268 for (bAnimListElem &ale : anim_data) {
5269 if (ale.type != ANIMTYPE_ACTION_SLOT) {
5270 continue;
5271 }
5272 BLI_assert(GS(ale.fcurve_owner_id->name) == ID_AC);
5273 bAction *owning_action = reinterpret_cast<bAction *>(ale.fcurve_owner_id);
5274 slots.append({reinterpret_cast<Slot *>(ale.data), owning_action});
5275 }
5276 ANIM_animdata_freelist(&anim_data);
5277
5278 if (slots.size() == 0) {
5279 BKE_report(op->reports, RPT_WARNING, "None of the selected channels is an Action Slot");
5280 return OPERATOR_CANCELLED;
5281 }
5282
5283 /* If multiple slots are selected they are moved to the new action together. In that case it is
5284 * hard to determine a name, so a constant default is used. */
5285 Action *target_action;
5286 Main *bmain = CTX_data_main(C);
5287 if (slots.size() == 1) {
5288 char actname[MAX_ID_NAME - 2];
5289 SNPRINTF_UTF8(actname, DATA_("%sAction"), slots[0].first->identifier + 2);
5290 target_action = &action_add(*bmain, actname);
5291 }
5292 else {
5293 target_action = &action_add(*bmain, DATA_("CombinedAction"));
5294 }
5295
5296 Layer &layer = target_action->layer_add(std::nullopt);
5297 layer.strip_add(*target_action, Strip::Type::Keyframe);
5298
5299 for (std::pair<Slot *, bAction *> &slot_data : slots) {
5300 Action &source_action = slot_data.second->wrap();
5301 move_slot(*bmain, *slot_data.first, source_action, *target_action);
5303 }
5304
5308
5309 return OPERATOR_FINISHED;
5310}
5311
5313{
5314 const Main *bmain = CTX_data_main(C);
5315 Scene *scene = CTX_data_scene(C);
5316 ViewLayer *view_layer = CTX_data_view_layer(C);
5317 ScrArea *area = CTX_wm_area(C);
5318 bAction *action = ANIM_active_action_from_area(*bmain, scene, view_layer, area);
5319
5320 if (!action) {
5321 CTX_wm_operator_poll_msg_set(C, "No active action to operate on");
5322 return false;
5323 }
5324 return true;
5325}
5326
5328{
5329 ot->name = "Move Slots to new Action";
5330 ot->idname = "ANIM_OT_slot_channels_move_to_new_action";
5331 ot->description = "Move the selected slots into a newly created action";
5332
5335
5337}
5338
5340
5341/* -------------------------------------------------------------------- */
5344
5346{
5347 using namespace blender::animrig;
5348 using animrig::Strip;
5349 Object *active_object = CTX_data_active_object(C);
5350 /* Checked by the poll function. */
5351 BLI_assert(active_object != nullptr);
5352
5353 Action *action = get_action(active_object->id);
5354 /* Also checked by the poll function. */
5355 BLI_assert(action != nullptr);
5356
5357 Main *bmain = CTX_data_main(C);
5358 int created_actions = 0;
5359 while (action->slot_array_num) {
5360 Slot *slot = action->slot(action->slot_array_num - 1);
5361 char actname[MAX_ID_NAME - 2];
5362 SNPRINTF_UTF8(actname, DATA_("%sAction"), slot->identifier + 2);
5363 Action &target_action = action_add(*bmain, actname);
5364 created_actions++;
5365 Layer &layer = target_action.layer_add(std::nullopt);
5366 layer.strip_add(target_action, Strip::Type::Keyframe);
5367 move_slot(*bmain, *slot, *action, target_action);
5369 }
5370
5371 BKE_reportf(op->reports,
5372 RPT_INFO,
5373 "Separated %s into %i new actions",
5374 action->id.name + 2,
5375 created_actions);
5376
5380
5381 return OPERATOR_FINISHED;
5382}
5383
5385{
5386 Object *active_object = CTX_data_active_object(C);
5387 if (!active_object) {
5388 CTX_wm_operator_poll_msg_set(C, "No active object");
5389 return false;
5390 }
5391
5392 animrig::Action *action = animrig::get_action(active_object->id);
5393 if (!action) {
5394 CTX_wm_operator_poll_msg_set(C, "Active object isn't animated");
5395 return false;
5396 }
5397 return true;
5398}
5399
5401{
5402 ot->name = "Separate Slots";
5403 ot->idname = "ANIM_OT_separate_slots";
5404 ot->description =
5405 "Move all slots of the action on the active object into newly created, separate actions. "
5406 "All users of those slots will be reassigned to the new actions. The current action won't "
5407 "be deleted but will be empty and might end up having zero users";
5408
5411
5413}
5414
5416
5417/* -------------------------------------------------------------------- */
5420
5425 wmWindow **r_win,
5426 ScrArea **r_area,
5427 ARegion **r_region)
5428{
5429 for (wmWindow &win : CTX_wm_manager(C)->windows) {
5430 bScreen *screen = WM_window_get_active_screen(&win);
5431
5432 for (ScrArea &area : screen->areabase) {
5433 if (area.spacetype != SPACE_GRAPH) {
5434 continue;
5435 }
5437 if (!region) {
5438 continue;
5439 }
5440
5441 *r_win = &win;
5442 *r_area = &area;
5443 *r_region = region;
5444 return true;
5445 }
5446 }
5447 return false;
5448}
5449
5450static void deselect_all_fcurves(bAnimContext *ac, const bool hide)
5451{
5452 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
5455 ANIM_animdata_filter(ac, &anim_data, filter, ac->data, eAnimCont_Types(ac->datatype));
5456
5457 for (bAnimListElem &ale : anim_data) {
5458 FCurve *fcu = static_cast<FCurve *>(ale.key_data);
5459 fcu->flag &= ~FCURVE_SELECTED;
5460 fcu->flag &= ~FCURVE_ACTIVE;
5461 if (hide) {
5462 fcu->flag &= ~FCURVE_VISIBLE;
5463 }
5464 }
5465
5466 ANIM_animdata_freelist(&anim_data);
5467}
5468
5470{
5471 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
5472 if (ac->sl->spacetype != SPACE_GRAPH) {
5473 return 0;
5474 }
5475 SpaceGraph *sipo = reinterpret_cast<SpaceGraph *>(ac->sl);
5477 ANIM_animdata_filter(ac, &anim_data, filter, ac->data, eAnimCont_Types(ac->datatype));
5478
5479 /* Adding FCurves to a map for quicker lookup times. */
5480 Map<FCurve *, bool> filtered_fcurves;
5481 for (bAnimListElem &ale : anim_data) {
5482 FCurve *fcu = static_cast<FCurve *>(ale.key_data);
5483 filtered_fcurves.add(fcu, true);
5484 }
5485
5486 int hidden_fcurve_count = fcurves.size();
5487 for (FCurve *fcu : fcurves) {
5488 if (filtered_fcurves.contains(fcu)) {
5489 hidden_fcurve_count--;
5490 }
5491 }
5492 ANIM_animdata_freelist(&anim_data);
5493 return hidden_fcurve_count;
5494}
5495
5497 ID *id, PointerRNA *ptr, PropertyRNA *prop, const bool whole_array, const int index)
5498{
5499 AnimData *anim_data = BKE_animdata_from_id(id);
5500 if (anim_data == nullptr) {
5501 return Vector<FCurve *>();
5502 }
5503
5504 const std::optional<std::string> path = RNA_path_from_ID_to_property(ptr, prop);
5505
5506 Vector<FCurve *> fcurves;
5507 if (RNA_property_array_check(prop) && whole_array) {
5508 const int length = RNA_property_array_length(ptr, prop);
5509 for (int i = 0; i < length; i++) {
5511 anim_data, path->c_str(), i, nullptr, nullptr);
5512 if (fcurve != nullptr) {
5513 fcurves.append(fcurve);
5514 }
5515 }
5516 }
5517 else {
5519 anim_data, path->c_str(), index, nullptr, nullptr);
5520 if (fcurve != nullptr) {
5521 fcurves.append(fcurve);
5522 }
5523 }
5524 return fcurves;
5525}
5526
5528 Scene *scene,
5529 ID *id,
5530 const Span<FCurve *> fcurves)
5531{
5532 rctf bounds;
5533 bounds.xmin = INFINITY;
5534 bounds.xmax = -INFINITY;
5535 bounds.ymin = INFINITY;
5536 bounds.ymax = -INFINITY;
5537
5538 if (space_link->spacetype != SPACE_GRAPH) {
5539 return bounds;
5540 }
5541
5542 AnimData *anim_data = BKE_animdata_from_id(id);
5543 if (anim_data == nullptr) {
5544 return bounds;
5545 }
5546
5547 float frame_range[2];
5548 get_view_range(scene, true, frame_range);
5549 float mapped_frame_range[2];
5550 mapped_frame_range[0] = BKE_nla_tweakedit_remap(
5551 anim_data, frame_range[0], NLATIME_CONVERT_UNMAP);
5552 mapped_frame_range[1] = BKE_nla_tweakedit_remap(
5553 anim_data, frame_range[1], NLATIME_CONVERT_UNMAP);
5554
5555 const bool include_handles = false;
5556
5557 for (FCurve *fcurve : fcurves) {
5558 fcurve->flag |= (FCURVE_SELECTED | FCURVE_VISIBLE);
5559 rctf fcu_bounds;
5561 fcurve, space_link, scene, id, include_handles, mapped_frame_range, &fcu_bounds);
5562
5563 if (BLI_rctf_is_valid(&fcu_bounds)) {
5564 BLI_rctf_union(&bounds, &fcu_bounds);
5565 }
5566 }
5567
5568 return bounds;
5569}
5570
5572 Span<PointerRNA> selection,
5573 PropertyRNA *prop,
5574 const StringRefNull id_to_prop_path,
5575 const int index,
5576 const bool whole_array,
5577 int *r_filtered_fcurve_count)
5578{
5579 rctf bounds;
5580 bounds.xmin = INFINITY;
5581 bounds.xmax = -INFINITY;
5582 bounds.ymin = INFINITY;
5583 bounds.ymax = -INFINITY;
5584
5585 for (const PointerRNA &selected : selection) {
5586 ID *selected_id = selected.owner_id;
5587 if (!BKE_animdata_id_is_animated(selected_id)) {
5588 continue;
5589 }
5590 PointerRNA resolved_ptr;
5591 PropertyRNA *resolved_prop;
5592 if (!id_to_prop_path.is_empty()) {
5593 const bool resolved = RNA_path_resolve_property(
5594 &selected, id_to_prop_path.c_str(), &resolved_ptr, &resolved_prop);
5595 if (!resolved) {
5596 continue;
5597 }
5598 }
5599 else {
5600 resolved_ptr = selected;
5601 resolved_prop = prop;
5602 }
5604 selected_id, &resolved_ptr, resolved_prop, whole_array, index);
5605 *r_filtered_fcurve_count += count_fcurves_hidden_by_filter(ac, fcurves);
5606 rctf fcu_bounds = calculate_fcurve_bounds_and_unhide(ac->sl, ac->scene, selected_id, fcurves);
5607 if (BLI_rctf_is_valid(&fcu_bounds)) {
5608 BLI_rctf_union(&bounds, &fcu_bounds);
5609 }
5610 }
5611
5612 return bounds;
5613}
5614
5616{
5617 PointerRNA button_ptr = {};
5618 PropertyRNA *button_prop = nullptr;
5619 ui::Button *but;
5620 int index;
5621
5622 if (!(but = ui::context_active_but_prop_get(C, &button_ptr, &button_prop, &index))) {
5623 /* Pass event on if no active button found. */
5625 }
5626
5628
5629 Vector<PointerRNA> selection;
5630
5631 struct {
5632 wmWindow *win;
5633 ScrArea *area;
5634 ARegion *region;
5635 } wm_context_prev = {nullptr}, wm_context_temp = {nullptr};
5636
5637 bool path_from_id;
5638 std::optional<std::string> id_to_prop_path;
5639 const bool selected_list_success = ui::context_copy_to_selected_list(
5640 C, &button_ptr, button_prop, &selection, &path_from_id, &id_to_prop_path);
5641
5643 C, &wm_context_temp.win, &wm_context_temp.area, &wm_context_temp.region))
5644 {
5645 BKE_report(op->reports, RPT_WARNING, "No open Graph Editor window found");
5646 retval = OPERATOR_CANCELLED;
5647 }
5648 else {
5649 wm_context_prev.win = CTX_wm_window(C);
5650 wm_context_prev.area = CTX_wm_area(C);
5651 wm_context_prev.region = CTX_wm_region(C);
5652
5653 CTX_wm_window_set(C, wm_context_temp.win);
5654 CTX_wm_area_set(C, wm_context_temp.area);
5655 CTX_wm_region_set(C, wm_context_temp.region);
5656
5657 bAnimContext ac;
5658 if (!ANIM_animdata_get_context(C, &ac)) {
5659 /* This might never be called since we are manually setting the Graph Editor just before. */
5660 BKE_report(op->reports, RPT_ERROR, "Cannot create the Animation Context");
5661 retval = OPERATOR_CANCELLED;
5662 }
5663 else {
5664 const bool isolate = RNA_boolean_get(op->ptr, "isolate");
5665 /* The index can be less than 0 e.g. on color properties. */
5666 const bool whole_array = RNA_boolean_get(op->ptr, "all") || index < 0;
5667
5668 deselect_all_fcurves(&ac, isolate);
5669
5670 rctf bounds;
5671 bounds.xmin = INFINITY;
5672 bounds.xmax = -INFINITY;
5673 bounds.ymin = INFINITY;
5674 bounds.ymax = -INFINITY;
5675 int filtered_fcurve_count = 0;
5676 if (selected_list_success && !selection.is_empty()) {
5677 rctf selection_bounds = calculate_selection_fcurve_bounds(&ac,
5678 selection,
5679 button_prop,
5680 id_to_prop_path.value_or(""),
5681 index,
5682 whole_array,
5683 &filtered_fcurve_count);
5684 if (BLI_rctf_is_valid(&selection_bounds)) {
5685 BLI_rctf_union(&bounds, &selection_bounds);
5686 }
5687 }
5688
5689 /* The object to which the button belongs might not be selected, or selectable. */
5691 button_ptr.owner_id, &button_ptr, button_prop, whole_array, index);
5692 filtered_fcurve_count += count_fcurves_hidden_by_filter(&ac, button_fcurves);
5694 ac.sl, ac.scene, button_ptr.owner_id, button_fcurves);
5695 if (BLI_rctf_is_valid(&button_bounds)) {
5696 BLI_rctf_union(&bounds, &button_bounds);
5697 }
5698
5699 if (filtered_fcurve_count > 0) {
5700 BKE_report(op->reports,
5702 "One or more F-Curves are not visible due to filter settings");
5703 }
5704
5705 if (!BLI_rctf_is_valid(&bounds)) {
5706 BKE_report(op->reports, RPT_ERROR, "F-Curves have no valid size");
5707 retval = OPERATOR_CANCELLED;
5708 }
5709 else {
5710 ARegion *region = wm_context_temp.region;
5711 ScrArea *area = wm_context_temp.area;
5712 add_region_padding(C, region, &bounds);
5713
5714 const int smooth_viewtx = WM_operator_smooth_viewtx_get(op);
5715 ui::view2d_smooth_view(C, region, &bounds, smooth_viewtx);
5716
5717 /* This ensures the channel list updates. */
5718 ED_area_tag_redraw(area);
5719 }
5720 }
5721
5722 CTX_wm_window_set(C, wm_context_prev.win);
5723 CTX_wm_area_set(C, wm_context_prev.area);
5724 CTX_wm_region_set(C, wm_context_prev.region);
5725 }
5726
5727 return retval;
5728}
5729
5731{
5732 /* Identifiers */
5733 ot->name = "View In Graph Editor";
5734 ot->idname = "ANIM_OT_view_curve_in_graph_editor";
5735 ot->description = "Frame the property under the cursor in the Graph Editor";
5736
5737 /* API callbacks */
5739
5741 "all",
5742 false,
5743 "Show All",
5744 "Frame the whole array property instead of only the index under the cursor");
5745
5747 "isolate",
5748 false,
5749 "Isolate",
5750 "Hides all F-Curves other than the ones being framed");
5751}
5752
5754
5755/* -------------------------------------------------------------------- */
5758
5760{
5763
5767
5769
5773
5777
5779
5780 /* XXX does this need to be a separate operator? */
5782
5784
5787
5789
5791
5794
5796
5799}
5800
5802{
5803 /* TODO: check on a poll callback for this, to get hotkeys into menus. */
5804
5805 WM_keymap_ensure(keyconf, "Animation Channels", SPACE_EMPTY, RGN_TYPE_WINDOW);
5806}
5807
5809
5810} // namespace blender
Functions and classes to work with Actions.
Functions for backward compatibility with the legacy Action API.
Functions to work with AnimData.
Functions to modify FCurves.
Blender kernel action and pose functionality.
Low-level operations for grease pencil.
#define SELECT
Definition BKE_mask.hh:19
#define ATTR_FALLTHROUGH
#define SNPRINTF_UTF8(dst, format,...)
#define DATA_(msgid)
#define MAX_ID_NAME
Definition DNA_ID.h:367
#define ID_IS_EDITABLE(_id)
Definition DNA_ID.h:708
#define ID_IS_OVERRIDE_LIBRARY(_id)
Definition DNA_ID.h:736
#define MAX_NAME
Definition DNA_defs.h:63
Object is a sort of wrapper for general info.
#define SEL_AGRP(agrp)
#define SEL_GPL(gpl)
#define NLATRACK_FIRST_TOP(ac)
#define NLATRACK_STEP(snla)
#define SEL_FCU(fcu)
#define ACHANNEL_SET_FLAG(channel, smode, sflag)
#define EXPANDED_DRVD(adt)
#define SEL_NLT(nlt)
#define NLATRACK_NAMEWIDTH
Read Blender memory allocation and freeing.
#define C
Definition RandGen.cpp:29
#define UI_MARKER_MARGIN_Y
Definition UI_view2d.hh:492
#define V2D_SCROLL_HANDLE_HEIGHT
Definition UI_view2d.hh:92
#define UI_TIME_SCRUB_MARGIN_Y
Definition UI_view2d.hh:493
#define ND_NLA_ACTCHANGE
Definition WM_types.hh:541
#define ND_DATA
Definition WM_types.hh:552
#define NC_ANIMATION
Definition WM_types.hh:401
#define ND_SPACE_PROPERTIES
Definition WM_types.hh:572
#define NA_EDITED
Definition WM_types.hh:634
#define NA_REMOVED
Definition WM_types.hh:637
#define ND_NLA_ORDER
Definition WM_types.hh:543
#define NC_GPENCIL
Definition WM_types.hh:412
#define ND_NLA
Definition WM_types.hh:540
#define NA_RENAME
Definition WM_types.hh:638
#define ND_KEYFRAME
Definition WM_types.hh:537
#define ND_ANIMCHAN
Definition WM_types.hh:539
#define NC_SPACE
Definition WM_types.hh:405
#define NA_SELECTED
Definition WM_types.hh:639
#define BLI_assert_unreachable()
#define UNUSED_VARS_NDEBUG(...)
#define ELEM(...)
#define BLI_assert_msg(a, msg)
#define STREQ(a, b)
bool add(const Key &key, const Value &value)
Definition BLI_map.hh:295
bool contains(const Key &key) const
Definition BLI_map.hh:353
bool add(const Key &key)
Definition BLI_set.hh:248
constexpr int64_t size() const
Definition BLI_span.hh:256
constexpr const char * c_str() const
int64_t size() const
void append(const T &value)
friend class Vector
bool is_empty() const
void slot_active_set(slot_handle_t slot_handle)
Span< const Slot * > slots() const
const Slot * slot(int64_t index) const
void slot_move_to_index(Slot &slot, int to_slot_index)
bool slot_remove(Slot &slot_to_remove)
Layer & layer_add(std::optional< StringRefNull > name)
const FCurve * fcurve(int64_t index) const
void fcurve_move_to_index(FCurve &fcurve, int to_fcurve_index)
bool fcurve_assign_to_channel_group(FCurve &fcurve, bActionGroup &to_group)
Span< const bActionGroup * > channel_groups() const
bActionGroup & channel_group_create(StringRefNull name)
bool fcurve_remove(FCurve &fcurve_to_remove)
const bActionGroup * channel_group(int64_t index) const
Span< const FCurve * > fcurves() const
void channel_group_move_to_index(bActionGroup &group, int to_group_index)
constexpr bool is_empty() const
#define offsetof(t, d)
#define FLT_MAX
#define INT_MAX
#define layer
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
float length(VecOp< float, D >) RET
#define T
bool action_fcurve_remove(Action &action, FCurve &fcu)
void animdata_fcurve_delete(AnimData *adt, FCurve *fcu)
Definition animdata.cc:251
Action & action_add(Main &bmain, StringRefNull name)
const animrig::Channelbag * channelbag_for_action_slot(const Action &action, slot_handle_t slot_handle)
void bake_fcurve(FCurve *fcu, int2 range, float step, BakeCurveRemove remove_existing)
Span< FCurve * > fcurves_for_action_slot(Action &action, slot_handle_t slot_handle)
Action * get_action(ID &animated_id)
void move_slot(Main &bmain, Slot &slot, Action &from_action, Action &to_action)
void base_select(Base *base, eObjectSelect_Mode mode)
void base_activate_with_mode_exit_if_needed(bContext *C, Base *base)
BLI_INLINE Texture * wrap(MTLTexture *texture)
bool context_copy_to_selected_list(bContext *C, PointerRNA *ptr, PropertyRNA *prop, Vector< PointerRNA > *r_lb, bool *r_use_path_from_id, std::optional< std::string > *r_path)
void view2d_region_to_view(const View2D *v2d, float x, float y, float *r_view_x, float *r_view_y) ATTR_NONNULL()
Definition view2d.cc:1651
void view2d_smooth_view(const bContext *C, ARegion *region, const rctf *cur, int smooth_viewtx)
void view2d_listview_view_to_cell(float columnwidth, float rowheight, float startx, float starty, float viewx, float viewy, int *r_column, int *r_row)
Definition view2d.cc:1604
Button * context_active_but_prop_get(const bContext *C, PointerRNA *r_ptr, PropertyRNA **r_prop, int *r_index)
BMesh Iterators.
void WM_main_add_notifier(uint type, void *reference)
static wmOperatorStatus animchannels_rename_invoke(bContext *C, wmOperator *, const wmEvent *event)
void * BLI_findptr(const ListBase *listbase, const void *ptr, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:710
static rctf calculate_fcurve_bounds_and_unhide(SpaceLink *space_link, Scene *scene, ID *id, const Span< FCurve * > fcurves)
int RNA_property_array_length(PointerRNA *ptr, PropertyRNA *prop)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void WM_operatortype_append(void(*opfunc)(wmOperatorType *))
static void rearrange_animchannel_flatten_islands(ListBaseT< tReorderChannelIsland > *islands, ListBaseT< T > *srcList)
void BKE_annotations_layer_active_set(struct bGPdata *gpd, struct bGPDlayer *active)
wmOperatorStatus WM_menu_invoke(bContext *C, wmOperator *op, const wmEvent *)
static void ANIM_OT_channels_select_box(wmOperatorType *ot)
static wmOperatorStatus graphkeys_channel_view_pick_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static bool channel_view_poll(bContext *C)
ScrArea * CTX_wm_area(const bContext *C)
short ANIM_channel_setting_get(bAnimContext *ac, bAnimListElem *ale, eAnimChannel_Settings setting)
@ NLATRACK_OVERRIDELIBRARY_LOCAL
int RNA_enum_get(PointerRNA *ptr, const char *name)
@ DRIVER_FLAG_INVALID
static Vector< FCurve * > get_fcurves_of_property(ID *id, PointerRNA *ptr, PropertyRNA *prop, const bool whole_array, const int index)
static wmOperatorStatus animchannels_expand_exec(bContext *C, wmOperator *op)
PropertyRNA * RNA_def_string(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, const int maxlen, const char *ui_name, const char *ui_description)
static void rearrange_nla_control_channels(bAnimContext *ac, AnimData *adt, eRearrangeAnimChan_Mode mode)
static void ANIM_OT_separate_slots(wmOperatorType *ot)
@ RPT_WARNING
Definition BKE_report.hh:40
float BKE_nla_tweakedit_remap(AnimData *adt, float cframe, eNlaTime_ConvertModes mode)
bool ED_operator_graphedit_active(bContext *C)
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
static void anim_channels_select_set(bAnimContext *ac, const ListBaseT< bAnimListElem > anim_data, eAnimChannels_SetFlag sel)
const bAnimChannelType * ANIM_channel_get_typeinfo(const bAnimListElem *ale)
static void rearrange_grease_pencil_channels(bAnimContext *ac, eRearrangeAnimChan_Mode mode)
void RNA_property_update(bContext *C, PointerRNA *ptr, PropertyRNA *prop)
wmOperatorStatus WM_gesture_box_invoke(bContext *C, wmOperator *op, const wmEvent *event)
wmOperatorStatus WM_operator_flag_only_pass_through_on_press(wmOperatorStatus retval, const wmEvent *event)
static void ANIM_OT_channels_move(wmOperatorType *ot)
float ANIM_UI_get_channel_name_width()
@ ANIMCONT_CHANNEL
@ ANIMCONT_SHAPEKEY
@ ANIMCONT_DRIVERS
@ ANIMCONT_TIMELINE
@ ANIMCONT_ACTION
@ ANIMCONT_DOPESHEET
@ ANIMCONT_FCURVES
@ ANIMCONT_GPENCIL
static wmOperatorStatus animchannels_rearrange_exec(bContext *C, wmOperator *op)
void BKE_id_free_us(Main *bmain, void *idv) ATTR_NONNULL()
static int click_select_channel_scene(bAnimListElem *ale, const short selectmode)
static bool rearrange_animchannel_islands(ListBaseT< T > *list, AnimChanRearrangeFp rearrange_func, eRearrangeAnimChan_Mode mode, eAnim_ChannelType type, ListBaseT< bAnimListElem > *anim_data_visible)
ListBaseT< TimeMarker > * ED_context_get_markers(const bContext *C)
void ANIM_anim_channels_select_set(bAnimContext *ac, eAnimChannels_SetFlag sel)
static void ANIM_OT_channels_expand(wmOperatorType *ot)
std::optional< std::string > RNA_path_from_ID_to_property(const PointerRNA *ptr, PropertyRNA *prop)
Definition rna_path.cc:1237
static wmOperatorStatus animchannels_selectall_exec(bContext *C, wmOperator *op)
static wmOperatorStatus view_curve_in_graph_editor_exec(bContext *C, wmOperator *op)
void ANIM_set_active_channel(bAnimContext *ac, void *data, eAnimCont_Types datatype, eAnimFilter_Flags filter, void *channel_data, eAnim_ChannelType channel_type)
static void ANIM_OT_channels_clean_empty(wmOperatorType *ot)
const char * RNA_property_identifier(const PropertyRNA *prop)
static int click_select_channel_action_slot(bAnimContext *ac, bAnimListElem *ale, short selectmode)
void RNA_string_set(PointerRNA *ptr, const char *name, const char *value)
static void anim_flush_channel_setting_down(bAnimContext *ac, const eAnimChannel_Settings setting, const eAnimChannels_SetFlag mode, bAnimListElem *const match, const int matchLevel)
void CTX_wm_window_set(bContext *C, wmWindow *win)
static void tag_update_animation_element(bAnimListElem *ale)
@ NLATIME_CONVERT_UNMAP
Definition BKE_nla.hh:560
@ NLATIME_CONVERT_MAP
Definition BKE_nla.hh:563
bool ANIM_animdata_get_context(const bContext *C, bAnimContext *ac)
int WM_operator_smooth_viewtx_get(const wmOperator *op)
@ ADT_NLA_SKEYS_COLLAPSED
float ANIM_nla_tweakedit_remap(bAnimListElem *ale, const float cframe, const eNlaTime_ConvertModes mode)
Definition anim_draw.cc:329
static void ANIM_OT_channel_select_keys(wmOperatorType *ot)
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
static void ANIM_OT_channels_select_all(wmOperatorType *ot)
static wmOperatorStatus graphkeys_view_selected_channels_exec(bContext *C, wmOperator *op)
static int click_select_channel_nlacontrols(bAnimListElem *ale)
void WM_operator_properties_gesture_box_select(wmOperatorType *ot)
void void void BLI_movelisttolist(ListBase *dst, ListBase *src) ATTR_NONNULL(1
Definition listbase.cc:32
static void select_pchan_for_action_group(bAnimContext *ac, bActionGroup *agrp, bAnimListElem *ale, const bool change_active)
static bool slot_channels_move_to_new_action_poll(bContext *C)
wmWindow * CTX_wm_window(const bContext *C)
static wmOperatorStatus separate_slots_exec(bContext *C, wmOperator *op)
static bool separate_slots_poll(bContext *C)
eAnimChannels_SetFlag
@ ACHANNEL_SETFLAG_INVERT
@ ACHANNEL_SETFLAG_EXTEND_RANGE
@ ACHANNEL_SETFLAG_CLEAR
@ ACHANNEL_SETFLAG_ADD
@ ACHANNEL_SETFLAG_TOGGLE
BLI_INLINE bool BLI_listbase_is_empty(const ListBase *lb)
MINLINE int max_ii(int a, int b)
void ED_keymap_animchannels(wmKeyConfig *keyconf)
static wmOperatorStatus animchannels_setflag_exec(bContext *C, wmOperator *op)
bool BKE_animdata_id_is_animated(const ID *id)
Definition anim_data.cc:224
static void get_view_range(Scene *scene, const bool use_preview_range, float r_range[2])
static bool animchannels_grouping_poll(bContext *C)
@ ANIMTYPE_MASKDATABLOCK
@ ANIMTYPE_NLAACTION
@ ANIMTYPE_NLACURVE
@ ANIMTYPE_GREASE_PENCIL_LAYER_GROUP
@ ANIMTYPE_DSPOINTCLOUD
@ ANIMTYPE_DSMCLIP
@ ANIMTYPE_DSLIGHTPROBE
@ ANIMTYPE_DSNTREE
@ ANIMTYPE_GREASE_PENCIL_DATABLOCK
@ ANIMTYPE_FCURVE
@ ANIMTYPE_ANIMDATA
@ ANIMTYPE_DSVOLUME
@ ANIMTYPE_NLATRACK
@ ANIMTYPE_OBJECT
@ ANIMTYPE_GPLAYER
@ ANIMTYPE_GREASE_PENCIL_LAYER
@ ANIMTYPE_DSMBALL
@ ANIMTYPE_DSMESH
@ ANIMTYPE_NUM_TYPES
@ ANIMTYPE_NLACONTROLS
@ ANIMTYPE_DSHAIR
@ ANIMTYPE_FILLDRIVERS
@ ANIMTYPE_SUMMARY
@ ANIMTYPE_FILLACT_LAYERED
@ ANIMTYPE_SHAPEKEY
@ ANIMTYPE_SPECIALDATA__UNUSED
@ ANIMTYPE_ACTION_SLOT
@ ANIMTYPE_DSCACHEFILE
@ ANIMTYPE_MASKLAYER
@ ANIMTYPE_DSGPENCIL
@ ANIMTYPE_DSPART
@ ANIMTYPE_FILLACTD
@ ANIMTYPE_DSSKEY
@ ANIMTYPE_DSLINESTYLE
@ ANIMTYPE_PALETTE
static void rearrange_layered_action_channel_groups(bAnimContext *ac, animrig::Action &action, const eRearrangeAnimChan_Mode mode)
void BLI_rctf_scale(rctf *rect, float scale)
Definition rct.cc:691
void ED_region_tag_redraw(ARegion *region)
Definition area.cc:681
bAction * ANIM_active_action_from_area(const Main &bmain, Scene *scene, ViewLayer *view_layer, const ScrArea *area, ID **r_action_user)
static wmOperatorStatus animchannels_delete_exec(bContext *C, wmOperator *)
static wmOperatorStatus animchannels_clean_empty_exec(bContext *C, wmOperator *)
void ANIM_animdata_update(bAnimContext *ac, ListBaseT< bAnimListElem > *anim_data)
Definition anim_deps.cc:365
ViewLayer * CTX_data_view_layer(const bContext *C)
void WM_operator_properties_select_all(wmOperatorType *ot)
static void rearrange_driver_channels(bAnimContext *ac, AnimData *adt, eRearrangeAnimChan_Mode mode)
static void ANIM_OT_view_curve_in_graph_editor(wmOperatorType *ot)
static bool rearrange_island_down(ListBaseT< tReorderChannelIsland > *list, tReorderChannelIsland *island)
static void anim_flush_channel_setting_up(bAnimContext *ac, const eAnimChannel_Settings setting, const eAnimChannels_SetFlag mode, bAnimListElem *const match, const int matchLevel)
static wmOperatorStatus channels_bake_exec(bContext *C, wmOperator *op)
bool RNA_property_array_check(PropertyRNA *prop)
Global G
Definition blender.cc:57
static void ANIM_OT_channel_view_pick(wmOperatorType *ot)
bool ED_operator_action_active(bContext *C)
void BKE_annotations_layer_delete(struct bGPdata *gpd, struct bGPDlayer *gpl)
static int mouse_anim_channels(bContext *C, bAnimContext *ac, const int channel_index, short selectmode)
static void deselect_all_fcurves(bAnimContext *ac, const bool hide)
static void setflag_anim_channels(bAnimContext *ac, eAnimChannel_Settings setting, eAnimChannels_SetFlag mode, bool onlysel, bool flush)
bool BLI_rctf_is_valid(const struct rctf *rect)
static void ANIM_OT_channels_delete(wmOperatorType *ot)
AnimData * BKE_animdata_from_id(const ID *id)
Definition anim_data.cc:93
static void rearrange_nla_tracks(bAnimContext *ac, AnimData *adt, eRearrangeAnimChan_Mode mode)
void * BLI_findlink(const ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:541
bool BKE_nlatrack_is_nonlocal_in_liboverride(const ID *id, const NlaTrack *nlt)
int BLI_findindex(const ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:593
float ANIM_UI_get_first_channel_top(View2D *v2d)
eAnimChannel_Settings
@ ACHANNEL_SETTING_EXPAND
@ ACHANNEL_SETTING_MUTE
@ ACHANNEL_SETTING_PROTECT
@ ACHANNEL_SETTING_VISIBLE
@ ACHANNEL_SETTING_ALWAYS_VISIBLE
@ ACHANNEL_SETTING_SELECT
bool BKE_nlastrip_controlcurve_remove(NlaStrip *strip, FCurve *fcurve)
@ ALE_GREASE_PENCIL_GROUP
@ ALE_ACTION_LAYERED
@ ALE_GREASE_PENCIL_DATA
@ ALE_ACTION_SLOT
@ ALE_GREASE_PENCIL_CEL
void RNA_int_set_array(PointerRNA *ptr, const char *name, const int *values)
void CTX_wm_operator_poll_msg_set(bContext *C, const char *msg)
static int count_fcurves_hidden_by_filter(bAnimContext *ac, const Span< FCurve * > fcurves)
void DEG_id_tag_update_ex(Main *bmain, ID *id, unsigned int flags)
VecBase< int32_t, 2 > int2
static int click_select_channel_masklayer(bAnimContext *ac, bAnimListElem *ale, const short selectmode)
size_t ANIM_animdata_filter(bAnimContext *ac, ListBaseT< bAnimListElem > *anim_data, const eAnimFilter_Flags filter_mode, void *data, const eAnimCont_Types datatype)
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
@ ANIMFILTER_FCURVESONLY
@ ANIMFILTER_ANIMDATA
@ ANIMFILTER_FOREDIT
@ ANIMFILTER_LIST_VISIBLE
@ ANIMFILTER_DATA_VISIBLE
@ ANIMFILTER_CURVE_VISIBLE
@ ANIMFILTER_NODUPLIS
@ ANIMFILTER_LIST_CHANNELS
bool BKE_fcurve_calc_bounds(const FCurve *fcu, bool selected_keys_only, bool include_handles, const float frame_range[2], rctf *r_bounds)
static void ANIM_OT_channels_select_filter(wmOperatorType *ot)
void BLI_remlink(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:138
static const EnumPropertyItem channel_bake_key_options[]
void DEG_id_tag_update(ID *id, unsigned int flags)
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
BMesh const char void * data
void BLI_insertlinkafter(ListBase *listbase, void *vprevlink, void *vnewlink) ATTR_NONNULL(1)
Definition listbase.cc:339
void ANIM_channel_setting_set(bAnimContext *ac, bAnimListElem *ale, eAnimChannel_Settings setting, eAnimChannels_SetFlag mode)
void BLI_rctf_pad_y(struct rctf *rect, float boundary_size, float pad_min, float pad_max)
Definition rct.cc:703
void RNA_int_get_array(PointerRNA *ptr, const char *name, int *values)
static bool get_channel_bounds(bAnimContext *ac, bAnimListElem *ale, const float range[2], const bool include_handles, rctf *r_bounds)
bool ANIM_is_active_channel(bAnimListElem *ale)
void BKE_animdata_free(ID *id, bool do_id_user)
Definition anim_data.cc:174
bool ED_pose_deselect_all(Object *ob, int select_mode, const bool ignore_visibility)
BLI_INLINE float BLI_rctf_size_y(const struct rctf *rct)
Definition BLI_rect.hh:215
wmWindowManager * CTX_wm_manager(const bContext *C)
static bool animchannels_select_filter_poll(bContext *C)
static const EnumPropertyItem prop_animchannel_setflag_types[]
static eAnimChannels_SetFlag anim_channels_selection_flag_for_toggle(const ListBaseT< bAnimListElem > anim_data)
static int click_select_channel_dummy(bAnimContext *ac, bAnimListElem *ale, const short selectmode)
static bool animchannels_enable_poll(bContext *C)
static wmOperatorStatus animchannels_box_select_exec(bContext *C, wmOperator *op)
static int click_select_channel_grease_pencil_layer(bContext *C, bAnimContext *ac, bAnimListElem *ale, const short selectmode, const int)
void WM_operator_properties_border_to_rcti(wmOperator *op, rcti *r_rect)
static int click_select_channel_shapekey(bContext *C, bAnimContext *ac, bAnimListElem *ale, const short selectmode)
FCurve * BKE_animadata_fcurve_find_by_rna_path(AnimData *animdata, const char *rna_path, const int rna_index, bAction **r_action, bool *r_driven)
void ED_pose_bone_select(Object *ob, bPoseChannel *pchan, bool select, bool change_active)
void BLI_freelinkN(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:277
static wmOperatorStatus animchannels_ungroup_exec(bContext *C, wmOperator *)
static bool animedit_poll_channels_active(bContext *C)
wmOperatorStatus WM_operator_props_popup(bContext *C, wmOperator *op, const wmEvent *)
static bool channels_bake_poll_property(const bContext *, wmOperator *op, const PropertyRNA *prop)
static void ANIM_OT_channels_view_selected(wmOperatorType *ot)
static bool rename_anim_channels(bAnimContext *ac, int channel_index)
static bool context_find_graph_editor(bContext *C, wmWindow **r_win, ScrArea **r_area, ARegion **r_region)
static int click_select_channel_gplayer(bContext *C, bAnimContext *ac, bAnimListElem *ale, const short selectmode, const int filter)
bool BKE_view_layer_synced_ensure(const Main &bmain, const Scene *scene, ViewLayer *view_layer)
wmKeyMap * WM_keymap_ensure(wmKeyConfig *keyconf, const char *idname, int spaceid, int regionid)
Definition wm_keymap.cc:935
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
static rctf calculate_selection_fcurve_bounds(bAnimContext *ac, Span< PointerRNA > selection, PropertyRNA *prop, const StringRefNull id_to_prop_path, const int index, const bool whole_array, int *r_filtered_fcurve_count)
static bool animedit_poll_channels_nla_tweakmode_off(bContext *C)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
void ED_region_toggle_hidden(bContext *C, ARegion *region)
Definition area.cc:2623
static int click_select_channel_grease_pencil_datablock(bAnimListElem *ale)
static wmOperatorStatus animchannels_group_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static void animchannels_group_channels(bAnimContext *ac, bAnimListElem *adt_ref, const char name[])
static int click_select_channel_grease_pencil_layer_group(bContext *C, bAnimListElem *ale)
static bool select_anim_channel_keys(bAnimContext *ac, int channel_index, bool extend)
void free_fmodifiers(ListBaseT< FModifier > *modifiers)
static void ANIM_OT_channels_bake(wmOperatorType *ot)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
static wmOperatorStatus animchannels_collapse_exec(bContext *C, wmOperator *op)
wmMsgBus * CTX_wm_message_bus(const bContext *C)
void BLI_insertlinkbefore(ListBase *listbase, void *vnextlink, void *vnewlink) ATTR_NONNULL(1)
Definition listbase.cc:378
bool(*)(ListBaseT< tReorderChannelIsland > *list, tReorderChannelIsland *island) AnimChanRearrangeFp
void BLI_rctf_union(struct rctf *rct_a, const struct rctf *rct_b)
static const EnumPropertyItem prop_animchannel_rearrange_types[]
static AnimChanRearrangeFp rearrange_get_mode_func(eRearrangeAnimChan_Mode mode)
void ED_anim_ale_fcurve_delete(bAnimContext &ac, bAnimListElem &ale)
static int click_select_channel_object(bContext *C, bAnimContext *ac, bAnimListElem *ale, const short selectmode)
void ED_operatortypes_animchannels()
static wmOperatorStatus animchannels_select_filter_invoke(bContext *C, wmOperator *, const wmEvent *)
ARegion * BKE_area_find_region_type(const ScrArea *area, int region_type)
Definition screen.cc:1024
SpaceLink * CTX_wm_space_data(const bContext *C)
static void add_region_padding(bContext *C, ARegion *region, rctf *bounds)
static void ANIM_OT_channels_setting_disable(wmOperatorType *ot)
wmOperatorStatus WM_gesture_box_modal(bContext *C, wmOperator *op, const wmEvent *event)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
static void ANIM_OT_channels_fcurves_enable(wmOperatorType *ot)
static AnimChanRearrangeFp rearrange_gpencil_get_mode_func(eRearrangeAnimChan_Mode mode)
static bool rearrange_layered_action_slots(bAnimContext *ac, const eRearrangeAnimChan_Mode mode)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
Definition report.cc:191
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:118
void BKE_annotations_free_data(struct bGPdata *gpd, bool free_all)
Main * CTX_data_main(const bContext *C)
void ANIM_flush_setting_anim_channels(bAnimContext *ac, ListBaseT< bAnimListElem > *anim_data, bAnimListElem *ale_setting, eAnimChannel_Settings setting, eAnimChannels_SetFlag mode)
static bool animchannels_delete_containers(const bContext *C, bAnimContext *ac)
static int animchannels_channel_get(bAnimContext *ac, const int mval[2])
static void ANIM_OT_slot_channels_move_to_new_action(wmOperatorType *ot)
static void ANIM_OT_channels_group(wmOperatorType *ot)
static void rearrange_animchannels_filter_visible(ListBaseT< bAnimListElem > *anim_data_visible, bAnimContext *ac, const eAnim_ChannelType type, const eAnimFilter_Flags additional_filters=eAnimFilter_Flags{})
void ANIM_animdata_freelist(ListBaseT< bAnimListElem > *anim_data)
Definition anim_deps.cc:472
static void ANIM_OT_channels_click(wmOperatorType *ot)
float ANIM_unit_mapping_get_factor(Scene *scene, ID *id, FCurve *fcu, short flag, float *r_offset)
Definition anim_draw.cc:636
@ ID_RECALC_ANIMATION
Definition DNA_ID.h:1077
@ ID_RECALC_ANIMATION_NO_FLUSH
Definition DNA_ID.h:1178
@ ID_RECALC_TRANSFORM
Definition DNA_ID.h:1054
@ ID_RECALC_GEOMETRY
Definition DNA_ID.h:1074
ID_Type GS(const char *name)
Definition DNA_ID.h:410
static void ANIM_OT_channels_setting_enable(wmOperatorType *ot)
@ PROP_SKIP_SAVE
Definition RNA_types.hh:414
@ PROP_HIDDEN
Definition RNA_types.hh:408
static int click_select_channel_maskdatablock(bAnimListElem *ale)
void WM_gesture_box_cancel(bContext *C, wmOperator *op)
@ MASK_LAYERFLAG_SELECT
static bool rearrange_island_ok(tReorderChannelIsland *island)
PropertyRNA * RNA_def_int_array(StructOrFunctionRNA *cont_, const char *identifier, const int len, const int *default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
static bool rearrange_island_up(ListBaseT< tReorderChannelIsland > *list, tReorderChannelIsland *island)
static bool animchannel_has_active_of_type(bAnimContext *ac, const eAnim_ChannelType type)
static void ANIM_OT_channels_collapse(wmOperatorType *ot)
static void rearrange_gpencil_channels(bAnimContext *ac, eRearrangeAnimChan_Mode mode)
static wmOperatorStatus animchannels_group_exec(bContext *C, wmOperator *op)
static void rearrange_action_channels(bAnimContext *ac, bAction *act, eRearrangeAnimChan_Mode mode)
void DEG_relations_tag_update(Main *bmain)
Scene * CTX_data_scene(const bContext *C)
void CTX_wm_region_set(bContext *C, ARegion *region)
int BKE_fcurve_bezt_binarysearch_index(const BezTriple array[], float frame, int arraylen, bool *r_replace)
static const EnumPropertyItem prop_animchannel_settings_types[]
static void ANIM_OT_channels_rename(wmOperatorType *ot)
@ OPTYPE_REGISTER
Definition WM_types.hh:188
@ OPTYPE_UNDO
Definition WM_types.hh:190
static wmOperatorStatus animchannels_mouseclick_invoke(bContext *C, wmOperator *op, const wmEvent *event)
std::string RNA_string_get(PointerRNA *ptr, const char *name)
static void templated_selection_state_update(T &selectable_thing, const eAnimChannels_SetFlag selectmode)
static bool get_normalized_fcurve_bounds(FCurve *fcu, SpaceLink *space_link, Scene *scene, ID *id, const bool include_handles, const float range[2], rctf *r_bounds)
static int click_select_channel_fcurve(bAnimContext *ac, bAnimListElem *ale, const short selectmode, const int filter)
static ListBaseT< bAnimListElem > anim_channels_for_selection(bAnimContext *ac)
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
static wmOperatorStatus slot_channels_move_to_new_action_exec(bContext *C, wmOperator *op)
static bool rearrange_island_bottom(ListBaseT< tReorderChannelIsland > *list, tReorderChannelIsland *island)
void ED_region_activate_rna_prop(bContext *C, ARegion *region, const void *data, StringRefNull prop_name)
Definition area.cc:696
static void rearrange_layered_action_fcurves(bAnimContext *ac, animrig::Action &action, const eRearrangeAnimChan_Mode mode)
static bool get_gpencil_bounds(bGPDlayer *gpl, const float range[2], rctf *r_bounds)
bScreen * WM_window_get_active_screen(const wmWindow *win)
MINLINE int min_ii(int a, int b)
bool RNA_path_resolve_property(const PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop)
Definition rna_path.cc:578
PropertyRNA * RNA_def_float(StructOrFunctionRNA *cont_, const char *identifier, const float default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
Object * CTX_data_active_object(const bContext *C)
static wmOperatorStatus animchannels_channel_select_keys_invoke(bContext *C, wmOperator *op, const wmEvent *event)
ARegion * CTX_wm_region(const bContext *C)
static void ANIM_OT_channels_ungroup(wmOperatorType *ot)
static bool get_grease_pencil_layer_bounds(const GreasePencilLayer *gplayer, const float range[2], rctf *r_bounds)
float ANIM_UI_get_channel_step()
@ ANIM_UPDATE_DEPS
void BKE_mask_layer_remove(Mask *mask, MaskLayer *masklay)
ListBaseT< Base > * BKE_view_layer_object_bases_get(ViewLayer *view_layer)
float RNA_float_get(PointerRNA *ptr, const char *name)
bPoseChannel * BKE_pose_channel_find_name(const bPose *pose, const char *name)
static wmOperatorStatus animchannels_enable_exec(bContext *C, wmOperator *)
void ANIM_anim_channels_select_toggle(bAnimContext *ac)
static void animchannel_select_range(bAnimContext *ac, bAnimListElem *cursor_elem)
static void box_select_anim_channels(bAnimContext *ac, const rcti &rect, short selectmode)
static void ANIM_OT_channels_editable_toggle(wmOperatorType *ot)
static void rearrange_animchannel_add_to_islands(ListBaseT< tReorderChannelIsland > *islands, ListBaseT< T > *srcList, Link *channel, eAnim_ChannelType type, const bool is_hidden)
static int click_select_channel_group(bAnimContext *ac, bAnimListElem *ale, const short selectmode, const int filter)
static void ANIM_OT_channels_setting_toggle(wmOperatorType *ot)
void ED_area_tag_redraw(ScrArea *area)
Definition area.cc:784
void ANIM_frame_channel_y_extents(bContext *C, bAnimContext *ac)
short ANIM_get_normalization_flags(SpaceLink *space_link)
Definition anim_draw.cc:420
void CTX_wm_area_set(bContext *C, ScrArea *area)
static bool rearrange_island_top(ListBaseT< tReorderChannelIsland > *list, tReorderChannelIsland *island)
@ FMODIFIER_FLAG_MUTED
eAnimData_Flag flag
ListBaseT< FCurve > drivers
ListBaseT< NlaTrack > nla_tracks
struct Object * object
eBezTriple_Flag f2
eBezTriple_Flag f3
eBezTriple_Flag f1
eBezTriple_Interpolation ipo
bActionGroup * grp
eFCurve_Flags flag
struct FCurve * next
ListBaseT< FModifier > modifiers
ChannelDriver * driver
unsigned int totvert
char name[258]
Definition DNA_ID.h:433
KeyBlockFlag flag
ListBaseT< KeyBlock > block
ListBaseT< FCurve > fcurves
struct NlaTrack * prev
eNlaTrack_Flag flag
ListBaseT< NlaStrip > strips
struct NlaTrack * next
struct AnimData * adt
struct bPose * pose
struct AnimData * adt
struct bGPdata * gpd
struct RenderData r
eAnimEdit_Context mode
struct bDopeSheet * ads
eGraphEdit_Mode mode
ListBaseT< FCurve > channels
struct ActionChannelbag * channelbag
bool(*) name_prop(bAnimListElem *ale, PointerRNA *r_ptr, PropertyRNA **r_prop)
short(*) get_offset(bAnimContext *ac, bAnimListElem *ale)
eRegion_Type regiontype
struct blender::bAnimContext::@354357007254244122245111034311231000121111260015 filters
eAnimCont_Types datatype
eAnim_ChannelType type
bAnimListElem * prev
bAnimListElem * next
eDopeSheet_FilterFlag filterflag
ListBaseT< bGPDframe > frames
ListBaseT< bGPDlayer > layers
ListBaseT< struct ScrArea > areabase
ListBaseT< bAnimListElem > channels
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1125
bool(*) poll_property(const bContext *C, wmOperator *op, const PropertyRNA *prop) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1171
const char * description
Definition WM_types.hh:1115
void(*) cancel(bContext *C, wmOperator *op)
Definition WM_types.hh:1149
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1165
wmOperatorStatus(*) invoke(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1141
wmOperatorStatus(*) modal(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1157
struct ReportList * reports
#define WM_msg_publish_rna_prop(mbus, id_, data_, type_, prop_)