#
# Module Node.tcl
#
# $Log: Node.tcl,v $
# Revision 1.2  2006/10/26 09:39:17  vfom
# Added code for netstate server query
#
# Revision 1.1.1.1  2006/09/21 10:57:02  vfom
# Loading TkNetmon to CVS
#
#
namespace eval ::Node {
variable	nodeProperties_exitFlag	0 \
		snmp_ver	$::node_SnmpVer	\
		err_msg	{}		
array set	mArray	[list]
array set	vArray	[list]
array set	trArray	[list]
}
#
proc NewNode {} {
    set hostKey [ CreateNodeNoUpdate node$::nodeIndex $::globalXpos $::globalYpos $::nodeIcon $::nodeFont $::nodeFontColor ]
    updateScrollRegion "[.canvas find withtag $hostKey ]"
    return "$hostKey"
}
#
proc CreateNode { name x y icon font fontColor } {
    set hostKey [ CreateNodeNoUpdate $name $x $y $icon $font $fontColor ]
    updateScrollRegion "[.canvas find withtag $hostKey ]"
    return "$hostKey"
}
#
proc CreateNodeNoUpdate { name x y icon font fontColor } {
    global nodeIndex  nodePoll nodeRetr nodeTmo nodeIP node_SrcIP node_getCommunity \
	globalBG activeFileChanged node_name node_key node_ip node_srcip dataSaveInterval \
	node_poll node_retr node_tmo node_descr node_font node_fontcolor \
	node_icon node_snmpget node_menu node_soundup node_sounddown  \
	node_iflist node_srvlist node_bgplist
    set hostKey ".node$::nodeIndex"
    set ::node_name($hostKey)	$name
    set ::node_key($name)		$hostKey
    set ::node_state($hostKey)		UNK
    set ::node_flashcnt($hostKey)	0
    set ::node_health($hostKey)		0    
    set ::node_ip($hostKey)		$::nodeIP
    set ::node_srcip($hostKey)		$::node_SrcIP
    set ::node_snmpget($hostKey)	$::node_getCommunity
    set ::node_snmptrap($hostKey)	$::node_trapCommunity
    set ::node_poll($hostKey)		$::nodePoll
    set ::node_retr($hostKey)		$::nodeRetr
    set ::node_dataSaveInterval($hostKey)	$::dataSaveInterval
    set ::node_tmo($hostKey)		$::nodeTmo
    set ::node_descr($hostKey)		"node$::nodeIndex"
    set ::node_datadir($hostKey)	""
    set ::node_font($hostKey)		$font
    set ::node_fontcolor($hostKey)	$fontColor
    set ::node_icon($hostKey)		$icon
    set ::node_menu($hostKey)		"Default"
    set ::node_action($hostKey)		$::node_dblClickCmd
    set ::node_soundup($hostKey)	""
    set ::node_sounddown($hostKey)	""
    set ::node_methodslist($hostKey)	[list [list Method ping {} ] ]
    set ::node_snmpver($hostKey)	$::node_SnmpVer
    set ::node_snmpvarslist($hostKey)	[list]
    set ::node_snmptrapslist($hostKey)	[list]
    set ::node_iflist($hostKey)		[list]
    set ::node_srvlist($hostKey)	[list]
    set ::node_bgplist($hostKey)	[list]
#
    set i_h [image height $::arIcons($icon)]
    label $hostKey -image $::arIcons($icon) -padx 2 -pady 2 -relief raised
    lower $hostKey; raise $hostKey .canvas
    .canvas create window $x $y -window $hostKey \
	-tags [list $hostKey $hostKey.icon $name ]

    .canvas create text $x [ expr $y - $i_h/2 - 2 ] -anchor s\
	-text "$::node_name($hostKey)" -fill $fontColor -font $font  -justify center \
	-tags  [list $hostKey $hostKey.up ]

    .canvas create text $x [ expr $y + $i_h/2 + 2] -anchor n\
	-text "rtt=0" -fill $fontColor -font $font -justify center\
	-tags  [list $hostKey $hostKey.dn ]
   
    incr ::nodeIndex
    set ::activeFileChanged "yes"
    return "$hostKey"
}
#
#
#
proc ActivateNode { w } {
    set ID [ .canvas find withtag $w.icon ]	
    if {  $ID != "" } {
	set  ::activeID $ID
	uplevel #0 "after idle ActiveNodeReloadStatus"
    }
}
#
proc NodeMove { iconID  x y } {
    set hostKey [.canvas itemcget $iconID -window ]
    set upID  [.canvas find withtag "$hostKey.up" ]
    set dnID  [.canvas find withtag "$hostKey.dn" ]

    set i_n [$hostKey cget -image ]
    set i_hc [expr [image height $i_n]/2 + 2 ]
    # Move node icon and labels
    .canvas coords $iconID $x $y
    .canvas coords $upID $x [expr $y - $i_hc ]
    .canvas coords $dnID $x [expr $y + $i_hc ]
    #
    # move all node links
    #
    foreach i [.canvas find withtag $::node_name($hostKey)] {
	if { [.canvas type $i]=="line" } {
	    set nodes [.canvas itemcget $i -tags ]
	    set node1 $::node_key([lindex $nodes 0])
	    set node2 $::node_key([lindex $nodes 1])
	    set node1id [.canvas find withtag $node1.icon ] 
	    set node2id [.canvas find withtag $node2.icon ] 
	    set startX  [ lindex [.canvas coords $node1id] 0]
	    set startY  [ lindex [.canvas coords $node1id] 1]
	    set endX    [ lindex [.canvas coords $node2id] 0]
	    set endY    [ lindex [.canvas coords $node2id] 1]
	    .canvas coords $i $startX $startY $endX $endY
	}
    }
    set ::activeFileChanged "yes"
    updateScrollRegion "[.canvas find withtag $hostKey ]"
}
#
proc NodeProperties_GUIconstructor {} {
    set w	.nodeProperties
    set b	$w.buttons
    set t	$w.tnb
    set f	$t.viewFrame
    set c	$f.canvas
    set fe	$f.entries
    set a       $t.actionsFrame
    set ag      $a.grid
    set fp	$t.pollingFrame
    set fpg	$fp.grid
    set m	$fp.methodsFrame
    set mg	$m.grid
    set mb	$m.buttons    
    set s	$t.saveFrame
    set sg	$s.grid
    set sb	$s.buttons    
    set fs	$t.snmpFrame
    set fsg	$fs.grid
    set v	$fs.methodsFrame
    set vg	$v.grid
    set vb	$v.buttons
    set tr	$fs.trapsFrame
    set trg	$tr.grid
    set trb	$tr.buttons
    set fg	$t.signalFrame
    set fgg	$fg.grid
    set fi	$t.inerfaceFrame
    set fib 	$fi.lbuttons
    set fig	$fi.grid
    set fr	$t.servicesFrame
    set frb 	$fr.lbuttons
    set frg	$fr.grid
    set fb	$t.bgpFrame
    set fbb 	$fb.lbuttons
    set fbg	$fb.grid
    
    toplevel $w -class Dialog
    wm transient $w [winfo toplevel [winfo parent $w]]
    wm title $w [msgcat::mc "Node Properties"]
    wm withdraw $w

    blt::tabset $t -tiers 2
    pack $t -side top -fill both -expand on

    $t insert end [msgcat::mc "View"]
    $t insert end [msgcat::mc "Actions"]	
    $t insert end [msgcat::mc "Polling"]
    $t insert end [msgcat::mc "Data collection"]
    $t insert end [msgcat::mc "SNMP"]	
    $t insert end [msgcat::mc "Interfaces"]	
    $t insert end [msgcat::mc "Services"]	
    $t insert end [msgcat::mc "Bgp"]	

#
#   Закладка "Вид"
#
    frame $f 
    $t tab configure [msgcat::mc "View"] -window $f -fill both -anchor n -padx 5 -pady 5

    frame $f.grid    
    pack  $f.grid -side top -expand on -fill both

    canvas $c -width 256 -height 128 -relief sunken  -bg $::globalBG
#
    set i_h	[image height $::arIcons($::nodeIcon)]
    label $c.icon -image $::arIcons($::nodeIcon) -padx 2 -relief raised
    $c create window 128 64  -window $c.icon
    $c create text 128 [expr 64 - $i_h/2 - 2 ]  -anchor s -text "node" \
	-font $::nodeFont -fill $::nodeFontColor
    $c create text 128  [expr 64 + $i_h/2 + 2 ] -anchor n -text "rtt=???" \
	-font $::nodeFont -fill $::nodeFontColor
#
    label $f.lname -text [msgcat::mc "Short Name:"]
    entry $f.ename -width 32 \
        -validatecommand {
	    set node [.canvas itemcget $::node2update -window ]
	    if { $node==""} { return false }
	    if { ![string equal [%W get] $::node_name($node)] }  {
		if { [info exists ::node_key([%W get])] } { return false } 		    
	    }
	    return true 
	} \
	-invalidcommand {
	    set tmp_name [%W get]
	    selection clear
	    tk_dialog .nodeProperties.dlg [msgcat::mc "Error"]  \
	        [msgcat::mc "Such a host name exist."] \
		error 0 [msgcat::mc "Ok" ]
	    focus %W
	}

    label $f.ltext -text [msgcat::mc "Description:"]
    text $f.etext  -width 32 -height 6 

    pack $f.grid -fill both -expand on -padx 5 -pady 8 -side top
    grid rowconfig $f.grid 0 -weight 1 -minsize 0
    grid rowconfig $f.grid 1 -weight 1 -minsize 0
    grid columnconfig $f.grid 0 -weight 1 -minsize 0
    grid $f.canvas -padx 5 -pady 2 -in $f.grid \
	-row 0 -column 0 -rowspan 1 -columnspan 1 -sticky news
    grid $f.lname -padx 5 -pady 2 -in $f.grid \
	-row 1 -column 0 -rowspan 1 -columnspan 1 -sticky nw    
    grid $f.ename -padx 5 -pady 2 -in $f.grid \
	-row 2 -column 0 -rowspan 1 -columnspan 1 -sticky nwe    
    grid $f.ltext -padx 5 -pady 2 -in $f.grid \
	-row 3 -column 0 -rowspan 1 -columnspan 1 -sticky nw    
    grid $f.etext -padx 5 -pady 2 -in $f.grid \
	-row 4 -column 0 -rowspan 1 -columnspan 1 -sticky news    

    bind $f.ename <FocusOut> "updateNodeView"
    
    bind $c <Configure> {
	set cv [winfo parent %W]
	set c_list [ grid bbox $cv.grid 0 0 0 0 ]
	set i_n   [%W.icon cget -image]
	set i_h   [image height $i_n]
	set new_w [expr [lindex $c_list 2]/2]
	set new_h [expr [lindex $c_list 3]/2]
	%W coords 1 $new_w  $new_h
	%W coords 2 $new_w [expr $new_h - $i_h/2 - 2]
	%W coords 3 $new_w [expr $new_h + $i_h/2 + 2]
    }
    set need_space [$f.canvas bbox 1 2 3 ]
    set x1 [lindex $need_space 0]
    set y1 [lindex $need_space 1]
    set x2 [lindex $need_space 2]
    set y2 [lindex $need_space 3]
    if { [expr ($y2-$y1)>128] || [expr ($x2-$x1)>256]} {
    	$c configure -height [expr ($y2 - $y1)*2] \
	    -width [expr $x2 - $x1 +16]
    }
    
    set curr_row 0
    
    frame $fe
    pack  $fe -side top -expand on -fill both

    label $fe.lx -text "X: " 
    grid $fe.lx -in $fe \
        -row $curr_row -column 0 -columnspan 1 -rowspan 1 -sticky e
    entry $fe.ex -width 8 \
        -validatecommand {  IsValidCoordinate [%W get] 	} \
	-invalidcommand {
	    selection clear
	    tk_dialog .nodeProperties.dlg [msgcat::mc "Error"]  \
	        [msgcat::mc "Invalid X coordinate."] \
		error 0 [msgcat::mc "Ok" ]
	    focus %W	    
	}
    grid $fe.ex -in $fe \
        -row $curr_row -column 1 -columnspan 1 -rowspan 1 -sticky w
    incr curr_row

    label $fe.ly -text "Y: " 
    grid $fe.ly -in $fe \
        -row $curr_row -column 0 -columnspan 1 -rowspan 1 -sticky e
    entry $fe.ey -width 8 \
        -validatecommand {  IsValidCoordinate [%W get] 	} \
	-invalidcommand {
	    selection clear
	    tk_dialog .nodeProperties.dlg [msgcat::mc "Error"]  \
	        [msgcat::mc "Invalid Y coordinate."] \
		error 0 [msgcat::mc "Ok" ]
	    focus %W	    
	}
	
    grid $fe.ey -in $fe \
        -row $curr_row -column 1 -columnspan 1 -rowspan 1 -sticky w
    incr curr_row

    label $fe.licon -text [msgcat::mc "Node  icon:"] 
    grid $fe.licon -in $fe \
	-row $curr_row -column 0 -columnspan 1 -rowspan 1 -sticky e
    entry $fe.eicon -width 20 \
	-validatecommand {
	    set tmp_icon [%W get]
	    if { [catch { $::arIcons($tmp_icon) cget -file } ]} { return false } 
	    return true } \
	-invalidcommand {
	    selection clear
	    tk_dialog .nodeProperties.dlg [msgcat::mc "Error"]  \
	        [msgcat::mc "Invalid Icon name."] \
		error 0 [msgcat::mc "Ok" ]
	    focus %W
	}
    grid $fe.eicon -in $fe \
	-row $curr_row -column 1 -columnspan 1 -rowspan 1 -sticky w
    button $fe.bicon -text "..." \
	-command "tk_chooseIcon $w $fe.eicon; updateNodeView"
    grid $fe.bicon -in $fe \
	-row $curr_row -column 2 -columnspan 1 -rowspan 1 -sticky w
    bind $fe.eicon <FocusOut> "updateNodeView"    
    incr curr_row
    label $fe.lfont -text [msgcat::mc "Text  font:"] 
    grid $fe.lfont -in $fe \
	-row $curr_row -column 0 -columnspan 1 -rowspan 1 -sticky e
    entry $fe.efont -width 32 \
	-validatecommand { IsValidFont [%W get] }	\
	-invalidcommand  {
	    selection clear
	    tk_dialog .nodeProperties.dlg [msgcat::mc "Error" ]  \
	        [ msgcat::mc "Invalid Font." ] \
		error 0 [msgcat::mc "Ok" ]
	    focus %W
	}
    
    grid $fe.efont -in $fe \
	-row $curr_row -column 1 -columnspan 1 -rowspan 1 -sticky w
    button $fe.bfont -text "..."  -command "tk_chooseFont $fe.efont"
    grid $fe.bfont -in $fe \
	-row $curr_row -column 2 -columnspan 1 -rowspan 1 -sticky w
    bind $fe.efont <FocusOut> "updateNodeView"    
    incr curr_row
    label $fe.lcolor -text [msgcat::mc "Text color:"] 
    grid $fe.lcolor -in $fe \
	-row $curr_row -column 0 -columnspan 1 -rowspan 1 -sticky e
    entry $fe.ecolor -width 32  \
	-validatecommand { IsValidColor [%W get] }	\
	-invalidcommand  {
	    selection clear
	    tk_dialog .nodeProperties.dlg [msgcat::mc "Error"]  \
	        [msgcat::mc "Invalid Font Color."] \
		error 0 [msgcat::mc "Ok" ]
	    focus %W
	}    
    grid $fe.ecolor -in $fe \
	-row $curr_row -column 1 -columnspan 1 -rowspan 1 -sticky w
    button $fe.bcolor -text "..."  -command "tk_chooseColor2 $fe.ecolor"
    grid $fe.bcolor -in $fe \
	-row $curr_row -column 2 -columnspan 1 -rowspan 1 -sticky w
    bind $fe.ecolor <FocusOut> "updateNodeView"
#
#   Закладка "Действия"
#
    frame $a 
    frame $ag
    pack $ag -side top -anchor nw -padx 5 -pady 5
     
    $t tab configure [msgcat::mc "Actions"] -window $a -fill both -anchor n -padx 5 -pady 5
    set curr_row 0
    label $ag.ldblclc -text [msgcat::mc "Run On Double Click:"] 
    grid $ag.ldblclc -in $ag \
	-row $curr_row -column 0 -columnspan 1 -rowspan 1 -sticky e
    entry $ag.edblclc -width 32
    grid $ag.edblclc -in $ag \
	-row $curr_row -column 1 -columnspan 1 -rowspan 1 -sticky w
    incr curr_row
    label $ag.lmenu -text [msgcat::mc "Node Service Menu:"] 
    grid $ag.lmenu -in $ag \
	-row $curr_row -column 0 -columnspan 1 -rowspan 1 -sticky e
    incr curr_row
    label $ag.lupsnd -text [msgcat::mc "Host Up sound:"] 
    grid $ag.lupsnd -in $ag \
	-row $curr_row -column 0 -columnspan 1 -rowspan 1 -sticky e
    entry $ag.eupsnd -width 32 \
	-validatecommand {
	    set tmp_snd [%W get]
	    if { $tmp_snd=="" } { return true }
	    if { [info exists ::arSounds($tmp_snd) ] } { return true } 
	    return false } \
	-invalidcommand {
	    selection clear
	    tk_dialog .nodeProperties.dlg [msgcat::mc "Error"]  \
	        [msgcat::mc "Invalid Sound UP name."] \
		error 0 [msgcat::mc "Ok" ]
	    focus %W
	}
    grid $ag.eupsnd -in $ag \
	-row $curr_row -column 1 -columnspan 1 -rowspan 1 -sticky w
    button $ag.bupsnd -text "..."  \
	-command "tk_chooseSound  $ag.bupsnd $ag.eupsnd"
    grid $ag.bupsnd -in $ag \
	-row $curr_row -column 2 -columnspan 1 -rowspan 1 -sticky w
    incr curr_row
    label $ag.ldownsnd -text [msgcat::mc "Host Down sound:"] 
    grid $ag.ldownsnd -in $ag \
	-row $curr_row -column 0 -columnspan 1 -rowspan 1 -sticky e
    entry $ag.edownsnd -width 32 \
	-validatecommand {
	    set tmp_snd [%W get]
	    if { $tmp_snd=="" } { return true }
	    if { [info exists ::arSounds($tmp_snd) ] } { return true } 
	    return false } \
	-invalidcommand {
	    selection clear
	    tk_dialog .nodeProperties.dlg [msgcat::mc "Error"]  \
	        [msgcat::mc "Invalid Sound Down name."] \
		error 0 [msgcat::mc "Ok" ]
	    focus %W
	}

    grid $ag.edownsnd -in $ag \
	-row $curr_row -column 1 -columnspan 1 -rowspan 1 -sticky w
    button $ag.bdownsnd -text "..." \
	-command "tk_chooseSound  $ag.bdownsnd $ag.edownsnd"
    grid $ag.bdownsnd -in $ag \
	-row $curr_row -column 2 -columnspan 1 -rowspan 1 -sticky w    
#
#   Закладка "Опрос"
#
    frame $fp  
    frame $fpg
    pack $fpg -side top -anchor nw -padx 5 -pady 5
 
    $t tab configure [msgcat::mc "Polling"] -window $fp -fill both -anchor n
    
    set curr_row 0
    label $fp.lip -text [msgcat::mc "Node IP address:"]  
    grid $fp.lip -in $fpg \
        -row $curr_row -column 0 -columnspan 1 -rowspan 1 -sticky e
    
    entry $fp.eip -width 16  \
	-validatecommand  { return [IsValidIpAddr [%W get]] } \
	-invalidcommand   { 
	    selection clear
	    tk_dialog .nodeProperties.dlg [msgcat::mc "Error"]  \
	        [msgcat::mc "Invalid IP address."] \
		error 0 [msgcat::mc "Ok" ] 
	    focus %W
	}
	
    grid $fp.eip -in $fpg \
    	-row $curr_row -column 1 -columnspan 1 -rowspan 1 -sticky w
    incr curr_row
    label $fp.lsip -text [msgcat::mc "Node Source IP address:"] 
    grid $fp.lsip -in $fpg \
	-row $curr_row -column 0 -columnspan 1 -rowspan 1 -sticky e    
    entry $fp.esip -width 16  \
	-validatecommand  { return [IsValidIpAddr [%W get]] } \
	-invalidcommand   { 
	    set tmp_ip [%W get] 
	    selection clear
	    tk_dialog .nodeProperties.dlg [msgcat::mc "Error"]  \
	        [msgcat::mc "Invalid IP address."] \
		error 0 [msgcat::mc "Ok" ] 
	    focus %W
	}
	
    grid $fp.esip -in $fpg \
	-row $curr_row -column 1 -columnspan 1 -rowspan 1 -sticky w
    incr curr_row
    label $fp.lpoll -text [msgcat::mc "Node polling interval:"] 
    grid $fp.lpoll -in $fpg \
	-row $curr_row -column 0 -columnspan 1 -rowspan 1 -sticky e
    entry $fp.epoll -width 5 \
	-validatecommand {
	    regsub -all { } [%W get] {} tmp_poll
	    if { ![regexp {^[0-9]+$} $tmp_poll]} { return false }
	    return true
	} \
	-invalidcommand {
	    set tmp_poll [%W get]
	    selection clear
	    tk_dialog .nodeProperties.dlg [msgcat::mc "Error"]  \
	        [msgcat::mc "Invalid polling interval."] \
		error 0 [msgcat::mc "Ok" ] 
	    focus %W	    
	}
    grid $fp.epoll -in $fpg \
	-row $curr_row -column 1 -columnspan 1 -rowspan 1 -sticky w
    incr curr_row
    label $fp.lretr -text [msgcat::mc "Retry count:"] 
    grid $fp.lretr -in $fpg \
	-row $curr_row -column 0 -columnspan 1 -rowspan 1 -sticky e
    entry $fp.eretr -width 5 \
	-validatecommand {
	    regsub -all { } [%W get] {} tmp_retr
	    if { ![ regexp {^[0-9]+$} $tmp_retr]} { return false }
	    return true
	} \
	-invalidcommand {
	    set tmp_retr [%W get]
	    selection clear
	    tk_dialog .nodeProperties.dlg [msgcat::mc "Error"]  \
	        [msgcat::mc "Invalid retry count."] \
		error 0 [msgcat::mc "Ok" ] 
	    focus %W	    
	}
    grid $fp.eretr -in $fpg \
	-row $curr_row -column 1 -columnspan 1 -rowspan 1 -sticky w
    incr curr_row
    label $fp.ltmo -text [msgcat::mc "Polling timeout:"] 
    grid $fp.ltmo -in $fpg \
	-row $curr_row -column 0 -columnspan 1 -rowspan 1 -sticky e
    entry $fp.etmo -width 9 \
	-validatecommand {
	    regsub -all { } [%W get] {} tmp_tmo
	    if { ![regexp {^[0-9]+$} $tmp_tmo]} { return false }
	    return true
	} \
	-invalidcommand {
	    set tmp_tmo [%W get]
	    selection clear
	    tk_dialog .nodeProperties.dlg [msgcat::mc "Error"]  \
	        [msgcat::mc "Invalid polling timeout."] \
		error 0 [msgcat::mc "Ok" ] 
	    focus %W	    
	}
    grid $fp.etmo -in $fpg \
	-row $curr_row -column 1 -columnspan 1 -rowspan 1 -sticky w
    incr curr_row
#
    frame $m -borderwidth 1 -relief sunken 
    pack $m -side top -padx 5 -pady 5 -expand on -fill both -anchor s
    label $m.lb -text [msgcat::mc "Node methods"] -font $::headerFont
    grid $m.lb -in $m -column 0 -row 0 -sticky w
    grid rowconfig $m 1 -weight 1 -minsize 0
    grid columnconfig $m 0 -weight 1 -minsize 0
    frame $mg
    grid $mg -in $m -column 0 -row 1 -sticky news
    grid configure $mg  -padx 5 -pady 5
    
    array set ::Node::mArray [list  {0,0} [msgcat::mc "Type"] {0,1} [msgcat::mc "Name"] {0,2} [msgcat::mc "Parameters"] ]
    
    grid rowconfig $mg 0 -weight 1 -minsize 0
    grid columnconfig $mg 0 -weight 1 -minsize 0
#
	table $m.tbl -rows 1  -cols 3 \
	    -variable ::Node::mArray \
	    -titlerows 1 -titlecols 0 \
	    -yscrollcommand "$m.sy set "  \
	    -xscrollcommand "$m.sx set "  \
	    -roworigin 0 -colorigin 0 \
	    -maxwidth 400 -maxheight 100 \
	    -selectmode browse \
	    -flashmode 0 \
	    -background #f700f700f700 \
	    -borderwidth 2 \
	    -selecttype row	\
	    -state disabled  \
	    -resizeborders both \
	    -anchor w
    scrollbar $m.sy -command "$m.tbl yview"
    scrollbar $m.sx -orient horiz -command "$m.tbl xview"
    grid $m.tbl -in $mg \
	-row 0 -column 0 -rowspan 1 -columnspan 1 -sticky news
    grid $m.sy -in $mg -column 1 -row 0 \
	-columnspan 1 -rowspan 1 -sticky news
    grid $m.sx -in $mg -column 0 -row 1 \
	-columnspan 1 -rowspan 1 -sticky news
    $m.tbl tag config title -bg #0000bf00ff00 -relief groove
    $m.tbl tag config sel -fg #f700f700f700 -bg #48003d008b00 
    $m.tbl width 0 10 1 14 2 36
    bind $m.tbl <Double-1> "LinkMethod $w $m.tbl {}   edit"
#
    frame $mb	
    grid $mb -in $m -column 0 -row 2 \
	-columnspan 1 -rowspan 1 -sticky n
    button	$mb.bsadd  -text [msgcat::mc "New Save"]   -command "LinkMethod $w $m.tbl Save add"
    button	$mb.bpadd  -text [msgcat::mc "New Poll"]   -command "LinkMethod $w $m.tbl Method add"
    button	$mb.bedit  -text [msgcat::mc "Edit"]   -command "LinkMethod $w $m.tbl {}   edit"
    button	$mb.bdel   -text [msgcat::mc "Delete"] -command "LinkMethod $w $m.tbl {}   delete"
    pack $mb.bsadd $mb.bpadd $mb.bedit $mb.bdel -padx 5 -pady 5 -side left 
#
#   Закладка "Сбор данных"
#
    frame $s 
    frame $sg
    pack $sg -side top -anchor nw -padx 5 -pady 5
    $t tab configure [msgcat::mc "Data collection"]  -window $s -fill both  -anchor n
    set curr_row 0
    label $s.ltsv -text [msgcat::mc "Data save interval:"] 
    grid $s.ltsv -in $sg \
	-row $curr_row -column 0 -columnspan 1 -rowspan 1 -sticky e
    entry $s.etsv -width 9 \
	-validatecommand {
	    regsub -all { } [%W get] {} tmp_tsv
	    if { ![regexp {^[0-9]+$} $tmp_tsv]} { return false }
	    return true
	} \
	-invalidcommand {
	    selection clear
	    tk_dialog .nodeProperties.dlg [msgcat::mc "Error"]  \
	        [msgcat::mc "Invalid datasave interval."] \
		error 0 [msgcat::mc "Ok" ] 
	    focus %W	    
	}
    grid $s.etsv -in $sg \
	-row $curr_row -column 1 -columnspan 1 -rowspan 1 -sticky w
    incr curr_row
    label $s.ldir -text [msgcat::mc "Data directory:"] 
    grid $s.ldir -in $sg \
	-row $curr_row -column 0 -columnspan 1 -rowspan 1 -sticky e
    entry $s.edir -width 32 
    grid $s.edir -in $sg \
	-row $curr_row -column 1 -columnspan 1 -rowspan 1 -sticky w
    incr curr_row
#
#   Закладка "SNMP"
#
    frame $fs 
    frame $fsg
    pack $fsg -side top -anchor nw -padx 5 -pady 5
    $t tab configure [msgcat::mc "SNMP"]  -window $fs -fill both  -anchor n

    set curr_row 0
    label $fs.lsnmp -text [msgcat::mc "SNMP Get Community:"] 
    grid $fs.lsnmp -in $fsg \
	-row $curr_row -column 0 -columnspan 1 -rowspan 1 -sticky e
    entry $fs.esnmp -width 32 
    grid $fs.esnmp -in $fsg \
	-row $curr_row -column 1 -columnspan 1 -rowspan 1 -sticky w
    radiobutton $fs.v1 -text "v1" -variable ::Node::snmp_ver -value ""
    grid $fs.v1 -in $fsg \
	-row $curr_row -column 2 -columnspan 1 -rowspan 1 -sticky w
    incr curr_row
#	
    label $fs.lsnmptrap -text [msgcat::mc "SNMP Trap Community:"] 
    grid $fs.lsnmptrap -in $fsg \
	-row $curr_row -column 0 -columnspan 1 -rowspan 1 -sticky e
    entry $fs.esnmptrap -width 32 
    grid $fs.esnmptrap -in $fsg \
	-row $curr_row -column 1 -columnspan 1 -rowspan 1 -sticky w
    radiobutton $fs.v2 -text "v2" -variable ::Node::snmp_ver -value "v2"
    grid $fs.v2 -in $fsg \
	-row $curr_row -column 2 -columnspan 1 -rowspan 1 -sticky w
#
    frame $v -borderwidth 1 -relief sunken
    pack $v -side top -padx 5 -pady 5 -expand on -fill both -anchor s
    label $v.lb -text [msgcat::mc "Node SNMP variables"] -font $::headerFont
    grid $v.lb -in $v -column 0 -row 0 -sticky w
    grid rowconfig $v 1 -weight 1 -minsize 0
    grid columnconfig $v 0 -weight 1 -minsize 0
    frame $vg
    grid $vg -in $v -column 0 -row 1 -sticky news
    grid configure $vg -padx 5 -pady 5

    array set ::Node::vArray [list {0,0} [msgcat::mc "Name"] {0,1} "OID" {0,2} [msgcat::mc "Value"] ]
    
    grid rowconfig $vg 0 -weight 1 -minsize 0
    grid columnconfig $vg 0 -weight 1 -minsize 0
#
	table $v.tbl -rows 1  -cols 3 \
	    -variable ::Node::vArray \
	    -titlerows 1 -titlecols 0 \
	    -maxwidth 400 -maxheight 100 \
	    -yscrollcommand "$v.sy set "  \
	    -xscrollcommand "$v.sx set "  \
	    -roworigin 0 -colorigin 0 \
	    -selectmode browse \
	    -flashmode 0 \
	    -background #f700f700f700 \
	    -borderwidth 2 \
	    -selecttype row	\
	    -state disabled  \
	    -resizeborders both \
	    -anchor w
    scrollbar $v.sy -command "$v.tbl yview"
    scrollbar $v.sx -orient horiz -command "$v.tbl xview"
    grid $v.tbl -in $vg \
	-row 0 -column 0 -rowspan 1 -columnspan 1 -sticky news
    grid $v.sy -in $vg -column 1 -row 0 \
	-columnspan 1 -rowspan 1 -sticky news
    grid $v.sx -in $vg -column 0 -row 1 \
	-columnspan 1 -rowspan 1 -sticky news
    $v.tbl tag config title -bg #0000bf00ff00 -relief groove
    $v.tbl tag config sel -fg #f700f700f700 -bg #48003d008b00 
    $v.tbl width 0 20 1 35 2 10
    bind $v.tbl <Double-1> "LinkVariable $v.tbl edit"
#
    frame $vb	
    grid $vb -in $v -column 0 -row 2 \
	-columnspan 1 -rowspan 1 -sticky n
    button	$vb.badd   -text [msgcat::mc "Add"]    -command "LinkVariable $v.tbl  add"
    button	$vb.bedit  -text [msgcat::mc "Edit"]   -command "LinkVariable $v.tbl  edit"
    button	$vb.bdel   -text [msgcat::mc "Delete"] -command "LinkVariable $v.tbl  delete"
    pack $vb.badd $vb.bedit $vb.bdel -padx 5 -pady 5 -side left 
#
    frame $tr -borderwidth 1 -relief sunken
    pack $tr -side top -padx 5 -pady 5 -expand on -fill both -anchor s
    label $tr.lb -text [msgcat::mc "Node SNMP traps"] -font $::headerFont
    grid $tr.lb -in $tr -column 0 -row 0 -sticky w
    grid rowconfig $tr 1 -weight 1 -minsize 0
    grid columnconfig $tr 0 -weight 1 -minsize 0
    frame $trg
    grid $trg -in $tr -column 0 -row 1 -sticky news
    grid configure $trg -padx 5 -pady 5
    
    grid rowconfig $trg 0 -weight 1 -minsize 0
    grid columnconfig $trg 0 -weight 1 -minsize 0
#    
    listbox $tr.lbx -width 18 -heigh 6  -yscrollcommand "$tr.syl set"
    grid $tr.lbx -in $trg  -column 0 -row 0 \
    	-columnspan 1 -rowspan 1 -sticky news    
    scrollbar $tr.syl -command "$tr.lbx yview" 
    grid $tr.syl -in $trg  -column 1 -row 0 \
    	-columnspan 1 -rowspan 1 -sticky news    
#
    frame $trb	
    grid $trb -in $trg -column 2 -row 0 \
	-columnspan 1 -rowspan 1 -sticky n
    button	$trb.badd   -text [msgcat::mc "Add"]    -command "LinkTrap $tr.lbx  add"
    button	$trb.bdel   -text [msgcat::mc "Delete"] -command "LinkTrap $tr.lbx  delete"
    pack $trb.badd $trb.bdel -padx 5 -pady 5 -side top -fill x
#
    frame $fi
    frame $fig
    pack $fig -side top -anchor nw -padx 5 -pady 5
    $t tab configure [msgcat::mc "Interfaces"] -window $fi -fill both -anchor n
    set curr_row 0
    frame $fig.gchk
    pack $fig.gchk -fill both -expand on -side top -anchor nw -padx 5 -pady 5
    grid $fig.gchk -in $fig \
	-row $curr_row -column 0 -columnspan 1 -rowspan 1 -sticky news 	
    listbox $fi.echk -width 32 -height 16  \
	-yscrollcommand "$fi.sychk set" -xscrollcommand "$fi.sxchk set"
    scrollbar $fi.sychk -command "$fi.echk yview"	
    scrollbar $fi.sxchk -orient horiz -command "$fi.echk xview"
    grid $fi.echk -in $fig.gchk \
	-row 0 -column 0 -columnspan 1 -rowspan 1 -sticky news	
    grid $fi.sychk -in $fig.gchk \
	-row 0 -column 1 -columnspan 1 -rowspan 1 -sticky news	
    grid $fi.sxchk -in $fig.gchk \
	-row 1 -column 0 -columnspan 1 -rowspan 1 -sticky news	
#
    frame $fib
    grid $fib -in $fig \
	-row $curr_row -column 1 -columnspan 1 -rowspan 1 -sticky nw
	
    button $fib.badd -text [msgcat::mc "Add"] \
	-command "EditIf $fi.echk $fp.eip $fs.esnmp add"	    
    button $fib.bclone -text [msgcat::mc "Clone"] \
	-command "EditIf $fi.echk $fp.eip $fs.esnmp clone"	    
    button $fib.bcfg -text [msgcat::mc "Edit"] \
	-command "EditIf $fi.echk $fp.eip $fs.esnmp edit"	    
    button $fib.bdel -text [msgcat::mc "Delete"] \
	-command "EditIf $fi.echk $fp.eip $fs.esnmp delete"	    
    pack $fib.badd $fib.bcfg $fib.bdel $fib.bclone -padx 5 -pady 5 -side top -expand on -fill x
    bind $fi.echk <Double-1> "EditIf $fi.echk $fp.eip $fs.esnmp edit"	    
#
    frame $fr 
    frame $frg
    pack $frg -side top -anchor nw -padx 5 -pady 5

    $t tab configure [msgcat::mc "Services"]  -window $fr -fill both  -anchor n	
    set curr_row 0
    frame $frg.gchk
    pack $frg.gchk -fill both -expand on -side top -anchor nw -padx 5 -pady 5
    grid $frg.gchk -in $frg \
	-row $curr_row -column 0 -columnspan 1 -rowspan 1 -sticky news 	
    listbox $fr.echk -width 32 -height 16 \
	-yscrollcommand "$fr.sychk set" -xscrollcommand "$fr.sxchk set"
    scrollbar $fr.sychk -command "$fr.echk yview"	
    scrollbar $fr.sxchk -orient horiz -command "$fr.echk xview"
    grid $fr.echk -in $frg.gchk \
	-row 0 -column 0 -columnspan 1 -rowspan 1 -sticky news	
    grid $fr.sychk -in $frg.gchk \
	-row 0 -column 1 -columnspan 1 -rowspan 1 -sticky news	
    grid $fr.sxchk -in $frg.gchk \
	-row 1 -column 0 -columnspan 1 -rowspan 1 -sticky news	
    bind $fr.echk <Double-1> "EditSrv $fr.echk edit"	    
#
    frame $frb
    grid $frb -in $frg \
	-row $curr_row -column 1 -columnspan 1 -rowspan 1 -sticky nw
	
    button $frb.badd -text [msgcat::mc "Add"] -command "EditSrv $fr.echk add"	    	    
    button $frb.bcfg -text [msgcat::mc "Edit"] -command "EditSrv $fr.echk edit"	    
    button $frb.bdel -text [msgcat::mc "Delete"] -command "EditSrv $fr.echk delete"	    
    pack $frb.badd $frb.bcfg $frb.bdel -padx 5 -pady 5 -side top -expand on -fill x
#
    frame $fb 
    frame $fbg
    pack $fbg -side top -anchor nw -padx 5 -pady 5

    $t tab configure [msgcat::mc "Bgp"]  -window $fb -fill both  -anchor n
    set curr_row 0
    frame $fbg.gchk
    pack $fbg.gchk -fill both -expand on -side top -anchor nw -padx 5 -pady 5
    grid $fbg.gchk -in $fbg \
	-row $curr_row -column 0 -columnspan 1 -rowspan 1 -sticky news 	
    listbox $fb.echk -width 32 -height 16 \
	-yscrollcommand "$fb.sychk set" -xscrollcommand "$fb.sxchk set"
    scrollbar $fb.sychk -command "$fb.echk yview"	
    scrollbar $fb.sxchk -orient horiz -command "$fb.echk xview"
    grid $fb.echk -in $fbg.gchk \
	-row 0 -column 0 -columnspan 1 -rowspan 1 -sticky news	
    grid $fb.sychk -in $fbg.gchk \
	-row 0 -column 1 -columnspan 1 -rowspan 1 -sticky news	
    grid $fb.sxchk -in $fbg.gchk \
	-row 1 -column 0 -columnspan 1 -rowspan 1 -sticky news	
    bind $fb.echk <Double-1> "EditBgp $fb.echk edit"	    
#
    frame $fbb
    grid $fbb -in $fbg \
	-row $curr_row -column 1 -columnspan 1 -rowspan 1 -sticky nw
	
    button $fbb.badd -text [msgcat::mc "Add"] -command "EditBgp $fb.echk add"	    
    button $fbb.bcfg -text [msgcat::mc "Edit"] -command "EditBgp $fb.echk edit"	    
    button $fbb.bdel -text [msgcat::mc "Delete"] -command "EditBgp $fb.echk delete"	    
    pack $fbb.badd $fbb.bcfg $fbb.bdel -padx 5 -pady 5 -side top -expand on -fill x
#
    frame $b
    pack $b -side bottom -padx 10 -pady 10
    button $b.apply -text [msgcat::mc "Apply"]   -command {
	set w	.nodeProperties
	set f	.nodeProperties.tnb.viewFrame
	set fe	.nodeProperties.tnb.viewFrame.entries
	set fp	.nodeProperties.tnb.pollingFrame
	set ag	.nodeProperties.tnb.actionsFrame.grid
	#    set fs	.nodeProperties.tnb.snmpFrame
	#    set fg	.nodeProperties.tnb.signalFrame
	#    set fi	.nodeProperties.tnb.inerfaceFrame
	if { ![$f.ename validate]  || ![$fp.eip validate]   || 
	     ![$fp.esip validate]  || ![$fe.eicon validate] ||
	     ![$fe.ecolor validate] || ![$fe.efont validate] ||
	     ![$fe.ex validate]    || ![$fe.ey validate]    || 
	     ![$fp.epoll validate] || ![$fp.etmo validate]  || 
	     ![$fp.eretr validate] || ![$ag.eupsnd validate] || ![$ag.edownsnd validate ]   
	} { return }	    
	set  ::Node::nodeProperties_exitFlag 1
    }
    button $b.cans  -text [msgcat::mc "Cancel"]  -command "set ::Node::nodeProperties_exitFlag  2"
    pack $b.apply $b.cans -side left -padx 5 -pady 5
    update idletasks

    set x [expr {[winfo screenwidth $w]/2 - [winfo reqwidth $w]/2 \
	- [winfo vrootx [winfo parent $w]]}]
    set y [expr {[winfo screenheight $w]/2 - [winfo reqheight $w]/2 \
	- [winfo vrooty [winfo parent $w]]}]
    wm geom $w +$x+$y
    
    bind $w <Destroy> "set ::Node::nodeProperties_exitFlag  2"

}
#
proc findMethod { node mName } {
    foreach i $::node_methodslist($node) {
	set mn [lindex $i 1]
	if { [string match $mName $mn ] } { return 1 }
    }
    return 0
}
#
proc NodeProperties { node } {    
    set w	.nodeProperties
    set b	$w.buttons
    set t	$w.tnb
    set f	$t.viewFrame
    set c	$f.canvas
    set fe	$f.entries
    set a       $t.actionsFrame
    set ag      $a.grid
    set fp	$t.pollingFrame
    set fpg	$fp.grid
    set s	$t.saveFrame
    set sg	$s.grid
    set sb	$s.buttons    
    set m	$fp.methodsFrame
    set mg	$m.grid
    set mb	$m.buttons
    set fs	$t.snmpFrame
    set fsg	$fs.grid
    set v	$fs.methodsFrame
    set vg	$m.grid
    set vb	$m.buttons
    set tr	$fs.trapsFrame
    set trg	$tr.grid
    set trb	$tr.buttons
    set fg	$t.signalFrame
    set fgg	$fg.grid
    set fi	$t.inerfaceFrame
    set fib 	$fi.lbuttons
    set fig	$fi.grid
    set fr	$t.servicesFrame
    set frb 	$fr.lbuttons
    set frg	$fr.grid
    set fb	$t.bgpFrame
    set fbb 	$fb.lbuttons
    set fbg	$fb.grid

    set ::node2update  [.canvas find withtag $node.icon]
    set lup	[.canvas find withtag $node.up ]
    set ldn	[.canvas find withtag $node.dn ]
    set i_n	$::node_icon($node) 
    set i_h	[image height $::arIcons($::node_icon($node))]
    set lXY	[.canvas coords $node.icon]

    if { ![winfo exists $w ] } {
	NodeProperties_GUIconstructor
    }
#
#  Load actual  data:
#
    $t select	0
    $t focus	0
    $t see	0
#
    $c.icon configure -image $::arIcons($::node_icon($node))
    $c  itemconfigure 2 -text $::node_name($node) -font $::node_font($node) \
	-fill $::node_fontcolor($node)
    $c  itemconfigure 3 -text [.canvas itemcget $ldn -text] -font $::node_font($node) \
	-fill $::node_fontcolor($node)
    $f.ename insert 0	$::node_name($node)
    $f.etext insert 0.0	$::node_descr($node)
    $fe.ex insert 0 [lindex $lXY 0]
    $fe.ey insert 0 [lindex $lXY 1]
    $fe.eicon insert 0	$::node_icon($node)
    $ag.edblclc insert 0 $::node_action($node)
    eval tk_optionMenu $ag.emenu ::node_menu($node) [ getServiceMenus ]
    grid $ag.emenu -in $ag \
	    -row 1 -column 1 -columnspan 1 -rowspan 1 -sticky w
    $ag.eupsnd insert 0	$::node_soundup($node)
    $ag.edownsnd insert 0 $::node_sounddown($node)    
    $fe.efont insert 0	$::node_font($node)
    $fe.ecolor insert 0	$::node_fontcolor($node)
    $fp.eip insert 0	$::node_ip($node)
    $fp.esip insert 0	$::node_srcip($node)
    $fp.epoll insert 0	$::node_poll($node)
    $fp.eretr insert 0	$::node_retr($node)
    $fp.etmo insert 0	$::node_tmo($node)
    $s.etsv insert 0	$::node_dataSaveInterval($node)
    $s.edir insert 0	$::node_datadir($node)
    set idx 1
    foreach i $::node_methodslist($node) {
	set ::Node::mArray($idx,0) [lindex $i 0]
	set ::Node::mArray($idx,1) [lindex $i 1]
	set ::Node::mArray($idx,2) [lindex $i 2]
	incr idx
    }
    $m.tbl configure -rows $idx
    $fs.esnmp insert 0	$::node_snmpget($node)
    set ::Node::snmp_ver $::node_snmpver($node)
    set idx 1
    foreach i $::node_snmpvarslist($node) {
	set ::Node::vArray($idx,0) [lindex $i 0]
	set ::Node::vArray($idx,1) [lindex $i 1]
	set ::Node::vArray($idx,2) [lindex $i 2]
	incr idx
    }
    $v.tbl configure -rows $idx
    $fs.esnmptrap insert 0	$::node_snmptrap($node)
    foreach i $::node_snmptrapslist($node) {
	$tr.lbx  insert end $i
    }
    #
    foreach i $::node_iflist($node)  { 
	set ifname [lindex $i 0]
	$fi.echk  insert end	$ifname 
    }	    
    set ::Interface::iflist  $::node_iflist($node)
    set ::Interface::nodeKey $node
    foreach i $::node_srvlist($node)  { 
	set srvname  [lindex $i 0]
	$fr.echk  insert end	$srvname 
    }	    
    set ::Service::srvlist  $::node_srvlist($node)
    set ::Service::nodeKey $node
    foreach i $::node_bgplist($node)  { 
	set asn [lindex $i 0]
	$fb.echk  insert end	$asn 
    }	    
    set ::Bgp::bgplist  $::node_bgplist($node)
    set ::Bgp::nodeKey $node
#
# Launch  entries validation
#
    $f.ename configure -validate focusout
    $fe.ex configure -validate focusout
    $fe.ey configure -validate focusout
#    $fe.eicon configure -validate focusout
#    $fe.ecolor configure -validate focusout
#    $fe.efont configure -validate focusout
    $fp.esip configure -validate focusout
    $fp.eip configure -validate focusout
    $fp.epoll configure -validate focusout
    $fp.etmo configure -validate focusout
    $s.etsv configure -validate focusout
    $fp.eretr configure -validate focusout
    $ag.eupsnd configure -validate focusout
    $ag.edownsnd configure -validate focusout
#
    if { [string equal [wm state $w] withdrawn] } {
        wm deiconify $w
    }
    raise $w 
    set ::Node::nodeProperties_exitFlag  0
    updateNodeView
#
    update idletasks
#    
    set oldFocus [focus]
    set oldGrab [grab current $w]
    if {[string compare $oldGrab ""]} {
	set grabStatus [grab status $oldGrab]
    }
    grab $w
    focus $w.buttons.apply

    tkwait variable ::Node::nodeProperties_exitFlag

    catch {focus $oldFocus}
    if {[winfo exists $w ]} {
	grab release $w
	wm withdraw $w
	if { $::Node::nodeProperties_exitFlag == 1 } {	
	    set old_name $::node_name($node)
	    set ::node_name($node)	[$f.ename get ]
	    set ::node_descr($node) 	[$f.etext get 0.0 "end-1 chars"]
	    set ::node_icon($node)	[$fe.eicon get]
	    set ::node_font($node)	[$fe.efont get]
	    set ::node_fontcolor($node)	[$fe.ecolor get]
	    set ::node_action($node)	[$ag.edblclc get]
	    set ::node_soundup($node)	[$ag.eupsnd get]
	    set ::node_sounddown($node)	[$ag.edownsnd get]
	    set ::node_ip($node)	[$fp.eip get]
    	    set ::node_srcip($node)	[$fp.esip get]
	    set ::node_poll($node)	[$fp.epoll get]
	    set ::node_retr($node)	[$fp.eretr get]
	    set ::node_tmo($node)	[$fp.etmo get]
	    set ::node_dataSaveInterval($node)	[$s.etsv get]
	    set ::node_datadir($node)	[$s.edir get]
	    set nmethods [ expr [array size ::Node::mArray] / 3 ]
	    set tmp_mlist [list]
	    for {set i 1} {$i <$nmethods} {incr i} {
		lappend tmp_mlist [list $::Node::mArray($i,0) $::Node::mArray($i,1) $::Node::mArray($i,2)]
	    }
	    set ::node_methodslist($node) $tmp_mlist	    	    
	    set ::node_snmpget($node)	[string trim [$fs.esnmp get]]
	    set ::node_snmpver($node)  $::Node::snmp_ver 
	    set nvars [ expr [array size ::Node::vArray] / 3 ]
	    set tmp_vlist [list]
	    for {set i 1} {$i <$nvars} {incr i} {
		lappend tmp_vlist [list $::Node::vArray($i,0) $::Node::vArray($i,1) $::Node::vArray($i,2)  ]
	    }
	    set ::node_snmpvarslist($node) $tmp_vlist	    
	    set ::node_snmptrap($node)	[string trim [$fs.esnmptrap get]]
	    set ::node_snmptrapslist($node) [$tr.lbx get 0 end ]	    
	    set ::node_iflist($node)	$::Interface::iflist
	    set ::node_srvlist($node)	$::Service::srvlist
	    set ::node_bgplist($node)	$::Bgp::bgplist
	    if  {  ($::node_iflist($node)!={} || $::node_bgplist($node)!={} ) && ![ findMethod $node "router"] } {
		# need automatic "router" method 
		lappend ::node_methodslist($node) [list "Method" "router" [ format {"%s"} $::node_snmpget($node) ] ]
	    }
	    if { ($::node_snmpvarslist($node) !={} ) && ![findMethod $node "snmp"] } {
		# need automatic "snmp" method 
		lappend ::node_methodslist($node) [list "Method" "snmp" [ format {"%s"} $::node_snmpget($node) ] ]
	    }
	    if { ($::node_snmptrapslist($node)!={} || $::node_iflist($node)!={} || $::node_bgplist($node)!={} ) 
		    && [lsearch -exact $::node_snmptrapslist($node) "generic"]<0 } {
		lappend ::node_snmptrapslist($node) "generic"
	    }
	    #
	    # Update real node view
	    #
	    .canvas  itemconfigure $::node2update \
		-tags [list $node $node.icon $::node_name($node)]
	    .canvas  itemconfigure $lup -text $::node_name($node) \
		 -font $::node_font($node) -fill $::node_fontcolor($node)
	    .canvas itemconfigure $ldn -font $::node_font($node) -fill $::node_fontcolor($node)
	    $node configure -image $::arIcons($::node_icon($node))
	    foreach i [.canvas find withtag $old_name] {
	        if { [.canvas type $i]=="line" } {
		    set nodes [.canvas itemcget $i -tags ]
		    set node1 $::node_key([lindex $nodes 0])
		    set node2 $::node_key([lindex $nodes 1])
		    set node1id [.canvas find withtag $node1.icon ] 
		    set node2id [.canvas find withtag $node2.icon ] 
		    .canvas itemconfigure $i -tags [list $::node_name($node1) $::node_name($node2)] 
		}
	    }
	    if { ![string equal $old_name $::node_name($node) ] } {
		unset ::node_key($old_name)	    
		set ::node_key([$f.ename get ])  $node 
	    }
	    NodeMove $::node2update [$f.entries.ex get] [$f.entries.ey get]
	    updateScrollRegion "[.canvas find withtag $node ]"
    	    set ::activeFileChanged "yes"	    	
	} 
#
# Stop  entries validation
#
	$f.ename configure -validate none
	$fe.ex configure -validate none
	$fe.ey configure -validate none
#	$fe.eicon configure -validate none
#	$fe.ecolor configure -validate none
#	$fe.efont configure -validate none
	$fp.esip configure -validate none
	$fp.eip configure -validate none	
	$fp.epoll configure -validate none	
	$fp.etmo configure -validate none	
	$s.etsv configure -validate none	
	$fp.eretr configure -validate none	
#
# Cleanup entries
#
	$f.ename delete 0 end
	$f.etext delete 0.0 end
	$fe.ex delete 0 end
	$fe.ey delete 0 end
	$fe.eicon delete 0 end
	$fe.efont delete 0 end
	$fe.ecolor delete 0 end
	$ag.edblclc delete 0 end
	destroy $ag.emenu
	$ag.eupsnd delete 0 end
	$ag.edownsnd delete 0 end	
	$fp.eip delete 0 end
	$fp.esip delete 0 end
	$fp.epoll delete 0 end
	$fp.eretr delete 0 end
	$fp.etmo delete 0 end
	$s.etsv delete 0 end
	$s.edir delete 0 end
	$m.tbl configure -rows 1
        $fs.esnmp delete 0 end
        $fs.esnmptrap delete 0 end
        $tr.lbx delete 0 end
	$v.tbl configure -rows 1
	$fi.echk delete 0 end
	$fr.echk delete 0 end
	$fb.echk delete 0 end
    }    
    array unset ::Node::mArray
    array set ::Node::mArray [list {0,0} [msgcat::mc "Type"] {0,1} [msgcat::mc "Name"] {0,2} [msgcat::mc "Parameters"] ]
    array unset ::Node::vArray
    array set ::Node::vArray [list {0,0} [msgcat::mc "Name"] {0,1} [msgcat::mc "OID"] ]
    set ::Interface::iflist [list]
    set ::Interface::ifs    [list]
    set ::Service::srvlist [list]
    set ::Bgp::bgplist [list]

    if {[string compare $oldGrab ""]} {
	if {![string compare $grabStatus "global"]} {
	    grab -global $oldGrab
	} else {
	    grab $oldGrab
	}
    }
    return 
}
#
proc updateNodeView { } {
    if { $::Node::nodeProperties_exitFlag == 0 } {	
	set w .nodeProperties
	set f $w.tnb.viewFrame
	set wc $f.canvas
	set coords [$wc coords 1]
	set x [lindex $coords 0]
	set y [lindex $coords 1]
	set i_n [$f.entries.eicon get]
	if { ![catch {$::arIcons($i_n) cget -file}] } {
	    set i_h [image height $::arIcons($i_n)]
	    $wc.icon configure -image $::arIcons($i_n)
	    $wc  coords 2  $x [expr $y - $i_h/2 - 2]
	    $wc  coords 3  $x [expr $y + $i_h/2 + 2]
	}
	if { [IsValidColor [$f.entries.ecolor get ]] } { 
	    $wc  itemconfigure 2 -fill [$f.entries.ecolor get] -text [$f.ename get ]
	    $wc  itemconfigure 3 -fill [$f.entries.ecolor get]
	}
	if { [IsValidFont [$f.entries.efont get] ] } {
	    $wc  itemconfigure 2 -font [$f.entries.efont get] 
	    $wc  itemconfigure 3 -font [$f.entries.efont get] 
	}
	set need_space [$wc bbox 1 2 3 ]
	set x1 [lindex $need_space 0]
	set y1 [lindex $need_space 1]
	set x2 [lindex $need_space 2]
	set y2 [lindex $need_space 3]
	if { [expr ($y2-$y1+16)>128] || [expr ($x2-$x1+16)>256]} {
	    $wc configure -height [expr ($y2 - $y1) + 16] \
	        -width [expr $x2 - $x1 + 16]
	}
    }
}
#
proc NodeDelete { node } {
    # remove label_window & strings
    set name $::node_name($node)
    foreach i [.canvas find withtag $node] {
		.canvas delete $i
    }
    # remove all connected links
    foreach i [.canvas find withtag $::node_name($node)] {
		.canvas delete $i
    }
    unset ::node_key($name)
    unset ::node_name($node)
    unset ::node_state($node)
    unset ::node_flashcnt($node)
    unset ::node_health($node)    
    unset ::node_descr($node)
    unset ::node_datadir($node)
    unset ::node_ip($node)
    unset ::node_srcip($node)
    unset ::node_snmpget($node)
    unset ::node_snmptrap($node)
    unset ::node_poll($node)
    unset ::node_retr($node)
    unset ::node_tmo($node)
    unset ::node_dataSaveInterval($node)
    unset ::node_font($node)
    unset ::node_fontcolor($node)
    unset ::node_icon($node)
    unset ::node_menu($node)
    unset ::node_action($node)
    unset ::node_soundup($node)
    unset ::node_sounddown($node)
    unset ::node_methodslist($node)
    unset ::node_snmpver($node)
    unset ::node_snmpvarslist($node)
    unset ::node_snmptrapslist($node)
    
    foreach sublist $::node_iflist($node) {
	set ifkey [lindex $sublist 1]
	unset ::if_methodslist($ifkey)
	unset ::if_name($ifkey)
	unset ::if_owner($ifkey)
	unset ::if_descr($ifkey)
	unset ::if_datadir($ifkey)
	unset ::if_bandwidth($ifkey)
    }
    unset ::node_iflist($node)
    foreach sublist $::node_srvlist($node) {
	set srvkey [lindex $sublist 1]
	unset ::srv_methodslist($srvkey)
	unset ::srv_snmpvarslist($srvKey)
	unset ::srv_name($srvkey)
	unset ::srv_owner($srvkey)
	unset ::srv_descr($srvkey)
	unset ::srv_datadir($srvkey)
    }
    unset ::node_srvlist($node)
    foreach sublist $::node_bgplist($node) {
	set bgpkey [lindex $sublist 1]
	unset ::bgp_methodslist($bgpkey)
	unset ::bgp_peerslist($bgpkey)
	unset ::bgp_asn($bgpkey)
	unset ::bgp_owner($bgpkey)
	unset ::bgp_descr($bgpkey)
	unset ::bgp_datadir($bgpkey)
    }
    unset ::node_bgplist($node)
       
    set ::activeFileChanged "yes"
}
#
proc NodeAction {  } {
    if { $::activeID !="" } {
	set node [ .canvas itemcget $::activeID -window ]
	if {$node != ""  &&  $::node_action($node) != "" } { 
	    execSrvMenuCmd $::node_action($node) 
	}
    }
}
#
#  add dialog for pregeneration
#
lappend ::GUI_pregenerate_list [list {NodeProperties_GUIconstructor} {Loading Node dialog...}]
#