
# This code creates the user interface for global.
#
# Copyright (c) 1993 - 1995 Pacific Marketing and Consulting, Inc,
#       and ICEM Systems, GmbH.  All rights reserved.
# Author:  Wayne A. Christopher, wayne@icemcfd.com

proc anal_freesurf {} {
    global freesurf_dir freesurf_vol freesurf_mat
    global families family_dims family_name
    global form_done_flag botform_geo
    
    set fams ""
    foreach f $families {
	if {$family_dims($f) == 3} {
	    lappend fams [list $f -text $family_name($f)]
	}
    }
    if {$fams == ""} {
	mess "Error: there are no volume families available.\n"
	return
    }
    
    if ![info exists freesurf_dir] {
	set freesurf_dir i
	set freesurf_vol 0.0
        set freesurf_mat [lindex [lindex $fams 0] 0]
    }
    
    form_kill .freesurf
    
    set d [form_init .freesurf "Free surface" anal]
    form_frame $d.fr sunken 3 {0 0}; set d $d.fr
    
    form_label $d.regionl "Material:" {1 1 -cols -}
    form_frame $d.region ridge 2 {2 1 -fill none -cols -}
    
    form_label $d.dirl "Direction:" {3 1}
    form_radiobutton $d.idir I freesurf_dir i {3 2}
    form_radiobutton $d.jdir J freesurf_dir j {3 3}
    form_radiobutton $d.kdir K freesurf_dir k {3 4}
    
    form_label $d.voll "Volume:" {4 1}
    form_entry $d.col freesurf_vol float {4 2 -cols -}
    
    check_box $d.region $fams 6 freesurf_mat 0
    
    form_finish $botform_geo
    
    tkwait variable form_done_flag(.freesurf)
    
    if $form_done_flag(.freesurf) {
	command "free_surface $freesurf_mat $freesurf_dir $freesurf_vol"
    }
}

proc anal_calcvol {} {
    global calcvol_mat
    global families family_dims family_name
    global form_done_flag botform_geo
    
    set fams ""
    foreach f $families {
	if {$family_dims($f) == 3} {
	    lappend fams [list $f -text $family_name($f)]
	}
    }
    if {$fams == ""} {
	mess "Error: there are no volume families available.\n"
	return
    }
    
    if ![info exists calcvol_mat] {
        set calcvol_mat [lindex [lindex $fams 0] 0]
    }
    
    form_kill .calcvol
    
    set buttons {{Accept {form_accept_hack .calcvol}}}
        
    set d [form_init .calcvol "Calculate volume" anal $buttons]
    form_frame $d.fr sunken 3 {0 0}; set d $d.fr
    
    form_label $d.regionl "Material:" {1 1 -cols -}
    form_frame $d.region ridge 2 {2 1 -fill none -cols -}
    
    check_box $d.region $fams 6 calcvol_mat 0
    
    form_finish $botform_geo
    
    tkwait variable form_done_flag(.calcvol)
    
    if $form_done_flag(.calcvol) {
	command "calculate_volume $calcvol_mat [range_string]"
    }
}
