From 8c707b2a5f306f149bcd3057ab6fe91076c75dd8 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 29 Oct 2009 19:59:38 +0000 Subject: [PATCH] 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 --- release/scripts/ui/space_console.py | 1 + source/blender/editors/animation/keyingsets.c | 7 +- .../blender/editors/screen/screen_context.c | 153 ++++++++++++++++++ .../editors/space_view3d/space_view3d.c | 152 +---------------- 4 files changed, 161 insertions(+), 152 deletions(-) diff --git a/release/scripts/ui/space_console.py b/release/scripts/ui/space_console.py index 5bb211f7d98..19024977992 100644 --- a/release/scripts/ui/space_console.py +++ b/release/scripts/ui/space_console.py @@ -133,6 +133,7 @@ class CONSOLE_OT_exec(bpy.types.Operator): return ('CANCELLED',) namespace, console, stdout, stderr = get_console(hash(context.region)) + namespace['C'] = context # redirect output sys.stdout = stdout diff --git a/source/blender/editors/animation/keyingsets.c b/source/blender/editors/animation/keyingsets.c index 97b64cb36c9..0f4f29d0091 100644 --- a/source/blender/editors/animation/keyingsets.c +++ b/source/blender/editors/animation/keyingsets.c @@ -1267,7 +1267,8 @@ short modifykey_get_context_data (bContext *C, ListBase *dsources, KeyingSet *ks /* 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 @@ short modifykey_get_context_data (bContext *C, ListBase *dsources, KeyingSet *ks /* 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) ------------ */ diff --git a/source/blender/editors/screen/screen_context.c b/source/blender/editors/screen/screen_context.c index e573ef06247..4f08ffb5c7b 100644 --- a/source/blender/editors/screen/screen_context.c +++ b/source/blender/editors/screen/screen_context.c @@ -28,16 +28,20 @@ #include #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 @@ int ed_screen_context(const bContext *C, const char *member, bContextDataResult 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 @@ int ed_screen_context(const bContext *C, const char *member, bContextDataResult 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); diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c index ae0c73e71cc..4a9042aa31c 100644 --- a/source/blender/editors/space_view3d/space_view3d.c +++ b/source/blender/editors/space_view3d/space_view3d.c @@ -663,9 +663,7 @@ static int view3d_context(const bContext *C, const char *member, bContextDataRes 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 @@ static int view3d_context(const bContext *C, const char *member, bContextDataRes 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; - } - } - return 0; }