Blender V5.0
node_geo_list_length.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2025 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
6#include "NOD_rna_define.hh"
7#include "NOD_socket.hh"
9
10#include "RNA_enum_types.hh"
11
13#include "UI_resources.hh"
14
15#include "node_geometry_util.hh"
16
18
20{
21 const bNode *node = b.node_or_null();
22
23 if (node != nullptr) {
25 b.add_input(type, "List").structure_type(StructureType::List).hide_value();
26 }
27
28 b.add_output<decl::Int>("Length");
29}
30
31static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
32{
33 layout->prop(ptr, "data_type", UI_ITEM_NONE, "", ICON_NONE);
34}
35
37 public:
41 {
42 bNode &node = params.add_node("GeometryNodeListLength");
43 node.custom1 = socket_type;
44 params.update_and_connect_available_socket(node, socket_name);
45 }
46};
47
49{
50 if (!U.experimental.use_geometry_nodes_lists) {
51 return;
52 }
53 const eNodeSocketDatatype socket_type = eNodeSocketDatatype(params.other_socket().type);
54 if (params.in_out() == SOCK_IN) {
55 params.add_item(IFACE_("List"), SocketSearchOp{"List", socket_type});
56 }
57 else {
58 if (params.node_tree().typeinfo->validate_link(socket_type, SOCK_INT)) {
59 params.add_item(IFACE_("Length"), SocketSearchOp{"Length", SOCK_INT});
60 }
61 }
62}
63
65{
66 ListPtr list = params.extract_input<ListPtr>("List");
67 if (!list) {
68 params.set_default_remaining_outputs();
69 return;
70 }
71 params.set_output("Length", int(list->size()));
72}
73
74static void node_rna(StructRNA *srna)
75{
77 srna,
78 "data_type",
79 "Data Type",
80 "",
84 [](bContext * /*C*/, PointerRNA * /*ptr*/, PropertyRNA * /*prop*/, bool *r_free) {
85 *r_free = true;
86 return enum_items_filter(
89 });
90 });
91}
92
93static void node_register()
94{
95 static blender::bke::bNodeType ntype;
96 geo_node_type_base(&ntype, "GeometryNodeListLength");
97 ntype.ui_name = "List Length";
98 ntype.ui_description = "Count how many items are in a given list";
101 ntype.declare = node_declare;
105 node_rna(ntype.rna_ext.srna);
106}
108
109} // namespace blender::nodes::node_geo_list_length_cc
#define NODE_CLASS_CONVERTER
Definition BKE_node.hh:453
#define IFACE_(msgid)
@ SOCK_IN
eNodeSocketDatatype
@ SOCK_INT
@ SOCK_GEOMETRY
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define NOD_inline_enum_accessors(member)
#define UI_ITEM_NONE
#define U
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void node_register_type(bNodeType &ntype)
Definition node.cc:2416
static void node_gather_link_searches(GatherLinkSearchOpParams &params)
static void node_layout(uiLayout *layout, bContext *, PointerRNA *ptr)
static void node_geo_exec(GeoNodeExecParams params)
static void node_declare(NodeDeclarationBuilder &b)
PropertyRNA * RNA_def_node_enum(StructRNA *srna, const char *identifier, const char *ui_name, const char *ui_description, const EnumPropertyItem *static_items, const EnumRNAAccessors accessors, std::optional< int > default_value, const EnumPropertyItemFunc item_func, const bool allow_animation)
ImplicitSharingPtr< List > ListPtr
bool socket_type_supports_fields(const eNodeSocketDatatype socket_type)
const EnumPropertyItem * enum_items_filter(const EnumPropertyItem *original_item_array, FunctionRef< bool(const EnumPropertyItem &item)> fn)
void geo_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
const EnumPropertyItem rna_enum_node_socket_data_type_items[]
StructRNA * srna
int16_t custom1
Defines a node type.
Definition BKE_node.hh:238
std::string ui_description
Definition BKE_node.hh:244
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:354
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:259
NodeGatherSocketLinkOperationsFunction gather_link_search_ops
Definition BKE_node.hh:378
NodeDeclareFunction declare
Definition BKE_node.hh:362
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< blender::StringRef > name_opt, int icon, std::optional< blender::StringRef > placeholder=std::nullopt)
PointerRNA * ptr
Definition wm_files.cc:4238