From e79d7747d21f3d3079c759abe0f20a7904aded80 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 13 Dec 2018 13:04:25 +1100 Subject: Cleanup: use doxy grouping for view3d select Easier to navigate, avoid mixing up functionality across the file. --- .../blender/editors/space_view3d/view3d_select.c | 390 +++++++++++---------- 1 file changed, 203 insertions(+), 187 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c index b2fbdbad31c..c740fa7814e 100644 --- a/source/blender/editors/space_view3d/view3d_select.c +++ b/source/blender/editors/space_view3d/view3d_select.c @@ -110,6 +110,11 @@ // #include "PIL_time_utildefines.h" + +/* -------------------------------------------------------------------- */ +/** \name Public Utilities + * \{ */ + float ED_view3d_select_dist_px(void) { return 75.0f * U.pixelsize; @@ -147,9 +152,33 @@ void ED_view3d_viewcontext_init_object(ViewContext *vc, Object *obact) } } -/* ********************** view3d_select: selection manipulations ********************* */ +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Internal Utilities + * \{ */ + +static void object_deselect_all_visible(ViewLayer *view_layer, View3D *v3d) +{ + Base *base; + + for (base = view_layer->object_bases.first; base; base = base->next) { + if (BASE_SELECTABLE(v3d, base)) { + ED_object_base_select(base, BA_DESELECT); + } + } +} -/* local prototypes */ +static void object_deselect_all_except(ViewLayer *view_layer, Base *b) /* deselect all except b */ +{ + for (Base *base = view_layer->object_bases.first; base; base = base->next) { + if (base->flag & BASE_SELECTED) { + if (b != base) { + ED_object_base_select(base, BA_DESELECT); + } + } + } +} static void edbm_backbuf_check_and_select_verts(BMEditMesh *em, const eSelectOp sel_op) { @@ -248,7 +277,11 @@ static void edbm_backbuf_check_and_select_tfaces(Mesh *me, const eSelectOp sel_o } } -/* *********************** GESTURE AND LASSO ******************* */ +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Lasso Select + * \{ */ typedef struct LassoSelectUserData { ViewContext *vc; @@ -405,17 +438,6 @@ static void do_lasso_tag_pose(ViewContext *vc, Object *ob, const int mcords[][2] pose_foreachScreenBone(&vc_tmp, do_lasso_select_pose__do_tag, &data, V3D_PROJ_TEST_CLIP_DEFAULT); } -static void object_deselect_all_visible(ViewLayer *view_layer, View3D *v3d) -{ - Base *base; - - for (base = view_layer->object_bases.first; base; base = base->next) { - if (BASE_SELECTABLE(v3d, base)) { - ED_object_base_select(base, BA_DESELECT); - } - } -} - static void do_lasso_select_objects( ViewContext *vc, const int mcords[][2], const short moves, const eSelectOp sel_op) @@ -1077,7 +1099,11 @@ void VIEW3D_OT_select_lasso(wmOperatorType *ot) WM_operator_properties_select_operation(ot); } -/* ************************** mouse select ************************* */ +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Cursor Picking + * \{ */ /* The max number of menu items in an object select menu */ typedef struct SelMenuItemF { @@ -1184,17 +1210,6 @@ void VIEW3D_OT_select_menu(wmOperatorType *ot) RNA_def_boolean(ot->srna, "toggle", 0, "Toggle", "Toggle selection instead of deselecting everything first"); } -static void deselectall_except(ViewLayer *view_layer, Base *b) /* deselect all except b */ -{ - for (Base *base = view_layer->object_bases.first; base; base = base->next) { - if (base->flag & BASE_SELECTED) { - if (b != base) { - ED_object_base_select(base, BA_DESELECT); - } - } - } -} - static Base *object_mouse_select_menu( bContext *C, ViewContext *vc, unsigned int *buffer, int hits, const int mval[2], bool toggle) @@ -1797,7 +1812,7 @@ static bool ed_object_select_pick( if (vc.obedit) { /* only do select */ - deselectall_except(view_layer, basact); + object_deselect_all_except(view_layer, basact); ED_object_base_select(basact, BA_SELECT); } /* also prevent making it active on mouse selection */ @@ -1821,7 +1836,7 @@ static bool ed_object_select_pick( else { /* When enabled, this puts other objects out of multi pose-mode. */ if (is_pose_mode == false) { - deselectall_except(view_layer, basact); + object_deselect_all_except(view_layer, basact); ED_object_base_select(basact, BA_SELECT); } } @@ -1860,7 +1875,160 @@ static bool ed_object_select_pick( return retval; } -/* ******************** border and circle ************************************** */ +/* mouse selection in weight paint */ +/* gets called via generic mouse select operator */ +static bool ed_wpaint_vertex_select_pick( + bContext *C, const int mval[2], + bool extend, bool deselect, bool toggle, Object *obact) +{ + View3D *v3d = CTX_wm_view3d(C); + const bool use_zbuf = V3D_IS_ZBUF(v3d); + + Mesh *me = obact->data; /* already checked for NULL */ + unsigned int index = 0; + MVert *mv; + + if (ED_mesh_pick_vert(C, obact, mval, &index, ED_MESH_PICK_DEFAULT_VERT_SIZE, use_zbuf)) { + mv = &me->mvert[index]; + if (extend) { + mv->flag |= SELECT; + } + else if (deselect) { + mv->flag &= ~SELECT; + } + else if (toggle) { + mv->flag ^= SELECT; + } + else { + paintvert_deselect_all_visible(obact, SEL_DESELECT, false); + mv->flag |= SELECT; + } + + /* update mselect */ + if (mv->flag & SELECT) { + BKE_mesh_mselect_active_set(me, index, ME_VSEL); + } + else { + BKE_mesh_mselect_validate(me); + } + + paintvert_flush_flags(obact); + paintvert_tag_select_update(C, obact); + return true; + } + return false; +} + +static int view3d_select_exec(bContext *C, wmOperator *op) +{ + Object *obedit = CTX_data_edit_object(C); + Object *obact = CTX_data_active_object(C); + bool extend = RNA_boolean_get(op->ptr, "extend"); + bool deselect = RNA_boolean_get(op->ptr, "deselect"); + bool toggle = RNA_boolean_get(op->ptr, "toggle"); + bool center = RNA_boolean_get(op->ptr, "center"); + bool enumerate = RNA_boolean_get(op->ptr, "enumerate"); + /* only force object select for editmode to support vertex parenting, + * or paint-select to allow pose bone select with vert/face select */ + bool object = (RNA_boolean_get(op->ptr, "object") && + (obedit || + BKE_paint_select_elem_test(obact) || + /* so its possible to select bones in weightpaint mode (LMB select) */ + (obact && (obact->mode & OB_MODE_WEIGHT_PAINT) && BKE_object_pose_armature_get(obact)))); + + bool retval = false; + int location[2]; + + RNA_int_get_array(op->ptr, "location", location); + + view3d_operator_needs_opengl(C); + + if (object) { + obedit = NULL; + obact = NULL; + + /* ack, this is incorrect but to do this correctly we would need an + * alternative editmode/objectmode keymap, this copies the functionality + * from 2.4x where Ctrl+Select in editmode does object select only */ + center = false; + } + + if (obedit && object == false) { + if (obedit->type == OB_MESH) + retval = EDBM_select_pick(C, location, extend, deselect, toggle); + else if (obedit->type == OB_ARMATURE) + retval = ED_armature_edit_select_pick(C, location, extend, deselect, toggle); + else if (obedit->type == OB_LATTICE) + retval = ED_lattice_select_pick(C, location, extend, deselect, toggle); + else if (ELEM(obedit->type, OB_CURVE, OB_SURF)) + retval = ED_curve_editnurb_select_pick(C, location, extend, deselect, toggle); + else if (obedit->type == OB_MBALL) + retval = ED_mball_select_pick(C, location, extend, deselect, toggle); + else if (obedit->type == OB_FONT) + retval = ED_curve_editfont_select_pick(C, location, extend, deselect, toggle); + + } + else if (obact && obact->mode & OB_MODE_PARTICLE_EDIT) + return PE_mouse_particles(C, location, extend, deselect, toggle); + else if (obact && BKE_paint_select_face_test(obact)) + retval = paintface_mouse_select(C, obact, location, extend, deselect, toggle); + else if (BKE_paint_select_vert_test(obact)) + retval = ed_wpaint_vertex_select_pick(C, location, extend, deselect, toggle, obact); + else + retval = ed_object_select_pick(C, location, extend, deselect, toggle, center, enumerate, object); + + /* passthrough allows tweaks + * FINISHED to signal one operator worked + * */ + if (retval) + return OPERATOR_PASS_THROUGH | OPERATOR_FINISHED; + else + return OPERATOR_PASS_THROUGH; /* nothing selected, just passthrough */ +} + +static int view3d_select_invoke(bContext *C, wmOperator *op, const wmEvent *event) +{ + RNA_int_set_array(op->ptr, "location", event->mval); + + return view3d_select_exec(C, op); +} + +void VIEW3D_OT_select(wmOperatorType *ot) +{ + PropertyRNA *prop; + + /* identifiers */ + ot->name = "Select"; + ot->description = "Select and activate item(s)"; + ot->idname = "VIEW3D_OT_select"; + + /* api callbacks */ + ot->invoke = view3d_select_invoke; + ot->exec = view3d_select_exec; + ot->poll = ED_operator_view3d_active; + + /* flags */ + ot->flag = OPTYPE_UNDO; + + /* properties */ + WM_operator_properties_mouse_select(ot); + + prop = RNA_def_boolean(ot->srna, "center", 0, "Center", "Use the object center when selecting, in editmode used to extend object selection"); + RNA_def_property_flag(prop, PROP_SKIP_SAVE); + prop = RNA_def_boolean(ot->srna, "enumerate", 0, "Enumerate", "List objects under the mouse (object mode only)"); + RNA_def_property_flag(prop, PROP_SKIP_SAVE); + prop = RNA_def_boolean(ot->srna, "object", 0, "Object", "Use object selection (editmode only)"); + RNA_def_property_flag(prop, PROP_SKIP_SAVE); + + prop = RNA_def_int_vector(ot->srna, "location", 2, NULL, INT_MIN, INT_MAX, "Location", "Mouse location", INT_MIN, INT_MAX); + RNA_def_property_flag(prop, PROP_HIDDEN); +} + +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Box Select + * \{ */ typedef struct BoxSelectUserData { ViewContext *vc; @@ -2618,10 +2786,6 @@ static int view3d_box_select_exec(bContext *C, wmOperator *op) return ret; } - -/* *****************Selection Operators******************* */ - -/* ****** Box Select ****** */ void VIEW3D_OT_select_box(wmOperatorType *ot) { /* identifiers */ @@ -2644,161 +2808,11 @@ void VIEW3D_OT_select_box(wmOperatorType *ot) WM_operator_properties_select_operation(ot); } +/** \} */ -/* mouse selection in weight paint */ -/* gets called via generic mouse select operator */ -static bool ed_wpaint_vertex_select_pick( - bContext *C, const int mval[2], - bool extend, bool deselect, bool toggle, Object *obact) -{ - View3D *v3d = CTX_wm_view3d(C); - const bool use_zbuf = V3D_IS_ZBUF(v3d); - - Mesh *me = obact->data; /* already checked for NULL */ - unsigned int index = 0; - MVert *mv; - - if (ED_mesh_pick_vert(C, obact, mval, &index, ED_MESH_PICK_DEFAULT_VERT_SIZE, use_zbuf)) { - mv = &me->mvert[index]; - if (extend) { - mv->flag |= SELECT; - } - else if (deselect) { - mv->flag &= ~SELECT; - } - else if (toggle) { - mv->flag ^= SELECT; - } - else { - paintvert_deselect_all_visible(obact, SEL_DESELECT, false); - mv->flag |= SELECT; - } - - /* update mselect */ - if (mv->flag & SELECT) { - BKE_mesh_mselect_active_set(me, index, ME_VSEL); - } - else { - BKE_mesh_mselect_validate(me); - } - - paintvert_flush_flags(obact); - paintvert_tag_select_update(C, obact); - return true; - } - return false; -} - -/* ****** Mouse Select ****** */ - - -static int view3d_select_exec(bContext *C, wmOperator *op) -{ - Object *obedit = CTX_data_edit_object(C); - Object *obact = CTX_data_active_object(C); - bool extend = RNA_boolean_get(op->ptr, "extend"); - bool deselect = RNA_boolean_get(op->ptr, "deselect"); - bool toggle = RNA_boolean_get(op->ptr, "toggle"); - bool center = RNA_boolean_get(op->ptr, "center"); - bool enumerate = RNA_boolean_get(op->ptr, "enumerate"); - /* only force object select for editmode to support vertex parenting, - * or paint-select to allow pose bone select with vert/face select */ - bool object = (RNA_boolean_get(op->ptr, "object") && - (obedit || - BKE_paint_select_elem_test(obact) || - /* so its possible to select bones in weightpaint mode (LMB select) */ - (obact && (obact->mode & OB_MODE_WEIGHT_PAINT) && BKE_object_pose_armature_get(obact)))); - - bool retval = false; - int location[2]; - - RNA_int_get_array(op->ptr, "location", location); - - view3d_operator_needs_opengl(C); - - if (object) { - obedit = NULL; - obact = NULL; - - /* ack, this is incorrect but to do this correctly we would need an - * alternative editmode/objectmode keymap, this copies the functionality - * from 2.4x where Ctrl+Select in editmode does object select only */ - center = false; - } - - if (obedit && object == false) { - if (obedit->type == OB_MESH) - retval = EDBM_select_pick(C, location, extend, deselect, toggle); - else if (obedit->type == OB_ARMATURE) - retval = ED_armature_edit_select_pick(C, location, extend, deselect, toggle); - else if (obedit->type == OB_LATTICE) - retval = ED_lattice_select_pick(C, location, extend, deselect, toggle); - else if (ELEM(obedit->type, OB_CURVE, OB_SURF)) - retval = ED_curve_editnurb_select_pick(C, location, extend, deselect, toggle); - else if (obedit->type == OB_MBALL) - retval = ED_mball_select_pick(C, location, extend, deselect, toggle); - else if (obedit->type == OB_FONT) - retval = ED_curve_editfont_select_pick(C, location, extend, deselect, toggle); - - } - else if (obact && obact->mode & OB_MODE_PARTICLE_EDIT) - return PE_mouse_particles(C, location, extend, deselect, toggle); - else if (obact && BKE_paint_select_face_test(obact)) - retval = paintface_mouse_select(C, obact, location, extend, deselect, toggle); - else if (BKE_paint_select_vert_test(obact)) - retval = ed_wpaint_vertex_select_pick(C, location, extend, deselect, toggle, obact); - else - retval = ed_object_select_pick(C, location, extend, deselect, toggle, center, enumerate, object); - - /* passthrough allows tweaks - * FINISHED to signal one operator worked - * */ - if (retval) - return OPERATOR_PASS_THROUGH | OPERATOR_FINISHED; - else - return OPERATOR_PASS_THROUGH; /* nothing selected, just passthrough */ -} - -static int view3d_select_invoke(bContext *C, wmOperator *op, const wmEvent *event) -{ - RNA_int_set_array(op->ptr, "location", event->mval); - - return view3d_select_exec(C, op); -} - -void VIEW3D_OT_select(wmOperatorType *ot) -{ - PropertyRNA *prop; - - /* identifiers */ - ot->name = "Select"; - ot->description = "Select and activate item(s)"; - ot->idname = "VIEW3D_OT_select"; - - /* api callbacks */ - ot->invoke = view3d_select_invoke; - ot->exec = view3d_select_exec; - ot->poll = ED_operator_view3d_active; - - /* flags */ - ot->flag = OPTYPE_UNDO; - - /* properties */ - WM_operator_properties_mouse_select(ot); - - prop = RNA_def_boolean(ot->srna, "center", 0, "Center", "Use the object center when selecting, in editmode used to extend object selection"); - RNA_def_property_flag(prop, PROP_SKIP_SAVE); - prop = RNA_def_boolean(ot->srna, "enumerate", 0, "Enumerate", "List objects under the mouse (object mode only)"); - RNA_def_property_flag(prop, PROP_SKIP_SAVE); - prop = RNA_def_boolean(ot->srna, "object", 0, "Object", "Use object selection (editmode only)"); - RNA_def_property_flag(prop, PROP_SKIP_SAVE); - - prop = RNA_def_int_vector(ot->srna, "location", 2, NULL, INT_MIN, INT_MAX, "Location", "Mouse location", INT_MIN, INT_MAX); - RNA_def_property_flag(prop, PROP_HIDDEN); -} - - -/* -------------------- circle select --------------------------------------------- */ +/* -------------------------------------------------------------------- */ +/** \name Circle Select + * \{ */ typedef struct CircleSelectUserData { ViewContext *vc; @@ -3327,3 +3341,5 @@ void VIEW3D_OT_select_circle(wmOperatorType *ot) /* properties */ WM_operator_properties_gesture_circle_select(ot); } + +/** \} */ -- cgit v1.2.3