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

proc pick_some_elements {max} {
    global last_line
    
    banner "Left button = select elements, middle = accept, right =\
	    back up / cancel."
    command "select_stuff elem $max" 0
    banner ""
    return $last_line
}

proc pick_some_bars {max} {
    global last_line
    
    banner "Left button = select bars, middle = accept, right =\
	    back up / cancel."
    command "select_stuff {elem BAR_2} $max" 0
    banner ""
    return $last_line
}

proc pick_some_nodes {max {extra_mess ""}} {
    global last_line
    
    banner "Left button = select nodes$extra_mess, middle = accept, right =\
	    back up / cancel."
    command "select_stuff node $max" 0
    banner ""
    return $last_line
}

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

proc old__modify_create_elems {} {
    global families topform_geo mesh_dirty
    
    toplevel .new_elem
    wm title .new_elem "New family"
    wm geometry .new_elem $topform_geo
    
    set fams ""
    foreach f $families {
	lappend fams $f
    }
    
    set mess "Please select a family for the new elements."
    set fam [choose_one $mess $fams "" +300+300]
    if {$fam == ""} return
    foreach f $families {
	if {$f == $fam} { set famno $f; break }
    }
    if ![info exists famno] { mess "No such family \"$fam\"\n" red; return }
    
    command "start_create_elements" 0
    while 1 {
	set nodes [pick_some_nodes 3]
	if {[llength $nodes] < 3} {
	    command "end_create_elements" 0
	    destroy .new_elems
	    return
	}
	command "create_elements \{$nodes\} $famno TRI"
    }
    set mesh_dirty 1
}

proc modify_del_elems {} {
    global mesh_dirty
    
    set elems [pick_some_elements 0]
    if {$elems == ""} return
    command "delete_elements \{$elems\}"
    set mesh_dirty 1
}

proc modify_change_family {} {
    global families change_family_name form_done_flag
    global topform_geo mesh_dirty
    
    set elems [pick_some_elements 0]
    if {$elems == ""} return
    
    form_kill .change_family
    set d [form_init .change_family "Change family" modify "accept cancel"]
    form_frame $d.box flat 0 {0 0}
    
    set fams ""
    foreach f $families {
	lappend fams [list $f -text $f]
    }
    check_box $d.box $fams 10 change_family_name 0
    form_finish $topform_geo
    
    tkwait variable form_done_flag(.change_family)
    if !$form_done_flag(.change_family) return
    
    command "change_family \{$elems\} $change_family_name"
    set mesh_dirty 1
}
