Blender V5.3
node_socket_tooltip.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2025 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <fmt/format.h>
10#include <sstream>
11
12#include "BKE_context.hh"
13#include "BKE_idtype.hh"
14#include "BKE_lib_id.hh"
15#include "BKE_node_enum.hh"
16#include "BKE_node_runtime.hh"
18
20#include "BLI_math_base.hh"
21#include "BLI_math_euler.hh"
22#include "BLI_math_matrix.hh"
24#include "BLI_string.hh"
25
26#include "BLT_translation.hh"
27
29#include "DNA_material_types.h"
30
31#include "NOD_eval_log.hh"
32#include "NOD_menu_value.hh"
34#include "NOD_socket.hh"
36
37#include "ED_node.hh"
38
39#include "node_intern.hh"
40
41namespace blender {
42
43namespace eval_log = nodes::eval_log;
44
45namespace ed::space_node {
46
48 private:
49 ui::TooltipData &tip_data_;
50 const bNodeTree &tree_;
51 const bNode &node_;
52 const bNodeSocket &socket_;
53 ui::Button *but_ = nullptr;
54 bContext &C_;
55 int indentation_ = 0;
56
57 enum class TooltipBlockType {
58 Label,
59 Description,
60 Value,
62 Python,
63 };
64
65 std::optional<TooltipBlockType> last_block_type_;
66
67 public:
69 const bNodeTree &tree,
70 const bNodeSocket &socket,
71 bContext &C,
72 ui::Button *but)
73 : tip_data_(tip_data),
74 tree_(tree),
75 node_(socket.owner_node()),
76 socket_(socket),
77 but_(but),
78 C_(C)
79 {
80 }
81
82 void build()
83 {
84 const bool is_extend = StringRef(socket_.idname) == "NodeSocketVirtual";
85 if (is_extend) {
86 this->build_tooltip_extend_socket();
87 return;
88 }
89 if (node_.is_dangling_reroute()) {
90 this->build_tooltip_dangling_reroute();
91 return;
92 }
93 if (this->should_show_label()) {
94 this->build_tooltip_label();
95 }
96 this->build_tooltip_description();
97 this->build_tooltip_value();
98 this->build_tooltip_expected_bundle_type();
99 this->build_python();
100
101 /* Extra padding at the bottom. */
102 this->add_space();
103 }
104
105 private:
106 void build_tooltip_extend_socket()
107 {
108 this->add_text_field(TIP_("Connect a link to create a new socket."));
109 }
110
111 void build_tooltip_dangling_reroute()
112 {
113 this->add_text_field(TIP_("Dangling reroute nodes are ignored."), ui::TIP_LC_ALERT);
114 }
115
116 bool should_show_label()
117 {
118 if (this->get_socket_description().value_or("").empty()) {
119 /* Show label when the description is empty so that the tooltip is never empty. */
120 return true;
121 }
122 if (socket_.is_output()) {
123 return false;
124 }
125 if (socket_.type == SOCK_MENU) {
126 return true;
127 }
128 if (socket_.runtime->declaration && socket_.runtime->declaration->optional_label) {
129 return true;
130 }
131 return false;
132 }
133
134 void build_tooltip_label()
135 {
136 this->start_block(TooltipBlockType::Label);
137 if (node_.is_reroute()) {
138 this->add_text_field_header(TIP_("Reroute"));
139 return;
140 }
141 const StringRefNull translated_socket_label = node_socket_get_label(&socket_, nullptr);
142 this->add_text_field_header(translated_socket_label);
143 }
144
145 void build_tooltip_description()
146 {
147 std::optional<std::string> description_opt = this->get_socket_description();
148 if (!description_opt) {
149 return;
150 }
151 std::string description = std::move(*description_opt);
152 if (description.empty()) {
153 return;
154 }
155 if (description[description.size() - 1] != '.') {
156 description += '.';
157 }
158 this->start_block(TooltipBlockType::Description);
159 this->add_text_field(std::move(description));
160 }
161
162 std::optional<std::string> get_socket_description()
163 {
164 if (socket_.runtime->declaration == nullptr) {
165 if (socket_.description[0]) {
166 return socket_.description;
167 }
168 return std::nullopt;
169 }
170 const nodes::SocketDeclaration &socket_decl = *socket_.runtime->declaration;
171 if (!socket_decl.description.empty()) {
172 return TIP_(socket_decl.description);
173 }
174 if (socket_decl.align_with_previous_socket) {
175 const Span<nodes::ItemDeclarationPtr> all_items = node_.runtime->declaration->all_items;
176 for (const int i : all_items.index_range()) {
177 if (&*all_items[i] != &socket_decl) {
178 continue;
179 }
180 if (i == 0) {
181 break;
182 }
183 const nodes::SocketDeclaration *previous_socket_decl =
184 dynamic_cast<const nodes::SocketDeclaration *>(all_items[i - 1].get());
185 if (!previous_socket_decl) {
186 break;
187 }
188 if (!previous_socket_decl->description.empty()) {
189 return TIP_(previous_socket_decl->description);
190 }
191 }
192 }
193
194 return std::nullopt;
195 }
196
197 void build_tooltip_value()
198 {
199 SpaceNode *snode = CTX_wm_space_node(&C_);
200 eval_log::ContextualNodeTreeLogs tree_logs;
201 if (snode) {
203 }
204 eval_log::NodeTreeLog *tree_log = tree_logs.get_main_tree_log(socket_);
205 if (tree_log && this->build_tooltip_value_from_tree_log(*tree_log)) {
206 return;
207 }
208 const bool always_show_value = tree_.type == NTREE_GEOMETRY;
209 if (node_.is_reroute()) {
210 if (always_show_value) {
211 this->start_block(TooltipBlockType::Value);
212 this->build_tooltip_value_unknown();
213 }
214 return;
215 }
216 if (socket_.is_input()) {
217 if (this->is_socket_default_value_used()) {
218 this->build_tooltip_value_socket_default();
219 return;
220 }
221 }
222 if (always_show_value) {
223 this->start_block(TooltipBlockType::Value);
224 this->build_tooltip_value_unknown();
225 }
226 }
227
228 void build_tooltip_value_unknown()
229 {
230 this->add_text_field_mono(TIP_("Value: Unknown (not evaluated)"));
231 }
232
233 void build_tooltip_value_socket_default()
234 {
235 if (socket_.is_multi_input()) {
236 this->start_block(TooltipBlockType::Value);
237 this->add_text_field_mono(TIP_("Values: None"));
238 return;
239 }
240 const nodes::SocketDeclaration *socket_decl = socket_.runtime->declaration;
241 if (socket_decl &&
242 socket_decl->default_input_type != NodeDefaultInputType::NODE_DEFAULT_INPUT_VALUE)
243 {
244 this->start_block(TooltipBlockType::Value);
245 build_tooltip_value_implicit_default(socket_decl->default_input_type);
246 return;
247 }
248 if (socket_decl && socket_decl->structure_type == nodes::StructureType::Grid) {
249 this->start_block(TooltipBlockType::Value);
250 this->build_tooltip_value_and_type_oneline(TIP_("Empty Grid"), TIP_("Volume Grid"));
251 return;
252 }
253 if (socket_.typeinfo->base_cpp_type == nullptr) {
254 return;
255 }
256 const CPPType &cpp_type = *socket_.typeinfo->base_cpp_type;
257 BUFFER_FOR_CPP_TYPE_VALUE(cpp_type, socket_value);
258 socket_.typeinfo->get_base_cpp_value(socket_.default_value, socket_value);
259 BLI_SCOPED_DEFER([&]() { cpp_type.destruct(socket_value); });
260 this->start_block(TooltipBlockType::Value);
261 this->build_tooltip_value_generic({cpp_type, socket_value});
262 }
263
264 [[nodiscard]] bool build_tooltip_value_from_tree_log(eval_log::NodeTreeLog &tree_log)
265 {
266 if (socket_.typeinfo->base_cpp_type == nullptr) {
267 return false;
268 }
269 tree_log.ensure_socket_values();
270 if (socket_.is_multi_input()) {
271 return this->build_tooltip_last_value_multi_input(tree_log);
272 }
273 eval_log::ValueLog *value_log = tree_log.find_socket_value_log(socket_);
274 if (!value_log) {
275 return false;
276 }
277 this->start_block(TooltipBlockType::Value);
278 this->build_tooltip_value_eval_log(*value_log);
279 return true;
280 }
281
282 bool build_tooltip_last_value_multi_input(eval_log::NodeTreeLog &tree_log)
283 {
284 const Span<const bNodeLink *> connected_links = socket_.directly_linked_links();
285
286 Vector<std::pair<int, eval_log::ValueLog *>> value_logs;
287 bool all_value_logs_missing = true;
288 for (const int i : connected_links.index_range()) {
289 const bNodeLink &link = *connected_links[i];
290 if (!link.is_used()) {
291 continue;
292 }
293 if (!(link.flag & NODE_LINK_VALID)) {
294 continue;
295 }
296 const bNodeSocket &from_socket = *link.fromsock;
297 eval_log::ValueLog *value_log = tree_log.find_socket_value_log(from_socket);
298 value_logs.append({i, value_log});
299 if (value_log) {
300 all_value_logs_missing = false;
301 }
302 }
303 if (all_value_logs_missing) {
304 return false;
305 }
306
307 this->start_block(TooltipBlockType::Value);
308 for (const auto &[i, value_log] : value_logs) {
309 const int connection_number = i + 1;
310 if (i > 0) {
311 this->add_space();
312 }
313 this->add_text_field_mono(fmt::format("{}:", connection_number));
314 this->add_space();
315 indentation_++;
316 BLI_SCOPED_DEFER([&]() { indentation_--; });
317 if (value_log) {
318 this->build_tooltip_value_eval_log(*value_log);
319 }
320 else {
321 this->build_tooltip_value_unknown();
322 }
323 }
324
325 return true;
326 }
327
328 void build_tooltip_value_eval_log(eval_log::ValueLog &value_log)
329 {
330 if (const auto *generic_value_log = dynamic_cast<const eval_log::GenericValueLog *>(
331 &value_log))
332 {
333 this->build_tooltip_value_generic(generic_value_log->value);
334 }
335 else if (const auto *string_value_log = dynamic_cast<const eval_log::StringLog *>(&value_log))
336 {
337 this->build_tooltip_value_string_log(*string_value_log);
338 }
339 else if (const auto *field_value_log = dynamic_cast<const eval_log::FieldInfoLog *>(
340 &value_log))
341 {
342 this->build_tooltip_value_field_log(*field_value_log);
343 }
344 else if (const auto *geometry_log = dynamic_cast<const eval_log::GeometryInfoLog *>(
345 &value_log))
346 {
347 this->build_tooltip_value_geometry_log(*geometry_log);
348 }
349 else if (const auto *grid_log = dynamic_cast<const eval_log::GridInfoLog *>(&value_log)) {
350 build_tooltip_value_grid_log(*grid_log);
351 }
352 else if (const auto *bundle_log = dynamic_cast<const eval_log::BundleValueLog *>(&value_log)) {
353 this->build_tooltip_value_bundle_log(*bundle_log);
354 }
355 else if (const auto *closure_log = dynamic_cast<const eval_log::ClosureValueLog *>(&value_log))
356 {
357 this->build_tooltip_value_closure_log(*closure_log);
358 }
359 else if (const auto *list_log = dynamic_cast<const eval_log::ListInfoLog *>(&value_log)) {
360 this->build_tooltip_value_list_log(*list_log);
361 }
362 else if (const auto *image_log = dynamic_cast<const eval_log::ImageInfoLog *>(&value_log)) {
363 this->build_tooltip_value_image_log(*image_log);
364 }
365 }
366
367 void build_tooltip_value_and_type_oneline(const StringRef value, const StringRef type)
368 {
369 this->add_text_field_mono(fmt::format("{}: {}", TIP_("Value"), value));
370 this->add_space();
371 this->add_text_field_mono(fmt::format("{}: {}", TIP_("Type"), type));
372 }
373
374 void build_tooltip_value_object(const Object *object)
375 {
376 std::string value_str;
377 if (object) {
378 value_str = BKE_id_name(id_cast<const ID &>(*object));
379 if (this->is_implicit_default_input(NODE_DEFAULT_INPUT_SELF_OBJECT)) {
380 value_str += TIP_(" (Self Object)");
381 }
382 }
383 else {
384 value_str = TIP_("None");
385 }
386 this->build_tooltip_value_and_type_oneline(value_str, TIP_("Object"));
387 }
388
389 template<typename T> [[nodiscard]] bool build_tooltip_value_data_block(const GPointer &value)
390 {
391 const CPPType &type = *value.type();
392 if (!type.is<T *>()) {
393 return false;
394 }
395 const T *data = *value.get<T *>();
396 std::string value_str;
397 if (data) {
398 value_str = BKE_id_name(id_cast<const ID &>(*data));
399 }
400 else {
401 value_str = TIP_("None");
402 }
403 const ID_Type id_type = T::id_type;
404 const char *id_type_name = BKE_idtype_idcode_to_name(id_type);
405
406 this->build_tooltip_value_and_type_oneline(value_str, TIP_(id_type_name));
407 return true;
408 }
409
410 void build_tooltip_value_enum(const nodes::MenuValue menu_item)
411 {
412 const auto *storage = socket_.default_value_typed<bNodeSocketValueMenu>();
413 if (!storage->enum_items || storage->has_conflict()) {
414 this->build_tooltip_value_and_type_oneline(TIP_("Unknown"), TIP_("Menu"));
415 return;
416 }
417 const bke::RuntimeNodeEnumItem *enum_item = storage->enum_items->find_item_by_identifier(
418 menu_item.value);
419 if (!enum_item) {
420 return;
421 }
422 if (!enum_item->description.empty()) {
423 this->add_text_field(TIP_(enum_item->description), ui::TIP_LC_VALUE);
424 this->add_space();
425 }
426 this->build_tooltip_value_and_type_oneline(TIP_(enum_item->name), TIP_("Menu"));
427 }
428
429 void build_tooltip_value_int(const int value)
430 {
431 std::string value_str = fmt::format("{}", value);
432 if (this->is_implicit_default_input(NODE_DEFAULT_INPUT_SCENE_FRAME)) {
433 value_str += TIP_(" (Scene Frame)");
434 }
435 this->build_tooltip_value_and_type_oneline(value_str, TIP_("Integer"));
436 }
437
438 void build_tooltip_value_float(const float value)
439 {
440 std::string value_str;
441 /* Above that threshold floats can't represent fractions anymore. */
442 if (std::abs(value) > (1 << 24)) {
443 /* Use higher precision to display correct integer value instead of one that is rounded to
444 * fewer significant digits. */
445 value_str = fmt::format("{:.10}", value);
446 }
447 else {
448 value_str = fmt::format("{}", value);
449 }
450 if (this->is_implicit_default_input(NODE_DEFAULT_INPUT_SCENE_FRAME)) {
451 value_str += TIP_(" (Scene Frame)");
452 }
453 this->build_tooltip_value_and_type_oneline(value_str, TIP_("Float"));
454 }
455
456 bool is_implicit_default_input(const NodeDefaultInputType type) const
457 {
458 return socket_.is_input() && !socket_.is_logically_linked() && socket_.runtime->declaration &&
459 socket_.runtime->declaration->default_input_type == type;
460 }
461
462 void build_tooltip_value_float2(const float2 &value)
463 {
464 const std::string value_str = fmt::format("{} {}", value.x, value.y);
465 this->build_tooltip_value_and_type_oneline(value_str, TIP_("2D Float Vector"));
466 }
467
468 void build_tooltip_value_float3(const float3 &value)
469 {
470 const std::string value_str = fmt::format("{} {} {}", value.x, value.y, value.z);
471 this->build_tooltip_value_and_type_oneline(value_str, TIP_("3D Float Vector"));
472 }
473
474 void build_tooltip_value_float4(const float4 &value)
475 {
476 const std::string value_str = fmt::format("{} {} {} {}", value.x, value.y, value.z, value.w);
477 this->build_tooltip_value_and_type_oneline(value_str, TIP_("4D Float Vector"));
478 }
479
480 void build_tooltip_value_color(const ColorGeometry4f &value)
481 {
482 const std::string value_str = fmt::format(
483 "{} {} {} {} ({})", value.r, value.g, value.b, value.a, TIP_("Linear"));
484 this->build_tooltip_value_and_type_oneline(value_str, TIP_("Float Color"));
485 this->add_space();
486
487 bool is_gamma = false;
488 const ColorManagedDisplay *display = nullptr;
489 if (but_) {
490 is_gamma = button_is_color_gamma(*but_);
491 display = button_cm_display_get(*but_);
492 }
494 tip_data_, float4(value), true, is_gamma, display, ui::TIP_LC_VALUE);
495 }
496
497 void build_tooltip_value_quaternion(const math::Quaternion &value)
498 {
499 const math::EulerXYZ euler = math::to_euler(value);
500 const std::string value_str = fmt::format("{}" BLI_STR_UTF8_DEGREE_SIGN
503 euler.x().degree(),
504 euler.y().degree(),
505 euler.z().degree());
506 this->build_tooltip_value_and_type_oneline(value_str, TIP_("Rotation"));
507 }
508
509 void build_tooltip_value_bool(const bool value)
510 {
511 std::string value_str = value ? TIP_("True") : TIP_("False");
512 this->build_tooltip_value_and_type_oneline(value_str, TIP_("Boolean"));
513 }
514
515 void build_tooltip_value_float4x4(const float4x4 &value)
516 {
517 /* Transpose to be able to print row by row. */
518 const float4x4 value_transposed = math::transpose(value);
519
520 std::stringstream ss;
521 for (const int row_i : IndexRange(4)) {
522 const float4 row = value_transposed[row_i];
523 ss << fmt::format("{:7.3} {:7.3} {:7.3} {:7.3}\n", row[0], row[1], row[2], row[3]);
524 }
525
526 this->add_text_field_mono(fmt::format("{}:", TIP_("Value")));
527 this->add_space();
528 this->add_text_field_mono(ss.str());
529 this->add_space();
530 this->add_text_field_mono(fmt::format("{}: {}", TIP_("Type"), TIP_("4x4 Float Matrix")));
531 }
532
533 void build_tooltip_value_generic(const GPointer &value)
534
535 {
536 const CPPType &value_type = *value.type();
537 if (value_type.is<Object *>()) {
538 this->build_tooltip_value_object(*value.get<Object *>());
539 return;
540 }
541 if (this->build_tooltip_value_data_block<Material>(value)) {
542 return;
543 }
544 if (this->build_tooltip_value_data_block<Tex>(value)) {
545 return;
546 }
547 if (this->build_tooltip_value_data_block<Image>(value)) {
548 return;
549 }
550 if (this->build_tooltip_value_data_block<Collection>(value)) {
551 return;
552 }
553
554 if (socket_.type == SOCK_MENU) {
555 if (!value_type.is<nodes::MenuValue>()) {
556 this->build_tooltip_value_unknown();
557 return;
558 }
559 const nodes::MenuValue menu_item = *value.get<nodes::MenuValue>();
560 this->build_tooltip_value_enum(menu_item);
561 return;
562 }
563
564 const CPPType &socket_base_cpp_type = *socket_.typeinfo->base_cpp_type;
565 const bke::DataTypeConversions &conversions = bke::get_implicit_type_conversions();
566 if (value_type != socket_base_cpp_type) {
567 if (!conversions.is_convertible(value_type, socket_base_cpp_type)) {
568 this->build_tooltip_value_unknown();
569 return;
570 }
571 }
572 BUFFER_FOR_CPP_TYPE_VALUE(socket_base_cpp_type, socket_value);
573 conversions.convert_to_uninitialized(
574 value_type, socket_base_cpp_type, value.get(), socket_value);
575 BLI_SCOPED_DEFER([&]() { socket_base_cpp_type.destruct(socket_value); });
576
577 if (socket_base_cpp_type.is<int>()) {
578 this->build_tooltip_value_int(*static_cast<int *>(socket_value));
579 return;
580 }
581 if (socket_base_cpp_type.is<float>()) {
582 this->build_tooltip_value_float(*static_cast<float *>(socket_value));
583 return;
584 }
585 if (socket_base_cpp_type.is<float2>()) {
586 this->build_tooltip_value_float2(*static_cast<float2 *>(socket_value));
587 return;
588 }
589 if (socket_base_cpp_type.is<float3>()) {
590 this->build_tooltip_value_float3(*static_cast<float3 *>(socket_value));
591 return;
592 }
593 if (socket_base_cpp_type.is<float4>()) {
594 this->build_tooltip_value_float4(*static_cast<float4 *>(socket_value));
595 return;
596 }
597 if (socket_base_cpp_type.is<ColorGeometry4f>()) {
598 this->build_tooltip_value_color(*static_cast<ColorGeometry4f *>(socket_value));
599 return;
600 }
601 if (socket_base_cpp_type.is<math::Quaternion>()) {
602 this->build_tooltip_value_quaternion(*static_cast<math::Quaternion *>(socket_value));
603 return;
604 }
605 if (socket_base_cpp_type.is<bool>()) {
606 this->build_tooltip_value_bool(*static_cast<bool *>(socket_value));
607 return;
608 }
609 if (socket_base_cpp_type.is<float4x4>()) {
610 this->build_tooltip_value_float4x4(*static_cast<float4x4 *>(socket_value));
611 return;
612 }
613 this->build_tooltip_value_unknown();
614 }
615
616 void build_tooltip_value_string_log(const eval_log::StringLog &value_log)
617 {
618 std::string value_str = value_log.value;
619 if (value_log.truncated) {
620 value_str += "...";
621 }
622 this->build_tooltip_value_and_type_oneline(value_str, TIP_("String"));
623 }
624
625 const char *get_field_type_name(const CPPType &base_type)
626 {
627 if (base_type.is<int>()) {
628 return TIP_("Integer Field");
629 }
630 if (base_type.is<float>()) {
631 return TIP_("Float Field");
632 }
633 if (base_type.is<float2>()) {
634 return TIP_("2D Float Vector Field");
635 }
636 if (base_type.is<float3>()) {
637 return TIP_("3D Float Vector Field");
638 }
639 if (base_type.is<float4>()) {
640 return TIP_("4D Float Vector Field");
641 }
642 if (base_type.is<bool>()) {
643 return TIP_("Boolean Field");
644 }
645 if (base_type.is<std::string>()) {
646 return TIP_("String Field");
647 }
648 if (base_type.is<ColorGeometry4f>()) {
649 return TIP_("Color Field");
650 }
651 if (base_type.is<math::Quaternion>()) {
652 return TIP_("Rotation Field");
653 }
654 if (base_type.is<float4x4>()) {
655 return TIP_("Matrix Field");
656 }
657 if (base_type.is<nodes::MenuValue>()) {
658 return TIP_("Menu Field");
659 }
660 return TIP_("Field");
661 }
662
663 void build_tooltip_value_field_log(const eval_log::FieldInfoLog &value_log)
664 {
665 const Span<std::string> input_tooltips = value_log.input_tooltips;
666
667 if (input_tooltips.is_empty()) {
668 /* Should have been logged as constant value. */
670 return;
671 }
672
673 this->add_text_field_mono(TIP_("Field depending on:"));
674
675 for (const std::string &input_tooltip : input_tooltips) {
676 this->add_space();
677 this->add_text_field_mono(fmt::format(" \u2022 {}", TIP_(input_tooltip)));
678 }
679
680 this->add_space();
681 std::string type_str = this->get_field_type_name(value_log.type);
682 this->add_text_field_mono(fmt::format("{}: {}", TIP_("Type"), type_str));
683 }
684
685 std::string count_to_string(const int count)
686 {
689 return std::string(str);
690 }
691
692 void build_tooltip_value_geometry_log(const eval_log::GeometryInfoLog &geometry_log)
693 {
694 Span<bke::GeometryComponent::Type> component_types = geometry_log.component_types;
695 if (component_types.is_empty()) {
696 this->build_tooltip_value_and_type_oneline(TIP_("None"), TIP_("Geometry Set"));
697 return;
698 }
699 this->add_text_field_mono(TIP_("Geometry components:"));
700 for (const bke::GeometryComponent::Type type : component_types) {
701 std::string component_str;
702 switch (type) {
704 const eval_log::GeometryInfoLog::MeshInfo &info = *geometry_log.mesh_info;
705 component_str = fmt::format(fmt::runtime(TIP_("Mesh: {} vertices, {} edges, {} faces")),
706 this->count_to_string(info.verts_num),
707 this->count_to_string(info.edges_num),
708 this->count_to_string(info.faces_num));
709 break;
710 }
712 const eval_log::GeometryInfoLog::PointCloudInfo &info = *geometry_log.pointcloud_info;
713 component_str = fmt::format(fmt::runtime(TIP_("Point Cloud: {} points")),
714 this->count_to_string(info.points_num));
715 break;
716 }
718 const eval_log::GeometryInfoLog::InstancesInfo &info = *geometry_log.instances_info;
719 component_str = fmt::format(fmt::runtime(TIP_("Instances: {}")),
720 this->count_to_string(info.instances_num));
721 break;
722 }
724 const eval_log::GeometryInfoLog::VolumeInfo &info = *geometry_log.volume_info;
725 component_str = fmt::format(fmt::runtime(TIP_("Volume: {} grids")),
726 this->count_to_string(info.grids.size()));
727 break;
728 }
730 const eval_log::GeometryInfoLog::CurveInfo &info = *geometry_log.curve_info;
731 component_str = fmt::format(fmt::runtime(TIP_("Curve: {} points, {} splines")),
732 this->count_to_string(info.points_num),
733 this->count_to_string(info.splines_num));
734 break;
735 }
737 const eval_log::GeometryInfoLog::GreasePencilInfo &info =
738 *geometry_log.grease_pencil_info;
739 component_str = fmt::format(fmt::runtime(TIP_("Grease Pencil: {} layers")),
740 this->count_to_string(info.layers_num));
741 break;
742 }
744 if (geometry_log.edit_data_info.has_value()) {
745 const eval_log::GeometryInfoLog::EditDataInfo &info = *geometry_log.edit_data_info;
746 component_str = fmt::format(
747 fmt::runtime(TIP_("Edit: {}, {}, {}")),
748 info.has_deformed_positions ? TIP_("positions") : TIP_("no positions"),
749 info.has_deform_matrices ? TIP_("matrices") : TIP_("no matrices"),
750 info.gizmo_transforms_num > 0 ? TIP_("gizmos") : TIP_("no gizmos"));
751 }
752 break;
753 }
754 }
755 if (!component_str.empty()) {
756 this->add_space();
757 this->add_text_field_mono(fmt::format(" \u2022 {}", component_str));
758 }
759 }
760 this->add_space();
761 this->add_text_field_mono(TIP_("Type: Geometry Set"));
762 }
763
764 void build_tooltip_value_grid_log(const eval_log::GridInfoLog &grid_log)
765 {
766 std::string value_str;
767 if (grid_log.is_empty) {
768 value_str = TIP_("None");
769 }
770 else {
771 value_str = TIP_("Volume Grid");
772 }
773 this->build_tooltip_value_and_type_oneline(value_str, TIP_("Volume Grid"));
774 }
775
776 void build_tooltip_value_bundle_log(const eval_log::BundleValueLog &bundle_log)
777 {
778 if (bundle_log.items.is_empty()) {
779 this->add_text_field_mono(TIP_("Values: None"));
780 }
781 else {
782 this->add_text_field_mono(TIP_("Values:"));
783 Vector<eval_log::BundleValueLog::Item> sorted_items = bundle_log.items;
784 std::ranges::sort(sorted_items, [](const auto &a, const auto &b) {
785 return BLI_strcasecmp_natural(a.key.c_str(), b.key.c_str()) < 0;
786 });
787 for (const eval_log::BundleValueLog::Item &item : sorted_items) {
788 this->add_space();
789 std::string type_name;
790 if (const bke::bNodeSocketType *const *socket_type =
791 std::get_if<const bke::bNodeSocketType *>(&item.type))
792 {
793 type_name = TIP_((*socket_type)->label);
794 }
795 else if (const StringRefNull *internal_type_name = std::get_if<StringRefNull>(&item.type))
796 {
797 type_name = *internal_type_name;
798 }
799 this->add_text_field_mono(fmt::format("\u2022 \"{}\" ({})\n", item.key, type_name));
800 }
801 }
802 this->add_space();
803 this->add_text_field_mono(TIP_("Type: Bundle"));
804 }
805
806 void build_tooltip_value_closure_log(const eval_log::ClosureValueLog &closure_log)
807 {
808 if (closure_log.inputs.is_empty() && closure_log.outputs.is_empty()) {
809 this->add_text_field_mono(TIP_("Value: None"));
810 }
811 else {
812 if (!closure_log.inputs.is_empty()) {
813 this->add_text_field_mono(TIP_("Inputs:"));
814 for (const eval_log::ClosureValueLog::Item &item : closure_log.inputs) {
815 this->add_space();
816 const std::string type_name = TIP_(item.type->label);
817 this->add_text_field_mono(fmt::format("\u2022 \"{}\" ({})\n", item.key, type_name));
818 }
819 }
820 if (!closure_log.outputs.is_empty()) {
821 this->add_space();
822 this->add_text_field_mono(TIP_("Outputs:"));
823 for (const eval_log::ClosureValueLog::Item &item : closure_log.outputs) {
824 this->add_space();
825 const std::string type_name = TIP_(item.type->label);
826 this->add_text_field_mono(fmt::format("\u2022 \"{}\" ({})\n", item.key, type_name));
827 }
828 }
829 }
830 this->add_space();
831 this->add_text_field_mono(TIP_("Type: Closure"));
832 }
833
834 void build_tooltip_value_list_log(const eval_log::ListInfoLog &list_log)
835 {
836 this->add_text_field_mono(fmt::format("{}: {}", TIP_("Length"), list_log.size));
837 this->add_space();
838 this->add_text_field_mono(TIP_("Type: List"));
839 }
840
841 void build_tooltip_value_image_log(const eval_log::ImageInfoLog &image_log)
842 {
843 const bool has_display_window = image_log.data_size != image_log.display_size ||
844 image_log.data_offset != int2(0);
845 if (has_display_window) {
846 this->add_text_field_mono(TIP_("Display/Data Window:"));
847 this->add_text_field_mono(fmt::format(
848 "\u2022 {}: {}x{}", TIP_("Data Size"), image_log.data_size.x, image_log.data_size.y));
849 this->add_text_field_mono(fmt::format("\u2022 {}: {}x{}",
850 TIP_("Display Size"),
851 image_log.display_size.x,
852 image_log.display_size.y));
853 this->add_text_field_mono(fmt::format("\u2022 {}: ({}, {})",
854 TIP_("Data Offset"),
855 image_log.data_offset.x,
856 image_log.data_offset.y));
857 }
858 else {
859 this->add_text_field_mono(fmt::format(
860 "{}: {}x{}", TIP_("Resolution"), image_log.data_size.x, image_log.data_size.y));
861 }
862
863 this->add_space();
864
865 float2 location;
868 to_loc_rot_scale(image_log.transformation, location, rotation, scale);
869
870 const bool is_translated = !math::is_equal(location, float2(0.0f), 10e-6f);
871 const bool is_rotated = math::abs(rotation.degree()) > 10e-6f;
872 const bool is_scaled = !math::is_equal(scale, float2(1.0f), 10e-6f);
873 if (is_translated || is_rotated || is_scaled) {
874 this->add_text_field_mono(TIP_("Transformation:"));
875 if (is_translated) {
876 this->add_text_field_mono(
877 fmt::format("\u2022 {}: ({}, {})", TIP_("Translation"), location.x, location.y));
878 }
879 if (is_rotated) {
880 this->add_text_field_mono(fmt::format(
881 "\u2022 {}: {}" BLI_STR_UTF8_DEGREE_SIGN, TIP_("Rotation"), rotation.degree()));
882 }
883 if (is_scaled) {
884 this->add_text_field_mono(
885 fmt::format("\u2022 {}: ({}, {})", TIP_("Scale"), scale.x, scale.y));
886 }
887 }
888 else {
889 this->add_text_field_mono(TIP_("Transformation: Identity"));
890 }
891
892 this->add_space();
893
894 this->add_text_field_mono(TIP_("Sampling:"));
895 this->add_text_field_mono(
896 fmt::format("\u2022 {}: {}", TIP_("Interpolation"), TIP_(image_log.interpolation)));
897 if (image_log.extension_x == image_log.extension_y) {
898 this->add_text_field_mono(
899 fmt::format("\u2022 {}: {}", TIP_("Extension"), TIP_(image_log.extension_x)));
900 }
901 else {
902 this->add_text_field_mono(
903 fmt::format("\u2022 {}: {}", TIP_("Extension X"), TIP_(image_log.extension_x)));
904 this->add_text_field_mono(
905 fmt::format("\u2022 {}: {}", TIP_("Extension Y"), TIP_(image_log.extension_y)));
906 }
907
908 this->add_space();
909
910 this->add_text_field_mono(fmt::format("{}: {}", TIP_("Precision"), TIP_(image_log.precision)));
911
912 this->add_space();
913
914 if (this->is_implicit_default_input(NODE_DEFAULT_INPUT_UNIFORM_IMAGE_COORDINATES)) {
915 this->add_text_field_mono(TIP_("Implicit Value: Uniform Image Coordinates"));
916 this->add_space();
917 }
918
919 this->add_text_field_mono(TIP_("Type: Image"));
920 }
921
922 void build_tooltip_value_implicit_default(const NodeDefaultInputType &type)
923 {
924 switch (type) {
926 /* Should be handled elsewhere. */
928 break;
929 }
931 this->build_tooltip_value_and_type_oneline(TIP_("Index Field"),
932 this->get_field_type_name(CPPType::get<int>()));
933 break;
934 }
936 this->build_tooltip_value_and_type_oneline(TIP_("ID or Index Field"),
937 this->get_field_type_name(CPPType::get<int>()));
938 break;
939 }
941 this->build_tooltip_value_and_type_oneline(
942 TIP_("Normal Field"), this->get_field_type_name(CPPType::get<float3>()));
943 break;
944 }
946 this->build_tooltip_value_and_type_oneline(
947 TIP_("Position Field"), this->get_field_type_name(CPPType::get<float3>()));
948 break;
949 }
951 this->build_tooltip_value_and_type_oneline(
952 TIP_("Instance Transform Field"), this->get_field_type_name(CPPType::get<float4x4>()));
953 break;
954 }
956 this->build_tooltip_value_and_type_oneline(
957 TIP_("Left Handle Field"), this->get_field_type_name(CPPType::get<float3>()));
958 break;
959 }
961 this->build_tooltip_value_and_type_oneline(
962 TIP_("Right Handle Field"), this->get_field_type_name(CPPType::get<float3>()));
963 break;
965 this->build_tooltip_value_and_type_oneline(
966 TIP_("Scene Frame"), socket_.type == SOCK_FLOAT ? TIP_("Float") : TIP_("Integer"));
967 break;
969 this->build_tooltip_value_and_type_oneline(TIP_("Uniform Image Coordinates"),
970 TIP_("2D Float Vector"));
971 break;
973 this->build_tooltip_value_and_type_oneline(TIP_("Self Object"), TIP_("Object"));
974 break;
975 }
976 }
977
978 bool is_socket_default_value_used()
979 {
980 BLI_assert(socket_.is_input());
981 for (const bNodeLink *link : socket_.directly_linked_links()) {
982 if (!link->is_used()) {
983 continue;
984 }
985 const bNodeSocket &from_socket = *link->fromsock;
986 const bNode &from_node = from_socket.owner_node();
987 if (from_node.is_dangling_reroute()) {
988 continue;
989 }
990 return false;
991 }
992 return true;
993 }
994
995 void build_tooltip_expected_bundle_type()
996 {
997 if (socket_.type != SOCK_BUNDLE) {
998 return;
999 }
1000 if (socket_.is_output()) {
1001 return;
1002 }
1003 const auto *socket_decl = dynamic_cast<const nodes::decl::Bundle *>(
1004 socket_.runtime->declaration);
1005 if (!socket_decl) {
1006 return;
1007 }
1008 if (!socket_decl->bundle_type) {
1009 return;
1010 }
1011 const nodes::BundleType &bundle_type = *socket_decl->bundle_type;
1012
1013 if (const auto *nested_bundle_type = std::get_if<nodes::NestedBundleTypePtr>(
1014 &bundle_type.type))
1015 {
1016 this->start_block(TooltipBlockType::BundleType);
1017 this->add_text_field_mono(TIP_("Bundle Types:"));
1018 for (const nodes::FlatBundleTypePtr &flat_type : (*nested_bundle_type)->items()) {
1019 this->add_text_field_mono(fmt::format(" \u2022 {}", flat_type->name()));
1020 }
1021 }
1022 else if (const auto *flat_bundle_type = std::get_if<nodes::FlatBundleTypePtr>(
1023 &bundle_type.type))
1024 {
1025 this->start_block(TooltipBlockType::BundleType);
1026 this->add_text_field_mono(TIP_("Bundle Type:"));
1027 for (const nodes::FlatBundleType::Item &item : (*flat_bundle_type)->items()) {
1028 this->add_text_field_mono(fmt::format(" \u2022 {}", item.name()));
1029 }
1030 }
1031 }
1032
1033 StringRef get_structure_type_tooltip(const nodes::StructureType &structure_type)
1034 {
1035 switch (structure_type) {
1036 case nodes::StructureType::Single: {
1037 return TIP_("Single Value");
1038 }
1039 case nodes::StructureType::Dynamic: {
1040 return TIP_("Dynamic");
1041 }
1042 case nodes::StructureType::Field: {
1043 return TIP_("Field");
1044 }
1045 case nodes::StructureType::Grid: {
1046 return TIP_("Volume Grid");
1047 }
1048 case nodes::StructureType::List: {
1049 return TIP_("List");
1050 }
1051 }
1053 return "Unknown";
1054 }
1055
1056 void build_python()
1057 {
1058 if (!(U.flag & USER_TOOLTIPS_PYTHON)) {
1059 return;
1060 }
1061 if (!but_) {
1062 return;
1063 }
1064 ui::tooltip_uibut_python_add(tip_data_, C_, *but_, nullptr);
1065 }
1066
1067 void start_block(const TooltipBlockType new_block_type)
1068 {
1069 if (last_block_type_.has_value()) {
1070 this->add_space(2);
1071 }
1072 last_block_type_ = new_block_type;
1073 }
1074
1075 void add_text_field_header(std::string text)
1076 {
1078 tip_data_, this->indent(text), {}, ui::TIP_STYLE_HEADER, ui::TIP_LC_MAIN);
1079 }
1080
1081 void add_text_field(std::string text, const ui::TooltipColorID color_id = ui::TIP_LC_NORMAL)
1082 {
1083 ui::tooltip_text_field_add(tip_data_, this->indent(text), {}, ui::TIP_STYLE_NORMAL, color_id);
1084 }
1085
1086 void add_text_field_mono(std::string text, const ui::TooltipColorID color_id = ui::TIP_LC_VALUE)
1087 {
1088 ui::tooltip_text_field_add(tip_data_, this->indent(text), {}, ui::TIP_STYLE_MONO, color_id);
1089 }
1090
1091 void add_space(const int amount = 1)
1092 {
1093 for ([[maybe_unused]] const int i : IndexRange(amount)) {
1095 }
1096 }
1097
1098 std::string indent(std::string text)
1099 {
1100 if (indentation_ == 0) {
1101 return text;
1102 }
1103 return fmt::format("{: <{}}{}", "", indentation_, text);
1104 }
1105};
1106
1108 bContext &C,
1109 ui::Button *but,
1110 const bNodeTree &tree,
1111 const bNodeSocket &socket)
1112{
1113 SocketTooltipBuilder builder(tip_data, tree, socket, C, but);
1114 builder.build();
1115}
1116
1117} // namespace ed::space_node
1118
1119} // namespace blender
#define BUFFER_FOR_CPP_TYPE_VALUE(type, variable_name)
#define BLI_SCOPED_DEFER(function_to_defer)
#define BLI_STR_FORMAT_INT32_GROUPED_SIZE
Definition BLI_string.hh:28
#define BLI_STR_UTF8_DEGREE_SIGN
#define TIP_(msgid)
Object groups, one object can be in many groups at once.
#define C
Definition RandGen.cpp:29
#define BLI_assert_unreachable()
#define BLI_assert(a)
constexpr IndexRange index_range() const
Definition BLI_span.hh:405
constexpr bool is_empty() const
Definition BLI_span.hh:264
static const CPPType & get()
constexpr IndexRange()=default
constexpr StringRef()
SocketTooltipBuilder(ui::TooltipData &tip_data, const bNodeTree &tree, const bNodeSocket &socket, bContext &C, ui::Button *but)
static ContextualNodeTreeLogs get_contextual_tree_logs(const SpaceNode &snode)
Definition eval_log.cc:1048
#define str(s)
#define storage(slot, qualifiers)
float3x3 scale(float3x3 mat, float2 scale)
void to_loc_rot_scale(float4x4 mat, float3 &r_location, EulerXYZ &r_rotation, float3 &r_scale)
#define T
const DataTypeConversions & get_implicit_type_conversions()
void build_socket_tooltip(ui::TooltipData &tip_data, bContext &C, ui::Button *but, const bNodeTree &tree, const bNodeSocket &socket)
const char * node_socket_get_label(const bNodeSocket *socket, const char *panel_label=nullptr)
Definition node_draw.cc:398
AngleRadianBase< float > AngleRadian
QuaternionBase< float > Quaternion
MatBase< T, NumCol, NumRow > transpose(const MatBase< T, NumRow, NumCol > &mat)
EulerXYZBase< float > EulerXYZ
bool is_equal(const MatBase< T, NumCol, NumRow > &a, const MatBase< T, NumCol, NumRow > &b, const T epsilon=T(0))
T abs(const T &a)
Euler3Base< T > to_euler(const AxisAngleBase< T, AngleT > &axis_angle, EulerOrder order)
std::shared_ptr< const FlatBundleType > FlatBundleTypePtr
void tooltip_color_field_add(TooltipData &data, const float4 &color, bool has_alpha, bool is_gamma, const ColorManagedDisplay *display, TooltipColorID color_id)
const ColorManagedDisplay * button_cm_display_get(Button &but)
void tooltip_uibut_python_add(TooltipData &data, bContext &C, Button &but, ButtonExtraOpIcon *extra_icon)
void tooltip_text_field_add(TooltipData &data, std::string text, std::string suffix, const TooltipStyle style, const TooltipColorID color_id, const bool is_pad=false)
bool button_is_color_gamma(Button &but)
BMesh Iterators.
const char * BKE_idtype_idcode_to_name(short idcode)
Definition idtype.cc:261
UserDef U
Definition blender.cc:58
int char char int int int BLI_strcasecmp_natural(const char *s1, const char *s2) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
MatBase< float, 4, 4 > float4x4
const char * BKE_id_name(const ID &id)
VecBase< float, 4 > float4
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
BMesh const char void * data
SpaceNode * CTX_wm_space_node(const bContext *C)
size_t BLI_str_format_int_grouped(char dst[BLI_STR_FORMAT_INT32_GROUPED_SIZE], int num) ATTR_NONNULL(1)
ColorSceneLinear4f< eAlpha::Premultiplied > ColorGeometry4f
VecBase< float, 3 > float3
ocio::Display ColorManagedDisplay
eUserPref_Flag flag
float x
float y
float z
Definition sky_math.h:136
float y
Definition sky_math.h:136
float x
Definition sky_math.h:136
float y
Definition sky_math.h:225
float z
Definition sky_math.h:225
float x
Definition sky_math.h:225
float w
Definition sky_math.h:225