[Bf-blender-cvs] [944b920] workspaces: Move scene utils into own file (and improve API)

Julian Eisel noreply at git.blender.org
Thu Dec 8 22:45:32 CET 2016


Commit: 944b920a5f3f8614911fd32666bba2703cfc4e01
Author: Julian Eisel
Date:   Thu Dec 8 22:44:08 2016 +0100
Branches: workspaces
https://developer.blender.org/rB944b920a5f3f8614911fd32666bba2703cfc4e01

Move scene utils into own file (and improve API)

Previously they were kinda mixed with screen utils.

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

M	build_files/cmake/macros.cmake
M	source/blender/blenkernel/BKE_scene.h
M	source/blender/editors/CMakeLists.txt
A	source/blender/editors/include/ED_scene.h
M	source/blender/editors/include/ED_screen.h
M	source/blender/editors/include/ED_util.h
A	source/blender/editors/scene/scene_edit.c
M	source/blender/editors/screen/screen_edit.c
M	source/blender/editors/screen/screen_ops.c
M	source/blender/editors/space_api/spacetypes.c
M	source/blender/editors/space_outliner/outliner_tools.c
M	source/blender/editors/util/CMakeLists.txt
M	source/blender/editors/util/ed_util.c
M	source/blender/windowmanager/intern/wm_window.c

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

diff --git a/build_files/cmake/macros.cmake b/build_files/cmake/macros.cmake
index 2e3a190..a455bf4 100644
--- a/build_files/cmake/macros.cmake
+++ b/build_files/cmake/macros.cmake
@@ -586,6 +586,7 @@ function(SETUP_BLENDER_SORTED_LIBS)
 		bf_editor_armature
 		bf_editor_physics
 		bf_editor_render
+		bf_editor_scene
 		bf_editor_screen
 		bf_editor_sculpt_paint
 		bf_editor_sound
diff --git a/source/blender/blenkernel/BKE_scene.h b/source/blender/blenkernel/BKE_scene.h
index d215295..81d28de 100644
--- a/source/blender/blenkernel/BKE_scene.h
+++ b/source/blender/blenkernel/BKE_scene.h
@@ -49,11 +49,13 @@ struct Scene;
 struct UnitSettings;
 struct Main;
 
-#define SCE_COPY_NEW        0
-#define SCE_COPY_EMPTY      1
-#define SCE_COPY_LINK_OB    2
-#define SCE_COPY_LINK_DATA  3
-#define SCE_COPY_FULL       4
+typedef enum eSceneCopyMethod {
+	SCE_COPY_NEW       = 0,
+	SCE_COPY_EMPTY     = 1,
+	SCE_COPY_LINK_OB   = 2,
+	SCE_COPY_LINK_DATA = 3,
+	SCE_COPY_FULL      = 4,
+} eSceneCopyMethod;
 
 /* Use as the contents of a 'for' loop: for (SETLOOPER(...)) { ... */
 #define SETLOOPER(_sce_basis, _sce_iter, _base)                               \
diff --git a/source/blender/editors/CMakeLists.txt b/source/blender/editors/CMakeLists.txt
index 1559512..3881621 100644
--- a/source/blender/editors/CMakeLists.txt
+++ b/source/blender/editors/CMakeLists.txt
@@ -35,6 +35,7 @@ if(WITH_BLENDER)
 	add_subdirectory(object)
 	add_subdirectory(physics)
 	add_subdirectory(render)
+	add_subdirectory(scene)
 	add_subdirectory(screen)
 	add_subdirectory(sculpt_paint)
 	add_subdirectory(sound)
diff --git a/source/blender/editors/include/ED_scene.h b/source/blender/editors/include/ED_scene.h
new file mode 100644
index 0000000..2f67f7b
--- /dev/null
+++ b/source/blender/editors/include/ED_scene.h
@@ -0,0 +1,40 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file ED_scene.h
+ *  \ingroup editors
+ */
+
+#ifndef __ED_SCENE_H__
+#define __ED_SCENE_H__
+
+#include "BLI_compiler_attrs.h"
+
+enum eSceneCopyMethod;
+
+struct Scene *ED_scene_add(struct Main *bmain, bContext *C, struct wmWindow *win, enum eSceneCopyMethod method) ATTR_NONNULL();
+bool ED_scene_delete(bContext *C, struct Main *bmain, struct wmWindow *win, struct Scene *scene) ATTR_NONNULL();
+void ED_scene_exit(bContext *C) ATTR_NONNULL();
+void ED_scene_changed_update(struct Main *bmain, bContext *C, struct Scene *scene_new,
+                             const struct bScreen *active_screen) ATTR_NONNULL();
+
+void ED_operatortypes_scene(void);
+
+#endif /* __ED_SCENE_H__ */
diff --git a/source/blender/editors/include/ED_screen.h b/source/blender/editors/include/ED_screen.h
index 3501005..4b0222d 100644
--- a/source/blender/editors/include/ED_screen.h
+++ b/source/blender/editors/include/ED_screen.h
@@ -107,7 +107,6 @@ void    ED_screen_refresh(struct wmWindowManager *wm, struct wmWindow *win);
 void    ED_screen_do_listen(struct bContext *C, struct wmNotifier *note);
 bool    ED_screen_set(struct bContext *C, struct bScreen *sc);
 void    ED_screen_update_after_scene_change(const struct bScreen *screen, struct Scene *scene_new);
-bool    ED_screen_delete_scene(struct bContext *C, struct Scene *scene);
 void    ED_screen_set_subwinactive(struct bContext *C, struct wmEvent *event);
 void    ED_screen_exit(struct bContext *C, struct wmWindow *window, struct bScreen *screen);
 void    ED_screen_animation_timer(struct bContext *C, int redraws, int refresh, int sync, int enable);
diff --git a/source/blender/editors/include/ED_util.h b/source/blender/editors/include/ED_util.h
index 4188f0a..a4afa95 100644
--- a/source/blender/editors/include/ED_util.h
+++ b/source/blender/editors/include/ED_util.h
@@ -43,11 +43,6 @@ void    ED_editors_exit(struct bContext *C);
 
 bool    ED_editors_flush_edits(const struct bContext *C, bool for_render);
 
-/* editor level scene utils, could move these into own file */
-void    ED_scene_exit(struct bContext *C);
-void    ED_scene_changed_update(struct Main *bmain, struct bContext *C, struct Scene *scene_new,
-                                const struct bScreen *active_screen);
-
 void    ED_spacedata_id_remap(struct ScrArea *sa, struct SpaceLink *sl, struct ID *old_id, struct ID *new_id);
 
 void    ED_OT_flush_edits(struct wmOperatorType *ot);
diff --git a/source/blender/editors/scene/scene_edit.c b/source/blender/editors/scene/scene_edit.c
new file mode 100644
index 0000000..b3e6764
--- /dev/null
+++ b/source/blender/editors/scene/scene_edit.c
@@ -0,0 +1,192 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/editors/screen/scene_edit.c
+ *  \ingroup edscr
+ */
+
+#include "BKE_context.h"
+#include "BKE_depsgraph.h"
+#include "BKE_global.h"
+#include "BKE_library_remap.h"
+#include "BKE_main.h"
+#include "BKE_scene.h"
+
+#include "BLI_compiler_attrs.h"
+
+#include "BLT_translation.h"
+
+#include "ED_object.h"
+#include "ED_render.h"
+#include "ED_scene.h"
+#include "ED_screen.h"
+#include "ED_util.h"
+
+#include "RNA_access.h"
+#include "RNA_define.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+
+Scene *ED_scene_add(Main *bmain, bContext *C, wmWindow *win, eSceneCopyMethod method)
+{
+	Scene *scene_new;
+
+	if (method == SCE_COPY_NEW) {
+		scene_new = BKE_scene_add(bmain, DATA_("Scene"));
+	}
+	else { /* different kinds of copying */
+		Scene *scene_old = WM_window_get_active_scene(win);
+
+		scene_new = BKE_scene_copy(bmain, scene_old, method);
+
+		/* these can't be handled in blenkernel currently, so do them here */
+		if (method == SCE_COPY_LINK_DATA) {
+			ED_object_single_users(bmain, scene_new, false, true);
+		}
+		else if (method == SCE_COPY_FULL) {
+			ED_editors_flush_edits(C, false);
+			ED_object_single_users(bmain, scene_new, true, true);
+		}
+	}
+
+	WM_window_set_active_scene(bmain, C, win, scene_new);
+
+	WM_event_add_notifier(C, NC_SCENE | ND_SCENEBROWSE, scene_new);
+
+	return scene_new;
+}
+
+/**
+ * \note Only call outside of area/region loops
+ * \return true if successful
+ */
+bool ED_scene_delete(bContext *C, Main *bmain, wmWindow *win, Scene *scene)
+{
+	Scene *scene_new;
+
+	if (scene->id.prev)
+		scene_new = scene->id.prev;
+	else if (scene->id.next)
+		scene_new = scene->id.next;
+	else
+		return false;
+
+	WM_window_set_active_scene(bmain, C, win, scene_new);
+
+	BKE_libblock_remap(bmain, scene, scene_new, ID_REMAP_SKIP_INDIRECT_USAGE | ID_REMAP_SKIP_NEVER_NULL_USAGE);
+	BKE_libblock_free(bmain, scene);
+
+	return true;
+}
+
+void ED_scene_exit(bContext *C)
+{
+	ED_object_editmode_exit(C, EM_FREEDATA | EM_DO_UNDO);
+}
+
+void ED_scene_changed_update(Main *bmain, bContext *C, Scene *scene_new, const bScreen *active_screen)
+{
+	CTX_data_scene_set(C, scene_new);
+	BKE_scene_set_background(bmain, scene_new);
+	DAG_on_visible_update(bmain, false);
+
+	ED_screen_update_after_scene_change(active_screen, scene_new);
+	ED_render_engine_changed(bmain);
+	ED_update_for_newframe(bmain, scene_new, 1);
+
+	/* complete redraw */
+	WM_event_add_notifier(C, NC_WINDOW, NULL);
+}
+
+static int scene_new_exec(bContext *C, wmOperator *op)
+{
+	Main *bmain = CTX_data_main(C);
+	wmWindow *win = CTX_wm_window(C);
+	int type = RNA_enum_get(op->ptr, "type");
+
+	ED_scene_add(bmain, C, win, type);
+
+	return OPERATOR_FINISHED;
+}
+
+static void SCENE_OT_new(wmOperatorType *ot)
+{
+	static EnumPropertyItem type_items[] = {
+		{SCE_COPY_NEW, "NEW", 0, "New", "Add new scene"},
+		{SCE_COPY_EMPTY, "EMPTY", 0, "Copy Settings", "Make a copy without any objects"},
+		{SCE_COPY_LINK_OB, "LINK_OBJECTS", 0, "Link Objects", "Link to the objects from the current scene"},
+		{SCE_COPY_LINK_DATA, "LINK_OBJECT_DATA", 0, "Link Object Data", "Copy objects linked to data from the current scene"},
+		{SCE_COPY_FULL, "FULL_COPY", 0, "Full Copy", "Make a full copy of the current scene"},
+		{0, NULL, 0, NULL, NULL}
+	};
+
+	/* identifiers */
+	ot->name = "New Scene";
+	ot->description = "Add new scene by type";
+	ot->idname = "SCENE_OT_new";
+
+	/* api callbacks */
+	ot->exec = scene_new_exec;
+	ot->invoke = WM_menu_invoke;
+
+	/* flags */
+	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+	/* properties */
+	ot->prop = RNA_def_enum(ot->srna, "type", type_items, 0, "Type", "");
+}
+
+static int scene_delete_exec(bContext *C, wmOperator *UNUSED(op))
+{
+	Scene *scene = CTX_data_scene(C);
+
+	if (ED_scene_delete(C, CTX_data_main(C), CTX_wm_window(C), scene) == false) {
+		return OPERATOR_CANCELLED;
+	}
+
+	if (G.debug & G_DEBUG)
+		printf("scene delete %p\n", scene);
+
+	WM_event_add_notifier(C, NC_SCENE | NA_REMOVED, scene);
+
+	return OPERATOR_FINISHED;
+}
+
+static void SCENE_OT_delete(wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name = "D

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list