[Bf-blender-cvs] [9031d5cc8f] workspaces: Fix and compile time option for workspace object-mode

Julian Eisel noreply at git.blender.org
Sun Jan 22 21:09:50 CET 2017


Commit: 9031d5cc8f7a5d24490cc76a2cee6a70a595901e
Author: Julian Eisel
Date:   Sun Jan 22 20:56:18 2017 +0100
Branches: workspaces
https://developer.blender.org/rB9031d5cc8f7a5d24490cc76a2cee6a70a595901e

Fix and compile time option for workspace object-mode

Now we also sync the workspace object-mode when selecting a different object. It's still quite easy to get the mode of the active object and the one stored in the workspace out of sync, but fixing this would require a bunch of changes that would only be temporary anyway. Remember, plan is to make object-mode a purely workspace level option, not storing it within the object anymore.
The current object-mode syncing isn't supposed to stay there for long, I added a #define USE_WORKSPACE_MODE so we can disable it easily (DNA still stores it in files though).

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

M	release/scripts/startup/bl_ui/space_info.py
M	source/blender/blenkernel/BKE_workspace.h
M	source/blender/blenkernel/intern/workspace.c
M	source/blender/editors/object/object_edit.c
M	source/blender/editors/object/object_select.c
M	source/blender/editors/workspace/workspace_edit.c
M	source/blender/makesrna/intern/rna_workspace.c

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

diff --git a/release/scripts/startup/bl_ui/space_info.py b/release/scripts/startup/bl_ui/space_info.py
index afdcf988fe..028a584d75 100644
--- a/release/scripts/startup/bl_ui/space_info.py
+++ b/release/scripts/startup/bl_ui/space_info.py
@@ -47,8 +47,9 @@ class INFO_HT_header(Header):
             layout.template_ID(window, "workspace", new="workspace.workspace_new", unlink="workspace.workspace_delete")
             layout.template_ID_preview(workspace, "screen", workspace, "screens", new="screen.new", unlink="screen.delete", rows=2, cols=6)
 
-        act_mode_item = bpy.types.Object.bl_rna.properties['mode'].enum_items[workspace.object_mode]
-        layout.operator_menu_enum("object.mode_set", "mode", text=act_mode_item.name, icon=act_mode_item.icon)
+        if hasattr(workspace, 'object_mode'):
+            act_mode_item = bpy.types.Object.bl_rna.properties['mode'].enum_items[workspace.object_mode]
+            layout.operator_menu_enum("object.mode_set", "mode", text=act_mode_item.name, icon=act_mode_item.icon)
 
         layout.separator()
 
diff --git a/source/blender/blenkernel/BKE_workspace.h b/source/blender/blenkernel/BKE_workspace.h
index e95146bcd7..8cd884e193 100644
--- a/source/blender/blenkernel/BKE_workspace.h
+++ b/source/blender/blenkernel/BKE_workspace.h
@@ -26,24 +26,37 @@
 #define __BKE_WORKSPACE_H__
 
 #include "BLI_compiler_attrs.h"
+#include "BLI_utildefines.h"
 
 struct bScreen;
+struct ListBase;
+struct Main;
 struct TransformOrientation;
 struct WorkSpace;
 
 typedef struct WorkSpace WorkSpace;
 typedef struct WorkSpaceLayout WorkSpaceLayout;
 
+/**
+ * Plan is to store the object-mode per workspace, not per object anymore.
+ * However, there's quite some work to be done for that, so for now, there is just a basic
+ * implementation of an object <-> workspace object-mode syncing for testing, with some known
+ * problems. Main problem being that the modes can get out of sync when changing object selection.
+ * Would require a pile of temporary changes to always sync modes when changing selection. So just
+ * leaving this here for some testing until object-mode is really a workspace level setting.
+ */
+#define USE_WORKSPACE_MODE
+
 
 /* -------------------------------------------------------------------- */
 /* Create, delete, init */
 
-WorkSpace *BKE_workspace_add(Main *bmain, const char *name);
+WorkSpace *BKE_workspace_add(struct Main *bmain, const char *name);
 void BKE_workspace_free(WorkSpace *ws);
-void BKE_workspace_remove(WorkSpace *workspace, Main *bmain);
+void BKE_workspace_remove(WorkSpace *workspace, struct Main *bmain);
 
 struct WorkSpaceLayout *BKE_workspace_layout_add(WorkSpace *workspace, struct bScreen *screen) ATTR_NONNULL();
-void BKE_workspace_layout_remove(WorkSpace *workspace, WorkSpaceLayout *layout, Main *bmain) ATTR_NONNULL();
+void BKE_workspace_layout_remove(WorkSpace *workspace, WorkSpaceLayout *layout, struct Main *bmain) ATTR_NONNULL();
 
 
 /* -------------------------------------------------------------------- */
@@ -54,7 +67,7 @@ void BKE_workspace_layout_remove(WorkSpace *workspace, WorkSpaceLayout *layout,
 		_workspace##_next = BKE_workspace_next_get(_workspace); /* support removing workspace from list */
 #define BKE_workspace_iter_end } (void)0
 
-void BKE_workspaces_transform_orientation_remove(const ListBase *workspaces,
+void BKE_workspaces_transform_orientation_remove(const struct ListBase *workspaces,
                                                  const struct TransformOrientation *orientation) ATTR_NONNULL();
 
 WorkSpaceLayout *BKE_workspace_layout_find(const WorkSpace *ws, const struct bScreen *screen) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
@@ -83,8 +96,10 @@ void             BKE_workspace_active_layout_set(WorkSpace *ws, WorkSpaceLayout
 struct bScreen *BKE_workspace_active_screen_get(const WorkSpace *ws) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
 void            BKE_workspace_active_screen_set(WorkSpace *ws, struct bScreen *screen) ATTR_NONNULL(1);
 enum ObjectMode BKE_workspace_object_mode_get(const WorkSpace *workspace) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
+#ifdef USE_WORKSPACE_MODE
 void            BKE_workspace_object_mode_set(WorkSpace *workspace, const enum ObjectMode mode) ATTR_NONNULL();
-ListBase *BKE_workspace_layouts_get(WorkSpace *workspace) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
+#endif
+struct ListBase *BKE_workspace_layouts_get(WorkSpace *workspace) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
 WorkSpaceLayout *BKE_workspace_new_layout_get(const WorkSpace *workspace) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
 void             BKE_workspace_new_layout_set(WorkSpace *workspace, WorkSpaceLayout *layout) ATTR_NONNULL(1);
 
diff --git a/source/blender/blenkernel/intern/workspace.c b/source/blender/blenkernel/intern/workspace.c
index 6a4d36d41e..cfdb22dc98 100644
--- a/source/blender/blenkernel/intern/workspace.c
+++ b/source/blender/blenkernel/intern/workspace.c
@@ -228,6 +228,7 @@ void BKE_workspace_active_screen_set(WorkSpace *ws, bScreen *screen)
 	ws->act_layout = BKE_workspace_layout_find(ws, screen);
 }
 
+#ifdef USE_WORKSPACE_MODE
 ObjectMode BKE_workspace_object_mode_get(const WorkSpace *workspace)
 {
 	return workspace->object_mode;
@@ -236,6 +237,7 @@ void BKE_workspace_object_mode_set(WorkSpace *workspace, const ObjectMode mode)
 {
 	workspace->object_mode = mode;
 }
+#endif
 
 ListBase *BKE_workspace_layouts_get(WorkSpace *workspace)
 {
diff --git a/source/blender/editors/object/object_edit.c b/source/blender/editors/object/object_edit.c
index 30d179552d..bc9ce29bf9 100644
--- a/source/blender/editors/object/object_edit.c
+++ b/source/blender/editors/object/object_edit.c
@@ -1694,7 +1694,11 @@ bool ED_object_mode_compat_set(bContext *C, Object *ob, int mode, ReportList *re
 		const char *opstring = object_mode_op_string(ob->mode);
 
 		WM_operator_name_call(C, opstring, WM_OP_EXEC_REGION_WIN, NULL);
+#ifdef USE_WORKSPACE_MODE
 		BKE_workspace_object_mode_set(workspace, ob->mode);
+#else
+		UNUSED_VARS(workspace);
+#endif
 		ok = ELEM(ob->mode, mode, OB_MODE_OBJECT);
 		if (!ok) {
 			wmOperatorType *ot = WM_operatortype_find(opstring, false);
@@ -1807,12 +1811,15 @@ void OBJECT_OT_mode_set(wmOperatorType *ot)
 void ED_object_toggle_modes(bContext *C, int mode)
 {
 	if (mode != OB_MODE_OBJECT) {
-		WorkSpace *workspace = CTX_wm_workspace(C);
 		const char *opstring = object_mode_op_string(mode);
 
 		if (opstring) {
-			WM_operator_name_call(C, opstring, WM_OP_EXEC_REGION_WIN, NULL);
+#ifdef USE_WORKSPACE_MODE
+			WorkSpace *workspace = CTX_wm_workspace(C);
+
 			BKE_workspace_object_mode_set(workspace, mode);
+#endif
+			WM_operator_name_call(C, opstring, WM_OP_EXEC_REGION_WIN, NULL);
 		}
 	}
 }
diff --git a/source/blender/editors/object/object_select.c b/source/blender/editors/object/object_select.c
index f1b7186f8a..743b965a91 100644
--- a/source/blender/editors/object/object_select.c
+++ b/source/blender/editors/object/object_select.c
@@ -57,6 +57,7 @@
 #include "BKE_property.h"
 #include "BKE_report.h"
 #include "BKE_scene.h"
+#include "BKE_workspace.h"
 #include "BKE_library.h"
 #include "BKE_deform.h"
 
@@ -108,7 +109,12 @@ void ED_base_object_activate(bContext *C, Base *base)
 	BASACT = base;
 	
 	if (base) {
-		
+#ifdef USE_WORKSPACE_MODE
+		WorkSpace *workspace = CTX_wm_workspace(C);
+
+		BKE_workspace_object_mode_set(workspace, base->object->mode);
+#endif
+
 		/* XXX old signals, remember to handle notifiers now! */
 		//		select_actionchannel_by_name(base->object->action, "Object", 1);
 		
diff --git a/source/blender/editors/workspace/workspace_edit.c b/source/blender/editors/workspace/workspace_edit.c
index 2118a20bde..64af6d7289 100644
--- a/source/blender/editors/workspace/workspace_edit.c
+++ b/source/blender/editors/workspace/workspace_edit.c
@@ -48,6 +48,8 @@
  * \brief API for managing workspaces and their data.
  * \{ */
 
+#ifdef USE_WORKSPACE_MODE
+
 /**
  * Changes the object mode (if needed) to the one set in \a workspace_new.
  * Object mode is still stored on object level. In future it should all be workspace level instead.
@@ -64,6 +66,8 @@ static void workspace_change_update_mode(const WorkSpace *workspace_old, const W
 	}
 }
 
+#endif
+
 /**
  * \brief Change the active workspace.
  *
@@ -88,7 +92,11 @@ bool ED_workspace_change(bContext *C, wmWindowManager *wm, wmWindow *win, WorkSp
 		/* update screen *after* changing workspace - which also causes the actual screen change */
 		screen_changed_update(C, win, screen_new);
 
+#ifdef USE_WORKSPACE_MODE
 		workspace_change_update_mode(workspace_old, workspace_new, C, CTX_data_active_object(C), &wm->reports);
+#else
+		UNUSED_VARS(wm);
+#endif
 
 		BLI_assert(CTX_wm_workspace(C) == workspace_new);
 
diff --git a/source/blender/makesrna/intern/rna_workspace.c b/source/blender/makesrna/intern/rna_workspace.c
index 96fcd1a4cc..287edf1d2b 100644
--- a/source/blender/makesrna/intern/rna_workspace.c
+++ b/source/blender/makesrna/intern/rna_workspace.c
@@ -22,6 +22,8 @@
  *  \ingroup RNA
  */
 
+#include "BKE_workspace.h"
+
 #include "RNA_define.h"
 #include "RNA_enum_types.h"
 #include "RNA_types.h"
@@ -31,8 +33,6 @@
 
 #ifdef RNA_RUNTIME
 
-#include "BKE_workspace.h"
-
 #include "DNA_object_types.h"
 #include "DNA_screen_types.h"
 
@@ -100,6 +100,8 @@ static PointerRNA rna_workspace_screens_item_get(CollectionPropertyIterator *ite
 	return rna_pointer_inherit_refine(&iter->parent, &RNA_Screen, screen);
 }
 
+#ifdef USE_WORKSPACE_MODE
+
 static int rna_workspace_object_mode_get(PointerRNA *ptr)
 {
 	WorkSpace *workspace = ptr->data;
@@ -112,6 +114,8 @@ static void rna_workspace_object_mode_set(PointerRNA *ptr, int value)
 	BKE_workspace_object_mode_set(workspace, value);
 }
 
+#endif /* USE_WORKSPACE_MODE */
+
 #else /* RNA_RUNTIME */
 
 static void rna_def_workspace(BlenderRNA *brna)
@@ -140,10 +144,12 @@ static void rna_def_workspace(BlenderRNA *brna)
 	                                  "rna_workspace_screens_item_get", NULL, NULL, NULL, NULL);
 	RNA_def_property_ui_text(prop, "Screens", "Screen layouts of a workspace");
 
+#ifdef USE_WORKSPACE_MODE
 	prop = RNA_def_property(srna, "object_mode", PROP_ENUM, PROP_NONE);
 	RNA_def_property_enum_items(prop, rna_enum_object_mode

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list