From b821e561657d725a783b9ae97c525857151e8b00 Mon Sep 17 00:00:00 2001 From: Nathan Vegdahl Date: Tue, 28 May 2024 09:59:35 +0200 Subject: [PATCH] Refactor: Anim: put default channel group names in one place Previously they were split between two places, and were not fully consistent with each other. The inconsistency didn't result in user-facing inconsistency due to what was called when at a higher level, but this will ensure continued user-facing consistency as we make more changes to the keyframing code. Pull Request: https://projects.blender.org/blender/blender/pulls/122317 --- source/blender/animrig/ANIM_keyframing.hh | 11 ++++++ source/blender/animrig/intern/keyframing.cc | 34 ++++++++++++++----- .../blender/editors/animation/keyframing.cc | 23 +------------ 3 files changed, 37 insertions(+), 31 deletions(-) diff --git a/source/blender/animrig/ANIM_keyframing.hh b/source/blender/animrig/ANIM_keyframing.hh index dd020e1b3f7..8a7dd36abb1 100644 --- a/source/blender/animrig/ANIM_keyframing.hh +++ b/source/blender/animrig/ANIM_keyframing.hh @@ -15,6 +15,7 @@ #include "BLI_array.hh" #include "BLI_bit_span.hh" +#include "BLI_string_ref.hh" #include "BLI_vector.hh" #include "DNA_anim_types.h" #include "RNA_path.hh" @@ -73,6 +74,16 @@ class CombinedKeyingResult { void generate_reports(ReportList *reports); }; +/** + * Return the default channel group name for the given RNA pointer and property + * path, or nullptr if it has no default. + * + * For example, for object location/rotation/scale this returns the standard + * "Object Transforms" channel group name. + */ +const char *default_channel_group_for_path(const PointerRNA *animated_struct, + const StringRef prop_rna_path); + /* -------------------------------------------------------------------- */ /** \name Key-Framing Management * \{ */ diff --git a/source/blender/animrig/intern/keyframing.cc b/source/blender/animrig/intern/keyframing.cc index 620fd074222..808eea89a93 100644 --- a/source/blender/animrig/intern/keyframing.cc +++ b/source/blender/animrig/intern/keyframing.cc @@ -163,6 +163,29 @@ void CombinedKeyingResult::generate_reports(ReportList *reports) BKE_report(reports, RPT_ERROR, error_message.c_str()); } +const char *default_channel_group_for_path(const PointerRNA *animated_struct, + const StringRef prop_rna_path) +{ + if (animated_struct->type == &RNA_PoseBone) { + bPoseChannel *pose_channel = static_cast(animated_struct->data); + return pose_channel->name; + } + + if (animated_struct->type == &RNA_Object) { + if (prop_rna_path.find("location") != StringRef::not_found || + prop_rna_path.find("rotation") != StringRef::not_found || + prop_rna_path.find("scale") != StringRef::not_found) + { + /* NOTE: Keep this label in sync with the "ID" case in + * keyingsets_utils.py :: get_transform_generators_base_info() + */ + return "Object Transforms"; + } + } + + return nullptr; +} + void update_autoflags_fcurve_direct(FCurve *fcu, PropertyRNA *prop) { /* Set additional flags for the F-Curve (i.e. only integer values). */ @@ -925,14 +948,7 @@ CombinedKeyingResult insert_key_action(Main *bmain, BLI_assert(bmain != nullptr); BLI_assert(action != nullptr); - std::string group; - if (ptr->type == &RNA_PoseBone) { - bPoseChannel *pose_channel = static_cast(ptr->data); - group = pose_channel->name; - } - else { - group = "Object Transforms"; - } + const char *group = default_channel_group_for_path(ptr, rna_path); int property_array_index = 0; CombinedKeyingResult combined_result; @@ -946,7 +962,7 @@ CombinedKeyingResult insert_key_action(Main *bmain, ptr, prop, action, - group.c_str(), + group, rna_path.c_str(), property_array_index, frame, diff --git a/source/blender/editors/animation/keyframing.cc b/source/blender/editors/animation/keyframing.cc index b9f6893dcec..c0126d5dc65 100644 --- a/source/blender/editors/animation/keyframing.cc +++ b/source/blender/editors/animation/keyframing.cc @@ -1025,28 +1025,7 @@ static int insert_key_button_exec(bContext *C, wmOperator *op) /* standard properties */ if (const std::optional path = RNA_path_from_ID_to_property(&ptr, prop)) { const char *identifier = RNA_property_identifier(prop); - const char *group = nullptr; - - /* Special exception for keyframing transforms: - * Set "group" for this manually, instead of having them appearing at the bottom - * (ungrouped) part of the channels list. - * Leaving these ungrouped is not a nice user behavior in this case. - * - * TODO: Perhaps we can extend this behavior in future for other properties... - */ - if (ptr.type == &RNA_PoseBone) { - bPoseChannel *pchan = static_cast(ptr.data); - group = pchan->name; - } - else if ((ptr.type == &RNA_Object) && - (strstr(identifier, "location") || strstr(identifier, "rotation") || - strstr(identifier, "scale"))) - { - /* NOTE: Keep this label in sync with the "ID" case in - * keyingsets_utils.py :: get_transform_generators_base_info() - */ - group = "Object Transforms"; - } + const char *group = default_channel_group_for_path(&ptr, identifier); if (all) { /* -1 indicates operating on the entire array (or the property itself otherwise) */