Refactor: combine insert_keyframe() and insert_key_rna() into a single function #122053
@ -100,14 +100,14 @@ void update_autoflags_fcurve_direct(FCurve *fcu, PropertyRNA *prop);
|
||||
* \returns A summary of the successful and failed keyframe insertions, with
|
||||
* reasons for the failures.
|
||||
*/
|
||||
CombinedKeyingResult insert_key_rna(Main *bmain,
|
||||
ID &id,
|
||||
std::optional<std::string> channel_group,
|
||||
const blender::Span<RNAPath> rna_paths,
|
||||
std::optional<float> scene_frame,
|
||||
const AnimationEvalContext &anim_eval_context,
|
||||
eBezTriple_KeyframeType key_type,
|
||||
eInsertKeyFlags insert_key_flags);
|
||||
CombinedKeyingResult insert_keyframes(Main *bmain,
|
||||
ID &id,
|
||||
const blender::Span<RNAPath> rna_paths,
|
||||
std::optional<std::string> channel_group,
|
||||
std::optional<float> scene_frame,
|
||||
const AnimationEvalContext &anim_eval_context,
|
||||
eBezTriple_KeyframeType key_type,
|
||||
eInsertKeyFlags insert_key_flags);
|
||||
|
||||
/**
|
||||
* \brief Secondary Insert Key-framing API call.
|
||||
|
@ -794,14 +794,14 @@ CombinedKeyingResult insert_key_action(Main *bmain,
|
||||
return combined_result;
|
||||
}
|
||||
|
||||
CombinedKeyingResult insert_key_rna(Main *bmain,
|
||||
ID &id,
|
||||
const std::optional<std::string> channel_group,
|
||||
const blender::Span<RNAPath> rna_paths,
|
||||
const std::optional<float> scene_frame,
|
||||
const AnimationEvalContext &anim_eval_context,
|
||||
const eBezTriple_KeyframeType key_type,
|
||||
const eInsertKeyFlags insert_key_flags)
|
||||
CombinedKeyingResult insert_keyframes(Main *bmain,
|
||||
ID &id,
|
||||
const blender::Span<RNAPath> rna_paths,
|
||||
const std::optional<std::string> channel_group,
|
||||
const std::optional<float> scene_frame,
|
||||
const AnimationEvalContext &anim_eval_context,
|
||||
const eBezTriple_KeyframeType key_type,
|
||||
const eInsertKeyFlags insert_key_flags)
|
||||
|
||||
{
|
||||
PointerRNA id_pointer = RNA_id_pointer_create(&id);
|
||||
|
@ -142,11 +142,11 @@ void autokeyframe_object(bContext *C, Scene *scene, Object *ob, Span<RNAPath> rn
|
||||
|
||||
CombinedKeyingResult combined_result;
|
||||
for (PointerRNA ptr : sources) {
|
||||
const CombinedKeyingResult result = insert_key_rna(
|
||||
const CombinedKeyingResult result = insert_keyframes(
|
||||
bmain,
|
||||
*ptr.owner_id,
|
||||
std::nullopt,
|
||||
rna_paths,
|
||||
std::nullopt,
|
||||
scene_frame,
|
||||
anim_eval_context,
|
||||
eBezTriple_KeyframeType(scene->toolsettings->keyframe_type),
|
||||
@ -246,11 +246,11 @@ void autokeyframe_pose_channel(bContext *C,
|
||||
|
||||
CombinedKeyingResult combined_result;
|
||||
for (PointerRNA &ptr : sources) {
|
||||
const CombinedKeyingResult result = insert_key_rna(
|
||||
const CombinedKeyingResult result = insert_keyframes(
|
||||
bmain,
|
||||
*ptr.owner_id,
|
||||
std::nullopt,
|
||||
rna_paths,
|
||||
std::nullopt,
|
||||
scene_frame,
|
||||
anim_eval_context,
|
||||
eBezTriple_KeyframeType(scene->toolsettings->keyframe_type),
|
||||
@ -335,14 +335,14 @@ bool autokeyframe_property(bContext *C,
|
||||
* all elements" or "not an array property". */
|
||||
const std::optional<int> array_index = rnaindex < 0 ? std::nullopt : std::optional(rnaindex);
|
||||
|
||||
CombinedKeyingResult result = insert_key_rna(bmain,
|
||||
*id,
|
||||
(fcu && fcu->grp) ? fcu->grp->name : nullptr,
|
||||
{{path, {}, array_index}},
|
||||
std::nullopt,
|
||||
anim_eval_context,
|
||||
eBezTriple_KeyframeType(ts->keyframe_type),
|
||||
flag);
|
||||
CombinedKeyingResult result = insert_keyframes(bmain,
|
||||
*id,
|
||||
{{path, {}, array_index}},
|
||||
(fcu && fcu->grp) ? fcu->grp->name : nullptr,
|
||||
std::nullopt,
|
||||
anim_eval_context,
|
||||
eBezTriple_KeyframeType(ts->keyframe_type),
|
||||
flag);
|
||||
changed = result.get_count(SingleKeyingResult::SUCCESS) != 0;
|
||||
WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, nullptr);
|
||||
}
|
||||
|
@ -402,14 +402,14 @@ static int insert_key(bContext *C, wmOperator *op)
|
||||
}
|
||||
Vector<RNAPath> rna_paths = construct_rna_paths(&id_ptr);
|
||||
|
||||
combined_result.merge(animrig::insert_key_rna(bmain,
|
||||
*selected_id,
|
||||
std::nullopt,
|
||||
rna_paths.as_span(),
|
||||
scene_frame,
|
||||
anim_eval_context,
|
||||
key_type,
|
||||
insert_key_flags));
|
||||
combined_result.merge(animrig::insert_keyframes(bmain,
|
||||
*selected_id,
|
||||
rna_paths.as_span(),
|
||||
std::nullopt,
|
||||
scene_frame,
|
||||
anim_eval_context,
|
||||
key_type,
|
||||
insert_key_flags));
|
||||
}
|
||||
|
||||
if (combined_result.get_count(animrig::SingleKeyingResult::SUCCESS) == 0) {
|
||||
@ -1026,7 +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);
|
||||
const char *group = nullptr;
|
||||
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
|
||||
@ -1054,14 +1054,14 @@ static int insert_key_button_exec(bContext *C, wmOperator *op)
|
||||
const std::optional<int> array_index = (all || index < 0) ? std::nullopt :
|
||||
std::optional(index);
|
||||
|
||||
CombinedKeyingResult result = insert_key_rna(bmain,
|
||||
*ptr.owner_id,
|
||||
group,
|
||||
{{*path, {}, array_index}},
|
||||
std::nullopt,
|
||||
anim_eval_context,
|
||||
eBezTriple_KeyframeType(ts->keyframe_type),
|
||||
flag);
|
||||
CombinedKeyingResult result = insert_keyframes(bmain,
|
||||
*ptr.owner_id,
|
||||
{{*path, {}, array_index}},
|
||||
group,
|
||||
std::nullopt,
|
||||
anim_eval_context,
|
||||
eBezTriple_KeyframeType(ts->keyframe_type),
|
||||
flag);
|
||||
changed = result.get_count(SingleKeyingResult::SUCCESS) != 0;
|
||||
}
|
||||
else {
|
||||
|
@ -1083,14 +1083,15 @@ static int insert_key_to_keying_set_path(bContext *C,
|
||||
for (; array_index < array_length; array_index++) {
|
||||
if (mode == ModifyKeyMode::INSERT) {
|
||||
BLI_assert(array_index >= 0);
|
||||
CombinedKeyingResult result = insert_key_rna(bmain,
|
||||
*keyingset_path->id,
|
||||
groupname,
|
||||
{{keyingset_path->rna_path, {}, array_index}},
|
||||
std::nullopt,
|
||||
anim_eval_context,
|
||||
keytype,
|
||||
path_insert_key_flags);
|
||||
CombinedKeyingResult result = insert_keyframes(bmain,
|
||||
*keyingset_path->id,
|
||||
{{keyingset_path->rna_path, {}, array_index}},
|
||||
groupname ? std::optional(groupname) :
|
||||
nathanvegdahl marked this conversation as resolved
Outdated
|
||||
std::nullopt,
|
||||
std::nullopt,
|
||||
anim_eval_context,
|
||||
keytype,
|
||||
path_insert_key_flags);
|
||||
keyed_channels += result.get_count(SingleKeyingResult::SUCCESS);
|
||||
combined_result.merge(result);
|
||||
}
|
||||
|
@ -851,15 +851,15 @@ static void insert_fcurve_key(bAnimContext *ac,
|
||||
* (TODO: add the full-blown PointerRNA relative parsing case here...)
|
||||
*/
|
||||
if (ale->id && !ale->owner) {
|
||||
CombinedKeyingResult result = insert_key_rna(ac->bmain,
|
||||
*ale->id,
|
||||
fcu->grp ? std::optional(fcu->grp->name) :
|
||||
std::nullopt,
|
||||
{{fcu->rna_path, {}, fcu->array_index}},
|
||||
std::nullopt,
|
||||
anim_eval_context,
|
||||
eBezTriple_KeyframeType(ts->keyframe_type),
|
||||
flag);
|
||||
CombinedKeyingResult result = insert_keyframes(ac->bmain,
|
||||
*ale->id,
|
||||
{{fcu->rna_path, {}, fcu->array_index}},
|
||||
fcu->grp ? std::optional(fcu->grp->name) :
|
||||
std::nullopt,
|
||||
std::nullopt,
|
||||
anim_eval_context,
|
||||
eBezTriple_KeyframeType(ts->keyframe_type),
|
||||
flag);
|
||||
if (result.get_count(SingleKeyingResult::SUCCESS) == 0) {
|
||||
result.generate_reports(reports);
|
||||
}
|
||||
|
@ -206,15 +206,15 @@ static void insert_graph_keys(bAnimContext *ac, eGraphKeys_InsertKey_Types mode)
|
||||
* up adding the keyframes on a new F-Curve in the action data instead.
|
||||
*/
|
||||
if (ale->id && !ale->owner && !fcu->driver) {
|
||||
CombinedKeyingResult result = insert_key_rna(ac->bmain,
|
||||
*ale->id,
|
||||
fcu->grp ? std::optional(fcu->grp->name) :
|
||||
std::nullopt,
|
||||
{{fcu->rna_path, {}, fcu->array_index}},
|
||||
std::nullopt,
|
||||
anim_eval_context,
|
||||
eBezTriple_KeyframeType(ts->keyframe_type),
|
||||
flag);
|
||||
CombinedKeyingResult result = insert_keyframes(ac->bmain,
|
||||
*ale->id,
|
||||
{{fcu->rna_path, {}, fcu->array_index}},
|
||||
fcu->grp ? std::optional(fcu->grp->name) :
|
||||
std::nullopt,
|
||||
std::nullopt,
|
||||
anim_eval_context,
|
||||
eBezTriple_KeyframeType(ts->keyframe_type),
|
||||
flag);
|
||||
if (result.get_count(SingleKeyingResult::SUCCESS) == 0) {
|
||||
result.generate_reports(reports);
|
||||
}
|
||||
|
@ -405,15 +405,15 @@ PyObject *pyrna_struct_keyframe_insert(BPy_StructRNA *self, PyObject *args, PyOb
|
||||
ID *id = self->ptr.owner_id;
|
||||
|
||||
BLI_assert(BKE_id_is_in_global_main(id));
|
||||
CombinedKeyingResult combined_result = insert_key_rna(G_MAIN,
|
||||
*id,
|
||||
group_name ? std::optional(group_name) :
|
||||
std::nullopt,
|
||||
{{path_full, {}, index}},
|
||||
std::nullopt,
|
||||
anim_eval_context,
|
||||
eBezTriple_KeyframeType(keytype),
|
||||
eInsertKeyFlags(options));
|
||||
CombinedKeyingResult combined_result = insert_keyframes(
|
||||
G_MAIN,
|
||||
*id,
|
||||
{{path_full, {}, index}},
|
||||
group_name ? std::optional(group_name) : std::nullopt,
|
||||
std::nullopt,
|
||||
anim_eval_context,
|
||||
eBezTriple_KeyframeType(keytype),
|
||||
eInsertKeyFlags(options));
|
||||
const int success_count = combined_result.get_count(SingleKeyingResult::SUCCESS);
|
||||
if (success_count == 0) {
|
||||
combined_result.generate_reports(&reports);
|
||||
|
Loading…
Reference in New Issue
Block a user
might just be me but I find it easier to read if such things are outside the function arguments.