Refactor: Geometry Nodes: extract warning type to separate file

It should be possible to use this type without having to include the
entire logging system.
This commit is contained in:
Jacques Lucke
2025-05-27 05:50:38 +02:00
parent 0d531078c6
commit 6f83928c6b
12 changed files with 75 additions and 58 deletions

View File

@@ -727,7 +727,7 @@ static wmOperatorStatus run_node_group_exec(bContext *C, wmOperator *op)
geo_log::GeoTreeLog &tree_log = eval_log.log->get_tree_log(compute_context.hash());
tree_log.ensure_node_warnings(*bmain);
for (const geo_log::NodeWarning &warning : tree_log.all_warnings) {
if (warning.type == geo_log::NodeWarningType::Info) {
if (warning.type == nodes::NodeWarningType::Info) {
BKE_report(op->reports, RPT_INFO, warning.message.c_str());
}
else {

View File

@@ -2657,10 +2657,10 @@ static void node_draw_panels(bNodeTree &ntree, const bNode &node, uiBlock &block
}
}
static geo_log::NodeWarningType node_error_highest_priority(Span<geo_log::NodeWarning> warnings)
static nodes::NodeWarningType node_error_highest_priority(Span<geo_log::NodeWarning> warnings)
{
int highest_priority = 0;
geo_log::NodeWarningType highest_priority_type = geo_log::NodeWarningType::Info;
nodes::NodeWarningType highest_priority_type = nodes::NodeWarningType::Info;
for (const geo_log::NodeWarning &warning : warnings) {
const int priority = node_warning_type_severity(warning.type);
if (priority > highest_priority) {
@@ -2747,14 +2747,14 @@ static void node_add_error_message_button(const TreeDrawContext &tree_draw_ctx,
return;
}
const geo_log::NodeWarningType display_type = node_error_highest_priority(warnings);
const nodes::NodeWarningType display_type = node_error_highest_priority(warnings);
icon_offset -= NODE_HEADER_ICON_SIZE;
UI_block_emboss_set(&block, blender::ui::EmbossType::None);
uiBut *but = uiDefIconBut(&block,
UI_BTYPE_BUT,
0,
geo_log::node_warning_type_icon(display_type),
nodes::node_warning_type_icon(display_type),
icon_offset,
rect.ymax - NODE_DY,
NODE_HEADER_ICON_SIZE,

View File

@@ -553,13 +553,9 @@ const EnumPropertyItem rna_enum_shrinkwrap_face_cull_items[] = {
};
const EnumPropertyItem rna_enum_node_warning_type_items[] = {
{int(blender::nodes::geo_eval_log::NodeWarningType::Error), "ERROR", ICON_CANCEL, "Error", ""},
{int(blender::nodes::geo_eval_log::NodeWarningType::Warning),
"WARNING",
ICON_ERROR,
"Warning",
""},
{int(blender::nodes::geo_eval_log::NodeWarningType::Info), "INFO", ICON_INFO, "Info", ""},
{int(blender::nodes::NodeWarningType::Error), "ERROR", ICON_CANCEL, "Error", ""},
{int(blender::nodes::NodeWarningType::Warning), "WARNING", ICON_ERROR, "Warning", ""},
{int(blender::nodes::NodeWarningType::Info), "INFO", ICON_INFO, "Info", ""},
{0, nullptr, 0, nullptr, nullptr},
};

View File

@@ -80,6 +80,7 @@ set(SRC
intern/geometry_nodes_lazy_function.cc
intern/geometry_nodes_log.cc
intern/geometry_nodes_repeat_zone.cc
intern/geometry_nodes_warning.cc
intern/inverse_eval.cc
intern/math_functions.cc
intern/node_common.cc
@@ -115,6 +116,7 @@ set(SRC
NOD_geometry_nodes_gizmos.hh
NOD_geometry_nodes_lazy_function.hh
NOD_geometry_nodes_log.hh
NOD_geometry_nodes_warning.hh
NOD_inverse_eval_params.hh
NOD_inverse_eval_path.hh
NOD_inverse_eval_run.hh

View File

@@ -59,7 +59,6 @@ using fn::FieldInput;
using fn::FieldOperation;
using fn::GField;
using geo_eval_log::NamedAttributeUsage;
using geo_eval_log::NodeWarningType;
class NodeAttributeFilter : public AttributeFilter {
private:

View File

@@ -42,6 +42,7 @@
#include "BKE_volume_grid_fwd.hh"
#include "NOD_geometry_nodes_closure_location.hh"
#include "NOD_geometry_nodes_warning.hh"
#include "NOD_socket_interface_key.hh"
#include "FN_field.hh"
@@ -56,16 +57,6 @@ namespace blender::nodes::geo_eval_log {
using fn::GField;
/** These values are also written to .blend files, so don't change them lightly. */
enum class NodeWarningType {
Error = 0,
Warning = 1,
Info = 2,
};
int node_warning_type_icon(NodeWarningType type);
int node_warning_type_severity(NodeWarningType type);
struct NodeWarning {
NodeWarningType type;
std::string message;

View File

@@ -0,0 +1,19 @@
/* SPDX-FileCopyrightText: 2025 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma once
namespace blender::nodes {
/** These values are also written to .blend files, so don't change them lightly. */
enum class NodeWarningType {
Error = 0,
Warning = 1,
Info = 2,
};
int node_warning_type_icon(NodeWarningType type);
int node_warning_type_severity(NodeWarningType type);
} // namespace blender::nodes

View File

@@ -347,7 +347,7 @@ class LazyFunctionForEvaluateClosureNode : public LazyFunction {
tree_logger->node_warnings.append(
*tree_logger->allocator,
{bnode_.identifier,
{geo_eval_log::NodeWarningType::Error, TIP_("Recursive closure is not allowed")}});
{NodeWarningType::Error, TIP_("Recursive closure is not allowed")}});
}
this->set_default_outputs(params);
return;
@@ -436,7 +436,7 @@ class LazyFunctionForEvaluateClosureNode : public LazyFunction {
tree_logger->node_warnings.append(
*tree_logger->allocator,
{bnode_.identifier,
{geo_eval_log::NodeWarningType::Error,
{NodeWarningType::Error,
fmt::format(fmt::runtime(TIP_("Closure input has incompatible type: \"{}\"")),
item.name)}});
}
@@ -446,7 +446,7 @@ class LazyFunctionForEvaluateClosureNode : public LazyFunction {
*tree_logger->allocator,
{bnode_.identifier,
{
geo_eval_log::NodeWarningType::Error,
NodeWarningType::Error,
fmt::format(fmt::runtime(TIP_("Closure does not have input: \"{}\"")), item.name),
}});
}
@@ -463,7 +463,7 @@ class LazyFunctionForEvaluateClosureNode : public LazyFunction {
tree_logger->node_warnings.append(
*tree_logger->allocator,
{bnode_.identifier,
{geo_eval_log::NodeWarningType::Error,
{NodeWarningType::Error,
fmt::format(fmt::runtime(TIP_("Closure output has incompatible type: \"{}\"")),
item.name)}});
}
@@ -472,7 +472,7 @@ class LazyFunctionForEvaluateClosureNode : public LazyFunction {
tree_logger->node_warnings.append(
*tree_logger->allocator,
{bnode_.identifier,
{geo_eval_log::NodeWarningType::Error,
{NodeWarningType::Error,
fmt::format(fmt::runtime(TIP_("Closure does not have output: \"{}\"")),
item.name)}});
}

View File

@@ -342,7 +342,7 @@ class LazyFunctionForForeachGeometryElementZone : public LazyFunction {
tree_logger->node_warnings.append(
*tree_logger->allocator,
{zone_.input_node()->identifier,
{geo_eval_log::NodeWarningType::Info,
{NodeWarningType::Info,
N_("Input geometry has no elements in the iteration domain.")}});
}
}

View File

@@ -966,34 +966,6 @@ const ViewerNodeLog *GeoNodesLog::find_viewer_node_log_for_path(const ViewerPath
return viewer_log;
}
int node_warning_type_icon(const NodeWarningType type)
{
switch (type) {
case NodeWarningType::Error:
return ICON_CANCEL;
case NodeWarningType::Warning:
return ICON_ERROR;
case NodeWarningType::Info:
return ICON_INFO;
}
BLI_assert_unreachable();
return ICON_ERROR;
}
int node_warning_type_severity(const NodeWarningType type)
{
switch (type) {
case NodeWarningType::Error:
return 3;
case NodeWarningType::Warning:
return 2;
case NodeWarningType::Info:
return 1;
}
BLI_assert_unreachable();
return 0;
}
ContextualGeoTreeLogs::ContextualGeoTreeLogs(
Map<const bke::bNodeTreeZone *, GeoTreeLog *> tree_logs_by_zone)
: tree_logs_by_zone_(std::move(tree_logs_by_zone))

View File

@@ -216,7 +216,7 @@ class LazyFunctionForRepeatZone : public LazyFunction {
tree_logger->node_warnings.append(
*tree_logger->allocator,
{repeat_output_bnode_.identifier,
{geo_eval_log::NodeWarningType::Info, N_("Inspection index is out of range")}});
{NodeWarningType::Info, N_("Inspection index is out of range")}});
}
}
}

View File

@@ -0,0 +1,38 @@
/* SPDX-FileCopyrightText: 2025 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#include "NOD_geometry_nodes_warning.hh"
#include "UI_resources.hh"
namespace blender::nodes {
int node_warning_type_icon(const NodeWarningType type)
{
switch (type) {
case NodeWarningType::Error:
return ICON_CANCEL;
case NodeWarningType::Warning:
return ICON_ERROR;
case NodeWarningType::Info:
return ICON_INFO;
}
BLI_assert_unreachable();
return ICON_ERROR;
}
int node_warning_type_severity(const NodeWarningType type)
{
switch (type) {
case NodeWarningType::Error:
return 3;
case NodeWarningType::Warning:
return 2;
case NodeWarningType::Info:
return 1;
}
BLI_assert_unreachable();
return 0;
}
} // namespace blender::nodes