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.
This commit is contained in:
Joshua Leung
2009-02-08 23:41:21 +00:00
parent eb929804d2
commit 7d6e7914de
3 changed files with 35 additions and 10 deletions

View File

@@ -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);

View File

@@ -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

View File

@@ -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 ********************* */