Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/workspace.c
| Show All 30 Lines | |||||
| #include "BLI_string.h" | #include "BLI_string.h" | ||||
| #include "BLI_string_utf8.h" | #include "BLI_string_utf8.h" | ||||
| #include "BLI_string_utils.h" | #include "BLI_string_utils.h" | ||||
| #include "BLI_listbase.h" | #include "BLI_listbase.h" | ||||
| #include "BKE_global.h" | #include "BKE_global.h" | ||||
| #include "BKE_library.h" | #include "BKE_library.h" | ||||
| #include "BKE_main.h" | #include "BKE_main.h" | ||||
| #include "BKE_object.h" | |||||
| #include "BKE_scene.h" | #include "BKE_scene.h" | ||||
| #include "BKE_screen.h" | #include "BKE_screen.h" | ||||
| #include "BKE_workspace.h" | #include "BKE_workspace.h" | ||||
| #include "DNA_object_types.h" | #include "DNA_object_types.h" | ||||
| #include "DNA_scene_types.h" | #include "DNA_scene_types.h" | ||||
| #include "DNA_screen_types.h" | #include "DNA_screen_types.h" | ||||
| #include "DNA_workspace_types.h" | #include "DNA_workspace_types.h" | ||||
| ▲ Show 20 Lines • Show All 100 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 206 Lines • ▼ Show 20 Lines | BLI_LISTBASE_CIRCULAR_FORWARD_BEGIN(&workspace->layouts, iter_layout, start) | ||||
| } | } | ||||
| } | } | ||||
| BLI_LISTBASE_CIRCULAR_FORWARD_END(&workspace->layouts, iter_layout, start) | BLI_LISTBASE_CIRCULAR_FORWARD_END(&workspace->layouts, iter_layout, start) | ||||
| } | } | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| void BKE_workspace_active_base_changed( | |||||
| WorkSpace *workspace, | |||||
| ViewLayer *active_view_layer) | |||||
| { | |||||
| BLI_assert((workspace != NULL) || (active_view_layer->basact == NULL)); | |||||
| if (workspace) { | |||||
| workspace->flags |= WORKSPACE_ACTIVE_BASE_CHANGED; | |||||
| } | |||||
| UNUSED_VARS_NDEBUG(active_view_layer); | |||||
| } | |||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /* Getters/Setters */ | /* Getters/Setters */ | ||||
| WorkSpace *BKE_workspace_active_get(WorkSpaceInstanceHook *hook) | WorkSpace *BKE_workspace_active_get(WorkSpaceInstanceHook *hook) | ||||
| { | { | ||||
| return hook->active; | return hook->active; | ||||
| } | } | ||||
| Show All 23 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 { | |||||
| /* The workspace must not have WORKSPACE_USE_PREFERED_MODE flag | |||||
| * set if the active object doesn't support preferred_mode. */ | |||||
| BLI_assert(!(BKE_object_is_mode_compatible(active_object, workspace->preferred_mode) && | |||||
| (workspace->flags & WORKSPACE_USE_PREFERED_MODE))); | |||||
| 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, 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); | ||||
| BKE_workspace_active_base_changed(workspace, layer); | |||||
| } | } | ||||
| 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 | |||||