@@ -203,12 +203,12 @@ impl NodeNetworkInterface {
203
203
}
204
204
205
205
/// Returns the first downstream layer(inclusive) from a node. If the node is a layer, it will return itself.
206
- pub fn downstream_layer ( & mut self , node_id : & NodeId , network_path : & [ NodeId ] ) -> Option < LayerNodeIdentifier > {
206
+ pub fn downstream_layer_for_chain_node ( & mut self , node_id : & NodeId , network_path : & [ NodeId ] ) -> Option < NodeId > {
207
207
let mut id = * node_id;
208
208
while !self . is_layer ( & id, network_path) {
209
209
id = self . outward_wires ( network_path) ?. get ( & OutputConnector :: node ( id, 0 ) ) ?. first ( ) ?. node_id ( ) ?;
210
210
}
211
- Some ( LayerNodeIdentifier :: new ( id , self , network_path ) )
211
+ Some ( id )
212
212
}
213
213
214
214
/// Returns all downstream layers (inclusive) from a node. If the node is a layer, it will return itself.
@@ -388,8 +388,8 @@ impl NodeNetworkInterface {
388
388
}
389
389
390
390
// If a chain node does not have a selected downstream layer, then set the position to absolute
391
- let downstream_layer = self . downstream_layer ( node_id, network_path) ;
392
- if downstream_layer. is_none_or ( |downstream_layer| new_ids. keys ( ) . all ( |key| * key != downstream_layer. to_node ( ) ) ) {
391
+ let downstream_layer = self . downstream_layer_for_chain_node ( node_id, network_path) ;
392
+ if downstream_layer. is_none_or ( |downstream_layer| new_ids. keys ( ) . all ( |key| * key != downstream_layer) ) {
393
393
let Some ( position) = self . position ( node_id, network_path) else {
394
394
log:: error!( "Could not get position in create_node_template" ) ;
395
395
return None ;
@@ -1244,7 +1244,7 @@ impl NodeNetworkInterface {
1244
1244
. as_ref ( )
1245
1245
. is_some_and ( |reference| reference == "Artboard" && self . connected_to_output ( node_id, & [ ] ) && self . is_layer ( node_id, & [ ] ) )
1246
1246
{
1247
- Some ( LayerNodeIdentifier :: new ( * node_id, self , & [ ] ) )
1247
+ Some ( LayerNodeIdentifier :: new ( * node_id, self ) )
1248
1248
} else {
1249
1249
None
1250
1250
}
@@ -3025,7 +3025,7 @@ impl NodeNetworkInterface {
3025
3025
3026
3026
// Helper functions for mutable getters
3027
3027
impl NodeNetworkInterface {
3028
- pub fn upstream_chain_nodes ( & mut self , network_path : & [ NodeId ] ) -> Vec < NodeId > {
3028
+ pub fn upstream_chain_nodes ( & self , network_path : & [ NodeId ] ) -> Vec < NodeId > {
3029
3029
let Some ( selected_nodes) = self . selected_nodes_in_nested_network ( network_path) else {
3030
3030
log:: error!( "Could not get selected nodes in upstream_chain_nodes" ) ;
3031
3031
return Vec :: new ( ) ;
@@ -3156,7 +3156,7 @@ impl NodeNetworkInterface {
3156
3156
self . document_metadata . document_to_viewport = transform;
3157
3157
}
3158
3158
3159
- pub fn is_eligible_to_be_layer ( & mut self , node_id : & NodeId , network_path : & [ NodeId ] ) -> bool {
3159
+ pub fn is_eligible_to_be_layer ( & self , node_id : & NodeId , network_path : & [ NodeId ] ) -> bool {
3160
3160
let Some ( node) = self . document_node ( node_id, network_path) else {
3161
3161
log:: error!( "Could not get node {node_id} in is_eligible_to_be_layer" ) ;
3162
3162
return false ;
@@ -3362,6 +3362,24 @@ impl NodeNetworkInterface {
3362
3362
. map ( |[ a, b] | [ node_graph_to_viewport. transform_point2 ( a) , node_graph_to_viewport. transform_point2 ( b) ] )
3363
3363
}
3364
3364
3365
+ pub fn selected_layers_artwork_bounding_box_viewport ( & self ) -> Option < [ DVec2 ; 2 ] > {
3366
+ self . selected_nodes ( )
3367
+ . 0
3368
+ . iter ( )
3369
+ . filter ( |node| self . is_layer ( & node, & [ ] ) )
3370
+ . filter_map ( |layer| self . document_metadata . bounding_box_viewport ( LayerNodeIdentifier :: new ( * layer, self ) ) )
3371
+ . reduce ( Quad :: combine_bounds)
3372
+ }
3373
+
3374
+ pub fn selected_unlocked_layers_bounding_box_viewport ( & self ) -> Option < [ DVec2 ; 2 ] > {
3375
+ self . selected_nodes ( )
3376
+ . 0
3377
+ . iter ( )
3378
+ . filter ( |node| self . is_layer ( & node, & [ ] ) && !self . is_layer ( & node, & [ ] ) )
3379
+ . filter_map ( |layer| self . document_metadata . bounding_box_viewport ( LayerNodeIdentifier :: new ( * layer, self ) ) )
3380
+ . reduce ( Quad :: combine_bounds)
3381
+ }
3382
+
3365
3383
/// Get the combined bounding box of the click targets of the selected nodes in the node graph in layer space
3366
3384
pub fn selected_nodes_bounding_box ( & mut self , network_path : & [ NodeId ] ) -> Option < [ DVec2 ; 2 ] > {
3367
3385
let Some ( selected_nodes) = self . selected_nodes_in_nested_network ( network_path) else {
@@ -3451,7 +3469,7 @@ impl NodeNetworkInterface {
3451
3469
3452
3470
let Some ( first_root_layer) = self
3453
3471
. upstream_flow_back_from_nodes ( vec ! [ root_node. node_id] , & [ ] , FlowType :: PrimaryFlow )
3454
- . find_map ( |node_id| if self . is_layer ( & node_id, & [ ] ) { Some ( LayerNodeIdentifier :: new ( node_id, self , & [ ] ) ) } else { None } )
3472
+ . find_map ( |node_id| if self . is_layer ( & node_id, & [ ] ) { Some ( LayerNodeIdentifier :: new ( node_id, self ) ) } else { None } )
3455
3473
else {
3456
3474
return ;
3457
3475
} ;
@@ -3467,7 +3485,7 @@ impl NodeNetworkInterface {
3467
3485
if horizontal_root_node_id == first_root_layer. to_node ( ) {
3468
3486
for current_node_id in horizontal_flow_iter {
3469
3487
if self . is_layer ( & current_node_id, & [ ] ) {
3470
- let current_layer_node = LayerNodeIdentifier :: new ( current_node_id, self , & [ ] ) ;
3488
+ let current_layer_node = LayerNodeIdentifier :: new ( current_node_id, self ) ;
3471
3489
if !self . document_metadata . structure . contains_key ( & current_layer_node) {
3472
3490
if current_node_id == first_root_layer. to_node ( ) {
3473
3491
awaiting_primary_flow. push ( ( current_node_id, LayerNodeIdentifier :: ROOT_PARENT ) ) ;
@@ -3484,7 +3502,7 @@ impl NodeNetworkInterface {
3484
3502
// Skip the horizontal_root_node_id node
3485
3503
for current_node_id in horizontal_flow_iter. skip ( 1 ) {
3486
3504
if self . is_layer ( & current_node_id, & [ ] ) {
3487
- let current_layer_node = LayerNodeIdentifier :: new ( current_node_id, self , & [ ] ) ;
3505
+ let current_layer_node = LayerNodeIdentifier :: new ( current_node_id, self ) ;
3488
3506
if !self . document_metadata . structure . contains_key ( & current_layer_node) {
3489
3507
awaiting_primary_flow. push ( ( current_node_id, parent_layer_node) ) ;
3490
3508
children. push ( ( parent_layer_node, current_layer_node) ) ;
@@ -3505,7 +3523,7 @@ impl NodeNetworkInterface {
3505
3523
for current_node_id in primary_flow_iter. skip ( 1 ) {
3506
3524
if self . is_layer ( & current_node_id, & [ ] ) {
3507
3525
// Create a new layer for the top of each stack, and add it as a child to the previous parent
3508
- let current_layer_node = LayerNodeIdentifier :: new ( current_node_id, self , & [ ] ) ;
3526
+ let current_layer_node = LayerNodeIdentifier :: new ( current_node_id, self ) ;
3509
3527
if !self . document_metadata . structure . contains_key ( & current_layer_node) {
3510
3528
children. push ( current_layer_node) ;
3511
3529
@@ -3568,7 +3586,7 @@ impl NodeNetworkInterface {
3568
3586
}
3569
3587
3570
3588
stack. extend ( self_network_metadata. persistent_metadata . node_metadata . keys ( ) . map ( |node_id| {
3571
- let mut current_path = path. clone ( ) ;
3589
+ let mut current_path: Vec < NodeId > = path. clone ( ) ;
3572
3590
current_path. push ( * node_id) ;
3573
3591
current_path
3574
3592
} ) ) ;
@@ -5087,8 +5105,8 @@ impl NodeNetworkInterface {
5087
5105
}
5088
5106
self . unload_upstream_node_click_targets ( vec ! [ * node_id] , network_path) ;
5089
5107
// Reload click target of the layer which encapsulate the chain
5090
- if let Some ( downstream_layer) = self . downstream_layer ( node_id, network_path) {
5091
- self . unload_node_click_targets ( & downstream_layer. to_node ( ) , network_path) ;
5108
+ if let Some ( downstream_layer) = self . downstream_layer_for_chain_node ( node_id, network_path) {
5109
+ self . unload_node_click_targets ( & downstream_layer, network_path) ;
5092
5110
}
5093
5111
self . unload_all_nodes_bounding_box ( network_path) ;
5094
5112
}
@@ -5205,7 +5223,7 @@ impl NodeNetworkInterface {
5205
5223
5206
5224
/// node_id is the first chain node, not the layer
5207
5225
fn set_upstream_chain_to_absolute ( & mut self , node_id : & NodeId , network_path : & [ NodeId ] ) {
5208
- let Some ( downstream_layer) = self . downstream_layer ( node_id, network_path) else {
5226
+ let Some ( downstream_layer) = self . downstream_layer_for_chain_node ( node_id, network_path) else {
5209
5227
log:: error!( "Could not get downstream layer in set_upstream_chain_to_absolute" ) ;
5210
5228
return ;
5211
5229
} ;
@@ -5218,7 +5236,7 @@ impl NodeNetworkInterface {
5218
5236
if self . is_chain ( upstream_id, network_path) {
5219
5237
self . set_absolute_position ( upstream_id, previous_position, network_path) ;
5220
5238
// Reload click target of the layer which used to encapsulate the chain
5221
- self . unload_node_click_targets ( & downstream_layer. to_node ( ) , network_path) ;
5239
+ self . unload_node_click_targets ( & downstream_layer, network_path) ;
5222
5240
}
5223
5241
// If there is an upstream layer then stop breaking the chain
5224
5242
else {
@@ -5297,8 +5315,8 @@ impl NodeNetworkInterface {
5297
5315
// Deselect chain nodes upstream from a selected layer
5298
5316
if self . is_chain ( selected_node, network_path)
5299
5317
&& self
5300
- . downstream_layer ( selected_node, network_path)
5301
- . is_some_and ( |downstream_layer| node_ids. contains ( & downstream_layer. to_node ( ) ) )
5318
+ . downstream_layer_for_chain_node ( selected_node, network_path)
5319
+ . is_some_and ( |downstream_layer| node_ids. contains ( & downstream_layer) )
5302
5320
{
5303
5321
node_ids. remove ( selected_node) ;
5304
5322
}
0 commit comments