Multi-Objects: POSE_OT_constraints_copy (refactor)

This was already supporting multiple objects, but I changed it to use the API
we are using elsewhere.
This commit is contained in:
Dalai Felinto
2018-10-16 19:20:01 -03:00
parent 647218af07
commit 418c16bd3b

View File

@@ -1497,8 +1497,6 @@ static int pose_constraint_copy_exec(bContext *C, wmOperator *op)
{
Main *bmain = CTX_data_main(C);
bPoseChannel *pchan = CTX_data_active_pose_bone(C);
ListBase lb;
CollectionPointerLink *link;
/* don't do anything if bone doesn't exist or doesn't have any constraints */
if (ELEM(NULL, pchan, pchan->constraints.first)) {
@@ -1506,23 +1504,25 @@ static int pose_constraint_copy_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
/* copy all constraints from active posebone to all selected posebones */
CTX_data_selected_pose_bones(C, &lb);
for (link = lb.first; link; link = link->next) {
Object *ob = link->ptr.id.data;
bPoseChannel *chan = link->ptr.data;
Object *prev_ob = NULL;
/* copy all constraints from active posebone to all selected posebones */
CTX_DATA_BEGIN_WITH_ID(C, bPoseChannel *, chan, selected_pose_bones, Object *, ob)
{
/* if we're not handling the object we're copying from, copy all constraints over */
if (pchan != chan) {
BKE_constraints_copy(&chan->constraints, &pchan->constraints, true);
/* update flags (need to add here, not just copy) */
chan->constflag |= pchan->constflag;
BKE_pose_tag_recalc(bmain, ob->pose);
DEG_id_tag_update((ID *)ob, OB_RECALC_DATA);
if (prev_ob != ob) {
BKE_pose_tag_recalc(bmain, ob->pose);
DEG_id_tag_update((ID *)ob, OB_RECALC_DATA);
prev_ob = ob;
}
}
}
BLI_freelistN(&lb);
CTX_DATA_END;
/* force depsgraph to get recalculated since new relationships added */
DEG_relations_tag_update(bmain);