Cleanup: Geometry Nodes: reduce boilerplate of defining socket item operators
This commit is contained in:
@@ -218,4 +218,25 @@ inline void move_active_item(wmOperatorType *ot,
|
||||
RNA_def_enum(ot->srna, "direction", direction_items, 0, "Direction", "Move direction");
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates simple operators for adding, removing and moving items.
|
||||
* The idnames are passed in explicitly, so that they are more searchable compared to when they
|
||||
* would be computed automatically.
|
||||
*/
|
||||
template<typename Accessor> inline void make_common_operators()
|
||||
{
|
||||
WM_operatortype_append([](wmOperatorType *ot) {
|
||||
socket_items::ops::add_item<Accessor>(
|
||||
ot, "Add Item", Accessor::operator_idnames::add_item, "Add item below active item");
|
||||
});
|
||||
WM_operatortype_append([](wmOperatorType *ot) {
|
||||
socket_items::ops::remove_active_item<Accessor>(
|
||||
ot, "Remove Item", Accessor::operator_idnames::remove_item, "Remove active item");
|
||||
});
|
||||
WM_operatortype_append([](wmOperatorType *ot) {
|
||||
socket_items::ops::move_active_item<Accessor>(
|
||||
ot, "Move Item", Accessor::operator_idnames::move_item, "Move active item");
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace blender::nodes::socket_items::ops
|
||||
|
||||
@@ -35,6 +35,11 @@ struct BakeItemsAccessor {
|
||||
static constexpr bool has_type = true;
|
||||
static constexpr bool has_name = true;
|
||||
static constexpr bool has_single_identifier_str = true;
|
||||
struct operator_idnames {
|
||||
static constexpr const char *add_item = "NODE_OT_bake_node_item_add";
|
||||
static constexpr const char *remove_item = "NODE_OT_bake_node_item_remove";
|
||||
static constexpr const char *move_item = "NODE_OT_bake_node_item_move";
|
||||
};
|
||||
|
||||
static socket_items::SocketItemsRef<NodeGeometryBakeItem> get_items_from_node(bNode &node)
|
||||
{
|
||||
|
||||
@@ -20,6 +20,11 @@ struct CaptureAttributeItemsAccessor {
|
||||
static constexpr bool has_type = true;
|
||||
static constexpr bool has_name = true;
|
||||
static constexpr bool has_single_identifier_str = false;
|
||||
struct operator_idnames {
|
||||
static constexpr const char *add_item = "NODE_OT_capture_attribute_item_add";
|
||||
static constexpr const char *remove_item = "NODE_OT_capture_attribute_item_remove";
|
||||
static constexpr const char *move_item = "NODE_OT_capture_attribute_item_move";
|
||||
};
|
||||
|
||||
static socket_items::SocketItemsRef<NodeGeometryAttributeCaptureItem> get_items_from_node(
|
||||
bNode &node)
|
||||
|
||||
@@ -18,6 +18,13 @@ struct ForeachGeometryElementInputItemsAccessor {
|
||||
static constexpr bool has_type = true;
|
||||
static constexpr bool has_name = true;
|
||||
static constexpr bool has_single_identifier_str = true;
|
||||
struct operator_idnames {
|
||||
static constexpr const char *add_item = "NODE_OT_foreach_geometry_element_zone_input_item_add";
|
||||
static constexpr const char *remove_item =
|
||||
"NODE_OT_foreach_geometry_element_zone_input_item_remove";
|
||||
static constexpr const char *move_item =
|
||||
"NODE_OT_foreach_geometry_element_zone_input_item_move";
|
||||
};
|
||||
|
||||
static socket_items::SocketItemsRef<ItemT> get_items_from_node(bNode &node)
|
||||
{
|
||||
@@ -90,6 +97,13 @@ struct ForeachGeometryElementMainItemsAccessor {
|
||||
static constexpr bool has_type = true;
|
||||
static constexpr bool has_name = true;
|
||||
static constexpr bool has_single_identifier_str = true;
|
||||
struct operator_idnames {
|
||||
static constexpr const char *add_item = "NODE_OT_foreach_geometry_element_zone_main_item_add";
|
||||
static constexpr const char *remove_item =
|
||||
"NODE_OT_foreach_geometry_element_zone_main_item_remove";
|
||||
static constexpr const char *move_item =
|
||||
"NODE_OT_foreach_geometry_element_zone_main_item_move";
|
||||
};
|
||||
|
||||
static socket_items::SocketItemsRef<ItemT> get_items_from_node(bNode &node)
|
||||
{
|
||||
@@ -161,6 +175,14 @@ struct ForeachGeometryElementGenerationItemsAccessor {
|
||||
static constexpr bool has_type = true;
|
||||
static constexpr bool has_name = true;
|
||||
static constexpr bool has_single_identifier_str = true;
|
||||
struct operator_idnames {
|
||||
static constexpr const char *add_item =
|
||||
"NODE_OT_foreach_geometry_element_zone_generation_item_add";
|
||||
static constexpr const char *remove_item =
|
||||
"NODE_OT_foreach_geometry_element_zone_generation_item_remove";
|
||||
static constexpr const char *move_item =
|
||||
"NODE_OT_foreach_geometry_element_zone_generation_item_move";
|
||||
};
|
||||
|
||||
static socket_items::SocketItemsRef<ItemT> get_items_from_node(bNode &node)
|
||||
{
|
||||
|
||||
@@ -23,6 +23,11 @@ struct MenuSwitchItemsAccessor {
|
||||
static constexpr bool has_type = false;
|
||||
static constexpr bool has_name = true;
|
||||
static constexpr bool has_single_identifier_str = true;
|
||||
struct operator_idnames {
|
||||
static constexpr const char *add_item = "NODE_OT_enum_definition_item_add";
|
||||
static constexpr const char *remove_item = "NODE_OT_enum_definition_item_remove";
|
||||
static constexpr const char *move_item = "NODE_OT_enum_definition_item_move";
|
||||
};
|
||||
|
||||
static socket_items::SocketItemsRef<NodeEnumItem> get_items_from_node(bNode &node)
|
||||
{
|
||||
|
||||
@@ -23,6 +23,11 @@ struct RepeatItemsAccessor {
|
||||
static constexpr bool has_type = true;
|
||||
static constexpr bool has_name = true;
|
||||
static constexpr bool has_single_identifier_str = true;
|
||||
struct operator_idnames {
|
||||
static constexpr const char *add_item = "NODE_OT_repeat_zone_item_add";
|
||||
static constexpr const char *remove_item = "NODE_OT_repeat_zone_item_remove";
|
||||
static constexpr const char *move_item = "NODE_OT_repeat_zone_item_move";
|
||||
};
|
||||
|
||||
static socket_items::SocketItemsRef<NodeRepeatItem> get_items_from_node(bNode &node)
|
||||
{
|
||||
|
||||
@@ -22,6 +22,11 @@ struct SimulationItemsAccessor {
|
||||
static constexpr bool has_type = true;
|
||||
static constexpr bool has_name = true;
|
||||
static constexpr bool has_single_identifier_str = true;
|
||||
struct operator_idnames {
|
||||
static constexpr const char *add_item = "NODE_OT_simulation_zone_item_add";
|
||||
static constexpr const char *remove_item = "NODE_OT_simulation_zone_item_remove";
|
||||
static constexpr const char *move_item = "NODE_OT_simulation_zone_item_move";
|
||||
};
|
||||
|
||||
static socket_items::SocketItemsRef<NodeSimulationItem> get_items_from_node(bNode &node)
|
||||
{
|
||||
|
||||
@@ -144,29 +144,9 @@ static void node_layout_ex(uiLayout *layout, bContext *C, PointerRNA *ptr)
|
||||
}
|
||||
}
|
||||
|
||||
static void NODE_OT_capture_attribute_item_add(wmOperatorType *ot)
|
||||
{
|
||||
socket_items::ops::add_item<CaptureAttributeItemsAccessor>(
|
||||
ot, "Add Capture Attribute Item", __func__, "Add capture attribute item");
|
||||
}
|
||||
|
||||
static void NODE_OT_capture_attribute_item_remove(wmOperatorType *ot)
|
||||
{
|
||||
socket_items::ops::remove_active_item<CaptureAttributeItemsAccessor>(
|
||||
ot, "Remove Capture Attribute Item", __func__, "Remove active capture attribute item");
|
||||
}
|
||||
|
||||
static void NODE_OT_capture_attribute_item_move(wmOperatorType *ot)
|
||||
{
|
||||
socket_items::ops::move_active_item<CaptureAttributeItemsAccessor>(
|
||||
ot, "Move Capture Attribute Item", __func__, "Move active capture attribute item");
|
||||
}
|
||||
|
||||
static void node_operators()
|
||||
{
|
||||
WM_operatortype_append(NODE_OT_capture_attribute_item_add);
|
||||
WM_operatortype_append(NODE_OT_capture_attribute_item_remove);
|
||||
WM_operatortype_append(NODE_OT_capture_attribute_item_move);
|
||||
socket_items::ops::make_common_operators<CaptureAttributeItemsAccessor>();
|
||||
}
|
||||
|
||||
static void clean_unused_attributes(const AttributeFilter &attribute_filter,
|
||||
|
||||
@@ -204,28 +204,9 @@ static void draw_bake_items(const bContext *C, uiLayout *layout, PointerRNA node
|
||||
}
|
||||
}
|
||||
|
||||
static void NODE_OT_bake_node_item_remove(wmOperatorType *ot)
|
||||
{
|
||||
socket_items::ops::remove_active_item<BakeItemsAccessor>(
|
||||
ot, "Remove Bake Item", __func__, "Remove active bake item");
|
||||
}
|
||||
|
||||
static void NODE_OT_bake_node_item_add(wmOperatorType *ot)
|
||||
{
|
||||
socket_items::ops::add_item<BakeItemsAccessor>(ot, "Add Bake Item", __func__, "Add bake item");
|
||||
}
|
||||
|
||||
static void NODE_OT_bake_node_item_move(wmOperatorType *ot)
|
||||
{
|
||||
socket_items::ops::move_active_item<BakeItemsAccessor>(
|
||||
ot, "Move Bake Item", __func__, "Move active bake item");
|
||||
}
|
||||
|
||||
static void node_operators()
|
||||
{
|
||||
WM_operatortype_append(NODE_OT_bake_node_item_add);
|
||||
WM_operatortype_append(NODE_OT_bake_node_item_remove);
|
||||
WM_operatortype_append(NODE_OT_bake_node_item_move);
|
||||
socket_items::ops::make_common_operators<BakeItemsAccessor>();
|
||||
}
|
||||
|
||||
static bake::BakeSocketConfig make_bake_socket_config(const Span<NodeGeometryBakeItem> bake_items)
|
||||
|
||||
@@ -534,73 +534,11 @@ static bool node_insert_link(bNodeTree *ntree, bNode *node, bNodeLink *link)
|
||||
ForeachGeometryElementGenerationItemsAccessor>(*ntree, *node, *node, *link);
|
||||
}
|
||||
|
||||
static void NODE_OT_foreach_geometry_element_zone_input_item_remove(wmOperatorType *ot)
|
||||
{
|
||||
socket_items::ops::remove_active_item<ForeachGeometryElementInputItemsAccessor>(
|
||||
ot, "Remove For Each Input Item", __func__, "Remove active for-each input item");
|
||||
}
|
||||
|
||||
static void NODE_OT_foreach_geometry_element_zone_input_item_add(wmOperatorType *ot)
|
||||
{
|
||||
socket_items::ops::add_item<ForeachGeometryElementInputItemsAccessor>(
|
||||
ot, "Add For Each Input Item", __func__, "Add for-each input item");
|
||||
}
|
||||
|
||||
static void NODE_OT_foreach_geometry_element_zone_input_item_move(wmOperatorType *ot)
|
||||
{
|
||||
socket_items::ops::move_active_item<ForeachGeometryElementInputItemsAccessor>(
|
||||
ot, "Move For Each Input Item", __func__, "Move active for-each input item");
|
||||
}
|
||||
|
||||
static void NODE_OT_foreach_geometry_element_zone_generation_item_remove(wmOperatorType *ot)
|
||||
{
|
||||
socket_items::ops::remove_active_item<ForeachGeometryElementGenerationItemsAccessor>(
|
||||
ot, "Remove For Each Generation Item", __func__, "Remove active for-each generation item");
|
||||
}
|
||||
|
||||
static void NODE_OT_foreach_geometry_element_zone_generation_item_add(wmOperatorType *ot)
|
||||
{
|
||||
socket_items::ops::add_item<ForeachGeometryElementGenerationItemsAccessor>(
|
||||
ot, "Add For Each Generation Item", __func__, "Add for-each generation item");
|
||||
}
|
||||
|
||||
static void NODE_OT_foreach_geometry_element_zone_generation_item_move(wmOperatorType *ot)
|
||||
{
|
||||
socket_items::ops::move_active_item<ForeachGeometryElementGenerationItemsAccessor>(
|
||||
ot, "Move For Each Generation Item", __func__, "Move active for-each generation item");
|
||||
}
|
||||
|
||||
static void NODE_OT_foreach_geometry_element_zone_main_item_remove(wmOperatorType *ot)
|
||||
{
|
||||
socket_items::ops::remove_active_item<ForeachGeometryElementMainItemsAccessor>(
|
||||
ot, "Remove For Each Main Item", __func__, "Remove active for-each main item");
|
||||
}
|
||||
|
||||
static void NODE_OT_foreach_geometry_element_zone_main_item_add(wmOperatorType *ot)
|
||||
{
|
||||
socket_items::ops::add_item<ForeachGeometryElementMainItemsAccessor>(
|
||||
ot, "Add For Each Main Item", __func__, "Add for-each main item");
|
||||
}
|
||||
|
||||
static void NODE_OT_foreach_geometry_element_zone_main_item_move(wmOperatorType *ot)
|
||||
{
|
||||
socket_items::ops::move_active_item<ForeachGeometryElementMainItemsAccessor>(
|
||||
ot, "Move For Each Main Item", __func__, "Move active for-each main item");
|
||||
}
|
||||
|
||||
static void node_operators()
|
||||
{
|
||||
WM_operatortype_append(NODE_OT_foreach_geometry_element_zone_input_item_add);
|
||||
WM_operatortype_append(NODE_OT_foreach_geometry_element_zone_input_item_remove);
|
||||
WM_operatortype_append(NODE_OT_foreach_geometry_element_zone_input_item_move);
|
||||
|
||||
WM_operatortype_append(NODE_OT_foreach_geometry_element_zone_generation_item_add);
|
||||
WM_operatortype_append(NODE_OT_foreach_geometry_element_zone_generation_item_remove);
|
||||
WM_operatortype_append(NODE_OT_foreach_geometry_element_zone_generation_item_move);
|
||||
|
||||
WM_operatortype_append(NODE_OT_foreach_geometry_element_zone_main_item_add);
|
||||
WM_operatortype_append(NODE_OT_foreach_geometry_element_zone_main_item_remove);
|
||||
WM_operatortype_append(NODE_OT_foreach_geometry_element_zone_main_item_move);
|
||||
socket_items::ops::make_common_operators<ForeachGeometryElementInputItemsAccessor>();
|
||||
socket_items::ops::make_common_operators<ForeachGeometryElementMainItemsAccessor>();
|
||||
socket_items::ops::make_common_operators<ForeachGeometryElementGenerationItemsAccessor>();
|
||||
}
|
||||
|
||||
static void node_extra_info(NodeExtraInfoParams ¶ms)
|
||||
|
||||
@@ -433,29 +433,9 @@ static void node_layout_ex(uiLayout *layout, bContext *C, PointerRNA *ptr)
|
||||
}
|
||||
}
|
||||
|
||||
static void NODE_OT_enum_definition_item_add(wmOperatorType *ot)
|
||||
{
|
||||
socket_items::ops::add_item<MenuSwitchItemsAccessor>(
|
||||
ot, "Add Menu Item", __func__, "Add menu item");
|
||||
}
|
||||
|
||||
static void NODE_OT_enum_definition_item_remove(wmOperatorType *ot)
|
||||
{
|
||||
socket_items::ops::remove_active_item<MenuSwitchItemsAccessor>(
|
||||
ot, "Remove Menu Item", __func__, "Remove active menu item");
|
||||
}
|
||||
|
||||
static void NODE_OT_enum_definition_item_move(wmOperatorType *ot)
|
||||
{
|
||||
socket_items::ops::move_active_item<MenuSwitchItemsAccessor>(
|
||||
ot, "Move Menu Item", __func__, "Move active menu item");
|
||||
}
|
||||
|
||||
static void node_operators()
|
||||
{
|
||||
WM_operatortype_append(NODE_OT_enum_definition_item_add);
|
||||
WM_operatortype_append(NODE_OT_enum_definition_item_remove);
|
||||
WM_operatortype_append(NODE_OT_enum_definition_item_move);
|
||||
socket_items::ops::make_common_operators<MenuSwitchItemsAccessor>();
|
||||
}
|
||||
|
||||
static bool node_insert_link(bNodeTree *ntree, bNode *node, bNodeLink *link)
|
||||
|
||||
@@ -269,29 +269,9 @@ static bool node_insert_link(bNodeTree *ntree, bNode *node, bNodeLink *link)
|
||||
*ntree, *node, *node, *link);
|
||||
}
|
||||
|
||||
static void NODE_OT_repeat_zone_item_remove(wmOperatorType *ot)
|
||||
{
|
||||
socket_items::ops::remove_active_item<RepeatItemsAccessor>(
|
||||
ot, "Remove Repeat Zone Item", __func__, "Remove active repeat zone item");
|
||||
}
|
||||
|
||||
static void NODE_OT_repeat_zone_item_add(wmOperatorType *ot)
|
||||
{
|
||||
socket_items::ops::add_item<RepeatItemsAccessor>(
|
||||
ot, "Add Repeat Zone Item", __func__, "Add repeat zone item");
|
||||
}
|
||||
|
||||
static void NODE_OT_repeat_zone_item_move(wmOperatorType *ot)
|
||||
{
|
||||
socket_items::ops::move_active_item<RepeatItemsAccessor>(
|
||||
ot, "Move Repeat Zone Item", __func__, "Move active repeat zone item");
|
||||
}
|
||||
|
||||
static void node_operators()
|
||||
{
|
||||
WM_operatortype_append(NODE_OT_repeat_zone_item_add);
|
||||
WM_operatortype_append(NODE_OT_repeat_zone_item_remove);
|
||||
WM_operatortype_append(NODE_OT_repeat_zone_item_move);
|
||||
socket_items::ops::make_common_operators<RepeatItemsAccessor>();
|
||||
}
|
||||
|
||||
static void node_register()
|
||||
|
||||
@@ -276,24 +276,6 @@ static void draw_simulation_state(const bContext *C,
|
||||
}
|
||||
}
|
||||
|
||||
static void NODE_OT_simulation_zone_item_remove(wmOperatorType *ot)
|
||||
{
|
||||
socket_items::ops::remove_active_item<SimulationItemsAccessor>(
|
||||
ot, "Remove Simulation Zone Item", __func__, "Remove active simulation zone item");
|
||||
}
|
||||
|
||||
static void NODE_OT_simulation_zone_item_add(wmOperatorType *ot)
|
||||
{
|
||||
socket_items::ops::add_item<SimulationItemsAccessor>(
|
||||
ot, "Add Simulation Zone Item", __func__, "Add simulation zone item");
|
||||
}
|
||||
|
||||
static void NODE_OT_simulation_zone_item_move(wmOperatorType *ot)
|
||||
{
|
||||
socket_items::ops::move_active_item<SimulationItemsAccessor>(
|
||||
ot, "Move Simulation Zone Item", __func__, "Move active simulation zone item");
|
||||
}
|
||||
|
||||
/** Shared for simulation input and output node. */
|
||||
static void node_layout_ex(uiLayout *layout, bContext *C, PointerRNA *current_node_ptr)
|
||||
{
|
||||
@@ -914,9 +896,7 @@ static void node_copy_storage(bNodeTree * /*dst_tree*/, bNode *dst_node, const b
|
||||
|
||||
static void node_operators()
|
||||
{
|
||||
WM_operatortype_append(NODE_OT_simulation_zone_item_add);
|
||||
WM_operatortype_append(NODE_OT_simulation_zone_item_remove);
|
||||
WM_operatortype_append(NODE_OT_simulation_zone_item_move);
|
||||
socket_items::ops::make_common_operators<SimulationItemsAccessor>();
|
||||
}
|
||||
|
||||
static bool node_insert_link(bNodeTree *ntree, bNode *node, bNodeLink *link)
|
||||
|
||||
Reference in New Issue
Block a user