Blender V5.0
node_geo_tool_active_element.cc
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#include "UI_interface.hh"
7
8#include "RNA_enum_types.hh"
9
10#include "BKE_node.hh"
11
12#include "NOD_rna_define.hh"
13
14#include "node_geometry_util.hh"
15
17
19{
20 b.add_output<decl::Int>("Index").description(
21 "Index of the active element in the specified domain");
22 b.add_output<decl::Bool>("Exists").description(
23 "True if an active element exists in the mesh, false otherwise");
24}
25
26static void node_init(bNodeTree * /*tree*/, bNode *node)
27{
28 node->custom1 = int16_t(AttrDomain::Point);
29}
30
31static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
32{
33 layout->use_property_split_set(true);
34 layout->use_property_decorate_set(false);
35 layout->prop(ptr, "domain", UI_ITEM_NONE, "", ICON_NONE);
36}
37
39{
41 return;
42 }
43
44 const GeoNodesOperatorData *operator_data = params.user_data()->call_data->operator_data;
45 const AttrDomain domain = static_cast<AttrDomain>(params.node().custom1);
46
47 /* Active Point, Edge, and Face are only supported in Edit Mode. */
48 if (operator_data->mode != OB_MODE_EDIT &&
49 ELEM(domain, AttrDomain::Point, AttrDomain::Edge, AttrDomain::Face))
50 {
51 params.set_default_remaining_outputs();
52 return;
53 }
54
55 switch (domain) {
56 case AttrDomain::Point:
57 params.set_output("Exists", operator_data->active_point_index >= 0);
58 params.set_output("Index", std::max(0, operator_data->active_point_index));
59 break;
60 case AttrDomain::Edge:
61 params.set_output("Exists", operator_data->active_edge_index >= 0);
62 params.set_output("Index", std::max(0, operator_data->active_edge_index));
63 break;
64 case AttrDomain::Face:
65 params.set_output("Exists", operator_data->active_face_index >= 0);
66 params.set_output("Index", std::max(0, operator_data->active_face_index));
67 break;
68 case AttrDomain::Layer:
69 params.set_output("Exists", operator_data->active_layer_index >= 0);
70 params.set_output("Index", std::max(0, operator_data->active_layer_index));
71 break;
72 default:
73 params.set_default_remaining_outputs();
75 break;
76 }
77}
78
79static void node_rna(StructRNA *srna)
80{
81 static const EnumPropertyItem rna_domain_items[] = {
82 {int(AttrDomain::Point), "POINT", 0, "Point", ""},
83 {int(AttrDomain::Edge), "EDGE", 0, "Edge", ""},
84 {int(AttrDomain::Face), "FACE", 0, "Face", ""},
85 {int(AttrDomain::Layer), "LAYER", 0, "Layer", ""},
86 {0, nullptr, 0, nullptr, nullptr},
87 };
88
90 "domain",
91 "Domain",
92 "",
93 rna_domain_items,
95 int(AttrDomain::Point));
96}
97
98static void node_register()
99{
100 static blender::bke::bNodeType ntype;
101 geo_node_type_base(&ntype, "GeometryNodeToolActiveElement", GEO_NODE_TOOL_ACTIVE_ELEMENT);
102 ntype.ui_name = "Active Element";
103 ntype.ui_description = "Active element indices of the edited geometry, for tool execution";
104 ntype.enum_name_legacy = "TOOL_ACTIVE_ELEMENT";
105 ntype.nclass = NODE_CLASS_INPUT;
106 ntype.initfunc = node_init;
108 ntype.declare = node_declare;
112
113 node_rna(ntype.rna_ext.srna);
114}
116
117} // namespace blender::nodes::node_geo_tool_active_element_cc
#define NODE_CLASS_INPUT
Definition BKE_node.hh:447
#define GEO_NODE_TOOL_ACTIVE_ELEMENT
#define BLI_assert_unreachable()
Definition BLI_assert.h:93
#define ELEM(...)
@ OB_MODE_EDIT
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define NOD_inline_enum_accessors(member)
#define UI_ITEM_NONE
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void node_register_type(bNodeType &ntype)
Definition node.cc:2416
static void node_layout(uiLayout *layout, bContext *, PointerRNA *ptr)
void search_link_ops_for_tool_node(GatherLinkSearchOpParams &params)
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 check_tool_context_and_error(GeoNodeExecParams &params)
void geo_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
StructRNA * srna
int16_t custom1
Defines a node type.
Definition BKE_node.hh:238
std::string ui_description
Definition BKE_node.hh:244
void(* initfunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:289
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:354
const char * enum_name_legacy
Definition BKE_node.hh:247
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:259
NodeGatherSocketLinkOperationsFunction gather_link_search_ops
Definition BKE_node.hh:378
NodeDeclareFunction declare
Definition BKE_node.hh:362
void use_property_decorate_set(bool is_sep)
void use_property_split_set(bool value)
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< blender::StringRef > name_opt, int icon, std::optional< blender::StringRef > placeholder=std::nullopt)
PointerRNA * ptr
Definition wm_files.cc:4238