Blender V4.3
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 const char *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;
23
25 bNode &node)
26 {
27 auto *storage = static_cast<NodeGeometryAttributeCapture *>(node.storage);
28 return {&storage->capture_items, &storage->capture_items_num, &storage->active_index};
29 }
30
33 {
34 dst = src;
35 dst.name = BLI_strdup_null(dst.name);
36 }
37
39 {
40 MEM_SAFE_FREE(item->name);
41 }
42
43 static void blend_write(BlendWriter *writer, const bNode &node);
44 static void blend_read_data(BlendDataReader *reader, bNode &node);
45
50
52 {
53 return &item.name;
54 }
55
56 static bool supports_socket_type(const eNodeSocketDatatype socket_type)
57 {
58 return bke::socket_type_to_custom_data_type(socket_type).has_value() &&
59 socket_type != SOCK_STRING;
60 }
61
64 const eNodeSocketDatatype socket_type,
65 const char *name)
66 {
67 auto *storage = static_cast<NodeGeometryAttributeCapture *>(node.storage);
69 item.identifier = storage->next_identifier++;
71 }
72
74 {
75 if (item.identifier == 0) {
76 /* This special case exists for compatibility. */
77 return "Value";
78 }
79 return "Value_" + std::to_string(item.identifier);
80 }
81
84 {
85 if (item.identifier == 0) {
86 /* This special case exists for compatibility. */
87 return "Attribute";
88 }
89 return "Attribute_" + std::to_string(item.identifier);
90 }
91};
92
93} // 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.c:45
eNodeSocketDatatype
@ SOCK_STRING
struct NodeGeometryAttributeCaptureItem NodeGeometryAttributeCaptureItem
#define MEM_SAFE_FREE(v)
std::optional< eNodeSocketDatatype > custom_data_type_to_socket_type(eCustomDataType type)
Definition node.cc:4403
std::optional< eCustomDataType > socket_type_to_custom_data_type(eNodeSocketDatatype type)
Definition node.cc:4379
void set_item_name_and_make_unique(bNode &node, typename Accessor::ItemT &item, const char *value)
NodeGeometryAttributeCaptureItem * capture_items
static char ** get_name(NodeGeometryAttributeCaptureItem &item)
static void copy_item(const NodeGeometryAttributeCaptureItem &src, NodeGeometryAttributeCaptureItem &dst)
static bool supports_socket_type(const eNodeSocketDatatype socket_type)
static eNodeSocketDatatype get_socket_type(const NodeGeometryAttributeCaptureItem &item)
static std::string input_socket_identifier_for_item(const NodeGeometryAttributeCaptureItem &item)
static socket_items::SocketItemsRef< NodeGeometryAttributeCaptureItem > get_items_from_node(bNode &node)
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 void blend_read_data(BlendDataReader *reader, bNode &node)
static std::string output_socket_identifier_for_item(const NodeGeometryAttributeCaptureItem &item)
static void blend_write(BlendWriter *writer, const bNode &node)