From 0ed43f45d6b22d55fb92288855adfb7b52f8a154 Mon Sep 17 00:00:00 2001 From: Iliya Katueshenock Date: Thu, 11 Apr 2024 01:23:40 +0300 Subject: [PATCH 1/4] init --- .../blender/editors/space_node/node_draw.cc | 169 ++++++++++++------ 1 file changed, 112 insertions(+), 57 deletions(-) diff --git a/source/blender/editors/space_node/node_draw.cc b/source/blender/editors/space_node/node_draw.cc index 607932e6807..51d32d3eaf2 100644 --- a/source/blender/editors/space_node/node_draw.cc +++ b/source/blender/editors/space_node/node_draw.cc @@ -1480,9 +1480,7 @@ static void create_inspection_string_for_geometry_info(const geo_log::GeometryIn } } -static void create_inspection_string_for_geometry_socket(std::stringstream &ss, - const nodes::decl::Geometry *socket_decl, - const bool after_log) +static void create_inspection_string_for_geometry_socket(std::stringstream &ss, const nodes::decl::Geometry *socket_decl) { /* If the geometry declaration is null, as is the case for input to group output, * or it is an output socket don't show supported types. */ @@ -1490,10 +1488,6 @@ static void create_inspection_string_for_geometry_socket(std::stringstream &ss, return; } - if (after_log) { - ss << ".\n\n"; - } - Span supported_types = socket_decl->supported_types(); if (supported_types.is_empty()) { ss << TIP_("Supported: All Types"); @@ -1537,40 +1531,105 @@ static void create_inspection_string_for_geometry_socket(std::stringstream &ss, } } -static std::optional create_socket_inspection_string( - geo_log::GeoTreeLog &geo_tree_log, const bNodeSocket &socket) +static void create_inspection_string_for_default_socket_value(const bNodeSocket &socket, std::stringstream &ss) +{ + if (!socket.is_input()) { + return; + } + if (socket.is_directly_linked()) { + return; + } + if (socket.flag & SOCK_HIDE_VALUE) { + return; + } + + if (socket.typeinfo->base_cpp_type == nullptr) { + return; + } + + const CPPType &value_type = *socket.typeinfo->base_cpp_type; + BUFFER_FOR_CPP_TYPE_VALUE(value_type, socket_value); + socket.typeinfo->get_base_cpp_value(socket.default_value, socket_value); + create_inspection_string_for_generic_value(socket, GPointer(value_type, socket_value), ss); + value_type.destruct(socket_value); +} + +static std::optional create_description_inspection_string(const bNodeSocket &socket) +{ + if (socket.runtime->declaration == nullptr) { + return std::nullopt; + } + const blender::nodes::SocketDeclaration &socket_decl = *socket.runtime->declaration; + blender::StringRef description = socket_decl.description; + if (description.is_empty()) { + return std::nullopt; + } + + return TIP_(description.data()); +} + +static std::optional create_log_inspection_string(geo_log::GeoTreeLog *geo_tree_log, const bNodeSocket &socket) { using namespace blender::nodes::geo_eval_log; + if (geo_tree_log == nullptr) { + return std::nullopt; + } if (socket.typeinfo->base_cpp_type == nullptr) { return std::nullopt; } - geo_tree_log.ensure_socket_values(); - ValueLog *value_log = geo_tree_log.find_socket_value_log(socket); + geo_tree_log->ensure_socket_values(); + ValueLog *value_log = geo_tree_log->find_socket_value_log(socket); std::stringstream ss; - if (const geo_log::GenericValueLog *generic_value_log = - dynamic_cast(value_log)) + if (const geo_log::GenericValueLog *generic_value_log = dynamic_cast(value_log)) { create_inspection_string_for_generic_value(socket, generic_value_log->value, ss); } - else if (const geo_log::FieldInfoLog *gfield_value_log = - dynamic_cast(value_log)) + else if (const geo_log::FieldInfoLog *gfield_value_log = dynamic_cast(value_log)) { create_inspection_string_for_field_info(socket, *gfield_value_log, ss); } - else if (const geo_log::GeometryInfoLog *geo_value_log = - dynamic_cast(value_log)) + else if (const geo_log::GeometryInfoLog *geo_value_log = dynamic_cast(value_log)) { create_inspection_string_for_geometry_info(*geo_value_log, ss); } - if (const nodes::decl::Geometry *socket_decl = dynamic_cast( - socket.runtime->declaration)) - { - const bool after_log = value_log != nullptr; - create_inspection_string_for_geometry_socket(ss, socket_decl, after_log); + std::string str = ss.str(); + if (str.empty()) { + return std::nullopt; } + return str; +} + +static std::optional create_declaration_inspection_string(const bNodeSocket &socket) +{ + std::stringstream ss; + if (const nodes::decl::Geometry *socket_decl = dynamic_cast(socket.runtime->declaration)) + { + create_inspection_string_for_geometry_socket(ss, socket_decl); + } + + if (const const nodes::SocketDeclaration * socket_decl = socket.runtime->declaration) { + if (socket_decl->input_field_type == nodes::InputSocketFieldType::Implicit) { + if (!ss.str().empty()) { + ss << ".\n\n"; + } + ss << TIP_("Implicit field input"); + } + } + + std::string str = ss.str(); + if (str.empty()) { + return std::nullopt; + } + return str; +} + +static std::optional create_default_value_inspection_string(const bNodeSocket &socket) +{ + std::stringstream ss; + create_inspection_string_for_default_socket_value(socket, ss); std::string str = ss.str(); if (str.empty()) { @@ -1581,16 +1640,7 @@ static std::optional create_socket_inspection_string( static bool node_socket_has_tooltip(const bNodeTree &ntree, const bNodeSocket &socket) { - if (ntree.type == NTREE_GEOMETRY) { - return true; - } - - if (socket.runtime->declaration != nullptr) { - const nodes::SocketDeclaration &socket_decl = *socket.runtime->declaration; - return !socket_decl.description.empty(); - } - - return false; + return true; } static std::string node_socket_get_tooltip(const SpaceNode *snode, @@ -1600,19 +1650,12 @@ static std::string node_socket_get_tooltip(const SpaceNode *snode, TreeDrawContext tree_draw_ctx; if (snode != nullptr) { if (ntree.type == NTREE_GEOMETRY) { - tree_draw_ctx.geo_log_by_zone = - geo_log::GeoModifierLog::get_tree_log_by_zone_for_node_editor(*snode); + tree_draw_ctx.geo_log_by_zone = geo_log::GeoModifierLog::get_tree_log_by_zone_for_node_editor(*snode); } } - std::stringstream output; - if (socket.runtime->declaration != nullptr) { - const blender::nodes::SocketDeclaration &socket_decl = *socket.runtime->declaration; - blender::StringRef description = socket_decl.description; - if (!description.is_empty()) { - output << TIP_(description.data()); - } - } + bool value_is_mentioned = false; + Vector inspection_strings; geo_log::GeoTreeLog *geo_tree_log = [&]() -> geo_log::GeoTreeLog * { const bNodeTreeZones *zones = ntree.zones(); @@ -1623,25 +1666,37 @@ static std::string node_socket_get_tooltip(const SpaceNode *snode, return tree_draw_ctx.geo_log_by_zone.lookup_default(zone, nullptr); }(); - if (ntree.type == NTREE_GEOMETRY && geo_tree_log != nullptr) { - if (!output.str().empty()) { - output << ".\n\n"; - } - - std::optional socket_inspection_str = create_socket_inspection_string( - *geo_tree_log, socket); - if (socket_inspection_str.has_value()) { - output << *socket_inspection_str; - } - else { - output << TIP_( - "Unknown socket value. Either the socket was not used or its value was not logged " - "during the last evaluation"); + if (std::optional info = create_description_inspection_string(socket)) { + inspection_strings.append(std::move(*info)); + } + if (std::optional info = create_log_inspection_string(geo_tree_log, socket)) { + inspection_strings.append(std::move(*info)); + value_is_mentioned = true; + } + if (std::optional info = create_declaration_inspection_string(socket)) { + inspection_strings.append(std::move(*info)); + } + if (!value_is_mentioned) { + if (std::optional info = create_default_value_inspection_string(socket)) { + inspection_strings.append(std::move(*info)); } } - if (output.str().empty()) { + std::stringstream output; + for (const std::string &info : inspection_strings) { + output << info; + if (&info != &inspection_strings.last()) { + output << ".\n\n"; + } + } + + if (inspection_strings.is_empty()) { output << bke::nodeSocketLabel(&socket); + + if (ntree.type == NTREE_GEOMETRY) { + output << ".\n\n"; + output << TIP_("Unknown socket value. Either the socket was not used or its value was not logged during the last evaluation"); + } } return output.str(); -- 2.30.2 From 3cab0b4ffb680976abe5802570054dbaf02b1971 Mon Sep 17 00:00:00 2001 From: Iliya Katueshenock Date: Thu, 11 Apr 2024 01:34:28 +0300 Subject: [PATCH 2/4] cleanup --- source/blender/editors/space_node/node_draw.cc | 9 --------- 1 file changed, 9 deletions(-) diff --git a/source/blender/editors/space_node/node_draw.cc b/source/blender/editors/space_node/node_draw.cc index c118f47e132..9ef37e7a5c0 100644 --- a/source/blender/editors/space_node/node_draw.cc +++ b/source/blender/editors/space_node/node_draw.cc @@ -1593,15 +1593,6 @@ static std::optional create_declaration_inspection_string(const bNo create_inspection_string_for_geometry_socket(ss, socket_decl); } - if (const nodes::SocketDeclaration *socket_decl = socket.runtime->declaration) { - if (socket_decl->input_field_type == nodes::InputSocketFieldType::Implicit) { - if (!ss.str().empty()) { - ss << ".\n\n"; - } - ss << TIP_("Implicit field input"); - } - } - std::string str = ss.str(); if (str.empty()) { return std::nullopt; -- 2.30.2 From 183eff45caf80a61c766e9e4539bda106eaea4ca Mon Sep 17 00:00:00 2001 From: Iliya Katueshenock Date: Thu, 11 Apr 2024 01:45:42 +0300 Subject: [PATCH 3/4] progress --- source/blender/editors/space_node/node_draw.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/blender/editors/space_node/node_draw.cc b/source/blender/editors/space_node/node_draw.cc index 9ef37e7a5c0..3d66329ad6c 100644 --- a/source/blender/editors/space_node/node_draw.cc +++ b/source/blender/editors/space_node/node_draw.cc @@ -1612,8 +1612,6 @@ static std::string node_socket_get_tooltip(const SpaceNode *snode, } } - Vector inspection_strings; - geo_log::GeoTreeLog *geo_tree_log = [&]() -> geo_log::GeoTreeLog * { const bNodeTreeZones *zones = ntree.zones(); if (!zones) { @@ -1623,6 +1621,8 @@ static std::string node_socket_get_tooltip(const SpaceNode *snode, return tree_draw_ctx.geo_log_by_zone.lookup_default(zone, nullptr); }(); + Vector inspection_strings; + if (std::optional info = create_description_inspection_string(socket)) { inspection_strings.append(std::move(*info)); } -- 2.30.2 From f89a6bc80405d76c1f3dbd131d8b23ae0a2ea274 Mon Sep 17 00:00:00 2001 From: Iliya Katueshenock Date: Thu, 11 Apr 2024 18:41:52 +0300 Subject: [PATCH 4/4] init --- source/blender/editors/space_node/node_draw.cc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/source/blender/editors/space_node/node_draw.cc b/source/blender/editors/space_node/node_draw.cc index 92824d2a044..8db31a56647 100644 --- a/source/blender/editors/space_node/node_draw.cc +++ b/source/blender/editors/space_node/node_draw.cc @@ -1641,7 +1641,15 @@ static std::string node_socket_get_tooltip(const SpaceNode *snode, } if (inspection_strings.is_empty()) { - output << bke::nodeSocketLabel(&socket); + const bNode &node = socket.owner_node(); + if (node.is_reroute()) { + char reroute_name[64]; + bke::nodeLabel(&ntree, &node, reroute_name, sizeof(reroute_name)); + output << reroute_name; + } + else { + output << bke::nodeSocketLabel(&socket); + } if (ntree.type == NTREE_GEOMETRY) { output << ".\n\n"; -- 2.30.2