From 40f8ddf8297a062968fc6a1523aa210d69c22626 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 26 Mar 2019 18:47:55 +1100 Subject: 3D View: move deselect all logic into an option This removes `VIEW3D_OT_select_or_deselect_all`, adding a deselect_all option to the `VIEW3D_OT_select` operator. - Add utility functions to simplify de-selecting all. - Return true from selection functions when they change the selection to avoid redundant updates. - Use arrays of bases when passing objects between selection utility functions since some users require bases. - Fix logical error in box selection that updated all objects after the first hit. --- .../blender/editors/lattice/editlattice_select.c | 66 +++++++++++++++++----- 1 file changed, 53 insertions(+), 13 deletions(-) (limited to 'source/blender/editors/lattice') diff --git a/source/blender/editors/lattice/editlattice_select.c b/source/blender/editors/lattice/editlattice_select.c index 2c7f084fe17..a92ed02c483 100644 --- a/source/blender/editors/lattice/editlattice_select.c +++ b/source/blender/editors/lattice/editlattice_select.c @@ -75,6 +75,29 @@ static void bpoint_select_set(BPoint *bp, bool select) } } +bool ED_lattice_deselect_all_multi_ex(struct Base **bases, const uint bases_len) +{ + bool changed_multi = false; + for (uint base_index = 0; base_index < bases_len; base_index++) { + Base *base_iter = bases[base_index]; + Object *ob_iter = base_iter->object; + changed_multi |= ED_lattice_flags_set(ob_iter, 0); + DEG_id_tag_update(ob_iter->data, ID_RECALC_SELECT); + } + return changed_multi; +} + +bool ED_lattice_deselect_all_multi(struct bContext *C) +{ + ViewContext vc; + ED_view3d_viewcontext_init(C, &vc); + uint bases_len = 0; + Base **bases = BKE_view_layer_array_from_bases_in_edit_mode_unique_data(vc.view_layer, vc.v3d, &bases_len); + bool changed_multi = ED_lattice_deselect_all_multi_ex(bases, bases_len); + MEM_freeN(bases); + return changed_multi; +} + /** \} */ /* -------------------------------------------------------------------- */ @@ -356,23 +379,32 @@ void LATTICE_OT_select_less(wmOperatorType *ot) /** \name Select All Operator * \{ */ -void ED_lattice_flags_set(Object *obedit, int flag) +bool ED_lattice_flags_set(Object *obedit, int flag) { Lattice *lt = obedit->data; BPoint *bp; int a; + bool changed = false; bp = lt->editlatt->latt->def; a = lt->editlatt->latt->pntsu * lt->editlatt->latt->pntsv * lt->editlatt->latt->pntsw; - lt->editlatt->latt->actbp = LT_ACTBP_NONE; + + if (lt->editlatt->latt->actbp != LT_ACTBP_NONE) { + lt->editlatt->latt->actbp = LT_ACTBP_NONE; + changed = true; + } while (a--) { if (bp->hide == 0) { - bp->f1 = flag; + if (bp->f1 != flag) { + bp->f1 = flag; + changed = true; + } } bp++; } + return changed; } static int lattice_select_all_exec(bContext *C, wmOperator *op) @@ -395,18 +427,20 @@ static int lattice_select_all_exec(bContext *C, wmOperator *op) } } + bool changed_multi = false; for (uint ob_index = 0; ob_index < objects_len; ob_index++) { Object *obedit = objects[ob_index]; Lattice *lt; BPoint *bp; int a; + bool changed = false; switch (action) { case SEL_SELECT: - ED_lattice_flags_set(obedit, 1); + changed = ED_lattice_flags_set(obedit, 1); break; case SEL_DESELECT: - ED_lattice_flags_set(obedit, 0); + changed = ED_lattice_flags_set(obedit, 0); break; case SEL_INVERT: lt = obedit->data; @@ -417,18 +451,24 @@ static int lattice_select_all_exec(bContext *C, wmOperator *op) while (a--) { if (bp->hide == 0) { bp->f1 ^= SELECT; + changed = true; } bp++; } break; } - DEG_id_tag_update(obedit->data, ID_RECALC_SELECT); - WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data); + if (changed) { + changed_multi = true; + DEG_id_tag_update(obedit->data, ID_RECALC_SELECT); + WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data); + } } MEM_freeN(objects); - - return OPERATOR_FINISHED; + if (changed_multi) { + return OPERATOR_FINISHED; + } + return OPERATOR_CANCELLED; } void LATTICE_OT_select_all(wmOperatorType *ot) @@ -597,10 +637,10 @@ bool ED_lattice_select_pick(bContext *C, const int mval[2], bool extend, bool de Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(vc.view_layer, vc.v3d, &objects_len); for (uint ob_index = 0; ob_index < objects_len; ob_index++) { Object *ob = objects[ob_index]; - ED_lattice_flags_set(ob, 0); - - DEG_id_tag_update(ob->data, ID_RECALC_SELECT); - WM_event_add_notifier(C, NC_GEOM | ND_SELECT, ob->data); + if (ED_lattice_flags_set(ob, 0)) { + DEG_id_tag_update(ob->data, ID_RECALC_SELECT); + WM_event_add_notifier(C, NC_GEOM | ND_SELECT, ob->data); + } } MEM_freeN(objects); } -- cgit v1.2.3