From 3953b82030ab75689ece389c02b8c7ca389311b4 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Wed, 16 Jun 2021 15:52:56 +0200 Subject: Tweaks to Constraints operators poll functions. Mainly: * Make `ED_operator_object_active_editable_ex` properly report poll messages on failure. * Add `ED_operator_object_active_local_editable_posemode_exclusive` for bone constraints requiring pure local Object (non-override one). * General cleanup and adding more poll messages on failures. --- source/blender/editors/include/ED_screen.h | 1 + source/blender/editors/object/object_constraint.c | 11 ++-- source/blender/editors/screen/screen_ops.c | 65 +++++++++++++++++------ 3 files changed, 56 insertions(+), 21 deletions(-) (limited to 'source/blender/editors') diff --git a/source/blender/editors/include/ED_screen.h b/source/blender/editors/include/ED_screen.h index addc3628f9e..a611fb50e4e 100644 --- a/source/blender/editors/include/ED_screen.h +++ b/source/blender/editors/include/ED_screen.h @@ -354,6 +354,7 @@ bool ED_operator_uvedit(struct bContext *C); bool ED_operator_uvedit_space_image(struct bContext *C); bool ED_operator_uvmap(struct bContext *C); bool ED_operator_posemode_exclusive(struct bContext *C); +bool ED_operator_object_active_local_editable_posemode_exclusive(struct bContext *C); bool ED_operator_posemode_context(struct bContext *C); bool ED_operator_posemode(struct bContext *C); bool ED_operator_posemode_local(struct bContext *C); diff --git a/source/blender/editors/object/object_constraint.c b/source/blender/editors/object/object_constraint.c index 244124a6e0a..06d6f2b94f3 100644 --- a/source/blender/editors/object/object_constraint.c +++ b/source/blender/editors/object/object_constraint.c @@ -696,12 +696,11 @@ static bool edit_constraint_poll_generic(bContext *C, Object *ob = (ptr.owner_id) ? (Object *)ptr.owner_id : ED_object_active_context(C); bConstraint *con = ptr.data; - if (!ob) { - CTX_wm_operator_poll_msg_set(C, "Context missing active object"); + if (!ED_operator_object_active_editable_ex(C, ob)) { return false; } - if (ID_IS_LINKED(ob) || (ptr.owner_id && ID_IS_LINKED(ptr.owner_id))) { + if (ptr.owner_id != NULL && ID_IS_LINKED(ptr.owner_id)) { CTX_wm_operator_poll_msg_set(C, "Cannot edit library data"); return false; } @@ -1746,8 +1745,8 @@ void POSE_OT_constraints_clear(wmOperatorType *ot) /* callbacks */ ot->exec = pose_constraints_clear_exec; - ot->poll = ED_operator_posemode_exclusive; /* XXX - do we want to ensure there are selected - * bones too? */ + /* XXX - do we want to ensure there are selected bones too? */ + ot->poll = ED_operator_object_active_local_editable_posemode_exclusive; } static int object_constraints_clear_exec(bContext *C, wmOperator *UNUSED(op)) @@ -2480,7 +2479,7 @@ void POSE_OT_ik_clear(wmOperatorType *ot) /* api callbacks */ ot->exec = pose_ik_clear_exec; - ot->poll = ED_operator_posemode_exclusive; + ot->poll = ED_operator_object_active_local_editable_posemode_exclusive; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c index 92413e808d3..88227207a24 100644 --- a/source/blender/editors/screen/screen_ops.c +++ b/source/blender/editors/screen/screen_ops.c @@ -358,9 +358,24 @@ bool ED_operator_object_active(bContext *C) return ((ob != NULL) && !ed_object_hidden(ob)); } -bool ED_operator_object_active_editable_ex(bContext *UNUSED(C), const Object *ob) +bool ED_operator_object_active_editable_ex(bContext *C, const Object *ob) { - return ((ob != NULL) && !ID_IS_LINKED(ob) && !ed_object_hidden(ob)); + if (ob == NULL) { + CTX_wm_operator_poll_msg_set(C, "Context missing active object"); + return false; + } + + if (ID_IS_LINKED(ob)) { + CTX_wm_operator_poll_msg_set(C, "Cannot edit library linked object"); + return false; + } + + if (ed_object_hidden(ob)) { + CTX_wm_operator_poll_msg_set(C, "Cannot edit hidden obect"); + return false; + } + + return true; } bool ED_operator_object_active_editable(bContext *C) @@ -444,28 +459,48 @@ bool ED_operator_editarmature(bContext *C) } /** - * \brief check for pose mode (no mixed modes) + * Check for pose mode (no mixed modes). * - * We want to enable most pose operations in weight paint mode, - * when it comes to transforming bones, but managing bones layers/groups - * can be left for pose mode only. (not weight paint mode) + * We want to enable most pose operations in weight paint mode, when it comes to transforming + * bones, but managing bones layers/groups and their constraints can be left for pose mode only + * (not weight paint mode). */ -bool ED_operator_posemode_exclusive(bContext *C) +static bool ed_operator_posemode_exclusive_ex(bContext *C, Object *obact) { - Object *obact = CTX_data_active_object(C); - - if (obact && !(obact->mode & OB_MODE_EDIT)) { - Object *obpose = BKE_object_pose_armature_get(obact); - if (obpose != NULL) { - if (obact == obpose) { - return true; - } + if (obact != NULL && !(obact->mode & OB_MODE_EDIT)) { + if (obact == BKE_object_pose_armature_get(obact)) { + return true; } } + CTX_wm_operator_poll_msg_set(C, "No object, or not exclusively in pose mode"); return false; } +bool ED_operator_posemode_exclusive(bContext *C) +{ + Object *obact = ED_object_active_context(C); + + return ed_operator_posemode_exclusive_ex(C, obact); +} + +/** Object must be editable, fully local (i.e. not an override), and exclusively in Pose mode. */ +bool ED_operator_object_active_local_editable_posemode_exclusive(bContext *C) +{ + Object *obact = ED_object_active_context(C); + + if (!ed_operator_posemode_exclusive_ex(C, obact)) { + return false; + } + + if (ID_IS_OVERRIDE_LIBRARY(obact)) { + CTX_wm_operator_poll_msg_set(C, "Object is a local library override"); + return false; + } + + return true; +} + /* allows for pinned pose objects to be used in the object buttons * and the non-active pose object to be used in the 3D view */ bool ED_operator_posemode_context(bContext *C) -- cgit v1.2.3