[Bf-blender-cvs] [6637530b811] id_copy_refactor: Move Text, Brush and GPencil datablocks to new copying code.

Bastien Montagne noreply at git.blender.org
Sun Jul 9 22:45:06 CEST 2017


Commit: 6637530b811f435f9dcf6b62092f465e96bef42c
Author: Bastien Montagne
Date:   Sun Jul 9 22:14:00 2017 +0200
Branches: id_copy_refactor
https://developer.blender.org/rB6637530b811f435f9dcf6b62092f465e96bef42c

Move Text, Brush and GPencil datablocks to new copying code.

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

M	source/blender/blenkernel/BKE_brush.h
M	source/blender/blenkernel/BKE_gpencil.h
M	source/blender/blenkernel/BKE_text.h
M	source/blender/blenkernel/intern/brush.c
M	source/blender/blenkernel/intern/gpencil.c
M	source/blender/blenkernel/intern/library.c
M	source/blender/blenkernel/intern/text.c

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

diff --git a/source/blender/blenkernel/BKE_brush.h b/source/blender/blenkernel/BKE_brush.h
index 42e4e73f2d5..dedb75a080a 100644
--- a/source/blender/blenkernel/BKE_brush.h
+++ b/source/blender/blenkernel/BKE_brush.h
@@ -44,6 +44,7 @@ void BKE_brush_system_exit(void);
 void BKE_brush_init(struct Brush *brush);
 struct Brush *BKE_brush_add(struct Main *bmain, const char *name, short ob_mode);
 struct Brush *BKE_brush_first_search(struct Main *bmain, short ob_mode);
+void BKE_brush_copy_data(struct Main *bmain, struct Brush *brush_dst, const struct Brush *brush_src, const int flag);
 struct Brush *BKE_brush_copy(struct Main *bmain, const struct Brush *brush);
 void BKE_brush_make_local(struct Main *bmain, struct Brush *brush, const bool lib_local);
 void BKE_brush_unlink(struct Main *bmain, struct Brush *brush);
diff --git a/source/blender/blenkernel/BKE_gpencil.h b/source/blender/blenkernel/BKE_gpencil.h
index bdd28baf137..b6de922c245 100644
--- a/source/blender/blenkernel/BKE_gpencil.h
+++ b/source/blender/blenkernel/BKE_gpencil.h
@@ -60,6 +60,7 @@ struct bGPdata   *BKE_gpencil_data_addnew(const char name[]);
 
 struct bGPDframe *BKE_gpencil_frame_duplicate(const struct bGPDframe *gpf_src);
 struct bGPDlayer *BKE_gpencil_layer_duplicate(const struct bGPDlayer *gpl_src);
+void BKE_gpencil_copy_data(struct Main *bmain, struct bGPdata *gpd_dst, const struct bGPdata *gpd_src, const int flag);
 struct bGPdata   *BKE_gpencil_data_duplicate(struct Main *bmain, const struct bGPdata *gpd, bool internal_copy);
 
 void BKE_gpencil_make_local(struct Main *bmain, struct bGPdata *gpd, const bool lib_local);
diff --git a/source/blender/blenkernel/BKE_text.h b/source/blender/blenkernel/BKE_text.h
index c8fb483cdf2..14d3318e059 100644
--- a/source/blender/blenkernel/BKE_text.h
+++ b/source/blender/blenkernel/BKE_text.h
@@ -52,6 +52,7 @@ bool            BKE_text_reload(struct Text *text);
 struct Text    *BKE_text_load_ex(struct Main *bmain, const char *file, const char *relpath,
                                  const bool is_internal);
 struct Text    *BKE_text_load	(struct Main *bmain, const char *file, const char *relpath);
+void            BKE_text_copy_data(struct Main *bmain, struct Text *ta_dst, const struct Text *ta_src, const int flag);
 struct Text    *BKE_text_copy		(struct Main *bmain, const struct Text *ta);
 void            BKE_text_make_local (struct Main *bmain, struct Text *text, const bool lib_local);
 void			BKE_text_clear      (struct Text *text);
diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c
index aae323a5056..8277d0a4b1c 100644
--- a/source/blender/blenkernel/intern/brush.c
+++ b/source/blender/blenkernel/intern/brush.c
@@ -172,34 +172,38 @@ struct Brush *BKE_brush_first_search(struct Main *bmain, short ob_mode)
 	return NULL;
 }
 
-Brush *BKE_brush_copy(Main *bmain, const Brush *brush)
+/**
+ * Only copy internal data of Brush 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_brush_copy_data(Main *UNUSED(bmain), Brush *brush_dst, const Brush *brush_src, const int flag)
 {
-	Brush *brushn;
-	
-	brushn = BKE_libblock_copy(bmain, &brush->id);
-
-	if (brush->mtex.tex)
-		id_us_plus((ID *)brush->mtex.tex);
-
-	if (brush->mask_mtex.tex)
-		id_us_plus((ID *)brush->mask_mtex.tex);
-
-	if (brush->paint_curve)
-		id_us_plus((ID *)brush->paint_curve);
-
-	if (brush->icon_imbuf)
-		brushn->icon_imbuf = IMB_dupImBuf(brush->icon_imbuf);
+	if (brush_src->icon_imbuf) {
+		brush_dst->icon_imbuf = IMB_dupImBuf(brush_src->icon_imbuf);
+	}
 
-	brushn->preview = NULL;
+	if ((flag & LIB_ID_COPY_NO_PREVIEW) == 0) {
+		BKE_previewimg_id_copy(&brush_dst->id, &brush_src->id);
+	}
+	else {
+		brush_dst->preview = NULL;
+	}
 
-	brushn->curve = curvemapping_copy(brush->curve);
+	brush_dst->curve = curvemapping_copy(brush_src->curve);
 
 	/* enable fake user by default */
-	id_fake_user_set(&brushn->id);
-
-	BKE_id_copy_ensure_local(bmain, &brush->id, &brushn->id);
+	id_fake_user_set(&brush_dst->id);
+}
 
-	return brushn;
+Brush *BKE_brush_copy(Main *bmain, const Brush *brush)
+{
+	Brush *brush_copy;
+	BKE_id_copy_ex(bmain, &brush->id, (ID **)&brush_copy, 0, false);
+	return brush_copy;
 }
 
 /** Free (or release) any data used by this brush (does not free the brush itself). */
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index 758438bb051..a9a741b0713 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -753,47 +753,62 @@ bGPDlayer *BKE_gpencil_layer_duplicate(const bGPDlayer *gpl_src)
 	return gpl_dst;
 }
 
-/* make a copy of a given gpencil datablock */
-bGPdata *BKE_gpencil_data_duplicate(Main *bmain, const bGPdata *gpd_src, bool internal_copy)
+/**
+ * Only copy internal data of GreasePencil 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_gpencil_copy_data(Main *UNUSED(bmain), bGPdata *gpd_dst, const bGPdata *gpd_src, const int UNUSED(flag))
 {
-	const bGPDlayer *gpl_src;
-	bGPDlayer *gpl_dst;
-	bGPdata *gpd_dst;
+	/* copy layers */
+	BLI_listbase_clear(&gpd_dst->layers);
+	for (const bGPDlayer *gpl_src = gpd_src->layers.first; gpl_src; gpl_src = gpl_src->next) {
+		/* make a copy of source layer and its data */
+		bGPDlayer *gpl_dst = BKE_gpencil_layer_duplicate(gpl_src);  /* TODO here too could add unused flags... */
+		BLI_addtail(&gpd_dst->layers, gpl_dst);
+	}
 
-	/* error checking */
-	if (gpd_src == NULL) {
-		return NULL;
+	/* copy palettes */
+	BLI_listbase_clear(&gpd_dst->palettes);
+	for (const bGPDpalette *palette_src = gpd_src->palettes.first; palette_src; palette_src = palette_src->next) {
+		bGPDpalette *palette_dst = BKE_gpencil_palette_duplicate(palette_src);  /* TODO here too could add unused flags... */
+		BLI_addtail(&gpd_dst->palettes, palette_dst);
 	}
-	
-	/* make a copy of the base-data */
+}
+
+/* make a copy of a given gpencil datablock */
+bGPdata *BKE_gpencil_data_duplicate(Main *bmain, const bGPdata *gpd_src, bool internal_copy)
+{
+	/* Yuck and super-uber-hyper yuck!!!
+	 * Should be replaceable with a no-main copy (LIB_ID_COPY_NO_MAIN etc.), but not sure about it,
+	 * so for now keep old code for that one. */
 	if (internal_copy) {
+		const bGPDlayer *gpl_src;
+		bGPDlayer *gpl_dst;
+		bGPdata *gpd_dst;
+
 		/* make a straight copy for undo buffers used during stroke drawing */
 		gpd_dst = MEM_dupallocN(gpd_src);
+
+		/* copy layers */
+		BLI_listbase_clear(&gpd_dst->layers);
+		for (gpl_src = gpd_src->layers.first; gpl_src; gpl_src = gpl_src->next) {
+			/* make a copy of source layer and its data */
+			gpl_dst = BKE_gpencil_layer_duplicate(gpl_src);
+			BLI_addtail(&gpd_dst->layers, gpl_dst);
+		}
+
+		/* return new */
+		return gpd_dst;
 	}
 	else {
-		/* make a copy when others use this */
-		gpd_dst = BKE_libblock_copy(bmain, &gpd_src->id);
-	}
-	
-	/* copy layers */
-	BLI_listbase_clear(&gpd_dst->layers);
-	for (gpl_src = gpd_src->layers.first; gpl_src; gpl_src = gpl_src->next) {
-		/* make a copy of source layer and its data */
-		gpl_dst = BKE_gpencil_layer_duplicate(gpl_src);
-		BLI_addtail(&gpd_dst->layers, gpl_dst);
-	}
-	if (!internal_copy) {
-		/* copy palettes */
-		bGPDpalette *palette_src, *palette_dst;
-		BLI_listbase_clear(&gpd_dst->palettes);
-		for (palette_src = gpd_src->palettes.first; palette_src; palette_src = palette_src->next) {
-			palette_dst = BKE_gpencil_palette_duplicate(palette_src);
-			BLI_addtail(&gpd_dst->palettes, palette_dst);
-		}
+		bGPdata *gpd_copy;
+		BKE_id_copy_ex(bmain, &gpd_src->id, (ID **)&gpd_copy, 0, false);
+		return gpd_copy;
 	}
-	
-	/* return new */
-	return gpd_dst;
 }
 
 void BKE_gpencil_make_local(Main *bmain, bGPdata *gpd, const bool lib_local)
diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c
index a25fea7fd9b..9917cac0f11 100644
--- a/source/blender/blenkernel/intern/library.c
+++ b/source/blender/blenkernel/intern/library.c
@@ -526,8 +526,8 @@ 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_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_AC, ID_NT, ID_PA, ID_MC
+#define ITEMS_IMPLEMENTED_1 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_WO, ID_TXT, ID_GR
+#define ITEMS_IMPLEMENTED_2 ID_AR, ID_AC, ID_NT, ID_BR, ID_PA, ID_GD, ID_MC
 
 	if (!test) {
 		/* Check to be removed of course, just here until all BKE_xxx_copy_ex functions are done. */
@@ -577,7 +577,7 @@ bool BKE_id_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int flag, con
 			if (!test) BKE_world_copy_data(bmain, (World *)*r_newid, (World *)id, flag);
 			break;
 		case ID_TXT:
-			if (!test) *r_newid = (ID *)BKE_text_copy(bmain, (Text *)id);
+			if (!test) BKE_text_copy_data(bmain, (Text *)*r_newid, (Text *)id, flag);
 			break;
 		case ID_GR:
 			if (!test) BKE_group_copy_data(bmain, (Group *)*r_newid, (Group *)id, flag);
@@ -592,13 +592,13 @@ bool BKE_id_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int flag, con
 			if (!test) BKE_node_tree_copy_data(bmain, (bNodeTree *)*r_newid, (bNodeTree *)id, flag);
 			break;
 		case ID_BR:
-			if (!test) *r_newid = (ID *)BKE_brush_copy(bmain, (Brush *)id);
+			if (!test) BKE_brush_copy_data(bmain, (Brush *)*r_newid, (Brush *)id, flag);
 			break;
 		case ID_PA:
 			if (!test) BKE_particlesettings_copy_data(bmain, (ParticleSettings *)*r_

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list