
#-------------------------------------------------------------------------------
# Module:     editArcLabels.tk
# Activation: Dynamically loaded on user request
# Scope:      Configuration and explicit application of the random generator
#-------------------------------------------------------------------------------



proc ShowRandomGenerator {} {
    global WDRandom InternalWindowing DialogFrame DefPadX DefPadY

    if {$InternalWindowing} {
        set WDRandom $DialogFrame.randopt
        if {![winfo exists $WDRandom]} {
            frame $WDRandom
        }
        
        RegisterDialog "Random Generator" $WDRandom ShowRandomGenerator {}
    } else {
        set WDRandom .randopt
        if {![winfo exists $WDRandom]} {
            toplevel $WDRandom
            wm title $WDRandom "Random Generator"
            wm resizable $WDRandom 0 0
        } else {return}
    }
     
    frame $WDRandom.f1
    label $WDRandom.f1.label -text "Random Labels:" -anchor w
    checkbutton $WDRandom.f1.length -text "Length Labels" \
        -variable goblinRandLength -anchor w
    checkbutton $WDRandom.f1.ucap -text "Upper Bounds" \
        -variable goblinRandUCap -anchor w
    checkbutton $WDRandom.f1.lcap -text "Lower Bounds" \
        -variable goblinRandLCap -anchor w
    checkbutton $WDRandom.f1.geometry -text "Geometric Embedding" \
        -variable goblinRandGeometry -anchor w
    pack $WDRandom.f1.label $WDRandom.f1.length $WDRandom.f1.ucap \
        $WDRandom.f1.lcap $WDRandom.f1.geometry -side top -fill x
     
    set goblinRandEuler 0
    frame $WDRandom.f2
    checkbutton $WDRandom.f2.parallels -text "Allow Parallel Arcs" \
        -variable goblinRandParallels -anchor w
    pack $WDRandom.f2.parallels -side top -fill x
     
    frame $WDRandom.f3
    label $WDRandom.f3.minText -text "Minimum Label:" -anchor w
    grid $WDRandom.f3.minText -in $WDRandom.f3  \
        -row 0 -column 0 -rowspan 1 -columnspan 1 -sticky news -padx 1m
    entry $WDRandom.f3.minimum -textvariable goblinRandMin -bg white -width 5
    grid $WDRandom.f3.minimum -in $WDRandom.f3 \
        -row 0 -column 1 -rowspan 1 -columnspan 1 -sticky news -padx 1m

    label $WDRandom.f3.maxText -text "Maximum Label:" -anchor w
    grid $WDRandom.f3.maxText -in $WDRandom.f3  \
        -row 1 -column 0 -rowspan 1 -columnspan 1 -sticky news -padx 1m
    entry $WDRandom.f3.maximum -textvariable goblinRandMax -bg white -width 5
    grid $WDRandom.f3.maximum -in $WDRandom.f3 \
        -row 1 -column 1 -rowspan 1 -columnspan 1 -sticky news -padx 1m

    grid rowconfig    $WDRandom.f3 0 -weight 1 -minsize 0
    grid columnconfig $WDRandom.f3 0 -weight 1 -minsize 0
    
    frame $WDRandom.buttons
    button $WDRandom.buttons.apply -text "Apply" -command {
        if {[QualifiedInt $goblinRandMin 0 50000] && [QualifiedInt $goblinRandMax 0 50000]} {
            if {$goblinRandLength==1} {$ThisGraph generate length}
            if {$goblinRandUCap==1} {$ThisGraph generate ucap}
            if {$goblinRandLCap==1} {$ThisGraph generate lcap}
            if {$goblinRandGeometry==1} {$ThisGraph generate geometry}
            global CanvasRegion
            if {[winfo exists $CanvasRegion]} {InitDisplay}
            destroy .randopt
        }
    }
    
    button $WDRandom.buttons.done -text "Done" -command {
        if {[QualifiedInt $goblinRandMin 0 50000] && [QualifiedInt $goblinRandMax 0 50000]} {
            if {$InternalWindowing} {
                DestroyActiveDialog
            } else {
                destroy $WDRandom
            }
        }
    }
    
    pack $WDRandom.buttons.apply $WDRandom.buttons.done \
        -side left -fill x -padx 3m
     
    pack $WDRandom.buttons -padx 3m -pady 3m -side bottom
    pack $WDRandom.f1 $WDRandom.f2 $WDRandom.f3 -padx $DefPadX -pady 5m \
        -side top -anchor w

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

global WDRandom
if {![info exists WDRandom] || ![winfo exists $WDRandom]} {ShowRandomGenerator}
