11#include <fmt/format.h>
25 N_(
"Rename a single attribute with the provided attribute name")},
30 N_(
"Rename all attributes with the provided prefix")},
36 b.use_custom_socket_order();
37 b.allow_any_socket_order();
40 b.add_output<
decl::Geometry>(
"Geometry"_ustr).align_with_previous().propagate_all_geometry();
46 b.add_input<
decl::Bool>(
"Overwrite"_ustr).default_value(
false);
53 const std::string old_name = params.
extract_input<std::string>(
"Old"_ustr);
54 const std::string new_name = params.
extract_input<std::string>(
"New"_ustr);
55 const bool overwrite = params.
extract_input<
bool>(
"Overwrite"_ustr);
57 if (old_name.empty()) {
58 params.
set_output(
"Geometry"_ustr, std::move(geometry_set));
61 if (old_name == new_name) {
62 params.
set_output(
"Geometry"_ustr, std::move(geometry_set));
66 std::atomic<bool> not_found =
false;
70 for (
const auto type :
90 if (!attributes.
contains(old_name)) {
94 renames.
add_new(old_name, new_name);
116 std::scoped_lock
lock(failures_lock);
117 for (
const StringRef failed_name : failed) {
118 failures.
add_as(failed_name, renames.
lookup(failed_name));
126 fmt::format(
"{}: '{}'",
TIP_(
"Attribute not found"), old_name));
128 for (
const auto &[old_name, new_name] : failures.
items()) {
131 fmt::format(fmt::runtime(
"Failed to rename attribute: '{}' to '{}'"), old_name, new_name));
134 params.
set_output(
"Geometry"_ustr, std::move(geometry_set));
142 ntype.
ui_name =
"Rename Attribute";
#define NODE_CLASS_GEOMETRY
#define NOD_REGISTER_NODE(REGISTER_FUNC)
StringRefNull copy_string(StringRef str)
bool add(const Key &key, const Value &value)
const Value & lookup(const Key &key) const
bool add_as(ForwardKey &&key, ForwardValue &&...value)
void add_new(const Key &key, const Value &value)
ItemIterator items() const &
T & construct(Args &&...args)
LinearAllocator & allocator()
void foreach_attribute(const FunctionRef< void(const AttributeIter &)> fn) const
bool contains(StringRef name) const
virtual std::optional< AttributeAccessor > attributes() const
virtual std::optional< MutableAttributeAccessor > attributes_for_write()
bool rename(StringRef old_name, StringRef new_name, bool overwrite=false)
constexpr bool startswith(StringRef prefix) const
constexpr StringRef substr(int64_t start, int64_t size) const
void error_message_add(const NodeWarningType type, StringRef message) const
T extract_input(const UString identifier)
void set_output(const UString identifier, T &&value)
void node_register_type(bNodeType &ntype)
void foreach_real_geometry(bke::GeometrySet &geometry, FunctionRef< void(bke::GeometrySet &geometry_set)> fn)
const EnumPropertyItem rename_mode_items[]
static void node_register()
static void node_geo_exec(GeoNodeExecParams params)
static void node_declare(NodeDeclarationBuilder &b)
void geo_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
std::string ui_description
NodeGeometryExecFunction geometry_node_execute
NodeDeclareFunction declare