Cleanup: Extract function to store bezt arrays

The code to store an original bezt array previously lived in
`graphkeys_decimate_invoke`.
Since future graph slider operators will need this function as well,
it has been extracted.

No functional changes.

Reviewed by: Sybren A. Stüvel
Differential Revision: https://developer.blender.org/D12487
Ref: D12487
This commit is contained in:
Christoph Lendenfeld 2021-10-31 11:28:10 +00:00
parent 1b6daa871d
commit b2e9f35c5e
Notes: blender-bot 2024-04-29 13:07:32 +02:00
Referenced by issue #81785, Implementation: Modal Key Manipulation Operators
1 changed files with 44 additions and 40 deletions

View File

@ -58,6 +58,48 @@
* operators are modal and use a slider that allows the user to define a percentage to modify the
* operator. */
/* ******************** Utility Functions ************************* */
/* Construct a list with the original bezt arrays so we can restore them during modal operation.
* The data is stored on the struct that is passed.*/
static void store_original_bezt_arrays(tDecimateGraphOp *dgo)
{
ListBase anim_data = {NULL, NULL};
bAnimContext *ac = &dgo->ac;
bAnimListElem *ale;
ANIM_animdata_filter(ac, &anim_data, OPERATOR_DATA_FILTER, ac->data, ac->datatype);
/* Loop through filtered data and copy the curves. */
for (ale = anim_data.first; ale; ale = ale->next) {
FCurve *fcu = (FCurve *)ale->key_data;
if (fcu->bezt == NULL) {
/* This curve is baked, skip it. */
continue;
}
const int arr_size = sizeof(BezTriple) * fcu->totvert;
tBeztCopyData *copy = MEM_mallocN(sizeof(tBeztCopyData), "bezts_copy");
BezTriple *bezts_copy = MEM_mallocN(arr_size, "bezts_copy_array");
copy->tot_vert = fcu->totvert;
memcpy(bezts_copy, fcu->bezt, arr_size);
copy->bezt = bezts_copy;
LinkData *link = NULL;
link = MEM_callocN(sizeof(LinkData), "Bezt Link");
link->data = copy;
BLI_addtail(&dgo->bezt_arr_list, link);
}
ANIM_animdata_freelist(&anim_data);
}
/* ******************** Decimate Keyframes Operator ************************* */
static void decimate_graph_keys(bAnimContext *ac, float remove_ratio, float error_sq_max)
@ -228,52 +270,14 @@ static int graphkeys_decimate_invoke(bContext *C, wmOperator *op, const wmEvent
dgo->area = CTX_wm_area(C);
dgo->region = CTX_wm_region(C);
store_original_bezt_arrays(dgo);
dgo->slider = ED_slider_create(C);
ED_slider_init(dgo->slider, event);
ED_slider_allow_overshoot_set(dgo->slider, false);
decimate_draw_status(C, dgo);
/* Construct a list with the original bezt arrays so we can restore them during modal operation.
*/
{
ListBase anim_data = {NULL, NULL};
bAnimContext *ac = &dgo->ac;
bAnimListElem *ale;
/* Filter data. */
ANIM_animdata_filter(ac, &anim_data, OPERATOR_DATA_FILTER, ac->data, ac->datatype);
/* Loop through filtered data and copy the curves. */
for (ale = anim_data.first; ale; ale = ale->next) {
FCurve *fcu = (FCurve *)ale->key_data;
if (fcu->bezt == NULL) {
/* This curve is baked, skip it. */
continue;
}
const int arr_size = sizeof(BezTriple) * fcu->totvert;
tBeztCopyData *copy = MEM_mallocN(sizeof(tBeztCopyData), "bezts_copy");
BezTriple *bezts_copy = MEM_mallocN(arr_size, "bezts_copy_array");
copy->tot_vert = fcu->totvert;
memcpy(bezts_copy, fcu->bezt, arr_size);
copy->bezt = bezts_copy;
LinkData *link = NULL;
link = MEM_callocN(sizeof(LinkData), "Bezt Link");
link->data = copy;
BLI_addtail(&dgo->bezt_arr_list, link);
}
ANIM_animdata_freelist(&anim_data);
}
if (dgo->bezt_arr_list.first == NULL) {
WM_report(RPT_WARNING,
"Fcurve Decimate: Can't decimate baked channels. Unbake them and try again.");