add 2.4x posemode & weightpaint feature as an operator - Flip Active, Shift+F.

This commit is contained in:
Campbell Barton 2011-02-23 04:58:08 +00:00
parent aeeb09bd56
commit 0a7fecac8f
5 changed files with 62 additions and 43 deletions

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

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

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

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

@ -35,6 +35,7 @@
#include "BKE_context.h"
#include "BKE_global.h"
#include "BKE_armature.h"
#include "WM_api.h"
#include "WM_types.h"