[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [26462] trunk/blender: bugfix [#20579] Context pinning error (pose mode)

Campbell Barton ideasman42 at gmail.com
Sun Jan 31 00:48:50 CET 2010


Revision: 26462
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=26462
Author:   campbellbarton
Date:     2010-01-31 00:48:49 +0100 (Sun, 31 Jan 2010)

Log Message:
-----------
bugfix [#20579] Context pinning error (pose mode)

Modified Paths:
--------------
    trunk/blender/release/scripts/ui/properties_object_constraint.py
    trunk/blender/source/blender/editors/space_buttons/buttons_context.c

Modified: trunk/blender/release/scripts/ui/properties_object_constraint.py
===================================================================
--- trunk/blender/release/scripts/ui/properties_object_constraint.py	2010-01-30 22:50:32 UTC (rev 26461)
+++ trunk/blender/release/scripts/ui/properties_object_constraint.py	2010-01-30 23:48:49 UTC (rev 26462)
@@ -744,18 +744,14 @@
     bl_context = "bone_constraint"
 
     def poll(self, context):
-        ob = context.object
-        return (ob and ob.type == 'ARMATURE' and context.bone)
+        return (context.pose_bone)
 
     def draw(self, context):
         layout = self.layout
 
-        ob = context.object
-        pchan = ob.pose.bones[context.bone.name]
-
         layout.operator_menu_enum("pose.constraint_add", "type")
 
-        for con in pchan.constraints:
+        for con in context.pose_bone.constraints:
             self.draw_constraint(context, con)
 
 bpy.types.register(OBJECT_PT_constraints)

Modified: trunk/blender/source/blender/editors/space_buttons/buttons_context.c
===================================================================
--- trunk/blender/source/blender/editors/space_buttons/buttons_context.c	2010-01-30 22:50:32 UTC (rev 26461)
+++ trunk/blender/source/blender/editors/space_buttons/buttons_context.c	2010-01-30 23:48:49 UTC (rev 26462)
@@ -48,6 +48,7 @@
 
 #include "BKE_context.h"
 #include "BKE_global.h"
+#include "BKE_action.h"
 #include "BKE_material.h"
 #include "BKE_modifier.h"
 #include "BKE_paint.h"
@@ -274,6 +275,40 @@
 	return 0;
 }
 
+static int buttons_context_path_pose_bone(ButsContextPath *path)
+{
+	PointerRNA *ptr= &path->ptr[path->len-1];
+
+	/* if we already have a (pinned) PoseBone, we're done */
+	if(RNA_struct_is_a(ptr->type, &RNA_PoseBone)) {
+		return 1;
+	}
+
+	/* if we have an armature, get the active bone */
+	if(buttons_context_path_object(path)) {
+		Object *ob= path->ptr[path->len-1].data;
+		bArmature *arm= ob->data; /* path->ptr[path->len-1].data - works too */
+
+		if(ob->type != OB_ARMATURE || arm->edbo) {
+			return 0;
+		}
+		else {
+			if(arm->act_bone) {
+				bPoseChannel *pchan= get_pose_channel(ob->pose, arm->act_bone->name);
+				if(pchan) {
+					RNA_pointer_create(&ob->id, &RNA_PoseBone, pchan, &path->ptr[path->len]);
+					path->len++;
+					return 1;
+				}
+			}
+		}
+	}
+
+	/* no path to a bone possible */
+	return 0;
+}
+
+
 static int buttons_context_path_particle(ButsContextPath *path)
 {
 	Object *ob;
@@ -461,11 +496,13 @@
 			found= buttons_context_path_texture(C, path);
 			break;
 		case BCONTEXT_BONE:
-		case BCONTEXT_BONE_CONSTRAINT:
 			found= buttons_context_path_bone(path);
 			if(!found)
 				found= buttons_context_path_data(path, OB_ARMATURE);
 			break;
+		case BCONTEXT_BONE_CONSTRAINT:
+			found= buttons_context_path_pose_bone(path);
+			break;
 		default:
 			found= 0;
 			break;
@@ -586,7 +623,7 @@
 		static const char *dir[] = {
 			"world", "object", "mesh", "armature", "lattice", "curve",
 			"meta_ball", "lamp", "camera", "material", "material_slot",
-			"texture", "texture_slot", "bone", "edit_bone", "particle_system", "particle_system_editable",
+			"texture", "texture_slot", "bone", "edit_bone", "pose_bone", "particle_system", "particle_system_editable",
 			"cloth", "soft_body", "fluid", "smoke", "collision", "brush", NULL};
 
 		CTX_data_dir_set(result, dir);
@@ -704,6 +741,10 @@
 		set_pointer_type(path, result, &RNA_EditBone);
 		return 1;
 	}
+	else if(CTX_data_equals(member, "pose_bone")) {
+		set_pointer_type(path, result, &RNA_PoseBone);
+		return 1;
+	}
 	else if(CTX_data_equals(member, "particle_system")) {
 		set_pointer_type(path, result, &RNA_ParticleSystem);
 		return 1;





More information about the Bf-blender-cvs mailing list