Merge branch 'master' into blender2.8
[blender.git] / source / blender / blenkernel / intern / library.c
index faa28f71cfddb939f482f24405931045c5af5a91..978f1acefbaf5c730987da3f7afc5f54ef323519 100644 (file)
 #include "BKE_mask.h"
 #include "BKE_node.h"
 #include "BKE_object.h"
-#include "BKE_particle.h"
 #include "BKE_packedFile.h"
 #include "BKE_speaker.h"
 #include "BKE_scene.h"
@@ -251,6 +250,24 @@ void id_fake_user_clear(ID *id)
        }
 }
 
+static int id_expand_local_callback(
+        void *UNUSED(user_data), struct ID *UNUSED(id_self), struct ID **id_pointer, int UNUSED(cd_flag))
+{
+       if (*id_pointer) {
+               id_lib_extern(*id_pointer);
+       }
+
+       return IDWALK_RET_NOP;
+}
+
+/**
+ * Expand ID usages of given id as 'extern' (and no more indirect) linked data. Used by ID copy/make_local functions.
+ */
+void BKE_id_expand_local(ID *id)
+{
+       BKE_library_foreach_ID_link(id, id_expand_local_callback, NULL, 0);
+}
+
 /* calls the appropriate make_local method for the block, unless test. Returns true
  * if the block can be made local. */
 bool id_make_local(Main *bmain, ID *id, bool test)
@@ -282,7 +299,7 @@ bool id_make_local(Main *bmain, ID *id, bool test)
                        if (!test) BKE_texture_make_local(bmain, (Tex *)id);
                        return true;
                case ID_IM:
-                       if (!test) BKE_image_make_local((Image *)id);
+                       if (!test) BKE_image_make_local(bmain, (Image *)id);
                        return true;
                case ID_LT:
                        if (!test) BKE_lattice_make_local(bmain, (Lattice *)id);
@@ -318,17 +335,14 @@ bool id_make_local(Main *bmain, ID *id, bool test)
                        if (!test) BKE_armature_make_local(bmain, (bArmature *)id);
                        return true;
                case ID_AC:
-                       if (!test) BKE_action_make_local((bAction *)id);
+                       if (!test) BKE_action_make_local(bmain, (bAction *)id);
                        return true;
                case ID_NT:
-                       if (!test) ntreeMakeLocal((bNodeTree *)id, true);
+                       if (!test) ntreeMakeLocal(bmain, (bNodeTree *)id, true);
                        return true;
                case ID_BR:
                        if (!test) BKE_brush_make_local(bmain, (Brush *)id);
                        return true;
-               case ID_PA:
-                       if (!test) BKE_particlesettings_make_local(bmain, (ParticleSettings *)id);
-                       return true;
                case ID_WM:
                        return false; /* can't be linked */
                case ID_GD:
@@ -423,9 +437,6 @@ bool id_copy(Main *bmain, ID *id, ID **newid, bool test)
                case ID_BR:
                        if (!test) *newid = (ID *)BKE_brush_copy(bmain, (Brush *)id);
                        return true;
-               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:
@@ -523,8 +534,6 @@ ListBase *which_libbase(Main *mainlib, short type)
                        return &(mainlib->nodetree);
                case ID_BR:
                        return &(mainlib->brush);
-               case ID_PA:
-                       return &(mainlib->particle);
                case ID_WM:
                        return &(mainlib->wm);
                case ID_GD:
@@ -676,7 +685,6 @@ int set_listbasepointers(Main *main, ListBase **lb)
        lb[a++] = &(main->palettes);
        lb[a++] = &(main->paintcurves);
        lb[a++] = &(main->brush);
-       lb[a++] = &(main->particle);
        lb[a++] = &(main->speaker);
 
        lb[a++] = &(main->world);
@@ -789,9 +797,6 @@ void *BKE_libblock_alloc_notest(short type)
                case ID_BR:
                        id = MEM_callocN(sizeof(Brush), "brush");
                        break;
-               case ID_PA:
-                       id = MEM_callocN(sizeof(ParticleSettings), "ParticleSettings");
-                       break;
                case ID_WM:
                        id = MEM_callocN(sizeof(wmWindowManager), "Window manager");
                        break;
@@ -933,9 +938,6 @@ void BKE_libblock_init_empty(ID *id)
                case ID_BR:
                        BKE_brush_init((Brush *)id);
                        break;
-               case ID_PA:
-                       /* Nothing to do. */
-                       break;
                case ID_PC:
                        /* Nothing to do. */
                        break;
@@ -1469,7 +1471,7 @@ void id_clear_lib_data_ex(Main *bmain, ID *id, bool id_in_mainlist)
        ntree = ntreeFromID(id);
 
        if (ntree) {
-               ntreeMakeLocal(ntree, false);
+               ntreeMakeLocal(bmain, ntree, false);
        }
 
        if (GS(id->name) == ID_OB) {