From c7bbcfe95444e730eacf655fd982f5091d5e2ff6 Mon Sep 17 00:00:00 2001 From: Dalai Felinto Date: Fri, 12 Oct 2018 14:23:06 -0300 Subject: [PATCH] Multi-Objects: POSE_OT_autoside_names Using CTX_DATA_BEGIN_WITH_ID here. Unlike the edit mode counter-part this operator is well served with the macro above. ARMATURE_OT_autoside_names needs to treat mirrored bones separately, while for pose we don't handle those cases. Be ware that using this macro makes the code smaller, however it also tags every single (selected) pose to update, regardless of whether we changed the names of the bones. In this case it is fine since we most likely renamed all the bones. But In other cases I'm still a bit wary of using CTX_DATA_BEGIN_WITH_ID instead of BKE_view_layer_array_from_objects_in_mode_unique_data. To be seen in upcoming commits. Stay tuned. --- source/blender/editors/armature/pose_edit.c | 29 ++++++++++----------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/source/blender/editors/armature/pose_edit.c b/source/blender/editors/armature/pose_edit.c index 13a54770338..b4651c82f5c 100644 --- a/source/blender/editors/armature/pose_edit.c +++ b/source/blender/editors/armature/pose_edit.c @@ -775,31 +775,30 @@ void POSE_OT_flip_names(wmOperatorType *ot) static int pose_autoside_names_exec(bContext *C, wmOperator *op) { Main *bmain = CTX_data_main(C); - Object *ob = BKE_object_pose_armature_get(CTX_data_active_object(C)); - bArmature *arm; char newname[MAXBONENAME]; short axis = RNA_enum_get(op->ptr, "axis"); - - /* paranoia checks */ - if (ELEM(NULL, ob, ob->pose)) - return OPERATOR_CANCELLED; - arm = ob->data; + Object *ob_prev = NULL; /* loop through selected bones, auto-naming them */ - CTX_DATA_BEGIN (C, bPoseChannel *, pchan, selected_pose_bones) + CTX_DATA_BEGIN_WITH_ID(C, bPoseChannel *, pchan, selected_pose_bones, Object *, ob) { + bArmature *arm = ob->data; BLI_strncpy(newname, pchan->name, sizeof(newname)); - if (bone_autoside_name(newname, 1, axis, pchan->bone->head[axis], pchan->bone->tail[axis])) + if (bone_autoside_name(newname, 1, axis, pchan->bone->head[axis], pchan->bone->tail[axis])) { ED_armature_bone_rename(bmain, arm, pchan->name, newname); + } + + if (ob_prev != ob) { + /* since we renamed stuff... */ + DEG_id_tag_update(&ob->id, OB_RECALC_DATA); + + /* note, notifier might evolve */ + WM_event_add_notifier(C, NC_OBJECT | ND_POSE, ob); + ob_prev = ob; + } } CTX_DATA_END; - /* since we renamed stuff... */ - DEG_id_tag_update(&ob->id, OB_RECALC_DATA); - - /* note, notifier might evolve */ - WM_event_add_notifier(C, NC_OBJECT | ND_POSE, ob); - return OPERATOR_FINISHED; }