2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2016-04-24 22:42:41 +10:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup bke
|
2016-04-24 22:42:41 +10:00
|
|
|
*
|
|
|
|
|
* High level `.blend` file read/write,
|
|
|
|
|
* and functions for writing *partial* files (only selected data-blocks).
|
|
|
|
|
*/
|
|
|
|
|
|
2023-07-22 11:27:25 +10:00
|
|
|
#include <cstdlib>
|
|
|
|
|
#include <cstring>
|
2016-04-24 22:42:41 +10:00
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
|
|
#include "DNA_scene_types.h"
|
|
|
|
|
#include "DNA_screen_types.h"
|
2023-03-16 15:05:52 +01:00
|
|
|
#include "DNA_space_types.h"
|
Main Workspace Integration
This commit does the main integration of workspaces, which is a design we agreed on during the 2.8 UI workshop (see https://wiki.blender.org/index.php/Dev:2.8/UI/Workshop_Writeup)
Workspaces should generally be stable, I'm not aware of any remaining bugs (or I've forgotten them :) ). If you find any, let me know!
(Exception: mode switching button might get out of sync with actual mode in some cases, would consider that a limitation/ToDo. Needs to be resolved at some point.)
== Main Changes/Features
* Introduces the new Workspaces as data-blocks.
* Allow storing a number of custom workspaces as part of the user configuration. Needs further work to allow adding and deleting individual workspaces.
* Bundle a default workspace configuration with Blender (current screen-layouts converted to workspaces).
* Pressing button to add a workspace spawns a menu to select between "Duplicate Current" and the workspaces from the user configuration. If no workspaces are stored in the user configuration, the default workspaces are listed instead.
* Store screen-layouts (`bScreen`) per workspace.
* Store an active screen-layout per workspace. Changing the workspace will enable this layout.
* Store active mode in workspace. Changing the workspace will also enter the mode of the new workspace. (Note that we still store the active mode in the object, moving this completely to workspaces is a separate project.)
* Store an active render layer per workspace.
* Moved mode switch from 3D View header to Info Editor header.
* Store active scene in window (not directly workspace related, but overlaps quite a bit).
* Removed 'Use Global Scene' User Preference option.
* Compatibility with old files - a new workspace is created for every screen-layout of old files. Old Blender versions should be able to read files saved with workspace support as well.
* Default .blend only contains one workspace ("General").
* Support appending workspaces.
Opening files without UI and commandline rendering should work fine.
Note that the UI is temporary! We plan to introduce a new global topbar
that contains the workspace options and tabs for switching workspaces.
== Technical Notes
* Workspaces are data-blocks.
* Adding and removing `bScreen`s should be done through `ED_workspace_layout` API now.
* A workspace can be active in multiple windows at the same time.
* The mode menu (which is now in the Info Editor header) doesn't display "Grease Pencil Edit" mode anymore since its availability depends on the active editor. Will be fixed by making Grease Pencil an own object type (as planned).
* The button to change the active workspace object mode may get out of sync with the mode of the active object. Will either be resolved by moving mode out of object data, or we'll disable workspace modes again (there's a `#define USE_WORKSPACE_MODE` for that).
* Screen-layouts (`bScreen`) are IDs and thus stored in a main list-base. Had to add a wrapper `WorkSpaceLayout` so we can store them in a list-base within workspaces, too. On the long run we could completely replace `bScreen` by workspace structs.
* `WorkSpace` types use some special compiler trickery to allow marking structs and struct members as private. BKE_workspace API should be used for accessing those.
* Added scene operators `SCENE_OT_`. Was previously done through screen operators.
== BPY API Changes
* Removed `Screen.scene`, added `Window.scene`
* Removed `UserPreferencesView.use_global_scene`
* Added `Context.workspace`, `Window.workspace` and `BlendData.workspaces`
* Added `bpy.types.WorkSpace` containing `screens`, `object_mode` and `render_layer`
* Added Screen.layout_name for the layout name that'll be displayed in the UI (may differ from internal name)
== What's left?
* There are a few open design questions (T50521). We should find the needed answers and implement them.
* Allow adding and removing individual workspaces from workspace configuration (needs UI design).
* Get the override system ready and support overrides per workspace.
* Support custom UI setups as part of workspaces (hidden panels, hidden buttons, customizable toolbars, etc).
* Allow enabling add-ons per workspace.
* Support custom workspace keymaps.
* Remove special exception for workspaces in linking code (so they're always appended, never linked). Depends on a few things, so best to solve later.
* Get the topbar done.
* Workspaces need a proper icon, current one is just a placeholder :)
Reviewed By: campbellbarton, mont29
Tags: #user_interface, #bf_blender_2.8
Maniphest Tasks: T50521
Differential Revision: https://developer.blender.org/D2451
2017-06-01 19:56:58 +02:00
|
|
|
#include "DNA_workspace_types.h"
|
2016-04-24 22:42:41 +10:00
|
|
|
|
2022-10-05 15:30:44 +11:00
|
|
|
#include "BLI_fileops.h"
|
2016-04-24 22:42:41 +10:00
|
|
|
#include "BLI_listbase.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BLI_path_util.h"
|
2016-04-24 22:42:41 +10:00
|
|
|
#include "BLI_string.h"
|
2019-07-31 22:24:19 +10:00
|
|
|
#include "BLI_system.h"
|
2024-01-19 14:32:28 +01:00
|
|
|
#include "BLI_time.h"
|
2016-04-24 22:42:41 +10:00
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
|
|
2024-01-18 22:50:23 +02:00
|
|
|
#include "IMB_colormanagement.hh"
|
2016-04-24 22:42:41 +10:00
|
|
|
|
2019-07-30 11:04:02 +10:00
|
|
|
#include "BKE_addon.h"
|
2024-01-21 19:42:13 +01:00
|
|
|
#include "BKE_appdir.hh"
|
2016-04-24 22:42:41 +10:00
|
|
|
#include "BKE_blender.h"
|
|
|
|
|
#include "BKE_blender_version.h"
|
2023-12-13 12:36:45 +01:00
|
|
|
#include "BKE_blendfile.hh"
|
2016-04-24 22:42:41 +10:00
|
|
|
#include "BKE_bpath.h"
|
2023-12-21 10:10:53 +01:00
|
|
|
#include "BKE_colorband.hh"
|
2023-11-16 11:41:55 +01:00
|
|
|
#include "BKE_context.hh"
|
2016-04-24 22:42:41 +10:00
|
|
|
#include "BKE_global.h"
|
2024-01-20 19:17:36 +01:00
|
|
|
#include "BKE_idtype.hh"
|
2016-04-24 22:42:41 +10:00
|
|
|
#include "BKE_ipo.h"
|
2019-07-31 21:46:13 +10:00
|
|
|
#include "BKE_keyconfig.h"
|
2024-01-23 15:18:09 -05:00
|
|
|
#include "BKE_layer.hh"
|
2024-01-15 12:44:04 -05:00
|
|
|
#include "BKE_lib_id.hh"
|
2023-08-02 15:00:40 +02:00
|
|
|
#include "BKE_lib_override.hh"
|
2024-01-18 12:20:42 +01:00
|
|
|
#include "BKE_lib_query.hh"
|
2023-11-30 19:51:22 +01:00
|
|
|
#include "BKE_lib_remap.hh"
|
2023-12-01 19:43:16 +01:00
|
|
|
#include "BKE_main.hh"
|
2023-11-27 16:21:49 +01:00
|
|
|
#include "BKE_main_idmap.hh"
|
|
|
|
|
#include "BKE_main_namemap.hh"
|
2020-12-14 13:39:41 +01:00
|
|
|
#include "BKE_preferences.h"
|
2016-04-24 22:42:41 +10:00
|
|
|
#include "BKE_report.h"
|
|
|
|
|
#include "BKE_scene.h"
|
2023-09-25 17:48:21 -04:00
|
|
|
#include "BKE_screen.hh"
|
2019-07-31 21:46:13 +10:00
|
|
|
#include "BKE_studiolight.h"
|
2024-01-15 12:26:09 -05:00
|
|
|
#include "BKE_undo_system.hh"
|
Main Workspace Integration
This commit does the main integration of workspaces, which is a design we agreed on during the 2.8 UI workshop (see https://wiki.blender.org/index.php/Dev:2.8/UI/Workshop_Writeup)
Workspaces should generally be stable, I'm not aware of any remaining bugs (or I've forgotten them :) ). If you find any, let me know!
(Exception: mode switching button might get out of sync with actual mode in some cases, would consider that a limitation/ToDo. Needs to be resolved at some point.)
== Main Changes/Features
* Introduces the new Workspaces as data-blocks.
* Allow storing a number of custom workspaces as part of the user configuration. Needs further work to allow adding and deleting individual workspaces.
* Bundle a default workspace configuration with Blender (current screen-layouts converted to workspaces).
* Pressing button to add a workspace spawns a menu to select between "Duplicate Current" and the workspaces from the user configuration. If no workspaces are stored in the user configuration, the default workspaces are listed instead.
* Store screen-layouts (`bScreen`) per workspace.
* Store an active screen-layout per workspace. Changing the workspace will enable this layout.
* Store active mode in workspace. Changing the workspace will also enter the mode of the new workspace. (Note that we still store the active mode in the object, moving this completely to workspaces is a separate project.)
* Store an active render layer per workspace.
* Moved mode switch from 3D View header to Info Editor header.
* Store active scene in window (not directly workspace related, but overlaps quite a bit).
* Removed 'Use Global Scene' User Preference option.
* Compatibility with old files - a new workspace is created for every screen-layout of old files. Old Blender versions should be able to read files saved with workspace support as well.
* Default .blend only contains one workspace ("General").
* Support appending workspaces.
Opening files without UI and commandline rendering should work fine.
Note that the UI is temporary! We plan to introduce a new global topbar
that contains the workspace options and tabs for switching workspaces.
== Technical Notes
* Workspaces are data-blocks.
* Adding and removing `bScreen`s should be done through `ED_workspace_layout` API now.
* A workspace can be active in multiple windows at the same time.
* The mode menu (which is now in the Info Editor header) doesn't display "Grease Pencil Edit" mode anymore since its availability depends on the active editor. Will be fixed by making Grease Pencil an own object type (as planned).
* The button to change the active workspace object mode may get out of sync with the mode of the active object. Will either be resolved by moving mode out of object data, or we'll disable workspace modes again (there's a `#define USE_WORKSPACE_MODE` for that).
* Screen-layouts (`bScreen`) are IDs and thus stored in a main list-base. Had to add a wrapper `WorkSpaceLayout` so we can store them in a list-base within workspaces, too. On the long run we could completely replace `bScreen` by workspace structs.
* `WorkSpace` types use some special compiler trickery to allow marking structs and struct members as private. BKE_workspace API should be used for accessing those.
* Added scene operators `SCENE_OT_`. Was previously done through screen operators.
== BPY API Changes
* Removed `Screen.scene`, added `Window.scene`
* Removed `UserPreferencesView.use_global_scene`
* Added `Context.workspace`, `Window.workspace` and `BlendData.workspaces`
* Added `bpy.types.WorkSpace` containing `screens`, `object_mode` and `render_layer`
* Added Screen.layout_name for the layout name that'll be displayed in the UI (may differ from internal name)
== What's left?
* There are a few open design questions (T50521). We should find the needed answers and implement them.
* Allow adding and removing individual workspaces from workspace configuration (needs UI design).
* Get the override system ready and support overrides per workspace.
* Support custom UI setups as part of workspaces (hidden panels, hidden buttons, customizable toolbars, etc).
* Allow enabling add-ons per workspace.
* Support custom workspace keymaps.
* Remove special exception for workspaces in linking code (so they're always appended, never linked). Depends on a few things, so best to solve later.
* Get the topbar done.
* Workspaces need a proper icon, current one is just a placeholder :)
Reviewed By: campbellbarton, mont29
Tags: #user_interface, #bf_blender_2.8
Maniphest Tasks: T50521
Differential Revision: https://developer.blender.org/D2451
2017-06-01 19:56:58 +02:00
|
|
|
#include "BKE_workspace.h"
|
2016-04-24 22:42:41 +10:00
|
|
|
|
|
|
|
|
#include "BLO_readfile.h"
|
2023-08-28 15:01:05 +02:00
|
|
|
#include "BLO_writefile.hh"
|
2016-04-24 22:42:41 +10:00
|
|
|
|
2023-08-10 22:40:27 +02:00
|
|
|
#include "RNA_access.hh"
|
2016-04-24 22:42:41 +10:00
|
|
|
|
|
|
|
|
#include "RE_pipeline.h"
|
|
|
|
|
|
|
|
|
|
#ifdef WITH_PYTHON
|
|
|
|
|
# include "BPY_extern.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
2023-03-16 12:56:55 +01:00
|
|
|
/** \name Blend/Library Paths
|
|
|
|
|
* \{ */
|
|
|
|
|
|
2023-03-17 16:44:03 +11:00
|
|
|
bool BKE_blendfile_extension_check(const char *str)
|
2023-03-16 12:56:55 +01:00
|
|
|
{
|
|
|
|
|
const char *ext_test[4] = {".blend", ".ble", ".blend.gz", nullptr};
|
|
|
|
|
return BLI_path_extension_check_array(str, ext_test);
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-17 16:44:03 +11:00
|
|
|
bool BKE_blendfile_library_path_explode(const char *path,
|
|
|
|
|
char *r_dir,
|
|
|
|
|
char **r_group,
|
|
|
|
|
char **r_name)
|
2023-03-16 12:56:55 +01:00
|
|
|
{
|
|
|
|
|
/* We might get some data names with slashes,
|
|
|
|
|
* so we have to go up in path until we find blend file itself,
|
|
|
|
|
* then we know next path item is group, and everything else is data name. */
|
|
|
|
|
char *slash = nullptr, *prev_slash = nullptr, c = '\0';
|
|
|
|
|
|
|
|
|
|
r_dir[0] = '\0';
|
|
|
|
|
if (r_group) {
|
|
|
|
|
*r_group = nullptr;
|
|
|
|
|
}
|
|
|
|
|
if (r_name) {
|
|
|
|
|
*r_name = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* if path leads to an existing directory, we can be sure we're not (in) a library */
|
|
|
|
|
if (BLI_is_dir(path)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-16 15:05:52 +01:00
|
|
|
BLI_strncpy(r_dir, path, FILE_MAX_LIBEXTRA);
|
2023-03-16 12:56:55 +01:00
|
|
|
|
|
|
|
|
while ((slash = (char *)BLI_path_slash_rfind(r_dir))) {
|
|
|
|
|
char tc = *slash;
|
|
|
|
|
*slash = '\0';
|
2023-03-17 16:44:03 +11:00
|
|
|
if (BKE_blendfile_extension_check(r_dir) && BLI_is_file(r_dir)) {
|
2023-03-16 12:56:55 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (STREQ(r_dir, BLO_EMBEDDED_STARTUP_BLEND)) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (prev_slash) {
|
|
|
|
|
*prev_slash = c;
|
|
|
|
|
}
|
|
|
|
|
prev_slash = slash;
|
|
|
|
|
c = tc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!slash) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (slash[1] != '\0') {
|
|
|
|
|
BLI_assert(strlen(slash + 1) < BLO_GROUP_MAX);
|
|
|
|
|
if (r_group) {
|
|
|
|
|
*r_group = slash + 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (prev_slash && (prev_slash[1] != '\0')) {
|
|
|
|
|
BLI_assert(strlen(prev_slash + 1) < MAX_ID_NAME - 2);
|
|
|
|
|
if (r_name) {
|
|
|
|
|
*r_name = prev_slash + 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-24 14:48:27 +02:00
|
|
|
bool BKE_blendfile_is_readable(const char *path, ReportList *reports)
|
|
|
|
|
{
|
|
|
|
|
BlendFileReadReport readfile_reports;
|
|
|
|
|
readfile_reports.reports = reports;
|
|
|
|
|
BlendHandle *bh = BLO_blendhandle_from_file(path, &readfile_reports);
|
|
|
|
|
if (bh != nullptr) {
|
|
|
|
|
BLO_blendhandle_close(bh);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-16 12:56:55 +01:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
2022-10-05 15:30:42 +11:00
|
|
|
/** \name Blend File IO (High Level)
|
2016-04-24 22:42:41 +10:00
|
|
|
* \{ */
|
|
|
|
|
|
2023-01-23 00:32:39 +01:00
|
|
|
static bool foreach_path_clean_cb(BPathForeachPathData * /*bpath_data*/,
|
Refactor BKE_bpath module.
The main goal of this refactor is to make BPath module use `IDTypeInfo`,
and move each ID-specific part of the `foreach_path` looper into their
own IDTypeInfo struct, using a new `foreach_path` callback.
Additionally, following improvements/cleanups are included:
* Attempt to get better, more consistent namings.
** In particular, move from `path_visitor` to more standard `foreach_path`.
* Update and extend documentation.
** API doc was moved to header, according to recent discussions on this
topic.
* Remove `BKE_bpath_relocate_visitor` from API, this is specific
callback that belongs in `lib_id.c` user code.
NOTE: This commit is expected to be 100% non-behavioral-change. This
implies that several potential further changes were only noted as
comments (like using a more generic solution for
`lib_id_library_local_paths`, addressing inconsistencies like path of
packed libraries always being skipped, regardless of the
`BKE_BPATH_FOREACH_PATH_SKIP_PACKED` `eBPathForeachFlag` flag value,
etc.).
NOTE: basic unittests were added to master already in
rBdcc500e5a265093bc9cc.
Reviewed By: brecht
Differential Revision: https://developer.blender.org/D13381
2021-11-29 14:20:58 +01:00
|
|
|
char *path_dst,
|
2023-06-23 10:09:01 +10:00
|
|
|
size_t path_dst_maxncpy,
|
Refactor BKE_bpath module.
The main goal of this refactor is to make BPath module use `IDTypeInfo`,
and move each ID-specific part of the `foreach_path` looper into their
own IDTypeInfo struct, using a new `foreach_path` callback.
Additionally, following improvements/cleanups are included:
* Attempt to get better, more consistent namings.
** In particular, move from `path_visitor` to more standard `foreach_path`.
* Update and extend documentation.
** API doc was moved to header, according to recent discussions on this
topic.
* Remove `BKE_bpath_relocate_visitor` from API, this is specific
callback that belongs in `lib_id.c` user code.
NOTE: This commit is expected to be 100% non-behavioral-change. This
implies that several potential further changes were only noted as
comments (like using a more generic solution for
`lib_id_library_local_paths`, addressing inconsistencies like path of
packed libraries always being skipped, regardless of the
`BKE_BPATH_FOREACH_PATH_SKIP_PACKED` `eBPathForeachFlag` flag value,
etc.).
NOTE: basic unittests were added to master already in
rBdcc500e5a265093bc9cc.
Reviewed By: brecht
Differential Revision: https://developer.blender.org/D13381
2021-11-29 14:20:58 +01:00
|
|
|
const char *path_src)
|
2016-04-24 22:42:41 +10:00
|
|
|
{
|
2023-06-23 10:09:01 +10:00
|
|
|
BLI_strncpy(path_dst, path_src, path_dst_maxncpy);
|
2020-04-07 12:02:21 +10:00
|
|
|
BLI_path_slash_native(path_dst);
|
2016-04-24 22:42:41 +10:00
|
|
|
return !STREQ(path_dst, path_src);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* make sure path names are correct for OS */
|
Refactor BKE_bpath module.
The main goal of this refactor is to make BPath module use `IDTypeInfo`,
and move each ID-specific part of the `foreach_path` looper into their
own IDTypeInfo struct, using a new `foreach_path` callback.
Additionally, following improvements/cleanups are included:
* Attempt to get better, more consistent namings.
** In particular, move from `path_visitor` to more standard `foreach_path`.
* Update and extend documentation.
** API doc was moved to header, according to recent discussions on this
topic.
* Remove `BKE_bpath_relocate_visitor` from API, this is specific
callback that belongs in `lib_id.c` user code.
NOTE: This commit is expected to be 100% non-behavioral-change. This
implies that several potential further changes were only noted as
comments (like using a more generic solution for
`lib_id_library_local_paths`, addressing inconsistencies like path of
packed libraries always being skipped, regardless of the
`BKE_BPATH_FOREACH_PATH_SKIP_PACKED` `eBPathForeachFlag` flag value,
etc.).
NOTE: basic unittests were added to master already in
rBdcc500e5a265093bc9cc.
Reviewed By: brecht
Differential Revision: https://developer.blender.org/D13381
2021-11-29 14:20:58 +01:00
|
|
|
static void clean_paths(Main *bmain)
|
2016-04-24 22:42:41 +10:00
|
|
|
{
|
2023-01-23 00:32:39 +01:00
|
|
|
BPathForeachPathData foreach_path_data{};
|
|
|
|
|
foreach_path_data.bmain = bmain;
|
|
|
|
|
foreach_path_data.callback_function = foreach_path_clean_cb;
|
|
|
|
|
foreach_path_data.flag = BKE_BPATH_FOREACH_PATH_SKIP_MULTIFILE;
|
|
|
|
|
foreach_path_data.user_data = nullptr;
|
|
|
|
|
|
|
|
|
|
BKE_bpath_foreach_path_main(&foreach_path_data);
|
2016-04-24 22:42:41 +10:00
|
|
|
|
Refactor BKE_bpath module.
The main goal of this refactor is to make BPath module use `IDTypeInfo`,
and move each ID-specific part of the `foreach_path` looper into their
own IDTypeInfo struct, using a new `foreach_path` callback.
Additionally, following improvements/cleanups are included:
* Attempt to get better, more consistent namings.
** In particular, move from `path_visitor` to more standard `foreach_path`.
* Update and extend documentation.
** API doc was moved to header, according to recent discussions on this
topic.
* Remove `BKE_bpath_relocate_visitor` from API, this is specific
callback that belongs in `lib_id.c` user code.
NOTE: This commit is expected to be 100% non-behavioral-change. This
implies that several potential further changes were only noted as
comments (like using a more generic solution for
`lib_id_library_local_paths`, addressing inconsistencies like path of
packed libraries always being skipped, regardless of the
`BKE_BPATH_FOREACH_PATH_SKIP_PACKED` `eBPathForeachFlag` flag value,
etc.).
NOTE: basic unittests were added to master already in
rBdcc500e5a265093bc9cc.
Reviewed By: brecht
Differential Revision: https://developer.blender.org/D13381
2021-11-29 14:20:58 +01:00
|
|
|
LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) {
|
2020-04-07 12:02:21 +10:00
|
|
|
BLI_path_slash_native(scene->r.pic);
|
2016-04-24 22:42:41 +10:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool wm_scene_is_visible(wmWindowManager *wm, Scene *scene)
|
|
|
|
|
{
|
2023-08-04 08:51:13 +10:00
|
|
|
LISTBASE_FOREACH (wmWindow *, win, &wm->windows) {
|
Main Workspace Integration
This commit does the main integration of workspaces, which is a design we agreed on during the 2.8 UI workshop (see https://wiki.blender.org/index.php/Dev:2.8/UI/Workshop_Writeup)
Workspaces should generally be stable, I'm not aware of any remaining bugs (or I've forgotten them :) ). If you find any, let me know!
(Exception: mode switching button might get out of sync with actual mode in some cases, would consider that a limitation/ToDo. Needs to be resolved at some point.)
== Main Changes/Features
* Introduces the new Workspaces as data-blocks.
* Allow storing a number of custom workspaces as part of the user configuration. Needs further work to allow adding and deleting individual workspaces.
* Bundle a default workspace configuration with Blender (current screen-layouts converted to workspaces).
* Pressing button to add a workspace spawns a menu to select between "Duplicate Current" and the workspaces from the user configuration. If no workspaces are stored in the user configuration, the default workspaces are listed instead.
* Store screen-layouts (`bScreen`) per workspace.
* Store an active screen-layout per workspace. Changing the workspace will enable this layout.
* Store active mode in workspace. Changing the workspace will also enter the mode of the new workspace. (Note that we still store the active mode in the object, moving this completely to workspaces is a separate project.)
* Store an active render layer per workspace.
* Moved mode switch from 3D View header to Info Editor header.
* Store active scene in window (not directly workspace related, but overlaps quite a bit).
* Removed 'Use Global Scene' User Preference option.
* Compatibility with old files - a new workspace is created for every screen-layout of old files. Old Blender versions should be able to read files saved with workspace support as well.
* Default .blend only contains one workspace ("General").
* Support appending workspaces.
Opening files without UI and commandline rendering should work fine.
Note that the UI is temporary! We plan to introduce a new global topbar
that contains the workspace options and tabs for switching workspaces.
== Technical Notes
* Workspaces are data-blocks.
* Adding and removing `bScreen`s should be done through `ED_workspace_layout` API now.
* A workspace can be active in multiple windows at the same time.
* The mode menu (which is now in the Info Editor header) doesn't display "Grease Pencil Edit" mode anymore since its availability depends on the active editor. Will be fixed by making Grease Pencil an own object type (as planned).
* The button to change the active workspace object mode may get out of sync with the mode of the active object. Will either be resolved by moving mode out of object data, or we'll disable workspace modes again (there's a `#define USE_WORKSPACE_MODE` for that).
* Screen-layouts (`bScreen`) are IDs and thus stored in a main list-base. Had to add a wrapper `WorkSpaceLayout` so we can store them in a list-base within workspaces, too. On the long run we could completely replace `bScreen` by workspace structs.
* `WorkSpace` types use some special compiler trickery to allow marking structs and struct members as private. BKE_workspace API should be used for accessing those.
* Added scene operators `SCENE_OT_`. Was previously done through screen operators.
== BPY API Changes
* Removed `Screen.scene`, added `Window.scene`
* Removed `UserPreferencesView.use_global_scene`
* Added `Context.workspace`, `Window.workspace` and `BlendData.workspaces`
* Added `bpy.types.WorkSpace` containing `screens`, `object_mode` and `render_layer`
* Added Screen.layout_name for the layout name that'll be displayed in the UI (may differ from internal name)
== What's left?
* There are a few open design questions (T50521). We should find the needed answers and implement them.
* Allow adding and removing individual workspaces from workspace configuration (needs UI design).
* Get the override system ready and support overrides per workspace.
* Support custom UI setups as part of workspaces (hidden panels, hidden buttons, customizable toolbars, etc).
* Allow enabling add-ons per workspace.
* Support custom workspace keymaps.
* Remove special exception for workspaces in linking code (so they're always appended, never linked). Depends on a few things, so best to solve later.
* Get the topbar done.
* Workspaces need a proper icon, current one is just a placeholder :)
Reviewed By: campbellbarton, mont29
Tags: #user_interface, #bf_blender_2.8
Maniphest Tasks: T50521
Differential Revision: https://developer.blender.org/D2451
2017-06-01 19:56:58 +02:00
|
|
|
if (win->scene == scene) {
|
2016-04-24 22:42:41 +10:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-10 18:46:13 +10:00
|
|
|
static void setup_app_userdef(BlendFileData *bfd)
|
|
|
|
|
{
|
|
|
|
|
if (bfd->user) {
|
|
|
|
|
/* only here free userdef themes... */
|
|
|
|
|
BKE_blender_userdef_data_set_and_free(bfd->user);
|
2023-01-23 00:32:39 +01:00
|
|
|
bfd->user = nullptr;
|
2019-05-10 18:46:13 +10:00
|
|
|
|
2023-06-08 10:33:50 +10:00
|
|
|
/* Security issue: any blend file could include a #BLO_CODE_USER block.
|
2019-05-10 18:46:13 +10:00
|
|
|
*
|
2023-06-08 10:33:50 +10:00
|
|
|
* Preferences are loaded from #BLENDER_STARTUP_FILE and later on load #BLENDER_USERPREF_FILE,
|
|
|
|
|
* to load the preferences defined in the users home directory.
|
2019-05-10 18:46:13 +10:00
|
|
|
*
|
|
|
|
|
* This means we will never accidentally (or maliciously)
|
2023-06-08 10:33:50 +10:00
|
|
|
* enable scripts auto-execution by loading a `.blend` file. */
|
2019-05-10 18:46:13 +10:00
|
|
|
U.flag |= USER_SCRIPT_AUTOEXEC_DISABLE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-21 11:28:58 +10:00
|
|
|
/**
|
|
|
|
|
* Helper struct to manage IDs that are re-used across blend-file loading (i.e. moved from the old
|
|
|
|
|
* Main the new one).
|
Readfile: Refactor several parts of the process
This commit affects:
* Reading undo steps from memfile (aka 'Global Undo');
* Handling of UI IDs (WindowManager, Workspaces and Screens) when
opening a .blend file.
While no major changes are expected from a user PoV, there may be some
unexpected changes in rare edge-cases. None has been identified so far.
Undo step loading should be marginally faster (`setup_app_data` itself
is 2-3 times faster, as it does not do remapping anymore, which makes the
whole 'read undo step' process about 20% faster - but the most
time-consuming step on undo is the depsgraph processing, which remains
unchanged here).
This commit also solves some bugs (crashes) in some relatively uncommon
cases, like e.g. if the WM had an IDProperty pointing at an object and
UI is not loaded when opening a new .blend file with the 'Load UI' option
enabled (as in previous code on file opening WM ID would never be
remapped).
From a more technical side, this commit aims mainly at cleaning things
up, in preparation for the introduction of new 'no undo, no readfile'
type of handling (as part of the Brush Assets project):
- Prevent WM code from doing (too much) horrible ID 'management' on
its WM when opening a new file. It used to remove current WM from
the Main database, store it in a temporary own list, and then free
it itself...
- Trying to make the complex logic behind WM handling on file reading a
bit more easy to follow, at least way more documented in code.
- Keep the handling of 'IDs being re-used from old Main' in a single
place, as much as possible:
-- Readfile code itself in undo case (because it's more efficient,
and undo case is in a way simpler than actual .blend file
reading case). The whole `blo_lib_link_restore` block of code
is also removed.
-- (Mostly) setup_app_data code in actual file reading case.
- Sanitize the usage of the 'libmap' in readfile code in undo case
(waaaaay too many pointers were added there, which was hiding some
other issues in the related code, and potentially causing (in
rare cases) memory addresses collisions.
Pull Request: https://projects.blender.org/blender/blender/pulls/108016
2023-06-05 13:54:49 +02:00
|
|
|
*
|
2023-06-21 11:28:58 +10:00
|
|
|
* NOTE: this is only used when actually loading a real `.blend` file,
|
|
|
|
|
* loading of memfile undo steps does not need it.
|
|
|
|
|
*/
|
2023-07-02 19:37:19 +10:00
|
|
|
struct ReuseOldBMainData {
|
Readfile: Refactor several parts of the process
This commit affects:
* Reading undo steps from memfile (aka 'Global Undo');
* Handling of UI IDs (WindowManager, Workspaces and Screens) when
opening a .blend file.
While no major changes are expected from a user PoV, there may be some
unexpected changes in rare edge-cases. None has been identified so far.
Undo step loading should be marginally faster (`setup_app_data` itself
is 2-3 times faster, as it does not do remapping anymore, which makes the
whole 'read undo step' process about 20% faster - but the most
time-consuming step on undo is the depsgraph processing, which remains
unchanged here).
This commit also solves some bugs (crashes) in some relatively uncommon
cases, like e.g. if the WM had an IDProperty pointing at an object and
UI is not loaded when opening a new .blend file with the 'Load UI' option
enabled (as in previous code on file opening WM ID would never be
remapped).
From a more technical side, this commit aims mainly at cleaning things
up, in preparation for the introduction of new 'no undo, no readfile'
type of handling (as part of the Brush Assets project):
- Prevent WM code from doing (too much) horrible ID 'management' on
its WM when opening a new file. It used to remove current WM from
the Main database, store it in a temporary own list, and then free
it itself...
- Trying to make the complex logic behind WM handling on file reading a
bit more easy to follow, at least way more documented in code.
- Keep the handling of 'IDs being re-used from old Main' in a single
place, as much as possible:
-- Readfile code itself in undo case (because it's more efficient,
and undo case is in a way simpler than actual .blend file
reading case). The whole `blo_lib_link_restore` block of code
is also removed.
-- (Mostly) setup_app_data code in actual file reading case.
- Sanitize the usage of the 'libmap' in readfile code in undo case
(waaaaay too many pointers were added there, which was hiding some
other issues in the related code, and potentially causing (in
rare cases) memory addresses collisions.
Pull Request: https://projects.blender.org/blender/blender/pulls/108016
2023-06-05 13:54:49 +02:00
|
|
|
Main *new_bmain;
|
|
|
|
|
Main *old_bmain;
|
|
|
|
|
|
|
|
|
|
/** Data generated and used by calling WM code to handle keeping WM and UI IDs as best as
|
|
|
|
|
* possible across file reading.
|
|
|
|
|
*
|
|
|
|
|
* \note: May be null in undo (memfile) case.. */
|
|
|
|
|
BlendFileReadWMSetupData *wm_setup_data;
|
|
|
|
|
|
|
|
|
|
/** Storage for all remapping rules (old_id -> new_id) required by the preservation of old IDs
|
|
|
|
|
* into the new Main. */
|
|
|
|
|
IDRemapper *remapper;
|
|
|
|
|
bool is_libraries_remapped;
|
|
|
|
|
|
|
|
|
|
/** Used to find matching IDs by name/lib in new main, to remap ID usages of data ported over
|
|
|
|
|
* from old main. */
|
|
|
|
|
IDNameLib_Map *id_map;
|
2023-07-02 19:37:19 +10:00
|
|
|
};
|
Readfile: Refactor several parts of the process
This commit affects:
* Reading undo steps from memfile (aka 'Global Undo');
* Handling of UI IDs (WindowManager, Workspaces and Screens) when
opening a .blend file.
While no major changes are expected from a user PoV, there may be some
unexpected changes in rare edge-cases. None has been identified so far.
Undo step loading should be marginally faster (`setup_app_data` itself
is 2-3 times faster, as it does not do remapping anymore, which makes the
whole 'read undo step' process about 20% faster - but the most
time-consuming step on undo is the depsgraph processing, which remains
unchanged here).
This commit also solves some bugs (crashes) in some relatively uncommon
cases, like e.g. if the WM had an IDProperty pointing at an object and
UI is not loaded when opening a new .blend file with the 'Load UI' option
enabled (as in previous code on file opening WM ID would never be
remapped).
From a more technical side, this commit aims mainly at cleaning things
up, in preparation for the introduction of new 'no undo, no readfile'
type of handling (as part of the Brush Assets project):
- Prevent WM code from doing (too much) horrible ID 'management' on
its WM when opening a new file. It used to remove current WM from
the Main database, store it in a temporary own list, and then free
it itself...
- Trying to make the complex logic behind WM handling on file reading a
bit more easy to follow, at least way more documented in code.
- Keep the handling of 'IDs being re-used from old Main' in a single
place, as much as possible:
-- Readfile code itself in undo case (because it's more efficient,
and undo case is in a way simpler than actual .blend file
reading case). The whole `blo_lib_link_restore` block of code
is also removed.
-- (Mostly) setup_app_data code in actual file reading case.
- Sanitize the usage of the 'libmap' in readfile code in undo case
(waaaaay too many pointers were added there, which was hiding some
other issues in the related code, and potentially causing (in
rare cases) memory addresses collisions.
Pull Request: https://projects.blender.org/blender/blender/pulls/108016
2023-06-05 13:54:49 +02:00
|
|
|
|
2023-07-04 12:27:38 +10:00
|
|
|
/**
|
|
|
|
|
* Search for all libraries in `old_bmain` that are also in `new_bmain` (i.e. different Library
|
Readfile: Refactor several parts of the process
This commit affects:
* Reading undo steps from memfile (aka 'Global Undo');
* Handling of UI IDs (WindowManager, Workspaces and Screens) when
opening a .blend file.
While no major changes are expected from a user PoV, there may be some
unexpected changes in rare edge-cases. None has been identified so far.
Undo step loading should be marginally faster (`setup_app_data` itself
is 2-3 times faster, as it does not do remapping anymore, which makes the
whole 'read undo step' process about 20% faster - but the most
time-consuming step on undo is the depsgraph processing, which remains
unchanged here).
This commit also solves some bugs (crashes) in some relatively uncommon
cases, like e.g. if the WM had an IDProperty pointing at an object and
UI is not loaded when opening a new .blend file with the 'Load UI' option
enabled (as in previous code on file opening WM ID would never be
remapped).
From a more technical side, this commit aims mainly at cleaning things
up, in preparation for the introduction of new 'no undo, no readfile'
type of handling (as part of the Brush Assets project):
- Prevent WM code from doing (too much) horrible ID 'management' on
its WM when opening a new file. It used to remove current WM from
the Main database, store it in a temporary own list, and then free
it itself...
- Trying to make the complex logic behind WM handling on file reading a
bit more easy to follow, at least way more documented in code.
- Keep the handling of 'IDs being re-used from old Main' in a single
place, as much as possible:
-- Readfile code itself in undo case (because it's more efficient,
and undo case is in a way simpler than actual .blend file
reading case). The whole `blo_lib_link_restore` block of code
is also removed.
-- (Mostly) setup_app_data code in actual file reading case.
- Sanitize the usage of the 'libmap' in readfile code in undo case
(waaaaay too many pointers were added there, which was hiding some
other issues in the related code, and potentially causing (in
rare cases) memory addresses collisions.
Pull Request: https://projects.blender.org/blender/blender/pulls/108016
2023-06-05 13:54:49 +02:00
|
|
|
* IDs having the same absolute filepath), and create a remapping rule for these.
|
|
|
|
|
*
|
|
|
|
|
* NOTE: The case where the `old_bmain` would be a library in the newly read one is not handled
|
|
|
|
|
* here, as it does not create explicit issues. The local data from `old_bmain` is either
|
|
|
|
|
* discarded, or added to the `new_bmain` as local data as well. Worst case, there will be a
|
2023-06-07 21:45:48 +10:00
|
|
|
* double of a linked data as a local one, without any known relationships between them. In
|
Readfile: Refactor several parts of the process
This commit affects:
* Reading undo steps from memfile (aka 'Global Undo');
* Handling of UI IDs (WindowManager, Workspaces and Screens) when
opening a .blend file.
While no major changes are expected from a user PoV, there may be some
unexpected changes in rare edge-cases. None has been identified so far.
Undo step loading should be marginally faster (`setup_app_data` itself
is 2-3 times faster, as it does not do remapping anymore, which makes the
whole 'read undo step' process about 20% faster - but the most
time-consuming step on undo is the depsgraph processing, which remains
unchanged here).
This commit also solves some bugs (crashes) in some relatively uncommon
cases, like e.g. if the WM had an IDProperty pointing at an object and
UI is not loaded when opening a new .blend file with the 'Load UI' option
enabled (as in previous code on file opening WM ID would never be
remapped).
From a more technical side, this commit aims mainly at cleaning things
up, in preparation for the introduction of new 'no undo, no readfile'
type of handling (as part of the Brush Assets project):
- Prevent WM code from doing (too much) horrible ID 'management' on
its WM when opening a new file. It used to remove current WM from
the Main database, store it in a temporary own list, and then free
it itself...
- Trying to make the complex logic behind WM handling on file reading a
bit more easy to follow, at least way more documented in code.
- Keep the handling of 'IDs being re-used from old Main' in a single
place, as much as possible:
-- Readfile code itself in undo case (because it's more efficient,
and undo case is in a way simpler than actual .blend file
reading case). The whole `blo_lib_link_restore` block of code
is also removed.
-- (Mostly) setup_app_data code in actual file reading case.
- Sanitize the usage of the 'libmap' in readfile code in undo case
(waaaaay too many pointers were added there, which was hiding some
other issues in the related code, and potentially causing (in
rare cases) memory addresses collisions.
Pull Request: https://projects.blender.org/blender/blender/pulls/108016
2023-06-05 13:54:49 +02:00
|
|
|
* practice, this latter case is not expected to commonly happen.
|
|
|
|
|
*/
|
|
|
|
|
static IDRemapper *reuse_bmain_data_remapper_ensure(ReuseOldBMainData *reuse_data)
|
|
|
|
|
{
|
|
|
|
|
if (reuse_data->is_libraries_remapped) {
|
|
|
|
|
return reuse_data->remapper;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (reuse_data->remapper == nullptr) {
|
|
|
|
|
reuse_data->remapper = BKE_id_remapper_create();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Main *new_bmain = reuse_data->new_bmain;
|
|
|
|
|
Main *old_bmain = reuse_data->old_bmain;
|
|
|
|
|
IDRemapper *remapper = reuse_data->remapper;
|
|
|
|
|
|
|
|
|
|
LISTBASE_FOREACH (Library *, old_lib_iter, &old_bmain->libraries) {
|
2023-08-01 21:15:52 +10:00
|
|
|
/* In case newly opened `new_bmain` is a library of the `old_bmain`, remap it to null, since a
|
Readfile: Refactor several parts of the process
This commit affects:
* Reading undo steps from memfile (aka 'Global Undo');
* Handling of UI IDs (WindowManager, Workspaces and Screens) when
opening a .blend file.
While no major changes are expected from a user PoV, there may be some
unexpected changes in rare edge-cases. None has been identified so far.
Undo step loading should be marginally faster (`setup_app_data` itself
is 2-3 times faster, as it does not do remapping anymore, which makes the
whole 'read undo step' process about 20% faster - but the most
time-consuming step on undo is the depsgraph processing, which remains
unchanged here).
This commit also solves some bugs (crashes) in some relatively uncommon
cases, like e.g. if the WM had an IDProperty pointing at an object and
UI is not loaded when opening a new .blend file with the 'Load UI' option
enabled (as in previous code on file opening WM ID would never be
remapped).
From a more technical side, this commit aims mainly at cleaning things
up, in preparation for the introduction of new 'no undo, no readfile'
type of handling (as part of the Brush Assets project):
- Prevent WM code from doing (too much) horrible ID 'management' on
its WM when opening a new file. It used to remove current WM from
the Main database, store it in a temporary own list, and then free
it itself...
- Trying to make the complex logic behind WM handling on file reading a
bit more easy to follow, at least way more documented in code.
- Keep the handling of 'IDs being re-used from old Main' in a single
place, as much as possible:
-- Readfile code itself in undo case (because it's more efficient,
and undo case is in a way simpler than actual .blend file
reading case). The whole `blo_lib_link_restore` block of code
is also removed.
-- (Mostly) setup_app_data code in actual file reading case.
- Sanitize the usage of the 'libmap' in readfile code in undo case
(waaaaay too many pointers were added there, which was hiding some
other issues in the related code, and potentially causing (in
rare cases) memory addresses collisions.
Pull Request: https://projects.blender.org/blender/blender/pulls/108016
2023-06-05 13:54:49 +02:00
|
|
|
* file should never ever have linked data from itself. */
|
|
|
|
|
if (STREQ(old_lib_iter->filepath_abs, new_bmain->filepath)) {
|
|
|
|
|
BKE_id_remapper_add(remapper, &old_lib_iter->id, nullptr);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* NOTE: Although this is quadratic complexity, it is not expected to be an issue in practice:
|
|
|
|
|
* - Files using more than a few tens of libraries are extremely rare.
|
|
|
|
|
* - This code is only executed once for every file reading (not on undos).
|
|
|
|
|
*/
|
|
|
|
|
LISTBASE_FOREACH (Library *, new_lib_iter, &new_bmain->libraries) {
|
|
|
|
|
if (!STREQ(old_lib_iter->filepath_abs, new_lib_iter->filepath_abs)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BKE_id_remapper_add(remapper, &old_lib_iter->id, &new_lib_iter->id);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
reuse_data->is_libraries_remapped = true;
|
|
|
|
|
return reuse_data->remapper;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool reuse_bmain_data_remapper_is_id_remapped(IDRemapper *remapper, ID *id)
|
|
|
|
|
{
|
|
|
|
|
IDRemapperApplyResult result = BKE_id_remapper_get_mapping_result(
|
|
|
|
|
remapper, id, ID_REMAP_APPLY_DEFAULT, nullptr);
|
|
|
|
|
if (ELEM(result, ID_REMAP_RESULT_SOURCE_REMAPPED, ID_REMAP_RESULT_SOURCE_UNASSIGNED)) {
|
2023-08-01 21:15:52 +10:00
|
|
|
/* ID is already remapped to its matching ID in the new main, or explicitly remapped to null,
|
Readfile: Refactor several parts of the process
This commit affects:
* Reading undo steps from memfile (aka 'Global Undo');
* Handling of UI IDs (WindowManager, Workspaces and Screens) when
opening a .blend file.
While no major changes are expected from a user PoV, there may be some
unexpected changes in rare edge-cases. None has been identified so far.
Undo step loading should be marginally faster (`setup_app_data` itself
is 2-3 times faster, as it does not do remapping anymore, which makes the
whole 'read undo step' process about 20% faster - but the most
time-consuming step on undo is the depsgraph processing, which remains
unchanged here).
This commit also solves some bugs (crashes) in some relatively uncommon
cases, like e.g. if the WM had an IDProperty pointing at an object and
UI is not loaded when opening a new .blend file with the 'Load UI' option
enabled (as in previous code on file opening WM ID would never be
remapped).
From a more technical side, this commit aims mainly at cleaning things
up, in preparation for the introduction of new 'no undo, no readfile'
type of handling (as part of the Brush Assets project):
- Prevent WM code from doing (too much) horrible ID 'management' on
its WM when opening a new file. It used to remove current WM from
the Main database, store it in a temporary own list, and then free
it itself...
- Trying to make the complex logic behind WM handling on file reading a
bit more easy to follow, at least way more documented in code.
- Keep the handling of 'IDs being re-used from old Main' in a single
place, as much as possible:
-- Readfile code itself in undo case (because it's more efficient,
and undo case is in a way simpler than actual .blend file
reading case). The whole `blo_lib_link_restore` block of code
is also removed.
-- (Mostly) setup_app_data code in actual file reading case.
- Sanitize the usage of the 'libmap' in readfile code in undo case
(waaaaay too many pointers were added there, which was hiding some
other issues in the related code, and potentially causing (in
rare cases) memory addresses collisions.
Pull Request: https://projects.blender.org/blender/blender/pulls/108016
2023-06-05 13:54:49 +02:00
|
|
|
* nothing else to do here. */
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
BLI_assert_msg(result != ID_REMAP_RESULT_SOURCE_NOT_MAPPABLE,
|
2023-08-01 21:15:52 +10:00
|
|
|
"There should never be a non-mappable (i.e. null) input here.");
|
Readfile: Refactor several parts of the process
This commit affects:
* Reading undo steps from memfile (aka 'Global Undo');
* Handling of UI IDs (WindowManager, Workspaces and Screens) when
opening a .blend file.
While no major changes are expected from a user PoV, there may be some
unexpected changes in rare edge-cases. None has been identified so far.
Undo step loading should be marginally faster (`setup_app_data` itself
is 2-3 times faster, as it does not do remapping anymore, which makes the
whole 'read undo step' process about 20% faster - but the most
time-consuming step on undo is the depsgraph processing, which remains
unchanged here).
This commit also solves some bugs (crashes) in some relatively uncommon
cases, like e.g. if the WM had an IDProperty pointing at an object and
UI is not loaded when opening a new .blend file with the 'Load UI' option
enabled (as in previous code on file opening WM ID would never be
remapped).
From a more technical side, this commit aims mainly at cleaning things
up, in preparation for the introduction of new 'no undo, no readfile'
type of handling (as part of the Brush Assets project):
- Prevent WM code from doing (too much) horrible ID 'management' on
its WM when opening a new file. It used to remove current WM from
the Main database, store it in a temporary own list, and then free
it itself...
- Trying to make the complex logic behind WM handling on file reading a
bit more easy to follow, at least way more documented in code.
- Keep the handling of 'IDs being re-used from old Main' in a single
place, as much as possible:
-- Readfile code itself in undo case (because it's more efficient,
and undo case is in a way simpler than actual .blend file
reading case). The whole `blo_lib_link_restore` block of code
is also removed.
-- (Mostly) setup_app_data code in actual file reading case.
- Sanitize the usage of the 'libmap' in readfile code in undo case
(waaaaay too many pointers were added there, which was hiding some
other issues in the related code, and potentially causing (in
rare cases) memory addresses collisions.
Pull Request: https://projects.blender.org/blender/blender/pulls/108016
2023-06-05 13:54:49 +02:00
|
|
|
BLI_assert(result == ID_REMAP_RESULT_SOURCE_UNAVAILABLE);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-30 14:15:11 +11:00
|
|
|
/**
|
|
|
|
|
* Does a complete replacement of data in `new_bmain` by data from `old_bmain. Original new data
|
Readfile: Refactor several parts of the process
This commit affects:
* Reading undo steps from memfile (aka 'Global Undo');
* Handling of UI IDs (WindowManager, Workspaces and Screens) when
opening a .blend file.
While no major changes are expected from a user PoV, there may be some
unexpected changes in rare edge-cases. None has been identified so far.
Undo step loading should be marginally faster (`setup_app_data` itself
is 2-3 times faster, as it does not do remapping anymore, which makes the
whole 'read undo step' process about 20% faster - but the most
time-consuming step on undo is the depsgraph processing, which remains
unchanged here).
This commit also solves some bugs (crashes) in some relatively uncommon
cases, like e.g. if the WM had an IDProperty pointing at an object and
UI is not loaded when opening a new .blend file with the 'Load UI' option
enabled (as in previous code on file opening WM ID would never be
remapped).
From a more technical side, this commit aims mainly at cleaning things
up, in preparation for the introduction of new 'no undo, no readfile'
type of handling (as part of the Brush Assets project):
- Prevent WM code from doing (too much) horrible ID 'management' on
its WM when opening a new file. It used to remove current WM from
the Main database, store it in a temporary own list, and then free
it itself...
- Trying to make the complex logic behind WM handling on file reading a
bit more easy to follow, at least way more documented in code.
- Keep the handling of 'IDs being re-used from old Main' in a single
place, as much as possible:
-- Readfile code itself in undo case (because it's more efficient,
and undo case is in a way simpler than actual .blend file
reading case). The whole `blo_lib_link_restore` block of code
is also removed.
-- (Mostly) setup_app_data code in actual file reading case.
- Sanitize the usage of the 'libmap' in readfile code in undo case
(waaaaay too many pointers were added there, which was hiding some
other issues in the related code, and potentially causing (in
rare cases) memory addresses collisions.
Pull Request: https://projects.blender.org/blender/blender/pulls/108016
2023-06-05 13:54:49 +02:00
|
|
|
* are moved to the `old_bmain`, and will be freed together with it.
|
|
|
|
|
*
|
|
|
|
|
* WARNING: Currently only expects to work on local data, won't work properly if some of the IDs of
|
|
|
|
|
* given type are linked.
|
|
|
|
|
*
|
|
|
|
|
* NOTE: There is no support at all for potential dependencies of the IDs moved around. This is not
|
2023-11-30 14:15:11 +11:00
|
|
|
* expected to be necessary for the current use cases (UI-related IDs).
|
|
|
|
|
*/
|
Readfile: Refactor several parts of the process
This commit affects:
* Reading undo steps from memfile (aka 'Global Undo');
* Handling of UI IDs (WindowManager, Workspaces and Screens) when
opening a .blend file.
While no major changes are expected from a user PoV, there may be some
unexpected changes in rare edge-cases. None has been identified so far.
Undo step loading should be marginally faster (`setup_app_data` itself
is 2-3 times faster, as it does not do remapping anymore, which makes the
whole 'read undo step' process about 20% faster - but the most
time-consuming step on undo is the depsgraph processing, which remains
unchanged here).
This commit also solves some bugs (crashes) in some relatively uncommon
cases, like e.g. if the WM had an IDProperty pointing at an object and
UI is not loaded when opening a new .blend file with the 'Load UI' option
enabled (as in previous code on file opening WM ID would never be
remapped).
From a more technical side, this commit aims mainly at cleaning things
up, in preparation for the introduction of new 'no undo, no readfile'
type of handling (as part of the Brush Assets project):
- Prevent WM code from doing (too much) horrible ID 'management' on
its WM when opening a new file. It used to remove current WM from
the Main database, store it in a temporary own list, and then free
it itself...
- Trying to make the complex logic behind WM handling on file reading a
bit more easy to follow, at least way more documented in code.
- Keep the handling of 'IDs being re-used from old Main' in a single
place, as much as possible:
-- Readfile code itself in undo case (because it's more efficient,
and undo case is in a way simpler than actual .blend file
reading case). The whole `blo_lib_link_restore` block of code
is also removed.
-- (Mostly) setup_app_data code in actual file reading case.
- Sanitize the usage of the 'libmap' in readfile code in undo case
(waaaaay too many pointers were added there, which was hiding some
other issues in the related code, and potentially causing (in
rare cases) memory addresses collisions.
Pull Request: https://projects.blender.org/blender/blender/pulls/108016
2023-06-05 13:54:49 +02:00
|
|
|
static void swap_old_bmain_data_for_blendfile(ReuseOldBMainData *reuse_data, const short id_code)
|
|
|
|
|
{
|
|
|
|
|
Main *new_bmain = reuse_data->new_bmain;
|
|
|
|
|
Main *old_bmain = reuse_data->old_bmain;
|
|
|
|
|
|
|
|
|
|
ListBase *new_lb = which_libbase(new_bmain, id_code);
|
|
|
|
|
ListBase *old_lb = which_libbase(old_bmain, id_code);
|
|
|
|
|
|
|
|
|
|
IDRemapper *remapper = reuse_bmain_data_remapper_ensure(reuse_data);
|
|
|
|
|
|
|
|
|
|
/* NOTE: Full swapping is only supported for ID types that are assumed to be only local
|
|
|
|
|
* data-blocks (like UI-like ones). Otherwise, the swapping could fail in many funny ways. */
|
|
|
|
|
BLI_assert(BLI_listbase_is_empty(old_lb) || !ID_IS_LINKED(old_lb->last));
|
|
|
|
|
BLI_assert(BLI_listbase_is_empty(new_lb) || !ID_IS_LINKED(new_lb->last));
|
|
|
|
|
|
2024-01-31 21:12:16 -05:00
|
|
|
std::swap(*new_lb, *old_lb);
|
Readfile: Refactor several parts of the process
This commit affects:
* Reading undo steps from memfile (aka 'Global Undo');
* Handling of UI IDs (WindowManager, Workspaces and Screens) when
opening a .blend file.
While no major changes are expected from a user PoV, there may be some
unexpected changes in rare edge-cases. None has been identified so far.
Undo step loading should be marginally faster (`setup_app_data` itself
is 2-3 times faster, as it does not do remapping anymore, which makes the
whole 'read undo step' process about 20% faster - but the most
time-consuming step on undo is the depsgraph processing, which remains
unchanged here).
This commit also solves some bugs (crashes) in some relatively uncommon
cases, like e.g. if the WM had an IDProperty pointing at an object and
UI is not loaded when opening a new .blend file with the 'Load UI' option
enabled (as in previous code on file opening WM ID would never be
remapped).
From a more technical side, this commit aims mainly at cleaning things
up, in preparation for the introduction of new 'no undo, no readfile'
type of handling (as part of the Brush Assets project):
- Prevent WM code from doing (too much) horrible ID 'management' on
its WM when opening a new file. It used to remove current WM from
the Main database, store it in a temporary own list, and then free
it itself...
- Trying to make the complex logic behind WM handling on file reading a
bit more easy to follow, at least way more documented in code.
- Keep the handling of 'IDs being re-used from old Main' in a single
place, as much as possible:
-- Readfile code itself in undo case (because it's more efficient,
and undo case is in a way simpler than actual .blend file
reading case). The whole `blo_lib_link_restore` block of code
is also removed.
-- (Mostly) setup_app_data code in actual file reading case.
- Sanitize the usage of the 'libmap' in readfile code in undo case
(waaaaay too many pointers were added there, which was hiding some
other issues in the related code, and potentially causing (in
rare cases) memory addresses collisions.
Pull Request: https://projects.blender.org/blender/blender/pulls/108016
2023-06-05 13:54:49 +02:00
|
|
|
|
|
|
|
|
/* TODO: Could add per-IDType control over namemaps clearing, if this becomes a performances
|
|
|
|
|
* concern. */
|
2023-07-08 16:16:49 +02:00
|
|
|
BKE_main_namemap_clear(old_bmain);
|
|
|
|
|
BKE_main_namemap_clear(new_bmain);
|
Readfile: Refactor several parts of the process
This commit affects:
* Reading undo steps from memfile (aka 'Global Undo');
* Handling of UI IDs (WindowManager, Workspaces and Screens) when
opening a .blend file.
While no major changes are expected from a user PoV, there may be some
unexpected changes in rare edge-cases. None has been identified so far.
Undo step loading should be marginally faster (`setup_app_data` itself
is 2-3 times faster, as it does not do remapping anymore, which makes the
whole 'read undo step' process about 20% faster - but the most
time-consuming step on undo is the depsgraph processing, which remains
unchanged here).
This commit also solves some bugs (crashes) in some relatively uncommon
cases, like e.g. if the WM had an IDProperty pointing at an object and
UI is not loaded when opening a new .blend file with the 'Load UI' option
enabled (as in previous code on file opening WM ID would never be
remapped).
From a more technical side, this commit aims mainly at cleaning things
up, in preparation for the introduction of new 'no undo, no readfile'
type of handling (as part of the Brush Assets project):
- Prevent WM code from doing (too much) horrible ID 'management' on
its WM when opening a new file. It used to remove current WM from
the Main database, store it in a temporary own list, and then free
it itself...
- Trying to make the complex logic behind WM handling on file reading a
bit more easy to follow, at least way more documented in code.
- Keep the handling of 'IDs being re-used from old Main' in a single
place, as much as possible:
-- Readfile code itself in undo case (because it's more efficient,
and undo case is in a way simpler than actual .blend file
reading case). The whole `blo_lib_link_restore` block of code
is also removed.
-- (Mostly) setup_app_data code in actual file reading case.
- Sanitize the usage of the 'libmap' in readfile code in undo case
(waaaaay too many pointers were added there, which was hiding some
other issues in the related code, and potentially causing (in
rare cases) memory addresses collisions.
Pull Request: https://projects.blender.org/blender/blender/pulls/108016
2023-06-05 13:54:49 +02:00
|
|
|
|
|
|
|
|
/* Original 'new' IDs have been moved into the old listbase and will be discarded (deleted).
|
|
|
|
|
* Original 'old' IDs have been moved into the new listbase and are being reused (kept).
|
|
|
|
|
* The discarded ones need to be remapped to a matching reused one, based on their names, if
|
|
|
|
|
* possible.
|
|
|
|
|
*
|
|
|
|
|
* Since both lists are ordered, and they are all local, we can do a smart parallel processing of
|
|
|
|
|
* both lists here instead of doing complete full list searches. */
|
|
|
|
|
ID *discarded_id_iter = static_cast<ID *>(old_lb->first);
|
|
|
|
|
ID *reused_id_iter = static_cast<ID *>(new_lb->first);
|
|
|
|
|
while (!ELEM(nullptr, discarded_id_iter, reused_id_iter)) {
|
|
|
|
|
const int strcmp_result = strcmp(discarded_id_iter->name + 2, reused_id_iter->name + 2);
|
|
|
|
|
if (strcmp_result == 0) {
|
|
|
|
|
/* Matching IDs, we can remap the discarded 'new' one to the re-used 'old' one. */
|
|
|
|
|
BKE_id_remapper_add(remapper, discarded_id_iter, reused_id_iter);
|
|
|
|
|
|
|
|
|
|
discarded_id_iter = static_cast<ID *>(discarded_id_iter->next);
|
|
|
|
|
reused_id_iter = static_cast<ID *>(reused_id_iter->next);
|
|
|
|
|
}
|
|
|
|
|
else if (strcmp_result < 0) {
|
|
|
|
|
/* No matching reused 'old' ID for this discarded 'new' one. */
|
|
|
|
|
BKE_id_remapper_add(remapper, discarded_id_iter, nullptr);
|
|
|
|
|
|
|
|
|
|
discarded_id_iter = static_cast<ID *>(discarded_id_iter->next);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
reused_id_iter = static_cast<ID *>(reused_id_iter->next);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* Also remap all remaining non-compared discarded 'new' IDs to null. */
|
|
|
|
|
for (; discarded_id_iter != nullptr;
|
|
|
|
|
discarded_id_iter = static_cast<ID *>(discarded_id_iter->next))
|
|
|
|
|
{
|
|
|
|
|
BKE_id_remapper_add(remapper, discarded_id_iter, nullptr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FOREACH_MAIN_LISTBASE_ID_BEGIN (new_lb, reused_id_iter) {
|
2024-01-22 13:47:13 +01:00
|
|
|
/* Necessary as all `session_uid` are renewed on blendfile loading. */
|
|
|
|
|
BKE_lib_libblock_session_uid_renew(reused_id_iter);
|
Readfile: Refactor several parts of the process
This commit affects:
* Reading undo steps from memfile (aka 'Global Undo');
* Handling of UI IDs (WindowManager, Workspaces and Screens) when
opening a .blend file.
While no major changes are expected from a user PoV, there may be some
unexpected changes in rare edge-cases. None has been identified so far.
Undo step loading should be marginally faster (`setup_app_data` itself
is 2-3 times faster, as it does not do remapping anymore, which makes the
whole 'read undo step' process about 20% faster - but the most
time-consuming step on undo is the depsgraph processing, which remains
unchanged here).
This commit also solves some bugs (crashes) in some relatively uncommon
cases, like e.g. if the WM had an IDProperty pointing at an object and
UI is not loaded when opening a new .blend file with the 'Load UI' option
enabled (as in previous code on file opening WM ID would never be
remapped).
From a more technical side, this commit aims mainly at cleaning things
up, in preparation for the introduction of new 'no undo, no readfile'
type of handling (as part of the Brush Assets project):
- Prevent WM code from doing (too much) horrible ID 'management' on
its WM when opening a new file. It used to remove current WM from
the Main database, store it in a temporary own list, and then free
it itself...
- Trying to make the complex logic behind WM handling on file reading a
bit more easy to follow, at least way more documented in code.
- Keep the handling of 'IDs being re-used from old Main' in a single
place, as much as possible:
-- Readfile code itself in undo case (because it's more efficient,
and undo case is in a way simpler than actual .blend file
reading case). The whole `blo_lib_link_restore` block of code
is also removed.
-- (Mostly) setup_app_data code in actual file reading case.
- Sanitize the usage of the 'libmap' in readfile code in undo case
(waaaaay too many pointers were added there, which was hiding some
other issues in the related code, and potentially causing (in
rare cases) memory addresses collisions.
Pull Request: https://projects.blender.org/blender/blender/pulls/108016
2023-06-05 13:54:49 +02:00
|
|
|
|
|
|
|
|
/* Ensure that the reused ID is remapped to itself, since it is known to be in the `new_bmain`.
|
|
|
|
|
*/
|
|
|
|
|
BKE_id_remapper_add_overwrite(remapper, reused_id_iter, reused_id_iter);
|
|
|
|
|
}
|
|
|
|
|
FOREACH_MAIN_LISTBASE_ID_END;
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-30 14:15:11 +11:00
|
|
|
/**
|
|
|
|
|
* Similar to #swap_old_bmain_data_for_blendfile, but with special handling for WM ID. Tightly
|
Readfile: Refactor several parts of the process
This commit affects:
* Reading undo steps from memfile (aka 'Global Undo');
* Handling of UI IDs (WindowManager, Workspaces and Screens) when
opening a .blend file.
While no major changes are expected from a user PoV, there may be some
unexpected changes in rare edge-cases. None has been identified so far.
Undo step loading should be marginally faster (`setup_app_data` itself
is 2-3 times faster, as it does not do remapping anymore, which makes the
whole 'read undo step' process about 20% faster - but the most
time-consuming step on undo is the depsgraph processing, which remains
unchanged here).
This commit also solves some bugs (crashes) in some relatively uncommon
cases, like e.g. if the WM had an IDProperty pointing at an object and
UI is not loaded when opening a new .blend file with the 'Load UI' option
enabled (as in previous code on file opening WM ID would never be
remapped).
From a more technical side, this commit aims mainly at cleaning things
up, in preparation for the introduction of new 'no undo, no readfile'
type of handling (as part of the Brush Assets project):
- Prevent WM code from doing (too much) horrible ID 'management' on
its WM when opening a new file. It used to remove current WM from
the Main database, store it in a temporary own list, and then free
it itself...
- Trying to make the complex logic behind WM handling on file reading a
bit more easy to follow, at least way more documented in code.
- Keep the handling of 'IDs being re-used from old Main' in a single
place, as much as possible:
-- Readfile code itself in undo case (because it's more efficient,
and undo case is in a way simpler than actual .blend file
reading case). The whole `blo_lib_link_restore` block of code
is also removed.
-- (Mostly) setup_app_data code in actual file reading case.
- Sanitize the usage of the 'libmap' in readfile code in undo case
(waaaaay too many pointers were added there, which was hiding some
other issues in the related code, and potentially causing (in
rare cases) memory addresses collisions.
Pull Request: https://projects.blender.org/blender/blender/pulls/108016
2023-06-05 13:54:49 +02:00
|
|
|
* related to further WM post-processing from calling WM code (see #WM_file_read and
|
2023-11-30 14:15:11 +11:00
|
|
|
* #wm_homefile_read_ex).
|
|
|
|
|
*/
|
Readfile: Refactor several parts of the process
This commit affects:
* Reading undo steps from memfile (aka 'Global Undo');
* Handling of UI IDs (WindowManager, Workspaces and Screens) when
opening a .blend file.
While no major changes are expected from a user PoV, there may be some
unexpected changes in rare edge-cases. None has been identified so far.
Undo step loading should be marginally faster (`setup_app_data` itself
is 2-3 times faster, as it does not do remapping anymore, which makes the
whole 'read undo step' process about 20% faster - but the most
time-consuming step on undo is the depsgraph processing, which remains
unchanged here).
This commit also solves some bugs (crashes) in some relatively uncommon
cases, like e.g. if the WM had an IDProperty pointing at an object and
UI is not loaded when opening a new .blend file with the 'Load UI' option
enabled (as in previous code on file opening WM ID would never be
remapped).
From a more technical side, this commit aims mainly at cleaning things
up, in preparation for the introduction of new 'no undo, no readfile'
type of handling (as part of the Brush Assets project):
- Prevent WM code from doing (too much) horrible ID 'management' on
its WM when opening a new file. It used to remove current WM from
the Main database, store it in a temporary own list, and then free
it itself...
- Trying to make the complex logic behind WM handling on file reading a
bit more easy to follow, at least way more documented in code.
- Keep the handling of 'IDs being re-used from old Main' in a single
place, as much as possible:
-- Readfile code itself in undo case (because it's more efficient,
and undo case is in a way simpler than actual .blend file
reading case). The whole `blo_lib_link_restore` block of code
is also removed.
-- (Mostly) setup_app_data code in actual file reading case.
- Sanitize the usage of the 'libmap' in readfile code in undo case
(waaaaay too many pointers were added there, which was hiding some
other issues in the related code, and potentially causing (in
rare cases) memory addresses collisions.
Pull Request: https://projects.blender.org/blender/blender/pulls/108016
2023-06-05 13:54:49 +02:00
|
|
|
static void swap_wm_data_for_blendfile(ReuseOldBMainData *reuse_data, const bool load_ui)
|
|
|
|
|
{
|
|
|
|
|
Main *old_bmain = reuse_data->old_bmain;
|
|
|
|
|
Main *new_bmain = reuse_data->new_bmain;
|
|
|
|
|
ListBase *old_wm_list = &old_bmain->wm;
|
|
|
|
|
ListBase *new_wm_list = &new_bmain->wm;
|
|
|
|
|
|
|
|
|
|
/* Currently there should never be more than one WM in a main. */
|
|
|
|
|
BLI_assert(BLI_listbase_count_at_most(new_wm_list, 2) <= 1);
|
|
|
|
|
BLI_assert(BLI_listbase_count_at_most(old_wm_list, 2) <= 1);
|
|
|
|
|
|
|
|
|
|
wmWindowManager *old_wm = static_cast<wmWindowManager *>(old_wm_list->first);
|
|
|
|
|
wmWindowManager *new_wm = static_cast<wmWindowManager *>(new_wm_list->first);
|
|
|
|
|
|
|
|
|
|
if (old_wm == nullptr) {
|
|
|
|
|
/* No current (old) WM. Either (new) WM from file is used, or if none, WM code is responsible
|
|
|
|
|
* to add a new default WM. Nothing to do here. */
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Current (old) WM, and (new) WM in file, and loading UI: use WM from file, keep old WM around
|
|
|
|
|
* for further processing in WM code. */
|
|
|
|
|
if (load_ui && new_wm != nullptr) {
|
|
|
|
|
/* Support window-manager ID references being held between file load operations by keeping
|
2023-06-13 14:51:49 -04:00
|
|
|
* #Main.wm.first memory address in-place, while swapping all of its contents.
|
Readfile: Refactor several parts of the process
This commit affects:
* Reading undo steps from memfile (aka 'Global Undo');
* Handling of UI IDs (WindowManager, Workspaces and Screens) when
opening a .blend file.
While no major changes are expected from a user PoV, there may be some
unexpected changes in rare edge-cases. None has been identified so far.
Undo step loading should be marginally faster (`setup_app_data` itself
is 2-3 times faster, as it does not do remapping anymore, which makes the
whole 'read undo step' process about 20% faster - but the most
time-consuming step on undo is the depsgraph processing, which remains
unchanged here).
This commit also solves some bugs (crashes) in some relatively uncommon
cases, like e.g. if the WM had an IDProperty pointing at an object and
UI is not loaded when opening a new .blend file with the 'Load UI' option
enabled (as in previous code on file opening WM ID would never be
remapped).
From a more technical side, this commit aims mainly at cleaning things
up, in preparation for the introduction of new 'no undo, no readfile'
type of handling (as part of the Brush Assets project):
- Prevent WM code from doing (too much) horrible ID 'management' on
its WM when opening a new file. It used to remove current WM from
the Main database, store it in a temporary own list, and then free
it itself...
- Trying to make the complex logic behind WM handling on file reading a
bit more easy to follow, at least way more documented in code.
- Keep the handling of 'IDs being re-used from old Main' in a single
place, as much as possible:
-- Readfile code itself in undo case (because it's more efficient,
and undo case is in a way simpler than actual .blend file
reading case). The whole `blo_lib_link_restore` block of code
is also removed.
-- (Mostly) setup_app_data code in actual file reading case.
- Sanitize the usage of the 'libmap' in readfile code in undo case
(waaaaay too many pointers were added there, which was hiding some
other issues in the related code, and potentially causing (in
rare cases) memory addresses collisions.
Pull Request: https://projects.blender.org/blender/blender/pulls/108016
2023-06-05 13:54:49 +02:00
|
|
|
*
|
|
|
|
|
* This is needed so items such as key-maps can be held by an add-on,
|
|
|
|
|
* without it pointing to invalid memory, see: #86431. */
|
|
|
|
|
BLI_remlink(old_wm_list, old_wm);
|
|
|
|
|
BLI_remlink(new_wm_list, new_wm);
|
|
|
|
|
BKE_lib_id_swap_full(nullptr,
|
|
|
|
|
&old_wm->id,
|
|
|
|
|
&new_wm->id,
|
|
|
|
|
true,
|
|
|
|
|
(ID_REMAP_SKIP_NEVER_NULL_USAGE | ID_REMAP_SKIP_UPDATE_TAGGING |
|
|
|
|
|
ID_REMAP_SKIP_USER_REFCOUNT | ID_REMAP_FORCE_UI_POINTERS));
|
|
|
|
|
/* Not strictly necessary, but helps for readability. */
|
|
|
|
|
std::swap<wmWindowManager *>(old_wm, new_wm);
|
|
|
|
|
BLI_addhead(new_wm_list, new_wm);
|
|
|
|
|
/* Do not add old WM back to `old_bmain`, so that it does not get freed when `old_bmain` is
|
|
|
|
|
* freed. Calling WM code will need this old WM to restore some windows etc. data into the
|
|
|
|
|
* new WM, and is responsible to free it properly. */
|
|
|
|
|
reuse_data->wm_setup_data->old_wm = old_wm;
|
|
|
|
|
|
|
|
|
|
IDRemapper *remapper = reuse_bmain_data_remapper_ensure(reuse_data);
|
|
|
|
|
BKE_id_remapper_add(remapper, &old_wm->id, &new_wm->id);
|
|
|
|
|
}
|
|
|
|
|
/* Current (old) WM, but no (new) one in file (should only happen when reading pre 2.5 files, no
|
|
|
|
|
* WM back then), or not loading UI: Keep current WM. */
|
|
|
|
|
else {
|
|
|
|
|
swap_old_bmain_data_for_blendfile(reuse_data, ID_WM);
|
|
|
|
|
old_wm->init_flag &= ~WM_INIT_FLAG_WINDOW;
|
2023-06-30 10:26:47 +02:00
|
|
|
reuse_data->wm_setup_data->old_wm = old_wm;
|
Readfile: Refactor several parts of the process
This commit affects:
* Reading undo steps from memfile (aka 'Global Undo');
* Handling of UI IDs (WindowManager, Workspaces and Screens) when
opening a .blend file.
While no major changes are expected from a user PoV, there may be some
unexpected changes in rare edge-cases. None has been identified so far.
Undo step loading should be marginally faster (`setup_app_data` itself
is 2-3 times faster, as it does not do remapping anymore, which makes the
whole 'read undo step' process about 20% faster - but the most
time-consuming step on undo is the depsgraph processing, which remains
unchanged here).
This commit also solves some bugs (crashes) in some relatively uncommon
cases, like e.g. if the WM had an IDProperty pointing at an object and
UI is not loaded when opening a new .blend file with the 'Load UI' option
enabled (as in previous code on file opening WM ID would never be
remapped).
From a more technical side, this commit aims mainly at cleaning things
up, in preparation for the introduction of new 'no undo, no readfile'
type of handling (as part of the Brush Assets project):
- Prevent WM code from doing (too much) horrible ID 'management' on
its WM when opening a new file. It used to remove current WM from
the Main database, store it in a temporary own list, and then free
it itself...
- Trying to make the complex logic behind WM handling on file reading a
bit more easy to follow, at least way more documented in code.
- Keep the handling of 'IDs being re-used from old Main' in a single
place, as much as possible:
-- Readfile code itself in undo case (because it's more efficient,
and undo case is in a way simpler than actual .blend file
reading case). The whole `blo_lib_link_restore` block of code
is also removed.
-- (Mostly) setup_app_data code in actual file reading case.
- Sanitize the usage of the 'libmap' in readfile code in undo case
(waaaaay too many pointers were added there, which was hiding some
other issues in the related code, and potentially causing (in
rare cases) memory addresses collisions.
Pull Request: https://projects.blender.org/blender/blender/pulls/108016
2023-06-05 13:54:49 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int swap_old_bmain_data_for_blendfile_dependencies_process_cb(
|
|
|
|
|
LibraryIDLinkCallbackData *cb_data)
|
|
|
|
|
{
|
|
|
|
|
ID *id = *cb_data->id_pointer;
|
|
|
|
|
|
|
|
|
|
if (id == nullptr) {
|
|
|
|
|
return IDWALK_RET_NOP;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ReuseOldBMainData *reuse_data = static_cast<ReuseOldBMainData *>(cb_data->user_data);
|
|
|
|
|
|
|
|
|
|
/* First check if it has already been remapped. */
|
|
|
|
|
IDRemapper *remapper = reuse_bmain_data_remapper_ensure(reuse_data);
|
|
|
|
|
if (reuse_bmain_data_remapper_is_id_remapped(remapper, id)) {
|
|
|
|
|
return IDWALK_RET_NOP;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IDNameLib_Map *id_map = reuse_data->id_map;
|
|
|
|
|
BLI_assert(id_map != nullptr);
|
|
|
|
|
|
|
|
|
|
ID *id_new = BKE_main_idmap_lookup_id(id_map, id);
|
|
|
|
|
BKE_id_remapper_add(remapper, id, id_new);
|
|
|
|
|
|
|
|
|
|
return IDWALK_RET_NOP;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void swap_old_bmain_data_dependencies_process(ReuseOldBMainData *reuse_data,
|
|
|
|
|
const short id_code)
|
|
|
|
|
{
|
|
|
|
|
Main *new_bmain = reuse_data->new_bmain;
|
|
|
|
|
ListBase *new_lb = which_libbase(new_bmain, id_code);
|
|
|
|
|
|
|
|
|
|
BLI_assert(reuse_data->id_map != nullptr);
|
|
|
|
|
|
|
|
|
|
ID *new_id_iter;
|
|
|
|
|
FOREACH_MAIN_LISTBASE_ID_BEGIN (new_lb, new_id_iter) {
|
|
|
|
|
/* Check all ID usages and find a matching new ID to remap them to in `new_bmain` if possible
|
|
|
|
|
* (matching by names and libraries).
|
|
|
|
|
*
|
|
|
|
|
* Note that this call does not do any effective remapping, it only adds required remapping
|
|
|
|
|
* operations to the remapper. */
|
|
|
|
|
BKE_library_foreach_ID_link(new_bmain,
|
|
|
|
|
new_id_iter,
|
|
|
|
|
swap_old_bmain_data_for_blendfile_dependencies_process_cb,
|
|
|
|
|
reuse_data,
|
|
|
|
|
IDWALK_READONLY | IDWALK_INCLUDE_UI | IDWALK_DO_LIBRARY_POINTER);
|
|
|
|
|
}
|
|
|
|
|
FOREACH_MAIN_LISTBASE_ID_END;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int reuse_bmain_data_invalid_local_usages_fix_cb(LibraryIDLinkCallbackData *cb_data)
|
|
|
|
|
{
|
|
|
|
|
ID *id = *cb_data->id_pointer;
|
|
|
|
|
|
|
|
|
|
if (id == nullptr) {
|
|
|
|
|
return IDWALK_RET_NOP;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Embedded data cannot (yet) be fully trusted to have the same lib pointer as their owner ID, so
|
|
|
|
|
* for now ignore them. This code should never have anything to fix for them anyway, otherwise
|
|
|
|
|
* there is something extremely wrong going on. */
|
|
|
|
|
if ((cb_data->cb_flag & (IDWALK_CB_EMBEDDED | IDWALK_CB_EMBEDDED_NOT_OWNING)) != 0) {
|
|
|
|
|
return IDWALK_RET_NOP;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!ID_IS_LINKED(id)) {
|
|
|
|
|
ID *owner_id = cb_data->owner_id;
|
|
|
|
|
|
|
|
|
|
/* Do not allow linked data to use local data. */
|
|
|
|
|
if (ID_IS_LINKED(owner_id)) {
|
|
|
|
|
if (cb_data->cb_flag & IDWALK_CB_USER) {
|
|
|
|
|
id_us_min(id);
|
|
|
|
|
}
|
|
|
|
|
*cb_data->id_pointer = nullptr;
|
|
|
|
|
}
|
|
|
|
|
/* Do not allow local liboverride data to use local data as reference. */
|
|
|
|
|
else if (ID_IS_OVERRIDE_LIBRARY_REAL(owner_id) &&
|
|
|
|
|
&owner_id->override_library->reference == cb_data->id_pointer)
|
|
|
|
|
{
|
|
|
|
|
if (cb_data->cb_flag & IDWALK_CB_USER) {
|
|
|
|
|
id_us_min(id);
|
|
|
|
|
}
|
|
|
|
|
*cb_data->id_pointer = nullptr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return IDWALK_RET_NOP;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-31 10:15:30 +10:00
|
|
|
/**
|
|
|
|
|
* Detect and fix invalid usages of locale IDs by linked ones (or as reference of liboverrides).
|
Readfile: Refactor several parts of the process
This commit affects:
* Reading undo steps from memfile (aka 'Global Undo');
* Handling of UI IDs (WindowManager, Workspaces and Screens) when
opening a .blend file.
While no major changes are expected from a user PoV, there may be some
unexpected changes in rare edge-cases. None has been identified so far.
Undo step loading should be marginally faster (`setup_app_data` itself
is 2-3 times faster, as it does not do remapping anymore, which makes the
whole 'read undo step' process about 20% faster - but the most
time-consuming step on undo is the depsgraph processing, which remains
unchanged here).
This commit also solves some bugs (crashes) in some relatively uncommon
cases, like e.g. if the WM had an IDProperty pointing at an object and
UI is not loaded when opening a new .blend file with the 'Load UI' option
enabled (as in previous code on file opening WM ID would never be
remapped).
From a more technical side, this commit aims mainly at cleaning things
up, in preparation for the introduction of new 'no undo, no readfile'
type of handling (as part of the Brush Assets project):
- Prevent WM code from doing (too much) horrible ID 'management' on
its WM when opening a new file. It used to remove current WM from
the Main database, store it in a temporary own list, and then free
it itself...
- Trying to make the complex logic behind WM handling on file reading a
bit more easy to follow, at least way more documented in code.
- Keep the handling of 'IDs being re-used from old Main' in a single
place, as much as possible:
-- Readfile code itself in undo case (because it's more efficient,
and undo case is in a way simpler than actual .blend file
reading case). The whole `blo_lib_link_restore` block of code
is also removed.
-- (Mostly) setup_app_data code in actual file reading case.
- Sanitize the usage of the 'libmap' in readfile code in undo case
(waaaaay too many pointers were added there, which was hiding some
other issues in the related code, and potentially causing (in
rare cases) memory addresses collisions.
Pull Request: https://projects.blender.org/blender/blender/pulls/108016
2023-06-05 13:54:49 +02:00
|
|
|
*/
|
|
|
|
|
static void reuse_bmain_data_invalid_local_usages_fix(ReuseOldBMainData *reuse_data)
|
|
|
|
|
{
|
|
|
|
|
Main *new_bmain = reuse_data->new_bmain;
|
|
|
|
|
ID *id_iter;
|
|
|
|
|
FOREACH_MAIN_ID_BEGIN (new_bmain, id_iter) {
|
|
|
|
|
if (!ID_IS_LINKED(id_iter) && !ID_IS_OVERRIDE_LIBRARY_REAL(id_iter)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ID *liboverride_reference = ID_IS_OVERRIDE_LIBRARY_REAL(id_iter) ?
|
|
|
|
|
id_iter->override_library->reference :
|
|
|
|
|
nullptr;
|
|
|
|
|
|
|
|
|
|
BKE_library_foreach_ID_link(
|
|
|
|
|
new_bmain, id_iter, reuse_bmain_data_invalid_local_usages_fix_cb, reuse_data, 0);
|
|
|
|
|
|
|
|
|
|
/* Liboverrides who lost their reference should not be liboverrides anymore, but regular IDs.
|
|
|
|
|
*/
|
|
|
|
|
if (ID_IS_OVERRIDE_LIBRARY_REAL(id_iter) &&
|
|
|
|
|
id_iter->override_library->reference != liboverride_reference)
|
|
|
|
|
{
|
|
|
|
|
BKE_lib_override_library_free(&id_iter->override_library, true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
FOREACH_MAIN_ID_END;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Post-remapping helpers to ensure validity of the UI data. */
|
|
|
|
|
|
|
|
|
|
static void view3d_data_consistency_ensure(wmWindow *win, Scene *scene, ViewLayer *view_layer)
|
|
|
|
|
{
|
|
|
|
|
bScreen *screen = BKE_workspace_active_screen_get(win->workspace_hook);
|
|
|
|
|
|
|
|
|
|
LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
|
|
|
|
|
LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) {
|
|
|
|
|
if (sl->spacetype != SPACE_VIEW3D) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
View3D *v3d = reinterpret_cast<View3D *>(sl);
|
|
|
|
|
if (v3d->camera == nullptr || v3d->scenelock) {
|
|
|
|
|
v3d->camera = scene->camera;
|
|
|
|
|
}
|
|
|
|
|
if (v3d->localvd == nullptr) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (v3d->localvd->camera == nullptr || v3d->scenelock) {
|
|
|
|
|
v3d->localvd->camera = v3d->camera;
|
|
|
|
|
}
|
|
|
|
|
/* Local-view can become invalid during undo/redo steps, exit it when no valid object could
|
|
|
|
|
* be found. */
|
|
|
|
|
Base *base;
|
|
|
|
|
for (base = static_cast<Base *>(view_layer->object_bases.first); base; base = base->next) {
|
2024-01-23 16:06:45 +11:00
|
|
|
if (base->local_view_bits & v3d->local_view_uid) {
|
Readfile: Refactor several parts of the process
This commit affects:
* Reading undo steps from memfile (aka 'Global Undo');
* Handling of UI IDs (WindowManager, Workspaces and Screens) when
opening a .blend file.
While no major changes are expected from a user PoV, there may be some
unexpected changes in rare edge-cases. None has been identified so far.
Undo step loading should be marginally faster (`setup_app_data` itself
is 2-3 times faster, as it does not do remapping anymore, which makes the
whole 'read undo step' process about 20% faster - but the most
time-consuming step on undo is the depsgraph processing, which remains
unchanged here).
This commit also solves some bugs (crashes) in some relatively uncommon
cases, like e.g. if the WM had an IDProperty pointing at an object and
UI is not loaded when opening a new .blend file with the 'Load UI' option
enabled (as in previous code on file opening WM ID would never be
remapped).
From a more technical side, this commit aims mainly at cleaning things
up, in preparation for the introduction of new 'no undo, no readfile'
type of handling (as part of the Brush Assets project):
- Prevent WM code from doing (too much) horrible ID 'management' on
its WM when opening a new file. It used to remove current WM from
the Main database, store it in a temporary own list, and then free
it itself...
- Trying to make the complex logic behind WM handling on file reading a
bit more easy to follow, at least way more documented in code.
- Keep the handling of 'IDs being re-used from old Main' in a single
place, as much as possible:
-- Readfile code itself in undo case (because it's more efficient,
and undo case is in a way simpler than actual .blend file
reading case). The whole `blo_lib_link_restore` block of code
is also removed.
-- (Mostly) setup_app_data code in actual file reading case.
- Sanitize the usage of the 'libmap' in readfile code in undo case
(waaaaay too many pointers were added there, which was hiding some
other issues in the related code, and potentially causing (in
rare cases) memory addresses collisions.
Pull Request: https://projects.blender.org/blender/blender/pulls/108016
2023-06-05 13:54:49 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (base != nullptr) {
|
|
|
|
|
/* The local view3D still has a valid object, nothing else to do. */
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* No valid object found for the local view3D, it has to be cleared off. */
|
|
|
|
|
MEM_freeN(v3d->localvd);
|
|
|
|
|
v3d->localvd = nullptr;
|
2024-01-23 16:06:45 +11:00
|
|
|
v3d->local_view_uid = 0;
|
Readfile: Refactor several parts of the process
This commit affects:
* Reading undo steps from memfile (aka 'Global Undo');
* Handling of UI IDs (WindowManager, Workspaces and Screens) when
opening a .blend file.
While no major changes are expected from a user PoV, there may be some
unexpected changes in rare edge-cases. None has been identified so far.
Undo step loading should be marginally faster (`setup_app_data` itself
is 2-3 times faster, as it does not do remapping anymore, which makes the
whole 'read undo step' process about 20% faster - but the most
time-consuming step on undo is the depsgraph processing, which remains
unchanged here).
This commit also solves some bugs (crashes) in some relatively uncommon
cases, like e.g. if the WM had an IDProperty pointing at an object and
UI is not loaded when opening a new .blend file with the 'Load UI' option
enabled (as in previous code on file opening WM ID would never be
remapped).
From a more technical side, this commit aims mainly at cleaning things
up, in preparation for the introduction of new 'no undo, no readfile'
type of handling (as part of the Brush Assets project):
- Prevent WM code from doing (too much) horrible ID 'management' on
its WM when opening a new file. It used to remove current WM from
the Main database, store it in a temporary own list, and then free
it itself...
- Trying to make the complex logic behind WM handling on file reading a
bit more easy to follow, at least way more documented in code.
- Keep the handling of 'IDs being re-used from old Main' in a single
place, as much as possible:
-- Readfile code itself in undo case (because it's more efficient,
and undo case is in a way simpler than actual .blend file
reading case). The whole `blo_lib_link_restore` block of code
is also removed.
-- (Mostly) setup_app_data code in actual file reading case.
- Sanitize the usage of the 'libmap' in readfile code in undo case
(waaaaay too many pointers were added there, which was hiding some
other issues in the related code, and potentially causing (in
rare cases) memory addresses collisions.
Pull Request: https://projects.blender.org/blender/blender/pulls/108016
2023-06-05 13:54:49 +02:00
|
|
|
|
|
|
|
|
/* Region-base storage is different depending on whether the space is active or not. */
|
|
|
|
|
ListBase *regionbase = (sl == area->spacedata.first) ? &area->regionbase : &sl->regionbase;
|
|
|
|
|
LISTBASE_FOREACH (ARegion *, region, regionbase) {
|
|
|
|
|
if (region->regiontype != RGN_TYPE_WINDOW) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata);
|
|
|
|
|
MEM_SAFE_FREE(rv3d->localvd);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void wm_data_consistency_ensure(wmWindowManager *curwm,
|
|
|
|
|
Scene *cur_scene,
|
|
|
|
|
ViewLayer *cur_view_layer)
|
|
|
|
|
{
|
|
|
|
|
/* There may not be any available WM (e.g. when reading `userpref.blend`). */
|
|
|
|
|
if (curwm == nullptr) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LISTBASE_FOREACH (wmWindow *, win, &curwm->windows) {
|
|
|
|
|
if (win->scene == nullptr) {
|
|
|
|
|
win->scene = cur_scene;
|
|
|
|
|
}
|
|
|
|
|
if (BKE_view_layer_find(win->scene, win->view_layer_name) == nullptr) {
|
|
|
|
|
STRNCPY(win->view_layer_name, cur_view_layer->name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
view3d_data_consistency_ensure(win, win->scene, cur_view_layer);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-24 22:42:41 +10:00
|
|
|
/**
|
2021-07-08 13:26:55 +10:00
|
|
|
* Context matching, handle no-UI case.
|
2016-04-24 22:42:41 +10:00
|
|
|
*
|
|
|
|
|
* \note this is called on Undo so any slow conversion functions here
|
|
|
|
|
* should be avoided or check (mode != LOAD_UNDO).
|
|
|
|
|
*
|
|
|
|
|
* \param bfd: Blend file data, freed by this function on exit.
|
|
|
|
|
*/
|
|
|
|
|
static void setup_app_data(bContext *C,
|
|
|
|
|
BlendFileData *bfd,
|
2023-06-03 08:36:28 +10:00
|
|
|
const BlendFileReadParams *params,
|
Readfile: Refactor several parts of the process
This commit affects:
* Reading undo steps from memfile (aka 'Global Undo');
* Handling of UI IDs (WindowManager, Workspaces and Screens) when
opening a .blend file.
While no major changes are expected from a user PoV, there may be some
unexpected changes in rare edge-cases. None has been identified so far.
Undo step loading should be marginally faster (`setup_app_data` itself
is 2-3 times faster, as it does not do remapping anymore, which makes the
whole 'read undo step' process about 20% faster - but the most
time-consuming step on undo is the depsgraph processing, which remains
unchanged here).
This commit also solves some bugs (crashes) in some relatively uncommon
cases, like e.g. if the WM had an IDProperty pointing at an object and
UI is not loaded when opening a new .blend file with the 'Load UI' option
enabled (as in previous code on file opening WM ID would never be
remapped).
From a more technical side, this commit aims mainly at cleaning things
up, in preparation for the introduction of new 'no undo, no readfile'
type of handling (as part of the Brush Assets project):
- Prevent WM code from doing (too much) horrible ID 'management' on
its WM when opening a new file. It used to remove current WM from
the Main database, store it in a temporary own list, and then free
it itself...
- Trying to make the complex logic behind WM handling on file reading a
bit more easy to follow, at least way more documented in code.
- Keep the handling of 'IDs being re-used from old Main' in a single
place, as much as possible:
-- Readfile code itself in undo case (because it's more efficient,
and undo case is in a way simpler than actual .blend file
reading case). The whole `blo_lib_link_restore` block of code
is also removed.
-- (Mostly) setup_app_data code in actual file reading case.
- Sanitize the usage of the 'libmap' in readfile code in undo case
(waaaaay too many pointers were added there, which was hiding some
other issues in the related code, and potentially causing (in
rare cases) memory addresses collisions.
Pull Request: https://projects.blender.org/blender/blender/pulls/108016
2023-06-05 13:54:49 +02:00
|
|
|
BlendFileReadWMSetupData *wm_setup_data,
|
2021-06-23 09:51:11 +02:00
|
|
|
BlendFileReadReport *reports)
|
2016-04-24 22:42:41 +10:00
|
|
|
{
|
2018-06-13 10:57:10 +02:00
|
|
|
Main *bmain = G_MAIN;
|
2021-03-15 13:30:26 +11:00
|
|
|
const bool recover = (G.fileflags & G_FILE_RECOVER_READ) != 0;
|
2020-03-17 12:29:36 +01:00
|
|
|
const bool is_startup = params->is_startup;
|
2016-04-24 22:42:41 +10:00
|
|
|
enum {
|
|
|
|
|
LOAD_UI = 1,
|
|
|
|
|
LOAD_UI_OFF,
|
|
|
|
|
LOAD_UNDO,
|
|
|
|
|
} mode;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-02-04 22:03:39 +01:00
|
|
|
if (params->undo_direction != STEP_INVALID) {
|
2023-01-23 00:32:39 +01:00
|
|
|
BLI_assert(bfd->curscene != nullptr);
|
2020-03-17 12:29:36 +01:00
|
|
|
mode = LOAD_UNDO;
|
|
|
|
|
}
|
2023-01-23 00:32:39 +01:00
|
|
|
/* may happen with library files - UNDO file should never have nullptr curscene (but may have a
|
|
|
|
|
* nullptr curscreen)... */
|
|
|
|
|
else if (ELEM(nullptr, bfd->curscreen, bfd->curscene)) {
|
2021-06-23 09:51:11 +02:00
|
|
|
BKE_report(reports->reports, RPT_WARNING, "Library file, loading empty scene");
|
2016-09-14 11:35:16 +02:00
|
|
|
mode = LOAD_UI_OFF;
|
|
|
|
|
}
|
2019-12-06 00:26:25 +11:00
|
|
|
else if (G.fileflags & G_FILE_NO_UI) {
|
2016-04-24 22:42:41 +10:00
|
|
|
mode = LOAD_UI_OFF;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
mode = LOAD_UI;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-04-24 22:42:41 +10:00
|
|
|
/* Free all render results, without this stale data gets displayed after loading files */
|
|
|
|
|
if (mode != LOAD_UNDO) {
|
|
|
|
|
RE_FreeAllRenderResults();
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-04-24 22:42:41 +10:00
|
|
|
/* Only make filepaths compatible when loading for real (not undo) */
|
|
|
|
|
if (mode != LOAD_UNDO) {
|
|
|
|
|
clean_paths(bfd->main);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Readfile: Refactor several parts of the process
This commit affects:
* Reading undo steps from memfile (aka 'Global Undo');
* Handling of UI IDs (WindowManager, Workspaces and Screens) when
opening a .blend file.
While no major changes are expected from a user PoV, there may be some
unexpected changes in rare edge-cases. None has been identified so far.
Undo step loading should be marginally faster (`setup_app_data` itself
is 2-3 times faster, as it does not do remapping anymore, which makes the
whole 'read undo step' process about 20% faster - but the most
time-consuming step on undo is the depsgraph processing, which remains
unchanged here).
This commit also solves some bugs (crashes) in some relatively uncommon
cases, like e.g. if the WM had an IDProperty pointing at an object and
UI is not loaded when opening a new .blend file with the 'Load UI' option
enabled (as in previous code on file opening WM ID would never be
remapped).
From a more technical side, this commit aims mainly at cleaning things
up, in preparation for the introduction of new 'no undo, no readfile'
type of handling (as part of the Brush Assets project):
- Prevent WM code from doing (too much) horrible ID 'management' on
its WM when opening a new file. It used to remove current WM from
the Main database, store it in a temporary own list, and then free
it itself...
- Trying to make the complex logic behind WM handling on file reading a
bit more easy to follow, at least way more documented in code.
- Keep the handling of 'IDs being re-used from old Main' in a single
place, as much as possible:
-- Readfile code itself in undo case (because it's more efficient,
and undo case is in a way simpler than actual .blend file
reading case). The whole `blo_lib_link_restore` block of code
is also removed.
-- (Mostly) setup_app_data code in actual file reading case.
- Sanitize the usage of the 'libmap' in readfile code in undo case
(waaaaay too many pointers were added there, which was hiding some
other issues in the related code, and potentially causing (in
rare cases) memory addresses collisions.
Pull Request: https://projects.blender.org/blender/blender/pulls/108016
2023-06-05 13:54:49 +02:00
|
|
|
BLI_assert(BKE_main_namemap_validate(bfd->main));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Readfile: Refactor several parts of the process
This commit affects:
* Reading undo steps from memfile (aka 'Global Undo');
* Handling of UI IDs (WindowManager, Workspaces and Screens) when
opening a .blend file.
While no major changes are expected from a user PoV, there may be some
unexpected changes in rare edge-cases. None has been identified so far.
Undo step loading should be marginally faster (`setup_app_data` itself
is 2-3 times faster, as it does not do remapping anymore, which makes the
whole 'read undo step' process about 20% faster - but the most
time-consuming step on undo is the depsgraph processing, which remains
unchanged here).
This commit also solves some bugs (crashes) in some relatively uncommon
cases, like e.g. if the WM had an IDProperty pointing at an object and
UI is not loaded when opening a new .blend file with the 'Load UI' option
enabled (as in previous code on file opening WM ID would never be
remapped).
From a more technical side, this commit aims mainly at cleaning things
up, in preparation for the introduction of new 'no undo, no readfile'
type of handling (as part of the Brush Assets project):
- Prevent WM code from doing (too much) horrible ID 'management' on
its WM when opening a new file. It used to remove current WM from
the Main database, store it in a temporary own list, and then free
it itself...
- Trying to make the complex logic behind WM handling on file reading a
bit more easy to follow, at least way more documented in code.
- Keep the handling of 'IDs being re-used from old Main' in a single
place, as much as possible:
-- Readfile code itself in undo case (because it's more efficient,
and undo case is in a way simpler than actual .blend file
reading case). The whole `blo_lib_link_restore` block of code
is also removed.
-- (Mostly) setup_app_data code in actual file reading case.
- Sanitize the usage of the 'libmap' in readfile code in undo case
(waaaaay too many pointers were added there, which was hiding some
other issues in the related code, and potentially causing (in
rare cases) memory addresses collisions.
Pull Request: https://projects.blender.org/blender/blender/pulls/108016
2023-06-05 13:54:49 +02:00
|
|
|
/* Temp data to handle swapping around IDs between old and new mains, and accumulate the
|
|
|
|
|
* required remapping accordingly. */
|
|
|
|
|
ReuseOldBMainData reuse_data = {nullptr};
|
|
|
|
|
reuse_data.new_bmain = bfd->main;
|
|
|
|
|
reuse_data.old_bmain = bmain;
|
|
|
|
|
reuse_data.wm_setup_data = wm_setup_data;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Readfile: Refactor several parts of the process
This commit affects:
* Reading undo steps from memfile (aka 'Global Undo');
* Handling of UI IDs (WindowManager, Workspaces and Screens) when
opening a .blend file.
While no major changes are expected from a user PoV, there may be some
unexpected changes in rare edge-cases. None has been identified so far.
Undo step loading should be marginally faster (`setup_app_data` itself
is 2-3 times faster, as it does not do remapping anymore, which makes the
whole 'read undo step' process about 20% faster - but the most
time-consuming step on undo is the depsgraph processing, which remains
unchanged here).
This commit also solves some bugs (crashes) in some relatively uncommon
cases, like e.g. if the WM had an IDProperty pointing at an object and
UI is not loaded when opening a new .blend file with the 'Load UI' option
enabled (as in previous code on file opening WM ID would never be
remapped).
From a more technical side, this commit aims mainly at cleaning things
up, in preparation for the introduction of new 'no undo, no readfile'
type of handling (as part of the Brush Assets project):
- Prevent WM code from doing (too much) horrible ID 'management' on
its WM when opening a new file. It used to remove current WM from
the Main database, store it in a temporary own list, and then free
it itself...
- Trying to make the complex logic behind WM handling on file reading a
bit more easy to follow, at least way more documented in code.
- Keep the handling of 'IDs being re-used from old Main' in a single
place, as much as possible:
-- Readfile code itself in undo case (because it's more efficient,
and undo case is in a way simpler than actual .blend file
reading case). The whole `blo_lib_link_restore` block of code
is also removed.
-- (Mostly) setup_app_data code in actual file reading case.
- Sanitize the usage of the 'libmap' in readfile code in undo case
(waaaaay too many pointers were added there, which was hiding some
other issues in the related code, and potentially causing (in
rare cases) memory addresses collisions.
Pull Request: https://projects.blender.org/blender/blender/pulls/108016
2023-06-05 13:54:49 +02:00
|
|
|
if (mode != LOAD_UNDO) {
|
|
|
|
|
const short ui_id_codes[]{ID_WS, ID_SCR};
|
|
|
|
|
|
|
|
|
|
/* WM needs special complex handling, regardless of whether UI is kept or loaded from file. */
|
|
|
|
|
swap_wm_data_for_blendfile(&reuse_data, mode == LOAD_UI);
|
|
|
|
|
if (mode != LOAD_UI) {
|
|
|
|
|
/* Re-use UI data from `old_bmain` if keeping existing UI. */
|
|
|
|
|
for (auto id_code : ui_id_codes) {
|
|
|
|
|
swap_old_bmain_data_for_blendfile(&reuse_data, id_code);
|
2020-04-21 18:26:32 +02:00
|
|
|
}
|
Readfile: Refactor several parts of the process
This commit affects:
* Reading undo steps from memfile (aka 'Global Undo');
* Handling of UI IDs (WindowManager, Workspaces and Screens) when
opening a .blend file.
While no major changes are expected from a user PoV, there may be some
unexpected changes in rare edge-cases. None has been identified so far.
Undo step loading should be marginally faster (`setup_app_data` itself
is 2-3 times faster, as it does not do remapping anymore, which makes the
whole 'read undo step' process about 20% faster - but the most
time-consuming step on undo is the depsgraph processing, which remains
unchanged here).
This commit also solves some bugs (crashes) in some relatively uncommon
cases, like e.g. if the WM had an IDProperty pointing at an object and
UI is not loaded when opening a new .blend file with the 'Load UI' option
enabled (as in previous code on file opening WM ID would never be
remapped).
From a more technical side, this commit aims mainly at cleaning things
up, in preparation for the introduction of new 'no undo, no readfile'
type of handling (as part of the Brush Assets project):
- Prevent WM code from doing (too much) horrible ID 'management' on
its WM when opening a new file. It used to remove current WM from
the Main database, store it in a temporary own list, and then free
it itself...
- Trying to make the complex logic behind WM handling on file reading a
bit more easy to follow, at least way more documented in code.
- Keep the handling of 'IDs being re-used from old Main' in a single
place, as much as possible:
-- Readfile code itself in undo case (because it's more efficient,
and undo case is in a way simpler than actual .blend file
reading case). The whole `blo_lib_link_restore` block of code
is also removed.
-- (Mostly) setup_app_data code in actual file reading case.
- Sanitize the usage of the 'libmap' in readfile code in undo case
(waaaaay too many pointers were added there, which was hiding some
other issues in the related code, and potentially causing (in
rare cases) memory addresses collisions.
Pull Request: https://projects.blender.org/blender/blender/pulls/108016
2023-06-05 13:54:49 +02:00
|
|
|
}
|
2020-04-21 18:26:32 +02:00
|
|
|
|
Readfile: Refactor several parts of the process
This commit affects:
* Reading undo steps from memfile (aka 'Global Undo');
* Handling of UI IDs (WindowManager, Workspaces and Screens) when
opening a .blend file.
While no major changes are expected from a user PoV, there may be some
unexpected changes in rare edge-cases. None has been identified so far.
Undo step loading should be marginally faster (`setup_app_data` itself
is 2-3 times faster, as it does not do remapping anymore, which makes the
whole 'read undo step' process about 20% faster - but the most
time-consuming step on undo is the depsgraph processing, which remains
unchanged here).
This commit also solves some bugs (crashes) in some relatively uncommon
cases, like e.g. if the WM had an IDProperty pointing at an object and
UI is not loaded when opening a new .blend file with the 'Load UI' option
enabled (as in previous code on file opening WM ID would never be
remapped).
From a more technical side, this commit aims mainly at cleaning things
up, in preparation for the introduction of new 'no undo, no readfile'
type of handling (as part of the Brush Assets project):
- Prevent WM code from doing (too much) horrible ID 'management' on
its WM when opening a new file. It used to remove current WM from
the Main database, store it in a temporary own list, and then free
it itself...
- Trying to make the complex logic behind WM handling on file reading a
bit more easy to follow, at least way more documented in code.
- Keep the handling of 'IDs being re-used from old Main' in a single
place, as much as possible:
-- Readfile code itself in undo case (because it's more efficient,
and undo case is in a way simpler than actual .blend file
reading case). The whole `blo_lib_link_restore` block of code
is also removed.
-- (Mostly) setup_app_data code in actual file reading case.
- Sanitize the usage of the 'libmap' in readfile code in undo case
(waaaaay too many pointers were added there, which was hiding some
other issues in the related code, and potentially causing (in
rare cases) memory addresses collisions.
Pull Request: https://projects.blender.org/blender/blender/pulls/108016
2023-06-05 13:54:49 +02:00
|
|
|
/* Needs to happen after all data from `old_bmain` has been moved into new one. */
|
|
|
|
|
BLI_assert(reuse_data.id_map == nullptr);
|
|
|
|
|
reuse_data.id_map = BKE_main_idmap_create(
|
|
|
|
|
reuse_data.new_bmain, true, reuse_data.old_bmain, MAIN_IDMAP_TYPE_NAME);
|
2020-04-21 18:26:32 +02:00
|
|
|
|
Readfile: Refactor several parts of the process
This commit affects:
* Reading undo steps from memfile (aka 'Global Undo');
* Handling of UI IDs (WindowManager, Workspaces and Screens) when
opening a .blend file.
While no major changes are expected from a user PoV, there may be some
unexpected changes in rare edge-cases. None has been identified so far.
Undo step loading should be marginally faster (`setup_app_data` itself
is 2-3 times faster, as it does not do remapping anymore, which makes the
whole 'read undo step' process about 20% faster - but the most
time-consuming step on undo is the depsgraph processing, which remains
unchanged here).
This commit also solves some bugs (crashes) in some relatively uncommon
cases, like e.g. if the WM had an IDProperty pointing at an object and
UI is not loaded when opening a new .blend file with the 'Load UI' option
enabled (as in previous code on file opening WM ID would never be
remapped).
From a more technical side, this commit aims mainly at cleaning things
up, in preparation for the introduction of new 'no undo, no readfile'
type of handling (as part of the Brush Assets project):
- Prevent WM code from doing (too much) horrible ID 'management' on
its WM when opening a new file. It used to remove current WM from
the Main database, store it in a temporary own list, and then free
it itself...
- Trying to make the complex logic behind WM handling on file reading a
bit more easy to follow, at least way more documented in code.
- Keep the handling of 'IDs being re-used from old Main' in a single
place, as much as possible:
-- Readfile code itself in undo case (because it's more efficient,
and undo case is in a way simpler than actual .blend file
reading case). The whole `blo_lib_link_restore` block of code
is also removed.
-- (Mostly) setup_app_data code in actual file reading case.
- Sanitize the usage of the 'libmap' in readfile code in undo case
(waaaaay too many pointers were added there, which was hiding some
other issues in the related code, and potentially causing (in
rare cases) memory addresses collisions.
Pull Request: https://projects.blender.org/blender/blender/pulls/108016
2023-06-05 13:54:49 +02:00
|
|
|
swap_old_bmain_data_dependencies_process(&reuse_data, ID_WM);
|
|
|
|
|
if (mode != LOAD_UI) {
|
|
|
|
|
for (auto id_code : ui_id_codes) {
|
|
|
|
|
swap_old_bmain_data_dependencies_process(&reuse_data, id_code);
|
2020-04-21 18:26:32 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
Readfile: Refactor several parts of the process
This commit affects:
* Reading undo steps from memfile (aka 'Global Undo');
* Handling of UI IDs (WindowManager, Workspaces and Screens) when
opening a .blend file.
While no major changes are expected from a user PoV, there may be some
unexpected changes in rare edge-cases. None has been identified so far.
Undo step loading should be marginally faster (`setup_app_data` itself
is 2-3 times faster, as it does not do remapping anymore, which makes the
whole 'read undo step' process about 20% faster - but the most
time-consuming step on undo is the depsgraph processing, which remains
unchanged here).
This commit also solves some bugs (crashes) in some relatively uncommon
cases, like e.g. if the WM had an IDProperty pointing at an object and
UI is not loaded when opening a new .blend file with the 'Load UI' option
enabled (as in previous code on file opening WM ID would never be
remapped).
From a more technical side, this commit aims mainly at cleaning things
up, in preparation for the introduction of new 'no undo, no readfile'
type of handling (as part of the Brush Assets project):
- Prevent WM code from doing (too much) horrible ID 'management' on
its WM when opening a new file. It used to remove current WM from
the Main database, store it in a temporary own list, and then free
it itself...
- Trying to make the complex logic behind WM handling on file reading a
bit more easy to follow, at least way more documented in code.
- Keep the handling of 'IDs being re-used from old Main' in a single
place, as much as possible:
-- Readfile code itself in undo case (because it's more efficient,
and undo case is in a way simpler than actual .blend file
reading case). The whole `blo_lib_link_restore` block of code
is also removed.
-- (Mostly) setup_app_data code in actual file reading case.
- Sanitize the usage of the 'libmap' in readfile code in undo case
(waaaaay too many pointers were added there, which was hiding some
other issues in the related code, and potentially causing (in
rare cases) memory addresses collisions.
Pull Request: https://projects.blender.org/blender/blender/pulls/108016
2023-06-05 13:54:49 +02:00
|
|
|
BKE_main_idmap_destroy(reuse_data.id_map);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Logic for 'track_undo_scene' is to keep using the scene which the active screen has, as long
|
|
|
|
|
* as the scene associated with the undo operation is visible in one of the open windows.
|
|
|
|
|
*
|
|
|
|
|
* - 'curscreen->scene' - scene the user is currently looking at.
|
|
|
|
|
* - 'bfd->curscene' - scene undo-step was created in.
|
|
|
|
|
*
|
|
|
|
|
* This means that users can have 2 or more windows open and undo in both without screens
|
|
|
|
|
* switching. But if they close one of the screens, undo will ensure that the scene being
|
|
|
|
|
* operated on will be activated (otherwise we'd be undoing on an off-screen scene which isn't
|
|
|
|
|
* acceptable). See: #43424. */
|
|
|
|
|
bool track_undo_scene = false;
|
|
|
|
|
|
|
|
|
|
/* Always use the Scene and ViewLayer pointers from new file, if possible. */
|
|
|
|
|
ViewLayer *cur_view_layer = bfd->cur_view_layer;
|
|
|
|
|
Scene *curscene = bfd->curscene;
|
|
|
|
|
|
|
|
|
|
wmWindow *win = nullptr;
|
|
|
|
|
bScreen *curscreen = nullptr;
|
|
|
|
|
|
2023-06-07 21:45:48 +10:00
|
|
|
/* Ensure that there is a valid scene and view-layer. */
|
Readfile: Refactor several parts of the process
This commit affects:
* Reading undo steps from memfile (aka 'Global Undo');
* Handling of UI IDs (WindowManager, Workspaces and Screens) when
opening a .blend file.
While no major changes are expected from a user PoV, there may be some
unexpected changes in rare edge-cases. None has been identified so far.
Undo step loading should be marginally faster (`setup_app_data` itself
is 2-3 times faster, as it does not do remapping anymore, which makes the
whole 'read undo step' process about 20% faster - but the most
time-consuming step on undo is the depsgraph processing, which remains
unchanged here).
This commit also solves some bugs (crashes) in some relatively uncommon
cases, like e.g. if the WM had an IDProperty pointing at an object and
UI is not loaded when opening a new .blend file with the 'Load UI' option
enabled (as in previous code on file opening WM ID would never be
remapped).
From a more technical side, this commit aims mainly at cleaning things
up, in preparation for the introduction of new 'no undo, no readfile'
type of handling (as part of the Brush Assets project):
- Prevent WM code from doing (too much) horrible ID 'management' on
its WM when opening a new file. It used to remove current WM from
the Main database, store it in a temporary own list, and then free
it itself...
- Trying to make the complex logic behind WM handling on file reading a
bit more easy to follow, at least way more documented in code.
- Keep the handling of 'IDs being re-used from old Main' in a single
place, as much as possible:
-- Readfile code itself in undo case (because it's more efficient,
and undo case is in a way simpler than actual .blend file
reading case). The whole `blo_lib_link_restore` block of code
is also removed.
-- (Mostly) setup_app_data code in actual file reading case.
- Sanitize the usage of the 'libmap' in readfile code in undo case
(waaaaay too many pointers were added there, which was hiding some
other issues in the related code, and potentially causing (in
rare cases) memory addresses collisions.
Pull Request: https://projects.blender.org/blender/blender/pulls/108016
2023-06-05 13:54:49 +02:00
|
|
|
if (curscene == nullptr) {
|
|
|
|
|
curscene = static_cast<Scene *>(bfd->main->scenes.first);
|
|
|
|
|
}
|
|
|
|
|
/* Empty file, add a scene to make Blender work. */
|
|
|
|
|
if (curscene == nullptr) {
|
|
|
|
|
curscene = BKE_scene_add(bfd->main, "Empty");
|
|
|
|
|
}
|
|
|
|
|
if (cur_view_layer == nullptr) {
|
|
|
|
|
/* Fallback to the active scene view layer. */
|
|
|
|
|
cur_view_layer = BKE_view_layer_default_view(curscene);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* If UI is not loaded when opening actual .blend file, and always in case of undo memfile
|
|
|
|
|
* reading. */
|
|
|
|
|
if (mode != LOAD_UI) {
|
|
|
|
|
/* Re-use current window and screen. */
|
Main Workspace Integration
This commit does the main integration of workspaces, which is a design we agreed on during the 2.8 UI workshop (see https://wiki.blender.org/index.php/Dev:2.8/UI/Workshop_Writeup)
Workspaces should generally be stable, I'm not aware of any remaining bugs (or I've forgotten them :) ). If you find any, let me know!
(Exception: mode switching button might get out of sync with actual mode in some cases, would consider that a limitation/ToDo. Needs to be resolved at some point.)
== Main Changes/Features
* Introduces the new Workspaces as data-blocks.
* Allow storing a number of custom workspaces as part of the user configuration. Needs further work to allow adding and deleting individual workspaces.
* Bundle a default workspace configuration with Blender (current screen-layouts converted to workspaces).
* Pressing button to add a workspace spawns a menu to select between "Duplicate Current" and the workspaces from the user configuration. If no workspaces are stored in the user configuration, the default workspaces are listed instead.
* Store screen-layouts (`bScreen`) per workspace.
* Store an active screen-layout per workspace. Changing the workspace will enable this layout.
* Store active mode in workspace. Changing the workspace will also enter the mode of the new workspace. (Note that we still store the active mode in the object, moving this completely to workspaces is a separate project.)
* Store an active render layer per workspace.
* Moved mode switch from 3D View header to Info Editor header.
* Store active scene in window (not directly workspace related, but overlaps quite a bit).
* Removed 'Use Global Scene' User Preference option.
* Compatibility with old files - a new workspace is created for every screen-layout of old files. Old Blender versions should be able to read files saved with workspace support as well.
* Default .blend only contains one workspace ("General").
* Support appending workspaces.
Opening files without UI and commandline rendering should work fine.
Note that the UI is temporary! We plan to introduce a new global topbar
that contains the workspace options and tabs for switching workspaces.
== Technical Notes
* Workspaces are data-blocks.
* Adding and removing `bScreen`s should be done through `ED_workspace_layout` API now.
* A workspace can be active in multiple windows at the same time.
* The mode menu (which is now in the Info Editor header) doesn't display "Grease Pencil Edit" mode anymore since its availability depends on the active editor. Will be fixed by making Grease Pencil an own object type (as planned).
* The button to change the active workspace object mode may get out of sync with the mode of the active object. Will either be resolved by moving mode out of object data, or we'll disable workspace modes again (there's a `#define USE_WORKSPACE_MODE` for that).
* Screen-layouts (`bScreen`) are IDs and thus stored in a main list-base. Had to add a wrapper `WorkSpaceLayout` so we can store them in a list-base within workspaces, too. On the long run we could completely replace `bScreen` by workspace structs.
* `WorkSpace` types use some special compiler trickery to allow marking structs and struct members as private. BKE_workspace API should be used for accessing those.
* Added scene operators `SCENE_OT_`. Was previously done through screen operators.
== BPY API Changes
* Removed `Screen.scene`, added `Window.scene`
* Removed `UserPreferencesView.use_global_scene`
* Added `Context.workspace`, `Window.workspace` and `BlendData.workspaces`
* Added `bpy.types.WorkSpace` containing `screens`, `object_mode` and `render_layer`
* Added Screen.layout_name for the layout name that'll be displayed in the UI (may differ from internal name)
== What's left?
* There are a few open design questions (T50521). We should find the needed answers and implement them.
* Allow adding and removing individual workspaces from workspace configuration (needs UI design).
* Get the override system ready and support overrides per workspace.
* Support custom UI setups as part of workspaces (hidden panels, hidden buttons, customizable toolbars, etc).
* Allow enabling add-ons per workspace.
* Support custom workspace keymaps.
* Remove special exception for workspaces in linking code (so they're always appended, never linked). Depends on a few things, so best to solve later.
* Get the topbar done.
* Workspaces need a proper icon, current one is just a placeholder :)
Reviewed By: campbellbarton, mont29
Tags: #user_interface, #bf_blender_2.8
Maniphest Tasks: T50521
Differential Revision: https://developer.blender.org/D2451
2017-06-01 19:56:58 +02:00
|
|
|
win = CTX_wm_window(C);
|
2016-04-24 22:42:41 +10:00
|
|
|
curscreen = CTX_wm_screen(C);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-04-24 22:42:41 +10:00
|
|
|
track_undo_scene = (mode == LOAD_UNDO && curscreen && curscene && bfd->main->wm.first);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-04-24 22:42:41 +10:00
|
|
|
if (track_undo_scene) {
|
Readfile: Refactor several parts of the process
This commit affects:
* Reading undo steps from memfile (aka 'Global Undo');
* Handling of UI IDs (WindowManager, Workspaces and Screens) when
opening a .blend file.
While no major changes are expected from a user PoV, there may be some
unexpected changes in rare edge-cases. None has been identified so far.
Undo step loading should be marginally faster (`setup_app_data` itself
is 2-3 times faster, as it does not do remapping anymore, which makes the
whole 'read undo step' process about 20% faster - but the most
time-consuming step on undo is the depsgraph processing, which remains
unchanged here).
This commit also solves some bugs (crashes) in some relatively uncommon
cases, like e.g. if the WM had an IDProperty pointing at an object and
UI is not loaded when opening a new .blend file with the 'Load UI' option
enabled (as in previous code on file opening WM ID would never be
remapped).
From a more technical side, this commit aims mainly at cleaning things
up, in preparation for the introduction of new 'no undo, no readfile'
type of handling (as part of the Brush Assets project):
- Prevent WM code from doing (too much) horrible ID 'management' on
its WM when opening a new file. It used to remove current WM from
the Main database, store it in a temporary own list, and then free
it itself...
- Trying to make the complex logic behind WM handling on file reading a
bit more easy to follow, at least way more documented in code.
- Keep the handling of 'IDs being re-used from old Main' in a single
place, as much as possible:
-- Readfile code itself in undo case (because it's more efficient,
and undo case is in a way simpler than actual .blend file
reading case). The whole `blo_lib_link_restore` block of code
is also removed.
-- (Mostly) setup_app_data code in actual file reading case.
- Sanitize the usage of the 'libmap' in readfile code in undo case
(waaaaay too many pointers were added there, which was hiding some
other issues in the related code, and potentially causing (in
rare cases) memory addresses collisions.
Pull Request: https://projects.blender.org/blender/blender/pulls/108016
2023-06-05 13:54:49 +02:00
|
|
|
/* Keep the old (to-be-freed) scene, remapping below will ensure it's remapped to the
|
2023-08-01 21:15:52 +10:00
|
|
|
* matching new scene if available, or null otherwise, in which case
|
Readfile: Refactor several parts of the process
This commit affects:
* Reading undo steps from memfile (aka 'Global Undo');
* Handling of UI IDs (WindowManager, Workspaces and Screens) when
opening a .blend file.
While no major changes are expected from a user PoV, there may be some
unexpected changes in rare edge-cases. None has been identified so far.
Undo step loading should be marginally faster (`setup_app_data` itself
is 2-3 times faster, as it does not do remapping anymore, which makes the
whole 'read undo step' process about 20% faster - but the most
time-consuming step on undo is the depsgraph processing, which remains
unchanged here).
This commit also solves some bugs (crashes) in some relatively uncommon
cases, like e.g. if the WM had an IDProperty pointing at an object and
UI is not loaded when opening a new .blend file with the 'Load UI' option
enabled (as in previous code on file opening WM ID would never be
remapped).
From a more technical side, this commit aims mainly at cleaning things
up, in preparation for the introduction of new 'no undo, no readfile'
type of handling (as part of the Brush Assets project):
- Prevent WM code from doing (too much) horrible ID 'management' on
its WM when opening a new file. It used to remove current WM from
the Main database, store it in a temporary own list, and then free
it itself...
- Trying to make the complex logic behind WM handling on file reading a
bit more easy to follow, at least way more documented in code.
- Keep the handling of 'IDs being re-used from old Main' in a single
place, as much as possible:
-- Readfile code itself in undo case (because it's more efficient,
and undo case is in a way simpler than actual .blend file
reading case). The whole `blo_lib_link_restore` block of code
is also removed.
-- (Mostly) setup_app_data code in actual file reading case.
- Sanitize the usage of the 'libmap' in readfile code in undo case
(waaaaay too many pointers were added there, which was hiding some
other issues in the related code, and potentially causing (in
rare cases) memory addresses collisions.
Pull Request: https://projects.blender.org/blender/blender/pulls/108016
2023-06-05 13:54:49 +02:00
|
|
|
* #wm_data_consistency_ensure will define `curscene` as the active one. */
|
2016-04-24 22:42:41 +10:00
|
|
|
}
|
Readfile: Refactor several parts of the process
This commit affects:
* Reading undo steps from memfile (aka 'Global Undo');
* Handling of UI IDs (WindowManager, Workspaces and Screens) when
opening a .blend file.
While no major changes are expected from a user PoV, there may be some
unexpected changes in rare edge-cases. None has been identified so far.
Undo step loading should be marginally faster (`setup_app_data` itself
is 2-3 times faster, as it does not do remapping anymore, which makes the
whole 'read undo step' process about 20% faster - but the most
time-consuming step on undo is the depsgraph processing, which remains
unchanged here).
This commit also solves some bugs (crashes) in some relatively uncommon
cases, like e.g. if the WM had an IDProperty pointing at an object and
UI is not loaded when opening a new .blend file with the 'Load UI' option
enabled (as in previous code on file opening WM ID would never be
remapped).
From a more technical side, this commit aims mainly at cleaning things
up, in preparation for the introduction of new 'no undo, no readfile'
type of handling (as part of the Brush Assets project):
- Prevent WM code from doing (too much) horrible ID 'management' on
its WM when opening a new file. It used to remove current WM from
the Main database, store it in a temporary own list, and then free
it itself...
- Trying to make the complex logic behind WM handling on file reading a
bit more easy to follow, at least way more documented in code.
- Keep the handling of 'IDs being re-used from old Main' in a single
place, as much as possible:
-- Readfile code itself in undo case (because it's more efficient,
and undo case is in a way simpler than actual .blend file
reading case). The whole `blo_lib_link_restore` block of code
is also removed.
-- (Mostly) setup_app_data code in actual file reading case.
- Sanitize the usage of the 'libmap' in readfile code in undo case
(waaaaay too many pointers were added there, which was hiding some
other issues in the related code, and potentially causing (in
rare cases) memory addresses collisions.
Pull Request: https://projects.blender.org/blender/blender/pulls/108016
2023-06-05 13:54:49 +02:00
|
|
|
/* Enforce curscene to be in current screen. */
|
2023-01-23 00:32:39 +01:00
|
|
|
else if (win) { /* The window may be nullptr in background-mode. */
|
Main Workspace Integration
This commit does the main integration of workspaces, which is a design we agreed on during the 2.8 UI workshop (see https://wiki.blender.org/index.php/Dev:2.8/UI/Workshop_Writeup)
Workspaces should generally be stable, I'm not aware of any remaining bugs (or I've forgotten them :) ). If you find any, let me know!
(Exception: mode switching button might get out of sync with actual mode in some cases, would consider that a limitation/ToDo. Needs to be resolved at some point.)
== Main Changes/Features
* Introduces the new Workspaces as data-blocks.
* Allow storing a number of custom workspaces as part of the user configuration. Needs further work to allow adding and deleting individual workspaces.
* Bundle a default workspace configuration with Blender (current screen-layouts converted to workspaces).
* Pressing button to add a workspace spawns a menu to select between "Duplicate Current" and the workspaces from the user configuration. If no workspaces are stored in the user configuration, the default workspaces are listed instead.
* Store screen-layouts (`bScreen`) per workspace.
* Store an active screen-layout per workspace. Changing the workspace will enable this layout.
* Store active mode in workspace. Changing the workspace will also enter the mode of the new workspace. (Note that we still store the active mode in the object, moving this completely to workspaces is a separate project.)
* Store an active render layer per workspace.
* Moved mode switch from 3D View header to Info Editor header.
* Store active scene in window (not directly workspace related, but overlaps quite a bit).
* Removed 'Use Global Scene' User Preference option.
* Compatibility with old files - a new workspace is created for every screen-layout of old files. Old Blender versions should be able to read files saved with workspace support as well.
* Default .blend only contains one workspace ("General").
* Support appending workspaces.
Opening files without UI and commandline rendering should work fine.
Note that the UI is temporary! We plan to introduce a new global topbar
that contains the workspace options and tabs for switching workspaces.
== Technical Notes
* Workspaces are data-blocks.
* Adding and removing `bScreen`s should be done through `ED_workspace_layout` API now.
* A workspace can be active in multiple windows at the same time.
* The mode menu (which is now in the Info Editor header) doesn't display "Grease Pencil Edit" mode anymore since its availability depends on the active editor. Will be fixed by making Grease Pencil an own object type (as planned).
* The button to change the active workspace object mode may get out of sync with the mode of the active object. Will either be resolved by moving mode out of object data, or we'll disable workspace modes again (there's a `#define USE_WORKSPACE_MODE` for that).
* Screen-layouts (`bScreen`) are IDs and thus stored in a main list-base. Had to add a wrapper `WorkSpaceLayout` so we can store them in a list-base within workspaces, too. On the long run we could completely replace `bScreen` by workspace structs.
* `WorkSpace` types use some special compiler trickery to allow marking structs and struct members as private. BKE_workspace API should be used for accessing those.
* Added scene operators `SCENE_OT_`. Was previously done through screen operators.
== BPY API Changes
* Removed `Screen.scene`, added `Window.scene`
* Removed `UserPreferencesView.use_global_scene`
* Added `Context.workspace`, `Window.workspace` and `BlendData.workspaces`
* Added `bpy.types.WorkSpace` containing `screens`, `object_mode` and `render_layer`
* Added Screen.layout_name for the layout name that'll be displayed in the UI (may differ from internal name)
== What's left?
* There are a few open design questions (T50521). We should find the needed answers and implement them.
* Allow adding and removing individual workspaces from workspace configuration (needs UI design).
* Get the override system ready and support overrides per workspace.
* Support custom UI setups as part of workspaces (hidden panels, hidden buttons, customizable toolbars, etc).
* Allow enabling add-ons per workspace.
* Support custom workspace keymaps.
* Remove special exception for workspaces in linking code (so they're always appended, never linked). Depends on a few things, so best to solve later.
* Get the topbar done.
* Workspaces need a proper icon, current one is just a placeholder :)
Reviewed By: campbellbarton, mont29
Tags: #user_interface, #bf_blender_2.8
Maniphest Tasks: T50521
Differential Revision: https://developer.blender.org/D2451
2017-06-01 19:56:58 +02:00
|
|
|
win->scene = curscene;
|
2016-04-24 22:42:41 +10:00
|
|
|
}
|
Readfile: Refactor several parts of the process
This commit affects:
* Reading undo steps from memfile (aka 'Global Undo');
* Handling of UI IDs (WindowManager, Workspaces and Screens) when
opening a .blend file.
While no major changes are expected from a user PoV, there may be some
unexpected changes in rare edge-cases. None has been identified so far.
Undo step loading should be marginally faster (`setup_app_data` itself
is 2-3 times faster, as it does not do remapping anymore, which makes the
whole 'read undo step' process about 20% faster - but the most
time-consuming step on undo is the depsgraph processing, which remains
unchanged here).
This commit also solves some bugs (crashes) in some relatively uncommon
cases, like e.g. if the WM had an IDProperty pointing at an object and
UI is not loaded when opening a new .blend file with the 'Load UI' option
enabled (as in previous code on file opening WM ID would never be
remapped).
From a more technical side, this commit aims mainly at cleaning things
up, in preparation for the introduction of new 'no undo, no readfile'
type of handling (as part of the Brush Assets project):
- Prevent WM code from doing (too much) horrible ID 'management' on
its WM when opening a new file. It used to remove current WM from
the Main database, store it in a temporary own list, and then free
it itself...
- Trying to make the complex logic behind WM handling on file reading a
bit more easy to follow, at least way more documented in code.
- Keep the handling of 'IDs being re-used from old Main' in a single
place, as much as possible:
-- Readfile code itself in undo case (because it's more efficient,
and undo case is in a way simpler than actual .blend file
reading case). The whole `blo_lib_link_restore` block of code
is also removed.
-- (Mostly) setup_app_data code in actual file reading case.
- Sanitize the usage of the 'libmap' in readfile code in undo case
(waaaaay too many pointers were added there, which was hiding some
other issues in the related code, and potentially causing (in
rare cases) memory addresses collisions.
Pull Request: https://projects.blender.org/blender/blender/pulls/108016
2023-06-05 13:54:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BLI_assert(BKE_main_namemap_validate(bfd->main));
|
|
|
|
|
|
|
|
|
|
/* Apply remapping of ID pointers caused by re-using part of the data from the 'old' main into
|
|
|
|
|
* the new one. */
|
|
|
|
|
if (reuse_data.remapper != nullptr) {
|
|
|
|
|
/* In undo case all 'keeping old data' and remapping logic is now handled in readfile code
|
|
|
|
|
* itself, so there should never be any remapping to do here. */
|
|
|
|
|
BLI_assert(mode != LOAD_UNDO);
|
|
|
|
|
|
|
|
|
|
/* Handle all pending remapping from swapping old and new IDs around. */
|
|
|
|
|
BKE_libblock_remap_multiple_raw(bfd->main,
|
|
|
|
|
reuse_data.remapper,
|
|
|
|
|
(ID_REMAP_FORCE_UI_POINTERS | ID_REMAP_SKIP_USER_REFCOUNT |
|
|
|
|
|
ID_REMAP_SKIP_UPDATE_TAGGING | ID_REMAP_SKIP_USER_CLEAR));
|
|
|
|
|
|
|
|
|
|
/* Fix potential invalid usages of now-locale-data created by remapping above. Should never
|
|
|
|
|
* be needed in undo case, this is to address cases like 'opening a blendfile that was a
|
|
|
|
|
* library of the previous opened blendfile'. */
|
|
|
|
|
reuse_bmain_data_invalid_local_usages_fix(&reuse_data);
|
|
|
|
|
|
|
|
|
|
BKE_id_remapper_free(reuse_data.remapper);
|
|
|
|
|
reuse_data.remapper = nullptr;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Readfile: Refactor several parts of the process
This commit affects:
* Reading undo steps from memfile (aka 'Global Undo');
* Handling of UI IDs (WindowManager, Workspaces and Screens) when
opening a .blend file.
While no major changes are expected from a user PoV, there may be some
unexpected changes in rare edge-cases. None has been identified so far.
Undo step loading should be marginally faster (`setup_app_data` itself
is 2-3 times faster, as it does not do remapping anymore, which makes the
whole 'read undo step' process about 20% faster - but the most
time-consuming step on undo is the depsgraph processing, which remains
unchanged here).
This commit also solves some bugs (crashes) in some relatively uncommon
cases, like e.g. if the WM had an IDProperty pointing at an object and
UI is not loaded when opening a new .blend file with the 'Load UI' option
enabled (as in previous code on file opening WM ID would never be
remapped).
From a more technical side, this commit aims mainly at cleaning things
up, in preparation for the introduction of new 'no undo, no readfile'
type of handling (as part of the Brush Assets project):
- Prevent WM code from doing (too much) horrible ID 'management' on
its WM when opening a new file. It used to remove current WM from
the Main database, store it in a temporary own list, and then free
it itself...
- Trying to make the complex logic behind WM handling on file reading a
bit more easy to follow, at least way more documented in code.
- Keep the handling of 'IDs being re-used from old Main' in a single
place, as much as possible:
-- Readfile code itself in undo case (because it's more efficient,
and undo case is in a way simpler than actual .blend file
reading case). The whole `blo_lib_link_restore` block of code
is also removed.
-- (Mostly) setup_app_data code in actual file reading case.
- Sanitize the usage of the 'libmap' in readfile code in undo case
(waaaaay too many pointers were added there, which was hiding some
other issues in the related code, and potentially causing (in
rare cases) memory addresses collisions.
Pull Request: https://projects.blender.org/blender/blender/pulls/108016
2023-06-05 13:54:49 +02:00
|
|
|
wm_data_consistency_ensure(CTX_wm_manager(C), curscene, cur_view_layer);
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-26 22:18:40 +11:00
|
|
|
if (mode == LOAD_UNDO) {
|
|
|
|
|
/* It's possible to undo into a time before the scene existed, in this case the window's scene
|
|
|
|
|
* will be null. Since it doesn't make sense to remove the window, set it to the current scene.
|
|
|
|
|
* NOTE: Redo will restore the active scene to the window so a reasonably consistent state
|
|
|
|
|
* is maintained. We could do better by keeping a window/scene map for each undo step. */
|
|
|
|
|
wmWindowManager *wm = static_cast<wmWindowManager *>(bfd->main->wm.first);
|
|
|
|
|
LISTBASE_FOREACH (wmWindow *, win, &wm->windows) {
|
|
|
|
|
if (win->scene == nullptr) {
|
|
|
|
|
win->scene = curscene;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
Readfile: Refactor several parts of the process
This commit affects:
* Reading undo steps from memfile (aka 'Global Undo');
* Handling of UI IDs (WindowManager, Workspaces and Screens) when
opening a .blend file.
While no major changes are expected from a user PoV, there may be some
unexpected changes in rare edge-cases. None has been identified so far.
Undo step loading should be marginally faster (`setup_app_data` itself
is 2-3 times faster, as it does not do remapping anymore, which makes the
whole 'read undo step' process about 20% faster - but the most
time-consuming step on undo is the depsgraph processing, which remains
unchanged here).
This commit also solves some bugs (crashes) in some relatively uncommon
cases, like e.g. if the WM had an IDProperty pointing at an object and
UI is not loaded when opening a new .blend file with the 'Load UI' option
enabled (as in previous code on file opening WM ID would never be
remapped).
From a more technical side, this commit aims mainly at cleaning things
up, in preparation for the introduction of new 'no undo, no readfile'
type of handling (as part of the Brush Assets project):
- Prevent WM code from doing (too much) horrible ID 'management' on
its WM when opening a new file. It used to remove current WM from
the Main database, store it in a temporary own list, and then free
it itself...
- Trying to make the complex logic behind WM handling on file reading a
bit more easy to follow, at least way more documented in code.
- Keep the handling of 'IDs being re-used from old Main' in a single
place, as much as possible:
-- Readfile code itself in undo case (because it's more efficient,
and undo case is in a way simpler than actual .blend file
reading case). The whole `blo_lib_link_restore` block of code
is also removed.
-- (Mostly) setup_app_data code in actual file reading case.
- Sanitize the usage of the 'libmap' in readfile code in undo case
(waaaaay too many pointers were added there, which was hiding some
other issues in the related code, and potentially causing (in
rare cases) memory addresses collisions.
Pull Request: https://projects.blender.org/blender/blender/pulls/108016
2023-06-05 13:54:49 +02:00
|
|
|
BLI_assert(BKE_main_namemap_validate(bfd->main));
|
|
|
|
|
|
|
|
|
|
if (mode != LOAD_UI) {
|
Main Workspace Integration
This commit does the main integration of workspaces, which is a design we agreed on during the 2.8 UI workshop (see https://wiki.blender.org/index.php/Dev:2.8/UI/Workshop_Writeup)
Workspaces should generally be stable, I'm not aware of any remaining bugs (or I've forgotten them :) ). If you find any, let me know!
(Exception: mode switching button might get out of sync with actual mode in some cases, would consider that a limitation/ToDo. Needs to be resolved at some point.)
== Main Changes/Features
* Introduces the new Workspaces as data-blocks.
* Allow storing a number of custom workspaces as part of the user configuration. Needs further work to allow adding and deleting individual workspaces.
* Bundle a default workspace configuration with Blender (current screen-layouts converted to workspaces).
* Pressing button to add a workspace spawns a menu to select between "Duplicate Current" and the workspaces from the user configuration. If no workspaces are stored in the user configuration, the default workspaces are listed instead.
* Store screen-layouts (`bScreen`) per workspace.
* Store an active screen-layout per workspace. Changing the workspace will enable this layout.
* Store active mode in workspace. Changing the workspace will also enter the mode of the new workspace. (Note that we still store the active mode in the object, moving this completely to workspaces is a separate project.)
* Store an active render layer per workspace.
* Moved mode switch from 3D View header to Info Editor header.
* Store active scene in window (not directly workspace related, but overlaps quite a bit).
* Removed 'Use Global Scene' User Preference option.
* Compatibility with old files - a new workspace is created for every screen-layout of old files. Old Blender versions should be able to read files saved with workspace support as well.
* Default .blend only contains one workspace ("General").
* Support appending workspaces.
Opening files without UI and commandline rendering should work fine.
Note that the UI is temporary! We plan to introduce a new global topbar
that contains the workspace options and tabs for switching workspaces.
== Technical Notes
* Workspaces are data-blocks.
* Adding and removing `bScreen`s should be done through `ED_workspace_layout` API now.
* A workspace can be active in multiple windows at the same time.
* The mode menu (which is now in the Info Editor header) doesn't display "Grease Pencil Edit" mode anymore since its availability depends on the active editor. Will be fixed by making Grease Pencil an own object type (as planned).
* The button to change the active workspace object mode may get out of sync with the mode of the active object. Will either be resolved by moving mode out of object data, or we'll disable workspace modes again (there's a `#define USE_WORKSPACE_MODE` for that).
* Screen-layouts (`bScreen`) are IDs and thus stored in a main list-base. Had to add a wrapper `WorkSpaceLayout` so we can store them in a list-base within workspaces, too. On the long run we could completely replace `bScreen` by workspace structs.
* `WorkSpace` types use some special compiler trickery to allow marking structs and struct members as private. BKE_workspace API should be used for accessing those.
* Added scene operators `SCENE_OT_`. Was previously done through screen operators.
== BPY API Changes
* Removed `Screen.scene`, added `Window.scene`
* Removed `UserPreferencesView.use_global_scene`
* Added `Context.workspace`, `Window.workspace` and `BlendData.workspaces`
* Added `bpy.types.WorkSpace` containing `screens`, `object_mode` and `render_layer`
* Added Screen.layout_name for the layout name that'll be displayed in the UI (may differ from internal name)
== What's left?
* There are a few open design questions (T50521). We should find the needed answers and implement them.
* Allow adding and removing individual workspaces from workspace configuration (needs UI design).
* Get the override system ready and support overrides per workspace.
* Support custom UI setups as part of workspaces (hidden panels, hidden buttons, customizable toolbars, etc).
* Allow enabling add-ons per workspace.
* Support custom workspace keymaps.
* Remove special exception for workspaces in linking code (so they're always appended, never linked). Depends on a few things, so best to solve later.
* Get the topbar done.
* Workspaces need a proper icon, current one is just a placeholder :)
Reviewed By: campbellbarton, mont29
Tags: #user_interface, #bf_blender_2.8
Maniphest Tasks: T50521
Differential Revision: https://developer.blender.org/D2451
2017-06-01 19:56:58 +02:00
|
|
|
if (win) {
|
|
|
|
|
curscene = win->scene;
|
2016-04-24 22:42:41 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-04-24 22:42:41 +10:00
|
|
|
if (track_undo_scene) {
|
2023-01-23 00:32:39 +01:00
|
|
|
wmWindowManager *wm = static_cast<wmWindowManager *>(bfd->main->wm.first);
|
Readfile: Refactor several parts of the process
This commit affects:
* Reading undo steps from memfile (aka 'Global Undo');
* Handling of UI IDs (WindowManager, Workspaces and Screens) when
opening a .blend file.
While no major changes are expected from a user PoV, there may be some
unexpected changes in rare edge-cases. None has been identified so far.
Undo step loading should be marginally faster (`setup_app_data` itself
is 2-3 times faster, as it does not do remapping anymore, which makes the
whole 'read undo step' process about 20% faster - but the most
time-consuming step on undo is the depsgraph processing, which remains
unchanged here).
This commit also solves some bugs (crashes) in some relatively uncommon
cases, like e.g. if the WM had an IDProperty pointing at an object and
UI is not loaded when opening a new .blend file with the 'Load UI' option
enabled (as in previous code on file opening WM ID would never be
remapped).
From a more technical side, this commit aims mainly at cleaning things
up, in preparation for the introduction of new 'no undo, no readfile'
type of handling (as part of the Brush Assets project):
- Prevent WM code from doing (too much) horrible ID 'management' on
its WM when opening a new file. It used to remove current WM from
the Main database, store it in a temporary own list, and then free
it itself...
- Trying to make the complex logic behind WM handling on file reading a
bit more easy to follow, at least way more documented in code.
- Keep the handling of 'IDs being re-used from old Main' in a single
place, as much as possible:
-- Readfile code itself in undo case (because it's more efficient,
and undo case is in a way simpler than actual .blend file
reading case). The whole `blo_lib_link_restore` block of code
is also removed.
-- (Mostly) setup_app_data code in actual file reading case.
- Sanitize the usage of the 'libmap' in readfile code in undo case
(waaaaay too many pointers were added there, which was hiding some
other issues in the related code, and potentially causing (in
rare cases) memory addresses collisions.
Pull Request: https://projects.blender.org/blender/blender/pulls/108016
2023-06-05 13:54:49 +02:00
|
|
|
if (!wm_scene_is_visible(wm, bfd->curscene)) {
|
2016-04-24 22:42:41 +10:00
|
|
|
curscene = bfd->curscene;
|
Readfile: Refactor several parts of the process
This commit affects:
* Reading undo steps from memfile (aka 'Global Undo');
* Handling of UI IDs (WindowManager, Workspaces and Screens) when
opening a .blend file.
While no major changes are expected from a user PoV, there may be some
unexpected changes in rare edge-cases. None has been identified so far.
Undo step loading should be marginally faster (`setup_app_data` itself
is 2-3 times faster, as it does not do remapping anymore, which makes the
whole 'read undo step' process about 20% faster - but the most
time-consuming step on undo is the depsgraph processing, which remains
unchanged here).
This commit also solves some bugs (crashes) in some relatively uncommon
cases, like e.g. if the WM had an IDProperty pointing at an object and
UI is not loaded when opening a new .blend file with the 'Load UI' option
enabled (as in previous code on file opening WM ID would never be
remapped).
From a more technical side, this commit aims mainly at cleaning things
up, in preparation for the introduction of new 'no undo, no readfile'
type of handling (as part of the Brush Assets project):
- Prevent WM code from doing (too much) horrible ID 'management' on
its WM when opening a new file. It used to remove current WM from
the Main database, store it in a temporary own list, and then free
it itself...
- Trying to make the complex logic behind WM handling on file reading a
bit more easy to follow, at least way more documented in code.
- Keep the handling of 'IDs being re-used from old Main' in a single
place, as much as possible:
-- Readfile code itself in undo case (because it's more efficient,
and undo case is in a way simpler than actual .blend file
reading case). The whole `blo_lib_link_restore` block of code
is also removed.
-- (Mostly) setup_app_data code in actual file reading case.
- Sanitize the usage of the 'libmap' in readfile code in undo case
(waaaaay too many pointers were added there, which was hiding some
other issues in the related code, and potentially causing (in
rare cases) memory addresses collisions.
Pull Request: https://projects.blender.org/blender/blender/pulls/108016
2023-06-05 13:54:49 +02:00
|
|
|
if (win) {
|
|
|
|
|
win->scene = curscene;
|
|
|
|
|
}
|
Main Workspace Integration
This commit does the main integration of workspaces, which is a design we agreed on during the 2.8 UI workshop (see https://wiki.blender.org/index.php/Dev:2.8/UI/Workshop_Writeup)
Workspaces should generally be stable, I'm not aware of any remaining bugs (or I've forgotten them :) ). If you find any, let me know!
(Exception: mode switching button might get out of sync with actual mode in some cases, would consider that a limitation/ToDo. Needs to be resolved at some point.)
== Main Changes/Features
* Introduces the new Workspaces as data-blocks.
* Allow storing a number of custom workspaces as part of the user configuration. Needs further work to allow adding and deleting individual workspaces.
* Bundle a default workspace configuration with Blender (current screen-layouts converted to workspaces).
* Pressing button to add a workspace spawns a menu to select between "Duplicate Current" and the workspaces from the user configuration. If no workspaces are stored in the user configuration, the default workspaces are listed instead.
* Store screen-layouts (`bScreen`) per workspace.
* Store an active screen-layout per workspace. Changing the workspace will enable this layout.
* Store active mode in workspace. Changing the workspace will also enter the mode of the new workspace. (Note that we still store the active mode in the object, moving this completely to workspaces is a separate project.)
* Store an active render layer per workspace.
* Moved mode switch from 3D View header to Info Editor header.
* Store active scene in window (not directly workspace related, but overlaps quite a bit).
* Removed 'Use Global Scene' User Preference option.
* Compatibility with old files - a new workspace is created for every screen-layout of old files. Old Blender versions should be able to read files saved with workspace support as well.
* Default .blend only contains one workspace ("General").
* Support appending workspaces.
Opening files without UI and commandline rendering should work fine.
Note that the UI is temporary! We plan to introduce a new global topbar
that contains the workspace options and tabs for switching workspaces.
== Technical Notes
* Workspaces are data-blocks.
* Adding and removing `bScreen`s should be done through `ED_workspace_layout` API now.
* A workspace can be active in multiple windows at the same time.
* The mode menu (which is now in the Info Editor header) doesn't display "Grease Pencil Edit" mode anymore since its availability depends on the active editor. Will be fixed by making Grease Pencil an own object type (as planned).
* The button to change the active workspace object mode may get out of sync with the mode of the active object. Will either be resolved by moving mode out of object data, or we'll disable workspace modes again (there's a `#define USE_WORKSPACE_MODE` for that).
* Screen-layouts (`bScreen`) are IDs and thus stored in a main list-base. Had to add a wrapper `WorkSpaceLayout` so we can store them in a list-base within workspaces, too. On the long run we could completely replace `bScreen` by workspace structs.
* `WorkSpace` types use some special compiler trickery to allow marking structs and struct members as private. BKE_workspace API should be used for accessing those.
* Added scene operators `SCENE_OT_`. Was previously done through screen operators.
== BPY API Changes
* Removed `Screen.scene`, added `Window.scene`
* Removed `UserPreferencesView.use_global_scene`
* Added `Context.workspace`, `Window.workspace` and `BlendData.workspaces`
* Added `bpy.types.WorkSpace` containing `screens`, `object_mode` and `render_layer`
* Added Screen.layout_name for the layout name that'll be displayed in the UI (may differ from internal name)
== What's left?
* There are a few open design questions (T50521). We should find the needed answers and implement them.
* Allow adding and removing individual workspaces from workspace configuration (needs UI design).
* Get the override system ready and support overrides per workspace.
* Support custom UI setups as part of workspaces (hidden panels, hidden buttons, customizable toolbars, etc).
* Allow enabling add-ons per workspace.
* Support custom workspace keymaps.
* Remove special exception for workspaces in linking code (so they're always appended, never linked). Depends on a few things, so best to solve later.
* Get the topbar done.
* Workspaces need a proper icon, current one is just a placeholder :)
Reviewed By: campbellbarton, mont29
Tags: #user_interface, #bf_blender_2.8
Maniphest Tasks: T50521
Differential Revision: https://developer.blender.org/D2451
2017-06-01 19:56:58 +02:00
|
|
|
BKE_screen_view3d_scene_sync(curscreen, curscene);
|
2016-04-24 22:42:41 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
2017-07-31 14:35:10 +10:00
|
|
|
/* We need to tag this here because events may be handled immediately after.
|
2021-06-22 10:42:32 -07:00
|
|
|
* only the current screen is important because we won't have to handle
|
2021-06-26 21:35:18 +10:00
|
|
|
* events from multiple screens at once. */
|
2018-09-26 14:20:52 +02:00
|
|
|
if (curscreen) {
|
2018-07-14 23:49:00 +02:00
|
|
|
BKE_screen_gizmo_tag_refresh(curscreen);
|
2016-04-24 22:42:41 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
Readfile: Refactor several parts of the process
This commit affects:
* Reading undo steps from memfile (aka 'Global Undo');
* Handling of UI IDs (WindowManager, Workspaces and Screens) when
opening a .blend file.
While no major changes are expected from a user PoV, there may be some
unexpected changes in rare edge-cases. None has been identified so far.
Undo step loading should be marginally faster (`setup_app_data` itself
is 2-3 times faster, as it does not do remapping anymore, which makes the
whole 'read undo step' process about 20% faster - but the most
time-consuming step on undo is the depsgraph processing, which remains
unchanged here).
This commit also solves some bugs (crashes) in some relatively uncommon
cases, like e.g. if the WM had an IDProperty pointing at an object and
UI is not loaded when opening a new .blend file with the 'Load UI' option
enabled (as in previous code on file opening WM ID would never be
remapped).
From a more technical side, this commit aims mainly at cleaning things
up, in preparation for the introduction of new 'no undo, no readfile'
type of handling (as part of the Brush Assets project):
- Prevent WM code from doing (too much) horrible ID 'management' on
its WM when opening a new file. It used to remove current WM from
the Main database, store it in a temporary own list, and then free
it itself...
- Trying to make the complex logic behind WM handling on file reading a
bit more easy to follow, at least way more documented in code.
- Keep the handling of 'IDs being re-used from old Main' in a single
place, as much as possible:
-- Readfile code itself in undo case (because it's more efficient,
and undo case is in a way simpler than actual .blend file
reading case). The whole `blo_lib_link_restore` block of code
is also removed.
-- (Mostly) setup_app_data code in actual file reading case.
- Sanitize the usage of the 'libmap' in readfile code in undo case
(waaaaay too many pointers were added there, which was hiding some
other issues in the related code, and potentially causing (in
rare cases) memory addresses collisions.
Pull Request: https://projects.blender.org/blender/blender/pulls/108016
2023-06-05 13:54:49 +02:00
|
|
|
CTX_data_scene_set(C, curscene);
|
|
|
|
|
|
|
|
|
|
BLI_assert(BKE_main_namemap_validate(bfd->main));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Readfile: Refactor several parts of the process
This commit affects:
* Reading undo steps from memfile (aka 'Global Undo');
* Handling of UI IDs (WindowManager, Workspaces and Screens) when
opening a .blend file.
While no major changes are expected from a user PoV, there may be some
unexpected changes in rare edge-cases. None has been identified so far.
Undo step loading should be marginally faster (`setup_app_data` itself
is 2-3 times faster, as it does not do remapping anymore, which makes the
whole 'read undo step' process about 20% faster - but the most
time-consuming step on undo is the depsgraph processing, which remains
unchanged here).
This commit also solves some bugs (crashes) in some relatively uncommon
cases, like e.g. if the WM had an IDProperty pointing at an object and
UI is not loaded when opening a new .blend file with the 'Load UI' option
enabled (as in previous code on file opening WM ID would never be
remapped).
From a more technical side, this commit aims mainly at cleaning things
up, in preparation for the introduction of new 'no undo, no readfile'
type of handling (as part of the Brush Assets project):
- Prevent WM code from doing (too much) horrible ID 'management' on
its WM when opening a new file. It used to remove current WM from
the Main database, store it in a temporary own list, and then free
it itself...
- Trying to make the complex logic behind WM handling on file reading a
bit more easy to follow, at least way more documented in code.
- Keep the handling of 'IDs being re-used from old Main' in a single
place, as much as possible:
-- Readfile code itself in undo case (because it's more efficient,
and undo case is in a way simpler than actual .blend file
reading case). The whole `blo_lib_link_restore` block of code
is also removed.
-- (Mostly) setup_app_data code in actual file reading case.
- Sanitize the usage of the 'libmap' in readfile code in undo case
(waaaaay too many pointers were added there, which was hiding some
other issues in the related code, and potentially causing (in
rare cases) memory addresses collisions.
Pull Request: https://projects.blender.org/blender/blender/pulls/108016
2023-06-05 13:54:49 +02:00
|
|
|
/* This frees the `old_bmain`. */
|
2022-10-05 12:55:32 +02:00
|
|
|
BKE_blender_globals_main_replace(bfd->main);
|
|
|
|
|
bmain = G_MAIN;
|
2023-01-23 00:32:39 +01:00
|
|
|
bfd->main = nullptr;
|
2018-06-05 15:10:33 +02:00
|
|
|
CTX_data_main_set(C, bmain);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Readfile: Refactor several parts of the process
This commit affects:
* Reading undo steps from memfile (aka 'Global Undo');
* Handling of UI IDs (WindowManager, Workspaces and Screens) when
opening a .blend file.
While no major changes are expected from a user PoV, there may be some
unexpected changes in rare edge-cases. None has been identified so far.
Undo step loading should be marginally faster (`setup_app_data` itself
is 2-3 times faster, as it does not do remapping anymore, which makes the
whole 'read undo step' process about 20% faster - but the most
time-consuming step on undo is the depsgraph processing, which remains
unchanged here).
This commit also solves some bugs (crashes) in some relatively uncommon
cases, like e.g. if the WM had an IDProperty pointing at an object and
UI is not loaded when opening a new .blend file with the 'Load UI' option
enabled (as in previous code on file opening WM ID would never be
remapped).
From a more technical side, this commit aims mainly at cleaning things
up, in preparation for the introduction of new 'no undo, no readfile'
type of handling (as part of the Brush Assets project):
- Prevent WM code from doing (too much) horrible ID 'management' on
its WM when opening a new file. It used to remove current WM from
the Main database, store it in a temporary own list, and then free
it itself...
- Trying to make the complex logic behind WM handling on file reading a
bit more easy to follow, at least way more documented in code.
- Keep the handling of 'IDs being re-used from old Main' in a single
place, as much as possible:
-- Readfile code itself in undo case (because it's more efficient,
and undo case is in a way simpler than actual .blend file
reading case). The whole `blo_lib_link_restore` block of code
is also removed.
-- (Mostly) setup_app_data code in actual file reading case.
- Sanitize the usage of the 'libmap' in readfile code in undo case
(waaaaay too many pointers were added there, which was hiding some
other issues in the related code, and potentially causing (in
rare cases) memory addresses collisions.
Pull Request: https://projects.blender.org/blender/blender/pulls/108016
2023-06-05 13:54:49 +02:00
|
|
|
BLI_assert(BKE_main_namemap_validate(bmain));
|
|
|
|
|
|
|
|
|
|
/* These context data should remain valid if old UI is being re-used. */
|
|
|
|
|
if (mode == LOAD_UI) {
|
|
|
|
|
/* Setting WindowManager in context clears all other Context UI data (window, area, etc.). So
|
|
|
|
|
* only do it when effectively loading a new WM, otherwise just assert that the WM from context
|
|
|
|
|
* is still the same as in `new_bmain`. */
|
2023-01-23 00:32:39 +01:00
|
|
|
CTX_wm_manager_set(C, static_cast<wmWindowManager *>(bmain->wm.first));
|
2016-04-24 22:42:41 +10:00
|
|
|
CTX_wm_screen_set(C, bfd->curscreen);
|
2023-01-23 00:32:39 +01:00
|
|
|
CTX_wm_area_set(C, nullptr);
|
|
|
|
|
CTX_wm_region_set(C, nullptr);
|
|
|
|
|
CTX_wm_menu_set(C, nullptr);
|
2016-04-24 22:42:41 +10:00
|
|
|
}
|
Readfile: Refactor several parts of the process
This commit affects:
* Reading undo steps from memfile (aka 'Global Undo');
* Handling of UI IDs (WindowManager, Workspaces and Screens) when
opening a .blend file.
While no major changes are expected from a user PoV, there may be some
unexpected changes in rare edge-cases. None has been identified so far.
Undo step loading should be marginally faster (`setup_app_data` itself
is 2-3 times faster, as it does not do remapping anymore, which makes the
whole 'read undo step' process about 20% faster - but the most
time-consuming step on undo is the depsgraph processing, which remains
unchanged here).
This commit also solves some bugs (crashes) in some relatively uncommon
cases, like e.g. if the WM had an IDProperty pointing at an object and
UI is not loaded when opening a new .blend file with the 'Load UI' option
enabled (as in previous code on file opening WM ID would never be
remapped).
From a more technical side, this commit aims mainly at cleaning things
up, in preparation for the introduction of new 'no undo, no readfile'
type of handling (as part of the Brush Assets project):
- Prevent WM code from doing (too much) horrible ID 'management' on
its WM when opening a new file. It used to remove current WM from
the Main database, store it in a temporary own list, and then free
it itself...
- Trying to make the complex logic behind WM handling on file reading a
bit more easy to follow, at least way more documented in code.
- Keep the handling of 'IDs being re-used from old Main' in a single
place, as much as possible:
-- Readfile code itself in undo case (because it's more efficient,
and undo case is in a way simpler than actual .blend file
reading case). The whole `blo_lib_link_restore` block of code
is also removed.
-- (Mostly) setup_app_data code in actual file reading case.
- Sanitize the usage of the 'libmap' in readfile code in undo case
(waaaaay too many pointers were added there, which was hiding some
other issues in the related code, and potentially causing (in
rare cases) memory addresses collisions.
Pull Request: https://projects.blender.org/blender/blender/pulls/108016
2023-06-05 13:54:49 +02:00
|
|
|
BLI_assert(CTX_wm_manager(C) == static_cast<wmWindowManager *>(bmain->wm.first));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-01-24 16:11:53 +01:00
|
|
|
/* Keep state from preferences. */
|
2019-02-02 14:01:48 +11:00
|
|
|
const int fileflags_keep = G_FILE_FLAG_ALL_RUNTIME;
|
|
|
|
|
G.fileflags = (G.fileflags & fileflags_keep) | (bfd->fileflags & ~fileflags_keep);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-04-24 22:42:41 +10:00
|
|
|
/* special cases, override loaded flags: */
|
|
|
|
|
if (G.f != bfd->globalf) {
|
2019-02-02 14:01:48 +11:00
|
|
|
const int flags_keep = G_FLAG_ALL_RUNTIME;
|
2019-02-02 14:45:42 +11:00
|
|
|
bfd->globalf &= G_FLAG_ALL_READFILE;
|
2016-04-24 22:42:41 +10:00
|
|
|
bfd->globalf = (bfd->globalf & ~flags_keep) | (G.f & flags_keep);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-04-24 22:42:41 +10:00
|
|
|
G.f = bfd->globalf;
|
|
|
|
|
|
|
|
|
|
#ifdef WITH_PYTHON
|
|
|
|
|
/* let python know about new main */
|
2020-10-15 18:12:03 +11:00
|
|
|
if (CTX_py_init_get(C)) {
|
|
|
|
|
BPY_context_update(C);
|
|
|
|
|
}
|
2016-04-24 22:42:41 +10:00
|
|
|
#endif
|
|
|
|
|
|
2023-08-15 20:07:55 +02:00
|
|
|
if (mode != LOAD_UNDO) {
|
|
|
|
|
/* Perform complex versioning that involves adding or removing IDs, and/or needs to operate
|
|
|
|
|
* over the whole Main data-base (versioning done in readfile code only operates on a
|
|
|
|
|
* per-library basis). */
|
|
|
|
|
BLO_read_do_version_after_setup(bmain, reports);
|
2022-01-12 10:43:42 +01:00
|
|
|
}
|
|
|
|
|
|
2022-09-14 15:48:49 +02:00
|
|
|
bmain->recovered = false;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-04-24 22:42:41 +10:00
|
|
|
/* startup.blend or recovered startup */
|
2018-11-22 14:57:41 +11:00
|
|
|
if (is_startup) {
|
2021-12-13 16:22:19 +11:00
|
|
|
bmain->filepath[0] = '\0';
|
2016-04-24 22:42:41 +10:00
|
|
|
}
|
2021-03-12 00:34:19 +11:00
|
|
|
else if (recover) {
|
2024-01-24 10:49:24 +01:00
|
|
|
/* In case of auto-save or quit.blend, use original filepath instead (see also #read_global in
|
|
|
|
|
* `readfile.cc`). */
|
2022-09-14 15:48:49 +02:00
|
|
|
bmain->recovered = true;
|
2021-12-13 16:22:19 +11:00
|
|
|
STRNCPY(bmain->filepath, bfd->filepath);
|
2016-04-24 22:42:41 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-01-31 14:22:22 +11:00
|
|
|
/* Base-flags, groups, make depsgraph, etc. */
|
2016-04-24 22:42:41 +10:00
|
|
|
/* first handle case if other windows have different scenes visible */
|
|
|
|
|
if (mode == LOAD_UI) {
|
2023-01-23 00:32:39 +01:00
|
|
|
wmWindowManager *wm = static_cast<wmWindowManager *>(bmain->wm.first);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-04-24 22:42:41 +10:00
|
|
|
if (wm) {
|
2020-04-03 19:15:01 +02:00
|
|
|
LISTBASE_FOREACH (wmWindow *, win, &wm->windows) {
|
Main Workspace Integration
This commit does the main integration of workspaces, which is a design we agreed on during the 2.8 UI workshop (see https://wiki.blender.org/index.php/Dev:2.8/UI/Workshop_Writeup)
Workspaces should generally be stable, I'm not aware of any remaining bugs (or I've forgotten them :) ). If you find any, let me know!
(Exception: mode switching button might get out of sync with actual mode in some cases, would consider that a limitation/ToDo. Needs to be resolved at some point.)
== Main Changes/Features
* Introduces the new Workspaces as data-blocks.
* Allow storing a number of custom workspaces as part of the user configuration. Needs further work to allow adding and deleting individual workspaces.
* Bundle a default workspace configuration with Blender (current screen-layouts converted to workspaces).
* Pressing button to add a workspace spawns a menu to select between "Duplicate Current" and the workspaces from the user configuration. If no workspaces are stored in the user configuration, the default workspaces are listed instead.
* Store screen-layouts (`bScreen`) per workspace.
* Store an active screen-layout per workspace. Changing the workspace will enable this layout.
* Store active mode in workspace. Changing the workspace will also enter the mode of the new workspace. (Note that we still store the active mode in the object, moving this completely to workspaces is a separate project.)
* Store an active render layer per workspace.
* Moved mode switch from 3D View header to Info Editor header.
* Store active scene in window (not directly workspace related, but overlaps quite a bit).
* Removed 'Use Global Scene' User Preference option.
* Compatibility with old files - a new workspace is created for every screen-layout of old files. Old Blender versions should be able to read files saved with workspace support as well.
* Default .blend only contains one workspace ("General").
* Support appending workspaces.
Opening files without UI and commandline rendering should work fine.
Note that the UI is temporary! We plan to introduce a new global topbar
that contains the workspace options and tabs for switching workspaces.
== Technical Notes
* Workspaces are data-blocks.
* Adding and removing `bScreen`s should be done through `ED_workspace_layout` API now.
* A workspace can be active in multiple windows at the same time.
* The mode menu (which is now in the Info Editor header) doesn't display "Grease Pencil Edit" mode anymore since its availability depends on the active editor. Will be fixed by making Grease Pencil an own object type (as planned).
* The button to change the active workspace object mode may get out of sync with the mode of the active object. Will either be resolved by moving mode out of object data, or we'll disable workspace modes again (there's a `#define USE_WORKSPACE_MODE` for that).
* Screen-layouts (`bScreen`) are IDs and thus stored in a main list-base. Had to add a wrapper `WorkSpaceLayout` so we can store them in a list-base within workspaces, too. On the long run we could completely replace `bScreen` by workspace structs.
* `WorkSpace` types use some special compiler trickery to allow marking structs and struct members as private. BKE_workspace API should be used for accessing those.
* Added scene operators `SCENE_OT_`. Was previously done through screen operators.
== BPY API Changes
* Removed `Screen.scene`, added `Window.scene`
* Removed `UserPreferencesView.use_global_scene`
* Added `Context.workspace`, `Window.workspace` and `BlendData.workspaces`
* Added `bpy.types.WorkSpace` containing `screens`, `object_mode` and `render_layer`
* Added Screen.layout_name for the layout name that'll be displayed in the UI (may differ from internal name)
== What's left?
* There are a few open design questions (T50521). We should find the needed answers and implement them.
* Allow adding and removing individual workspaces from workspace configuration (needs UI design).
* Get the override system ready and support overrides per workspace.
* Support custom UI setups as part of workspaces (hidden panels, hidden buttons, customizable toolbars, etc).
* Allow enabling add-ons per workspace.
* Support custom workspace keymaps.
* Remove special exception for workspaces in linking code (so they're always appended, never linked). Depends on a few things, so best to solve later.
* Get the topbar done.
* Workspaces need a proper icon, current one is just a placeholder :)
Reviewed By: campbellbarton, mont29
Tags: #user_interface, #bf_blender_2.8
Maniphest Tasks: T50521
Differential Revision: https://developer.blender.org/D2451
2017-06-01 19:56:58 +02:00
|
|
|
if (win->scene && win->scene != curscene) {
|
2018-06-05 17:02:50 +02:00
|
|
|
BKE_scene_set_background(bmain, win->scene);
|
2016-04-24 22:42:41 +10:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
2017-07-20 15:00:09 +02:00
|
|
|
/* Setting scene might require having a dependency graph, with copy on write
|
|
|
|
|
* we need to make sure we ensure scene has correct color management before
|
|
|
|
|
* constructing dependency graph.
|
|
|
|
|
*/
|
|
|
|
|
if (mode != LOAD_UNDO) {
|
2018-06-05 17:02:50 +02:00
|
|
|
IMB_colormanagement_check_file_config(bmain);
|
2017-07-20 15:00:09 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-06-05 15:10:33 +02:00
|
|
|
BKE_scene_set_background(bmain, curscene);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-04-24 22:42:41 +10:00
|
|
|
if (mode != LOAD_UNDO) {
|
2017-07-20 15:00:09 +02:00
|
|
|
/* TODO(sergey): Can this be also move above? */
|
2016-04-24 22:42:41 +10:00
|
|
|
RE_FreeAllPersistentData();
|
|
|
|
|
}
|
2019-05-22 23:34:07 +02:00
|
|
|
|
Readfile: Refactor several parts of the process
This commit affects:
* Reading undo steps from memfile (aka 'Global Undo');
* Handling of UI IDs (WindowManager, Workspaces and Screens) when
opening a .blend file.
While no major changes are expected from a user PoV, there may be some
unexpected changes in rare edge-cases. None has been identified so far.
Undo step loading should be marginally faster (`setup_app_data` itself
is 2-3 times faster, as it does not do remapping anymore, which makes the
whole 'read undo step' process about 20% faster - but the most
time-consuming step on undo is the depsgraph processing, which remains
unchanged here).
This commit also solves some bugs (crashes) in some relatively uncommon
cases, like e.g. if the WM had an IDProperty pointing at an object and
UI is not loaded when opening a new .blend file with the 'Load UI' option
enabled (as in previous code on file opening WM ID would never be
remapped).
From a more technical side, this commit aims mainly at cleaning things
up, in preparation for the introduction of new 'no undo, no readfile'
type of handling (as part of the Brush Assets project):
- Prevent WM code from doing (too much) horrible ID 'management' on
its WM when opening a new file. It used to remove current WM from
the Main database, store it in a temporary own list, and then free
it itself...
- Trying to make the complex logic behind WM handling on file reading a
bit more easy to follow, at least way more documented in code.
- Keep the handling of 'IDs being re-used from old Main' in a single
place, as much as possible:
-- Readfile code itself in undo case (because it's more efficient,
and undo case is in a way simpler than actual .blend file
reading case). The whole `blo_lib_link_restore` block of code
is also removed.
-- (Mostly) setup_app_data code in actual file reading case.
- Sanitize the usage of the 'libmap' in readfile code in undo case
(waaaaay too many pointers were added there, which was hiding some
other issues in the related code, and potentially causing (in
rare cases) memory addresses collisions.
Pull Request: https://projects.blender.org/blender/blender/pulls/108016
2023-06-05 13:54:49 +02:00
|
|
|
/* Both undo and regular file loading can perform some fairly complex ID manipulation, simpler
|
|
|
|
|
* and safer to fully redo reference-counting. This is a relatively cheap process anyway. */
|
|
|
|
|
BKE_main_id_refcount_recompute(bmain, false);
|
|
|
|
|
|
|
|
|
|
BLI_assert(BKE_main_namemap_validate(bmain));
|
2021-03-05 09:21:12 +01:00
|
|
|
|
2021-03-12 16:45:45 +01:00
|
|
|
if (mode != LOAD_UNDO && !USER_EXPERIMENTAL_TEST(&U, no_override_auto_resync)) {
|
2024-01-19 14:32:28 +01:00
|
|
|
reports->duration.lib_overrides_resync = BLI_check_seconds_timer();
|
2021-06-23 09:51:11 +02:00
|
|
|
|
2021-03-05 09:21:12 +01:00
|
|
|
BKE_lib_override_library_main_resync(
|
|
|
|
|
bmain,
|
|
|
|
|
curscene,
|
2021-05-06 19:04:47 +02:00
|
|
|
bfd->cur_view_layer ? bfd->cur_view_layer : BKE_view_layer_default_view(curscene),
|
|
|
|
|
reports);
|
2021-06-23 09:51:11 +02:00
|
|
|
|
2024-01-19 14:32:28 +01:00
|
|
|
reports->duration.lib_overrides_resync = BLI_check_seconds_timer() -
|
2021-06-23 09:51:11 +02:00
|
|
|
reports->duration.lib_overrides_resync;
|
|
|
|
|
|
2021-03-25 22:27:00 +01:00
|
|
|
/* We need to rebuild some of the deleted override rules (for UI feedback purpose). */
|
2023-01-23 00:32:39 +01:00
|
|
|
BKE_lib_override_library_main_operations_create(bmain, true, nullptr);
|
2021-03-05 09:21:12 +01:00
|
|
|
}
|
2019-05-10 18:46:13 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-05-10 18:46:13 +10:00
|
|
|
static void setup_app_blend_file_data(bContext *C,
|
|
|
|
|
BlendFileData *bfd,
|
2023-06-03 08:36:28 +10:00
|
|
|
const BlendFileReadParams *params,
|
Readfile: Refactor several parts of the process
This commit affects:
* Reading undo steps from memfile (aka 'Global Undo');
* Handling of UI IDs (WindowManager, Workspaces and Screens) when
opening a .blend file.
While no major changes are expected from a user PoV, there may be some
unexpected changes in rare edge-cases. None has been identified so far.
Undo step loading should be marginally faster (`setup_app_data` itself
is 2-3 times faster, as it does not do remapping anymore, which makes the
whole 'read undo step' process about 20% faster - but the most
time-consuming step on undo is the depsgraph processing, which remains
unchanged here).
This commit also solves some bugs (crashes) in some relatively uncommon
cases, like e.g. if the WM had an IDProperty pointing at an object and
UI is not loaded when opening a new .blend file with the 'Load UI' option
enabled (as in previous code on file opening WM ID would never be
remapped).
From a more technical side, this commit aims mainly at cleaning things
up, in preparation for the introduction of new 'no undo, no readfile'
type of handling (as part of the Brush Assets project):
- Prevent WM code from doing (too much) horrible ID 'management' on
its WM when opening a new file. It used to remove current WM from
the Main database, store it in a temporary own list, and then free
it itself...
- Trying to make the complex logic behind WM handling on file reading a
bit more easy to follow, at least way more documented in code.
- Keep the handling of 'IDs being re-used from old Main' in a single
place, as much as possible:
-- Readfile code itself in undo case (because it's more efficient,
and undo case is in a way simpler than actual .blend file
reading case). The whole `blo_lib_link_restore` block of code
is also removed.
-- (Mostly) setup_app_data code in actual file reading case.
- Sanitize the usage of the 'libmap' in readfile code in undo case
(waaaaay too many pointers were added there, which was hiding some
other issues in the related code, and potentially causing (in
rare cases) memory addresses collisions.
Pull Request: https://projects.blender.org/blender/blender/pulls/108016
2023-06-05 13:54:49 +02:00
|
|
|
BlendFileReadWMSetupData *wm_setup_data,
|
2021-06-23 09:51:11 +02:00
|
|
|
BlendFileReadReport *reports)
|
2019-05-10 18:46:13 +10:00
|
|
|
{
|
|
|
|
|
if ((params->skip_flags & BLO_READ_SKIP_USERDEF) == 0) {
|
|
|
|
|
setup_app_userdef(bfd);
|
|
|
|
|
}
|
|
|
|
|
if ((params->skip_flags & BLO_READ_SKIP_DATA) == 0) {
|
Readfile: Refactor several parts of the process
This commit affects:
* Reading undo steps from memfile (aka 'Global Undo');
* Handling of UI IDs (WindowManager, Workspaces and Screens) when
opening a .blend file.
While no major changes are expected from a user PoV, there may be some
unexpected changes in rare edge-cases. None has been identified so far.
Undo step loading should be marginally faster (`setup_app_data` itself
is 2-3 times faster, as it does not do remapping anymore, which makes the
whole 'read undo step' process about 20% faster - but the most
time-consuming step on undo is the depsgraph processing, which remains
unchanged here).
This commit also solves some bugs (crashes) in some relatively uncommon
cases, like e.g. if the WM had an IDProperty pointing at an object and
UI is not loaded when opening a new .blend file with the 'Load UI' option
enabled (as in previous code on file opening WM ID would never be
remapped).
From a more technical side, this commit aims mainly at cleaning things
up, in preparation for the introduction of new 'no undo, no readfile'
type of handling (as part of the Brush Assets project):
- Prevent WM code from doing (too much) horrible ID 'management' on
its WM when opening a new file. It used to remove current WM from
the Main database, store it in a temporary own list, and then free
it itself...
- Trying to make the complex logic behind WM handling on file reading a
bit more easy to follow, at least way more documented in code.
- Keep the handling of 'IDs being re-used from old Main' in a single
place, as much as possible:
-- Readfile code itself in undo case (because it's more efficient,
and undo case is in a way simpler than actual .blend file
reading case). The whole `blo_lib_link_restore` block of code
is also removed.
-- (Mostly) setup_app_data code in actual file reading case.
- Sanitize the usage of the 'libmap' in readfile code in undo case
(waaaaay too many pointers were added there, which was hiding some
other issues in the related code, and potentially causing (in
rare cases) memory addresses collisions.
Pull Request: https://projects.blender.org/blender/blender/pulls/108016
2023-06-05 13:54:49 +02:00
|
|
|
setup_app_data(C, bfd, params, wm_setup_data, reports);
|
2019-05-10 18:46:13 +10:00
|
|
|
}
|
2016-04-24 22:42:41 +10:00
|
|
|
}
|
|
|
|
|
|
2021-06-23 09:51:11 +02:00
|
|
|
static void handle_subversion_warning(Main *main, BlendFileReadReport *reports)
|
2016-04-24 22:42:41 +10:00
|
|
|
{
|
2023-11-03 12:55:29 +01:00
|
|
|
if (main->versionfile > BLENDER_FILE_VERSION || (main->versionfile == BLENDER_FILE_VERSION &&
|
|
|
|
|
main->subversionfile > BLENDER_FILE_SUBVERSION))
|
Blender: change bugfix release versioning from a/b/c to .1/.2/.3
The file subversion is no longer used in the Python API or user interface,
and is now internal to Blender.
User interface, Python API and file I/O metadata now use more consistent
formatting for version numbers. Official releases use "2.83.0", "2.83.1",
and releases under development use "2.90.0 Alpha", "2.90.0 Beta".
Some Python add-ons may need to lower the Blender version in bl_info to
(2, 83, 0) or (2, 90, 0) if they used a subversion number higher than 0.
https://wiki.blender.org/wiki/Reference/Release_Notes/2.83/Python_API#Compatibility
This change is in preparation of LTS releases, and also brings us more
in line with semantic versioning.
Fixes T76058.
Differential Revision: https://developer.blender.org/D7748
2020-05-25 10:49:04 +02:00
|
|
|
{
|
2021-06-23 09:51:11 +02:00
|
|
|
BKE_reportf(reports->reports,
|
2022-08-17 10:22:26 +02:00
|
|
|
RPT_WARNING,
|
2016-04-24 22:42:41 +10:00
|
|
|
"File written by newer Blender binary (%d.%d), expect loss of data!",
|
2023-11-03 12:55:29 +01:00
|
|
|
main->versionfile,
|
|
|
|
|
main->subversionfile);
|
2016-04-24 22:42:41 +10:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
Readfile: Refactor several parts of the process
This commit affects:
* Reading undo steps from memfile (aka 'Global Undo');
* Handling of UI IDs (WindowManager, Workspaces and Screens) when
opening a .blend file.
While no major changes are expected from a user PoV, there may be some
unexpected changes in rare edge-cases. None has been identified so far.
Undo step loading should be marginally faster (`setup_app_data` itself
is 2-3 times faster, as it does not do remapping anymore, which makes the
whole 'read undo step' process about 20% faster - but the most
time-consuming step on undo is the depsgraph processing, which remains
unchanged here).
This commit also solves some bugs (crashes) in some relatively uncommon
cases, like e.g. if the WM had an IDProperty pointing at an object and
UI is not loaded when opening a new .blend file with the 'Load UI' option
enabled (as in previous code on file opening WM ID would never be
remapped).
From a more technical side, this commit aims mainly at cleaning things
up, in preparation for the introduction of new 'no undo, no readfile'
type of handling (as part of the Brush Assets project):
- Prevent WM code from doing (too much) horrible ID 'management' on
its WM when opening a new file. It used to remove current WM from
the Main database, store it in a temporary own list, and then free
it itself...
- Trying to make the complex logic behind WM handling on file reading a
bit more easy to follow, at least way more documented in code.
- Keep the handling of 'IDs being re-used from old Main' in a single
place, as much as possible:
-- Readfile code itself in undo case (because it's more efficient,
and undo case is in a way simpler than actual .blend file
reading case). The whole `blo_lib_link_restore` block of code
is also removed.
-- (Mostly) setup_app_data code in actual file reading case.
- Sanitize the usage of the 'libmap' in readfile code in undo case
(waaaaay too many pointers were added there, which was hiding some
other issues in the related code, and potentially causing (in
rare cases) memory addresses collisions.
Pull Request: https://projects.blender.org/blender/blender/pulls/108016
2023-06-05 13:54:49 +02:00
|
|
|
void BKE_blendfile_read_setup_readfile(bContext *C,
|
|
|
|
|
BlendFileData *bfd,
|
|
|
|
|
const BlendFileReadParams *params,
|
|
|
|
|
BlendFileReadWMSetupData *wm_setup_data,
|
|
|
|
|
BlendFileReadReport *reports,
|
|
|
|
|
/* Extra args. */
|
|
|
|
|
const bool startup_update_defaults,
|
|
|
|
|
const char *startup_app_template)
|
2016-04-24 22:42:41 +10:00
|
|
|
{
|
2023-02-22 16:37:15 +01:00
|
|
|
if (bfd->main->is_read_invalid) {
|
|
|
|
|
BKE_reports_prepend(reports->reports,
|
|
|
|
|
"File could not be read, critical data corruption detected");
|
|
|
|
|
BLO_blendfiledata_free(bfd);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-12 00:34:21 +11:00
|
|
|
if (startup_update_defaults) {
|
|
|
|
|
if ((params->skip_flags & BLO_READ_SKIP_DATA) == 0) {
|
|
|
|
|
BLO_update_defaults_startup_blend(bfd->main, startup_app_template);
|
|
|
|
|
}
|
|
|
|
|
}
|
Readfile: Refactor several parts of the process
This commit affects:
* Reading undo steps from memfile (aka 'Global Undo');
* Handling of UI IDs (WindowManager, Workspaces and Screens) when
opening a .blend file.
While no major changes are expected from a user PoV, there may be some
unexpected changes in rare edge-cases. None has been identified so far.
Undo step loading should be marginally faster (`setup_app_data` itself
is 2-3 times faster, as it does not do remapping anymore, which makes the
whole 'read undo step' process about 20% faster - but the most
time-consuming step on undo is the depsgraph processing, which remains
unchanged here).
This commit also solves some bugs (crashes) in some relatively uncommon
cases, like e.g. if the WM had an IDProperty pointing at an object and
UI is not loaded when opening a new .blend file with the 'Load UI' option
enabled (as in previous code on file opening WM ID would never be
remapped).
From a more technical side, this commit aims mainly at cleaning things
up, in preparation for the introduction of new 'no undo, no readfile'
type of handling (as part of the Brush Assets project):
- Prevent WM code from doing (too much) horrible ID 'management' on
its WM when opening a new file. It used to remove current WM from
the Main database, store it in a temporary own list, and then free
it itself...
- Trying to make the complex logic behind WM handling on file reading a
bit more easy to follow, at least way more documented in code.
- Keep the handling of 'IDs being re-used from old Main' in a single
place, as much as possible:
-- Readfile code itself in undo case (because it's more efficient,
and undo case is in a way simpler than actual .blend file
reading case). The whole `blo_lib_link_restore` block of code
is also removed.
-- (Mostly) setup_app_data code in actual file reading case.
- Sanitize the usage of the 'libmap' in readfile code in undo case
(waaaaay too many pointers were added there, which was hiding some
other issues in the related code, and potentially causing (in
rare cases) memory addresses collisions.
Pull Request: https://projects.blender.org/blender/blender/pulls/108016
2023-06-05 13:54:49 +02:00
|
|
|
setup_app_blend_file_data(C, bfd, params, wm_setup_data, reports);
|
2021-03-12 00:34:21 +11:00
|
|
|
BLO_blendfiledata_free(bfd);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Readfile: Refactor several parts of the process
This commit affects:
* Reading undo steps from memfile (aka 'Global Undo');
* Handling of UI IDs (WindowManager, Workspaces and Screens) when
opening a .blend file.
While no major changes are expected from a user PoV, there may be some
unexpected changes in rare edge-cases. None has been identified so far.
Undo step loading should be marginally faster (`setup_app_data` itself
is 2-3 times faster, as it does not do remapping anymore, which makes the
whole 'read undo step' process about 20% faster - but the most
time-consuming step on undo is the depsgraph processing, which remains
unchanged here).
This commit also solves some bugs (crashes) in some relatively uncommon
cases, like e.g. if the WM had an IDProperty pointing at an object and
UI is not loaded when opening a new .blend file with the 'Load UI' option
enabled (as in previous code on file opening WM ID would never be
remapped).
From a more technical side, this commit aims mainly at cleaning things
up, in preparation for the introduction of new 'no undo, no readfile'
type of handling (as part of the Brush Assets project):
- Prevent WM code from doing (too much) horrible ID 'management' on
its WM when opening a new file. It used to remove current WM from
the Main database, store it in a temporary own list, and then free
it itself...
- Trying to make the complex logic behind WM handling on file reading a
bit more easy to follow, at least way more documented in code.
- Keep the handling of 'IDs being re-used from old Main' in a single
place, as much as possible:
-- Readfile code itself in undo case (because it's more efficient,
and undo case is in a way simpler than actual .blend file
reading case). The whole `blo_lib_link_restore` block of code
is also removed.
-- (Mostly) setup_app_data code in actual file reading case.
- Sanitize the usage of the 'libmap' in readfile code in undo case
(waaaaay too many pointers were added there, which was hiding some
other issues in the related code, and potentially causing (in
rare cases) memory addresses collisions.
Pull Request: https://projects.blender.org/blender/blender/pulls/108016
2023-06-05 13:54:49 +02:00
|
|
|
void BKE_blendfile_read_setup_undo(bContext *C,
|
|
|
|
|
BlendFileData *bfd,
|
|
|
|
|
const BlendFileReadParams *params,
|
|
|
|
|
BlendFileReadReport *reports)
|
2021-03-12 00:34:21 +11:00
|
|
|
{
|
Readfile: Refactor several parts of the process
This commit affects:
* Reading undo steps from memfile (aka 'Global Undo');
* Handling of UI IDs (WindowManager, Workspaces and Screens) when
opening a .blend file.
While no major changes are expected from a user PoV, there may be some
unexpected changes in rare edge-cases. None has been identified so far.
Undo step loading should be marginally faster (`setup_app_data` itself
is 2-3 times faster, as it does not do remapping anymore, which makes the
whole 'read undo step' process about 20% faster - but the most
time-consuming step on undo is the depsgraph processing, which remains
unchanged here).
This commit also solves some bugs (crashes) in some relatively uncommon
cases, like e.g. if the WM had an IDProperty pointing at an object and
UI is not loaded when opening a new .blend file with the 'Load UI' option
enabled (as in previous code on file opening WM ID would never be
remapped).
From a more technical side, this commit aims mainly at cleaning things
up, in preparation for the introduction of new 'no undo, no readfile'
type of handling (as part of the Brush Assets project):
- Prevent WM code from doing (too much) horrible ID 'management' on
its WM when opening a new file. It used to remove current WM from
the Main database, store it in a temporary own list, and then free
it itself...
- Trying to make the complex logic behind WM handling on file reading a
bit more easy to follow, at least way more documented in code.
- Keep the handling of 'IDs being re-used from old Main' in a single
place, as much as possible:
-- Readfile code itself in undo case (because it's more efficient,
and undo case is in a way simpler than actual .blend file
reading case). The whole `blo_lib_link_restore` block of code
is also removed.
-- (Mostly) setup_app_data code in actual file reading case.
- Sanitize the usage of the 'libmap' in readfile code in undo case
(waaaaay too many pointers were added there, which was hiding some
other issues in the related code, and potentially causing (in
rare cases) memory addresses collisions.
Pull Request: https://projects.blender.org/blender/blender/pulls/108016
2023-06-05 13:54:49 +02:00
|
|
|
BKE_blendfile_read_setup_readfile(C, bfd, params, nullptr, reports, false, nullptr);
|
2021-03-12 00:34:21 +11:00
|
|
|
}
|
|
|
|
|
|
2023-06-03 08:36:28 +10:00
|
|
|
BlendFileData *BKE_blendfile_read(const char *filepath,
|
|
|
|
|
const BlendFileReadParams *params,
|
|
|
|
|
BlendFileReadReport *reports)
|
2021-03-12 00:34:21 +11:00
|
|
|
{
|
2019-07-30 10:38:06 +10:00
|
|
|
/* Don't print startup file loading. */
|
|
|
|
|
if (params->is_startup == false) {
|
2023-03-09 12:05:57 +11:00
|
|
|
printf("Read blend: \"%s\"\n", filepath);
|
2017-03-23 10:32:16 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-01-23 00:32:39 +01:00
|
|
|
BlendFileData *bfd = BLO_read_from_file(filepath, eBLOReadSkip(params->skip_flags), reports);
|
2023-02-22 16:37:15 +01:00
|
|
|
if (bfd && bfd->main->is_read_invalid) {
|
|
|
|
|
BLO_blendfiledata_free(bfd);
|
|
|
|
|
bfd = nullptr;
|
|
|
|
|
}
|
2016-04-24 22:42:41 +10:00
|
|
|
if (bfd) {
|
2020-10-03 01:17:31 +10:00
|
|
|
handle_subversion_warning(bfd->main, reports);
|
2016-04-24 22:42:41 +10:00
|
|
|
}
|
2019-04-22 09:39:35 +10:00
|
|
|
else {
|
2023-03-09 12:05:57 +11:00
|
|
|
BKE_reports_prependf(reports->reports, "Loading \"%s\" failed: ", filepath);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2021-03-12 00:34:21 +11:00
|
|
|
return bfd;
|
2016-04-24 22:42:41 +10:00
|
|
|
}
|
|
|
|
|
|
2023-06-03 08:36:28 +10:00
|
|
|
BlendFileData *BKE_blendfile_read_from_memory(const void *filebuf,
|
|
|
|
|
int filelength,
|
|
|
|
|
const BlendFileReadParams *params,
|
|
|
|
|
ReportList *reports)
|
2016-04-24 22:42:41 +10:00
|
|
|
{
|
2023-01-23 00:32:39 +01:00
|
|
|
BlendFileData *bfd = BLO_read_from_memory(
|
|
|
|
|
filebuf, filelength, eBLOReadSkip(params->skip_flags), reports);
|
2023-02-22 16:37:15 +01:00
|
|
|
if (bfd && bfd->main->is_read_invalid) {
|
|
|
|
|
BLO_blendfiledata_free(bfd);
|
|
|
|
|
bfd = nullptr;
|
|
|
|
|
}
|
2016-04-24 22:42:41 +10:00
|
|
|
if (bfd) {
|
2021-03-12 00:34:21 +11:00
|
|
|
/* Pass. */
|
2016-04-24 22:42:41 +10:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
BKE_reports_prepend(reports, "Loading failed: ");
|
|
|
|
|
}
|
2021-03-12 00:34:21 +11:00
|
|
|
return bfd;
|
2016-04-24 22:42:41 +10:00
|
|
|
}
|
|
|
|
|
|
2023-06-03 08:36:28 +10:00
|
|
|
BlendFileData *BKE_blendfile_read_from_memfile(Main *bmain,
|
|
|
|
|
MemFile *memfile,
|
|
|
|
|
const BlendFileReadParams *params,
|
|
|
|
|
ReportList *reports)
|
2016-04-24 22:42:41 +10:00
|
|
|
{
|
2020-10-03 01:17:31 +10:00
|
|
|
BlendFileData *bfd = BLO_read_from_memfile(
|
|
|
|
|
bmain, BKE_main_blendfile_path(bmain), memfile, params, reports);
|
2023-02-22 16:37:15 +01:00
|
|
|
if (bfd && bfd->main->is_read_invalid) {
|
|
|
|
|
BLO_blendfiledata_free(bfd);
|
|
|
|
|
bfd = nullptr;
|
|
|
|
|
}
|
Readfile: Refactor several parts of the process
This commit affects:
* Reading undo steps from memfile (aka 'Global Undo');
* Handling of UI IDs (WindowManager, Workspaces and Screens) when
opening a .blend file.
While no major changes are expected from a user PoV, there may be some
unexpected changes in rare edge-cases. None has been identified so far.
Undo step loading should be marginally faster (`setup_app_data` itself
is 2-3 times faster, as it does not do remapping anymore, which makes the
whole 'read undo step' process about 20% faster - but the most
time-consuming step on undo is the depsgraph processing, which remains
unchanged here).
This commit also solves some bugs (crashes) in some relatively uncommon
cases, like e.g. if the WM had an IDProperty pointing at an object and
UI is not loaded when opening a new .blend file with the 'Load UI' option
enabled (as in previous code on file opening WM ID would never be
remapped).
From a more technical side, this commit aims mainly at cleaning things
up, in preparation for the introduction of new 'no undo, no readfile'
type of handling (as part of the Brush Assets project):
- Prevent WM code from doing (too much) horrible ID 'management' on
its WM when opening a new file. It used to remove current WM from
the Main database, store it in a temporary own list, and then free
it itself...
- Trying to make the complex logic behind WM handling on file reading a
bit more easy to follow, at least way more documented in code.
- Keep the handling of 'IDs being re-used from old Main' in a single
place, as much as possible:
-- Readfile code itself in undo case (because it's more efficient,
and undo case is in a way simpler than actual .blend file
reading case). The whole `blo_lib_link_restore` block of code
is also removed.
-- (Mostly) setup_app_data code in actual file reading case.
- Sanitize the usage of the 'libmap' in readfile code in undo case
(waaaaay too many pointers were added there, which was hiding some
other issues in the related code, and potentially causing (in
rare cases) memory addresses collisions.
Pull Request: https://projects.blender.org/blender/blender/pulls/108016
2023-06-05 13:54:49 +02:00
|
|
|
if (bfd == nullptr) {
|
2016-04-24 22:42:41 +10:00
|
|
|
BKE_reports_prepend(reports, "Loading failed: ");
|
|
|
|
|
}
|
2021-03-12 00:34:21 +11:00
|
|
|
return bfd;
|
2016-04-24 22:42:41 +10:00
|
|
|
}
|
|
|
|
|
|
2017-03-29 19:07:21 +11:00
|
|
|
void BKE_blendfile_read_make_empty(bContext *C)
|
|
|
|
|
{
|
|
|
|
|
Main *bmain = CTX_data_main(C);
|
2019-03-18 11:32:06 +01:00
|
|
|
ListBase *lb;
|
2017-03-29 19:07:21 +11:00
|
|
|
ID *id;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-21 04:40:16 +10:00
|
|
|
FOREACH_MAIN_LISTBASE_BEGIN (bmain, lb) {
|
|
|
|
|
FOREACH_MAIN_LISTBASE_ID_BEGIN (lb, id) {
|
2019-03-18 11:32:06 +01:00
|
|
|
if (ELEM(GS(id->name), ID_SCE, ID_SCR, ID_WM, ID_WS)) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
BKE_id_delete(bmain, id);
|
2017-03-29 19:07:21 +11:00
|
|
|
}
|
2019-03-18 11:32:06 +01:00
|
|
|
FOREACH_MAIN_LISTBASE_ID_END;
|
2017-03-29 19:07:21 +11:00
|
|
|
}
|
2019-03-18 11:32:06 +01:00
|
|
|
FOREACH_MAIN_LISTBASE_END;
|
2017-03-29 19:07:21 +11:00
|
|
|
}
|
|
|
|
|
|
2022-10-05 15:30:42 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Blend File IO (Preferences)
|
|
|
|
|
*
|
|
|
|
|
* Application Templates
|
|
|
|
|
* =====================
|
|
|
|
|
*
|
|
|
|
|
* When using app-templates, both regular & app-template preferences are used.
|
|
|
|
|
* Note that "regular" preferences refers to the preferences used with no app-template is active.
|
|
|
|
|
*
|
|
|
|
|
* - Reading preferences is performed for both the app-template & regular preferences.
|
|
|
|
|
*
|
|
|
|
|
* The preferences are merged by using some from the app-template and other settings from the
|
|
|
|
|
* regular preferences (add-ons from the app-template for example are used),
|
|
|
|
|
* undo-memory uses the regular preferences (for e.g.).
|
|
|
|
|
*
|
|
|
|
|
* - Writing preferences is performed for both the app-template & regular preferences.
|
|
|
|
|
*
|
|
|
|
|
* Writing unmodified preference (#U) into the regular preferences
|
|
|
|
|
* would loose any settings the app-template overrides.
|
|
|
|
|
* To keep default settings the regular preferences is read, add-ons etc temporarily swapped
|
|
|
|
|
* into #U for writing, then swapped back out so as not to change the run-time preferences.
|
|
|
|
|
*
|
|
|
|
|
* \note The function #BKE_blender_userdef_app_template_data_swap determines which settings
|
|
|
|
|
* the app-template overrides.
|
|
|
|
|
* \{ */
|
|
|
|
|
|
2017-03-17 05:10:36 +11:00
|
|
|
UserDef *BKE_blendfile_userdef_read(const char *filepath, ReportList *reports)
|
2016-04-24 22:42:41 +10:00
|
|
|
{
|
|
|
|
|
BlendFileData *bfd;
|
2023-01-23 00:32:39 +01:00
|
|
|
UserDef *userdef = nullptr;
|
|
|
|
|
|
|
|
|
|
BlendFileReadReport blend_file_read_reports{};
|
|
|
|
|
blend_file_read_reports.reports = reports;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-01-23 00:32:39 +01:00
|
|
|
bfd = BLO_read_from_file(
|
|
|
|
|
filepath, BLO_READ_SKIP_ALL & ~BLO_READ_SKIP_USERDEF, &blend_file_read_reports);
|
2016-04-24 22:42:41 +10:00
|
|
|
if (bfd) {
|
|
|
|
|
if (bfd->user) {
|
2017-03-17 05:10:36 +11:00
|
|
|
userdef = bfd->user;
|
2016-04-24 22:42:41 +10:00
|
|
|
}
|
|
|
|
|
BKE_main_free(bfd->main);
|
|
|
|
|
MEM_freeN(bfd);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-03-17 05:10:36 +11:00
|
|
|
return userdef;
|
2016-04-24 22:42:41 +10:00
|
|
|
}
|
|
|
|
|
|
2017-03-17 07:01:11 +11:00
|
|
|
UserDef *BKE_blendfile_userdef_read_from_memory(const void *filebuf,
|
|
|
|
|
int filelength,
|
|
|
|
|
ReportList *reports)
|
|
|
|
|
{
|
|
|
|
|
BlendFileData *bfd;
|
2023-01-23 00:32:39 +01:00
|
|
|
UserDef *userdef = nullptr;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-11-22 14:57:41 +11:00
|
|
|
bfd = BLO_read_from_memory(
|
|
|
|
|
filebuf, filelength, BLO_READ_SKIP_ALL & ~BLO_READ_SKIP_USERDEF, reports);
|
2017-03-17 07:01:11 +11:00
|
|
|
if (bfd) {
|
|
|
|
|
if (bfd->user) {
|
|
|
|
|
userdef = bfd->user;
|
|
|
|
|
}
|
|
|
|
|
BKE_main_free(bfd->main);
|
|
|
|
|
MEM_freeN(bfd);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
BKE_reports_prepend(reports, "Loading failed: ");
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-03-17 07:01:11 +11:00
|
|
|
return userdef;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-02 19:37:22 +10:00
|
|
|
UserDef *BKE_blendfile_userdef_from_defaults()
|
2019-07-30 11:04:02 +10:00
|
|
|
{
|
2023-01-23 02:16:35 +01:00
|
|
|
UserDef *userdef = static_cast<UserDef *>(MEM_callocN(sizeof(UserDef), __func__));
|
2023-01-23 00:55:15 +01:00
|
|
|
*userdef = blender::dna::shallow_copy(U_default);
|
2019-07-30 11:04:02 +10:00
|
|
|
|
|
|
|
|
/* Add-ons. */
|
|
|
|
|
{
|
|
|
|
|
const char *addons[] = {
|
|
|
|
|
"io_anim_bvh",
|
|
|
|
|
"io_curve_svg",
|
|
|
|
|
"io_mesh_stl",
|
|
|
|
|
"io_mesh_uv_layout",
|
|
|
|
|
"io_scene_fbx",
|
|
|
|
|
"io_scene_gltf2",
|
|
|
|
|
"io_scene_x3d",
|
2019-08-02 13:04:10 +02:00
|
|
|
"cycles",
|
2021-07-08 11:06:37 +02:00
|
|
|
"pose_library",
|
2019-07-30 11:04:02 +10:00
|
|
|
};
|
2019-07-31 22:24:19 +10:00
|
|
|
for (int i = 0; i < ARRAY_SIZE(addons); i++) {
|
2019-07-30 11:04:02 +10:00
|
|
|
bAddon *addon = BKE_addon_new();
|
|
|
|
|
STRNCPY(addon->module, addons[i]);
|
|
|
|
|
BLI_addtail(&userdef->addons, addon);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-01 17:23:41 +10:00
|
|
|
/* Theme. */
|
|
|
|
|
{
|
2023-01-23 00:32:39 +01:00
|
|
|
bTheme *btheme = static_cast<bTheme *>(MEM_mallocN(sizeof(*btheme), __func__));
|
2019-08-01 17:23:41 +10:00
|
|
|
memcpy(btheme, &U_theme_default, sizeof(*btheme));
|
|
|
|
|
|
|
|
|
|
BLI_addtail(&userdef->themes, btheme);
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-31 21:46:13 +10:00
|
|
|
#ifdef WITH_PYTHON_SECURITY
|
|
|
|
|
/* use alternative setting for security nuts
|
|
|
|
|
* otherwise we'd need to patch the binary blob - startup.blend.c */
|
|
|
|
|
userdef->flag |= USER_SCRIPT_AUTOEXEC_DISABLE;
|
|
|
|
|
#else
|
|
|
|
|
userdef->flag &= ~USER_SCRIPT_AUTOEXEC_DISABLE;
|
|
|
|
|
#endif
|
|
|
|
|
|
2023-06-22 13:39:17 +10:00
|
|
|
/* System-specific fonts directory.
|
|
|
|
|
* NOTE: when not found, leaves as-is (`//` for the blend-file directory). */
|
|
|
|
|
if (BKE_appdir_font_folder_default(userdef->fontdir, sizeof(userdef->fontdir))) {
|
|
|
|
|
/* Not actually needed, just a convention that directory selection
|
|
|
|
|
* adds a trailing slash. */
|
|
|
|
|
BLI_path_slash_ensure(userdef->fontdir, sizeof(userdef->fontdir));
|
|
|
|
|
}
|
2019-07-31 21:46:13 +10:00
|
|
|
|
2019-08-01 10:03:20 +10:00
|
|
|
userdef->memcachelimit = min_ii(BLI_system_memory_max_in_megabytes_int() / 2,
|
|
|
|
|
userdef->memcachelimit);
|
2019-07-31 21:46:13 +10:00
|
|
|
|
|
|
|
|
/* Init weight paint range. */
|
|
|
|
|
BKE_colorband_init(&userdef->coba_weight, true);
|
|
|
|
|
|
|
|
|
|
/* Default studio light. */
|
|
|
|
|
BKE_studiolight_default(userdef->light_param, userdef->light_ambient);
|
|
|
|
|
|
2020-12-14 13:39:41 +01:00
|
|
|
BKE_preferences_asset_library_default_add(userdef);
|
|
|
|
|
|
2019-07-30 11:04:02 +10:00
|
|
|
return userdef;
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-22 17:11:03 +11:00
|
|
|
bool BKE_blendfile_userdef_write(const char *filepath, ReportList *reports)
|
2016-04-24 22:42:41 +10:00
|
|
|
{
|
2023-01-23 00:32:39 +01:00
|
|
|
Main *mainb = MEM_cnew<Main>("empty main");
|
2017-11-22 17:11:03 +11:00
|
|
|
bool ok = false;
|
2016-04-24 22:42:41 +10:00
|
|
|
|
2023-01-23 00:32:39 +01:00
|
|
|
BlendFileWriteParams params{};
|
|
|
|
|
params.use_userdef = true;
|
|
|
|
|
|
|
|
|
|
if (BLO_write_file(mainb, filepath, 0, ¶ms, reports)) {
|
2017-11-22 17:11:03 +11:00
|
|
|
ok = true;
|
2016-04-24 22:42:41 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MEM_freeN(mainb);
|
|
|
|
|
|
2017-11-22 17:11:03 +11:00
|
|
|
return ok;
|
2016-04-24 22:42:41 +10:00
|
|
|
}
|
|
|
|
|
|
2017-11-23 03:10:58 +11:00
|
|
|
bool BKE_blendfile_userdef_write_app_template(const char *filepath, ReportList *reports)
|
|
|
|
|
{
|
2022-10-05 15:30:44 +11:00
|
|
|
/* Checking that `filepath` exists is not essential, it just avoids printing a warning that
|
|
|
|
|
* the file can't be found. In this case it's not an error - as the file is used if it exists,
|
|
|
|
|
* falling back to the defaults.
|
|
|
|
|
* If the preferences exists but file reading fails - the file can be assumed corrupt
|
|
|
|
|
* so overwriting the file is OK. */
|
2023-01-23 00:32:39 +01:00
|
|
|
UserDef *userdef_default = BLI_exists(filepath) ? BKE_blendfile_userdef_read(filepath, nullptr) :
|
|
|
|
|
nullptr;
|
|
|
|
|
if (userdef_default == nullptr) {
|
2022-10-05 15:30:46 +11:00
|
|
|
userdef_default = BKE_blendfile_userdef_from_defaults();
|
2017-11-23 03:10:58 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-11-23 03:10:58 +11:00
|
|
|
BKE_blender_userdef_app_template_data_swap(&U, userdef_default);
|
|
|
|
|
bool ok = BKE_blendfile_userdef_write(filepath, reports);
|
|
|
|
|
BKE_blender_userdef_app_template_data_swap(&U, userdef_default);
|
|
|
|
|
BKE_blender_userdef_data_free(userdef_default, false);
|
|
|
|
|
MEM_freeN(userdef_default);
|
|
|
|
|
return ok;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-10 15:46:31 +10:00
|
|
|
bool BKE_blendfile_userdef_write_all(ReportList *reports)
|
|
|
|
|
{
|
|
|
|
|
char filepath[FILE_MAX];
|
2024-01-23 18:38:15 +01:00
|
|
|
std::optional<std::string> cfgdir;
|
2019-05-10 15:46:31 +10:00
|
|
|
bool ok = true;
|
|
|
|
|
const bool use_template_userpref = BKE_appdir_app_template_has_userpref(U.app_template);
|
|
|
|
|
|
2023-01-23 00:32:39 +01:00
|
|
|
if ((cfgdir = BKE_appdir_folder_id_create(BLENDER_USER_CONFIG, nullptr))) {
|
2019-05-10 15:46:31 +10:00
|
|
|
bool ok_write;
|
2024-01-23 18:38:15 +01:00
|
|
|
BLI_path_join(filepath, sizeof(filepath), cfgdir->c_str(), BLENDER_USERPREF_FILE);
|
2019-05-10 15:46:31 +10:00
|
|
|
|
2023-03-09 12:05:57 +11:00
|
|
|
printf("Writing userprefs: \"%s\" ", filepath);
|
2019-05-10 15:46:31 +10:00
|
|
|
if (use_template_userpref) {
|
|
|
|
|
ok_write = BKE_blendfile_userdef_write_app_template(filepath, reports);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
ok_write = BKE_blendfile_userdef_write(filepath, reports);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ok_write) {
|
|
|
|
|
printf("ok\n");
|
2021-07-31 03:15:10 +02:00
|
|
|
BKE_report(reports, RPT_INFO, "Preferences saved");
|
2019-05-10 15:46:31 +10:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
printf("fail\n");
|
|
|
|
|
ok = false;
|
2021-07-31 03:15:10 +02:00
|
|
|
BKE_report(reports, RPT_ERROR, "Saving preferences failed");
|
2019-05-10 15:46:31 +10:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
BKE_report(reports, RPT_ERROR, "Unable to create userpref path");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (use_template_userpref) {
|
|
|
|
|
if ((cfgdir = BKE_appdir_folder_id_create(BLENDER_USER_CONFIG, U.app_template))) {
|
2023-07-15 15:45:06 +10:00
|
|
|
/* Also save app-template preferences. */
|
2024-01-23 18:38:15 +01:00
|
|
|
BLI_path_join(filepath, sizeof(filepath), cfgdir->c_str(), BLENDER_USERPREF_FILE);
|
2019-05-10 15:46:31 +10:00
|
|
|
|
2023-03-09 12:05:57 +11:00
|
|
|
printf("Writing userprefs app-template: \"%s\" ", filepath);
|
2019-05-10 15:46:31 +10:00
|
|
|
if (BKE_blendfile_userdef_write(filepath, reports) != 0) {
|
|
|
|
|
printf("ok\n");
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
printf("fail\n");
|
|
|
|
|
ok = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
BKE_report(reports, RPT_ERROR, "Unable to create app-template userpref path");
|
|
|
|
|
ok = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-10 15:57:23 +10:00
|
|
|
if (ok) {
|
|
|
|
|
U.runtime.is_dirty = false;
|
|
|
|
|
}
|
2019-05-10 15:46:31 +10:00
|
|
|
return ok;
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-05 15:30:42 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Blend File IO (WorkSpace)
|
|
|
|
|
* \{ */
|
|
|
|
|
|
2018-08-20 13:52:50 +02:00
|
|
|
WorkspaceConfigFileData *BKE_blendfile_workspace_config_read(const char *filepath,
|
|
|
|
|
const void *filebuf,
|
|
|
|
|
int filelength,
|
|
|
|
|
ReportList *reports)
|
Main Workspace Integration
This commit does the main integration of workspaces, which is a design we agreed on during the 2.8 UI workshop (see https://wiki.blender.org/index.php/Dev:2.8/UI/Workshop_Writeup)
Workspaces should generally be stable, I'm not aware of any remaining bugs (or I've forgotten them :) ). If you find any, let me know!
(Exception: mode switching button might get out of sync with actual mode in some cases, would consider that a limitation/ToDo. Needs to be resolved at some point.)
== Main Changes/Features
* Introduces the new Workspaces as data-blocks.
* Allow storing a number of custom workspaces as part of the user configuration. Needs further work to allow adding and deleting individual workspaces.
* Bundle a default workspace configuration with Blender (current screen-layouts converted to workspaces).
* Pressing button to add a workspace spawns a menu to select between "Duplicate Current" and the workspaces from the user configuration. If no workspaces are stored in the user configuration, the default workspaces are listed instead.
* Store screen-layouts (`bScreen`) per workspace.
* Store an active screen-layout per workspace. Changing the workspace will enable this layout.
* Store active mode in workspace. Changing the workspace will also enter the mode of the new workspace. (Note that we still store the active mode in the object, moving this completely to workspaces is a separate project.)
* Store an active render layer per workspace.
* Moved mode switch from 3D View header to Info Editor header.
* Store active scene in window (not directly workspace related, but overlaps quite a bit).
* Removed 'Use Global Scene' User Preference option.
* Compatibility with old files - a new workspace is created for every screen-layout of old files. Old Blender versions should be able to read files saved with workspace support as well.
* Default .blend only contains one workspace ("General").
* Support appending workspaces.
Opening files without UI and commandline rendering should work fine.
Note that the UI is temporary! We plan to introduce a new global topbar
that contains the workspace options and tabs for switching workspaces.
== Technical Notes
* Workspaces are data-blocks.
* Adding and removing `bScreen`s should be done through `ED_workspace_layout` API now.
* A workspace can be active in multiple windows at the same time.
* The mode menu (which is now in the Info Editor header) doesn't display "Grease Pencil Edit" mode anymore since its availability depends on the active editor. Will be fixed by making Grease Pencil an own object type (as planned).
* The button to change the active workspace object mode may get out of sync with the mode of the active object. Will either be resolved by moving mode out of object data, or we'll disable workspace modes again (there's a `#define USE_WORKSPACE_MODE` for that).
* Screen-layouts (`bScreen`) are IDs and thus stored in a main list-base. Had to add a wrapper `WorkSpaceLayout` so we can store them in a list-base within workspaces, too. On the long run we could completely replace `bScreen` by workspace structs.
* `WorkSpace` types use some special compiler trickery to allow marking structs and struct members as private. BKE_workspace API should be used for accessing those.
* Added scene operators `SCENE_OT_`. Was previously done through screen operators.
== BPY API Changes
* Removed `Screen.scene`, added `Window.scene`
* Removed `UserPreferencesView.use_global_scene`
* Added `Context.workspace`, `Window.workspace` and `BlendData.workspaces`
* Added `bpy.types.WorkSpace` containing `screens`, `object_mode` and `render_layer`
* Added Screen.layout_name for the layout name that'll be displayed in the UI (may differ from internal name)
== What's left?
* There are a few open design questions (T50521). We should find the needed answers and implement them.
* Allow adding and removing individual workspaces from workspace configuration (needs UI design).
* Get the override system ready and support overrides per workspace.
* Support custom UI setups as part of workspaces (hidden panels, hidden buttons, customizable toolbars, etc).
* Allow enabling add-ons per workspace.
* Support custom workspace keymaps.
* Remove special exception for workspaces in linking code (so they're always appended, never linked). Depends on a few things, so best to solve later.
* Get the topbar done.
* Workspaces need a proper icon, current one is just a placeholder :)
Reviewed By: campbellbarton, mont29
Tags: #user_interface, #bf_blender_2.8
Maniphest Tasks: T50521
Differential Revision: https://developer.blender.org/D2451
2017-06-01 19:56:58 +02:00
|
|
|
{
|
|
|
|
|
BlendFileData *bfd;
|
2023-01-23 00:32:39 +01:00
|
|
|
WorkspaceConfigFileData *workspace_config = nullptr;
|
Main Workspace Integration
This commit does the main integration of workspaces, which is a design we agreed on during the 2.8 UI workshop (see https://wiki.blender.org/index.php/Dev:2.8/UI/Workshop_Writeup)
Workspaces should generally be stable, I'm not aware of any remaining bugs (or I've forgotten them :) ). If you find any, let me know!
(Exception: mode switching button might get out of sync with actual mode in some cases, would consider that a limitation/ToDo. Needs to be resolved at some point.)
== Main Changes/Features
* Introduces the new Workspaces as data-blocks.
* Allow storing a number of custom workspaces as part of the user configuration. Needs further work to allow adding and deleting individual workspaces.
* Bundle a default workspace configuration with Blender (current screen-layouts converted to workspaces).
* Pressing button to add a workspace spawns a menu to select between "Duplicate Current" and the workspaces from the user configuration. If no workspaces are stored in the user configuration, the default workspaces are listed instead.
* Store screen-layouts (`bScreen`) per workspace.
* Store an active screen-layout per workspace. Changing the workspace will enable this layout.
* Store active mode in workspace. Changing the workspace will also enter the mode of the new workspace. (Note that we still store the active mode in the object, moving this completely to workspaces is a separate project.)
* Store an active render layer per workspace.
* Moved mode switch from 3D View header to Info Editor header.
* Store active scene in window (not directly workspace related, but overlaps quite a bit).
* Removed 'Use Global Scene' User Preference option.
* Compatibility with old files - a new workspace is created for every screen-layout of old files. Old Blender versions should be able to read files saved with workspace support as well.
* Default .blend only contains one workspace ("General").
* Support appending workspaces.
Opening files without UI and commandline rendering should work fine.
Note that the UI is temporary! We plan to introduce a new global topbar
that contains the workspace options and tabs for switching workspaces.
== Technical Notes
* Workspaces are data-blocks.
* Adding and removing `bScreen`s should be done through `ED_workspace_layout` API now.
* A workspace can be active in multiple windows at the same time.
* The mode menu (which is now in the Info Editor header) doesn't display "Grease Pencil Edit" mode anymore since its availability depends on the active editor. Will be fixed by making Grease Pencil an own object type (as planned).
* The button to change the active workspace object mode may get out of sync with the mode of the active object. Will either be resolved by moving mode out of object data, or we'll disable workspace modes again (there's a `#define USE_WORKSPACE_MODE` for that).
* Screen-layouts (`bScreen`) are IDs and thus stored in a main list-base. Had to add a wrapper `WorkSpaceLayout` so we can store them in a list-base within workspaces, too. On the long run we could completely replace `bScreen` by workspace structs.
* `WorkSpace` types use some special compiler trickery to allow marking structs and struct members as private. BKE_workspace API should be used for accessing those.
* Added scene operators `SCENE_OT_`. Was previously done through screen operators.
== BPY API Changes
* Removed `Screen.scene`, added `Window.scene`
* Removed `UserPreferencesView.use_global_scene`
* Added `Context.workspace`, `Window.workspace` and `BlendData.workspaces`
* Added `bpy.types.WorkSpace` containing `screens`, `object_mode` and `render_layer`
* Added Screen.layout_name for the layout name that'll be displayed in the UI (may differ from internal name)
== What's left?
* There are a few open design questions (T50521). We should find the needed answers and implement them.
* Allow adding and removing individual workspaces from workspace configuration (needs UI design).
* Get the override system ready and support overrides per workspace.
* Support custom UI setups as part of workspaces (hidden panels, hidden buttons, customizable toolbars, etc).
* Allow enabling add-ons per workspace.
* Support custom workspace keymaps.
* Remove special exception for workspaces in linking code (so they're always appended, never linked). Depends on a few things, so best to solve later.
* Get the topbar done.
* Workspaces need a proper icon, current one is just a placeholder :)
Reviewed By: campbellbarton, mont29
Tags: #user_interface, #bf_blender_2.8
Maniphest Tasks: T50521
Differential Revision: https://developer.blender.org/D2451
2017-06-01 19:56:58 +02:00
|
|
|
|
2018-08-20 13:52:50 +02:00
|
|
|
if (filepath) {
|
2023-01-23 00:32:39 +01:00
|
|
|
BlendFileReadReport blend_file_read_reports{};
|
|
|
|
|
blend_file_read_reports.reports = reports;
|
|
|
|
|
bfd = BLO_read_from_file(filepath, BLO_READ_SKIP_USERDEF, &blend_file_read_reports);
|
2018-08-20 13:52:50 +02:00
|
|
|
}
|
|
|
|
|
else {
|
2018-11-22 15:16:45 +11:00
|
|
|
bfd = BLO_read_from_memory(filebuf, filelength, BLO_READ_SKIP_USERDEF, reports);
|
2018-08-20 13:52:50 +02:00
|
|
|
}
|
|
|
|
|
|
Main Workspace Integration
This commit does the main integration of workspaces, which is a design we agreed on during the 2.8 UI workshop (see https://wiki.blender.org/index.php/Dev:2.8/UI/Workshop_Writeup)
Workspaces should generally be stable, I'm not aware of any remaining bugs (or I've forgotten them :) ). If you find any, let me know!
(Exception: mode switching button might get out of sync with actual mode in some cases, would consider that a limitation/ToDo. Needs to be resolved at some point.)
== Main Changes/Features
* Introduces the new Workspaces as data-blocks.
* Allow storing a number of custom workspaces as part of the user configuration. Needs further work to allow adding and deleting individual workspaces.
* Bundle a default workspace configuration with Blender (current screen-layouts converted to workspaces).
* Pressing button to add a workspace spawns a menu to select between "Duplicate Current" and the workspaces from the user configuration. If no workspaces are stored in the user configuration, the default workspaces are listed instead.
* Store screen-layouts (`bScreen`) per workspace.
* Store an active screen-layout per workspace. Changing the workspace will enable this layout.
* Store active mode in workspace. Changing the workspace will also enter the mode of the new workspace. (Note that we still store the active mode in the object, moving this completely to workspaces is a separate project.)
* Store an active render layer per workspace.
* Moved mode switch from 3D View header to Info Editor header.
* Store active scene in window (not directly workspace related, but overlaps quite a bit).
* Removed 'Use Global Scene' User Preference option.
* Compatibility with old files - a new workspace is created for every screen-layout of old files. Old Blender versions should be able to read files saved with workspace support as well.
* Default .blend only contains one workspace ("General").
* Support appending workspaces.
Opening files without UI and commandline rendering should work fine.
Note that the UI is temporary! We plan to introduce a new global topbar
that contains the workspace options and tabs for switching workspaces.
== Technical Notes
* Workspaces are data-blocks.
* Adding and removing `bScreen`s should be done through `ED_workspace_layout` API now.
* A workspace can be active in multiple windows at the same time.
* The mode menu (which is now in the Info Editor header) doesn't display "Grease Pencil Edit" mode anymore since its availability depends on the active editor. Will be fixed by making Grease Pencil an own object type (as planned).
* The button to change the active workspace object mode may get out of sync with the mode of the active object. Will either be resolved by moving mode out of object data, or we'll disable workspace modes again (there's a `#define USE_WORKSPACE_MODE` for that).
* Screen-layouts (`bScreen`) are IDs and thus stored in a main list-base. Had to add a wrapper `WorkSpaceLayout` so we can store them in a list-base within workspaces, too. On the long run we could completely replace `bScreen` by workspace structs.
* `WorkSpace` types use some special compiler trickery to allow marking structs and struct members as private. BKE_workspace API should be used for accessing those.
* Added scene operators `SCENE_OT_`. Was previously done through screen operators.
== BPY API Changes
* Removed `Screen.scene`, added `Window.scene`
* Removed `UserPreferencesView.use_global_scene`
* Added `Context.workspace`, `Window.workspace` and `BlendData.workspaces`
* Added `bpy.types.WorkSpace` containing `screens`, `object_mode` and `render_layer`
* Added Screen.layout_name for the layout name that'll be displayed in the UI (may differ from internal name)
== What's left?
* There are a few open design questions (T50521). We should find the needed answers and implement them.
* Allow adding and removing individual workspaces from workspace configuration (needs UI design).
* Get the override system ready and support overrides per workspace.
* Support custom UI setups as part of workspaces (hidden panels, hidden buttons, customizable toolbars, etc).
* Allow enabling add-ons per workspace.
* Support custom workspace keymaps.
* Remove special exception for workspaces in linking code (so they're always appended, never linked). Depends on a few things, so best to solve later.
* Get the topbar done.
* Workspaces need a proper icon, current one is just a placeholder :)
Reviewed By: campbellbarton, mont29
Tags: #user_interface, #bf_blender_2.8
Maniphest Tasks: T50521
Differential Revision: https://developer.blender.org/D2451
2017-06-01 19:56:58 +02:00
|
|
|
if (bfd) {
|
2023-01-23 00:32:39 +01:00
|
|
|
workspace_config = MEM_cnew<WorkspaceConfigFileData>(__func__);
|
Main Workspace Integration
This commit does the main integration of workspaces, which is a design we agreed on during the 2.8 UI workshop (see https://wiki.blender.org/index.php/Dev:2.8/UI/Workshop_Writeup)
Workspaces should generally be stable, I'm not aware of any remaining bugs (or I've forgotten them :) ). If you find any, let me know!
(Exception: mode switching button might get out of sync with actual mode in some cases, would consider that a limitation/ToDo. Needs to be resolved at some point.)
== Main Changes/Features
* Introduces the new Workspaces as data-blocks.
* Allow storing a number of custom workspaces as part of the user configuration. Needs further work to allow adding and deleting individual workspaces.
* Bundle a default workspace configuration with Blender (current screen-layouts converted to workspaces).
* Pressing button to add a workspace spawns a menu to select between "Duplicate Current" and the workspaces from the user configuration. If no workspaces are stored in the user configuration, the default workspaces are listed instead.
* Store screen-layouts (`bScreen`) per workspace.
* Store an active screen-layout per workspace. Changing the workspace will enable this layout.
* Store active mode in workspace. Changing the workspace will also enter the mode of the new workspace. (Note that we still store the active mode in the object, moving this completely to workspaces is a separate project.)
* Store an active render layer per workspace.
* Moved mode switch from 3D View header to Info Editor header.
* Store active scene in window (not directly workspace related, but overlaps quite a bit).
* Removed 'Use Global Scene' User Preference option.
* Compatibility with old files - a new workspace is created for every screen-layout of old files. Old Blender versions should be able to read files saved with workspace support as well.
* Default .blend only contains one workspace ("General").
* Support appending workspaces.
Opening files without UI and commandline rendering should work fine.
Note that the UI is temporary! We plan to introduce a new global topbar
that contains the workspace options and tabs for switching workspaces.
== Technical Notes
* Workspaces are data-blocks.
* Adding and removing `bScreen`s should be done through `ED_workspace_layout` API now.
* A workspace can be active in multiple windows at the same time.
* The mode menu (which is now in the Info Editor header) doesn't display "Grease Pencil Edit" mode anymore since its availability depends on the active editor. Will be fixed by making Grease Pencil an own object type (as planned).
* The button to change the active workspace object mode may get out of sync with the mode of the active object. Will either be resolved by moving mode out of object data, or we'll disable workspace modes again (there's a `#define USE_WORKSPACE_MODE` for that).
* Screen-layouts (`bScreen`) are IDs and thus stored in a main list-base. Had to add a wrapper `WorkSpaceLayout` so we can store them in a list-base within workspaces, too. On the long run we could completely replace `bScreen` by workspace structs.
* `WorkSpace` types use some special compiler trickery to allow marking structs and struct members as private. BKE_workspace API should be used for accessing those.
* Added scene operators `SCENE_OT_`. Was previously done through screen operators.
== BPY API Changes
* Removed `Screen.scene`, added `Window.scene`
* Removed `UserPreferencesView.use_global_scene`
* Added `Context.workspace`, `Window.workspace` and `BlendData.workspaces`
* Added `bpy.types.WorkSpace` containing `screens`, `object_mode` and `render_layer`
* Added Screen.layout_name for the layout name that'll be displayed in the UI (may differ from internal name)
== What's left?
* There are a few open design questions (T50521). We should find the needed answers and implement them.
* Allow adding and removing individual workspaces from workspace configuration (needs UI design).
* Get the override system ready and support overrides per workspace.
* Support custom UI setups as part of workspaces (hidden panels, hidden buttons, customizable toolbars, etc).
* Allow enabling add-ons per workspace.
* Support custom workspace keymaps.
* Remove special exception for workspaces in linking code (so they're always appended, never linked). Depends on a few things, so best to solve later.
* Get the topbar done.
* Workspaces need a proper icon, current one is just a placeholder :)
Reviewed By: campbellbarton, mont29
Tags: #user_interface, #bf_blender_2.8
Maniphest Tasks: T50521
Differential Revision: https://developer.blender.org/D2451
2017-06-01 19:56:58 +02:00
|
|
|
workspace_config->main = bfd->main;
|
2019-07-16 16:06:50 +02:00
|
|
|
|
|
|
|
|
/* Only 2.80+ files have actual workspaces, don't try to use screens
|
|
|
|
|
* from older versions. */
|
|
|
|
|
if (bfd->main->versionfile >= 280) {
|
|
|
|
|
workspace_config->workspaces = bfd->main->workspaces;
|
|
|
|
|
}
|
Main Workspace Integration
This commit does the main integration of workspaces, which is a design we agreed on during the 2.8 UI workshop (see https://wiki.blender.org/index.php/Dev:2.8/UI/Workshop_Writeup)
Workspaces should generally be stable, I'm not aware of any remaining bugs (or I've forgotten them :) ). If you find any, let me know!
(Exception: mode switching button might get out of sync with actual mode in some cases, would consider that a limitation/ToDo. Needs to be resolved at some point.)
== Main Changes/Features
* Introduces the new Workspaces as data-blocks.
* Allow storing a number of custom workspaces as part of the user configuration. Needs further work to allow adding and deleting individual workspaces.
* Bundle a default workspace configuration with Blender (current screen-layouts converted to workspaces).
* Pressing button to add a workspace spawns a menu to select between "Duplicate Current" and the workspaces from the user configuration. If no workspaces are stored in the user configuration, the default workspaces are listed instead.
* Store screen-layouts (`bScreen`) per workspace.
* Store an active screen-layout per workspace. Changing the workspace will enable this layout.
* Store active mode in workspace. Changing the workspace will also enter the mode of the new workspace. (Note that we still store the active mode in the object, moving this completely to workspaces is a separate project.)
* Store an active render layer per workspace.
* Moved mode switch from 3D View header to Info Editor header.
* Store active scene in window (not directly workspace related, but overlaps quite a bit).
* Removed 'Use Global Scene' User Preference option.
* Compatibility with old files - a new workspace is created for every screen-layout of old files. Old Blender versions should be able to read files saved with workspace support as well.
* Default .blend only contains one workspace ("General").
* Support appending workspaces.
Opening files without UI and commandline rendering should work fine.
Note that the UI is temporary! We plan to introduce a new global topbar
that contains the workspace options and tabs for switching workspaces.
== Technical Notes
* Workspaces are data-blocks.
* Adding and removing `bScreen`s should be done through `ED_workspace_layout` API now.
* A workspace can be active in multiple windows at the same time.
* The mode menu (which is now in the Info Editor header) doesn't display "Grease Pencil Edit" mode anymore since its availability depends on the active editor. Will be fixed by making Grease Pencil an own object type (as planned).
* The button to change the active workspace object mode may get out of sync with the mode of the active object. Will either be resolved by moving mode out of object data, or we'll disable workspace modes again (there's a `#define USE_WORKSPACE_MODE` for that).
* Screen-layouts (`bScreen`) are IDs and thus stored in a main list-base. Had to add a wrapper `WorkSpaceLayout` so we can store them in a list-base within workspaces, too. On the long run we could completely replace `bScreen` by workspace structs.
* `WorkSpace` types use some special compiler trickery to allow marking structs and struct members as private. BKE_workspace API should be used for accessing those.
* Added scene operators `SCENE_OT_`. Was previously done through screen operators.
== BPY API Changes
* Removed `Screen.scene`, added `Window.scene`
* Removed `UserPreferencesView.use_global_scene`
* Added `Context.workspace`, `Window.workspace` and `BlendData.workspaces`
* Added `bpy.types.WorkSpace` containing `screens`, `object_mode` and `render_layer`
* Added Screen.layout_name for the layout name that'll be displayed in the UI (may differ from internal name)
== What's left?
* There are a few open design questions (T50521). We should find the needed answers and implement them.
* Allow adding and removing individual workspaces from workspace configuration (needs UI design).
* Get the override system ready and support overrides per workspace.
* Support custom UI setups as part of workspaces (hidden panels, hidden buttons, customizable toolbars, etc).
* Allow enabling add-ons per workspace.
* Support custom workspace keymaps.
* Remove special exception for workspaces in linking code (so they're always appended, never linked). Depends on a few things, so best to solve later.
* Get the topbar done.
* Workspaces need a proper icon, current one is just a placeholder :)
Reviewed By: campbellbarton, mont29
Tags: #user_interface, #bf_blender_2.8
Maniphest Tasks: T50521
Differential Revision: https://developer.blender.org/D2451
2017-06-01 19:56:58 +02:00
|
|
|
|
|
|
|
|
MEM_freeN(bfd);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return workspace_config;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool BKE_blendfile_workspace_config_write(Main *bmain, const char *filepath, ReportList *reports)
|
|
|
|
|
{
|
2020-06-19 15:41:07 +10:00
|
|
|
const int fileflags = G.fileflags & ~G_FILE_NO_UI;
|
Main Workspace Integration
This commit does the main integration of workspaces, which is a design we agreed on during the 2.8 UI workshop (see https://wiki.blender.org/index.php/Dev:2.8/UI/Workshop_Writeup)
Workspaces should generally be stable, I'm not aware of any remaining bugs (or I've forgotten them :) ). If you find any, let me know!
(Exception: mode switching button might get out of sync with actual mode in some cases, would consider that a limitation/ToDo. Needs to be resolved at some point.)
== Main Changes/Features
* Introduces the new Workspaces as data-blocks.
* Allow storing a number of custom workspaces as part of the user configuration. Needs further work to allow adding and deleting individual workspaces.
* Bundle a default workspace configuration with Blender (current screen-layouts converted to workspaces).
* Pressing button to add a workspace spawns a menu to select between "Duplicate Current" and the workspaces from the user configuration. If no workspaces are stored in the user configuration, the default workspaces are listed instead.
* Store screen-layouts (`bScreen`) per workspace.
* Store an active screen-layout per workspace. Changing the workspace will enable this layout.
* Store active mode in workspace. Changing the workspace will also enter the mode of the new workspace. (Note that we still store the active mode in the object, moving this completely to workspaces is a separate project.)
* Store an active render layer per workspace.
* Moved mode switch from 3D View header to Info Editor header.
* Store active scene in window (not directly workspace related, but overlaps quite a bit).
* Removed 'Use Global Scene' User Preference option.
* Compatibility with old files - a new workspace is created for every screen-layout of old files. Old Blender versions should be able to read files saved with workspace support as well.
* Default .blend only contains one workspace ("General").
* Support appending workspaces.
Opening files without UI and commandline rendering should work fine.
Note that the UI is temporary! We plan to introduce a new global topbar
that contains the workspace options and tabs for switching workspaces.
== Technical Notes
* Workspaces are data-blocks.
* Adding and removing `bScreen`s should be done through `ED_workspace_layout` API now.
* A workspace can be active in multiple windows at the same time.
* The mode menu (which is now in the Info Editor header) doesn't display "Grease Pencil Edit" mode anymore since its availability depends on the active editor. Will be fixed by making Grease Pencil an own object type (as planned).
* The button to change the active workspace object mode may get out of sync with the mode of the active object. Will either be resolved by moving mode out of object data, or we'll disable workspace modes again (there's a `#define USE_WORKSPACE_MODE` for that).
* Screen-layouts (`bScreen`) are IDs and thus stored in a main list-base. Had to add a wrapper `WorkSpaceLayout` so we can store them in a list-base within workspaces, too. On the long run we could completely replace `bScreen` by workspace structs.
* `WorkSpace` types use some special compiler trickery to allow marking structs and struct members as private. BKE_workspace API should be used for accessing those.
* Added scene operators `SCENE_OT_`. Was previously done through screen operators.
== BPY API Changes
* Removed `Screen.scene`, added `Window.scene`
* Removed `UserPreferencesView.use_global_scene`
* Added `Context.workspace`, `Window.workspace` and `BlendData.workspaces`
* Added `bpy.types.WorkSpace` containing `screens`, `object_mode` and `render_layer`
* Added Screen.layout_name for the layout name that'll be displayed in the UI (may differ from internal name)
== What's left?
* There are a few open design questions (T50521). We should find the needed answers and implement them.
* Allow adding and removing individual workspaces from workspace configuration (needs UI design).
* Get the override system ready and support overrides per workspace.
* Support custom UI setups as part of workspaces (hidden panels, hidden buttons, customizable toolbars, etc).
* Allow enabling add-ons per workspace.
* Support custom workspace keymaps.
* Remove special exception for workspaces in linking code (so they're always appended, never linked). Depends on a few things, so best to solve later.
* Get the topbar done.
* Workspaces need a proper icon, current one is just a placeholder :)
Reviewed By: campbellbarton, mont29
Tags: #user_interface, #bf_blender_2.8
Maniphest Tasks: T50521
Differential Revision: https://developer.blender.org/D2451
2017-06-01 19:56:58 +02:00
|
|
|
bool retval = false;
|
|
|
|
|
|
|
|
|
|
BKE_blendfile_write_partial_begin(bmain);
|
|
|
|
|
|
2023-01-23 00:32:39 +01:00
|
|
|
for (WorkSpace *workspace = static_cast<WorkSpace *>(bmain->workspaces.first); workspace;
|
|
|
|
|
workspace = static_cast<WorkSpace *>(workspace->id.next))
|
|
|
|
|
{
|
Main Workspace Integration
This commit does the main integration of workspaces, which is a design we agreed on during the 2.8 UI workshop (see https://wiki.blender.org/index.php/Dev:2.8/UI/Workshop_Writeup)
Workspaces should generally be stable, I'm not aware of any remaining bugs (or I've forgotten them :) ). If you find any, let me know!
(Exception: mode switching button might get out of sync with actual mode in some cases, would consider that a limitation/ToDo. Needs to be resolved at some point.)
== Main Changes/Features
* Introduces the new Workspaces as data-blocks.
* Allow storing a number of custom workspaces as part of the user configuration. Needs further work to allow adding and deleting individual workspaces.
* Bundle a default workspace configuration with Blender (current screen-layouts converted to workspaces).
* Pressing button to add a workspace spawns a menu to select between "Duplicate Current" and the workspaces from the user configuration. If no workspaces are stored in the user configuration, the default workspaces are listed instead.
* Store screen-layouts (`bScreen`) per workspace.
* Store an active screen-layout per workspace. Changing the workspace will enable this layout.
* Store active mode in workspace. Changing the workspace will also enter the mode of the new workspace. (Note that we still store the active mode in the object, moving this completely to workspaces is a separate project.)
* Store an active render layer per workspace.
* Moved mode switch from 3D View header to Info Editor header.
* Store active scene in window (not directly workspace related, but overlaps quite a bit).
* Removed 'Use Global Scene' User Preference option.
* Compatibility with old files - a new workspace is created for every screen-layout of old files. Old Blender versions should be able to read files saved with workspace support as well.
* Default .blend only contains one workspace ("General").
* Support appending workspaces.
Opening files without UI and commandline rendering should work fine.
Note that the UI is temporary! We plan to introduce a new global topbar
that contains the workspace options and tabs for switching workspaces.
== Technical Notes
* Workspaces are data-blocks.
* Adding and removing `bScreen`s should be done through `ED_workspace_layout` API now.
* A workspace can be active in multiple windows at the same time.
* The mode menu (which is now in the Info Editor header) doesn't display "Grease Pencil Edit" mode anymore since its availability depends on the active editor. Will be fixed by making Grease Pencil an own object type (as planned).
* The button to change the active workspace object mode may get out of sync with the mode of the active object. Will either be resolved by moving mode out of object data, or we'll disable workspace modes again (there's a `#define USE_WORKSPACE_MODE` for that).
* Screen-layouts (`bScreen`) are IDs and thus stored in a main list-base. Had to add a wrapper `WorkSpaceLayout` so we can store them in a list-base within workspaces, too. On the long run we could completely replace `bScreen` by workspace structs.
* `WorkSpace` types use some special compiler trickery to allow marking structs and struct members as private. BKE_workspace API should be used for accessing those.
* Added scene operators `SCENE_OT_`. Was previously done through screen operators.
== BPY API Changes
* Removed `Screen.scene`, added `Window.scene`
* Removed `UserPreferencesView.use_global_scene`
* Added `Context.workspace`, `Window.workspace` and `BlendData.workspaces`
* Added `bpy.types.WorkSpace` containing `screens`, `object_mode` and `render_layer`
* Added Screen.layout_name for the layout name that'll be displayed in the UI (may differ from internal name)
== What's left?
* There are a few open design questions (T50521). We should find the needed answers and implement them.
* Allow adding and removing individual workspaces from workspace configuration (needs UI design).
* Get the override system ready and support overrides per workspace.
* Support custom UI setups as part of workspaces (hidden panels, hidden buttons, customizable toolbars, etc).
* Allow enabling add-ons per workspace.
* Support custom workspace keymaps.
* Remove special exception for workspaces in linking code (so they're always appended, never linked). Depends on a few things, so best to solve later.
* Get the topbar done.
* Workspaces need a proper icon, current one is just a placeholder :)
Reviewed By: campbellbarton, mont29
Tags: #user_interface, #bf_blender_2.8
Maniphest Tasks: T50521
Differential Revision: https://developer.blender.org/D2451
2017-06-01 19:56:58 +02:00
|
|
|
BKE_blendfile_write_partial_tag_ID(&workspace->id, true);
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-18 15:25:22 +10:00
|
|
|
if (BKE_blendfile_write_partial(bmain, filepath, fileflags, BLO_WRITE_PATH_REMAP_NONE, reports))
|
|
|
|
|
{
|
Main Workspace Integration
This commit does the main integration of workspaces, which is a design we agreed on during the 2.8 UI workshop (see https://wiki.blender.org/index.php/Dev:2.8/UI/Workshop_Writeup)
Workspaces should generally be stable, I'm not aware of any remaining bugs (or I've forgotten them :) ). If you find any, let me know!
(Exception: mode switching button might get out of sync with actual mode in some cases, would consider that a limitation/ToDo. Needs to be resolved at some point.)
== Main Changes/Features
* Introduces the new Workspaces as data-blocks.
* Allow storing a number of custom workspaces as part of the user configuration. Needs further work to allow adding and deleting individual workspaces.
* Bundle a default workspace configuration with Blender (current screen-layouts converted to workspaces).
* Pressing button to add a workspace spawns a menu to select between "Duplicate Current" and the workspaces from the user configuration. If no workspaces are stored in the user configuration, the default workspaces are listed instead.
* Store screen-layouts (`bScreen`) per workspace.
* Store an active screen-layout per workspace. Changing the workspace will enable this layout.
* Store active mode in workspace. Changing the workspace will also enter the mode of the new workspace. (Note that we still store the active mode in the object, moving this completely to workspaces is a separate project.)
* Store an active render layer per workspace.
* Moved mode switch from 3D View header to Info Editor header.
* Store active scene in window (not directly workspace related, but overlaps quite a bit).
* Removed 'Use Global Scene' User Preference option.
* Compatibility with old files - a new workspace is created for every screen-layout of old files. Old Blender versions should be able to read files saved with workspace support as well.
* Default .blend only contains one workspace ("General").
* Support appending workspaces.
Opening files without UI and commandline rendering should work fine.
Note that the UI is temporary! We plan to introduce a new global topbar
that contains the workspace options and tabs for switching workspaces.
== Technical Notes
* Workspaces are data-blocks.
* Adding and removing `bScreen`s should be done through `ED_workspace_layout` API now.
* A workspace can be active in multiple windows at the same time.
* The mode menu (which is now in the Info Editor header) doesn't display "Grease Pencil Edit" mode anymore since its availability depends on the active editor. Will be fixed by making Grease Pencil an own object type (as planned).
* The button to change the active workspace object mode may get out of sync with the mode of the active object. Will either be resolved by moving mode out of object data, or we'll disable workspace modes again (there's a `#define USE_WORKSPACE_MODE` for that).
* Screen-layouts (`bScreen`) are IDs and thus stored in a main list-base. Had to add a wrapper `WorkSpaceLayout` so we can store them in a list-base within workspaces, too. On the long run we could completely replace `bScreen` by workspace structs.
* `WorkSpace` types use some special compiler trickery to allow marking structs and struct members as private. BKE_workspace API should be used for accessing those.
* Added scene operators `SCENE_OT_`. Was previously done through screen operators.
== BPY API Changes
* Removed `Screen.scene`, added `Window.scene`
* Removed `UserPreferencesView.use_global_scene`
* Added `Context.workspace`, `Window.workspace` and `BlendData.workspaces`
* Added `bpy.types.WorkSpace` containing `screens`, `object_mode` and `render_layer`
* Added Screen.layout_name for the layout name that'll be displayed in the UI (may differ from internal name)
== What's left?
* There are a few open design questions (T50521). We should find the needed answers and implement them.
* Allow adding and removing individual workspaces from workspace configuration (needs UI design).
* Get the override system ready and support overrides per workspace.
* Support custom UI setups as part of workspaces (hidden panels, hidden buttons, customizable toolbars, etc).
* Allow enabling add-ons per workspace.
* Support custom workspace keymaps.
* Remove special exception for workspaces in linking code (so they're always appended, never linked). Depends on a few things, so best to solve later.
* Get the topbar done.
* Workspaces need a proper icon, current one is just a placeholder :)
Reviewed By: campbellbarton, mont29
Tags: #user_interface, #bf_blender_2.8
Maniphest Tasks: T50521
Differential Revision: https://developer.blender.org/D2451
2017-06-01 19:56:58 +02:00
|
|
|
retval = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BKE_blendfile_write_partial_end(bmain);
|
|
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BKE_blendfile_workspace_config_data_free(WorkspaceConfigFileData *workspace_config)
|
|
|
|
|
{
|
|
|
|
|
BKE_main_free(workspace_config->main);
|
|
|
|
|
MEM_freeN(workspace_config);
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-24 22:42:41 +10:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
2022-10-05 15:30:42 +11:00
|
|
|
/** \name Blend File Write (Partial)
|
2016-04-24 22:42:41 +10:00
|
|
|
* \{ */
|
|
|
|
|
|
2023-06-02 10:16:18 +10:00
|
|
|
static void blendfile_write_partial_clear_flags(Main *bmain_src)
|
2016-04-24 22:42:41 +10:00
|
|
|
{
|
2023-06-02 10:16:18 +10:00
|
|
|
ListBase *lbarray[INDEX_ID_MAX];
|
|
|
|
|
int a = set_listbasepointers(bmain_src, lbarray);
|
|
|
|
|
while (a--) {
|
|
|
|
|
LISTBASE_FOREACH (ID *, id, lbarray[a]) {
|
|
|
|
|
id->tag &= ~(LIB_TAG_NEED_EXPAND | LIB_TAG_DOIT);
|
|
|
|
|
id->flag &= ~(LIB_CLIPBOARD_MARK);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BKE_blendfile_write_partial_begin(Main *bmain)
|
|
|
|
|
{
|
|
|
|
|
blendfile_write_partial_clear_flags(bmain);
|
2016-04-24 22:42:41 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BKE_blendfile_write_partial_tag_ID(ID *id, bool set)
|
|
|
|
|
{
|
|
|
|
|
if (set) {
|
|
|
|
|
id->tag |= LIB_TAG_NEED_EXPAND | LIB_TAG_DOIT;
|
2023-06-02 10:16:18 +10:00
|
|
|
id->flag |= LIB_CLIPBOARD_MARK;
|
2016-04-24 22:42:41 +10:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
id->tag &= ~(LIB_TAG_NEED_EXPAND | LIB_TAG_DOIT);
|
2023-06-02 10:16:18 +10:00
|
|
|
id->flag &= ~LIB_CLIPBOARD_MARK;
|
2016-04-24 22:42:41 +10:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-23 00:32:39 +01:00
|
|
|
static void blendfile_write_partial_cb(void * /*handle*/, Main * /*bmain*/, void *vid)
|
2016-04-24 22:42:41 +10:00
|
|
|
{
|
|
|
|
|
if (vid) {
|
2023-01-23 00:32:39 +01:00
|
|
|
ID *id = static_cast<ID *>(vid);
|
2016-04-24 22:42:41 +10:00
|
|
|
/* only tag for need-expand if not done, prevents eternal loops */
|
2019-04-22 09:39:35 +10:00
|
|
|
if ((id->tag & LIB_TAG_DOIT) == 0) {
|
2016-04-24 22:42:41 +10:00
|
|
|
id->tag |= LIB_TAG_NEED_EXPAND | LIB_TAG_DOIT;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (id->lib && (id->lib->id.tag & LIB_TAG_DOIT) == 0) {
|
2016-05-13 14:07:30 +02:00
|
|
|
id->lib->id.tag |= LIB_TAG_DOIT;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2016-04-24 22:42:41 +10:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool BKE_blendfile_write_partial(Main *bmain_src,
|
|
|
|
|
const char *filepath,
|
|
|
|
|
const int write_flags,
|
2020-06-18 15:25:22 +10:00
|
|
|
const int remap_mode,
|
2016-04-24 22:42:41 +10:00
|
|
|
ReportList *reports)
|
|
|
|
|
{
|
2023-01-23 00:32:39 +01:00
|
|
|
Main *bmain_dst = MEM_cnew<Main>("copybuffer");
|
2021-03-04 18:39:07 +01:00
|
|
|
ListBase *lbarray_dst[INDEX_ID_MAX], *lbarray_src[INDEX_ID_MAX];
|
2016-04-24 22:42:41 +10:00
|
|
|
int a, retval;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-01-23 00:32:39 +01:00
|
|
|
void *path_list_backup = nullptr;
|
Refactor BKE_bpath module.
The main goal of this refactor is to make BPath module use `IDTypeInfo`,
and move each ID-specific part of the `foreach_path` looper into their
own IDTypeInfo struct, using a new `foreach_path` callback.
Additionally, following improvements/cleanups are included:
* Attempt to get better, more consistent namings.
** In particular, move from `path_visitor` to more standard `foreach_path`.
* Update and extend documentation.
** API doc was moved to header, according to recent discussions on this
topic.
* Remove `BKE_bpath_relocate_visitor` from API, this is specific
callback that belongs in `lib_id.c` user code.
NOTE: This commit is expected to be 100% non-behavioral-change. This
implies that several potential further changes were only noted as
comments (like using a more generic solution for
`lib_id_library_local_paths`, addressing inconsistencies like path of
packed libraries always being skipped, regardless of the
`BKE_BPATH_FOREACH_PATH_SKIP_PACKED` `eBPathForeachFlag` flag value,
etc.).
NOTE: basic unittests were added to master already in
rBdcc500e5a265093bc9cc.
Reviewed By: brecht
Differential Revision: https://developer.blender.org/D13381
2021-11-29 14:20:58 +01:00
|
|
|
const eBPathForeachFlag path_list_flag = (BKE_BPATH_FOREACH_PATH_SKIP_LINKED |
|
|
|
|
|
BKE_BPATH_FOREACH_PATH_SKIP_MULTIFILE);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-09-14 11:35:16 +02:00
|
|
|
/* This is needed to be able to load that file as a real one later
|
2021-12-13 16:22:19 +11:00
|
|
|
* (otherwise `main->filepath` will not be set at read time). */
|
|
|
|
|
STRNCPY(bmain_dst->filepath, bmain_src->filepath);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-04-24 22:42:41 +10:00
|
|
|
BLO_main_expander(blendfile_write_partial_cb);
|
2023-01-23 00:32:39 +01:00
|
|
|
BLO_expand_main(nullptr, bmain_src);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-04-24 22:42:41 +10:00
|
|
|
/* move over all tagged blocks */
|
|
|
|
|
set_listbasepointers(bmain_src, lbarray_src);
|
|
|
|
|
a = set_listbasepointers(bmain_dst, lbarray_dst);
|
|
|
|
|
while (a--) {
|
|
|
|
|
ID *id, *nextid;
|
|
|
|
|
ListBase *lb_dst = lbarray_dst[a], *lb_src = lbarray_src[a];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-01-23 00:32:39 +01:00
|
|
|
for (id = static_cast<ID *>(lb_src->first); id; id = nextid) {
|
|
|
|
|
nextid = static_cast<ID *>(id->next);
|
2016-04-24 22:42:41 +10:00
|
|
|
if (id->tag & LIB_TAG_DOIT) {
|
|
|
|
|
BLI_remlink(lb_src, id);
|
|
|
|
|
BLI_addtail(lb_dst, id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-10-18 19:51:34 +02:00
|
|
|
/* Backup paths because remap relative will overwrite them.
|
|
|
|
|
*
|
2019-06-12 09:04:10 +10:00
|
|
|
* NOTE: we do this only on the list of data-blocks that we are writing
|
2018-10-18 19:51:34 +02:00
|
|
|
* because the restored full list is not guaranteed to be in the same
|
|
|
|
|
* order as before, as expected by BKE_bpath_list_restore.
|
|
|
|
|
*
|
|
|
|
|
* This happens because id_sort_by_name does not take into account
|
|
|
|
|
* string case or the library name, so the order is not strictly
|
2019-06-12 09:04:10 +10:00
|
|
|
* defined for two linked data-blocks with the same name! */
|
2020-06-18 15:25:22 +10:00
|
|
|
if (remap_mode != BLO_WRITE_PATH_REMAP_NONE) {
|
2018-10-18 19:51:34 +02:00
|
|
|
path_list_backup = BKE_bpath_list_backup(bmain_dst, path_list_flag);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-04-24 22:42:41 +10:00
|
|
|
/* save the buffer */
|
2023-01-23 00:32:39 +01:00
|
|
|
BlendFileWriteParams blend_file_write_params{};
|
|
|
|
|
blend_file_write_params.remap_mode = eBLO_WritePathRemap(remap_mode);
|
|
|
|
|
retval = BLO_write_file(bmain_dst, filepath, write_flags, &blend_file_write_params, reports);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-10-18 19:51:34 +02:00
|
|
|
if (path_list_backup) {
|
|
|
|
|
BKE_bpath_list_restore(bmain_dst, path_list_flag, path_list_backup);
|
|
|
|
|
BKE_bpath_list_free(path_list_backup);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-04-24 22:42:41 +10:00
|
|
|
/* move back the main, now sorted again */
|
|
|
|
|
set_listbasepointers(bmain_src, lbarray_dst);
|
|
|
|
|
a = set_listbasepointers(bmain_dst, lbarray_src);
|
|
|
|
|
while (a--) {
|
|
|
|
|
ListBase *lb_dst = lbarray_dst[a], *lb_src = lbarray_src[a];
|
2023-08-03 18:23:49 +10:00
|
|
|
while (ID *id = static_cast<ID *>(BLI_pophead(lb_src))) {
|
2016-04-24 22:42:41 +10:00
|
|
|
BLI_addtail(lb_dst, id);
|
2023-01-23 00:32:39 +01:00
|
|
|
id_sort_by_name(lb_dst, id, nullptr);
|
2016-04-24 22:42:41 +10:00
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-04-24 22:42:41 +10:00
|
|
|
MEM_freeN(bmain_dst);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-04-24 22:42:41 +10:00
|
|
|
return retval;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BKE_blendfile_write_partial_end(Main *bmain_src)
|
|
|
|
|
{
|
2023-06-02 10:16:18 +10:00
|
|
|
blendfile_write_partial_clear_flags(bmain_src);
|
2016-04-24 22:42:41 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** \} */
|