diff options
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_idtype.h | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/BKE_linestyle.h | 9 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/idtype.c | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/lib_id.c | 9 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/lib_id_delete.c | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/linestyle.c | 214 |
6 files changed, 124 insertions, 114 deletions
diff --git a/source/blender/blenkernel/BKE_idtype.h b/source/blender/blenkernel/BKE_idtype.h index bf205a7615f..4e715fe23ea 100644 --- a/source/blender/blenkernel/BKE_idtype.h +++ b/source/blender/blenkernel/BKE_idtype.h @@ -154,7 +154,7 @@ extern IDTypeInfo IDType_ID_PA; extern IDTypeInfo IDType_ID_WM; extern IDTypeInfo IDType_ID_MC; extern IDTypeInfo IDType_ID_MSK; -// extern IDTypeInfo IDType_ID_LS; +extern IDTypeInfo IDType_ID_LS; // extern IDTypeInfo IDType_ID_PAL; extern IDTypeInfo IDType_ID_PC; extern IDTypeInfo IDType_ID_CF; diff --git a/source/blender/blenkernel/BKE_linestyle.h b/source/blender/blenkernel/BKE_linestyle.h index 420f4b79e56..b086f244923 100644 --- a/source/blender/blenkernel/BKE_linestyle.h +++ b/source/blender/blenkernel/BKE_linestyle.h @@ -43,17 +43,8 @@ struct bContext; void BKE_linestyle_init(struct FreestyleLineStyle *linestyle); FreestyleLineStyle *BKE_linestyle_new(struct Main *bmain, const char *name); -void BKE_linestyle_free(FreestyleLineStyle *linestyle); -void BKE_linestyle_copy_data(struct Main *bmain, - struct FreestyleLineStyle *linestyle_dst, - const struct FreestyleLineStyle *linestyle_src, - const int flag); FreestyleLineStyle *BKE_linestyle_copy(struct Main *bmain, const FreestyleLineStyle *linestyle); -void BKE_linestyle_make_local(struct Main *bmain, - struct FreestyleLineStyle *linestyle, - const int flags); - FreestyleLineStyle *BKE_linestyle_active_from_view_layer(struct ViewLayer *view_layer); LineStyleModifier *BKE_linestyle_color_modifier_add(FreestyleLineStyle *linestyle, diff --git a/source/blender/blenkernel/intern/idtype.c b/source/blender/blenkernel/intern/idtype.c index 49bf948054e..6074ba85147 100644 --- a/source/blender/blenkernel/intern/idtype.c +++ b/source/blender/blenkernel/intern/idtype.c @@ -81,7 +81,7 @@ static void id_type_init(void) INIT_TYPE(ID_WM); INIT_TYPE(ID_MC); INIT_TYPE(ID_MSK); - // INIT_TYPE(ID_LS); + INIT_TYPE(ID_LS); // INIT_TYPE(ID_PAL); INIT_TYPE(ID_PC); INIT_TYPE(ID_CF); diff --git a/source/blender/blenkernel/intern/lib_id.c b/source/blender/blenkernel/intern/lib_id.c index 69f62e8e023..17e9adbfba6 100644 --- a/source/blender/blenkernel/intern/lib_id.c +++ b/source/blender/blenkernel/intern/lib_id.c @@ -547,9 +547,7 @@ bool BKE_lib_id_make_local(Main *bmain, ID *id, const bool test, const int flags BLI_assert(0); return true; case ID_LS: - if (!test) { - BKE_linestyle_make_local(bmain, (FreestyleLineStyle *)id, flags); - } + BLI_assert(0); return true; case ID_PAL: if (!test) { @@ -751,8 +749,7 @@ bool BKE_id_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int flag) BLI_assert(0); break; case ID_LS: - BKE_linestyle_copy_data( - bmain, (FreestyleLineStyle *)*r_newid, (FreestyleLineStyle *)id, flag); + BLI_assert(0); break; case ID_PAL: BKE_palette_copy_data(bmain, (Palette *)*r_newid, (Palette *)id, flag); @@ -1377,7 +1374,7 @@ void BKE_libblock_init_empty(ID *id) BLI_assert(0); break; case ID_LS: - BKE_linestyle_init((FreestyleLineStyle *)id); + BLI_assert(0); break; case ID_CF: BLI_assert(0); diff --git a/source/blender/blenkernel/intern/lib_id_delete.c b/source/blender/blenkernel/intern/lib_id_delete.c index 004eedb6164..241b7dab0b9 100644 --- a/source/blender/blenkernel/intern/lib_id_delete.c +++ b/source/blender/blenkernel/intern/lib_id_delete.c @@ -229,7 +229,7 @@ void BKE_libblock_free_datablock(ID *id, const int UNUSED(flag)) BLI_assert(0); break; case ID_LS: - BKE_linestyle_free((FreestyleLineStyle *)id); + BLI_assert(0); break; case ID_PAL: BKE_palette_free((Palette *)id); diff --git a/source/blender/blenkernel/intern/linestyle.c b/source/blender/blenkernel/intern/linestyle.c index c8f21c3f959..c309557e531 100644 --- a/source/blender/blenkernel/intern/linestyle.c +++ b/source/blender/blenkernel/intern/linestyle.c @@ -37,15 +37,132 @@ #include "BLI_string_utils.h" #include "BLI_utildefines.h" +#include "BLT_translation.h" + #include "BKE_colorband.h" #include "BKE_context.h" #include "BKE_freestyle.h" +#include "BKE_idtype.h" #include "BKE_lib_id.h" #include "BKE_linestyle.h" +#include "BKE_main.h" #include "BKE_node.h" #include "BKE_colortools.h" #include "BKE_animsys.h" +static void linestyle_init_data(ID *id) +{ + FreestyleLineStyle *linestyle = (FreestyleLineStyle *)id; + + BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(linestyle, id)); + + MEMCPY_STRUCT_AFTER(linestyle, DNA_struct_default_get(FreestyleLineStyle), id); + + BKE_linestyle_geometry_modifier_add(linestyle, NULL, LS_MODIFIER_SAMPLING); +} + +static void linestyle_copy_data(Main *bmain, ID *id_dst, const ID *id_src, const int flag) +{ + FreestyleLineStyle *linestyle_dst = (FreestyleLineStyle *)id_dst; + const FreestyleLineStyle *linestyle_src = (const FreestyleLineStyle *)id_src; + + /* We never handle usercount here for own data. */ + const int flag_subdata = flag | LIB_ID_CREATE_NO_USER_REFCOUNT; + /* We always need allocation of our private ID data. */ + const int flag_private_id_data = flag & ~LIB_ID_CREATE_NO_ALLOCATE; + + for (int a = 0; a < MAX_MTEX; a++) { + if (linestyle_src->mtex[a]) { + linestyle_dst->mtex[a] = MEM_mallocN(sizeof(*linestyle_dst->mtex[a]), __func__); + *linestyle_dst->mtex[a] = *linestyle_src->mtex[a]; + } + } + + if (linestyle_src->nodetree) { + BKE_id_copy_ex(bmain, + (ID *)linestyle_src->nodetree, + (ID **)&linestyle_dst->nodetree, + flag_private_id_data); + } + + LineStyleModifier *linestyle_modifier; + BLI_listbase_clear(&linestyle_dst->color_modifiers); + for (linestyle_modifier = (LineStyleModifier *)linestyle_src->color_modifiers.first; + linestyle_modifier; + linestyle_modifier = linestyle_modifier->next) { + BKE_linestyle_color_modifier_copy(linestyle_dst, linestyle_modifier, flag_subdata); + } + + BLI_listbase_clear(&linestyle_dst->alpha_modifiers); + for (linestyle_modifier = (LineStyleModifier *)linestyle_src->alpha_modifiers.first; + linestyle_modifier; + linestyle_modifier = linestyle_modifier->next) { + BKE_linestyle_alpha_modifier_copy(linestyle_dst, linestyle_modifier, flag_subdata); + } + + BLI_listbase_clear(&linestyle_dst->thickness_modifiers); + for (linestyle_modifier = (LineStyleModifier *)linestyle_src->thickness_modifiers.first; + linestyle_modifier; + linestyle_modifier = linestyle_modifier->next) { + BKE_linestyle_thickness_modifier_copy(linestyle_dst, linestyle_modifier, flag_subdata); + } + + BLI_listbase_clear(&linestyle_dst->geometry_modifiers); + for (linestyle_modifier = (LineStyleModifier *)linestyle_src->geometry_modifiers.first; + linestyle_modifier; + linestyle_modifier = linestyle_modifier->next) { + BKE_linestyle_geometry_modifier_copy(linestyle_dst, linestyle_modifier, flag_subdata); + } +} + +static void linestyle_free_data(ID *id) +{ + FreestyleLineStyle *linestyle = (FreestyleLineStyle *)id; + LineStyleModifier *linestyle_modifier; + + BKE_animdata_free(&linestyle->id, false); + + for (int material_slot_index = 0; material_slot_index < MAX_MTEX; material_slot_index++) { + MEM_SAFE_FREE(linestyle->mtex[material_slot_index]); + } + + /* is no lib link block, but linestyle extension */ + if (linestyle->nodetree) { + ntreeFreeNestedTree(linestyle->nodetree); + MEM_freeN(linestyle->nodetree); + linestyle->nodetree = NULL; + } + + while ((linestyle_modifier = (LineStyleModifier *)linestyle->color_modifiers.first)) { + BKE_linestyle_color_modifier_remove(linestyle, linestyle_modifier); + } + while ((linestyle_modifier = (LineStyleModifier *)linestyle->alpha_modifiers.first)) { + BKE_linestyle_alpha_modifier_remove(linestyle, linestyle_modifier); + } + while ((linestyle_modifier = (LineStyleModifier *)linestyle->thickness_modifiers.first)) { + BKE_linestyle_thickness_modifier_remove(linestyle, linestyle_modifier); + } + while ((linestyle_modifier = (LineStyleModifier *)linestyle->geometry_modifiers.first)) { + BKE_linestyle_geometry_modifier_remove(linestyle, linestyle_modifier); + } +} + +IDTypeInfo IDType_ID_LS = { + .id_code = ID_LS, + .id_filter = FILTER_ID_LS, + .main_listbase_index = INDEX_ID_LS, + .struct_size = sizeof(FreestyleLineStyle), + .name = "FreestyleLineStyle", + .name_plural = "linestyles", + .translation_context = BLT_I18NCONTEXT_ID_FREESTYLELINESTYLE, + .flags = 0, + + .init_data = linestyle_init_data, + .copy_data = linestyle_copy_data, + .free_data = linestyle_free_data, + .make_local = NULL, +}; + static const char *modifier_name[LS_MODIFIER_NUM] = { NULL, "Along Stroke", @@ -75,11 +192,7 @@ static const char *modifier_name[LS_MODIFIER_NUM] = { void BKE_linestyle_init(FreestyleLineStyle *linestyle) { - BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(linestyle, id)); - - MEMCPY_STRUCT_AFTER(linestyle, DNA_struct_default_get(FreestyleLineStyle), id); - - BKE_linestyle_geometry_modifier_add(linestyle, NULL, LS_MODIFIER_SAMPLING); + linestyle_init_data(&linestyle->id); } FreestyleLineStyle *BKE_linestyle_new(struct Main *bmain, const char *name) @@ -93,92 +206,6 @@ FreestyleLineStyle *BKE_linestyle_new(struct Main *bmain, const char *name) return linestyle; } -/** Free (or release) any data used by this linestyle (does not free the linestyle itself). */ -void BKE_linestyle_free(FreestyleLineStyle *linestyle) -{ - LineStyleModifier *m; - int a; - - BKE_animdata_free(&linestyle->id, false); - - for (a = 0; a < MAX_MTEX; a++) { - MEM_SAFE_FREE(linestyle->mtex[a]); - } - - /* is no lib link block, but linestyle extension */ - if (linestyle->nodetree) { - ntreeFreeNestedTree(linestyle->nodetree); - MEM_freeN(linestyle->nodetree); - linestyle->nodetree = NULL; - } - - while ((m = (LineStyleModifier *)linestyle->color_modifiers.first)) { - BKE_linestyle_color_modifier_remove(linestyle, m); - } - while ((m = (LineStyleModifier *)linestyle->alpha_modifiers.first)) { - BKE_linestyle_alpha_modifier_remove(linestyle, m); - } - while ((m = (LineStyleModifier *)linestyle->thickness_modifiers.first)) { - BKE_linestyle_thickness_modifier_remove(linestyle, m); - } - while ((m = (LineStyleModifier *)linestyle->geometry_modifiers.first)) { - BKE_linestyle_geometry_modifier_remove(linestyle, m); - } -} - -/** - * Only copy internal data of Linestyle 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_linestyle_copy_data(struct Main *bmain, - FreestyleLineStyle *linestyle_dst, - const FreestyleLineStyle *linestyle_src, - const int flag) -{ - /* We never handle usercount here for own data. */ - const int flag_subdata = flag | LIB_ID_CREATE_NO_USER_REFCOUNT; - /* We always need allocation of our private ID data. */ - const int flag_private_id_data = flag & ~LIB_ID_CREATE_NO_ALLOCATE; - - for (int a = 0; a < MAX_MTEX; a++) { - if (linestyle_src->mtex[a]) { - linestyle_dst->mtex[a] = MEM_mallocN(sizeof(*linestyle_dst->mtex[a]), __func__); - *linestyle_dst->mtex[a] = *linestyle_src->mtex[a]; - } - } - - if (linestyle_src->nodetree) { - BKE_id_copy_ex(bmain, - (ID *)linestyle_src->nodetree, - (ID **)&linestyle_dst->nodetree, - flag_private_id_data); - } - - LineStyleModifier *m; - BLI_listbase_clear(&linestyle_dst->color_modifiers); - for (m = (LineStyleModifier *)linestyle_src->color_modifiers.first; m; m = m->next) { - BKE_linestyle_color_modifier_copy(linestyle_dst, m, flag_subdata); - } - BLI_listbase_clear(&linestyle_dst->alpha_modifiers); - for (m = (LineStyleModifier *)linestyle_src->alpha_modifiers.first; m; m = m->next) { - BKE_linestyle_alpha_modifier_copy(linestyle_dst, m, flag_subdata); - } - BLI_listbase_clear(&linestyle_dst->thickness_modifiers); - for (m = (LineStyleModifier *)linestyle_src->thickness_modifiers.first; m; m = m->next) { - BKE_linestyle_thickness_modifier_copy(linestyle_dst, m, flag_subdata); - } - BLI_listbase_clear(&linestyle_dst->geometry_modifiers); - for (m = (LineStyleModifier *)linestyle_src->geometry_modifiers.first; m; m = m->next) { - BKE_linestyle_geometry_modifier_copy(linestyle_dst, m, flag_subdata); - } -} - FreestyleLineStyle *BKE_linestyle_copy(struct Main *bmain, const FreestyleLineStyle *linestyle) { FreestyleLineStyle *linestyle_copy; @@ -186,11 +213,6 @@ FreestyleLineStyle *BKE_linestyle_copy(struct Main *bmain, const FreestyleLineSt return linestyle_copy; } -void BKE_linestyle_make_local(struct Main *bmain, FreestyleLineStyle *linestyle, const int flags) -{ - BKE_lib_id_make_local_generic(bmain, &linestyle->id, flags); -} - FreestyleLineStyle *BKE_linestyle_active_from_view_layer(ViewLayer *view_layer) { FreestyleConfig *config = &view_layer->freestyle_config; |