Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/workspace.c
| Show First 20 Lines • Show All 146 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /* Create, delete, init */ | /* Create, delete, init */ | ||||
| WorkSpace *BKE_workspace_add(Main *bmain, const char *name) | WorkSpace *BKE_workspace_add(Main *bmain, const char *name) | ||||
| { | { | ||||
| WorkSpace *new_workspace = BKE_libblock_alloc(bmain, ID_WS, name, 0); | WorkSpace *new_workspace = BKE_libblock_alloc(bmain, ID_WS, name, 0); | ||||
| /* TABKEY toggles to edit mode by default (no WORKSPACE_USE_PREFERED_MODE flag) */ | |||||
| new_workspace->preferred_mode = OB_MODE_EDIT; | |||||
| return new_workspace; | return new_workspace; | ||||
| } | } | ||||
| /** | /** | ||||
| * The function that actually frees the workspace data (not workspace itself). It shouldn't be called | * The function that actually frees the workspace data (not workspace itself). It shouldn't be called | ||||
| * directly, instead #BKE_workspace_remove should be, which calls this through #BKE_libblock_free then. | * directly, instead #BKE_workspace_remove should be, which calls this through #BKE_libblock_free then. | ||||
| * | * | ||||
| * Should something like a bke_internal.h be added, this should go there! | * Should something like a bke_internal.h be added, this should go there! | ||||
| ▲ Show 20 Lines • Show All 245 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| void BKE_workspace_active_screen_set(WorkSpaceInstanceHook *hook, WorkSpace *workspace, bScreen *screen) | void BKE_workspace_active_screen_set(WorkSpaceInstanceHook *hook, WorkSpace *workspace, bScreen *screen) | ||||
| { | { | ||||
| /* we need to find the WorkspaceLayout that wraps this screen */ | /* we need to find the WorkspaceLayout that wraps this screen */ | ||||
| WorkSpaceLayout *layout = BKE_workspace_layout_find(hook->active, screen); | WorkSpaceLayout *layout = BKE_workspace_layout_find(hook->active, screen); | ||||
| BKE_workspace_hook_layout_for_workspace_set(hook, workspace, layout); | BKE_workspace_hook_layout_for_workspace_set(hook, workspace, layout); | ||||
| } | } | ||||
| #ifdef USE_WORKSPACE_MODE | |||||
| eObjectMode BKE_workspace_object_mode_get(const WorkSpace *workspace, const Scene *scene) | eObjectMode BKE_workspace_object_mode_get(const WorkSpace *workspace, const Scene *scene) | ||||
| { | { | ||||
| Base *active_base = BKE_workspace_active_base_get(workspace, scene); | Base *active_base = BKE_workspace_active_base_get(workspace, scene); | ||||
| /* preferred_mode should never be OB_MODE_OBJECT! Doing this | |||||
| * here is a bit arbitrary, but this is called regularly. */ | |||||
| BLI_assert(workspace->preferred_mode != OB_MODE_OBJECT); | |||||
| return active_base ? active_base->object->mode : OB_MODE_OBJECT; | return active_base ? active_base->object->mode : OB_MODE_OBJECT; | ||||
| } | } | ||||
| void BKE_workspace_object_mode_ensure_updated( | |||||
| WorkSpace *workspace, | |||||
| Object *object, eObjectMode new_mode, | |||||
| const bool is_active) | |||||
| { | |||||
| if (is_active) { | |||||
| if (new_mode == OB_MODE_OBJECT) { | |||||
| workspace->flags &= ~WORKSPACE_USE_PREFERED_MODE; | |||||
| } | |||||
| else { | |||||
| workspace->preferred_mode = new_mode; | |||||
| workspace->flags |= WORKSPACE_USE_PREFERED_MODE; | |||||
| } | |||||
| } | |||||
| object->mode = new_mode; | |||||
| } | |||||
| void BKE_workspace_object_mode_set(WorkSpace *workspace, Scene *scene, const eObjectMode mode) | void BKE_workspace_object_mode_set(WorkSpace *workspace, Scene *scene, const eObjectMode mode) | ||||
| { | { | ||||
| Base *active_base = BKE_workspace_active_base_get(workspace, scene); | Base *active_base = BKE_workspace_active_base_get(workspace, scene); | ||||
| if (active_base) { | if (active_base) { | ||||
| active_base->object->mode = mode; | BKE_workspace_object_mode_ensure_updated(workspace, active_base->object, mode, true); | ||||
| } | |||||
| } | |||||
| enum eObjectMode BKE_workspace_object_mode_for_toggle_get( | |||||
| const WorkSpace *workspace, const Object *active_object) | |||||
| { | |||||
| if (active_object->mode == workspace->preferred_mode) { | |||||
| BLI_assert(workspace->flags & WORKSPACE_USE_PREFERED_MODE); | |||||
| /* The active object is already in the workspace mode, so it should toggle into object mode now. */ | |||||
| return OB_MODE_OBJECT; | |||||
| } | |||||
| else { | |||||
| BLI_assert((workspace->flags & WORKSPACE_USE_PREFERED_MODE) == 0); | |||||
| return workspace->preferred_mode; | |||||
| } | |||||
| } | |||||
| void BKE_workspace_object_mode_for_object_set( | |||||
| WorkSpace *workspace, Scene *scene, | |||||
| Object *object, eObjectMode new_mode) | |||||
| { | |||||
| const Base *active_base = BKE_workspace_active_base_get(workspace, scene); | |||||
| if (active_base) { | |||||
| const bool is_active = active_base && (object == active_base->object); | |||||
| BKE_workspace_object_mode_ensure_updated(workspace, active_base->object, new_mode, is_active); | |||||
| } | } | ||||
| } | } | ||||
| #endif | |||||
| Base *BKE_workspace_active_base_get(const WorkSpace *workspace, const Scene *scene) | Base *BKE_workspace_active_base_get(const WorkSpace *workspace, const Scene *scene) | ||||
| { | { | ||||
| ViewLayer *view_layer = BKE_workspace_view_layer_get(workspace, scene); | ViewLayer *view_layer = BKE_workspace_view_layer_get(workspace, scene); | ||||
| return view_layer->basact; | return view_layer->basact; | ||||
| } | } | ||||
| ListBase *BKE_workspace_transform_orientations_get(WorkSpace *workspace) | ListBase *BKE_workspace_transform_orientations_get(WorkSpace *workspace) | ||||
| { | { | ||||
| return &workspace->transform_orientations; | return &workspace->transform_orientations; | ||||
| } | } | ||||
| ViewLayer *BKE_workspace_view_layer_get(const WorkSpace *workspace, const Scene *scene) | ViewLayer *BKE_workspace_view_layer_get(const WorkSpace *workspace, const Scene *scene) | ||||
| { | { | ||||
| return workspace_relation_get_data_matching_parent(&workspace->scene_viewlayer_relations, scene); | return workspace_relation_get_data_matching_parent(&workspace->scene_viewlayer_relations, scene); | ||||
| } | } | ||||
| void BKE_workspace_view_layer_set(WorkSpace *workspace, ViewLayer *layer, Scene *scene) | void BKE_workspace_view_layer_set(WorkSpace *workspace, ViewLayer *layer, Scene *scene) | ||||
| { | { | ||||
| workspace_relation_ensure_updated(&workspace->scene_viewlayer_relations, scene, layer); | workspace_relation_ensure_updated(&workspace->scene_viewlayer_relations, scene, layer); | ||||
| if (layer->basact) { | |||||
| BKE_workspace_object_mode_ensure_updated(workspace, layer->basact->object, layer->basact->object->mode, true); | |||||
| } | |||||
| } | } | ||||
| ListBase *BKE_workspace_layouts_get(WorkSpace *workspace) | ListBase *BKE_workspace_layouts_get(WorkSpace *workspace) | ||||
| { | { | ||||
| return &workspace->layouts; | return &workspace->layouts; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 67 Lines • Show Last 20 Lines | |||||