
# This code creates the user interface for the mesh editor.
#
# Copyright (c) 1993 - 1995 Pacific Marketing and Consulting, Inc,
#       and ICEM Systems, GmbH.  All rights reserved.
# Author:  Wayne A. Christopher, wayne@icemcfd.com
#
# Note that many of the functions that used to be here are now in
# guibase/select_geom.tcl and select_common.tcl

proc select_family {{mess ""} {varn ""} {wpos ""}} {
    global fam_visible ai_environment
    
    set f [select_families 0 0 1 $mess fam_visible $wpos]
    if {($varn != "") && ($f != "")} {
	upvar \#0 $varn lvar
	set lvar $f
    }
    if {$f != ""} {
	fam_check_new $f
    }
    if { ([info exists ai_environment] && $ai_environment) } {
	if {[llength $f] > 1} {
	    set f [lindex $f 1]
	}
    }
    return $f
}

proc unstruct_select_existing_family {} {
    global select_defaults fam_visible select_existing_varname
    
    set fams [concat [list "Screen select"] [lsort [ic_uns_list_families]]]
    set ch [choose_one "Select a family or type the name of a new one." \
		$fams $select_defaults(family)]
    if {$ch != ""} {
	if {$ch == "Screen select"} {
	    unstruct_screen_select_family select_existing_varname
	    set ch $select_existing_varname
	}
    }
    return $ch
}

proc unstruct_screen_select_family {varname} {
    global select_defaults
    
    set cur visible
    set sel_map [select_unstruct element 1 $cur ""]
    if {$sel_map == ""} return
    set f [lindex [ic_uns_subset_list_families $sel_map] 0]
    ic_uns_subset_delete $sel_map
    uplevel \#0 set $varname $f
}

proc unstruct_select_new_family {varname checkbox} {
    global select_defaults
    
    set ch [question_box .newf "Family name" "Enter a new family name" ""]
    if {$ch != ""} {
	set ch [string toupper $ch]
	uplevel \#0 set $varname $ch
	if {$checkbox != ""} {
	    check_box_add_one $checkbox $ch
	}
    }
}

# ---------------------------------------------------------------------------

proc unstruct_select_type {} {
    global select_defaults
    set ch [choose_one "Select the type." \
		[ic_uns_list_possible_types] \
		$select_defaults(type)]
    if {$ch != ""} { set select_defaults(type) $ch }
    return $ch
}

proc unstruct_screen_select_type { varname} {
    global select_defaults
    
    set cur visible
    set sel_map [select_unstruct element 1 $cur ""]
    if {$sel_map == ""} return
    set f [lindex [ic_uns_subset_list_types $sel_map] 0]
    uplevel \#0 set $varname $f
}
