Geometry Nodes: Add legacy warning and "View Legacy" operator

This commit adds warning messages to "legacy" nodes that will be
removed in the future. The warning is shown in the node header, but
it is not printed in the terminal or displayed in the modifier. It is
also not propogated to node groups, but that is a more general task.

If the modifier's node tree has executed a deprecated node, it will
display a warning and a "Search" button that will select the nodes and
pan to them in the node editor. This doesn't open child node trees and
select nodes in there, because I want to keep this operator simple and
avoid wasting a lot of time perfecting this behavior.

Differential Revision: https://developer.blender.org/D12454
This commit is contained in:
Hans Goudey 2021-09-21 17:17:40 -05:00
parent 8324ac8457
commit 41e3bf8a8e
Notes: blender-bot 2023-11-20 12:14:32 +01:00
Referenced by issue #91216, Deprecated nodes in the UI
7 changed files with 121 additions and 2 deletions

View File

@ -1446,6 +1446,8 @@ static int node_error_type_to_icon(const geo_log::NodeWarningType type)
return ICON_ERROR;
case geo_log::NodeWarningType::Info:
return ICON_INFO;
case geo_log::NodeWarningType::Legacy:
return ICON_ERROR;
}
BLI_assert(false);
@ -1456,6 +1458,8 @@ static uint8_t node_error_type_priority(const geo_log::NodeWarningType type)
{
switch (type) {
case geo_log::NodeWarningType::Error:
return 4;
case geo_log::NodeWarningType::Legacy:
return 3;
case geo_log::NodeWarningType::Warning:
return 2;

View File

@ -175,6 +175,7 @@ int space_node_view_flag(struct bContext *C,
void NODE_OT_view_all(struct wmOperatorType *ot);
void NODE_OT_view_selected(struct wmOperatorType *ot);
void NODE_OT_geometry_node_view_legacy(struct wmOperatorType *ot);
void NODE_OT_backimage_move(struct wmOperatorType *ot);
void NODE_OT_backimage_zoom(struct wmOperatorType *ot);

View File

@ -51,6 +51,7 @@ void node_operatortypes(void)
WM_operatortype_append(NODE_OT_view_all);
WM_operatortype_append(NODE_OT_view_selected);
WM_operatortype_append(NODE_OT_geometry_node_view_legacy);
WM_operatortype_append(NODE_OT_mute_toggle);
WM_operatortype_append(NODE_OT_hide_toggle);

View File

@ -23,8 +23,10 @@
#include "DNA_node_types.h"
#include "BLI_listbase.h"
#include "BLI_math.h"
#include "BLI_rect.h"
#include "BLI_string_ref.hh"
#include "BLI_utildefines.h"
#include "BKE_context.h"
@ -54,6 +56,8 @@
#include "node_intern.h" /* own include */
using blender::StringRef;
/* -------------------------------------------------------------------- */
/** \name View All Operator
* \{ */
@ -700,3 +704,89 @@ void NODE_OT_backimage_sample(wmOperatorType *ot)
}
/** \} */
/* -------------------------------------------------------------------- */
/** \name View Geometry Nodes Legacy Operator
*
* This operator should be removed when the 2.93 legacy nodes are removed.
* \{ */
static int space_node_view_geometry_nodes_legacy(bContext *C, SpaceNode *snode, wmOperator *op)
{
ARegion *region = CTX_wm_region(C);
/* Only use the node editor's active node tree. Otherwise this will be too complicated. */
bNodeTree *node_tree = snode->nodetree;
if (node_tree == nullptr || node_tree->type != NTREE_GEOMETRY) {
return OPERATOR_CANCELLED;
}
bool found_legacy_node = false;
LISTBASE_FOREACH_BACKWARD (bNode *, node, &node_tree->nodes) {
StringRef idname{node->idname};
if (idname.find("Legacy") == StringRef::not_found) {
node->flag &= ~NODE_SELECT;
}
else {
found_legacy_node = true;
node->flag |= NODE_SELECT;
}
}
if (!found_legacy_node) {
WM_report(RPT_INFO, "Legacy node not found, may be in nested node group");
}
const int smooth_viewtx = WM_operator_smooth_viewtx_get(op);
if (space_node_view_flag(C, snode, region, NODE_SELECT, smooth_viewtx)) {
return OPERATOR_FINISHED;
}
return OPERATOR_CANCELLED;
}
static int geometry_node_view_legacy_exec(bContext *C, wmOperator *op)
{
/* Allow running this operator directly in a specific node editor. */
if (SpaceNode *snode = CTX_wm_space_node(C)) {
return space_node_view_geometry_nodes_legacy(C, snode, op);
}
/* Since the operator is meant to be called from a button in the modifier panel, the node tree
* must be found from the screen, using the largest node editor if there is more than one. */
if (ScrArea *area = BKE_screen_find_big_area(CTX_wm_screen(C), SPACE_NODE, 0)) {
if (SpaceNode *snode = static_cast<SpaceNode *>(area->spacedata.first)) {
ScrArea *old_area = CTX_wm_area(C);
ARegion *old_region = CTX_wm_region(C);
/* Override the context since it is used by the View2D panning code. */
CTX_wm_area_set(C, area);
CTX_wm_region_set(C, static_cast<ARegion *>(area->regionbase.last));
const int result = space_node_view_geometry_nodes_legacy(C, snode, op);
CTX_wm_area_set(C, old_area);
CTX_wm_region_set(C, old_region);
return result;
}
}
return OPERATOR_CANCELLED;
}
static bool geometry_node_view_legacy_poll(bContext *C)
{
/* Allow direct execution in a node editor, but also affecting any visible node editor. */
return ED_operator_node_active(C) || BKE_screen_find_big_area(CTX_wm_screen(C), SPACE_NODE, 0);
}
void NODE_OT_geometry_node_view_legacy(wmOperatorType *ot)
{
ot->name = "View Deprecated Geometry Nodes";
ot->idname = "NODE_OT_geometry_node_view_legacy";
ot->description = "Select and view legacy geometry nodes in the node editor";
ot->exec = geometry_node_view_legacy_exec;
ot->poll = geometry_node_view_legacy_poll;
ot->flag = OPTYPE_INTERNAL;
}
/** \} */

View File

@ -68,6 +68,8 @@
#include "UI_interface.h"
#include "UI_resources.h"
#include "BLT_translation.h"
#include "WM_types.h"
#include "RNA_access.h"
@ -1090,17 +1092,29 @@ static void panel_draw(const bContext *C, Panel *panel)
}
/* Draw node warnings. */
bool has_legacy_node = false;
if (nmd->runtime_eval_log != nullptr) {
const geo_log::ModifierLog &log = *static_cast<geo_log::ModifierLog *>(nmd->runtime_eval_log);
log.foreach_node_log([layout](const geo_log::NodeLog &node_log) {
log.foreach_node_log([&](const geo_log::NodeLog &node_log) {
for (const geo_log::NodeWarning &warning : node_log.warnings()) {
if (warning.type != geo_log::NodeWarningType::Info) {
if (warning.type == geo_log::NodeWarningType::Legacy) {
has_legacy_node = true;
}
else if (warning.type != geo_log::NodeWarningType::Info) {
uiItemL(layout, warning.message.c_str(), ICON_ERROR);
}
}
});
}
if (USER_EXPERIMENTAL_TEST(&U, use_geometry_nodes_fields) && has_legacy_node) {
uiLayout *row = uiLayoutRow(layout, false);
uiItemL(row, IFACE_("Node tree has legacy node"), ICON_ERROR);
uiLayout *sub = uiLayoutRow(row, false);
uiLayoutSetAlignment(sub, UI_LAYOUT_ALIGN_RIGHT);
uiItemO(sub, "", ICON_VIEWZOOM, "NODE_OT_geometry_node_view_legacy");
}
modifier_panel_end(layout, ptr);
}

View File

@ -26,6 +26,8 @@
#include "FN_generic_value_map.hh"
#include "FN_multi_function.hh"
#include "BLT_translation.h"
#include "BLI_enumerable_thread_specific.hh"
#include "BLI_stack.hh"
#include "BLI_task.h"
@ -868,6 +870,12 @@ class GeometryNodesEvaluator {
NodeParamsProvider params_provider{*this, node, node_state};
GeoNodeExecParams params{params_provider};
if (USER_EXPERIMENTAL_TEST(&U, use_geometry_nodes_fields)) {
if (node->idname().find("Legacy") != StringRef::not_found) {
params.error_message_add(geo_log::NodeWarningType::Legacy,
TIP_("Legacy node will be removed before Blender 4.0"));
}
}
bnode.typeinfo->geometry_node_execute(params);
}

View File

@ -131,6 +131,7 @@ enum class NodeWarningType {
Error,
Warning,
Info,
Legacy,
};
struct NodeWarning {