typegraph/scripts/blocks/detachConnectionEnd.gml

48 lines
1.2 KiB
Plaintext
Raw Normal View History

///detachConnectionEnd(conn)
/**
* layoutCluster :: ConnectionEnd -> ()
*
* Detaches a connection end from an anchor
*
* @param conn the end point to detach
*/
var conn = argument0;
if (conn.target == noone)
show_error("Connection not attached.", true);
var targetBlock = conn.target.parent;
var otherEnd = noone;
var blocks = getBlockCluster(targetBlock);
if (instanceof(conn, ConnectionSource))
otherEnd = conn.parent.drain;
if (instanceof(conn, ConnectionDrain))
otherEnd = conn.parent.source;
if (otherEnd.target != noone) {
for (var block = ds_set_first(blocks); ds_set_exists(blocks, block); block = ds_set_next(blocks, block))
freshTypes(block);
conn.target.line = noone;
conn.target = noone;
var lines = getConnectionsForCluster(blocks);
for (var line = ds_set_first(lines); ds_set_exists(lines, line); line = ds_set_next(lines, line))
unifyAnchors(line.source.target, line.drain.target);
layoutCluster(ds_set_first(blocks));
for (var block = ds_set_first(blocks); ds_set_exists(blocks, block); block = ds_set_next(blocks, block))
layout(block);
ds_set_destroy(lines);
}
else {
conn.target.line = noone;
conn.target = noone;
}
ds_set_destroy(blocks);