# 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 {} {
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
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
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] {
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