set SNMPAPI_VERSION 2; set Dm_BuildTime {Tue Mar 23 08:50:28 PST 1999}; set Dm_Version 2.0.0
if ![info exists env(DMPATH)] {set env(DMPATH) [file dirname [file dirname [info nameofexecutable]]]}
if [info exists env(DMOS)] {set bin bin.$env(DMOS)} else {set bin bin}
if {$tcl_platform(os) != "AIX"} {foreach l {dms itcl snmp} {if [catch {load $env(DMPATH)/$bin/$l[info sharedlibextension] $l} err] {wm withdraw .
tk_dialog .err "" "DM failure: $err" error 0 Exit
exit}}}
proc dm_GetNameFromOid {oid} {if [catch {set name [snmpinfo mibprop $oid descriptor]}] {return $oid}
return $name[string range $oid [string length [snmpinfo mibprop $name value]] end]}
proc dm_GetOidFromName {name} {return [snmpinfo mibprop $name value][string range $name [string last . $name] end]}
proc dm_DoAction {sess varlist {prompt ""}} {global Dm_Status Dm_Pref
if {$prompt!=""} {if {[dm_Prompt .ask $prompt Confirm Cancel]==1} return}
if [catch {$sess set null $varlist} err] {dm_Prompt .err [dm_SnmpError err set] Continue} else {set Dm_Status ok}}
proc dm_DoMenu {action class} {global Dm_WinInst Dm_Selection Dm_Status DmDMS
set subClassList ""
if {$Dm_Selection(win)==""} {set sess Sess0
set inst 0} else {set sess [rlindex Dm_WinInst([rlindex Dm_Selection(win) 0]) 2]
if {$DmDMS(Chassis.isStack) == 1} {set sess [lindex [split $sess .] 0]}
foreach s [lsort -integer $Dm_Selection(win)] {lappend inst [rlindex Dm_WinInst($s) 1]
lappend subClassList [lindex [split [rlindex Dm_WinInst($s) 0] ::] 2]}}
dm_Dialog $action [lindex [split $class ::] 0] $inst $subClassList $sess}
proc dm_RequestOpen {dName read write} {global Dm_Pref
if {$Dm_Pref(devName) == $dName} return
dm_Open $dName $read $write}
proc dm_InitDrag {w win} {global Dm_Status Dm_DevName Dm_WinInst DmDMS
if !$DmDMS([lindex [$w itemcget current -tags] 0].isDrag) {return ""}
if {[winfo children $win] == ""} {label $win.l -bd 0
pack $win.l}
$win.l config -image [$w itemcget current -image]
set Dm_Status "Drag over destination window..."
return "$Dm_DevName,[rlindex Dm_WinInst([$w find withtag current]) 1]"}
proc dm_Send {interp win val} {send $interp "dd_Receive $val"
send $interp "drag&drop target $win handle Dm_Component"}
proc dm_DlgOpen {} {global Dm_Pref
if [dm_MakeDlg .opnDlg "Open Device" {
		{Entry "Device Name"} 
		{Entry "Read Community"} 
		{Entry "Write Community"}
	}] return
.opnDlg.f.v0 insert 0 $Dm_Pref(devName)
.opnDlg.f.v1 config -textvariable Dm_Pref(readComm) -show *
.opnDlg.f.v2 config -textvariable Dm_Pref(writeComm) -show *
.opnDlg.fb.ok config -text Open -command {dm_Open [.opnDlg.f.v0 get] $Dm_Pref(readComm) $Dm_Pref(writeComm)
	}
.opnDlg.fb.help config -state normal -command {dm_Help help/dm.html#openDevice}
focus .opnDlg.f.v0}
proc dm_Open {dName readComm writeComm {version 1}} {global DmDMS Dm_ID Dm_Pref Dm_Path Dm_StatusWinList Dm_WinInst Dm_NumSess Dm_PollTimerId Dm_StatusList Dm_Edits Dm_Graphs Dm_Card2Sess Dm_RememberedAttr Dm_Status Dm_PopupMenus tcl_platform
if [winfo exists .chassis] {if [info exists DmDMS(Chassis.closeDeviceProc)] {if {[set ans [$DmDMS(Chassis.closeDeviceProc)]] == -1} return}
catch {after cancel $Dm_PollTimerId}
catch {after cancel $DmDMS(hotswapTimerId)}
catch {destroy .chassis}
catch {pack forget .fC.sbh .fC.sbv}
catch {unset DmDMS}
catch {unset DmsPriv}
catch {unset DmsIdList}
catch {unset Dm_WinInst}
catch {unset Dm_StatusList}
catch {unset Dm_StatusWinList}
catch {unset Dm_RememberedAttr}
catch {unset Dm_PopupMenus}
dm_ClearSelection
set kill 0
foreach m [winfo children .mBar] {if $kill {destroy $m} elseif {$m==".mBar.help"} {set kill 1}}
catch {destroy .mBar.edit.m}
catch {destroy .mBar.graph.m}
pack forget .mBar.edit .mBar.graph
.mBar.file.m entryconfig 4 -state disabled
.mBar.file.m entryconfig 5 -state disabled
if {$tcl_platform(platform) == "unix"} {.mBar.file.m entryconfig 7 -state disabled}
.mBar.help.m entryconfig 1 -state disabled
set kill 0
foreach m [winfo children .tBar] {if $kill {destroy $m} elseif {$m==".tBar.sep"} {set kill 1}}
foreach win [winfo children .] {if {$win == ".opnDlg"} continue
if [winfo exists $win.fBtn.cancel] {$win.fBtn.cancel invoke} elseif [winfo exists $win.fb.cancel] {$win.fb.cancel invoke}}
if [info exists Dm_NumSess] {loop i 0 $Dm_NumSess {Sess$i destroy}}}
set Dm_NumSess 0
dm_BusyCursor .
if [winfo exists .opnDlg] {update idletasks}
if [catch {dm_Connect $dName $readComm $writeComm $version} errMsg] {dm_OpenFail "$dName: $errMsg"
dm_BusyCursor . 0
return}
if [catch {readDMS $Dm_Path/dmdb/$Dm_Pref(dmsFile)} errMsg] {dm_OpenFail $errMsg
Sess0 destroy
dm_BusyCursor . 0
return}
if {[info exists DmDMS(Chassis.snmpVersion)] &&
	    $DmDMS(Chassis.snmpVersion) != $version} {if {$tcl_platform(platform) == "unix"} {Sess0 config -version $DmDMS(Chassis.snmpVersion)} else {Sess0 destroy
if [catch {newsnmp Sess0 $dName -rd $readComm -wr $writeComm -version $DmDMS(Chassis.snmpVersion) -timeout $Dm_Pref(timeout) -retries $Dm_Pref(retries)} err] {error $err}}}
set Dm_NumSess 1
catch {destroy .opnDlg}
set Dm_Pref(devName) $dName
if ![info exists DmDMS(Chassis.isStack)] {set DmDMS(Chassis.isStack) 0}
if [catch {dm_Create .chassis} err] {dm_OpenFail $err}
wm title . "$Dm_Pref(progName) - $dName"
wm iconname . $dName
.mBar.file.m entryconfig 1 -state normal
if [catch {.mBar.file.m.h index $dName}] {.mBar.file.m.h add command -label $dName -command "dm_Open $dName $readComm $writeComm"
if {[.mBar.file.m.h index last]>14} {.mBar.file.m.h delete 0}}
if [info exists DmDMS(Chassis.help)] {.mBar.help.m entryconfig 1 -state normal -command "dm_Help $DmDMS(Chassis.help)"}
dm_CreateEGMenu Dm_Edits edit
dm_CreateSelectMenu .chassis
dm_CreateEGMenu Dm_Graphs graph
catch {unset Dm_Edits Dm_Graphs}
if [info exists DmDMS(Chassis.menubar)] {foreach menu $DmDMS(Chassis.menubar) {set m [rlindex menu 0]
menubutton .mBar.$m -menu .mBar.$m.m -und 0
if {[set mOpt [rlindex menu 1]]!=""} {eval .mBar.$m config $mOpt}
pack .mBar.$m -side left -before .mBar.help
dm_AddMenu .mBar.$m.m $m}}
set i 0
foreach {tip bmap cmd} {
		"Edit Component" edit.gif {dm_Window edit}
        "Graph Component" graph.gif {dm_Window graph}
        "Trap Log" trap.gif {dm_ShowLog .trap}
		"Refresh Display" reload.gif {dm_Rediscover}
        "Telnet" telnet.gif {dm_telnet} } {image create photo imgDMS$i -file $Dm_Path/bitmaps/$bmap
button .tBar.bds$i -image imgDMS$i -text $tip -command $cmd -padx 0 -pady 0
pack .tBar.bds$i -side left
dm_ToolTipBind .tBar.bds$i
incr i}
if [info exists DmDMS(Chassis.toolbar)] {foreach bOpt $DmDMS(Chassis.toolbar) {eval image create photo imgDMS$i -file [rlindex bOpt 3]
eval button .tBar.bds$i [lreplace $bOpt 3 3 imgDMS$i] -padx 0 -pady 0
pack .tBar.bds$i -side left
dm_ToolTipBind .tBar.bds$i
incr i}}
update idletasks
foreach p [info procs *.display] {set DmDMS($p) 1}
foreach p [info procs *.namedisplay] {set DmDMS($p) 1}
if [info exists DmDMS(Chassis.trapProc)] {if [catch {Sess0 register trap $DmDMS(Chassis.trapProc)} err] {set Dm_Status [rlindex err 2]
bell} else {set Dm_Pref(pollFreq) 300
set Dm_Pref(hotswapFreq) 600
if [info exists DmDMS(Chassis.trapRegisterProc)] {if [catch {$DmDMS(Chassis.trapRegisterProc) Sess0} err] {set Dm_Status $err
bell}}}}
if $Dm_Pref(pollFreq) {dm_PollDevice $Dm_Pref(pollFreq)}
if {$Dm_Pref(hotswapFreq) && [info exists DmDMS(Chassis.hotswapProc)]} {eval $DmDMS(Chassis.hotswapProc)}
set Dm_Pref(rtrqos) superlinear
Sess0 config -rtrqos $Dm_Pref(rtrqos)
set Dm_Pref(readComm) $readComm
set Dm_Pref(writeComm) $writeComm
.mBar.file.m entryconfig 4 -state normal
.mBar.file.m entryconfig 5 -state normal
.mBar.file.m entryconfig 7 -state normal
dm_BusyCursor . 0
if [info exists DmDMS(Chassis.endDiscoverProc)] {$DmDMS(Chassis.endDiscoverProc) Sess0}
return 0}
proc dm_Connect {dName readComm writeComm version} {global DmDMS Dm_ID Dm_Pref Dm_Path Dm_SysUpTime Dm_SysUpTimeOrig Dm_Launcher Dm_Pref
if [catch {newsnmp Sess0 $dName -rd $readComm -wr $writeComm -version $version -timeout $Dm_Pref(timeout) -retries $Dm_Pref(retries)} err] {error $err}
if [catch {set resp [Sess0 get null {{1.3.6.1.2.1.1.2.0}  {1.3.6.1.2.1.1.3.0}  {1.3.6.1.2.1.1.1.0}}]} resp] {Sess0 destroy
if {[set reason [rlindex resp 2]] == "timeout"} {error "timeout.  This could be due to:\n\n1: No route to device.\n2: Network is busy (increase timeout).\n3: Invalid read community.\n4: No SNMP agent on device."} else {error "unmanageable ($reason)"}}
set vbl [rlindex resp 4]
set sysObjectId [lindex [rlindex vbl 0] 2]
set DmDMS(sysObjectId) $sysObjectId
set sysDescr [lindex [rlindex vbl 2] 2]
set Dm_SysUpTimeOrig [lindex [rlindex vbl 1] 2]
set Dm_SysUpTime [timeticks clock $Dm_SysUpTimeOrig]
if [info exists Dm_ID($sysObjectId)] {if {[info procs $Dm_ID($sysObjectId)]==""} {set devType $Dm_ID($sysObjectId)} else {if [catch {set devType [$Dm_ID($sysObjectId) $sysObjectId $sysDescr]} errMsg] {Sess0 destroy
error "$errMsg ([snmpinfo mibprop $sysObjectId descriptor])"}
set newmibdir $Dm_Launcher(newmib)
if {$Dm_Launcher(curmib) != $Dm_Launcher(newmib)} {set Dm_Launcher(curmib) $Dm_Launcher(newmib)
if $Dm_Pref(trace) {puts "newmib = $Dm_Launcher(newmib)"}
if {$Dm_Launcher(curmib) != ""} {catch {mibunload}}
if [catch {mibload $Dm_Launcher(curmib)} msg] {error $msg
exit}
foreach pname [info procs *.display] {deleteProc $pname}
foreach pname [info procs *.namedisplay] {deleteProc $pname}
foreach pname [info procs *.modify] {deleteProc $pname}
global Dm_Alias Dm_MibVarDisplay Dm_AgentCap
catch {unset Dm_Alias}
catch {unset Dm_MibVarDisplay}
catch {unset Dm_AgentCap}}}} else {Sess0 destroy
error "unsupported device: $sysDescr"}
set Dm_Pref(dmsFile) $devType}
proc dm_OpenFail {errMsg} {global Dm_Pref
if [winfo exists .opnDlg] {bell
.opnDlg.status config -text $errMsg} else {dm_Prompt .err $errMsg Continue}}
proc dm_Create {w} {global Dm_WinInst DmDMS Dm_Status Dm_Path Dm_PopupMenus Dm_Edits Dm_Graphs Dm_NumSess Dm_StatusList Dm_StatusWinList tcl_platform
canvas $w -bg black
$w xview moveto 0
$w yview moveto 0
lappend Dm_StatusList(Sess0.0) [list sysUpTime 0]
lappend Dm_StatusWinList(Sess0.0) -1
if {$DmDMS(Chassis.isStack) == 1} {if [catch {set resp [Sess0 get null s5ChasGrpEncodeFactor.$DmDMS(Chassis.grpIndx)]} err] {error $err
return}
set DmDMS(encodeFactor) [lindex [lindex [lindex $resp 4] 0] 2]
if [info exists DmDMS(cardInstance)] {set DmDMS(cardInstance) 0}}
set b [$w create image 0 0 -anchor nw -tags Chassis -image [dm_GetImage $DmDMS(Chassis.bitmap)]]
scan [$w bbox $b] "%d%d%d%d" x y width height
$w config -width $width -height $height
dm_NeedScrollbars $w
set DmDMS(Chassis.height) $height
set Dm_WinInst($b) "Chassis 0 Sess0"
dm_RememberAttrs Chassis
if {$DmDMS(Chassis.isStack) == 0} {dm_AddStatusList $w $b Chassis "" 0 Sess0}
if [info exists DmDMS(Chassis.background)] {set bg $DmDMS(Chassis.background)} else {set bg [$w cget -background]}
if [info exists DmDMS(Chassis.children)] {dm_CreateChildren $w $bg Chassis 0 0 0 Sess0}
if [info exists Dm_PopupMenus] {foreach i [array names Dm_PopupMenus] {dm_AddMenu $w.pMenu$i $i $i}}
bind $w <1> {
		catch {
			dm_SelectClick %W [%W find withtag current] %x %y
			set Dm_Status ""
			dm_ItemMark %W %x %y
		}
	}
bind $w <Control-1> {dm_AdjSelect %W [%W find withtag current]}
bind $w <Double-1> {
		# Call doubleClickAction else show edit dialog
		set c [lindex [%W itemcget current -tags] 0]
		if [info exists DmDMS($c.doubleClickAction)] {
			eval $DmDMS($c.doubleClickAction)
		} else {
			dm_Window edit
		}
	}
bind $w <B1-Motion> "dm_ItemStroke $w %x %y"
bind $w <ButtonRelease-1> "dm_ItemsUnderArea $w"
bind $w <ButtonPress-3> "dm_PostMenu $w %X %Y %x %y"
if {[info exists DmDMS(Chassis.maxOidInPDU)] &&
	    [llength $Dm_StatusList(Sess0.0)] > $DmDMS(Chassis.maxOidInPDU)} {while 1 {foreach s [array names Dm_StatusList] {if {[llength $Dm_StatusList($s)] < $DmDMS(Chassis.maxOidInPDU)} return
dm_SplitStatusList $s}}}}
proc dm_CreateChildren {w bg parent xOrig yOrig inst sess} {global Dm_WinInst Dm_Path DmDMS Dm_Card2Sess Dm_Pref Dm_NumSess
foreach c $DmDMS($parent.children) {if [info exists DmDMS($c.discoverProc)] {eval $DmDMS($c.discoverProc) $inst $parent $sess}
if [info exists DmDMS($c.subClassVar)] {set cInst 0
set indexOffset [expr [string length [snmpinfo mibprop $DmDMS($c.subClassVar) value]]+1]
set IPAddressIndex 0
while 1 {set vbl $DmDMS($c.subClassVar).$cInst
if [info exists DmDMS($c.positionVar)] {lappend vbl $DmDMS($c.positionVar).$cInst}
if [info exists DmDMS($c.iPAddress)] {lappend vbl $DmDMS($c.iPAddress).$cInst
set IPAddressIndex [expr [llength $vbl] -1]}
if [catch {set resp [$sess next null $vbl]}] break
set vbl [rlindex resp 4]
set subClass [lindex [rlindex vbl 0] 2]
set cInst [string range [lindex [rlindex vbl 0] 0] $indexOffset end]
if ![info exists DmDMS($c::$subClass.bitmap)] {if [info exists DmDMS($c::?.bitmap)] {set DmDMS($c::$subClass.bitmap) $DmDMS($c::?.bitmap)} else {continue}}
if {$DmDMS($c::$subClass.bitmap)==""} continue
if [info exists DmDMS($c.positionVar)] {set pos [lindex $DmDMS($parent.$c.positions) [lindex [rlindex vbl 1] 2]]} else {set instList [split $cInst .]
set lastInst [rlindex instList [expr [llength $instList]-1]]
incr lastInst -1
set pos [rlindex DmDMS($parent.$c.positions) $lastInst]}
set newSess $sess
if $IPAddressIndex {set addr [lindex [rlindex vbl $IPAddressIndex] 2]
if {$addr == "0.0.0.0"} continue
if [catch {newsnmp Sess$Dm_NumSess $addr  -rc $Dm_Pref(readComm) -wc $Dm_Pref(writeComm)} err] {dm_Prompt .err "$addr: $err" Continue
continue}
set newSess Sess$Dm_NumSess
incr Dm_NumSess
set Dm_Card2Sess($cInst) $newSess}
set x [expr $xOrig+[rlindex pos 0]]
set y [expr $yOrig+[rlindex pos 1]]
dm_RememberAttrs $c ::$subClass
if [string match *.gif $DmDMS($c::$subClass.bitmap)] {set win [$w create image $x $y -anchor nw -tags $c::$subClass -image [dm_GetImage $DmDMS($c::$subClass.bitmap)]]} else {set win [$w create bitmap $x $y -anchor nw -tags $c::$subClass -bitmap @$Dm_Path/dmdb/$DmDMS($c::$subClass.bitmap)]}
set Dm_WinInst($win) "$c::$subClass $cInst $newSess"
dm_AddStatusList $w $win $c ::$subClass $cInst $newSess
if [info exists DmDMS($c::$subClass.children)] {dm_CreateChildren $w $bg $c::$subClass $x $y $cInst $newSess}}} elseif [info exists DmDMS($parent.$c.subClasses)] {set i 0
foreach subClass $DmDMS($parent.$c.subClasses) {if ![info exists DmDMS($c::$subClass.bitmap)] {if [info exists DmDMS($c::?.bitmap)] {set DmDMS($c::$subClass.bitmap) $DmDMS($c::?.bitmap)} else {incr i
continue}}
if {$DmDMS($c::$subClass.bitmap)==""} {incr i
continue}
dm_RememberAttrs $c ::$subClass
scan [rlindex DmDMS($parent.$c.positions) $i] %d%d x y
incr x $xOrig
incr y $yOrig
if [info exists DmDMS($parent.$c.instances)] {set cInst [rlindex DmDMS($parent.$c.instances) $i]
if {$DmDMS(Chassis.isStack) == 1} {if {[info exists DmDMS($c.instanceProc)] && [info exists DmDMS(cardInstance)]} {set cInst [$DmDMS($c.instanceProc) $DmDMS(cardInstance) $cInst]}}} else {set cInst $inst.[expr $i+1]
if [info exists DmDMS($c.instanceProc)] {set cInst [$DmDMS($c.instanceProc) $cInst]}}
if [string match *.gif $DmDMS($c::$subClass.bitmap)] {set win [$w create image $x $y -anchor nw -tags $c::$subClass -image [dm_GetImage $DmDMS($c::$subClass.bitmap)]]} else {set win [$w create bitmap $x $y -anchor nw -tags $c::$subClass -bitmap @$Dm_Path/dmdb/$DmDMS($c::$subClass.bitmap)]}
if {$DmDMS(Chassis.isStack) == 1} {if {$c == "Card"} {scan [$w bbox $win] "%d%d%d%d" x y width height
if {$DmDMS(Chassis.height) < $height} {$w config -height $height
dm_NeedScrollbars $w
set DmDMS(Chassis.height) $height}
set DmDMS(cardInstance) $cInst
set sess Sess0.$cInst
dm_AddStatusList $w $win $c DmDMS(Chassis.Card.statusVar) $cInst $sess}
set oldtag [$w gettags $win]
$w addtag $DmDMS(cardInstance):$oldtag withtag $win}
if {$DmDMS(Chassis.isStack) == 1 && $c == "Card" &&
				[info exists DmDMS(Card.instanceProc)]} {set newInst [$DmDMS($c.instanceProc) $DmDMS(cardInstance) $cInst]
set Dm_WinInst($win) "$c::$subClass $newInst $sess"} else {set Dm_WinInst($win) "$c::$subClass $cInst $sess"}
dm_AddStatusList $w $win $c ::$subClass $cInst $sess
if [info exists DmDMS($c::$subClass.children)] {dm_CreateChildren $w $bg $c::$subClass $x $y $cInst $sess}
incr i}} else {dm_RememberAttrs $c
set i 0
foreach pos $DmDMS($parent.$c.positions) {if ![info exists DmDMS($c.bitmap)] {incr i
continue}
if {$DmDMS($c.bitmap)==""} {incr i
continue}
scan $pos %d%d x y
incr x $xOrig
incr y $yOrig
if [string match *.gif $DmDMS($c.bitmap)] {set win [$w create image $x $y -anchor nw -tags $c -image [dm_GetImage $DmDMS($c.bitmap)]]} else {set win [$w create bitmap $x $y -anchor nw -tags $c -bitmap @$Dm_Path/dmdb/$DmDMS($c.bitmap)]}
if [info exists DmDMS($parent.$c.instances)] {set cInst [rlindex DmDMS($parent.$c.instances) $i]} else {set cInst $inst.[expr $i+1]
if [info exists DmDMS($c.instanceProc)] {set cInst [$DmDMS($c.instanceProc) $cInst]}}
set Dm_WinInst($win) "$c $cInst $sess"
dm_AddStatusList $w $win $c "" $cInst $sess
if [info exists DmDMS($c.children)] {dm_CreateChildren $w $bg $c $x $y $cInst $sess}
incr i}}}}
proc dm_RememberAttrs {c {subClass ""}} {global DmDMS Dm_Edits Dm_Graphs Dm_PopupMenus Dm_RememberedAttr
if [info exists Dm_RememberedAttr($c$subClass)] return
set Dm_RememberedAttr($c$subClass) 1
foreach attr {isDrag isSelect} {if ![info exists DmDMS($c$subClass.$attr)] {if [info exists DmDMS($c.$attr)] {set DmDMS($c$subClass.$attr) $DmDMS($c.$attr)} else {set DmDMS($c$subClass.$attr) 0}}}
foreach attr {statusVar statusProc statusInstanceProc instanceProc menu} {if ![info exists DmDMS($c$subClass.$attr)] {if [info exists DmDMS($c.$attr)] {set DmDMS($c$subClass.$attr) $DmDMS($c.$attr)}}}
if [info exists DmDMS($c.edit)] {set Dm_Edits($c) 1}
if [info exists DmDMS($c.graph)] {set Dm_Graphs($c) 1}
if [info exists DmDMS($c$subClass.menu)] {set Dm_PopupMenus($c$subClass) 1}}
proc dm_AddStatusList {w win c t cInst sess} {global Dm_StatusWinList Dm_StatusList DmDMS
if [info exists DmDMS($c$t.statusVar)] {if [info exists DmDMS($c$t.statusInstanceProc)] {set cInst [$DmDMS($c$t.statusInstanceProc) $cInst]}
if {$DmDMS(Chassis.isStack) == 1} {lappend Dm_StatusList($sess) [list $DmDMS($c$t.statusVar) $cInst]
lappend Dm_StatusWinList($sess) $win} else {lappend Dm_StatusList($sess.0) [list $DmDMS($c$t.statusVar) $cInst]
lappend Dm_StatusWinList($sess.0) $win}}}
proc dm_CreateSelectMenu {w} {global Dm_Edits
.mBar.edit.m add separator
.mBar.edit.m add cascade -label Select -menu .mBar.edit.m.select
menu .mBar.edit.m.select
foreach i [lsort [array names Dm_Edits]] {.mBar.edit.m.select add command -label $i -command "dm_SelectAll $w $i"}}
proc dm_CreateEGMenu {arr menuName} {upvar $arr a
if [info exists a] {menu .mBar.$menuName.m
foreach i [lsort [array names a]] {.mBar.$menuName.m add command -label $i -state disabled -command "dm_DoMenu $menuName $i"}
global DmDMS
if [info exists DmDMS(Chassis.menu$menuName)] {.mBar.$menuName.m add separator
foreach mdef $DmDMS(Chassis.menu$menuName) {eval .mBar.$menuName.m add $mdef
if {[rlindex mdef 0] == "cascade"} {set menu [rlindex mdef 4]
set nLen [llength [set mNames [split $menu .]]]
incr nLen -1
dm_AddMenu $menu [rlindex mNames $nLen]}}}
pack .mBar.$menuName -side left -before .mBar.help
.mBar.$menuName config -state normal}}
proc dm_AddMenu {m obj {title ""}} {global DmDMS
menu $m -disabledforeground black
if {$title!=""} {$m add command -state disabled -background grey}
foreach mDef $DmDMS($obj.menu) {eval $m add $mDef
if {[rlindex mDef 0] == "cascade"} {set menu [rlindex mDef 4]
set nLen [llength [set mNames [split $menu .]]]
incr nLen -1
dm_AddMenu $menu [rlindex mNames $nLen]}}}
proc dm_Rediscover {} {global Dm_WinInst Dm_StatusList Dm_StatusWinList Dm_PollTimerId Dm_Pref Dm_NumSess Dm_Card2Sess Dm_RememberedAttr Dm_PopupMenus Dm_SysUpTime
catch {after cancel $Dm_PollTimerId}
catch {unset Dm_WinInst}
catch {unset Dm_Card2Sess}
catch {unset Dm_StatusList}
catch {unset Dm_StatusWinList}
loop i 1 $Dm_NumSess {Sess$i destroy}
set Dm_NumSess 1
catch {destroy .chassis}
dm_Create .chassis
if $Dm_Pref(pollFreq) {dm_PollDevice $Dm_Pref(pollFreq)} else {dm_GetStatus}}
proc dm_GetImage {file} {global Dm_ImageCache Dm_Path
if [info exists Dm_ImageCache($file)] {return $Dm_ImageCache($file)}
set Dm_ImageCache($file) [image create photo $file -file $Dm_Path/dmdb/$file]}
proc dm_DelCache {} {global Dm_ImageCache
foreach i [array names Dm_ImageCache] {catch {image delete $i}}}
proc dm_telnet {} {global Dm_Pref
if [catch {eval exec $Dm_Pref(telnet) $Dm_Pref(devName) &} err] {dm_Prompt .err $err Continue}}
proc dm_ShowPref {} {global Dm_Pref Dm_Temp Dm_Radio tcl_platform
set w .prpsDlg
set Dm_Temp(pollFreq) $Dm_Pref(pollFreq)
set Dm_Temp(retries) $Dm_Pref(retries)
set Dm_Temp(timeout) $Dm_Pref(timeout)
set Dm_Temp(hotswapFreq) $Dm_Pref(hotswapFreq)
set Dm_Temp(trapLogSize) $Dm_Pref(trapLogSize)
set fields {
		{Radio "Status Poll Enable" {false true}}
		{Spin "Status Poll Interval" 0 Dm_Temp(pollFreq) 600 secs}
		{Spin "Retry Count" 1 Dm_Temp(retries) 5}
		{Spin "Timeout" 1 Dm_Temp(timeout) 20 secs}
		{Radio "Retransmission\nStrategy" {linear superlinear} 1}
		{Spin "Hotswap Poll Interval" 10 Dm_Temp(hotswapFreq) 6000 secs} 
		{Spin "Max Traps in Log" 10 Dm_Temp(trapLogSize) 2000}
		{Radio "Display Hostnames As" {"IP Address" "DNS Name"} 1}
		{Radio "Display SNMP Errors In" {"Status area" "Error window"} 1}
		{Radio "Click Table Header to" {"select" "sort"}}
	}
if {$tcl_platform(platform) == "unix"} {lappend fields {Radio "SNMP Trace PDU" {none out in both} 2}
set Dm_Radio($w.f.v10) $Dm_Pref(debug)}
if [dm_MakeDlg $w "Properties" $fields] return
if $Dm_Pref(pollFreq) {set Dm_Radio($w.f.v0) 1} else {set Dm_Radio($w.f.v0) 0}
set Dm_Temp(rtrqos) $Dm_Pref(rtrqos)
$w.f.v4.r0 config -value linear -variable Dm_Temp(rtrqos)
$w.f.v4.r1 config -value superlinear -variable Dm_Temp(rtrqos)
foreach {var fNo} {showDNSName 7 promptSNMPError 8 tableSort 9} {eval set Dm_Temp($var) $Dm_Pref($var)
eval $w.f.v$fNo.r0 config -variable Dm_Temp($var)
eval $w.f.v$fNo.r1 config -variable Dm_Temp($var)}
$w.fb.ok config -command "dm_ApplyPref $w"
$w.fb.help config -state normal -command {dm_Help help/dm.html#pref}
pack [button $w.fb.save -text Save -command "dm_SavePref $w"] -after $w.fb.ok -side left
raise $w.fb.save $w.fb.ok
focus $w.f.v0.r0}
proc dm_ApplyPref {w} {global Dm_Pref Dm_Temp Dm_Status Dm_PollTimerId Dm_Radio tcl_platform
set Dm_Pref(retries) [$w.f.v2 get]
set Dm_Pref(timeout) [$w.f.v3 get]
set Dm_Pref(hotswapFreq) [$w.f.v5 get]
set Dm_Pref(trapLogSize) [$w.f.v6 get]
set Dm_Pref(showDNSName) [$w.f.v6 get]
set Dm_Pref(rtrqos) $Dm_Temp(rtrqos)
set Dm_Pref(showDNSName) $Dm_Temp(showDNSName)
set Dm_Pref(promptSNMPError) $Dm_Temp(promptSNMPError)
set Dm_Pref(tableSort) $Dm_Temp(tableSort)
if {[info commands Sess0] == "Sess0"} {if {$tcl_platform(platform) == "unix"} {set Dm_Pref(debug) $Dm_Radio($w.f.v10)
Sess0 config -debug $Dm_Pref(debug)}
if {$Dm_Radio($w.f.v0) == 0} {set tmpPollFreq 0} else {if {$Dm_Temp(pollFreq) == 0 && [$w.f.v1 get] == 0} {$w.f.v1 delete 0 end
set tmpPollFreq [expr $Dm_Pref(retries)*$Dm_Pref(timeout)]
$w.f.v1 insert 0 $tmpPollFreq} else {set tmpPollFreq [$w.f.v1 get]}}
if {$tmpPollFreq != $Dm_Pref(pollFreq)} {if $tmpPollFreq {set delay [expr $Dm_Pref(retries)*$Dm_Pref(timeout)]
if {$tmpPollFreq < $delay} {$w.status config -text "Poll frequency must be >= (retries x timeouts)"
bell
return}}
catch {
				if {$Dm_PollTimerId!=0} {
					after cancel $Dm_PollTimerId
					set Dm_PollTimerId 0
				}
			}
set Dm_Pref(pollFreq) $tmpPollFreq
if $Dm_Pref(pollFreq) {dm_PollDevice $Dm_Pref(pollFreq)} else {set Dm_Status "Polling stopped"}} else {set Dm_Pref(pollFreq) $tmpPollFreq}
Sess0 config -timeout $Dm_Pref(timeout) -retries $Dm_Pref(retries) -rtrqos $Dm_Pref(rtrqos)}
destroy $w}
proc dm_SavePref {w} {global env Dm_Pref Dm_Status
dm_ApplyPref $w
if [winfo exists $w] return
if [catch {set fd [open $env(HOME)/.dmrc w]} err] {dm_Prompt .err $err Continue}
foreach opt {pollFreq hotswapFreq retries timeout rtrqos debug trapLogSize
		showDNSName promptSNMPError tableSort} {catch {puts $fd "set Dm_Pref($opt) $Dm_Pref($opt)"}}
close $fd
catch {chmod $env(HOME)/.dmrc 666}
set Dm_Status saved}
proc dm_Dialog {action class {instance 0} {subClass ""} {sess Sess0} {w ""} {catNo -1}} {global DmDMS Dm_Status Dm_Pref
if ![info exists DmDMS($class.$action)] {bell
set Dm_Status "$class has nothing to $action"
return}
set type DM$action
if {$w == ""} {if {$type == "DMedit"} {set w ed$class} else {set w gr$class}}
if {[llength $instance] > 1} {append w T
if {$type == "DMedit"} {set type DMeditMultiple} else {set type DMgraphMultiple}
if [winfo exists .$w] {raise .$w
bell
return}} elseif {$type == "DMgraph"} {set type DMgraphSingle}
if [winfo exists .$w] {$w configure -GlobInst $instance -SubClass $subClass -sess $sess
if {$catNo != -1} {$w configure -CatNo $catNo
$w display} else {$w updateIndex $instance
$w goto}
raise .$w} else {if {$catNo == -1} {set catNo 0}
$type $w -Component $class -SubClass $subClass -GlobInst $instance -sess $sess -CatNo $catNo
$w display}}
class DMwindow {constructor {args} {global DmDMS Dm_InitDialog Dm_Pref
if ![info exists Dm_InitDialog] dm_InitDMwindow
eval configure $args
set This [toplevel .[info namespace tail $this]]
wm transient $This .
wm protocol $This WM_DELETE_WINDOW "$This.fBtn.cancel invoke"
wm geom $This "+[winfo pointerx .]+[winfo pointery .]"
wm withdraw $This
$this parseOpt
frame $This.nb -bd 0
set NumCat [llength $DmDMS($Component.$Op)]
set maxHeight 0
loop i 0 $NumCat {if {[info exists NeedSubClass($i)] && [lsearch $SubClass $NeedSubClass($i)] == -1} continue
button $This.nb.fCat$i -text $Title($i) -highlightthickness 1 -padx 2 -font $Dm_Pref(normalFont) -command "$this clickTab $i"
pack $This.nb.fCat$i -side left -fill y -expand 1
if {[set height [winfo reqheight $This.nb.fCat$i]] > $maxHeight} {set maxHeight $height}}
pack $This.nb -anchor w
frame $This.blank -height 4 -highlightthickness 0
$This.blank config -width [expr [winfo reqwidth $This.nb.fCat0]-4]
incr maxHeight -2
place $This.blank -x 2 -y $maxHeight
$this createIndex
frame $This.fBtn -class FBtn
button $This.fBtn.cancel -command "delete object $this"
bind $This <Escape> "$This.fBtn.cancel invoke"
button $This.fBtn.help
pack $This.fBtn.cancel $This.fBtn.help -side left
pack $This.fBtn -pady 5
label $This.status -bd 0 -foreground red
pack $This.status -anchor w
bind $This <F10> break}
destructor {destroy $This}
method display {} {global Dm_Pref DmDMS
$this setCatState
if [winfo exists $This.fIndex] {$this updateIndex $GlobInst}
$this invokeTab $CatNo
raise $This.blank
if {[info exists DmDMS($Component.indexNames)] || $GlobInst==0 || $Multiple} {wm title $This "($Dm_Pref(devName)) - $Op $Component"} else {wm title $This "($Dm_Pref(devName)) - $Op $Component $GlobInst"}
dm_OnScreen $This}
method parseOpt {} {global DmDMS
set j 0
foreach a $DmDMS($Component.$Op) {set Title($j) ""
set Prefix($j) ""
set opt [rlindex a 0]
loop i 0 [llength $opt] {switch -- [rlindex opt $i] {-title {incr i; set Title($j) [rlindex opt $i]}
-help {incr i; set Help($j) [rlindex opt $i]}
-prefix {incr i; set Prefix($j) [rlindex opt $i]}
-use? {incr i; set IsUse($j) [rlindex opt $i]}
-useProc? {incr i; set IsUseProc($j) [rlindex opt $i]}
-cvtProc {incr i; set CvtProc($j) [rlindex opt $i]}
-custom {incr i; set Custom($j) [rlindex opt $i]}
-table {set Table($j) 1}
-rotate {set Rotate($j) 1}
-noMultiple {set NoMultiple($j) 1}
-showTableIndex {set ShowTableIndex($j) 1}
-list {incr i; set List($j) [rlindex opt $i]}
-bulk {incr i; set Bulk($j) [rlindex opt $i]}
-insert {incr i; set Insert($j) [rlindex opt $i]}
-insertCB {incr i; set InsertCB($j) [rlindex opt $i]}
-augmentInsert {incr i; set AugmentInsert($j) [rlindex opt $i]}
-delete {incr i; set Delete($j) [rlindex opt $i]}
-buildCB {incr i; set BuildCB($j) [rlindex opt $i]}
-getCB {incr i; set GetCB($j) [rlindex opt $i]}
-needSubClass {incr i; set NeedSubClass($j) [rlindex opt $i]}
-aggregrateList {incr i; set AggregList($j) [rlindex opt $i]}
-startIndexProc {incr i; set StartIndexProc($j) [rlindex opt $i]}
-stopIndexProc {incr i; set StopIndexProc($j) [rlindex opt $i]}
-grOption {incr i; set GrOption($j) [rlindex opt $i]}
-buttons {incr i; set Buttons($j) [rlindex opt $i]}
-enumRules {incr i; set EnumRules($j) [rlindex opt $i]}}}
incr j}}
method createIndex {} {global DmDMS
if ![info exists DmDMS($Component.indexNames)] return
frame $This.fIndex -class FIndex
set i 0
foreach name $DmDMS($Component.indexNames) {label $This.fIndex.l$i -text $name
entry $This.fIndex.e$i -width 5
bind $This.fIndex.e$i <Return> "$this goto"
pack $This.fIndex.l$i $This.fIndex.e$i -side left
incr i}
pack $This.fIndex -anchor w -fill x}
method updateIndex {instance} {global DmDMS
if [info exists DmDMS($Component.indexNamesProc)] {$This.fIndex.e0 delete 0 end
$This.fIndex.e0 insert 0 [$DmDMS($Component.indexNamesProc) $instance 1]} else {set i 0
foreach inst [split $instance .] {if ![winfo exists $This.fIndex.e$i] break
$This.fIndex.e$i delete 0 end
$This.fIndex.e$i insert 0 $inst
incr i}}}
method goto {} {global DmDMS
if [info exists DmDMS($Component.indexNamesProc)] {set GlobInst [$DmDMS($Component.indexNamesProc) [$This.fIndex.e0 get] 0]} else {for {set i 0} {[winfo exists $This.fIndex.e$i]} {incr i} {doCheck $This.fIndex.e$i
if $i {append GlobInst .[$This.fIndex.e$i get]} else {set GlobInst [$This.fIndex.e$i get]}}}
$this setCatState
if {[$This.nb.fCat$CatNo cget -state] == "disabled"} {clickTab 0} else {set CatInst [$this cvtInst]
$this get $CatInst}}
method clickTab {catNo} {if {$CurrentActive == $catNo} return
set w $This.nb.fCat$catNo
$w config -cursor watch
update idletasks
$this invokeTab $catNo
scan [winfo geometry $w] %dx%d+%d width height x
incr width -4
incr height -2
incr x 2
$This.blank config -width $width
place $This.blank -x $x -y $height
raise $This.blank
$w config -cursor {}}
method invokeTab {catNo} {set CatNo $catNo
if $Multiple {set CatInst {}
foreach i $GlobInst {if [info exists CvtProc($catNo)] {lappend CatInst [$CvtProc($catNo) $i]} else {lappend CatInst $i}}} else {set CatInst [$this cvtInst]}
$This.status config -text ""
if {$CurrentActive != -1} {pack forget $This.fCat$CurrentActive}
$this showCat
set CurrentActive $catNo}
method showCat {} {if [info exists Help($CatNo)] {$This.fBtn.help config -state normal -command "dm_Help $Help($CatNo)"} else {$This.fBtn.help config -state disabled}
focus $This.fBtn.cancel}
method cvtInst {{catNo -1}} {if {$catNo == -1} {set catNo $CatNo}
if [info exists CvtProc($catNo)] {return [$CvtProc($catNo) $GlobInst]}
return $GlobInst}
method setCatState {} {global DmDMS
loop i 0 $NumCat {if {!$Multiple && [info exists IsUse($i)]} {lappend vbl [list $IsUse($i) [$this cvtInst $i]]}
incr i}
if [info exists vbl] {if [catch {set values [$sess expr null $vbl]} err] {loop i 0 [llength $vbl] {lappend values 0}} else {set values [rlindex values 4]}
set exprIndex 0}
loop i 0 $NumCat {set catState normal
if $Multiple {if {[info exists Table($i)] || [info exists Custom($i)] || [info exists NoMultiple($i)]} {pack forget $This.nb.fCat$i
continue}} else {if [info exists IsUse($i)] {if {[rlindex values $exprIndex] == 0} {set catState disabled}
incr exprIndex} elseif [info exists IsUseProc($i)] {if {[$IsUseProc($i) $GlobInst $sess] == 0} {set catState disabled}}}
$This.nb.fCat$i config -state $catState}}
method error {msg {bell 1}} {$This.status config -text $msg
if $bell bell}
public variable sess
public variable GlobInst 0
public variable CatInst
public variable Component
public variable SubClass ""
public variable Op
public variable Multiple 0
public variable CatNo 0
protected variable This
protected variable NumCat
protected variable CurrentActive -1
protected variable TableName
protected variable IsUse
protected variable IsUseProc
protected variable NeedSubClass
protected variable CvtProc
protected variable Title
protected variable Rotate
protected variable Help
protected variable Table
protected variable NoMultiple
protected variable ShowTableIndex
protected variable Bulk
protected variable Custom
protected variable Insert
protected variable InsertCB
protected variable AugmentInsert
protected variable Delete
protected variable Prefix
protected variable BuildCB
protected variable GetCB
protected variable AggregList
protected variable StartIndexProc
protected variable StopIndexProc
protected variable GrOption
protected variable Buttons
protected variable EnumRules
protected variable List}
proc dm_InitDMwindow {} {global Dm_InitDialog Dm_Pref env tk_library blt_library tcl_platform
set Dm_InitDialog 1
if {$tcl_platform(os) != "AIX"} {if [info exists env(DMOS)] {set bin bin.$env(DMOS)} else {set bin bin}
foreach l {blt tkTable} {if [catch {load $env(DMPATH)/$bin/$l[info sharedlibextension] $l} err] {dm_Prompt .err $err Exit}}}
set blt_library $tk_library
source $tk_library/tkTable.tcl
rename tkEntryInsert _tkEntryInsert
rename tkEntryBackspace _tkEntryBackspace
proc tkEntryInsert {w s} {_tkEntryInsert $w $s
if {$s != ""} {dm_ShowChange $w}}
proc tkEntryBackspace {w} {_tkEntryBackspace $w
dm_ShowChange $w}
bind Entry <Delete> {
		if [%W selection present] {
			%W delete sel.first sel.last
		} else {
			%W delete insert
		}
		dm_ShowChange %W
	}
proc dm_ShowChange {w} {set top [winfo toplevel $w]
if [winfo exists $top.fBtn.apply] {global Dm_Pref
$w config -font $Dm_Pref(changeFont)
$top.fBtn.apply config -state normal}}
dm_InitGraph
rename dm_InitGraph ""}
proc dm_SnmpError {error {cmd ""}} {upvar $error err
if {$cmd == "set" && [rlindex err 2] == "timeout"} {return "timeout (possible invalid write community)"}
if {[set i [rlindex err 3]] <= 0} {return [rlindex err 2]}
incr i -1
set name [lindex [lindex [rlindex err 4] $i] 0]
catch {set name [dm_GetNameFromOid $name]}
return "[rlindex err 2] ($name)"}
proc dm_displayError {w msg} {global Dm_Pref
if $Dm_Pref(promptSNMPError) {dm_Prompt .err $msg Continue} else {$w.status config -text $msg
bell}}
class DMedit {inherit DMwindow
constructor {args} {set Op edit
eval DMwindow::constructor $args} {
		global Dm_Path
		# Create edit buttons (but don't display them until needed)
		foreach b {insert remove apply refresh} {
			button $This.fBtn.$b -command "$this $b"
		}
		menubutton $This.fBtn.other -bitmap @$Dm_Path/bitmaps/pulldown.xbm -takefocus 1 -highlightthickness 1 -relief raised -menu $This.fBtn.other.m
		menu $This.fBtn.other.m
		foreach {label cmd} {Stop stop Replicate replicate Export... save} {
			$This.fBtn.other.m add command -label $label -command "$this $cmd"
		}
		# Lower buttons in tab order. XXX Doesn't work!
		#lower $This.fBtn.cancel
		#lower $This.fBtn.help
	}
destructor {foreach w [winfo children .] {if [string match $This*-Ins $w] {destroy $w}}
loop i 0 $NumCat {if [info exists TableName($i)] {catch {upvar #0 $TableName($i) tab; unset tab}
delete object ::DMedit$this.fCat$i}}}
method showCat {} {if ![winfo exists $This.fCat$CatNo] {if [info exists Custom($CatNo)] {eval $Custom($CatNo) $This.fCat$CatNo {$CatInst} $sess} else {$this build $This.fCat$CatNo}
$this get $CatInst
if [info exists Buttons($CatNo)] {set i 0
foreach b $Buttons($CatNo) {lappend CustomButtons($CatNo) [eval button $This.fBtn.b$CatNo$i $b]
incr i}}} else {if {!$Multiple && $CatLastInst($CatNo) != $CatInst} {$this get $CatInst}}
eval pack forget [winfo children $This.fBtn]
if [info exists CustomButtons($CatNo)] {eval lappend btnList $CustomButtons($CatNo)}
if [info exists Insert($CatNo)] {lappend btnList $This.fBtn.insert}
if [info exists Delete($CatNo)] {lappend btnList $This.fBtn.remove}
$This.fBtn.other.m entryconfig 1 -state disabled
if [info exists Modify($CatNo)] {lappend btnList $This.fBtn.apply
$This.fBtn.apply config -state disabled
$This.fBtn.other.m entryconfig 1 -state normal
if {$Multiple || [info exists Table($CatNo)]} {$This.fBtn.other.m entryconfig 1 -state normal}}
lappend btnList $This.fBtn.refresh $This.fBtn.cancel $This.fBtn.help
if {$Multiple || [info exists Table($CatNo)]} {lappend btnList $This.fBtn.other
set packOpt ""} else {set packOpt "-ipadx 4 -ipady 4"}
eval pack $btnList -side left
DMwindow::showCat
eval pack $This.fCat$CatNo -after $This.nb -fill both -expand 1 $packOpt}
method build {frm} {if [info exists Table($CatNo)] {set TableName($CatNo) Dm_Edit$Component$CatNo
$this buildTable $frm [info exists ShowTableIndex($CatNo)]} else {$this buildForm $frm}
if [info exists BuildCB($CatNo)] {$BuildCB($CatNo) $frm $CatInst $sess false}}
method buildTable {frm colt {numRows -1}} {global DmDMS Dm_AgentCap
upvar #0 $TableName($CatNo) tab
set numCols [llength [lindex [rlindex DmDMS($Component.edit) $CatNo] 1]]
incr numCols $colt
incr numRows 1
set tabInstance [string range $frm 1 end]
DMtableEdit $tabInstance -Table $TableName($CatNo) -Colt $colt -NumRows $numRows -NumCols $numCols
set col 0
foreach l [lindex [rlindex DmDMS($Component.edit) $CatNo] 1] {if [string match *.* $l] {scan [split $l .] %s%s l instProc}
if {$l == "separator"} continue
set enum [dm_GetEnums $l]
set tab(-2,$col) "$l \{$enum\}"
if {[set access [dm_GetACCESS $l]] == "read-write"} {set Modify($CatNo) 1
if {[info exists Dm_AgentCap($l.TYPE)] && $Dm_AgentCap($l.TYPE) == "BitSet"} {set isBitSet 1} else {set isBitSet 0}
$frm.t tag coltag editable $col
if {$enum != ""} {$frm.t tag coltag option $col
menu $frm.mb.m$col
set i 0
foreach e $enum {if {[rlindex e 1] == "none" && [rlindex e 0] == 0} continue
set menuVal [rlindex e 1]
if $isBitSet {$frm.mb.m$col add checkbutton -label $menuVal -onvalue [rlindex e 0] -var Dm_Radio($frm.mb.m$col.$i) -command "::DMedit::$tabInstance menuBitSet $frm.mb.m$col"} else {$frm.mb.m$col add radiobutton -label $menuVal -command "::DMedit::$tabInstance menuSet $menuVal"}
incr i}} elseif {[dm_GetTYPE $l] == "PortSet"} {$frm.t tag coltag popup $col
::DMedit::$tabInstance setPopupCmd $col "dm_BuildPromptPort $frm.t $col"} elseif [info exists Dm_MibVarDisplay($l.pulldown)] {$frm.t tag coltag option $col
menu $frm.mb.m$col}}
set tab(-1,$col) [set l [dm_GetAlias $l $Prefix($CatNo)]]
incr col}
if [info exists Modify($CatNo)] {bind $frm.t <Return> "tkTableMoveCell $frm.t 1 0; $This.fBtn.apply invoke; break"} else {$frm.t config -state disabled}}
method buildForm {frm {insertVars ""}} {global Dm_Pref Dm_Radio DmDMS Dm_AgentCap Dm_Path Dm_MibVarDisplay
if {$insertVars == ""} {set varList [lindex [rlindex DmDMS($Component.edit) $CatNo] 1]
set editTest {$access=="read-write"}
frame $frm -bd 1 -relief raised} else {upvar $insertVars varList
set editTest {$access=="read-write" || $access == "read-create" || [snmpinfo mibprop $m property IsINDEX]}}
set i 0
set r 0
foreach m $varList {if [string match *.* $m] {scan [split $m .] %s%s m instProc} elseif {$m == {separator}} {frame $frm.sep$i -bd 1 -height 2 -relief sunken
grid $frm.sep$i -column 0 -row $r -columnspan 2 -sticky ew -pady 4 -padx 8
incr r
continue}
label $frm.l$i -text "[dm_GetAlias $m $Prefix($CatNo)]:"
grid $frm.l$i -row $r -column 0 -sticky e -padx 2
set access [dm_GetACCESS $m]
set sticky w
if {[set enum [dm_GetEnums $m]]==""} {if [expr $editTest] {set Modify($CatNo) 1
entry $frm.v$i
if {[set range [snmpinfo mibprop $m range]]!="" ||
						[info exists Dm_AgentCap($m.UNITS)]} {set lab ""
set width 8
if {$range != ""} {set min [rlindex range 0]
set max [rlindex range 1]
set lab "$min..$max"
bind $frm.v$i <FocusOut> "doCheck %W $min $max"
set width [expr [string length $max]+1]}
if [info exists Dm_AgentCap($m.UNITS)] {append lab " ($Dm_AgentCap($m.UNITS))"}
frame $frm.f$i
label $frm.f$i.l -text $lab
pack $frm.v$i -in $frm.f$i -side left
pack $frm.f$i.l -side left
grid $frm.f$i -row $r -column 1 -sticky ew
$frm.v$i config -width $width
raise $frm.v$i
if [info exists Dm_MibVarDisplay($m.pulldown)] {menubutton $frm.f$i.mb -bitmap @$Dm_Path/bitmaps/pulldown.xbm -takefocus 1 -highlightthickness 1 -relief raised -menu $frm.f$i.mb.m
menu $frm.f$i.mb.m
pack $frm.f$i.mb -side left}
incr i
incr r
continue} else {set vType [dm_GetTYPE $m]
if {$vType == "PortSet"} {dm_CreatePortPicker $frm.f$i
grid $frm.f$i -row $r -column 1 -sticky w -padx 2
incr i
incr r
continue} elseif {$vType == "InterfaceIndex"} {frame $frm.f$i
$frm.v$i config -width 6
button $frm.f$i.b -bitmap @$Dm_Path/bitmaps/pulldown.xbm -command "$this promptIfIndex $frm.v$i"
pack $frm.v$i -in $frm.f$i -side left
pack $frm.f$i.b -side left
grid $frm.f$i -row $r -column 1 -sticky ew -padx 2
raise $frm.v$i
incr i
incr r
continue} else {set type [snmpinfo mibprop $m property SYNTAX]
if {$type == "Integer32"} {$frm.v$i config -width 10
bind $frm.v$i <FocusOut> {doCheck %W}} elseif {$type == "IpAddress"} {bind $frm.v$i <FocusOut> {doCheckIPAddr %W}} elseif {[dm_GetTYPE $m] == "MacAddress"} {bind $frm.v$i <FocusOut> {doCheckMacAddr %W}} else {set sticky ew}}}} else {label $frm.v$i -anchor w -justify left}} else {if {[info exists Dm_AgentCap($m.TYPE)] && $Dm_AgentCap($m.TYPE) == "BitSet"} {set isBitSet 1
set frameClass FBitSet} else {set isBitSet 0
set frameClass FRadio}
if [expr $editTest] {frame $frm.v$i -class $frameClass
if [info exists Dm_MibVarDisplay($m.grid)] {set max $Dm_MibVarDisplay($m.grid)} else {set max 3}
set j 0
foreach e $enum {if {[rlindex e 1] == "none" && [rlindex e 0] == 0} continue
if $isBitSet {checkbutton $frm.v$i.r$j -text [rlindex e 1] -on [rlindex e 0] -var Dm_Radio($frm.v$i.r$j)} else {radiobutton $frm.v$i.r$j -text [rlindex e 1] -value [rlindex e 0] -var Dm_Radio($frm.v$i)}
bind $frm.v$i.r$j <1> "dm_RadioSet $frm.v$i %W"
bind $frm.v$i.r$j <space> "dm_RadioSet $frm.v$i %W"
grid $frm.v$i.r$j -row [expr $j/$max] -column [expr $j%$max] -sticky w
incr j}
set Modify($CatNo) 1} else {set m $frm.v$i.m
menubutton $frm.v$i -anchor w -padx 0 -pady 0 -menu $m -font $Dm_Pref(normalFont)
bind $frm.v$i <1> break
menu $m
foreach e $enum {$m add radiobutton -label [rlindex e 1] -value [rlindex e 0]}}}
grid $frm.v$i -row $r -column 1 -sticky $sticky -padx 2
incr i
incr r}
bind $This <Return> "$This.fBtn.apply invoke"
if {[info exists EnumRules($CatNo)]} {foreach {enumVar rule} $EnumRules($CatNo) {set enumVarFieldNo [lsearch $varList $enumVar]
foreach {val action} $rule {set radioNo 0
foreach enum [dm_GetEnums $enumVar] {if {[rlindex enum 1] == $val} break
if {[rlindex enum 1] == "none" && [rlindex enum 0] == 0} continue
incr radioNo}
if ![winfo exists $frm.v$enumVarFieldNo.r$radioNo] continue
set command "{"
foreach {opt targetVars} $action {if {$opt == "disabled"} {set labelState "-fg gray"
set valueState "-state disabled"} else {set labelState "-fg black"
set valueState "-state normal"}
foreach targetVar $targetVars {set fNo [lsearch $varList $targetVar]
append command "$frm.l$fNo config $labelState; "
if {[winfo class $frm.v$fNo] == "FRadio"} {append command "dm_enableFrame $frm.v$fNo $opt; "} else {if {[winfo class $frm.v$fNo] == "Entry" &&  $valueState == "-state disabled"} {append command "$frm.v$fNo delete 0 end; "}
append command "$frm.v$fNo config $valueState; "}}}
append command "}"
eval $frm.v$enumVarFieldNo.r$radioNo config -command $command}}}
grid columnconfig $frm 1 -weight 1}
method get {{inst ""}} {global DmDMS Dm_Pref
if {$inst==""} {set inst $CatInst}
if [info exists Custom($CatNo)] {eval $Custom($CatNo) $This.fCat$CatNo {$CatInst} $sess} elseif [info exists Table($CatNo)] {set table Dm_Edit$Component$CatNo
upvar #0 $table tab
set t $This.fCat$CatNo.t
if {[set editList [$t tag celltag edited]]!={}} {foreach e $editList {$t tag celltag {} $e}}
if [info exists StartIndexProc($CatNo)] {set i [$StartIndexProc($CatNo) $inst $sess]} else {set i ""}
foreach l [lindex [rlindex DmDMS($Component.edit) $CatNo] 1] {if ![info exists firstVar] {set firstVar $l}
lappend vbl $l.$i}
set firstVar [snmpinfo mibprop $firstVar value]
set indexOffset [expr [string length $firstVar]+1]
if {$DmDMS(Chassis.snmpVersion) == 2 && [info exists Bulk($CatNo)]} {if [catch {set rc [$sess get null $Bulk($CatNo)]} err] {dm_displayError $This [dm_SnmpError err]
set CatLastInst($CatNo) $inst
return}
if ![set numRows [lindex [lindex [rlindex rc 4] 0] 2]] {$This.fCat$CatNo.t config -rows 1
$This.fCat$CatNo.t bestfit
$This.status config -text "0 row(s)"} else {set rowLen [llength $vbl]
$sess config -maxrept $numRows
if [catch {$sess bulkvar "$this getBulkTableCB $firstVar $rowLen $indexOffset $numRows -1 $table" $vbl} err] {dm_displayError $This [dm_SnmpError err]} else {$This.status config -text "Asking for $numRows row(s)..."
$This.fBtn.other.m entryconfig 0 -state normal}}} else {if [catch {$sess next "$this getTableCB $indexOffset 0 $table" $vbl} err] {dm_displayError $This [dm_SnmpError err]} else {$This.status config -text "Reading..."
$This.fBtn.other.m entryconfig 0 -state normal}}} else {foreach var [lindex [rlindex DmDMS($Component.edit) $CatNo] 1] {if [string match *.* $var] {scan [split $var .] %s%s var instProc
if {[info proc $instProc] != ""} {lappend vbl $var.[eval $instProc $inst]} else {lappend vbl $var.$instProc}} elseif {$var != "separator"} {lappend vbl $var.$inst}}
if [catch {$sess get "$this getFormCB" $vbl} err] {dm_displayError $This [dm_SnmpError err]}}
set CatLastInst($CatNo) $inst}
method getFormCB {sess reqid errStat errIdx vbl} {if ![winfo exists $This] return
global DmDMS Dm_Radio Dm_Pref
if {$errStat != "noError"} {if $errIdx {incr errIdx -1
$This.fCat$CatNo.l$errIdx config -fg red
$this error "[$This.fCat$CatNo.l$errIdx cget -text] $errStat"} else {$this error $errStat}
return}
$This.status config -text ""
set win $This.fCat$CatNo
set fg [$This.fBtn.help cget -fg]
set i 0
foreach vb $vbl {if [string match noSuch* [set val [rlindex vb 2]]] {$This.fCat$CatNo.l$i config -fg red} else {if {[$This.fCat$CatNo.l$i cget -fg] == "red"} {$This.fCat$CatNo.l$i config -fg $fg}
set var [snmpinfo mibprop [rlindex vb 0] descriptor]
if [info exists DmDMS($var.display)] {set val [$var.display $val]}}
switch [winfo class $win.v$i] {
			Entry {
					$win.v$i config -font $Dm_Pref(normalFont)
					$win.v$i delete 0 end
					if {[dm_GetTYPE $var] == "PortSet"} {
						dm_PortSetDisplay $win.f$i $val
					} else {
						$win.v$i insert 0 $val
					}
				}
			Label {$win.v$i config -text $val}
			Menubutton {dm_SetROEnum $win.v$i $val}
			FRadio {dm_SetRWEnum $win.v$i $val}
			FCheck {dm_SetBitSet $win.v$i $val}
			}
incr i}
if [info exists GetCB($CatNo)] {eval $GetCB($CatNo) $win $CatInst $sess}}
method getTableCB {indexOffset numRows table sess reqid errStat errIdx vbl} {if ![winfo exists $This] return
if [info exists Stop($table)] {set errStat stopped}
if {$errStat == "noError"} {upvar $table tab
if {[lindex [set vb [rlindex vbl 0]] 1] == "endOfMibView"} {set errStat end} else {set newInst [string range [rlindex vb 0] $indexOffset end]
if [info exists StopIndexProc($CatNo)] {if [$StopIndexProc($CatNo) $GlobInst $newInst $sess] {set errStat end}}}}
if {$errStat != "noError"} {set msg "$numRows row(s)"
if {$errStat != "end"} {bell
append msg " ($errStat)"}
$This.status config -text $msg
resetStop
$This.fCat$CatNo.t config -rows [incr numRows]
$This.fCat$CatNo.t bestfit
::DMtable::needScrollbars $This.fCat$CatNo.t
return}
set tab($numRows,-1) $newInst
set c 0
foreach vb $vbl {$this displayCell [rlindex vb 2] $numRows $c tab
if !$c {lappend varBind [rlindex tab(-2,0) 0].$newInst} else {lappend varBind [rlindex vb 0]}
incr c}
incr numRows
$sess next "$this getTableCB $indexOffset $numRows $table" $varBind
if {[expr $numRows % 25] == 0} {$This.status config -text "$numRows row(s)... reading..."
if {$numRows == 25 && [$This.fCat$CatNo.t cget -rows] == 1} {$This.fCat$CatNo.t config -rows $numRows
$This.fCat$CatNo.t bestfit
update idletasks}}}
method getBulkTableCB {firstOid rowLen indexOffset maxrept numRows table sess reqid errStat errIdx} {if ![winfo exists $This] return
if [info exists Stop($table)] {set errStat stopped}
if {$errStat != "noError"} {$This.fCat$CatNo.t config -rows [incr numRows]
$This.fCat$CatNo.t bestfit
::DMtable::needScrollbars $This.fCat$CatNo.t
$This.status config -text "$errStat at $numRows row(s)"
resetStop
return}
upvar $table tab
global BULKVAR
set i 0
foreach {oid val} $BULKVAR {if {[expr $i % $rowLen] == 0} {set inst [string range $oid $indexOffset end]
if [info exists StopIndexProc($CatNo)] {if [$StopIndexProc($CatNo) $GlobInst $inst $sess] {set firstOid ""}}
set c 0
incr maxrept -1
incr numRows
set tab($numRows,-1) $inst}
$this displayCell $val $numRows $c tab
incr c
incr i}
if {$maxrept == 0} {$This.status config -text "[incr numRows] row(s)"
$This.fCat$CatNo.t config -rows [incr numRows]
$This.fCat$CatNo.t bestfit
::DMtable::needScrollbars $This.fCat$CatNo.t
resetStop
return}
set lastFullRow [expr ($i/$rowLen)*$rowLen]
if {$i > $lastFullRow} {incr numRows -1
incr maxrept}
for {set k [expr $lastFullRow*2]; set j [expr $k-($rowLen*2)]} {$j < $k} {incr j 2} {lappend varBind [rlindex BULKVAR $j]}
$sess config -maxrept $maxrept
$sess bulkvar "$this getBulkTableCB $firstOid $rowLen $indexOffset $maxrept $numRows $table" $varBind
$This.status config -text "$numRows row(s)... $maxrept remaining..."
if {[$This.fCat$CatNo.t cget -rows] == 0 && $numRows >= 50} {$This.fCat$CatNo.t config -rows $numRows
$This.fCat$CatNo.t bestfit
update idletasks}}
method refresh {} {$this get
$This.fBtn.apply config -state disabled
if {!$Multiple && ![info exists Table($CatNo)]} {$this resetFont}}
method resetFont {} {global DmDMS Dm_Pref
set win $This.fCat$CatNo
set i 0
foreach var [lindex [rlindex DmDMS($Component.edit) $CatNo] 1] {if {$var == {separator}} continue
if {[winfo class $win.v$i]=="FRadio"} {foreach r [winfo children $win.v$i] {if {[$r cget -font]==$Dm_Pref(changeFont)} {$r config -font $Dm_Pref(normalFont)}}} elseif {[$win.v$i cget -font]==$Dm_Pref(changeFont)} {$win.v$i config -font $Dm_Pref(normalFont)}
incr i}}
method promptIfIndex {entry} {if ![catch {set ifIndex [dm_PromptPortPicker]}] {global Dm_Pref
$entry delete 0 end
$entry insert 0 $ifIndex
$entry config -font $Dm_Pref(changeFont)}
$This.fBtn.apply config -state normal}
method apply {} {if [info exists Table($CatNo)] {$this applyTable} else {$this applyForm}}
method applyForm {} {global Dm_Pref DmDMS Dm_Radio val
focus $This.fBtn.apply
update
set win $This.fCat$CatNo
set i 0
foreach var [lindex [rlindex DmDMS($Component.edit) $CatNo] 1] {if {$var == {separator}} continue
set changed 0
if {[winfo class $win.v$i]=="FRadio"} {foreach r [winfo children $win.v$i] {if {[$r cget -font]==$Dm_Pref(changeFont)} {set changed 1
break}}} elseif {[$win.v$i cget -font]==$Dm_Pref(changeFont)} {set changed 1}
if {$changed || [dm_GetTYPE $var] == "PortSet"} {if {[winfo class $win.v$i]=="Entry"} {if {[dm_GetTYPE $var] == "PortSet"} {set tmp [bit parse [dm_GetPortPicker $win.f$i]]
if {[string length $tmp] == 2} {set tmp 0x$tmp}
$win.v$i delete 0 end
$win.v$i insert 0 $tmp}
set val [list [$win.v$i get]]} else {set val $Dm_Radio($win.v$i)}
if [catch {dm_CheckModifyProc $var val $CatInst} err] {$this error $err
return}
if [string match *.* $var] {scan [split $var .] %s%s var instProc
lappend varBind "$var.[eval $instProc $CatInst] {} $val"} else {lappend varBind "$var.$CatInst {} $val"}
lappend changeList $i}
incr i}
if ![info exists changeList] return
if $Dm_Pref(trace) {catch {puts "debug: $varBind"}}
dm_BusyCursor $This
update idletasks
if [catch {$sess set null $varBind} err] {dm_displayError $This [dm_SnmpError err set]} else {foreach i $changeList {if {[winfo class $win.v$i]=="FRadio"} {foreach r [winfo children $win.v$i] {$r config -font $Dm_Pref(normalFont)}} else {$win.v$i config -font $Dm_Pref(normalFont)}}
$this get $CatInst
$this setCatState
$This.status config -text ok}
dm_BusyCursor $This 0}
method replicate {} {::DMedit$this.fCat$CatNo replicate
$This.fBtn.apply config -state normal}
method applyTable {} {set t $This.fCat$CatNo.t
if {[set editList [$t tag celltag edited]]=={}} return
global DmDMS Dm_Pref val
set currActive [$This.fCat$CatNo.t index active]
scan $currActive %d,%d activeRow activeCol
if {$activeCol == 0} {$This.fCat$CatNo.t activate 0,[incr activeCol]} else {$This.fCat$CatNo.t activate 0,0}
$This.fCat$CatNo.t activate $currActive
upvar #0 $TableName($CatNo) tab
if {$Multiple && [info exists DmDMS($Component.indexNamesProc)]} {set instanceRow -2} else {set instanceRow -1}
set tmpVarList [lindex [rlindex DmDMS($Component.edit) $CatNo] 1]
set varList ""
foreach l $tmpVarList {if {$l != "separator"} {lappend varList $l}}
set numVarBind 0
foreach cell $editList {scan $cell %d,%d row col
set var [lindex $varList $col]
set cc [expr -5 - $col]
if [info exists tab($row,$cc)] {set val $tab($row,$cc)} else {set val [list $tab($row,$col)]}
if {[lsearch [$t tag coltag option] $col]!=-1} {foreach e [dm_GetEnums $var] {if {[rlindex e 1]==$val} {set val [rlindex e 0]
break}}} elseif {[dm_GetTYPE $var] == "PortSet"} {set tmp [port parse $val]
if {[string length $tmp] == 2} {set tmp 0x$tmp}
set val $tmp}
if [catch {dm_CheckModifyProc $var val $tab($row,$instanceRow)} err] {$this error $err
return}
lappend varBind "$var.$tab($row,$instanceRow) {} $val"
incr numVarBind}
dm_BusyCursor $This
update idletasks
if $Dm_Pref(trace) {catch {puts "debug: $varBind"}}
$sess config -timeout [expr $Dm_Pref(timeout)*(($numVarBind/10)+1)]
if [catch {$sess set null $varBind} err] {dm_displayError $This [dm_SnmpError err set]} else {foreach e $editList {$t tag celltag {} $e}
$This.status config -text ok}
$sess config -timeout $Dm_Pref(timeout)
dm_BusyCursor $This 0}
method insert {} {global Dm_Pref
$This.status config -text ""
set w $This$CatNo-Ins
if [dm_MakeDlg $w "" {}] {wm deiconify $w
raise $w
return}
dm_transient $w $This
wm title $w "($Dm_Pref(devName)) - Insert $Title($CatNo)"
wm group $w $This
global Dm_Pref Dm_AgentCap Dm_Radio
upvar #0 $TableName($CatNo) tab
set insVar [rlindex Insert($CatNo) 1]
set parent [snmpinfo mibprop $insVar parent]
set varList [snmpinfo mibprop $parent property INDEX]
set numIndeces [llength $varList]
foreach v [snmpinfo mibprop $parent children] {if [snmpinfo mibprop $v property IsINDEX] continue
if {$v == $insVar} continue
set access [dm_GetACCESS $v]
if {$access == "read-write" || $access == "read-create"} {lappend varList $v}}
if [info exists AugmentInsert($CatNo)] {$AugmentInsert($CatNo) varList}
$this buildForm $w.f varList
loop i 0 $numIndeces {$w.f.l$i config -font $Dm_Pref(boldFont)}
if {$numIndeces == 1 &&
		    [snmpinfo mibprop [rlindex varList 0] property SYNTAX] == "Integer32"} {set lastRow [$This.fCat$CatNo.t cget -rows]
incr lastRow -2
if [info exists tab($lastRow,-1)] {$w.f.v0 insert 0 [expr $tab($lastRow,-1)+1]
focus $w.f.v1}}
set i 0
foreach var $varList {raise $w.f.v$i
if {[set val [dm_GetDEFVAL $var]] != ""} {set frameClass [winfo class $w.f.v$i]
if {$frameClass == "Entry"} {$w.f.v$i insert 0 $val} elseif {$frameClass == "FRadio"} {dm_SetRWEnum $w.f.v$i $val} elseif {$frameClass == "FBitSet"} {dm_SetBitSet $w.f.v$i $val}}
incr i}
$w.fb.ok config -text Insert -command "$this insertCB $w $parent $CatNo $varList"
if {[$This.fBtn.help cget -state] == "normal"} {$w.fb.help config -state normal -command [$This.fBtn.help cget -command]}
focus $w.f.v0
if [info exists InsertCB($CatNo)] {$InsertCB($CatNo) $w $CatInst $sess}}
method insertCB {w parent catNo args} {global Dm_Radio DmDMS Dm_Pref val
set i 0
foreach var [snmpinfo mibprop $parent property INDEX] {if {[winfo class $w.f.v$i] == "Entry"} {set val [$w.f.v$i get]
if [catch {dm_CheckModifyProc $var val 0} err] {$this error $err
return}
if {[snmpinfo mibprop $var type] == "DisplayString"} {append inst [str2oid $val].} else {append inst [hex2dec $val].}} else {append inst $Dm_Radio($w.f.v$i).}
incr i}
set inst [string trimright $inst .]
lappend varBind "[rlindex Insert($catNo) 1].$inst {} [rlindex Insert($catNo) 0]"
while 1 {set var [rlindex args $i]
if [catch {
				if {[winfo class $w.f.v$i]=="Entry"} {
					if {[dm_GetTYPE $var] == "PortSet"} {
# puts "insertCB: portSet=[dm_GetPortPicker $w.f.f$i]"
						set tmp [bit parse [dm_GetPortPicker $w.f.f$i]]
						if {[string length $tmp] == 2} {
							set tmp 0x$tmp
						}
						$w.f.v$i delete 0 end
						$w.f.v$i insert 0 $tmp
					}
					set val [list [$w.f.v$i get]]
				} elseif {[winfo class $w.f.v$i]=="FRadio"} {
					set val $Dm_Radio($w.f.v$i)
				} elseif {[winfo class $w.f.v$i]=="FBitSet"} {
					set val [dm_GetBitSet $w.f.v$i]
				}
			}] break
if [catch {dm_CheckModifyProc $var val $inst} err] {$this error $err
return}
if {"x$val" != "x" && "x$val" != "x{}"} {lappend varBind "$var.$inst {} $val"}
incr i}
if {$DmDMS(Chassis.snmpVersion) == 2} {if ![catch {set r [$sess get null [rlindex Insert($catNo) 1].$inst]} err] {if ![string match noSuch* [lindex [lindex [rlindex r 4] 0] 2]] {$w.status config -text "Row $inst already exists"
focus $w.f.v0
bell
return}}}
if $Dm_Pref(trace) {catch {puts "debug: $varBind"}}
if [catch {$sess set null $varBind} err] {dm_displayError $w [dm_SnmpError err set]} else {if {[set createAndGo [rlindex Insert($catNo) 2]] != ""} {if [catch {$sess set null [list [list [rlindex Insert($catNo) 1].$inst {} $createAndGo]]} err] {dm_displayError $w [dm_SnmpError err set]
return}}
if ![catch {$this showInsertedRow $inst}] {$w.fb.cancel invoke
$This.status config -text inserted.
$this setCatState
$This.fCat$CatNo.t bestfit}}}
method showInsertedRow {inst} {set numRows [$This.fCat$CatNo.t cget -rows]
$This.fCat$CatNo.t config -rows [incr numRows]
$This.fCat$CatNo.t see $numRows,0
$This.fCat$CatNo.t activate $numRows,0
upvar #0 [$This.fCat$CatNo.t cget -var] tab
incr numRows -2
global DmDMS
foreach l [lindex [rlindex DmDMS($Component.edit) $CatNo] 1] {lappend vbl $l.$inst}
set tab($numRows,-1) $inst
set c 0
foreach vb [lindex [$sess get null $vbl] 4] {$this displayCell [rlindex vb 2] $numRows $c tab
incr c}
::DMtable::needScrollbars $This.fCat$CatNo.t}
method remove {} {upvar #0 $TableName($CatNo) tab
set row [$This.fCat$CatNo.t index active row]
if ![info exists tab($row,-1)] return
set inst $tab($row,-1)
lappend vbl [list [rlindex Delete($CatNo) 1].$inst {} [rlindex Delete($CatNo) 0]]
if [catch {set resp [$sess set null $vbl]} err] {dm_displayError $This [dm_SnmpError err set]} else {[string range $This.fCat$CatNo 1 end] deleteRow $row $row
if {$row > 0 && $row == [$This.fCat$CatNo.t cget -rows]} {$This.fCat$CatNo.t activate [incr row -1],0}
$This.status config -text deleted.
$this setCatState}
::DMtable::needScrollbars $This.fCat$CatNo.t}
method displayCell {val row col table} {upvar $table tab
global DmDMS
if ![catch {set var [rlindex tab(-2,$col) 0]}] {if [info exists DmDMS($var.display)] {if {[lindex $tab(-2,$col) 1] != ""} {set cc [expr -5 - $col]
set tab($row,$cc) $val}
if [catch {set tab($row,$col) [$var.display $val]}] {set tab($row,$col) Err}
return} elseif {[set enum [rlindex tab(-2,$col) 1]] != ""} {foreach e $enum {if {$val == [rlindex e 0]} {set tab($row,$col) [rlindex e 1]
return}}} elseif {[dm_GetTYPE $var] == "PortSet"} {set tab($row,$col) [port print $val range]
return}}
set tab($row,$col) $val}
method save {} {::DMedit$this.fCat$CatNo save [rlindex Title($CatNo) 0] $Component}
method stop {} {set Stop(Dm_Edit$Component$CatNo) 1}
method resetStop {} {catch {unset Stop(Dm_Edit$Component$CatNo}
$This.fBtn.other.m entryconfig 0 -state disabled}
public variable Modify
protected variable CatLastInst
protected variable CustomButtons
protected variable Stop}
class DMeditMultiple {inherit DMedit
constructor {args} {set Multiple 1
eval DMedit::constructor $args} {
	}
method createIndex {} {}
method updateIndex {instance} {}
method build {frm} {global DmDMS
set TableName($CatNo) Dm_EditM$Component$CatNo
set numRows [llength $GlobInst]
buildTable $frm 1 $numRows
set NumVars($CatNo) [llength [lindex [rlindex DmDMS($Component.edit) $CatNo] 1]]
foreach l [lindex [rlindex DmDMS($Component.edit) $CatNo] 1] {if {$l == "separator"} {incr NumVars($CatNo) -1}}
upvar #0 $TableName($CatNo) tab
set i 0
foreach instance $GlobInst {if {[info exists NeedSubClass($CatNo)] &&
			   $NeedSubClass($CatNo) != [rlindex SubClass $i]} {incr i
continue}
if [info exists CvtProc($CatNo)] {set instance [$CvtProc($CatNo) $instance]}
set tab($i,-2) $instance
if [info exists DmDMS($Component.indexNamesProc)] {set tab($i,-1) [$DmDMS($Component.indexNamesProc) $instance 1]} else {set tab($i,-1) $instance}
incr i}
set tab($i,-2) end
if [info exists BuildCB($CatNo)] {$BuildCB($CatNo) $frm $CatInst $sess true}}
method get {{inst ""}} {global DmDMS Dm_Pref
upvar #0 $TableName($CatNo) tab
set t $This.fCat$CatNo.t
if {[set editList [$t tag celltag edited]]!={}} {foreach e $editList {$t tag celltag {} $e}}
for {set row 0} {$tab($row,-2) != "end"} {incr row} {if [info exists tab($row,-2)] {set vbl ""
loop i 0 $NumVars($CatNo) {lappend vbl [rlindex tab(-2,$i) 0].$tab($row,-2)}
if [catch {$sess get "$this GetCB $row $TableName($CatNo) $t" $vbl} err] {$This.status config -text [rlindex err 2]
bell}
after [expr 3*$NumVars($CatNo)]}}}
method GetCB {row table t sess reqid errStat errIdx vbl} {if ![winfo exists $This] return
upvar $table tab
if {$errStat!="noError"} {if $errIdx {incr errIdx -1
$this error "$tab(-1,$errIdx).$tab($row,-2): $errStat"} else {$this error $errStat}} else {set i 0
foreach vb $vbl {if {[set val [rlindex vb 2]] == "noSuchInstance"} {set val "N/A"}
$this displayCell $val $row $i tab
incr i}}
if {$row == 0} {$t bestfit
::DMtable::needScrollbars $t
update idletasks}}
method apply {} {$this applyTable}
protected variable NumVars}
proc dm_GetEnums {var} {global Dm_AgentCap
if [info exists Dm_AgentCap($var.enums)] {return $Dm_AgentCap($var.enums)}
return [snmpinfo mibprop $var enums]}
proc dm_GetACCESS {var} {global Dm_AgentCap
if [info exists Dm_AgentCap($var.ACCESS)] {return $Dm_AgentCap($var.ACCESS)}
return [snmpinfo mibprop $var property ACCESS]}
proc dm_GetDEFVAL {var} {global Dm_AgentCap
if [info exists Dm_AgentCap($var.DEFVAL)] {return $Dm_AgentCap($var.DEFVAL)}
return [snmpinfo mibprop $var property DEFVAL]}
proc dm_GetTYPE {var} {global Dm_AgentCap
if [info exists Dm_AgentCap($var.TYPE)] {return $Dm_AgentCap($var.TYPE)}
return [snmpinfo mibprop $var type]}
proc dm_RadioSet {w r} {global Dm_Pref Dm_Radio
foreach i [winfo children $w] {$i config -font $Dm_Pref(normalFont)}
$r config -font $Dm_Pref(changeFont)
catch {set Dm_Radio($w) [$r cget -value]}
catch {[winfo toplevel $w].fBtn.apply config -state normal}}
proc dm_PortPickerSet {c} {global Dm_Pref
$c config -font $Dm_Pref(changeFont)
catch {[winfo toplevel $c].fBtn.apply config -state normal}}
proc dm_CheckModifyProc {var value inst} {upvar $value val
if {[info proc $var.modify]!=""} {set val [$var.modify $val $inst]}}
proc dm_SetROEnum {w val} {set mLen [$w.m index last]
incr mLen
loop j 0 $mLen {if {$val==[$w.m entrycget $j -value]} {$w config -text [$w.m entrycget $j -label]
return}}
$w config -text "unknown ($val)"}
proc dm_SetRWEnum {w val} {global Dm_Radio Dm_Pref
set Dm_Radio($w) $val
set j 0
while 1 {if ![winfo exists $w.r$j] break
$w.r$j config -font $Dm_Pref(normalFont)
if {$val==[$w.r$j cget -value]} {$w.r$j invoke
return}
incr j}}
proc dm_SetBitSet {w val} {global Dm_Radio
foreach cb [winfo children $w] {set onValue [$cb cget -on]
if [expr $val & $onValue] {set Dm_Radio($cb) $onValue} else {set Dm_Radio($cb) 0}}}
proc dm_GetBitSet {w} {global Dm_Radio
set val 0
foreach cb [winfo children $w] {if $Dm_Radio($cb) {set val [expr $val | $Dm_Radio($cb)]}}
return $val}
proc dm_enableFrame {f state} {foreach r [winfo children $f] {$r config -state $state}}
proc dm_GetFieldNo {mibVar frm} {global DmDMS
set class [lindex [split $frm .] 1]
set i 0
foreach v [lindex [rlindex DmDMS([$class cget -Component].edit) [$class cget -CatNo]] 1] {if {$v == $mibVar} {return $i}
if {$v != {separator}} {incr i}}
return -1}
class DMgraph {inherit DMwindow
constructor {args} {set Op graph
eval DMwindow::constructor $args} {
		global DmDMS

		# Transient windows aren't resizable on PCs; remove attribute.
		# (Custom graphs may need to be resizable.)  
		# Anyhow, on Unix, we want the window to be iconifable.
		wm transient $This ""

		bind $This <Return> {catch {[focus -lastfor %W] invoke}}
		button $This.fBtn.colResize -text "Resize Columns" -command "$this colResize"
		pack $This.fBtn.colResize -side left -before $This.fBtn.cancel
	}
destructor {loop i 0 $NumCat {if [info exists TimerId($i)] {catch {$sess poll destroy $TimerId($i)}}
if [info exists TableName($i)] {delete object ::DMgraph$this.fCat$i.f
catch {upvar #0 $TableName($i) tab; unset tab}}}
foreach w [winfo children .] {if [string match $This-* $w] {if [winfo exists $w.fBtn.cancel] {$w.fBtn.cancel invoke} elseif [winfo exists $w.fb.cancel] {$w.fb.cancel invoke}}}}
method showCat {} {$this suspend
if ![winfo exists $This.fCat$CatNo] {if [info exists Custom($CatNo)] {set PollFreq($CatNo) ""
if [catch {eval $Custom($CatNo) $This.fCat$CatNo {$CatInst} $sess} err] {$this error $err
return}} else {if [info exists List($CatNo)] {set List($CatNo) [$List($CatNo) $CatInst $sess]
if {$List($CatNo) == ""} {$This.status config -text "Nothing to graph"
return}}
set PollFreq($CatNo) 5
$this build $This.fCat$CatNo
$this get $CatInst
if ![info exists PollVbl($CatNo)] {return}}} else {if {![info exists TimerId($CatNo)] && ![info exists Custom($CatNo)]} {$this buildTimer $CatInst}
if [info exists TimerId($CatNo)] {$sess poll config $TimerId($CatNo) -freq $PollFreq($CatNo)}}
DMwindow::showCat
pack $This.fCat$CatNo -after $This.nb -fill both -expand 1}
method save {} {::DMgraph$this.fCat$CatNo.f save [rlindex Title($CatNo) 0] $Component}
method colResize {} {$This.fCat$CatNo.f.t bestfit}
method build {w table} {global Dm_ImageCache Dm_Path DmDMS Dm_Pref
set tabObj [string range $w.f 1 end]
DMtable $tabObj -Table $table -Colt 1
$w.f.t config -state disabled
$w.f.t tag coltag tagLeft -1
upvar #0 $table tab
set rows 0
foreach gdef [lindex [rlindex DmDMS($Component.graph) $CatNo] 1] {if {[set i [lsearch [rlindex gdef 1] -label]] != -1} {set tab($rows,-1) [lindex [rlindex gdef 1] [incr i]]} else {set tab($rows,-1) [dm_GetAlias [rlindex gdef 0] $Prefix($CatNo)]}
incr rows}
set NumDataset($CatNo) $rows
$w.f.t config -rows [incr rows] -width 12
pack $w.f -anchor w
frame $w.fCmd
foreach b {linegraph barchart pie save} {if ![info exists Dm_ImageCache($b)] {set Dm_ImageCache($b) [image create photo $b.gif -file $Dm_Path/bitmaps/$b.gif]}
if [catch {button $w.fCmd.$b -text $b -image $Dm_ImageCache($b)}] {button $w.fCmd.$b -text $b -padx 0 -pady 0}
pack $w.fCmd.$b -side left
dm_ToolTipBind $w.fCmd.$b}
$w.fCmd.save config -command "$this save"
$w.fCmd.pie config -command "$this graph $w.f.t Pie"
$w.fCmd.linegraph config -command "$this graph $w.f.t Line"
$w.fCmd.barchart config -command "$this graph $w.f.t Bar"
if [info exists Table($CatNo)] {pack [button $w.fCmd.refresh -text Refresh -command "$this getTable $w $table"] -side right
set PollFreq($CatNo) 0} else {label $w.fCmd.lpoll -text "Poll Interval:"
label $w.fCmd.poll -text "5s" -relief sunken
menubutton $w.fCmd.pDown -bitmap @$Dm_Path/bitmaps/pulldown.xbm -menu $w.fCmd.pDown.m -takefocus 1 -highlightthickness 1 -relief raised
menu $w.fCmd.pDown.m
foreach lab {none 2s 5s 10s 30s 1m 5m 60m} val {0 2 5 10 30 60 360 3600} {
				$w.fCmd.pDown.m add command -label $lab -command "$w.fCmd.poll config -text $lab; $this setPollInterval $val"
			}
label $w.fCmd.cumulative
pack $w.fCmd.lpoll $w.fCmd.poll $w.fCmd.pDown $w.fCmd.cumulative -side left}
pack $w.fCmd -anchor w}
method get {inst} {if [info exists Custom($CatNo)] {eval $Custom($CatNo) $This.fCat$CatNo $inst $sess
return} elseif [info exists Table($CatNo)] {if [info exists BuildCB($CatNo)] {getTable $This.fCat$CatNo $TableName($CatNo)}
return}
if {[info exists TimerId($CatNo)] && $PollInst($CatNo) != $inst} {loop i 0 $NumCat {if {[info exists TimerId($i)] && $PollInst($i) != $inst} {$sess poll destroy $TimerId($i)
unset TimerId($i)
unset PollVbl($i)
upvar #0 [$This.fCat$i.f.t cget -var] tab
set rows [$This.fCat$i.f.t cget -rows]
set cols [$This.fCat$i.f.t cget -cols]
incr cols -1
loop r 0 [incr rows -1] {loop c 0 $cols {set tab($r,$c) ""}}}}}
if ![info exists TimerId($CatNo)] {$this buildTimer $inst}}
method buildTimer {inst} {if ![info exists PollVbl($CatNo)] {$this createPollVbl $inst
if ![info exists PollVbl($CatNo)] {return}
set CumulTimeStamp($CatNo) [timeticks clock 0]}
if ![info exists PollVbl($CatNo)] return
if [catch {set TimerId($CatNo) [$sess poll "$this pollCB" $PollVbl($CatNo) $PollFreq($CatNo)]} err] {$This.status config -text [rlindex err 2]}
set PollInst($CatNo) $inst}
method getTable {w table} {global DmDMS
foreach v [lindex [rlindex DmDMS($Component.graph) $CatNo] 1] {lappend varList $v}
if [catch {set cols [$BuildCB($CatNo) $table $CatInst $sess varList]} err] {$w.f.t config -cols 1
error [dm_SnmpError err]} else {$w.f.t config -cols [incr cols]
$This.status config -text ""}
$w.f.t bestfit
::DMtable::needScrollbars $w.f.t}
method suspend {} {loop i 0 $NumCat {if [info exists TimerId($i)] {$sess poll config $TimerId($i) -freq 0}}}
method setPollInterval {freq} {if {$freq != $PollFreq($CatNo)} {$sess poll config $TimerId($CatNo) -freq $freq
set PollFreq($CatNo) $freq}}
method graph {t type} {if [winfo exists $This-$CatNo$type] {raise $This-$CatNo$type
bell
return}
if {[set selected [$t curselection]] == ""} {$This.status config -text "Please select single row or column"
bell
return}
scan [rlindex selected 0] %d,%d selRow1 selCol1
scan [lindex $selected end] %d,%d selRow2 selCol2
if {$type != "Bar" && $selRow1 != $selRow2 && $selCol1 != $selCol2} {$This.status config -text "Please select single row or column"
bell
return}
set table [$t cget -var]
upvar #0 $table tab
foreach cell $selected {if {$tab($cell) == "N/A"} {$This.status config -text "N/A is invalid for graphing"
bell
return}}
if ![info exists GrOption($CatNo)] {set GrOption($CatNo) ""}
DMgraph$type [string range $This-$CatNo$type 1 end] -Table $table -Title "[wm title $This] $Title($CatNo)" -Selected $selected -Parent $This -GrOptions $GrOption($CatNo) -SelRow1 $selRow1 -SelCol1 $selCol1 -SelRow2 $selRow2 -SelCol2 $selCol2}
method customOptions {} {dm_GrSetOptions $This-Opt $This.fCat$CatNo ""}
protected variable PollVbl
protected variable PollInst
protected variable TimerId
protected variable CumulTimeStamp
protected variable NumDataset
public variable PollFreq}
class DMgraphSingle {inherit DMgraph
constructor {args} {eval DMgraph::constructor $args} {
	}
method build {frm} {if [info exists List($CatNo)] {DMgraphMultiple::build $This.fCat$CatNo $List($CatNo) $this
return}
set w [frame $frm -bd 1 -relief raised]
set TableName($CatNo) Dm_Graph$Component$CatNo
DMgraph::build $w $TableName($CatNo)
if ![info exists Table($CatNo)] {upvar #0 $TableName($CatNo) tab
set col 0
foreach lab {Absolute Cumulative Average/sec Min/sec Max/sec Last/sec} {set tab(-1,$col) $lab
$w.f.t tag coltag tagRight $col
incr col}
loop r 0 [expr [$w.f.t cget -rows]-1] {loop col 0 7 {set tab($r,$col) 0}}
$w.f.t config -cols 7
$w.f.t bestfit -1}}
method createPollVbl {inst} {if [info exists List($CatNo)] {return [DMgraphMultiple::createPollVbl $List($CatNo) $this]}
global DmDMS
if [info exists StartIndexProc($CatNo)] {set inst [$StartIndexProc($CatNo) $inst $sess]}
foreach m [lindex [rlindex DmDMS($Component.graph) $CatNo] 1] {lappend PollVbl($CatNo) "[rlindex m 0] $inst"}
if [info exists PollVbl($CatNo)] {return $PollVbl($CatNo)} else {return ""}}
method pollCB {s reqid err errIndex valList} {if [info exists List($CatNo)] {DMgraphMultiple::pollCB $s $reqid $err $errIndex $valList $this
return}
if {$err != "noError"} {$this error "$err $errIndex"
return}
$This.status config -text ""
set table Dm_Graph$Component$CatNo
upvar #0 $table tab
set row 0
foreach var [$sess poll stat $TimerId($CatNo)] last $valList {
			set tab($row,5) $last
			set col 0
			foreach stat $var {
				set tab($row,$col) $stat
				incr col
			}
			incr row
		}
$This.fCat$CatNo.fCmd.cumulative config -text ([timeticks rel [expr [timeticks clock 0]-$CumulTimeStamp($CatNo)]])
foreach type {Pie Line Bar} {if [winfo exists $This-$CatNo$type] {::DMgraph$this-$CatNo$type refresh}}}
method setDisplay {type} {DMgraphMultiple::setDisplay $type}}
class DMgraphMultiple {inherit DMgraph
constructor {args} {set Multiple 1
eval DMgraph::constructor $args} {
	}
method createIndex {} {}
method updateIndex {instance} {}
method build {frm {instList ""} {t ""}} {global DmDMS Dm_Path
if {$instList == ""} {set instList $GlobInst}
if {$t != ""} {set this $t}
set w [frame $frm -bd 1 -relief raised]
set TableName($CatNo) Dm_GraphM$Component$CatNo
DMgraph::build $w $TableName($CatNo)
label $w.fCmd.lD -text "Show:"
label $w.fCmd.lDisplay -text "Last/sec" -relief raised
menubutton $w.fCmd.mbDisplay -bitmap @$Dm_Path/bitmaps/pulldown.xbm -menu $w.fCmd.mbDisplay.m -takefocus 1 -highlightthickness 1 -relief raised
menu $w.fCmd.mbDisplay.m
foreach lab {Absolute Cumulative Average/sec Minimum/sec Maximum/sec Last/sec} {$w.fCmd.mbDisplay.m add command -label $lab -command "$w.fCmd.lDisplay config -text $lab; $this setDisplay $lab"}
pack $w.fCmd.lD $w.fCmd.lDisplay $w.fCmd.mbDisplay -side left
upvar #0 $TableName($CatNo) tab
if [info exists Rotate($CatNo)] {set numRows [$w.f.t cget -rows]
$w.f.t config -cols $numRows
set numCols $numRows
loop r 0 [incr numRows -1] {set tab(-1,$r) $tab($r,-1)}
set row 0} else {set col 0}
foreach sc $SubClass inst $instList {
			# Does this instance match subclass required?
			if {[info exists NeedSubClass($CatNo)] &&
			   $NeedSubClass($CatNo) != $sc} {
				continue
			}
			if [info exists DmDMS($Component.indexNamesProc)] {
				catch {set inst [$DmDMS($Component.indexNamesProc) $inst 1]}
			}
			if [info exists Rotate($CatNo)] {
				set tab($row,-1) $inst
				incr row
			} else {
				set tab(-1,$col) $inst
				incr col
			}
		}
if [info exists Rotate($CatNo)] {set NumDataset($CatNo) $row
$w.f.t config -rows [incr row]
$w.f.t bestfit} else {$w.f.t config -cols [incr col]
$w.f.t bestfit -1
set numCols $col}
loop c 0 $numCols {$w.f.t tag coltag tagRight $c}
::DMtable::needScrollbars $w.f.t}
method createPollVbl {inst {t ""}} {global DmDMS
if {$t != ""} {set this $t}
set count 0
foreach gdef [lindex [rlindex DmDMS($Component.graph) $CatNo] 1] {foreach i $inst {lappend PollVbl($CatNo) "[rlindex gdef 0] $i"
incr count}}
if {[info exists DmDMS(Chassis.maxOidInPDU)] && $count > $DmDMS(Chassis.maxOidInPDU)} {dm_Prompt .err "You have requested more data than can be returned\nin a single poll response from the agent.\n\nPlease select fewer ports to graph this category." Continue
catch {unset PollVbl($CatNo)}}}
method pollCB {s reqid err errIndex valList {t ""}} {if {$t != ""} {set this $t}
if {$err!="noError"} {$this error $err
return}
$This.status config -text ""
set table Dm_GraphM$Component$CatNo
upvar #0 $table tab
set i 0
if [info exists Rotate($CatNo)] {set len [$This.fCat$CatNo.f.t cget -rows]
incr len -1
foreach val $valList {set tab([expr $i % $len],[expr $i / $len]) $val
incr i}} else {set len [$This.fCat$CatNo.f.t cget -cols]
incr len -1
foreach val $valList {set tab([expr $i / $len],[expr $i % $len]) $val
incr i}}
$This.fCat$CatNo.fCmd.cumulative config -text ([timeticks rel [expr [timeticks clock 0]-$CumulTimeStamp($CatNo)]])
foreach type {Pie Line Bar} {if [winfo exists $This-$CatNo$type] {::DMgraph$this-$CatNo$type refresh}}}
method setDisplay {type} {catch {
			set DisplayType($CatNo) $type
			$sess poll config $TimerId($CatNo) -display $type

			set table Dm_GraphM$Component$CatNo
			upvar #0 $table tab
			set i 0
			set numInst [llength $GlobInst]
			foreach val [$sess poll stat $TimerId($CatNo) $type] {
				set tab([expr $i / $numInst],[expr $i % $numInst]) [rlindex val 0]
				incr i
			}
		}}
protected variable DisplayType}
class DMgraphAggregrate {inherit DMgraph
constructor {} {DMgraph::constructor}
destructor {DMgraph::destructor}
method createPollVbl {inst} {global DmDMS
foreach gdef [lindex [rlindex DmDMS($Component.graph) $CatNo] 1] {foreach i $AggregList($CatNo) {lappend PollVbl($CatNo) "[rlindex gdef 0] $i"}}
set NumAggregList($CatNo) [llength $AggregList($CatNo)]}
method pollCB {s reqid err errIndex valList} {if {$err!="noError"} {$this error $err
return}
set numData $NumAggregList($CatNo)
set i 0
set j 0
set value($j) 0
foreach val $valList {if {$i && ([expr $i % $numData] == 0)} {lappend aggregrate $value($j)
incr j
set value($j) 0}
incr value($j) $val
incr i}
lappend aggregrate $value($j)
DMgraph::pollCB $s $reqid $err $errIndex $aggregrate}
protected variable NumAggregList}
proc dm_InitGraph {} {global Dm_Pref
set Dm_Pref(numColors) [llength $Dm_Pref(colors)]
set fg [.status cget -fg]
foreach {opt val} "borderWidth 1 relief raised plotBackground black
		plotBorderwidth 1 legendBorderwidth 1 legendForeground $fg
		legendForeground $fg xColor $fg yColor $fg y2Color $fg
		title {} xTitle {} yTitle {} gridMapped 1 gridMinor 0
		GridColor #a0a0a0 elemActiveLineWidth 2 elemActiveFill white
		elemActiveColor white halo 3
		y2Mapped true legendIPadY 0
		legendPadX 0 legendAnchor ne y2Title {} yMin 0 y2Min 0" {option add *Graph.$opt $val
option add *Barchart.$opt $val}
option add *Graph.legendFont $Dm_Pref(normalFont)
option add *Graph.xTickFont $Dm_Pref(smallFont)
option add *Graph.xTitleFont $Dm_Pref(boldFont)
option add *Graph.x2TickFont $Dm_Pref(smallFont)
option add *Graph.yTickFont $Dm_Pref(smallFont)
option add *Graph.yTitleFont $Dm_Pref(normalFont)
option add *Graph.y2TickFont $Dm_Pref(smallFont)
option add *Graph.xTitleFont $Dm_Pref(boldFont)
option add *Barchart.legendFont $Dm_Pref(normalFont)
option add *Barchart.xTickFont $Dm_Pref(smallFont)
option add *Barchart.xTitleFont $Dm_Pref(boldFont)
option add *Barchart.x2TickFont $Dm_Pref(smallFont)
option add *Barchart.yTickFont $Dm_Pref(smallFont)
option add *Barchart.yTitleFont $Dm_Pref(normalFont)
option add *Barchart.y2TickFont $Dm_Pref(smallFont)
option add *Barchart.xTitleFont $Dm_Pref(boldFont)
option add *Barchart.xStepsize 1
option add *Barchart.elemBorderwidth 0
bind Graph <ButtonPress-1> {dm_GrShowVal %W %x %y}
bind Graph <ButtonRelease-1> {dm_GrRemoveVal %W %x %y}
bind Barchart <ButtonPress-1> {dm_GrShowVal %W %x %y}
bind Barchart <ButtonRelease-1> {dm_GrRemoveVal %W %x %y}
bind Graph <ButtonPress-2> {BltResetZoom %W}
bind Barchart <ButtonPress-2> {BltResetZoom %W}
bind Graph <ButtonPress-3> {dm_GrPopup %W %X %Y}
bind Barchart <ButtonPress-3> {dm_GrPopup %W %X %Y}}
class DMgraphWidget {constructor {args} {set This [toplevel .[info namespace tail $this]]
eval configure $args
wm withdraw $This
wm protocol $This WM_DELETE_WINDOW "$This.fBtn.cancel invoke"
wm geom $This "+[winfo pointerx .]+[winfo pointery .]"
upvar #0 $Table tab
if {$SelRow1 == $SelRow2} {set IsRow 1
append Title " ($tab($SelRow1,-1))"} elseif {$SelCol1 == $SelCol2} {set IsRow 0
append Title " ($tab(-1,$SelCol1))"}
wm title $This $Title
$this build
createButtons
dm_OnScreen $This
bind $This <Escape> "$This.fBtn.cancel invoke"
bind $This <Return> {catch {[focus -lastfor %W] invoke}}}
destructor {if [winfo exists $This] {destroy $This}}
method createButtons {} {global tcl_platform
frame $This.fBtn -class FBtn
button $This.fBtn.options -text "Options..." -command "$this options"
button $This.fBtn.print -text "Print..." -command "$this print"
button $This.fBtn.cancel -command "delete object $this"
if {$tcl_platform(platform) != "windows"} {pack $This.fBtn.options $This.fBtn.print $This.fBtn.cancel -side left} else {pack $This.fBtn.print $This.fBtn.cancel -side left}
pack $This.fBtn -pady 5}
method print {} {if [catch {dm_Print "dm_GrPrint $This.g"} err] {dm_Prompt .err $err Continue}}
method setYTitle {title} {$This.g yaxis config -title $title}
public variable Table
public variable Selected
public variable Title
public variable Parent
public variable YTitle ""
public variable MaxElem 50
public variable GrOptions ""
public variable SelRow1
public variable SelRow2
public variable SelCol1
public variable SelCol2
protected variable This
protected variable IsRow}
class DMgraphPie {inherit DMgraphWidget
constructor {args} {eval DMgraphWidget::constructor $args} {
	}
method build {} {upvar #0 $Table tab
global Dm_Pref
wm resizable $This 0 0
canvas $This.c -width 202 -height 202
frame $This.fBtn -class FBtn
frame $This.fBtn.f -bd 1 -relief sunken
set i 0
foreach cell $Selected {set Total [expr $Total+$tab($cell)]
incr i}
set Total [expr double($Total)]
if {$Total == 0.0} {set Total 1.0}
set bg [$This.fBtn.f cget -bg]
set s 0
set i 0
foreach cell $Selected {set tmpextent [expr $tab($cell)/$Total*360.0]
set extent [format %.2f $tmpextent]
set color [rlindex Dm_Pref(colors) $i]
set item [$This.c create arc 4 4 199 199 -style pieslice -fill $color -start $s -extent $extent]
set s [expr $s+$extent]
label $This.fBtn.f.c$i -text " " -fg $color -bg $color -bd 0
label $This.fBtn.f.v$i -text [format %.2f [expr $extent/360.0*100.0]]%
scan $cell %d,%d row col
if $IsRow {set lab $tab(-1,$col)} else {set lab $tab($row,-1)}
label $This.fBtn.f.t$i -text $lab
bind $This.fBtn.f.t$i <Enter> "%W config -bg white; $This.c itemconfig $item -outline white -width 2"
bind $This.fBtn.f.t$i <Leave> "%W config -bg $bg; $This.c itemconfig $item -outline black -width 1"
grid $This.fBtn.f.c$i -row $i -column 0 -padx 1 -pady 1
grid $This.fBtn.f.t$i -row $i -column 1 -sticky w
grid $This.fBtn.f.v$i -row $i -column 2 -sticky e
incr i}
pack $This.c -side left}
method createButtons {} {pack $This.fBtn.f -padx 2 -pady 2
pack [button $This.fBtn.cancel -command "delete object $this"] -side bottom -anchor e
pack $This.fBtn -side right -fill y -expand 1}
method refresh {} {upvar #0 $Table tab
set Total 0
set i 0
foreach cell $Selected {set Total [expr $Total+$tab($cell)]
incr i}
set Total [expr double($Total)]
if {$Total == 0.0} {set Total 1.0}
set s 0
set arcNo 1
set i 0
foreach cell $Selected {if {[set extent [expr $tab($cell)/$Total*360]] >= 360} {set extent 359.99}
$This.c itemconfig $arcNo -start $s -extent $extent
$This.fBtn.f.v$i config -text [format %.2f [expr $extent/360.0*100.0]]%
incr arcNo
set s [expr $s+$extent]
incr i}}
method setYTitle {title} {}
protected variable Total 0}
class DMgraphLine {inherit DMgraphWidget
constructor {args} {eval DMgraphWidget::constructor $args} {
	}
method build {} {global Dm_Pref
upvar #0 $Table tab
::blt::graph $This.g -bufferelements 0 -topmargin 2
$This.g xaxis config -subdivisions 1 -command "$this formatXLabel" -mapped 1
$This.g legend config -borderwidth 1
$This.g marker create text -mapped 0 -name VALUE -font $Dm_Pref(normalFont)
if {$GrOptions != ""} {eval $GrOptions}
set i 0
foreach cell $Selected {scan $cell %d,%d row col
if $IsRow {set lab $tab(-1,$col)} else {set lab $tab($row,-1)}
$This.g element create e$i -mapy both -label $lab -color [lindex $Dm_Pref(colors) [expr $i%$Dm_Pref(numColors)]] -data "0 $tab($cell) 1 $tab($cell)"
incr i}
pack $This.g -fill both -expand 1
if {$i > 1} {Blt_ActiveLegend $This.g
if {$i <= 6} {$This.g legend config -pos bottom}} else {$This.g legend config -mapped 0}
Blt_ZoomStack $This.g
lappend XLabel [lindex [timeticks now 0] 3]}
method refresh {} {incr Count
if {$Count > $MaxElem} {set XLabel [lreplace $XLabel 0 0]}
lappend XLabel [lindex [timeticks now 0] 3]
upvar #0 $Table tab
set i 0
foreach cell $Selected {set yData [$This.g element cget e$i -ydata]
if {$Count < $MaxElem} {set xData [$This.g element cget e$i -xdata]
lappend xData [expr $Count-1]
$This.g element config e$i -xdata $xData} else {set yData [lreplace $yData 0 0]}
lappend yData $tab($cell)
$This.g element config e$i -ydata $yData
incr i}}
method formatXLabel {w n} {if {$Count < 4} {return ""}
return [rlindex XLabel [lindex [split $n .] 0]]}
method options {} {dm_GrSetOptions $This-Opt $This.g $MaxElem}
protected variable Count 2
protected variable XLabel ""}
class DMgraphBar {inherit DMgraphWidget
constructor {args} {eval DMgraphWidget::constructor $args} {
	}
method build {} {global Dm_Pref
upvar #0 $Table tab
::blt::barchart $This.g -bufferelements 0 -barmode aligned
$This.g xaxis config -title "" -showticks 0
$This.g legend config -borderwidth 1
$This.g marker create text -mapped 0 -name VALUE -font $Dm_Pref(normalFont)
if {$YTitle != ""} {$This.g yaxis config -title $YTitle}
if {$SelRow1 != $SelRow2 && $SelCol1 != $SelCol2} {$This.g config -barmode stacked}
if {$SelCol1 != $SelCol2} {$This.g xaxis config -showticks 1 -command "$this formatXLabel"}
if {$SelRow1 == $SelRow2} {$This.g legend config -mapped 0}
incr SelRow2
incr SelCol2
set i 0
loop r $SelRow1 $SelRow2 {set j 0
loop c $SelCol1 $SelCol2 {lappend yData $tab($r,$c)
lappend xData [incr j]}
$This.g element create e$i -xdata $xData -ydata $yData -mapy both -label $tab($r,-1) -foreground [rlindex Dm_Pref(colors) [expr $i%$Dm_Pref(numColors)]]
set yData {}
set xData {}
incr i}
if {$i <= 6} {$This.g legend config -pos bottom}
Blt_ZoomStack $This.g
if {$j > 20} {$This.g xaxis config -rotate 90}
pack $This.g -fill both -expand 1}
method refresh {} {upvar #0 $Table tab
set i 0
loop r $SelRow1 $SelRow2 {loop c $SelCol1 $SelCol2 {lappend yData $tab($r,$c)}
$This.g element config e$i -ydata $yData
set yData {}
incr i}}
method options {} {dm_GrSetOptions $This-Opt $This.g}
method formatXLabel {w n} {upvar #0 $Table tab
return $tab(-1,[expr [lindex [split $n .] 0]+$SelCol1-1])}}
proc dm_GrSetOptions {w g {maxXElem ""}} {global Dm_Radio Dm_GrMaxX Dm_Pref Dm_GrSymbol Dm_GrChange Dm_Path tcl_platform
if [winfo exists $w] {wm deiconify $w
raise $w
return}
set fields {
		{Check "Display" {legend "grid lines" "x axis" "y axis"} 4}
		{Radio "Position Legend At" {leftmargin rightmargin bottommargin plotarea} 2}
		{Radio "Legend Relief" {flat sunken raised}}
		{Radio "X Axis Label Rotation" {0.0 90.0}}
		{Radio "Y Axis Scale" {linear log}}
	}
if {[winfo class $g] == "Barchart"} {lappend fields {Check "Barchart" {stacked horizontal}}
if {[$g cget -barmode] == "stacked"} {set Dm_Radio($w.f.v5.c0) 1} else {set Dm_Radio($w.f.v5.c0) 0}
if [$g cget -invertxy] {set Dm_Radio($w.f.v5.c1) 1} else {set Dm_Radio($w.f.v5.c1) 0}
set colorOpt -foreground
set isBar 1} else {set Dm_GrMaxX($w) $maxXElem
lappend fields "Spin {Num X Axis Elements} 10 Dm_GrMaxX($w) 100"
set colorOpt -color
set isBar 0}
set parent [winfo parent $g]
dm_MakeDlg $w "" $fields
pack forget $w.status
dm_transient $w $parent
wm title $w "[wm title $parent] Options"
set i 0
foreach opt {legend grid xaxis yaxis} {set Dm_Radio($w.f.v0.c$i) [$g $opt cget -mapped]
incr i}
set Dm_Radio($w.f.v1) [$g legend cget -pos]
set Dm_Radio($w.f.v2) [$g legend cget -relief]
set Dm_Radio($w.f.v3) [$g xaxis cget -rotate]
set Dm_Radio($w.f.v4) [$g xaxis cget -logscale]
foreach e {1 2 3} {set i 0
foreach v [lindex [rlindex fields $e] 2] {$w.f.v$e.r$i config -value $v
incr i}}
if ![info exists Dm_GrSymbol] {source $Dm_Path/bitmaps/grxbm.tcl}
frame $w.fe -bd 1 -relief raised
set Dm_GrChange($w) ""
bind $w <1> "dm_Add2ChangeList %W $w.fe.v"
set titleList {Dataset Display? Color}
if !$isBar {lappend titleList Symbol Width}
set c 0
foreach lab $titleList {label $w.fe.t$c -text $lab -font $Dm_Pref(boldFont)
grid $w.fe.t$c -row 0 -column $c
incr c}
set rows [llength [$g element names]]
for {set i 0; set r 1} {$i < $rows} {incr i; incr r} {label $w.fe.l$r,0 -text [$g element cget e$i -label] -bd 0
grid $w.fe.l$r,0 -row $r -column 0
set Dm_Radio($w.$i,1) [$g element cget e$i -mapped]
grid [checkbutton $w.fe.v$i,1 -variable Dm_Radio($w.$i,1)] -row $r -column 1
set color [$g element cget e$i $colorOpt]
grid [button $w.fe.v$i,2 -bg $color -bitmap @$Dm_Path/bitmaps/pulldown.xbm -fg black -command "dm_GetColor $w.fe.v$i,2"] -row $r -column 2}
if !$isBar {catch {
		# Graphs only: symbol and linewidth
		set c 3
		foreach opt {-symbol -linewidth} val {{none square circle diamond plus cross splus scross triangle} {0 1 2 3 4}} {
			for {set i 0; set r 1} {$i < $rows} {incr i; incr r} {
				set Dm_Radio($w.$i,$c) [$g element cget e$i $opt]
				button $w.fe.v$i,$c -image $Dm_GrSymbol($Dm_Radio($w.$i,$c)) -command "dm_GrGetImage $w.fe.v$i,$c $w.$i,$c $opt"
#puts "$Dm_Radio($w.$i,$c) $Dm_GrSymbol($Dm_Radio($w.$i,$c))"
				grid $w.fe.v$i,$c -row $r -column $c
			}
			incr c
		}
	} err}
pack $w.fe -before $w.fb -fill x
$w.fb.ok config -command "dm_GrSetOptionsCB $w $g"
$w.fb.help config -state normal -command {dm_Help help/dm.html#grOption}
focus $w.f.v0}
proc dm_GrSetOptionsCB {w g} {global Dm_Radio Dm_GrChange
if ![winfo exists $g] return
set i 0
foreach opt {legend grid xaxis yaxis} {$g $opt config -mapped $Dm_Radio($w.f.v0.c$i)
incr i}
$g y2axis config -mapped $Dm_Radio($w.f.v0.c3)
$g legend config -pos $Dm_Radio($w.f.v1) -relief $Dm_Radio($w.f.v2)
if {$Dm_Radio($w.f.v1) == "plotarea"} {$g legend config -fg white -bd 0} else {$g legend config -fg black -bd 1}
$g xaxis config -rotate $Dm_Radio($w.f.v3)
$g yaxis config -logscale $Dm_Radio($w.f.v4)
$g y2axis config -logscale $Dm_Radio($w.f.v4)
if {[winfo class $g] == "Barchart"} {if $Dm_Radio($w.f.v5.c0) {$g config -barmode stacked} else {$g config -barmode aligned}
$g config -invertxy $Dm_Radio($w.f.v5.c1)
set opt {"" -mapped -fg}} else {if {[set maxElem [$w.f.v5 get]] < 10 || $maxElem > 100} {set maxElem 50
bell} else {::DMgraph::[string range [winfo parent $g] 1 end] configure -MaxElem $maxElem}
set opt {"" -mapped -color -symbol -linewidth}}
foreach change $Dm_GrChange($w) {scan $change %d,%d row col
if {$col == 2} {set val [$w.fe.v$row,$col cget -bg]} else {set val $Dm_Radio($w.$row,$col)}
$g element config e$row [rlindex opt $col] $val}
set Dm_GrChange($w) ""}
proc dm_Add2ChangeList {w filter} {global Dm_GrChange
if ![string match $filter* $w] return
set top [winfo toplevel $w]
if {[lsearch $Dm_GrChange($top) $w] == -1} {lappend Dm_GrChange($top) [string range $w [string length $filter] end]}}
proc dm_GetColor {w} {global Dm_Radio
set Dm_Radio(.color) [$w cget -bg]
dm_RadioBox .color color
$w config -bg $Dm_Radio(.color)}
proc dm_GrGetImage {w var opt} {global Dm_Radio Dm_GrSymbol
set box .grImage$opt
if {$opt == "-symbol"} {set imageList {none square circle diamond plus cross splus scross triangle}} else {set imageList {0 1 2 3 4}}
set Dm_Radio($box) $Dm_Radio($var)
dm_RadioBox $box image $imageList
set Dm_Radio($var) $Dm_Radio($box)
$w config -image $Dm_GrSymbol($Dm_Radio($var))}
proc dm_GrShowVal {w x y} {if [$w element closest $x $y grVal -interpolate 1] {if ![$w marker exists VALUE] {$w marker create text -name VALUE}
if {[winfo class $w] == "Barchart"} {$w marker config VALUE -mapped 1 -text [expr round($grVal(y))] -coords "[$w xaxis invtransform $x] [$w yaxis invtransform $y]"} else {set val $grVal(y)
catch {
				set time [[winfo toplevel $w] getXLabel $grVal(index)]
				append val \n$time
			}
$w marker config VALUE -mapped 1 -text $val -coords "$grVal(x) $grVal(y)"}} else {BltSetZoomPoint $w $x $y}}
proc dm_GrRemoveVal {w x y} {if [$w marker cget VALUE -mapped] {$w marker config VALUE -mapped 0} else {BltSetZoomPoint $w $x $y}}
proc dm_GrPopup {g X Y} {if ![winfo exists $g.m] {set btn [winfo toplevel $g].fBtn
menu $g.m
$g.m add command -label "Options..." -command "$btn.options invoke"
$g.m add command -label "Print..." -command "$btn.print invoke"
$g.m add command -label "Toggle Legend & Axis"}
$g.m entryconfig 2 -command "dm_GrToggle $g [expr ![$g legend cget -mapped]]"
tk_popup $g.m $X $Y}
proc dm_GrToggle {g map} {foreach o {legend xaxis yaxis y2axis} {$g $o config -mapped $map}}
proc dm_GrPrint {w {file ""}} {global Dm_Pref
if {$file == ""} {if ![file exists $Dm_Pref(/tmp)] {file mkdir $Dm_Pref(/tmp)}
set file $Dm_Pref(/tmp)/DM$w.ps}
$w postscript output $file
return $file}
class DMtable {constructor {args} {global Dm_Pref
eval configure $args
set This [frame .[info namespace tail $this] -bd 1 -relief raised -highlightthickness 1]
table $This.t -titlerows 1 -titlecols $Colt -roworigin -1 -colorigin -$Colt -rows $NumRows -cols $NumCols -var $Table -maxheight [expr [winfo screenheight .]-160] -maxwidth [expr [winfo screenwidth .]-20] -batchmode true -drawmode fast -selectmode extended -rowseparator "\n" -colseparator "\t"
$This.t tag configure title -bg black -fg white -relief sunken
$This.t tag configure sel -bg $Dm_Pref(selectColor) -fg black
$This.t tag configure tagRight -anchor e
$This.t tag configure tagLeft -anchor w
pack $This.t -anchor w
scrollbar $This.sh -orient horiz -com "$This.t xview"
scrollbar $This.sv -com "$This.t yview"}
destructor {destroy $This}
proc needScrollbars {t} {set p [winfo parent $t]
set reqHeight [expr [$t cget -rows]*([$t cget -height]+2)]
if {[winfo reqheight $t] < $reqHeight} {$t config -yscr "$p.sv set"
pack $p.sv -before $t -side right -fill y} elseif [winfo ismapped $p.sv] {pack forget $p.sv}
set width 0
set colOrigin [$t cget -colorigin]
set cols [$t cget -cols]
incr cols $colOrigin
loop c $colOrigin $cols {incr width [$t width $c]}
if {$width >= $MaxWidthInChars} {$t config -xscr "$p.sh set"
pack $p.sh -before $t -side bottom -fill x} elseif [winfo ismapped $p.sh] {pack forget $p.sh}}
method save {fName title} {global Dm_Pref
set types {
			{"Text files" .txt}
			{"All files" *}
		}
set file [tk_getSaveFile -filetypes $types -parent [winfo parent $This] -title "($Dm_Pref(devName)) - Export $title" -initialfile $fName.txt -defaultextension .txt]
if {$file == ""} return
upvar #0 [$This.t cget -var] tab
set cols [$This.t cget -cols]
set colt [$This.t cget -colorigin]
incr cols $colt
set rows [$This.t cget -rows]
set rowt [$This.t cget -roworigin]
incr rows $rowt
if [catch {set fd [open $file w]} err] {dm_Prompt .err $err Acknowledge
return}
loop r $rowt $rows {loop c $colt $cols {if [info exists tab($r,$c)] {puts -nonewline $fd $tab($r,$c)\t} else {puts -nonewline $fd \t}}
puts $fd ""}
close $fd}
public variable Table
public variable NumRows 1
public variable NumCols 10
public variable Colt 0
protected variable This
common MaxWidthInChars [expr [winfo screenwidth .]/8]}
class DMtableEdit {inherit DMtable
constructor {args} {eval DMtable::configure $args} {
		global Dm_Pref Dm_Path

		$This.t tag configure edited -bg $Dm_Pref(entryBackground) -font $Dm_Pref(changeFont)
		$This.t tag configure editable -bg $Dm_Pref(entryBackground)
		$This.t tag configure option -bg $Dm_Pref(entryBackground) -anchor w
		$This.t tag configure popup -bg $Dm_Pref(entryBackground) -anchor w

		$This.t activate 0,0
		$This.t config -browsecmd "$this hideButtons"

		menubutton $This.mb -bitmap @$Dm_Path/bitmaps/pulldown.xbm -relief raised -bd 1
		button $This.b -text "..." -pady 0 -padx 0 -highlightthickness 0

		bind $This.t <1> "$this buttonDown %x %y; break"
		bind $This.t <KeyPress> {
			if {[%W cget -state] != "normal"} break
			if [string comp {} %A] {
				%W tag celltag edited [%W index active]
				catch {[winfo toplevel %W].fBtn.apply config -state normal}
			}
		}
		bind $This.t <Control-r> "$this replicate"
		bind $This.t <Up> "$this moveCell -1 0; break"
		bind $This.t <Down> "$this moveCell 1 0; break"
		bind $This.t <Left> "$this moveCell 0 -1; break"
		bind $This.t <Right> "$this moveCell 0 1; break"
	}
method buttonDown {x y} {global Dm_Pref tkPriv
scan [$This.t index @$x,$y] %d,%d row col
if {$row < 0} {if {$Dm_Pref(tableSort) == 0} {tkTableBeginSelect $This.t $row,$col} else {upvar #0 [$This.t cget -var] tab
if [info exists tab(-4,$col)] {$This.t sort -descending -- $col
unset tab(-4,$col)} else {$This.t sort $col
set tab(-4,$col) 1}
if {$col != 0} {$This.t activate 0,0} else {$This.t activate 0,1}}
return}
$This.t selection clear all
$This.t selection set $row,$col
$This.t selection anchor $row,$col
set tkPriv(tablePrev) $row,$col
focus $This.t
if [winfo ismapped $This.mb] {place forget $This.mb}
if [winfo ismapped $This.b] {place forget $This.b}
setState $row $col
if {[lsearch [$This.t tag coltag option] $col]!=-1} {upvar #0 [$This.t cget -var] tab
if [info exists tab($row,$col)] {if {[$This.mb.m$col type 0] == "radiobutton"} {global selectedButton
set selectedButton $tab($row,$col)} else {catch {menuBitGet $This.mb.m$col $tab($row,$col)}}}
catch {
				scan [$This.t bbox $row,$col] %d%d%d%d x y width height
				place $This.mb -x [expr $x+$width-15] -y $y
				$This.mb config -menu $This.mb.m$col
				raise $This.mb
			}} elseif {[lsearch [$This.t tag coltag popup] $col]!=-1} {scan [$This.t bbox $row,$col] %d%d%d%d x y width height
place $This.b -x [expr $x+$width-[winfo reqwidth $This.b]] -y $y
raise $This.b
upvar #0 [$This.t cget -var] tab
$This.b config -command $tab(-3,$col)}}
method hideButtons {} {if [winfo ismapped $This.mb] {place forget $This.mb}
if [winfo ismapped $This.b] {place forget $This.b}}
method hide {what} {place forget $This.b}
method setPopupCmd {col cmd} {upvar #0 [$This.t cget -var] tab
set tab(-3,$col) $cmd}
method setState {row col} {if {[lsearch [$This.t tag coltag editable] $col]==-1} {set state disabled} else {set state normal}
if {[$This.t cget -state] != $state} {$This.t activate $row,$col
$This.t config -state $state}}
method moveCell {x y} {if [catch {$This.t index active row} r] return
set c [$This.t index active col]
$This.t activate [incr r $x],[incr c $y]
$This.t see active
setState $r $c}
method menuSet {l} {upvar #0 [$This.t cget -var] tab
set cell [$This.t index active]
set tab($cell) $l
$This.t tag celltag edited $cell
$This.t bestfit
catch {[winfo toplevel $This.t].fBtn.apply config -state normal}
$this hideButtons}
method menuBitSet {menu} {global Dm_Radio DmDMS
upvar #0 [$This.t cget -var] tab
set cell [$This.t index active]
set val 0
set i 0
while 1 {if [catch {set val [expr $val | $Dm_Radio($menu.$i)]}] break
incr i}
set row [lindex [split $cell ,] 0]
set col [lindex [split $cell ,] 1]
set var [rlindex tab(-2,$col) 0]
if [info exists DmDMS($var.display)] {set cc [expr -5 -$col]
set tab($row,$cc) $val
if [catch {set tab($cell) [$var.display $val]}] {set tab($cell) $val}} else {set tab($cell) $val}
$This.t tag celltag edited $cell
catch {[winfo toplevel $This.t].fBtn.apply config -state normal}}
method menuBitGet {menu val} {global Dm_Radio DmDMS
upvar #0 [$This.t cget -var] tab
set cell [$This.t index active]
set row [lindex [split $cell ,] 0]
set col [lindex [split $cell ,] 1]
set var [lindex $tab(-2,$col) 0]
set cc [expr -5 - $col]
if [info exists tab($row,$cc)] {set val $tab($row,$cc)}
set i 0
while 1 {if ![info exists Dm_Radio($menu.$i)] break
set onValue [$menu entrycget $i -onvalue]
if {[expr $val & $onValue] == $onValue} {set Dm_Radio($menu.$i) $onValue} else {set Dm_Radio($menu.$i) 0}
incr i}}
method replicate {} {upvar #0 [$This.t cget -var] tab
set src [$This.t index active]
if [info exists tab($src)] {foreach target [$This.t curselection] {set col [lindex [split $target ,] 1]
if {[lsearch [$This.t tag coltag option] $col] == -1 &&
				    [lsearch [$This.t tag coltag editable] $col] == -1} continue
set tab($target) $tab($src)
$This.t tag celltag edited $target}
catch {[winfo toplevel $This].fBtn.apply config -state normal}}}
method deleteRow {r1 r2} {upvar #0 [$This.t cget -var] tab
set cols [$This.t cget -cols]
incr cols
set diff [expr $r2-$r1+1]
set rows [expr [$This.t cget -rows]-$diff]
set row [expr $r1+$diff]
loop r $r1 $rows {loop c -1 $cols {if [info exists tab($row,$c)] {set tab($r,$c) $tab($row,$c)} else {catch {unset tab($r,$c)}}}
incr row}
$This.t config -rows $rows}}
proc dm_PollDevice {n} {global Dm_Pref Dm_PollTimerId Dm_Status
if [winfo ismapped .] {if [catch {dm_GetStatus} errMsg] {set Dm_Status "Poll failed; $errMsg"
return}}
set Dm_PollTimerId [after [expr $n*1000] dm_PollDevice $n]}
proc dm_GetStatus {} {global Dm_StatusList
foreach s [array names Dm_StatusList] {set sess [lindex [split $s .] 0]
if [catch {$sess expr "dm_GetStatusCB $s" $Dm_StatusList($s)} err] {error "[rlindex err 2] ($sess)"}}}
proc dm_GetStatusCB {sIndex sess reqid errStat errIdx resp} {global Dm_WinInst Dm_StatusWinList DmDMS Dm_Status Dm_Path
if ![info exists Dm_StatusWinList($sIndex)] return
if {$errStat != "noError"} {if {$errStat == "tooBig" ||
		    (![info exists DmDMS(gotResponse.$sIndex)] && 
		    $errStat == "timeout" && 
		    [llength $Dm_StatusWinList($sIndex)]>=16)} {dm_SplitStatusList $sIndex
global Dm_PollTimerId Dm_Pref
catch {after cancel $Dm_PollTimerId}
set n $Dm_Pref(pollFreq)
set Dm_PollTimerId [after [expr $n*1000] dm_PollDevice $n]
return} elseif {$errStat == "timeout"} {foreach i $Dm_StatusWinList($sIndex) {catch {
					set obj [rlindex Dm_WinInst($i) 0]
					set fName $DmDMS($obj.bitmap)
					if [string match *.gif $fName] {
						.chassis itemconfig $i -image [dm_GetImage $fName]
					} else {
						.chassis itemconfig $i -foreground black
					}	
				}}}
if $errIdx {incr errIdx -1
lappend errStat [dm_GetNameFromOid [lindex [rlindex resp $errIdx] 0]]}
set Dm_Status "poll failed: $errStat"
return}
set DmDMS(gotResponse.$sIndex) 1
if [string match poll* $Dm_Status] {set Dm_Status ""}
set i 0
set statusList ""
foreach status $resp {set win [rlindex Dm_StatusWinList($sIndex) $i]
if {$win == -1} {global Dm_SysUpTime Dm_SysUpTimeOrig
if {$status < $Dm_SysUpTimeOrig} {dm_Rediscover
set Dm_Status "System reboot since last poll"
set Dm_SysUpTimeOrig $status
set Dm_SysUpTime [timeticks clock $status]
return}} else {set obj [rlindex Dm_WinInst($win) 0]
if [info exists DmDMS($obj.statusProc)] {set inst [rlindex Dm_WinInst($win) 1]
if {$DmDMS(Chassis.isStack) == 1} {eval $DmDMS($obj.statusProc) $sess $status $obj $inst} else {eval $DmDMS($obj.statusProc) $sess $status}} elseif [info exists DmDMS($obj.status==$status)] {set sList $DmDMS($obj.status==$status)
switch [rlindex sList 0] {
				"bitmap" {.chassis itemconfig $win -image [dm_GetImage [rlindex sList 1]]}
				"color" {.chassis itemconfig $win -foreground [rlindex sList 1]}
				"proc" {[rlindex sList 1] $sess $obj [rlindex Dm_WinInst($win) 1] $win $status}
				}
lappend statusList $status} else {if [string match *.gif $DmDMS($obj.bitmap)] {.chassis itemconfig $win -image [dm_GetImage $DmDMS($obj.bitmap)]} else {.chassis itemconfig $win -foreground black}}}
incr i}
if {$DmDMS(Chassis.isStack) == 1 && [info exists DmDMS(Card.endStatusProc)]} {eval $DmDMS(Card.endStatusProc) $inst {$statusList}}
if [info exists DmDMS(Chassis.endStatusProc)] {eval $DmDMS(Chassis.endStatusProc) {$statusList}}}
proc dm_SplitStatusList {sIndex} {global Dm_StatusWinList Dm_StatusList
set len [expr [llength $Dm_StatusList($sIndex)]/2]
if {$len<1} return
set sess [lindex [split $sIndex .] 0]
set n [lindex [split $sIndex .] 1]
set Dm_StatusList($sess.$n-0) [lrange $Dm_StatusList($sIndex) 0 $len]
set Dm_StatusWinList($sess.$n-0) [lrange $Dm_StatusWinList($sIndex) 0 $len]
set Dm_StatusList($sess.$n-1) [lrange $Dm_StatusList($sIndex) [incr len] end]
set Dm_StatusWinList($sess.$n-1) [lrange $Dm_StatusWinList($sIndex) $len end]
unset Dm_StatusList($sIndex) Dm_StatusWinList($sIndex)
$sess expr "dm_GetStatusCB $sess.$n-0" $Dm_StatusList($sess.$n-0)
$sess expr "dm_GetStatusCB $sess.$n-1" $Dm_StatusList($sess.$n-1)}
proc dm_RecordTrap {time trap vbList} {upvar $vbList vbl
global Dm_SysUpTime Dm_Pref DmDMS
set w .trap
if ![winfo exists $w] {dm_CreateLogWin $w}
set varBind ""
foreach vb $vbl {set var [snmpinfo mibprop [rlindex vb 0] descriptor]
set val [rlindex vb 2]
if {[rlindex vb 1] == "ObjectId"} {set val [dm_GetNameFromOid $val]} elseif {[snmpinfo mibprop $var type] == "InterfaceIndex"} {catch {set val [dmsIfIndex2Port $val]}} else {foreach e [snmpinfo mibprop $var enums] {if {[rlindex e 0] == $val} {set val [rlindex e 1]
break}}}
if [info exists DmDMS($var.namedisplay)] {set var [$var.namedisplay $var]}
append varBind " $var=$val"}
if {[set time [expr $time-[timeticks ticks $Dm_SysUpTime]]] < 0} {set time 0}
MultiListbox:insert $w.fList [list "[timeticks now $time]" $trap "$varBind"]
MultiListbox:op $w.fList see end
if {[set num [$w.fList.list0 index end]] > $Dm_Pref(trapLogSize)} {MultiListbox:op $w.f.l delete 0
incr num -1}
$w.status config -text "$num rows(s)"}
proc dm_ShowLog {w} {if ![winfo exists $w] {dm_CreateLogWin $w
wm geom $w "+[winfo pointerx .]+[winfo pointery .]"}
wm deiconify $w
focus $w.fBtn.cancel
raise $w}
proc dm_CreateLogWin {w} {global Dm_Pref tcl_platform
toplevel $w
if {$tcl_platform(platform) == "unix"} {wm transient $w .}
wm withdraw $w
wm title $w "$Dm_Pref(progName) - [winfo name $w] Log"
wm protocol $w WM_DELETE_WINDOW "$w.fBtn.cancel invoke"
MultiListbox:create $w.fList {Time {-width 22}} {Type {-width 17}} {Description {-width 40}}
$w.fList.header.h2 config -width 0
pack [label $w.status -bd 0] -in $w.fList.header -side right
pack $w.fList -fill both -expand 1
frame $w.fBtn -class FBtn
button $w.fBtn.save -text Save... -command "dm_SaveLog $w"
menubutton $w.fBtn.clear -text Clear -bd 1 -padx 8 -relief raised -menu $w.fBtn.clear.m
menu $w.fBtn.clear.m
foreach opt {all selected coldStart warmStart linkUp linkDown authenticationFailure risingAlarm fallingAlarm} {$w.fBtn.clear.m add command -label $opt -command "dm_LogClear $w 1 $opt"}
button $w.fBtn.cancel -command "wm withdraw $w"
pack $w.fBtn.save $w.fBtn.clear $w.fBtn.cancel -pady 5 -side left
pack $w.fBtn
bind $w <Escape> "$w.fBtn.cancel invoke"}
proc dm_SaveLog {w} {set types {
		{"Log files" .log}
		{"All files" *}
	}
set file [tk_getSaveFile -filetypes $types -parent $w -title "[wm title $w] Save" -initialfile [winfo name $w].log -defaultextension .log]
if {$file == ""} return
if [catch {
		set fd [open $file w]
		puts $fd [MultiListbox:get $w.fList -1]
		loop i 0 [$w.fList.list0 index end] {
			puts $fd [MultiListbox:get $w.fList $i]
		}
		close $fd
		$w.status config -text "Saved"
	} err] {dm_Prompt .err $err Continue}}
proc dm_LogClear {w listNo what} {if {$what == "all"} {MultiListbox:op $w.fList delete 0 end} elseif {$what == "selected"} {if {[set sel [$w.fList.list0 curselection]] != ""} {MultiListbox:op $w.fList delete $sel $sel}} else {set i 0
set max [$w.fList.list$listNo index end]
while {$i <= $max} {if {[$w.fList.list$listNo get $i] == $what} {MultiListbox:op $w.fList delete $i
incr max -1} else {incr i}}}
$w.status config -text "[$w.fList.list0 index end] rows(s)"}
proc dm_About {} {global Dm_Pref Dm_Path Dm_BuildTime Dm_Vendor
set w .about
if [winfo exists $w] {wm deiconify $w
raise $w
return}
toplevel $w
wm withdraw $w
wm title $w "$Dm_Pref(progName) - About"
wm protocol $w WM_DELETE_WINDOW "$w.cancel invoke"
wm resizable $w 0 0
wm transient $w .
canvas $w.c -highlightthickness 0
$w.c xview moveto 0
$w.c xview moveto 0
if [catch {image type logo}] {if [file readable $Dm_Path/bitmaps/logo.gif] {image create photo logo -file $Dm_Path/bitmaps/logo.gif}}
if ![catch {image type logo}] {set b [$w.c create image 0 0 -anchor nw -image logo]
scan [$w.c bbox $b] "%d%d%d%d" x y width height
$w.c config -width $width -height $height
pack $w.c}
if [info exists Dm_Vendor] {set msg "(c) 1997-1999 $Dm_Vendor\n"} else {set msg ""}
append msg "Built: $Dm_BuildTime"
pack [label $w.l -text $msg] -side left
pack [button $w.cancel -text Close -command "destroy $w"] -side right
bind $w <Escape> "$w.cancel invoke"
bind $w <Return> "$w.cancel invoke"
wm geom $w "+[winfo pointerx .]+[winfo pointery .]"
dm_OnScreen $w}
proc Blt_ActiveLegend {g} {global bltActiveEntry
set bltActiveEntry($g) "-1"
bind $g <Motion> {BltActivateLegend %W %x %y}}
proc BltActivateLegend { g x y } {global bltActiveEntry
set old $bltActiveEntry($g)
set new [$g legend get @$x,$y]
if { $old != $new } {if { $old != "-1" } {$g legend deactivate $old
$g element deactivate $old}
if { $new != "" } {$g legend activate $new
$g element activate $new}}
set bltActiveEntry($g) $new}
proc Blt_ZoomStack { graph } {global bltZoom Dm_Path
set bltZoom($graph,A,x) {}
set bltZoom($graph,A,y) {}
set bltZoom($graph,B,x) {}
set bltZoom($graph,B,y) {}
set bltZoom($graph,stack) {}
set bltZoom($graph,corner) A
button $graph.unzoom -bitmap @$Dm_Path/bitmaps/unzoom.xbm -command "BltPopZoom $graph"}
proc BltGetCoords { graph x y index } {set coords [$graph invtransform $x $y]
set x [lindex $coords 0]
set y [lindex $coords 1]
scan [$graph xaxis limits] "%s %s" xmin xmax
scan [$graph yaxis limits] "%s %s" ymin ymax
if { $x > $xmax } {set x $xmax} elseif {$x < $xmin} {set x $xmin}
if { $y > $ymax } {set y $ymax} elseif {$y < $ymin} {set y $ymin}
global bltZoom
set bltZoom($graph,$index,x) $x
set bltZoom($graph,$index,y) $y}
proc BltPopZoom { graph } {global bltZoom
set zoomStack $bltZoom($graph,stack)
if { [llength $zoomStack] > 0 } {set cmd [lindex $zoomStack 0]
set bltZoom($graph,stack) [lrange $zoomStack 1 end]
eval $cmd
BltZoomTitleLast $graph
set cmd [format {
	    if { $bltZoom(%s,corner) == "A" } {
		%s marker delete "bltZoom_title"
	    }
	} $graph $graph]
after 2000 $cmd
if {[llength $bltZoom($graph,stack)] == 0} {$graph marker delete "bltZoom_title"
place forget $graph.unzoom
$graph y2axis config -mapped 1}}}
proc BltPushZoom { graph } {$graph marker delete "bltZoom_*"
global bltZoom
set x1 $bltZoom($graph,A,x)
set y1 $bltZoom($graph,A,y)
set x2 $bltZoom($graph,B,x)
set y2 $bltZoom($graph,B,y)
if { ($x1 == $x2) && ($y1 == $y2) } {return}
set cmd [format {
	%s xaxis configure -min "%s" -max "%s"
	%s yaxis configure -min "%s" -max "%s"
    } $graph [$graph xaxis cget -min] [$graph xaxis cget -max] $graph [$graph yaxis cget -min] [$graph yaxis cget -max]]
if { $x1 > $x2 } {$graph xaxis configure -min $x2 -max $x1} elseif {$x1 < $x2} {$graph xaxis configure -min $x1 -max $x2}
if { $y1 > $y2 } {$graph yaxis configure -min $y2 -max $y1} elseif {$y1 < $y2} {$graph yaxis configure -min $y1 -max $y2}
set bltZoom($graph,stack) [linsert $bltZoom($graph,stack) 0 $cmd]
place $graph.unzoom -x 2 -y 22
$graph y2axis config -mapped 0}
proc BltResetZoom { graph } {global bltZoom
$graph marker delete "bltZoom_*"
if { $bltZoom($graph,corner) == "A" } {BltPopZoom $graph} else {set bltZoom($graph,corner) A}}
proc BltZoomTitleNext { graph } {global bltZoom
set level [expr [llength $bltZoom($graph,stack)] + 1]
set title "Zoom #$level"
$graph marker create text -name "bltZoom_title" -text $title -coords {-Inf Inf} -anchor nw -bg {} -fg white}
proc BltZoomTitleLast { graph } {global bltZoom
set level [llength $bltZoom($graph,stack)]
if { $level > 0 } {set title "Zoom #$level"
$graph marker create text -name "bltZoom_title" -text $title -coords {-Inf Inf} -anchor nw -bg {} -fg white}}
proc BltSetZoomPoint { graph x y } {global bltZoom
BltGetCoords $graph $x $y $bltZoom($graph,corner)
if { $bltZoom($graph,corner) == "A" } {BltZoomTitleNext $graph
bind $graph <B1-Motion> {
	    BltGetCoords %W %x %y B
	    BltBox %W
	}
set bltZoom($graph,corner) B} else {bind $graph <B1-Motion> { }
BltPushZoom $graph
set bltZoom($graph,corner) A}}
proc BltBox { graph } {global bltZoom
if { $bltZoom($graph,A,x) > $bltZoom($graph,B,x) } {set x1 $bltZoom($graph,B,x)
set x2 $bltZoom($graph,A,x)
set y1 $bltZoom($graph,B,y)
set y2 $bltZoom($graph,A,y)} else {set x1 $bltZoom($graph,A,x)
set x2 $bltZoom($graph,B,x)
set y1 $bltZoom($graph,A,y)
set y2 $bltZoom($graph,B,y)}
set coords {
	$x1 $y1 $x1 $y2 $x1 $y1 $x2 $y1 $x2 $y1 $x2 $y2 $x1 $y2 $x2 $y2 
    }
if [$graph marker exists "bltZoom_outline"] {$graph marker configure "bltZoom_outline" -coords $coords} else {$graph marker create line -coords $coords -name "bltZoom_outline" -foreground yellow}
$graph marker before "bltZoom_outline"}
proc dm_BuildPromptPort {t col} {global Dm_Pref Dm_Radio
set w .pp
if [winfo exists $w] {raise $w} else {toplevel $w
dm_transient $w [winfo toplevel $t]
wm geom $w "+[winfo pointerx .]+[winfo pointery .]"
wm resizable $w 0 0
dm_CreatePortPicker $w.f
frame $w.fBtn -class FBtn
button $w.fBtn.ok -text Ok
button $w.fBtn.cancel -text Cancel -command "destroy $w"
pack $w.fBtn.cancel $w.fBtn.ok -side right -pady 5
pack $w.f $w.fBtn
bind $w <Escape> "$w.fBtn.cancel invoke"
bind $w <Return> "$w.fBtn.ok invoke"}
set row [$t index active row]
upvar #0 [$t cget -var] tab
$w.fBtn.ok config -command "dm_BuildPromptPortCB $w $t $row $col"
wm title $w "($Dm_Pref(devName)) - $tab($row,-1) PortMembers"
catch {dm_PortSetDisplay $w.f [port parse [list $tab($row,$col)]]}}
proc dm_BuildPromptPortCB {w t row col} {global Dm_Radio
if ![winfo exists $t] return
set ports [dm_GetPortPicker $w.f]
upvar #0 [$t cget -var] tab
set tab($row,$col) [port print [bit parse $ports] range]
$t tag celltag edited $row,$col
[winfo toplevel $t].fBtn.apply config -state normal
[winfo toplevel $t].fBtn.apply invoke
destroy $w}
proc dm_CreatePortPicker {f} {global Dm_PortPicker Dm_WinInst Dm_Radio Dm_Pref
set instList ""
foreach i [lsort -integer [array names Dm_WinInst]] {if [string match Port* [rlindex Dm_WinInst($i) 0]] {lappend instList [dmsIfIndex2Port [rlindex Dm_WinInst($i) 1]]}}
frame $f -bd 1 -relief sunken
set slots ""
set numPorts 0
foreach inst $instList {scan $inst %d/%d cardNo portNo
if {[lsearch $slots $cardNo] == -1} {lappend slots $cardNo}
set Dm_Radio($f.c$numPorts) -1
checkbutton $f.c$numPorts -indicatoron 0 -onvalue [dmsIndexPort $inst] -text $portNo -selectcolor white -variable Dm_Radio($f.c$numPorts)
bind $f.c$numPorts <1> "dm_PortPickerSet $f.c$numPorts"
grid $f.c$numPorts -row [lindex [split $inst /] 0] -column [lindex [split $inst /] 1]
incr numPorts}
set Dm_PortPicker($f.numPorts) $numPorts
foreach s $slots {button $f.l$s -text $s/ -font $Dm_Pref(boldFont) -padx 1 -pady 1 -command "dm_PortPickerRowCB $f $s"
grid $f.l$s -row $s -column 0 -sticky e}}
proc dm_PortPickerRowCB {f row} {global Dm_Radio
foreach cb [grid slaves $f -row $row] {if {[winfo class $cb] != "Checkbutton"} continue
if ![info exists on] {if $Dm_Radio($cb) {set on 0} else {set on 1}}
if {[$cb cget -state] == "normal"} {if $on {set Dm_Radio($cb) [$cb cget -onvalue]} else {set Dm_Radio($cb) 0}}}}
proc dm_PortSetDisplay {f instList} {global Dm_PortPicker Dm_Radio Dm_Pref
set instList [bit print $instList]
loop i 0 $Dm_PortPicker($f.numPorts) {set inst [$f.c$i cget -onvalue]
if {[lsearch $instList $inst] != -1} {set Dm_Radio($f.c$i) $inst} else {set Dm_Radio($f.c$i) 0}
$f.c$i config -font $Dm_Pref(normalFont)}}
proc dm_PortSetEnable {f instList} {global Dm_PortPicker Dm_Radio Dm_Pref
set instList [bit print $instList]
loop i 0 $Dm_PortPicker($f.numPorts) {set inst [$f.c$i cget -onvalue]
if {[lsearch $instList $inst] != -1} {$f.c$i config -state normal} else {$f.c$i config -state disabled}}}
proc dm_GetPortPicker {f} {global Dm_Radio Dm_PortPicker
set ports ""
loop i 0 $Dm_PortPicker($f.numPorts) {if {$Dm_Radio($f.c$i) > -1} {lappend ports $Dm_Radio($f.c$i)}}
return $ports}
proc dm_PromptPortPicker {} {global Dm_PickedPort Dm_WinInst Dm_Pref
foreach i [lsort -integer [array names Dm_WinInst]] {if [string match Port* [rlindex Dm_WinInst($i) 0]] {lappend instList [dmsIfIndex2Port [rlindex Dm_WinInst($i) 1]]}}
if {$instList == ""} {return ""}
set w .rcPort
toplevel $w -highlightthickness 1
wm withdraw $w
wm overrideredirect $w 1
grid [label $w.l -text "Which Port?"] -row 0 -column 1 -columnspan 16 -sticky w
set Dm_PickedPort ""
set slots ""
set i 0
foreach inst $instList {scan $inst %d/%d cardNo portNo
if {[lsearch $slots $cardNo] == -1} {lappend slots $cardNo}
radiobutton $w.r$i -indicatoron 0 -variable Dm_PickedPort -value $inst -text $portNo
grid $w.r$i -row $cardNo -column $portNo
incr i}
foreach s $slots {grid [label $w.l$s -text $s/ -font $Dm_Pref(boldFont)] -row $s -column 0 -sticky e}
bind $w <1> {set Dm_PickedPort [set Dm_PickedPort]}
bind $w <Escape> {set Dm_PickedPort ""}
dm_OnScreen $w
focus $w
grab $w
vwait Dm_PickedPort
grab release $w
destroy $w
return $Dm_PickedPort}
proc dmBuildIdList {nameIds w} {global Dm_Radio
frame $w -bd 1 -relief sunken
canvas $w.c -scrollregion {0 0 200 180} -width 250 -height 200 -yscrollcommand "$w.vs set"
scrollbar $w.vs -command "$w.c yview"
pack $w.vs -side right -fill y
pack $w.c -side left -expand 1 -fill both
set nameIds [lsort -command dmCompareIds $nameIds]
set i 0
foreach pair $nameIds {set id [lindex $pair 0]
set name [lindex $pair 1]
set Dm_Radio($w.c.c$i) 0
checkbutton $w.c.c$i -text "($id) $name" -variable Dm_Radio($w.c.c$i) -on $id
$w.c create window 2 [expr 17*$i] -window $w.c.c$i -anchor nw
incr i}
$w.c config -scrollregion "0 0 200 [expr 17*$i]"
$w.c yview moveto 0}
proc dmIdListInsertApply {source {target {}}} {global Dm_Radio
foreach cb [winfo children $source] {if $Dm_Radio($cb) {if ![info exists filterIdList] {set filterIdList $Dm_Radio($cb)} else {append filterIdList ,$Dm_Radio($cb)}}}
if ![info exists filterIdList] {set filterIdList {}}
if {$target != ""} {$target delete 0 end
$target insert 0 $filterIdList} else {return $filterIdList}}
proc dmShowIdListWindow {w t nameIds} {global Dm_Pref Dm_Radio
if [dm_MakeDlg $w "" {}] {wm deiconify $w
raise $w} else {dm_transient $w [winfo toplevel $t]
set gw [winfo parent [winfo parent $t]]
wm title $w "($Dm_Pref(devName)) - ID List"
wm resizable $w 0 0
dmBuildIdList $nameIds $w.f.f0
pack $w.f.f0}
upvar #0 [$t cget -var] tab
set row [$t index active row]
set col [$t index active col]
set selIds $tab($row,$col)
set sids [split $selIds ,]
foreach sid $sids {foreach cb [winfo children $w.f.f0.c] {set ltext [$cb cget -text]
if {[string last "($sid)" $ltext] != -1} {$cb select
break}}}
$w.fb.ok config -command "dmIdListUpdateApply $w $t $row $col; [$w.fb.ok cget -command]"
$w.fb.cancel config -command "destroy $w"}
proc dmIdListUpdateApply {w t row col} {global Dm_Radio
upvar #0 [$t cget -var] tab
set nameIds [dmIdListInsertApply $w.f.f0.c {}]
set tab($row,$col) $nameIds
$t tag celltag edited $row,$col
[winfo toplevel $t].fBtn.apply config -state normal
[winfo toplevel $t].fBtn.apply invoke
destroy $w}
proc dmCompareIds {first second} {set id1 [lindex $first 0]
set id2 [lindex $second 0]
return [expr $id1 - $id2]}
proc Main {argc av} {upvar $av argv
global Dm_Pref Dm_ID DmDMS Dm_Path Dm_Version Dm_Selection Dm_Launcher env
set Dm_Pref(devName) ""
set Dm_Selection(win) {}
set Dm_Selection(box) {}
if [catch {set Dm_Path $env(DMPATH)} err] {set Dm_Path .}
if ![info exists env(HOME)] {set env(HOME) $Dm_Path}
if [catch {
		source $Dm_Path/dmid.tcl
		source $Dm_Path/dm.ini
		source $Dm_Path/lib/dmdialog.tcl
		source $Dm_Path/lib/dmprint.tcl
	} rc] {tk_dialog .err "" $rc error 0 Exit
exit}
set Dm_Pref(progName) "Device Manager ($Dm_Version)"
set Dm_Pref(trace) 0
set Dm_Pref(showDNSName) 0
set Dm_Pref(promptSNMPError) 0
set Dm_Pref(tableSort) 0
if [catch {source $env(HOME)/.dmrc}] {set Dm_Pref(pollFreq) 15
set Dm_Pref(hotswapFreq) 30
set Dm_Pref(retries) 3
set Dm_Pref(timeout) 3
set Dm_Pref(rtrqos) linear
set Dm_Pref(debug) 0
set Dm_Pref(trapLogSize) 500}
dm_MainWin
loop i 0 $argc {switch -exact -- [rlindex argv $i] {-rd {incr i
			 set comm [rlindex argv $i]
			 if {$comm != "\\\""} {
				 set Dm_Pref(readComm) $comm
			 }
			}
-wr {incr i
			 set comm [rlindex argv $i]
			 if {$comm != "\\\""} {
				 set Dm_Pref(writeComm) $comm
			 }
			}
-t {incr i; set Dm_Pref(timeout) [rlindex argv $i]}
-r {incr i; set Dm_Pref(retries) [rlindex argv $i]}
-P {incr i; set Dm_Pref(pollFreq) [rlindex argv $i]}
-hs {incr i; set Dm_Pref(hotswapFreq) [rlindex argv $i]
			 if {Dm_Pref(hotswapFreq) < 30} {
				set Dm_Pref(hotswapFreq) 30
			 }
			}
-ov {set Dm_Pref(nmsplatform) ov}
-snm {set Dm_Pref(nmsplatform) snm}
-trace {set Dm_Pref(trace) 1}
default {set Dm_Pref(devName) [rlindex argv $i]
			if [info exists env(OVServer)] {
				# We're running under HPOV; fetch snmpConf
				if {[set db [snmpinfo nmsprop $Dm_Pref(devName)]] != ""} {
					set Dm_Pref(readComm) [rlindex db 0]
					set Dm_Pref(writeComm) [rlindex db 1]
					set Dm_Pref(timeout) [rlindex db 2]
				}
			}
			}}}
if !$Dm_Pref(trace) {proc bgerror err {global Dm_Status
set Dm_Status $err}}
if {$Dm_Pref(pollFreq) > 0 &&
            [set minPoll [expr $Dm_Pref(timeout)*$Dm_Pref(retries)]] >= $Dm_Pref(pollFreq)} {set Dm_Pref(pollFreq) [incr minPoll]}
if {$Dm_Pref(devName) != ""} {dm_Open $Dm_Pref(devName) $Dm_Pref(readComm) $Dm_Pref(writeComm)}}
proc dm_MainWin {} {global Dm_Status Dm_Pref Dm_Path tcl_platform env
wm title . $Dm_Pref(progName)
wm protocol . WM_DELETE_WINDOW dm_Quit
wm resizable . 0 0
frame .mBar -class Menubar
menubutton .mBar.file -text Device -und 0 -menu .mBar.file.m
menu .mBar.file.m
.mBar.file.m add command -label "Open..." -und 0 -command dm_DlgOpen -accelerator Ctrl+O
bind . <Control-o> dm_DlgOpen
.mBar.file.m add cascade -label "Open Last" -und 5 -menu .mBar.file.m.h -state disabled
menu .mBar.file.m.h -tearoff 1
if ![catch {set fd [open $env(HOME)/.dmlastopen r]}] {while {[set line [gets $fd]] != ""} {.mBar.file.m.h add command -label [rlindex line 0] -command "dm_Open $line"}
close $fd
.mBar.file.m entryconfigure 1 -state normal}
.mBar.file.m add separator
.mBar.file.m add command -label "Properties..." -und 7 -command dm_ShowPref
.mBar.file.m add command -label "Refresh" -und 0 -state disabled -command dm_Rediscover
.mBar.file.m add command -label "Trap Log..." -und 0 -state disabled -command "dm_ShowLog .trap"
if {$tcl_platform(os) == "SunOS"} {.mBar.file.m add separator
.mBar.file.m add command -label "Print Chassis..." -und 0 -state disabled -accelerator Ctrl+P -command {dm_Print "dm_PrintChassis .chassis"}
bind . <Control-p> {dm_Print "dm_PrintChassis .chassis"}}
.mBar.file.m add separator
.mBar.file.m add command -label "Exit" -und 1 -command dm_Quit -accelerator Alt+F4
menubutton .mBar.edit -text Edit -state disabled -und 0 -menu .mBar.edit.m
menubutton .mBar.graph -text Graph -state disabled -und 0 -menu .mBar.graph.m
pack .mBar.file -side left
menubutton .mBar.help -text Help -und 0 -menu .mBar.help.m
menu .mBar.help.m
.mBar.help.m add command -label "Contents..." -und 0 -command {dm_Help help/dm.html} -accelerator F1
bind . <F1> {dm_Help help/dm.html}
.mBar.help.m add command -label "Device..." -und 0 -state disabled
.mBar.help.m add cascade -label "Legend" -und 0 -menu .mBar.help.m.l
menu .mBar.help.m.l -tearoff 1 -fg black
foreach color $Dm_Pref(statusColor) {.mBar.help.m.l add command -label [rlindex color 0] -background [rlindex color 1]}
.mBar.help.m add separator
.mBar.help.m add command -label "About Device Manager..." -und 0 -command dm_About
if {$tcl_platform(platform) == "unix"} {pack .mBar.help -side right
bind . <Alt-F4> dm_Quit
catch {wm iconbitmap . @$Dm_Path/bitmaps/logo.xbm}} else {pack .mBar.help -side left
pack [label .mBar.blank -text "       "] -side left
catch {info hostname}}
pack .mBar -fill x
frame .tBar -class Toolbar -highlightthickness 0
set i 0
foreach {text file command} {
		"Open Device" open.gif dm_DlgOpen
		"Help" help.gif {dm_Help help/dm.html}} {image create photo img$i -file $Dm_Path/bitmaps/$file
button .tBar.b$i -image img$i -text $text -command $command
pack .tBar.b$i -side left
dm_ToolTipBind .tBar.b$i
incr i}
label .tBar.sep
pack .tBar.sep -side left
pack .tBar -fill x
pack [frame .fC]
label .status -relief sunken -anchor w -textvariable Dm_Status
pack .status -fill x}
proc dm_Quit {} {global DmDMS env
if [info exists DmDMS(Chassis.closeDeviceProc)] {if {[set ans [$DmDMS(Chassis.closeDeviceProc)]] == -1} return}
if {[.mBar.file.m entrycget 1 -state] == "normal"} {if ![catch {set fd [open $env(HOME)/.dmlastopen w]}] {set num [.mBar.file.m.h index last]
loop i 1 [incr num] {set cmd [.mBar.file.m.h entrycget $i -command]
puts $fd [string range $cmd 8 end]}
close $fd}}
catch {snmpexit}
exit}
proc dm_NeedScrollbars {w} {set scrW [winfo screenwidth .]
set canW [$w cget -width]
if {$canW > $scrW} {set scrollW $scrW} else {set scrollW $canW}
if {$canW > $scrW} {$w config -xscrollcommand ".fC.sbh set"
if ![winfo exists .fC.sbh] {scrollbar .fC.sbh -orient horiz -command "$w xview"}
pack .fC.sbh -side bottom -fill x}
set scrH [winfo screenheight .]
incr scrH -100
set canH [winfo reqheight $w]
if {$canH > $scrH} {set scrollH $scrH} else {set scrollH $canH}
if {$canH > $scrH} {$w config -yscrollcommand ".fC.sbv set"
if ![winfo exists .fC.sbv] {scrollbar .fC.sbv -command "$w yview"}
pack .fC.sbv -side right -fill y}
if {$canW > $scrW || $canH > $scrH} {$w config -width $scrollW -height $scrollH -scrollregion "0 0 $canW $canH"}
pack $w -in .fC -fill both -expand 1}
proc dm_ItemMark {w x y} {global Dm_bbAreaX1 Dm_bbAreaY1
set Dm_bbAreaX1 [$w canvasx $x]
set Dm_bbAreaY1 [$w canvasy $y]}
proc dm_ItemStroke {w x y} {global Dm_bbAreaX1 Dm_bbAreaY1 Dm_Pref
if ![info exists Dm_bbAreaX1] return
set x [$w canvasx $x]
set y [$w canvasy $y]
if {$Dm_bbAreaX1 != $x && $Dm_bbAreaY1 != $y} {if {[$w find withtag marquee] == ""} {$w create rect $Dm_bbAreaX1 $Dm_bbAreaY1 $x $y -outline $Dm_Pref(selectColor) -width 2 -tag marquee} else {$w coords marquee $Dm_bbAreaX1 $Dm_bbAreaY1 $x $y}}}
proc dm_SelectClick {w c x y} {global DmDMS
if $DmDMS([lindex [$w itemcget $c -tags] 0].isSelect) {dm_Select $w $c} else {set over [$w find overlapping $x $y $x $y]
for {set i [expr [llength $over]-1]} {$i >= 0} {incr i -1} {set c [rlindex over $i]
if $DmDMS([lindex [$w itemcget $c -tags] 0].isSelect) {dm_Select $w $c
break}}}}
proc dm_ItemsUnderArea {w} {global DmDMS
if {[set bbox [$w bbox marquee]] == ""} return
$w delete marquee
set first 1
foreach c [eval $w find enclosed $bbox] {set class [lindex [$w itemcget $c -tags] 0]
if {[info exists DmDMS($class.isSelect)] && $DmDMS($class.isSelect)} {if $first {dm_Select $w $c
set first 0} else {dm_AdjSelect $w $c}}}}
proc dm_SelectAll {w class} {set first 1
foreach c [$w find withtag all] {if ![string match $class* [$w itemcget $c -tags]] continue
if $first {dm_Select $w $c} else {dm_AdjSelect $w $c}
set first 0}}
proc dm_Select {w c} {global Dm_Selection Dm_WinInst
set Dm_Selection(win) {}
dm_MenuDeselect
foreach s $Dm_Selection(box) {$w delete $s}
set Dm_Selection(box) {}
set Dm_Selection(class) [lindex [split [rlindex Dm_WinInst($c) 0] ::] 0]
set Dm_Selection(sess) [rlindex Dm_WinInst($c) 2]
dm_AdjSelect $w $c}
proc dm_AdjSelect {w c} {global Dm_Selection Dm_WinInst Dm_Pref Dm_Status
if ![info exists Dm_Selection(class)] return
if ![info exists Dm_WinInst($c)] return
if {$Dm_Selection(class) != [lindex [split [rlindex Dm_WinInst($c) 0] ::] 0]} return
if {$Dm_Selection(sess) != [rlindex Dm_WinInst($c) 2]} return
if {[set i [lsearch $Dm_Selection(win) $c]]!=-1} {$w delete [rlindex Dm_Selection(box) $i]
set Dm_Selection(win) [lreplace $Dm_Selection(win) $i $i]
set Dm_Selection(box) [lreplace $Dm_Selection(box) $i $i]
dm_MenuDeselect
foreach c $Dm_Selection(win) {dm_MenuContext $c}
return}
lappend Dm_Selection(win) $c
lappend Dm_Selection(box) [eval $w create rectangle [$w bbox $c] -outline $Dm_Pref(selectColor) -width 2]
dm_MenuContext $c}
proc dm_MenuContext {c} {global Dm_WinInst
set base [lindex [split [rlindex Dm_WinInst($c) 0] ::] 0]
foreach m {.mBar.edit.m .mBar.graph.m} {if ![winfo exists $m] continue
loop i 0 [expr [$m index last]+1] {if {[$m type $i] == "separator"} break
if {[$m entrycget $i -label]==$base} {$m entryconfig $i -state normal}}}}
proc dm_MenuDeselect {} {foreach m {.mBar.edit.m .mBar.graph.m} {if ![winfo exists $m] continue
loop i 0 [expr [$m index last]+1] {if {[$m type $i] == "separator"} break
$m entryconfig $i -state disabled}}}
proc dm_PostMenu {w X Y x y} {global Dm_WinInst Dm_Selection
set c [$w find withtag current]
if {[lsearch $Dm_Selection(win) $c] == -1} {if [catch {dm_Select $w [set c [dm_SelectContainer $w $c $x $y]]}] return}
set class [rlindex Dm_WinInst($c) 0]
if ![winfo exists $w.pMenu$class] {set class [lindex [split $class ::] 0]}
if ![winfo exists $w.pMenu$class] return
if {[llength $Dm_Selection(win)] > 1 || [set inst [rlindex Dm_WinInst($c) 1]]==0} {set inst ""}
$w.pMenu$class entryconfig 0 -label [string toupper "$class $inst"]
tk_popup $w.pMenu$class $X $Y}
proc dm_SelectContainer {w c x y} {global DmDMS
if !$DmDMS([lindex [$w itemcget $c -tags] 0].isSelect) {set over [$w find overlapping $x $y $x $y]
set parentIndex [expr [llength $over]-1]
while !$DmDMS([lindex [$w itemcget $c -tags] 0].isSelect) {incr parentIndex -1
if {$parentIndex<0} break
set c [rlindex over $parentIndex]}}
return $c}
proc dm_ClearSelection {} {global Dm_Selection
set Dm_Selection(win) {}
set Dm_Selection(box) {}}
proc dm_GetSelInst {class} {global Dm_WinInst Dm_Selection
if {![info exists Dm_Selection(class)] || $class != $Dm_Selection(class)} {error "$class not selected"}
set instList ""
foreach s $Dm_Selection(win) {lappend instList [rlindex Dm_WinInst($s) 1]}
return $instList}
proc dm_GetSelSess {} {global Dm_WinInst Dm_Selection
foreach s $Dm_Selection(win) {lappend sessList [rlindex Dm_WinInst($s) 2]}
if ![info exists sessList] {return Sess0}
return $sessList}
proc dm_GetCurrSess {} {global Dm_WinInst Dm_Selection
if [catch {set sess [rlindex Dm_WinInst([rlindex Dm_Selection(win) 0]) 2]}] {return Sess0} else {return $sess}}
proc dm_DoActions {val var {cvtProc {}}} {global Dm_WinInst Dm_Selection
foreach s $Dm_Selection(win) {set inst [rlindex Dm_WinInst($s) 1]
if {$cvtProc!=""} {set inst [$cvtProc $inst]}
lappend varBind([rlindex Dm_WinInst($s) 2]) "$var.$inst {} $val"}
foreach sess [array names varBind] {dm_DoAction $sess $varBind($sess)}}
proc dm_Window {type} {global DmDMS Dm_WinInst Dm_Selection Dm_Status
if {$Dm_Selection(win) == ""} return
dm_DoMenu $type [rlindex Dm_WinInst([rlindex Dm_Selection(win) 0]) 0]}
proc dm_GetAlias {var {prefix ""}} {global Dm_Alias Dm_Pref
if [info exists Dm_Alias($var)] {return $Dm_Alias($var)} elseif {$prefix != ""} {if [regsub $prefix $var "" l] {return $l}}
return $var}
proc dm_PrintChassis {w {fName ""}} {global Dm_Pref Dm_Path tcl_platform env
if {$fName == ""} {set fName $Dm_Pref(/tmp)/chassis.ps}
if {$tcl_platform(platform) == "unix"} {raise .
update
if [info exists env(DMOS)] {exec $Dm_Path/bin.$env(DMOS)/xgrabsc -id [winfo id $w] -nobell > $fName} else {exec $Dm_Path/bin/xgrabsc -id [winfo id $w] -nobell > $fName}}
return $fName}
Main $argc argv
rename Main ""
rename dm_MainWin ""
