@@ -5,14 +5,16 @@ use graphene_std::uuid::NodeId;
55use crate :: {
66 consts:: { EXPORTS_TO_RIGHT_EDGE_PIXEL_GAP , EXPORTS_TO_TOP_EDGE_PIXEL_GAP , GRID_SIZE , IMPORTS_TO_LEFT_EDGE_PIXEL_GAP , IMPORTS_TO_TOP_EDGE_PIXEL_GAP } ,
77 messages:: portfolio:: document:: {
8- node_graph:: utility_types:: { FrontendGraphDataType , FrontendGraphInput , FrontendGraphOutput , FrontendNode , FrontendXY } ,
8+ node_graph:: utility_types:: {
9+ FrontendGraphDataType , FrontendGraphInput , FrontendGraphOutput , FrontendLayer , FrontendNode , FrontendNodeMetadata , FrontendNodeOrLayer , FrontendNodeToRender , FrontendXY ,
10+ } ,
911 utility_types:: network_interface:: { FlowType , InputConnector , NodeNetworkInterface , OutputConnector } ,
1012 } ,
1113} ;
1214
1315// Functions used to collect data from the network interface for use in rendering the node graph
1416impl NodeNetworkInterface {
15- pub fn collect_nodes ( & mut self , node_graph_errors : & GraphErrors , network_path : & [ NodeId ] ) -> Vec < FrontendNode > {
17+ pub fn collect_nodes ( & mut self , node_graph_errors : & GraphErrors , network_path : & [ NodeId ] ) -> Vec < FrontendNodeToRender > {
1618 let Some ( network) = self . nested_network ( network_path) else {
1719 log:: error!( "Could not get nested network when collecting nodes" ) ;
1820 return Vec :: new ( ) ;
@@ -22,32 +24,6 @@ impl NodeNetworkInterface {
2224 for ( node_id, visible) in network. nodes . iter ( ) . map ( |( node_id, node) | ( * node_id, node. visible ) ) . collect :: < Vec < _ > > ( ) {
2325 let node_id_path = [ network_path, & [ node_id] ] . concat ( ) ;
2426
25- let primary_input_connector = InputConnector :: node ( node_id, 0 ) ;
26-
27- let primary_input = if self . input_from_connector ( & primary_input_connector, network_path) . is_some_and ( |input| input. is_exposed ( ) ) {
28- self . frontend_input_from_connector ( & primary_input_connector, network_path)
29- } else {
30- None
31- } ;
32- let exposed_inputs = ( 1 ..self . number_of_inputs ( & node_id, network_path) )
33- . filter_map ( |input_index| self . frontend_input_from_connector ( & InputConnector :: node ( node_id, input_index) , network_path) )
34- . collect ( ) ;
35-
36- let primary_output = self . frontend_output_from_connector ( & OutputConnector :: node ( node_id, 0 ) , network_path) ;
37-
38- let exposed_outputs = ( 1 ..self . number_of_outputs ( & node_id, network_path) )
39- . filter_map ( |output_index| self . frontend_output_from_connector ( & OutputConnector :: node ( node_id, output_index) , network_path) )
40- . collect ( ) ;
41-
42- let Some ( position) = self . position ( & node_id, network_path) else {
43- log:: error!( "Could not get position for node: {node_id}" ) ;
44- continue ;
45- } ;
46- let position = FrontendXY { x : position. x , y : position. y } ;
47- let previewed = self . previewed_node ( network_path) == Some ( node_id) ;
48-
49- let locked = self . is_locked ( & node_id, network_path) ;
50-
5127 let errors = node_graph_errors
5228 . iter ( )
5329 . find ( |error| error. node_path == node_id_path)
@@ -60,31 +36,73 @@ impl NodeNetworkInterface {
6036 }
6137 } ) ;
6238
63- nodes. push ( FrontendNode {
64- id : node_id,
65- is_layer : self . node_metadata ( & node_id, network_path) . is_some_and ( |node_metadata| node_metadata. persistent_metadata . is_layer ( ) ) ,
39+ let metadata = FrontendNodeMetadata {
40+ node_id,
6641 can_be_layer : self . is_eligible_to_be_layer ( & node_id, network_path) ,
42+ display_name : self . display_name ( & node_id, network_path) ,
6743 selected : selected_nodes. 0 . contains ( & node_id) ,
6844 reference : self . reference ( & node_id, network_path) . cloned ( ) . unwrap_or_default ( ) ,
69- display_name : self . display_name ( & node_id, network_path) ,
70- previewed,
7145 visible,
7246 errors,
47+ } ;
7348
74- primary_input,
75- exposed_inputs,
76- primary_output,
77- exposed_outputs,
78- position,
79-
80- locked,
81- chain_width : self . chain_width ( & node_id, network_path) ,
82- layer_has_left_border_gap : self . layer_has_left_border_gap ( & node_id, network_path) ,
83- primary_input_connected_to_layer : self . primary_output_connected_to_layer ( & node_id, network_path) ,
84- primary_output_connected_to_layer : self . primary_input_connected_to_layer ( & node_id, network_path) ,
85- } ) ;
86- }
49+ let node_or_layer = match self . is_layer ( & node_id, network_path) {
50+ true => {
51+ let Some ( position) = self . position ( & node_id, network_path) else {
52+ log:: error!( "Could not get position for node: {node_id}" ) ;
53+ continue ;
54+ } ;
55+ let position = FrontendXY { x : position. x , y : position. y } ;
56+
57+ let Some ( bottom_input) = self . frontend_input_from_connector ( & InputConnector :: node ( node_id, 0 ) , network_path) else {
58+ log:: error!( "Layer must have a visible primary input" ) ;
59+ continue ;
60+ } ;
61+ let side_input = self . frontend_input_from_connector ( & InputConnector :: node ( node_id, 1 ) , network_path) ;
62+ let Some ( output) = self . frontend_output_from_connector ( & OutputConnector :: node ( node_id, 0 ) , network_path) else {
63+ log:: error!( "Layer must have a visible primary output" ) ;
64+ continue ;
65+ } ;
66+
67+ let layer = Some ( FrontendLayer {
68+ bottom_input,
69+ side_input,
70+ output,
71+ position,
72+ locked : self . is_locked ( & node_id, network_path) ,
73+ chain_width : self . chain_width ( & node_id, network_path) ,
74+ layer_has_left_border_gap : self . layer_has_left_border_gap ( & node_id, network_path) ,
75+ primary_input_connected_to_layer : self . primary_output_connected_to_layer ( & node_id, network_path) ,
76+ primary_output_connected_to_layer : self . primary_input_connected_to_layer ( & node_id, network_path) ,
77+ } ) ;
78+ FrontendNodeOrLayer { node : None , layer }
79+ }
80+ false => {
81+ let Some ( position) = self . position ( & node_id, network_path) else {
82+ log:: error!( "Could not get position for node: {node_id}" ) ;
83+ continue ;
84+ } ;
85+
86+ let position = FrontendXY { x : position. x , y : position. y } ;
87+
88+ let inputs = ( 0 ..self . number_of_inputs ( & node_id, network_path) )
89+ . map ( |input_index| self . frontend_input_from_connector ( & InputConnector :: node ( node_id, input_index) , network_path) )
90+ . collect ( ) ;
8791
92+ let outputs = ( 0 ..self . number_of_outputs ( & node_id, network_path) )
93+ . map ( |output_index| self . frontend_output_from_connector ( & OutputConnector :: node ( node_id, output_index) , network_path) )
94+ . collect ( ) ;
95+
96+ let node = Some ( FrontendNode { position, inputs, outputs } ) ;
97+
98+ FrontendNodeOrLayer { node, layer : None }
99+ }
100+ } ;
101+
102+ let frontend_node_to_render = FrontendNodeToRender { metadata, node_or_layer } ;
103+
104+ nodes. push ( frontend_node_to_render) ;
105+ }
88106 nodes
89107 }
90108
@@ -146,12 +164,15 @@ impl NodeNetworkInterface {
146164 // }
147165 // };
148166
167+ let connected_to_node = self . upstream_output_connector ( input_connector, network_path) . and_then ( |output_connector| output_connector. node_id ( ) ) ;
168+
149169 Some ( FrontendGraphInput {
150170 data_type,
151171 resolved_type,
152172 name,
153173 description,
154174 connected_to,
175+ connected_to_node,
155176 } )
156177 }
157178
0 commit comments