Blender V4.3
node_geo_warning.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
6
7#include "UI_interface.hh"
8#include "UI_resources.hh"
9
10#include "NOD_rna_define.hh"
11
12#include "RNA_enum_types.hh"
13
15
17{
18 b.use_custom_socket_order();
19 b.allow_any_socket_order();
20
21 b.add_input<decl::Bool>("Show").default_value(true).hide_value();
22 b.add_output<decl::Bool>("Show").align_with_previous();
23 b.add_input<decl::String>("Message").hide_label();
24}
25
27 const bNode &node_;
28
29 public:
30 LazyFunctionForWarningNode(const bNode &node) : node_(node)
31 {
33 inputs_.append_as("Show", type, lf::ValueUsage::Used);
34 inputs_.append_as("Message", type);
35 outputs_.append_as("Show", type);
36 }
37
38 void execute_impl(lf::Params &params, const lf::Context &context) const override
39 {
40 const SocketValueVariant show_variant = params.get_input<SocketValueVariant>(0);
41 const bool show = show_variant.get<bool>();
42 if (!show) {
43 params.set_output(0, show_variant);
44 return;
45 }
46 SocketValueVariant *message_variant =
47 params.try_get_input_data_ptr_or_request<SocketValueVariant>(1);
48 if (!message_variant) {
49 /* Wait for the message to be computed. */
50 return;
51 }
52 std::string message = message_variant->extract<std::string>();
53 GeoNodesLFUserData &user_data = *static_cast<GeoNodesLFUserData *>(context.user_data);
54 GeoNodesLFLocalUserData &local_user_data = *static_cast<GeoNodesLFLocalUserData *>(
55 context.local_user_data);
56 if (geo_eval_log::GeoTreeLogger *tree_logger = local_user_data.try_get_tree_logger(user_data))
57 {
58 tree_logger->node_warnings.append(
59 *tree_logger->allocator,
60 {node_.identifier, {NodeWarningType(node_.custom1), std::move(message)}});
61 }
62 /* Only set output in the end so that this node is not finished before the warning is set. */
63 params.set_output(0, show_variant);
64 }
65};
66
67static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
68{
69 uiLayoutSetPropSep(layout, true);
70 uiLayoutSetPropDecorate(layout, false);
71 uiItemR(layout, ptr, "warning_type", UI_ITEM_NONE, "", ICON_NONE);
72}
73
74static void node_rna(StructRNA *srna)
75{
77 "warning_type",
78 "Warning Type",
79 "",
82}
83
84static void node_register()
85{
86 static blender::bke::bNodeType ntype;
87
88 geo_node_type_base(&ntype, GEO_NODE_WARNING, "Warning", NODE_CLASS_INTERFACE);
89 ntype.declare = node_declare;
92
93 node_rna(ntype.rna_ext.srna);
94}
95NOD_REGISTER_NODE(node_register)
96
97} // namespace blender::nodes::node_geo_warning_cc
98
99namespace blender::nodes {
100
101std::unique_ptr<LazyFunction> get_warning_node_lazy_function(const bNode &node)
102{
103 using namespace node_geo_warning_cc;
104 BLI_assert(node.type == GEO_NODE_WARNING);
105 return std::make_unique<LazyFunctionForWarningNode>(node);
106}
107
108} // namespace blender::nodes
#define NODE_CLASS_INTERFACE
Definition BKE_node.hh:416
#define BLI_assert(a)
Definition BLI_assert.h:50
#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)
void uiItemR(uiLayout *layout, PointerRNA *ptr, const char *propname, eUI_Item_Flag flag, const char *name, int icon)
static const CPPType & get()
void execute_impl(lf::Params &params, const lf::Context &context) const override
local_group_size(16, 16) .push_constant(Type b
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void node_register_type(bNodeType *ntype)
Definition node.cc:1708
static void node_rna(StructRNA *srna)
static void node_declare(NodeDeclarationBuilder &b)
static void node_layout(uiLayout *layout, bContext *, PointerRNA *ptr)
std::unique_ptr< LazyFunction > get_warning_node_lazy_function(const bNode &node)
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, int type, const char *name, short nclass)
const EnumPropertyItem rna_enum_node_warning_type_items[]
StructRNA * srna
Definition RNA_types.hh:780
int16_t custom1
int32_t identifier
Defines a node type.
Definition BKE_node.hh:218
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:238
NodeDeclareFunction declare
Definition BKE_node.hh:347
geo_eval_log::GeoTreeLogger * try_get_tree_logger(const GeoNodesLFUserData &user_data) const
PointerRNA * ptr
Definition wm_files.cc:4126