[Bf-blender-cvs] [df7f6a3e2e9] master: Option to load startup file with empty-data

Campbell Barton noreply at git.blender.org
Wed Mar 29 11:11:26 CEST 2017


Commit: df7f6a3e2e91a7ad27f8ca2b2b43a6c51da8c2c9
Author: Campbell Barton
Date:   Wed Mar 29 19:07:21 2017 +1100
Branches: master
https://developer.blender.org/rBdf7f6a3e2e91a7ad27f8ca2b2b43a6c51da8c2c9

Option to load startup file with empty-data

Useful for batch conversion and tests.

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

M	source/blender/blenkernel/BKE_blendfile.h
M	source/blender/blenkernel/intern/blendfile.c
M	source/blender/windowmanager/intern/wm_files.c
M	source/blender/windowmanager/intern/wm_init_exit.c
M	source/blender/windowmanager/wm_files.h

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

diff --git a/source/blender/blenkernel/BKE_blendfile.h b/source/blender/blenkernel/BKE_blendfile.h
index 75978120051..ac58451e412 100644
--- a/source/blender/blenkernel/BKE_blendfile.h
+++ b/source/blender/blenkernel/BKE_blendfile.h
@@ -50,6 +50,7 @@ bool BKE_blendfile_read_from_memory(
 bool BKE_blendfile_read_from_memfile(
         struct bContext *C, struct MemFile *memfile,
         struct ReportList *reports, int skip_flag);
+void BKE_blendfile_read_make_empty(struct bContext *C);
 
 struct UserDef *BKE_blendfile_userdef_read(
         const char *filepath, struct ReportList *reports);
diff --git a/source/blender/blenkernel/intern/blendfile.c b/source/blender/blenkernel/intern/blendfile.c
index 6bcd3c8fb65..a521d671ea4 100644
--- a/source/blender/blenkernel/intern/blendfile.c
+++ b/source/blender/blenkernel/intern/blendfile.c
@@ -426,6 +426,32 @@ bool BKE_blendfile_read_from_memfile(
 	return (bfd != NULL);
 }
 
+/**
+ * Utility to make a file 'empty' used for startup to optionally give an empty file.
+ * Handy for tests.
+ */
+void BKE_blendfile_read_make_empty(bContext *C)
+{
+	Main *bmain = CTX_data_main(C);
+
+	ListBase *lbarray[MAX_LIBARRAY];
+	ID *id;
+	int a;
+
+	a = set_listbasepointers(bmain, lbarray);
+	while (a--) {
+		id = lbarray[a]->first;
+		if (id != NULL) {
+			if (ELEM(GS(id->name), ID_SCE, ID_SCR, ID_WM)) {
+				continue;
+			}
+			while ((id = lbarray[a]->first)) {
+				BKE_libblock_delete(bmain, id);
+			}
+		}
+	}
+}
+
 /* only read the userdef from a .blend */
 UserDef *BKE_blendfile_userdef_read(const char *filepath, ReportList *reports)
 {
diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c
index 27395dbaf3e..2e799307cc0 100644
--- a/source/blender/windowmanager/intern/wm_files.c
+++ b/source/blender/windowmanager/intern/wm_files.c
@@ -643,7 +643,8 @@ bool WM_file_read(bContext *C, const char *filepath, ReportList *reports)
  * When not-null, this is written into the user preferences.
  */
 int wm_homefile_read(
-        bContext *C, ReportList *reports, bool use_factory_settings,
+        bContext *C, ReportList *reports,
+        bool use_factory_settings, bool use_empty_data,
         const char *filepath_startup_override, const char *app_template_override)
 {
 	ListBase wmbase;
@@ -779,6 +780,10 @@ int wm_homefile_read(
 		}
 	}
 
+	if (use_empty_data) {
+		BKE_blendfile_read_make_empty(C);
+	}
+
 	/* Load template preferences,
 	 * unlike regular preferences we only use some of the settings,
 	 * see: BKE_blender_userdef_set_app_template */
@@ -1551,6 +1556,7 @@ static int wm_homefile_read_exec(bContext *C, wmOperator *op)
 	const char *app_template;
 	PropertyRNA *prop_app_template = RNA_struct_find_property(op->ptr, "app_template");
 	const bool use_splash = !use_factory_settings && RNA_boolean_get(op->ptr, "use_splash");
+	const bool use_empty_data = RNA_boolean_get(op->ptr, "use_empty");
 
 	if (prop_app_template && RNA_property_is_set(op->ptr, prop_app_template)) {
 		RNA_property_string_get(op->ptr, prop_app_template, app_template_buf);
@@ -1560,7 +1566,7 @@ static int wm_homefile_read_exec(bContext *C, wmOperator *op)
 		app_template = NULL;
 	}
 
-	if (wm_homefile_read(C, op->reports, use_factory_settings, filepath, app_template)) {
+	if (wm_homefile_read(C, op->reports, use_factory_settings, use_empty_data, filepath, app_template)) {
 		if (use_splash) {
 			WM_init_splash(C);
 		}
@@ -1591,6 +1597,9 @@ void WM_OT_read_homefile(wmOperatorType *ot)
 	                       "Load user interface setup from the .blend file");
 	RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
 
+	prop = RNA_def_boolean(ot->srna, "use_empty", false, "Empty", "");
+	RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
+
 	/* So the splash can be kept open after loading a file (for templates). */
 	prop = RNA_def_boolean(ot->srna, "use_splash", false, "Splash", "");
 	RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
@@ -1615,6 +1624,9 @@ void WM_OT_read_factory_settings(wmOperatorType *ot)
 	prop = RNA_def_string(ot->srna, "app_template", "Template", sizeof(U.app_template), "", "");
 	RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
 
+	prop = RNA_def_boolean(ot->srna, "use_empty", false, "Empty", "");
+	RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
+
 	/* omit poll to run in background mode */
 }
 
diff --git a/source/blender/windowmanager/intern/wm_init_exit.c b/source/blender/windowmanager/intern/wm_init_exit.c
index 5483cf25e40..9bafe72d805 100644
--- a/source/blender/windowmanager/intern/wm_init_exit.c
+++ b/source/blender/windowmanager/intern/wm_init_exit.c
@@ -192,7 +192,7 @@ void WM_init(bContext *C, int argc, const char **argv)
 	wm_init_reports(C);
 
 	/* get the default database, plus a wm */
-	wm_homefile_read(C, NULL, G.factory_startup, NULL, NULL);
+	wm_homefile_read(C, NULL, G.factory_startup, false, NULL, NULL);
 	
 
 	BLT_lang_set(NULL);
diff --git a/source/blender/windowmanager/wm_files.h b/source/blender/windowmanager/wm_files.h
index 15a94d2da70..9a1518e15b0 100644
--- a/source/blender/windowmanager/wm_files.h
+++ b/source/blender/windowmanager/wm_files.h
@@ -36,7 +36,8 @@ struct wmOperatorType;
 /* wm_files.c */
 void		wm_history_file_read(void);
 int			wm_homefile_read(
-        struct bContext *C, struct ReportList *reports, bool use_factory_settings,
+        struct bContext *C, struct ReportList *reports,
+        bool use_factory_settings, bool use_empty_data,
         const char *filepath_startup_override, const char *app_template_override);
 void		wm_file_read_report(bContext *C);




More information about the Bf-blender-cvs mailing list