diff options
author | Philipp Oeser <info@graphics-engineer.com> | 2019-11-27 17:02:41 +0300 |
---|---|---|
committer | Philipp Oeser <info@graphics-engineer.com> | 2019-11-27 17:55:32 +0300 |
commit | 6992fc0b3bf85e985169157b2e7ced1e1ed7fcdf (patch) | |
tree | 6af1fd9209963ca17e38d3037961e7fea47f5948 /source/blender | |
parent | 7959dcd4f6316ade726209f2452323406f3672ea (diff) |
Add 'EDBM_selectmode_disable_multi' and use in knifeproject
As a followup to rB6f4e595e9ba9 and as per @campbellbarton suggestion,
this adds EDBM_selectmode_disable_multi, similar to
EDBM_mesh_deselect_all_multi & EDBM_mesh_deselect_all, so other similar
uses don't need to be done in a loop.
Also, selected_objects isn't a reliable way to handle this case - since
objects can be in edit-mode & not selected, use
BKE_view_layer_array_from_bases_in_edit_mode_unique_data instead
Differential Revision: https://developer.blender.org/D6317
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/editors/include/ED_mesh.h | 8 | ||||
-rw-r--r-- | source/blender/editors/mesh/editmesh_knife_project.c | 17 | ||||
-rw-r--r-- | source/blender/editors/mesh/editmesh_select.c | 35 |
3 files changed, 44 insertions, 16 deletions
diff --git a/source/blender/editors/include/ED_mesh.h b/source/blender/editors/include/ED_mesh.h index fc7b0d8be8f..835e1b4e26f 100644 --- a/source/blender/editors/include/ED_mesh.h +++ b/source/blender/editors/include/ED_mesh.h @@ -236,6 +236,14 @@ void em_setup_viewcontext(struct bContext *C, struct ViewContext *vc); /* rename bool EDBM_mesh_deselect_all_multi_ex(struct Base **bases, const uint bases_len); bool EDBM_mesh_deselect_all_multi(struct bContext *C); +bool EDBM_selectmode_disable_multi_ex(struct Scene *scene, + struct Base **bases, + const uint bases_len, + const short selectmode_disable, + const short selectmode_fallback); +bool EDBM_selectmode_disable_multi(struct bContext *C, + const short selectmode_disable, + const short selectmode_fallback); /* editmesh_preselect_edgering.c */ struct EditMesh_PreSelEdgeRing; diff --git a/source/blender/editors/mesh/editmesh_knife_project.c b/source/blender/editors/mesh/editmesh_knife_project.c index a709bd010aa..ebd1e62e596 100644 --- a/source/blender/editors/mesh/editmesh_knife_project.c +++ b/source/blender/editors/mesh/editmesh_knife_project.c @@ -22,7 +22,6 @@ */ #include "DNA_curve_types.h" -#include "DNA_mesh_types.h" #include "DNA_object_types.h" #include "BLI_math.h" @@ -143,21 +142,7 @@ static int knifeproject_exec(bContext *C, wmOperator *op) /* select only tagged faces */ BM_mesh_elem_hflag_disable_all(em->bm, BM_VERT | BM_EDGE | BM_FACE, BM_ELEM_SELECT, false); - CTX_DATA_BEGIN (C, Object *, ob, selected_objects) { - if (ob->type == OB_MESH) { - Mesh *me = (Mesh *)ob->data; - BMEditMesh *embm = me->edit_mesh; - if (embm) { - /* not essential, but switch out of vertex mode since the - * selected regions wont be nicely isolated after flushing. - * note: call after de-select to avoid selection flushing. - * note: do this on all participating meshes so this is in sync - * e.g. for later selection picking, see T68852.*/ - EDBM_selectmode_disable(scene, embm, SCE_SELECT_VERTEX, SCE_SELECT_EDGE); - } - } - } - CTX_DATA_END; + EDBM_selectmode_disable_multi(C, SCE_SELECT_VERTEX, SCE_SELECT_EDGE); BM_mesh_elem_hflag_enable_test(em->bm, BM_FACE, BM_ELEM_SELECT, true, false, BM_ELEM_TAG); diff --git a/source/blender/editors/mesh/editmesh_select.c b/source/blender/editors/mesh/editmesh_select.c index 7955ccc0977..40d57af97aa 100644 --- a/source/blender/editors/mesh/editmesh_select.c +++ b/source/blender/editors/mesh/editmesh_select.c @@ -2653,6 +2653,41 @@ bool EDBM_mesh_deselect_all_multi(struct bContext *C) return changed_multi; } +bool EDBM_selectmode_disable_multi_ex(Scene *scene, + struct Base **bases, + const uint bases_len, + const short selectmode_disable, + const short selectmode_fallback) +{ + 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; + BMEditMesh *em_iter = BKE_editmesh_from_object(ob_iter); + + EDBM_selectmode_disable(scene, em_iter, selectmode_disable, selectmode_fallback); + changed_multi = true; + } + return changed_multi; +} + +bool EDBM_selectmode_disable_multi(struct bContext *C, + const short selectmode_disable, + const short selectmode_fallback) +{ + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); + Scene *scene = CTX_data_scene(C); + ViewContext vc; + ED_view3d_viewcontext_init(C, &vc, depsgraph); + uint bases_len = 0; + Base **bases = BKE_view_layer_array_from_bases_in_edit_mode_unique_data( + vc.view_layer, NULL, &bases_len); + bool changed_multi = EDBM_selectmode_disable_multi_ex( + scene, bases, bases_len, selectmode_disable, selectmode_fallback); + MEM_freeN(bases); + return changed_multi; +} + /** \} */ /* -------------------------------------------------------------------- */ |