diff options
author | Joshua Leung <aligorith@gmail.com> | 2009-07-26 15:01:56 +0400 |
---|---|---|
committer | Joshua Leung <aligorith@gmail.com> | 2009-07-26 15:01:56 +0400 |
commit | 812530aca81385af5a34fab851b4031521a1abe0 (patch) | |
tree | 209a6eaaac3087e84942d9a0b45c02b86109d6e1 /source/blender/editors/armature | |
parent | 3d096c2712cf846cfb0bf56cb084599349783129 (diff) |
2.5 - More armature/bone operator tweaks
* Restored quick operators for moving bones between layers and switching visible armature layers. The popup used here (based on the layers template) is not optimal yet - you can click on multiple layer buttons to enable/disable them, but you need to move your mouse outside the area for it to confirm.
* Separate armatures works again. I've tweaked the arguments to ED_object_duplicate() to make this work (besides, the other users of this wouldn't have been affected).
* Added some missing special (transform) operators to the menus + keymaps
Diffstat (limited to 'source/blender/editors/armature')
-rw-r--r-- | source/blender/editors/armature/armature_intern.h | 6 | ||||
-rw-r--r-- | source/blender/editors/armature/armature_ops.c | 34 | ||||
-rw-r--r-- | source/blender/editors/armature/editarmature.c | 9 | ||||
-rw-r--r-- | source/blender/editors/armature/poseobject.c | 323 |
4 files changed, 289 insertions, 83 deletions
diff --git a/source/blender/editors/armature/armature_intern.h b/source/blender/editors/armature/armature_intern.h index bf329270b8c..0c8c0e8e644 100644 --- a/source/blender/editors/armature/armature_intern.h +++ b/source/blender/editors/armature/armature_intern.h @@ -63,6 +63,9 @@ void ARMATURE_OT_flip_names(struct wmOperatorType *ot); void ARMATURE_OT_flags_set(struct wmOperatorType *ot); +void ARMATURE_OT_armature_layers(struct wmOperatorType *ot); +void ARMATURE_OT_bone_layers(struct wmOperatorType *ot); + /* ******************************************************* */ /* Pose-Mode Operators */ void POSE_OT_hide(struct wmOperatorType *ot); @@ -99,6 +102,9 @@ void POSE_OT_flip_names(struct wmOperatorType *ot); void POSE_OT_flags_set(struct wmOperatorType *ot); +void POSE_OT_armature_layers(struct wmOperatorType *ot); +void POSE_OT_bone_layers(struct wmOperatorType *ot); + /* ******************************************************* */ /* Etch-A-Ton */ diff --git a/source/blender/editors/armature/armature_ops.c b/source/blender/editors/armature/armature_ops.c index bfe3befe1b3..389a0a5174a 100644 --- a/source/blender/editors/armature/armature_ops.c +++ b/source/blender/editors/armature/armature_ops.c @@ -55,6 +55,7 @@ #include "ED_armature.h" #include "ED_screen.h" #include "ED_object.h" +#include "ED_transform.h" #include "armature_intern.h" @@ -137,6 +138,9 @@ void ED_operatortypes_armature(void) WM_operatortype_append(ARMATURE_OT_flip_names); WM_operatortype_append(ARMATURE_OT_flags_set); + + WM_operatortype_append(ARMATURE_OT_armature_layers); + WM_operatortype_append(ARMATURE_OT_bone_layers); /* SKETCH */ WM_operatortype_append(SKETCH_OT_gesture); @@ -182,6 +186,9 @@ void ED_operatortypes_armature(void) WM_operatortype_append(POSE_OT_flags_set); + WM_operatortype_append(POSE_OT_armature_layers); + WM_operatortype_append(POSE_OT_bone_layers); + /* POSELIB */ WM_operatortype_append(POSELIB_OT_browse_interactive); @@ -243,7 +250,7 @@ void ED_keymap_armature(wmWindowManager *wm) WM_keymap_add_item(keymap, "ARMATURE_OT_fill", FKEY, KM_PRESS, 0, 0); WM_keymap_add_item(keymap, "ARMATURE_OT_merge", MKEY, KM_PRESS, KM_ALT, 0); - WM_keymap_add_item(keymap, "ARMATURE_OT_separate", PKEY, KM_PRESS, /*KM_CTRL|KM_ALT*/0, 0); + WM_keymap_add_item(keymap, "ARMATURE_OT_separate", PKEY, KM_PRESS, KM_CTRL|KM_ALT, 0); /* set flags */ kmi= WM_keymap_add_item(keymap, "ARMATURE_OT_flags_set", WKEY, KM_PRESS, KM_SHIFT, 0); @@ -252,6 +259,18 @@ void ED_keymap_armature(wmWindowManager *wm) RNA_enum_set(kmi->ptr, "mode", 1); // enable kmi= WM_keymap_add_item(keymap, "ARMATURE_OT_flags_set", WKEY, KM_PRESS, KM_ALT, 0); RNA_enum_set(kmi->ptr, "mode", 0); // clear + + /* armature/bone layers */ + WM_keymap_add_item(keymap, "ARMATURE_OT_armature_layers", MKEY, KM_PRESS, KM_SHIFT, 0); + WM_keymap_add_item(keymap, "ARMATURE_OT_bone_layers", MKEY, KM_PRESS, 0, 0); + + /* special transforms: */ + /* 1) envelope/b-bone size */ + kmi= WM_keymap_add_item(keymap, "TFM_OT_transform", SKEY, KM_PRESS, KM_ALT, 0); + RNA_enum_set(kmi->ptr, "mode", TFM_BONESIZE); + /* 2) set roll */ + kmi= WM_keymap_add_item(keymap, "TFM_OT_transform", RKEY, KM_PRESS, KM_CTRL, 0); + RNA_enum_set(kmi->ptr, "mode", TFM_BONE_ROLL); /* Armature -> Etch-A-Ton ------------------------ */ WM_keymap_add_item(keymap, "SKETCH_OT_delete", XKEY, KM_PRESS, 0, 0); @@ -270,7 +289,7 @@ void ED_keymap_armature(wmWindowManager *wm) WM_keymap_add_item(keymap, "POSE_OT_apply", AKEY, KM_PRESS, KM_CTRL, 0); - /*clear pose*/ + // TODO: clear pose WM_keymap_add_item(keymap, "POSE_OT_rot_clear", RKEY, KM_PRESS, KM_ALT, 0); WM_keymap_add_item(keymap, "POSE_OT_loc_clear", GKEY, KM_PRESS, KM_ALT, 0); WM_keymap_add_item(keymap, "POSE_OT_scale_clear", SKEY, KM_PRESS, KM_ALT, 0); @@ -307,13 +326,22 @@ void ED_keymap_armature(wmWindowManager *wm) WM_keymap_add_item(keymap, "POSE_OT_groups_menu", GKEY, KM_PRESS, KM_CTRL, 0); - /* set flags */ + /* set flags */ kmi= WM_keymap_add_item(keymap, "POSE_OT_flags_set", WKEY, KM_PRESS, KM_SHIFT, 0); RNA_enum_set(kmi->ptr, "mode", 2); // toggle kmi= WM_keymap_add_item(keymap, "POSE_OT_flags_set", WKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0); RNA_enum_set(kmi->ptr, "mode", 1); // enable kmi= WM_keymap_add_item(keymap, "POSE_OT_flags_set", WKEY, KM_PRESS, KM_ALT, 0); RNA_enum_set(kmi->ptr, "mode", 0); // clear + + /* armature/bone layers */ + WM_keymap_add_item(keymap, "POSE_OT_armature_layers", MKEY, KM_PRESS, KM_SHIFT, 0); + WM_keymap_add_item(keymap, "POSE_OT_bone_layers", MKEY, KM_PRESS, 0, 0); + + /* special transforms: */ + /* 1) envelope/b-bone size */ + kmi= WM_keymap_add_item(keymap, "TFM_OT_transform", SKEY, KM_PRESS, KM_ALT, 0); + RNA_enum_set(kmi->ptr, "mode", TFM_BONESIZE); // XXX this should probably be in screen instead... here for testing purposes in the meantime... - Aligorith WM_keymap_verify_item(keymap, "ANIM_OT_insert_keyframe_menu", IKEY, KM_PRESS, 0, 0); diff --git a/source/blender/editors/armature/editarmature.c b/source/blender/editors/armature/editarmature.c index f20c38a0246..95d4e263490 100644 --- a/source/blender/editors/armature/editarmature.c +++ b/source/blender/editors/armature/editarmature.c @@ -99,9 +99,7 @@ /* ************* XXX *************** */ static int okee() {return 0;} -static int pupmenu() {return 0;} static void BIF_undo_push() {} -static void adduplicate() {} /* ************* XXX *************** */ /* **************** tools on Editmode Armature **************** */ @@ -1043,9 +1041,7 @@ static int separate_armature_exec (bContext *C, wmOperator *op) ED_armature_edit_free(obedit); /* 2) duplicate base */ - adduplicate(1, USER_DUP_ARM); /* no transform and zero so do get a linked dupli */ - - newbase= BASACT; /* basact is set in adduplicate() */ + newbase= ED_object_add_duplicate(scene, oldbase, USER_DUP_ARM); /* only duplicate linked armature */ newob= newbase->object; newbase->flag &= ~SELECT; @@ -1064,8 +1060,6 @@ static int separate_armature_exec (bContext *C, wmOperator *op) /* 5) restore original conditions */ obedit= oldob; - BASACT= oldbase; - BASACT->flag |= SELECT; ED_armature_to_edit(obedit); @@ -1274,7 +1268,6 @@ static int pose_setflag_exec (bContext *C, wmOperator *op) /* callback for editbones setflag */ static int armature_bones_setflag_exec (bContext *C, wmOperator *op) { - Object *ob= CTX_data_active_object(C); int flag= RNA_enum_get(op->ptr, "type"); int mode= RNA_enum_get(op->ptr, "mode"); diff --git a/source/blender/editors/armature/poseobject.c b/source/blender/editors/armature/poseobject.c index e9ebdb87a3c..174bb39d7b9 100644 --- a/source/blender/editors/armature/poseobject.c +++ b/source/blender/editors/armature/poseobject.c @@ -89,7 +89,6 @@ #include "armature_intern.h" /* ************* XXX *************** */ -static int movetolayer_short_buts() {return 1;} static int pupmenu() {return 0;} static void error() {}; static void BIF_undo_push() {} @@ -1683,90 +1682,270 @@ void pose_activate_flipped_bone(Scene *scene) } } -/* This function pops up the move-to-layer popup widgets when the user - * presses either SHIFT-MKEY or MKEY in PoseMode OR EditMode (for Armatures) - */ -void pose_movetolayer(Scene *scene) + +/* ********************************************** */ + +/* Present a popup to get the layers that should be used */ +// TODO: move to wm? +static uiBlock *wm_layers_select_create_menu(bContext *C, ARegion *ar, void *arg_op) { - Object *obedit= scene->obedit; // XXX context - Object *ob= OBACT; - bArmature *arm; - short lay= 0; - short shift= 0; // XXX + wmOperator *op= arg_op; + uiBlock *block; + uiLayout *layout; + uiStyle *style= U.uistyles.first; - if (ob==NULL) return; - arm= ob->data; + block= uiBeginBlock(C, ar, "_popup", UI_EMBOSS); + uiBlockClearFlag(block, UI_BLOCK_LOOP); + uiBlockSetFlag(block, UI_BLOCK_KEEP_OPEN); - if (shift) { - /* armature layers */ - lay= arm->layer; - if ( movetolayer_short_buts(&lay, "Armature Layers")==0 ) return; - if (lay==0) return; - arm->layer= lay; - if(ob->pose) - ob->pose->proxy_layer= lay; + layout= uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, 0, 0, 150, 20, style); + uiItemL(layout, op->type->name, 0); + uiTemplateLayers(layout, op->ptr, "layers"); /* must have a property named layers setup */ - } - else if (obedit) { - /* the check for editbone layer moving needs to occur before posemode one to work */ - EditBone *ebo; - EditBone *flipBone; - - for (ebo= arm->edbo->first; ebo; ebo= ebo->next) { - if (arm->layer & ebo->layer) { - if (ebo->flag & BONE_SELECTED) - lay |= ebo->layer; - } - } - if (lay==0) return; + uiPopupBoundsBlock(block, 4.0f, 0, 0); + uiEndBlock(C, block); + + return block; +} + +/* ------------------- */ + +/* Present a popup to get the layers that should be used */ +static int pose_armature_layers_invoke (bContext *C, wmOperator *op, wmEvent *evt) +{ + Object *ob= CTX_data_active_object(C); + bArmature *arm= (ob)? ob->data : NULL; + PointerRNA ptr; + int layers[16]; /* hardcoded for now - we can only have 16 armature layers, so this should be fine... */ + + /* sanity checking */ + if (arm == NULL) + return OPERATOR_CANCELLED; - if ( movetolayer_short_buts(&lay, "Bone Layers")==0 ) return; - if (lay==0) return; + /* get RNA pointer to armature data to use that to retrieve the layers as ints to init the operator */ + RNA_id_pointer_create((ID *)arm, &ptr); + RNA_boolean_get_array(&ptr, "layer", layers); + RNA_boolean_set_array(op->ptr, "layers", layers); + + /* part to sync with other similar operators... */ + /* pass on operator, so return modal */ + uiPupBlockOperator(C, wm_layers_select_create_menu, op, WM_OP_EXEC_DEFAULT); + return OPERATOR_RUNNING_MODAL|OPERATOR_PASS_THROUGH; +} + +/* Set the visible layers for the active armature (edit and pose modes) */ +static int pose_armature_layers_exec (bContext *C, wmOperator *op) +{ + Object *ob= CTX_data_active_object(C); + bArmature *arm= (ob)? ob->data : NULL; + PointerRNA ptr; + int layers[16]; /* hardcoded for now - we can only have 16 armature layers, so this should be fine... */ + + /* get the values set in the operator properties */ + RNA_boolean_get_array(op->ptr, "layers", layers); + + /* get pointer for armature, and write data there... */ + RNA_id_pointer_create((ID *)arm, &ptr); + RNA_boolean_set_array(&ptr, "layer", layers); + + /* note, notifier might evolve */ + WM_event_add_notifier(C, NC_OBJECT|ND_POSE, ob); + + return OPERATOR_FINISHED; +} + + +void POSE_OT_armature_layers (wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Change Armature Layers"; + ot->idname= "POSE_OT_armature_layers"; + ot->description= "Change the visible armature layers."; + + /* callbacks */ + ot->invoke= pose_armature_layers_invoke; + ot->exec= pose_armature_layers_exec; + ot->poll= ED_operator_posemode; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + + /* properties */ + RNA_def_boolean_array(ot->srna, "layers", 16, NULL, "Layers", "Armature layers to make visible."); +} + +void ARMATURE_OT_armature_layers (wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Change Armature Layers"; + ot->idname= "ARMATURE_OT_armature_layers"; + ot->description= "Change the visible armature layers."; + + /* callbacks */ + ot->invoke= pose_armature_layers_invoke; + ot->exec= pose_armature_layers_exec; + ot->poll= ED_operator_editarmature; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + + /* properties */ + RNA_def_boolean_array(ot->srna, "layers", 16, NULL, "Layers", "Armature layers to make visible."); +} + +/* ------------------- */ + +/* Present a popup to get the layers that should be used */ +static int pose_bone_layers_invoke (bContext *C, wmOperator *op, wmEvent *evt) +{ + int layers[16]; /* hardcoded for now - we can only have 16 armature layers, so this should be fine... */ + + /* get layers that are active already */ + memset(&layers, 0, sizeof(layers)); /* set all layers to be off by default */ + + CTX_DATA_BEGIN(C, bPoseChannel *, pchan, selected_pchans) + { + short bit; - for (ebo= arm->edbo->first; ebo; ebo= ebo->next) { - if (arm->layer & ebo->layer) { - if (ebo->flag & BONE_SELECTED) { - ebo->layer= lay; - if (arm->flag & ARM_MIRROR_EDIT) { - flipBone = ED_armature_bone_get_mirrored(arm->edbo, ebo); - if (flipBone) - flipBone->layer = lay; - } - } - } + /* loop over the bits for this pchan's layers, adding layers where they're needed */ + for (bit= 0; bit < 16; bit++) { + if (pchan->bone->layer & (1<<bit)) + layers[bit]= 1; } - - BIF_undo_push("Move Bone Layer"); } - else if (ob->flag & OB_POSEMODE) { - /* pose-channel layers */ - bPoseChannel *pchan; - - if (pose_has_protected_selected(ob, 0, 1)) - return; - - for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) { - if (arm->layer & pchan->bone->layer) { - if (pchan->bone->flag & BONE_SELECTED) - lay |= pchan->bone->layer; - } - } - if (lay==0) return; - - if ( movetolayer_short_buts(&lay, "Bone Layers")==0 ) return; - if (lay==0) return; + CTX_DATA_END; + + /* copy layers to operator */ + RNA_boolean_set_array(op->ptr, "layers", layers); + + /* part to sync with other similar operators... */ + /* pass on operator, so return modal */ + uiPupBlockOperator(C, wm_layers_select_create_menu, op, WM_OP_EXEC_DEFAULT); + return OPERATOR_RUNNING_MODAL|OPERATOR_PASS_THROUGH; +} + +/* Set the visible layers for the active armature (edit and pose modes) */ +static int pose_bone_layers_exec (bContext *C, wmOperator *op) +{ + Object *ob= CTX_data_active_object(C); + bArmature *arm= (ob)? ob->data : NULL; + PointerRNA ptr; + int layers[16]; /* hardcoded for now - we can only have 16 armature layers, so this should be fine... */ + + /* get the values set in the operator properties */ + RNA_boolean_get_array(op->ptr, "layers", layers); + + /* set layers of pchans based on the values set in the operator props */ + CTX_DATA_BEGIN(C, bPoseChannel *, pchan, selected_pchans) + { + /* get pointer for pchan, and write flags this way */ + RNA_pointer_create((ID *)arm, &RNA_Bone, pchan->bone, &ptr); + RNA_boolean_set_array(&ptr, "layer", layers); + } + CTX_DATA_END; + + /* note, notifier might evolve */ + WM_event_add_notifier(C, NC_OBJECT|ND_POSE, ob); + + return OPERATOR_FINISHED; +} + +void POSE_OT_bone_layers (wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Change Bone Layers"; + ot->idname= "POSE_OT_bone_layers"; + ot->description= "Change the layers that the selected bones belong to."; + + /* callbacks */ + ot->invoke= pose_bone_layers_invoke; + ot->exec= pose_bone_layers_exec; + ot->poll= ED_operator_posemode; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + + /* properties */ + RNA_def_boolean_array(ot->srna, "layers", 16, NULL, "Layers", "Armature layers that bone belongs to."); +} + +/* ------------------- */ + +/* Present a popup to get the layers that should be used */ +static int armature_bone_layers_invoke (bContext *C, wmOperator *op, wmEvent *evt) +{ + int layers[16]; /* hardcoded for now - we can only have 16 armature layers, so this should be fine... */ + + /* get layers that are active already */ + memset(&layers, 0, sizeof(layers)); /* set all layers to be off by default */ + + CTX_DATA_BEGIN(C, EditBone *, ebone, selected_editable_bones) + { + short bit; - for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) { - if (arm->layer & pchan->bone->layer) { - if (pchan->bone->flag & BONE_SELECTED) - pchan->bone->layer= lay; - } + /* loop over the bits for this pchan's layers, adding layers where they're needed */ + for (bit= 0; bit < 16; bit++) { + if (ebone->layer & (1<<bit)) + layers[bit]= 1; } - - BIF_undo_push("Move Bone Layer"); } + CTX_DATA_END; + + /* copy layers to operator */ + RNA_boolean_set_array(op->ptr, "layers", layers); + + /* part to sync with other similar operators... */ + /* pass on operator, so return modal */ + uiPupBlockOperator(C, wm_layers_select_create_menu, op, WM_OP_EXEC_DEFAULT); + return OPERATOR_RUNNING_MODAL|OPERATOR_PASS_THROUGH; +} + +/* Set the visible layers for the active armature (edit and pose modes) */ +static int armature_bone_layers_exec (bContext *C, wmOperator *op) +{ + Object *ob= CTX_data_active_object(C); + bArmature *arm= (ob)? ob->data : NULL; + PointerRNA ptr; + int layers[16]; /* hardcoded for now - we can only have 16 armature layers, so this should be fine... */ + + /* get the values set in the operator properties */ + RNA_boolean_get_array(op->ptr, "layers", layers); + + /* set layers of pchans based on the values set in the operator props */ + CTX_DATA_BEGIN(C, EditBone *, ebone, selected_editable_bones) + { + /* get pointer for pchan, and write flags this way */ + RNA_pointer_create((ID *)arm, &RNA_EditBone, ebone, &ptr); + RNA_boolean_set_array(&ptr, "layers", layers); + } + CTX_DATA_END; + + /* note, notifier might evolve */ + WM_event_add_notifier(C, NC_OBJECT|ND_POSE, ob); + + return OPERATOR_FINISHED; +} + +void ARMATURE_OT_bone_layers (wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Change Bone Layers"; + ot->idname= "ARMATURE_OT_bone_layers"; + ot->description= "Change the layers that the selected bones belong to."; + + /* callbacks */ + ot->invoke= armature_bone_layers_invoke; + ot->exec= armature_bone_layers_exec; + ot->poll= ED_operator_editarmature; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + + /* properties */ + RNA_def_boolean_array(ot->srna, "layers", 16, NULL, "Layers", "Armature layers that bone belongs to."); } + #if 0 // XXX old sys /* for use with pose_relax only */ |