patch [#28588] BMesh: "Split" tool
authorCampbell Barton <ideasman42@gmail.com>
Fri, 9 Sep 2011 14:58:49 +0000 (14:58 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Fri, 9 Sep 2011 14:58:49 +0000 (14:58 +0000)
from Andrew Wiggin (ender79)

Impliments the split tool in bmesh.

source/blender/editors/mesh/bmesh_tools.c

index f66be3ac71b29e6cb415c2256f472d393e21456b..83415a65017433188bbf8dc7a82ca993e798d5e8 100644 (file)
@@ -3883,28 +3883,42 @@ void MESH_OT_edge_flip(wmOperatorType *ot)
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
 
-//BMESH_TODO
-static int split_mesh(bContext *UNUSED(C), wmOperator *UNUSED(op))
+static int split_mesh_exec(bContext *C, wmOperator *op)
 {
-#if 0
-       Object *obedit= CTX_data_edit_object(C);
-       EditMesh *em= BKE_mesh_get_editmesh((Mesh *)obedit->data);
-
-       WM_cursor_wait(1);
+       Object *ob= CTX_data_edit_object(C);
+       BMEditMesh *em= ((Mesh*)ob->data)->edit_btmesh;
+       BMOperator bmopDupe, bmopDel;
+
+       /*Duplicate selected geometry*/
+       EDBM_InitOpf(em, &bmopDupe, op, "dupe geom=%hvef", BM_SELECT);
+       BMO_Exec_Op(em->bm, &bmopDupe);
+
+       /*Duplicated geometry starts out selected. Deselect all duplicated
+         geometry to return to the original selection.*/
+       BMO_UnHeaderFlag_Buffer(em->bm, &bmopDupe, "newout", BM_SELECT, BM_ALL);
+
+       /*Delete selected faces*/
+       EDBM_InitOpf(em, &bmopDel, op, "del geom=%hvef context=%i", BM_SELECT, DEL_FACES);
+       BMO_Exec_Op(em->bm, &bmopDel);
+       if (!EDBM_FinishOp(em, &bmopDel, op, 1)) {
+               /*Also clean up the dupe op*/
+               EDBM_FinishOp(em, &bmopDupe, op, 1);
+               return OPERATOR_CANCELLED;
+       }
 
-       /* make duplicate first */
-       adduplicateflag(em, SELECT);
-       /* old faces have flag 128 set, delete them */
-       delfaceflag(em, 128);
-       recalc_editnormals(em);
+       /*Clear prior selection and select the dupliated geometry*/
+       BM_clear_flag_all(em->bm, BM_SELECT);
+       BMO_HeaderFlag_Buffer(em->bm, &bmopDupe, "newout", BM_SELECT, BM_ALL);
+       if (!EDBM_FinishOp(em, &bmopDupe, op, 1))
+               return OPERATOR_CANCELLED;
 
-       WM_cursor_wait(0);
+       /*Geometry has changed, need to recalc normals and looptris*/
+       BMEdit_RecalcTesselation(em);
+       EDBM_RecalcNormals(em);
 
-       DAG_id_tag_update(obedit->data, OB_RECALC_DATA);
-       WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
+       DAG_id_tag_update(ob->data, OB_RECALC_DATA);
+       WM_event_add_notifier(C, NC_GEOM|ND_DATA, ob->data);
 
-       BKE_mesh_end_editmesh(obedit->data, em);
-#endif
        return OPERATOR_FINISHED;
 }
 
@@ -3915,7 +3929,7 @@ void MESH_OT_split(wmOperatorType *ot)
        ot->idname= "MESH_OT_split";
 
        /* api callbacks */
-       ot->exec= split_mesh;
+       ot->exec= split_mesh_exec;
        ot->poll= ED_operator_editmesh;
 
        /* flags */