Blender  V3.3
node_geo_viewer.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #include "BKE_context.h"
4 
5 #include "UI_interface.h"
6 #include "UI_resources.h"
7 
8 #include "ED_node.h"
9 #include "ED_spreadsheet.h"
10 
12 
13 #include "node_geometry_util.hh"
14 
16 
18 
20 {
21  b.add_input<decl::Geometry>(N_("Geometry"));
22  b.add_input<decl::Float>(N_("Value")).supports_field().hide_value();
23  b.add_input<decl::Vector>(N_("Value"), "Value_001").supports_field().hide_value();
24  b.add_input<decl::Color>(N_("Value"), "Value_002").supports_field().hide_value();
25  b.add_input<decl::Int>(N_("Value"), "Value_003").supports_field().hide_value();
26  b.add_input<decl::Bool>(N_("Value"), "Value_004").supports_field().hide_value();
27 }
28 
30 {
31  NodeGeometryViewer *data = MEM_cnew<NodeGeometryViewer>(__func__);
32  data->data_type = CD_PROP_FLOAT;
33 
34  node->storage = data;
35 }
36 
37 static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
38 {
39  uiItemR(layout, ptr, "data_type", 0, "", ICON_NONE);
40 }
41 
43 {
44  switch (type) {
45  case CD_PROP_FLOAT:
46  return SOCK_FLOAT;
47  case CD_PROP_INT32:
48  return SOCK_INT;
49  case CD_PROP_FLOAT3:
50  return SOCK_VECTOR;
51  case CD_PROP_BOOL:
52  return SOCK_BOOLEAN;
53  case CD_PROP_COLOR:
54  return SOCK_RGBA;
55  default:
57  return SOCK_FLOAT;
58  }
59 }
60 
62 {
63  const NodeGeometryViewer &storage = node_storage(*node);
64  const eCustomDataType data_type = static_cast<eCustomDataType>(storage.data_type);
65  const eNodeSocketDatatype socket_type = custom_data_type_to_socket_type(data_type);
66 
67  LISTBASE_FOREACH (bNodeSocket *, socket, &node->inputs) {
68  if (socket->type == SOCK_GEOMETRY) {
69  continue;
70  }
71  nodeSetSocketAvailability(ntree, socket, socket->type == socket_type);
72  }
73 }
74 
76 {
77  auto set_active_fn = [](LinkSearchOpParams &params, bNode &viewer_node) {
78  /* Set this new viewer node active in spreadsheet editors. */
79  SpaceNode *snode = CTX_wm_space_node(&params.C);
80  Main *bmain = CTX_data_main(&params.C);
81  ED_node_set_active(bmain, snode, &params.node_tree, &viewer_node, nullptr);
82  ED_spreadsheet_context_paths_set_geometry_node(bmain, snode, &viewer_node);
83  };
84 
85  const std::optional<eCustomDataType> type = node_socket_to_custom_data_type(
86  params.other_socket());
87  if (params.in_out() == SOCK_OUT) {
88  /* The viewer node only has inputs. */
89  return;
90  }
91  if (params.other_socket().type == SOCK_GEOMETRY) {
92  params.add_item(IFACE_("Geometry"), [set_active_fn](LinkSearchOpParams &params) {
93  bNode &node = params.add_node("GeometryNodeViewer");
94  params.connect_available_socket(node, "Geometry");
95  set_active_fn(params, node);
96  });
97  }
98  if (type &&
100  params.add_item(IFACE_("Value"), [type, set_active_fn](LinkSearchOpParams &params) {
101  bNode &node = params.add_node("GeometryNodeViewer");
102  node_storage(node).data_type = *type;
103  params.update_and_connect_available_socket(node, "Value");
104 
105  /* If the source node has a geometry socket, connect it to the new viewer node as well. */
106  LISTBASE_FOREACH (bNodeSocket *, socket, &params.node.outputs) {
107  if (socket->type == SOCK_GEOMETRY && !(socket->flag & (SOCK_UNAVAIL | SOCK_HIDDEN))) {
108  nodeAddLink(&params.node_tree,
109  &params.node,
110  socket,
111  &node,
112  static_cast<bNodeSocket *>(node.inputs.first));
113  }
114  }
115 
116  set_active_fn(params, node);
117  });
118  }
119 }
120 
121 } // namespace blender::nodes::node_geo_viewer_cc
122 
124 {
125  namespace file_ns = blender::nodes::node_geo_viewer_cc;
126 
127  static bNodeType ntype;
128 
131  &ntype, "NodeGeometryViewer", node_free_standard_storage, node_copy_standard_storage);
137  nodeRegisterType(&ntype);
138 }
struct SpaceNode * CTX_wm_space_node(const bContext *C)
Definition: context.c:878
struct Main * CTX_data_main(const bContext *C)
Definition: context.c:1074
#define NODE_CLASS_OUTPUT
Definition: BKE_node.h:346
void node_type_update(struct bNodeType *ntype, void(*updatefunc)(struct bNodeTree *ntree, struct bNode *node))
Definition: node.cc:4443
#define GEO_NODE_VIEWER
Definition: BKE_node.h:1413
#define NODE_STORAGE_FUNCS(StorageT)
Definition: BKE_node.h:1563
void nodeSetSocketAvailability(struct bNodeTree *ntree, struct bNodeSocket *sock, bool is_available)
Definition: node.cc:3664
void node_type_init(struct bNodeType *ntype, void(*initfunc)(struct bNodeTree *ntree, struct bNode *node))
Definition: node.cc:4390
void node_type_storage(struct bNodeType *ntype, const char *storagename, void(*freefunc)(struct bNode *node), void(*copyfunc)(struct bNodeTree *dest_ntree, struct bNode *dest_node, const struct bNode *src_node))
Definition: node.cc:4426
struct bNodeLink * nodeAddLink(struct bNodeTree *ntree, struct bNode *fromnode, struct bNodeSocket *fromsock, struct bNode *tonode, struct bNodeSocket *tosock)
Definition: node.cc:2296
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1357
#define BLI_assert_unreachable()
Definition: BLI_assert.h:93
#define LISTBASE_FOREACH(type, var, list)
Definition: BLI_listbase.h:336
#define UNUSED(x)
#define ELEM(...)
#define IFACE_(msgid)
eCustomDataType
@ CD_PROP_FLOAT
@ CD_PROP_FLOAT3
@ CD_PROP_COLOR
@ CD_PROP_INT32
@ CD_PROP_BOOL
@ SOCK_OUT
@ SOCK_HIDDEN
@ SOCK_UNAVAIL
eNodeSocketDatatype
@ SOCK_INT
@ SOCK_VECTOR
@ SOCK_BOOLEAN
@ SOCK_FLOAT
@ SOCK_GEOMETRY
@ SOCK_RGBA
void ED_node_set_active(struct Main *bmain, struct SpaceNode *snode, struct bNodeTree *ntree, struct bNode *node, bool *r_active_texture_changed)
Definition: node_edit.cc:659
void ED_spreadsheet_context_paths_set_geometry_node(struct Main *bmain, struct SpaceNode *snode, struct bNode *node)
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
void uiItemR(uiLayout *layout, struct PointerRNA *ptr, const char *propname, int flag, const char *name, int icon)
OperationNode * node
void * tree
bNodeTree * ntree
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
static void node_update(bNodeTree *ntree, bNode *node)
static eNodeSocketDatatype custom_data_type_to_socket_type(const eCustomDataType type)
static void node_init(bNodeTree *UNUSED(tree), bNode *node)
static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
static void node_declare(NodeDeclarationBuilder &b)
static void node_gather_link_searches(GatherLinkSearchOpParams &params)
std::optional< eCustomDataType > node_socket_to_custom_data_type(const bNodeSocket &socket)
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
static void node_init(const struct bContext *C, bNodeTree *ntree, bNode *node)
Definition: node.cc:1082
void register_node_type_geo_viewer()
void geo_node_type_base(bNodeType *ntype, int type, const char *name, short nclass)
void node_copy_standard_storage(bNodeTree *UNUSED(dest_ntree), bNode *dest_node, const bNode *src_node)
Definition: node_util.c:55
void node_free_standard_storage(bNode *node)
Definition: node_util.c:43
Definition: BKE_main.h:121
Defines a node type.
Definition: BKE_node.h:226
NodeGatherSocketLinkOperationsFunction gather_link_search_ops
Definition: BKE_node.h:335
void(* draw_buttons_ex)(struct uiLayout *, struct bContext *C, struct PointerRNA *ptr)
Definition: BKE_node.h:246
NodeDeclareFunction declare
Definition: BKE_node.h:324
#define N_(msgid)
PointerRNA * ptr
Definition: wm_files.c:3480