View3D: move some of the early returns from operators to the poll function

Some navigation operators check flags like `RV3D_LOCK_ROTATION` in the
invoke function to see if the operation can be performed.

As the comment indicates, these checks should be in the poll function.

This avoids redundant initialization.

Note that this brings functional changes as now operators with context
`EXEC_DEFAULT`  will also be affected by the flag.
(There doesn't seem to be a problem with the current code).

Differential Revision: https://developer.blender.org/D14005
This commit is contained in:
Germano Cavalcante 2022-02-03 14:00:41 -03:00
parent 7099d5b661
commit 3d973d01fa
5 changed files with 26 additions and 34 deletions

View File

@ -59,22 +59,29 @@
/** \name Navigation Polls
* \{ */
static bool view3d_pan_poll(bContext *C)
static bool view3d_navigation_poll_impl(bContext *C, const char viewlock)
{
if (ED_operator_region_view3d_active(C)) {
const RegionView3D *rv3d = CTX_wm_region_view3d(C);
return !(RV3D_LOCK_FLAGS(rv3d) & RV3D_LOCK_LOCATION);
if (!ED_operator_region_view3d_active(C)) {
return false;
}
return false;
const RegionView3D *rv3d = CTX_wm_region_view3d(C);
return !(RV3D_LOCK_FLAGS(rv3d) & viewlock);
}
bool view3d_location_poll(bContext *C)
{
return view3d_navigation_poll_impl(C, RV3D_LOCK_LOCATION);
}
bool view3d_rotation_poll(bContext *C)
{
return view3d_navigation_poll_impl(C, RV3D_LOCK_ROTATION);
}
bool view3d_zoom_or_dolly_poll(bContext *C)
{
if (ED_operator_region_view3d_active(C)) {
const RegionView3D *rv3d = CTX_wm_region_view3d(C);
return !(RV3D_LOCK_FLAGS(rv3d) & RV3D_LOCK_ZOOM_AND_DOLLY);
}
return false;
return view3d_navigation_poll_impl(C, RV3D_LOCK_ZOOM_AND_DOLLY);
}
/** \} */
@ -1053,7 +1060,7 @@ void VIEW3D_OT_view_center_cursor(wmOperatorType *ot)
/* api callbacks */
ot->exec = viewcenter_cursor_exec;
ot->poll = view3d_pan_poll;
ot->poll = view3d_location_poll;
/* flags */
ot->flag = 0;
@ -1105,7 +1112,7 @@ void VIEW3D_OT_view_center_pick(wmOperatorType *ot)
/* api callbacks */
ot->invoke = viewcenter_pick_invoke;
ot->poll = view3d_pan_poll;
ot->poll = view3d_location_poll;
/* flags */
ot->flag = 0;
@ -1582,7 +1589,7 @@ void VIEW3D_OT_view_pan(wmOperatorType *ot)
/* api callbacks */
ot->invoke = viewpan_invoke;
ot->poll = view3d_pan_poll;
ot->poll = view3d_location_poll;
/* flags */
ot->flag = 0;

View File

@ -149,6 +149,8 @@ typedef struct ViewOpsData {
} ViewOpsData;
/* view3d_navigate.c */
bool view3d_location_poll(struct bContext *C);
bool view3d_rotation_poll(struct bContext *C);
bool view3d_zoom_or_dolly_poll(struct bContext *C);
enum eViewOpsFlag viewops_flag_from_prefs(void);

View File

@ -243,12 +243,6 @@ static int viewdolly_invoke(bContext *C, wmOperator *op, const wmEvent *event)
viewops_data_alloc(C, op);
vod = op->customdata;
/* poll should check but in some cases fails, see poll func for details */
if (RV3D_LOCK_FLAGS(vod->rv3d) & RV3D_LOCK_ROTATION) {
viewops_data_free(C, op);
return OPERATOR_PASS_THROUGH;
}
ED_view3d_smooth_view_force_finish(C, vod->v3d, vod->region);
/* needs to run before 'viewops_data_create' so the backup 'rv3d->ofs' is correct */
@ -329,7 +323,7 @@ void VIEW3D_OT_dolly(wmOperatorType *ot)
ot->invoke = viewdolly_invoke;
ot->exec = viewdolly_exec;
ot->modal = viewdolly_modal;
ot->poll = ED_operator_region_view3d_active;
ot->poll = view3d_rotation_poll;
ot->cancel = viewdolly_cancel;
/* flags */

View File

@ -133,17 +133,12 @@ static int viewmove_invoke(bContext *C, wmOperator *op, const wmEvent *event)
/* makes op->customdata */
viewops_data_alloc(C, op);
vod = op->customdata;
if (RV3D_LOCK_FLAGS(vod->rv3d) & RV3D_LOCK_LOCATION) {
viewops_data_free(C, op);
return OPERATOR_PASS_THROUGH;
}
viewops_data_create(C,
op,
event,
(viewops_flag_from_prefs() & ~VIEWOPS_FLAG_ORBIT_SELECT) |
(use_cursor_init ? VIEWOPS_FLAG_USE_MOUSE_INIT : 0));
vod = op->customdata;
ED_view3d_smooth_view_force_finish(C, vod->v3d, vod->region);
@ -179,7 +174,7 @@ void VIEW3D_OT_move(wmOperatorType *ot)
/* api callbacks */
ot->invoke = viewmove_invoke;
ot->modal = viewmove_modal;
ot->poll = ED_operator_region_view3d_active;
ot->poll = view3d_location_poll;
ot->cancel = viewmove_cancel;
/* flags */

View File

@ -386,12 +386,6 @@ static int viewrotate_invoke(bContext *C, wmOperator *op, const wmEvent *event)
viewops_data_alloc(C, op);
vod = op->customdata;
/* poll should check but in some cases fails, see poll func for details */
if (RV3D_LOCK_FLAGS(vod->rv3d) & RV3D_LOCK_ROTATION) {
viewops_data_free(C, op);
return OPERATOR_PASS_THROUGH;
}
ED_view3d_smooth_view_force_finish(C, vod->v3d, vod->region);
viewops_data_create(C,
@ -446,7 +440,7 @@ void VIEW3D_OT_rotate(wmOperatorType *ot)
/* api callbacks */
ot->invoke = viewrotate_invoke;
ot->modal = viewrotate_modal;
ot->poll = ED_operator_region_view3d_active;
ot->poll = view3d_rotation_poll;
ot->cancel = viewrotate_cancel;
/* flags */