Undo revision 23130 which was a merge with 2.5, a messy one because I did something...
[blender.git] / source / blender / editors / space_view3d / view3d_select.c
index b6098e5..7743ede 100644 (file)
@@ -59,6 +59,7 @@
 #include "BKE_depsgraph.h"
 #include "BKE_object.h"
 #include "BKE_global.h"
+#include "BKE_paint.h"
 #include "BKE_scene.h"
 #include "BKE_screen.h"
 #include "BKE_utildefines.h"
@@ -66,7 +67,6 @@
 #include "RE_pipeline.h"       // make_stars
 
 #include "BIF_gl.h"
-#include "BIF_retopo.h"
 
 #include "WM_api.h"
 #include "WM_types.h"
 #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_mball.h"
 
 #include "UI_interface.h"
 #include "UI_resources.h"
@@ -126,7 +128,7 @@ void view3d_get_transformation(ViewContext *vc, Object *ob, bglMats *mats)
        float cpy[4][4];
        int i, j;
 
-       Mat4MulMat4(cpy, vc->rv3d->viewmat, ob->obmat);
+       Mat4MulMat4(cpy, ob->obmat, vc->rv3d->viewmat);
 
        for(i = 0; i < 4; ++i) {
                for(j = 0; j < 4; ++j) {
@@ -377,7 +379,7 @@ static void do_lasso_select_objects(ViewContext *vc, short mcords[][2], short mo
                                else ED_base_object_select(base, BA_DESELECT);
                                base->object->flag= base->flag;
                        }
-                       if(base->object->flag & OB_POSEMODE) {
+                       if(base->object->mode & OB_MODE_POSE) {
                                do_lasso_select_pose(vc, mcords, moves, select);
                        }
                }
@@ -438,6 +440,7 @@ static void do_lasso_select_mesh__doSelectFace(void *userData, EditFace *efa, in
 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;
        
@@ -456,14 +459,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);
        
-       if(vc->scene->selectmode & SCE_SELECT_VERTEX) {
+       if(ts->selectmode & SCE_SELECT_VERTEX) {
                if (bbsel) {
                        EM_backbuf_checkAndSelectVerts(vc->em, select);
                } else {
                        mesh_foreachScreenVert(vc, do_lasso_select_mesh__doSelectVert, &data, 1);
                }
        }
-       if(vc->scene->selectmode & SCE_SELECT_EDGE) {
+       if(ts->selectmode & SCE_SELECT_EDGE) {
                        /* Does both bbsel and non-bbsel versions (need screen cos for both) */
 
                data.pass = 0;
@@ -475,7 +478,7 @@ static void do_lasso_select_mesh(ViewContext *vc, short mcords[][2], short moves
                }
        }
        
-       if(vc->scene->selectmode & SCE_SELECT_FACE) {
+       if(ts->selectmode & SCE_SELECT_FACE) {
                if (bbsel) {
                        EM_backbuf_checkAndSelectFaces(vc->em, select);
                } else {
@@ -691,12 +694,14 @@ static void do_lasso_select_node(short mcords[][2], short moves, short select)
 
 void view3d_lasso_select(bContext *C, ViewContext *vc, short mcords[][2], short moves, short select)
 {
+       Object *ob = CTX_data_active_object(C);
+
        if(vc->obedit==NULL) {
-               if(FACESEL_PAINT_TEST)
+               if(paint_facesel_test(ob))
                        do_lasso_select_facemode(vc, mcords, moves, select);
-               else if(G.f & (G_VERTEXPAINT|G_TEXTUREPAINT|G_WEIGHTPAINT))
+               else if(ob && ob->mode & (OB_MODE_VERTEX_PAINT|OB_MODE_WEIGHT_PAINT|OB_MODE_TEXTURE_PAINT))
                        ;
-               else if(G.f & G_PARTICLEEDIT)
+               else if(ob && ob->mode & OB_MODE_PARTICLE_EDIT)
                        PE_lasso_select(C, mcords, moves, select);
                else  
                        do_lasso_select_objects(vc, mcords, moves, select);
@@ -714,12 +719,6 @@ void view3d_lasso_select(bContext *C, ViewContext *vc, short mcords[][2], short
        
 }
 
-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 */
@@ -746,7 +745,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_enum_is_equal(op->ptr, "type", "SELECT");
+               select= !RNA_boolean_get(op->ptr, "deselect");
                view3d_lasso_select(C, &vc, mcords, i, select);
                
                return OPERATOR_FINISHED;
@@ -754,10 +753,10 @@ static int view3d_lasso_select_exec(bContext *C, wmOperator *op)
        return OPERATOR_PASS_THROUGH;
 }
 
-void VIEW3D_OT_lasso_select(wmOperatorType *ot)
+void VIEW3D_OT_select_lasso(wmOperatorType *ot)
 {
        ot->name= "Lasso Select";
-       ot->idname= "VIEW3D_OT_lasso_select";
+       ot->idname= "VIEW3D_OT_select_lasso";
        
        ot->invoke= WM_gesture_lasso_invoke;
        ot->modal= WM_gesture_lasso_modal;
@@ -765,10 +764,10 @@ void VIEW3D_OT_lasso_select(wmOperatorType *ot)
        ot->poll= WM_operator_winactive;
        
        /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag= OPTYPE_UNDO;
        
        RNA_def_collection_runtime(ot->srna, "path", &RNA_OperatorMousePath, "Path", "");
-       RNA_def_enum(ot->srna, "type", lasso_select_types, 0, "Type", "");
+       RNA_def_boolean(ot->srna, "deselect", 0, "Deselect", "Deselect rather than select items.");
 }
 
 
@@ -1113,7 +1112,7 @@ static void mouse_select(bContext *C, short *mval, short extend, short obcenter)
                                        WM_event_add_notifier(C, NC_OBJECT|ND_BONE_ACTIVE, basact->object);
                                        
                                        /* in weightpaint, we use selected bone to select vertexgroup, so no switch to new active object */
-                                       if(G.f & G_WEIGHTPAINT) {
+                                       if(basact->object->mode & OB_MODE_WEIGHT_PAINT) {
                                                /* prevent activating */
                                                basact= NULL;
                                        }
@@ -1277,6 +1276,7 @@ static void do_mesh_box_select__doSelectFace(void *userData, EditFace *efa, int
 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;
@@ -1287,14 +1287,14 @@ static void do_mesh_box_select(ViewContext *vc, rcti *rect, int select)
 
        bbsel= EM_init_backbuf_border(vc, rect->xmin, rect->ymin, rect->xmax, rect->ymax);
 
-       if(vc->scene->selectmode & SCE_SELECT_VERTEX) {
+       if(ts->selectmode & SCE_SELECT_VERTEX) {
                if (bbsel) {
                        EM_backbuf_checkAndSelectVerts(vc->em, select);
                } else {
                        mesh_foreachScreenVert(vc, do_mesh_box_select__doSelectVert, &data, 1);
                }
        }
-       if(vc->scene->selectmode & SCE_SELECT_EDGE) {
+       if(ts->selectmode & SCE_SELECT_EDGE) {
                        /* Does both bbsel and non-bbsel versions (need screen cos for both) */
 
                data.pass = 0;
@@ -1306,7 +1306,7 @@ static void do_mesh_box_select(ViewContext *vc, rcti *rect, int select)
                }
        }
        
-       if(vc->scene->selectmode & SCE_SELECT_FACE) {
+       if(ts->selectmode & SCE_SELECT_FACE) {
                if(bbsel) {
                        EM_backbuf_checkAndSelectFaces(vc->em, select);
                } else {
@@ -1326,6 +1326,7 @@ static int view3d_borderselect_exec(bContext *C, wmOperator *op)
        ScrArea *sa= CTX_wm_area(C);
        View3D *v3d= sa->spacedata.first;
        Object *obedit= CTX_data_edit_object(C);
+       Object *obact= CTX_data_active_object(C);
        rcti rect;
        Base *base;
        MetaElem *ml;
@@ -1344,11 +1345,11 @@ static int view3d_borderselect_exec(bContext *C, wmOperator *op)
        rect.xmax= RNA_int_get(op->ptr, "xmax");
        rect.ymax= RNA_int_get(op->ptr, "ymax");
        
-       if(obedit==NULL && (FACESEL_PAINT_TEST)) {
+       if(obedit==NULL && (paint_facesel_test(OBACT))) {
 // XXX         face_borderselect();
                return OPERATOR_FINISHED;
        }
-       else if(obedit==NULL && (G.f & G_PARTICLEEDIT)) {
+       else if(obedit==NULL && (obact && obact->mode & OB_MODE_PARTICLE_EDIT)) {
                return PE_border_select(C, &rect, (val==LEFTMOUSE));
        }
        
@@ -1365,9 +1366,10 @@ static int view3d_borderselect_exec(bContext *C, wmOperator *op)
                        do_nurbs_box_select(&vc, &rect, val==LEFTMOUSE);
                }
                else if(obedit->type==OB_MBALL) {
+                       MetaBall *mb = (MetaBall*)obedit->data;
                        hits= view3d_opengl_select(&vc, buffer, MAXPICKBUF, &rect);
                        
-                       ml= NULL; // XXX editelems.first;
+                       ml= mb->editelems->first;
                        
                        while(ml) {
                                for(a=0; a<hits; a++) {
@@ -1440,6 +1442,7 @@ 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, val==LEFTMOUSE);
@@ -1454,7 +1457,7 @@ static int view3d_borderselect_exec(bContext *C, wmOperator *op)
                int bone_only;
                int totobj= MAXPICKBUF; // XXX solve later
                
-               if((ob) && (ob->flag & OB_POSEMODE))
+               if((ob) && (ob->mode & OB_MODE_POSE))
                        bone_only= 1;
                else
                        bone_only= 0;
@@ -1525,18 +1528,13 @@ static int view3d_borderselect_exec(bContext *C, wmOperator *op)
 
 
 /* *****************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)
+void VIEW3D_OT_select_border(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Border Select";
-       ot->idname= "VIEW3D_OT_borderselect";
+       ot->idname= "VIEW3D_OT_select_border";
        
        /* api callbacks */
        ot->invoke= WM_border_select_invoke;
@@ -1546,7 +1544,7 @@ void VIEW3D_OT_borderselect(wmOperatorType *ot)
        ot->poll= ED_operator_view3d_active;
        
        /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag= OPTYPE_UNDO;
        
        /* rna */
        RNA_def_int(ot->srna, "event_type", 0, INT_MIN, INT_MAX, "Event Type", "", INT_MIN, INT_MAX);
@@ -1555,7 +1553,7 @@ void VIEW3D_OT_borderselect(wmOperatorType *ot)
        RNA_def_int(ot->srna, "ymin", 0, INT_MIN, INT_MAX, "Y Min", "", INT_MIN, INT_MAX);
        RNA_def_int(ot->srna, "ymax", 0, INT_MIN, INT_MAX, "Y Max", "", INT_MIN, INT_MAX);
 
-       RNA_def_enum(ot->srna, "type", prop_select_types, 0, "Type", "");
+       RNA_def_boolean(ot->srna, "extend", 0, "Extend", "Extend selection instead of deselecting everyting first.");
 }
 
 /* ****** Mouse Select ****** */
@@ -1564,7 +1562,8 @@ void VIEW3D_OT_borderselect(wmOperatorType *ot)
 static int view3d_select_invoke(bContext *C, wmOperator *op, wmEvent *event)
 {
        Object *obedit= CTX_data_edit_object(C);
-       short extend= RNA_enum_is_equal(op->ptr, "type", "EXTEND");
+       Object *obact= CTX_data_active_object(C);
+       short extend= RNA_boolean_get(op->ptr, "extend");
 
        view3d_operator_needs_opengl(C);
        
@@ -1577,9 +1576,11 @@ static int view3d_select_invoke(bContext *C, wmOperator *op, wmEvent *event)
                        mouse_lattice(C, event->mval, extend);
                else if(ELEM(obedit->type, OB_CURVE, OB_SURF))
                        mouse_nurb(C, event->mval, extend);
+               else if(obedit->type==OB_MBALL)
+                       mouse_mball(C, event->mval, extend);
                        
        }
-       else if(G.f & G_PARTICLEEDIT)
+       else if(obact && obact->mode & OB_MODE_PARTICLE_EDIT)
                PE_mouse_particles(C, event->mval, extend);
        else 
                mouse_select(C, event->mval, extend, 0);
@@ -1599,10 +1600,10 @@ void VIEW3D_OT_select(wmOperatorType *ot)
        ot->poll= ED_operator_view3d_active;
        
        /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag= OPTYPE_UNDO;
        
        /* properties */
-       RNA_def_enum(ot->srna, "type", prop_select_types, 0, "Type", "");
+       RNA_def_boolean(ot->srna, "extend", 0, "Extend", "Extend selection instead of deselecting everyting first.");
 }
 
 
@@ -1639,10 +1640,11 @@ static void mesh_circle_doSelectFace(void *userData, EditFace *efa, int x, int y
 
 static void mesh_circle_select(ViewContext *vc, int selecting, short *mval, float rad)
 {
+       ToolSettings *ts= vc->scene->toolsettings;
        int bbsel;
+       Object *ob= vc->obact;
        
-       if(vc->obedit==NULL && (FACESEL_PAINT_TEST)) {
-               Object *ob= vc->obact;
+       if(vc->obedit==NULL && paint_facesel_test(ob)) {
                Mesh *me = ob?ob->data:NULL;
 
                if (me) {
@@ -1666,7 +1668,7 @@ static void mesh_circle_select(ViewContext *vc, int selecting, short *mval, floa
                data.mval[1] = mval[1];
                data.radius = rad;
 
-               if(vc->scene->selectmode & SCE_SELECT_VERTEX) {
+               if(ts->selectmode & SCE_SELECT_VERTEX) {
                        if(bbsel) {
                                EM_backbuf_checkAndSelectVerts(vc->em, selecting==LEFTMOUSE);
                        } else {
@@ -1674,7 +1676,7 @@ static void mesh_circle_select(ViewContext *vc, int selecting, short *mval, floa
                        }
                }
 
-               if(vc->scene->selectmode & SCE_SELECT_EDGE) {
+               if(ts->selectmode & SCE_SELECT_EDGE) {
                        if (bbsel) {
                                EM_backbuf_checkAndSelectEdges(vc->em, selecting==LEFTMOUSE);
                        } else {
@@ -1682,7 +1684,7 @@ static void mesh_circle_select(ViewContext *vc, int selecting, short *mval, floa
                        }
                }
                
-               if(vc->scene->selectmode & SCE_SELECT_FACE) {
+               if(ts->selectmode & SCE_SELECT_FACE) {
                        if(bbsel) {
                                EM_backbuf_checkAndSelectFaces(vc->em, selecting==LEFTMOUSE);
                        } else {
@@ -1781,12 +1783,13 @@ 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);
+       Object *obact= CTX_data_active_object(C);
        View3D *v3d= sa->spacedata.first;
        int x= RNA_int_get(op->ptr, "x");
        int y= RNA_int_get(op->ptr, "y");
        int radius= RNA_int_get(op->ptr, "radius");
        
-       if(CTX_data_edit_object(C) || (G.f & G_PARTICLEEDIT)) {
+       if(CTX_data_edit_object(C) || (obact && obact->mode & OB_MODE_PARTICLE_EDIT)) {
                ViewContext vc;
                short mval[2], selecting;
                
@@ -1797,8 +1800,10 @@ static int view3d_circle_select_exec(bContext *C, wmOperator *op)
                mval[1]= y;
                selecting= LEFTMOUSE==RNA_int_get(op->ptr, "event_type"); // XXX solve
 
-               if(CTX_data_edit_object(C))
+               if(CTX_data_edit_object(C)) {
                        obedit_circle_select(&vc, selecting, mval, (float)radius);
+                       WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obact);
+               }
                else
                        return PE_circle_select(C, selecting, mval, (float)radius);
        }
@@ -1823,10 +1828,10 @@ static int view3d_circle_select_exec(bContext *C, wmOperator *op)
        return OPERATOR_FINISHED;
 }
 
-void VIEW3D_OT_circle_select(wmOperatorType *ot)
+void VIEW3D_OT_select_circle(wmOperatorType *ot)
 {
        ot->name= "Circle Select";
-       ot->idname= "VIEW3D_OT_circle_select";
+       ot->idname= "VIEW3D_OT_select_circle";
        
        ot->invoke= WM_gesture_circle_invoke;
        ot->modal= WM_gesture_circle_modal;
@@ -1834,7 +1839,7 @@ void VIEW3D_OT_circle_select(wmOperatorType *ot)
        ot->poll= ED_operator_view3d_active;
        
        /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag= OPTYPE_UNDO;
        
        RNA_def_int(ot->srna, "x", 0, INT_MIN, INT_MAX, "X", "", INT_MIN, INT_MAX);
        RNA_def_int(ot->srna, "y", 0, INT_MIN, INT_MAX, "Y", "", INT_MIN, INT_MAX);