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.
This commit is contained in:
Dalai Felinto
2018-10-12 14:23:06 -03:00
parent 2677e99217
commit c7bbcfe954

View File

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