[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [24164] trunk/blender: moved the following into the screen context rather then the view3d context so python scripts can access these when running in the console .

Campbell Barton ideasman42 at gmail.com
Thu Oct 29 20:59:38 CET 2009


Revision: 24164
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=24164
Author:   campbellbarton
Date:     2009-10-29 20:59:38 +0100 (Thu, 29 Oct 2009)

Log Message:
-----------
moved the following into the screen context rather then the view3d context so python scripts can access these when running in the console.
 "visible_bones", "editable_bones", "selected_bones", "selected_editable_bones", "visible_pchans", "selected_pchans", "active_bone", "active_pchan",

added "C" to the consoles namespace, temp hack but useful

Modified Paths:
--------------
    trunk/blender/release/scripts/ui/space_console.py
    trunk/blender/source/blender/editors/animation/keyingsets.c
    trunk/blender/source/blender/editors/screen/screen_context.c
    trunk/blender/source/blender/editors/space_view3d/space_view3d.c

Modified: trunk/blender/release/scripts/ui/space_console.py
===================================================================
--- trunk/blender/release/scripts/ui/space_console.py	2009-10-29 19:26:13 UTC (rev 24163)
+++ trunk/blender/release/scripts/ui/space_console.py	2009-10-29 19:59:38 UTC (rev 24164)
@@ -133,6 +133,7 @@
 			return ('CANCELLED',)
 		
 		namespace, console, stdout, stderr = get_console(hash(context.region))
+		namespace['C'] = context
 		
 		# redirect output
 		sys.stdout = stdout

Modified: trunk/blender/source/blender/editors/animation/keyingsets.c
===================================================================
--- trunk/blender/source/blender/editors/animation/keyingsets.c	2009-10-29 19:26:13 UTC (rev 24163)
+++ trunk/blender/source/blender/editors/animation/keyingsets.c	2009-10-29 19:59:38 UTC (rev 24164)
@@ -1267,7 +1267,8 @@
 	/* for now, the active area is used to determine what set of contexts apply */
 	if (sa == NULL)
 		return 0;
-		
+
+#if 0
 	switch (sa->spacetype) {
 		case SPACE_VIEW3D:	/* 3D-View: Selected Objects or Bones */
 			return modifykey_get_context_v3d_data(C, dsources, ks);
@@ -1275,6 +1276,10 @@
 	
 	/* nothing happened */
 	return 0;
+#endif
+
+	/* looking into this code, it doesnt use the 3D view - Campbell */
+	return modifykey_get_context_v3d_data(C, dsources, ks);
 } 
 
 /* KeyingSet Operations (Insert/Delete Keyframes) ------------ */

Modified: trunk/blender/source/blender/editors/screen/screen_context.c
===================================================================
--- trunk/blender/source/blender/editors/screen/screen_context.c	2009-10-29 19:26:13 UTC (rev 24163)
+++ trunk/blender/source/blender/editors/screen/screen_context.c	2009-10-29 19:59:38 UTC (rev 24164)
@@ -28,16 +28,20 @@
 #include <string.h>
 
 #include "DNA_object_types.h"
+#include "DNA_armature_types.h"
+#include "DNA_action_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_screen_types.h"
 
 #include "BKE_context.h"
 #include "BKE_utildefines.h"
 #include "BKE_global.h"
+#include "BKE_action.h"
 
 #include "RNA_access.h"
 
 #include "ED_object.h"
+#include "ED_armature.h"
 
 int ed_screen_context(const bContext *C, const char *member, bContextDataResult *result)
 {
@@ -53,6 +57,8 @@
 		static const char *dir[] = {
 			"scene", "selected_objects", "selected_bases",
 			"selected_editable_objects", "selected_editable_bases",
+			"visible_bones", "editable_bones", "selected_bones", "selected_editable_bones",
+			"visible_pchans", "selected_pchans", "active_bone", "active_pchan",
 			"active_base", "active_object", "edit_object",
 			"sculpt_object", "vertex_paint_object", "weight_paint_object",
 			"texture_paint_object", "brush", "particle_edit_object", NULL};
@@ -96,6 +102,153 @@
 
 		return 1;
 	}
+	else if(CTX_data_equals(member, "visible_bones") || CTX_data_equals(member, "editable_bones")) {
+		Object *obedit= scene->obedit; // XXX get from context?
+		bArmature *arm= (obedit) ? obedit->data : NULL;
+		EditBone *ebone, *flipbone=NULL;
+		int editable_bones= CTX_data_equals(member, "editable_bones");
+		
+		if (arm && arm->edbo) {
+			/* Attention: X-Axis Mirroring is also handled here... */
+			for (ebone= arm->edbo->first; ebone; ebone= ebone->next) {
+				/* first and foremost, bone must be visible and selected */
+				if (EBONE_VISIBLE(arm, ebone)) {
+					/* Get 'x-axis mirror equivalent' bone if the X-Axis Mirroring option is enabled
+					 * so that most users of this data don't need to explicitly check for it themselves.
+					 * 
+					 * We need to make sure that these mirrored copies are not selected, otherwise some
+					 * bones will be operated on twice.
+					 */
+					if (arm->flag & ARM_MIRROR_EDIT)
+						flipbone = ED_armature_bone_get_mirrored(arm->edbo, ebone);
+					
+					/* if we're filtering for editable too, use the check for that instead, as it has selection check too */
+					if (editable_bones) {
+						/* only selected + editable */
+						if (EBONE_EDITABLE(ebone)) {
+							CTX_data_list_add(result, &arm->id, &RNA_UnknownType, ebone);
+						
+							if ((flipbone) && !(flipbone->flag & BONE_SELECTED))
+								CTX_data_list_add(result, &arm->id, &RNA_UnknownType, flipbone);
+						}
+					}
+					else {
+						/* only include bones if visible */
+						CTX_data_list_add(result, &arm->id, &RNA_UnknownType, ebone);
+						
+						if ((flipbone) && EBONE_VISIBLE(arm, flipbone)==0)
+							CTX_data_list_add(result, &arm->id, &RNA_UnknownType, flipbone);
+					}
+				}
+			}	
+			
+			return 1;
+		}
+	}
+	else if(CTX_data_equals(member, "selected_bones") || CTX_data_equals(member, "selected_editable_bones")) {
+		Object *obedit= scene->obedit; // XXX get from context?
+		bArmature *arm= (obedit) ? obedit->data : NULL;
+		EditBone *ebone, *flipbone=NULL;
+		int selected_editable_bones= CTX_data_equals(member, "selected_editable_bones");
+		
+		if (arm && arm->edbo) {
+			/* Attention: X-Axis Mirroring is also handled here... */
+			for (ebone= arm->edbo->first; ebone; ebone= ebone->next) {
+				/* first and foremost, bone must be visible and selected */
+				if (EBONE_VISIBLE(arm, ebone) && (ebone->flag & BONE_SELECTED)) {
+					/* Get 'x-axis mirror equivalent' bone if the X-Axis Mirroring option is enabled
+					 * so that most users of this data don't need to explicitly check for it themselves.
+					 * 
+					 * We need to make sure that these mirrored copies are not selected, otherwise some
+					 * bones will be operated on twice.
+					 */
+					if (arm->flag & ARM_MIRROR_EDIT)
+						flipbone = ED_armature_bone_get_mirrored(arm->edbo, ebone);
+					
+					/* if we're filtering for editable too, use the check for that instead, as it has selection check too */
+					if (selected_editable_bones) {
+						/* only selected + editable */
+						if (EBONE_EDITABLE(ebone)) {
+							CTX_data_list_add(result, &arm->id, &RNA_UnknownType, ebone);
+						
+							if ((flipbone) && !(flipbone->flag & BONE_SELECTED))
+								CTX_data_list_add(result, &arm->id, &RNA_UnknownType, flipbone);
+						}
+					}
+					else {
+						/* only include bones if selected */
+						CTX_data_list_add(result, &arm->id, &RNA_UnknownType, ebone);
+						
+						if ((flipbone) && !(flipbone->flag & BONE_SELECTED))
+							CTX_data_list_add(result, &arm->id, &RNA_UnknownType, flipbone);
+					}
+				}
+			}	
+			
+			return 1;
+		}
+	}
+	else if(CTX_data_equals(member, "visible_pchans")) {
+		Object *obact= OBACT;
+		bArmature *arm= (obact) ? obact->data : NULL;
+		bPoseChannel *pchan;
+		
+		if (obact && arm) {
+			for (pchan= obact->pose->chanbase.first; pchan; pchan= pchan->next) {
+				/* ensure that PoseChannel is on visible layer and is not hidden in PoseMode */
+				if ((pchan->bone) && (arm->layer & pchan->bone->layer) && !(pchan->bone->flag & BONE_HIDDEN_P)) {
+					CTX_data_list_add(result, &obact->id, &RNA_PoseChannel, pchan);
+				}
+			}
+			
+			return 1;
+		}
+	}
+	else if(CTX_data_equals(member, "selected_pchans")) {
+		Object *obact= OBACT;
+		bArmature *arm= (obact) ? obact->data : NULL;
+		bPoseChannel *pchan;
+		
+		if (obact && arm) {
+			for (pchan= obact->pose->chanbase.first; pchan; pchan= pchan->next) {
+				/* ensure that PoseChannel is on visible layer and is not hidden in PoseMode */
+				if ((pchan->bone) && (arm->layer & pchan->bone->layer) && !(pchan->bone->flag & BONE_HIDDEN_P)) {
+					if (pchan->bone->flag & (BONE_SELECTED|BONE_ACTIVE)) 
+						CTX_data_list_add(result, &obact->id, &RNA_PoseChannel, pchan);
+				}
+			}
+			
+			return 1;
+		}
+	}
+	else if(CTX_data_equals(member, "active_bone")) {
+		Object *obedit= scene->obedit; // XXX get from context?
+		bArmature *arm= (obedit) ? obedit->data : NULL;
+		EditBone *ebone;
+		
+		if (arm && arm->edbo) {
+			for (ebone= arm->edbo->first; ebone; ebone= ebone->next) {
+				if (EBONE_VISIBLE(arm, ebone)) {
+					if (ebone->flag & BONE_ACTIVE) {
+						CTX_data_pointer_set(result, &arm->id, &RNA_UnknownType, ebone);
+						
+						return 1;
+					}
+				}
+			}
+		}
+		
+	}
+	else if(CTX_data_equals(member, "active_pchan")) {
+		Object *obact= OBACT;
+		bPoseChannel *pchan;
+		
+		pchan= get_active_posechannel(obact);
+		if (pchan) {
+			CTX_data_pointer_set(result, &obact->id, &RNA_PoseChannel, pchan);
+			return 1;
+		}
+	}
 	else if(CTX_data_equals(member, "active_base")) {
 		if(scene->basact)
 			CTX_data_pointer_set(result, &scene->id, &RNA_UnknownType, scene->basact);

Modified: trunk/blender/source/blender/editors/space_view3d/space_view3d.c
===================================================================
--- trunk/blender/source/blender/editors/space_view3d/space_view3d.c	2009-10-29 19:26:13 UTC (rev 24163)
+++ trunk/blender/source/blender/editors/space_view3d/space_view3d.c	2009-10-29 19:59:38 UTC (rev 24164)
@@ -663,9 +663,7 @@
 		static const char *dir[] = {
 			"selected_objects", "selected_bases", "selected_editable_objects",
 			"selected_editable_bases", "visible_objects", "visible_bases", "selectable_objects", "selectable_bases",
-			"active_base", "active_object", "visible_bones", "editable_bones",
-			"selected_bones", "selected_editable_bones", "visible_pchans",
-			"selected_pchans", "active_bone", "active_pchan", NULL};
+			"active_base", "active_object", NULL};
 
 		CTX_data_dir_set(result, dir);
 	}
@@ -749,154 +747,6 @@
 		
 		return 1;
 	}
-	else if(CTX_data_equals(member, "visible_bones") || CTX_data_equals(member, "editable_bones")) {
-		Object *obedit= scene->obedit; // XXX get from context?
-		bArmature *arm= (obedit) ? obedit->data : NULL;
-		EditBone *ebone, *flipbone=NULL;
-		int editable_bones= CTX_data_equals(member, "editable_bones");
-		
-		if (arm && arm->edbo) {
-			/* Attention: X-Axis Mirroring is also handled here... */
-			for (ebone= arm->edbo->first; ebone; ebone= ebone->next) {
-				/* first and foremost, bone must be visible and selected */
-				if (EBONE_VISIBLE(arm, ebone)) {
-					/* Get 'x-axis mirror equivalent' bone if the X-Axis Mirroring option is enabled
-					 * so that most users of this data don't need to explicitly check for it themselves.
-					 * 
-					 * We need to make sure that these mirrored copies are not selected, otherwise some
-					 * bones will be operated on twice.
-					 */
-					if (arm->flag & ARM_MIRROR_EDIT)
-						flipbone = ED_armature_bone_get_mirrored(arm->edbo, ebone);
-					
-					/* if we're filtering for editable too, use the check for that instead, as it has selection check too */

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list