Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenloader/intern/readfile.c
- This file is larger than 256 KB, so syntax highlighting is disabled by default.
| Show First 20 Lines • Show All 2,859 Lines • ▼ Show 20 Lines | static void direct_link_cachefile(FileData *fd, CacheFile *cache_file) | ||||
| /* relink animdata */ | /* relink animdata */ | ||||
| cache_file->adt = newdataadr(fd, cache_file->adt); | cache_file->adt = newdataadr(fd, cache_file->adt); | ||||
| direct_link_animdata(fd, cache_file->adt); | direct_link_animdata(fd, cache_file->adt); | ||||
| } | } | ||||
| /* ************ READ WORKSPACES *************** */ | /* ************ READ WORKSPACES *************** */ | ||||
| static void lib_link_workspace_scene_data(FileData *fd, WorkSpace *workspace) | |||||
| { | |||||
| for (WorkSpaceSceneRelation *relation = workspace->scene_relations.first; | |||||
| relation != NULL; | |||||
| relation = relation->next) | |||||
| { | |||||
| relation->scene = newlibadr(fd, workspace->id.lib, relation->scene); | |||||
| } | |||||
| /* Free any relations that got lost due to missing datablocks. */ | |||||
| BKE_workspace_scene_relations_free_invalid(workspace); | |||||
| } | |||||
| static void lib_link_workspaces(FileData *fd, Main *bmain) | static void lib_link_workspaces(FileData *fd, Main *bmain) | ||||
| { | { | ||||
| for (WorkSpace *workspace = bmain->workspaces.first; workspace; workspace = workspace->id.next) { | for (WorkSpace *workspace = bmain->workspaces.first; workspace; workspace = workspace->id.next) { | ||||
| ListBase *layouts = BKE_workspace_layouts_get(workspace); | ListBase *layouts = BKE_workspace_layouts_get(workspace); | ||||
| ID *id = (ID *)workspace; | ID *id = (ID *)workspace; | ||||
| if ((id->tag & LIB_TAG_NEED_LINK) == 0) { | if ((id->tag & LIB_TAG_NEED_LINK) == 0) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| IDP_LibLinkProperty(id->properties, fd); | IDP_LibLinkProperty(id->properties, fd); | ||||
| id_us_ensure_real(id); | id_us_ensure_real(id); | ||||
| for (WorkSpaceDataRelation *relation = workspace->scene_viewlayer_relations.first, | lib_link_workspace_scene_data(fd, workspace); | ||||
| *relation_next = NULL; | |||||
| relation != NULL; | |||||
| relation = relation_next) | |||||
| { | |||||
| relation_next = relation->next; | |||||
| relation->parent = newlibadr(fd, id->lib, relation->parent); | |||||
| /* relation->value is set in direct_link_workspace_link_scene_data, | |||||
| * except when loading linked data. */ | |||||
| Scene *scene = relation->parent; | |||||
| if (scene) { | |||||
| if (scene->id.lib != NULL) { | |||||
| relation->value = BLI_findstring(&scene->view_layers, relation->value_name, offsetof(ViewLayer, name)); | |||||
| } | |||||
| if (relation->value == NULL) { | |||||
| relation->value = scene->view_layers.first; | |||||
| } | |||||
| } | |||||
| else { | |||||
| /* Remove empty relation if scene got lost. */ | |||||
| BLI_freelinkN(&workspace->scene_viewlayer_relations, relation); | |||||
| } | |||||
| } | |||||
| for (WorkSpaceLayout *layout = layouts->first, *layout_next; layout; layout = layout_next) { | for (WorkSpaceLayout *layout = layouts->first, *layout_next; layout; layout = layout_next) { | ||||
| bScreen *screen = newlibadr(fd, id->lib, BKE_workspace_layout_screen_get(layout)); | bScreen *screen = newlibadr(fd, id->lib, BKE_workspace_layout_screen_get(layout)); | ||||
| layout_next = layout->next; | layout_next = layout->next; | ||||
| if (screen) { | if (screen) { | ||||
| BKE_workspace_layout_screen_set(layout, screen); | BKE_workspace_layout_screen_set(layout, screen); | ||||
| Show All 10 Lines | for (WorkSpace *workspace = bmain->workspaces.first; workspace; workspace = workspace->id.next) { | ||||
| id->tag &= ~LIB_TAG_NEED_LINK; | id->tag &= ~LIB_TAG_NEED_LINK; | ||||
| } | } | ||||
| } | } | ||||
| static void direct_link_workspace(FileData *fd, WorkSpace *workspace, const Main *main) | static void direct_link_workspace(FileData *fd, WorkSpace *workspace, const Main *main) | ||||
| { | { | ||||
| link_list(fd, BKE_workspace_layouts_get(workspace)); | link_list(fd, BKE_workspace_layouts_get(workspace)); | ||||
| link_list(fd, &workspace->hook_layout_relations); | link_list(fd, &workspace->hook_layout_relations); | ||||
| link_list(fd, &workspace->scene_viewlayer_relations); | link_list(fd, &workspace->scene_relations); | ||||
| link_list(fd, &workspace->owner_ids); | link_list(fd, &workspace->owner_ids); | ||||
| link_list(fd, &workspace->tools); | link_list(fd, &workspace->tools); | ||||
| for (WorkSpaceDataRelation *relation = workspace->hook_layout_relations.first; | for (WorkSpaceDataRelation *relation = workspace->hook_layout_relations.first; | ||||
| relation; | relation; | ||||
| relation = relation->next) | relation = relation->next) | ||||
| { | { | ||||
| relation->parent = newglobadr(fd, relation->parent); /* data from window - need to access through global oldnew-map */ | relation->parent = newglobadr(fd, relation->parent); /* data from window - need to access through global oldnew-map */ | ||||
| relation->value = newdataadr(fd, relation->value); | relation->value = newdataadr(fd, relation->value); | ||||
| } | } | ||||
| if (ID_IS_LINKED(&workspace->id)) { | |||||
| /* Appending workspace so render layer is likely from a different scene. Unset | |||||
| * now, when activating workspace later we set a valid one from current scene. */ | |||||
| BKE_workspace_relations_free(&workspace->scene_viewlayer_relations); | |||||
| } | |||||
| /* Same issue/fix as in direct_link_workspace_link_scene_data: Can't read workspace data | /* Same issue/fix as in direct_link_workspace_link_scene_data: Can't read workspace data | ||||
| * when reading windows, so have to update windows after/when reading workspaces. */ | * when reading windows, so have to update windows after/when reading workspaces. */ | ||||
| for (wmWindowManager *wm = main->wm.first; wm; wm = wm->id.next) { | for (wmWindowManager *wm = main->wm.first; wm; wm = wm->id.next) { | ||||
| for (wmWindow *win = wm->windows.first; win; win = win->next) { | for (wmWindow *win = wm->windows.first; win; win = win->next) { | ||||
| WorkSpaceLayout *act_layout = newdataadr(fd, BKE_workspace_active_layout_get(win->workspace_hook)); | WorkSpaceLayout *act_layout = newdataadr(fd, BKE_workspace_active_layout_get(win->workspace_hook)); | ||||
| if (act_layout) { | if (act_layout) { | ||||
| BKE_workspace_active_layout_set(win->workspace_hook, act_layout); | BKE_workspace_active_layout_set(win->workspace_hook, act_layout); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 3,109 Lines • ▼ Show 20 Lines | for (smd = lb->first; smd; smd = smd->next) { | ||||
| else if (smd->type == seqModifierType_HueCorrect) { | else if (smd->type == seqModifierType_HueCorrect) { | ||||
| HueCorrectModifierData *hcmd = (HueCorrectModifierData *) smd; | HueCorrectModifierData *hcmd = (HueCorrectModifierData *) smd; | ||||
| direct_link_curvemapping(fd, &hcmd->curve_mapping); | direct_link_curvemapping(fd, &hcmd->curve_mapping); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /** | static void direct_link_scene(FileData *fd, Scene *sce) | ||||
| * Workspaces store a render layer pointer which can only be read after scene is read. | |||||
| */ | |||||
| static void direct_link_workspace_link_scene_data( | |||||
| FileData *fd, Scene *scene, const ListBase *workspaces) | |||||
| { | |||||
| for (WorkSpace *workspace = workspaces->first; workspace; workspace = workspace->id.next) { | |||||
| for (WorkSpaceDataRelation *relation = workspace->scene_viewlayer_relations.first; | |||||
| relation != NULL; | |||||
| relation = relation->next) | |||||
| { | |||||
| ViewLayer *view_layer = newdataadr(fd, relation->value); | |||||
| if (view_layer != NULL) { | |||||
| BLI_assert(BLI_findindex(&scene->view_layers, view_layer) != -1); | |||||
| /* relation->parent is set in lib_link_workspaces */ | |||||
| } | |||||
| if (UNLIKELY(view_layer == NULL)) { | |||||
| view_layer = scene->view_layers.first; | |||||
| } | |||||
| relation->value = view_layer; | |||||
| } | |||||
| } | |||||
| } | |||||
| static void direct_link_scene(FileData *fd, Scene *sce, Main *bmain) | |||||
| { | { | ||||
| Editing *ed; | Editing *ed; | ||||
| Sequence *seq; | Sequence *seq; | ||||
| MetaStack *ms; | MetaStack *ms; | ||||
| RigidBodyWorld *rbw; | RigidBodyWorld *rbw; | ||||
| ViewLayer *view_layer; | ViewLayer *view_layer; | ||||
| SceneRenderLayer *srl; | SceneRenderLayer *srl; | ||||
| ▲ Show 20 Lines • Show All 249 Lines • ▼ Show 20 Lines | #endif | ||||
| /* insert into global old-new map for reading without UI (link_global accesses it again) */ | /* insert into global old-new map for reading without UI (link_global accesses it again) */ | ||||
| link_glob_list(fd, &sce->view_layers); | link_glob_list(fd, &sce->view_layers); | ||||
| for (view_layer = sce->view_layers.first; view_layer; view_layer = view_layer->next) { | for (view_layer = sce->view_layers.first; view_layer; view_layer = view_layer->next) { | ||||
| direct_link_view_layer(fd, view_layer); | direct_link_view_layer(fd, view_layer); | ||||
| } | } | ||||
| sce->layer_properties = newdataadr(fd, sce->layer_properties); | sce->layer_properties = newdataadr(fd, sce->layer_properties); | ||||
| IDP_DirectLinkGroup_OrFree(&sce->layer_properties, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd); | IDP_DirectLinkGroup_OrFree(&sce->layer_properties, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd); | ||||
| direct_link_workspace_link_scene_data(fd, sce, &bmain->workspaces); | |||||
| } | } | ||||
| /* ****************** READ GREASE PENCIL ***************** */ | /* ****************** READ GREASE PENCIL ***************** */ | ||||
| /* relink's grease pencil data's refs */ | /* relink's grease pencil data's refs */ | ||||
| static void lib_link_gpencil(FileData *fd, Main *main) | static void lib_link_gpencil(FileData *fd, Main *main) | ||||
| { | { | ||||
| for (bGPdata *gpd = main->gpencil.first; gpd; gpd = gpd->id.next) { | for (bGPdata *gpd = main->gpencil.first; gpd; gpd = gpd->id.next) { | ||||
| ▲ Show 20 Lines • Show All 795 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| static void lib_link_clipboard_restore(struct IDNameLib_Map *id_map) | static void lib_link_clipboard_restore(struct IDNameLib_Map *id_map) | ||||
| { | { | ||||
| /* update IDs stored in sequencer clipboard */ | /* update IDs stored in sequencer clipboard */ | ||||
| BKE_sequencer_base_recursive_apply(&seqbase_clipboard, lib_link_seq_clipboard_cb, id_map); | BKE_sequencer_base_recursive_apply(&seqbase_clipboard, lib_link_seq_clipboard_cb, id_map); | ||||
| } | } | ||||
| static void lib_link_workspace_scene_data_restore(wmWindow *win, Scene *scene) | static void lib_link_workspace_scene_data_restore(struct IDNameLib_Map *id_map, WorkSpace *workspace) | ||||
| { | |||||
| for (WorkSpaceSceneRelation *relation = workspace->scene_relations.first; | |||||
| relation != NULL; | |||||
| relation = relation->next) | |||||
| { | |||||
| relation->scene = restore_pointer_by_name(id_map, &relation->scene->id, USER_IGNORE); | |||||
| } | |||||
| /* Free any relations that got lost due to missing datablocks or view layers. */ | |||||
| BKE_workspace_scene_relations_free_invalid(workspace); | |||||
| } | |||||
| static void lib_link_window_scene_data_restore(wmWindow *win, Scene *scene) | |||||
| { | { | ||||
| bScreen *screen = BKE_workspace_active_screen_get(win->workspace_hook); | bScreen *screen = BKE_workspace_active_screen_get(win->workspace_hook); | ||||
| for (ScrArea *area = screen->areabase.first; area; area = area->next) { | for (ScrArea *area = screen->areabase.first; area; area = area->next) { | ||||
| for (SpaceLink *sl = area->spacedata.first; sl; sl = sl->next) { | for (SpaceLink *sl = area->spacedata.first; sl; sl = sl->next) { | ||||
| if (sl->spacetype == SPACE_VIEW3D) { | if (sl->spacetype == SPACE_VIEW3D) { | ||||
| View3D *v3d = (View3D *)sl; | View3D *v3d = (View3D *)sl; | ||||
| ▲ Show 20 Lines • Show All 244 Lines • ▼ Show 20 Lines | |||||
| * Used to link a file (without UI) to the current UI. | * Used to link a file (without UI) to the current UI. | ||||
| * Note that it assumes the old pointers in UI are still valid, so old Main is not freed. | * Note that it assumes the old pointers in UI are still valid, so old Main is not freed. | ||||
| */ | */ | ||||
| void blo_lib_link_restore(Main *newmain, wmWindowManager *curwm, Scene *curscene, ViewLayer *cur_view_layer) | void blo_lib_link_restore(Main *newmain, wmWindowManager *curwm, Scene *curscene, ViewLayer *cur_view_layer) | ||||
| { | { | ||||
| struct IDNameLib_Map *id_map = BKE_main_idmap_create(newmain); | struct IDNameLib_Map *id_map = BKE_main_idmap_create(newmain); | ||||
| for (WorkSpace *workspace = newmain->workspaces.first; workspace; workspace = workspace->id.next) { | for (WorkSpace *workspace = newmain->workspaces.first; workspace; workspace = workspace->id.next) { | ||||
| lib_link_workspace_scene_data_restore(id_map, workspace); | |||||
| BKE_workspace_view_layer_set(workspace, cur_view_layer, curscene); | |||||
| ListBase *layouts = BKE_workspace_layouts_get(workspace); | ListBase *layouts = BKE_workspace_layouts_get(workspace); | ||||
| for (WorkSpaceLayout *layout = layouts->first; layout; layout = layout->next) { | for (WorkSpaceLayout *layout = layouts->first; layout; layout = layout->next) { | ||||
| lib_link_workspace_layout_restore(id_map, newmain, layout); | lib_link_workspace_layout_restore(id_map, newmain, layout); | ||||
| } | } | ||||
| BKE_workspace_view_layer_set(workspace, cur_view_layer, curscene); | |||||
| } | } | ||||
| for (wmWindow *win = curwm->windows.first; win; win = win->next) { | for (wmWindow *win = curwm->windows.first; win; win = win->next) { | ||||
| WorkSpace *workspace = BKE_workspace_active_get(win->workspace_hook); | WorkSpace *workspace = BKE_workspace_active_get(win->workspace_hook); | ||||
| ID *workspace_id = (ID *)workspace; | ID *workspace_id = (ID *)workspace; | ||||
| Scene *oldscene = win->scene; | Scene *oldscene = win->scene; | ||||
| workspace = restore_pointer_by_name(id_map, workspace_id, USER_REAL); | workspace = restore_pointer_by_name(id_map, workspace_id, USER_REAL); | ||||
| BKE_workspace_active_set(win->workspace_hook, workspace); | BKE_workspace_active_set(win->workspace_hook, workspace); | ||||
| win->scene = restore_pointer_by_name(id_map, (ID *)win->scene, USER_REAL); | win->scene = restore_pointer_by_name(id_map, (ID *)win->scene, USER_REAL); | ||||
| if (win->scene == NULL) { | if (win->scene == NULL) { | ||||
| win->scene = curscene; | win->scene = curscene; | ||||
| } | } | ||||
| BKE_workspace_active_set(win->workspace_hook, workspace); | BKE_workspace_active_set(win->workspace_hook, workspace); | ||||
| /* keep cursor location through undo */ | /* keep cursor location through undo */ | ||||
| copy_v3_v3(win->scene->cursor.location, oldscene->cursor.location); | copy_v3_v3(win->scene->cursor.location, oldscene->cursor.location); | ||||
| copy_qt_qt(win->scene->cursor.rotation, oldscene->cursor.rotation); | copy_qt_qt(win->scene->cursor.rotation, oldscene->cursor.rotation); | ||||
| lib_link_workspace_scene_data_restore(win, win->scene); | lib_link_window_scene_data_restore(win, win->scene); | ||||
| BLI_assert(win->screen == NULL); | BLI_assert(win->screen == NULL); | ||||
| } | } | ||||
| /* update IDs stored in all possible clipboards */ | /* update IDs stored in all possible clipboards */ | ||||
| lib_link_clipboard_restore(id_map); | lib_link_clipboard_restore(id_map); | ||||
| BKE_main_idmap_destroy(id_map); | BKE_main_idmap_destroy(id_map); | ||||
| ▲ Show 20 Lines • Show All 895 Lines • ▼ Show 20 Lines | static BHead *read_libblock(FileData *fd, Main *main, BHead *bhead, const short tag, ID **r_id) | ||||
| switch (GS(id->name)) { | switch (GS(id->name)) { | ||||
| case ID_WM: | case ID_WM: | ||||
| direct_link_windowmanager(fd, (wmWindowManager *)id); | direct_link_windowmanager(fd, (wmWindowManager *)id); | ||||
| break; | break; | ||||
| case ID_SCR: | case ID_SCR: | ||||
| wrong_id = direct_link_screen(fd, (bScreen *)id); | wrong_id = direct_link_screen(fd, (bScreen *)id); | ||||
| break; | break; | ||||
| case ID_SCE: | case ID_SCE: | ||||
| direct_link_scene(fd, (Scene *)id, main); | direct_link_scene(fd, (Scene *)id); | ||||
| break; | break; | ||||
| case ID_OB: | case ID_OB: | ||||
| direct_link_object(fd, (Object *)id); | direct_link_object(fd, (Object *)id); | ||||
| break; | break; | ||||
| case ID_ME: | case ID_ME: | ||||
| direct_link_mesh(fd, (Mesh *)id); | direct_link_mesh(fd, (Mesh *)id); | ||||
| break; | break; | ||||
| case ID_CU: | case ID_CU: | ||||
| ▲ Show 20 Lines • Show All 2,364 Lines • Show Last 20 Lines | |||||