From 7d6e7914de9b4ff3c846adb2a3304d2f818500e2 Mon Sep 17 00:00:00 2001 From: Joshua Leung Date: Sun, 8 Feb 2009 23:41:21 +0000 Subject: Armature Tools - Ported Switch Direction (Alt-F) This is one of the few armature tools where it is currently not that easy/desireable to port to use context-loops exclusively, since they depend on working with 'chains' of bones from the tips to the roots, which cannot be easily done using EditBones. --- source/blender/editors/armature/armature_intern.h | 2 ++ source/blender/editors/armature/armature_ops.c | 2 ++ source/blender/editors/armature/editarmature.c | 41 +++++++++++++++++------ 3 files changed, 35 insertions(+), 10 deletions(-) (limited to 'source/blender/editors/armature') diff --git a/source/blender/editors/armature/armature_intern.h b/source/blender/editors/armature/armature_intern.h index fd91b70dcdd..dc13e2475ee 100644 --- a/source/blender/editors/armature/armature_intern.h +++ b/source/blender/editors/armature/armature_intern.h @@ -36,6 +36,8 @@ void armature_bone_rename(Object *ob, char *oldnamep, char *newnamep); void ARMATURE_OT_align_bones(struct wmOperatorType *ot); void ARMATURE_OT_calculate_roll(struct wmOperatorType *ot); +void ARMATURE_OT_switch_direction(struct wmOperatorType *ot); + void POSE_OT_hide(struct wmOperatorType *ot); void POSE_OT_reveil(struct wmOperatorType *ot); diff --git a/source/blender/editors/armature/armature_ops.c b/source/blender/editors/armature/armature_ops.c index 6736561e36c..d2749128004 100644 --- a/source/blender/editors/armature/armature_ops.c +++ b/source/blender/editors/armature/armature_ops.c @@ -109,6 +109,7 @@ void ED_operatortypes_armature(void) { WM_operatortype_append(ARMATURE_OT_align_bones); WM_operatortype_append(ARMATURE_OT_calculate_roll); + WM_operatortype_append(ARMATURE_OT_switch_direction); WM_operatortype_append(POSE_OT_hide); WM_operatortype_append(POSE_OT_reveil); @@ -131,6 +132,7 @@ void ED_keymap_armature(wmWindowManager *wm) // WM_keymap_add_item(keymap, "ARMATURE_OT_hide", HKEY, KM_PRESS, 0, 0); WM_keymap_add_item(keymap, "ARMATURE_OT_align_bones", AKEY, KM_PRESS, KM_CTRL|KM_ALT, 0); WM_keymap_add_item(keymap, "ARMATURE_OT_calculate_roll", NKEY, KM_PRESS, KM_CTRL, 0); + WM_keymap_add_item(keymap, "ARMATURE_OT_switch_direction", FKEY, KM_PRESS, KM_ALT, 0); WM_keymap_add_item(keymap, "ARMATURE_OT_test", TKEY, KM_PRESS, 0, 0); // XXX temp test for context iterators... to be removed diff --git a/source/blender/editors/armature/editarmature.c b/source/blender/editors/armature/editarmature.c index 1d3d1f9b567..943d7f324ab 100644 --- a/source/blender/editors/armature/editarmature.c +++ b/source/blender/editors/armature/editarmature.c @@ -3294,18 +3294,22 @@ void subdivide_armature(Scene *scene, int numcuts) else BIF_undo_push("Subdivide multi"); } -/* switch direction of bone chains */ -void switch_direction_armature (Scene *scene) +/* ----------- */ + +/* Switch Direction operator: + * Currently, this does not use context loops, as context loops do not make it + * easy to retrieve any hierarchial/chain relationships which are necessary for + * this to be done easily. + */ + +static int armature_switch_direction_exec(bContext *C, wmOperator *op) { - Object *obedit= scene->obedit; // XXX get from context - bArmature *arm= (obedit) ? obedit->data : NULL; + Scene *scene= CTX_data_scene(C); + Object *ob= CTX_data_edit_object(C); + bArmature *arm= (bArmature *)ob->data; ListBase chains = {NULL, NULL}; LinkData *chain; - /* error checking paranoia */ - if (arm == NULL) - return; - /* get chains of bones (ends on chains) */ chains_find_tips(arm->edbo, &chains); if (chains.first == NULL) return; @@ -3363,9 +3367,26 @@ void switch_direction_armature (Scene *scene) } /* free chains */ - BLI_freelistN(&chains); + BLI_freelistN(&chains); + + /* note, notifier might evolve */ + WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, ob); - BIF_undo_push("Switch Direction"); + return OPERATOR_FINISHED; +} + +void ARMATURE_OT_switch_direction(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Switch Direction"; + ot->idname= "ARMATURE_OT_switch_direction"; + + /* api callbacks */ + ot->exec = armature_switch_direction_exec; + ot->poll = ED_operator_editarmature; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; } /* ***************** EditBone Alignment ********************* */ -- cgit v1.2.3