Allow renaming F-curve modifier

Modifier name is being displayed as label in panel header which has restricted
the editing of it. This PR will allow to change the name of F-curve modifier
by exposing string property "name"
Included versioning code for modifier name. This will add suffix to the name if
multiple instances of same modifier exists in modifier stack.

Differential Revision: https://archive.blender.org/developer/D17142

Pull Request: https://projects.blender.org/blender/blender/pulls/104949
This commit is contained in:
Pratik Borhade
2023-05-02 13:07:48 +02:00
committed by Pratik Borhade
parent 90361278d7
commit 0001485365
6 changed files with 43 additions and 7 deletions

View File

@@ -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).

View File

@@ -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;

View File

@@ -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;

View File

@@ -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.
*

View File

@@ -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_("<Unknown Modifier>"), ICON_NONE);
}
/* Right align. */
sub = uiLayoutRow(layout, true);
uiLayoutSetAlignment(sub, UI_LAYOUT_ALIGN_RIGHT);

View File

@@ -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);