10#include <fmt/ranges.h>
65 const bNode &separate_bundle_node,
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);
77 snode, compute_context_cache, *src_bundle_socket);
78 if (!current_context) {
82 current_context, *src_bundle_socket, compute_context_cache);
83 if (linked_signatures.
items.is_empty()) {
87 if (!merged_signature.has_value()) {
91 merged_signature->set_auto_structure_types();
95 if (*merged_signature != current_signature) {
104 BLI_assert(combine_bundle_node.is_type(
"NodeCombineBundle"_ustr));
105 snode.
edittree->ensure_topology_cache();
107 if (!src_bundle_socket) {
108 src_bundle_socket = &combine_bundle_node.output_socket(0);
114 snode, compute_context_cache, *src_bundle_socket);
115 if (!current_context) {
120 combine_bundle_node);
126 result.items.append({flat_bundle_type->to_bundle_signature(),
true, socket});
131 current_context, *src_bundle_socket, compute_context_cache);
136 const bNode &combine_bundle_node,
140 snode, combine_bundle_node, src_bundle_socket);
141 if (source_signatures.
items.is_empty()) {
145 if (!merged_signature.has_value()) {
149 merged_signature->set_auto_structure_types();
153 if (*merged_signature != current_signature) {
161 const bNode &closure_output_node,
164 snode.
edittree->ensure_topology_cache();
165 if (!src_closure_socket) {
166 src_closure_socket = &closure_output_node.output_socket(0);
172 snode, compute_context_cache, *src_closure_socket);
173 if (!current_context) {
177 current_context, *src_closure_socket, compute_context_cache);
178 if (linked_signatures.
items.is_empty()) {
182 if (!merged_signature.has_value()) {
186 merged_signature->set_auto_structure_types();
190 if (*merged_signature != current_signature) {
198 const bNode &evaluate_closure_node,
201 snode.
edittree->ensure_topology_cache();
202 if (!src_closure_socket) {
203 src_closure_socket = &evaluate_closure_node.input_socket(0);
209 snode, compute_context_cache, *src_closure_socket);
210 if (!current_context) {
214 current_context, *src_closure_socket, compute_context_cache);
215 if (linked_signatures.
items.is_empty()) {
219 if (!merged_signature.has_value()) {
223 merged_signature->set_auto_structure_types();
227 if (*merged_signature != current_signature) {
235 const bNode &closure_to_list_node,
238 snode.
edittree->ensure_topology_cache();
239 if (!src_closure_socket) {
240 src_closure_socket = closure_to_list_node.input_by_identifier(
"Closure"_ustr);
245 snode, compute_context_cache, *src_closure_socket);
246 if (!current_context) {
250 current_context, *src_closure_socket, compute_context_cache);
251 if (linked_signatures.
items.is_empty()) {
255 if (!merged_signature.has_value()) {
259 closure_to_list_node);
260 if (*merged_signature != current_signature) {
267 bNode &separate_bundle_node,
272 snode, separate_bundle_node, src_bundle_socket);
273 switch (sync_state.
state) {
297 nodes ::SeparateBundleItemsAccessor>(
300 if (
const std::optional<int> old_identifier = old_identifiers.
lookup_try(item.
key)) {
308 bNode &combine_bundle_node,
313 snode, combine_bundle_node, src_bundle_socket);
314 switch (sync_state.
state) {
338 nodes ::CombineBundleItemsAccessor>(
341 if (
const std::optional<int> old_identifier = old_identifiers.
lookup_try(item.
key)) {
350 bNode &evaluate_closure_node,
355 snode, evaluate_closure_node, src_closure_socket);
356 switch (sync_state.
state) {
391 if (
const std::optional<int> old_identifier = old_input_identifiers.
lookup_try(item.
key)) {
401 if (
const std::optional<int> old_identifier = old_output_identifiers.
lookup_try(item.
key)) {
409 bNode &closure_input_node,
410 bNode &closure_output_node,
415 snode, closure_output_node, src_closure_socket);
416 switch (sync_state.
state) {
451 if (
const std::optional<int> old_identifier = old_input_identifiers.
lookup_try(item.
key)) {
460 if (
const std::optional<int> old_identifier = old_output_identifiers.
lookup_try(item.
key)) {
471 snode.
edittree->ensure_topology_cache();
473 for (
const int input_i : signature.
inputs.index_range()) {
475 if (old_input_identifiers.
contains(input_item.
key)) {
478 for (
const int output_i : signature.
outputs.index_range()) {
480 if (old_output_identifiers.
contains(output_item.
key)) {
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)});
489 for (
auto &&[from_socket, to_socket] : internal_links) {
492 to_socket->typeinfo->type))
495 *snode.
edittree, closure_input_node, *from_socket, closure_output_node, *to_socket);
501 bNode &closure_to_list_node,
506 snode, closure_to_list_node, src_closure_socket);
507 switch (sync_state.
state) {
535 if (
const std::optional<int> old_identifier = old_identifiers.
lookup_try(item.
key)) {
550 bool order_changed =
false;
552 for (
const int new_item_i : new_signature.
items.index_range()) {
554 const int old_item_i = old_signature.
items.index_of_try_as(new_item.
key);
555 if (old_item_i == -1) {
560 if (new_item != old_item) {
563 if (old_item_i != new_item_i) {
564 order_changed =
true;
569 if (!new_signature.
items.contains_as(old_item.
key)) {
574 fmt::memory_buffer string_buffer;
575 auto buf = fmt::appender(string_buffer);
577 fmt::format_to(buf,
"\u2022 {}: {}\n",
TIP_(
"Add"), fmt::join(added_items,
", "));
580 fmt::format_to(buf,
"\u2022 {}: {}\n",
TIP_(
"Remove"), fmt::join(removed_items,
", "));
583 fmt::format_to(buf,
"\u2022 {}: {}\n",
TIP_(
"Change"), fmt::join(changed_items,
", "));
586 fmt::format_to(buf,
"\u2022 {}",
TIP_(
"Reorder"));
588 fmt::format_to(buf,
"\n{}",
TIP_(
"Update based on linked bundle signature"));
590 return fmt::to_string(string_buffer);
599 bool input_order =
false;
604 bool output_order =
false;
606 for (
const int new_item_i : new_signature.
inputs.index_range()) {
608 const int old_item_i = old_signature.
inputs.index_of_try_as(new_item.
key);
609 if (old_item_i == -1) {
614 if (new_item != old_item) {
617 if (old_item_i != new_item_i) {
623 if (!new_signature.
inputs.contains_as(old_item.
key)) {
627 for (
const int new_item_i : new_signature.
outputs.index_range()) {
629 const int old_item_i = old_signature.
outputs.index_of_try_as(new_item.
key);
630 if (old_item_i == -1) {
635 if (new_item != old_item) {
638 if (old_item_i != new_item_i) {
644 if (!new_signature.
outputs.contains_as(old_item.
key)) {
649 fmt::memory_buffer string_buffer;
650 auto buf = fmt::appender(string_buffer);
652 fmt::format_to(buf,
"\u2022 {}: {}\n",
TIP_(
"Add Inputs"), fmt::join(added_inputs,
", "));
655 fmt::format_to(buf,
"\u2022 {}: {}\n",
TIP_(
"Remove Inputs"), fmt::join(removed_inputs,
", "));
658 fmt::format_to(buf,
"\u2022 {}: {}\n",
TIP_(
"Change Inputs"), fmt::join(changed_inputs,
", "));
661 fmt::format_to(buf,
"\u2022 {}\n",
TIP_(
"Reorder Inputs"));
664 fmt::format_to(buf,
"\u2022 {}: {}\n",
TIP_(
"Add Outputs"), fmt::join(added_outputs,
", "));
668 buf,
"\u2022 {}: {}\n",
TIP_(
"Remove Outputs"), fmt::join(removed_outputs,
", "));
672 buf,
"\u2022 {}: {}\n",
TIP_(
"Change Outputs"), fmt::join(changed_outputs,
", "));
675 fmt::format_to(buf,
"\u2022 {}\n",
TIP_(
"Reorder Outputs"));
677 fmt::format_to(buf,
"\n{}",
TIP_(
"Update based on linked closure signature"));
679 return fmt::to_string(string_buffer);
686 if (
node.is_type(
"NodeEvaluateClosure"_ustr)) {
689 else if (
node.is_type(
"NodeSeparateBundle"_ustr)) {
692 else if (
node.is_type(
"NodeCombineBundle"_ustr)) {
695 else if (
node.is_type(
"NodeClosureInput"_ustr)) {
698 *snode.
edittree, closure_input_node))
703 else if (
node.is_type(
"NodeClosureOutput"_ustr)) {
706 closure_output_node))
711 else if (
node.is_type(
"GeometryNodeClosureToList"_ustr)) {
723 if (
node.is_type(
"NodeSeparateBundle"_ustr)) {
726 if (
const std::optional<nodes::BundleSignature> new_signature =
732 else if (
node.is_type(
"NodeCombineBundle"_ustr)) {
735 if (
const std::optional<nodes::BundleSignature> new_signature =
741 else if (
node.is_type(
"NodeEvaluateClosure"_ustr)) {
744 if (
const std::optional<nodes::ClosureSignature> new_signature =
750 else if (
node.is_type(
"NodeClosureOutput"_ustr)) {
753 if (
const std::optional<nodes::ClosureSignature> new_signature =
759 else if (
node.is_type(
"GeometryNodeClosureToList"_ustr)) {
762 if (
const std::optional<nodes::ClosureSignature> new_signature =
779 if (node.is_type(
"NodeEvaluateClosure"_ustr)) {
780 return get_sync_state_evaluate_closure(*snode, node).source_signature.has_value();
782 if (
node.is_type(
"NodeClosureOutput"_ustr)) {
783 return get_sync_state_closure_output(*snode, node).source_signature.has_value();
785 if (
node.is_type(
"NodeCombineBundle"_ustr)) {
786 return get_sync_state_combine_bundle(*snode, node).source_signature.has_value();
788 if (
node.is_type(
"NodeSeparateBundle"_ustr)) {
789 return get_sync_state_separate_bundle(*snode, node).source_signature.has_value();
791 if (
node.is_type(
"GeometryNodeClosureToList"_ustr)) {
792 return get_sync_state_closure_to_list(*snode, node).source_signature.has_value();
#define NODE_CLOSURE_OUTPUT
constexpr IndexRange()=default
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
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)
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)
bScreen * BKE_workspace_active_screen_get(const WorkSpaceInstanceHook *hook) GETTER_ATTRS
void BKE_report(ReportList *reports, eReportType type, const char *message)
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
NodeSocketInterfaceStructureType structure_type
NodeSocketInterfaceStructureType structure_type
NodeSocketInterfaceStructureType structure_type
NodeSocketInterfaceStructureType structure_type
ListBaseT< SpaceLink > spacedata
struct bNodeTree * edittree
bke::bNodeTreeType * typeinfo
ListBaseT< struct ScrArea > areabase
bool(*) validate_link(eNodeSocketDatatype from, eNodeSocketDatatype to)
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
struct WorkSpaceInstanceHook * workspace_hook