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



proc NewGraphObject {} {
    global WDNew

    set title "New Graph Object"

    if {[RegisterFormOrWindow $title newGraph WDNew NewGraphObject \
            "Cancel"        {} \
            "Generate"      {Generate} \
            ""              {} \
            ""              {} \
        ]
    } {
        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
     
    bind $WDNew.f3.nodes <Return> {Generate}

    pack $WDNew.f1 $WDNew.f3 -padx 5m -pady 5m -side top -anchor w


    DisplayForm $title
}

proc Generate {} {
    global ObjectType ThisGraph NNodes OrigFileName FileName goblinNodeStyle \
        WDNew TraceDir

    DestroyFormOrWindow "New Graph Object" $WDNew

    $ThisGraph delete
    DeleteTempFiles
    set OrigFileName [file join [pwd] unnamed]
    set FileName [file join $TraceDir unnamed]
    wm title . "GOBLET: unnamed"

    if {[string equal $ObjectType "sparse bigraph"] ||
        [string equal $ObjectType "dense bigraph"]} {
        eval goblin $ObjectType $ThisGraph $NNodes $NNodes
        
        for {set i 0} {$i<$NNodes} {incr i} {
            $ThisGraph node $i set colour 0
            $ThisGraph node [expr $i+$NNodes] set colour 1
        }

        $ThisGraph layout colours
    } else {
        eval goblin $ObjectType $ThisGraph $NNodes
        $ThisGraph layout circle
    }

    set goblinNodeStyle 1
    InitFile
}

NewGraphObject

