58 const bNode &separate_bundle_node,
61 BLI_assert(separate_bundle_node.is_type(
"NodeSeparateBundle"));
62 snode.
edittree->ensure_topology_cache();
63 if (!src_bundle_socket) {
64 src_bundle_socket = &separate_bundle_node.input_socket(0);
70 snode, compute_context_cache, *src_bundle_socket);
71 if (!current_context) {
75 current_context, *src_bundle_socket, compute_context_cache);
80 if (!merged_signature.has_value()) {
84 merged_signature->set_auto_structure_types();
88 if (*merged_signature != current_signature) {
96 const bNode &combine_bundle_node,
99 BLI_assert(combine_bundle_node.is_type(
"NodeCombineBundle"));
100 snode.
edittree->ensure_topology_cache();
101 if (!src_bundle_socket) {
102 src_bundle_socket = &combine_bundle_node.output_socket(0);
108 snode, compute_context_cache, *src_bundle_socket);
109 if (!current_context) {
113 current_context, *src_bundle_socket, compute_context_cache);
118 if (!merged_signature.has_value()) {
122 merged_signature->set_auto_structure_types();
126 if (*merged_signature != current_signature) {
134 const bNode &closure_output_node,
137 snode.
edittree->ensure_topology_cache();
138 if (!src_closure_socket) {
139 src_closure_socket = &closure_output_node.output_socket(0);
145 snode, compute_context_cache, *src_closure_socket);
146 if (!current_context) {
150 current_context, *src_closure_socket, compute_context_cache);
155 if (!merged_signature.has_value()) {
159 merged_signature->set_auto_structure_types();
163 if (*merged_signature != current_signature) {
171 const bNode &evaluate_closure_node,
174 snode.
edittree->ensure_topology_cache();
175 if (!src_closure_socket) {
176 src_closure_socket = &evaluate_closure_node.input_socket(0);
182 snode, compute_context_cache, *src_closure_socket);
183 if (!current_context) {
187 current_context, *src_closure_socket, compute_context_cache);
192 if (!merged_signature.has_value()) {
196 merged_signature->set_auto_structure_types();
200 if (*merged_signature != current_signature) {
207 bNode &separate_bundle_node,
212 snode, separate_bundle_node, src_bundle_socket);
213 switch (sync_state.
state) {
229 for (
const int i :
IndexRange(storage.items_num)) {
237 nodes ::SeparateBundleItemsAccessor>(
240 if (
const std::optional<int> old_identifier = old_identifiers.
lookup_try(item.
key)) {
248 bNode &combine_bundle_node,
253 snode, combine_bundle_node, src_bundle_socket);
254 switch (sync_state.
state) {
270 for (
const int i :
IndexRange(storage.items_num)) {
278 nodes ::CombineBundleItemsAccessor>(
281 if (
const std::optional<int> old_identifier = old_identifiers.
lookup_try(item.
key)) {
290 bNode &evaluate_closure_node,
295 snode, evaluate_closure_node, src_closure_socket);
296 switch (sync_state.
state) {
313 for (
const int i :
IndexRange(storage.input_items.items_num)) {
317 for (
const int i :
IndexRange(storage.output_items.items_num)) {
331 if (
const std::optional<int> old_identifier = old_input_identifiers.
lookup_try(item.
key)) {
341 if (
const std::optional<int> old_identifier = old_output_identifiers.
lookup_try(item.
key)) {
349 bNode &closure_input_node,
350 bNode &closure_output_node,
355 snode, closure_output_node, src_closure_socket);
356 switch (sync_state.
state) {
374 for (
const int i :
IndexRange(storage.input_items.items_num)) {
378 for (
const int i :
IndexRange(storage.output_items.items_num)) {
391 if (
const std::optional<int> old_identifier = old_input_identifiers.
lookup_try(item.
key)) {
400 if (
const std::optional<int> old_identifier = old_output_identifiers.
lookup_try(item.
key)) {
411 snode.
edittree->ensure_topology_cache();
413 for (
const int input_i : signature.
inputs.index_range()) {
415 if (old_input_identifiers.
contains(input_item.
key)) {
418 for (
const int output_i : signature.
outputs.index_range()) {
420 if (old_output_identifiers.
contains(output_item.
key)) {
423 if (input_item.
key == output_item.
key) {
424 internal_links.
append({&closure_input_node.output_socket(input_i),
425 &closure_output_node.input_socket(output_i)});
429 for (
auto &&[from_socket, to_socket] : internal_links) {
432 to_socket->typeinfo->type))
435 *snode.
edittree, closure_input_node, *from_socket, closure_output_node, *to_socket);
446 bool order_changed =
false;
448 for (
const int new_item_i : new_signature.
items.index_range()) {
450 const int old_item_i = old_signature.
items.index_of_try_as(new_item.
key);
451 if (old_item_i == -1) {
456 if (new_item != old_item) {
459 if (old_item_i != new_item_i) {
460 order_changed =
true;
465 if (!new_signature.
items.contains_as(old_item.
key)) {
470 fmt::memory_buffer string_buffer;
471 auto buf = fmt::appender(string_buffer);
473 fmt::format_to(buf,
"\u2022 {}: {}\n",
TIP_(
"Add"), fmt::join(added_items,
", "));
476 fmt::format_to(buf,
"\u2022 {}: {}\n",
TIP_(
"Remove"), fmt::join(removed_items,
", "));
479 fmt::format_to(buf,
"\u2022 {}: {}\n",
TIP_(
"Change"), fmt::join(changed_items,
", "));
482 fmt::format_to(buf,
"\u2022 {}",
TIP_(
"Reorder"));
484 fmt::format_to(buf,
"\n{}",
TIP_(
"Update based on linked bundle signature"));
486 return fmt::to_string(string_buffer);
495 bool input_order =
false;
500 bool output_order =
false;
502 for (
const int new_item_i : new_signature.
inputs.index_range()) {
504 const int old_item_i = old_signature.
inputs.index_of_try_as(new_item.
key);
505 if (old_item_i == -1) {
510 if (new_item != old_item) {
513 if (old_item_i != new_item_i) {
519 if (!new_signature.
inputs.contains_as(old_item.
key)) {
523 for (
const int new_item_i : new_signature.
outputs.index_range()) {
525 const int old_item_i = old_signature.
outputs.index_of_try_as(new_item.
key);
526 if (old_item_i == -1) {
531 if (new_item != old_item) {
534 if (old_item_i != new_item_i) {
540 if (!new_signature.
outputs.contains_as(old_item.
key)) {
545 fmt::memory_buffer string_buffer;
546 auto buf = fmt::appender(string_buffer);
548 fmt::format_to(buf,
"\u2022 {}: {}\n",
TIP_(
"Add Inputs"), fmt::join(added_inputs,
", "));
551 fmt::format_to(buf,
"\u2022 {}: {}\n",
TIP_(
"Remove Inputs"), fmt::join(removed_inputs,
", "));
554 fmt::format_to(buf,
"\u2022 {}: {}\n",
TIP_(
"Change Inputs"), fmt::join(changed_inputs,
", "));
557 fmt::format_to(buf,
"\u2022 {}\n",
TIP_(
"Reorder Inputs"));
560 fmt::format_to(buf,
"\u2022 {}: {}\n",
TIP_(
"Add Outputs"), fmt::join(added_outputs,
", "));
564 buf,
"\u2022 {}: {}\n",
TIP_(
"Remove Outputs"), fmt::join(removed_outputs,
", "));
568 buf,
"\u2022 {}: {}\n",
TIP_(
"Change Outputs"), fmt::join(changed_outputs,
", "));
571 fmt::format_to(buf,
"\u2022 {}\n",
TIP_(
"Reorder Outputs"));
573 fmt::format_to(buf,
"\n{}",
TIP_(
"Update based on linked closure signature"));
575 return fmt::to_string(string_buffer);
582 if (node.is_type(
"NodeEvaluateClosure")) {
585 else if (node.is_type(
"NodeSeparateBundle")) {
588 else if (node.is_type(
"NodeCombineBundle")) {
591 else if (node.is_type(
"NodeClosureInput")) {
592 bNode &closure_input_node = node;
594 *snode.
edittree, closure_input_node))
599 else if (node.is_type(
"NodeClosureOutput")) {
600 bNode &closure_output_node = node;
602 closure_output_node))
616 if (node.is_type(
"NodeSeparateBundle")) {
619 if (
const std::optional<nodes::BundleSignature> new_signature =
625 else if (node.is_type(
"NodeCombineBundle")) {
628 if (
const std::optional<nodes::BundleSignature> new_signature =
634 else if (node.is_type(
"NodeEvaluateClosure")) {
637 if (
const std::optional<nodes::ClosureSignature> new_signature =
643 else if (node.is_type(
"NodeClosureOutput")) {
646 if (
const std::optional<nodes::ClosureSignature> new_signature =
663 if (node.is_type(
"NodeEvaluateClosure")) {
664 return get_sync_state_evaluate_closure(*snode, node).source_signature.has_value();
666 if (node.is_type(
"NodeClosureOutput")) {
667 return get_sync_state_closure_output(*snode, node).source_signature.has_value();
669 if (node.is_type(
"NodeCombineBundle")) {
670 return get_sync_state_combine_bundle(*snode, node).source_signature.has_value();
672 if (node.is_type(
"NodeSeparateBundle")) {
673 return get_sync_state_separate_bundle(*snode, node).source_signature.has_value();
SpaceNode * CTX_wm_space_node(const bContext *C)
#define NODE_CLOSURE_OUTPUT
void BKE_ntree_update_tag_node_property(bNodeTree *ntree, bNode *node)
void BKE_report(ReportList *reports, eReportType type, const char *message)
bScreen * BKE_workspace_active_screen_get(const WorkSpaceInstanceHook *hook) GETTER_ATTRS
#define LISTBASE_FOREACH(type, var, list)
std::optional< Value > lookup_try(const Key &key) const
Value & lookup_or_add_cb(const Key &key, const CreateValueF &create_value)
void add_new(const Key &key, const Value &value)
bool contains(const Key &key) const
void append(const T &value)
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
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)
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)
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)
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)
static BundleSyncState get_sync_state_separate_bundle(const SpaceNode &snode, const bNode &separate_bundle_node, const bNodeSocket *src_bundle_socket=nullptr)
void update_node_declaration_and_sockets(bNodeTree &ntree, bNode &node)
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)
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)
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::string sync_node_description_get(const bContext &C, const bNode &node)
SpaceNode_Runtime * runtime
struct bNodeTree * edittree
bNodeTreeTypeHandle * typeinfo
const bke::bNodeSocketType * type
NodeSocketInterfaceStructureType structure_type
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
NodeSocketInterfaceStructureType structure_type
const bke::bNodeSocketType * type
std::optional< nodes::ClosureSignature > source_signature
bool has_type_definition() const
std::optional< BundleSignature > get_merged_signature() const
bool has_type_definition() const
std::optional< ClosureSignature > get_merged_signature() const