Cleanup: Remove unnecessary C API for asset representation

Now that almost all code is in C++, this is unnecessary and
just confuses things with multiple entry points to the same code.

Pull Request: https://projects.blender.org/blender/blender/pulls/109661
This commit is contained in:
Hans Goudey
2023-07-04 14:46:19 +02:00
committed by Hans Goudey
parent 2ee0c23a82
commit 1b4b90f5f7
27 changed files with 129 additions and 282 deletions

View File

@@ -1,49 +0,0 @@
/* SPDX-FileCopyrightText: 2023 Blender Foundation
*
* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup asset_system
*/
#pragma once
#include "BLI_compiler_attrs.h"
#include "DNA_ID_enums.h"
#ifdef __cplusplus
extern "C" {
#endif
struct AssetMetaData;
struct AssetWeakReference;
/** C handle for #asset_system::AssetRepresentation. */
typedef struct AssetRepresentation AssetRepresentation;
const char *AS_asset_representation_name_get(const AssetRepresentation *asset)
ATTR_WARN_UNUSED_RESULT;
ID_Type AS_asset_representation_id_type_get(const AssetRepresentation *asset)
ATTR_WARN_UNUSED_RESULT;
AssetMetaData *AS_asset_representation_metadata_get(const AssetRepresentation *asset)
ATTR_WARN_UNUSED_RESULT;
struct ID *AS_asset_representation_local_id_get(const AssetRepresentation *asset)
ATTR_WARN_UNUSED_RESULT;
bool AS_asset_representation_is_local_id(const AssetRepresentation *asset) ATTR_WARN_UNUSED_RESULT;
bool AS_asset_representation_is_never_link(const AssetRepresentation *asset)
ATTR_WARN_UNUSED_RESULT;
bool AS_asset_representation_may_override_import_method(const AssetRepresentation *asset);
bool AS_asset_representation_use_relative_path_get(const AssetRepresentation *asset);
/**
* C version of #AssetRepresentation::make_weak_reference. Returned pointer needs freeing with
* #MEM_delete() or #BKE_asset_weak_reference_free().
*/
AssetWeakReference *AS_asset_representation_weak_reference_create(const AssetRepresentation *asset)
ATTR_WARN_UNUSED_RESULT;
#ifdef __cplusplus
}
#endif

View File

@@ -114,19 +114,3 @@ class AssetRepresentation {
};
} // namespace blender::asset_system
/* C-Handle */
struct AssetRepresentation;
const blender::StringRefNull AS_asset_representation_library_relative_identifier_get(
const AssetRepresentation *asset_handle);
std::string AS_asset_representation_full_path_get(const ::AssetRepresentation *asset);
/**
* Get the absolute path to the .blend file containing the given asset. String will be empty if
* the asset could not be mapped to a valid .blend file path. Valid in this case also means that
* the file needs to exist on disk.
*/
std::string AS_asset_representation_full_library_path_get(const ::AssetRepresentation *asset);
std::optional<eAssetImportMethod> AS_asset_representation_import_method_get(
const ::AssetRepresentation *asset_handle);

View File

@@ -39,7 +39,6 @@ set(SRC
intern/utils.hh
AS_asset_library.h
AS_asset_representation.h
)
set(LIB

View File

@@ -14,7 +14,6 @@
#include "AS_asset_identifier.hh"
#include "AS_asset_library.hh"
#include "AS_asset_representation.h"
#include "AS_asset_representation.hh"
namespace blender::asset_system {
@@ -143,101 +142,3 @@ const AssetLibrary &AssetRepresentation::owner_asset_library() const
}
} // namespace blender::asset_system
using namespace blender;
const StringRefNull AS_asset_representation_library_relative_identifier_get(
const AssetRepresentation *asset_handle)
{
const asset_system::AssetRepresentation *asset =
reinterpret_cast<const asset_system::AssetRepresentation *>(asset_handle);
const asset_system::AssetIdentifier &identifier = asset->get_identifier();
return identifier.library_relative_identifier();
}
std::string AS_asset_representation_full_path_get(const AssetRepresentation *asset_handle)
{
const asset_system::AssetRepresentation *asset =
reinterpret_cast<const asset_system::AssetRepresentation *>(asset_handle);
const asset_system::AssetIdentifier &identifier = asset->get_identifier();
return identifier.full_path();
}
std::string AS_asset_representation_full_library_path_get(const AssetRepresentation *asset_handle)
{
const asset_system::AssetRepresentation *asset =
reinterpret_cast<const asset_system::AssetRepresentation *>(asset_handle);
return asset->get_identifier().full_library_path();
}
std::optional<eAssetImportMethod> AS_asset_representation_import_method_get(
const AssetRepresentation *asset_handle)
{
const asset_system::AssetRepresentation *asset =
reinterpret_cast<const asset_system::AssetRepresentation *>(asset_handle);
return asset->get_import_method();
}
bool AS_asset_representation_may_override_import_method(const AssetRepresentation *asset_handle)
{
const asset_system::AssetRepresentation *asset =
reinterpret_cast<const asset_system::AssetRepresentation *>(asset_handle);
return asset->may_override_import_method();
}
bool AS_asset_representation_use_relative_path_get(const AssetRepresentation *asset_handle)
{
const asset_system::AssetRepresentation *asset =
reinterpret_cast<const asset_system::AssetRepresentation *>(asset_handle);
return asset->get_use_relative_path();
}
/* ---------------------------------------------------------------------- */
/** \name C-API
* \{ */
const char *AS_asset_representation_name_get(const AssetRepresentation *asset_handle)
{
const asset_system::AssetRepresentation *asset =
reinterpret_cast<const asset_system::AssetRepresentation *>(asset_handle);
return asset->get_name().c_str();
}
ID_Type AS_asset_representation_id_type_get(const AssetRepresentation *asset_handle)
{
const asset_system::AssetRepresentation *asset =
reinterpret_cast<const asset_system::AssetRepresentation *>(asset_handle);
return asset->get_id_type();
}
AssetMetaData *AS_asset_representation_metadata_get(const AssetRepresentation *asset_handle)
{
const asset_system::AssetRepresentation *asset =
reinterpret_cast<const asset_system::AssetRepresentation *>(asset_handle);
return &asset->get_metadata();
}
ID *AS_asset_representation_local_id_get(const AssetRepresentation *asset_handle)
{
const asset_system::AssetRepresentation *asset =
reinterpret_cast<const asset_system::AssetRepresentation *>(asset_handle);
return asset->local_id();
}
bool AS_asset_representation_is_local_id(const AssetRepresentation *asset_handle)
{
const asset_system::AssetRepresentation *asset =
reinterpret_cast<const asset_system::AssetRepresentation *>(asset_handle);
return asset->is_local_id();
}
AssetWeakReference *AS_asset_representation_weak_reference_create(
const AssetRepresentation *asset_handle)
{
const asset_system::AssetRepresentation *asset =
reinterpret_cast<const asset_system::AssetRepresentation *>(asset_handle);
std::unique_ptr<AssetWeakReference> weak_ref = asset->make_weak_reference();
return MEM_new<AssetWeakReference>(__func__, std::move(*weak_ref));
}
/** \} */

View File

@@ -5,7 +5,6 @@
#include "asset_library_service.hh"
#include "asset_library_test_common.hh"
#include "AS_asset_representation.h"
#include "AS_asset_representation.hh"
#include "DNA_asset_types.h"
@@ -48,16 +47,6 @@ TEST_F(AssetRepresentationTest, weak_reference__current_file)
EXPECT_EQ(weak_ref->asset_library_identifier, nullptr);
EXPECT_STREQ(weak_ref->relative_asset_identifier, "path/to/an/asset");
}
{
/* Also test the C-API, it moves memory, so worth testing. */
AssetWeakReference *c_weak_ref = AS_asset_representation_weak_reference_create(
reinterpret_cast<::AssetRepresentation *>(&asset));
EXPECT_EQ(c_weak_ref->asset_library_type, ASSET_LIBRARY_LOCAL);
EXPECT_EQ(c_weak_ref->asset_library_identifier, nullptr);
EXPECT_STREQ(c_weak_ref->relative_asset_identifier, "path/to/an/asset");
MEM_delete(c_weak_ref);
}
}
TEST_F(AssetRepresentationTest, weak_reference__custom_library)

View File

@@ -105,6 +105,10 @@ struct bContextStore {
bool used = false;
};
namespace blender::asset_system {
class AssetRepresentation;
}
#endif
/* for the context's rna mode enum
@@ -400,7 +404,9 @@ bool CTX_data_editable_gpencil_strokes(const bContext *C, ListBase *list);
const struct AssetLibraryReference *CTX_wm_asset_library_ref(const bContext *C);
struct AssetHandle CTX_wm_asset_handle(const bContext *C, bool *r_is_valid);
struct AssetRepresentation *CTX_wm_asset(const bContext *C);
#ifdef __cplusplus
struct blender::asset_system::AssetRepresentation *CTX_wm_asset(const bContext *C);
#endif
bool CTX_wm_interface_locked(const bContext *C);

View File

@@ -1522,9 +1522,10 @@ AssetHandle CTX_wm_asset_handle(const bContext *C, bool *r_is_valid)
return AssetHandle{nullptr};
}
AssetRepresentation *CTX_wm_asset(const bContext *C)
blender::asset_system::AssetRepresentation *CTX_wm_asset(const bContext *C)
{
return static_cast<AssetRepresentation *>(ctx_data_pointer_get(C, "asset"));
return static_cast<blender::asset_system::AssetRepresentation *>(
ctx_data_pointer_get(C, "asset"));
}
Depsgraph *CTX_data_depsgraph_pointer(const bContext *C)

View File

@@ -23,6 +23,9 @@
namespace blender::asset_system {
class AssetRepresentation;
}
using AssetRepresentationHandle = blender::asset_system::AssetRepresentation;
#else
typedef struct AssetRepresentationHandle AssetRepresentationHandle;
#endif
#ifdef __cplusplus
@@ -31,10 +34,7 @@ extern "C" {
struct AssetHandle;
struct AssetRepresentation *ED_asset_handle_get_representation(const struct AssetHandle *asset);
const char *ED_asset_handle_get_name(const struct AssetHandle *asset);
struct AssetMetaData *ED_asset_handle_get_metadata(const struct AssetHandle *asset);
struct ID *ED_asset_handle_get_local_id(const struct AssetHandle *asset);
AssetRepresentationHandle *ED_asset_handle_get_representation(const struct AssetHandle *asset);
ID_Type ED_asset_handle_get_id_type(const struct AssetHandle *asset);
int ED_asset_handle_get_preview_icon_id(const struct AssetHandle *asset);
void ED_asset_handle_get_full_library_path(

View File

@@ -8,7 +8,6 @@
#include <string>
#include "AS_asset_representation.h"
#include "AS_asset_representation.hh"
#include "BKE_blendfile.h"
@@ -23,29 +22,15 @@
#include "ED_asset_handle.h"
AssetRepresentation *ED_asset_handle_get_representation(const AssetHandle *asset)
blender::asset_system::AssetRepresentation *ED_asset_handle_get_representation(
const AssetHandle *asset)
{
return asset->file_data->asset;
}
const char *ED_asset_handle_get_name(const AssetHandle *asset)
{
return AS_asset_representation_name_get(asset->file_data->asset);
}
AssetMetaData *ED_asset_handle_get_metadata(const AssetHandle *asset_handle)
{
return AS_asset_representation_metadata_get(asset_handle->file_data->asset);
}
ID *ED_asset_handle_get_local_id(const AssetHandle *asset_handle)
{
return AS_asset_representation_local_id_get(asset_handle->file_data->asset);
}
ID_Type ED_asset_handle_get_id_type(const AssetHandle *asset_handle)
{
return AS_asset_representation_id_type_get(asset_handle->file_data->asset);
return asset_handle->file_data->asset->get_id_type();
}
int ED_asset_handle_get_preview_icon_id(const AssetHandle *asset)
@@ -58,8 +43,7 @@ void ED_asset_handle_get_full_library_path(const AssetHandle *asset_handle,
{
*r_full_lib_path = '\0';
std::string library_path = AS_asset_representation_full_library_path_get(
asset_handle->file_data->asset);
std::string library_path = asset_handle->file_data->asset->get_identifier().full_library_path();
if (library_path.empty()) {
return;
}

View File

@@ -8,6 +8,7 @@
#include "AS_asset_library.h"
#include "AS_asset_library.hh"
#include "AS_asset_representation.hh"
#include "BKE_bpath.h"
#include "BKE_context.h"
@@ -288,7 +289,7 @@ void AssetClearHelper::reportResults(const bContext *C, ReportList &reports) con
/* Dedicated error message for when there is an active asset detected, but it's not an ID local
* to this file. Helps users better understanding what's going on. */
if (AssetHandle active_asset = CTX_wm_asset_handle(C, &is_valid);
is_valid && !ED_asset_handle_get_local_id(&active_asset))
is_valid && !ED_asset_handle_get_representation(&active_asset)->local_id())
{
BKE_report(&reports,
RPT_ERROR,

View File

@@ -12,7 +12,6 @@
#include <new>
#include <string>
#include "AS_asset_representation.h"
#include "AS_asset_representation.hh"
#include "DNA_space_types.h"
@@ -32,11 +31,13 @@
using namespace blender;
class AssetTemporaryIDConsumer : NonCopyable, NonMovable {
const AssetRepresentation *asset_;
const blender::asset_system::AssetRepresentation *asset_;
TempLibraryContext *temp_lib_context_ = nullptr;
public:
AssetTemporaryIDConsumer(const AssetRepresentation *asset) : asset_(asset) {}
AssetTemporaryIDConsumer(const blender::asset_system::AssetRepresentation *asset) : asset_(asset)
{
}
~AssetTemporaryIDConsumer()
{
if (temp_lib_context_) {
@@ -46,13 +47,13 @@ class AssetTemporaryIDConsumer : NonCopyable, NonMovable {
ID *get_local_id()
{
return AS_asset_representation_local_id_get(asset_);
return asset_->local_id();
}
ID *import_id(ID_Type id_type, Main &bmain, ReportList &reports)
{
const char *asset_name = AS_asset_representation_name_get(asset_);
std::string blend_file_path = AS_asset_representation_full_library_path_get(asset_);
const char *asset_name = asset_->get_name().c_str();
std::string blend_file_path = asset_->get_identifier().full_library_path();
temp_lib_context_ = BLO_library_temp_load_id(
&bmain, blend_file_path.c_str(), id_type, asset_name, &reports);

View File

@@ -69,14 +69,9 @@ namespace blender::ed::geometry {
/** \name Operator
* \{ */
static const asset_system::AssetRepresentation *get_context_asset(const bContext &C)
{
return reinterpret_cast<const asset_system::AssetRepresentation *>(CTX_wm_asset(&C));
}
static const bNodeTree *get_node_group(const bContext &C)
{
const asset_system::AssetRepresentation *asset = get_context_asset(C);
const asset_system::AssetRepresentation *asset = CTX_wm_asset(&C);
if (!asset) {
return nullptr;
}
@@ -287,7 +282,7 @@ static char *run_node_group_get_description(bContext *C,
wmOperatorType * /*ot*/,
PointerRNA * /*ptr*/)
{
const asset_system::AssetRepresentation *asset = get_context_asset(*C);
const asset_system::AssetRepresentation *asset = CTX_wm_asset(C);
if (!asset) {
return nullptr;
}
@@ -300,7 +295,7 @@ static char *run_node_group_get_description(bContext *C,
static bool run_node_group_poll(bContext *C)
{
const asset_system::AssetRepresentation *asset = get_context_asset(*C);
const asset_system::AssetRepresentation *asset = CTX_wm_asset(C);
if (!asset) {
return false;
}

View File

@@ -1809,16 +1809,20 @@ void UI_but_drag_set_id(uiBut *but, struct ID *id);
* Sets #UI_BUT_DRAG_FULL_BUT so the full button can be dragged.
*/
void UI_but_drag_attach_image(uiBut *but, struct ImBuf *imb, float scale);
#ifdef __cplusplus
/**
* Sets #UI_BUT_DRAG_FULL_BUT so the full button can be dragged.
* \param asset: May be passed from a temporary variable, drag data only stores a copy of this.
*/
void UI_but_drag_set_asset(uiBut *but,
const struct AssetRepresentation *asset,
const blender::asset_system::AssetRepresentation *asset,
int import_type, /* eAssetImportType */
int icon,
struct ImBuf *imb,
float scale);
#endif
void UI_but_drag_set_rna(uiBut *but, struct PointerRNA *ptr);
/**
* Enable dragging a path from this button.

View File

@@ -30,7 +30,7 @@ void UI_but_drag_attach_image(uiBut *but, ImBuf *imb, const float scale)
}
void UI_but_drag_set_asset(uiBut *but,
const AssetRepresentation *asset,
const blender::asset_system::AssetRepresentation *asset,
int import_type,
int icon,
ImBuf *imb,

View File

@@ -6,7 +6,6 @@
* \ingroup edinterface
*/
#include "AS_asset_representation.h"
#include "AS_asset_representation.hh"
#include "DNA_space_types.h"
@@ -47,16 +46,17 @@ struct AssetViewListData {
static void asset_view_item_but_drag_set(uiBut *but, AssetHandle *asset_handle)
{
AssetRepresentation *asset = ED_asset_handle_get_representation(asset_handle);
blender::asset_system::AssetRepresentation *asset = ED_asset_handle_get_representation(
asset_handle);
ID *id = AS_asset_representation_local_id_get(asset);
ID *id = asset->local_id();
if (id != nullptr) {
UI_but_drag_set_id(but, id);
return;
}
const eAssetImportMethod import_method =
AS_asset_representation_import_method_get(asset).value_or(ASSET_IMPORT_APPEND_REUSE);
const eAssetImportMethod import_method = asset->get_import_method().value_or(
ASSET_IMPORT_APPEND_REUSE);
ImBuf *imbuf = ED_assetlist_asset_image_get(asset_handle);
UI_but_drag_set_asset(
@@ -90,21 +90,22 @@ static void asset_view_draw_item(uiList *ui_list,
const bool show_names = list_data->show_names;
const float size_x = UI_preview_tile_size_x();
const float size_y = show_names ? UI_preview_tile_size_y() : UI_preview_tile_size_y_no_label();
uiBut *but = uiDefIconTextBut(block,
UI_BTYPE_PREVIEW_TILE,
0,
ED_asset_handle_get_preview_icon_id(&asset_handle),
show_names ? ED_asset_handle_get_name(&asset_handle) : "",
0,
0,
size_x,
size_y,
nullptr,
0,
0,
0,
0,
"");
uiBut *but = uiDefIconTextBut(
block,
UI_BTYPE_PREVIEW_TILE,
0,
ED_asset_handle_get_preview_icon_id(&asset_handle),
show_names ? ED_asset_handle_get_representation(&asset_handle)->get_name().c_str() : "",
0,
0,
size_x,
size_y,
nullptr,
0,
0,
0,
0,
"");
ui_def_but_icon(but,
ED_asset_handle_get_preview_icon_id(&asset_handle),
/* NOLINTNEXTLINE: bugprone-suspicious-enum-usage */

View File

@@ -12,7 +12,7 @@
#include "MEM_guardedalloc.h"
#include "AS_asset_representation.h"
#include "AS_asset_representation.hh"
#include "BLI_blenlib.h"
#include "BLI_fileops_types.h"
@@ -116,9 +116,9 @@ static char *file_draw_tooltip_func(bContext * /*C*/, void *argN, const char * /
static char *file_draw_asset_tooltip_func(bContext * /*C*/, void *argN, const char * /*tip*/)
{
const AssetRepresentation *asset = static_cast<AssetRepresentation *>(argN);
std::string complete_string = AS_asset_representation_name_get(asset);
const AssetMetaData &meta_data = *AS_asset_representation_metadata_get(asset);
const auto *asset = static_cast<blender::asset_system::AssetRepresentation *>(argN);
std::string complete_string = asset->get_name();
const AssetMetaData &meta_data = asset->get_metadata();
if (meta_data.description) {
complete_string += '\n';
complete_string += meta_data.description;

View File

@@ -1151,7 +1151,7 @@ void filelist_file_get_full_path(const FileList *filelist,
char r_filepath[/*FILE_MAX_LIBEXTRA*/])
{
if (file->asset) {
const std::string asset_path = AS_asset_representation_full_path_get(file->asset);
const std::string asset_path = file->asset->get_identifier().full_path();
BLI_strncpy(r_filepath, asset_path.c_str(), FILE_MAX_LIBEXTRA);
return;
}
@@ -2107,7 +2107,7 @@ static FileDirEntry *filelist_file_create_entry(FileList *filelist, const int in
ret->redirection_path = BLI_strdup(entry->redirection_path);
}
ret->id = entry->local_data.id;
ret->asset = reinterpret_cast<::AssetRepresentation *>(entry->asset);
ret->asset = entry->asset;
/* For some file types the preview is already available. */
if (entry->local_data.preview_image &&
BKE_previewimg_is_finished(entry->local_data.preview_image, ICON_SIZE_PREVIEW))

View File

@@ -61,7 +61,7 @@
#include "UI_interface_icons.h"
#include "UI_view2d.h"
#include "AS_asset_representation.h"
#include "AS_asset_representation.hh"
#include "AS_essentials_library.hh"
#include "file_intern.h"
@@ -513,16 +513,15 @@ int ED_fileselect_asset_import_method_get(const SpaceFile *sfile, const FileDirE
}
/* First handle the case where the asset system dictates a certain import method. */
if (AS_asset_representation_may_override_import_method(file->asset) == false) {
BLI_assert(AS_asset_representation_import_method_get(file->asset).has_value());
return *AS_asset_representation_import_method_get(file->asset);
if (file->asset->may_override_import_method() == false) {
BLI_assert(file->asset->get_import_method().has_value());
return *file->asset->get_import_method();
}
const FileAssetSelectParams *params = ED_fileselect_get_asset_params(sfile);
if (params->import_type == FILE_ASSET_IMPORT_FOLLOW_PREFS) {
std::optional import_method = AS_asset_representation_import_method_get(file->asset);
std::optional import_method = file->asset->get_import_method();
return import_method ? *import_method : -1;
}

View File

@@ -168,7 +168,7 @@ static void gather_add_node_operations(const bContext &C,
/* Use a set to avoid adding items for node groups that are also assets. Using data-block
* names is a crutch, since different assets may have the same name. However, an alternative
* using #ED_asset_handle_get_local_id didn't work in this case. */
* using #AssetRepresentation::local_id() didn't work in this case. */
Set<std::string> added_assets;
gather_search_items_for_all_assets(C, node_tree, added_assets, r_search_items);
gather_search_items_for_node_groups(C, node_tree, added_assets, r_search_items);

View File

@@ -8,7 +8,6 @@
#include <numeric>
#include "AS_asset_representation.h"
#include "AS_asset_representation.hh"
#include "MEM_guardedalloc.h"
@@ -380,14 +379,13 @@ void NODE_OT_add_group(wmOperatorType *ot)
* \{ */
static bool add_node_group_asset(const bContext &C,
const AssetRepresentation &asset_c_handle,
const asset_system::AssetRepresentation &asset,
ReportList &reports)
{
Main &bmain = *CTX_data_main(&C);
SpaceNode &snode = *CTX_wm_space_node(&C);
bNodeTree &edit_tree = *snode.edittree;
auto &asset = reinterpret_cast<const asset_system::AssetRepresentation &>(asset_c_handle);
bNodeTree *node_group = reinterpret_cast<bNodeTree *>(
ED_asset_get_local_id_from_asset_or_append_and_reuse(&bmain, asset, ID_NT));
if (!node_group) {
@@ -427,7 +425,7 @@ static int node_add_group_asset_invoke(bContext *C, wmOperator *op, const wmEven
ARegion &region = *CTX_wm_region(C);
SpaceNode &snode = *CTX_wm_space_node(C);
const AssetRepresentation *asset = CTX_wm_asset(C);
const asset_system::AssetRepresentation *asset = CTX_wm_asset(C);
if (!asset) {
return OPERATOR_CANCELLED;
}
@@ -459,11 +457,11 @@ static char *node_add_group_asset_get_description(bContext *C,
wmOperatorType * /*op*/,
PointerRNA * /*values*/)
{
const AssetRepresentation *asset = CTX_wm_asset(C);
const asset_system::AssetRepresentation *asset = CTX_wm_asset(C);
if (!asset) {
return nullptr;
}
const AssetMetaData &asset_data = *AS_asset_representation_metadata_get(asset);
const AssetMetaData &asset_data = asset->get_metadata();
if (!asset_data.description) {
return nullptr;
}

View File

@@ -12,7 +12,7 @@
#include <cstdio>
#include <cstring>
#include "AS_asset_representation.h"
#include "AS_asset_representation.hh"
#include "DNA_collection_types.h"
#include "DNA_defaults.h"
@@ -502,7 +502,7 @@ static ID_Type view3d_drop_id_in_main_region_poll_get_id_type(bContext *C,
wmDragAsset *asset_drag = WM_drag_get_asset_data(drag, 0);
if (asset_drag) {
return AS_asset_representation_id_type_get(asset_drag->asset);
return asset_drag->asset->get_id_type();
}
return ID_Type(0);
@@ -737,7 +737,7 @@ static bool view3d_geometry_nodes_drop_poll(bContext *C, wmDrag *drag, const wmE
if (!asset_data) {
return false;
}
const AssetMetaData *metadata = AS_asset_representation_metadata_get(asset_data->asset);
const AssetMetaData *metadata = &asset_data->asset->get_metadata();
const IDProperty *tree_type = BKE_asset_metadata_idprop_find(metadata, "type");
if (!tree_type || IDP_Int(tree_type) != NTREE_GEOMETRY) {
return false;

View File

@@ -49,6 +49,15 @@ struct bNodeTree;
struct wmOperator;
struct wmTimer;
#ifdef __cplusplus
namespace blender::asset_system {
class AssetRepresentation;
}
using AssetRepresentationHandle = blender::asset_system::AssetRepresentation;
#else
typedef struct AssetRepresentationHandle AssetRepresentationHandle;
#endif
/** Defined in `buttons_intern.h`. */
typedef struct SpaceProperties_Runtime SpaceProperties_Runtime;
@@ -1148,7 +1157,7 @@ typedef struct FileDirEntry {
/** If this file represents an asset, its asset data is here. Note that we may show assets of
* external files in which case this is set but not the id above.
* Note comment for FileListInternEntry.local_data, the same applies here! */
struct AssetRepresentation *asset;
AssetRepresentationHandle *asset;
/* The icon_id for the preview image. */
int preview_icon_id;

View File

@@ -20,6 +20,7 @@
#ifdef RNA_RUNTIME
# include "AS_asset_library.h"
# include "AS_asset_representation.hh"
# include "BKE_asset.h"
# include "BKE_context.h"
@@ -367,7 +368,7 @@ static void rna_AssetHandle_get_full_library_path(
static PointerRNA rna_AssetHandle_local_id_get(PointerRNA *ptr)
{
const AssetHandle *asset = static_cast<const AssetHandle *>(ptr->data);
ID *id = ED_asset_handle_get_local_id(asset);
ID *id = ED_asset_handle_get_representation(asset)->local_id();
return rna_pointer_inherit_refine(ptr, &RNA_ID, id);
}

View File

@@ -535,7 +535,7 @@ static const EnumPropertyItem rna_enum_curve_display_handle_items[] = {
#ifdef RNA_RUNTIME
# include "AS_asset_representation.h"
# include "AS_asset_representation.hh"
# include "DNA_anim_types.h"
# include "DNA_asset_types.h"
@@ -2789,14 +2789,14 @@ static PointerRNA rna_FileBrowser_FileSelectEntry_asset_data_get(PointerRNA *ptr
return PointerRNA_NULL;
}
AssetMetaData *asset_data = AS_asset_representation_metadata_get(entry->asset);
AssetMetaData *asset_data = &entry->asset->get_metadata();
/* Note that the owning ID of the RNA pointer (`ptr->owner_id`) has to be set carefully:
* Local IDs (`entry->id`) own their asset metadata themselves. Asset metadata from other blend
* files are owned by the file browser (`entry`). Only if this is set correctly, we can tell from
* the metadata RNA pointer if the metadata is stored locally and can thus be edited or not. */
if (AS_asset_representation_is_local_id(entry->asset)) {
if (entry->asset->is_local_id()) {
PointerRNA id_ptr;
RNA_id_pointer_create(entry->id, &id_ptr);
return rna_pointer_inherit_refine(&id_ptr, &RNA_AssetMetaData, asset_data);

View File

@@ -67,6 +67,12 @@ typedef struct wmGizmoMap wmGizmoMap;
typedef struct wmGizmoMapType wmGizmoMapType;
typedef struct wmJob wmJob;
#ifdef __cplusplus
namespace blender::asset_system {
class AssetRepresentation;
}
#endif
/* General API. */
/**
@@ -1439,11 +1445,14 @@ struct ID *WM_drag_get_local_ID_from_event(const struct wmEvent *event, short id
*/
bool WM_drag_is_ID_type(const struct wmDrag *drag, int idcode);
#ifdef __cplusplus
/**
* \note Does not store \a asset in any way, so it's fine to pass a temporary.
*/
wmDragAsset *WM_drag_create_asset_data(const struct AssetRepresentation *asset,
wmDragAsset *WM_drag_create_asset_data(const blender::asset_system::AssetRepresentation *asset,
int /* #eAssetImportMethod */ import_type);
#endif
struct wmDragAsset *WM_drag_get_asset_data(const struct wmDrag *drag, int idcode);
struct AssetMetaData *WM_drag_get_asset_meta_data(const struct wmDrag *drag, int idcode);
/**
@@ -1469,10 +1478,14 @@ void WM_drag_free_imported_drag_ID(struct Main *bmain,
struct wmDragAssetCatalog *WM_drag_get_asset_catalog_data(const struct wmDrag *drag);
#ifdef __cplusplus
/**
* \note Does not store \a asset in any way, so it's fine to pass a temporary.
*/
void WM_drag_add_asset_list_item(wmDrag *drag, const struct AssetRepresentation *asset);
void WM_drag_add_asset_list_item(wmDrag *drag,
const blender::asset_system::AssetRepresentation *asset);
#endif
const ListBase *WM_drag_asset_list_get(const wmDrag *drag);
const char *WM_drag_get_item_name(struct wmDrag *drag);

View File

@@ -118,6 +118,15 @@ struct wmWindowManager;
/* Include external gizmo API's */
#include "gizmo/WM_gizmo_api.h"
#ifdef __cplusplus
namespace blender::asset_system {
class AssetRepresentation;
}
using AssetRepresentationHandle = blender::asset_system::AssetRepresentation;
#else
typedef struct AssetRepresentationHandle AssetRepresentationHandle;
#endif
#ifdef __cplusplus
extern "C" {
#endif
@@ -1097,7 +1106,7 @@ typedef struct wmDragID {
typedef struct wmDragAsset {
int import_method; /* eAssetImportType */
const struct AssetRepresentation *asset;
const AssetRepresentationHandle *asset;
/* FIXME: This is temporary evil solution to get scene/view-layer/etc in the copy callback of the
* #wmDropBox.

View File

@@ -10,7 +10,6 @@
#include <cstring>
#include "AS_asset_representation.h"
#include "AS_asset_representation.hh"
#include "DNA_asset_types.h"
@@ -569,7 +568,8 @@ bool WM_drag_is_ID_type(const wmDrag *drag, int idcode)
return WM_drag_get_local_ID(drag, idcode) || WM_drag_get_asset_data(drag, idcode);
}
wmDragAsset *WM_drag_create_asset_data(const AssetRepresentation *asset, int import_type)
wmDragAsset *WM_drag_create_asset_data(const blender::asset_system::AssetRepresentation *asset,
int import_type)
{
wmDragAsset *asset_drag = MEM_new<wmDragAsset>(__func__);
@@ -591,7 +591,7 @@ wmDragAsset *WM_drag_get_asset_data(const wmDrag *drag, int idcode)
}
wmDragAsset *asset_drag = static_cast<wmDragAsset *>(drag->poin);
ID_Type asset_idcode = AS_asset_representation_id_type_get(asset_drag->asset);
ID_Type asset_idcode = asset_drag->asset->get_id_type();
return ELEM(idcode, 0, asset_idcode) ? asset_drag : nullptr;
}
@@ -599,7 +599,7 @@ AssetMetaData *WM_drag_get_asset_meta_data(const wmDrag *drag, int idcode)
{
wmDragAsset *drag_asset = WM_drag_get_asset_data(drag, idcode);
if (drag_asset) {
return AS_asset_representation_metadata_get(drag_asset->asset);
return &drag_asset->asset->get_metadata();
}
ID *local_id = WM_drag_get_local_ID(drag, idcode);
@@ -617,10 +617,10 @@ ID *WM_drag_asset_id_import(wmDragAsset *asset_drag, const int flag_extra)
eFileSel_Params_Flag flag = static_cast<eFileSel_Params_Flag>(flag_extra) |
FILE_ACTIVE_COLLECTION;
const char *name = AS_asset_representation_name_get(asset_drag->asset);
const std::string blend_path = AS_asset_representation_full_library_path_get(asset_drag->asset);
const ID_Type idtype = AS_asset_representation_id_type_get(asset_drag->asset);
const bool use_relative_path = AS_asset_representation_use_relative_path_get(asset_drag->asset);
const char *name = asset_drag->asset->get_name().c_str();
const std::string blend_path = asset_drag->asset->get_identifier().full_library_path();
const ID_Type idtype = asset_drag->asset->get_id_type();
const bool use_relative_path = asset_drag->asset->get_use_relative_path();
/* FIXME: Link/Append should happens in the operator called at the end of drop process, not from
* here. */
@@ -707,7 +707,7 @@ void WM_drag_free_imported_drag_ID(Main *bmain, wmDrag *drag, wmDropBox *drop)
return;
}
ID_Type asset_id_type = AS_asset_representation_id_type_get(asset_drag->asset);
ID_Type asset_id_type = asset_drag->asset->get_id_type();
/* Try to find the imported ID. For this to work either a "session_uuid" or "name" property must
* have been defined (see #WM_operator_properties_id_lookup()). */
ID *id = WM_operator_properties_id_lookup_from_name_or_session_uuid(
@@ -730,7 +730,8 @@ wmDragAssetCatalog *WM_drag_get_asset_catalog_data(const wmDrag *drag)
return static_cast<wmDragAssetCatalog *>(drag->poin);
}
void WM_drag_add_asset_list_item(wmDrag *drag, const AssetRepresentation *asset)
void WM_drag_add_asset_list_item(wmDrag *drag,
const blender::asset_system::AssetRepresentation *asset)
{
BLI_assert(drag->type == WM_DRAG_ASSET_LIST);
@@ -738,7 +739,7 @@ void WM_drag_add_asset_list_item(wmDrag *drag, const AssetRepresentation *asset)
/* Add to list. */
wmDragAssetListItem *drag_asset = MEM_cnew<wmDragAssetListItem>(__func__);
ID *local_id = AS_asset_representation_local_id_get(asset);
ID *local_id = asset->local_id();
if (local_id) {
drag_asset->is_external = false;
drag_asset->asset_data.local_id = local_id;
@@ -841,7 +842,7 @@ const char *WM_drag_get_item_name(wmDrag *drag)
}
case WM_DRAG_ASSET: {
const wmDragAsset *asset_drag = WM_drag_get_asset_data(drag, 0);
return AS_asset_representation_name_get(asset_drag->asset);
return asset_drag->asset->get_name().c_str();
}
case WM_DRAG_PATH: {
const wmDragPath *path_drag_data = static_cast<const wmDragPath *>(drag->poin);