[Bf-blender-cvs] [9206c3d] workspaces: Move workspace DNA back into DNA module

Julian Eisel noreply at git.blender.org
Wed Jan 4 02:25:37 CET 2017


Commit: 9206c3d40a8287aa9f5102cd9a4080b5aa26385e
Author: Julian Eisel
Date:   Wed Jan 4 02:21:43 2017 +0100
Branches: workspaces
https://developer.blender.org/rB9206c3d40a8287aa9f5102cd9a4080b5aa26385e

Move workspace DNA back into DNA module

Added some special include guards to protect from access from outside of BKE_workspace and makesdna.

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

M	source/blender/CMakeLists.txt
M	source/blender/blenkernel/BKE_workspace.h
M	source/blender/blenkernel/intern/library.c
M	source/blender/blenkernel/intern/workspace.c
M	source/blender/editors/screen/workspace_edit.c
R079	source/blender/blenkernel/intern/workspace_dna.h	source/blender/makesdna/dna_workspace_types.h
M	source/blender/makesdna/intern/makesdna.c

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

diff --git a/source/blender/CMakeLists.txt b/source/blender/CMakeLists.txt
index 6f2b78e..1593148 100644
--- a/source/blender/CMakeLists.txt
+++ b/source/blender/CMakeLists.txt
@@ -88,6 +88,7 @@ set(SRC_DNA_INC
 	${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_view2d_types.h
 	${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_view3d_types.h
 	${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_windowmanager_types.h
+	${CMAKE_CURRENT_SOURCE_DIR}/makesdna/dna_workspace_types.h
 	${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_world_types.h
 	${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_movieclip_types.h
 	${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_tracking_types.h
diff --git a/source/blender/blenkernel/BKE_workspace.h b/source/blender/blenkernel/BKE_workspace.h
index 48591d8..9b7eb6c 100644
--- a/source/blender/blenkernel/BKE_workspace.h
+++ b/source/blender/blenkernel/BKE_workspace.h
@@ -91,4 +91,9 @@ void            BKE_workspace_layout_screen_set(WorkSpaceLayout *layout, struct
 WorkSpaceLayout *BKE_workspace_layout_next_get(const WorkSpaceLayout *layout) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
 WorkSpaceLayout *BKE_workspace_layout_prev_get(const WorkSpaceLayout *layout) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
 
+/* -------------------------------------------------------------------- */
+/* Don't use outside of BKE! */
+
+WorkSpace *workspace_alloc(void) ATTR_WARN_UNUSED_RESULT;
+
 #endif /* __BKE_WORKSPACE_H__ */
diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c
index 2d969df..83142e7 100644
--- a/source/blender/blenkernel/intern/library.c
+++ b/source/blender/blenkernel/intern/library.c
@@ -132,9 +132,6 @@
 
 #include "atomic_ops.h"
 
-/* local DNA files */
-#include "workspace_dna.h"
-
 
 /* GS reads the memory pointed at in a specific ordering. 
  * only use this definition, makes little and big endian systems
@@ -969,7 +966,7 @@ void *BKE_libblock_alloc_notest(short type)
 			id = MEM_callocN(sizeof(CacheFile), "Cache File");
 			break;
 		case ID_WS:
-			id = MEM_callocN(sizeof(WorkSpace), "Workspace");
+			id = (ID *)workspace_alloc();
 			break;
 	}
 	return id;
diff --git a/source/blender/blenkernel/intern/workspace.c b/source/blender/blenkernel/intern/workspace.c
index 5564e3a..bcbc06f 100644
--- a/source/blender/blenkernel/intern/workspace.c
+++ b/source/blender/blenkernel/intern/workspace.c
@@ -22,6 +22,8 @@
  *  \ingroup bke
  */
 
+#define NAMESPACE_WORKSPACE /* allow including specially guarded dna_workspace_types.h */
+
 #include "BLI_utildefines.h"
 
 #include "BKE_global.h"
@@ -32,11 +34,10 @@
 
 #include "DNA_scene_types.h"
 #include "DNA_screen_types.h"
+#include "dna_workspace_types.h"
 
 #include "MEM_guardedalloc.h"
 
-#include "workspace_dna.h"
-
 
 static bool workspaces_is_screen_used(const Main *bmain, bScreen *screen);
 
@@ -44,6 +45,14 @@ static bool workspaces_is_screen_used(const Main *bmain, bScreen *screen);
 /* -------------------------------------------------------------------- */
 /* Create, delete, init */
 
+/**
+ * Only to be called by #BKE_libblock_alloc_notest! Always use BKE_workspace_add to add a new workspace.
+ */
+WorkSpace *workspace_alloc(void)
+{
+	return MEM_callocN(sizeof(WorkSpace), "Workspace");
+}
+
 WorkSpace *BKE_workspace_add(Main *bmain, const char *name)
 {
 	WorkSpace *new_ws = BKE_libblock_alloc(bmain, ID_WS, name);
diff --git a/source/blender/editors/screen/workspace_edit.c b/source/blender/editors/screen/workspace_edit.c
index b1bcc03..5586b18 100644
--- a/source/blender/editors/screen/workspace_edit.c
+++ b/source/blender/editors/screen/workspace_edit.c
@@ -84,22 +84,22 @@ WorkSpace *ED_workspace_duplicate(WorkSpace *workspace_old, Main *bmain, wmWindo
 {
 	WorkSpaceLayout *layout_active_old = BKE_workspace_active_layout_get(workspace_old);
 	ListBase *layouts_old = BKE_workspace_layouts_get(workspace_old);
-	WorkSpace *worspace_new = BKE_libblock_alloc(bmain, ID_WS, BKE_workspace_name_get(workspace_old));
+	WorkSpace *workspace_new = BKE_workspace_add(bmain, BKE_workspace_name_get(workspace_old));
 
 	BKE_workspace_layout_iter_begin(layout_old, layouts_old->first)
 	{
-		WorkSpaceLayout *layout_new = ED_workspace_layout_duplicate(worspace_new, layout_old, win);
+		WorkSpaceLayout *layout_new = ED_workspace_layout_duplicate(workspace_new, layout_old, win);
 
 		if (layout_active_old == layout_old) {
 			bScreen *screen_new = BKE_workspace_layout_screen_get(layout_new);
 
 			screen_new_activate_refresh(win, screen_new);
-			BKE_workspace_active_layout_set(worspace_new, layout_new);
+			BKE_workspace_active_layout_set(workspace_new, layout_new);
 		}
 	}
 	BKE_workspace_layout_iter_end;
 
-	return worspace_new;
+	return workspace_new;
 }
 
 /**
diff --git a/source/blender/blenkernel/intern/workspace_dna.h b/source/blender/makesdna/dna_workspace_types.h
similarity index 79%
rename from source/blender/blenkernel/intern/workspace_dna.h
rename to source/blender/makesdna/dna_workspace_types.h
index 97cbffc..4a68acb 100644
--- a/source/blender/blenkernel/intern/workspace_dna.h
+++ b/source/blender/makesdna/dna_workspace_types.h
@@ -18,14 +18,18 @@
  * ***** END GPL LICENSE BLOCK *****
  */
 
-/** \file blender/blenkernel/intern/workspace_dna.h
- *  \ingroup bke
+/** \file DNA_workspace_types.h
+ *  \ingroup DNA
  *
- * Local header with WorkSpace DNA types. makesdna.c includes this.
+ * Only use with API in BKE_workspace.h!
  */
 
-#ifndef __WORKSPACE_DNA_H__
-#define __WORKSPACE_DNA_H__
+#ifndef __DNA_WORKSPACE_TYPES_H__
+#define __DNA_WORKSPACE_TYPES_H__
+
+#if !defined(NAMESPACE_WORKSPACE) && !defined(NAMESPACE_DNA)
+#  error "This file shouldn't be included outside of workspace namespace."
+#endif
 
 /**
  * Layouts are basically bScreens. We use this struct to wrap a reference to a screen so that we can store it in
@@ -45,4 +49,4 @@ typedef struct WorkSpace {
 	struct WorkSpaceLayout *new_layout; /* temporary when switching screens */
 } WorkSpace;
 
-#endif /* __WORKSPACE_DNA_H__ */
+#endif /* __DNA_WORKSPACE_TYPES_H__ */
diff --git a/source/blender/makesdna/intern/makesdna.c b/source/blender/makesdna/intern/makesdna.c
index 1ba83ff..6fef41d 100644
--- a/source/blender/makesdna/intern/makesdna.c
+++ b/source/blender/makesdna/intern/makesdna.c
@@ -56,6 +56,8 @@
 
 #include "../blenlib/BLI_sys_types.h" // for intptr_t support
 
+#define NAMESPACE_DNA /* Allow including DNA files for specially guarded namespaces */
+
 #define SDNA_MAX_FILENAME_LENGTH 255
 
 
@@ -130,9 +132,7 @@ static const char *includefiles[] = {
 	"DNA_freestyle_types.h",
 	"DNA_linestyle_types.h",
 	"DNA_cachefile_types.h",
-
-	/* local DNA headers */
-	"../blenkernel/intern/workspace_dna.h",
+	"dna_workspace_types.h",
 
 	/* see comment above before editing! */
 
@@ -1346,8 +1346,6 @@ int main(int argc, char **argv)
 #include "DNA_freestyle_types.h"
 #include "DNA_linestyle_types.h"
 #include "DNA_cachefile_types.h"
-
-/* local DNA headers */
-#include "../blenkernel/intern/workspace_dna.h"
+#include "dna_workspace_types.h"
 
 /* end of list */




More information about the Bf-blender-cvs mailing list