Skip to content

Commit 4318a0e

Browse files
committed
FIXED: linking when element is resized
- allow connected to connect to the same connector as the one it was connected
1 parent 4e7a80a commit 4318a0e

File tree

6 files changed

+78
-91
lines changed

6 files changed

+78
-91
lines changed

lib/App/Asciio/Connections.pm

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ use strict;
77
use warnings;
88

99
use Data::TreeDumper ;
10-
use Clone;
11-
use List::Util qw(min max) ;
12-
use List::MoreUtils qw(any minmax first_value) ;
1310

1411
#-----------------------------------------------------------------------------
1512

@@ -168,21 +165,21 @@ return($connectee) ;
168165

169166
#-----------------------------------------------------------------------------
170167

171-
sub get_connected
168+
sub get_connections_with_connectee
172169
{
173170
my($self, $element) = @_ ;
174171

175-
my(@connected) ;
172+
my(@connections) ;
176173

177174
for my $connection (@{$self->{CONNECTIONS}})
178175
{
179176
if($connection->{CONNECTEE} == $element)
180177
{
181-
push @connected, $connection ;
178+
push @connections, $connection ;
182179
}
183180
}
184181

185-
return(@connected) ;
182+
return(@connections) ;
186183
}
187184

188185
#-----------------------------------------------------------------------------

lib/App/Asciio/Elements.pm

Lines changed: 57 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ use App::Asciio::GTK::Asciio::stripes::editable_exec_box ;
2121
use App::Asciio::GTK::Asciio::stripes::editable_box2 ;
2222
use App::Asciio::GTK::Asciio::stripes::rhombus ;
2323
use App::Asciio::GTK::Asciio::stripes::ellipse ;
24-
2524
use App::Asciio::GTK::Asciio::stripes::editable_arrow2 ;
2625
use App::Asciio::GTK::Asciio::stripes::wirl_arrow ;
2726
use App::Asciio::GTK::Asciio::stripes::angled_arrow ;
@@ -264,11 +263,11 @@ for my $element (@elements)
264263
! exists $selected_elements{$_->{CONNECTEE}}
265264
}
266265
$self->get_possible_connections($element) ;
267-
266+
268267
$self->add_connections(@new_connections) ;
269268

270269
# handle box element
271-
for my $connection ($self->get_connected($element))
270+
for my $connection ($self->get_connections_with_connectee($element))
272271
{
273272
# move connected with connectees
274273
if (exists $selected_elements{$connection->{CONNECTED}})
@@ -297,10 +296,9 @@ for my $element (@elements)
297296
# move them relatively to their previous position
298297
if($connection->{CONNECTED} == $other_connection->{CONNECTED})
299298
{
300-
my ($new_connector) = # in characters relative to element origin
301-
$other_connection->{CONNECTED}->get_named_connection($other_connection->{CONNECTOR}{NAME}) ;
299+
my ($named_connection) = $other_connection->{CONNECTED}->get_named_connection($other_connection->{CONNECTOR}{NAME}) ;
302300

303-
$other_connection->{CONNECTOR} = $new_connector ;
301+
$other_connection->{CONNECTOR} = $named_connection ;
304302
$other_connection->{FIXED}++ ;
305303
}
306304
}
@@ -329,64 +327,65 @@ my ($x_offset, $y_offset, undef, undef, $resized_connector_name) =
329327
$selected_element->{X} += $x_offset ;
330328
$selected_element->{Y} += $y_offset;
331329

332-
# handle connections
333330
if($self->is_connected($selected_element))
334331
{
332+
# handle connections for arrows
333+
335334
# disconnect current connections
336335
$self->delete_connections_containing($selected_element) ;
336+
$self->connect_elements($selected_element) ; # connect to new elements if any
337337
}
338-
339-
$self->connect_elements($selected_element) ; # connect to new elements if any
340-
341-
for my $connection ($self->get_connected($selected_element))
338+
else
342339
{
343-
# all connection where the selected element is the connectee
344-
345-
my ($new_connection) = # in characters relative to element origin
346-
$selected_element->get_named_connection($connection->{CONNECTION}{NAME}) ;
347-
348-
if(defined $new_connection)
340+
# handle connections for non arrows
341+
for my $connection ($self->get_connections_with_connectee($selected_element))
349342
{
350-
my ($x_offset, $y_offset, $width, $height, $new_connector) =
351-
$connection->{CONNECTED}->move_connector
352-
(
353-
$connection->{CONNECTOR}{NAME},
354-
$new_connection->{X} - $connection->{CONNECTION}{X},
355-
$new_connection->{Y}- $connection->{CONNECTION}{Y}
356-
) ;
357-
358-
$connection->{CONNECTED}{X} += $x_offset ;
359-
$connection->{CONNECTED}{Y} += $y_offset ;
360-
361-
# the connection point has also changed
362-
$connection->{CONNECTOR} = $new_connector ;
363-
$connection->{CONNECTION} = $new_connection ;
364-
365-
$connection->{FIXED}++ ;
343+
my ($named_connection) = $selected_element->get_named_connection($connection->{CONNECTION}{NAME}) ;
344+
# {X => ..., Y => ..., NAME => same_as_apssed as argumnent} ;
366345

367-
#find the other connectors belonging to this connected
368-
for my $other_connection (grep{ ! $_->{FIXED}} @{$self->{CONNECTIONS}})
346+
if(defined $named_connection)
369347
{
370-
# move them relatively to their previous position
371-
if($connection->{CONNECTED} == $other_connection->{CONNECTED})
348+
# move arrow connector to match the element connection
349+
my ($x_offset, $y_offset, $width, $height, $new_connector) =
350+
$connection->{CONNECTED}->move_connector
351+
(
352+
$connection->{CONNECTOR}{NAME},
353+
$named_connection->{X} - $connection->{CONNECTION}{X},
354+
$named_connection->{Y}- $connection->{CONNECTION}{Y}
355+
) ;
356+
357+
$connection->{CONNECTED}{X} += $x_offset ;
358+
$connection->{CONNECTED}{Y} += $y_offset ;
359+
360+
# the connection point has also changed
361+
$connection->{CONNECTOR} = $new_connector ;
362+
$connection->{CONNECTION} = $named_connection ;
363+
364+
$connection->{FIXED}++ ;
365+
366+
# find the other connectors belonging to this arrow
367+
for my $other_connection (grep{ ! $_->{FIXED}} @{$self->{CONNECTIONS}})
372368
{
373-
my ($new_connector) = # in characters relative to element origin
374-
$other_connection->{CONNECTED}->get_named_connection($other_connection->{CONNECTOR}{NAME}) ;
369+
# move them relatively to their previous position
370+
if($connection->{CONNECTED} == $other_connection->{CONNECTED})
371+
{
372+
my ($named_connection) = $other_connection->{CONNECTED}->get_named_connection($other_connection->{CONNECTOR}{NAME}) ;
373+
374+
$other_connection->{CONNECTOR} = $named_connection ;
375+
$other_connection->{FIXED}++ ;
376+
}
377+
}
375378

376-
$other_connection->{CONNECTOR} = $new_connector ;
377-
$other_connection->{FIXED}++ ;
379+
for my $connection (@{$self->{CONNECTIONS}})
380+
{
381+
delete $connection->{FIXED} ;
378382
}
379383
}
380-
381-
for my $connection (@{$self->{CONNECTIONS}})
384+
else
382385
{
383-
delete $connection->{FIXED} ;
386+
$self->delete_connections($connection) ;
384387
}
385388
}
386-
else
387-
{
388-
$self->delete_connections($connection) ;
389-
}
390389
}
391390

392391
return($x_offset, $y_offset, $resized_connector_name) ;
@@ -487,29 +486,28 @@ if($self->is_connected($selected_element))
487486

488487
$self->connect_elements($selected_element) ; # connect to new elements if any
489488

490-
for my $connection ($self->get_connected($selected_element))
489+
for my $connection ($self->get_connectons($selected_element))
491490
{
492491
# all connection where the selected element is the connectee
493492

494-
my ($new_connection) = # in characters relative to element origin
495-
$selected_element->get_named_connection($connection->{CONNECTION}{NAME}) ;
493+
my ($named_connection) = $selected_element->get_named_connection($connection->{CONNECTION}{NAME}) ;
496494

497-
if(defined $new_connection)
495+
if(defined $named_connection)
498496
{
499497
my ($x_offset, $y_offset, $width, $height, $new_connector) =
500498
$connection->{CONNECTED}->move_connector
501499
(
502500
$connection->{CONNECTOR}{NAME},
503-
$new_connection->{X} - $connection->{CONNECTION}{X},
504-
$new_connection->{Y}- $connection->{CONNECTION}{Y}
501+
$named_connection->{X} - $connection->{CONNECTION}{X},
502+
$named_connection->{Y}- $connection->{CONNECTION}{Y}
505503
) ;
506504

507505
$connection->{CONNECTED}{X} += $x_offset ;
508506
$connection->{CONNECTED}{Y} += $y_offset;
509507

510508
# the connection point has also changed
511509
$connection->{CONNECTOR} = $new_connector ;
512-
$connection->{CONNECTION} = $new_connection ;
510+
$connection->{CONNECTION} = $named_connection ;
513511

514512
$connection->{FIXED}++ ;
515513

@@ -519,18 +517,14 @@ for my $connection ($self->get_connected($selected_element))
519517
# move them relatively to their previous position
520518
if($connection->{CONNECTED} == $other_connection->{CONNECTED})
521519
{
522-
my ($new_connector) = # in characters relative to element origin
523-
$other_connection->{CONNECTED}->get_named_connection($other_connection->{CONNECTOR}{NAME}) ;
520+
my ($named_connection) = $other_connection->{CONNECTED}->get_named_connection($other_connection->{CONNECTOR}{NAME}) ;
524521

525-
$other_connection->{CONNECTOR} = $new_connector ;
522+
$other_connection->{CONNECTOR} = $named_connection ;
526523
$other_connection->{FIXED}++ ;
527524
}
528525
}
529-
530-
for my $connection (@{$self->{CONNECTIONS}})
531-
{
532-
delete $connection->{FIXED} ;
533-
}
526+
527+
delete $_->{FIXED} for @{$self->{CONNECTIONS}} ;
534528
}
535529
else
536530
{

lib/App/Asciio/stripes/editable_box2.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ if($self->is_optimize_enabled() && $x >= 0 && $x < $self->{WIDTH} && $y >= 0 &&
441441
{
442442
return {X => -1, Y => -1, NAME => 'to_be_optimized'} ;
443443
}
444-
444+
445445
if($self->{ALLOW_BORDER_CONNECTION} && $x >= -1 && $x <= $self->{WIDTH} && $y >= -1 && $y <= $self->{HEIGHT})
446446
{
447447
return {X => $x, Y => $y, NAME => 'border'} ;

lib/App/Asciio/stripes/wirl_arrow.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,7 @@ if($is_start)
798798
my $new_end_x = $self->{END_X} - $x_offset ;
799799
my $new_end_y = $self->{END_Y} - $y_offset ;
800800

801-
$self->setup($self->{ARROW_TYPE}, $new_end_x, $new_end_y, $hint || $self->{DIRECTION},$self ->{ALLOW_DIAGONAL_LINES}, $self->{EDITABLE}) ;
801+
$self->setup($self->{ARROW_TYPE}, $new_end_x, $new_end_y, $hint // $self->{DIRECTION},$self ->{ALLOW_DIAGONAL_LINES}, $self->{EDITABLE}) ;
802802

803803
return($x_offset, $y_offset, $self->{WIDTH}, $self->{HEIGHT}, 'start') ;
804804
}
@@ -807,7 +807,7 @@ else
807807
my $new_end_x = $new_x ;
808808
my $new_end_y = $new_y ;
809809

810-
$self->setup($self->{ARROW_TYPE}, $new_end_x, $new_end_y, $hint || $self->{DIRECTION}, $self ->{ALLOW_DIAGONAL_LINES}, $self->{EDITABLE}) ;
810+
$self->setup($self->{ARROW_TYPE}, $new_end_x, $new_end_y, $hint // $self->{DIRECTION}, $self ->{ALLOW_DIAGONAL_LINES}, $self->{EDITABLE}) ;
811811

812812
return(0, 0, $self->{WIDTH}, $self->{HEIGHT}, 'end') ;
813813
}

setup/actions/default_bindings.pl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@
227227
'Display undo stack statistics' => ['000-u', \&App::Asciio::Actions::Unsorted::display_undo_stack_statistics ],
228228
'Dump self' => ['000-s', \&App::Asciio::Actions::Debug::dump_self ],
229229
'Dump all elements' => ['000-e', \&App::Asciio::Actions::Debug::dump_all_elements ],
230-
'Dump selected elements' => ['000-E', \&App::Asciio::Actions::Debug::dump_selected_elements ],
230+
'Dump selected elements' => ['00S-E', \&App::Asciio::Actions::Debug::dump_selected_elements ],
231231
'Display numbered objects' => ['000-t', sub { $_[0]->{NUMBERED_OBJECTS} ^= 1 ; $_[0]->update_display() }],
232232
'Test' => ['000-o', \&App::Asciio::Actions::Debug::test ],
233233
'ZBuffer Test' => ['000-z', \&App::Asciio::Actions::ZBuffer::dump_crossings ],

setup/hooks/canonize_connections.pl

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -226,26 +226,22 @@ sub reconnect
226226
{
227227
my($asciio_connection, $connection_name, $connector_name, $hint) = @_ ;
228228

229-
if($asciio_connection->{CONNECTION}{NAME} ne $connection_name)
230-
{
231-
my ($connected, $connectee) = ($asciio_connection->{CONNECTED}, $asciio_connection->{CONNECTEE}) ;
229+
my ($connected, $connectee) = ($asciio_connection->{CONNECTED}, $asciio_connection->{CONNECTEE}) ;
232230

233-
my ($connection) = $connectee->get_named_connection($connection_name) ;
234-
my ($connector) = $connected->get_named_connection($connector_name) ;
231+
my ($connection) = $connectee->get_named_connection($connection_name) ;
232+
my ($connector) = $connected->get_named_connection($connector_name) ;
235233

236-
my $x_offset_to_connection = ($connectee->{X} + $connection->{X}) - ($connected->{X} + $connector->{X}) ;
237-
my $y_offset_to_connection = ($connectee->{Y} + $connection->{Y}) - ($connected->{Y} + $connector->{Y}) ;
234+
my $x_offset_to_connection = ($connectee->{X} + $connection->{X}) - ($connected->{X} + $connector->{X}) ;
235+
my $y_offset_to_connection = ($connectee->{Y} + $connection->{Y}) - ($connected->{Y} + $connector->{Y}) ;
238236

239-
# move connector
240-
#~ print STDERR "reconnect: $connection_name $connector_name\n" ;
241-
my ($x_offset, $y_offset, $width, $height, $new_connector) =
242-
$connected->move_connector($connector_name, $x_offset_to_connection, $y_offset_to_connection, $hint) ;
243-
244-
$connected->{X} += $x_offset ;
245-
$connected->{Y} += $y_offset ;
237+
# move connector
238+
my ($x_offset, $y_offset, $width, $height, $new_connector) =
239+
$connected->move_connector($connector_name, $x_offset_to_connection, $y_offset_to_connection, $hint) ;
246240

247-
$asciio_connection->{CONNECTOR} = $new_connector ;
248-
$asciio_connection->{CONNECTION} = $connection ;
249-
}
241+
$connected->{X} += $x_offset ;
242+
$connected->{Y} += $y_offset ;
243+
244+
$asciio_connection->{CONNECTOR} = $new_connector ;
245+
$asciio_connection->{CONNECTION} = $connection ;
250246
}
251247

0 commit comments

Comments
 (0)