[Bf-blender-cvs] [8b953fa83d6] blender-v2.90-release: Refactor getting constraints
Philipp Oeser
noreply at git.blender.org
Mon Sep 21 09:50:33 CEST 2020
Commit: 8b953fa83d64ef0fa140c82e79d1a3101d7496b0
Author: Philipp Oeser
Date: Wed Sep 9 13:52:37 2020 +0200
Branches: blender-v2.90-release
https://developer.blender.org/rB8b953fa83d64ef0fa140c82e79d1a3101d7496b0
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
===================================================================
M source/blender/editors/include/ED_object.h
M source/blender/editors/interface/interface_templates.c
M source/blender/editors/object/object_constraint.c
M source/blender/io/collada/BCAnimationSampler.cpp
===================================================================
diff --git a/source/blender/editors/include/ED_object.h b/source/blender/editors/include/ED_object.h
index 4c7dd4fe66c..99ecf0b69de 100644
--- a/source/blender/editors/include/ED_object.h
+++ b/source/blender/editors/include/ED_object.h
@@ -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);
diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c
index 50148d8a8cd..a7fe3074e1f 100644
--- a/source/blender/editors/interface/interface_templates.c
+++ b/source/blender/editors/interface/interface_templates.c
@@ -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 :
diff --git a/source/blender/editors/object/object_constraint.c b/source/blender/editors/object/object_constraint.c
index 70404af6433..b6ff599da9a 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);
@@ -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)
diff --git a/source/blender/io/collada/BCAnimationSampler.cpp b/source/blender/io/collada/BCAnimationSampler.cpp
index f44e3e8385d..bf2f2ab90f6 100644
--- a/source/blender/io/collada/BCAnimationSampler.cpp
+++ b/source/blender/io/collada/BCAnimationSampler.cpp
@@ -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);
More information about the Bf-blender-cvs
mailing list