Blender V5.0
NOD_geo_repeat.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2024 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
11namespace blender::nodes {
12
20 static int node_type;
21 static constexpr StringRefNull node_idname = "GeometryNodeRepeatOutput";
22 static constexpr bool has_type = true;
23 static constexpr bool has_name = true;
25 static constexpr StringRefNull add_item = "NODE_OT_repeat_zone_item_add";
26 static constexpr StringRefNull remove_item = "NODE_OT_repeat_zone_item_remove";
27 static constexpr StringRefNull move_item = "NODE_OT_repeat_zone_item_move";
28 };
29 struct ui_idnames {
30 static constexpr StringRefNull list = "DATA_UL_repeat_zone_state";
31 };
32 struct rna_names {
33 static constexpr StringRefNull items = "repeat_items";
34 static constexpr StringRefNull active_index = "active_index";
35 };
36
38 {
39 auto *storage = static_cast<NodeGeometryRepeatOutput *>(node.storage);
40 return {&storage->items, &storage->items_num, &storage->active_index};
41 }
42
43 static void copy_item(const NodeRepeatItem &src, NodeRepeatItem &dst)
44 {
45 dst = src;
46 dst.name = BLI_strdup_null(dst.name);
47 }
48
49 static void destruct_item(NodeRepeatItem *item)
50 {
51 MEM_SAFE_FREE(item->name);
52 }
53
54 static void blend_write_item(BlendWriter *writer, const ItemT &item);
55 static void blend_read_data_item(BlendDataReader *reader, ItemT &item);
56
61
62 static char **get_name(NodeRepeatItem &item)
63 {
64 return &item.name;
65 }
66
67 static bool supports_socket_type(const eNodeSocketDatatype socket_type, const int ntree_type)
68 {
69 switch (ntree_type) {
70 case NTREE_GEOMETRY:
71 return ELEM(socket_type,
87 case NTREE_SHADER:
88 return ELEM(socket_type,
95 SOCK_INT);
96 default:
97 return false;
98 }
99 }
100
102 NodeRepeatItem &item,
103 const eNodeSocketDatatype socket_type,
104 const char *name)
105 {
106 auto *storage = static_cast<NodeGeometryRepeatOutput *>(node.storage);
107 item.socket_type = socket_type;
108 item.identifier = storage->next_identifier++;
110 }
111
112 static std::string socket_identifier_for_item(const NodeRepeatItem &item)
113 {
114 return "Item_" + std::to_string(item.identifier);
115 }
116};
117
118} // namespace blender::nodes
char * BLI_strdup_null(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_MALLOC
Definition string.cc:46
#define ELEM(...)
@ NTREE_SHADER
@ NTREE_GEOMETRY
eNodeSocketDatatype
@ SOCK_INT
@ SOCK_VECTOR
@ SOCK_CLOSURE
@ SOCK_BOOLEAN
@ SOCK_MATERIAL
@ SOCK_SHADER
@ SOCK_MATRIX
@ SOCK_FLOAT
@ SOCK_IMAGE
@ SOCK_COLLECTION
@ SOCK_BUNDLE
@ SOCK_GEOMETRY
@ SOCK_ROTATION
@ SOCK_OBJECT
@ SOCK_STRING
@ SOCK_RGBA
#define MEM_SAFE_FREE(v)
void set_item_name_and_make_unique(bNode &node, typename Accessor::ItemT &item, const char *value)
const char * name
void * storage
static constexpr StringRefNull active_index
static void init_with_socket_type_and_name(bNode &node, NodeRepeatItem &item, const eNodeSocketDatatype socket_type, const char *name)
static void blend_write_item(BlendWriter *writer, const ItemT &item)
static socket_items::SocketItemsRef< NodeRepeatItem > get_items_from_node(bNode &node)
static char ** get_name(NodeRepeatItem &item)
static constexpr StringRefNull node_idname
static void copy_item(const NodeRepeatItem &src, NodeRepeatItem &dst)
static bool supports_socket_type(const eNodeSocketDatatype socket_type, const int ntree_type)
static eNodeSocketDatatype get_socket_type(const NodeRepeatItem &item)
static void blend_read_data_item(BlendDataReader *reader, ItemT &item)
static void destruct_item(NodeRepeatItem *item)
static std::string socket_identifier_for_item(const NodeRepeatItem &item)