[Bf-blender-cvs] [3cb0e8e1af4] blender2.8: IDProperty: New util function to merge groups recursively

Dalai Felinto noreply at git.blender.org
Thu Apr 20 11:00:41 CEST 2017


Commit: 3cb0e8e1af4f8a045590d85a999fd5dacd0d835e
Author: Dalai Felinto
Date:   Wed Apr 19 19:05:59 2017 +0200
Branches: blender2.8
https://developer.blender.org/rB3cb0e8e1af4f8a045590d85a999fd5dacd0d835e

IDProperty: New util function to merge groups recursively

===================================================================

M	source/blender/blenkernel/BKE_idprop.h
M	source/blender/blenkernel/intern/idprop.c

===================================================================

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
@@ -600,6 +600,31 @@ void IDP_ReplaceInGroup(IDProperty *group, IDProperty *prop)
 }
 
 /**
+ * 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.
  */
 void IDP_MergeGroup(IDProperty *dest, const IDProperty *src, const bool do_overwrite)




More information about the Bf-blender-cvs mailing list