Changeset View
Changeset View
Standalone View
Standalone View
source/blender/asset_system/intern/asset_library.cc
- This file was moved from source/blender/blenkernel/intern/asset_library.cc.
| /* SPDX-License-Identifier: GPL-2.0-or-later */ | /* SPDX-License-Identifier: GPL-2.0-or-later */ | ||||
| /** \file | /** \file | ||||
| * \ingroup bke | * \ingroup asset_system | ||||
| */ | */ | ||||
| #include <memory> | #include <memory> | ||||
| #include "BKE_asset_library.hh" | #include "AS_asset_library.h" | ||||
| #include "BKE_asset_representation.hh" | #include "AS_asset_library.hh" | ||||
| #include "AS_asset_representation.hh" | |||||
| #include "BKE_lib_remap.h" | #include "BKE_lib_remap.h" | ||||
| #include "BKE_main.h" | #include "BKE_main.h" | ||||
| #include "BKE_preferences.h" | #include "BKE_preferences.h" | ||||
| #include "BLI_fileops.h" | #include "BLI_fileops.h" | ||||
| #include "BLI_path_util.h" | #include "BLI_path_util.h" | ||||
| #include "BLI_set.hh" | #include "BLI_set.hh" | ||||
| #include "DNA_asset_types.h" | #include "DNA_asset_types.h" | ||||
| #include "DNA_userdef_types.h" | #include "DNA_userdef_types.h" | ||||
| #include "asset_library_service.hh" | #include "asset_library_service.hh" | ||||
| bool blender::bke::AssetLibrary::save_catalogs_when_file_is_saved = true; | using namespace blender; | ||||
| using namespace blender::asset_system; | |||||
| bool asset_system::AssetLibrary::save_catalogs_when_file_is_saved = true; | |||||
| blender::bke::AssetLibrary *BKE_asset_library_load(const Main *bmain, | asset_system::AssetLibrary *AS_asset_library_load(const Main *bmain, | ||||
| const AssetLibraryReference &library_reference) | const AssetLibraryReference &library_reference) | ||||
| { | { | ||||
| blender::bke::AssetLibraryService *service = blender::bke::AssetLibraryService::get(); | AssetLibraryService *service = AssetLibraryService::get(); | ||||
| return service->get_asset_library(bmain, library_reference); | return service->get_asset_library(bmain, library_reference); | ||||
| } | } | ||||
| /** | /** | ||||
| * Loading an asset library at this point only means loading the catalogs. Later on this should | * Loading an asset library at this point only means loading the catalogs. Later on this should | ||||
| * invoke reading of asset representations too. | * invoke reading of asset representations too. | ||||
| */ | */ | ||||
| struct AssetLibrary *BKE_asset_library_load(const char *library_path) | struct ::AssetLibrary *AS_asset_library_load(const char *library_path) | ||||
| { | { | ||||
| blender::bke::AssetLibraryService *service = blender::bke::AssetLibraryService::get(); | AssetLibraryService *service = AssetLibraryService::get(); | ||||
| blender::bke::AssetLibrary *lib; | asset_system::AssetLibrary *lib; | ||||
| if (library_path == nullptr || library_path[0] == '\0') { | if (library_path == nullptr || library_path[0] == '\0') { | ||||
| lib = service->get_asset_library_current_file(); | lib = service->get_asset_library_current_file(); | ||||
| } | } | ||||
| else { | else { | ||||
| lib = service->get_asset_library_on_disk(library_path); | lib = service->get_asset_library_on_disk(library_path); | ||||
| } | } | ||||
| return reinterpret_cast<struct AssetLibrary *>(lib); | return reinterpret_cast<struct ::AssetLibrary *>(lib); | ||||
| } | } | ||||
| bool BKE_asset_library_has_any_unsaved_catalogs() | bool AS_asset_library_has_any_unsaved_catalogs() | ||||
| { | { | ||||
| blender::bke::AssetLibraryService *service = blender::bke::AssetLibraryService::get(); | AssetLibraryService *service = AssetLibraryService::get(); | ||||
| return service->has_any_unsaved_catalogs(); | return service->has_any_unsaved_catalogs(); | ||||
| } | } | ||||
| std::string BKE_asset_library_find_suitable_root_path_from_path( | std::string AS_asset_library_find_suitable_root_path_from_path( | ||||
| const blender::StringRefNull input_path) | const blender::StringRefNull input_path) | ||||
| { | { | ||||
| if (bUserAssetLibrary *preferences_lib = BKE_preferences_asset_library_containing_path( | if (bUserAssetLibrary *preferences_lib = BKE_preferences_asset_library_containing_path( | ||||
| &U, input_path.c_str())) { | &U, input_path.c_str())) { | ||||
| return preferences_lib->path; | return preferences_lib->path; | ||||
| } | } | ||||
| char buffer[FILE_MAXDIR]; | char buffer[FILE_MAXDIR]; | ||||
| BLI_split_dir_part(input_path.c_str(), buffer, FILE_MAXDIR); | BLI_split_dir_part(input_path.c_str(), buffer, FILE_MAXDIR); | ||||
| return buffer; | return buffer; | ||||
| } | } | ||||
| std::string BKE_asset_library_find_suitable_root_path_from_main(const Main *bmain) | std::string AS_asset_library_find_suitable_root_path_from_main(const Main *bmain) | ||||
| { | { | ||||
| return BKE_asset_library_find_suitable_root_path_from_path(bmain->filepath); | return AS_asset_library_find_suitable_root_path_from_path(bmain->filepath); | ||||
| } | } | ||||
| blender::bke::AssetCatalogService *BKE_asset_library_get_catalog_service( | AssetCatalogService *AS_asset_library_get_catalog_service(const ::AssetLibrary *library_c) | ||||
| const ::AssetLibrary *library_c) | |||||
| { | { | ||||
| if (library_c == nullptr) { | if (library_c == nullptr) { | ||||
| return nullptr; | return nullptr; | ||||
| } | } | ||||
| const blender::bke::AssetLibrary &library = reinterpret_cast<const blender::bke::AssetLibrary &>( | const asset_system::AssetLibrary &library = reinterpret_cast<const asset_system::AssetLibrary &>( | ||||
| *library_c); | *library_c); | ||||
| return library.catalog_service.get(); | return library.catalog_service.get(); | ||||
| } | } | ||||
| blender::bke::AssetCatalogTree *BKE_asset_library_get_catalog_tree(const ::AssetLibrary *library) | AssetCatalogTree *AS_asset_library_get_catalog_tree(const ::AssetLibrary *library) | ||||
| { | { | ||||
| blender::bke::AssetCatalogService *catalog_service = BKE_asset_library_get_catalog_service( | AssetCatalogService *catalog_service = AS_asset_library_get_catalog_service(library); | ||||
| library); | |||||
| if (catalog_service == nullptr) { | if (catalog_service == nullptr) { | ||||
| return nullptr; | return nullptr; | ||||
| } | } | ||||
| return catalog_service->get_catalog_tree(); | return catalog_service->get_catalog_tree(); | ||||
| } | } | ||||
| void BKE_asset_library_refresh_catalog_simplename(struct AssetLibrary *asset_library, | void AS_asset_library_refresh_catalog_simplename(struct ::AssetLibrary *asset_library, | ||||
| struct AssetMetaData *asset_data) | struct AssetMetaData *asset_data) | ||||
| { | { | ||||
| blender::bke::AssetLibrary *lib = reinterpret_cast<blender::bke::AssetLibrary *>(asset_library); | asset_system::AssetLibrary *lib = reinterpret_cast<asset_system::AssetLibrary *>(asset_library); | ||||
| lib->refresh_catalog_simplename(asset_data); | lib->refresh_catalog_simplename(asset_data); | ||||
| } | } | ||||
| void BKE_asset_library_remap_ids(IDRemapper *mappings) | void AS_asset_library_remap_ids(IDRemapper *mappings) | ||||
| { | { | ||||
| blender::bke::AssetLibraryService *service = blender::bke::AssetLibraryService::get(); | AssetLibraryService *service = AssetLibraryService::get(); | ||||
| service->foreach_loaded_asset_library( | service->foreach_loaded_asset_library( | ||||
| [mappings](blender::bke::AssetLibrary &library) { library.remap_ids(*mappings); }); | [mappings](asset_system::AssetLibrary &library) { library.remap_ids(*mappings); }); | ||||
| } | } | ||||
| namespace blender::bke { | namespace blender::asset_system { | ||||
| AssetLibrary::AssetLibrary() : catalog_service(std::make_unique<AssetCatalogService>()) | AssetLibrary::AssetLibrary() : catalog_service(std::make_unique<AssetCatalogService>()) | ||||
| { | { | ||||
| } | } | ||||
| AssetLibrary::~AssetLibrary() | AssetLibrary::~AssetLibrary() | ||||
| { | { | ||||
| if (on_save_callback_store_.func) { | if (on_save_callback_store_.func) { | ||||
| ▲ Show 20 Lines • Show All 147 Lines • ▼ Show 20 Lines | Vector<AssetLibraryReference> all_valid_asset_library_refs() | ||||
| AssetLibraryReference library_ref{}; | AssetLibraryReference library_ref{}; | ||||
| library_ref.custom_library_index = -1; | library_ref.custom_library_index = -1; | ||||
| library_ref.type = ASSET_LIBRARY_LOCAL; | library_ref.type = ASSET_LIBRARY_LOCAL; | ||||
| result.append(library_ref); | result.append(library_ref); | ||||
| return result; | return result; | ||||
| } | } | ||||
| } // namespace blender::bke | } // namespace blender::asset_system | ||||