Blender  V3.3
Public Member Functions | Static Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
blender::bke::AssetCatalogService Class Reference

#include <BKE_asset_catalog.hh>

Inheritance diagram for blender::bke::AssetCatalogService:
blender::bke::tests::TestableAssetCatalogService

Public Member Functions

 AssetCatalogService ()
 
 AssetCatalogService (const CatalogFilePath &asset_library_root)
 
void tag_has_unsaved_changes (AssetCatalog *edited_catalog)
 
bool has_unsaved_changes () const
 
void load_from_disk ()
 
void load_from_disk (const CatalogFilePath &file_or_directory_path)
 
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)
 
AssetCatalogTreeget_catalog_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)
 
std::unique_ptr< AssetCatalogTreeread_into_tree ()
 
void rebuild_tree ()
 
void create_missing_catalogs ()
 
void tag_all_catalogs_as_unsaved_changes ()
 
AssetCatalogDefinitionFileget_catalog_definition_file ()
 
OwningAssetCatalogMapget_catalogs ()
 
OwningAssetCatalogMapget_deleted_catalogs ()
 

Static Protected Member Functions

static CatalogFilePath find_suitable_cdf_path_for_writing (const CatalogFilePath &blend_file_path)
 

Protected Attributes

std::unique_ptr< AssetCatalogCollectioncatalog_collection_
 
std::unique_ptr< AssetCatalogTreecatalog_tree_ = std::make_unique<AssetCatalogTree>()
 
CatalogFilePath asset_library_root_
 
Vector< std::unique_ptr< AssetCatalogCollection > > undo_snapshots_
 
Vector< std::unique_ptr< AssetCatalogCollection > > redo_snapshots_
 

Detailed Description

Definition at line 44 of file BKE_asset_catalog.hh.

Constructor & Destructor Documentation

◆ AssetCatalogService() [1/2]

blender::bke::AssetCatalogService::AssetCatalogService ( )

Definition at line 39 of file blenkernel/intern/asset_catalog.cc.

◆ AssetCatalogService() [2/2]

blender::bke::AssetCatalogService::AssetCatalogService ( const CatalogFilePath asset_library_root)
explicit

Definition at line 44 of file blenkernel/intern/asset_catalog.cc.

Member Function Documentation

◆ construct_cdf_in_memory()

std::unique_ptr< AssetCatalogDefinitionFile > blender::bke::AssetCatalogService::construct_cdf_in_memory ( const CatalogFilePath file_path)
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 532 of file blenkernel/intern/asset_catalog.cc.

References catalog_collection_.

Referenced by write_to_disk_ex().

◆ create_catalog()

AssetCatalog * blender::bke::AssetCatalogService::create_catalog ( const AssetCatalogPath catalog_path)

Create a catalog with some sensible auto-generated catalog ID. The catalog will be saved to the default catalog file.

Definition at line 258 of file blenkernel/intern/asset_catalog.cc.

References BLI_assert_msg, catalog_collection_, catalog_tree_, and blender::bke::AssetCatalog::from_path().

Referenced by create_missing_catalogs(), ED_asset_catalog_add(), blender::bke::tests::AssetCatalogTest::save_from_memory_into_existing_asset_lib(), and blender::bke::tests::TEST_F().

◆ create_catalog_filter()

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

Create a filter object that can be used to determine whether an asset belongs to the given catalog, or any of the catalogs in the sub-tree rooted at the given catalog.

See also
#AssetCatalogFilter

Definition at line 151 of file blenkernel/intern/asset_catalog.cc.

References blender::Set< Key, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::add(), catalog_collection_, find_catalog(), blender::bke::AssetCatalogPath::is_contained_in(), and blender::bke::AssetCatalog::path.

Referenced by file_ensure_updated_catalog_filter_data(), and blender::bke::tests::TEST_F().

◆ create_missing_catalogs()

void blender::bke::AssetCatalogService::create_missing_catalogs ( )
protected

◆ delete_catalog_by_id_hard()

void blender::bke::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 196 of file blenkernel/intern/asset_catalog.cc.

References catalog_collection_.

Referenced by purge_catalogs_not_listed().

◆ delete_catalog_by_id_soft()

void blender::bke::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 175 of file blenkernel/intern/asset_catalog.cc.

References catalog_collection_, blender::bke::AssetCatalog::flags, and blender::bke::AssetCatalog::Flags::is_deleted.

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

◆ find_catalog()

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

◆ find_catalog_by_path()

AssetCatalog * blender::bke::AssetCatalogService::find_catalog_by_path ( const AssetCatalogPath path) const

Return first catalog with the given path. Return nullptr if not found. This is not an efficient call as it's just a linear search over the catalogs.

If there are multiple catalogs with the same path, return the first-loaded one. If there is none marked as "first loaded", return the one with the lowest UUID.

Definition at line 124 of file blenkernel/intern/asset_catalog.cc.

References catalog_collection_.

Referenced by catalog_name_exists_fn(), and blender::bke::tests::TEST_F().

◆ find_suitable_cdf_path_for_writing()

CatalogFilePath blender::bke::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 503 of file blenkernel/intern/asset_catalog.cc.

References blender::bke::asset_definition_default_file_path_from_dir(), BKE_asset_library_find_suitable_root_path_from_path(), BLI_assert_msg, BLI_path_join(), BLI_split_dir_part(), DEFAULT_CATALOG_FILENAME, NULL, and PATH_MAX.

Referenced by write_to_disk_ex().

◆ get_catalog_definition_file()

AssetCatalogDefinitionFile * blender::bke::AssetCatalogService::get_catalog_definition_file ( )
protected

◆ get_catalog_tree()

AssetCatalogTree * blender::bke::AssetCatalogService::get_catalog_tree ( )

◆ get_catalogs()

OwningAssetCatalogMap & blender::bke::AssetCatalogService::get_catalogs ( )
protected

◆ get_deleted_catalogs()

OwningAssetCatalogMap & blender::bke::AssetCatalogService::get_deleted_catalogs ( )
protected

◆ has_unsaved_changes()

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

◆ is_catalog_known()

bool blender::bke::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 145 of file blenkernel/intern/asset_catalog.cc.

References BLI_assert, and catalog_collection_.

◆ is_catalog_known_with_unsaved_changes()

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

◆ is_empty()

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

Return true only if there are no catalogs known.

Definition at line 94 of file blenkernel/intern/asset_catalog.cc.

References BLI_assert, and catalog_collection_.

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

◆ is_redo_possbile()

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

◆ is_undo_possbile()

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

◆ load_directory_recursive()

void blender::bke::AssetCatalogService::load_directory_recursive ( const CatalogFilePath directory_path)
protected

◆ load_from_disk() [1/2]

void blender::bke::AssetCatalogService::load_from_disk ( )

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

Definition at line 295 of file blenkernel/intern/asset_catalog.cc.

References asset_library_root_.

Referenced by blender::bke::tests::AssetCatalogTest::save_from_memory_into_existing_asset_lib(), and blender::bke::tests::TEST_F().

◆ load_from_disk() [2/2]

void blender::bke::AssetCatalogService::load_from_disk ( const CatalogFilePath file_or_directory_path)

Load asset catalog definitions from the given file or directory.

Definition at line 300 of file blenkernel/intern/asset_catalog.cc.

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

◆ load_single_file()

void blender::bke::AssetCatalogService::load_single_file ( const CatalogFilePath catalog_definition_file_path)
protected

◆ parse_catalog_file()

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

◆ prepare_to_merge_on_write()

void blender::bke::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 485 of file blenkernel/intern/asset_catalog.cc.

References catalog_collection_, and tag_all_catalogs_as_unsaved_changes().

Referenced by asset_bundle_install_exec().

◆ prune_catalogs_by_id()

void blender::bke::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 224 of file blenkernel/intern/asset_catalog.cc.

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

Referenced by ED_asset_catalog_remove(), and blender::bke::tests::TEST_F().

◆ prune_catalogs_by_path()

void blender::bke::AssetCatalogService::prune_catalogs_by_path ( const AssetCatalogPath path)

◆ purge_catalogs_not_listed()

void blender::bke::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 415 of file blenkernel/intern/asset_catalog.cc.

References blender::Set< Key, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::add(), catalog_collection_, 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::bke::AssetCatalogService::read_into_tree ( )
protected

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

References catalog_collection_, and tree.

Referenced by rebuild_tree().

◆ rebuild_tree()

void blender::bke::AssetCatalogService::rebuild_tree ( )
protected

◆ redo()

void blender::bke::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 627 of file blenkernel/intern/asset_catalog.cc.

References BLI_assert_msg, catalog_collection_, is_redo_possbile(), rebuild_tree(), redo_snapshots_, and undo_snapshots_.

Referenced by asset_catalog_redo_exec(), and blender::bke::tests::TEST_F().

◆ reload_catalogs()

void blender::bke::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 382 of file blenkernel/intern/asset_catalog.cc.

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

Referenced by blender::bke::tests::TEST_F(), and write_to_disk_ex().

◆ tag_all_catalogs_as_unsaved_changes()

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

For every catalog, mark it as "dirty".

Definition at line 86 of file blenkernel/intern/asset_catalog.cc.

References catalog_collection_.

Referenced by prepare_to_merge_on_write().

◆ tag_has_unsaved_changes()

void blender::bke::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 50 of file blenkernel/intern/asset_catalog.cc.

References BLI_assert, catalog_collection_, blender::bke::AssetCatalog::flags, and blender::bke::AssetCatalog::Flags::has_unsaved_changes.

Referenced by ED_asset_catalog_add(), ED_asset_catalog_move(), ED_asset_catalog_remove(), ED_asset_catalog_rename(), blender::bke::tests::TEST_F(), and update_catalog_path().

◆ undo()

void blender::bke::AssetCatalogService::undo ( )

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

Definition at line 618 of file blenkernel/intern/asset_catalog.cc.

References BLI_assert_msg, catalog_collection_, is_undo_possbile(), rebuild_tree(), redo_snapshots_, and undo_snapshots_.

Referenced by asset_bundle_install_exec(), asset_catalog_undo_exec(), and blender::bke::tests::TEST_F().

◆ undo_push()

void blender::bke::AssetCatalogService::undo_push ( )

◆ untag_has_unsaved_changes()

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

Definition at line 59 of file blenkernel/intern/asset_catalog.cc.

References BLI_assert, and catalog_collection_.

Referenced by write_to_disk().

◆ update_catalog_path()

void blender::bke::AssetCatalogService::update_catalog_path ( CatalogID  catalog_id,
const AssetCatalogPath new_catalog_path 
)

◆ write_to_disk()

bool blender::bke::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 452 of file blenkernel/intern/asset_catalog.cc.

References rebuild_tree(), untag_has_unsaved_changes(), and write_to_disk_ex().

Referenced by ED_asset_catalogs_save_from_main_path(), blender::bke::tests::AssetCatalogTest::save_from_memory_into_existing_asset_lib(), and blender::bke::tests::TEST_F().

◆ write_to_disk_ex()

bool blender::bke::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 463 of file blenkernel/intern/asset_catalog.cc.

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

Referenced by write_to_disk().

Member Data Documentation

◆ asset_library_root_

CatalogFilePath blender::bke::AssetCatalogService::asset_library_root_
protected

Definition at line 173 of file BKE_asset_catalog.hh.

Referenced by load_from_disk().

◆ catalog_collection_

std::unique_ptr<AssetCatalogCollection> blender::bke::AssetCatalogService::catalog_collection_
protected

◆ catalog_tree_

std::unique_ptr<AssetCatalogTree> blender::bke::AssetCatalogService::catalog_tree_ = std::make_unique<AssetCatalogTree>()
protected

Definition at line 172 of file BKE_asset_catalog.hh.

Referenced by create_catalog(), get_catalog_tree(), and rebuild_tree().

◆ DEFAULT_CATALOG_FILENAME

const CatalogFilePath blender::bke::AssetCatalogService::DEFAULT_CATALOG_FILENAME = "blender_assets.cats.txt"
static

◆ redo_snapshots_

Vector<std::unique_ptr<AssetCatalogCollection> > blender::bke::AssetCatalogService::redo_snapshots_
protected

Definition at line 176 of file BKE_asset_catalog.hh.

Referenced by is_redo_possbile(), redo(), undo(), and undo_push().

◆ undo_snapshots_

Vector<std::unique_ptr<AssetCatalogCollection> > blender::bke::AssetCatalogService::undo_snapshots_
protected

Definition at line 175 of file BKE_asset_catalog.hh.

Referenced by is_undo_possbile(), redo(), undo(), and undo_push().


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