[Bf-blender-cvs] [caae973b8ab] id_copy_refactor: Move Group and ParticleSettings to new copying system.

Bastien Montagne noreply at git.blender.org
Sat Jul 8 17:12:22 CEST 2017


Commit: caae973b8ab0d092e2ed42bd0c164c4a76ffc14d
Author: Bastien Montagne
Date:   Sat Jul 8 17:09:52 2017 +0200
Branches: id_copy_refactor
https://developer.blender.org/rBcaae973b8ab0d092e2ed42bd0c164c4a76ffc14d

Move Group and ParticleSettings to new copying system.

Also fix several mistakes from previous commits.

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

M	source/blender/blenkernel/BKE_group.h
M	source/blender/blenkernel/BKE_particle.h
M	source/blender/blenkernel/intern/group.c
M	source/blender/blenkernel/intern/image.c
M	source/blender/blenkernel/intern/lamp.c
M	source/blender/blenkernel/intern/library.c
M	source/blender/blenkernel/intern/material.c
M	source/blender/blenkernel/intern/object.c
M	source/blender/blenkernel/intern/particle.c
M	source/blender/blenkernel/intern/texture.c
M	source/blender/blenkernel/intern/world.c

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

diff --git a/source/blender/blenkernel/BKE_group.h b/source/blender/blenkernel/BKE_group.h
index 684251c9561..404d1704c78 100644
--- a/source/blender/blenkernel/BKE_group.h
+++ b/source/blender/blenkernel/BKE_group.h
@@ -42,6 +42,7 @@ struct Scene;
 
 void          BKE_group_free(struct Group *group);
 struct Group *BKE_group_add(struct Main *bmain, const char *name);
+void          BKE_group_copy_data(struct Main *bmain, struct Group *group_dst, const struct Group *group_src, const int flag);
 struct Group *BKE_group_copy(struct Main *bmain, const struct Group *group);
 void          BKE_group_make_local(struct Main *bmain, struct Group *group, const bool lib_local);
 bool          BKE_group_object_add(struct Group *group, struct Object *ob, struct Scene *scene, struct Base *base);
diff --git a/source/blender/blenkernel/BKE_particle.h b/source/blender/blenkernel/BKE_particle.h
index f9948ba500a..2b621e217ab 100644
--- a/source/blender/blenkernel/BKE_particle.h
+++ b/source/blender/blenkernel/BKE_particle.h
@@ -324,6 +324,9 @@ struct ParticleSystemModifierData *psys_get_modifier(struct Object *ob, struct P
 struct ModifierData *object_add_particle_system(struct Scene *scene, struct Object *ob, const char *name);
 void object_remove_particle_system(struct Scene *scene, struct Object *ob);
 struct ParticleSettings *psys_new_settings(const char *name, struct Main *main);
+void BKE_particlesettings_copy_data(
+        struct Main *bmain, struct ParticleSettings *part_dst, const struct ParticleSettings *part_src,
+        const int flag);
 struct ParticleSettings *BKE_particlesettings_copy(struct Main *bmain, const struct ParticleSettings *part);
 void BKE_particlesettings_make_local(struct Main *bmain, struct ParticleSettings *part, const bool lib_local);
 
diff --git a/source/blender/blenkernel/intern/group.c b/source/blender/blenkernel/intern/group.c
index 932f41ac4ba..7b292fb2d10 100644
--- a/source/blender/blenkernel/intern/group.c
+++ b/source/blender/blenkernel/intern/group.c
@@ -89,19 +89,32 @@ Group *BKE_group_add(Main *bmain, const char *name)
 	return group;
 }
 
-Group *BKE_group_copy(Main *bmain, const Group *group)
+/**
+ * Only copy internal data of Group ID from source to already allocated/initialized destination.
+ * You probably nerver want to use that directly, use id_copy or BKE_id_copy_ex for typical needs.
+ *
+ * WARNING! This function will not handle ID user count!
+ *
+ * \param flag  Copying options (see BKE_library.h's LIB_ID_COPY_... flags for more).
+ */
+void BKE_group_copy_data(Main *UNUSED(bmain), Group *group_dst, const Group *group_src, const int flag)
 {
-	Group *groupn;
-
-	groupn = BKE_libblock_copy(bmain, &group->id);
-	BLI_duplicatelist(&groupn->gobject, &group->gobject);
+	BLI_duplicatelist(&group_dst->gobject, &group_src->gobject);
 
 	/* Do not copy group's preview (same behavior as for objects). */
-	groupn->preview = NULL;
-
-	BKE_id_copy_ensure_local(bmain, &group->id, &groupn->id);
+	if ((flag & LIB_ID_COPY_NO_PREVIEW) == 0 && false) {  /* XXX TODO temp hack */
+		BKE_previewimg_id_copy(&group_dst->id, &group_src->id);
+	}
+	else {
+		group_dst->preview = NULL;
+	}
+}
 
-	return groupn;
+Group *BKE_group_copy(Main *bmain, const Group *group)
+{
+	Group *group_copy;
+	BKE_id_copy_ex(bmain, &group->id, (ID **)&group_copy, 0, false);
+	return group_copy;
 }
 
 void BKE_group_make_local(Main *bmain, Group *group, const bool lib_local)
diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c
index 255c2b9550c..b0cfbad786f 100644
--- a/source/blender/blenkernel/intern/image.c
+++ b/source/blender/blenkernel/intern/image.c
@@ -466,7 +466,7 @@ void BKE_image_copy_data(Main *UNUSED(bmain), Image *ima_dst, const Image *ima_s
 	}
 	ima_dst->repbind = NULL;
 
-	if ((flag & LIB_ID_COPY_NO_PREVIEW) != 1) {
+	if ((flag & LIB_ID_COPY_NO_PREVIEW) == 0) {
 		BKE_previewimg_id_copy(&ima_dst->id, &ima_src->id);
 	}
 	else {
diff --git a/source/blender/blenkernel/intern/lamp.c b/source/blender/blenkernel/intern/lamp.c
index bbbbf0ea49d..4103863ff6a 100644
--- a/source/blender/blenkernel/intern/lamp.c
+++ b/source/blender/blenkernel/intern/lamp.c
@@ -139,7 +139,7 @@ void BKE_lamp_copy_data(Main *bmain, Lamp *la_dst, const Lamp *la_src, const int
 		BKE_id_copy_ex(bmain, (ID *)la_src->nodetree, (ID **)&la_dst->nodetree, flag, false);
 	}
 
-	if ((flag & LIB_ID_COPY_NO_PREVIEW) != 1) {
+	if ((flag & LIB_ID_COPY_NO_PREVIEW) == 0) {
 		BKE_previewimg_id_copy(&la_dst->id, &la_src->id);
 	}
 	else {
diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c
index fb0f043c733..c6e8d0f85ad 100644
--- a/source/blender/blenkernel/intern/library.c
+++ b/source/blender/blenkernel/intern/library.c
@@ -526,11 +526,12 @@ static int id_copy_libmanagement_cb(void *user_data, ID *id_self, ID **id_pointe
 /* XXX TODO remove test thing, *all* IDs should be copyable that way! */
 bool BKE_id_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int flag, const bool test)
 {
-#define ITEMS_IMPLEMENTED ID_OB, ID_ME, ID_CU, ID_MB, ID_MA, ID_TE, ID_IM, ID_LT, ID_LA, ID_SPK, ID_CA, ID_KE, ID_AR, ID_NT
+#define ITEMS_IMPLEMENTED_1 ID_OB, ID_ME, ID_CU, ID_MB, ID_MA, ID_TE, ID_IM, ID_LT, ID_LA, ID_SPK
+#define ITEMS_IMPLEMENTED_2 ID_CA, ID_KE, ID_WO, ID_GR, ID_AR, ID_NT, ID_PA, ID_MC
 
 	if (!test) {
 		/* Check to be removed of course, just here until all BKE_xxx_copy_ex functions are done. */
-		if (ELEM(GS(id->name), ITEMS_IMPLEMENTED)) {
+		if (ELEM(GS(id->name), ITEMS_IMPLEMENTED_1) || ELEM(GS(id->name), ITEMS_IMPLEMENTED_2)) {
 			BKE_libblock_copy_ex(bmain, id, r_newid, flag);
 		}
 	}
@@ -579,7 +580,7 @@ bool BKE_id_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int flag, con
 			if (!test) *r_newid = (ID *)BKE_text_copy(bmain, (Text *)id);
 			break;
 		case ID_GR:
-			if (!test) *r_newid = (ID *)BKE_group_copy(bmain, (Group *)id);
+			if (!test) BKE_group_copy_data(bmain, (Group *)*r_newid, (Group *)id, flag);
 			break;
 		case ID_AR:
 			if (!test) BKE_armature_copy_data(bmain, (bArmature *)*r_newid, (bArmature *)id, flag);
@@ -594,7 +595,7 @@ bool BKE_id_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int flag, con
 			if (!test) *r_newid = (ID *)BKE_brush_copy(bmain, (Brush *)id);
 			break;
 		case ID_PA:
-			if (!test) *r_newid = (ID *)BKE_particlesettings_copy(bmain, (ParticleSettings *)id);
+			if (!test) BKE_particlesettings_copy_data(bmain, (ParticleSettings *)*r_newid, (ParticleSettings *)id, flag);
 			break;
 		case ID_GD:
 			if (!test) *r_newid = (ID *)BKE_gpencil_data_duplicate(bmain, (bGPdata *)id, false);
@@ -631,7 +632,7 @@ bool BKE_id_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int flag, con
 
 	if (!test) {
 		/* Check to be removed of course, just here until all BKE_xxx_copy_ex functions are done. */
-		if (ELEM(GS(id->name), ITEMS_IMPLEMENTED)) {
+		if (ELEM(GS(id->name), ITEMS_IMPLEMENTED_1) || ELEM(GS(id->name), ITEMS_IMPLEMENTED_2)) {
 			/* Update ID refcount, remap pointers to self in new ID. */
 			struct IDCopyLibManagementData data = {.id_src=id, .flag=flag};
 			BKE_library_foreach_ID_link(bmain, *r_newid, id_copy_libmanagement_cb, &data, IDWALK_NOP);
diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c
index a8e2ec31831..dfe440fea9c 100644
--- a/source/blender/blenkernel/intern/material.c
+++ b/source/blender/blenkernel/intern/material.c
@@ -247,7 +247,7 @@ void BKE_material_copy_data(Main *bmain, Material *ma_dst, const Material *ma_sr
 		BKE_id_copy_ex(bmain, (ID *)ma_src->nodetree, (ID **)&ma_dst->nodetree, flag, false);
 	}
 
-	if ((flag & LIB_ID_COPY_NO_PREVIEW) != 1) {
+	if ((flag & LIB_ID_COPY_NO_PREVIEW) == 0) {
 		BKE_previewimg_id_copy(&ma_dst->id, &ma_src->id);
 	}
 	else {
diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c
index f2b7a809f45..8a626b123d2 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -1179,11 +1179,11 @@ void BKE_object_copy_data(Main *UNUSED(bmain), Object *ob_dst, const Object *ob_
 	ob_dst->curve_cache = NULL;
 
 	/* Do not copy object's preview (mostly due to the fact renderers create temp copy of objects). */
-	if ((flag & LIB_ID_COPY_NO_PREVIEW) == 1 || true) {  /* XXX TODO temp hack */
-		ob_dst->preview = NULL;
+	if ((flag & LIB_ID_COPY_NO_PREVIEW) == 0 && false) {  /* XXX TODO temp hack */
+		BKE_previewimg_id_copy(&ob_dst->id, &ob_src->id);
 	}
 	else {
-		BKE_previewimg_id_copy(&ob_dst->id, &ob_src->id);
+		ob_dst->preview = NULL;
 	}
 }
 
diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c
index 416d63cfefb..d9553d8ba41 100644
--- a/source/blender/blenkernel/intern/particle.c
+++ b/source/blender/blenkernel/intern/particle.c
@@ -3331,38 +3331,45 @@ void BKE_particlesettings_rough_curve_init(ParticleSettings *part)
 	part->roughcurve = cumap;
 }
 
-ParticleSettings *BKE_particlesettings_copy(Main *bmain, const ParticleSettings *part)
+/**
+ * Only copy internal data of ParticleSettings ID from source to already allocated/initialized destination.
+ * You probably nerver want to use that directly, use id_copy or BKE_id_copy_ex for typical needs.
+ *
+ * WARNING! This function will not handle ID user count!
+ *
+ * \param flag  Copying options (see BKE_library.h's LIB_ID_COPY_... flags for more).
+ */
+void BKE_particlesettings_copy_data(
+        Main *UNUSED(bmain), ParticleSettings *part_dst, const ParticleSettings *part_src, const int UNUSED(flag))
 {
-	ParticleSettings *partn;
-	int a;
+	part_dst->pd = MEM_dupallocN(part_src->pd);
+	part_dst->pd2 = MEM_dupallocN(part_src->pd2);
+	part_dst->effector_weights = MEM_dupallocN(part_src->effector_weights);
+	part_dst->fluid = MEM_dupallocN(part_src->fluid);
 
-	partn = BKE_libblock_copy(bmain, &part->id);
+	if (part_src->clumpcurve) {
+		part_dst->clumpcurve = curvemapping_copy(part_src->clumpcurve);
+	}
+	if (part_src->roughcurve) {
+		part_dst->roughcurve = curvemapping_copy(part_src->roughcurve);
+	}
 
-	partn->pd = MEM_dupallocN(part->pd);
-	partn->pd2 = MEM_dupallocN(part->pd2);
-	partn->effector_weights = MEM_d

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list