Blender V5.0
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
8#include "UI_resources.hh"
9
10#include "BLI_string_utf8.h"
11
12#include "NOD_rna_define.hh"
13#include "RNA_access.hh"
14#include "RNA_enum_types.hh"
15
17
19{
20 b.use_custom_socket_order();
21 b.allow_any_socket_order();
22
23 b.add_default_layout();
24
25 b.add_input<decl::Bool>("Show").default_value(true).hide_value();
26 b.add_output<decl::Bool>("Show").align_with_previous();
27 b.add_input<decl::String>("Message").optional_label();
28}
29
31 const bNode &node_;
32
33 public:
34 LazyFunctionForWarningNode(const bNode &node) : node_(node)
35 {
36 debug_name_ = "Warning";
38 inputs_.append_as("Show", type, lf::ValueUsage::Used);
39 inputs_.append_as("Message", type);
40 outputs_.append_as("Show", type);
41 }
42
43 void execute_impl(lf::Params &params, const lf::Context &context) const override
44 {
45 const SocketValueVariant show_variant = params.get_input<SocketValueVariant>(0);
46 const bool show = show_variant.get<bool>();
47 if (!show) {
48 params.set_output(0, show_variant);
49 return;
50 }
51 SocketValueVariant *message_variant =
52 params.try_get_input_data_ptr_or_request<SocketValueVariant>(1);
53 if (!message_variant) {
54 /* Wait for the message to be computed. */
55 return;
56 }
57 std::string message = message_variant->extract<std::string>();
58 GeoNodesUserData &user_data = *static_cast<GeoNodesUserData *>(context.user_data);
59 GeoNodesLocalUserData &local_user_data = *static_cast<GeoNodesLocalUserData *>(
60 context.local_user_data);
61 if (geo_eval_log::GeoTreeLogger *tree_logger = local_user_data.try_get_tree_logger(user_data))
62 {
63 tree_logger->node_warnings.append(
64 *tree_logger->allocator,
65 {node_.identifier, {NodeWarningType(node_.custom1), std::move(message)}});
66 }
67 /* Only set output in the end so that this node is not finished before the warning is set. */
68 params.set_output(0, show_variant);
69 }
70};
71
72static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
73{
74 layout->use_property_split_set(true);
75 layout->use_property_decorate_set(false);
76 layout->prop(ptr, "warning_type", UI_ITEM_NONE, "", ICON_NONE);
77}
78
79static void node_rna(StructRNA *srna)
80{
82 "warning_type",
83 "Warning Type",
84 "",
87}
88
89static void node_label(const bNodeTree * /*ntree*/,
90 const bNode *node,
91 char *label,
92 int label_maxncpy)
93{
94 const char *name;
96 if (!enum_label) {
97 name = N_("Unknown");
98 }
99 BLI_strncpy_utf8(label, IFACE_(name), label_maxncpy);
100}
101
102static void node_register()
103{
104 static blender::bke::bNodeType ntype;
105
106 geo_node_type_base(&ntype, "GeometryNodeWarning", GEO_NODE_WARNING);
107 ntype.ui_name = "Warning";
108 ntype.ui_description = "Create custom warnings in node groups";
109 ntype.enum_name_legacy = "WARNING";
111 ntype.declare = node_declare;
112 ntype.labelfunc = node_label;
115
116 node_rna(ntype.rna_ext.srna);
117}
118NOD_REGISTER_NODE(node_register)
119
120} // namespace blender::nodes::node_geo_warning_cc
121
122namespace blender::nodes {
123
124std::unique_ptr<LazyFunction> get_warning_node_lazy_function(const bNode &node)
125{
126 using namespace node_geo_warning_cc;
128 return std::make_unique<LazyFunctionForWarningNode>(node);
129}
130
131} // namespace blender::nodes
#define NODE_CLASS_INTERFACE
Definition BKE_node.hh:459
#define GEO_NODE_WARNING
#define BLI_assert(a)
Definition BLI_assert.h:46
char * BLI_strncpy_utf8(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
#define IFACE_(msgid)
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define NOD_inline_enum_accessors(member)
#define UI_ITEM_NONE
static const CPPType & get()
void execute_impl(lf::Params &params, const lf::Context &context) const override
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void node_register_type(bNodeType &ntype)
Definition node.cc:2416
static void node_rna(StructRNA *srna)
static void node_declare(NodeDeclarationBuilder &b)
static void node_layout(uiLayout *layout, bContext *, PointerRNA *ptr)
static void node_label(const bNodeTree *, const bNode *node, char *label, int label_maxncpy)
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, std::string idname, const std::optional< int16_t > legacy_type)
const char * name
bool RNA_enum_name(const EnumPropertyItem *item, const int value, const char **r_name)
const EnumPropertyItem rna_enum_node_warning_type_items[]
StructRNA * srna
int16_t custom1
int16_t type_legacy
Defines a node type.
Definition BKE_node.hh:238
std::string ui_description
Definition BKE_node.hh:244
void(* labelfunc)(const bNodeTree *ntree, const bNode *node, char *label, int label_maxncpy)
Definition BKE_node.hh:270
const char * enum_name_legacy
Definition BKE_node.hh:247
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:259
NodeDeclareFunction declare
Definition BKE_node.hh:362
geo_eval_log::GeoTreeLogger * try_get_tree_logger(const GeoNodesUserData &user_data) const
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)
#define N_(msgid)
PointerRNA * ptr
Definition wm_files.cc:4238