From 0a7fecac8f967150d736e3b99d469179b7290f45 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 23 Feb 2011 04:58:08 +0000 Subject: [PATCH] add 2.4x posemode & weightpaint feature as an operator - Flip Active, Shift+F. --- release/scripts/ui/space_view3d.py | 1 + .../editors/armature/armature_intern.h | 1 + .../blender/editors/armature/armature_ops.c | 4 +- source/blender/editors/armature/poseobject.c | 98 +++++++++++-------- .../blender/editors/transform/transform_ops.c | 1 + 5 files changed, 62 insertions(+), 43 deletions(-) diff --git a/release/scripts/ui/space_view3d.py b/release/scripts/ui/space_view3d.py index f7f177e07e3..e6d546dda22 100644 --- a/release/scripts/ui/space_view3d.py +++ b/release/scripts/ui/space_view3d.py @@ -425,6 +425,7 @@ class VIEW3D_MT_select_pose(bpy.types.Menu): layout.operator("pose.select_all", text="Select/Deselect All") layout.operator("pose.select_inverse", text="Inverse") + layout.operator("pose.select_flip_active", text="Flip Active") layout.operator("pose.select_constraint_target", text="Constraint Target") layout.operator("pose.select_linked", text="Linked") diff --git a/source/blender/editors/armature/armature_intern.h b/source/blender/editors/armature/armature_intern.h index d898eddd885..2f85861cecd 100644 --- a/source/blender/editors/armature/armature_intern.h +++ b/source/blender/editors/armature/armature_intern.h @@ -103,6 +103,7 @@ void POSE_OT_select_hierarchy(struct wmOperatorType *ot); void POSE_OT_select_linked(struct wmOperatorType *ot); void POSE_OT_select_constraint_target(struct wmOperatorType *ot); void POSE_OT_select_grouped(struct wmOperatorType *ot); +void POSE_OT_select_flip_active(struct wmOperatorType *ot); void POSE_OT_group_add(struct wmOperatorType *ot); void POSE_OT_group_remove(struct wmOperatorType *ot); diff --git a/source/blender/editors/armature/armature_ops.c b/source/blender/editors/armature/armature_ops.c index 1abb1c05489..f480a3ba3a2 100644 --- a/source/blender/editors/armature/armature_ops.c +++ b/source/blender/editors/armature/armature_ops.c @@ -119,6 +119,7 @@ void ED_operatortypes_armature(void) WM_operatortype_append(POSE_OT_select_linked); WM_operatortype_append(POSE_OT_select_constraint_target); WM_operatortype_append(POSE_OT_select_grouped); + WM_operatortype_append(POSE_OT_select_flip_active); WM_operatortype_append(POSE_OT_group_add); WM_operatortype_append(POSE_OT_group_remove); @@ -132,7 +133,7 @@ void ED_operatortypes_armature(void) WM_operatortype_append(POSE_OT_autoside_names); WM_operatortype_append(POSE_OT_flip_names); - + WM_operatortype_append(POSE_OT_quaternions_flip); WM_operatortype_append(POSE_OT_flags_set); @@ -323,6 +324,7 @@ void ED_keymap_armature(wmKeyConfig *keyconf) WM_keymap_add_item(keymap, "POSE_OT_select_linked", LKEY, KM_PRESS, 0, 0); WM_keymap_add_item(keymap, "POSE_OT_select_grouped", GKEY, KM_PRESS, KM_SHIFT, 0); + WM_keymap_add_item(keymap, "POSE_OT_select_flip_active", FKEY, KM_PRESS, KM_SHIFT, 0); WM_keymap_add_item(keymap, "POSE_OT_constraint_add_with_targets", CKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0); WM_keymap_add_item(keymap, "POSE_OT_constraints_clear", CKEY, KM_PRESS, KM_CTRL|KM_ALT, 0); diff --git a/source/blender/editors/armature/poseobject.c b/source/blender/editors/armature/poseobject.c index c122460e5bb..1e9e5e6fb3b 100644 --- a/source/blender/editors/armature/poseobject.c +++ b/source/blender/editors/armature/poseobject.c @@ -656,6 +656,62 @@ void POSE_OT_select_grouped (wmOperatorType *ot) ot->prop= RNA_def_enum(ot->srna, "type", prop_select_grouped_types, 0, "Type", ""); } + +/* ********************************************** */ + +/* context active object, or weightpainted object with armature in posemode */ +static int pose_bone_flip_active_exec (bContext *C, wmOperator *UNUSED(op)) +{ + Object *ob_act= CTX_data_active_object(C); + Object *ob= ED_object_pose_armature(ob_act); + + if(ob && (ob->mode & OB_MODE_POSE)) { + bArmature *arm= ob->data; + + if(arm->act_bone) { + bPoseChannel *pchanf; + char name[MAXBONENAME]; + flip_side_name(name, arm->act_bone->name, TRUE); + + pchanf= get_pose_channel(ob->pose, name); + if(pchanf && pchanf->bone != arm->act_bone) { + arm->act_bone->flag &= ~BONE_SELECTED; + pchanf->bone->flag |= BONE_SELECTED; + + arm->act_bone= pchanf->bone; + + /* in weightpaint we select the associated vertex group too */ + if(ob_act->mode & OB_MODE_WEIGHT_PAINT) { + ED_vgroup_select_by_name(ob_act, name); + DAG_id_tag_update(&ob_act->id, OB_RECALC_DATA); + } + + WM_event_add_notifier(C, NC_OBJECT|ND_BONE_SELECT, ob); + + return OPERATOR_FINISHED; + } + } + } + + return OPERATOR_CANCELLED; +} + +void POSE_OT_select_flip_active(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Flip Selected Active Bone"; + ot->idname= "POSE_OT_select_flip_active"; + ot->description= "Activate the bone with a flipped name."; + + /* api callbacks */ + ot->exec= pose_bone_flip_active_exec; + ot->poll= ED_operator_posemode; + + /* flags */ + ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; +} + + /* ********************************************** */ #if 0 /* UNUSED 2.5 */ static void pose_copy_menu(Scene *scene) @@ -1560,48 +1616,6 @@ void POSE_OT_autoside_names (wmOperatorType *ot) ot->prop= RNA_def_enum(ot->srna, "axis", axis_items, 0, "Axis", "Axis tag names with."); } -/* ********************************************** */ - -/* context active object, or weightpainted object with armature in posemode */ -static void pose_activate_flipped_bone(Scene *scene) -{ - Object *ob= OBACT; - - if(ob==NULL) return; - - if(ob->mode & OB_MODE_WEIGHT_PAINT) { - ob= modifiers_isDeformedByArmature(ob); - } - - if(ob && (ob->mode & OB_MODE_POSE)) { - bPoseChannel *pchanf; - bArmature *arm= ob->data; - - if(arm->act_bone) { - char name[32]; - flip_side_name(name, arm->act_bone->name, TRUE); - - pchanf= get_pose_channel(ob->pose, name); - if(pchanf && pchanf->bone != arm->act_bone) { - arm->act_bone->flag &= ~BONE_SELECTED; - pchanf->bone->flag |= BONE_SELECTED; - - arm->act_bone= pchanf->bone; - - /* in weightpaint we select the associated vertex group too */ - if(ob->mode & OB_MODE_WEIGHT_PAINT) { - ED_vgroup_select_by_name(OBACT, name); - DAG_id_tag_update(&OBACT->id, OB_RECALC_DATA); - } - - // XXX notifiers need to be sent to other editors to update - - } - } - } -} - - /* ********************************************** */ /* Show all armature layers */ diff --git a/source/blender/editors/transform/transform_ops.c b/source/blender/editors/transform/transform_ops.c index 5c42a59ac69..fa602f7341f 100644 --- a/source/blender/editors/transform/transform_ops.c +++ b/source/blender/editors/transform/transform_ops.c @@ -35,6 +35,7 @@ #include "BKE_context.h" #include "BKE_global.h" +#include "BKE_armature.h" #include "WM_api.h" #include "WM_types.h"