svn merge -r36603:36651 https://svn.blender.org/svnroot/bf-blender/trunk/blender...
[blender.git] / source / blender / editors / space_view3d / view3d_select.c
index c4999b961f04608fc14626a69a3670fb592a52ef..a9f8a3f075a8a4b90ca17cf5614bd0258df6876f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id$
+ * $Id: view3d_select.c 35106 2011-02-23 10:52:22Z jesterking $
  *
  * ***** BEGIN GPL LICENSE BLOCK *****
  *
@@ -57,7 +57,7 @@
 #include "BKE_context.h"
 #include "BKE_paint.h"
 #include "BKE_armature.h"
-
+#include "BKE_tessmesh.h"
 
 #include "BIF_gl.h"
 #include "BIF_glutil.h"
@@ -154,57 +154,63 @@ void view3d_get_transformation(ARegion *ar, RegionView3D *rv3d, Object *ob, bglM
 
 /* local prototypes */
 
-static void EM_backbuf_checkAndSelectVerts(EditMesh *em, int select)
+static void EDBM_backbuf_checkAndSelectVerts(BMEditMesh *em, int select)
 {
-       EditVert *eve;
-       int index= em_wireoffs;
+       BMVert *eve;
+       BMIter iter;
+       int index= bm_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);
+       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);
                        }
                }
        }
 }
 
-static void EM_backbuf_checkAndSelectEdges(EditMesh *em, int select)
+static void EDBM_backbuf_checkAndSelectEdges(BMEditMesh *em, int select)
 {
-       EditEdge *eed;
-       int index= em_solidoffs;
+       BMEdge *eed;
+       BMIter iter;
+       int index= bm_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);
+       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);
                        }
                }
        }
 }
 
-static void EM_backbuf_checkAndSelectFaces(EditMesh *em, int select)
+static void EDBM_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);
                        }
                }
        }
 }
 
-static void EM_backbuf_checkAndSelectTFaces(Mesh *me, int select)
+static void EDBM_backbuf_checkAndSelectTFaces(Mesh *me, int select)
 {
-       MFace *mface = me->mface;
+       MPoly *mpoly = me->mpoly;
        int a;
 
-       if (mface) {
-               for(a=1; a<=me->totface; a++, mface++) {
-                       if(EM_check_backbuf(a)) {
-                               mface->flag = select?(mface->flag|ME_FACE_SEL):(mface->flag&~ME_FACE_SEL);
+       if (mpoly) {
+               for(a=1; a<=me->totpoly; a++, mpoly++) {
+                       if(EDBM_check_backbuf(a)) {
+                               mpoly->flag = select?(mpoly->flag|ME_FACE_SEL):(mpoly->flag&~ME_FACE_SEL);
                        }
                }
        }
@@ -424,39 +430,39 @@ static void lasso_select_boundbox(rcti *rect, int mcords[][2], short moves)
        }
 }
 
-static void do_lasso_select_mesh__doSelectVert(void *userData, EditVert *eve, int x, int y, int UNUSED(index))
+static void do_lasso_select_mesh__doSelectVert(void *userData, BMVert *eve, int x, int y, int UNUSED(index))
 {
        struct { ViewContext vc; rcti *rect; int (*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(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; int (*mcords)[2], moves, select, pass, done; } *data = userData;
 
-       if (EM_check_backbuf(em_solidoffs+index)) {
+       if (EDBM_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(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(data->vc.em->bm, eed, data->select);
                        }
                }
        }
 }
-static void do_lasso_select_mesh__doSelectFace(void *userData, EditFace *efa, int x, int y, int UNUSED(index))
+static void do_lasso_select_mesh__doSelectFace(void *userData, BMFace *efa, int x, int y, int UNUSED(index))
 {
        struct { ViewContext vc; rcti *rect; int (*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(data->vc.em->bm, efa, data->select);
        }
 }
 
@@ -470,7 +476,7 @@ static void do_lasso_select_mesh(ViewContext *vc, int mcords[][2], short moves,
        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;
@@ -481,7 +487,7 @@ static void do_lasso_select_mesh(ViewContext *vc, int mcords[][2], short moves,
        data.pass = 0;
 
        if (extend == 0 && select)
-               EM_deselect_all(vc->em);
+               EDBM_clear_flag_all(vc->em, BM_SELECT);
 
        /* workaround: init mats first, EM_mask_init_backbuf_border can change
           view matrix to pixel space, breaking edge select with backbuf. fixes bug [#20936] */
@@ -490,11 +496,11 @@ static void do_lasso_select_mesh(ViewContext *vc, int mcords[][2], short moves,
        /* ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d) */
 
        glLoadMatrixf(vc->rv3d->viewmat);
-       bbsel= EM_mask_init_backbuf_border(vc, mcords, moves, rect.xmin, rect.ymin, rect.xmax, rect.ymax);
+       bbsel= EDBM_mask_init_backbuf_border(vc, mcords, moves, rect.xmin, rect.ymin, rect.xmax, rect.ymax);
        
        if(ts->selectmode & SCE_SELECT_VERTEX) {
                if (bbsel) {
-                       EM_backbuf_checkAndSelectVerts(vc->em, select);
+                       EDBM_backbuf_checkAndSelectVerts(vc->em, select);
                } else {
                        ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d); /* for foreach's screen/vert projection */
                        mesh_foreachScreenVert(vc, do_lasso_select_mesh__doSelectVert, &data, 1);
@@ -515,15 +521,15 @@ static void do_lasso_select_mesh(ViewContext *vc, int mcords[][2], short moves,
        
        if(ts->selectmode & SCE_SELECT_FACE) {
                if (bbsel) {
-                       EM_backbuf_checkAndSelectFaces(vc->em, select);
+                       EDBM_backbuf_checkAndSelectFaces(vc->em, select);
                } else {
                        ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d); /* for foreach's screen/vert projection */
                        mesh_foreachScreenFace(vc, do_lasso_select_mesh__doSelectFace, &data);
                }
        }
        
-       EM_free_backbuf();
-       EM_selectmode_flush(vc->em);    
+       EDBM_free_backbuf();
+       EDBM_selectmode_flush(vc->em);  
 }
 
 #if 0
@@ -742,14 +748,14 @@ static void do_lasso_select_paintface(ViewContext *vc, int mcords[][2], short mo
        if(extend==0 && select)
                paintface_deselect_all_visible(ob, SEL_DESELECT, FALSE); /* flush selection at the end */
 
-       em_vertoffs= me->totface+1;     /* max index array */
+       bm_vertoffs= me->totpoly+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);
+       EDBM_mask_init_backbuf_border(vc, mcords, moves, rect.xmin, rect.ymin, rect.xmax, rect.ymax);
        
-       EM_backbuf_checkAndSelectTFaces(me, select);
+       EDBM_backbuf_checkAndSelectTFaces(me, select);
 
-       EM_free_backbuf();
+       EDBM_free_backbuf();
 
        paintface_flush_flags(ob);
 }
@@ -1440,37 +1446,37 @@ static int do_lattice_box_select(ViewContext *vc, rcti *rect, int select, int ex
        return OPERATOR_FINISHED;
 }
 
-static void do_mesh_box_select__doSelectVert(void *userData, EditVert *eve, int x, int y, int UNUSED(index))
+static void do_mesh_box_select__doSelectVert(void *userData, BMVert *eve, int x, int y, int UNUSED(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(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(EDBM_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(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(data->vc.em->bm, eed, data->select);
                        }
                }
        }
 }
-static void do_mesh_box_select__doSelectFace(void *userData, EditFace *efa, int x, int y, int UNUSED(index))
+static void do_mesh_box_select__doSelectFace(void *userData, BMFace *efa, int x, int y, int UNUSED(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(data->vc.em->bm, efa, data->select);
        }
 }
 static int do_mesh_box_select(ViewContext *vc, rcti *rect, int select, int extend)
@@ -1486,7 +1492,7 @@ static int do_mesh_box_select(ViewContext *vc, rcti *rect, int select, int exten
        data.done = 0;
 
        if (extend == 0 && select)
-               EM_deselect_all(vc->em);
+               EDBM_clear_flag_all(vc->em, BM_SELECT);
 
        /* workaround: init mats first, EM_mask_init_backbuf_border can change
           view matrix to pixel space, breaking edge select with backbuf. fixes bug #20936 */
@@ -1496,11 +1502,11 @@ static int do_mesh_box_select(ViewContext *vc, rcti *rect, int select, int exten
        /* ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d) */
 
        glLoadMatrixf(vc->rv3d->viewmat);
-       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);
 
        if(ts->selectmode & SCE_SELECT_VERTEX) {
                if (bbsel) {
-                       EM_backbuf_checkAndSelectVerts(vc->em, select);
+                       EDBM_backbuf_checkAndSelectVerts(vc->em, select);
                } else {
                        ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d);
                        mesh_foreachScreenVert(vc, do_mesh_box_select__doSelectVert, &data, 1);
@@ -1520,16 +1526,16 @@ static int do_mesh_box_select(ViewContext *vc, rcti *rect, int select, int exten
        
        if(ts->selectmode & SCE_SELECT_FACE) {
                if(bbsel) {
-                       EM_backbuf_checkAndSelectFaces(vc->em, select);
+                       EDBM_backbuf_checkAndSelectFaces(vc->em, select);
                } else {
                        ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d);
                        mesh_foreachScreenFace(vc, do_mesh_box_select__doSelectFace, &data);
                }
        }
        
-       EM_free_backbuf();
+       EDBM_free_backbuf();
                
-       EM_selectmode_flush(vc->em);
+       EDBM_selectmode_flush(vc->em);
        
        return OPERATOR_FINISHED;
 }
@@ -1763,7 +1769,7 @@ static int view3d_borderselect_exec(bContext *C, wmOperator *op)
        if(vc.obedit) {
                switch(vc.obedit->type) {
                case OB_MESH:
-                       vc.em= ((Mesh *)vc.obedit->data)->edit_mesh;
+                       vc.em= ((Mesh *)vc.obedit->data)->edit_btmesh;
                        ret= do_mesh_box_select(&vc, &rect, select, extend);
 //                     if (EM_texFaceCheck())
                        if(ret & OPERATOR_FINISHED) {
@@ -1903,32 +1909,32 @@ void VIEW3D_OT_select(wmOperatorType *ot)
 
 /* -------------------- circle select --------------------------------------------- */
 
-static void mesh_circle_doSelectVert(void *userData, EditVert *eve, int x, int y, int UNUSED(index))
+static void mesh_circle_doSelectVert(void *userData, BMVert *eve, int x, int y, int UNUSED(index))
 {
        struct {ViewContext *vc; short select; int 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(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 UNUSED(index))
+static void mesh_circle_doSelectEdge(void *userData, BMEdge *eed, int x0, int y0, int x1, int y1, int UNUSED(index))
 {
        struct {ViewContext *vc; short select; int 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(data->vc->em->bm, eed, data->select);
        }
 }
-static void mesh_circle_doSelectFace(void *userData, EditFace *efa, int x, int y, int UNUSED(index))
+static void mesh_circle_doSelectFace(void *userData, BMFace *efa, int x, int y, int UNUSED(index))
 {
        struct {ViewContext *vc; short select; int 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(data->vc->em->bm, efa, data->select);
        }
 }
 
@@ -1938,10 +1944,10 @@ static void mesh_circle_select(ViewContext *vc, int select, const int mval[2], f
        int bbsel;
        struct {ViewContext *vc; short select; int mval[2]; float radius; } data;
        
-       bbsel= EM_init_backbuf_circle(vc, mval[0], mval[1], (short)(rad+1.0f));
+       bbsel= EDBM_init_backbuf_circle(vc, mval[0], mval[1], (short)(rad+1.0));
        ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d); /* for foreach's screen/vert projection */
 
-       vc->em= ((Mesh *)vc->obedit->data)->edit_mesh;
+       vc->em= ((Mesh *)vc->obedit->data)->edit_btmesh;
 
        data.vc = vc;
        data.select = select;
@@ -1951,7 +1957,7 @@ static void mesh_circle_select(ViewContext *vc, int select, const int mval[2], f
 
        if(ts->selectmode & SCE_SELECT_VERTEX) {
                if(bbsel) {
-                       EM_backbuf_checkAndSelectVerts(vc->em, select==LEFTMOUSE);
+                       EDBM_backbuf_checkAndSelectVerts(vc->em, select==LEFTMOUSE);
                } else {
                        mesh_foreachScreenVert(vc, mesh_circle_doSelectVert, &data, 1);
                }
@@ -1959,7 +1965,7 @@ static void mesh_circle_select(ViewContext *vc, int select, const int mval[2], f
 
        if(ts->selectmode & SCE_SELECT_EDGE) {
                if (bbsel) {
-                       EM_backbuf_checkAndSelectEdges(vc->em, select==LEFTMOUSE);
+                       EDBM_backbuf_checkAndSelectEdges(vc->em, select==LEFTMOUSE);
                } else {
                        mesh_foreachScreenEdge(vc, mesh_circle_doSelectEdge, &data, 0);
                }
@@ -1967,14 +1973,14 @@ static void mesh_circle_select(ViewContext *vc, int select, const int mval[2], f
        
        if(ts->selectmode & SCE_SELECT_FACE) {
                if(bbsel) {
-                       EM_backbuf_checkAndSelectFaces(vc->em, select==LEFTMOUSE);
+                       EDBM_backbuf_checkAndSelectFaces(vc->em, select==LEFTMOUSE);
                } else {
                        mesh_foreachScreenFace(vc, mesh_circle_doSelectFace, &data);
                }
        }
 
-       EM_free_backbuf();
-       EM_selectmode_flush(vc->em);
+       EDBM_free_backbuf();
+       EDBM_selectmode_flush(vc->em);
 }
 
 static void paint_facesel_circle_select(ViewContext *vc, int select, const int mval[2], float rad)
@@ -1984,11 +1990,11 @@ static void paint_facesel_circle_select(ViewContext *vc, int select, const int m
        int bbsel;
 
        if (me) {
-               em_vertoffs= me->totface+1;     /* max index array */
+               bm_vertoffs= me->totpoly+1;     /* max index array */
 
-               bbsel= EM_init_backbuf_circle(vc, mval[0], mval[1], (short)(rad+1.0f));
-               EM_backbuf_checkAndSelectTFaces(me, select==LEFTMOUSE);
-               EM_free_backbuf();
+               bbsel= EDBM_init_backbuf_circle(vc, mval[0], mval[1], (short)(rad+1.0));
+               EDBM_backbuf_checkAndSelectTFaces(me, select==LEFTMOUSE);
+               EDBM_free_backbuf();
        }
 }