[Bf-blender-cvs] [0b009edbdea] id_copy_refactor: Move Palette, PaintCurve and CacheFIle to new ID copying system.

Bastien Montagne noreply at git.blender.org
Tue Jul 11 15:57:54 CEST 2017


Commit: 0b009edbdea348c6d39134dd9c0c86914c899869
Author: Bastien Montagne
Date:   Mon Jul 10 09:56:52 2017 +0200
Branches: id_copy_refactor
https://developer.blender.org/rB0b009edbdea348c6d39134dd9c0c86914c899869

Move Palette, PaintCurve and CacheFIle to new ID copying system.

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

M	source/blender/blenkernel/BKE_cachefile.h
M	source/blender/blenkernel/BKE_paint.h
M	source/blender/blenkernel/intern/cachefile.c
M	source/blender/blenkernel/intern/library.c
M	source/blender/blenkernel/intern/paint.c

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

diff --git a/source/blender/blenkernel/BKE_cachefile.h b/source/blender/blenkernel/BKE_cachefile.h
index f1e643c4a19..e9712681090 100644
--- a/source/blender/blenkernel/BKE_cachefile.h
+++ b/source/blender/blenkernel/BKE_cachefile.h
@@ -47,6 +47,8 @@ void BKE_cachefile_init(struct CacheFile *cache_file);
 
 void BKE_cachefile_free(struct CacheFile *cache_file);
 
+void BKE_cachefile_copy_data(
+        struct Main *bmain, struct CacheFile *cache_file_dst, const struct CacheFile *cache_file_src, const int flag);
 struct CacheFile *BKE_cachefile_copy(struct Main *bmain, const struct CacheFile *cache_file);
 
 void BKE_cachefile_make_local(struct Main *bmain, struct CacheFile *cache_file, const bool lib_local);
diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h
index 821dc211591..0802da8619a 100644
--- a/source/blender/blenkernel/BKE_paint.h
+++ b/source/blender/blenkernel/BKE_paint.h
@@ -99,6 +99,8 @@ void BKE_paint_set_overlay_override(enum OverlayFlags flag);
 /* palettes */
 void                 BKE_palette_free(struct Palette *palette);
 struct Palette      *BKE_palette_add(struct Main *bmain, const char *name);
+void BKE_palette_copy_data(
+        struct Main *bmain, struct Palette *palette_dst, const struct Palette *palette_src, const int flag);
 struct Palette      *BKE_palette_copy(struct Main *bmain, const struct Palette *palette);
 void                 BKE_palette_make_local(struct Main *bmain, struct Palette *palette, const bool lib_local);
 struct PaletteColor *BKE_palette_color_add(struct Palette *palette);
@@ -109,6 +111,8 @@ void                 BKE_palette_clear(struct Palette *palette);
 /* paint curves */
 struct PaintCurve *BKE_paint_curve_add(struct Main *bmain, const char *name);
 void BKE_paint_curve_free(struct PaintCurve *pc);
+void BKE_paint_curve_copy_data(
+        struct Main *bmain, struct PaintCurve *pc_dst, const struct PaintCurve *pc_src, const int flag);
 struct PaintCurve *BKE_paint_curve_copy(struct Main *bmain, const struct PaintCurve *pc);
 void               BKE_paint_curve_make_local(struct Main *bmain, struct PaintCurve *pc, const bool lib_local);
 
diff --git a/source/blender/blenkernel/intern/cachefile.c b/source/blender/blenkernel/intern/cachefile.c
index cf619a32783..2d9a1b762c1 100644
--- a/source/blender/blenkernel/intern/cachefile.c
+++ b/source/blender/blenkernel/intern/cachefile.c
@@ -100,16 +100,26 @@ void BKE_cachefile_free(CacheFile *cache_file)
 	BLI_freelistN(&cache_file->object_paths);
 }
 
-CacheFile *BKE_cachefile_copy(Main *bmain, const CacheFile *cache_file)
+/**
+ * Only copy internal data of CacheFile 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_cachefile_copy_data(
+        Main *UNUSED(bmain), CacheFile *cache_file_dst, const CacheFile *UNUSED(cache_file_src), const int UNUSED(flag))
 {
-	CacheFile *new_cache_file = BKE_libblock_copy(bmain, &cache_file->id);
-	new_cache_file->handle = NULL;
-
-	BLI_listbase_clear(&new_cache_file->object_paths);
-
-	BKE_id_copy_ensure_local(bmain, &cache_file->id, &new_cache_file->id);
+	cache_file_dst->handle = NULL;
+	BLI_listbase_clear(&cache_file_dst->object_paths);
+}
 
-	return new_cache_file;
+CacheFile *BKE_cachefile_copy(Main *bmain, const CacheFile *cache_file)
+{
+	CacheFile *cache_file_copy;
+	BKE_id_copy_ex(bmain, &cache_file->id, (ID **)&cache_file_copy, 0, false);
+	return cache_file_copy;
 }
 
 void BKE_cachefile_make_local(Main *bmain, CacheFile *cache_file, const bool lib_local)
diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c
index 6e8c41843b6..5ec7020080a 100644
--- a/source/blender/blenkernel/intern/library.c
+++ b/source/blender/blenkernel/intern/library.c
@@ -527,7 +527,7 @@ static int id_copy_libmanagement_cb(void *user_data, ID *id_self, ID **id_pointe
 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, ID_CA, ID_KE, ID_WO, ID_TXT
-#define ITEMS_IMPLEMENTED_2 ID_GR, ID_AR, ID_AC, ID_NT, ID_BR, ID_PA, ID_GD, ID_MC, ID_MSK, ID_LS
+#define ITEMS_IMPLEMENTED_2 ID_GR, ID_AR, ID_AC, ID_NT, ID_BR, ID_PA, ID_GD, ID_MC, ID_MSK, ID_LS, ID_PAL, ID_PC, ID_CF
 
 	if (!test) {
 		/* Check to be removed of course, just here until all BKE_xxx_copy_ex functions are done. */
@@ -610,13 +610,13 @@ bool BKE_id_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int flag, con
 			if (!test) BKE_linestyle_copy_data(bmain, (FreestyleLineStyle *)*r_newid, (FreestyleLineStyle *)id, flag);
 			break;
 		case ID_PAL:
-			if (!test) *r_newid = (ID *)BKE_palette_copy(bmain, (Palette *)id);
+			if (!test) BKE_palette_copy_data(bmain, (Palette *)*r_newid, (Palette *)id, flag);
 			break;
 		case ID_PC:
-			if (!test) *r_newid = (ID *)BKE_paint_curve_copy(bmain, (PaintCurve *)id);
+			if (!test) BKE_paint_curve_copy_data(bmain, (PaintCurve *)*r_newid, (PaintCurve *)id, flag);
 			break;
 		case ID_CF:
-			if (!test) *r_newid = (ID *)BKE_cachefile_copy(bmain, (CacheFile *)id);
+			if (!test) BKE_cachefile_copy_data(bmain, (CacheFile *)*r_newid, (CacheFile *)id, flag);
 			break;
 		case ID_SCE:
 		case ID_VF:
diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c
index c7cfe55f659..6bbcd535f27 100644
--- a/source/blender/blenkernel/intern/paint.c
+++ b/source/blender/blenkernel/intern/paint.c
@@ -314,19 +314,26 @@ PaintCurve *BKE_paint_curve_add(Main *bmain, const char *name)
 	return pc;
 }
 
-PaintCurve *BKE_paint_curve_copy(Main *bmain, const PaintCurve *pc)
+/**
+ * Only copy internal data of PaintCurve 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_paint_curve_copy_data(Main *UNUSED(bmain), PaintCurve *pc_dst, const PaintCurve *pc_src, const int UNUSED(flag))
 {
-	PaintCurve *pc_new;
-
-	pc_new = BKE_libblock_copy(bmain, &pc->id);
-
-	if (pc->tot_points != 0) {
-		pc_new->points = MEM_dupallocN(pc->points);
+	if (pc_src->tot_points != 0) {
+		pc_dst->points = MEM_dupallocN(pc_src->points);
 	}
+}
 
-	BKE_id_copy_ensure_local(bmain, &pc->id, &pc_new->id);
-
-	return pc_new;
+PaintCurve *BKE_paint_curve_copy(Main *bmain, const PaintCurve *pc)
+{
+	PaintCurve *pc_copy;
+	BKE_id_copy_ex(bmain, &pc->id, (ID **)&pc_copy, 0, false);
+	return pc_copy;
 }
 
 void BKE_paint_curve_make_local(Main *bmain, PaintCurve *pc, const bool lib_local)
@@ -396,17 +403,24 @@ Palette *BKE_palette_add(Main *bmain, const char *name)
 	return palette;
 }
 
-Palette *BKE_palette_copy(Main *bmain, const Palette *palette)
+/**
+ * Only copy internal data of Palette 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_palette_copy_data(Main *UNUSED(bmain), Palette *palette_dst, const Palette *palette_src, const int UNUSED(flag))
 {
-	Palette *palette_new;
-
-	palette_new = BKE_libblock_copy(bmain, &palette->id);
-
-	BLI_duplicatelist(&palette_new->colors, &palette->colors);
-
-	BKE_id_copy_ensure_local(bmain, &palette->id, &palette_new->id);
+	BLI_duplicatelist(&palette_dst->colors, &palette_src->colors);
+}
 
-	return palette_new;
+Palette *BKE_palette_copy(Main *bmain, const Palette *palette)
+{
+	Palette *palette_copy;
+	BKE_id_copy_ex(bmain, &palette->id, (ID **)&palette_copy, 0, false);
+	return palette_copy;
 }
 
 void BKE_palette_make_local(Main *bmain, Palette *palette, const bool lib_local)




More information about the Bf-blender-cvs mailing list