From 3cb0e8e1af4f8a045590d85a999fd5dacd0d835e Mon Sep 17 00:00:00 2001 From: Dalai Felinto Date: Wed, 19 Apr 2017 19:05:59 +0200 Subject: IDProperty: New util function to merge groups recursively --- source/blender/blenkernel/BKE_idprop.h | 1 + source/blender/blenkernel/intern/idprop.c | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) (limited to 'source') diff --git a/source/blender/blenkernel/BKE_idprop.h b/source/blender/blenkernel/BKE_idprop.h index ab8728faedb..1f44719e2d3 100644 --- a/source/blender/blenkernel/BKE_idprop.h +++ b/source/blender/blenkernel/BKE_idprop.h @@ -91,6 +91,7 @@ void IDP_ReplaceGroupInGroup(struct IDProperty *dest, const struct IDProperty *s void IDP_ReplaceInGroup(struct IDProperty *group, struct IDProperty *prop) ATTR_NONNULL(); void IDP_ReplaceInGroup_ex(struct IDProperty *group, struct IDProperty *prop, struct IDProperty *prop_exist); void IDP_MergeGroup(IDProperty *dest, const IDProperty *src, const bool do_overwrite) ATTR_NONNULL(); +void IDP_MergeGroupValues(IDProperty *dest, IDProperty *src); bool IDP_AddToGroup(struct IDProperty *group, struct IDProperty *prop) ATTR_NONNULL(); bool IDP_InsertToGroup(struct IDProperty *group, struct IDProperty *previous, struct IDProperty *pnew) ATTR_NONNULL(1 /* group */, 3 /* pnew */); diff --git a/source/blender/blenkernel/intern/idprop.c b/source/blender/blenkernel/intern/idprop.c index 78a5273f0d0..eadeeb2d86a 100644 --- a/source/blender/blenkernel/intern/idprop.c +++ b/source/blender/blenkernel/intern/idprop.c @@ -599,6 +599,31 @@ void IDP_ReplaceInGroup(IDProperty *group, IDProperty *prop) IDP_ReplaceInGroup_ex(group, prop, prop_exist); } +/** + * Same as IDP_MergeGroup but recursively + */ +void IDP_MergeGroupValues(IDProperty *dest, IDProperty *src) +{ + IDProperty *prop; + + BLI_assert(dest->type == IDP_GROUP); + BLI_assert(src->type == IDP_GROUP); + + for (prop = src->data.group.first; prop; prop = prop->next) { + if (prop->type == IDP_GROUP) { + IDProperty *prop_exist = IDP_GetPropertyFromGroup(dest, prop->name); + + if (prop_exist != NULL) { + IDP_MergeGroupValues(prop_exist, prop); + continue; + } + } + + IDProperty *copy = IDP_CopyProperty(prop); + IDP_ReplaceInGroup(dest, copy); + } +} + /** * If a property is missing in \a dest, add it. */ -- cgit v1.2.3