Blender V4.5
node_geo_viewer.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#include "BLI_listbase.h"
6
7#include "BKE_context.hh"
8
10#include "NOD_rna_define.hh"
12
13#include "UI_interface.hh"
14#include "UI_resources.hh"
15
16#include "ED_node.hh"
17#include "ED_viewer_path.hh"
18
19#include "RNA_enum_types.hh"
20
21#include "node_geometry_util.hh"
22
24
26
28{
29 const bNode *node = b.node_or_null();
30
31 b.add_input<decl::Geometry>("Geometry");
32 if (node != nullptr) {
33 const eCustomDataType data_type = eCustomDataType(node_storage(*node).data_type);
34 b.add_input(data_type, "Value").field_on_all().hide_value();
35 }
36}
37
38static void node_init(bNodeTree * /*tree*/, bNode *node)
39{
41 data->data_type = CD_PROP_FLOAT;
42 data->domain = int8_t(AttrDomain::Auto);
43 node->storage = data;
44}
45
46static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
47{
48 layout->prop(ptr, "domain", UI_ITEM_NONE, "", ICON_NONE);
49}
50
51static void node_layout_ex(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
52{
53 layout->prop(ptr, "data_type", UI_ITEM_NONE, "", ICON_NONE);
54}
55
57{
58 auto set_active_fn = [](LinkSearchOpParams &params, bNode &viewer_node) {
59 /* Set this new viewer node active in spreadsheet editors. */
61 Main *bmain = CTX_data_main(&params.C);
62 ED_node_set_active(bmain, snode, &params.node_tree, &viewer_node, nullptr);
63 ed::viewer_path::activate_geometry_node(*bmain, *snode, viewer_node);
64 };
65
66 const eNodeSocketDatatype socket_type = eNodeSocketDatatype(params.other_socket().type);
67 const std::optional<eCustomDataType> type = bke::socket_type_to_custom_data_type(socket_type);
68 if (params.in_out() == SOCK_OUT) {
69 /* The viewer node only has inputs. */
70 return;
71 }
72 if (params.other_socket().type == SOCK_GEOMETRY) {
73 params.add_item(IFACE_("Geometry"), [set_active_fn](LinkSearchOpParams &params) {
74 bNode &node = params.add_node("GeometryNodeViewer");
75 params.connect_available_socket(node, "Geometry");
76 set_active_fn(params, node);
77 });
78 }
79 if (type && ELEM(*type,
87 {
88 params.add_item(IFACE_("Value"), [type, set_active_fn](LinkSearchOpParams &params) {
89 bNode &node = params.add_node("GeometryNodeViewer");
90 node_storage(node).data_type = *type;
91 params.update_and_connect_available_socket(node, "Value");
92
93 /* If the source node has a geometry socket, connect it to the new viewer node as well. */
94 LISTBASE_FOREACH (bNodeSocket *, socket, &params.node.outputs) {
95 if (socket->type == SOCK_GEOMETRY && socket->is_visible()) {
96 bke::node_add_link(params.node_tree,
97 params.node,
98 *socket,
99 node,
100 *static_cast<bNodeSocket *>(node.inputs.first));
101 break;
102 }
103 }
104
105 set_active_fn(params, node);
106 });
107 }
108}
109
111{
112 const auto data_type = eCustomDataType(node_storage(params.node).data_type);
113 if (ELEM(data_type, CD_PROP_QUATERNION, CD_PROP_FLOAT4X4)) {
115 row.icon = ICON_INFO;
116 row.text = TIP_("No color overlay");
117 row.tooltip = TIP_(
118 "Rotation values can only be displayed with the text overlay in the 3D view");
119 params.rows.append(std::move(row));
120 }
121}
122
123static void node_rna(StructRNA *srna)
124{
126 "data_type",
127 "Data Type",
128 "",
133
135 "domain",
136 "Domain",
137 "Domain to evaluate the field on",
140 int(AttrDomain::Point));
141
142 PropertyRNA *prop;
143 prop = RNA_def_property(srna, "ui_shortcut", PROP_INT, PROP_NONE);
150}
151
152static void node_register()
153{
154 static blender::bke::bNodeType ntype;
155
156 geo_node_type_base(&ntype, "GeometryNodeViewer", GEO_NODE_VIEWER);
157 ntype.ui_name = "Viewer";
158 ntype.ui_description = "Display the input data in the Spreadsheet Editor";
159 ntype.enum_name_legacy = "VIEWER";
162 ntype, "NodeGeometryViewer", node_free_standard_storage, node_copy_standard_storage);
163 ntype.declare = node_declare;
164 ntype.initfunc = node_init;
168 ntype.no_muting = true;
171
172 node_rna(ntype.rna_ext.srna);
173}
175
176} // namespace blender::nodes::node_geo_viewer_cc
SpaceNode * CTX_wm_space_node(const bContext *C)
Main * CTX_data_main(const bContext *C)
#define NODE_CLASS_OUTPUT
Definition BKE_node.hh:434
#define NODE_STORAGE_FUNCS(StorageT)
Definition BKE_node.hh:1215
#define GEO_NODE_VIEWER
#define LISTBASE_FOREACH(type, var, list)
#define ELEM(...)
#define TIP_(msgid)
#define IFACE_(msgid)
@ CD_PROP_FLOAT
@ CD_PROP_FLOAT3
@ CD_PROP_COLOR
@ CD_PROP_QUATERNION
@ CD_PROP_INT32
@ CD_PROP_FLOAT4X4
@ SOCK_OUT
@ NODE_VIEWER_SHORTCUT_NONE
eNodeSocketDatatype
@ SOCK_GEOMETRY
void ED_node_set_active(Main *bmain, SpaceNode *snode, bNodeTree *ntree, bNode *node, bool *r_active_texture_changed)
Definition node_edit.cc:772
#define NOD_REGISTER_NODE(REGISTER_FUNC)
int rna_Node_Viewer_shortcut_node_get(PointerRNA *ptr, PropertyRNA *prop)
void rna_Node_Viewer_shortcut_node_set(PointerRNA *ptr, PropertyRNA *prop, int value)
#define NOD_storage_enum_accessors(member)
@ PROP_INT
Definition RNA_types.hh:151
@ PROPOVERRIDE_IGNORE
Definition RNA_types.hh:489
@ PROP_ANIMATABLE
Definition RNA_types.hh:305
@ PROP_NONE
Definition RNA_types.hh:221
#define UI_ITEM_NONE
#define NC_NODE
Definition WM_types.hh:391
#define ND_DISPLAY
Definition WM_types.hh:488
BMesh const char void * data
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void * MEM_callocN(size_t len, const char *str)
Definition mallocn.cc:118
void node_register_type(bNodeType &ntype)
Definition node.cc:2748
bNodeLink & node_add_link(bNodeTree &ntree, bNode &fromnode, bNodeSocket &fromsock, bNode &tonode, bNodeSocket &tosock)
Definition node.cc:4087
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))
Definition node.cc:5603
std::optional< eCustomDataType > socket_type_to_custom_data_type(eNodeSocketDatatype type)
Definition node.cc:5355
void activate_geometry_node(Main &bmain, SpaceNode &snode, bNode &node)
const EnumPropertyItem * attribute_type_type_with_socket_fn(bContext *, PointerRNA *, PropertyRNA *, bool *r_free)
static void node_rna(StructRNA *srna)
static void node_init(bNodeTree *, bNode *node)
static void node_layout_ex(uiLayout *layout, bContext *, PointerRNA *ptr)
static void node_declare(NodeDeclarationBuilder &b)
static void node_extra_info(NodeExtraInfoParams &params)
static void node_layout(uiLayout *layout, bContext *, PointerRNA *ptr)
static void node_gather_link_searches(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)
void geo_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
void node_free_standard_storage(bNode *node)
Definition node_util.cc:42
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
Definition node_util.cc:54
const EnumPropertyItem rna_enum_attribute_domain_with_auto_items[]
const EnumPropertyItem rna_enum_attribute_type_items[]
void RNA_def_property_int_funcs_runtime(PropertyRNA *prop, IntPropertyGetFunc getfunc, IntPropertySetFunc setfunc, IntPropertyRangeFunc rangefunc)
void RNA_def_property_int_default(PropertyRNA *prop, int value)
void RNA_def_property_update_notifier(PropertyRNA *prop, const int noteflag)
PropertyRNA * RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier, int type, int subtype)
void RNA_def_property_clear_flag(PropertyRNA *prop, PropertyFlag flag)
void RNA_def_property_override_flag(PropertyRNA *prop, PropertyOverrideFlag flag)
StructRNA * srna
Definition RNA_types.hh:909
void * first
ListBase inputs
void * storage
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
void(* draw_buttons_ex)(uiLayout *, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:249
NodeExtraInfoFunction get_extra_info
Definition BKE_node.hh:374
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