diff options
Diffstat (limited to 'source/blender/blenkernel/intern')
-rw-r--r-- | source/blender/blenkernel/intern/gpencil.c | 85 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/idtype.c | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/lib_id.c | 8 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/lib_id_delete.c | 2 |
4 files changed, 55 insertions, 42 deletions
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c index 0b33eaccb6f..e2f28355ff3 100644 --- a/source/blender/blenkernel/intern/gpencil.c +++ b/source/blender/blenkernel/intern/gpencil.c @@ -59,6 +59,7 @@ #include "BKE_deform.h" #include "BKE_gpencil.h" #include "BKE_icons.h" +#include "BKE_idtype.h" #include "BKE_image.h" #include "BKE_lib_id.h" #include "BKE_main.h" @@ -73,6 +74,54 @@ static CLG_LogRef LOG = {"bke.gpencil"}; +static void greasepencil_copy_data(Main *UNUSED(bmain), + ID *id_dst, + const ID *id_src, + const int UNUSED(flag)) +{ + bGPdata *gpd_dst = (bGPdata *)id_dst; + const bGPdata *gpd_src = (const bGPdata *)id_src; + + /* duplicate material array */ + if (gpd_src->mat) { + gpd_dst->mat = MEM_dupallocN(gpd_src->mat); + } + + /* copy layers */ + BLI_listbase_clear(&gpd_dst->layers); + LISTBASE_FOREACH (bGPDlayer *, gpl_src, &gpd_src->layers) { + /* make a copy of source layer and its data */ + + /* TODO here too could add unused flags... */ + bGPDlayer *gpl_dst = BKE_gpencil_layer_duplicate(gpl_src); + + BLI_addtail(&gpd_dst->layers, gpl_dst); + } +} + +static void greasepencil_free_data(ID *id) +{ + /* Really not ideal, but for now will do... In theory custom behaviors like not freeing cache + * should be handled through specific API, and not be part of the generic one. */ + BKE_gpencil_free((bGPdata *)id, true); +} + +IDTypeInfo IDType_ID_GD = { + .id_code = ID_GD, + .id_filter = FILTER_ID_GD, + .main_listbase_index = INDEX_ID_GD, + .struct_size = sizeof(bGPdata), + .name = "GPencil", + .name_plural = "grease_pencils", + .translation_context = BLT_I18NCONTEXT_ID_GPENCIL, + .flags = 0, + + .init_data = NULL, + .copy_data = greasepencil_copy_data, + .free_data = greasepencil_free_data, + .make_local = NULL, +}; + /* ************************************************** */ /* Draw Engine */ @@ -671,35 +720,6 @@ bGPDlayer *BKE_gpencil_layer_duplicate(const bGPDlayer *gpl_src) return gpl_dst; } -/** - * Only copy internal data of GreasePencil ID from source - * to already allocated/initialized destination. - * You probably never want to use that directly, - * use #BKE_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_lib_id.h's LIB_ID_COPY_... flags for more). - */ -void BKE_gpencil_copy_data(bGPdata *gpd_dst, const bGPdata *gpd_src, const int UNUSED(flag)) -{ - /* duplicate material array */ - if (gpd_src->mat) { - gpd_dst->mat = MEM_dupallocN(gpd_src->mat); - } - - /* copy layers */ - BLI_listbase_clear(&gpd_dst->layers); - LISTBASE_FOREACH (bGPDlayer *, gpl_src, &gpd_src->layers) { - /* make a copy of source layer and its data */ - - /* TODO here too could add unused flags... */ - bGPDlayer *gpl_dst = BKE_gpencil_layer_duplicate(gpl_src); - - BLI_addtail(&gpd_dst->layers, gpl_dst); - } -} - /* Standard API to make a copy of GP datablock, separate from copying its data */ bGPdata *BKE_gpencil_copy(Main *bmain, const bGPdata *gpd) { @@ -733,17 +753,12 @@ bGPdata *BKE_gpencil_data_duplicate(Main *bmain, const bGPdata *gpd_src, bool in } /* Copy internal data (layers, etc.) */ - BKE_gpencil_copy_data(gpd_dst, gpd_src, 0); + greasepencil_copy_data(bmain, &gpd_dst->id, &gpd_src->id, 0); /* return new */ return gpd_dst; } -void BKE_gpencil_make_local(Main *bmain, bGPdata *gpd, const int flags) -{ - BKE_lib_id_make_local_generic(bmain, &gpd->id, flags); -} - /* ************************************************** */ /* GP Stroke API */ diff --git a/source/blender/blenkernel/intern/idtype.c b/source/blender/blenkernel/intern/idtype.c index 6fbce96c870..bf2b949eccf 100644 --- a/source/blender/blenkernel/intern/idtype.c +++ b/source/blender/blenkernel/intern/idtype.c @@ -77,7 +77,7 @@ static void id_type_init(void) INIT_TYPE(ID_NT); INIT_TYPE(ID_BR); INIT_TYPE(ID_PA); - // INIT_TYPE(ID_GD); + INIT_TYPE(ID_GD); INIT_TYPE(ID_WM); INIT_TYPE(ID_MC); INIT_TYPE(ID_MSK); diff --git a/source/blender/blenkernel/intern/lib_id.c b/source/blender/blenkernel/intern/lib_id.c index 17e9adbfba6..abd12d1f606 100644 --- a/source/blender/blenkernel/intern/lib_id.c +++ b/source/blender/blenkernel/intern/lib_id.c @@ -536,9 +536,7 @@ bool BKE_lib_id_make_local(Main *bmain, ID *id, const bool test, const int flags BLI_assert(0); return true; case ID_GD: - if (!test) { - BKE_gpencil_make_local(bmain, (bGPdata *)id, flags); - } + BLI_assert(0); return true; case ID_MC: BLI_assert(0); @@ -740,7 +738,7 @@ bool BKE_id_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int flag) BLI_assert(0); break; case ID_GD: - BKE_gpencil_copy_data((bGPdata *)*r_newid, (bGPdata *)id, flag); + BLI_assert(0); break; case ID_MC: BLI_assert(0); @@ -1368,7 +1366,7 @@ void BKE_libblock_init_empty(ID *id) BLI_assert(0); break; case ID_GD: - /* Nothing to do. */ + BLI_assert(0); break; case ID_MSK: BLI_assert(0); diff --git a/source/blender/blenkernel/intern/lib_id_delete.c b/source/blender/blenkernel/intern/lib_id_delete.c index fb89aab75fb..e743f29eeda 100644 --- a/source/blender/blenkernel/intern/lib_id_delete.c +++ b/source/blender/blenkernel/intern/lib_id_delete.c @@ -220,7 +220,7 @@ void BKE_libblock_free_datablock(ID *id, const int UNUSED(flag)) BLI_assert(0); break; case ID_GD: - BKE_gpencil_free((bGPdata *)id, true); + BLI_assert(0); break; case ID_MC: BLI_assert(0); |