diff options
author | Campbell Barton <ideasman42@gmail.com> | 2018-02-22 07:52:30 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2018-02-22 07:52:30 +0300 |
commit | 026ac65831f340c4517903d2b7a377a957b55c0a (patch) | |
tree | de6711ec7116a57f46accf7b0f340ea556a4297f /source/blender | |
parent | 648df0fcdb8249d8d00ee501d6947216bb7330d5 (diff) |
WorkSpace: Restore saved object-modes again
Was temporarily removed when moving object mode to workspace.
Note: there is an issue where eval_ctx->view_layer is NULL on load,
for now pass a view layer argument, we might wan't to set the value
instead.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenkernel/intern/scene.c | 10 | ||||
-rw-r--r-- | source/blender/editors/util/ed_util.c | 43 |
2 files changed, 47 insertions, 6 deletions
diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c index 899a911270f..7032541f90d 100644 --- a/source/blender/blenkernel/intern/scene.c +++ b/source/blender/blenkernel/intern/scene.c @@ -1376,7 +1376,10 @@ static bool check_rendered_viewport_visible(Main *bmain) return false; } -static void prepare_mesh_for_viewport_render(Main *bmain, const EvaluationContext *eval_ctx) +/* TODO(campbell): shouldn't we be able to use 'eval_ctx->view_layer' here? + * Currently this is NULL on load, so don't. */ +static void prepare_mesh_for_viewport_render( + Main *bmain, const EvaluationContext *eval_ctx, const ViewLayer *view_layer) { /* This is needed to prepare mesh to be used by the render * engine from the viewport rendering. We do loading here @@ -1387,7 +1390,8 @@ static void prepare_mesh_for_viewport_render(Main *bmain, const EvaluationContex * call loading of the edit data for the mesh objects. */ - Object *obedit = OBEDIT_FROM_EVAL_CTX(eval_ctx); + /* Expanded 'OBEDIT_FROM_EVAL_CTX' */ + Object *obedit = (eval_ctx->object_mode & OB_MODE_EDIT) ? OBACT(view_layer) : NULL; if (obedit) { Mesh *mesh = obedit->data; if ((obedit->type == OB_MESH) && @@ -1429,7 +1433,7 @@ void BKE_scene_graph_update_tagged(EvaluationContext *eval_ctx, /* Uncomment this to check if graph was properly tagged for update. */ // DEG_debug_graph_relations_validate(depsgraph, bmain, scene); /* Flush editing data if needed. */ - prepare_mesh_for_viewport_render(bmain, eval_ctx); + prepare_mesh_for_viewport_render(bmain, eval_ctx, view_layer); /* Flush recalc flags to dependencies. */ DEG_graph_flush_update(bmain, depsgraph); /* Update all objects: drivers, matrices, displists, etc. flags set diff --git a/source/blender/editors/util/ed_util.c b/source/blender/editors/util/ed_util.c index a5a26cf4d57..562ba2c42b3 100644 --- a/source/blender/editors/util/ed_util.c +++ b/source/blender/editors/util/ed_util.c @@ -60,6 +60,8 @@ #include "BKE_packedFile.h" #include "BKE_paint.h" #include "BKE_screen.h" +#include "BKE_workspace.h" +#include "BKE_layer.h" #include "ED_armature.h" #include "ED_buttons.h" @@ -90,7 +92,6 @@ void ED_editors_init(bContext *C) { wmWindowManager *wm = CTX_wm_manager(C); - Scene *sce = CTX_data_scene(C); /* This is called during initialization, so we don't want to store any reports */ ReportList *reports = CTX_wm_reports(C); @@ -98,9 +99,45 @@ void ED_editors_init(bContext *C) SWAP(int, reports->flag, reports_flag_prev); + + /* toggle on modes for objects that were saved with these enabled. for + * e.g. linked objects we have to ensure that they are actually the + * active object in this scene. */ + { + wmWindow *win_orig = CTX_wm_window(C); + CTX_wm_window_set(C, NULL); + for (wmWindow *win = wm->windows.first; win; win = win->next) { + WorkSpace *workspace = WM_window_get_active_workspace(win); + Scene *scene = WM_window_get_active_scene(win); + ViewLayer *view_layer = BKE_view_layer_from_workspace_get(scene, workspace); + Object *obact = view_layer ? OBACT(view_layer) : NULL; + eObjectMode object_mode = workspace->object_mode; + workspace->object_mode = OB_MODE_OBJECT; + if (view_layer && obact) { + const ID *data = obact->data; + if (!ELEM(object_mode, OB_MODE_OBJECT, OB_MODE_POSE)) { + if (!ID_IS_LINKED(obact) && !(data && ID_IS_LINKED(data))) { + CTX_wm_window_set(C, win); + ED_object_toggle_modes(C, object_mode); + CTX_wm_window_set(C, NULL); + } + } + else if (object_mode == OB_MODE_POSE) { + if (!ID_IS_LINKED(obact) && (obact->type == OB_ARMATURE)) { + workspace->object_mode = object_mode; + } + } + } + } + CTX_wm_window_set(C, win_orig); + } + /* image editor paint mode */ - if (sce) { - ED_space_image_paint_update(wm, sce); + { + Scene *sce = CTX_data_scene(C); + if (sce) { + ED_space_image_paint_update(wm, sce); + } } SWAP(int, reports->flag, reports_flag_prev); |