Fix T39895: Displaying the armature layers popup in edit mode always fails.
authorBastien Montagne <montagne29@wanadoo.fr>
Fri, 25 Apr 2014 15:07:30 +0000 (17:07 +0200)
committerBastien Montagne <montagne29@wanadoo.fr>
Fri, 25 Apr 2014 15:22:49 +0000 (17:22 +0200)
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.

release/scripts/presets/keyconfig/3dsmax.py
release/scripts/presets/keyconfig/maya.py
release/scripts/startup/bl_ui/space_view3d.py
source/blender/editors/armature/armature_intern.h
source/blender/editors/armature/armature_ops.c
source/blender/editors/armature/pose_edit.c

index 19f1c23b5ab7c63dda7c791a0216d393f6f8e4ef..808ba7cee811e0ebc918051f048641e71d100563 100644 (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'
index 9becc1091eb021b438c17f55c3a7897ee307752c..3a5a6c7570a6c53f5e95034941a518ae4e8b3197 100644 (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')
index a433832c96eaafb1f8be9a388dd8fbad42ab2de7..2697feec3c3818f4795947c8963ac79871bae29e 100644 (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()
index f3db904287925cba0c89f064e5b92b4e89747975..1d054ffc2e9d490da93e946721ff8cb903c79792 100644 (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);
 
 /* ******************************************************* */
index f3c23c1f202f25bca9031200465c9afdacfc349e..b7e38546ca203e0bb9c5b6a64656c602f0828224 100644 (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: */
index 4705d1062487a56d73e941c3d9f6d60577707413..26ea4835b7d3b5291463440caa8483eb57bee24e 100644 (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;