Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/screen/workspace_edit.c
| Show First 20 Lines • Show All 73 Lines • ▼ Show 20 Lines | WorkSpace *ED_workspace_add( | ||||
| Main *bmain, const char *name, Scene *scene, | Main *bmain, const char *name, Scene *scene, | ||||
| ViewLayer *act_view_layer, ViewRender *view_render) | ViewLayer *act_view_layer, ViewRender *view_render) | ||||
| { | { | ||||
| WorkSpace *workspace = BKE_workspace_add(bmain, name); | WorkSpace *workspace = BKE_workspace_add(bmain, name); | ||||
| BKE_workspace_view_layer_set(workspace, act_view_layer, scene); | BKE_workspace_view_layer_set(workspace, act_view_layer, scene); | ||||
| BKE_viewrender_copy(&workspace->view_render, view_render); | BKE_viewrender_copy(&workspace->view_render, view_render); | ||||
| #ifdef USE_WORKSPACE_MODE | |||||
| BKE_workspace_object_mode_set(workspace, scene, OB_MODE_OBJECT); | BKE_workspace_object_mode_set(workspace, scene, OB_MODE_OBJECT); | ||||
| #endif | |||||
| return workspace; | return workspace; | ||||
| } | } | ||||
| #ifdef USE_WORKSPACE_MODE | |||||
| /** | /** | ||||
| * Changes the object mode (if needed) to the one set in \a workspace_new. | * 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. | * Object mode is still stored on object level. In future it should all be workspace level instead. | ||||
| */ | */ | ||||
| static void workspace_change_update_mode( | static void workspace_change_update_mode( | ||||
| const WorkSpace *workspace_old, const WorkSpace *workspace_new, | WorkSpace *workspace_new, | ||||
| bContext *C, Object *ob_act, ReportList *reports) | bContext *C, ReportList *reports) | ||||
| { | { | ||||
| const Scene *scene = CTX_data_scene(C); | const Scene *scene = CTX_data_scene(C); | ||||
| eObjectMode mode_old = BKE_workspace_object_mode_get(workspace_old, scene); | Base *base_active_new = BKE_workspace_active_base_get(workspace_new, scene); | ||||
| eObjectMode mode_new = BKE_workspace_object_mode_get(workspace_new, scene); | eObjectMode mode_new = (workspace_new->flags & WORKSPACE_USE_PREFERED_MODE) ? | ||||
| workspace_new->preferred_mode : OB_MODE_OBJECT; | |||||
| if (mode_old != mode_new) { | if (base_active_new->object->mode != mode_new) { /* Mode of active object needs changing. */ | ||||
| ED_object_mode_compat_set(C, ob_act, mode_new, reports); | ED_object_mode_compat_set(C, base_active_new->object, mode_new, reports); | ||||
| ED_object_toggle_modes(C, mode_new); | ED_object_toggle_modes(C, mode_new); | ||||
| } | } | ||||
| } | } | ||||
| #endif | |||||
| static void workspace_change_update_view_layer( | static void workspace_change_update_view_layer( | ||||
| WorkSpace *workspace_new, const WorkSpace *workspace_old, | WorkSpace *workspace_new, const WorkSpace *workspace_old, | ||||
| Scene *scene) | Scene *scene) | ||||
| { | { | ||||
| if (!BKE_workspace_view_layer_get(workspace_new, scene)) { | if (!BKE_workspace_view_layer_get(workspace_new, scene)) { | ||||
| BKE_workspace_view_layer_set(workspace_new, BKE_workspace_view_layer_get(workspace_old, scene), scene); | BKE_workspace_view_layer_set(workspace_new, BKE_workspace_view_layer_get(workspace_old, scene), scene); | ||||
| } | } | ||||
| } | } | ||||
| static void workspace_change_update( | static void workspace_change_update( | ||||
| WorkSpace *workspace_new, const WorkSpace *workspace_old, | WorkSpace *workspace_new, const WorkSpace *workspace_old, | ||||
| bContext *C, wmWindowManager *wm) | bContext *C, wmWindowManager *wm) | ||||
| { | { | ||||
| /* needs to be done before changing mode! (to ensure right context) */ | /* 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_view_layer(workspace_new, workspace_old, CTX_data_scene(C)); | ||||
| #ifdef USE_WORKSPACE_MODE | |||||
| workspace_change_update_mode(workspace_old, workspace_new, C, CTX_data_active_object(C), &wm->reports); | workspace_change_update_mode(workspace_new, C, &wm->reports); | ||||
| #else | |||||
| UNUSED_VARS(C, wm); | |||||
| #endif | |||||
| } | } | ||||
| static bool workspace_change_find_new_layout_cb(const WorkSpaceLayout *layout, void *UNUSED(arg)) | static bool workspace_change_find_new_layout_cb(const WorkSpaceLayout *layout, void *UNUSED(arg)) | ||||
| { | { | ||||
| /* return false to stop the iterator if we've found a layout that can be activated */ | /* return false to stop the iterator if we've found a layout that can be activated */ | ||||
| return workspace_layout_set_poll(layout) ? false : true; | return workspace_layout_set_poll(layout) ? false : true; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 89 Lines • ▼ Show 20 Lines | WorkSpace *ED_workspace_duplicate( | ||||
| Scene *scene = WM_window_get_active_scene(win); | Scene *scene = WM_window_get_active_scene(win); | ||||
| WorkSpace *workspace_new = ED_workspace_add( | WorkSpace *workspace_new = ED_workspace_add( | ||||
| bmain, workspace_old->id.name + 2, scene, | bmain, workspace_old->id.name + 2, scene, | ||||
| BKE_workspace_view_layer_get(workspace_old, scene), | BKE_workspace_view_layer_get(workspace_old, scene), | ||||
| &workspace_old->view_render); | &workspace_old->view_render); | ||||
| ListBase *transform_orientations_old = BKE_workspace_transform_orientations_get(workspace_old); | ListBase *transform_orientations_old = BKE_workspace_transform_orientations_get(workspace_old); | ||||
| ListBase *transform_orientations_new = BKE_workspace_transform_orientations_get(workspace_new); | ListBase *transform_orientations_new = BKE_workspace_transform_orientations_get(workspace_new); | ||||
| #ifdef USE_WORKSPACE_MODE | |||||
| BKE_workspace_object_mode_set(workspace_new, scene, BKE_workspace_object_mode_get(workspace_old, scene)); | BKE_workspace_object_mode_set(workspace_new, scene, BKE_workspace_object_mode_get(workspace_old, scene)); | ||||
| #endif | |||||
| BLI_duplicatelist(transform_orientations_new, transform_orientations_old); | BLI_duplicatelist(transform_orientations_new, transform_orientations_old); | ||||
| workspace_new->tool = workspace_old->tool; | workspace_new->tool = workspace_old->tool; | ||||
| workspace_new->preferred_mode = workspace_old->preferred_mode; | |||||
| workspace_new->flags = workspace_old->flags; | |||||
| for (WorkSpaceLayout *layout_old = layouts_old->first; layout_old; layout_old = layout_old->next) { | 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); | WorkSpaceLayout *layout_new = ED_workspace_layout_duplicate(workspace_new, layout_old, win); | ||||
| if (layout_active_old == layout_old) { | if (layout_active_old == layout_old) { | ||||
| win->workspace_hook->temp_layout_store = layout_new; | win->workspace_hook->temp_layout_store = layout_new; | ||||
| } | } | ||||
| } | } | ||||
| Show All 40 Lines | |||||
| { | { | ||||
| for (WorkSpace *workspace = bmain->workspaces.first; workspace; workspace = workspace->id.next) { | for (WorkSpace *workspace = bmain->workspaces.first; workspace; workspace = workspace->id.next) { | ||||
| if (BKE_workspace_view_layer_get(workspace, scene) == layer_unset) { | if (BKE_workspace_view_layer_get(workspace, scene) == layer_unset) { | ||||
| BKE_workspace_view_layer_set(workspace, layer_new, scene); | BKE_workspace_view_layer_set(workspace, layer_new, scene); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static void workspace_refresh_active_base_changed( | |||||
| WorkSpace *workspace, bContext *C, | |||||
| const Scene *scene, Object *active_object, | |||||
| ReportList *reports) | |||||
| { | |||||
| BLI_assert(workspace->flags & WORKSPACE_ACTIVE_BASE_CHANGED); | |||||
| if (workspace->flags & WORKSPACE_USE_PREFERED_MODE) { | |||||
| if (active_object->mode != workspace->preferred_mode) { | |||||
| eObjectMode preferred_mode = workspace->preferred_mode; | |||||
| if (active_object != scene->obedit) { | |||||
| ED_object_editmode_exit(C, EM_FREEDATA | EM_FREEUNDO | EM_WAITCURSOR | EM_DO_UNDO); | |||||
| } | |||||
| ED_object_mode_compat_set(C, active_object, preferred_mode, reports); | |||||
| ED_object_toggle_modes(C, preferred_mode); | |||||
| } | |||||
| } | |||||
| else if (active_object->mode != OB_MODE_OBJECT) { | |||||
| ED_object_mode_compat_set(C, active_object, OB_MODE_OBJECT, reports); | |||||
| } | |||||
| workspace->flags &= ~WORKSPACE_ACTIVE_BASE_CHANGED; | |||||
| } | |||||
| void ED_workspaces_refresh( | |||||
| bContext *C, ReportList *reports) | |||||
| { | |||||
| wmWindowManager *wm = CTX_wm_manager(C); | |||||
| wmWindow *old_ctx_window = CTX_wm_window(C); | |||||
| for (wmWindow *win = wm->windows.first; win; win = win->next) { | |||||
| WorkSpace *workspace = WM_window_get_active_workspace(win); | |||||
| if (workspace->flags & WORKSPACE_ACTIVE_BASE_CHANGED) { | |||||
| Scene *scene = WM_window_get_active_scene(win); | |||||
| Base *basact = BKE_workspace_active_base_get(workspace, scene); | |||||
| if (basact) { | |||||
| CTX_wm_window_set(C, win); | |||||
| workspace_refresh_active_base_changed(workspace, C, scene, basact->object, reports); | |||||
| } | |||||
| } | |||||
| } | |||||
| CTX_wm_window_set(C, old_ctx_window); | |||||
| } | |||||
| /** \} Workspace API */ | /** \} Workspace API */ | ||||
| /** \name Workspace Operators | /** \name Workspace Operators | ||||
| * | * | ||||
| * \{ */ | * \{ */ | ||||
| static int workspace_new_exec(bContext *C, wmOperator *UNUSED(op)) | static int workspace_new_exec(bContext *C, wmOperator *UNUSED(op)) | ||||
| ▲ Show 20 Lines • Show All 151 Lines • Show Last 20 Lines | |||||