| 1 | |||
| 2 | #~ use Data::TreeDumper ; | ||
| 3 | |||
| 4 | #---------------------------------------------------------------------------------------------- | ||
| 5 | |||
| 6 | register_hooks | ||
| 7 | ( | ||
| 8 | { CANONIZE_CONNECTIONS => \&canonize_connections}, | ||
| 9 | ) ; | ||
| 10 | |||
| 11 | #---------------------------------------------------------------------------------------------- | ||
| 12 | |||
| 13 | =pod | ||
| 14 | .-------. | ||
| 15 | | | | ||
| 16 | | .---. | ||
| 17 | | | C | start connector (first character) | ||
| 18 | | C | o | / | ||
| 19 | | O | n | / | ||
| 20 | | N | n | .---. end connector (last character) | ||
| 21 | | N | e | | --------------------------------. / | ||
| 22 | | E | c | '---' | / | ||
| 23 | | C | t | CONNECTED .-|-./ | ||
| 24 | | T | i | | v | | ||
| 25 | | E | o | '---' | ||
| 26 | | E | n | | ||
| 27 | | '---' .------------. | ||
| 28 | | | | Connection | | ||
| 29 | '-------' .----'------------'-----. | ||
| 30 | | | | ||
| 31 | | CONNECTEE | | ||
| 32 | | | | ||
| 33 | '-----------------------' | ||
| 34 | =cut | ||
| 35 | |||
| 36 | sub canonize_connections | ||
| 37 | { | ||
| 38 | my ($connections) = @_ ; | ||
| 39 | |||
| 40 | for my $connection (@{$connections}) | ||
| 41 | { | ||
| 42 | if | ||
| 43 | ( | ||
| 44 | ( | ||
| 45 | ref $connection->{CONNECTED} eq 'App::Asciio::stripes::section_wirl_arrow' || | ||
| 46 | ref $connection->{CONNECTED} eq 'App::Asciio::stripes::angled_arrow' | ||
| 47 | ) | ||
| 48 | && $connection->{CONNECTED}->is_autoconnect_enabled() | ||
| 49 | && $connection->{CONNECTEE}->is_autoconnect_enabled() | ||
| 50 | ) | ||
| 51 | { | ||
| 52 | reconnect_section_wirl_arrow($connection) ; | ||
| 53 | } | ||
| 54 | } | ||
| 55 | } | ||
| 56 | |||
| 57 | sub reconnect_section_wirl_arrow | ||
| 58 | { | ||
| 59 | my ($connection) = @_ ; | ||
| 60 | |||
| 61 | my ($connected, $connectee) = ($connection->{CONNECTED}, $connection->{CONNECTEE}) ; | ||
| 62 | |||
| 63 | my @connectors = $connected->get_all_points() ; | ||
| 64 | my ($start_name, $end_name) = ($connectors[0]{NAME}, $connectors[-1]{NAME}) ; | ||
| 65 | |||
| 66 | if($connection->{CONNECTOR}{NAME} eq $end_name) | ||
| 67 | { | ||
| 68 | # end connector | ||
| 69 | |||
| 70 | return unless $connectee->is_optimize_enabled() ; | ||
| 71 | |||
| 72 | my ($connectee_x, $connectee_y, $connectee_width, $connectee_hight) = | ||
| 73 | ($connectee->{X}, $connectee->{Y}, $connectee->get_size()) ; | ||
| 74 | |||
| 75 | my $connected_x = $connected->{X} + $connectors[-2]{X}; | ||
| 76 | my $connected_y = $connected->{Y} + $connectors[-2]{Y}; | ||
| 77 | |||
| 78 | if($connected_x < $connectee_x) | ||
| 79 | { | ||
| 80 | # arrow starts on left of the box | ||
| 81 | if($connected->get_section_direction(-1) =~ /^right/) | ||
| 82 | { | ||
| 83 | if($connected_y < $connectee_y) | ||
| 84 | { | ||
| 85 | reconnect($connection, 'top_center', $end_name) ; | ||
| 86 | } | ||
| 87 | else | ||
| 88 | { | ||
| 89 | if($connected_y < $connectee_y + $connectee_hight) | ||
| 90 | { | ||
| 91 | reconnect($connection, 'left_center', $end_name) ; | ||
| 92 | } | ||
| 93 | else | ||
| 94 | { | ||
| 95 | # arrow below, right-up to bottom_center | ||
| 96 | reconnect($connection, 'bottom_center', $end_name) ; | ||
| 97 | } | ||
| 98 | } | ||
| 99 | } | ||
| 100 | else | ||
| 101 | { | ||
| 102 | # arrow going up or down | ||
| 103 | reconnect($connection, 'left_center', $end_name) ; | ||
| 104 | } | ||
| 105 | } | ||
| 106 | elsif($connected_x < $connectee_x + $connectee_width) | ||
| 107 | { | ||
| 108 | # arrow starts within width of the box | ||
| 109 | if($connected_y < $connectee_y) | ||
| 110 | { | ||
| 111 | #arrow above, right-down to top_center | ||
| 112 | reconnect($connection, 'top_center', $end_name, 'right') ; | ||
| 113 | } | ||
| 114 | else | ||
| 115 | { | ||
| 116 | reconnect($connection, 'bottom_center', $end_name) ; | ||
| 117 | } | ||
| 118 | } | ||
| 119 | else | ||
| 120 | { | ||
| 121 | # arrow starts on right of the box | ||
| 122 | if($connected->get_section_direction(-1) =~ /^left/) | ||
| 123 | { | ||
| 124 | if($connected_y < $connectee_y) | ||
| 125 | { | ||
| 126 | reconnect($connection, 'top_center', $end_name) ; | ||
| 127 | } | ||
| 128 | else | ||
| 129 | { | ||
| 130 | if($connected_y < $connectee_y + $connectee_hight) | ||
| 131 | { | ||
| 132 | reconnect($connection, 'right_center', $end_name) ; | ||
| 133 | } | ||
| 134 | else | ||
| 135 | { | ||
| 136 | reconnect($connection, 'bottom_center', $end_name) ; | ||
| 137 | } | ||
| 138 | } | ||
| 139 | } | ||
| 140 | else | ||
| 141 | { | ||
| 142 | # arrow going up or down | ||
| 143 | reconnect($connection, 'right_center', $end_name) ; | ||
| 144 | } | ||
| 145 | } | ||
| 146 | } | ||
| 147 | else | ||
| 148 | { | ||
| 149 | # start connector | ||
| 150 | return unless $connectee->is_optimize_enabled() ; | ||
| 151 | |||
| 152 | my ($connectee_x, $connectee_y, $connectee_width, $connectee_hight) = | ||
| 153 | ($connectee->{X}, $connectee->{Y}, $connectee->get_size()) ; | ||
| 154 | |||
| 155 | my $end_connector_x = $connected->{X} + $connectors[1]{X}; | ||
| 156 | my $end_connector_y = $connected->{Y} + $connectors[1]{Y} ; | ||
| 157 | |||
| 158 | if($end_connector_x < $connectee_x) | ||
| 159 | { | ||
| 160 | # arrow ends on left of the box | ||
| 161 | if($connected->get_section_direction(0) !~ /^left/) | ||
| 162 | { | ||
| 163 | if($end_connector_y < $connectee_y) | ||
| 164 | { | ||
| 165 | reconnect($connection, 'top_center', $start_name) ; | ||
| 166 | } | ||
| 167 | else | ||
| 168 | { | ||
| 169 | if($end_connector_y < $connectee_y + $connectee_hight) | ||
| 170 | { | ||
| 171 | reconnect($connection, 'left_center', $start_name) ; | ||
| 172 | } | ||
| 173 | else | ||
| 174 | { | ||
| 175 | reconnect($connection, 'bottom_center', $start_name) ; | ||
| 176 | } | ||
| 177 | } | ||
| 178 | } | ||
| 179 | else | ||
| 180 | { | ||
| 181 | reconnect($connection, 'left_center', $start_name) ; | ||
| 182 | } | ||
| 183 | } | ||
| 184 | elsif($end_connector_x < $connectee_x + $connectee_width) | ||
| 185 | { | ||
| 186 | # arrow starts within width of the box | ||
| 187 | if($end_connector_y < $connectee_y) | ||
| 188 | { | ||
| 189 | reconnect($connection, 'top_center', $start_name) ; | ||
| 190 | } | ||
| 191 | else | ||
| 192 | { | ||
| 193 | reconnect($connection, 'bottom_center', $start_name) ; | ||
| 194 | } | ||
| 195 | } | ||
| 196 | else | ||
| 197 | { | ||
| 198 | # arrow ends on right of the box | ||
| 199 | if($connected->get_section_direction(0) !~ /^right/) | ||
| 200 | { | ||
| 201 | if($end_connector_y < $connectee_y) | ||
| 202 | { | ||
| 203 | reconnect($connection, 'top_center', $start_name) ; | ||
| 204 | } | ||
| 205 | else | ||
| 206 | { | ||
| 207 | if($end_connector_y < $connectee_y + $connectee_hight) | ||
| 208 | { | ||
| 209 | reconnect($connection, 'right_center', $start_name) ; | ||
| 210 | } | ||
| 211 | else | ||
| 212 | { | ||
| 213 | reconnect($connection, 'bottom_center', $start_name) ; | ||
| 214 | } | ||
| 215 | } | ||
| 216 | } | ||
| 217 | else | ||
| 218 | { | ||
| 219 | reconnect($connection, 'right_center', $start_name) ; | ||
| 220 | } | ||
| 221 | } | ||
| 222 | } | ||
| 223 | } | ||
| 224 | |||
| 225 | sub reconnect | ||
| 226 | { | ||
| 227 | my($asciio_connection, $connection_name, $connector_name, $hint) = @_ ; | ||
| 228 | |||
| 229 | if($asciio_connection->{CONNECTION}{NAME} ne $connection_name) | ||
| 230 | { | ||
| 231 | my ($connected, $connectee) = ($asciio_connection->{CONNECTED}, $asciio_connection->{CONNECTEE}) ; | ||
| 232 | |||
| 233 | my ($connection) = $connectee->get_named_connection($connection_name) ; | ||
| 234 | my ($connector) = $connected->get_named_connection($connector_name) ; | ||
| 235 | |||
| 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}) ; | ||
| 238 | |||
| 239 | # move connector | ||
| 240 | #~ print "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 ; | ||
| 246 | |||
| 247 | $asciio_connection->{CONNECTOR} = $new_connector ; | ||
| 248 | $asciio_connection->{CONNECTION} = $connection ; | ||
| 249 | } | ||
| 250 | } | ||
| 251 |