Commit: 9e9cb9fce9c74d32b4f7fad9fdbcbbc59acc53b9
Author: Campbell Barton
Date:   Wed Feb 28 16:27:55 2018 +1100
Branches: blender2.8
https://developer.blender.org/rB9e9cb9fce9c74d32b4f7fad9fdbcbbc59acc53b9

Workspace: sync object-modes to other workspaces

When changing the mode of an object, apply this to all other
workspaces that share the same active object.

Also use copy the object-mode when duplicating workspaces.

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

M       source/blender/editors/include/ED_screen.h
M       source/blender/editors/object/object_edit.c
M       source/blender/editors/physics/particle_edit.c
M       source/blender/editors/screen/workspace_edit.c
M       source/blender/editors/sculpt_paint/paint_image.c
M       source/blender/editors/sculpt_paint/paint_vertex.c
M       source/blender/editors/sculpt_paint/sculpt.c

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

diff --git a/source/blender/editors/include/ED_screen.h 
b/source/blender/editors/include/ED_screen.h
index be1a24aeac4..a98f8287162 100644
--- a/source/blender/editors/include/ED_screen.h
+++ b/source/blender/editors/include/ED_screen.h
@@ -187,6 +187,11 @@ bool ED_workspace_layout_cycle(
         struct WorkSpace *workspace, const short direction,
         struct bContext *C) ATTR_NONNULL();
 
+void ED_workspace_object_mode_sync_from_object(
+        struct wmWindowManager *wm, WorkSpace *workspace, struct Object 
*obact);
+void ED_workspace_object_mode_sync_from_scene(
+        struct wmWindowManager *wm, WorkSpace *workspace, struct Scene *scene);
+
 /* anim */
 void    ED_update_for_newframe(struct Main *bmain, struct Scene *scene, struct 
ViewLayer *view_layer, struct Depsgraph *depsgraph);
 
diff --git a/source/blender/editors/object/object_edit.c 
b/source/blender/editors/object/object_edit.c
index 0da4bd1e045..e975ee40c3c 100644
--- a/source/blender/editors/object/object_edit.c
+++ b/source/blender/editors/object/object_edit.c
@@ -313,6 +313,8 @@ void ED_object_editmode_exit_ex(bContext *C, WorkSpace 
*workspace, Scene *scene,
                workspace->object_mode &= ~OB_MODE_EDIT;
        }
 
+       ED_workspace_object_mode_sync_from_object(G.main->wm.first, workspace, 
obedit);
+
        if (flag & EM_WAITCURSOR) waitcursor(0);
 
        /* This way we ensure scene's obedit is copied into all CoW scenes.  */
@@ -441,6 +443,8 @@ void ED_object_editmode_enter(bContext *C, int flag)
                WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_MODE_OBJECT, 
scene);
        }
 
+       ED_workspace_object_mode_sync_from_object(G.main->wm.first, workspace, 
ob);
+
        if (flag & EM_DO_UNDO) ED_undo_push(C, "Enter Editmode");
        if (flag & EM_WAITCURSOR) waitcursor(0);
 }
@@ -506,6 +510,7 @@ void OBJECT_OT_editmode_toggle(wmOperatorType *ot)
 
 static int posemode_exec(bContext *C, wmOperator *op)
 {
+       wmWindowManager *wm = CTX_wm_manager(C);
        WorkSpace *workspace = CTX_wm_workspace(C);
        Base *base = CTX_data_active_base(C);
        Object *ob = base->object;
@@ -527,7 +532,9 @@ static int posemode_exec(bContext *C, wmOperator *op)
                        ED_armature_exit_posemode(C, base);
                else
                        ED_armature_enter_posemode(C, base);
-               
+
+               ED_workspace_object_mode_sync_from_object(wm, workspace, ob);
+
                return OPERATOR_FINISHED;
        }
        
diff --git a/source/blender/editors/physics/particle_edit.c 
b/source/blender/editors/physics/particle_edit.c
index 376e4659b92..850ef0ad958 100644
--- a/source/blender/editors/physics/particle_edit.c
+++ b/source/blender/editors/physics/particle_edit.c
@@ -72,6 +72,7 @@
 #include "ED_physics.h"
 #include "ED_mesh.h"
 #include "ED_particle.h"
+#include "ED_screen.h"
 #include "ED_view3d.h"
 
 #include "GPU_immediate.h"
@@ -4786,6 +4787,7 @@ static int particle_edit_toggle_poll(bContext *C)
 
 static int particle_edit_toggle_exec(bContext *C, wmOperator *op)
 {
+       wmWindowManager *wm = CTX_wm_manager(C);
        struct WorkSpace *workspace = CTX_wm_workspace(C);
        EvaluationContext eval_ctx;
        CTX_data_eval_ctx(C, &eval_ctx);
@@ -4820,6 +4822,8 @@ static int particle_edit_toggle_exec(bContext *C, 
wmOperator *op)
                WM_event_add_notifier(C, NC_SCENE|ND_MODE|NS_MODE_OBJECT, NULL);
        }
 
+       ED_workspace_object_mode_sync_from_object(wm, workspace, ob);
+
        DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
 
        return OPERATOR_FINISHED;
diff --git a/source/blender/editors/screen/workspace_edit.c 
b/source/blender/editors/screen/workspace_edit.c
index 465e30357dc..94527b82ce8 100644
--- a/source/blender/editors/screen/workspace_edit.c
+++ b/source/blender/editors/screen/workspace_edit.c
@@ -36,6 +36,7 @@
 #include "BKE_context.h"
 #include "BKE_idcode.h"
 #include "BKE_main.h"
+#include "BKE_layer.h"
 #include "BKE_library.h"
 #include "BKE_report.h"
 #include "BKE_scene.h"
@@ -248,6 +249,7 @@ WorkSpace *ED_workspace_duplicate(
        BLI_duplicatelist(transform_orientations_new, 
transform_orientations_old);
 
        workspace_new->tool = workspace_old->tool;
+       workspace_new->object_mode = workspace_old->object_mode;
 
        for (WorkSpaceLayout *layout_old = layouts_old->first; layout_old; 
layout_old = layout_old->next) {
                WorkSpaceLayout *layout_new = 
ED_workspace_layout_duplicate(workspace_new, layout_old, win);
@@ -304,6 +306,41 @@ void ED_workspace_view_layer_unset(
        }
 }
 
+/**
+ * When a work-space mode has changed,
+ * flush it to all other visible work-spaces using the same object
+ * since we don't support one object being in two different modes at once.
+ * \note We could support this but it's more trouble than it's worth.
+ */
+
+void ED_workspace_object_mode_sync_from_object(wmWindowManager *wm, WorkSpace 
*workspace, Object *obact)
+{
+       if (obact == NULL) {
+               return;
+       }
+       for (wmWindow *win = wm->windows.first; win; win = win->next) {
+               WorkSpace *workspace_iter = 
BKE_workspace_active_get(win->workspace_hook);
+               if (workspace != workspace_iter) {
+                       Scene *scene_iter = WM_window_get_active_scene(win);
+                       ViewLayer *view_layer = 
BKE_view_layer_from_workspace_get(scene_iter, workspace_iter);
+                       if (obact == OBACT(view_layer)) {
+                               workspace_iter->object_mode = 
workspace->object_mode;
+                               /* TODO(campbell), use msgbus */
+                               WM_main_add_notifier(NC_SCENE | ND_MODE | 
NS_MODE_OBJECT, scene_iter);
+                       }
+               }
+       }
+}
+
+void ED_workspace_object_mode_sync_from_scene(wmWindowManager *wm, WorkSpace 
*workspace, Scene *scene)
+{
+       ViewLayer *view_layer = BKE_workspace_view_layer_get(workspace, scene);
+       if (view_layer) {
+               Object *obact = obact = OBACT(view_layer);
+               ED_workspace_object_mode_sync_from_object(wm, workspace, obact);
+       }
+}
+
 /** \} Workspace API */
 
 
diff --git a/source/blender/editors/sculpt_paint/paint_image.c 
b/source/blender/editors/sculpt_paint/paint_image.c
index 1cb37fc10cd..5595f81dd4e 100644
--- a/source/blender/editors/sculpt_paint/paint_image.c
+++ b/source/blender/editors/sculpt_paint/paint_image.c
@@ -1376,6 +1376,7 @@ static int texture_paint_toggle_poll(bContext *C)
 
 static int texture_paint_toggle_exec(bContext *C, wmOperator *op)
 {
+       wmWindowManager *wm = CTX_wm_manager(C);
        WorkSpace *workspace = CTX_wm_workspace(C);
        Scene *scene = CTX_data_scene(C);
        Object *ob = CTX_data_active_object(C);
@@ -1450,6 +1451,8 @@ static int texture_paint_toggle_exec(bContext *C, 
wmOperator *op)
                toggle_paint_cursor(C, 1);
        }
 
+       ED_workspace_object_mode_sync_from_object(wm, workspace, ob);
+
        GPU_drawobject_free(ob->derivedFinal);
        WM_event_add_notifier(C, NC_SCENE | ND_MODE, scene);
 
diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c 
b/source/blender/editors/sculpt_paint/paint_vertex.c
index 8ce0af068d6..e028c752b88 100644
--- a/source/blender/editors/sculpt_paint/paint_vertex.c
+++ b/source/blender/editors/sculpt_paint/paint_vertex.c
@@ -55,6 +55,8 @@
 #include "BKE_brush.h"
 #include "BKE_context.h"
 #include "BKE_deform.h"
+#include "BKE_global.h"
+#include "BKE_main.h"
 #include "BKE_mesh.h"
 #include "BKE_mesh_mapping.h"
 #include "BKE_object_deform.h"
@@ -1089,6 +1091,8 @@ static void ed_vwpaintmode_enter_generic(
        }
 
        vertex_paint_init_session(eval_ctx, scene, ob);
+
+       ED_workspace_object_mode_sync_from_object(wm, workspace, ob);
 }
 
 void ED_object_vpaintmode_enter_ex(
@@ -1174,6 +1178,8 @@ static void ed_vwpaintmode_exit_generic(
                ED_mesh_mirror_spatial_table(NULL, NULL, NULL, NULL, 'e');
                ED_mesh_mirror_topo_table(NULL, NULL, 'e');
        }
+
+       ED_workspace_object_mode_sync_from_object(G.main->wm.first, workspace, 
ob);
 }
 
 void ED_object_vpaintmode_exit_ex(WorkSpace *workspace, Object *ob)
diff --git a/source/blender/editors/sculpt_paint/sculpt.c 
b/source/blender/editors/sculpt_paint/sculpt.c
index 8df3d4e9f90..debc719a5d9 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -60,6 +60,7 @@
 #include "BKE_image.h"
 #include "BKE_key.h"
 #include "BKE_library.h"
+#include "BKE_main.h"
 #include "BKE_mesh.h"
 #include "BKE_mesh_mapping.h"
 #include "BKE_modifier.h"
@@ -5669,6 +5670,8 @@ void ED_object_sculptmode_exit_ex(
        /* Leave sculptmode */
        workspace->object_mode &= ~mode_flag;
 
+       ED_workspace_object_mode_sync_from_object(G.main->wm.first, workspace, 
ob);
+
        BKE_sculptsession_free(ob);
 
        paint_cursor_delete_textures();
@@ -5691,6 +5694,7 @@ void ED_object_sculptmode_exit(bContext *C)
 
 static int sculpt_mode_toggle_exec(bContext *C, wmOperator *op)
 {
+       wmWindowManager *wm = CTX_wm_manager(C);
        WorkSpace *workspace = CTX_wm_workspace(C);
        Scene *scene = CTX_data_scene(C);
        Object *ob = CTX_data_active_object(C);
@@ -5800,6 +5804,8 @@ static int sculpt_mode_toggle_exec(bContext *C, 
wmOperator *op)
                        }
                }
 
+               ED_workspace_object_mode_sync_from_object(wm, workspace, ob);
+
                /* VBO no longer valid */
                if (ob->derivedFinal) {
                        GPU_drawobject_free(ob->derivedFinal);

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to