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.
This commit is contained in:
Bastien Montagne 2021-06-16 15:52:56 +02:00
parent 88aa056d1a
commit 3953b82030
3 changed files with 56 additions and 21 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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)