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

proc auto_load_projlib {tetin_file vis noisy l_surf l_curve l_point l_mat} {
    global blank_family_color projlib geom_visible fam_visible
    global tetin_try_binary tetin_load_rename_family 
    
    array set geom_visible {
	surface 0 curve 0 point 0 material 0 loop 0 density 0
    }
    
    #set tetin_load_rename_family(ORFN) DEFAULT
    set blank_family_color gray
    set tetin_try_binary 0
    
    # want to keep the old stuff
    # delete_projlib
    
    if $noisy {
	mess "Loading geometry file $tetin_file ...\n"
    }
    if [make_projlib $tetin_file $l_mat $l_surf $l_curve $l_point 0 0] {
	foreach {t f} {surface DEF_SURF curve DEF_CURVE point DEF_POINT} {
	    set nf 0
	    foreach s [$projlib list_objects $t] {
		if {[$projlib get_family $t $s] == "ORFN"} {
		    if !$nf {
			$projlib new_family $f
			set fam_visible($f) 1
			set col [family_color_for_name $f]
			incr nf
		    }
		    $projlib set_family $t $s $f
			set bsp [$projlib get_object $t $s]
			if {$bsp == ""} continue
		    $bsp configure -family $f -color $col
		}
	    }
	}
	if $noisy {
	    mess "Done loading geometry file.\n"
	    geom_summary
	}
	set got 0
	foreach t {surface curve point} {
	    if [$projlib num_objects $t] {
		set geom_visible($t) 1
		set got 1
		break
	    }
	}
	if !$got {
	    mess "Warning: no CAD objects were found\n" red
	    return ""
	}
	foreach t [array names geom_visible] {
	    $projlib update_visibility $t fam_visible $geom_visible($t)
	    $projlib configure_objects $t \
		1 wire \
		0 0 0 0 \
		0 1 0 \
		"1 1 1 1" \
		0 0 0 0 \
		"0 0 0" \
		0 0 0 0 0 0 0 0
	}
	$projlib signal_change 1
	return $projlib
    } else {
	return ""
    }
}

proc auto_define_geom_object {type num} {
    set obj [define_geom_object $type $num]
    $obj configure -simple 1 -shade wire -color white ;# -visible 0
    return $obj
}

proc shape_cad_add_bsplines {shape type names} {
    global projlib
    if {$projlib == ""} {
	user_error "Can't add bsplines - no projlib"
	return
    }
    
    foreach n $names {
	set obj [$projlib get_object_by_name $type $n]
	if {$obj != ""} {
	    $shape add_bspline $obj
	} else {
	    error "no such $type $n"
	}
    }
}

# These are dummy functions

proc update_geom_window {} {
}

proc update_geom_visible {what how} {
}

proc auto_save_projlib {file} {
    global projlib whoami
    if {$projlib != ""} {
	$projlib save_model $file $whoami 1
    }
}
