From e531fc2967bbe9a0ff3bebb84e45720d5a0b7468 Mon Sep 17 00:00:00 2001 From: marko Date: Mon, 7 Jan 2008 11:50:04 +0000 Subject: [PATCH] Adjust node and nodelabel position to fit into the target canvas when pasting objects which were originally positioned outside the bounds of the target canvas, i.e. when copying from a bigger to a smaller canvas. Bug found by: Submitted by: Reviewed by: Approved by: Obtained from: --- copypaste.tcl | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/copypaste.tcl b/copypaste.tcl index 1c49e3e..4fe83a6 100644 --- a/copypaste.tcl +++ b/copypaste.tcl @@ -23,7 +23,7 @@ # SUCH DAMAGE. # -# $Id: copypaste.tcl,v 1.2 2008/01/05 18:06:25 marko Exp $ +# $Id: copypaste.tcl,v 1.3 2008/01/07 11:50:04 marko Exp $ proc cutSelection {} { @@ -82,6 +82,7 @@ proc paste {} { upvar 0 ::cf::[set ::curcfg]::node_list node_list upvar 0 ::cf::[set ::curcfg]::link_list link_list upvar 0 ::cf::[set ::curcfg]::curcanvas curcanvas + global sizex sizey global changed # Nothing to do if clipboard is empty @@ -89,7 +90,7 @@ proc paste {} { return } - # Paste nodes from the clipboard while renaming them + # Paste nodes from the clipboard and rename them on the fly foreach node_orig [set ::cf::clipboard::node_list] { set node_copy [newObjectId node] set node_map($node_orig) $node_copy @@ -100,7 +101,13 @@ proc paste {} { setNodeCanvas $node_copy $curcanvas } - # Remap interface peerings to match new node names + # + # Remap interface peerings to match new node names and + # adjust node positions so that all fit in the target canvas + # + set delta 128 + set curx [expr $delta / 2] + set cury [expr $delta / 2] foreach node_orig [set ::cf::clipboard::node_list] { set node_copy $node_map($node_orig) foreach ifc [ifcList $node_copy] { @@ -109,9 +116,21 @@ proc paste {} { set $node_copy [lreplace [set $node_copy] $i $i \ "interface-peer {$ifc $node_map($old_peer)}"] } + + set nodecoords [getNodeCoords $node_copy] + if { [lindex $nodecoords 0] >= $sizex || + [lindex $nodecoords 1] >= $sizey } { + setNodeCoords $node_copy "$curx $cury" + setNodeLabelCoords $node_copy "$curx [expr $cury + $delta / 4]" + incr curx $delta + if { $curx > $sizex } { + incr cury $delta + set curx [expr $delta / 2] + } + } } - # Paste links from the clipboard while renaming them + # Paste links from the clipboard and rename them on the fly foreach link_orig [set ::cf::clipboard::link_list] { set link_copy [newObjectId link] upvar 0 ::cf::[set ::curcfg]::$link_copy $link_copy -- 2.39.5