[Bf-blender-cvs] [5e0ec49] master: Fix T48416: Impossible to append from another file without localizing also all indirectly linked data.

Bastien Montagne noreply at git.blender.org
Fri May 13 14:12:41 CEST 2016


Commit: 5e0ec49570fa745c28bd028cb7796733a1d9dfce
Author: Bastien Montagne
Date:   Fri May 13 12:54:09 2016 +0200
Branches: master
https://developer.blender.org/rB5e0ec49570fa745c28bd028cb7796733a1d9dfce

Fix T48416: Impossible to append from another file without localizing also all indirectly linked data.

Previous to 2.77, this used to be default behavior, was changed in rB591f4549c958b.

However, in most append cases, you do want a full localization of your data, so this new behavior
is kept by default, but there is now an option in append operator to only localize the 'first level'
of data (i.e. datablocks from linked library itself, and not those from other 'sub-libraries').

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

M	source/blender/blenkernel/BKE_library.h
M	source/blender/blenkernel/intern/library.c
M	source/blender/windowmanager/intern/wm_files_link.c

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

diff --git a/source/blender/blenkernel/BKE_library.h b/source/blender/blenkernel/BKE_library.h
index 21585a1..2215fbf 100644
--- a/source/blender/blenkernel/BKE_library.h
+++ b/source/blender/blenkernel/BKE_library.h
@@ -119,7 +119,8 @@ void BKE_main_lib_objects_recalc_all(struct Main *bmain);
 /* (MAX_ID_NAME - 2) + 3 */
 void BKE_id_ui_prefix(char name[66 + 1], const struct ID *id);
 
-void BKE_library_make_local(struct Main *bmain, struct Library *lib, bool untagged_only, bool set_fake);
+void BKE_library_make_local(
+        struct Main *bmain, const struct Library *lib, const bool untagged_only, const bool set_fake);
 
 typedef void (*BKE_library_free_window_manager_cb)(struct bContext *, struct wmWindowManager *);
 typedef void (*BKE_library_free_notifier_reference_cb)(const void *);
diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c
index 9e81cde..0a681a7 100644
--- a/source/blender/blenkernel/intern/library.c
+++ b/source/blender/blenkernel/intern/library.c
@@ -1830,9 +1830,14 @@ static void lib_indirect_test_id(ID *id, Library *lib)
 #undef LIBTAG
 }
 
-/* if lib!=NULL, only all from lib local
- * bmain is almost certainly G.main */
-void BKE_library_make_local(Main *bmain, Library *lib, bool untagged_only, bool set_fake)
+/** Make linked datablocks local.
+ *
+ * \param bmain Almost certainly G.main.
+ * \param lib If not NULL, only make local datablocks from this library.
+ * \param untagged_only If true, only make local datablocks not tagged with LIB_TAG_PRE_EXISTING.
+ * \param set_fake If true, set fake user on all localized datablocks (except group and objects ones).
+ */
+void BKE_library_make_local(Main *bmain, const Library *lib, const bool untagged_only, const bool set_fake)
 {
 	ListBase *lbarray[MAX_LIBARRAY];
 	ID *id, *idn;
diff --git a/source/blender/windowmanager/intern/wm_files_link.c b/source/blender/windowmanager/intern/wm_files_link.c
index 5041eeb..b5a8ff0 100644
--- a/source/blender/windowmanager/intern/wm_files_link.c
+++ b/source/blender/windowmanager/intern/wm_files_link.c
@@ -405,18 +405,38 @@ static int wm_link_append_exec(bContext *C, wmOperator *op)
 
 	/* BKE_main_unlock(bmain); */
 
-	wm_link_append_data_free(lapp_data);
-
 	/* mark all library linked objects to be updated */
 	BKE_main_lib_objects_recalc_all(bmain);
 	IMB_colormanagement_check_file_config(bmain);
 
 	/* append, rather than linking */
 	if ((flag & FILE_LINK) == 0) {
-		bool set_fake = RNA_boolean_get(op->ptr, "set_fake");
-		BKE_library_make_local(bmain, NULL, true, set_fake);
+		const bool set_fake = RNA_boolean_get(op->ptr, "set_fake");
+		const bool do_recursive = RNA_boolean_get(op->ptr, "do_recursive");
+
+		if (do_recursive) {
+			BKE_library_make_local(bmain, NULL, true, set_fake);
+		}
+		else {
+			LinkNode *itemlink;
+			GSet *done_libraries = BLI_gset_new_ex(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp,
+			                                       __func__, lapp_data->num_libraries);
+
+			for (itemlink = lapp_data->items.list; itemlink; itemlink = itemlink->next) {
+				ID *new_id = ((WMLinkAppendDataItem *)(itemlink->link))->new_id;
+
+				if (new_id && !BLI_gset_haskey(done_libraries, new_id->lib)) {
+					BKE_library_make_local(bmain, new_id->lib, true, set_fake);
+					BLI_gset_insert(done_libraries, new_id->lib);
+				}
+			}
+
+			BLI_gset_free(done_libraries, NULL);
+		}
 	}
 
+	wm_link_append_data_free(lapp_data);
+
 	/* important we unset, otherwise these object wont
 	 * link into other scenes from this blend file */
 	BKE_main_id_tag_all(bmain, LIB_TAG_PRE_EXISTING, false);
@@ -493,5 +513,8 @@ void WM_OT_append(wmOperatorType *ot)
 	        FILE_DEFAULTDISPLAY, FILE_SORT_ALPHA);
 
 	wm_link_append_properties_common(ot, false);
-	RNA_def_boolean(ot->srna, "set_fake", false, "Fake User", "Set Fake User for appended items (except Objects and Groups)");
+	RNA_def_boolean(ot->srna, "set_fake", false, "Fake User",
+	                "Set Fake User for appended items (except Objects and Groups)");
+	RNA_def_boolean(ot->srna, "do_recursive", true, "Localize All",
+	                "Localize all appended data, including those indirectly linked from other libraries");
 }




More information about the Bf-blender-cvs mailing list