From c1d461bcbc407c69f9f9b543cf76c8ab10cc9e06 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 5 Apr 2022 12:59:19 +1000 Subject: Cleanup: avoid unnecessary undo steps for curves & simplify code Some edit-curve operators used an 'ok' variable to represent if the selection was found and if a change was made. Previously it would only return cancel if an error was shown causing a redundant undo step to be added without a selection. Since this is simple behavior that shouldn't need much explanation, use two variables with meaningful names to avoid confusion. Reviewing D14511 highlighted this issue. --- source/blender/editors/curve/editcurve.c | 41 ++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 15 deletions(-) (limited to 'source/blender/editors/curve/editcurve.c') diff --git a/source/blender/editors/curve/editcurve.c b/source/blender/editors/curve/editcurve.c index 755e538f415..9da9845116d 100644 --- a/source/blender/editors/curve/editcurve.c +++ b/source/blender/editors/curve/editcurve.c @@ -1471,7 +1471,8 @@ static int curve_split_exec(bContext *C, wmOperator *op) Main *bmain = CTX_data_main(C); ViewLayer *view_layer = CTX_data_view_layer(C); View3D *v3d = CTX_wm_view3d(C); - int ok = -1; + bool changed = false; + int count_failed = 0; uint objects_len; Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data( @@ -1489,7 +1490,7 @@ static int curve_split_exec(bContext *C, wmOperator *op) adduplicateflagNurb(obedit, v3d, &newnurb, SELECT, true); if (BLI_listbase_is_empty(&newnurb)) { - ok = MAX2(ok, 0); + count_failed += 1; continue; } @@ -1504,14 +1505,16 @@ static int curve_split_exec(bContext *C, wmOperator *op) WM_event_add_notifier(C, NC_OBJECT | ND_KEYS, obedit); } - ok = 1; + changed = true; WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data); DEG_id_tag_update(obedit->data, 0); } MEM_freeN(objects); - if (ok == 0) { - BKE_report(op->reports, RPT_ERROR, "Cannot split current selection"); + if (changed == false) { + if (count_failed != 0) { + BKE_report(op->reports, RPT_ERROR, "Cannot split current selection"); + } return OPERATOR_CANCELLED; } return OPERATOR_FINISHED; @@ -4998,7 +5001,8 @@ static int spin_exec(bContext *C, wmOperator *op) View3D *v3d = CTX_wm_view3d(C); RegionView3D *rv3d = ED_view3d_context_rv3d(C); float cent[3], axis[3], viewmat[4][4]; - int ok = -1; + bool changed = false; + int count_failed = 0; RNA_float_get_array(op->ptr, "center", cent); RNA_float_get_array(op->ptr, "axis", axis); @@ -5025,11 +5029,11 @@ static int spin_exec(bContext *C, wmOperator *op) mul_m4_v3(obedit->imat, cent); if (!ed_editnurb_spin(viewmat, v3d, obedit, axis, cent)) { - ok = MAX2(ok, 0); + count_failed += 1; continue; } - ok = 1; + changed = true; if (ED_curve_updateAnimPaths(bmain, cu)) { WM_event_add_notifier(C, NC_OBJECT | ND_KEYS, obedit); } @@ -5039,8 +5043,11 @@ static int spin_exec(bContext *C, wmOperator *op) } MEM_freeN(objects); - if (ok == 0) { - BKE_report(op->reports, RPT_ERROR, "Cannot spin"); + if (changed == false) { + if (count_failed != 0) { + BKE_report(op->reports, RPT_ERROR, "Cannot spin"); + } + return OPERATOR_CANCELLED; } return OPERATOR_FINISHED; } @@ -5889,7 +5896,9 @@ static int duplicate_exec(bContext *C, wmOperator *op) { ViewLayer *view_layer = CTX_data_view_layer(C); View3D *v3d = CTX_wm_view3d(C); - int ok = -1; + + bool changed = false; + int count_failed = 0; uint objects_len = 0; Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data( @@ -5906,19 +5915,21 @@ static int duplicate_exec(bContext *C, wmOperator *op) adduplicateflagNurb(obedit, v3d, &newnurb, SELECT, false); if (BLI_listbase_is_empty(&newnurb)) { - ok = MAX2(ok, 0); + count_failed += 1; continue; } - ok = 1; + changed = true; BLI_movelisttolist(object_editcurve_get(obedit), &newnurb); DEG_id_tag_update(&cu->id, ID_RECALC_SELECT); WM_event_add_notifier(C, NC_GEOM | ND_SELECT, &cu->id); } MEM_freeN(objects); - if (ok == 0) { - BKE_report(op->reports, RPT_ERROR, "Cannot duplicate current selection"); + if (changed == false) { + if (count_failed != 0) { + BKE_report(op->reports, RPT_ERROR, "Cannot duplicate current selection"); + } return OPERATOR_CANCELLED; } return OPERATOR_FINISHED; -- cgit v1.2.3