diff options
author | Philipp Oeser <info@graphics-engineer.com> | 2020-09-09 14:52:37 +0300 |
---|---|---|
committer | Philipp Oeser <info@graphics-engineer.com> | 2020-09-09 15:12:55 +0300 |
commit | 9dcae4eb17d7b5a90fda43d0abab1636acf42851 (patch) | |
tree | 60dc9706c2bab6e363096baf865b585a46a4d31f /source/blender/editors/object | |
parent | 98eb89be5dd08f3b38f34e7881bae37c3b13e8bb (diff) |
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
Diffstat (limited to 'source/blender/editors/object')
-rw-r--r-- | source/blender/editors/object/object_constraint.c | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/source/blender/editors/object/object_constraint.c b/source/blender/editors/object/object_constraint.c index 2cca3045aee..9da5b774af2 100644 --- a/source/blender/editors/object/object_constraint.c +++ b/source/blender/editors/object/object_constraint.c @@ -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); @@ -2161,8 +2174,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); } /* ------------------ */ @@ -2363,12 +2375,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) |