[Bf-blender-cvs] [32153c56da3] node-add-asset-menu: Progress
Hans Goudey
noreply at git.blender.org
Mon Oct 3 23:16:52 CEST 2022
Commit: 32153c56da303d9844fcae8d4687d01677cfb542
Author: Hans Goudey
Date: Mon Oct 3 16:03:41 2022 -0500
Branches: node-add-asset-menu
https://developer.blender.org/rB32153c56da303d9844fcae8d4687d01677cfb542
Progress
===================================================================
M release/scripts/startup/bl_ui/node_add_menu.py
M source/blender/editors/space_node/add_menu_assets.cc
M source/blender/editors/space_node/node_add.cc
M source/blender/makesrna/intern/rna_asset.c
===================================================================
diff --git a/release/scripts/startup/bl_ui/node_add_menu.py b/release/scripts/startup/bl_ui/node_add_menu.py
index 3225cafe759..debed301904 100644
--- a/release/scripts/startup/bl_ui/node_add_menu.py
+++ b/release/scripts/startup/bl_ui/node_add_menu.py
@@ -62,7 +62,7 @@ def draw_assets_for_catalog(layout, catalog):
layout.menu_contents("NODE_MT_node_add_catalog_assets")
def draw_root_assets(layout):
- layout.menu_contents("NODE_MT_node_add_catalog_assets")
+ layout.menu_contents("NODE_MT_node_add_root_catalogs")
classes = (
diff --git a/source/blender/editors/space_node/add_menu_assets.cc b/source/blender/editors/space_node/add_menu_assets.cc
index b2df498da78..f83b301500c 100644
--- a/source/blender/editors/space_node/add_menu_assets.cc
+++ b/source/blender/editors/space_node/add_menu_assets.cc
@@ -1,5 +1,6 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
+#include "DNA_screen_types.h"
#include "DNA_space_types.h"
#include "BKE_asset.h"
@@ -22,12 +23,17 @@ static bool node_add_menu_poll(const bContext *C, MenuType * /*mt*/)
return CTX_wm_space_node(C);
}
+struct AssetItem {
+ AssetHandle handle;
+ const AssetLibraryReference &library_ref;
+};
+
static void gather_items_for_asset_library(const bContext &C,
const bNodeTree &node_tree,
const AssetLibraryReference &library_ref,
bke::AssetLibrary &library,
const bke::AssetCatalogPath &path,
- Vector<AssetHandle> &assets)
+ Vector<AssetItem> &assets)
{
const bke::AssetCatalogFilter filter = library.catalog_service->create_catalog_filter(path);
AssetFilterSettings type_filter{};
@@ -49,7 +55,7 @@ static void gather_items_for_asset_library(const bContext &C,
if (tree_type == nullptr || IDP_Int(tree_type) != node_tree.type) {
return true;
}
- assets.append(asset);
+ assets.append({asset, library_ref});
return true;
});
}
@@ -84,46 +90,48 @@ static void gather_root_catalogs(const bke::AssetLibrary &library,
static void node_add_catalog_assets_draw(const bContext *C, Menu *menu)
{
const Main &bmain = *CTX_data_main(C);
+ bScreen &screen = *CTX_wm_screen(C);
const SpaceNode &snode = *CTX_wm_space_node(C);
const bNodeTree *edit_tree = snode.edittree;
if (!edit_tree) {
return;
}
- const bke::AssetCatalogPath menu_path("Test Catalog");
+ const PointerRNA menu_path_ptr = CTX_data_pointer_get(C, "asset_catalog_path");
+ if (RNA_pointer_is_null(&menu_path_ptr)) {
+ return;
+ }
+ const bke::AssetCatalogPath &menu_path = *static_cast<const bke::AssetCatalogPath *>(
+ menu_path_ptr.data);
- Vector<AssetHandle> assets;
+ Vector<AssetItem> asset_item;
Vector<bke::AssetCatalogPath> child_catalogs;
for (const AssetLibraryReference &ref : bke::all_asset_library_refs()) {
if (bke::AssetLibrary *library = BKE_asset_library_load(&bmain, ref)) {
- gather_items_for_asset_library(*C, *edit_tree, ref, *library, menu_path, assets);
+ gather_items_for_asset_library(*C, *edit_tree, ref, *library, menu_path, asset_item);
gather_child_catalogs(*library, menu_path, child_catalogs);
}
}
- if (assets.is_empty() && child_catalogs.is_empty()) {
+ if (asset_item.is_empty() && child_catalogs.is_empty()) {
return;
}
uiLayout *layout = menu->layout;
uiItemS(layout);
- for (AssetHandle asset : assets) {
- PointerRNA props;
- uiItemFullO(layout,
- "NODE_OT_add_group_asset",
- ED_asset_handle_get_name(&asset),
- ICON_NONE,
- nullptr,
- WM_OP_INVOKE_DEFAULT,
- 0,
- &props);
- /* TODO: Really use null for PointerRNA.owner_id? */
- /* TODO: Really use null for PointerRNA.owner_id? */
- RNA_pointer_set(&props,
- "asset_handle",
- PointerRNA{
- nullptr,
- &RNA_AssetHandle,
- &asset // AGH! NO! THIS DOES NOT WORK!
- });
+ for (AssetItem item : asset_item) {
+ uiLayout *row = uiLayoutRow(layout, false);
+ PointerRNA file_data_ptr{};
+ file_data_ptr.owner_id = &screen.id;
+ file_data_ptr.type = &RNA_FileSelectEntry;
+ file_data_ptr.data = const_cast<FileDirEntry *>(item.handle.file_data);
+ uiLayoutSetContextPointer(row, "active_file", &file_data_ptr);
+
+ PointerRNA library_ptr{};
+ library_ptr.owner_id = &screen.id;
+ library_ptr.type = &RNA_AssetLibraryReference;
+ library_ptr.data = const_cast<AssetLibraryReference *>(&item.library_ref);
+ uiLayoutSetContextPointer(row, "asset_library_ref", &library_ptr);
+
+ uiItemO(layout, ED_asset_handle_get_name(&item.handle), ICON_NONE, "NODE_OT_add_group_asset");
}
for (const bke::AssetCatalogPath &child_catalog : child_catalogs) {
uiItemM(layout, "NODE_MT_node_add_catalog_assets", child_catalog.name().c_str(), ICON_NONE);
@@ -133,6 +141,7 @@ static void node_add_catalog_assets_draw(const bContext *C, Menu *menu)
static void add_root_catalogs_draw(const bContext *C, Menu *menu)
{
const Main &bmain = *CTX_data_main(C);
+ bScreen &screen = *CTX_wm_screen(C);
Vector<bke::AssetCatalogPath> catalogs;
for (const AssetLibraryReference &ref : bke::all_asset_library_refs()) {
@@ -143,6 +152,14 @@ static void add_root_catalogs_draw(const bContext *C, Menu *menu)
uiLayout *layout = menu->layout;
for (const bke::AssetCatalogPath &path : catalogs) {
+ uiLayout *row = uiLayoutRow(layout, false);
+
+ PointerRNA catalog_path_ptr{};
+ catalog_path_ptr.owner_id = &screen.id;
+ catalog_path_ptr.type = &RNA_AssetCatalogPath;
+ catalog_path_ptr.data = new bke::AssetCatalogPath(path); // Where should this memory live?
+
+ uiLayoutSetContextPointer(row, "asset_catalog_path", &catalog_path_ptr);
uiItemM(layout, "NODE_MT_node_add_catalog_assets", path.name().c_str(), ICON_NONE);
}
}
diff --git a/source/blender/editors/space_node/node_add.cc b/source/blender/editors/space_node/node_add.cc
index d81eec935bb..812389d6923 100644
--- a/source/blender/editors/space_node/node_add.cc
+++ b/source/blender/editors/space_node/node_add.cc
@@ -371,40 +371,33 @@ void NODE_OT_add_group(wmOperatorType *ot)
/** \name Add Node Group Asset Operator
* \{ */
-static int node_add_group_asset_exec(bContext *C, wmOperator *op)
+static int add_node_group_asset(const bContext &C,
+ const AssetLibraryReference &library_ref,
+ const AssetHandle asset,
+ ReportList &reports)
{
- Main &bmain = *CTX_data_main(C);
- SpaceNode &snode = *CTX_wm_space_node(C);
+ Main &bmain = *CTX_data_main(&C);
+ SpaceNode &snode = *CTX_wm_space_node(&C);
bNodeTree &edit_tree = *snode.edittree;
- PointerRNA asset_ptr = RNA_pointer_get(op->ptr, "asset_handle");
- if (RNA_pointer_is_null(&asset_ptr)) {
- return OPERATOR_CANCELLED;
- }
- PointerRNA library_ptr = RNA_pointer_get(op->ptr, "library_reference");
- if (RNA_pointer_is_null(&library_ptr)) {
- return OPERATOR_CANCELLED;
- }
- const AssetHandle asset = *static_cast<AssetHandle *>(asset_ptr.data);
- const AssetLibraryReference &library = *static_cast<AssetLibraryReference *>(library_ptr.data);
bNodeTree *node_group = reinterpret_cast<bNodeTree *>(
- asset::get_local_id_from_asset_or_append_and_reuse(bmain, library, asset));
+ asset::get_local_id_from_asset_or_append_and_reuse(bmain, library_ref, asset));
if (!node_group) {
return OPERATOR_CANCELLED;
}
- if (!node_group_add_poll(edit_tree, *node_group, *op->reports)) {
+ if (!node_group_add_poll(edit_tree, *node_group, reports)) {
/* Remove the node group if it was newly appended but can't be added to the tree. */
id_us_plus(&node_group->id);
BKE_id_free_us(&bmain, node_group);
return OPERATOR_CANCELLED;
}
- ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C));
+ ED_preview_kill_jobs(CTX_wm_manager(&C), CTX_data_main(&C));
bNode *group_node = add_node(
- *C, ntreeTypeFind(node_group->idname)->group_idname, snode.runtime->cursor);
+ C, ntreeTypeFind(node_group->idname)->group_idname, snode.runtime->cursor);
if (!group_node) {
- BKE_report(op->reports, RPT_WARNING, "Could not add node group");
+ BKE_report(&reports, RPT_WARNING, "Could not add node group");
return OPERATOR_CANCELLED;
}
@@ -413,16 +406,42 @@ static int node_add_group_asset_exec(bContext *C, wmOperator *op)
BKE_ntree_update_tag_node_property(&edit_tree, group_node);
nodeSetActive(&edit_tree, group_node);
- ED_node_tree_propagate_change(C, &bmain, nullptr);
+ ED_node_tree_propagate_change(&C, &bmain, nullptr);
DEG_relations_tag_update(&bmain);
return OPERATOR_FINISHED;
}
+// static int node_add_group_asset_exec(bContext *C, wmOperator *op)
+// {
+
+// PointerRNA asset_ptr = RNA_pointer_get(op->ptr, "asset_handle");
+// if (RNA_pointer_is_null(&asset_ptr)) {
+// return OPERATOR_CANCELLED;
+// }
+// PointerRNA library_ptr = RNA_pointer_get(op->ptr, "library_reference");
+// if (RNA_pointer_is_null(&library_ptr)) {
+// return OPERATOR_CANCELLED;
+// }
+// const AssetHandle asset = *static_cast<AssetHandle *>(asset_ptr.data);
+// const AssetLibraryReference &library = *static_cast<AssetLibraryReference
+// *>(library_ptr.data);
+// }
+
static int node_add_group_asset_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
ARegion ®ion = *CTX_wm_region(C);
SpaceNode &snode = *CTX_wm_space_node(C);
+ const AssetLibraryReference *library_ref = CTX_wm_asset_library_ref(C);
+ if (!library_ref) {
+ return OPERATOR_CANCELLED;
+ }
+ bool is_valid;
+ const AssetHandle handle = CTX_wm_asset_handle(C, &is_valid);
+ if (!is_valid) {
+ return OPERATOR_CANCELLED;
+ }
+
/* Convert mouse coordinates to v2d space. */
UI_view2d_region_to_view(®ion.v2d,
event
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list