diff options
Diffstat (limited to 'source/blender/editors/curve/editcurve.c')
-rw-r--r-- | source/blender/editors/curve/editcurve.c | 189 |
1 files changed, 103 insertions, 86 deletions
diff --git a/source/blender/editors/curve/editcurve.c b/source/blender/editors/curve/editcurve.c index 2dcddd01670..1c1783669c3 100644 --- a/source/blender/editors/curve/editcurve.c +++ b/source/blender/editors/curve/editcurve.c @@ -44,6 +44,7 @@ #include "ED_object.h" #include "ED_outliner.h" #include "ED_screen.h" +#include "ED_select_utils.h" #include "ED_transform.h" #include "ED_transform_snap_object_context.h" #include "ED_types.h" @@ -4722,8 +4723,9 @@ void CURVE_OT_make_segment(wmOperatorType *ot) /** \name Pick Select from 3D View * \{ */ -bool ED_curve_editnurb_select_pick( - bContext *C, const int mval[2], bool extend, bool deselect, bool toggle) +bool ED_curve_editnurb_select_pick(bContext *C, + const int mval[2], + const struct SelectPick_Params *params) { Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); ViewContext vc; @@ -4732,129 +4734,144 @@ bool ED_curve_editnurb_select_pick( BPoint *bp = NULL; Base *basact = NULL; short hand; + bool changed = false; view3d_operator_needs_opengl(C); ED_view3d_viewcontext_init(C, &vc, depsgraph); copy_v2_v2_int(vc.mval, mval); - if (ED_curve_pick_vert(&vc, 1, &nu, &bezt, &bp, &hand, &basact)) { - Object *obedit = basact->object; - Curve *cu = obedit->data; - ListBase *editnurb = object_editcurve_get(obedit); - const void *vert = BKE_curve_vert_active_get(cu); + const bool found = ED_curve_pick_vert(&vc, 1, &nu, &bezt, &bp, &hand, &basact); - if (!extend && !deselect && !toggle) { - uint objects_len = 0; - 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_iter = objects[ob_index]; + if ((params->sel_op == SEL_OP_SET) && (found || params->deselect_all)) { + /* Deselect everything. */ + uint objects_len = 0; + 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_iter = objects[ob_index]; - ED_curve_deselect_all(((Curve *)ob_iter->data)->editnurb); + ED_curve_deselect_all(((Curve *)ob_iter->data)->editnurb); - DEG_id_tag_update(ob_iter->data, ID_RECALC_SELECT | ID_RECALC_COPY_ON_WRITE); - WM_event_add_notifier(C, NC_GEOM | ND_SELECT, ob_iter->data); - } - MEM_freeN(objects); + DEG_id_tag_update(ob_iter->data, ID_RECALC_SELECT | ID_RECALC_COPY_ON_WRITE); + WM_event_add_notifier(C, NC_GEOM | ND_SELECT, ob_iter->data); } + MEM_freeN(objects); + changed = true; + } - if (extend) { - if (bezt) { - if (hand == 1) { - select_beztriple(bezt, SELECT, SELECT, HIDDEN); - } - else { - if (hand == 0) { - bezt->f1 |= SELECT; + if (found) { + Object *obedit = basact->object; + Curve *cu = obedit->data; + ListBase *editnurb = object_editcurve_get(obedit); + const void *vert = BKE_curve_vert_active_get(cu); + + switch (params->sel_op) { + case SEL_OP_ADD: { + if (bezt) { + if (hand == 1) { + select_beztriple(bezt, SELECT, SELECT, HIDDEN); } else { - bezt->f3 |= SELECT; - } - } - BKE_curve_nurb_vert_active_set(cu, nu, bezt); - } - else { - select_bpoint(bp, SELECT, SELECT, HIDDEN); - BKE_curve_nurb_vert_active_set(cu, nu, bp); - } - } - else if (deselect) { - if (bezt) { - if (hand == 1) { - select_beztriple(bezt, DESELECT, SELECT, HIDDEN); - if (bezt == vert) { - cu->actvert = CU_ACT_NONE; + if (hand == 0) { + bezt->f1 |= SELECT; + } + else { + bezt->f3 |= SELECT; + } } - } - else if (hand == 0) { - bezt->f1 &= ~SELECT; + BKE_curve_nurb_vert_active_set(cu, nu, bezt); } else { - bezt->f3 &= ~SELECT; - } - } - else { - select_bpoint(bp, DESELECT, SELECT, HIDDEN); - if (bp == vert) { - cu->actvert = CU_ACT_NONE; + select_bpoint(bp, SELECT, SELECT, HIDDEN); + BKE_curve_nurb_vert_active_set(cu, nu, bp); } + break; } - } - else if (toggle) { - if (bezt) { - if (hand == 1) { - if (bezt->f2 & SELECT) { + case SEL_OP_SUB: { + if (bezt) { + if (hand == 1) { select_beztriple(bezt, DESELECT, SELECT, HIDDEN); if (bezt == vert) { cu->actvert = CU_ACT_NONE; } } + else if (hand == 0) { + bezt->f1 &= ~SELECT; + } else { - select_beztriple(bezt, SELECT, SELECT, HIDDEN); - BKE_curve_nurb_vert_active_set(cu, nu, bezt); + bezt->f3 &= ~SELECT; } } - else if (hand == 0) { - bezt->f1 ^= SELECT; - } else { - bezt->f3 ^= SELECT; - } - } - else { - if (bp->f1 & SELECT) { select_bpoint(bp, DESELECT, SELECT, HIDDEN); if (bp == vert) { cu->actvert = CU_ACT_NONE; } } + break; + } + case SEL_OP_XOR: { + if (bezt) { + if (hand == 1) { + if (bezt->f2 & SELECT) { + select_beztriple(bezt, DESELECT, SELECT, HIDDEN); + if (bezt == vert) { + cu->actvert = CU_ACT_NONE; + } + } + else { + select_beztriple(bezt, SELECT, SELECT, HIDDEN); + BKE_curve_nurb_vert_active_set(cu, nu, bezt); + } + } + else if (hand == 0) { + bezt->f1 ^= SELECT; + } + else { + bezt->f3 ^= SELECT; + } + } else { - select_bpoint(bp, SELECT, SELECT, HIDDEN); - BKE_curve_nurb_vert_active_set(cu, nu, bp); + if (bp->f1 & SELECT) { + select_bpoint(bp, DESELECT, SELECT, HIDDEN); + if (bp == vert) { + cu->actvert = CU_ACT_NONE; + } + } + else { + select_bpoint(bp, SELECT, SELECT, HIDDEN); + BKE_curve_nurb_vert_active_set(cu, nu, bp); + } } + break; } - } - else { - BKE_nurbList_flag_set(editnurb, SELECT, false); + case SEL_OP_SET: { + BKE_nurbList_flag_set(editnurb, SELECT, false); - if (bezt) { + if (bezt) { - if (hand == 1) { - select_beztriple(bezt, SELECT, SELECT, HIDDEN); - } - else { - if (hand == 0) { - bezt->f1 |= SELECT; + if (hand == 1) { + select_beztriple(bezt, SELECT, SELECT, HIDDEN); } else { - bezt->f3 |= SELECT; + if (hand == 0) { + bezt->f1 |= SELECT; + } + else { + bezt->f3 |= SELECT; + } } + BKE_curve_nurb_vert_active_set(cu, nu, bezt); + } + else { + select_bpoint(bp, SELECT, SELECT, HIDDEN); + BKE_curve_nurb_vert_active_set(cu, nu, bp); } - BKE_curve_nurb_vert_active_set(cu, nu, bezt); + break; } - else { - select_bpoint(bp, SELECT, SELECT, HIDDEN); - BKE_curve_nurb_vert_active_set(cu, nu, bp); + case SEL_OP_AND: { + BLI_assert_unreachable(); /* Doesn't make sense for picking. */ + break; } } @@ -4876,10 +4893,10 @@ bool ED_curve_editnurb_select_pick( DEG_id_tag_update(obedit->data, ID_RECALC_SELECT | ID_RECALC_COPY_ON_WRITE); WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data); - return true; + changed = true; } - return false; + return changed || found; } /** \} */ |