23#include "RNA_prototypes.hh"
44 if (!params.menu_switch_source_by_index_switch) {
45 params.draw_standard(params.layout);
48 const bNode *menu_switch_node = params.menu_switch_source_by_index_switch->lookup_default(
49 ¶ms.node,
nullptr);
50 if (!menu_switch_node) {
51 params.draw_standard(params.layout);
54 const auto &menu_switch_storage = *
static_cast<const NodeMenuSwitch *
>(
55 menu_switch_node->storage);
58 for (
const int i :
IndexRange(menu_switch_storage.enum_definition.items_num)) {
59 const NodeEnumItem &item = menu_switch_storage.enum_definition.items_array[i];
60 const bNodeSocket &menu_switch_input_socket = menu_switch_node->input_socket(1 + i);
61 if (menu_switch_input_socket.is_directly_linked()) {
62 params.draw_standard(params.layout);
67 if (menu_switch_input_socket_value.value ==
index) {
70 params.draw_standard(params.layout);
77 params.draw_standard(params.layout);
80 const std::string label = fmt::format(
"{}: {}",
index, found_item->
name);
81 params.draw_standard(params.layout, label);
96 StructureType value_structure_type = StructureType::Dynamic;
97 StructureType index_structure_type = value_structure_type;
102 if (is_single_compositor_type) {
103 value_structure_type = StructureType::Single;
105 index_structure_type = StructureType::Single;
110 b.add_input<
decl::Int>(
"Index"_ustr).
min(0).max(std::max<int>(0, items.
size() - 1));
111 if (supports_fields) {
112 index.structure_type(index_structure_type);
117 auto &input =
b.add_input(data_type,
UString(std::to_string(i)),
UString(identifier));
121 input.optional_label(
ELEM(data_type,
131 input.structure_type(value_structure_type);
137 b.add_output(data_type,
"Output"_ustr)
139 .inferred_structure_type()
140 .structure_type(value_structure_type);
143 .custom_draw(socket_items::ui::draw_extend_socket_fn<IndexSwitchItemsAccessor>());
157 panel->op(
"node.index_switch_item_add",
IFACE_(
"Add Item"), ICON_ADD);
161 row->
label(
node.input_socket(i + 1).name, ICON_NONE);
162 PointerRNA op_ptr = row->
op(
"node.index_switch_item_remove",
"", ICON_REMOVE);
179 data->next_identifier = 0;
182 const int default_items_num = 2;
183 data->items = MEM_new_array<IndexSwitchItem>(default_items_num, __func__);
184 for (
const int i :
IndexRange(default_items_num)) {
185 data->items[i].identifier =
data->next_identifier++;
187 data->items_num = default_items_num;
203 int value_weight = 0;
233 mf::Signature signature_;
239 mf::SignatureBuilder builder{
"Index Switch", signature_};
240 builder.single_input<
int>(
"Index");
241 debug_names_.reinitialize(items_num);
243 debug_names_[i] = std::to_string(i);
244 builder.single_input(debug_names_[i].c_str(), type);
246 builder.single_output(
"Output", type);
252 const int inputs_num = signature_.params.size() - 2;
253 const VArray<int> indices = params.readonly_single_input<
int>(0,
"Index");
256 signature_.params.index_range().last(),
"Output");
271 const int invalid_index = inputs_num;
278 const int index = indices[i];
284 if (!masks[i].is_empty()) {
304 bool can_be_field_ =
false;
305 const CPPType *field_base_type_;
318 debug_name_ =
node.name;
324 lf_index_by_bsocket[index_socket.index_in_tree()] = inputs_.append_and_get_index_as(
326 lf_index_by_bsocket[output_socket.index_in_tree()] = outputs_.append_and_get_index_as(
329 for (
const int i :
storage.items_span().index_range()) {
331 lf_index_by_bsocket[input.index_in_tree()] = inputs_.append_and_get_index_as(
332 input.
identifier, cpp_type, lf::ValueUsage::Maybe);
336 void execute_impl(lf::Params ¶ms,
const lf::Context & )
const override
369 if (value_to_forward ==
nullptr) {
373 const CPPType &type = *outputs_[0].type;
374 void *output_ptr = params.get_output_data_ptr(0);
376 params.output_set(0);
387 if (input_values.
as_span().contains(
nullptr)) {
397 std::unique_ptr<mf::MultiFunction> switch_fn = std::make_unique<IndexSwitchFunction>(
401 void *output_ptr = params.get_output_data_ptr(0);
403 params.output_set(0);
420 output.allocate_invalid();
472 auto *dst_storage = MEM_new<NodeIndexSwitch>(__func__,
dna::shallow_copy(src_storage));
473 dst_node->
storage = dst_storage;
503 return &
node.input_socket(1);
511 ntype.
ui_name =
"Index Switch";
512 ntype.
ui_description =
"Choose between an arbitrary number of values with an index";
543 return std::make_unique<LazyFunctionForIndexSwitchNode>(
node, lf_graph_info);
#define NODE_CLASS_CONVERTER
#define NODE_STORAGE_FUNCS(StorageT)
#define GEO_NODE_INDEX_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 fill_construct_indices(const void *value, void *dst, const IndexMask &mask) const
const void * default_value() const
void move_construct(void *src, void *dst) const
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
constexpr MutableSpan()=default
constexpr int64_t size() const
constexpr IndexRange index_range() const
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
static bool is_single_value_only_type(ResultType type)
T get_single_value_default() const
void set_signature(const Signature *signature)
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 bNodeTree & node_tree() const
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)
static SocketValueVariant & construct_in(void *ptr, T &&value)
IndexSwitchFunction(const CPPType &type, const int items_num)
ExecutionHints get_execution_hints() const override
void call(const IndexMask &mask, mf::Params params, mf::Context) const override
NodeOperation(Context &context, const bNode &node)
void execute_single(const int index, lf::Params ¶ms) const
void execute_field(Field< int > index, lf::Params ¶ms) const
LazyFunctionForIndexSwitchNode(const bNode &node, GeometryNodesLazyFunctionGraphInfo &lf_graph_info)
void execute_impl(lf::Params ¶ms, const lf::Context &) const override
#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)
static void node_copy_storage(bNodeTree *, bNode *dst_node, const bNode *src_node)
static void node_layout_ex(ui::Layout &layout, bContext *C, PointerRNA *ptr)
static void node_blend_read(bNodeTree &, bNode &node, BlendDataReader &reader)
static void node_layout(ui::Layout &layout, bContext *, PointerRNA *ptr)
static void node_gather_link_searches(GatherLinkSearchOpParams ¶ms)
static bool node_insert_link(bke::NodeInsertLinkParams ¶ms)
static void node_declare(NodeDeclarationBuilder &b)
static void register_node()
static void node_rna(StructRNA *srna)
static void node_operators()
static void node_blend_write(const bNodeTree &, const bNode &node, BlendWriter &writer)
constexpr int value_inputs_start
static void node_init(bNodeTree *tree, bNode *node)
static void draw_item_socket(CustomSocketDrawParams ¶ms, const int index)
static const EnumPropertyItem * data_type_items_callback(bContext *, PointerRNA *ptr, PropertyRNA *, bool *r_free)
static void node_free_storage(bNode *node)
static const bNodeSocket * node_internally_linked_input(const bNodeTree &, const bNode &node, const bNodeSocket &)
static NodeOperation * get_compositor_operation(Context &context, const bNode &node)
void make_add_item_operator()
void make_remove_item_by_index_operator()
void make_move_item_operator()
void blend_write(BlendWriter *writer, const bNode &node)
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)
std::unique_ptr< LazyFunction > get_index_switch_node_lazy_function(const bNode &node, GeometryNodesLazyFunctionGraphInfo &lf_graph_info)
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)
bool socket_type_supports_fields(const eNodeSocketDatatype socket_type)
void set_default_remaining_node_outputs(lf::Params ¶ms, const bNode &node)
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)
void RNA_int_set(PointerRNA *ptr, const char *name, int value)
BMesh const char void * data
const EnumPropertyItem rna_enum_node_socket_data_type_items[]
void common_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
bke::bNodeSocketType * typeinfo
bke::bNodeTreeType * typeinfo
const CPPType * base_cpp_type
bool(*) valid_socket_type(bNodeTreeType *ntreetype, bNodeSocketType *socket_type)
bool(*) validate_link(eNodeSocketDatatype from, eNodeSocketDatatype to)
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
static std::string socket_identifier_for_item(const IndexSwitchItem &item)
static void blend_read_data_item(BlendDataReader *reader, ItemT &item)
static StructRNA ** item_srna
static void blend_write_item(BlendWriter *writer, const ItemT &item)
void label(StringRef name, int icon)
PointerRNA op(wmOperatorType *ot, std::optional< StringRef > name, int icon, wm::OpCallContext context, eUI_Item_Flag flag)
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)
Layout & column(bool align)