
# 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 modify_offset {} {
    global config_dir offset_bin last_line cut_domain
    
    banner "Select a node in the surface with the left button;\
	    middle = done, right = cancel."
    command "select_stuff node 2"
    banner ""
    if {$last_line == ""} return
    set nodenum [lindex $last_line 0]
    
    set vec [question_box .direction "Offset direction" \
	    "Enter a direction from the selected node, to\n\
	    indicate which side the offset surface should\n\
	    be on, as three numbers separated by spaces."]
    if {[llength $vec] != 3} return
    
    set val [question_box .distance "Offset distance" \
	    "Enter the distance from the current\n\
	    surface to the offset surface."]
    if {[llength $val] != 1} return
    
    set off_dom $cut_domain.offset
    set files ""
    foreach f [glob -nocomplain $config_dir(domains)/*] {
	set ft [file tail $f]
	if ![string match __temp_* $ft] { lappend files $ft }
    }
    set mess "Please select a file to save the offset surface to. \
	    You can delete domain files using the \"Delete\" button\
	    once you have\
	    selected them."
    set off_dom [choose_one $mess $files $off_dom +300+300 delete_cut_domain]
    if {$off_dom == ""} return
    
    mess "Offset surface being written to domain \"$off_dom\" ...\n"
    
    set mesh1 $config_dir(domains)/__temp_offset
    set mesh2 $config_dir(domains)/$off_dom
    
    command "write_tetra_domain $mesh1 \"[mesh_family_string]\"" 0
    
    eval exec $offset_bin $mesh1 $mesh2 -node $nodenum -direction $vec \
	    -distance $val
    
    busy 1
    mess "Loading offset domain ...\n"
    command "view_active 0" 0
    command "load_tetra_domain $mesh2 0 0" 0
    if {$last_line == ""} {
	mess "Domain not loaded.\n" red
	busy 0
	return 0
    }
    update_display face
    command "view_active 1" 0
    busy 0
	    
    mess "Done.\n"
}
