2.5
[blender.git] / source / blender / editors / space_view3d / view3d_select.c
index 0d9a92c86c3a140e9d8e029a1f081d57546199e8..2be8df678f0d266fd42a4f0f754a691e6e4a4e78 100644 (file)
@@ -679,51 +679,8 @@ void view3d_lasso_select(Scene *scene, ARegion *ar, View3D *v3d, short mcords[][
        
 }
 
-/* mx my in region coords */
-void mouse_cursor(Scene *scene, ARegion *ar, View3D *v3d, short mx, short my)
-{
-       float dx, dy, fz, *fp = NULL, dvec[3], oldcurs[3];
-       short lr_click=0, mval[2];
-       short ctrl= 0; // XXX
-       
-       fp= give_cursor(scene, v3d);
-       
-       if(G.obedit && ctrl) lr_click= 1;
-       VECCOPY(oldcurs, fp);
-       
-       project_short_noclip(ar, v3d, fp, mval);
-
-       initgrabz(v3d, fp[0], fp[1], fp[2]);
-       
-       if(mval[0]!=IS_CLIPPED) {
-               
-               window_to_3d(ar, v3d, dvec, mval[0]-mx, mval[1]-my);
-               VecSubf(fp, fp, dvec);
-               
-       }
-       else {
 
-               dx= ((float)(mx-(ar->winx/2)))*v3d->zfac/(ar->winx/2);
-               dy= ((float)(my-(ar->winy/2)))*v3d->zfac/(ar->winy/2);
-               
-               fz= v3d->persmat[0][3]*fp[0]+ v3d->persmat[1][3]*fp[1]+ v3d->persmat[2][3]*fp[2]+ v3d->persmat[3][3];
-               fz= fz/v3d->zfac;
-               
-               fp[0]= (v3d->persinv[0][0]*dx + v3d->persinv[1][0]*dy+ v3d->persinv[2][0]*fz)-v3d->ofs[0];
-               fp[1]= (v3d->persinv[0][1]*dx + v3d->persinv[1][1]*dy+ v3d->persinv[2][1]*fz)-v3d->ofs[1];
-               fp[2]= (v3d->persinv[0][2]*dx + v3d->persinv[1][2]*dy+ v3d->persinv[2][2]*fz)-v3d->ofs[2];
-       }
-       
-       if(lr_click) {
-// XXX         if(G.obedit->type==OB_MESH) add_click_mesh();
-//             else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) addvert_Nurb(0);
-//             else if (G.obedit->type==OB_ARMATURE) addvert_armature();
-               VECCOPY(fp, oldcurs);
-       }
-       
-}
-
-void deselectall(View3D *v3d)  /* is toggle */
+void deselectall(Scene *scene, View3D *v3d)    /* is toggle */
 {
        Base *base;
        int a=0, ok=0; 
@@ -806,7 +763,7 @@ void selectrandom(Scene *scene, View3D *v3d)
 }
 
 /* selects all objects of a particular type, on currently visible layers */
-void selectall_type(View3D *v3d, short obtype) 
+void selectall_type(Scene *scene, View3D *v3d, short obtype) 
 {
        Base *base;
        
@@ -825,7 +782,7 @@ void selectall_type(View3D *v3d, short obtype)
        BIF_undo_push("Select all per type");
 }
 /* selects all objects on a particular layer */
-void selectall_layer(unsigned int layernum) 
+void selectall_layer(Scene *scene, unsigned int layernum) 
 {
        Base *base;
        
@@ -1277,33 +1234,71 @@ static void mouse_select(Scene *scene, ARegion *ar, View3D *v3d, short *mval)
        
 }
 
-static int view3d_select_invoke(bContext *C, wmOperator *op, wmEvent *event)
+/* *****************Selection Operations Operator******************* */
+
+static EnumPropertyItem prop_select_items[] = {
+       {V3D_SELECT_MOUSE, "NORMAL", "Normal Select", "Select using the mouse"},
+       {0, NULL, NULL, NULL}};
+               
+static int view3d_select_exec(bContext *C, wmOperator *op)
 {
        ScrArea *sa= CTX_wm_area(C);
        ARegion *ar= CTX_wm_region(C);
        View3D *v3d= sa->spacedata.first;
+       Scene *scene= CTX_data_scene(C);
+       int select_type;
        short mval[2];
+
+       select_type = RNA_enum_get(op->ptr, "select_type");
        
-       /* note; otherwise opengl select won't work. do this for every glSelectBuffer() */
-       wmSubWindowSet(CTX_wm_window(C), ar->swinid);
+       view3d_operator_needs_opengl(C);
+       printf("about to look at enum");
+       switch (select_type) {
+               case V3D_SELECT_MOUSE :
+                       printf("caught event");
+                       mval[0] = RNA_int_get(op->ptr, "mx");
+                       mval[1] = RNA_int_get(op->ptr, "my");
+                       mouse_select(scene, ar, v3d, mval);
+                       printf("selected object");
+                       break;
+       }
+       return OPERATOR_FINISHED;
+}
+
+static int view3d_select_invoke(bContext *C, wmOperator *op, wmEvent *event)
+{
+       ScrArea *sa= CTX_wm_area(C);
+       ARegion *ar= CTX_wm_region(C);
+       View3D *v3d= sa->spacedata.first;
+       short mval[2];  
        
        mval[0]= event->x - ar->winrct.xmin;
        mval[1]= event->y - ar->winrct.ymin;
-       mouse_select(CTX_data_scene(C), ar, v3d, mval);
+       
+       RNA_int_set(op->ptr, "mx", mval[0]);
+       RNA_int_set(op->ptr, "my", mval[1]);
+
+       return view3d_select_exec(C,op);
 
-       return OPERATOR_FINISHED;
 }
 
-void ED_VIEW3D_OT_select(wmOperatorType *ot)
+void VIEW3D_OT_select(wmOperatorType *ot)
 {
+       PropertyRNA *prop;
        
        /* identifiers */
        ot->name= "Activate/Select";
-       ot->idname= "ED_VIEW3D_OT_select";
+       ot->idname= "VIEW3D_OT_select";
        
        /* api callbacks */
        ot->invoke= view3d_select_invoke;
-       ot->poll= ED_operator_areaactive;
+       ot->poll= ED_operator_view3d_active;
+       
+       prop = RNA_def_property(ot->srna, "select_type", PROP_ENUM, PROP_NONE);
+       RNA_def_property_enum_items(prop, prop_select_items);
+       
+       prop = RNA_def_property(ot->srna, "mx", PROP_INT, PROP_NONE);
+       prop = RNA_def_property(ot->srna, "my", PROP_INT, PROP_NONE);
 }
 
 /* ********************  border and circle ************************************** */
@@ -1659,19 +1654,19 @@ static int view3d_borderselect_exec(bContext *C, wmOperator *op)
 } 
 
 
-void ED_VIEW3D_OT_borderselect(wmOperatorType *ot)
+void VIEW3D_OT_borderselect(wmOperatorType *ot)
 {
        
        /* identifiers */
        ot->name= "Border Select";
-       ot->idname= "ED_VIEW3D_OT_borderselect";
+       ot->idname= "VIEW3D_OT_borderselect";
        
        /* api callbacks */
        ot->invoke= WM_border_select_invoke;
        ot->exec= view3d_borderselect_exec;
        ot->modal= WM_border_select_modal;
        
-       ot->poll= ED_operator_areaactive;
+       ot->poll= ED_operator_view3d_active;
        
        /* rna */
        RNA_def_property(ot->srna, "event_type", PROP_INT, PROP_NONE);
@@ -1863,6 +1858,7 @@ static int view3d_circle_select(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;
 
@@ -1886,15 +1882,15 @@ static int view3d_circle_select(bContext *C, wmOperator *op)
        return 0;
 }
 
-void ED_VIEW3D_OT_circle_select(wmOperatorType *ot)
+void VIEW3D_OT_circle_select(wmOperatorType *ot)
 {
        ot->name= "Circle Select";
-       ot->idname= "ED_VIEW3D_OT_circle_select";
+       ot->idname= "VIEW3D_OT_circle_select";
        
        ot->invoke= WM_gesture_circle_invoke;
        ot->modal= WM_gesture_circle_modal;
        ot->exec= view3d_circle_select;
-       ot->poll= WM_operator_winactive;
+       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);