/* note, init has to be called succesfully */ static void ed_marker_move_apply(bContext *C, wmOperator *op) { #ifdef DURIAN_CAMERA_SWITCH bScreen *sc = CTX_wm_screen(C); Scene *scene = CTX_data_scene(C); Object *camera = scene->camera; #endif MarkerMove *mm = op->customdata; TimeMarker *marker; int a, offs; offs = RNA_int_get(op->ptr, "frames"); for (a = 0, marker = mm->markers->first; marker; marker = marker->next) { if (marker->flag & SELECT) { marker->frame = mm->oldframe[a] + offs; a++; } } WM_event_add_notifier(C, NC_SCENE | ND_MARKERS, NULL); WM_event_add_notifier(C, NC_ANIMATION | ND_MARKERS, NULL); #ifdef DURIAN_CAMERA_SWITCH /* so we get view3d redraws */ BKE_scene_camera_switch_update(scene); if (camera != scene->camera) { BKE_screen_view3d_scene_sync(sc); WM_event_add_notifier(C, NC_SCENE | NA_EDITED, scene); } #endif }
static int ed_marker_camera_bind_exec(bContext *C, wmOperator *UNUSED(op)) { bScreen *sc = CTX_wm_screen(C); Scene *scene = CTX_data_scene(C); Object *ob = CTX_data_active_object(C); ListBase *markers = ED_context_get_markers(C); TimeMarker *marker; marker = ED_markers_get_first_selected(markers); if (marker == NULL) return OPERATOR_CANCELLED; marker->camera = ob; /* camera may have changes */ BKE_scene_camera_switch_update(scene); BKE_screen_view3d_scene_sync(sc); WM_event_add_notifier(C, NC_SCENE | ND_MARKERS, NULL); WM_event_add_notifier(C, NC_ANIMATION | ND_MARKERS, NULL); WM_event_add_notifier(C, NC_SCENE | NA_EDITED, scene); /* so we get view3d redraws */ return OPERATOR_FINISHED; }
static void setup_app_data(bContext *C, BlendFileData *bfd, const char *filepath) { bScreen *curscreen = NULL; Scene *curscene = NULL; int recover; enum { LOAD_UI = 1, LOAD_UI_OFF, LOAD_UNDO, } mode; if (BLI_listbase_is_empty(&bfd->main->screen)) { mode = LOAD_UNDO; } else if (G.fileflags & G_FILE_NO_UI) { mode = LOAD_UI_OFF; } else { mode = LOAD_UI; } recover = (G.fileflags & G_FILE_RECOVER); /* Free all render results, without this stale data gets displayed after loading files */ if (mode != LOAD_UNDO) { RE_FreeAllRenderResults(); } /* Only make filepaths compatible when loading for real (not undo) */ if (mode != LOAD_UNDO) { clean_paths(bfd->main); } /* XXX here the complex windowmanager matching */ /* no load screens? */ if (mode != LOAD_UI) { /* 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 users can have 2+ 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: T43424 */ bool track_undo_scene; /* comes from readfile.c */ SWAP(ListBase, G.main->wm, bfd->main->wm); SWAP(ListBase, G.main->screen, bfd->main->screen); /* we re-use current screen */ curscreen = CTX_wm_screen(C); /* but use new Scene pointer */ curscene = bfd->curscene; track_undo_scene = (mode == LOAD_UNDO && curscreen && curscene && bfd->main->wm.first); if (curscene == NULL) curscene = bfd->main->scene.first; /* empty file, we add a scene to make Blender work */ if (curscene == NULL) curscene = BKE_scene_add(bfd->main, "Empty"); if (track_undo_scene) { /* keep the old (free'd) scene, let 'blo_lib_link_screen_restore' * replace it with 'curscene' if its needed */ } else { /* and we enforce curscene to be in current screen */ if (curscreen) { /* can run in bgmode */ curscreen->scene = curscene; } } /* clear_global will free G.main, here we can still restore pointers */ blo_lib_link_screen_restore(bfd->main, curscreen, curscene); /* curscreen might not be set when loading without ui (see T44217) so only re-assign if available */ if (curscreen) { curscene = curscreen->scene; } if (track_undo_scene) { wmWindowManager *wm = bfd->main->wm.first; if (wm_scene_is_visible(wm, bfd->curscene) == false) { curscene = bfd->curscene; curscreen->scene = curscene; BKE_screen_view3d_scene_sync(curscreen); } } } /* free G.main Main database */ // CTX_wm_manager_set(C, NULL); clear_global(); /* clear old property update cache, in case some old references are left dangling */ RNA_property_update_cache_free(); G.main = bfd->main; CTX_data_main_set(C, G.main); if (bfd->user) { /* only here free userdef themes... */ BKE_userdef_free(); U = *bfd->user; /* Security issue: any blend file could include a USER block. * * Currently we load prefs from BLENDER_STARTUP_FILE and later on load BLENDER_USERPREF_FILE, * to load the preferences defined in the users home dir. * * This means we will never accidentally (or maliciously) * enable scripts auto-execution by loading a '.blend' file. */ U.flag |= USER_SCRIPT_AUTOEXEC_DISABLE; MEM_freeN(bfd->user); } /* case G_FILE_NO_UI or no screens in file */ if (mode != LOAD_UI) { /* leave entire context further unaltered? */ CTX_data_scene_set(C, curscene); } else { G.fileflags = bfd->fileflags; CTX_wm_manager_set(C, G.main->wm.first); CTX_wm_screen_set(C, bfd->curscreen); CTX_data_scene_set(C, bfd->curscene); CTX_wm_area_set(C, NULL); CTX_wm_region_set(C, NULL); CTX_wm_menu_set(C, NULL); curscene = bfd->curscene; } /* this can happen when active scene was lib-linked, and doesn't exist anymore */ if (CTX_data_scene(C) == NULL) { /* in case we don't even have a local scene, add one */ if (!G.main->scene.first) BKE_scene_add(G.main, "Scene"); CTX_data_scene_set(C, G.main->scene.first); CTX_wm_screen(C)->scene = CTX_data_scene(C); curscene = CTX_data_scene(C); } BLI_assert(curscene == CTX_data_scene(C)); /* special cases, override loaded flags: */ if (G.f != bfd->globalf) { const int flags_keep = (G_SWAP_EXCHANGE | G_SCRIPT_AUTOEXEC | G_SCRIPT_OVERRIDE_PREF); bfd->globalf = (bfd->globalf & ~flags_keep) | (G.f & flags_keep); } G.f = bfd->globalf; #ifdef WITH_PYTHON /* let python know about new main */ BPY_context_update(C); #endif if (!G.background) { //setscreen(G.curscreen); } /* FIXME: this version patching should really be part of the file-reading code, * but we still get too many unrelated data-corruption crashes otherwise... */ if (G.main->versionfile < 250) do_versions_ipos_to_animato(G.main); G.main->recovered = 0; /* startup.blend or recovered startup */ if (bfd->filename[0] == 0) { G.main->name[0] = 0; } else if (recover && G.relbase_valid) { /* in case of autosave or quit.blend, use original filename instead * use relbase_valid to make sure the file is saved, else we get <memory2> in the filename */ filepath = bfd->filename; G.main->recovered = 1; /* these are the same at times, should never copy to the same location */ if (G.main->name != filepath) BLI_strncpy(G.main->name, filepath, FILE_MAX); } /* baseflags, groups, make depsgraph, etc */ /* first handle case if other windows have different scenes visible */ if (mode == LOAD_UI) { wmWindowManager *wm = G.main->wm.first; if (wm) { wmWindow *win; for (win = wm->windows.first; win; win = win->next) { if (win->screen && win->screen->scene) /* zealous check... */ if (win->screen->scene != curscene) BKE_scene_set_background(G.main, win->screen->scene); } } } BKE_scene_set_background(G.main, curscene); if (mode != LOAD_UNDO) { RE_FreeAllPersistentData(); IMB_colormanagement_check_file_config(G.main); } MEM_freeN(bfd); }
/** * Some editor data may need to be synced with scene data (3D View camera and layers). * This function ensures data is synced for editors in active layout of \a workspace. */ void ED_workspace_scene_data_sync(WorkSpaceInstanceHook *hook, Scene *scene) { bScreen *screen = BKE_workspace_active_screen_get(hook); BKE_screen_view3d_scene_sync(screen, scene); }