Refactor getting constraints

This is the refactoring part of D8805 (should be no functional changes).

- exposes pose-related part of former 'get_constraints()' from
interface_templates.c to new ED_object_pose_constraint_list
- rename ED_object_constraint_list_from_context -->
ED_object_constraint_active_list

Also clarify comments on both of these.

ref T80464
ref https://developer.blender.org/D8805
This commit is contained in:
Philipp Oeser 2020-09-09 13:52:37 +02:00 committed by Jeroen Bakker
parent d52d56e83d
commit 8b953fa83d
Notes: blender-bot 2023-02-14 11:29:52 +01:00
Referenced by issue #80464, Deleting bone constraints when the armature layer isn't active crashes Blender
4 changed files with 33 additions and 23 deletions

View File

@ -310,7 +310,8 @@ void ED_objects_recalculate_paths(struct bContext *C,
eObjectPathCalcRange range);
/* constraints */
struct ListBase *ED_object_constraint_list_from_context(struct Object *ob);
struct ListBase *ED_object_constraint_active_list(struct Object *ob);
struct ListBase *ED_object_pose_constraint_list(const struct bContext *C);
struct ListBase *ED_object_constraint_list_from_constraint(struct Object *ob,
struct bConstraint *con,
struct bPoseChannel **r_pchan);

View File

@ -1950,18 +1950,13 @@ static bool constraint_panel_is_bone(Panel *panel)
*/
static ListBase *get_constraints(const bContext *C, bool use_bone_constraints)
{
ListBase *constraints = {NULL};
ListBase *constraints = NULL;
if (use_bone_constraints) {
bPoseChannel *pose_bone = CTX_data_pointer_get(C, "pose_bone").data;
if (pose_bone != NULL) {
constraints = &pose_bone->constraints;
}
constraints = ED_object_pose_constraint_list(C);
}
else {
Object *ob = ED_object_active_context(C);
if (ob != NULL) {
constraints = &ob->constraints;
}
constraints = ED_object_constraint_active_list(ob);
}
return constraints;
}
@ -2043,7 +2038,13 @@ void uiTemplateConstraints(uiLayout *UNUSED(layout), bContext *C, bool use_bone_
ARegion *region = CTX_wm_region(C);
Object *ob = ED_object_active_context(C);
ListBase *constraints = get_constraints(C, use_bone_constraints);
ListBase *constraints = {NULL};
if (use_bone_constraints) {
constraints = ED_object_pose_constraint_list(C);
}
else {
constraints = ED_object_constraint_active_list(ob);
}
/* Switch between the bone panel ID function and the object panel ID function. */
uiListPanelIDFromDataFunc panel_id_func = use_bone_constraints ? bone_constraint_panel_id :

View File

@ -80,8 +80,9 @@
/** \name Constraint Data Accessors
* \{ */
/* if object in posemode, active bone constraints, else object constraints */
ListBase *ED_object_constraint_list_from_context(Object *ob)
/* If object is in posemode, return active bone constraints, else object constraints. No
* constraints are returned for a bone on an inactive bonelayer. */
ListBase *ED_object_constraint_active_list(Object *ob)
{
if (ob == NULL) {
return NULL;
@ -102,6 +103,18 @@ ListBase *ED_object_constraint_list_from_context(Object *ob)
return NULL;
}
/* Get the constraints for the active pose bone. Bone may be on an inactive bonelayer (unlike
* ED_object_constraint_active_list, such constraints are not excluded here). */
ListBase *ED_object_pose_constraint_list(const bContext *C)
{
bPoseChannel *pose_bone = CTX_data_pointer_get(C, "pose_bone").data;
if (pose_bone == NULL) {
return NULL;
}
return &pose_bone->constraints;
}
/* Find the list that a given constraint belongs to,
* and/or also get the posechannel this is from (if applicable) */
ListBase *ED_object_constraint_list_from_constraint(Object *ob,
@ -147,7 +160,7 @@ ListBase *ED_object_constraint_list_from_constraint(Object *ob,
/* single constraint */
bConstraint *ED_object_constraint_active_get(Object *ob)
{
return BKE_constraints_active_get(ED_object_constraint_list_from_context(ob));
return BKE_constraints_active_get(ED_object_constraint_active_list(ob));
}
/** \} */
@ -813,7 +826,7 @@ static bConstraint *edit_constraint_property_get(wmOperator *op, Object *ob, int
printf("edit_constraint_property_get: defaulting to getting list in the standard way\n");
}
#endif
list = ED_object_constraint_list_from_context(ob);
list = ED_object_constraint_active_list(ob);
}
con = BKE_constraints_find_name(list, constraint_name);
@ -2162,8 +2175,7 @@ static int pose_constraint_add_exec(bContext *C, wmOperator *op)
with_targets = 1;
}
return constraint_add_exec(
C, op, ob, ED_object_constraint_list_from_context(ob), type, with_targets);
return constraint_add_exec(C, op, ob, ED_object_constraint_active_list(ob), type, with_targets);
}
/* ------------------ */
@ -2364,12 +2376,8 @@ static int pose_ik_add_exec(bContext *C, wmOperator *op)
/* add the constraint - all necessary checks should have
* been done by the invoke() callback already... */
return constraint_add_exec(C,
op,
ob,
ED_object_constraint_list_from_context(ob),
CONSTRAINT_TYPE_KINEMATIC,
with_targets);
return constraint_add_exec(
C, op, ob, ED_object_constraint_active_list(ob), CONSTRAINT_TYPE_KINEMATIC, with_targets);
}
void POSE_OT_ik_add(wmOperatorType *ot)

View File

@ -271,7 +271,7 @@ void BCAnimationSampler::find_depending_animated(std::set<Object *> &animated_ob
std::set<Object *>::iterator it;
for (it = candidates.begin(); it != candidates.end(); ++it) {
Object *cob = *it;
ListBase *conlist = ED_object_constraint_list_from_context(cob);
ListBase *conlist = ED_object_constraint_active_list(cob);
if (is_animated_by_constraint(cob, conlist, animated_objects)) {
animated_objects.insert(cob);
candidates.erase(cob);