]> git.entuzijast.net Git - imunes.git/commitdiff
Adjust node and nodelabel position to fit into the target canvas
authormarko <marko>
Mon, 7 Jan 2008 11:50:04 +0000 (11:50 +0000)
committermarko <marko>
Mon, 7 Jan 2008 11:50:04 +0000 (11:50 +0000)
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

index 1c49e3e30393fa16a5afab6450cb7326b5f6ec8f..4fe83a6fe210b14ce6d1cca9cdca30fb23aabc67 100644 (file)
@@ -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