2.5
[blender.git] / source / blender / editors / space_view3d / view3d_select.c
index 3b3eba41ce8d87309b73989612412653c9c9bd58..33ac9a649682fcf3a020118f1c9f367b76a9915d 100644 (file)
@@ -75,6 +75,7 @@
 #include "RNA_access.h"
 #include "RNA_define.h"
 
+#include "ED_mesh.h"
 #include "ED_object.h"
 #include "ED_screen.h"
 #include "ED_types.h"
 
 #include "view3d_intern.h"     // own include
 
+
+static void view3d_set_viewcontext(bContext *C, ViewContext *vc)
+{
+       memset(vc, 0, sizeof(ViewContext));
+       vc->ar= CTX_wm_region(C);
+       vc->scene= CTX_data_scene(C);
+       vc->v3d= (View3D *)CTX_wm_space_data(C);
+       vc->obact= CTX_data_active_object(C);
+       vc->obedit= CTX_data_edit_object(C); 
+}
+
 /* ********************** view3d_select: selection manipulations ********************* */
 
 /* XXX to solve *************** */
-unsigned int em_vertoffs=0, em_solidoffs=0, em_wireoffs=0;
-int EM_check_backbuf() {return 0;}
-void EM_select_edge() {}
-void EM_select_face_fgon() {}
-int EM_mask_init_backbuf_border() {return 0;}
-void EM_free_backbuf() {}
-void EM_selectmode_flush() {}
-void EM_deselect_flush() {}
 static void BIF_undo_push() {}
-int EM_texFaceCheck() {return 0;}
-int EM_init_backbuf_border() {return 0;}
-int EM_init_backbuf_circle() {return 0;}
-
 /* XXX end ********************* */
 
 /* local prototypes */
@@ -143,7 +143,7 @@ void EM_backbuf_checkAndSelectFaces(EditMesh *em, int select)
        for(efa= em->faces.first; efa; efa= efa->next, index++) {
                if(efa->h==0) {
                        if(EM_check_backbuf(index)) {
-                               EM_select_face_fgon(efa, select);
+                               EM_select_face_fgon(em, efa, select);
                        }
                }
        }
@@ -297,8 +297,9 @@ int lasso_inside_edge(short mcords[][2], short moves, int x0, int y0, int x1, in
 /* warning; lasso select with backbuffer-check draws in backbuf with persp(PERSP_WIN) 
    and returns with persp(PERSP_VIEW). After lasso select backbuf is not OK
 */
-static void do_lasso_select_pose(ARegion *ar, View3D *v3d, Object *ob, short mcords[][2], short moves, short select)
+static void do_lasso_select_pose(ViewContext *vc, short mcords[][2], short moves, short select)
 {
+       Object *ob= vc->obact;
        bPoseChannel *pchan;
        float vec[3];
        short sco1[2], sco2[2];
@@ -308,10 +309,10 @@ static void do_lasso_select_pose(ARegion *ar, View3D *v3d, Object *ob, short mco
        for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
                VECCOPY(vec, pchan->pose_head);
                Mat4MulVecfl(ob->obmat, vec);
-               project_short(ar, v3d, vec, sco1);
+               project_short(vc->ar, vc->v3d, vec, sco1);
                VECCOPY(vec, pchan->pose_tail);
                Mat4MulVecfl(ob->obmat, vec);
-               project_short(ar, v3d, vec, sco2);
+               project_short(vc->ar, vc->v3d, vec, sco2);
                
                if(lasso_inside_edge(mcords, moves, sco1[0], sco1[1], sco2[0], sco2[1])) {
                        if(select) pchan->bone->flag |= BONE_SELECTED;
@@ -321,13 +322,13 @@ static void do_lasso_select_pose(ARegion *ar, View3D *v3d, Object *ob, short mco
 }
 
 
-static void do_lasso_select_objects(Scene *scene, ARegion *ar, View3D *v3d, short mcords[][2], short moves, short select)
+static void do_lasso_select_objects(ViewContext *vc, short mcords[][2], short moves, short select)
 {
        Base *base;
        
-       for(base= scene->base.first; base; base= base->next) {
-               if(base->lay & v3d->lay) {
-                       project_short(ar, v3d, base->object->obmat[3], &base->sx);
+       for(base= vc->scene->base.first; base; base= base->next) {
+               if(base->lay & vc->v3d->lay) {
+                       project_short(vc->ar, vc->v3d, base->object->obmat[3], &base->sx);
                        if(lasso_inside(mcords, moves, base->sx, base->sy)) {
                                
                                if(select) ED_base_object_select(base, BA_SELECT);
@@ -335,7 +336,7 @@ static void do_lasso_select_objects(Scene *scene, ARegion *ar, View3D *v3d, shor
                                base->object->flag= base->flag;
                        }
                        if(base->object->flag & OB_POSEMODE) {
-                               do_lasso_select_pose(ar, v3d, base->object, mcords, moves, select);
+                               do_lasso_select_pose(vc, mcords, moves, select);
                        }
                }
        }
@@ -358,7 +359,7 @@ 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)
 {
-       struct { rcti *rect; short (*mcords)[2], moves, select, pass, done; } *data = userData;
+       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);
@@ -366,7 +367,7 @@ static void do_lasso_select_mesh__doSelectVert(void *userData, EditVert *eve, in
 }
 static void do_lasso_select_mesh__doSelectEdge(void *userData, EditEdge *eed, int x0, int y0, int x1, int y1, int index)
 {
-       struct { rcti *rect; short (*mcords)[2], moves, select, pass, done; } *data = userData;
+       struct { ViewContext vc; rcti *rect; short (*mcords)[2], moves, select, pass, done; } *data = userData;
 
        if (EM_check_backbuf(em_solidoffs+index)) {
                if (data->pass==0) {
@@ -385,22 +386,25 @@ static void do_lasso_select_mesh__doSelectEdge(void *userData, EditEdge *eed, in
 }
 static void do_lasso_select_mesh__doSelectFace(void *userData, EditFace *efa, int x, int y, int index)
 {
-       struct { rcti *rect; short (*mcords)[2], moves, select, pass, done; } *data = userData;
+       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(efa, data->select);
+               EM_select_face_fgon(data->vc.em, efa, data->select);
        }
 }
 
-static void do_lasso_select_mesh(Scene *scene, ARegion *ar, View3D *v3d, short mcords[][2], short moves, short select)
+static void do_lasso_select_mesh(ViewContext *vc, short mcords[][2], short moves, short select)
 {
-       struct { rcti *rect; short (*mcords)[2], moves, select, pass, done; } data;
-       EditMesh *em = G.editMesh;
+       struct { ViewContext vc; rcti *rect; short (*mcords)[2], moves, select, pass, done; } data;
        rcti rect;
        int bbsel;
        
        lasso_select_boundbox(&rect, mcords, moves);
        
+       /* set editmesh */
+       vc->em= ((Mesh *)vc->obedit->data)->edit_mesh;
+
+       data.vc= *vc;
        data.rect = ▭
        data.mcords = mcords;
        data.moves = moves;
@@ -408,44 +412,43 @@ static void do_lasso_select_mesh(Scene *scene, ARegion *ar, View3D *v3d, short m
        data.done = 0;
        data.pass = 0;
 
-       bbsel= EM_mask_init_backbuf_border(mcords, moves, rect.xmin, rect.ymin, rect.xmax, rect.ymax);
+       bbsel= EM_mask_init_backbuf_border(vc, mcords, moves, rect.xmin, rect.ymin, rect.xmax, rect.ymax);
        
-       if(scene->selectmode & SCE_SELECT_VERTEX) {
+       if(vc->scene->selectmode & SCE_SELECT_VERTEX) {
                if (bbsel) {
-                       EM_backbuf_checkAndSelectVerts(em, select);
+                       EM_backbuf_checkAndSelectVerts(vc->em, select);
                } else {
-                       mesh_foreachScreenVert(ar, v3d, do_lasso_select_mesh__doSelectVert, &data, 1);
+                       mesh_foreachScreenVert(vc, do_lasso_select_mesh__doSelectVert, &data, 1);
                }
        }
-       if(scene->selectmode & SCE_SELECT_EDGE) {
+       if(vc->scene->selectmode & SCE_SELECT_EDGE) {
                        /* Does both bbsel and non-bbsel versions (need screen cos for both) */
 
                data.pass = 0;
-               mesh_foreachScreenEdge(ar, v3d, do_lasso_select_mesh__doSelectEdge, &data, 0);
+               mesh_foreachScreenEdge(vc, do_lasso_select_mesh__doSelectEdge, &data, 0);
 
                if (data.done==0) {
                        data.pass = 1;
-                       mesh_foreachScreenEdge(ar, v3d, do_lasso_select_mesh__doSelectEdge, &data, 0);
+                       mesh_foreachScreenEdge(vc, do_lasso_select_mesh__doSelectEdge, &data, 0);
                }
        }
        
-       if(scene->selectmode & SCE_SELECT_FACE) {
+       if(vc->scene->selectmode & SCE_SELECT_FACE) {
                if (bbsel) {
-                       EM_backbuf_checkAndSelectFaces(em, select);
+                       EM_backbuf_checkAndSelectFaces(vc->em, select);
                } else {
-                       mesh_foreachScreenFace(ar, v3d, do_lasso_select_mesh__doSelectFace, &data);
+                       mesh_foreachScreenFace(vc, do_lasso_select_mesh__doSelectFace, &data);
                }
        }
        
        EM_free_backbuf();
-       EM_selectmode_flush();  
+       EM_selectmode_flush(vc->em);    
 }
 
 #if 0
 /* this is an exception in that its the only lasso that dosnt use the 3d view (uses space image view) */
 static void do_lasso_select_mesh_uv(short mcords[][2], short moves, short select)
 {
-       EditMesh *em = G.editMesh;
        EditFace *efa;
        MTFace *tf;
        int screenUV[2], nverts, i, ok = 1;
@@ -493,8 +496,8 @@ static void do_lasso_select_mesh_uv(short mcords[][2], short moves, short select
                }
        }
        if (ok && G.sima->flag & SI_SYNC_UVSEL) {
-               if (select) EM_select_flush();
-               else            EM_deselect_flush();
+               if (select) EM_select_flush(vc->em);
+               else            EM_deselect_flush(vc->em);
        }
 }
 #endif
@@ -523,15 +526,16 @@ static void do_lasso_select_curve__doSelect(void *userData, Nurb *nu, BPoint *bp
        }
 }
 
-static void do_lasso_select_curve(ARegion *ar, View3D *v3d, short mcords[][2], short moves, short select)
+static void do_lasso_select_curve(ViewContext *vc, short mcords[][2], short moves, short select)
 {
        struct { short (*mcords)[2]; short moves; short select; } data;
 
+       /* set vc->editnurb */
        data.mcords = mcords;
        data.moves = moves;
        data.select = select;
 
-       nurbs_foreachScreenVert(ar, v3d, do_lasso_select_curve__doSelect, &data);
+       nurbs_foreachScreenVert(vc, do_lasso_select_curve__doSelect, &data);
 }
 
 static void do_lasso_select_lattice__doSelect(void *userData, BPoint *bp, int x, int y)
@@ -542,31 +546,34 @@ static void do_lasso_select_lattice__doSelect(void *userData, BPoint *bp, int x,
                bp->f1 = data->select?(bp->f1|SELECT):(bp->f1&~SELECT);
        }
 }
-static void do_lasso_select_lattice(short mcords[][2], short moves, short select)
+static void do_lasso_select_lattice(ViewContext *vc, short mcords[][2], short moves, short select)
 {
        struct { short (*mcords)[2]; short moves; short select; } data;
 
+       /* set editdata in vc */
        data.mcords = mcords;
        data.moves = moves;
        data.select = select;
 
-       lattice_foreachScreenVert(do_lasso_select_lattice__doSelect, &data);
+       lattice_foreachScreenVert(vc, do_lasso_select_lattice__doSelect, &data);
 }
 
-static void do_lasso_select_armature(ARegion *ar, View3D *v3d, short mcords[][2], short moves, short select)
+static void do_lasso_select_armature(ViewContext *vc, short mcords[][2], short moves, short select)
 {
        EditBone *ebone;
        float vec[3];
        short sco1[2], sco2[2], didpoint;
        
+       /* set editdata in vc */
+       
        for (ebone=G.edbo.first; ebone; ebone=ebone->next) {
 
                VECCOPY(vec, ebone->head);
                Mat4MulVecfl(G.obedit->obmat, vec);
-               project_short(ar, v3d, vec, sco1);
+               project_short(vc->ar, vc->v3d, vec, sco1);
                VECCOPY(vec, ebone->tail);
                Mat4MulVecfl(G.obedit->obmat, vec);
-               project_short(ar, v3d, vec, sco2);
+               project_short(vc->ar, vc->v3d, vec, sco2);
                
                didpoint= 0;
                if(lasso_inside(mcords, moves, sco1[0], sco1[1])) {
@@ -588,9 +595,9 @@ static void do_lasso_select_armature(ARegion *ar, View3D *v3d, short mcords[][2]
        // XXX countall();      /* abused for flushing selection!!!! */
 }
 
-static void do_lasso_select_facemode(Scene *scene, short mcords[][2], short moves, short select)
+static void do_lasso_select_facemode(ViewContext *vc, short mcords[][2], short moves, short select)
 {
-       Object *ob= OBACT;
+       Object *ob= vc->obact;
        Mesh *me= ob?ob->data:NULL;
        rcti rect;
        
@@ -600,7 +607,7 @@ static void do_lasso_select_facemode(Scene *scene, short mcords[][2], short move
        em_vertoffs= me->totface+1;     /* max index array */
        
        lasso_select_boundbox(&rect, mcords, moves);
-       EM_mask_init_backbuf_border(mcords, moves, rect.xmin, rect.ymin, rect.xmax, rect.ymax);
+       EM_mask_init_backbuf_border(vc, mcords, moves, rect.xmin, rect.ymin, rect.xmax, rect.ymax);
        
        EM_backbuf_checkAndSelectTFaces(me, select);
        
@@ -640,31 +647,90 @@ static void do_lasso_select_node(short mcords[][2], short moves, short select)
 }
 #endif
 
-void view3d_lasso_select(Scene *scene, ARegion *ar, View3D *v3d, short mcords[][2], short moves, short select)
+void view3d_lasso_select(ViewContext *vc, short mcords[][2], short moves, short select)
 {
        if(G.obedit==NULL) {
                if(FACESEL_PAINT_TEST)
-                       do_lasso_select_facemode(scene, mcords, moves, select);
+                       do_lasso_select_facemode(vc, mcords, moves, select);
                else if(G.f & (G_VERTEXPAINT|G_TEXTUREPAINT|G_WEIGHTPAINT))
                        ;
 // XX          else if(G.f & G_PARTICLEEDIT)
 //                     PE_do_lasso_select(mcords, moves, select);
                else  
-                       do_lasso_select_objects(scene, ar, v3d, mcords, moves, select);
+                       do_lasso_select_objects(vc, mcords, moves, select);
        }
        else if(G.obedit->type==OB_MESH) {
-               do_lasso_select_mesh(scene, ar, v3d, mcords, moves, select);
+               do_lasso_select_mesh(vc, mcords, moves, select);
        } else if(G.obedit->type==OB_CURVE || G.obedit->type==OB_SURF) 
-               do_lasso_select_curve(ar, v3d, mcords, moves, select);
+               do_lasso_select_curve(vc, mcords, moves, select);
        else if(G.obedit->type==OB_LATTICE) 
-               do_lasso_select_lattice(mcords, moves, select);
+               do_lasso_select_lattice(vc, mcords, moves, select);
        else if(G.obedit->type==OB_ARMATURE)
-               do_lasso_select_armature(ar, v3d, mcords, moves, select);
+               do_lasso_select_armature(vc, mcords, moves, select);
 
        BIF_undo_push("Lasso select");
        
 }
 
+static EnumPropertyItem lasso_select_types[] = {
+       {0, "SELECT", "Select", ""},
+       {1, "DESELECT", "Deselect", ""},
+       {0, NULL, NULL, NULL}
+};
+
+
+/* lasso operator gives properties, but since old code works
+   with short array we convert */
+static int view3d_lasso_select_exec(bContext *C, wmOperator *op)
+{
+       ViewContext vc;
+       int select, i= 0;
+       short mcords[1024][2];
+
+       RNA_BEGIN(op->ptr, itemptr, "path") {
+               float loc[2];
+               
+               RNA_float_get_array(&itemptr, "loc", loc);
+               mcords[i][0]= (short)loc[0];
+               mcords[i][1]= (short)loc[1];
+               i++;
+               if(i>=1024) break;
+       }
+       RNA_END;
+       
+       /* setup view context for argument to callbacks */
+       view3d_set_viewcontext(C, &vc);
+       
+       select= RNA_enum_is_equal(op->ptr, "type", "SELECT");
+       view3d_lasso_select(&vc, mcords, i, select);
+       
+       return OPERATOR_FINISHED;
+}
+
+void VIEW3D_OT_lasso_select(wmOperatorType *ot)
+{
+       PropertyRNA *prop;
+       
+       ot->name= "Lasso Select";
+       ot->idname= "VIEW3D_OT_lasso_select";
+       
+       ot->invoke= WM_gesture_lasso_invoke;
+       ot->modal= WM_gesture_lasso_modal;
+       ot->exec= view3d_lasso_select_exec;
+       
+       ot->poll= WM_operator_winactive;
+       
+       prop= RNA_def_property(ot->srna, "path", PROP_COLLECTION, PROP_NONE);
+       RNA_def_property_struct_runtime(prop, &RNA_OperatorMousePath);
+       
+       prop = RNA_def_property(ot->srna, "type", PROP_ENUM, PROP_NONE);
+       RNA_def_property_enum_items(prop, lasso_select_types);
+
+}
+
+
+/* ************************************************* */
+
 #if 0
 /* smart function to sample a rect spiralling outside, nice for backbuf selection */
 static unsigned int samplerect(unsigned int *buf, int size, unsigned int dontdo)
@@ -735,8 +801,10 @@ static void deselectall_except(Scene *scene, Base *b)   /* deselect all except b
        }
 }
 
-static Base *mouse_select_menu(Scene *scene, ARegion *ar, View3D *v3d, unsigned int *buffer, int hits, short *mval)
+static Base *mouse_select_menu(ViewContext *vc, unsigned int *buffer, int hits, short *mval)
 {
+       Scene *scene= vc->scene;
+       View3D *v3d= vc->v3d;
        Base *baseList[SEL_MENU_SIZE]={NULL}; /*baseList is used to store all possible bases to bring up a menu */
        Base *base;
        short baseCount = 0;
@@ -758,7 +826,7 @@ static Base *mouse_select_menu(Scene *scene, ARegion *ar, View3D *v3d, unsigned
                        else {
                                int temp, dist=15;
                                
-                               project_short(ar, v3d, base->object->obmat[3], &base->sx);
+                               project_short(vc->ar, vc->v3d, base->object->obmat[3], &base->sx);
                                
                                temp= abs(base->sx -mval[0]) + abs(base->sy -mval[1]);
                                if(temp<dist ) baseList[baseCount] = base;
@@ -788,7 +856,7 @@ static Base *mouse_select_menu(Scene *scene, ARegion *ar, View3D *v3d, unsigned
 
 /* we want a select buffer with bones, if there are... */
 /* so check three selection levels and compare */
-static short mixed_bones_object_selectbuffer(Scene *scene, ARegion *ar, View3D *v3d, unsigned int *buffer, short *mval)
+static short mixed_bones_object_selectbuffer(ViewContext *vc, unsigned int *buffer, short *mval)
 {
        rcti rect;
        int offs;
@@ -796,19 +864,19 @@ static short mixed_bones_object_selectbuffer(Scene *scene, ARegion *ar, View3D *
        short has_bones15=0, has_bones9=0, has_bones5=0;
        
        BLI_init_rcti(&rect, mval[0]-14, mval[0]+14, mval[1]-14, mval[1]+14);
-       hits15= view3d_opengl_select(scene, ar, v3d, buffer, MAXPICKBUF, &rect);
+       hits15= view3d_opengl_select(vc, buffer, MAXPICKBUF, &rect);
        if(hits15>0) {
                for(a=0; a<hits15; a++) if(buffer[4*a+3] & 0xFFFF0000) has_bones15= 1;
                
                offs= 4*hits15;
                BLI_init_rcti(&rect, mval[0]-9, mval[0]+9, mval[1]-9, mval[1]+9);
-               hits9= view3d_opengl_select(scene, ar, v3d, buffer+offs, MAXPICKBUF-offs, &rect);
+               hits9= view3d_opengl_select(vc, buffer+offs, MAXPICKBUF-offs, &rect);
                if(hits9>0) {
                        for(a=0; a<hits9; a++) if(buffer[offs+4*a+3] & 0xFFFF0000) has_bones9= 1;
                        
                        offs+= 4*hits9;
                        BLI_init_rcti(&rect, mval[0]-5, mval[0]+5, mval[1]-5, mval[1]+5);
-                       hits5= view3d_opengl_select(scene, ar, v3d, buffer+offs, MAXPICKBUF-offs, &rect);
+                       hits5= view3d_opengl_select(vc, buffer+offs, MAXPICKBUF-offs, &rect);
                        if(hits5>0) {
                                for(a=0; a<hits5; a++) if(buffer[offs+4*a+3] & 0xFFFF0000) has_bones5= 1;
                        }
@@ -844,9 +912,11 @@ static short mixed_bones_object_selectbuffer(Scene *scene, ARegion *ar, View3D *
        return 0;
 }
 
+
 /* mval is region coords */
-static void mouse_select(bContext *C, short *mval, short modifier)
+static void mouse_select(bContext *C, short *mval, short extend, short obcenter)
 {
+       ViewContext vc;
        ARegion *ar= CTX_wm_region(C);
        View3D *v3d= (View3D *)CTX_wm_space_data(C);
        Scene *scene= CTX_data_scene(C);
@@ -855,16 +925,21 @@ static void mouse_select(bContext *C, short *mval, short modifier)
        int temp, a, dist=100;
        short hits;
        
+       /* setup view context for argument to callbacks */
+       view3d_set_viewcontext(C, &vc);
+       
        /* always start list from basact in wire mode */
        startbase=  FIRSTBASE;
        if(BASACT && BASACT->next) startbase= BASACT->next;
        
        /* This block uses the control key to make the object selected by its center point rather then its contents */
-       if(G.obedit==0 && modifier == KM_CTRL) {
+       /* XXX later on, in editmode do not activate */
+       if(G.obedit==NULL && obcenter) {
                
                /* note; shift+alt goes to group-flush-selecting */
-               if(modifier == KM_ALT && modifier == KM_CTRL) 
-                       basact= mouse_select_menu(scene, ar, v3d, NULL, 0, mval);
+               /* XXX solve */
+               if(0) 
+                       basact= mouse_select_menu(&vc, NULL, 0, mval);
                else {
                        base= startbase;
                        while(base) {
@@ -889,7 +964,7 @@ static void mouse_select(bContext *C, short *mval, short modifier)
        else {
                /* if objects have posemode set, the bones are in the same selection buffer */
                
-               hits= mixed_bones_object_selectbuffer(scene, ar, v3d, buffer, mval);
+               hits= mixed_bones_object_selectbuffer(&vc, buffer, mval);
                
                if(hits>0) {
                        int has_bones= 0;
@@ -897,8 +972,8 @@ static void mouse_select(bContext *C, short *mval, short modifier)
                        for(a=0; a<hits; a++) if(buffer[4*a+3] & 0xFFFF0000) has_bones= 1;
 
                        /* note; shift+alt goes to group-flush-selecting */
-                       if(has_bones==0 && (modifier == KM_ALT)
-                               basact= mouse_select_menu(scene, ar, v3d, buffer, hits, mval);
+                       if(has_bones==0 && 0
+                               basact= mouse_select_menu(&vc, buffer, hits, mval);
                        else {
                                static short lastmval[2]={-100, -100};
                                int donearest= 0;
@@ -1024,11 +1099,11 @@ static void mouse_select(bContext *C, short *mval, short modifier)
                        oldbasact= BASACT;
                        BASACT= basact;
                        
-                       if(modifier != KM_SHIFT) {
+                       if(!extend) {
                                deselectall_except(scene, basact);
                                ED_base_object_select(basact, BA_SELECT);
                        }
-                       else if(modifier == KM_CTRL && modifier == KM_ALT) {
+                       else if(0) {
                                // XXX select_all_from_groups(basact);
                        }
                        else {
@@ -1077,7 +1152,7 @@ int edge_inside_circle(short centx, short centy, short rad, short x1, short y1,
 
 static void do_nurbs_box_select__doSelect(void *userData, Nurb *nu, BPoint *bp, BezTriple *bezt, int beztindex, int x, int y)
 {
-       struct { rcti *rect; int select; } *data = userData;
+       struct { ViewContext vc; rcti *rect; int select; } *data = userData;
 
        if (BLI_in_rcti(data->rect, x, y)) {
                if (bp) {
@@ -1098,37 +1173,39 @@ static void do_nurbs_box_select__doSelect(void *userData, Nurb *nu, BPoint *bp,
                }
        }
 }
-static void do_nurbs_box_select(ARegion *ar, View3D *v3d, rcti *rect, int select)
+static void do_nurbs_box_select(ViewContext *vc, rcti *rect, int select)
 {
-       struct { rcti *rect; int select; } data;
-
+       struct { ViewContext vc; rcti *rect; int select; } data;
+       
+       data.vc= *vc;
        data.rect = rect;
        data.select = select;
 
-       nurbs_foreachScreenVert(ar, v3d, do_nurbs_box_select__doSelect, &data);
+       nurbs_foreachScreenVert(vc, do_nurbs_box_select__doSelect, &data);
 }
 
 static void do_lattice_box_select__doSelect(void *userData, BPoint *bp, int x, int y)
 {
-       struct { rcti *rect; int select; } *data = userData;
+       struct { ViewContext vc; rcti *rect; int select; } *data = userData;
 
        if (BLI_in_rcti(data->rect, x, y)) {
                bp->f1 = data->select?(bp->f1|SELECT):(bp->f1&~SELECT);
        }
 }
-static void do_lattice_box_select(rcti *rect, int select)
+static void do_lattice_box_select(ViewContext *vc, rcti *rect, int select)
 {
-       struct { rcti *rect; int select, pass, done; } data;
+       struct { ViewContext vc; rcti *rect; int select, pass, done; } data;
 
+       data.vc= *vc;
        data.rect = rect;
        data.select = select;
 
-       lattice_foreachScreenVert(do_lattice_box_select__doSelect, &data);
+       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)
 {
-       struct { rcti *rect; short select, pass, done; } *data = userData;
+       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);
@@ -1136,7 +1213,7 @@ static void do_mesh_box_select__doSelectVert(void *userData, EditVert *eve, int
 }
 static void do_mesh_box_select__doSelectEdge(void *userData, EditEdge *eed, int x0, int y0, int x1, int y1, int index)
 {
-       struct { rcti *rect; short select, pass, done; } *data = userData;
+       struct { ViewContext vc; rcti *rect; short select, pass, done; } *data = userData;
 
        if(EM_check_backbuf(em_solidoffs+index)) {
                if (data->pass==0) {
@@ -1153,62 +1230,62 @@ static void do_mesh_box_select__doSelectEdge(void *userData, EditEdge *eed, int
 }
 static void do_mesh_box_select__doSelectFace(void *userData, EditFace *efa, int x, int y, int index)
 {
-       struct { rcti *rect; short select, pass, done; } *data = userData;
+       struct { ViewContext vc; rcti *rect; short select, pass, done; } *data = userData;
 
        if (BLI_in_rcti(data->rect, x, y)) {
-               EM_select_face_fgon(efa, data->select);
+               EM_select_face_fgon(data->vc.em, efa, data->select);
        }
 }
-static void do_mesh_box_select(Scene *scene, ARegion *ar, View3D *v3d, rcti *rect, int select)
+static void do_mesh_box_select(ViewContext *vc, rcti *rect, int select)
 {
-       struct { rcti *rect; short select, pass, done; } data;
-       EditMesh *em = G.editMesh;
+       struct { ViewContext vc; rcti *rect; short select, pass, done; } data;
        int bbsel;
        
+       data.vc= *vc;
        data.rect = rect;
        data.select = select;
        data.pass = 0;
        data.done = 0;
 
-       bbsel= EM_init_backbuf_border(rect->xmin, rect->ymin, rect->xmax, rect->ymax);
+       bbsel= EM_init_backbuf_border(vc, rect->xmin, rect->ymin, rect->xmax, rect->ymax);
 
-       if(scene->selectmode & SCE_SELECT_VERTEX) {
+       if(vc->scene->selectmode & SCE_SELECT_VERTEX) {
                if (bbsel) {
-                       EM_backbuf_checkAndSelectVerts(em, select);
+                       EM_backbuf_checkAndSelectVerts(vc->em, select);
                } else {
-                       mesh_foreachScreenVert(ar, v3d, do_mesh_box_select__doSelectVert, &data, 1);
+                       mesh_foreachScreenVert(vc, do_mesh_box_select__doSelectVert, &data, 1);
                }
        }
-       if(scene->selectmode & SCE_SELECT_EDGE) {
+       if(vc->scene->selectmode & SCE_SELECT_EDGE) {
                        /* Does both bbsel and non-bbsel versions (need screen cos for both) */
 
                data.pass = 0;
-               mesh_foreachScreenEdge(ar, v3d, do_mesh_box_select__doSelectEdge, &data, 0);
+               mesh_foreachScreenEdge(vc, do_mesh_box_select__doSelectEdge, &data, 0);
 
                if (data.done==0) {
                        data.pass = 1;
-                       mesh_foreachScreenEdge(ar, v3d, do_mesh_box_select__doSelectEdge, &data, 0);
+                       mesh_foreachScreenEdge(vc, do_mesh_box_select__doSelectEdge, &data, 0);
                }
        }
        
-       if(scene->selectmode & SCE_SELECT_FACE) {
+       if(vc->scene->selectmode & SCE_SELECT_FACE) {
                if(bbsel) {
-                       EM_backbuf_checkAndSelectFaces(em, select);
+                       EM_backbuf_checkAndSelectFaces(vc->em, select);
                } else {
-                       mesh_foreachScreenFace(ar, v3d, do_mesh_box_select__doSelectFace, &data);
+                       mesh_foreachScreenFace(vc, do_mesh_box_select__doSelectFace, &data);
                }
        }
        
        EM_free_backbuf();
                
-       EM_selectmode_flush();
+       EM_selectmode_flush(vc->em);
 }
 
 static int view3d_borderselect_exec(bContext *C, wmOperator *op)
 {
+       ViewContext vc;
        Scene *scene= CTX_data_scene(C);
        ScrArea *sa= CTX_wm_area(C);
-       ARegion *ar= CTX_wm_region(C);
        View3D *v3d= sa->spacedata.first;
        rcti rect;
        Base *base;
@@ -1217,6 +1294,11 @@ static int view3d_borderselect_exec(bContext *C, wmOperator *op)
        int a, index;
        short hits, val;
 
+       view3d_operator_needs_opengl(C);
+       
+       /* setup view context for argument to callbacks */
+       view3d_set_viewcontext(C, &vc);
+       
        val= RNA_int_get(op->ptr, "event_type");
        rect.xmin= RNA_int_get(op->ptr, "xmin");
        rect.ymin= RNA_int_get(op->ptr, "ymin");
@@ -1234,18 +1316,19 @@ static int view3d_borderselect_exec(bContext *C, wmOperator *op)
        
        if(G.obedit) {
                if(G.obedit->type==OB_MESH) {
-                       do_mesh_box_select(scene, ar, v3d, &rect, (val==LEFTMOUSE));
-//                     allqueue(REDRAWVIEW3D, 0);
+                       Mesh *me= G.obedit->data;
+                       vc.em= me->edit_mesh;
+                       do_mesh_box_select(&vc, &rect, (val==LEFTMOUSE));
 //                     if (EM_texFaceCheck())
-//                             allqueue(REDRAWIMAGE, 0);
+                       WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, G.obedit);
                        
                }
                else if(ELEM(G.obedit->type, OB_CURVE, OB_SURF)) {
-                       do_nurbs_box_select(ar, v3d, &rect, val==LEFTMOUSE);
+                       do_nurbs_box_select(&vc, &rect, val==LEFTMOUSE);
 //                     allqueue(REDRAWVIEW3D, 0);
                }
                else if(G.obedit->type==OB_MBALL) {
-                       hits= view3d_opengl_select(scene, ar, v3d, buffer, MAXPICKBUF, &rect);
+                       hits= view3d_opengl_select(&vc, buffer, MAXPICKBUF, &rect);
                        
                        ml= NULL; // XXX editelems.first;
                        
@@ -1274,7 +1357,7 @@ static int view3d_borderselect_exec(bContext *C, wmOperator *op)
                        for(ebone= G.edbo.first; ebone; ebone= ebone->next)
                                ebone->flag &= ~BONE_DONE;
                        
-                       hits= view3d_opengl_select(scene, ar, v3d, buffer, MAXPICKBUF, &rect);
+                       hits= view3d_opengl_select(&vc, buffer, MAXPICKBUF, &rect);
                        
                        /* first we only check points inside the border */
                        for (a=0; a<hits; a++){
@@ -1321,7 +1404,7 @@ static int view3d_borderselect_exec(bContext *C, wmOperator *op)
                        
                }
                else if(G.obedit->type==OB_LATTICE) {
-                       do_lattice_box_select(&rect, val==LEFTMOUSE);
+                       do_lattice_box_select(&vc, &rect, val==LEFTMOUSE);
                }
        }
        else {  /* no editmode, unified for bones and objects */
@@ -1342,7 +1425,7 @@ static int view3d_borderselect_exec(bContext *C, wmOperator *op)
                
                /* selection buffer now has bones potentially too, so we add MAXPICKBUF */
                vbuffer = MEM_mallocN(4 * (G.totobj+MAXPICKBUF) * sizeof(unsigned int), "selection buffer");
-               hits= view3d_opengl_select(scene, ar, v3d, vbuffer, 4*(G.totobj+MAXPICKBUF), &rect);
+               hits= view3d_opengl_select(&vc, vbuffer, 4*(G.totobj+MAXPICKBUF), &rect);
                /*
                LOGIC NOTES (theeth):
                The buffer and ListBase have the same relative order, which makes the selection
@@ -1398,18 +1481,22 @@ static int view3d_borderselect_exec(bContext *C, wmOperator *op)
                }
                MEM_freeN(vbuffer);
        }
-
-       BIF_undo_push("Border select");
        
        return OPERATOR_FINISHED;
 } 
 
 
 /* *****************Selection Operators******************* */
+static EnumPropertyItem prop_select_types[] = {
+       {0, "EXCLUSIVE", "Exclusive", ""},
+       {1, "EXTEND", "Extend", ""},
+       {0, NULL, NULL, NULL}
+};
 
 /* ****** Border Select ****** */
 void VIEW3D_OT_borderselect(wmOperatorType *ot)
 {
+       PropertyRNA *prop;
        
        /* identifiers */
        ot->name= "Border Select";
@@ -1428,13 +1515,19 @@ void VIEW3D_OT_borderselect(wmOperatorType *ot)
        RNA_def_property(ot->srna, "xmax", PROP_INT, PROP_NONE);
        RNA_def_property(ot->srna, "ymin", PROP_INT, PROP_NONE);
        RNA_def_property(ot->srna, "ymax", PROP_INT, PROP_NONE);
+
+       prop = RNA_def_property(ot->srna, "type", PROP_ENUM, PROP_NONE);
+       RNA_def_property_enum_items(prop, prop_select_types);
 }
 
 /* ****** Mouse Select ****** */
 
+
 static int view3d_select_invoke(bContext *C, wmOperator *op, wmEvent *event)
 {
        ARegion *ar= CTX_wm_region(C);
+       Object *obedit= CTX_data_edit_object(C);
+       short extend= RNA_enum_is_equal(op->ptr, "type", "EXTEND");
        short mval[2];  
        
        mval[0]= event->x - ar->winrct.xmin;
@@ -1442,13 +1535,20 @@ static int view3d_select_invoke(bContext *C, wmOperator *op, wmEvent *event)
 
        view3d_operator_needs_opengl(C);
        
-       mouse_select(C, mval, 0);
+       if(obedit) {
+               if(obedit->type==OB_MESH)
+                       mouse_mesh(C, mval, extend);
+       }
+       else 
+               mouse_select(C, mval, extend, 0);
        
-       return OPERATOR_FINISHED;
+       /* allowing tweaks */
+       return OPERATOR_PASS_THROUGH;
 }
 
 void VIEW3D_OT_select(wmOperatorType *ot)
 {
+       PropertyRNA *prop;
 
        /* identifiers */
        ot->name= "Activate/Select";
@@ -1458,61 +1558,14 @@ void VIEW3D_OT_select(wmOperatorType *ot)
        ot->invoke= view3d_select_invoke;
        ot->poll= ED_operator_view3d_active;
 
-}
-static EnumPropertyItem prop_select_extend_types[] = {
-       {KM_SHIFT, "SHIFT", "Shift", ""},
-       {KM_CTRL, "CTRL", "Ctrl", ""},
-       {KM_ALT, "ALT", "Alt", ""},
-       {0, NULL, NULL, NULL}
-};
-
-static int view3d_select_extend_invoke(bContext *C, wmOperator *op, wmEvent *event)
-{
-       ARegion *ar= CTX_wm_region(C);
-       short mval[2], modifier;        
-       
-       mval[0]= event->x - ar->winrct.xmin;
-       mval[1]= event->y - ar->winrct.ymin;
-
-       modifier = RNA_enum_get(op->ptr, "modifier");
-       
-       view3d_operator_needs_opengl(C);        
-       
-       mouse_select(C, mval, modifier);
-       
-       return OPERATOR_FINISHED;
-}
-
-void VIEW3D_OT_select_extend(wmOperatorType *ot)
-{
-       PropertyRNA *prop;
-       
-       /* identifiers */
-       ot->name= "Activate/Select Extend";
-       ot->idname= "VIEW3D_OT_select_extend";
-       
-       /* api callbacks */
-       ot->invoke= view3d_select_extend_invoke;
-       ot->poll= ED_operator_view3d_active;    
-       
-       prop = RNA_def_property(ot->srna, "modifier", PROP_ENUM, PROP_NONE);
-       RNA_def_property_enum_items(prop, prop_select_extend_types);
-
+       prop = RNA_def_property(ot->srna, "type", PROP_ENUM, PROP_NONE);
+       RNA_def_property_enum_items(prop, prop_select_types);
 }
 
 
-/* ------------------------------------------------------------------------- */
+/* -------------------- circle select --------------------------------------------- */
 
-/** The following functions are quick & dirty callback functions called
-  * on the Circle select function (press B twice in Editmode)
-  * They were torn out of the circle_select to make the latter more reusable
-  * The callback version of circle_select (called circle_selectCB) was moved
-  * to edit.c because of it's (wanted) generality.
-
-       XXX These callback functions are still dirty, because they call globals... 
-  */
-
-static void mesh_selectionCB__doSelectVert(void *userData, EditVert *eve, int x, int y, int index)
+static void mesh_circle_doSelectVert(void *userData, EditVert *eve, int x, int y, int index)
 {
        struct { short select, mval[2]; float radius; } *data = userData;
        int mx = x - data->mval[0], my = y - data->mval[1];
@@ -1522,7 +1575,7 @@ static void mesh_selectionCB__doSelectVert(void *userData, EditVert *eve, int x,
                eve->f = data->select?(eve->f|1):(eve->f&~1);
        }
 }
-static void mesh_selectionCB__doSelectEdge(void *userData, EditEdge *eed, int x0, int y0, int x1, int y1, int index)
+static void mesh_circle_doSelectEdge(void *userData, EditEdge *eed, int x0, int y0, int x1, int y1, int index)
 {
        struct { short select, mval[2]; float radius; } *data = userData;
 
@@ -1530,77 +1583,78 @@ static void mesh_selectionCB__doSelectEdge(void *userData, EditEdge *eed, int x0
                EM_select_edge(eed, data->select);
        }
 }
-static void mesh_selectionCB__doSelectFace(void *userData, EditFace *efa, int x, int y, int index)
+static void mesh_circle_doSelectFace(void *userData, EditFace *efa, int x, int y, int index)
 {
        struct { 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);
-
+       EditMesh *em= NULL; // XXX
+       
        if (r<=data->radius) {
-               EM_select_face_fgon(efa, data->select);
+               EM_select_face_fgon(em, efa, data->select);
        }
 }
 
-static void mesh_selectionCB(Scene *scene, ARegion *ar, View3D *v3d, int selecting, Object *editobj, short *mval, float rad)
+static void mesh_circle_select(ViewContext *vc, int selecting, short *mval, float rad)
 {
-       struct { short select, mval[2]; float radius; } data;
-       EditMesh *em = G.editMesh;
        int bbsel;
-
-       if(!G.obedit && (FACESEL_PAINT_TEST)) {
-               Object *ob= OBACT;
+       
+       if(vc->obedit==NULL && (FACESEL_PAINT_TEST)) {
+               Object *ob= vc->obact;
                Mesh *me = ob?ob->data:NULL;
 
                if (me) {
                        em_vertoffs= me->totface+1;     /* max index array */
 
-                       bbsel= EM_init_backbuf_circle(mval[0], mval[1], (short)(rad+1.0));
+                       bbsel= EM_init_backbuf_circle(vc, mval[0], mval[1], (short)(rad+1.0));
                        EM_backbuf_checkAndSelectTFaces(me, selecting==LEFTMOUSE);
                        EM_free_backbuf();
 
 // XXX                 object_tface_flags_changed(OBACT, 0);
                }
-
-               return;
        }
+       else {
+               struct { short select, mval[2]; float radius; } data;
+               
+               bbsel= EM_init_backbuf_circle(vc, mval[0], mval[1], (short)(rad+1.0));
+               vc->em= ((Mesh *)vc->obedit->data)->edit_mesh;
 
-       bbsel= EM_init_backbuf_circle(mval[0], mval[1], (short)(rad+1.0));
-       
-       data.select = (selecting==LEFTMOUSE);
-       data.mval[0] = mval[0];
-       data.mval[1] = mval[1];
-       data.radius = rad;
+               data.select = selecting;
+               data.mval[0] = mval[0];
+               data.mval[1] = mval[1];
+               data.radius = rad;
 
-       if(scene->selectmode & SCE_SELECT_VERTEX) {
-               if(bbsel) {
-                       EM_backbuf_checkAndSelectVerts(em, selecting==LEFTMOUSE);
-               } else {
-                       mesh_foreachScreenVert(ar, v3d, mesh_selectionCB__doSelectVert, &data, 1);
+               if(vc->scene->selectmode & SCE_SELECT_VERTEX) {
+                       if(bbsel) {
+                               EM_backbuf_checkAndSelectVerts(vc->em, selecting==LEFTMOUSE);
+                       } else {
+                               mesh_foreachScreenVert(vc, mesh_circle_doSelectVert, &data, 1);
+                       }
                }
-       }
 
-       if(scene->selectmode & SCE_SELECT_EDGE) {
-               if (bbsel) {
-                       EM_backbuf_checkAndSelectEdges(em, selecting==LEFTMOUSE);
-               } else {
-                       mesh_foreachScreenEdge(ar, v3d, mesh_selectionCB__doSelectEdge, &data, 0);
+               if(vc->scene->selectmode & SCE_SELECT_EDGE) {
+                       if (bbsel) {
+                               EM_backbuf_checkAndSelectEdges(vc->em, selecting==LEFTMOUSE);
+                       } else {
+                               mesh_foreachScreenEdge(vc, mesh_circle_doSelectEdge, &data, 0);
+                       }
                }
-       }
-       
-       if(scene->selectmode & SCE_SELECT_FACE) {
-               if(bbsel) {
-                       EM_backbuf_checkAndSelectFaces(em, selecting==LEFTMOUSE);
-               } else {
-                       mesh_foreachScreenFace(ar, v3d, mesh_selectionCB__doSelectFace, &data);
+               
+               if(vc->scene->selectmode & SCE_SELECT_FACE) {
+                       if(bbsel) {
+                               EM_backbuf_checkAndSelectFaces(vc->em, selecting==LEFTMOUSE);
+                       } else {
+                               mesh_foreachScreenFace(vc, mesh_circle_doSelectFace, &data);
+                       }
                }
-       }
 
-       EM_free_backbuf();
-       EM_selectmode_flush();
+               EM_free_backbuf();
+               EM_selectmode_flush(vc->em);
+       }
 }
 
 
-static void nurbscurve_selectionCB__doSelect(void *userData, Nurb *nu, BPoint *bp, BezTriple *bezt, int beztindex, int x, int y)
+static void nurbscurve_circle_doSelect(void *userData, Nurb *nu, BPoint *bp, BezTriple *bezt, int beztindex, int x, int y)
 {
        struct { short select, mval[2]; float radius; } *data = userData;
        int mx = x - data->mval[0], my = y - data->mval[1];
@@ -1620,20 +1674,22 @@ static void nurbscurve_selectionCB__doSelect(void *userData, Nurb *nu, BPoint *b
                }
        }
 }
-static void nurbscurve_selectionCB(ARegion *ar, View3D *v3d, int selecting, Object *editobj, short *mval, float rad)
+static void nurbscurve_circle_select(ViewContext *vc, int selecting, short *mval, float rad)
 {
        struct { short select, mval[2]; float radius; } data;
 
-       data.select = (selecting==LEFTMOUSE);
+       /* set vc-> edit data */
+       
+       data.select = selecting;
        data.mval[0] = mval[0];
        data.mval[1] = mval[1];
        data.radius = rad;
 
-       nurbs_foreachScreenVert(ar, v3d, nurbscurve_selectionCB__doSelect, &data);
+       nurbs_foreachScreenVert(vc, nurbscurve_circle_doSelect, &data);
 }
 
 
-static void latticecurve_selectionCB__doSelect(void *userData, BPoint *bp, int x, int y)
+static void latticecurve_circle_doSelect(void *userData, BPoint *bp, int x, int y)
 {
        struct { short select, mval[2]; float radius; } *data = userData;
        int mx = x - data->mval[0], my = y - data->mval[1];
@@ -1643,67 +1699,80 @@ static void latticecurve_selectionCB__doSelect(void *userData, BPoint *bp, int x
                bp->f1 = data->select?(bp->f1|SELECT):(bp->f1&~SELECT);
        }
 }
-static void lattice_selectionCB(int selecting, Object *editobj, short *mval, float rad)
+static void lattice_circle_select(ViewContext *vc, int selecting, short *mval, float rad)
 {
        struct { short select, mval[2]; float radius; } data;
 
-       data.select = (selecting==LEFTMOUSE);
+       /* set vc-> edit data */
+       
+       data.select = selecting;
        data.mval[0] = mval[0];
        data.mval[1] = mval[1];
        data.radius = rad;
 
-       lattice_foreachScreenVert(latticecurve_selectionCB__doSelect, &data);
+       lattice_foreachScreenVert(vc, latticecurve_circle_doSelect, &data);
 }
 
-/** Callbacks for selection in Editmode */
+/** Callbacks for circle selection in Editmode */
 
-void obedit_selectionCB(Scene *scene, ARegion *ar, View3D *v3d, short selecting, Object *editobj, short *mval, float rad) 
+static void obedit_circle_select(ViewContext *vc, short selecting, short *mval, float rad) 
 {
-       switch(editobj->type) {         
+       switch(vc->obedit->type) {              
        case OB_MESH:
-               mesh_selectionCB(scene, ar, v3d, selecting, editobj, mval, rad);
+               mesh_circle_select(vc, selecting, mval, rad);
                break;
        case OB_CURVE:
        case OB_SURF:
-               nurbscurve_selectionCB(ar, v3d, selecting, editobj, mval, rad);
+               nurbscurve_circle_select(vc, selecting, mval, rad);
                break;
        case OB_LATTICE:
-               lattice_selectionCB(selecting, editobj, mval, rad);
+               lattice_circle_select(vc, selecting, mval, rad);
                break;
        default:
                return;
        }
-
-//     draw_sel_circle(0, 0, 0, 0, 0); /* signal */
-//     force_draw(0);
 }
 
 /* not a real operator, only for circle test */
-static int view3d_circle_select(bContext *C, wmOperator *op)
+static int view3d_circle_select_exec(bContext *C, wmOperator *op)
 {
        ScrArea *sa= CTX_wm_area(C);
        ARegion *ar= CTX_wm_region(C);
        Scene *scene= CTX_data_scene(C);
        View3D *v3d= sa->spacedata.first;
-       Base *base;
-
        int x= RNA_int_get(op->ptr, "x");
        int y= RNA_int_get(op->ptr, "y");
        int radius= RNA_int_get(op->ptr, "radius");
        
-       for(base= FIRSTBASE; base; base= base->next) {
-               if(base->lay & v3d->lay) {
-                       project_short(ar, v3d, base->object->obmat[3], &base->sx);
-                       if(base->sx!=IS_CLIPPED) {
-                               int dx= base->sx-x;
-                               int dy= base->sy-y;
-                               if( dx*dx + dy*dy < radius*radius)
-                                       ED_base_object_select(base, BA_SELECT);
+       if(CTX_data_edit_object(C)) {
+               ViewContext vc;
+               short mval[2], selecting;
+               
+               view3d_set_viewcontext(C, &vc);
+               mval[0]= x;
+               mval[1]= y;
+               selecting= LEFTMOUSE==RNA_int_get(op->ptr, "event_type"); // XXX solve
+               obedit_circle_select(&vc, selecting, mval, (float)radius);
+       }
+       else {
+               Base *base;
+               
+               for(base= FIRSTBASE; base; base= base->next) {
+                       if(base->lay & v3d->lay) {
+                               project_short(ar, v3d, base->object->obmat[3], &base->sx);
+                               if(base->sx!=IS_CLIPPED) {
+                                       int dx= base->sx-x;
+                                       int dy= base->sy-y;
+                                       if( dx*dx + dy*dy < radius*radius)
+                                               ED_base_object_select(base, BA_SELECT);
+                               }
                        }
                }
+               
+               WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, CTX_data_scene(C));
        }
-       WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, CTX_data_scene(C));
-       return 0;
+       
+       return OPERATOR_FINISHED;
 }
 
 void VIEW3D_OT_circle_select(wmOperatorType *ot)
@@ -1713,11 +1782,12 @@ void VIEW3D_OT_circle_select(wmOperatorType *ot)
        
        ot->invoke= WM_gesture_circle_invoke;
        ot->modal= WM_gesture_circle_modal;
-       ot->exec= view3d_circle_select;
+       ot->exec= view3d_circle_select_exec;
        ot->poll= ED_operator_view3d_active;
        
        RNA_def_property(ot->srna, "x", PROP_INT, PROP_NONE);
        RNA_def_property(ot->srna, "y", PROP_INT, PROP_NONE);
        RNA_def_property(ot->srna, "radius", PROP_INT, PROP_NONE);
+       RNA_def_property(ot->srna, "event_type", PROP_INT, PROP_NONE);
        
 }