28#include "RNA_prototypes.hh"
47 b.use_custom_socket_order();
48 b.allow_any_socket_order();
52 if (
node ==
nullptr) {
58 StructureType value_structure_type = StructureType::Dynamic;
59 StructureType menu_structure_type = value_structure_type;
64 if (is_single_compositor_type) {
65 value_structure_type = StructureType::Single;
67 menu_structure_type = StructureType::Single;
70 b.add_output(data_type,
"Output"_ustr)
72 .inferred_structure_type()
73 .structure_type(value_structure_type);
75 b.add_default_layout();
80 storage.enum_definition.items().first().identifier));
81 menu.structure_type(menu_structure_type);
82 menu.optional_label();
85 const UString name(enum_item.name);
87 auto &input =
b.add_input(data_type, name, identifier)
91 .description(
"Becomes the output value if it is chosen by the menu input");
93 input.optional_label(
ELEM(data_type,
103 input.structure_type(value_structure_type);
105 .align_with_previous()
106 .
description(
"True if this item is chosen by the menu input")
107 .inferred_structure_type({menu.index()})
108 .propagate_references({menu.index()});
112 .structure_type(StructureType::Dynamic)
113 .custom_draw(socket_items::ui::draw_extend_socket_fn<MenuSwitchItemsAccessor>());
125 data->enum_definition.next_identifier = 0;
126 data->enum_definition.items_array =
nullptr;
127 data->enum_definition.items_num = 0;
144 dst_node->
storage = dst_storage;
178 mf::Signature signature_;
182 : enum_def_(enum_def), type_(type)
184 mf::SignatureBuilder builder{
"Menu Switch", signature_};
186 for (
const NodeEnumItem &enum_item : enum_def.items()) {
187 builder.single_input(enum_item.name, type);
189 builder.single_output(
"Output", type, mf::ParamFlag::SupportsUnusedOutput);
190 this->set_signature(&signature_);
195 const int value_inputs_start = 1;
196 const int inputs_num = enum_def_.items_num;
199 const int invalid_index = inputs_num;
201 GMutableSpan value_output = params.uninitialized_single_output_if_required(1 + inputs_num,
204 auto find_item_index = [&](
const MenuValue value) ->
int {
205 for (
const int i : enum_def_.items().index_range()) {
211 return invalid_index;
214 if (
const std::optional<MenuValue> value = values.
get_if_single()) {
215 const int index = find_item_index(*value);
216 if (
index < inputs_num) {
218 const GVArray inputs = params.readonly_single_input(value_inputs_start +
index);
224 type_.fill_construct_indices(type_.default_value(), value_output.
data(),
mask);
233 mask, memory, [&](
const int64_t i) {
return find_item_index(values[i]); }, masks);
235 for (
const int item_i :
IndexRange(inputs_num)) {
236 const IndexMask &mask_for_index = masks[item_i];
238 const GVArray inputs = params.readonly_single_input(value_inputs_start + item_i);
243 type_.fill_construct_indices(type_.default_value(), value_output.
data(), masks[invalid_index]);
248 static constexpr int8_t id = 0;
251 hash.add(&enum_def_);
258 mf::Signature signature_;
263 mf::SignatureBuilder builder{
"Menu Switch Bools", signature_};
265 for (
const NodeEnumItem &enum_item : enum_def.items()) {
266 builder.single_output(
267 enum_item.name, CPPType::get<bool>(), mf::ParamFlag::SupportsUnusedOutput);
269 this->set_signature(&signature_);
278 for (
const int item_i :
IndexRange(enum_def_.items_num)) {
279 item_spans[item_i] = params.uninitialized_single_output_if_required<
bool>(1 + item_i);
280 if (!item_spans[item_i].is_empty()) {
281 used_output_items.append(item_i);
285 if (
const std::optional<MenuValue> value = values.
get_if_single()) {
286 for (
const int item_i : used_output_items) {
287 const NodeEnumItem &enum_item = enum_def_.items()[item_i];
288 const bool is_selected = enum_item.
identifier == value->value;
294 mask.foreach_index([&](
const int i) {
296 for (
const int item_i : used_output_items) {
297 const NodeEnumItem &enum_item = enum_def_.items_array[item_i];
299 item_spans[item_i][i] = is_selected;
306 static constexpr int8_t id = 0;
308 hash.add(&enum_def_);
315 bool can_be_field_ =
false;
317 const CPPType *field_base_type_;
322 : node_(
node), enum_def_(node_storage(
node).enum_definition)
332 debug_name_ =
node.name;
333 lf_index_by_bsocket[
node.input_socket(0).index_in_tree()] = inputs_.append_and_get_index_as(
335 for (
const int i : enum_def_.items().index_range()) {
337 lf_index_by_bsocket[
node.input_socket(i + 1).index_in_tree()] =
338 inputs_.append_and_get_index_as(
341 lf_index_by_bsocket[
node.output_socket(0).index_in_tree()] = outputs_.append_and_get_index_as(
345 void execute_impl(lf::Params ¶ms,
const lf::Context & )
const override
358 bool output_was_set =
false;
359 for (
const int i :
IndexRange(enum_def_.items_num)) {
360 const NodeEnumItem &enum_item = enum_def_.items_array[i];
361 const int input_index = i + 1;
366 if (value_to_forward ==
nullptr) {
371 params.set_output(0, std::move(*value_to_forward));
372 output_was_set =
true;
375 params.set_input_unused(input_index);
378 if (!output_was_set) {
388 const int values_num = this->enum_def_.
items_num;
391 const int input_index = i + 1;
392 input_values[i] = params.try_get_input_data_ptr_or_request<
SocketValueVariant>(input_index);
394 if (input_values.
as_span().contains(
nullptr)) {
400 item_fields.
reserve(enum_def_.items_num + 1);
401 item_fields.append(std::move(
condition));
402 for (
const int i :
IndexRange(enum_def_.items_num)) {
405 std::unique_ptr<MultiFunction> multi_function = std::make_unique<MenuSwitchFn>(
406 enum_def_, *field_base_type_);
408 std::move(item_fields));
417 bool can_be_field_ =
false;
423 : enum_def_(node_storage(
node).enum_definition), fn_(enum_def_)
425 debug_name_ =
node.name;
430 lf_index_by_bsocket[
node.input_socket(0).index_in_tree()] = inputs_.append_and_get_index_as(
432 for (
const int i : enum_def_.items().index_range()) {
433 const NodeEnumItem &enum_item = enum_def_.items_array[i];
434 lf_index_by_bsocket[
node.output_socket(i + 1).index_in_tree()] =
439 void execute_impl(lf::Params ¶ms,
const lf::Context &context)
const override
450 for (
const int i :
IndexRange(enum_def_.items_num)) {
451 if (params.get_output_usage(i) != lf::ValueUsage::Unused) {
456 std::string error_message;
458 fn_, input_values, output_values, user_data, error_message))
462 for (
const int i :
IndexRange(enum_def_.items_num)) {
463 if (output_values[i]) {
464 params.output_set(i);
471 for (
const int i :
IndexRange(enum_def_.items_num)) {
472 const NodeEnumItem &enum_item = enum_def_.items_array[i];
489 : enum_def_(node_storage(
node).enum_definition)
493 for (
const int i :
IndexRange(enum_def_.items_num)) {
494 const NodeEnumItem &enum_item = enum_def_.items()[i];
495 outputs_.append_as(enum_item.name, CPPType::get<bool>());
499 void execute_impl(lf::Params ¶ms,
const lf::Context & )
const override
503 for (
const int i :
IndexRange(enum_def_.items_num)) {
504 params.set_output(i,
true);
509 for (
const int i :
IndexRange(enum_def_.items_num)) {
528 bool found_item =
false;
530 for (
const int i :
IndexRange(enum_definition.items_num)) {
531 const NodeEnumItem &enum_item = enum_definition.items()[i];
534 const bool is_selected = enum_item.
identifier == menu_identifier.
value;
568 socket_items::ui::draw_items_list_with_operators<MenuSwitchItemsAccessor>(
569 C, panel, tree,
node);
570 socket_items::ui::draw_active_item_props<MenuSwitchItemsAccessor>(
572 panel->use_property_split_set(
true);
573 panel->use_property_decorate_set(
false);
574 panel->prop(item_ptr,
"description",
UI_ITEM_NONE, std::nullopt, ICON_NONE);
605 if (
storage.enum_definition.items_num == 0) {
608 if (&output_socket ==
node.outputs.first_) {
610 return &
node.input_socket(1);
679 return std::make_unique<LazyFunctionForMenuSwitchNode>(
node, lf_graph_info);
687 return std::make_unique<LazyFunctionMenuSwitchBooleanOutputs>(
node, lf_graph_info);
694 return std::make_unique<LazyFunctionForMenuSwitchSocketUsage>(
node);
#define NODE_CLASS_CONVERTER
#define NODE_STORAGE_FUNCS(StorageT)
#define GEO_NODE_MENU_SWITCH
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define NOD_storage_enum_accessors(member)
__forceinline float extract(const int4 &b)
Span< T > as_span() const
static const CPPType & get()
void materialize_to_uninitialized(void *dst) const
static void from_groups(const IndexMask &universe, LinearAllocator<> &memory, Fn &&get_group_index, MutableSpan< IndexMask > r_masks)
constexpr IndexRange()=default
std::optional< T > get_if_single() const
bool is_context_dependent_field() const
NodeOperation(Context &context, const bNode &node)
const bNode & node() const
Result & get_result(StringRef identifier)
Result & get_input(StringRef identifier) const
void share_data(const Result &source)
bool should_compute() const
static bool is_single_value_only_type(ResultType type)
void set_single_value(const T &value)
void allocate_single_value()
const T & get_single_value() const
static FieldOperationPtr from(std::shared_ptr< const mf::MultiFunction > fn, Vector< GField > inputs)
void add_item(std::string socket_name, SocketLinkOperation::LinkSocketFn fn, int weight=0)
const bNodeSocket & other_socket() const
eNodeSocketInOut in_out() const
void update_and_connect_available_socket(bNode &new_node, UString socket_name)
bNode & add_node(UString idname)
SocketValueVariant()=default
static SocketValueVariant from(T &&value)
#define storage(slot, qualifiers)
void node_register_type(bNodeType &ntype)
bNodeSocketType * node_socket_type_find_static(int type, int subtype=0)
void node_type_storage(bNodeType &ntype, std::optional< StringRefNull > storagename, void(*freefunc)(bNode *node), void(*copyfunc)(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node))
ResultType socket_data_type_to_result_type(const eNodeSocketDatatype data_type, const std::optional< int > dimensions=std::nullopt)
internal::ShallowDataConstRef< T > shallow_copy(const T &other)
ImplicitSharingPtr< FieldOperation > FieldOperationPtr
void masked_fill(MutableSpan< T > data, const T &value, const IndexMask &mask)
void make_common_operators()
void blend_write(BlendWriter *writer, const bNode &node)
Accessor::ItemT * add_item_with_name(bNode &node, const char *name)
void destruct_array(bNode &node)
void blend_read_data(BlendDataReader *reader, bNode &node)
void copy_array(const bNode &src_node, bNode &dst_node)
bool try_add_item_via_any_extend_socket(bNodeTree &ntree, bNode &extend_node, bNode &storage_node, bNodeLink &link, const std::optional< StringRef > socket_identifier=std::nullopt, typename Accessor::ItemT **r_new_item=nullptr)
PropertyRNA * RNA_def_node_enum(StructRNA *srna, const char *identifier, const char *ui_name, const char *ui_description, const EnumPropertyItem *static_items, const EnumRNAAccessors accessors, std::optional< int > default_value, const EnumPropertyItemFunc item_func, const bool allow_animation)
std::unique_ptr< LazyFunction > get_menu_switch_node_socket_usage_lazy_function(const bNode &node)
bool execute_multi_function_on_value_variant(const MultiFunction &fn, const std::shared_ptr< MultiFunction > &owned_fn, const Span< SocketValueVariant * > input_values, const Span< SocketValueVariant * > output_values, GeoNodesUserData *user_data, std::string &r_error_message)
bool socket_type_supports_fields(const eNodeSocketDatatype socket_type)
std::unique_ptr< LazyFunction > get_menu_switch_node_boolean_outputs_lazy_function(const bNode &node, GeometryNodesLazyFunctionGraphInfo &lf_graph_info)
void set_default_value_for_output_socket(lf::Params ¶ms, const int lf_index, const bNodeSocket &bsocket)
std::unique_ptr< LazyFunction > get_menu_switch_node_lazy_function(const bNode &node, GeometryNodesLazyFunctionGraphInfo &lf_graph_info)
const EnumPropertyItem * enum_items_filter(const EnumPropertyItem *original_item_array, FunctionRef< bool(const EnumPropertyItem &item)> fn)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
BMesh const char void * data
const EnumPropertyItem rna_enum_node_socket_data_type_items[]
void BLO_read_string(BlendDataReader *reader, char **ptr_p)
void common_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
void write_string(const char *data)
bke::bNodeTreeType * typeinfo
const CPPType * base_cpp_type
bool(*) valid_socket_type(bNodeTreeType *ntreetype, bNodeSocketType *socket_type)
NodeInternallyLinkedInputFunction internally_linked_input
void(*) draw_buttons(ui::Layout &, bContext *C, PointerRNA *ptr)
NodeBlendWriteFunction blend_write_storage_content
void(*) register_operators()
std::string ui_description
NodeBlendDataReadFunction blend_data_read_storage_content
NodeGetCompositorOperationFunction get_compositor_operation
void(*) draw_buttons_ex(ui::Layout &, bContext *C, PointerRNA *ptr)
void(*) initfunc(bNodeTree *ntree, bNode *node)
const char * enum_name_legacy
NodeGatherSocketLinkOperationsFunction gather_link_search_ops
NodeDeclareFunction declare
bool ignore_inferred_input_socket_visibility
bool(*) insert_link(NodeInsertLinkParams ¶ms)
Array< int > lf_index_by_bsocket
GeometryNodeLazyFunctionGraphMapping mapping
PanelLayout panel(const bContext *C, StringRef idname, bool default_closed)
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< StringRef > name_opt, int icon, std::optional< StringRef > placeholder=std::nullopt)
void reserve(int new_size)