fix bug with editmesh rip, active edge could be left on the unselected side of the...
authorCampbell Barton <ideasman42@gmail.com>
Wed, 14 Aug 2013 09:14:33 +0000 (09:14 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 14 Aug 2013 09:14:33 +0000 (09:14 +0000)
source/blender/bmesh/tools/bmesh_edgesplit.c
source/blender/editors/mesh/editmesh_rip.c

index adcf325b51c8db3c20dd5bc9850fba0187fcba77..aad600d13fa9e527afba68a97feb3a07c9f48f5c 100644 (file)
@@ -103,6 +103,21 @@ void BM_mesh_edgesplit(BMesh *bm, const bool use_verts, const bool tag_only, con
        BMIter iter;
        BMEdge *e;
 
+       bool use_ese = false;
+       GHash *ese_gh = NULL;
+
+       if (copy_select && bm->selected.first) {
+               BMEditSelection *ese;
+
+               ese_gh = BLI_ghash_ptr_new(__func__);
+               for (ese = bm->selected.first; ese; ese = ese->next) {
+                       if (ese->htype != BM_FACE) {
+                               BLI_ghash_insert(ese_gh, ese->ele, ese);
+                       }
+               }
+
+               use_ese = true;
+       }
 
        if (tag_only == false) {
                BM_mesh_elem_hflag_enable_all(bm, BM_EDGE | (use_verts ? BM_VERT : 0), BM_ELEM_TAG, false);
@@ -135,9 +150,18 @@ void BM_mesh_edgesplit(BMesh *bm, const bool use_verts, const bool tag_only, con
                        BM_elem_flag_enable(e, BM_ELEM_INTERNAL_TAG);
 
                        /* keep splitting until each loop has its own edge */
-                       do {
-                               bmesh_edge_separate(bm, e, e->l, copy_select);
-                       } while (!BM_edge_is_boundary(e));
+                       while (!BM_edge_is_boundary(e)) {
+                               BMLoop *l_sep = e->l;
+                               bmesh_edge_separate(bm, e, l_sep, copy_select);
+                               BLI_assert(l_sep->e != e);
+
+                               if (use_ese) {
+                                       BMEditSelection *ese = BLI_ghash_lookup(ese_gh, e);
+                                       if (UNLIKELY(ese)) {
+                                               BM_select_history_store_after_notest(bm, ese, l_sep->e);
+                                       }
+                               }
+                       }
 
                        BM_elem_flag_enable(e->v1, BM_ELEM_TAG);
                        BM_elem_flag_enable(e->v2, BM_ELEM_TAG);
@@ -157,14 +181,39 @@ void BM_mesh_edgesplit(BMesh *bm, const bool use_verts, const bool tag_only, con
 
        BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) {
                if (BM_elem_flag_test(e, BM_ELEM_TAG)) {
-                       if (BM_elem_flag_test(e->v1, BM_ELEM_TAG)) {
-                               BM_elem_flag_disable(e->v1, BM_ELEM_TAG);
-                               bmesh_vert_separate(bm, e->v1, NULL, NULL, copy_select);
-                       }
-                       if (BM_elem_flag_test(e->v2, BM_ELEM_TAG)) {
-                               BM_elem_flag_disable(e->v2, BM_ELEM_TAG);
-                               bmesh_vert_separate(bm, e->v2, NULL, NULL, copy_select);
+                       unsigned int i;
+                       for (i = 0; i < 2; i++) {
+                               BMVert *v = ((&e->v1)[i]);
+                               if (BM_elem_flag_test(v, BM_ELEM_TAG)) {
+                                       BM_elem_flag_disable(v, BM_ELEM_TAG);
+
+                                       if (use_ese) {
+                                               BMVert **vtar;
+                                               int vtar_len;
+
+                                               bmesh_vert_separate(bm, v, &vtar, &vtar_len, copy_select);
+
+                                               if (vtar_len) {
+                                                       BMEditSelection *ese = BLI_ghash_lookup(ese_gh, v);
+                                                       if (UNLIKELY(ese)) {
+                                                               int j;
+                                                               for (j = 0; j < vtar_len; j++) {
+                                                                       BLI_assert(v != vtar[j]);
+                                                                       BM_select_history_store_after_notest(bm, ese, vtar[j]);
+                                                               }
+                                                       }
+                                               }
+                                               MEM_freeN(vtar);
+                                       }
+                                       else {
+                                               bmesh_vert_separate(bm, v, NULL, NULL, copy_select);
+                                       }
+                               }
                        }
                }
        }
+
+       if (use_ese) {
+               BLI_ghash_free(ese_gh, NULL, NULL);
+       }
 }
index 59fe2a6705784c73d2638ef3f3129fc6d937a8c9..1360a180b2d02a136a962486fb94f6c69888dac2 100644 (file)
@@ -952,6 +952,8 @@ static int edbm_rip_invoke__edge(bContext *C, wmOperator *op, const wmEvent *eve
                return OPERATOR_CANCELLED;
        }
 
+       BM_select_history_validate(bm);
+
        return OPERATOR_FINISHED;
 }