Blender V4.3
blender::asset_system::AssetCatalogService Class Reference

#include <AS_asset_catalog.hh>

Inherited by blender::asset_system::tests::TestableAssetCatalogService.

Classes

struct  read_only_tag
 

Public Member Functions

 AssetCatalogService (const CatalogFilePath &asset_library_root={})
 
 AssetCatalogService (read_only_tag)
 
void tag_has_unsaved_changes (AssetCatalog *edited_catalog)
 
bool has_unsaved_changes () const
 
bool is_read_only () const
 
void load_from_disk ()
 
void load_from_disk (const CatalogFilePath &file_or_directory_path)
 
void add_from_existing (const AssetCatalogService &other_service, FunctionRef< void(const AssetCatalog &existing, const AssetCatalog &to_be_ignored)> on_duplicate_items)
 
bool write_to_disk (const CatalogFilePath &blend_file_path)
 
void prepare_to_merge_on_write ()
 
void reload_catalogs ()
 
AssetCatalogfind_catalog (CatalogID catalog_id) const
 
AssetCatalogfind_catalog_by_path (const AssetCatalogPath &path) const
 
bool is_catalog_known (CatalogID catalog_id) const
 
AssetCatalogFilter create_catalog_filter (CatalogID active_catalog_id) const
 
AssetCatalogcreate_catalog (const AssetCatalogPath &catalog_path)
 
void prune_catalogs_by_path (const AssetCatalogPath &path)
 
void prune_catalogs_by_id (CatalogID catalog_id)
 
void update_catalog_path (CatalogID catalog_id, const AssetCatalogPath &new_catalog_path)
 
const AssetCatalogTreecatalog_tree ()
 
bool is_empty () const
 
void undo_push ()
 
void undo ()
 
bool is_undo_possbile () const
 
void redo ()
 
bool is_redo_possbile () const
 

Static Public Attributes

static const CatalogFilePath DEFAULT_CATALOG_FILENAME = "blender_assets.cats.txt"
 

Protected Member Functions

void load_directory_recursive (const CatalogFilePath &directory_path)
 
void load_single_file (const CatalogFilePath &catalog_definition_file_path)
 
bool write_to_disk_ex (const CatalogFilePath &blend_file_path)
 
void untag_has_unsaved_changes ()
 
bool is_catalog_known_with_unsaved_changes (CatalogID catalog_id) const
 
void purge_catalogs_not_listed (const Set< CatalogID > &catalogs_to_keep)
 
void delete_catalog_by_id_soft (CatalogID catalog_id)
 
void delete_catalog_by_id_hard (CatalogID catalog_id)
 
std::unique_ptr< AssetCatalogDefinitionFileparse_catalog_file (const CatalogFilePath &catalog_definition_file_path)
 
std::unique_ptr< AssetCatalogDefinitionFileconstruct_cdf_in_memory (const CatalogFilePath &file_path) const
 
std::unique_ptr< AssetCatalogTreeread_into_tree () const
 
void invalidate_catalog_tree ()
 
void create_missing_catalogs ()
 
void tag_all_catalogs_as_unsaved_changes ()
 
const AssetCatalogDefinitionFileget_catalog_definition_file () const
 
const OwningAssetCatalogMapget_catalogs () const
 
const OwningAssetCatalogMapget_deleted_catalogs () const
 

Static Protected Member Functions

static CatalogFilePath find_suitable_cdf_path_for_writing (const CatalogFilePath &blend_file_path)
 

Detailed Description

Definition at line 41 of file AS_asset_catalog.hh.

Constructor & Destructor Documentation

◆ AssetCatalogService() [1/2]

blender::asset_system::AssetCatalogService::AssetCatalogService ( const CatalogFilePath & asset_library_root = {})
explicit

Definition at line 36 of file asset_system/intern/asset_catalog.cc.

◆ AssetCatalogService() [2/2]

blender::asset_system::AssetCatalogService::AssetCatalogService ( read_only_tag )
explicit

Definition at line 42 of file asset_system/intern/asset_catalog.cc.

Member Function Documentation

◆ add_from_existing()

void blender::asset_system::AssetCatalogService::add_from_existing ( const AssetCatalogService & other_service,
FunctionRef< void(const AssetCatalog &existing, const AssetCatalog &to_be_ignored)> on_duplicate_items )

Duplicate the catalogs from other_service into this one. Does not rebuild the tree, this needs to be done by the caller (call #rebuild_tree()!).

Note
If a catalog from other already exists in this collection (identified by catalog ID), it will be skipped and on_duplicate_items will be called.

Definition at line 332 of file asset_system/intern/asset_catalog.cc.

◆ catalog_tree()

◆ construct_cdf_in_memory()

std::unique_ptr< AssetCatalogDefinitionFile > blender::asset_system::AssetCatalogService::construct_cdf_in_memory ( const CatalogFilePath & file_path) const
protected

Construct an in-memory catalog definition file (CDF) from the currently known catalogs. This object can then be processed further before saving to disk.

Definition at line 550 of file asset_system/intern/asset_catalog.cc.

Referenced by write_to_disk_ex().

◆ create_catalog()

◆ create_catalog_filter()

AssetCatalogFilter blender::asset_system::AssetCatalogService::create_catalog_filter ( CatalogID active_catalog_id) const

◆ create_missing_catalogs()

◆ delete_catalog_by_id_hard()

void blender::asset_system::AssetCatalogService::delete_catalog_by_id_hard ( CatalogID catalog_id)
protected

Hard delete a catalog. This simply removes the catalog from existence. The deletion will not be remembered, and reloading the CDF will bring it back.

Definition at line 200 of file asset_system/intern/asset_catalog.cc.

Referenced by purge_catalogs_not_listed().

◆ delete_catalog_by_id_soft()

void blender::asset_system::AssetCatalogService::delete_catalog_by_id_soft ( CatalogID catalog_id)
protected

Delete a catalog, without deleting any of its children and without rebuilding the catalog tree. The deletion in "Soft", in the sense that the catalog pointer is moved from catalogs_ to deleted_catalogs_; the AssetCatalog instance itself is kept in memory. As a result, it will be removed from a CDF when saved to disk.

This is a lower-level function than prune_catalogs_by_path.

Definition at line 179 of file asset_system/intern/asset_catalog.cc.

References blender::asset_system::AssetCatalog::flags, and blender::asset_system::AssetCatalog::Flags::is_deleted.

Referenced by blender::asset_system::tests::TestableAssetCatalogService::delete_catalog_by_id_soft(), and prune_catalogs_by_path().

◆ find_catalog()

AssetCatalog * blender::asset_system::AssetCatalogService::find_catalog ( CatalogID catalog_id) const

Return catalog with the given ID. Return nullptr if not found.

Definition at line 118 of file asset_system/intern/asset_catalog.cc.

Referenced by blender::ed::sculpt_paint::brush_asset_edit_metadata_invoke(), blender::ed::sculpt_paint::brush_asset_save_as_invoke(), blender::ed::asset::build_filtered_all_catalog_tree(), blender::ed::asset::build_filtered_catalog_tree(), blender::ed::asset::catalog_move(), blender::ed::asset::catalog_rename(), compare_asset_catalog(), create_catalog_filter(), blender::ed::asset_browser::AssetCatalogDropTarget::get_drag_catalog(), prune_catalogs_by_id(), blender::asset_system::AssetLibrary::refresh_catalog_simplename(), blender::asset_system::tests::AssetCatalogTest::save_from_memory_into_existing_asset_lib(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), and update_catalog_path().

◆ find_catalog_by_path()

AssetCatalog * blender::asset_system::AssetCatalogService::find_catalog_by_path ( const AssetCatalogPath & path) const

◆ find_suitable_cdf_path_for_writing()

CatalogFilePath blender::asset_system::AssetCatalogService::find_suitable_cdf_path_for_writing ( const CatalogFilePath & blend_file_path)
staticprotected

Find a suitable path to write a CDF to.

This depends on the location of the blend file, and on whether a CDF already exists next to it or whether the blend file is saved inside an asset library.

Definition at line 523 of file asset_system/intern/asset_catalog.cc.

References AS_asset_library_find_suitable_root_path_from_path(), blender::asset_system::asset_definition_default_file_path_from_dir(), BLI_assert_msg, BLI_path_join, BLI_path_split_dir_part(), DEFAULT_CATALOG_FILENAME, and PATH_MAX.

Referenced by write_to_disk_ex().

◆ get_catalog_definition_file()

const AssetCatalogDefinitionFile * blender::asset_system::AssetCatalogService::get_catalog_definition_file ( ) const
protected

◆ get_catalogs()

const OwningAssetCatalogMap & blender::asset_system::AssetCatalogService::get_catalogs ( ) const
protected

◆ get_deleted_catalogs()

const OwningAssetCatalogMap & blender::asset_system::AssetCatalogService::get_deleted_catalogs ( ) const
protected

◆ has_unsaved_changes()

bool blender::asset_system::AssetCatalogService::has_unsaved_changes ( ) const

◆ invalidate_catalog_tree()

void blender::asset_system::AssetCatalogService::invalidate_catalog_tree ( )
protected

Ensure a catalog_tree() will update the tree. Must be called whenever the contained user visible catalogs change. May be called from multiple threads.

Definition at line 574 of file asset_system/intern/asset_catalog.cc.

References lock.

Referenced by create_catalog(), load_from_disk(), prune_catalogs_by_path(), redo(), reload_catalogs(), undo(), update_catalog_path(), and write_to_disk().

◆ is_catalog_known()

bool blender::asset_system::AssetCatalogService::is_catalog_known ( CatalogID catalog_id) const

Return true only if this catalog is known. This treats deleted catalogs as "unknown".

Definition at line 149 of file asset_system/intern/asset_catalog.cc.

References BLI_assert.

◆ is_catalog_known_with_unsaved_changes()

bool blender::asset_system::AssetCatalogService::is_catalog_known_with_unsaved_changes ( CatalogID catalog_id) const
protected

◆ is_empty()

bool blender::asset_system::AssetCatalogService::is_empty ( ) const

Return true only if there are no catalogs known.

Definition at line 98 of file asset_system/intern/asset_catalog.cc.

References BLI_assert.

Referenced by blender::asset_system::tests::TEST_F().

◆ is_read_only()

bool blender::asset_system::AssetCatalogService::is_read_only ( ) const

Check if this is a read-only service meaning the user shouldn't be able to do edits. This is not enforced by internal catalog code, the catalog service user is responsible for it. For example the UI should disallow edits.

Definition at line 85 of file asset_system/intern/asset_catalog.cc.

Referenced by blender::ed::asset::catalog_add(), blender::ed::asset::catalog_move(), blender::ed::asset::catalog_remove(), blender::ed::asset::catalog_rename(), blender::ed::asset::catalogs_read_only(), and blender::ed::asset::catalogs_save_from_main_path().

◆ is_redo_possbile()

bool blender::asset_system::AssetCatalogService::is_redo_possbile ( ) const

◆ is_undo_possbile()

bool blender::asset_system::AssetCatalogService::is_undo_possbile ( ) const

◆ load_directory_recursive()

void blender::asset_system::AssetCatalogService::load_directory_recursive ( const CatalogFilePath & directory_path)
protected

◆ load_from_disk() [1/2]

void blender::asset_system::AssetCatalogService::load_from_disk ( )

Load asset catalog definitions from the files found in the asset library.

Definition at line 302 of file asset_system/intern/asset_catalog.cc.

References load_from_disk().

Referenced by blender::asset_system::AssetLibrary::load_catalogs(), load_from_disk(), blender::asset_system::tests::AssetCatalogTest::save_from_memory_into_existing_asset_lib(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), and blender::asset_system::tests::TEST_F().

◆ load_from_disk() [2/2]

void blender::asset_system::AssetCatalogService::load_from_disk ( const CatalogFilePath & file_or_directory_path)

Load asset catalog definitions from the given file or directory.

Definition at line 307 of file asset_system/intern/asset_catalog.cc.

References BLI_stat(), CLOG_WARN, create_missing_catalogs(), invalidate_catalog_tree(), load_directory_recursive(), load_single_file(), LOG, S_ISDIR, and S_ISREG.

◆ load_single_file()

void blender::asset_system::AssetCatalogService::load_single_file ( const CatalogFilePath & catalog_definition_file_path)
protected

◆ parse_catalog_file()

std::unique_ptr< AssetCatalogDefinitionFile > blender::asset_system::AssetCatalogService::parse_catalog_file ( const CatalogFilePath & catalog_definition_file_path)
protected

◆ prepare_to_merge_on_write()

void blender::asset_system::AssetCatalogService::prepare_to_merge_on_write ( )

Ensure that the next call to #on_blend_save_post() will choose a new location for the CDF suitable for the location of the blend file (regardless of where the current catalogs come from), and that catalogs will be merged with already-existing ones in that location.

Use this for a "Save as..." that has to write the catalogs to the new blend file location, instead of updating the previously read CDF.

Definition at line 505 of file asset_system/intern/asset_catalog.cc.

References tag_all_catalogs_as_unsaved_changes().

Referenced by blender::ed::asset::asset_bundle_install_exec().

◆ prune_catalogs_by_id()

void blender::asset_system::AssetCatalogService::prune_catalogs_by_id ( CatalogID catalog_id)

Delete all catalogs with the same path as the identified catalog, and their children. This call is the same as calling prune_catalogs_by_path(find_catalog(catalog_id)->path).

Definition at line 229 of file asset_system/intern/asset_catalog.cc.

References BLI_assert_msg, find_catalog(), blender::asset_system::AssetCatalog::path, and prune_catalogs_by_path().

Referenced by blender::ed::asset::catalog_remove(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), and blender::asset_system::tests::TEST_F().

◆ prune_catalogs_by_path()

◆ purge_catalogs_not_listed()

void blender::asset_system::AssetCatalogService::purge_catalogs_not_listed ( const Set< CatalogID > & catalogs_to_keep)
protected

Delete catalogs, only keeping them when they are either listed in catalogs_to_keep or have unsaved changes.

Note
Deleted catalogs are hard-deleted, i.e. they just vanish instead of remembering them as "deleted".

Definition at line 431 of file asset_system/intern/asset_catalog.cc.

References blender::Set< Key, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::add(), blender::Set< Key, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::contains(), delete_catalog_by_id_hard(), and is_catalog_known_with_unsaved_changes().

Referenced by reload_catalogs().

◆ read_into_tree()

std::unique_ptr< AssetCatalogTree > blender::asset_system::AssetCatalogService::read_into_tree ( ) const
protected

Definition at line 562 of file asset_system/intern/asset_catalog.cc.

References tree.

Referenced by catalog_tree().

◆ redo()

void blender::asset_system::AssetCatalogService::redo ( )

Restore the last-saved redo snapshot, pushing the current state onto the undo stack. The caller is responsible for first checking that undoing is possible.

Definition at line 654 of file asset_system/intern/asset_catalog.cc.

References BLI_assert, BLI_assert_msg, create_missing_catalogs(), blender::asset_system::AssetLibraryService::get(), invalidate_catalog_tree(), is_redo_possbile(), and blender::asset_system::AssetLibraryService::tag_all_library_catalogs_dirty().

Referenced by blender::ed::asset::asset_catalog_redo_exec(), and blender::asset_system::tests::TEST_F().

◆ reload_catalogs()

void blender::asset_system::AssetCatalogService::reload_catalogs ( )

Merge on-disk changes into the in-memory asset catalogs. This should be called before writing the asset catalogs to disk.

  • New on-disk catalogs are loaded into memory.
  • Already-known on-disk catalogs are ignored (so will be overwritten with our in-memory data). This includes in-memory marked-as-deleted catalogs.

Definition at line 397 of file asset_system/intern/asset_catalog.cc.

References blender::Set< Key, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::add(), BLI_is_file(), create_missing_catalogs(), blender::asset_system::AssetCatalogDefinitionFile::file_path, invalidate_catalog_tree(), is_catalog_known_with_unsaved_changes(), blender::asset_system::AssetCatalogDefinitionFile::parse_catalog_file(), and purge_catalogs_not_listed().

Referenced by blender::asset_system::OnDiskAssetLibrary::refresh_catalogs(), blender::asset_system::tests::TEST_F(), and write_to_disk_ex().

◆ tag_all_catalogs_as_unsaved_changes()

void blender::asset_system::AssetCatalogService::tag_all_catalogs_as_unsaved_changes ( )
protected

For every catalog, mark it as "dirty".

Definition at line 90 of file asset_system/intern/asset_catalog.cc.

Referenced by prepare_to_merge_on_write().

◆ tag_has_unsaved_changes()

void blender::asset_system::AssetCatalogService::tag_has_unsaved_changes ( AssetCatalog * edited_catalog)

Set tag indicating that some catalog modifications are unsaved, which could get lost on exit. This tag is not set by internal catalog code, the catalog service user is responsible for it. It is cleared by write_to_disk().

This "dirty" state is tracked per catalog, so that it's possible to gracefully load changes from disk. Any catalog with unsaved changes will not be overwritten by on-disk changes.

Definition at line 47 of file asset_system/intern/asset_catalog.cc.

References BLI_assert, blender::asset_system::AssetCatalog::flags, and blender::asset_system::AssetCatalog::Flags::has_unsaved_changes.

Referenced by blender::ed::asset::catalog_add(), blender::ed::asset::catalog_move(), blender::ed::asset::catalog_remove(), blender::ed::asset::catalog_rename(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), and update_catalog_path().

◆ undo()

void blender::asset_system::AssetCatalogService::undo ( )

◆ undo_push()

◆ untag_has_unsaved_changes()

void blender::asset_system::AssetCatalogService::untag_has_unsaved_changes ( )
protected

Definition at line 58 of file asset_system/intern/asset_catalog.cc.

References BLI_assert.

Referenced by write_to_disk().

◆ update_catalog_path()

◆ write_to_disk()

bool blender::asset_system::AssetCatalogService::write_to_disk ( const CatalogFilePath & blend_file_path)

Write the catalog definitions to disk.

The location where the catalogs are saved is variable, and depends on the location of the blend file. The first matching rule wins:

  • Already loaded a CDF from disk? -> Always write to that file.
  • The directory containing the blend file has a blender_assets.cats.txt file? -> Merge with & write to that file.
  • The directory containing the blend file is part of an asset library, as per the user's preferences? -> Merge with & write to ${ASSET_LIBRARY_ROOT}/blender_assets.cats.txt
  • Create a new file blender_assets.cats.txt next to the blend file.

Return true on success, which either means there were no in-memory categories to save, or the save was successful.

Definition at line 468 of file asset_system/intern/asset_catalog.cc.

References BLI_assert, invalidate_catalog_tree(), untag_has_unsaved_changes(), and write_to_disk_ex().

Referenced by blender::ed::sculpt_paint::brush_asset_edit_metadata_exec(), blender::ed::sculpt_paint::brush_asset_save_as_exec(), blender::ed::asset::catalogs_save_from_main_path(), blender::asset_system::AssetLibrary::on_blend_save_post(), blender::asset_system::tests::AssetCatalogTest::save_from_memory_into_existing_asset_lib(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), and blender::asset_system::tests::TEST_F().

◆ write_to_disk_ex()

bool blender::asset_system::AssetCatalogService::write_to_disk_ex ( const CatalogFilePath & blend_file_path)
protected

Implementation of write_to_disk() that doesn't clear the "has unsaved changes" tag.

Definition at line 481 of file asset_system/intern/asset_catalog.cc.

References construct_cdf_in_memory(), find_suitable_cdf_path_for_writing(), and reload_catalogs().

Referenced by write_to_disk().

Member Data Documentation

◆ DEFAULT_CATALOG_FILENAME


The documentation for this class was generated from the following files: