Blender V5.3
sync_sockets.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 <fmt/ranges.h>
11
12#include "DNA_node_types.h"
13#include "DNA_space_types.h"
14
15#include "RNA_access.hh"
16
17#include "WM_api.hh"
18
20#include "BKE_context.hh"
21#include "BKE_main.hh"
24#include "BKE_node_runtime.hh"
26#include "BKE_report.hh"
27#include "BKE_workspace.hh"
28
29#include "ED_node.hh"
30#include "ED_screen.hh"
31
32#include "BLI_listbase.hh"
33
34#include "BLT_translation.hh"
35
36#include "NOD_bundle_type.hh"
37#include "NOD_geo_bundle.hh"
38#include "NOD_geo_closure.hh"
40#include "NOD_socket_items.hh"
41#include "NOD_sync_sockets.hh"
42#include "NOD_trace_values.hh"
43
44namespace blender::nodes {
45
52
55 std::optional<nodes::BundleSignature> source_signature;
56};
57
60 std::optional<nodes::ClosureSignature> source_signature;
61};
62
64 const SpaceNode &snode,
65 const bNode &separate_bundle_node,
66 const bNodeSocket *src_bundle_socket = nullptr)
67{
68 BLI_assert(separate_bundle_node.is_type("NodeSeparateBundle"_ustr));
69 snode.edittree->ensure_topology_cache();
70 if (!src_bundle_socket) {
71 src_bundle_socket = &separate_bundle_node.input_socket(0);
72 }
73 BLI_assert(src_bundle_socket->type == SOCK_BUNDLE);
74
75 bke::ComputeContextCache compute_context_cache;
77 snode, compute_context_cache, *src_bundle_socket);
78 if (!current_context) {
80 }
82 current_context, *src_bundle_socket, compute_context_cache);
83 if (linked_signatures.items.is_empty()) {
85 }
86 std::optional<BundleSignature> merged_signature = linked_signatures.get_merged_signature();
87 if (!merged_signature.has_value()) {
89 }
90 if (!linked_signatures.has_type_definition()) {
91 merged_signature->set_auto_structure_types();
92 }
93 const nodes::BundleSignature &current_signature =
94 nodes::BundleSignature::from_separate_bundle_node(separate_bundle_node, true);
95 if (*merged_signature != current_signature) {
96 return {NodeSyncState::CanBeSynced, std::move(merged_signature)};
97 }
98 return {NodeSyncState::Synced};
99}
100
102 const SpaceNode &snode, const bNode &combine_bundle_node, const bNodeSocket *src_bundle_socket)
103{
104 BLI_assert(combine_bundle_node.is_type("NodeCombineBundle"_ustr));
105 snode.edittree->ensure_topology_cache();
106
107 if (!src_bundle_socket) {
108 src_bundle_socket = &combine_bundle_node.output_socket(0);
109 }
110 BLI_assert(src_bundle_socket->type == SOCK_BUNDLE);
111
112 bke::ComputeContextCache compute_context_cache;
114 snode, compute_context_cache, *src_bundle_socket);
115 if (!current_context) {
116 return {};
117 }
118
119 const std::optional<StringRef> type = combine_bundle_node_type(*snode.edittree,
120 combine_bundle_node);
121 if (type) {
122 if (const FlatBundleTypePtr flat_bundle_type = BundleTypeRegistry::try_find_single_flat(*type))
123 {
124 SocketInContext socket = {current_context, src_bundle_socket};
126 result.items.append({flat_bundle_type->to_bundle_signature(), true, socket});
127 return result;
128 }
129 }
131 current_context, *src_bundle_socket, compute_context_cache);
132}
133
135 const SpaceNode &snode,
136 const bNode &combine_bundle_node,
137 const bNodeSocket *src_bundle_socket = nullptr)
138{
140 snode, combine_bundle_node, src_bundle_socket);
141 if (source_signatures.items.is_empty()) {
143 }
144 std::optional<BundleSignature> merged_signature = source_signatures.get_merged_signature();
145 if (!merged_signature.has_value()) {
147 }
148 if (!source_signatures.has_type_definition()) {
149 merged_signature->set_auto_structure_types();
150 }
151 const nodes::BundleSignature &current_signature =
152 nodes::BundleSignature::from_combine_bundle_node(combine_bundle_node, true);
153 if (*merged_signature != current_signature) {
154 return {NodeSyncState::CanBeSynced, std::move(merged_signature)};
155 }
156 return {NodeSyncState::Synced};
157}
158
160 const SpaceNode &snode,
161 const bNode &closure_output_node,
162 const bNodeSocket *src_closure_socket = nullptr)
163{
164 snode.edittree->ensure_topology_cache();
165 if (!src_closure_socket) {
166 src_closure_socket = &closure_output_node.output_socket(0);
167 }
168 BLI_assert(src_closure_socket->type == SOCK_CLOSURE);
169
170 bke::ComputeContextCache compute_context_cache;
172 snode, compute_context_cache, *src_closure_socket);
173 if (!current_context) {
175 }
177 current_context, *src_closure_socket, compute_context_cache);
178 if (linked_signatures.items.is_empty()) {
180 }
181 std::optional<ClosureSignature> merged_signature = linked_signatures.get_merged_signature();
182 if (!merged_signature.has_value()) {
184 }
185 if (!linked_signatures.has_type_definition()) {
186 merged_signature->set_auto_structure_types();
187 }
188 const nodes::ClosureSignature &current_signature =
189 nodes::ClosureSignature::from_closure_output_node(closure_output_node, true);
190 if (*merged_signature != current_signature) {
191 return {NodeSyncState::CanBeSynced, merged_signature};
192 }
193 return {NodeSyncState::Synced};
194}
195
197 const SpaceNode &snode,
198 const bNode &evaluate_closure_node,
199 const bNodeSocket *src_closure_socket = nullptr)
200{
201 snode.edittree->ensure_topology_cache();
202 if (!src_closure_socket) {
203 src_closure_socket = &evaluate_closure_node.input_socket(0);
204 }
205 BLI_assert(src_closure_socket->type == SOCK_CLOSURE);
206
207 bke::ComputeContextCache compute_context_cache;
209 snode, compute_context_cache, *src_closure_socket);
210 if (!current_context) {
212 }
214 current_context, *src_closure_socket, compute_context_cache);
215 if (linked_signatures.items.is_empty()) {
217 }
218 std::optional<ClosureSignature> merged_signature = linked_signatures.get_merged_signature();
219 if (!merged_signature.has_value()) {
221 }
222 if (!linked_signatures.has_type_definition()) {
223 merged_signature->set_auto_structure_types();
224 }
225 const nodes::ClosureSignature &current_signature =
226 nodes::ClosureSignature::from_evaluate_closure_node(evaluate_closure_node, true);
227 if (*merged_signature != current_signature) {
228 return {NodeSyncState::CanBeSynced, merged_signature};
229 }
230 return {NodeSyncState::Synced};
231}
232
234 const SpaceNode &snode,
235 const bNode &closure_to_list_node,
236 const bNodeSocket *src_closure_socket = nullptr)
237{
238 snode.edittree->ensure_topology_cache();
239 if (!src_closure_socket) {
240 src_closure_socket = closure_to_list_node.input_by_identifier("Closure"_ustr);
241 }
242
243 bke::ComputeContextCache compute_context_cache;
245 snode, compute_context_cache, *src_closure_socket);
246 if (!current_context) {
248 }
250 current_context, *src_closure_socket, compute_context_cache);
251 if (linked_signatures.items.is_empty()) {
253 }
254 std::optional<ClosureSignature> merged_signature = linked_signatures.get_merged_signature();
255 if (!merged_signature.has_value()) {
257 }
259 closure_to_list_node);
260 if (*merged_signature != current_signature) {
261 return {NodeSyncState::CanBeSynced, merged_signature};
262 }
263 return {NodeSyncState::Synced};
264}
265
267 bNode &separate_bundle_node,
268 ReportList *reports,
269 const bNodeSocket *src_bundle_socket)
270{
272 snode, separate_bundle_node, src_bundle_socket);
273 switch (sync_state.state) {
275 return;
277 BKE_report(reports, RPT_INFO, "No bundle signature found");
278 return;
280 BKE_report(reports, RPT_INFO, "Found conflicting bundle signatures");
281 return;
283 break;
284 }
285
286 auto &storage = *static_cast<NodeSeparateBundle *>(separate_bundle_node.storage);
287
288 Map<std::string, int> old_identifiers;
289 for (const int i : IndexRange(storage.items_num)) {
290 const NodeSeparateBundleItem &item = storage.items[i];
291 old_identifiers.add_new(StringRef(item.name), item.identifier);
292 }
293
295 for (const nodes::BundleSignature::Item &item : sync_state.source_signature->items) {
297 nodes ::SeparateBundleItemsAccessor>(
298 *snode.edittree, separate_bundle_node, item.type->type, item.key.c_str());
299 new_item.structure_type = item.structure_type;
300 if (const std::optional<int> old_identifier = old_identifiers.lookup_try(item.key)) {
301 new_item.identifier = *old_identifier;
302 }
303 }
304 BKE_ntree_update_tag_node_property(snode.edittree, &separate_bundle_node);
305}
306
308 bNode &combine_bundle_node,
309 ReportList *reports,
310 const bNodeSocket *src_bundle_socket)
311{
313 snode, combine_bundle_node, src_bundle_socket);
314 switch (sync_state.state) {
316 return;
318 BKE_report(reports, RPT_INFO, "No bundle signature found");
319 return;
321 BKE_report(reports, RPT_INFO, "Found conflicting bundle signatures");
322 return;
324 break;
325 }
326
327 auto &storage = *static_cast<NodeCombineBundle *>(combine_bundle_node.storage);
328
329 Map<std::string, int> old_identifiers;
330 for (const int i : IndexRange(storage.items_num)) {
331 const NodeCombineBundleItem &item = storage.items[i];
332 old_identifiers.add_new(StringRef(item.name), item.identifier);
333 }
334
336 for (const nodes::BundleSignature::Item &item : sync_state.source_signature->items) {
338 nodes ::CombineBundleItemsAccessor>(
339 *snode.edittree, combine_bundle_node, item.type->type, item.key.c_str());
340 new_item.structure_type = item.structure_type;
341 if (const std::optional<int> old_identifier = old_identifiers.lookup_try(item.key)) {
342 new_item.identifier = *old_identifier;
343 }
344 }
345
346 BKE_ntree_update_tag_node_property(snode.edittree, &combine_bundle_node);
347}
348
350 bNode &evaluate_closure_node,
351 ReportList *reports,
352 const bNodeSocket *src_closure_socket)
353{
355 snode, evaluate_closure_node, src_closure_socket);
356 switch (sync_state.state) {
358 return;
360 BKE_report(reports, RPT_INFO, "No closure signature found");
361 return;
363 BKE_report(reports, RPT_INFO, "Found conflicting closure signatures");
364 return;
366 break;
367 }
368
369 auto &storage = *static_cast<NodeEvaluateClosure *>(evaluate_closure_node.storage);
370
371 Map<std::string, int> old_input_identifiers;
372 Map<std::string, int> old_output_identifiers;
373 for (const int i : IndexRange(storage.input_items.items_num)) {
374 const NodeEvaluateClosureInputItem &item = storage.input_items.items[i];
375 old_input_identifiers.add_new(StringRef(item.name), item.identifier);
376 }
377 for (const int i : IndexRange(storage.output_items.items_num)) {
378 const NodeEvaluateClosureOutputItem &item = storage.output_items.items[i];
379 old_output_identifiers.add_new(StringRef(item.name), item.identifier);
380 }
381
384
385 for (const nodes::ClosureSignature::Item &item : sync_state.source_signature->inputs) {
389 *snode.edittree, evaluate_closure_node, item.type->type, item.key.c_str());
390 new_item.structure_type = item.structure_type;
391 if (const std::optional<int> old_identifier = old_input_identifiers.lookup_try(item.key)) {
392 new_item.identifier = *old_identifier;
393 }
394 }
395 for (const nodes::ClosureSignature::Item &item : sync_state.source_signature->outputs) {
399 *snode.edittree, evaluate_closure_node, item.type->type, item.key.c_str());
400 new_item.structure_type = item.structure_type;
401 if (const std::optional<int> old_identifier = old_output_identifiers.lookup_try(item.key)) {
402 new_item.identifier = *old_identifier;
403 }
404 }
405 BKE_ntree_update_tag_node_property(snode.edittree, &evaluate_closure_node);
406}
407
409 bNode &closure_input_node,
410 bNode &closure_output_node,
411 ReportList *reports,
412 const bNodeSocket *src_closure_socket)
413{
415 snode, closure_output_node, src_closure_socket);
416 switch (sync_state.state) {
418 return;
420 BKE_report(reports, RPT_INFO, "No closure signature found");
421 return;
423 BKE_report(reports, RPT_INFO, "Found conflicting closure signatures");
424 return;
426 break;
427 }
428 const nodes::ClosureSignature &signature = *sync_state.source_signature;
429
430 auto &storage = *static_cast<NodeClosureOutput *>(closure_output_node.storage);
431
432 Map<std::string, int> old_input_identifiers;
433 Map<std::string, int> old_output_identifiers;
434 for (const int i : IndexRange(storage.input_items.items_num)) {
435 const NodeClosureInputItem &item = storage.input_items.items[i];
436 old_input_identifiers.add_new(StringRef(item.name), item.identifier);
437 }
438 for (const int i : IndexRange(storage.output_items.items_num)) {
439 const NodeClosureOutputItem &item = storage.output_items.items[i];
440 old_output_identifiers.add_new(StringRef(item.name), item.identifier);
441 }
442
445
446 for (const nodes::ClosureSignature::Item &item : signature.inputs) {
447 NodeClosureInputItem &new_item =
449 *snode.edittree, closure_output_node, item.type->type, item.key.c_str());
450 new_item.structure_type = item.structure_type;
451 if (const std::optional<int> old_identifier = old_input_identifiers.lookup_try(item.key)) {
452 new_item.identifier = *old_identifier;
453 }
454 }
455 for (const nodes::ClosureSignature::Item &item : signature.outputs) {
458 *snode.edittree, closure_output_node, item.type->type, item.key.c_str());
459 new_item.structure_type = item.structure_type;
460 if (const std::optional<int> old_identifier = old_output_identifiers.lookup_try(item.key)) {
461 new_item.identifier = *old_identifier;
462 }
463 }
464 BKE_ntree_update_tag_node_property(snode.edittree, &closure_input_node);
465 BKE_ntree_update_tag_node_property(snode.edittree, &closure_output_node);
466
467 nodes::update_node_declaration_and_sockets(*snode.edittree, closure_input_node);
468 nodes::update_node_declaration_and_sockets(*snode.edittree, closure_output_node);
469
470 /* Create internal zone links for newly created sockets. */
471 snode.edittree->ensure_topology_cache();
473 for (const int input_i : signature.inputs.index_range()) {
474 const nodes::ClosureSignature::Item &input_item = signature.inputs[input_i];
475 if (old_input_identifiers.contains(input_item.key)) {
476 continue;
477 }
478 for (const int output_i : signature.outputs.index_range()) {
479 const nodes::ClosureSignature::Item &output_item = signature.outputs[output_i];
480 if (old_output_identifiers.contains(output_item.key)) {
481 continue;
482 }
483 if (input_item.key == output_item.key) {
484 internal_links.append({&closure_input_node.output_socket(input_i),
485 &closure_output_node.input_socket(output_i)});
486 }
487 };
488 }
489 for (auto &&[from_socket, to_socket] : internal_links) {
490 if (!snode.edittree->typeinfo->validate_link ||
491 snode.edittree->typeinfo->validate_link(from_socket->typeinfo->type,
492 to_socket->typeinfo->type))
493 {
495 *snode.edittree, closure_input_node, *from_socket, closure_output_node, *to_socket);
496 }
497 }
498}
499
501 bNode &closure_to_list_node,
502 ReportList *reports,
503 const bNodeSocket *src_closure_socket)
504{
506 snode, closure_to_list_node, src_closure_socket);
507 switch (sync_state.state) {
509 return;
511 BKE_report(reports, RPT_INFO, "No closure signature found");
512 return;
514 BKE_report(reports, RPT_WARNING, "Found conflicting closure signatures");
515 return;
517 break;
518 }
519
520 const ClosureSignature &signature = *sync_state.source_signature;
521 auto &storage = *static_cast<GeometryNodeClosureToList *>(closure_to_list_node.storage);
522
523 Map<std::string, int> old_identifiers;
524 for (const int i : IndexRange(storage.items_num)) {
525 const GeometryNodeClosureToListItem &item = storage.items[i];
526 old_identifiers.add_new(StringRef(item.name), item.identifier);
527 }
528
530 for (const nodes::ClosureSignature::Item &item : signature.outputs) {
533 *snode.edittree, closure_to_list_node, item.type->type, item.key.c_str());
534 new_item.structure_type = item.structure_type;
535 if (const std::optional<int> old_identifier = old_identifiers.lookup_try(item.key)) {
536 new_item.identifier = *old_identifier;
537 }
538 }
539
540 BKE_ntree_update_tag_node_property(snode.edittree, &closure_to_list_node);
541 update_node_declaration_and_sockets(*snode.edittree, closure_to_list_node);
542}
543
544static std::string get_bundle_sync_tooltip(const nodes::BundleSignature &old_signature,
545 const nodes::BundleSignature &new_signature)
546{
547 Vector<StringRef> added_items;
548 Vector<StringRef> removed_items;
549 Vector<StringRef> changed_items;
550 bool order_changed = false;
551
552 for (const int new_item_i : new_signature.items.index_range()) {
553 const BundleSignature::Item &new_item = new_signature.items[new_item_i];
554 const int old_item_i = old_signature.items.index_of_try_as(new_item.key);
555 if (old_item_i == -1) {
556 added_items.append(new_item.key);
557 }
558 else {
559 const BundleSignature::Item &old_item = old_signature.items[old_item_i];
560 if (new_item != old_item) {
561 changed_items.append(new_item.key);
562 }
563 if (old_item_i != new_item_i) {
564 order_changed = true;
565 }
566 }
567 }
568 for (const nodes::BundleSignature::Item &old_item : old_signature.items) {
569 if (!new_signature.items.contains_as(old_item.key)) {
570 removed_items.append(old_item.key);
571 }
572 }
573
574 fmt::memory_buffer string_buffer;
575 auto buf = fmt::appender(string_buffer);
576 if (!added_items.is_empty()) {
577 fmt::format_to(buf, "\u2022 {}: {}\n", TIP_("Add"), fmt::join(added_items, ", "));
578 }
579 if (!removed_items.is_empty()) {
580 fmt::format_to(buf, "\u2022 {}: {}\n", TIP_("Remove"), fmt::join(removed_items, ", "));
581 }
582 if (!changed_items.is_empty()) {
583 fmt::format_to(buf, "\u2022 {}: {}\n", TIP_("Change"), fmt::join(changed_items, ", "));
584 }
585 if (order_changed) {
586 fmt::format_to(buf, "\u2022 {}", TIP_("Reorder"));
587 }
588 fmt::format_to(buf, "\n{}", TIP_("Update based on linked bundle signature"));
589
590 return fmt::to_string(string_buffer);
591}
592
593static std::string get_closure_sync_tooltip(const nodes::ClosureSignature &old_signature,
594 const nodes::ClosureSignature &new_signature)
595{
596 Vector<StringRef> added_inputs;
597 Vector<StringRef> removed_inputs;
598 Vector<StringRef> changed_inputs;
599 bool input_order = false;
600
601 Vector<StringRef> added_outputs;
602 Vector<StringRef> removed_outputs;
603 Vector<StringRef> changed_outputs;
604 bool output_order = false;
605
606 for (const int new_item_i : new_signature.inputs.index_range()) {
607 const nodes::ClosureSignature::Item &new_item = new_signature.inputs[new_item_i];
608 const int old_item_i = old_signature.inputs.index_of_try_as(new_item.key);
609 if (old_item_i == -1) {
610 added_inputs.append(new_item.key);
611 }
612 else {
613 const nodes::ClosureSignature::Item &old_item = old_signature.inputs[old_item_i];
614 if (new_item != old_item) {
615 changed_inputs.append(new_item.key);
616 }
617 if (old_item_i != new_item_i) {
618 input_order = true;
619 }
620 }
621 }
622 for (const nodes::ClosureSignature::Item &old_item : old_signature.inputs) {
623 if (!new_signature.inputs.contains_as(old_item.key)) {
624 removed_inputs.append(old_item.key);
625 }
626 }
627 for (const int new_item_i : new_signature.outputs.index_range()) {
628 const nodes::ClosureSignature::Item &new_item = new_signature.outputs[new_item_i];
629 const int old_item_i = old_signature.outputs.index_of_try_as(new_item.key);
630 if (old_item_i == -1) {
631 added_outputs.append(new_item.key);
632 }
633 else {
634 const nodes::ClosureSignature::Item &old_item = old_signature.outputs[old_item_i];
635 if (new_item != old_item) {
636 changed_outputs.append(new_item.key);
637 }
638 if (old_item_i != new_item_i) {
639 output_order = true;
640 }
641 }
642 }
643 for (const nodes::ClosureSignature::Item &old_item : old_signature.outputs) {
644 if (!new_signature.outputs.contains_as(old_item.key)) {
645 removed_outputs.append(old_item.key);
646 }
647 }
648
649 fmt::memory_buffer string_buffer;
650 auto buf = fmt::appender(string_buffer);
651 if (!added_inputs.is_empty()) {
652 fmt::format_to(buf, "\u2022 {}: {}\n", TIP_("Add Inputs"), fmt::join(added_inputs, ", "));
653 }
654 if (!removed_inputs.is_empty()) {
655 fmt::format_to(buf, "\u2022 {}: {}\n", TIP_("Remove Inputs"), fmt::join(removed_inputs, ", "));
656 }
657 if (!changed_inputs.is_empty()) {
658 fmt::format_to(buf, "\u2022 {}: {}\n", TIP_("Change Inputs"), fmt::join(changed_inputs, ", "));
659 }
660 if (input_order) {
661 fmt::format_to(buf, "\u2022 {}\n", TIP_("Reorder Inputs"));
662 }
663 if (!added_outputs.is_empty()) {
664 fmt::format_to(buf, "\u2022 {}: {}\n", TIP_("Add Outputs"), fmt::join(added_outputs, ", "));
665 }
666 if (!removed_outputs.is_empty()) {
667 fmt::format_to(
668 buf, "\u2022 {}: {}\n", TIP_("Remove Outputs"), fmt::join(removed_outputs, ", "));
669 }
670 if (!changed_outputs.is_empty()) {
671 fmt::format_to(
672 buf, "\u2022 {}: {}\n", TIP_("Change Outputs"), fmt::join(changed_outputs, ", "));
673 }
674 if (output_order) {
675 fmt::format_to(buf, "\u2022 {}\n", TIP_("Reorder Outputs"));
676 }
677 fmt::format_to(buf, "\n{}", TIP_("Update based on linked closure signature"));
678
679 return fmt::to_string(string_buffer);
680}
681
683{
685 SpaceNode &snode = *CTX_wm_space_node(&C);
686 if (node.is_type("NodeEvaluateClosure"_ustr)) {
687 sync_sockets_evaluate_closure(snode, node, reports);
688 }
689 else if (node.is_type("NodeSeparateBundle"_ustr)) {
690 sync_sockets_separate_bundle(snode, node, reports);
691 }
692 else if (node.is_type("NodeCombineBundle"_ustr)) {
693 sync_sockets_combine_bundle(snode, node, reports);
694 }
695 else if (node.is_type("NodeClosureInput"_ustr)) {
696 bNode &closure_input_node = node;
697 if (bNode *closure_output_node = closure_zone_type.get_corresponding_output(
698 *snode.edittree, closure_input_node))
699 {
700 sync_sockets_closure(snode, closure_input_node, *closure_output_node, reports);
701 }
702 }
703 else if (node.is_type("NodeClosureOutput"_ustr)) {
704 bNode &closure_output_node = node;
705 if (bNode *closure_input_node = closure_zone_type.get_corresponding_input(*snode.edittree,
706 closure_output_node))
707 {
708 sync_sockets_closure(snode, *closure_input_node, closure_output_node, reports);
709 }
710 }
711 else if (node.is_type("GeometryNodeClosureToList"_ustr)) {
712 sync_sockets_closure_to_list(snode, node, reports);
713 }
714}
715
716std::string sync_node_description_get(const bContext &C, const bNode &node)
717{
718 const SpaceNode *snode = CTX_wm_space_node(&C);
719 if (!snode) {
720 return "";
721 }
722
723 if (node.is_type("NodeSeparateBundle"_ustr)) {
725 node, true);
726 if (const std::optional<nodes::BundleSignature> new_signature =
727 get_sync_state_separate_bundle(*snode, node).source_signature)
728 {
729 return get_bundle_sync_tooltip(old_signature, *new_signature);
730 }
731 }
732 else if (node.is_type("NodeCombineBundle"_ustr)) {
734 node, true);
735 if (const std::optional<nodes::BundleSignature> new_signature =
736 get_sync_state_combine_bundle(*snode, node).source_signature)
737 {
738 return get_bundle_sync_tooltip(old_signature, *new_signature);
739 }
740 }
741 else if (node.is_type("NodeEvaluateClosure"_ustr)) {
742 const nodes::ClosureSignature old_signature =
744 if (const std::optional<nodes::ClosureSignature> new_signature =
745 get_sync_state_evaluate_closure(*snode, node).source_signature)
746 {
747 return get_closure_sync_tooltip(old_signature, *new_signature);
748 }
749 }
750 else if (node.is_type("NodeClosureOutput"_ustr)) {
751 const nodes::ClosureSignature old_signature =
753 if (const std::optional<nodes::ClosureSignature> new_signature =
754 get_sync_state_closure_output(*snode, node).source_signature)
755 {
756 return get_closure_sync_tooltip(old_signature, *new_signature);
757 }
758 }
759 else if (node.is_type("GeometryNodeClosureToList"_ustr)) {
760 const nodes::ClosureSignature old_signature =
762 if (const std::optional<nodes::ClosureSignature> new_signature =
763 get_sync_state_closure_to_list(*snode, node).source_signature)
764 {
765 return get_closure_sync_tooltip(old_signature, *new_signature);
766 }
767 }
768 return "";
769}
770
771bool node_can_sync_sockets(const bContext &C, const bNodeTree & /*tree*/, const bNode &node)
772{
773 SpaceNode *snode = CTX_wm_space_node(&C);
774 if (!snode) {
775 return false;
776 }
778 const bool can_sync = cache.lookup_or_add_cb(node.identifier, [&]() {
779 if (node.is_type("NodeEvaluateClosure"_ustr)) {
780 return get_sync_state_evaluate_closure(*snode, node).source_signature.has_value();
781 }
782 if (node.is_type("NodeClosureOutput"_ustr)) {
783 return get_sync_state_closure_output(*snode, node).source_signature.has_value();
784 }
785 if (node.is_type("NodeCombineBundle"_ustr)) {
786 return get_sync_state_combine_bundle(*snode, node).source_signature.has_value();
787 }
788 if (node.is_type("NodeSeparateBundle"_ustr)) {
789 return get_sync_state_separate_bundle(*snode, node).source_signature.has_value();
790 }
791 if (node.is_type("GeometryNodeClosureToList"_ustr)) {
792 return get_sync_state_closure_to_list(*snode, node).source_signature.has_value();
793 }
794 return false;
795 });
796 return can_sync;
797}
798
800{
801 if (wmWindowManager *wm = bmain.wm.first()) {
802 for (wmWindow &window : wm->windows) {
804 for (ScrArea &area : screen->areabase) {
805 SpaceLink *sl = area.spacedata.first_as<SpaceLink>();
806 if (sl->spacetype == SPACE_NODE) {
807 SpaceNode *snode = reinterpret_cast<SpaceNode *>(sl);
809 cache.clear();
810 }
811 }
812 }
813 }
814}
815
816} // namespace blender::nodes
#define NODE_CLOSURE_OUTPUT
#define TIP_(msgid)
#define C
Definition RandGen.cpp:29
constexpr IndexRange()=default
void clear()
Definition BLI_map.hh:1038
std::optional< Value > lookup_try(const Key &key) const
Definition BLI_map.hh:531
Value & lookup_or_add_cb(const Key &key, const CreateValueF &create_value)
Definition BLI_map.hh:620
void add_new(const Key &key, const Value &value)
Definition BLI_map.hh:265
bool contains(const Key &key) const
Definition BLI_map.hh:353
constexpr StringRef()
void append(const T &value)
bool is_empty() const
const bNode * get_corresponding_input(const bNodeTree &tree, const bNode &output_bnode) const
const bNode * get_corresponding_output(const bNodeTree &tree, const bNode &input_bnode) const
static FlatBundleTypePtr try_find_single_flat(StringRef name)
CustomIDVectorSet< Item, ItemKeyGetter > inputs
CustomIDVectorSet< Item, ItemKeyGetter > outputs
static ClosureSignature from_evaluate_closure_node(const bNode &node, bool allow_auto_structure_type)
static ClosureSignature from_closure_output_node(const bNode &node, bool allow_auto_structure_type)
static ClosureSignature from_closure_to_list_node(const bNode &node)
#define storage(slot, qualifiers)
const bNodeZoneType * zone_type_by_node_type(const int node_type)
bNodeLink & node_add_link(bNodeTree &ntree, bNode &fromnode, bNodeSocket &fromsock, bNode &tonode, bNodeSocket &tosock)
Definition node.cc:4638
const ComputeContext * compute_context_for_edittree_socket(const SpaceNode &snode, bke::ComputeContextCache &compute_context_cache, const bNodeSocket &socket)
Map< int, bool > & node_can_sync_cache_get(SpaceNode &snode)
Accessor::ItemT * add_item_with_socket_type_and_name(bNodeTree &ntree, bNode &node, const eNodeSocketDatatype socket_type, const char *name, std::optional< int > dimensions=std::nullopt)
void sync_node(bContext &C, bNode &node, ReportList *reports)
static std::string get_bundle_sync_tooltip(const nodes::BundleSignature &old_signature, const nodes::BundleSignature &new_signature)
void sync_sockets_evaluate_closure(SpaceNode &snode, bNode &evaluate_closure_node, ReportList *reports, const bNodeSocket *src_closure_socket)
static ClosureSyncState get_sync_state_closure_to_list(const SpaceNode &snode, const bNode &closure_to_list_node, const bNodeSocket *src_closure_socket=nullptr)
bool node_can_sync_sockets(const bContext &C, const bNodeTree &, const bNode &node)
void sync_sockets_combine_bundle(SpaceNode &snode, bNode &combine_bundle_node, ReportList *reports, const bNodeSocket *src_bundle_socket)
void sync_sockets_separate_bundle(SpaceNode &snode, bNode &separate_bundle_node, ReportList *reports, const bNodeSocket *src_bundle_socket)
void sync_sockets_closure(SpaceNode &snode, bNode &closure_input_node, bNode &closure_output_node, ReportList *reports, const bNodeSocket *src_closure_socket)
LinkedBundleSignatures gather_linked_target_bundle_signatures(const ComputeContext *bundle_socket_context, const bNodeSocket &bundle_socket, bke::ComputeContextCache &compute_context_cache)
static BundleSyncState get_sync_state_combine_bundle(const SpaceNode &snode, const bNode &combine_bundle_node, const bNodeSocket *src_bundle_socket=nullptr)
static ClosureSyncState get_sync_state_closure_output(const SpaceNode &snode, const bNode &closure_output_node, const bNodeSocket *src_closure_socket=nullptr)
void update_node_declaration_and_sockets(bNodeTree &ntree, bNode &node, Main *bmain)
static BundleSyncState get_sync_state_separate_bundle(const SpaceNode &snode, const bNode &separate_bundle_node, const bNodeSocket *src_bundle_socket=nullptr)
std::shared_ptr< const FlatBundleType > FlatBundleTypePtr
LinkedClosureSignatures gather_linked_target_closure_signatures(const ComputeContext *closure_socket_context, const bNodeSocket &closure_socket, bke::ComputeContextCache &compute_context_cache)
static std::string get_closure_sync_tooltip(const nodes::ClosureSignature &old_signature, const nodes::ClosureSignature &new_signature)
static LinkedBundleSignatures get_expected_combine_bundle_signatures(const SpaceNode &snode, const bNode &combine_bundle_node, const bNodeSocket *src_bundle_socket)
void node_can_sync_cache_clear(Main &bmain)
static ClosureSyncState get_sync_state_evaluate_closure(const SpaceNode &snode, const bNode &evaluate_closure_node, const bNodeSocket *src_closure_socket=nullptr)
void sync_sockets_closure_to_list(SpaceNode &snode, bNode &closure_to_list_node, ReportList *reports, const bNodeSocket *src_closure_socket)
LinkedBundleSignatures gather_linked_origin_bundle_signatures(const ComputeContext *bundle_socket_context, const bNodeSocket &bundle_socket, bke::ComputeContextCache &compute_context_cache)
LinkedClosureSignatures gather_linked_origin_closure_signatures(const ComputeContext *closure_socket_context, const bNodeSocket &closure_socket, bke::ComputeContextCache &compute_context_cache)
std::optional< StringRefNull > combine_bundle_node_type(const bNodeTree &tree, const bNode &node)
std::string sync_node_description_get(const bContext &C, const bNode &node)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
@ RPT_WARNING
Definition BKE_report.hh:40
bScreen * BKE_workspace_active_screen_get(const WorkSpaceInstanceHook *hook) GETTER_ATTRS
Definition workspace.cc:684
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
SpaceNode * CTX_wm_space_node(const bContext *C)
void BKE_ntree_update_tag_node_property(bNodeTree *ntree, bNode *node)
NodeSocketInterfaceStructureType structure_type
ListBaseT< wmWindowManager > wm
Definition BKE_main.hh:415
NodeSocketInterfaceStructureType structure_type
NodeSocketInterfaceStructureType structure_type
NodeSocketInterfaceStructureType structure_type
NodeSocketInterfaceStructureType structure_type
NodeSocketInterfaceStructureType structure_type
NodeSocketInterfaceStructureType structure_type
ListBaseT< SpaceLink > spacedata
struct bNodeTree * edittree
eNodeSocketDatatype type
bke::bNodeTreeType * typeinfo
ListBaseT< struct ScrArea > areabase
eNodeSocketDatatype type
Definition BKE_node.hh:198
bool(*) validate_link(eNodeSocketDatatype from, eNodeSocketDatatype to)
Definition BKE_node.hh:566
static BundleSignature from_separate_bundle_node(const bNode &node, bool allow_auto_structure_type)
CustomIDVectorSet< Item, ItemKeyGetter > items
static BundleSignature from_combine_bundle_node(const bNode &node, bool allow_auto_structure_type)
std::optional< nodes::BundleSignature > source_signature
std::optional< nodes::ClosureSignature > source_signature
std::optional< BundleSignature > get_merged_signature() const
std::optional< ClosureSignature > get_merged_signature() const
struct WorkSpaceInstanceHook * workspace_hook