Blender V5.3
node_geo_get_nested_bundle_paths.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2026 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#include "NOD_geo_bundle.hh"
9
10#include "RNA_enum_types.hh"
11
12#include "UI_resources.hh"
13
14#include "node_geometry_util.hh"
15
17
18enum class Mode {
19 All = 0,
22};
23
24static const EnumPropertyItem mode_items[] = {
25 {int(Mode::All), "ALL", ICON_NONE, "All", "Output all paths"},
26 {int(Mode::BundleType),
27 "BUNDLE_TYPE",
28 ICON_NONE,
29 N_("Bundle Type"),
30 N_("Find paths to bundles of a specific type")},
31 {int(Mode::DataType),
32 "DATA_TYPE",
33 ICON_NONE,
34 N_("Data Type"),
35 N_("Find paths to values of a specific data type")},
36 {0},
37};
38
40{
41 b.add_input<decl::Bundle>("Bundle"_ustr);
42 b.add_input<decl::Menu>("Mode"_ustr).static_items(mode_items).optional_label();
43 b.add_input<decl::Menu>("Pattern Mode"_ustr)
44 .static_items(string_pattern_mode_items)
46 .usage_by_menu("Mode"_ustr, int(Mode::BundleType));
47 b.add_input<decl::String>("Bundle Type"_ustr)
48 .optional_label()
49 .usage_by_menu("Mode"_ustr, int(Mode::BundleType));
50 b.add_input<decl::Menu>("Data Type"_ustr)
52 [](const EnumPropertyItem &item) {
55 })
56 .optional_label()
57 .usage_by_menu("Mode"_ustr, int(Mode::DataType));
58 b.add_output<decl::String>("Paths"_ustr).structure_type(StructureType::List);
59}
60
62{
63 BundlePtr bundle_ptr = params.extract_input<BundlePtr>("Bundle"_ustr);
64 const Mode mode = params.extract_input<Mode>("Mode"_ustr);
65 if (!bundle_ptr) {
67 return;
68 }
69 const Bundle &bundle = *bundle_ptr;
70
72 switch (mode) {
73 case Mode::All: {
75 bundle, [&](const Span<BundleKey> path, const BundleItemValue & /*value*/) {
76 paths.append(Bundle::combine_path(path));
77 });
78 break;
79 }
80 case Mode::BundleType: {
81 const std::string type_pattern = params.extract_input<std::string>("Bundle Type"_ustr);
82 const StringPatternMode pattern_mode = params.extract_input<StringPatternMode>(
83 "Pattern Mode"_ustr);
84 std::string pattern_error;
85 std::optional<StringPattern> pattern_fn = StringPattern::from_str(
86 pattern_mode, type_pattern, pattern_error);
87 if (!pattern_fn) {
88 params.error_message_add(NodeWarningType::Error, pattern_error);
89 break;
90 }
91 if (!type_pattern.empty()) {
93 bundle, [&](const StringRef type) { return pattern_fn->match(type); });
94 }
95 break;
96 }
97 case Mode::DataType:
99 "Data Type"_ustr);
100 paths = gather_bundle_paths_by_data_type(bundle, data_type);
101 break;
102 }
103
104 /* Make sure the order is deterministic and doesn't depend on hash tables in the bundle. */
105 std::ranges::sort(paths);
106
107 params.set_output("Paths"_ustr, GList::from_container(std::move(paths)));
108}
109
110static void node_register()
111{
112 static bke::bNodeType ntype;
113
114 geo_node_type_base(&ntype, "NodeGetNestedBundlePaths"_ustr);
115 ntype.ui_name = "Get Nested Bundle Paths";
116 ntype.ui_description = "Get paths to items in a nested bundle with a filter";
119 ntype.declare = node_declare;
122}
124
125} // namespace blender::nodes::node_geo_get_nested_bundle_paths_cc
#define NODE_CLASS_CONVERTER
Definition BKE_node.hh:484
#define NOD_REGISTER_NODE(REGISTER_FUNC)
void append(const T &value)
static std::string combine_path(Span< StringRef > path)
static GListPtr from_container(ContainerT &&container)
void error_message_add(const NodeWarningType type, StringRef message) const
T extract_input(const UString identifier)
void set_output(const UString identifier, T &&value)
static std::optional< StringPattern > from_str(StringPatternMode mode, StringRef pattern, std::string &r_error)
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
const EnumPropertyItem string_pattern_mode_items[]
Vector< std::string > gather_bundle_paths_by_bundle_type(const Bundle &bundle, const FunctionRef< bool(StringRef type)> type_filter_fn)
bool socket_type_supported_in_bundle(const eNodeSocketDatatype socket_type, const int ntree_type)
Vector< std::string > gather_bundle_paths_by_data_type(const Bundle &bundle, const eNodeSocketDatatype data_type)
void foreach_nested_bundle_item(const Bundle &bundle, const FunctionRef< void(Span< BundleKey >, const BundleItemValue &value)> fn)
ImplicitSharingPtr< Bundle > BundlePtr
const EnumPropertyItem rna_enum_node_socket_data_type_items[]
void geo_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
static constexpr int _180
Definition BKE_node.hh:247
Defines a node type.
Definition BKE_node.hh:265
std::string ui_description
Definition BKE_node.hh:271
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:385
NodeDeclareFunction declare
Definition BKE_node.hh:393
#define N_(msgid)