From 76efd2b1b7e1392d755911f459c6859a093641f2 Mon Sep 17 00:00:00 2001 From: Pratik Borhade Date: Sun, 19 Feb 2023 17:48:41 +0530 Subject: [PATCH 1/6] Allow renaming F-curve modifier Modifier name is being displayed as label in panel header which has restricted the name editing of it. Patch will allow to change the name of F-curve modifier by exposing string property "name" Differential Revision: https://archive.blender.org/developer/D17142 --- source/blender/blenkernel/intern/fmodifier.c | 3 +++ .../blender/editors/animation/fmodifier_ui.c | 10 +++------- source/blender/makesrna/intern/rna_fcurve.c | 19 ++++++++++++++++--- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/source/blender/blenkernel/intern/fmodifier.c b/source/blender/blenkernel/intern/fmodifier.c index ae9b0f5e558..adca26b895c 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); + /* Copy Modifier name. */ + BLI_strncpy(fcm->name, fmi->name, sizeof(fmi->name)); + /* 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/editors/animation/fmodifier_ui.c b/source/blender/editors/animation/fmodifier_ui.c index 5bb95f1155e..9a885ad3ebd 100644 --- a/source/blender/editors/animation/fmodifier_ui.c +++ b/source/blender/editors/animation/fmodifier_ui.c @@ -308,19 +308,15 @@ 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); - } - else { - uiItemL(sub, IFACE_(""), ICON_NONE); + if (fmi && fcm->name[0] == '\0') { + BLI_strncpy(fcm->name, fmi->name, sizeof(fmi->name)); } + uiItemR(sub, ptr, "name", 0, "", ICON_NONE); /* Right align. */ sub = uiLayoutRow(layout, true); diff --git a/source/blender/makesrna/intern/rna_fcurve.c b/source/blender/makesrna/intern/rna_fcurve.c index f92b137d3ae..f07700b4544 100644 --- a/source/blender/makesrna/intern/rna_fcurve.c +++ b/source/blender/makesrna/intern/rna_fcurve.c @@ -15,6 +15,8 @@ #include "BLT_translation.h" +#include "BLI_string_utils.h" + #include "BKE_action.h" #include "RNA_access.h" @@ -758,6 +760,17 @@ 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; + BLI_strncpy(fcm->name, value, sizeof(fcm->name)); + + /* Check unique name. */ + 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)); +} + static void rna_FModifier_verify_data_update(Main *bmain, Scene *scene, PointerRNA *ptr) { FModifier *fcm = (FModifier *)ptr->data; @@ -1662,12 +1675,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); -- 2.30.2 From 8f66da6088250a3f2da76ba7fcde8ebef195463c Mon Sep 17 00:00:00 2001 From: Pratik Borhade Date: Fri, 14 Apr 2023 17:59:17 +0530 Subject: [PATCH 2/6] Include following fixes: - Ensure uniqueness of names when creating modifiers - Use `fcm->name` instead of `fmi->name` for max size - New function `BKE_fmodifier_unique_name_set` to check unique modifier names - Revert change from `fmodifier_ui.c` which was setting `fcm->name` --- source/blender/blenkernel/BKE_fcurve.h | 2 ++ source/blender/blenkernel/intern/fcurve.c | 8 ++++++++ source/blender/blenkernel/intern/fmodifier.c | 5 ++++- source/blender/editors/animation/fmodifier_ui.c | 9 +++++---- source/blender/makesrna/intern/rna_fcurve.c | 6 +----- 5 files changed, 20 insertions(+), 10 deletions(-) diff --git a/source/blender/blenkernel/BKE_fcurve.h b/source/blender/blenkernel/BKE_fcurve.h index 2f18eef7850..315cf138633 100644 --- a/source/blender/blenkernel/BKE_fcurve.h +++ b/source/blender/blenkernel/BKE_fcurve.h @@ -240,6 +240,8 @@ void BKE_fcurves_free(ListBase *list); */ void BKE_fcurves_copy(ListBase *dst, ListBase *src); +void BKE_fmodifier_unique_name_set(struct FModifier *fcm); + /** * 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 4372e2f81ab..2ff9bd28814 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,13 @@ void BKE_fcurves_copy(ListBase *dst, ListBase *src) } } +void BKE_fmodifier_unique_name_set(FModifier *fcm) +{ + 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 adca26b895c..9edcadad20c 100644 --- a/source/blender/blenkernel/intern/fmodifier.c +++ b/source/blender/blenkernel/intern/fmodifier.c @@ -1110,7 +1110,10 @@ FModifier *add_fmodifier(ListBase *modifiers, int type, FCurve *owner_fcu) BLI_addtail(modifiers, fcm); /* Copy Modifier name. */ - BLI_strncpy(fcm->name, fmi->name, sizeof(fmi->name)); + BLI_strncpy(fcm->name, fmi->name, sizeof(fcm->name)); + + /* Check unique name. */ + BKE_fmodifier_unique_name_set(fcm); /* tag modifier as "active" if no other modifiers exist in the stack yet */ if (BLI_listbase_is_single(modifiers)) { diff --git a/source/blender/editors/animation/fmodifier_ui.c b/source/blender/editors/animation/fmodifier_ui.c index 0b60500dc35..175bce8266f 100644 --- a/source/blender/editors/animation/fmodifier_ui.c +++ b/source/blender/editors/animation/fmodifier_ui.c @@ -308,11 +308,12 @@ static void fmodifier_panel_header(const bContext *C, Panel *panel) uiItemR(sub, ptr, "active", UI_ITEM_R_ICON_ONLY, "", ICON_NONE); /* Name. */ - if (fmi && fcm->name[0] == '\0') { - BLI_strncpy(fcm->name, fmi->name, sizeof(fmi->name)); + if (fmi) { + uiItemR(sub, ptr, "name", 0, "", ICON_NONE); + } + else { + uiItemL(sub, IFACE_(""), ICON_NONE); } - uiItemR(sub, ptr, "name", 0, "", 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 9bf2f651925..62922c12739 100644 --- a/source/blender/makesrna/intern/rna_fcurve.c +++ b/source/blender/makesrna/intern/rna_fcurve.c @@ -15,8 +15,6 @@ #include "BLT_translation.h" -#include "BLI_string_utils.h" - #include "BKE_action.h" #include "RNA_access.h" @@ -846,9 +844,7 @@ static void rna_fModifier_name_set(PointerRNA *ptr, const char *value) BLI_strncpy(fcm->name, value, sizeof(fcm->name)); /* Check unique name. */ - 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)); + BKE_fmodifier_unique_name_set(fcm); } static void rna_FModifier_verify_data_update(Main *bmain, Scene *scene, PointerRNA *ptr) -- 2.30.2 From dbb1b162ef9bb6a82dbcf02a6e7a0e8416bdba9a Mon Sep 17 00:00:00 2001 From: Pratik Borhade Date: Tue, 18 Apr 2023 14:55:38 +0530 Subject: [PATCH 3/6] Use single function to set name and check uniqueness - `BKE_fmodifier_name_set` function created --- source/blender/blenkernel/BKE_fcurve.h | 3 ++- source/blender/blenkernel/intern/fcurve.c | 6 +++++- source/blender/blenkernel/intern/fmodifier.c | 7 ++----- source/blender/makesrna/intern/rna_fcurve.c | 5 +---- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/source/blender/blenkernel/BKE_fcurve.h b/source/blender/blenkernel/BKE_fcurve.h index 315cf138633..6a13b8fe1e2 100644 --- a/source/blender/blenkernel/BKE_fcurve.h +++ b/source/blender/blenkernel/BKE_fcurve.h @@ -240,7 +240,8 @@ void BKE_fcurves_free(ListBase *list); */ void BKE_fcurves_copy(ListBase *dst, ListBase *src); -void BKE_fmodifier_unique_name_set(struct FModifier *fcm); +/* Set fcurve modifier name and check uniqueness. */ +void BKE_fmodifier_name_set(struct FModifier *fcm, const char *name); /** * Callback used by lib_query to walk over all ID usages diff --git a/source/blender/blenkernel/intern/fcurve.c b/source/blender/blenkernel/intern/fcurve.c index 2ff9bd28814..688f7dcaef9 100644 --- a/source/blender/blenkernel/intern/fcurve.c +++ b/source/blender/blenkernel/intern/fcurve.c @@ -158,8 +158,12 @@ void BKE_fcurves_copy(ListBase *dst, ListBase *src) } } -void BKE_fmodifier_unique_name_set(FModifier *fcm) +void BKE_fmodifier_name_set(FModifier *fcm, const char *name) { + /* Copy Modifier name. */ + BLI_strncpy(fcm->name, name, sizeof(fcm->name)); + + /* Check unique name. */ 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)); diff --git a/source/blender/blenkernel/intern/fmodifier.c b/source/blender/blenkernel/intern/fmodifier.c index 9edcadad20c..79c51807eae 100644 --- a/source/blender/blenkernel/intern/fmodifier.c +++ b/source/blender/blenkernel/intern/fmodifier.c @@ -1109,11 +1109,8 @@ FModifier *add_fmodifier(ListBase *modifiers, int type, FCurve *owner_fcu) fcm->influence = 1.0f; BLI_addtail(modifiers, fcm); - /* Copy Modifier name. */ - BLI_strncpy(fcm->name, fmi->name, sizeof(fcm->name)); - - /* Check unique name. */ - BKE_fmodifier_unique_name_set(fcm); + /* Set modifier name. */ + BKE_fmodifier_name_set(fcm, fmi->name); /* tag modifier as "active" if no other modifiers exist in the stack yet */ if (BLI_listbase_is_single(modifiers)) { diff --git a/source/blender/makesrna/intern/rna_fcurve.c b/source/blender/makesrna/intern/rna_fcurve.c index 62922c12739..1f554aa147c 100644 --- a/source/blender/makesrna/intern/rna_fcurve.c +++ b/source/blender/makesrna/intern/rna_fcurve.c @@ -841,10 +841,7 @@ static void rna_FModifier_update(Main *bmain, Scene *UNUSED(scene), PointerRNA * static void rna_fModifier_name_set(PointerRNA *ptr, const char *value) { FModifier *fcm = (FModifier *)ptr->data; - BLI_strncpy(fcm->name, value, sizeof(fcm->name)); - - /* Check unique name. */ - BKE_fmodifier_unique_name_set(fcm); + BKE_fmodifier_name_set(fcm, value); } static void rna_FModifier_verify_data_update(Main *bmain, Scene *scene, PointerRNA *ptr) -- 2.30.2 From 91e27b96ebd47e5d6bddd7658bbac5095d72433e Mon Sep 17 00:00:00 2001 From: Pratik Borhade Date: Tue, 18 Apr 2023 16:58:58 +0530 Subject: [PATCH 4/6] Add versioning code to name fcurve modifiers when opening old files. This change is needed. Otherwise modifier would have empty name field and duplicate names. --- source/blender/blenkernel/BKE_blender_version.h | 2 +- source/blender/blenloader/intern/versioning_300.cc | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/source/blender/blenkernel/BKE_blender_version.h b/source/blender/blenkernel/BKE_blender_version.h index cfd38d6167b..ba870cd7882 100644 --- a/source/blender/blenkernel/BKE_blender_version.h +++ b/source/blender/blenkernel/BKE_blender_version.h @@ -25,7 +25,7 @@ extern "C" { /* Blender file format version. */ #define BLENDER_FILE_VERSION BLENDER_VERSION -#define BLENDER_FILE_SUBVERSION 5 +#define BLENDER_FILE_SUBVERSION 6 /* Minimum Blender version that supports reading file written with the current * version. Older Blender versions will test this and show a warning if the file diff --git a/source/blender/blenloader/intern/versioning_300.cc b/source/blender/blenloader/intern/versioning_300.cc index 82375346a74..fc45714a715 100644 --- a/source/blender/blenloader/intern/versioning_300.cc +++ b/source/blender/blenloader/intern/versioning_300.cc @@ -4283,6 +4283,17 @@ void blo_do_versions_300(FileData *fd, Library * /*lib*/, Main *bmain) } } + /* Set fcurve modifier name and check their uniqueness when opening old files. Otherwise + * modifiers would have empty name field. */ + 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. * -- 2.30.2 From 660fcd9b607850ba271207f94c99b6b6d6bbd6c5 Mon Sep 17 00:00:00 2001 From: Pratik Borhade Date: Tue, 2 May 2023 14:32:54 +0530 Subject: [PATCH 5/6] Improve code comments --- source/blender/blenkernel/BKE_fcurve.h | 3 ++- source/blender/blenkernel/intern/fcurve.c | 5 +++-- source/blender/blenkernel/intern/fmodifier.c | 4 ++-- source/blender/blenloader/intern/versioning_300.cc | 6 ++++-- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/source/blender/blenkernel/BKE_fcurve.h b/source/blender/blenkernel/BKE_fcurve.h index 6a13b8fe1e2..7c4f18af848 100644 --- a/source/blender/blenkernel/BKE_fcurve.h +++ b/source/blender/blenkernel/BKE_fcurve.h @@ -240,7 +240,8 @@ void BKE_fcurves_free(ListBase *list); */ void BKE_fcurves_copy(ListBase *dst, ListBase *src); -/* Set fcurve modifier name and check uniqueness. */ +/* Set fcurve modifier name and ensure uniqueness. + * Pass new name string when its edited otherwise pass empty string. */ void BKE_fmodifier_name_set(struct FModifier *fcm, const char *name); /** diff --git a/source/blender/blenkernel/intern/fcurve.c b/source/blender/blenkernel/intern/fcurve.c index 688f7dcaef9..06313a3bc2f 100644 --- a/source/blender/blenkernel/intern/fcurve.c +++ b/source/blender/blenkernel/intern/fcurve.c @@ -160,10 +160,11 @@ void BKE_fcurves_copy(ListBase *dst, ListBase *src) void BKE_fmodifier_name_set(FModifier *fcm, const char *name) { - /* Copy Modifier name. */ + /* Copy new Modifier name. */ BLI_strncpy(fcm->name, name, sizeof(fcm->name)); - /* Check unique 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)); diff --git a/source/blender/blenkernel/intern/fmodifier.c b/source/blender/blenkernel/intern/fmodifier.c index 79c51807eae..629521aa484 100644 --- a/source/blender/blenkernel/intern/fmodifier.c +++ b/source/blender/blenkernel/intern/fmodifier.c @@ -1109,8 +1109,8 @@ FModifier *add_fmodifier(ListBase *modifiers, int type, FCurve *owner_fcu) fcm->influence = 1.0f; BLI_addtail(modifiers, fcm); - /* Set modifier name. */ - BKE_fmodifier_name_set(fcm, fmi->name); + /* 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)) { diff --git a/source/blender/blenloader/intern/versioning_300.cc b/source/blender/blenloader/intern/versioning_300.cc index fc45714a715..1c971cc0961 100644 --- a/source/blender/blenloader/intern/versioning_300.cc +++ b/source/blender/blenloader/intern/versioning_300.cc @@ -4283,8 +4283,10 @@ void blo_do_versions_300(FileData *fd, Library * /*lib*/, Main *bmain) } } - /* Set fcurve modifier name and check their uniqueness when opening old files. Otherwise - * modifiers would have empty name field. */ + /* 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) { -- 2.30.2 From b8c2d440f4e2081becc36f903538c6a84dd537ba Mon Sep 17 00:00:00 2001 From: Pratik Borhade Date: Tue, 2 May 2023 14:54:54 +0530 Subject: [PATCH 6/6] Fix grammar mistake --- source/blender/blenkernel/BKE_fcurve.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/blender/blenkernel/BKE_fcurve.h b/source/blender/blenkernel/BKE_fcurve.h index 7c4f18af848..7c2f2f306f4 100644 --- a/source/blender/blenkernel/BKE_fcurve.h +++ b/source/blender/blenkernel/BKE_fcurve.h @@ -241,7 +241,7 @@ 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 its edited otherwise pass empty string. */ + * Pass new name string when it's been edited otherwise pass empty string. */ void BKE_fmodifier_name_set(struct FModifier *fcm, const char *name); /** -- 2.30.2