[Bf-blender-cvs] [18060d8] master: Fix T39895: Displaying the armature layers popup in edit mode always fails.

Bastien Montagne noreply at git.blender.org
Fri Apr 25 17:37:19 CEST 2014


Commit: 18060d863207d98a06b743437f2353516605436e
Author: Bastien Montagne
Date:   Fri Apr 25 17:07:30 2014 +0200
https://developer.blender.org/rB18060d863207d98a06b743437f2353516605436e

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.

===================================================================

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

===================================================================

diff --git a/release/scripts/presets/keyconfig/3dsmax.py b/release/scripts/presets/keyconfig/3dsmax.py
index 19f1c23..808ba7c 100644
--- a/release/scripts/presets/keyconfig/3dsmax.py
+++ b/release/scripts/presets/keyconfig/3dsmax.py
@@ -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'
diff --git a/release/scripts/presets/keyconfig/maya.py b/release/scripts/presets/keyconfig/maya.py
index 9becc10..3a5a6c7 100644
--- a/release/scripts/presets/keyconfig/maya.py
+++ b/release/scripts/presets/keyconfig/maya.py
@@ -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')
diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index a433832..2697fee 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -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()
diff --git a/source/blender/editors/armature/armature_intern.h b/source/blender/editors/armature/armature_intern.h
index f3db904..1d054ff 100644
--- a/source/blender/editors/armature/armature_intern.h
+++ b/source/blender/editors/armature/armature_intern.h
@@ -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);
 
 /* ******************************************************* */
diff --git a/source/blender/editors/armature/armature_ops.c b/source/blender/editors/armature/armature_ops.c
index f3c23c1..b7e3854 100644
--- a/source/blender/editors/armature/armature_ops.c
+++ b/source/blender/editors/armature/armature_ops.c
@@ -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: */
diff --git a/source/blender/editors/armature/pose_edit.c b/source/blender/editors/armature/pose_edit.c
index 4705d10..26ea483 100644
--- a/source/blender/editors/armature/pose_edit.c
+++ b/source/blender/editors/armature/pose_edit.c
@@ -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;




More information about the Bf-blender-cvs mailing list