diff options
Diffstat (limited to 'source/blender/editors/screen')
-rw-r--r-- | source/blender/editors/screen/screen_context.c | 16 | ||||
-rw-r--r-- | source/blender/editors/screen/screen_ops.c | 63 | ||||
-rw-r--r-- | source/blender/editors/screen/workspace_edit.c | 130 |
3 files changed, 53 insertions, 156 deletions
diff --git a/source/blender/editors/screen/screen_context.c b/source/blender/editors/screen/screen_context.c index 4c217a5e829..e0c73b1782e 100644 --- a/source/blender/editors/screen/screen_context.c +++ b/source/blender/editors/screen/screen_context.c @@ -93,6 +93,7 @@ int ed_screen_context(const bContext *C, const char *member, bContextDataResult WorkSpace *workspace = BKE_workspace_active_get(win->workspace_hook); ViewLayer *view_layer = BKE_view_layer_from_workspace_get(scene, workspace); Object *obact = (view_layer && view_layer->basact) ? view_layer->basact->object : NULL; + Object *obedit = OBEDIT_FROM_VIEW_LAYER(view_layer); if (CTX_data_dir(member)) { CTX_data_dir_set(result, screen_context_dir); @@ -203,7 +204,6 @@ int ed_screen_context(const bContext *C, const char *member, bContextDataResult return 1; } else if (CTX_data_equals(member, "visible_bones") || CTX_data_equals(member, "editable_bones")) { - Object *obedit = BKE_workspace_edit_object(workspace, scene); bArmature *arm = (obedit && obedit->type == OB_ARMATURE) ? obedit->data : NULL; EditBone *ebone, *flipbone = NULL; const bool editable_bones = CTX_data_equals(member, "editable_bones"); @@ -246,7 +246,6 @@ int ed_screen_context(const bContext *C, const char *member, bContextDataResult } } else if (CTX_data_equals(member, "selected_bones") || CTX_data_equals(member, "selected_editable_bones")) { - Object *obedit = BKE_workspace_edit_object(workspace, scene); bArmature *arm = (obedit && obedit->type == OB_ARMATURE) ? obedit->data : NULL; EditBone *ebone, *flipbone = NULL; const bool selected_editable_bones = CTX_data_equals(member, "selected_editable_bones"); @@ -368,38 +367,37 @@ int ed_screen_context(const bContext *C, const char *member, bContextDataResult } else if (CTX_data_equals(member, "edit_object")) { /* convenience for now, 1 object per scene in editmode */ - Object *obedit = BKE_workspace_edit_object(workspace, scene); if (obedit) CTX_data_id_pointer_set(result, &obedit->id); return 1; } else if (CTX_data_equals(member, "sculpt_object")) { - if (obact && (workspace->object_mode & OB_MODE_SCULPT)) { + if (obact && (obact->mode & OB_MODE_SCULPT)) CTX_data_id_pointer_set(result, &obact->id); - } + return 1; } else if (CTX_data_equals(member, "vertex_paint_object")) { - if (obact && (workspace->object_mode & OB_MODE_VERTEX_PAINT)) + if (obact && (obact->mode & OB_MODE_VERTEX_PAINT)) CTX_data_id_pointer_set(result, &obact->id); return 1; } else if (CTX_data_equals(member, "weight_paint_object")) { - if (obact && (workspace->object_mode & OB_MODE_WEIGHT_PAINT)) + if (obact && (obact->mode & OB_MODE_WEIGHT_PAINT)) CTX_data_id_pointer_set(result, &obact->id); return 1; } else if (CTX_data_equals(member, "image_paint_object")) { - if (obact && (workspace->object_mode & OB_MODE_TEXTURE_PAINT)) + if (obact && (obact->mode & OB_MODE_TEXTURE_PAINT)) CTX_data_id_pointer_set(result, &obact->id); return 1; } else if (CTX_data_equals(member, "particle_edit_object")) { - if (obact && (workspace->object_mode & OB_MODE_PARTICLE_EDIT)) + if (obact && (obact->mode & OB_MODE_PARTICLE_EDIT)) CTX_data_id_pointer_set(result, &obact->id); return 1; diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c index c24d08d5fed..0b893d23e13 100644 --- a/source/blender/editors/screen/screen_ops.c +++ b/source/blender/editors/screen/screen_ops.c @@ -153,7 +153,6 @@ int ED_operator_scene_editable(bContext *C) int ED_operator_objectmode(bContext *C) { - const WorkSpace *workspace = CTX_wm_workspace(C); Scene *scene = CTX_data_scene(C); Object *obact = CTX_data_active_object(C); @@ -163,7 +162,7 @@ int ED_operator_objectmode(bContext *C) return 0; /* add a check for ob->mode too? */ - if (obact && (workspace->object_mode != OB_MODE_OBJECT)) + if (obact && (obact->mode != OB_MODE_OBJECT)) return 0; return 1; @@ -305,39 +304,35 @@ int ED_operator_console_active(bContext *C) return ed_spacetype_test(C, SPACE_CONSOLE); } -static int ed_object_hidden(Object *ob, eObjectMode object_mode) +static int ed_object_hidden(Object *ob) { /* if hidden but in edit mode, we still display, can happen with animation */ - return ((ob->restrictflag & OB_RESTRICT_VIEW) && !(object_mode & OB_MODE_EDIT)); + return ((ob->restrictflag & OB_RESTRICT_VIEW) && !(ob->mode & OB_MODE_EDIT)); } int ED_operator_object_active(bContext *C) { - const WorkSpace *workspace = CTX_wm_workspace(C); Object *ob = ED_object_active_context(C); - return ((ob != NULL) && !ed_object_hidden(ob, workspace->object_mode)); + return ((ob != NULL) && !ed_object_hidden(ob)); } int ED_operator_object_active_editable(bContext *C) { - const WorkSpace *workspace = CTX_wm_workspace(C); Object *ob = ED_object_active_context(C); - return ((ob != NULL) && !ID_IS_LINKED(ob) && !ed_object_hidden(ob, workspace->object_mode)); + return ((ob != NULL) && !ID_IS_LINKED(ob) && !ed_object_hidden(ob)); } int ED_operator_object_active_editable_mesh(bContext *C) { - const WorkSpace *workspace = CTX_wm_workspace(C); Object *ob = ED_object_active_context(C); - return ((ob != NULL) && !ID_IS_LINKED(ob) && !ed_object_hidden(ob, workspace->object_mode) && + return ((ob != NULL) && !ID_IS_LINKED(ob) && !ed_object_hidden(ob) && (ob->type == OB_MESH) && !ID_IS_LINKED(ob->data)); } int ED_operator_object_active_editable_font(bContext *C) { - const WorkSpace *workspace = CTX_wm_workspace(C); Object *ob = ED_object_active_context(C); - return ((ob != NULL) && !ID_IS_LINKED(ob) && !ed_object_hidden(ob, workspace->object_mode) && + return ((ob != NULL) && !ID_IS_LINKED(ob) && !ed_object_hidden(ob) && (ob->type == OB_FONT)); } @@ -382,14 +377,11 @@ int ED_operator_posemode_exclusive(bContext *C) { Object *obact = CTX_data_active_object(C); - if (obact) { - const WorkSpace *workspace = CTX_wm_workspace(C); - if ((workspace->object_mode & OB_MODE_EDIT) == 0) { - Object *obpose; - if ((obpose = BKE_object_pose_armature_get(obact))) { - if (obact == obpose) { - return 1; - } + if (obact && !(obact->mode & OB_MODE_EDIT)) { + Object *obpose; + if ((obpose = BKE_object_pose_armature_get(obact))) { + if (obact == obpose) { + return 1; } } } @@ -403,15 +395,9 @@ int ED_operator_posemode_context(bContext *C) { Object *obpose = ED_pose_object_from_context(C); - if (obpose) { - const WorkSpace *workspace = CTX_wm_workspace(C); - /* TODO, should we allow this out of pose mode? */ - if (workspace->object_mode & OB_MODE_POSE) { - // if ((workspace->object_mode & OB_MODE_EDIT) == 0) { - if (BKE_object_pose_context_check(obpose)) { - return 1; - } - // } + if (obpose && !(obpose->mode & OB_MODE_EDIT)) { + if (BKE_object_pose_context_check(obpose)) { + return 1; } } @@ -422,17 +408,11 @@ int ED_operator_posemode(bContext *C) { Object *obact = CTX_data_active_object(C); - - if (obact) { - const WorkSpace *workspace = CTX_wm_workspace(C); - if ((workspace->object_mode & OB_MODE_EDIT) == 0) { - Object *obpose; - if ((obpose = BKE_object_pose_armature_get(obact))) { - if (((workspace->object_mode & OB_MODE_POSE) && (obact == obpose)) || - (workspace->object_mode & OB_MODE_WEIGHT_PAINT)) - { - return 1; - } + if (obact && !(obact->mode & OB_MODE_EDIT)) { + Object *obpose; + if ((obpose = BKE_object_pose_armature_get(obact))) { + if ((obact == obpose) || (obact->mode & OB_MODE_WEIGHT_PAINT)) { + return 1; } } } @@ -568,10 +548,9 @@ int ED_operator_mask(bContext *C) } case SPACE_IMAGE: { - WorkSpace *workspace = CTX_wm_workspace(C); SpaceImage *sima = sa->spacedata.first; ViewLayer *view_layer = CTX_data_view_layer(C); - return ED_space_image_check_show_maskedit(sima, workspace, view_layer); + return ED_space_image_check_show_maskedit(sima, view_layer); } } } diff --git a/source/blender/editors/screen/workspace_edit.c b/source/blender/editors/screen/workspace_edit.c index bf2e788e2b0..dee62f9c5dd 100644 --- a/source/blender/editors/screen/workspace_edit.c +++ b/source/blender/editors/screen/workspace_edit.c @@ -85,6 +85,26 @@ WorkSpace *ED_workspace_add( return workspace; } +/** + * 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. + */ +static void workspace_change_update_mode( + const WorkSpace *workspace_old, const WorkSpace *workspace_new, + bContext *C, Object *ob_act, ReportList *reports) +{ + UNUSED_VARS(workspace_old, workspace_new, C, ob_act, reports); +#if 0 + eObjectMode mode_old = workspace_old->object_mode; + eObjectMode mode_new = workspace_new->object_mode; + + if (mode_old != mode_new) { + ED_object_mode_compat_set(C, ob_act, mode_new, reports); + ED_object_mode_toggle(C, mode_new); + } +#endif +} + static void workspace_change_update_view_layer( WorkSpace *workspace_new, const WorkSpace *workspace_old, Scene *scene) @@ -96,10 +116,11 @@ static void workspace_change_update_view_layer( static void workspace_change_update( WorkSpace *workspace_new, const WorkSpace *workspace_old, - bContext *C) + bContext *C, wmWindowManager *wm) { /* needs to be done before changing mode! (to ensure right context) */ workspace_change_update_view_layer(workspace_new, workspace_old, CTX_data_scene(C)); + workspace_change_update_mode(workspace_old, workspace_new, C, CTX_data_active_object(C), &wm->reports); } static bool workspace_change_find_new_layout_cb(const WorkSpaceLayout *layout, void *UNUSED(arg)) @@ -151,7 +172,7 @@ static WorkSpaceLayout *workspace_change_get_new_layout( * \returns if workspace changing was successful. */ bool ED_workspace_change( - WorkSpace *workspace_new, bContext *C, wmWindow *win) + WorkSpace *workspace_new, bContext *C, wmWindowManager *wm, wmWindow *win) { Main *bmain = CTX_data_main(C); WorkSpace *workspace_old = WM_window_get_active_workspace(win); @@ -169,20 +190,11 @@ bool ED_workspace_change( BLI_assert(BKE_workspace_layout_screen_get(layout_new) == screen_new); if (screen_new) { - Scene *scene = WM_window_get_active_scene(win); - bool use_object_mode = false; - - /* Store old context for exiting edit-mode. */ - EvaluationContext eval_ctx_old; - CTX_data_eval_ctx(C, &eval_ctx_old); - - WM_window_set_active_layout(win, workspace_new, layout_new); WM_window_set_active_workspace(win, workspace_new); /* update screen *after* changing workspace - which also causes the actual screen change */ - screen_change_update(C, win, screen_new); - workspace_change_update(workspace_new, workspace_old, C); + workspace_change_update(workspace_new, workspace_old, C, wm); BLI_assert(BKE_workspace_view_layer_get(workspace_new, CTX_data_scene(C)) != NULL); BLI_assert(CTX_wm_workspace(C) == workspace_new); @@ -190,40 +202,6 @@ bool ED_workspace_change( WM_toolsystem_unlink(C, workspace_old); WM_toolsystem_link(C, workspace_new); - ViewLayer *view_layer_old = BKE_workspace_view_layer_get(workspace_old, scene); - Object *obact_old = OBACT(view_layer_old); - - ViewLayer *view_layer_new = BKE_workspace_view_layer_get(workspace_new, scene); - Object *obact_new = OBACT(view_layer_new); - - /* Handle object mode switching */ - if ((workspace_old->object_mode != OB_MODE_OBJECT) || - (workspace_new->object_mode != OB_MODE_OBJECT)) - { - if ((workspace_old->object_mode == workspace_new->object_mode) && - (obact_old == obact_new)) - { - /* pass */ - } - else { - use_object_mode = true; - } - } - - if (use_object_mode) { - /* weak, set it back so it's used when activating again. */ - eObjectMode object_mode = workspace_old->object_mode; - ED_object_mode_generic_exit_or_other_window(&eval_ctx_old, bmain->wm.first, workspace_old, scene, obact_old); - workspace_old->object_mode = object_mode; - ED_workspace_object_mode_sync_from_object(bmain->wm.first, workspace_old, obact_old); - ED_object_mode_generic_enter_or_other_window(C, NULL, workspace_new->object_mode); - } - else { - if (obact_new == NULL) { - workspace_new->object_mode = OB_MODE_OBJECT; - } - } - return true; } @@ -250,7 +228,6 @@ 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); @@ -278,7 +255,7 @@ bool ED_workspace_delete( WorkSpace *prev = workspace_id->prev; WorkSpace *next = workspace_id->next; - ED_workspace_change((prev != NULL) ? prev : next, C, win); + ED_workspace_change((prev != NULL) ? prev : next, C, wm, win); } BKE_libblock_free(bmain, workspace_id); @@ -307,63 +284,6 @@ 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) && (workspace->object_mode != workspace_iter->object_mode)) { - 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(view_layer); - ED_workspace_object_mode_sync_from_object(wm, workspace, obact); - } -} - -bool ED_workspace_object_mode_in_other_window( - struct wmWindowManager *wm, const wmWindow *win_compare, Object *obact, - eObjectMode *r_object_mode) -{ - for (wmWindow *win_iter = wm->windows.first; win_iter; win_iter = win_iter->next) { - if (win_compare != win_iter) { - WorkSpace *workspace_iter = BKE_workspace_active_get(win_iter->workspace_hook); - Scene *scene_iter = WM_window_get_active_scene(win_iter); - ViewLayer *view_layer_iter = BKE_view_layer_from_workspace_get(scene_iter, workspace_iter); - Object *obact_iter = OBACT(view_layer_iter); - if (obact == obact_iter) { - if (r_object_mode) { - *r_object_mode = workspace_iter->object_mode; - } - return true; - } - } - } - - return false; -} - /** \} Workspace API */ |