merge with trunk at r27259 and commit of a patch by anthony jones to fix msvc (though...
[blender-staging.git] / source / blender / editors / space_view3d / view3d_buttons.c
index f1668190ea8c9e3c4b31725b50fea9c1dad6272a..f2c2c7ff4d45b114e192540eac5f5b05c087e5ad 100644 (file)
@@ -70,6 +70,7 @@
 #include "BKE_scene.h"
 #include "BKE_screen.h"
 #include "BKE_utildefines.h"
+#include "BKE_tessmesh.h"
 #include "BKE_deform.h"
 
 #include "BIF_gl.h"
@@ -168,31 +169,30 @@ static void v3d_editvertex_buts(const bContext *C, uiLayout *layout, View3D *v3d
 
        if(ob->type==OB_MESH) {
                Mesh *me= ob->data;
-               EditMesh *em = BKE_mesh_get_editmesh(me);
-               EditVert *eve, *evedef=NULL;
-               EditEdge *eed;
+               BMEditMesh *em = me->edit_btmesh;
+               BMesh *bm = em->bm;
+               BMVert *eve, *evedef=NULL;
+               BMEdge *eed;
+               BMIter iter;
                
-               eve= em->verts.first;
-               while(eve) {
-                       if(eve->f & SELECT) {
+               BM_ITER(eve, &iter, bm, BM_VERTS_OF_MESH, NULL) {
+                       if(BM_TestHFlag(eve, BM_SELECT)) {
                                evedef= eve;
                                tot++;
                                add_v3_v3v3(median, median, eve->co);
                        }
-                       eve= eve->next;
                }
-               eed= em->edges.first;
-               while(eed) {
-                       if((eed->f & SELECT)) {
+
+               BM_ITER(eed, &iter, bm, BM_EDGES_OF_MESH, NULL) {
+                       if(BM_TestHFlag(eed, BM_SELECT)) {
                                totedge++;
                                median[3]+= eed->crease;
                        }
-                       eed= eed->next;
                }
 
                /* check for defgroups */
                if(evedef)
-                       dvert= CustomData_em_get(&em->vdata, evedef->data, CD_MDEFORMVERT);
+                       dvert= CustomData_bmesh_get(&em->bm->vdata, evedef->head.data, CD_MDEFORMVERT);
                if(tot==1 && dvert && dvert->totweight) {
                        bDeformGroup *dg;
                        int i, max=1, init=1;
@@ -216,8 +216,6 @@ static void v3d_editvertex_buts(const bContext *C, uiLayout *layout, View3D *v3d
                                tfp->defweightp= &dvert->dw[0].weight;
                        }
                }
-
-               BKE_mesh_end_editmesh(me, em);
        }
        else if(ob->type==OB_CURVE || ob->type==OB_SURF) {
                Curve *cu= ob->data;
@@ -382,20 +380,19 @@ static void v3d_editvertex_buts(const bContext *C, uiLayout *layout, View3D *v3d
                
                if(ob->type==OB_MESH) {
                        Mesh *me= ob->data;
-                       EditMesh *em = BKE_mesh_get_editmesh(me);
-                       EditVert *eve;
-                       EditEdge *eed;
-                       
-                       eve= em->verts.first;
-                       while(eve) {
-                               if(eve->f & SELECT) {
+                       BMEditMesh *em = me->edit_btmesh;
+                       BMVert *eve;
+                       BMEdge *eed;
+                       BMIter iter;
+
+                       BM_ITER(eve, &iter, em->bm, BM_VERTS_OF_MESH, NULL) {
+                               if(BM_TestHFlag(eve, BM_SELECT)) {
                                        add_v3_v3v3(eve->co, eve->co, median);
                                }
-                               eve= eve->next;
                        }
                        
-                       for(eed= em->edges.first; eed; eed= eed->next) {
-                               if(eed->f & SELECT) {
+                       BM_ITER(eed, &iter, em->bm, BM_EDGES_OF_MESH, NULL) {
+                               if(BM_TestHFlag(eed, BM_SELECT)) {
                                        /* ensure the median can be set to zero or one */
                                        if(ve_median[3]==0.0f) eed->crease= 0.0f;
                                        else if(ve_median[3]==1.0f) eed->crease= 1.0f;
@@ -406,9 +403,7 @@ static void v3d_editvertex_buts(const bContext *C, uiLayout *layout, View3D *v3d
                                }
                        }
                        
-                       recalc_editnormals(em);
-
-                       BKE_mesh_end_editmesh(me, em);
+                       EDBM_RecalcNormals(em);
                }
                else if(ob->type==OB_CURVE || ob->type==OB_SURF) {
                        Curve *cu= ob->data;
@@ -482,29 +477,28 @@ static void v3d_editvertex_buts(const bContext *C, uiLayout *layout, View3D *v3d
 #define B_VGRP_PNL_EDIT_SINGLE 8 /* or greater */
 #define B_VGRP_PNL_COPY_SINGLE 16384 /* or greater */
 
-static void act_vert_def(Object *ob, EditVert **eve, MDeformVert **dvert)
+static void act_vert_def(Object *ob, BMVert **eve, MDeformVert **dvert)
 {
        if(ob && ob->mode & OB_MODE_EDIT && ob->type==OB_MESH && ob->defbase.first) {
                Mesh *me= ob->data;
-               EditMesh *em = BKE_mesh_get_editmesh(me);
-               EditSelection *ese = ((EditSelection*)em->selected.last);
+               BMEditMesh *em = me->edit_btmesh;
+               BMEditSelection *ese = ((BMEditSelection*)em->bm->selected.last);
 
-               if(ese && ese->type == EDITVERT) {
-                       *eve= (EditVert*)ese->data;
-                       *dvert= CustomData_em_get(&em->vdata, (*eve)->data, CD_MDEFORMVERT);
+               if(ese && ese->type == BM_VERT) {
+                       *eve= (BMVert*)ese->data;
+                       *dvert= CustomData_bmesh_get(&em->bm->vdata, (*eve)->head.data, CD_MDEFORMVERT);
                        return;
                }
-
-               BKE_mesh_end_editmesh(me, em);
        }
 
        *eve= NULL;
        *dvert= NULL;
 }
 
-static void editvert_mirror_update(Object *ob, EditVert *eve, int def_nr, int index)
+static void editvert_mirror_update(Object *ob, BMVert *eve, int def_nr, int index)
 {
        Mesh *me= ob->data;
+#if 0 //BMESH_TODO use editbmesh_bvh.h code for this! see EDBM_FindNearestVertTopo.
        EditMesh *em = BKE_mesh_get_editmesh(me);
        EditVert *eve_mirr;
 
@@ -530,11 +524,12 @@ static void editvert_mirror_update(Object *ob, EditVert *eve, int def_nr, int in
                        }
                }
        }
+#endif
 }
 
 static void vgroup_adjust_active(Object *ob, int def_nr)
 {
-       EditVert *eve_act;
+       BMVert *eve_act;
        MDeformVert *dvert_act;
 
        act_vert_def(ob, &eve_act, &dvert_act);
@@ -547,7 +542,7 @@ static void vgroup_adjust_active(Object *ob, int def_nr)
 
 static void vgroup_copy_active_to_sel(Object *ob)
 {
-       EditVert *eve_act;
+       BMVert *eve_act;
        MDeformVert *dvert_act;
 
        act_vert_def(ob, &eve_act, &dvert_act);
@@ -557,14 +552,15 @@ static void vgroup_copy_active_to_sel(Object *ob)
        }
        else {
                Mesh *me= ob->data;
-               EditMesh *em = BKE_mesh_get_editmesh(me);
-               EditVert *eve;
+               BMEditMesh *em = me->edit_btmesh;
+               BMIter iter;
+               BMVert *eve;
                MDeformVert *dvert;
                int index= 0;
 
-               for(eve= em->verts.first; eve; eve= eve->next, index++) {
-                       if(eve->f & SELECT && eve != eve_act) {
-                               dvert= CustomData_em_get(&em->vdata, eve->data, CD_MDEFORMVERT);
+               BM_ITER(eve, &iter, em->bm, BM_VERTS_OF_MESH, NULL) {
+                       if(BM_TestHFlag(eve, BM_SELECT) && eve != eve_act) {
+                               dvert= CustomData_bmesh_get(&em->bm->vdata, eve->head.data, CD_MDEFORMVERT);
                                if(dvert) {
                                        defvert_copy(dvert, dvert_act);
 
@@ -573,13 +569,15 @@ static void vgroup_copy_active_to_sel(Object *ob)
 
                                }
                        }
+
+                       index++;
                }
        }
 }
 
 static void vgroup_copy_active_to_sel_single(Object *ob, int def_nr)
 {
-       EditVert *eve_act;
+       BMVert *eve_act;
        MDeformVert *dvert_act;
 
        act_vert_def(ob, &eve_act, &dvert_act);
@@ -589,8 +587,9 @@ static void vgroup_copy_active_to_sel_single(Object *ob, int def_nr)
        }
        else {
                Mesh *me= ob->data;
-               EditMesh *em = BKE_mesh_get_editmesh(me);
-               EditVert *eve;
+               BMEditMesh *em = me->edit_btmesh;
+               BMIter iter;
+               BMVert *eve;
                MDeformVert *dvert;
                MDeformWeight *dw;
                float act_weight = -1.0f;
@@ -606,10 +605,11 @@ static void vgroup_copy_active_to_sel_single(Object *ob, int def_nr)
 
                if(act_weight < -0.5f)
                        return;
-
-               for(eve= em->verts.first; eve; eve= eve->next, index++) {
-                       if(eve->f & SELECT && eve != eve_act) {
-                               dvert= CustomData_em_get(&em->vdata, eve->data, CD_MDEFORMVERT);
+               
+               eve = BMIter_New(&iter, em->bm, BM_VERTS_OF_MESH, NULL);
+               for (index=0; eve; eve=BMIter_Step(&iter), index++) {
+                       if(BM_TestHFlag(eve, BM_SELECT) && eve != eve_act) {
+                               dvert= CustomData_bmesh_get(&em->bm->vdata, eve->head.data, CD_MDEFORMVERT);
                                if(dvert) {
                                        for(i=0, dw=dvert->dw; i < dvert->totweight; i++, dw++) {
                                                if(def_nr == dw->def_nr) {
@@ -633,7 +633,7 @@ static void vgroup_copy_active_to_sel_single(Object *ob, int def_nr)
 
 static void vgroup_normalize_active(Object *ob)
 {
-       EditVert *eve_act;
+       BMVert *eve_act;
        MDeformVert *dvert_act;
 
        act_vert_def(ob, &eve_act, &dvert_act);
@@ -681,7 +681,7 @@ int view3d_panel_vgroup_poll(const bContext *C, PanelType *pt)
 {
        Scene *scene= CTX_data_scene(C);
        Object *ob= OBACT;
-       EditVert *eve_act;
+       BMVert *eve_act;
        MDeformVert *dvert_act;
 
        act_vert_def(ob, &eve_act, &dvert_act);
@@ -696,7 +696,7 @@ static void view3d_panel_vgroup(const bContext *C, Panel *pa)
        Scene *scene= CTX_data_scene(C);
        Object *ob= OBACT;
 
-       EditVert *eve;
+       BMVert *eve;
        MDeformVert *dvert;
 
        act_vert_def(ob, &eve, &dvert);
@@ -951,10 +951,10 @@ static void v3d_editmetaball_buts(uiLayout *layout, Object *ob, float lim)
 //     row= uiLayoutRow(layout, 0);
 
        RNA_pointer_create(&mball->id, &RNA_MetaElement, mball->lastelem, &ptr);
-       
+               
        col= uiLayoutColumn(layout, 0);
        uiItemR(col, "Location", 0, &ptr, "location", 0);
-       
+               
        uiItemR(col, "Radius", 0, &ptr, "radius", 0);
        uiItemR(col, "Stiffness", 0, &ptr, "stiffness", 0);
        
@@ -1015,7 +1015,7 @@ static void do_view3d_region_buttons(bContext *C, void *arg, int event)
                DAG_id_flush_update(&ob->id, OB_RECALC_OB);
                break;
 
-       
+                               
        case B_OBJECTPANELMEDIAN:
                if(ob) {
                        v3d_editvertex_buts(C, NULL, v3d, ob, 1.0);
@@ -1219,7 +1219,7 @@ static void view3d_panel_object(const bContext *C, Panel *pa)
        else {
 
                v3d_transform_butsR(col, &obptr);
-       }
+               }
 }
 
 #if 0