2.5
[blender.git] / source / blender / editors / space_view3d / view3d_select.c
index 9d0616d4f54b27b13582af79f77c97d1aad17bbf..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,20 +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);
@@ -1680,7 +1674,6 @@ void ED_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);
-       
 }
 
 
@@ -1861,232 +1854,46 @@ void obedit_selectionCB(Scene *scene, ARegion *ar, View3D *v3d, short selecting,
 //     force_draw(0);
 }
 
-void set_render_border(Scene *scene, ARegion *ar, View3D *v3d)
+static int view3d_circle_select(bContext *C, wmOperator *op)
 {
-       rcti rect;
-       short val;
-       
-       val= 0; // XXX get_border(&rect, 3);
-       if(val) {
-               rctf vb;
-
-               calc_viewborder(scene, ar, v3d, &vb);
+       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;
 
-               scene->r.border.xmin= ((float)rect.xmin-vb.xmin)/(vb.xmax-vb.xmin);
-               scene->r.border.ymin= ((float)rect.ymin-vb.ymin)/(vb.ymax-vb.ymin);
-               scene->r.border.xmax= ((float)rect.xmax-vb.xmin)/(vb.xmax-vb.xmin);
-               scene->r.border.ymax= ((float)rect.ymax-vb.ymin)/(vb.ymax-vb.ymin);
+       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)
                                
-               CLAMP(scene->r.border.xmin, 0.0, 1.0);
-               CLAMP(scene->r.border.ymin, 0.0, 1.0);
-               CLAMP(scene->r.border.xmax, 0.0, 1.0);
-               CLAMP(scene->r.border.ymax, 0.0, 1.0);
-       
-               /* drawing a border surrounding the entire camera view switches off border rendering
-                * or the border covers no pixels */
-               if ((scene->r.border.xmin <= 0.0 && scene->r.border.xmax >= 1.0 &&
-                       scene->r.border.ymin <= 0.0 && scene->r.border.ymax >= 1.0) ||
-                  (scene->r.border.xmin == scene->r.border.xmax ||
-                       scene->r.border.ymin == scene->r.border.ymax ))
-               {
-                       scene->r.mode &= ~R_BORDER;
-               } else {
-                       scene->r.mode |= R_BORDER;
+                                       select_base_v3d(base, BA_SELECT);
+                               base->object->flag= base->flag;
+                       }
                }
        }
+       return 0;
 }
 
-void view3d_border_zoom(Scene *scene, ARegion *ar, View3D *v3d)
+void VIEW3D_OT_circle_select(wmOperatorType *ot)
 {
+       ot->name= "Circle Select";
+       ot->idname= "VIEW3D_OT_circle_select";
        
-       /* Zooms in on a border drawn by the user */
-       rcti rect;
-       short val;
-       float dvec[3], vb[2], xscale, yscale, scale;
-       
-       
-       /* SMOOTHVIEW */
-       float new_dist;
-       float new_ofs[3];
-       
-       /* ZBuffer depth vars */
-       bglMats mats;
-       float depth, depth_close= MAXFLOAT;
-       int had_depth = 0;
-       double cent[2],  p[3];
-       int xs, ys;
-       
-       /* Get the border input */
-       val = 0; // XXX get_border(&rect, 3);
-       if(!val) return;
-       
-       /* Get Z Depths, needed for perspective, nice for ortho */
-       bgl_get_mats(&mats);
-       draw_depth(scene, ar, v3d, NULL);
-       
-       /* force updating */
-       if (v3d->depths) {
-               had_depth = 1;
-               v3d->depths->damaged = 1;
-       }
-       
-       view3d_update_depths(ar, v3d);
-       
-       /* Constrain rect to depth bounds */
-       if (rect.xmin < 0) rect.xmin = 0;
-       if (rect.ymin < 0) rect.ymin = 0;
-       if (rect.xmax >= v3d->depths->w) rect.xmax = v3d->depths->w-1;
-       if (rect.ymax >= v3d->depths->h) rect.ymax = v3d->depths->h-1;          
-       
-       /* Find the closest Z pixel */
-       for (xs=rect.xmin; xs < rect.xmax; xs++) {
-               for (ys=rect.ymin; ys < rect.ymax; ys++) {
-                       depth= v3d->depths->depths[ys*v3d->depths->w+xs];
-                       if(depth < v3d->depths->depth_range[1] && depth > v3d->depths->depth_range[0]) {
-                               if (depth_close > depth) {
-                                       depth_close = depth;
-                               }
-                       }
-               }
-       }
-       
-       if (had_depth==0) {
-               MEM_freeN(v3d->depths->depths);
-               v3d->depths->depths = NULL;
-       }
-       v3d->depths->damaged = 1;
+       ot->invoke= WM_gesture_circle_invoke;
+       ot->modal= WM_gesture_circle_modal;
+       ot->exec= view3d_circle_select;
+       ot->poll= ED_operator_view3d_active;
        
-       cent[0] = (((double)rect.xmin)+((double)rect.xmax)) / 2;
-       cent[1] = (((double)rect.ymin)+((double)rect.ymax)) / 2;
+       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);
        
-       if (v3d->persp==V3D_PERSP) {
-               double p_corner[3];
-
-               /* no depths to use, we cant do anything! */
-               if (depth_close==MAXFLOAT) 
-                       return;
-               
-               /* convert border to 3d coordinates */
-               if ((   !gluUnProject(cent[0], cent[1], depth_close, mats.modelview, mats.projection, (GLint *)mats.viewport, &p[0], &p[1], &p[2])) || 
-                       (       !gluUnProject((double)rect.xmin, (double)rect.ymin, depth_close, mats.modelview, mats.projection, (GLint *)mats.viewport, &p_corner[0], &p_corner[1], &p_corner[2])))
-                       return;
-               
-               dvec[0] = p[0]-p_corner[0];
-               dvec[1] = p[1]-p_corner[1];
-               dvec[2] = p[2]-p_corner[2];
-               
-               new_dist = VecLength(dvec);
-               if(new_dist <= v3d->near*1.5) new_dist= v3d->near*1.5; 
-               
-               new_ofs[0] = -p[0];
-               new_ofs[1] = -p[1];
-               new_ofs[2] = -p[2];
-               
-       } else { /* othographic */
-               /* find the current window width and height */
-               vb[0] = ar->winx;
-               vb[1] = ar->winy;
-               
-               new_dist = v3d->dist;
-               
-               /* convert the drawn rectangle into 3d space */
-               if (depth_close!=MAXFLOAT && gluUnProject(cent[0], cent[1], depth_close, mats.modelview, mats.projection, (GLint *)mats.viewport, &p[0], &p[1], &p[2])) {
-                       new_ofs[0] = -p[0];
-                       new_ofs[1] = -p[1];
-                       new_ofs[2] = -p[2];
-               } else {
-                       /* We cant use the depth, fallback to the old way that dosnt set the center depth */
-                       new_ofs[0] = v3d->ofs[0];
-                       new_ofs[1] = v3d->ofs[1];
-                       new_ofs[2] = v3d->ofs[2];
-                       
-                       initgrabz(v3d, -new_ofs[0], -new_ofs[1], -new_ofs[2]);
-                       
-                       window_to_3d(ar, v3d, dvec, (rect.xmin+rect.xmax-vb[0])/2, (rect.ymin+rect.ymax-vb[1])/2);
-                       /* center the view to the center of the rectangle */
-                       VecSubf(new_ofs, new_ofs, dvec);
-               }
-               
-               /* work out the ratios, so that everything selected fits when we zoom */
-               xscale = ((rect.xmax-rect.xmin)/vb[0]);
-               yscale = ((rect.ymax-rect.ymin)/vb[1]);
-               scale = (xscale >= yscale)?xscale:yscale;
-               
-               /* zoom in as required, or as far as we can go */
-               new_dist = ((new_dist*scale) >= 0.001*v3d->grid)? new_dist*scale:0.001*v3d->grid;
-       }
-       
-       smooth_view(v3d, new_ofs, NULL, &new_dist, NULL);
 }
-
-
-void view3d_edit_clipping(ARegion *ar, View3D *v3d)
-{
-       
-       if(v3d->flag & V3D_CLIPPING) {
-               v3d->flag &= ~V3D_CLIPPING;
-               ED_region_tag_redraw(ar);
-               if(v3d->clipbb) MEM_freeN(v3d->clipbb);
-               v3d->clipbb= NULL;
-       }
-       else {
-               rcti rect;
-               double mvmatrix[16];
-               double projmatrix[16];
-               double xs, ys, p[3];
-               GLint viewport[4];
-               short val;
-               
-               /* get border in window coords */
-               setlinestyle(2);
-               val= 0; // XX get_border(&rect, 3);
-               setlinestyle(0);
-               if(val==0) return;
-               
-               v3d->flag |= V3D_CLIPPING;
-               v3d->clipbb= MEM_callocN(sizeof(BoundBox), "clipbb");
-               
-               /* convert border to 3d coordinates */
-               
-               /* Get the matrices needed for gluUnProject */
-               glGetIntegerv(GL_VIEWPORT, viewport);
-               glGetDoublev(GL_MODELVIEW_MATRIX, mvmatrix);
-               glGetDoublev(GL_PROJECTION_MATRIX, projmatrix);
-
-               /* near zero floating point values can give issues with gluUnProject
-                  in side view on some implementations */
-               if(fabs(mvmatrix[0]) < 1e-6) mvmatrix[0]= 0.0;
-               if(fabs(mvmatrix[5]) < 1e-6) mvmatrix[5]= 0.0;
-               
-               /* Set up viewport so that gluUnProject will give correct values */
-               viewport[0] = 0;
-               viewport[1] = 0;
-               
-               /* four clipping planes and bounding volume */
-               /* first do the bounding volume */
-               for(val=0; val<4; val++) {
-                       
-                       xs= (val==0||val==3)?rect.xmin:rect.xmax;
-                       ys= (val==0||val==1)?rect.ymin:rect.ymax;
-                       
-                       gluUnProject(xs, ys, 0.0, mvmatrix, projmatrix, viewport, &p[0], &p[1], &p[2]);
-                       VECCOPY(v3d->clipbb->vec[val], p);
-                       
-                       gluUnProject(xs, ys, 1.0, mvmatrix, projmatrix, viewport, &p[0], &p[1], &p[2]);
-                       VECCOPY(v3d->clipbb->vec[4+val], p);
-               }
-               
-               /* then plane equations */
-               for(val=0; val<4; val++) {
-                       
-                       CalcNormFloat(v3d->clipbb->vec[val], v3d->clipbb->vec[val==3?0:val+1], v3d->clipbb->vec[val+4],
-                                                 v3d->clip[val]); 
-                       
-                       v3d->clip[val][3]= - v3d->clip[val][0]*v3d->clipbb->vec[val][0] 
-                                                          - v3d->clip[val][1]*v3d->clipbb->vec[val][1] 
-                                                          - v3d->clip[val][2]*v3d->clipbb->vec[val][2];
-               }
-       }
-}
-
-