diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h index c84c0e83626..4cac1a8d618 100644 --- a/source/blender/editors/include/ED_view3d.h +++ b/source/blender/editors/include/ED_view3d.h @@ -163,6 +163,8 @@ int lasso_inside_edge(short mcords[][2], short moves, int x0, int y0, int x1, in /* get 3d region from context, also if mouse is in header or toolbar */ struct RegionView3D *ED_view3d_context_rv3d(struct bContext *C); +struct ARegion *ED_view3d_context_region_unlock(struct bContext *C); +int ED_operator_rv3d_unlock_poll(struct bContext *C); void ED_view3d_init_mats_rv3d(struct Object *ob, struct RegionView3D *rv3d); diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c index a8cdc99645d..93d86f2d97b 100644 --- a/source/blender/editors/space_view3d/space_view3d.c +++ b/source/blender/editors/space_view3d/space_view3d.c @@ -156,6 +156,44 @@ RegionView3D *ED_view3d_context_rv3d(bContext *C) return rv3d; } +/* ideally would return an rv3d but in some cases the region is needed too + * so return that, the caller can then access the ar->regiondata */ +ARegion *ED_view3d_context_region_unlock(bContext *C) +{ + ScrArea *sa= CTX_wm_area(C); + if(sa && sa->spacetype==SPACE_VIEW3D) { + ARegion *ar= CTX_wm_region(C); + if(ar) { + RegionView3D *rv3d= ar->regiondata; + if(rv3d && rv3d->viewlock == 0) { + return ar; + } + else { + ARegion *ar_unlock_user= NULL; + ARegion *ar_unlock= NULL; + for(ar= sa->regionbase.first; ar; ar= ar->next) { + /* find the first unlocked rv3d */ + if(ar->regiondata && ar->regiontype == RGN_TYPE_WINDOW) { + rv3d= ar->regiondata; + if(rv3d->viewlock == 0) { + ar_unlock= ar; + if(rv3d->persp==RV3D_PERSP || rv3d->persp==RV3D_CAMOB) { + ar_unlock_user= ar; + break; + } + } + } + } + + /* camera/perspective view get priority when the active region is locked */ + if(ar_unlock_user) return ar_unlock_user; + if(ar_unlock) return ar_unlock; + } + } + } + return NULL; +} + /* Most of the time this isn't needed since you could assume the view matrix was * set while drawing, however when functions like mesh_foreachScreenVert are * called by selection tools, we can't be sure this object was the last. diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index fe90b8daa97..bfde8a8972c 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -2151,8 +2151,8 @@ static EnumPropertyItem prop_view_items[] = { static void axis_set_view(bContext *C, float q1, float q2, float q3, float q4, short view, int perspo, int align_active) { View3D *v3d = CTX_wm_view3d(C); - ARegion *ar= CTX_wm_region(C); - RegionView3D *rv3d= CTX_wm_region_view3d(C); + ARegion *ar= ED_view3d_context_region_unlock(C); + RegionView3D *rv3d= ar->regiondata; /* no NULL check is needed, poll checks */ float new_quat[4]; new_quat[0]= q1; new_quat[1]= q2; @@ -2221,8 +2221,8 @@ static void axis_set_view(bContext *C, float q1, float q2, float q3, float q4, s static int viewnumpad_exec(bContext *C, wmOperator *op) { View3D *v3d = CTX_wm_view3d(C); - ARegion *ar= CTX_wm_region(C); - RegionView3D *rv3d= CTX_wm_region_view3d(C); + ARegion *ar= ED_view3d_context_region_unlock(C); + RegionView3D *rv3d= ar->regiondata; /* no NULL check is needed, poll checks */ Scene *scene= CTX_data_scene(C); static int perspo=RV3D_PERSP; int viewnum, align_active, nextperspo; @@ -2350,7 +2350,7 @@ void VIEW3D_OT_viewnumpad(wmOperatorType *ot) /* api callbacks */ ot->exec= viewnumpad_exec; - ot->poll= ED_operator_region_view3d_active; + ot->poll= ED_operator_rv3d_unlock_poll; /* flags */ ot->flag= 0; @@ -2368,7 +2368,8 @@ static EnumPropertyItem prop_view_orbit_items[] = { static int vieworbit_exec(bContext *C, wmOperator *op) { - RegionView3D *rv3d= CTX_wm_region_view3d(C); + ARegion *ar= ED_view3d_context_region_unlock(C); + RegionView3D *rv3d= ar->regiondata; /* no NULL check is needed, poll checks */ float phi, q1[4], new_quat[4]; int orbitdir; @@ -2402,7 +2403,7 @@ static int vieworbit_exec(bContext *C, wmOperator *op) rv3d->view= 0; } - smooth_view(C, CTX_wm_view3d(C), CTX_wm_region(C), NULL, NULL, NULL, new_quat, NULL, NULL); + smooth_view(C, CTX_wm_view3d(C), ar, NULL, NULL, NULL, new_quat, NULL, NULL); } } @@ -2418,7 +2419,7 @@ void VIEW3D_OT_view_orbit(wmOperatorType *ot) /* api callbacks */ ot->exec= vieworbit_exec; - ot->poll= ED_operator_region_view3d_active; + ot->poll= ED_operator_rv3d_unlock_poll; /* flags */ ot->flag= 0; @@ -2474,8 +2475,8 @@ void VIEW3D_OT_view_pan(wmOperatorType *ot) static int viewpersportho_exec(bContext *C, wmOperator *UNUSED(op)) { - ARegion *ar= CTX_wm_region(C); - RegionView3D *rv3d= CTX_wm_region_view3d(C); + ARegion *ar= ED_view3d_context_region_unlock(C); + RegionView3D *rv3d= ar->regiondata; /* no NULL check is needed, poll checks */ if(rv3d->viewlock==0) { if(rv3d->persp!=RV3D_ORTHO) @@ -2497,12 +2498,13 @@ void VIEW3D_OT_view_persportho(wmOperatorType *ot) /* api callbacks */ ot->exec= viewpersportho_exec; - ot->poll= ED_operator_region_view3d_active; + ot->poll= ED_operator_rv3d_unlock_poll; /* flags */ ot->flag= 0; } + /* ******************** add background image operator **************** */ static BGpic *background_image_add(bContext *C) diff --git a/source/blender/editors/space_view3d/view3d_view.c b/source/blender/editors/space_view3d/view3d_view.c index faec04917a0..15f6fae8c71 100644 --- a/source/blender/editors/space_view3d/view3d_view.c +++ b/source/blender/editors/space_view3d/view3d_view.c @@ -466,8 +466,8 @@ void VIEW3D_OT_setcameratoview(wmOperatorType *ot) static int view3d_setobjectascamera_exec(bContext *C, wmOperator *UNUSED(op)) { View3D *v3d = CTX_wm_view3d(C); - ARegion *ar= CTX_wm_region(C); - RegionView3D *rv3d= ar->regiondata; + ARegion *ar= ED_view3d_context_region_unlock(C); + RegionView3D *rv3d= ar->regiondata; /* no NULL check is needed, poll checks */ Scene *scene= CTX_data_scene(C); Object *ob = CTX_data_active_object(C); @@ -487,13 +487,11 @@ static int view3d_setobjectascamera_exec(bContext *C, wmOperator *UNUSED(op)) return OPERATOR_FINISHED; } -static int region3d_unlocked_poll(bContext *C) +int ED_operator_rv3d_unlock_poll(bContext *C) { - RegionView3D *rv3d= CTX_wm_region_view3d(C); - return (rv3d && rv3d->viewlock==0); + return ED_view3d_context_region_unlock(C) != NULL; } - void VIEW3D_OT_object_as_camera(wmOperatorType *ot) { @@ -504,7 +502,7 @@ void VIEW3D_OT_object_as_camera(wmOperatorType *ot) /* api callbacks */ ot->exec= view3d_setobjectascamera_exec; - ot->poll= region3d_unlocked_poll; + ot->poll= ED_operator_rv3d_unlock_poll; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;