Fix T39895: Displaying the armature layers popup in edit mode always fails.

In fact, armature layers operators (set layers, and show all) were kind of messy and broken
in Edit mode (Select layers had two different operators for Pose and Edit modes, both
using the same funcs that could only work in Pose mode, Show All was supposed to be
used in both modes but again, its exec code could only work in Pose one).

Fixed that by:
* Using only one op for each task, for both modes (with adapted poll func).
* Replacing 'object from context' access by an helper that returns the right Armature
object in both Edit and Pose modes.
This commit is contained in:
Bastien Montagne 2014-04-25 17:07:30 +02:00
parent dd86773969
commit 18060d8632
Notes: blender-bot 2023-02-14 10:44:55 +01:00
Referenced by issue #39895, Displaying the armature layers popup in edit mode always fails
Referenced by issue #39895, Displaying the armature layers popup in edit mode always fails
6 changed files with 42 additions and 43 deletions

View File

@ -270,7 +270,7 @@ kmi.properties.name = 'VIEW3D_MT_bone_options_enable'
kmi = km.keymap_items.new('wm.call_menu', 'W', 'PRESS', alt=True)
kmi.properties.name = 'VIEW3D_MT_bone_options_disable'
kmi = km.keymap_items.new('armature.layers_show_all', 'ACCENT_GRAVE', 'PRESS', ctrl=True)
kmi = km.keymap_items.new('pose.armature_layers', 'M', 'PRESS', shift=True)
kmi = km.keymap_items.new('armature.armature_layers', 'M', 'PRESS', shift=True)
kmi = km.keymap_items.new('pose.bone_layers', 'M', 'PRESS')
kmi = km.keymap_items.new('transform.transform', 'S', 'PRESS', ctrl=True, alt=True)
kmi.properties.mode = 'BONE_SIZE'

View File

@ -326,7 +326,7 @@ kmi.properties.name = 'VIEW3D_MT_pose_group'
kmi = km.keymap_items.new('wm.call_menu', 'RIGHTMOUSE', 'PRESS')
kmi.properties.name = 'VIEW3D_MT_bone_options_toggle'
kmi = km.keymap_items.new('armature.layers_show_all', 'ACCENT_GRAVE', 'PRESS', ctrl=True)
kmi = km.keymap_items.new('pose.armature_layers', 'M', 'PRESS', shift=True)
kmi = km.keymap_items.new('armature.armature_layers', 'M', 'PRESS', shift=True)
kmi = km.keymap_items.new('pose.bone_layers', 'M', 'PRESS')
kmi = km.keymap_items.new('transform.transform', 'S', 'PRESS', ctrl=True, alt=True)
kmi = km.keymap_items.new('anim.keyframe_insert_menu', 'S', 'PRESS')

View File

@ -1786,7 +1786,7 @@ class VIEW3D_MT_pose(Menu):
layout.separator()
layout.operator_context = 'INVOKE_AREA'
layout.operator("pose.armature_layers", text="Change Armature Layers...")
layout.operator("armature.armature_layers", text="Change Armature Layers...")
layout.operator("pose.bone_layers", text="Change Bone Layers...")
layout.separator()

View File

@ -133,7 +133,6 @@ void POSE_OT_rotation_mode_set(struct wmOperatorType *ot);
void POSE_OT_quaternions_flip(struct wmOperatorType *ot);
void POSE_OT_armature_layers(struct wmOperatorType *ot);
void POSE_OT_bone_layers(struct wmOperatorType *ot);
/* ******************************************************* */

View File

@ -139,7 +139,6 @@ void ED_operatortypes_armature(void)
WM_operatortype_append(POSE_OT_quaternions_flip);
WM_operatortype_append(POSE_OT_armature_layers);
WM_operatortype_append(POSE_OT_bone_layers);
WM_operatortype_append(POSE_OT_propagate);
@ -284,7 +283,7 @@ void ED_keymap_armature(wmKeyConfig *keyconf)
WM_keymap_add_menu(keymap, "VIEW3D_MT_bone_options_toggle", WKEY, KM_PRESS, KM_SHIFT, 0);
WM_keymap_add_menu(keymap, "VIEW3D_MT_bone_options_enable", WKEY, KM_PRESS, KM_CTRL | KM_SHIFT, 0);
WM_keymap_add_menu(keymap, "VIEW3D_MT_bone_options_disable", WKEY, KM_PRESS, KM_ALT, 0);
/* armature/bone layers */
WM_keymap_add_item(keymap, "ARMATURE_OT_layers_show_all", ACCENTGRAVEKEY, KM_PRESS, KM_CTRL, 0);
WM_keymap_add_item(keymap, "ARMATURE_OT_armature_layers", MKEY, KM_PRESS, KM_SHIFT, 0);
@ -385,7 +384,7 @@ void ED_keymap_armature(wmKeyConfig *keyconf)
/* armature/bone layers */
WM_keymap_add_item(keymap, "ARMATURE_OT_layers_show_all", ACCENTGRAVEKEY, KM_PRESS, KM_CTRL, 0);
WM_keymap_add_item(keymap, "POSE_OT_armature_layers", MKEY, KM_PRESS, KM_SHIFT, 0);
WM_keymap_add_item(keymap, "ARMATURE_OT_armature_layers", MKEY, KM_PRESS, KM_SHIFT, 0);
WM_keymap_add_item(keymap, "POSE_OT_bone_layers", MKEY, KM_PRESS, 0, 0);
/* special transforms: */

View File

@ -707,17 +707,37 @@ void POSE_OT_rotation_mode_set(wmOperatorType *ot)
/* ********************************************** */
/* Show all armature layers */
static int pose_armature_layers_showall_poll(bContext *C)
static int armature_layers_poll(bContext *C)
{
/* this single operator can be used in posemode OR editmode for armatures */
/* Armature layers operators can be used in posemode OR editmode for armatures */
return ED_operator_posemode(C) || ED_operator_editarmature(C);
}
static bArmature *armature_layers_get_data(Object **ob)
{
bArmature *arm = NULL;
/* Sanity checking and handling of posemode. */
if (*ob) {
Object *tob = BKE_object_pose_armature_get(*ob);
if (tob) {
*ob = tob;
arm = (*ob)->data;
}
else if ((*ob)->type == OB_ARMATURE) {
arm = (*ob)->data;
}
}
return arm;
}
/* Show all armature layers */
static int pose_armature_layers_showall_exec(bContext *C, wmOperator *op)
{
Object *ob = BKE_object_pose_armature_get(CTX_data_active_object(C));
bArmature *arm = (ob) ? ob->data : NULL;
Object *ob = CTX_data_active_object(C);
bArmature *arm = armature_layers_get_data(&ob);
PointerRNA ptr;
int maxLayers = (RNA_boolean_get(op->ptr, "all")) ? 32 : 16;
int layers[32] = {0}; /* hardcoded for now - we can only have 32 armature layers, so this should be fine... */
@ -754,7 +774,7 @@ void ARMATURE_OT_layers_show_all(wmOperatorType *ot)
/* callbacks */
ot->exec = pose_armature_layers_showall_exec;
ot->poll = pose_armature_layers_showall_poll;
ot->poll = armature_layers_poll;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
@ -766,10 +786,10 @@ void ARMATURE_OT_layers_show_all(wmOperatorType *ot)
/* ------------------- */
/* Present a popup to get the layers that should be used */
static int pose_armature_layers_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static int armature_layers_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
Object *ob = BKE_object_pose_armature_get(CTX_data_active_object(C));
bArmature *arm = (ob) ? ob->data : NULL;
Object *ob = CTX_data_active_object(C);
bArmature *arm = armature_layers_get_data(&ob);
PointerRNA ptr;
int layers[32]; /* hardcoded for now - we can only have 32 armature layers, so this should be fine... */
@ -787,13 +807,14 @@ static int pose_armature_layers_invoke(bContext *C, wmOperator *op, const wmEven
}
/* Set the visible layers for the active armature (edit and pose modes) */
static int pose_armature_layers_exec(bContext *C, wmOperator *op)
static int armature_layers_exec(bContext *C, wmOperator *op)
{
Object *ob = BKE_object_pose_armature_get(CTX_data_active_object(C));
Object *ob = CTX_data_active_object(C);
bArmature *arm = armature_layers_get_data(&ob);
PointerRNA ptr;
int layers[32]; /* hardcoded for now - we can only have 32 armature layers, so this should be fine... */
if (ELEM(NULL, ob, ob->data)) {
if (arm == NULL) {
return OPERATOR_CANCELLED;
}
@ -801,7 +822,7 @@ static int pose_armature_layers_exec(bContext *C, wmOperator *op)
RNA_boolean_get_array(op->ptr, "layers", layers);
/* get pointer for armature, and write data there... */
RNA_id_pointer_create((ID *)ob->data, &ptr);
RNA_id_pointer_create((ID *)arm, &ptr);
RNA_boolean_set_array(&ptr, "layers", layers);
/* note, notifier might evolve */
@ -810,26 +831,6 @@ static int pose_armature_layers_exec(bContext *C, wmOperator *op)
return OPERATOR_FINISHED;
}
void POSE_OT_armature_layers(wmOperatorType *ot)
{
/* identifiers */
ot->name = "Change Armature Layers";
ot->idname = "POSE_OT_armature_layers";
ot->description = "Change the visible armature layers";
/* callbacks */
ot->invoke = pose_armature_layers_invoke;
ot->exec = pose_armature_layers_exec;
ot->poll = ED_operator_posemode;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
/* properties */
RNA_def_boolean_layer_member(ot->srna, "layers", 32, NULL, "Layer", "Armature layers to make visible");
}
void ARMATURE_OT_armature_layers(wmOperatorType *ot)
{
/* identifiers */
@ -838,9 +839,9 @@ void ARMATURE_OT_armature_layers(wmOperatorType *ot)
ot->description = "Change the visible armature layers";
/* callbacks */
ot->invoke = pose_armature_layers_invoke;
ot->exec = pose_armature_layers_exec;
ot->poll = ED_operator_editarmature;
ot->invoke = armature_layers_invoke;
ot->exec = armature_layers_exec;
ot->poll = armature_layers_poll;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;