Anim: Multi Editing for FCurve modifiers #112419

Merged
Christoph Lendenfeld merged 2 commits from ChrisLend/blender:fcu_mod_multi_edit into main 2023-09-21 09:57:25 +02:00

View File

@ -1055,6 +1055,33 @@ static void ui_context_selected_bones_via_pose(bContext *C, ListBase *r_lb)
*r_lb = lb;
}
static void ui_context_fcurve_modifiers_via_fcurve(bContext *C, ListBase *r_lb, FModifier *source)
{
ListBase /* CollectionPointerLink */ fcurve_links;

As a rule of thumb, I always recommend documenting what's in the listbase, so ListBase /*CollectionPointerLink*/ lb.

And probably a better name than lb is also more 'modern', so something like ListBase /*CollectionPointerLink*/ fcurve_links?

As a rule of thumb, I always recommend documenting what's in the listbase, so `ListBase /*CollectionPointerLink*/ lb`. And probably a better name than `lb` is also more 'modern', so something like `ListBase /*CollectionPointerLink*/ fcurve_links`?
fcurve_links = CTX_data_collection_get(C, "selected_editable_fcurves");
if (BLI_listbase_is_empty(&fcurve_links)) {
return;
}
LISTBASE_FOREACH_MUTABLE (CollectionPointerLink *, link, &fcurve_links) {
FCurve *fcu = static_cast<FCurve *>(link->ptr.data);

Use LISTBASE_FOREACH_MUTABLE here, as you're modifying lb while iterating.

Use `LISTBASE_FOREACH_MUTABLE` here, as you're modifying `lb` while iterating.
bool found_modifier = false;
LISTBASE_FOREACH (FModifier *, mod, &fcu->modifiers) {
if (STREQ(mod->name, source->name) && mod->type == source->type) {
link->ptr = RNA_pointer_create(link->ptr.owner_id, &RNA_FModifier, mod);
found_modifier = true;
/* Since names are unique it is safe to break here. */
break;
}
}
if (!found_modifier) {
/* FCurves that don't have a modifier named the same must be removed to avoid segfaults. */
BLI_freelinkN(&fcurve_links, link);
}
}
*r_lb = fcurve_links;
}
bool UI_context_copy_to_selected_list(bContext *C,
PointerRNA *ptr,
PropertyRNA *prop,
@ -1184,6 +1211,10 @@ bool UI_context_copy_to_selected_list(bContext *C,
else if (RNA_struct_is_a(ptr->type, &RNA_FCurve)) {
*r_lb = CTX_data_collection_get(C, "selected_editable_fcurves");
}
else if (RNA_struct_is_a(ptr->type, &RNA_FModifier)) {
FModifier *mod = static_cast<FModifier *>(ptr->data);
ui_context_fcurve_modifiers_via_fcurve(C, r_lb, mod);
}
else if (RNA_struct_is_a(ptr->type, &RNA_Keyframe)) {
*r_lb = CTX_data_collection_get(C, "selected_editable_keyframes");
}