diff --git a/source/blender/blenkernel/BKE_fcurve.h b/source/blender/blenkernel/BKE_fcurve.h index ee38250a056..3d7aa88cd8c 100644 --- a/source/blender/blenkernel/BKE_fcurve.h +++ b/source/blender/blenkernel/BKE_fcurve.h @@ -240,6 +240,10 @@ void BKE_fcurves_free(ListBase *list); */ void BKE_fcurves_copy(ListBase *dst, ListBase *src); +/* Set fcurve modifier name and ensure uniqueness. + * Pass new name string when it's been edited otherwise pass empty string. */ +void BKE_fmodifier_name_set(struct FModifier *fcm, const char *name); + /** * Callback used by lib_query to walk over all ID usages * (mimics `foreach_id` callback of #IDTypeInfo structure). diff --git a/source/blender/blenkernel/intern/fcurve.c b/source/blender/blenkernel/intern/fcurve.c index afec3349ca7..7e1b95ac6b1 100644 --- a/source/blender/blenkernel/intern/fcurve.c +++ b/source/blender/blenkernel/intern/fcurve.c @@ -22,6 +22,7 @@ #include "BLI_ghash.h" #include "BLI_math.h" #include "BLI_sort_utils.h" +#include "BLI_string_utils.h" #include "BKE_anim_data.h" #include "BKE_animsys.h" @@ -157,6 +158,18 @@ void BKE_fcurves_copy(ListBase *dst, ListBase *src) } } +void BKE_fmodifier_name_set(FModifier *fcm, const char *name) +{ + /* Copy new Modifier name. */ + BLI_strncpy(fcm->name, name, sizeof(fcm->name)); + + /* Set default modifier name when name parameter is an empty string. + * Ensure the name is unique. */ + const FModifierTypeInfo *fmi = get_fmodifier_typeinfo(fcm->type); + ListBase list = BLI_listbase_from_link((Link *)fcm); + BLI_uniquename(&list, fcm, fmi->name, '.', offsetof(FModifier, name), sizeof(fcm->name)); +} + void BKE_fcurve_foreach_id(FCurve *fcu, LibraryForeachIDData *data) { ChannelDriver *driver = fcu->driver; diff --git a/source/blender/blenkernel/intern/fmodifier.c b/source/blender/blenkernel/intern/fmodifier.c index 486eba9c274..35216407495 100644 --- a/source/blender/blenkernel/intern/fmodifier.c +++ b/source/blender/blenkernel/intern/fmodifier.c @@ -1109,6 +1109,9 @@ FModifier *add_fmodifier(ListBase *modifiers, int type, FCurve *owner_fcu) fcm->influence = 1.0f; BLI_addtail(modifiers, fcm); + /* Set modifier name and make sure it is unique. */ + BKE_fmodifier_name_set(fcm, ""); + /* tag modifier as "active" if no other modifiers exist in the stack yet */ if (BLI_listbase_is_single(modifiers)) { fcm->flag |= FMODIFIER_FLAG_ACTIVE; diff --git a/source/blender/blenloader/intern/versioning_300.cc b/source/blender/blenloader/intern/versioning_300.cc index 26864b762b8..8c01375c3e5 100644 --- a/source/blender/blenloader/intern/versioning_300.cc +++ b/source/blender/blenloader/intern/versioning_300.cc @@ -4331,6 +4331,19 @@ void blo_do_versions_300(FileData *fd, Library * /*lib*/, Main *bmain) do_versions_rename_id(bmain, ID_BR, "Draw Weight", "Weight Draw"); } + /* fcm->name was never used to store modifier name so it has always been an empty string. Now + * this property supports name editing. So assign value to name variable of Fmodifier otherwise + * modifier interface would show an empty name field. Also ensure uniqueness when opening old + * files. */ + if (!MAIN_VERSION_ATLEAST(bmain, 306, 6)) { + LISTBASE_FOREACH (bAction *, act, &bmain->actions) { + LISTBASE_FOREACH (FCurve *, fcu, &act->curves) { + LISTBASE_FOREACH (FModifier *, fcm, &fcu->modifiers) { + BKE_fmodifier_name_set(fcm, ""); + } + } + } + } /** * Versioning code until next subversion bump goes here. * diff --git a/source/blender/editors/animation/fmodifier_ui.c b/source/blender/editors/animation/fmodifier_ui.c index 007e911156e..175bce8266f 100644 --- a/source/blender/editors/animation/fmodifier_ui.c +++ b/source/blender/editors/animation/fmodifier_ui.c @@ -303,20 +303,17 @@ static void fmodifier_panel_header(const bContext *C, Panel *panel) uiBlock *block = uiLayoutGetBlock(layout); uiLayout *sub = uiLayoutRow(layout, true); - uiLayoutSetAlignment(sub, UI_LAYOUT_ALIGN_LEFT); - uiLayoutSetEmboss(sub, UI_EMBOSS_NONE); /* Checkbox for 'active' status (for now). */ uiItemR(sub, ptr, "active", UI_ITEM_R_ICON_ONLY, "", ICON_NONE); /* Name. */ if (fmi) { - uiItemL(sub, IFACE_(fmi->name), ICON_NONE); + uiItemR(sub, ptr, "name", 0, "", ICON_NONE); } else { uiItemL(sub, IFACE_(""), ICON_NONE); } - /* Right align. */ sub = uiLayoutRow(layout, true); uiLayoutSetAlignment(sub, UI_LAYOUT_ALIGN_RIGHT); diff --git a/source/blender/makesrna/intern/rna_fcurve.c b/source/blender/makesrna/intern/rna_fcurve.c index f681af20979..a0c65a48fe1 100644 --- a/source/blender/makesrna/intern/rna_fcurve.c +++ b/source/blender/makesrna/intern/rna_fcurve.c @@ -839,6 +839,12 @@ static void rna_FModifier_update(Main *bmain, Scene *UNUSED(scene), PointerRNA * rna_tag_animation_update(bmain, id); } +static void rna_fModifier_name_set(PointerRNA *ptr, const char *value) +{ + FModifier *fcm = (FModifier *)ptr->data; + BKE_fmodifier_name_set(fcm, value); +} + static void rna_FModifier_verify_data_update(Main *bmain, Scene *scene, PointerRNA *ptr) { FModifier *fcm = (FModifier *)ptr->data; @@ -1749,12 +1755,12 @@ static void rna_def_fmodifier(BlenderRNA *brna) RNA_def_struct_refine_func(srna, "rna_FModifierType_refine"); RNA_def_struct_ui_text(srna, "F-Modifier", "Modifier for values of F-Curve"); -# if 0 /* XXX not used yet */ /* name */ prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE); + RNA_def_property_string_funcs(prop, NULL, NULL, "rna_fModifier_name_set"); + RNA_def_property_ui_text(prop, "Name", "F-Curve Modifier name"); + RNA_def_property_update(prop, NC_OBJECT | ND_MODIFIER | NA_RENAME, NULL); RNA_def_struct_name_property(srna, prop); - RNA_def_property_ui_text(prop, "Name", "Short description of F-Curve Modifier"); -# endif /* XXX not used yet */ /* type */ prop = RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);