Blender V5.3
NOD_geo_viewer.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2025 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
7#include "DNA_node_types.h"
8
9#include "NOD_eval_log.hh"
10#include "NOD_socket_items.hh"
11
12namespace blender::nodes {
13
21 static int node_type;
22 static constexpr StringRefNull node_idname = "GeometryNodeViewer";
23 static constexpr bool has_type = true;
24 static constexpr bool has_name = true;
26 static constexpr StringRefNull add_item = "NODE_OT_geometry_nodes_viewer_item_add";
27 static constexpr StringRefNull remove_item = "NODE_OT_geometry_nodes_viewer_item_remove";
28 static constexpr StringRefNull move_item = "NODE_OT_geometry_nodes_viewer_item_move";
29 };
30 struct ui_idnames {
31 static constexpr StringRefNull list = "NODE_UL_geometry_nodes_viewer_items";
32 };
33 struct rna_names {
34 static constexpr StringRefNull items = "viewer_items";
35 static constexpr StringRefNull active_index = "active_index";
36 };
37
39 {
40 auto *storage = static_cast<NodeGeometryViewer *>(node.storage);
41 return {&storage->items, &storage->items_num, &storage->active_index};
42 }
43
45 {
46 dst = src;
47 dst.name = BLI_strdup_null(dst.name);
48 }
49
51 {
52 MEM_SAFE_DELETE(item->name);
53 }
54
55 static void blend_write_item(BlendWriter *writer, const ItemT &item);
56 static void blend_read_data_item(BlendDataReader *reader, ItemT &item);
57
59 {
60 return item.socket_type;
61 }
62
63 static char **get_name(NodeGeometryViewerItem &item)
64 {
65 return &item.name;
66 }
67
70 const eNodeSocketDatatype socket_type,
71 const char *name)
72 {
73 auto *storage = static_cast<NodeGeometryViewer *>(node.storage);
74 item.socket_type = socket_type;
75 item.identifier = storage->next_identifier++;
77 }
78
79 static bool supports_socket_type(const eNodeSocketDatatype socket_type, const int ntree_type)
80 {
81 return bke::node_tree_type_supports_socket_type_static(ntree_type, socket_type);
82 }
83
84 static std::string socket_identifier_for_item(const NodeGeometryViewerItem &item)
85 {
86 /* These special cases exist for compatibility with older Blender versions when the viewer did
87 * not have a dynamic number of inputs yet. */
88 if (item.identifier == 0 && item.socket_type == SOCK_GEOMETRY) {
89 return "Geometry";
90 }
91 if (item.identifier == 1 && item.socket_type != SOCK_GEOMETRY) {
92 return "Value";
93 }
94 return "Item_" + std::to_string(item.identifier);
95 }
96};
97
99 const Span<bke::SocketValueVariant *> input_values,
101
102} // namespace blender::nodes
#define storage(slot, qualifiers)
bool node_tree_type_supports_socket_type_static(const int ntree_type, const eNodeSocketDatatype socket_type)
Definition node.cc:6295
void set_item_name_and_make_unique(bNode &node, typename Accessor::ItemT &item, const char *value)
void geo_viewer_node_log(const bNode &node, const Span< bke::SocketValueVariant * > input_values, eval_log::ViewerNodeLog &r_log)
char * BLI_strdup_null(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_MALLOC
static void blend_read_data_item(BlendDataReader *reader, ItemT &item)
static void copy_item(const NodeGeometryViewerItem &src, NodeGeometryViewerItem &dst)
static std::string socket_identifier_for_item(const NodeGeometryViewerItem &item)
static void destruct_item(NodeGeometryViewerItem *item)
static socket_items::SocketItemsRef< NodeGeometryViewerItem > get_items_from_node(bNode &node)
static eNodeSocketDatatype get_socket_type(const NodeGeometryViewerItem &item)
static bool supports_socket_type(const eNodeSocketDatatype socket_type, const int ntree_type)
static constexpr StringRefNull node_idname
static void blend_write_item(BlendWriter *writer, const ItemT &item)
static void init_with_socket_type_and_name(bNode &node, NodeGeometryViewerItem &item, const eNodeSocketDatatype socket_type, const char *name)
static char ** get_name(NodeGeometryViewerItem &item)