diff options
author | Campbell Barton <ideasman42@gmail.com> | 2009-10-29 22:59:38 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2009-10-29 22:59:38 +0300 |
commit | 8c707b2a5f306f149bcd3057ab6fe91076c75dd8 (patch) | |
tree | 4dbc20ad3f05af87037215e652f56c003f1f452c /source/blender/editors/screen/screen_context.c | |
parent | 099438f087b20a3ead6f018e208e8a5e84ac99f9 (diff) |
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
Diffstat (limited to 'source/blender/editors/screen/screen_context.c')
-rw-r--r-- | source/blender/editors/screen/screen_context.c | 153 |
1 files changed, 153 insertions, 0 deletions
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 <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 @@ 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); |