Changeset View
Changeset View
Standalone View
Standalone View
source/blender/makesrna/intern/rna_pose.c
| Show First 20 Lines • Show All 644 Lines • ▼ Show 20 Lines | |||||
| static bConstraint *rna_PoseChannel_constraints_copy(ID *id, | static bConstraint *rna_PoseChannel_constraints_copy(ID *id, | ||||
| bPoseChannel *pchan, | bPoseChannel *pchan, | ||||
| Main *bmain, | Main *bmain, | ||||
| PointerRNA *con_ptr) | PointerRNA *con_ptr) | ||||
| { | { | ||||
| Object *ob = (Object *)id; | Object *ob = (Object *)id; | ||||
| bConstraint *con = con_ptr->data; | bConstraint *con = con_ptr->data; | ||||
| bConstraint *new_con = BKE_constraint_copy_for_pose(ob, pchan, con); | bConstraint *new_con = BKE_constraint_copy_for_pose(ob, pchan, con); | ||||
| new_con->flag |= CONSTRAINT_OVERRIDE_LIBRARY_LOCAL; | |||||
| ED_object_constraint_dependency_tag_update(bmain, ob, new_con); | ED_object_constraint_dependency_tag_update(bmain, ob, new_con); | ||||
| WM_main_add_notifier(NC_OBJECT | ND_CONSTRAINT | NA_ADDED, id); | WM_main_add_notifier(NC_OBJECT | ND_CONSTRAINT | NA_ADDED, id); | ||||
| return new_con; | return new_con; | ||||
| } | } | ||||
| bool rna_PoseChannel_constraints_override_apply(Main *UNUSED(bmain), | bool rna_PoseChannel_constraints_override_apply(Main *UNUSED(bmain), | ||||
| Show All 15 Lines | BLI_assert(opop->operation == IDOVERRIDE_LIBRARY_OP_INSERT_AFTER && | ||||
| "Unsupported RNA override operation on constraints collection"); | "Unsupported RNA override operation on constraints collection"); | ||||
| bPoseChannel *pchan_dst = (bPoseChannel *)ptr_dst->data; | bPoseChannel *pchan_dst = (bPoseChannel *)ptr_dst->data; | ||||
| bPoseChannel *pchan_src = (bPoseChannel *)ptr_src->data; | bPoseChannel *pchan_src = (bPoseChannel *)ptr_src->data; | ||||
| /* Remember that insertion operations are defined and stored in correct order, which means that | /* Remember that insertion operations are defined and stored in correct order, which means that | ||||
| * even if we insert several items in a row, we always insert first one, then second one, etc. | * even if we insert several items in a row, we always insert first one, then second one, etc. | ||||
| * So we should always find 'anchor' constraint in both _src *and* _dst */ | * So we should always find 'anchor' constraint in both _src *and* _dst */ | ||||
| bConstraint *con_anchor = NULL; | const size_t name_offset = offsetof(bConstraint, name); | ||||
| if (opop->subitem_local_name && opop->subitem_local_name[0]) { | bConstraint *con_anchor = BLI_listbase_string_or_index_find(&pchan_dst->constraints, | ||||
| con_anchor = BLI_findstring( | opop->subitem_reference_name, | ||||
| &pchan_dst->constraints, opop->subitem_local_name, offsetof(bConstraint, name)); | name_offset, | ||||
| } | opop->subitem_reference_index); | ||||
| if (con_anchor == NULL && opop->subitem_local_index >= 0) { | /* If `con_anchor` is NULL, `con_src` will be inserted in first position. */ | ||||
| con_anchor = BLI_findlink(&pchan_dst->constraints, opop->subitem_local_index); | |||||
| } | |||||
| /* Otherwise we just insert in first position. */ | |||||
| bConstraint *con_src = NULL; | bConstraint *con_src = BLI_listbase_string_or_index_find( | ||||
| if (opop->subitem_local_name && opop->subitem_local_name[0]) { | &pchan_src->constraints, opop->subitem_local_name, name_offset, opop->subitem_local_index); | ||||
| con_src = BLI_findstring( | |||||
| &pchan_src->constraints, opop->subitem_local_name, offsetof(bConstraint, name)); | |||||
| } | |||||
| if (con_src == NULL && opop->subitem_local_index >= 0) { | |||||
| con_src = BLI_findlink(&pchan_src->constraints, opop->subitem_local_index); | |||||
| } | |||||
| con_src = con_src ? con_src->next : pchan_src->constraints.first; | |||||
| if (con_src == NULL) { | if (con_src == NULL) { | ||||
| printf("%s: Could not find constraint to insert, doing nothing...\n", __func__); | BLI_assert(con_src != NULL); | ||||
| BLI_assert(0); | |||||
| return false; | return false; | ||||
| } | } | ||||
| bConstraint *con_dst = BKE_constraint_duplicate_ex(con_src, 0, true); | bConstraint *con_dst = BKE_constraint_duplicate_ex(con_src, 0, true); | ||||
| /* This handles NULL anchor as expected by adding at head of list. */ | /* This handles NULL anchor as expected by adding at head of list. */ | ||||
| BLI_insertlinkafter(&pchan_dst->constraints, con_anchor, con_dst); | BLI_insertlinkafter(&pchan_dst->constraints, con_anchor, con_dst); | ||||
| ▲ Show 20 Lines • Show All 1,049 Lines • Show Last 20 Lines | |||||