
#-------------------------------------------------------------------------------
# Module:     editExtract.tk
# Activation: Dynamically loaded on user request
# Scope:      Extract potential solutions from other data structures
#-------------------------------------------------------------------------------



proc ExtractSolutions {} {
    global WDExtract InternalWindowing DialogFrame DefPadX DefPadY

    if {$InternalWindowing} {
        set WDExtract $DialogFrame.extract
        if {![winfo exists $WDExtract]} {
            frame $WDExtract
        }
        
        RegisterDialog "Extract Solutions" $WDExtract ExtractSolutions {}
    } else {
        set WDExtract .extract
        if {![winfo exists $WDExtract]} {
            toplevel $WDExtract
            wm title $WDExtract "Extract Solutions"
            wm resizable $WDExtract 0 0
        } else {return}
    }

    global ThisGraph ThisStructure
    if {![info exists ThisStructure] || \
            ($ThisStructure!="trees" && $ThisStructure!="bipartition" && \
             $ThisStructure!="cut" && $ThisStructure!="matching" && \
             $ThisStructure!="colours" && $ThisStructure!="cycles")} {
        set ThisStructure "trees"
    }

    frame $WDExtract.options
    pack $WDExtract.options -padx $DefPadX -pady 5m -side top -anchor w

    label $WDExtract.options.label -text "Desired Structure:" -anchor w
    radiobutton $WDExtract.options.trees -text "Trees" \
        -variable ThisStructure -value "trees" -anchor w
    radiobutton $WDExtract.options.cut -text "Cut" \
        -variable ThisStructure -value "cut" -anchor w
    radiobutton $WDExtract.options.bipartition -text "Bipartition" \
        -variable ThisStructure -value "bipartition" -anchor w
    radiobutton $WDExtract.options.colours -text "Colours" \
        -variable ThisStructure -value "colours" -anchor w
    radiobutton $WDExtract.options.matching -text "Matching" \
        -variable ThisStructure -value "matching" -anchor w
    radiobutton $WDExtract.options.cycles -text "Cycles" \
        -variable ThisStructure -value "cycles" -anchor w
    pack $WDExtract.options.label $WDExtract.options.trees \
        $WDExtract.options.cut $WDExtract.options.bipartition \
        $WDExtract.options.colours $WDExtract.options.matching \
        $WDExtract.options.cycles -side top -fill x
     
    frame $WDExtract.buttons
    pack $WDExtract.buttons -padx 3m -pady 3m -side bottom

    button $WDExtract.buttons.go -text "Go" -command { \
        $ThisGraph extract $ThisStructure
        PropagateModifications
    }    

    button $WDExtract.buttons.cancel -text "Cancel" -command { \
        if {$InternalWindowing} {
            DestroyActiveDialog
        } else {
            destroy $WDExtract
        }
    }
    
    pack $WDExtract.buttons.go \
        $WDExtract.buttons.cancel \
        -side left -fill x -padx 3m

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

if {![info exists WDExtract] || ![winfo exists $WDExtract]} {ExtractSolutions}
