Refactor: combine insert_keyframe() and insert_key_rna() into a single function #122053

Merged
Nathan Vegdahl merged 49 commits from nathanvegdahl/blender:combine_keying_functions into main 2024-06-11 16:43:08 +02:00
3 changed files with 14 additions and 24 deletions
Showing only changes of commit 7030b35174 - Show all commits

View File

@ -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 none if it has no default.
*
* For example, for object location/rotation/scale this returns the standard
* object transforms channel group name.
*/
std::optional<StringRefNull> default_channel_group_for_path(const PointerRNA *ptr,
const StringRef rna_path);
/* -------------------------------------------------------------------- */
/** \name Key-Framing Management
* \{ */

View File

@ -742,8 +742,8 @@ int clear_keyframe(Main *bmain,
return key_count;
}
static std::optional<StringRefNull> default_channel_group_for_path(const PointerRNA *ptr,
const StringRef rna_path)
std::optional<StringRefNull> default_channel_group_for_path(const PointerRNA *ptr,
const StringRef rna_path)
{
if (ptr->type == &RNA_PoseBone) {
bPoseChannel *pose_channel = static_cast<bPoseChannel *>(ptr->data);

View File

@ -1026,28 +1026,7 @@ static int insert_key_button_exec(bContext *C, wmOperator *op)
/* standard properties */
if (const std::optional<std::string> path = RNA_path_from_ID_to_property(&ptr, prop)) {
const char *identifier = RNA_property_identifier(prop);
std::optional<std::string> group = std::nullopt;
/* 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<bPoseChannel *>(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";
}
std::optional<std::string> group = default_channel_group_for_path(&ptr, identifier);
/* NOTE: `index == -1` is a magic number, meaning either "operate on all
* elements" or "not an array property". */