
#-------------------------------------------------------------------------------
# Module:     editConstants.tk
# Activation: Dynamically loaded on user request
# Scope:      Dialog for generating constant node and arc labels
#-------------------------------------------------------------------------------



proc SelectConstants {} {
    global WDConstant InternalWindowing DialogFrame DefPadX DefPadY

    if {$InternalWindowing} {
        set WDConstant $DialogFrame.constant
        if {![winfo exists $WDConstant]} {
            frame $WDConstant
        }
        
        RegisterDialog "Constant Labels" $WDConstant SelectConstants {}
    } else {
        set WDConstant .constant
        if {![winfo exists $WDConstant]} {
            toplevel $WDConstant
            wm title $WDConstant "Constants"
            wm resizable $WDConstant 0 0
        } else {return}
    }

    global ThisGraph ThisLabel ThisValue
    if {![info exists ThisLabel] || \
            ($ThisLabel!="ucap" && $ThisLabel!="lcap" && \
             $ThisLabel!="length" && $ThisLabel!="demand")} {
        set ThisLabel "ucap"
        set ThisValue ""
    }

    frame $WDConstant.options
    label $WDConstant.options.label -text "Labels:" -anchor w
    radiobutton $WDConstant.options.ucap -text "Upper Bounds" \
        -variable ThisLabel -value "ucap" -anchor w
    radiobutton $WDConstant.options.lcap -text "Lower Bounds" \
        -variable ThisLabel -value "lcap" -anchor w
    radiobutton $WDConstant.options.length -text "Arc Lengths" \
        -variable ThisLabel -value "length" -anchor w
    radiobutton $WDConstant.options.demand -text "Node Demands" \
        -variable ThisLabel -value "demand" -anchor w
    pack $WDConstant.options.label $WDConstant.options.ucap \
        $WDConstant.options.lcap $WDConstant.options.length \
        $WDConstant.options.demand -side top -fill x
     
    frame $WDConstant.value
    label $WDConstant.value.label -text "New Constant Value:" -anchor w
    entry $WDConstant.value.value -textvariable ThisValue -bg white
    pack $WDConstant.value.label $WDConstant.value.value -side top -fill x

    pack $WDConstant.options $WDConstant.value -padx $DefPadX \
        -pady 5m -side top -anchor w

     
    frame $WDConstant.buttons
    pack $WDConstant.buttons -padx 3m -pady 3m -side bottom

    button $WDConstant.buttons.apply -text "Apply" -command { \
        if {$ThisValue!=""} {
            $ThisGraph set $ThisLabel $ThisValue
            PropagateModifications
        }
    }    

    button $WDConstant.buttons.done -text "Done" -command { \
        if {$InternalWindowing} {
            DestroyActiveDialog
        } else {
            destroy $WDConstant
        }
    }
    
    pack $WDConstant.buttons.apply \
        $WDConstant.buttons.done \
        -side left -fill x -padx 3m

    if {$InternalWindowing} {
        pack $WDConstant -anchor nw
        AlignActiveDialog
    }
}

if {![info exists WDConstant] || ![winfo exists $WDConstant]} {SelectConstants}
