
#-------------------------------------------------------------------------------
# Module:     fileNew.tk
# Activation: Dynamically loaded on user request
# Scope:      Dialog for generation of new graph objects
#-------------------------------------------------------------------------------



proc NewGraphObject {} {
    global WDNew InternalWindowing DialogFrame DefPadX DefPadY

    if {$InternalWindowing} {
        set WDNew $DialogFrame.new
        if {![winfo exists $WDNew]} {
            frame $WDNew
        }
        
        RegisterDialog "New Graph Object" $WDNew NewGraphObject {}
    } else {
        set WDNew .new
        if {![winfo exists $WDNew]} {
            toplevel $WDNew
            wm title $WDNew "New Graph Object"
            wm resizable $WDNew 0 0
        } else {return}
    }

    global ObjectType NNodes
    set ObjectType "sparse graph"
     
    frame $WDNew.f1
    label $WDNew.f1.label -text "Object Type:" -anchor w
    radiobutton $WDNew.f1.mixedGraph -text "Mixed Graph" \
        -variable ObjectType -value "mixed graph" -anchor w
    radiobutton $WDNew.f1.sparseGraph -text "Sparse Graph" \
        -variable ObjectType -value "sparse graph" -anchor w
    radiobutton $WDNew.f1.denseGraph -text "Dense Graph" \
        -variable ObjectType -value "dense graph" -anchor w
    radiobutton $WDNew.f1.sparseDiGraph -text "Sparse Digraph" \
        -variable ObjectType -value "sparse digraph" -anchor w
    radiobutton $WDNew.f1.denseDiGraph -text "Dense Digraph" \
        -variable ObjectType -value "dense digraph" -anchor w
    radiobutton $WDNew.f1.sparseBiGraph -text "Sparse Bigraph" \
        -variable ObjectType -value "sparse bigraph" -anchor w
    radiobutton $WDNew.f1.denseBiGraph -text "Dense Bigraph" \
        -variable ObjectType -value "dense bigraph" -anchor w
    pack $WDNew.f1.label $WDNew.f1.mixedGraph $WDNew.f1.sparseGraph \
        $WDNew.f1.denseGraph \
        $WDNew.f1.sparseDiGraph $WDNew.f1.denseDiGraph \
        $WDNew.f1.sparseBiGraph $WDNew.f1.denseBiGraph \
        -side top -fill x

    set NNodes 0
    frame $WDNew.f3
    label $WDNew.f3.nText -text "Number of Nodes:" -anchor w
    grid $WDNew.f3.nText -in $WDNew.f3  \
        -row 0 -column 0 -rowspan 1 -columnspan 1 -sticky news -padx 1m
    entry $WDNew.f3.nodes -textvariable NNodes -bg white -width 5
    grid $WDNew.f3.nodes -in $WDNew.f3 \
        -row 0 -column 1 -rowspan 1 -columnspan 1 -sticky news -padx 1m

    grid rowconfig    $WDNew.f3 0 -weight 1 -minsize 0
    grid columnconfig $WDNew.f3 0 -weight 1 -minsize 0

    
    frame $WDNew.buttons
    button $WDNew.buttons.generate -text "Generate" -command Generate

    button $WDNew.buttons.cancel -text "Cancel" -command {
        if {$InternalWindowing} {
            DestroyActiveDialog
        } else {
            destroy $WDNew
        }
    }
    
    pack $WDNew.buttons.generate $WDNew.buttons.cancel \
        -side left -fill x -padx 3m
     
    bind $WDNew.f3.nodes <Return> {Generate}

    pack $WDNew.buttons -padx 3m -pady 3m -side bottom
    pack $WDNew.f1 $WDNew.f3 -padx 10m -pady 5m -side top -anchor w

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

proc Generate {} {
    global ObjectType ThisGraph NNodes OrigFileName FileName Unchanged Mode \
        env InternalWindowing WDNew

    if {$InternalWindowing} {
        DestroyActiveDialog
    } else {
        destroy $WDNew
    }

    $ThisGraph delete
    DeleteTempFiles
    set OrigFileName [file join [pwd] unnamed]
    set FileName [file join $env(HOME) unnamed]
    wm title . "GOBLET: unnamed"
    if {[string equal $ObjectType "sparse bigraph"] ||
        [string equal $ObjectType "dense bigraph"]} {
        eval goblin $ObjectType $ThisGraph $NNodes $NNodes
    } else {
        eval goblin $ObjectType $ThisGraph $NNodes
    }
    set goblinNodeStyle 1
    InitFile
}

global WDNew
if {![info exists WDNew] || ![winfo exists $WDNew]} {NewGraphObject}

