[Bf-blender-cvs] [c7bbcfe9544] blender2.8: Multi-Objects: POSE_OT_autoside_names

Dalai Felinto noreply at git.blender.org
Fri Oct 12 20:27:25 CEST 2018


Commit: c7bbcfe95444e730eacf655fd982f5091d5e2ff6
Author: Dalai Felinto
Date:   Fri Oct 12 14:23:06 2018 -0300
Branches: blender2.8
https://developer.blender.org/rBc7bbcfe95444e730eacf655fd982f5091d5e2ff6

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.

===================================================================

M	source/blender/editors/armature/pose_edit.c

===================================================================

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,30 +775,29 @@ 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);
-	}
-	CTX_DATA_END;
+		}
 
-	/* since we renamed stuff... */
-	DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
+		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);
+			/* note, notifier might evolve */
+			WM_event_add_notifier(C, NC_OBJECT | ND_POSE, ob);
+			ob_prev = ob;
+		}
+	}
+	CTX_DATA_END;
 
 	return OPERATOR_FINISHED;
 }



More information about the Bf-blender-cvs mailing list