Refactor: delete_keyframe function arguments

No functional changes intended.

This simplifies the arguments for the `delete_keyframe` function.
The `bAction *` was always a `nullptr` so I just removed it.
The rna path char array and the array index were merged into the `RNAPath` struct.

Pull Request: https://projects.blender.org/blender/blender/pulls/125479
This commit is contained in:
Christoph Lendenfeld
2024-07-26 13:29:25 +02:00
committed by Christoph Lendenfeld
parent 2bf5a12e3b
commit ebd123c90b
5 changed files with 27 additions and 43 deletions

View File

@@ -189,13 +189,7 @@ bool insert_keyframe_direct(ReportList *reports,
* Will perform checks just in case.
* \return The number of key-frames deleted.
*/
int delete_keyframe(Main *bmain,
ReportList *reports,
ID *id,
bAction *act,
const char rna_path[],
int array_index,
float cfra);
int delete_keyframe(Main *bmain, ReportList *reports, ID *id, const RNAPath &path, float cfra);
/**
* Main Keyframing API call:

View File

@@ -627,15 +627,8 @@ static void deg_tag_after_keyframe_delete(Main *bmain, ID *id, AnimData *adt)
}
}
int delete_keyframe(Main *bmain,
ReportList *reports,
ID *id,
bAction *act,
const char rna_path[],
int array_index,
float cfra)
int delete_keyframe(Main *bmain, ReportList *reports, ID *id, const RNAPath &rna_path, float cfra)
{
BLI_assert(rna_path != nullptr);
AnimData *adt = BKE_animdata_from_id(id);
if (ELEM(nullptr, id, adt)) {
@@ -646,33 +639,27 @@ int delete_keyframe(Main *bmain,
PointerRNA ptr;
PropertyRNA *prop;
PointerRNA id_ptr = RNA_id_pointer_create(id);
if (RNA_path_resolve_property(&id_ptr, rna_path, &ptr, &prop) == false) {
if (RNA_path_resolve_property(&id_ptr, rna_path.path.c_str(), &ptr, &prop) == false) {
BKE_reportf(
reports,
RPT_ERROR,
"Could not delete keyframe, as RNA path is invalid for the given ID (ID = %s, path = %s)",
id->name,
rna_path);
rna_path.path.c_str());
return 0;
}
if (act == nullptr) {
if (adt->action) {
act = adt->action;
cfra = BKE_nla_tweakedit_remap(adt, cfra, NLATIME_CONVERT_UNMAP);
}
else {
BKE_reportf(reports, RPT_ERROR, "No action to delete keyframes from for ID = %s", id->name);
return 0;
}
if (!adt->action) {
BKE_reportf(reports, RPT_ERROR, "No action to delete keyframes from for ID = %s", id->name);
return 0;
}
bAction *act = adt->action;
cfra = BKE_nla_tweakedit_remap(adt, cfra, NLATIME_CONVERT_UNMAP);
int array_index = rna_path.index.value_or(0);
int array_index_max = array_index + 1;
if (array_index == -1) {
array_index = 0;
if (!rna_path.index.has_value()) {
array_index_max = RNA_property_array_length(&ptr, prop);
/* For single properties, increase max_index so that the property itself gets included,
* but don't do this for standard arrays since that can cause corruption issues
* (extra unused curves).
@@ -695,7 +682,7 @@ int delete_keyframe(Main *bmain,
* paths. In the future when legacy actions are removed, we can restructure
* it to be clearer. */
for (; array_index < array_index_max; array_index++) {
FCurve *fcurve = fcurve_find(fcurves, {rna_path, array_index});
FCurve *fcurve = fcurve_find(fcurves, {rna_path.path, array_index});
if (fcurve == nullptr) {
continue;
}
@@ -708,7 +695,7 @@ int delete_keyframe(Main *bmain,
/* Will only loop once unless the array index was -1. */
int key_count = 0;
for (; array_index < array_index_max; array_index++) {
FCurve *fcu = action_fcurve_find(act, {rna_path, array_index});
FCurve *fcu = action_fcurve_find(act, {rna_path.path, array_index});
if (fcu == nullptr) {
continue;

View File

@@ -1205,13 +1205,14 @@ static int delete_key_button_exec(bContext *C, wmOperator *op)
else {
/* standard properties */
if (const std::optional<std::string> path = RNA_path_from_ID_to_property(&ptr, prop)) {
RNAPath rna_path = {path->c_str(), std::nullopt, index};
if (all) {
/* -1 indicates operating on the entire array (or the property itself otherwise) */
index = -1;
/* nullopt indicates operating on the entire array (or the property itself otherwise). */
rna_path.index = std::nullopt;
}
changed = blender::animrig::delete_keyframe(
bmain, op->reports, ptr.owner_id, nullptr, path->c_str(), index, cfra) != 0;
bmain, op->reports, ptr.owner_id, rna_path, cfra) != 0;
}
else if (G.debug & G_DEBUG) {
printf("Button Delete-Key: no path to property\n");

View File

@@ -1102,13 +1102,11 @@ static int insert_key_to_keying_set_path(bContext *C,
combined_result.merge(result);
}
else if (mode == ModifyKeyMode::DELETE) {
keyed_channels += delete_keyframe(bmain,
reports,
keyingset_path->id,
nullptr,
keyingset_path->rna_path,
array_index,
frame);
RNAPath rna_path = {keyingset_path->rna_path, std::nullopt, array_index};
if (array_index < 0) {
rna_path.index = std::nullopt;
}
keyed_channels += delete_keyframe(bmain, reports, keyingset_path->id, rna_path, frame);
}
}

View File

@@ -551,8 +551,12 @@ PyObject *pyrna_struct_keyframe_delete(BPy_StructRNA *self, PyObject *args, PyOb
}
}
else {
RNAPath rna_path = {path_full, std::nullopt, index};
if (index < 0) {
rna_path.index = std::nullopt;
}
result = (blender::animrig::delete_keyframe(
G.main, &reports, self->ptr.owner_id, nullptr, path_full, index, cfra) != 0);
G.main, &reports, self->ptr.owner_id, rna_path, cfra) != 0);
}
MEM_freeN((void *)path_full);