Changeset View
Changeset View
Standalone View
Standalone View
source/blender/windowmanager/intern/wm_files_link.c
| Show First 20 Lines • Show All 208 Lines • ▼ Show 20 Lines | static WMLinkAppendDataItem *wm_link_append_data_item_add( | ||||
| BLI_linklist_append_arena(&lapp_data->items, item, lapp_data->memarena); | BLI_linklist_append_arena(&lapp_data->items, item, lapp_data->memarena); | ||||
| lapp_data->num_items++; | lapp_data->num_items++; | ||||
| return item; | return item; | ||||
| } | } | ||||
| static void wm_link_do( | static void wm_link_do( | ||||
| WMLinkAppendData *lapp_data, ReportList *reports, Main *bmain, Scene *scene, SceneLayer *scene_layer, | WMLinkAppendData *lapp_data, ReportList *reports, Main *bmain, Scene *scene, ViewLayer *view_layer, | ||||
| const bool use_placeholders, const bool force_indirect) | const bool use_placeholders, const bool force_indirect) | ||||
| { | { | ||||
| Main *mainl; | Main *mainl; | ||||
| BlendHandle *bh; | BlendHandle *bh; | ||||
| Library *lib; | Library *lib; | ||||
| const int flag = lapp_data->flag; | const int flag = lapp_data->flag; | ||||
| Show All 32 Lines | for (item_idx = 0, itemlink = lapp_data->items.list; itemlink; item_idx++, itemlink = itemlink->next) { | ||||
| WMLinkAppendDataItem *item = itemlink->link; | WMLinkAppendDataItem *item = itemlink->link; | ||||
| ID *new_id; | ID *new_id; | ||||
| if (!BLI_BITMAP_TEST(item->libraries, lib_idx)) { | if (!BLI_BITMAP_TEST(item->libraries, lib_idx)) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| new_id = BLO_library_link_named_part_ex( | new_id = BLO_library_link_named_part_ex( | ||||
| mainl, &bh, item->idcode, item->name, flag, scene, scene_layer, use_placeholders, force_indirect); | mainl, &bh, item->idcode, item->name, flag, scene, view_layer, use_placeholders, force_indirect); | ||||
| if (new_id) { | if (new_id) { | ||||
| /* If the link is successful, clear item's libs 'todo' flags. | /* If the link is successful, clear item's libs 'todo' flags. | ||||
| * This avoids trying to link same item with other libraries to come. */ | * This avoids trying to link same item with other libraries to come. */ | ||||
| BLI_BITMAP_SET_ALL(item->libraries, false, lapp_data->num_libraries); | BLI_BITMAP_SET_ALL(item->libraries, false, lapp_data->num_libraries); | ||||
| item->new_id = new_id; | item->new_id = new_id; | ||||
| } | } | ||||
| } | } | ||||
| BLO_library_link_end(mainl, &bh, flag, scene, scene_layer); | BLO_library_link_end(mainl, &bh, flag, scene, view_layer); | ||||
| BLO_blendhandle_close(bh); | BLO_blendhandle_close(bh); | ||||
| } | } | ||||
| } | } | ||||
| /** | /** | ||||
| * Check if an item defined by \a name and \a group can be appended/linked. | * Check if an item defined by \a name and \a group can be appended/linked. | ||||
| * | * | ||||
| * \param reports: Optionally report an error when an item can't be appended/linked. | * \param reports: Optionally report an error when an item can't be appended/linked. | ||||
| Show All 26 Lines | static bool wm_link_append_item_poll( | ||||
| return true; | return true; | ||||
| } | } | ||||
| static int wm_link_append_exec(bContext *C, wmOperator *op) | static int wm_link_append_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| Main *bmain = CTX_data_main(C); | Main *bmain = CTX_data_main(C); | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| SceneLayer *scene_layer = CTX_data_scene_layer(C); | ViewLayer *view_layer = CTX_data_view_layer(C); | ||||
| PropertyRNA *prop; | PropertyRNA *prop; | ||||
| WMLinkAppendData *lapp_data; | WMLinkAppendData *lapp_data; | ||||
| char path[FILE_MAX_LIBEXTRA], root[FILE_MAXDIR], libname[FILE_MAX_LIBEXTRA], relname[FILE_MAX]; | char path[FILE_MAX_LIBEXTRA], root[FILE_MAXDIR], libname[FILE_MAX_LIBEXTRA], relname[FILE_MAX]; | ||||
| char *group, *name; | char *group, *name; | ||||
| int totfiles = 0; | int totfiles = 0; | ||||
| short flag; | short flag; | ||||
| bool has_item = false; | bool has_item = false; | ||||
| bool do_append; | bool do_append; | ||||
| ▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | if (scene && scene->id.lib) { | ||||
| BKE_reportf(op->reports, RPT_WARNING, | BKE_reportf(op->reports, RPT_WARNING, | ||||
| "Scene '%s' is linked, instantiation of objects & groups is disabled", scene->id.name + 2); | "Scene '%s' is linked, instantiation of objects & groups is disabled", scene->id.name + 2); | ||||
| flag &= ~FILE_GROUP_INSTANCE; | flag &= ~FILE_GROUP_INSTANCE; | ||||
| scene = NULL; | scene = NULL; | ||||
| } | } | ||||
| /* from here down, no error returns */ | /* from here down, no error returns */ | ||||
| if (scene_layer && RNA_boolean_get(op->ptr, "autoselect")) { | if (view_layer && RNA_boolean_get(op->ptr, "autoselect")) { | ||||
| BKE_scene_layer_base_deselect_all(scene_layer); | BKE_view_layer_base_deselect_all(view_layer); | ||||
| } | } | ||||
| /* tag everything, all untagged data can be made local | /* tag everything, all untagged data can be made local | ||||
| * its also generally useful to know what is new | * its also generally useful to know what is new | ||||
| * | * | ||||
| * take extra care BKE_main_id_flag_all(bmain, LIB_TAG_PRE_EXISTING, false) is called after! */ | * take extra care BKE_main_id_flag_all(bmain, LIB_TAG_PRE_EXISTING, false) is called after! */ | ||||
| BKE_main_id_tag_all(bmain, LIB_TAG_PRE_EXISTING, true); | BKE_main_id_tag_all(bmain, LIB_TAG_PRE_EXISTING, true); | ||||
| ▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | static int wm_link_append_exec(bContext *C, wmOperator *op) | ||||
| if (!has_item) { | if (!has_item) { | ||||
| wm_link_append_data_free(lapp_data); | wm_link_append_data_free(lapp_data); | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| /* XXX We'd need re-entrant locking on Main for this to work... */ | /* XXX We'd need re-entrant locking on Main for this to work... */ | ||||
| /* BKE_main_lock(bmain); */ | /* BKE_main_lock(bmain); */ | ||||
| wm_link_do(lapp_data, op->reports, bmain, scene, scene_layer, false, false); | wm_link_do(lapp_data, op->reports, bmain, scene, view_layer, false, false); | ||||
| /* BKE_main_unlock(bmain); */ | /* BKE_main_unlock(bmain); */ | ||||
| /* mark all library linked objects to be updated */ | /* mark all library linked objects to be updated */ | ||||
| BKE_main_lib_objects_recalc_all(bmain); | BKE_main_lib_objects_recalc_all(bmain); | ||||
| IMB_colormanagement_check_file_config(bmain); | IMB_colormanagement_check_file_config(bmain); | ||||
| /* append, rather than linking */ | /* append, rather than linking */ | ||||
| ▲ Show 20 Lines • Show All 531 Lines • Show Last 20 Lines | |||||