diff options
author | Lukas Tönne <lukas.toenne@gmail.com> | 2016-08-09 17:37:15 +0300 |
---|---|---|
committer | Lukas Tönne <lukas.toenne@gmail.com> | 2016-08-09 17:37:15 +0300 |
commit | 4a801f6c6f0421ffd515c12422dd197441440520 (patch) | |
tree | 5415e844b460bb2aa07b9467c72e13abc2e61228 /source/blender/blenkernel/intern/library.c | |
parent | 49c63d46db8c055152d9e431e89405f9b51a4bbe (diff) | |
parent | 02719521d2e25abcc8ffcccc086d3a651986f52f (diff) |
Merge branch 'master' into object_nodesobject_nodes
Diffstat (limited to 'source/blender/blenkernel/intern/library.c')
-rw-r--r-- | source/blender/blenkernel/intern/library.c | 230 |
1 files changed, 139 insertions, 91 deletions
diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c index c31df685136..6d94cd28b31 100644 --- a/source/blender/blenkernel/intern/library.c +++ b/source/blender/blenkernel/intern/library.c @@ -45,6 +45,7 @@ #include "DNA_anim_types.h" #include "DNA_armature_types.h" #include "DNA_brush_types.h" +#include "DNA_cachefile_types.h" #include "DNA_camera_types.h" #include "DNA_group_types.h" #include "DNA_gpencil_types.h" @@ -56,6 +57,7 @@ #include "DNA_material_types.h" #include "DNA_mesh_types.h" #include "DNA_meta_types.h" +#include "DNA_modifier_types.h" #include "DNA_movieclip_types.h" #include "DNA_mask_types.h" #include "DNA_node_types.h" @@ -81,6 +83,7 @@ #include "BKE_bpath.h" #include "BKE_brush.h" #include "BKE_camera.h" +#include "BKE_cachefile.h" #include "BKE_context.h" #include "BKE_curve.h" #include "BKE_depsgraph.h" @@ -103,8 +106,10 @@ #include "BKE_main.h" #include "BKE_mball.h" #include "BKE_mask.h" +#include "BKE_movieclip.h" #include "BKE_node.h" #include "BKE_object.h" +#include "BKE_paint.h" #include "BKE_particle.h" #include "BKE_packedFile.h" #include "BKE_sound.h" @@ -272,6 +277,17 @@ void BKE_id_expand_local(ID *id) } /** + * Ensure new (copied) ID is fully made local. + */ +void BKE_id_copy_ensure_local(Main *bmain, ID *old_id, ID *new_id) +{ + if (ID_IS_LINKED_DATABLOCK(old_id)) { + BKE_id_expand_local(new_id); + BKE_id_lib_local_paths(bmain, old_id->lib, new_id); + } +} + +/** * Generic 'make local' function, works for most of datablock types... */ void BKE_id_make_local_generic(Main *bmain, ID *id, const bool id_in_mainlist, const bool lib_local) @@ -308,7 +324,6 @@ void BKE_id_make_local_generic(Main *bmain, ID *id, const bool id_in_mainlist, c } } } - } /** @@ -320,16 +335,16 @@ void BKE_id_make_local_generic(Main *bmain, ID *id, const bool id_in_mainlist, c */ bool id_make_local(Main *bmain, ID *id, const bool test, const bool lib_local) { - if (id->tag & LIB_TAG_INDIRECT) + /* We don't care whether ID is directly or indirectly linked in case we are making a whole lib local... */ + if (!lib_local && (id->tag & LIB_TAG_INDIRECT)) { return false; + } - switch (GS(id->name)) { + switch ((ID_Type)GS(id->name)) { case ID_SCE: /* Partially implemented (has no copy...). */ if (!test) BKE_scene_make_local(bmain, (Scene *)id, lib_local); return true; - case ID_LI: - return false; /* can't be linked */ case ID_OB: if (!test) BKE_object_make_local(bmain, (Object *)id, lib_local); return true; @@ -363,15 +378,9 @@ bool id_make_local(Main *bmain, ID *id, const bool test, const bool lib_local) case ID_SPK: if (!test) BKE_speaker_make_local(bmain, (Speaker *)id, lib_local); return true; - case ID_IP: - return false; /* deprecated */ - case ID_KE: - return false; /* can't be linked */ case ID_WO: if (!test) BKE_world_make_local(bmain, (World *)id, lib_local); return true; - case ID_SCR: - return false; /* can't be linked */ case ID_VF: /* Partially implemented (has no copy...). */ if (!test) BKE_vfont_make_local(bmain, (VFont *)id, lib_local); @@ -401,17 +410,34 @@ bool id_make_local(Main *bmain, ID *id, const bool test, const bool lib_local) case ID_PA: if (!test) BKE_particlesettings_make_local(bmain, (ParticleSettings *)id, lib_local); return true; - case ID_WM: - return false; /* can't be linked */ case ID_GD: if (!test) BKE_gpencil_make_local(bmain, (bGPdata *)id, lib_local); return true; + case ID_MC: + if (!test) BKE_movieclip_make_local(bmain, (MovieClip *)id, lib_local); + return true; case ID_MSK: if (!test) BKE_mask_make_local(bmain, (Mask *)id, lib_local); return true; case ID_LS: if (!test) BKE_linestyle_make_local(bmain, (FreestyleLineStyle *)id, lib_local); return true; + case ID_PAL: + if (!test) BKE_palette_make_local(bmain, (Palette *)id, lib_local); + return true; + case ID_PC: + if (!test) BKE_paint_curve_make_local(bmain, (PaintCurve *)id, lib_local); + return true; + case ID_CF: + if (!test) BKE_cachefile_make_local(bmain, (CacheFile *)id, lib_local); + return true; + case ID_SCR: + case ID_LI: + case ID_KE: + case ID_WM: + return false; /* can't be linked */ + case ID_IP: + return false; /* deprecated */ } return false; @@ -430,11 +456,7 @@ bool id_copy(Main *bmain, ID *id, ID **newid, bool test) /* conventions: * - make shallow copy, only this ID block * - id.us of the new ID is set to 1 */ - switch (GS(id->name)) { - case ID_SCE: - return false; /* can't be copied from here */ - case ID_LI: - return false; /* can't be copied from here */ + switch ((ID_Type)GS(id->name)) { case ID_OB: if (!test) *newid = (ID *)BKE_object_copy(bmain, (Object *)id); return true; @@ -468,23 +490,15 @@ bool id_copy(Main *bmain, ID *id, ID **newid, bool test) case ID_CA: if (!test) *newid = (ID *)BKE_camera_copy(bmain, (Camera *)id); return true; - case ID_IP: - return false; /* deprecated */ case ID_KE: if (!test) *newid = (ID *)BKE_key_copy(bmain, (Key *)id); return true; case ID_WO: if (!test) *newid = (ID *)BKE_world_copy(bmain, (World *)id); return true; - case ID_SCR: - return false; /* can't be copied from here */ - case ID_VF: - return false; /* not implemented */ case ID_TXT: if (!test) *newid = (ID *)BKE_text_copy(bmain, (Text *)id); return true; - case ID_SO: - return false; /* not implemented */ case ID_GR: if (!test) *newid = (ID *)BKE_group_copy(bmain, (Group *)id); return true; @@ -503,10 +517,11 @@ bool id_copy(Main *bmain, ID *id, ID **newid, bool test) case ID_PA: if (!test) *newid = (ID *)BKE_particlesettings_copy(bmain, (ParticleSettings *)id); return true; - case ID_WM: - return false; /* can't be copied from here */ case ID_GD: - if (!test) *newid = (ID *)gpencil_data_duplicate(bmain, (bGPdata *)id, false); + if (!test) *newid = (ID *)BKE_gpencil_data_duplicate(bmain, (bGPdata *)id, false); + return true; + case ID_MC: + if (!test) *newid = (ID *)BKE_movieclip_copy(bmain, (MovieClip *)id); return true; case ID_MSK: if (!test) *newid = (ID *)BKE_mask_copy(bmain, (Mask *)id); @@ -514,6 +529,25 @@ bool id_copy(Main *bmain, ID *id, ID **newid, bool test) case ID_LS: if (!test) *newid = (ID *)BKE_linestyle_copy(bmain, (FreestyleLineStyle *)id); return true; + case ID_PAL: + if (!test) *newid = (ID *)BKE_palette_copy(bmain, (Palette *)id); + return true; + case ID_PC: + if (!test) *newid = (ID *)BKE_paint_curve_copy(bmain, (PaintCurve *)id); + return true; + case ID_CF: + if (!test) *newid = (ID *)BKE_cachefile_copy(bmain, (CacheFile *)id); + return true; + case ID_SCE: + case ID_LI: + case ID_SCR: + case ID_WM: + return false; /* can't be copied from here */ + case ID_VF: + case ID_SO: + return false; /* not implemented */ + case ID_IP: + return false; /* deprecated */ } return false; @@ -549,7 +583,7 @@ bool id_single_user(bContext *C, ID *id, PointerRNA *ptr, PropertyRNA *prop) ListBase *which_libbase(Main *mainlib, short type) { - switch (type) { + switch ((ID_Type)type) { case ID_SCE: return &(mainlib->scene); case ID_LI: @@ -616,6 +650,8 @@ ListBase *which_libbase(Main *mainlib, short type) return &(mainlib->palettes); case ID_PC: return &(mainlib->paintcurves); + case ID_CF: + return &(mainlib->cachefiles); } return NULL; } @@ -717,59 +753,56 @@ void BKE_main_lib_objects_recalc_all(Main *bmain) * \note MAX_LIBARRAY define should match this code */ int set_listbasepointers(Main *main, ListBase **lb) { - int a = 0; - /* BACKWARDS! also watch order of free-ing! (mesh<->mat), first items freed last. * This is important because freeing data decreases usercounts of other datablocks, * if this data is its self freed it can crash. */ - lb[a++] = &(main->library); /* Libraries may be accessed from pretty much any other ID... */ - lb[a++] = &(main->ipo); - lb[a++] = &(main->action); /* moved here to avoid problems when freeing with animato (aligorith) */ - lb[a++] = &(main->key); - lb[a++] = &(main->gpencil); /* referenced by nodes, objects, view, scene etc, before to free after. */ - lb[a++] = &(main->nodetree); - lb[a++] = &(main->image); - lb[a++] = &(main->tex); - lb[a++] = &(main->mat); - lb[a++] = &(main->vfont); + lb[INDEX_ID_LI] = &(main->library); /* Libraries may be accessed from pretty much any other ID... */ + lb[INDEX_ID_IP] = &(main->ipo); + lb[INDEX_ID_AC] = &(main->action); /* moved here to avoid problems when freeing with animato (aligorith) */ + lb[INDEX_ID_KE] = &(main->key); + lb[INDEX_ID_GD] = &(main->gpencil); /* referenced by nodes, objects, view, scene etc, before to free after. */ + lb[INDEX_ID_NT] = &(main->nodetree); + lb[INDEX_ID_IM] = &(main->image); + lb[INDEX_ID_TE] = &(main->tex); + lb[INDEX_ID_MA] = &(main->mat); + lb[INDEX_ID_VF] = &(main->vfont); /* Important!: When adding a new object type, * the specific data should be inserted here */ - lb[a++] = &(main->armature); - - lb[a++] = &(main->mesh); - lb[a++] = &(main->curve); - lb[a++] = &(main->mball); - - lb[a++] = &(main->latt); - lb[a++] = &(main->lamp); - lb[a++] = &(main->camera); - - lb[a++] = &(main->text); - lb[a++] = &(main->sound); - lb[a++] = &(main->group); - lb[a++] = &(main->palettes); - lb[a++] = &(main->paintcurves); - lb[a++] = &(main->brush); - lb[a++] = &(main->particle); - lb[a++] = &(main->speaker); - - lb[a++] = &(main->world); - lb[a++] = &(main->movieclip); - lb[a++] = &(main->screen); - lb[a++] = &(main->object); - lb[a++] = &(main->linestyle); /* referenced by scenes */ - lb[a++] = &(main->scene); - lb[a++] = &(main->wm); - lb[a++] = &(main->mask); + lb[INDEX_ID_AR] = &(main->armature); + + lb[INDEX_ID_CF] = &(main->cachefiles); + lb[INDEX_ID_ME] = &(main->mesh); + lb[INDEX_ID_CU] = &(main->curve); + lb[INDEX_ID_MB] = &(main->mball); + + lb[INDEX_ID_LT] = &(main->latt); + lb[INDEX_ID_LA] = &(main->lamp); + lb[INDEX_ID_CA] = &(main->camera); + + lb[INDEX_ID_TXT] = &(main->text); + lb[INDEX_ID_SO] = &(main->sound); + lb[INDEX_ID_GR] = &(main->group); + lb[INDEX_ID_PAL] = &(main->palettes); + lb[INDEX_ID_PC] = &(main->paintcurves); + lb[INDEX_ID_BR] = &(main->brush); + lb[INDEX_ID_PA] = &(main->particle); + lb[INDEX_ID_SPK] = &(main->speaker); + + lb[INDEX_ID_WO] = &(main->world); + lb[INDEX_ID_MC] = &(main->movieclip); + lb[INDEX_ID_SCR] = &(main->screen); + lb[INDEX_ID_OB] = &(main->object); + lb[INDEX_ID_LS] = &(main->linestyle); /* referenced by scenes */ + lb[INDEX_ID_SCE] = &(main->scene); + lb[INDEX_ID_WM] = &(main->wm); + lb[INDEX_ID_MSK] = &(main->mask); - lb[a] = NULL; - - BLI_assert(a + 1 == MAX_LIBARRAY); + lb[INDEX_ID_NULL] = NULL; - return a; + return (MAX_LIBARRAY - 1); } /* *********** ALLOC AND FREE ***************** @@ -790,7 +823,7 @@ void *BKE_libblock_alloc_notest(short type) { ID *id = NULL; - switch (type) { + switch ((ID_Type)type) { case ID_SCE: id = MEM_callocN(sizeof(Scene), "scene"); break; @@ -890,6 +923,9 @@ void *BKE_libblock_alloc_notest(short type) case ID_PC: id = MEM_callocN(sizeof(PaintCurve), "Paint Curve"); break; + case ID_CF: + id = MEM_callocN(sizeof(CacheFile), "Cache File"); + break; } return id; } @@ -927,7 +963,7 @@ void *BKE_libblock_alloc(Main *bmain, short type, const char *name) void BKE_libblock_init_empty(ID *id) { /* Note that only ID types that are not valid when filled of zero should have a callback here. */ - switch (GS(id->name)) { + switch ((ID_Type)GS(id->name)) { case ID_SCE: BKE_scene_init((Scene *)id); break; @@ -971,15 +1007,6 @@ void BKE_libblock_init_empty(ID *id) case ID_CA: BKE_camera_init((Camera *)id); break; - case ID_IP: - /* Should not be needed - animation from lib pre-2.5 is broken anyway. */ - BLI_assert(0); - break; - case ID_KE: - /* Shapekeys are a complex topic too - they depend on their 'user' data type... - * They are not linkable, though, so it should never reach here anyway. */ - BLI_assert(0); - break; case ID_WO: BKE_world_init((World *)id); break; @@ -1016,10 +1043,6 @@ void BKE_libblock_init_empty(ID *id) case ID_PC: /* Nothing to do. */ break; - case ID_WM: - /* We should never reach this. */ - BLI_assert(0); - break; case ID_GD: /* Nothing to do. */ break; @@ -1029,6 +1052,24 @@ void BKE_libblock_init_empty(ID *id) case ID_LS: BKE_linestyle_init((FreestyleLineStyle *)id); break; + case ID_CF: + BKE_cachefile_init((CacheFile *)id); + break; + case ID_KE: + /* Shapekeys are a complex topic too - they depend on their 'user' data type... + * They are not linkable, though, so it should never reach here anyway. */ + BLI_assert(0); + break; + case ID_WM: + /* We should never reach this. */ + BLI_assert(0); + break; + case ID_IP: + /* Should not be needed - animation from lib pre-2.5 is broken anyway. */ + BLI_assert(0); + break; + default: + BLI_assert(0); /* Should never reach this point... */ } } @@ -1201,6 +1242,7 @@ void BKE_main_free(Main *mainvar) case 31: BKE_libblock_free_ex(mainvar, id, false); break; case 32: BKE_libblock_free_ex(mainvar, id, false); break; case 33: BKE_libblock_free_ex(mainvar, id, false); break; + case 34: BKE_libblock_free_ex(mainvar, id, false); break; default: BLI_assert(0); break; @@ -1612,16 +1654,22 @@ void BKE_library_make_local(Main *bmain, const Library *lib, const bool untagged int a; for (a = set_listbasepointers(bmain, lbarray); a--; ) { - for (id = lbarray[a]->first; id; id = id_next) { + id = lbarray[a]->first; + + /* Do not explicitly make local non-linkable IDs (shapekeys, in fact), they are assumed to be handled + * by real datablocks responsible of them. */ + const bool do_skip = (id && !BKE_idcode_is_linkable(GS(id->name))); + + for (; id; id = id_next) { id->newid = NULL; id_next = id->next; /* id is possibly being inserted again */ - + /* The check on the second line (LIB_TAG_PRE_EXISTING) is done so its * possible to tag data you don't want to be made local, used for * appending data, so any libdata already linked wont become local * (very nasty to discover all your links are lost after appending) * */ - if (id->tag & (LIB_TAG_EXTERN | LIB_TAG_INDIRECT | LIB_TAG_NEW) && + if (!do_skip && id->tag & (LIB_TAG_EXTERN | LIB_TAG_INDIRECT | LIB_TAG_NEW) && ((untagged_only == false) || !(id->tag & LIB_TAG_PRE_EXISTING))) { if (lib == NULL || id->lib == lib) { |