Blender V5.0
NOD_geo_capture_attribute.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 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_socket_items.hh"
10
11#include "BKE_customdata.hh"
12
13namespace blender::nodes {
14
18 static int node_type;
19 static constexpr StringRefNull node_idname = "GeometryNodeCaptureAttribute";
20 static constexpr bool has_type = true;
21 static constexpr bool has_name = true;
22 static constexpr bool has_single_identifier_str = false;
24 static constexpr StringRefNull add_item = "NODE_OT_capture_attribute_item_add";
25 static constexpr StringRefNull remove_item = "NODE_OT_capture_attribute_item_remove";
26 static constexpr StringRefNull move_item = "NODE_OT_capture_attribute_item_move";
27 };
28 struct ui_idnames {
29 static constexpr StringRefNull list = "NODE_UL_capture_items_list";
30 };
31 struct rna_names {
32 static constexpr StringRefNull items = "capture_items";
33 static constexpr StringRefNull active_index = "active_index";
34 };
35
37 bNode &node)
38 {
39 auto *storage = static_cast<NodeGeometryAttributeCapture *>(node.storage);
40 return {&storage->capture_items, &storage->capture_items_num, &storage->active_index};
41 }
42
45 {
46 dst = src;
47 dst.name = BLI_strdup_null(dst.name);
48 }
49
51 {
52 MEM_SAFE_FREE(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
62
64 {
65 return &item.name;
66 }
67
68 static bool supports_socket_type(const eNodeSocketDatatype socket_type, const int /*ntree_type*/)
69 {
70 return bke::socket_type_to_custom_data_type(socket_type).has_value() &&
71 socket_type != SOCK_STRING;
72 }
73
76 const eNodeSocketDatatype socket_type,
77 const char *name)
78 {
79 auto *storage = static_cast<NodeGeometryAttributeCapture *>(node.storage);
81 item.identifier = storage->next_identifier++;
83 }
84
86 {
87 if (item.identifier == 0) {
88 /* This special case exists for compatibility. */
89 return "Value";
90 }
91 return "Value_" + std::to_string(item.identifier);
92 }
93
96 {
97 if (item.identifier == 0) {
98 /* This special case exists for compatibility. */
99 return "Attribute";
100 }
101 return "Attribute_" + std::to_string(item.identifier);
102 }
103};
104
105} // namespace blender::nodes
CustomData interface, see also DNA_customdata_types.h.
char * BLI_strdup_null(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_MALLOC
Definition string.cc:46
eNodeSocketDatatype
@ SOCK_STRING
#define MEM_SAFE_FREE(v)
std::optional< eNodeSocketDatatype > custom_data_type_to_socket_type(eCustomDataType type)
Definition node.cc:5168
std::optional< eCustomDataType > socket_type_to_custom_data_type(eNodeSocketDatatype type)
Definition node.cc:5144
void set_item_name_and_make_unique(bNode &node, typename Accessor::ItemT &item, const char *value)
const char * name
void * storage
static char ** get_name(NodeGeometryAttributeCaptureItem &item)
static void copy_item(const NodeGeometryAttributeCaptureItem &src, NodeGeometryAttributeCaptureItem &dst)
static eNodeSocketDatatype get_socket_type(const NodeGeometryAttributeCaptureItem &item)
static std::string input_socket_identifier_for_item(const NodeGeometryAttributeCaptureItem &item)
static void blend_read_data_item(BlendDataReader *reader, ItemT &item)
static socket_items::SocketItemsRef< NodeGeometryAttributeCaptureItem > get_items_from_node(bNode &node)
static bool supports_socket_type(const eNodeSocketDatatype socket_type, const int)
static void init_with_socket_type_and_name(bNode &node, NodeGeometryAttributeCaptureItem &item, const eNodeSocketDatatype socket_type, const char *name)
static void destruct_item(NodeGeometryAttributeCaptureItem *item)
static std::string output_socket_identifier_for_item(const NodeGeometryAttributeCaptureItem &item)
static void blend_write_item(BlendWriter *writer, const ItemT &item)