ok, apparently didn't commit this either. apparently includes a merge with trunk...
[blender-staging.git] / source / blender / editors / space_view3d / view3d_select.c
index 508bf56cc718fb5407703b8f2163b56e29042e63..2037eeab235c1f32dc2c369c5b7728c19737370f 100644 (file)
@@ -64,6 +64,7 @@
 #include "BKE_scene.h"
 #include "BKE_screen.h"
 #include "BKE_utildefines.h"
+#include "BKE_tessmesh.h"
 
 #include "RE_pipeline.h"       // make_stars
 
 #include "ED_particle.h"
 #include "ED_mesh.h"
 #include "ED_object.h"
-#include "ED_retopo.h"
 #include "ED_screen.h"
 #include "ED_types.h"
 #include "ED_util.h"
+#include "ED_retopo.h"
 #include "ED_mball.h"
 
 #include "UI_interface.h"
@@ -148,43 +149,49 @@ void view3d_get_transformation(ViewContext *vc, Object *ob, bglMats *mats)
 
 /* local prototypes */
 
-void EM_backbuf_checkAndSelectVerts(EditMesh *em, int select)
+void EM_backbuf_checkAndSelectVerts(BMEditMesh *em, int select)
 {
-       EditVert *eve;
-       int index= em_wireoffs;
-
-       for(eve= em->verts.first; eve; eve= eve->next, index++) {
-               if(eve->h==0) {
-                       if(EM_check_backbuf(index)) {
-                               eve->f = select?(eve->f|1):(eve->f&~1);
+       BMVert *eve;
+       BMIter iter;
+       int index= bm_wireoffs;
+
+       eve = BMIter_New(&iter, em->bm, BM_VERTS_OF_MESH, NULL);
+       for ( ; eve; eve=BMIter_Step(&iter), index++) {
+               if(!BM_TestHFlag(eve, BM_HIDDEN)) {
+                       if(EDBM_check_backbuf(index)) {
+                               BM_Select_Vert(em->bm, eve, select);
                        }
                }
        }
 }
 
-void EM_backbuf_checkAndSelectEdges(EditMesh *em, int select)
+void EM_backbuf_checkAndSelectEdges(BMEditMesh *em, int select)
 {
-       EditEdge *eed;
-       int index= em_solidoffs;
-
-       for(eed= em->edges.first; eed; eed= eed->next, index++) {
-               if(eed->h==0) {
-                       if(EM_check_backbuf(index)) {
-                               EM_select_edge(eed, select);
+       BMEdge *eed;
+       BMIter iter;
+       int index= bm_solidoffs;
+
+       eed = BMIter_New(&iter, em->bm, BM_EDGES_OF_MESH, NULL);
+       for ( ; eed; eed=BMIter_Step(&iter), index++) {
+               if(!BM_TestHFlag(eed, BM_HIDDEN)) {
+                       if(EDBM_check_backbuf(index)) {
+                               BM_Select_Edge(em->bm, eed, select);
                        }
                }
        }
 }
 
-void EM_backbuf_checkAndSelectFaces(EditMesh *em, int select)
+void EM_backbuf_checkAndSelectFaces(BMEditMesh *em, int select)
 {
-       EditFace *efa;
+       BMFace *efa;
+       BMIter iter;
        int index= 1;
 
-       for(efa= em->faces.first; efa; efa= efa->next, index++) {
-               if(efa->h==0) {
-                       if(EM_check_backbuf(index)) {
-                               EM_select_face_fgon(em, efa, select);
+       efa = BMIter_New(&iter, em->bm, BM_FACES_OF_MESH, NULL);
+       for ( ; efa; efa=BMIter_Step(&iter), index++) {
+               if(!BM_TestHFlag(efa, BM_HIDDEN)) {
+                       if(EDBM_check_backbuf(index)) {
+                               BM_Select_Face(em->bm, efa, select);
                        }
                }
        }
@@ -197,7 +204,7 @@ void EM_backbuf_checkAndSelectTFaces(Mesh *me, int select)
 
        if (mface) {
                for(a=1; a<=me->totface; a++, mface++) {
-                       if(EM_check_backbuf(a)) {
+                       if(EDBM_check_backbuf(a)) {
                                mface->flag = select?(mface->flag|ME_FACE_SEL):(mface->flag&~ME_FACE_SEL);
                        }
                }
@@ -405,53 +412,52 @@ void lasso_select_boundbox(rcti *rect, short mcords[][2], short moves)
        }
 }
 
-static void do_lasso_select_mesh__doSelectVert(void *userData, EditVert *eve, int x, int y, int index)
+static void do_lasso_select_mesh__doSelectVert(void *userData, BMVert *eve, int x, int y, int index)
 {
        struct { ViewContext vc; rcti *rect; short (*mcords)[2], moves, select, pass, done; } *data = userData;
 
        if (BLI_in_rcti(data->rect, x, y) && lasso_inside(data->mcords, data->moves, x, y)) {
-               eve->f = data->select?(eve->f|1):(eve->f&~1);
+               BM_Select_Vert(data->vc.em->bm, eve, data->select);
        }
 }
-static void do_lasso_select_mesh__doSelectEdge(void *userData, EditEdge *eed, int x0, int y0, int x1, int y1, int index)
+static void do_lasso_select_mesh__doSelectEdge(void *userData, BMEdge *eed, int x0, int y0, int x1, int y1, int index)
 {
        struct { ViewContext vc; rcti *rect; short (*mcords)[2], moves, select, pass, done; } *data = userData;
 
-       if (EM_check_backbuf(em_solidoffs+index)) {
+       if (EM_check_backbuf(bm_solidoffs+index)) {
                if (data->pass==0) {
                        if (    edge_fully_inside_rect(data->rect, x0, y0, x1, y1)  &&
                                        lasso_inside(data->mcords, data->moves, x0, y0) &&
                                        lasso_inside(data->mcords, data->moves, x1, y1)) {
-                               EM_select_edge(eed, data->select);
+                               BM_Select_Edge(data->vc.em->bm, eed, data->select);
                                data->done = 1;
                        }
                } else {
                        if (lasso_inside_edge(data->mcords, data->moves, x0, y0, x1, y1)) {
-                               EM_select_edge(eed, data->select);
+                               BM_Select_Edge(data->vc.em->bm, eed, data->select);
                        }
                }
        }
 }
-static void do_lasso_select_mesh__doSelectFace(void *userData, EditFace *efa, int x, int y, int index)
+static void do_lasso_select_mesh__doSelectFace(void *userData, BMFace *efa, int x, int y, int index)
 {
        struct { ViewContext vc; rcti *rect; short (*mcords)[2], moves, select, pass, done; } *data = userData;
 
        if (BLI_in_rcti(data->rect, x, y) && lasso_inside(data->mcords, data->moves, x, y)) {
-               EM_select_face_fgon(data->vc.em, efa, data->select);
+               BM_Select_Face(data->vc.em->bm, efa, data->select);
        }
 }
 
 static void do_lasso_select_mesh(ViewContext *vc, short mcords[][2], short moves, short select)
 {
        struct { ViewContext vc; rcti *rect; short (*mcords)[2], moves, select, pass, done; } data;
-       ToolSettings *ts= vc->scene->toolsettings;
        rcti rect;
        int bbsel;
        
        lasso_select_boundbox(&rect, mcords, moves);
        
        /* set editmesh */
-       vc->em= ((Mesh *)vc->obedit->data)->edit_mesh;
+       vc->em= ((Mesh *)vc->obedit->data)->edit_btmesh;
 
        data.vc= *vc;
        data.rect = &rect;
@@ -464,14 +470,14 @@ static void do_lasso_select_mesh(ViewContext *vc, short mcords[][2], short moves
        bbsel= EM_mask_init_backbuf_border(vc, mcords, moves, rect.xmin, rect.ymin, rect.xmax, rect.ymax);
        ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d); /* for foreach's screen/vert projection */
        
-       if(ts->selectmode & SCE_SELECT_VERTEX) {
+       if(vc->scene->toolsettings->selectmode & SCE_SELECT_VERTEX) {
                if (bbsel) {
                        EM_backbuf_checkAndSelectVerts(vc->em, select);
                } else {
                        mesh_foreachScreenVert(vc, do_lasso_select_mesh__doSelectVert, &data, 1);
                }
        }
-       if(ts->selectmode & SCE_SELECT_EDGE) {
+       if(vc->scene->toolsettings->selectmode & SCE_SELECT_EDGE) {
                        /* Does both bbsel and non-bbsel versions (need screen cos for both) */
 
                data.pass = 0;
@@ -483,7 +489,7 @@ static void do_lasso_select_mesh(ViewContext *vc, short mcords[][2], short moves
                }
        }
        
-       if(ts->selectmode & SCE_SELECT_FACE) {
+       if(vc->scene->toolsettings->selectmode & SCE_SELECT_FACE) {
                if (bbsel) {
                        EM_backbuf_checkAndSelectFaces(vc->em, select);
                } else {
@@ -492,7 +498,7 @@ static void do_lasso_select_mesh(ViewContext *vc, short mcords[][2], short moves
        }
        
        EM_free_backbuf();
-       EM_selectmode_flush(vc->em);    
+       EDBM_selectmode_flush(vc->em);  
 }
 
 #if 0
@@ -661,7 +667,7 @@ static void do_lasso_select_facemode(ViewContext *vc, short mcords[][2], short m
        if(me==NULL || me->mtface==NULL) return;
        if(me->totface==0) return;
        
-       em_vertoffs= me->totface+1;     /* max index array */
+       bm_vertoffs= me->totface+1;     /* max index array */
        
        lasso_select_boundbox(&rect, mcords, moves);
        EM_mask_init_backbuf_border(vc, mcords, moves, rect.xmin, rect.ymin, rect.xmax, rect.ymax);
@@ -720,18 +726,24 @@ void view3d_lasso_select(bContext *C, ViewContext *vc, short mcords[][2], short
        }
        else { /* Edit Mode */
                if(vc->obedit->type==OB_MESH)
-                       do_lasso_select_mesh(vc, mcords, moves, select);
+               do_lasso_select_mesh(vc, mcords, moves, select);
                else if(vc->obedit->type==OB_CURVE || vc->obedit->type==OB_SURF) 
-                       do_lasso_select_curve(vc, mcords, moves, select);
-               else if(vc->obedit->type==OB_LATTICE) 
-                       do_lasso_select_lattice(vc, mcords, moves, select);
-               else if(vc->obedit->type==OB_ARMATURE)
-                       do_lasso_select_armature(vc, mcords, moves, select);
+               do_lasso_select_curve(vc, mcords, moves, select);
+       else if(vc->obedit->type==OB_LATTICE) 
+               do_lasso_select_lattice(vc, mcords, moves, select);
+       else if(vc->obedit->type==OB_ARMATURE)
+               do_lasso_select_armature(vc, mcords, moves, select);
        
                WM_event_add_notifier(C, NC_GEOM|ND_SELECT, vc->obedit->data);
        }
 }
 
+static EnumPropertyItem lasso_select_types[] = {
+       {0, "SELECT", 0, "Select", ""},
+       {1, "DESELECT", 0, "Deselect", ""},
+       {0, NULL, 0, NULL, NULL}
+};
+
 
 /* lasso operator gives properties, but since old code works
    with short array we convert */
@@ -758,7 +770,7 @@ static int view3d_lasso_select_exec(bContext *C, wmOperator *op)
                /* setup view context for argument to callbacks */
                view3d_set_viewcontext(C, &vc);
                
-               select= !RNA_boolean_get(op->ptr, "deselect");
+               select= RNA_enum_is_equal(C, op->ptr, "type", "SELECT");
                view3d_lasso_select(C, &vc, mcords, i, select);
                
                return OPERATOR_FINISHED;
@@ -781,7 +793,7 @@ void VIEW3D_OT_select_lasso(wmOperatorType *ot)
        ot->flag= OPTYPE_UNDO;
        
        RNA_def_collection_runtime(ot->srna, "path", &RNA_OperatorMousePath, "Path", "");
-       RNA_def_boolean(ot->srna, "deselect", 0, "Deselect", "Deselect rather than select items.");
+       RNA_def_enum(ot->srna, "type", lasso_select_types, 0, "Type", "");
 }
 
 
@@ -1289,43 +1301,47 @@ static void do_lattice_box_select(ViewContext *vc, rcti *rect, int select)
        lattice_foreachScreenVert(vc, do_lattice_box_select__doSelect, &data);
 }
 
-static void do_mesh_box_select__doSelectVert(void *userData, EditVert *eve, int x, int y, int index)
+static void do_mesh_box_select__doSelectVert(void *userData, BMVert *eve, int x, int y, int index)
 {
        struct { ViewContext vc; rcti *rect; short select, pass, done; } *data = userData;
 
        if (BLI_in_rcti(data->rect, x, y)) {
-               eve->f = data->select?(eve->f|1):(eve->f&~1);
+               BM_Select_Vert(data->vc.em->bm, eve, data->select);
        }
 }
-static void do_mesh_box_select__doSelectEdge(void *userData, EditEdge *eed, int x0, int y0, int x1, int y1, int index)
+static void do_mesh_box_select__doSelectEdge(void *userData, BMEdge *eed, int x0, int y0, int x1, int y1, int index)
 {
        struct { ViewContext vc; rcti *rect; short select, pass, done; } *data = userData;
 
-       if(EM_check_backbuf(em_solidoffs+index)) {
+       if(EM_check_backbuf(bm_solidoffs+index)) {
                if (data->pass==0) {
                        if (edge_fully_inside_rect(data->rect, x0, y0, x1, y1)) {
-                               EM_select_edge(eed, data->select);
+                               BM_Select_Edge(data->vc.em->bm, eed, data->select);
                                data->done = 1;
                        }
                } else {
                        if (edge_inside_rect(data->rect, x0, y0, x1, y1)) {
-                               EM_select_edge(eed, data->select);
+                               BM_Select_Edge(data->vc.em->bm, eed, data->select);
                        }
                }
        }
 }
-static void do_mesh_box_select__doSelectFace(void *userData, EditFace *efa, int x, int y, int index)
+
+static void 
+do_mesh_box_select__doSelectFace(void *userData, BMFace
+                               *efa, int x, int y,
+                               int index)
+
 {
        struct { ViewContext vc; rcti *rect; short select, pass, done; } *data = userData;
 
        if (BLI_in_rcti(data->rect, x, y)) {
-               EM_select_face_fgon(data->vc.em, efa, data->select);
+               BM_Select_Face(data->vc.em->bm, efa, data->select);
        }
 }
 static void do_mesh_box_select(ViewContext *vc, rcti *rect, int select)
 {
        struct { ViewContext vc; rcti *rect; short select, pass, done; } data;
-       ToolSettings *ts= vc->scene->toolsettings;
        int bbsel;
        
        data.vc= *vc;
@@ -1334,17 +1350,17 @@ static void do_mesh_box_select(ViewContext *vc, rcti *rect, int select)
        data.pass = 0;
        data.done = 0;
 
-       bbsel= EM_init_backbuf_border(vc, rect->xmin, rect->ymin, rect->xmax, rect->ymax);
+       bbsel= EDBM_init_backbuf_border(vc, rect->xmin, rect->ymin, rect->xmax, rect->ymax);
        ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d); /* for foreach's screen/vert projection */
 
-       if(ts->selectmode & SCE_SELECT_VERTEX) {
+       if(vc->scene->toolsettings->selectmode & SCE_SELECT_VERTEX) {
                if (bbsel) {
                        EM_backbuf_checkAndSelectVerts(vc->em, select);
                } else {
                        mesh_foreachScreenVert(vc, do_mesh_box_select__doSelectVert, &data, 1);
                }
        }
-       if(ts->selectmode & SCE_SELECT_EDGE) {
+       if(vc->scene->toolsettings->selectmode & SCE_SELECT_EDGE) {
                        /* Does both bbsel and non-bbsel versions (need screen cos for both) */
 
                data.pass = 0;
@@ -1356,7 +1372,7 @@ static void do_mesh_box_select(ViewContext *vc, rcti *rect, int select)
                }
        }
        
-       if(ts->selectmode & SCE_SELECT_FACE) {
+       if(vc->scene->toolsettings->selectmode & SCE_SELECT_FACE) {
                if(bbsel) {
                        EM_backbuf_checkAndSelectFaces(vc->em, select);
                } else {
@@ -1366,7 +1382,7 @@ static void do_mesh_box_select(ViewContext *vc, rcti *rect, int select)
        
        EM_free_backbuf();
                
-       EM_selectmode_flush(vc->em);
+       EDBM_selectmode_flush(vc->em);
 }
 
 static int view3d_borderselect_exec(bContext *C, wmOperator *op)
@@ -1406,7 +1422,7 @@ static int view3d_borderselect_exec(bContext *C, wmOperator *op)
        if(obedit) {
                if(obedit->type==OB_MESH) {
                        Mesh *me= obedit->data;
-                       vc.em= me->edit_mesh;
+                       vc.em= me->edit_btmesh;
                        do_mesh_box_select(&vc, &rect, selecting);
 //                     if (EM_texFaceCheck())
                        WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit->data);
@@ -1492,7 +1508,6 @@ static int view3d_borderselect_exec(bContext *C, wmOperator *op)
                                }
                        }
                        
-                       ED_armature_sync_selection(arm->edbo);
                }
                else if(obedit->type==OB_LATTICE) {
                        do_lattice_box_select(&vc, &rect, selecting);
@@ -1578,6 +1593,11 @@ static int view3d_borderselect_exec(bContext *C, wmOperator *op)
 
 
 /* *****************Selection Operators******************* */
+static EnumPropertyItem prop_select_types[] = {
+       {0, "EXCLUSIVE", 0, "Exclusive", ""},
+       {1, "EXTEND", 0, "Extend", ""},
+       {0, NULL, 0, NULL, NULL}
+};
 
 /* ****** Border Select ****** */
 void VIEW3D_OT_select_border(wmOperatorType *ot)
@@ -1607,8 +1627,8 @@ void VIEW3D_OT_select_border(wmOperatorType *ot)
 static int view3d_select_invoke(bContext *C, wmOperator *op, wmEvent *event)
 {
        Object *obedit= CTX_data_edit_object(C);
-       Object *obact= CTX_data_active_object(C);
        short extend= RNA_boolean_get(op->ptr, "extend");
+       Object *obact= CTX_data_active_object(C);
        short center= RNA_boolean_get(op->ptr, "center");
        short enumerate= RNA_boolean_get(op->ptr, "enumerate");
 
@@ -1661,38 +1681,37 @@ void VIEW3D_OT_select(wmOperatorType *ot)
 
 /* -------------------- circle select --------------------------------------------- */
 
-static void mesh_circle_doSelectVert(void *userData, EditVert *eve, int x, int y, int index)
+static void mesh_circle_doSelectVert(void *userData, BMVert *eve, int x, int y, int index)
 {
        struct {ViewContext *vc; short select, mval[2]; float radius; } *data = userData;
        int mx = x - data->mval[0], my = y - data->mval[1];
        float r = sqrt(mx*mx + my*my);
 
        if (r<=data->radius) {
-               eve->f = data->select?(eve->f|1):(eve->f&~1);
+               BM_Select_Vert(data->vc->em->bm, eve, data->select);
        }
 }
-static void mesh_circle_doSelectEdge(void *userData, EditEdge *eed, int x0, int y0, int x1, int y1, int index)
+static void mesh_circle_doSelectEdge(void *userData, BMEdge *eed, int x0, int y0, int x1, int y1, int index)
 {
        struct {ViewContext *vc; short select, mval[2]; float radius; } *data = userData;
 
        if (edge_inside_circle(data->mval[0], data->mval[1], (short) data->radius, x0, y0, x1, y1)) {
-               EM_select_edge(eed, data->select);
+               BM_Select_Edge(data->vc->em->bm, eed, data->select);
        }
 }
-static void mesh_circle_doSelectFace(void *userData, EditFace *efa, int x, int y, int index)
+static void mesh_circle_doSelectFace(void *userData, BMFace *efa, int x, int y, int index)
 {
        struct {ViewContext *vc; short select, mval[2]; float radius; } *data = userData;
        int mx = x - data->mval[0], my = y - data->mval[1];
        float r = sqrt(mx*mx + my*my);
        
        if (r<=data->radius) {
-               EM_select_face_fgon(data->vc->em, efa, data->select);
+               BM_Select_Face(data->vc->em->bm, efa, data->select);
        }
 }
 
 static void mesh_circle_select(ViewContext *vc, int selecting, short *mval, float rad)
 {
-       ToolSettings *ts= vc->scene->toolsettings;
        int bbsel;
        Object *ob= vc->obact;
        
@@ -1700,11 +1719,11 @@ static void mesh_circle_select(ViewContext *vc, int selecting, short *mval, floa
                Mesh *me = ob?ob->data:NULL;
 
                if (me) {
-                       em_vertoffs= me->totface+1;     /* max index array */
+                       bm_vertoffs= me->totface+1;     /* max index array */
 
-                       bbsel= EM_init_backbuf_circle(vc, mval[0], mval[1], (short)(rad+1.0));
-                       EM_backbuf_checkAndSelectTFaces(me, selecting==LEFTMOUSE);
-                       EM_free_backbuf();
+                       //bbsel= EDBM_init_backbuf_circle(vc, mval[0], mval[1], (short)(rad+1.0));
+                       //BMESH_TODO EM_backbuf_checkAndSelectTFaces(me, selecting==LEFTMOUSE);
+                       //EDBM_free_backbuf();
 
 // XXX                 object_tface_flags_changed(OBACT, 0);
                }
@@ -1712,18 +1731,18 @@ static void mesh_circle_select(ViewContext *vc, int selecting, short *mval, floa
        else {
                struct {ViewContext *vc; short select, mval[2]; float radius; } data;
                
-               bbsel= EM_init_backbuf_circle(vc, mval[0], mval[1], (short)(rad+1.0));
+               bbsel= EDBM_init_backbuf_circle(vc, mval[0], mval[1], (short)(rad+1.0));
+               vc->em= ((Mesh *)vc->obedit->data)->edit_btmesh;
                ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d); /* for foreach's screen/vert projection */
 
-               vc->em= ((Mesh *)vc->obedit->data)->edit_mesh;
-
                data.vc = vc;
                data.select = selecting;
                data.mval[0] = mval[0];
                data.mval[1] = mval[1];
                data.radius = rad;
+               data.vc = vc;
 
-               if(ts->selectmode & SCE_SELECT_VERTEX) {
+               if(vc->scene->toolsettings->selectmode & SCE_SELECT_VERTEX) {
                        if(bbsel) {
                                EM_backbuf_checkAndSelectVerts(vc->em, selecting==LEFTMOUSE);
                        } else {
@@ -1731,7 +1750,7 @@ static void mesh_circle_select(ViewContext *vc, int selecting, short *mval, floa
                        }
                }
 
-               if(ts->selectmode & SCE_SELECT_EDGE) {
+               if(vc->scene->toolsettings->selectmode & SCE_SELECT_EDGE) {
                        if (bbsel) {
                                EM_backbuf_checkAndSelectEdges(vc->em, selecting==LEFTMOUSE);
                        } else {
@@ -1739,7 +1758,7 @@ static void mesh_circle_select(ViewContext *vc, int selecting, short *mval, floa
                        }
                }
                
-               if(ts->selectmode & SCE_SELECT_FACE) {
+               if(vc->scene->toolsettings->selectmode & SCE_SELECT_FACE) {
                        if(bbsel) {
                                EM_backbuf_checkAndSelectFaces(vc->em, selecting==LEFTMOUSE);
                        } else {
@@ -1747,8 +1766,8 @@ static void mesh_circle_select(ViewContext *vc, int selecting, short *mval, floa
                        }
                }
 
-               EM_free_backbuf();
-               EM_selectmode_flush(vc->em);
+               EDBM_free_backbuf();
+               EDBM_selectmode_flush(vc->em);
        }
 }