Blender V4.5
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"
6
7#include "RNA_enum_types.hh"
8
9#include "BKE_node.hh"
10
11#include "NOD_rna_define.hh"
12
13#include "node_geometry_util.hh"
14
16
18{
19 b.add_output<decl::Int>("Index").description(
20 "Index of the active element in the specified domain");
21 b.add_output<decl::Bool>("Exists").description(
22 "True if an active element exists in the mesh, false otherwise");
23}
24
25static void node_init(bNodeTree * /*tree*/, bNode *node)
26{
27 node->custom1 = int16_t(AttrDomain::Point);
28}
29
30static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
31{
32 uiLayoutSetPropSep(layout, true);
33 uiLayoutSetPropDecorate(layout, false);
34 layout->prop(ptr, "domain", UI_ITEM_NONE, "", ICON_NONE);
35}
36
38{
40 return;
41 }
42
43 const GeoNodesOperatorData *operator_data = params.user_data()->call_data->operator_data;
44 const AttrDomain domain = static_cast<AttrDomain>(params.node().custom1);
45
46 /* Active Point, Edge, and Face are only supported in Edit Mode. */
47 if (operator_data->mode != OB_MODE_EDIT &&
48 ELEM(domain, AttrDomain::Point, AttrDomain::Edge, AttrDomain::Face))
49 {
50 params.set_default_remaining_outputs();
51 return;
52 }
53
54 switch (domain) {
55 case AttrDomain::Point:
56 params.set_output("Exists", operator_data->active_point_index >= 0);
57 params.set_output("Index", std::max(0, operator_data->active_point_index));
58 break;
59 case AttrDomain::Edge:
60 params.set_output("Exists", operator_data->active_edge_index >= 0);
61 params.set_output("Index", std::max(0, operator_data->active_edge_index));
62 break;
63 case AttrDomain::Face:
64 params.set_output("Exists", operator_data->active_face_index >= 0);
65 params.set_output("Index", std::max(0, operator_data->active_face_index));
66 break;
67 case AttrDomain::Layer:
68 params.set_output("Exists", operator_data->active_layer_index >= 0);
69 params.set_output("Index", std::max(0, operator_data->active_layer_index));
70 break;
71 default:
72 params.set_default_remaining_outputs();
74 break;
75 }
76}
77
78static void node_rna(StructRNA *srna)
79{
80 static const EnumPropertyItem rna_domain_items[] = {
81 {int(AttrDomain::Point), "POINT", 0, "Point", ""},
82 {int(AttrDomain::Edge), "EDGE", 0, "Edge", ""},
83 {int(AttrDomain::Face), "FACE", 0, "Face", ""},
84 {int(AttrDomain::Layer), "LAYER", 0, "Layer", ""},
85 {0, nullptr, 0, nullptr, nullptr},
86 };
87
89 "domain",
90 "Domain",
91 "",
92 rna_domain_items,
94 int(AttrDomain::Point));
95}
96
97static void node_register()
98{
99 static blender::bke::bNodeType ntype;
100 geo_node_type_base(&ntype, "GeometryNodeToolActiveElement", GEO_NODE_TOOL_ACTIVE_ELEMENT);
101 ntype.ui_name = "Active Element";
102 ntype.ui_description = "Active element indices of the edited geometry, for tool execution";
103 ntype.enum_name_legacy = "TOOL_ACTIVE_ELEMENT";
104 ntype.nclass = NODE_CLASS_INPUT;
105 ntype.initfunc = node_init;
107 ntype.declare = node_declare;
111
112 node_rna(ntype.rna_ext.srna);
113}
115
116} // namespace blender::nodes::node_geo_tool_active_element_cc
#define NODE_CLASS_INPUT
Definition BKE_node.hh:433
#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)
void uiLayoutSetPropSep(uiLayout *layout, bool is_sep)
#define UI_ITEM_NONE
void uiLayoutSetPropDecorate(uiLayout *layout, bool is_sep)
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void node_register_type(bNodeType &ntype)
Definition node.cc:2748
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
Definition RNA_types.hh:909
int16_t custom1
Defines a node type.
Definition BKE_node.hh:226
std::string ui_description
Definition BKE_node.hh:232
void(* initfunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:277
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:347
const char * enum_name_legacy
Definition BKE_node.hh:235
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:247
NodeGatherSocketLinkOperationsFunction gather_link_search_ops
Definition BKE_node.hh:371
NodeDeclareFunction declare
Definition BKE_node.hh:355
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:4226