]> git.entuzijast.net Git - imunes.git/commitdiff
Introduce a global variable cfg_list which holds all cfg ids (not eids)
authormarko <marko>
Tue, 8 Jan 2008 12:35:30 +0000 (12:35 +0000)
committermarko <marko>
Tue, 8 Jan 2008 12:35:30 +0000 (12:35 +0000)
for currently open projects.

Move previously global variable currentFile to per-cfg namespaces, given
that each project should typically correspond to a different file.

Rename proc newFile to newProc, and slightly reorganize it so that
newProc does all necessary steps for setting up a project environment
inside the GUI.

Introduce proc setWmTitle which should be used exclusively for updating
window title.

Deprecate procs fileOpenStartup and fileNewDialogBox.

It is no longer necessary to set up the default config namespace in
imunes.tcl and initgui.tcl, given that proc loadCfg and proc newFile
now initialize all the necessary state.

Bug found by:
Submitted by:
Reviewed by:
Approved by:
Obtained from:

cfgparse.tcl
exec.tcl
filemgmt.tcl
imunes.tcl
initgui.tcl

index 9027fb6759da6b10d58a32013b9d1e7ae45dc8f5..ead9439c00c5e68a5f984aa476b34e7862649292 100755 (executable)
@@ -26,7 +26,7 @@
 # and Technology through the research contract #IP-2003-143.
 #
 
-# $Id: cfgparse.tcl,v 1.38 2008/01/02 12:08:46 marko Exp $
+# $Id: cfgparse.tcl,v 1.39 2008/01/08 12:35:30 marko Exp $
 
 
 #****h* imunes/cfgparse.tcl
@@ -208,6 +208,7 @@ proc loadCfg { cfg } {
     upvar 0 ::cf::[set ::curcfg]::link_list link_list
     upvar 0 ::cf::[set ::curcfg]::annotation_list annotation_list
     upvar 0 ::cf::[set ::curcfg]::canvas_list canvas_list
+    upvar 0 ::cf::[set ::curcfg]::eid eid
     global showIfNames showNodeLabels showLinkLabels
     global showIfIPaddrs showIfIPv6addrs
     global showIPsecConfig
@@ -220,6 +221,7 @@ proc loadCfg { cfg } {
     set canvas_list {}
     set class ""
     set object ""
+    set eid ""
     foreach entry $cfg {
        if {"$class" == ""} {
            set class $entry
@@ -513,6 +515,7 @@ proc newObjectId { type } {
     upvar 0 ::cf::[set ::curcfg]::link_list link_list
     upvar 0 ::cf::[set ::curcfg]::annotation_list annotation_list
     upvar 0 ::cf::[set ::curcfg]::canvas_list canvas_list
+    global cfg_list
 
     set mark [string range [set type] 0 0]
     set id 0
index 0c014aeb005a64f47462f52df8202bc43e9c9247..ce332aa05fd570706c5f2a7d2a59e44277bce61f 100755 (executable)
--- a/exec.tcl
+++ b/exec.tcl
@@ -26,7 +26,7 @@
 # and Technology through the research contract #IP-2003-143.
 #
 
-# $Id: exec.tcl,v 1.69 2008/01/05 18:06:25 marko Exp $
+# $Id: exec.tcl,v 1.70 2008/01/08 12:35:30 marko Exp $
 
 
 #****f* exec.tcl/nexec
@@ -506,13 +506,14 @@ proc deployCfg {} {
     global supp_router_models
     global mac_byte4 mac_byte5
     global remote_exec
+    global eid_base
 
     set mac_byte4 0
     set mac_byte5 0
 
-    set t_start [clock seconds]
+    set eid ${eid_base}[string range $::curcfg 1 end]
 
-    vimageCleanup $eid
+    set t_start [clock seconds]
 
     catch { nexec vimage -c $eid }
     catch { nexec rm -fr /tmp/$eid }
index e4bead6e87a58d3e74de8e1b53152801d7bdb9cf..c34be5a0cab863327f49d0a1f0db298b537d37a3 100755 (executable)
@@ -26,7 +26,7 @@
 # and Technology through the research contract #IP-2003-143.
 #
 
-# $Id: filemgmt.tcl,v 1.16 2008/01/05 18:06:25 marko Exp $
+# $Id: filemgmt.tcl,v 1.17 2008/01/08 12:35:30 marko Exp $
 
 
 ##****h* imunes/filemgmt.tcl
@@ -46,7 +46,7 @@
 #
 # procedures used for loading and storing the configuration file:
 #
-# newFile 
+# newProject
 #   - creates an empty project
 #
 # openFile
@@ -59,9 +59,6 @@
 # fileOpenStartUp
 #   - opens the file named as command line argument
 # 
-# fileNewDialogBox
-#   - opens message box to optionally save the changes 
-#
 # fileOpenDialogBox
 #   - opens dialog box for selecting a file to open
 #
@@ -81,34 +78,49 @@ set fileTypes {
 }
 
 
-#****f* filemgmt.tcl/newFile
-# NAME
-#   newFile -- new file
-# SYNOPSIS
-#   newFile
-# FUNCTION
-#   Loads an empty configuration, i.e. creates an empty project.
-#****
-proc newFile {} {
+proc newProject {} {
+    global curcfg cfg_list sizex sizey
+
+    set curcfg [newObjectId cfg]
+    lappend cfg_list $curcfg
+    namespace eval ::cf::[set curcfg] {}
+
     upvar 0 ::cf::[set ::curcfg]::canvas_list canvas_list
     upvar 0 ::cf::[set ::curcfg]::curcanvas curcanvas
     upvar 0 ::cf::[set ::curcfg]::undolevel undolevel
     upvar 0 ::cf::[set ::curcfg]::redolevel redolevel
+    upvar 0 ::cf::[set ::curcfg]::undolog undolog
+    upvar 0 ::cf::[set ::curcfg]::zoom zoom
     upvar 0 ::cf::[set ::curcfg]::oper_mode oper_mode
     upvar 0 ::cf::[set ::curcfg]::eid eid
-    global currentFile
+    upvar 0 ::cf::[set ::curcfg]::currentFile currentFile
 
-    if { $oper_mode == "exec" } {
-       vimageCleanup $eid
-    }
     loadCfg ""
+    set oper_mode edit
     set undolevel 0
     set redolevel 0
+    set undolog(0) ""
+    set zoom 1.0
+    set canvas_list {}
+    newCanvas ""
     set curcanvas [lindex $canvas_list 0]
+    set sizex [lindex [getCanvasSize $curcanvas] 0]
+    set sizey [lindex [getCanvasSize $curcanvas] 1]
     switchCanvas none
     redrawAll
     set currentFile ""
-    wm title . "IMUNES"
+    setWmTitle $currentFile
+}
+
+
+proc setWmTitle { fname } {
+    global curcfg
+
+    if { $fname == "" } {
+       wm title . "IMUNES - untitled[string range $curcfg 1 end]"
+    } else {
+       wm title . "IMUNES - $fname"
+    }
 }
 
 
@@ -126,11 +138,10 @@ proc openFile {} {
     upvar 0 ::cf::[set ::curcfg]::undolevel undolevel
     upvar 0 ::cf::[set ::curcfg]::redolevel redolevel
     upvar 0 ::cf::[set ::curcfg]::undolog undolog
-    global currentFile 
+    upvar 0 ::cf::[set ::curcfg]::currentFile currentFile
     global activetool
     
     set fileName [file tail $currentFile]
-    wm title . "IMUNES $fileName"
     set fileId [open $currentFile r]
     set cfg ""
     foreach entry [read $fileId] {
@@ -145,6 +156,7 @@ proc openFile {} {
     set redolevel 0
     set undolog(0) $cfg 
     set activetool select
+    setWmTitle $fileName
 }
 
 
@@ -160,60 +172,16 @@ proc openFile {} {
 #   configuration is saved.
 #****
 proc saveFile { selectedFile } {
-    global currentFile 
+    upvar 0 ::cf::[set ::curcfg]::currentFile currentFile
+
     if { $selectedFile != ""} {
        set currentFile $selectedFile
        set fileName [file tail $currentFile]
-       wm title . "IMUNES $fileName"
        set fileId [open $currentFile w]
        dumpCfg file $fileId
        close $fileId
        .bottom.textbox config -text "Saved $fileName"
-    }
-}
-
-
-#****f* filemgmt.tcl/fileOpenStartUp
-# NAME
-#   fileOpenStartUp -- file open in batch mode
-# SYNOPSIS
-#   fileOpenStartUp
-# FUNCTION
-#   Loads configuration from batch input file to the current 
-#   configuration.
-#****
-proc fileOpenStartUp {} {
-    global argv
-    global currentFile
-
-    if { $argv != "" } {
-       set currentFile $argv
-       openFile
-    }
-}
-
-
-#****f* filemgmt.tcl/fileNewDialogBox
-# NAME
-#   fileNewDialogBox -- save changes dialog box
-# SYNOPSIS
-#   fileNewDialogBox
-# FUNCTION
-#   Opens message box to optionally save the changes.
-#****
-proc fileNewDialogBox {} {
-    global currentFile
-
-    set choice [tk_messageBox -type yesnocancel -default yes\
-         -message "Save changes?" -icon question]
-    
-    if { $choice != "cancel"} {
-       if { $choice == "yes"} {
-           fileSaveDialogBox    
-           newFile
-       } else {
-           newFile
-       }
+       setWmTitle $fileName
     }
 }
 
@@ -227,8 +195,9 @@ proc fileNewDialogBox {} {
 #   Opens a open file dialog box.
 #****
 proc fileOpenDialogBox {} {
-    global currentFile 
+    upvar 0 ::cf::[set ::curcfg]::currentFile currentFile
     global fileTypes
+
     set selectedFile [tk_getOpenFile -filetypes $fileTypes]
     if { $selectedFile != ""} {
        set currentFile $selectedFile
@@ -247,7 +216,7 @@ proc fileOpenDialogBox {} {
 #   current file.
 #****
 proc fileSaveDialogBox {} {
-    global currentFile 
+    upvar 0 ::cf::[set ::curcfg]::currentFile currentFile
     global fileTypes
     
     if { $currentFile == "" } {
@@ -269,8 +238,9 @@ proc fileSaveDialogBox {} {
 #   Opens dialog box for saving a file under new name.
 #****
 proc fileSaveAsDialogBox {} {
-    global currentFile 
+    upvar 0 ::cf::[set ::curcfg]::currentFile currentFile
     global fileTypes
+
     set selectedFile [tk_getSaveFile -filetypes $fileTypes -initialfile\
               untitled -defaultextension .imn]
 
@@ -331,7 +301,8 @@ proc readConfigFile {} {
 
 ;#proc relpath {basedir target} {
 proc relpath {target} {
-    global currentFile
+    upvar 0 ::cf::[set ::curcfg]::currentFile currentFile
+
     set basedir $currentFile
     # Try and make a relative path to a target file/dir from base directory
     set bparts [file split [file normalize $basedir]]
index d4513086ffc234d92a3a168597dd4aeffe0692ec..ddf1fd90648ba94d741f4e085f35cd2a6fc38b6d 100755 (executable)
@@ -26,7 +26,7 @@
 # and Technology through the research contract #IP-2003-143.
 #
 
-# $Id: imunes.tcl,v 1.34 2008/01/05 18:06:25 marko Exp $
+# $Id: imunes.tcl,v 1.35 2008/01/08 12:35:30 marko Exp $
 
 
 #****h* imunes/imunes.tcl
@@ -141,21 +141,15 @@ source "$ROOTDIR/$LIBDIR/ns2imunes.tcl"
 #    this list is empty.
 #*****
 
-# Default configuration
-namespace eval cf::cfg0 {}
-set cf::cfg0::node_list {}
-set cf::cfg0::link_list {}
-set cf::cfg0::annotation_list {}
-set cf::cfg0::canvas_list {}
-set cf::cfg0::eid $eid_base
-
-set cfg_list cfg0
-set curcfg cfg0
-
 # Clipboard
 namespace eval cf::clipboard {}
 set cf::clipboard::node_list {}
 set cf::clipboard::link_list {}
+set cf::clipboard::annotation_list {}
+set cf::clipboard::canvas_list {}
+
+set cfg_list {}
+set curcfg ""
 
 #****v* imunes.tcl/exec_hosts
 # NAME
@@ -251,8 +245,13 @@ if {$execMode == "interactive"} {
     source "$ROOTDIR/$LIBDIR/topogen.tcl"
     source "$ROOTDIR/$LIBDIR/graph_partitioning.tcl"
     source "$ROOTDIR/$LIBDIR/gpgui.tcl"
-    setOperMode edit
-    fileOpenStartUp 
+    newProject
+    if { $argv != "" } {
+        set ::cf::[set curcfg]::currentFile $argv
+        openFile
+    }
+    # Fire up the animation loop
+    animate
 } else {
     if {$argv != ""} {
        set fileId [open $argv r]
@@ -261,6 +260,11 @@ if {$execMode == "interactive"} {
            lappend cfg $entry
        }
        close $fileId
+
+       set curcfg [newObjectId cfg]
+       lappend cfg_list $curcfg
+       namespace eval ::cf::[set curcfg] {}
+
        loadCfg $cfg
        deployCfg
     } else {
index c57a17baf28dedf006f5dc5f62e350d1e55ba6e2..28c5fe6f5f29d57d6d70fad069933db752afe3ac 100755 (executable)
@@ -26,7 +26,7 @@
 # and Technology through the research contract #IP-2003-143.
 #
 
-# $Id: initgui.tcl,v 1.45 2008/01/07 10:53:15 marko Exp $
+# $Id: initgui.tcl,v 1.46 2008/01/08 12:35:30 marko Exp $
 
 
 #****h* imunes/initgui.tcl
 set newlink ""
 set selectbox ""
 set selected ""
-newCanvas ""
-
-set ::cf::cfg0::undolevel 0
-set ::cf::cfg0::redolevel 0
-set ::cf::cfg0::undolog(0) ""
-set ::cf::cfg0::curcanvas [lindex [set ::cf::cfg0::canvas_list] 0]
-set ::cf::cfg0::zoom 1.0
-set ::cf::cfg0::oper_mode edit
 
 set animatephase 0
 set changed 0
@@ -157,7 +149,6 @@ set def_router_model quagga
 
 wm minsize . 640 400
 wm geometry . 1016x716-30+30
-wm title . IMUNES
 
 menu .menubar
 . config -menu .menubar -bg white
@@ -178,8 +169,8 @@ menu .menubar
 menu .menubar.file -tearoff 0
 
 .menubar.file add command -label New -underline 0 \
-  -accelerator "Ctrl+N" -command { fileNewDialogBox }
-bind . <Control-n> "fileNewDialogBox"
+  -accelerator "Ctrl+N" -command { newProject }
+bind . <Control-n> "newProject"
 
 .menubar.file add command -label Open -underline 0 \
   -accelerator "Ctrl+O" -command { fileOpenDialogBox }
@@ -662,14 +653,4 @@ bind . <Control-i> {
     redrawAll
 }
 
-#
-# Done with initialization, draw an empty canvas
-#
-switchCanvas first
-
 focus -force . 
-
-#
-# Fire up the animation loop - used basically for selectbox
-#
-animate