
# Generic stuff.

# Copyright (c) 1993, 1994 Pacific Marketing and Consulting
# Author:  Wayne A. Christopher, wayne@pmac.com
#          Pacific Marketing and Consulting, Berkeley, California

set version 11.0
set tool_name "AutoHexa"

set env(ICEM_USE_MENUBAR) 1
set env(ICEM_ONE_WINDOW) 1
set toplevel(windows_menu) ""
set gray_background 1
set default_font_weight normal
set drop_down_arrow 1
set object_edit_use_notebook 1
set no_menu_tearoff 1
set hollow_objects_always_higher_priority 1
set cad_include_best_fit_command 1

if {[info exists env(ICEM_ACN)] && [file exists $env(ICEM_ACN)/icemcfd/version]} {
    set fp [open $env(ICEM_ACN)/icemcfd/version r]
    # This is because the version gets tacked on later
     set whoami [lrange [gets $fp] 0 end-1]
    close $fp
} else {
    set whoami "$tool_name version $version"
}

if {[info exists env(ICEM_ACN)] && [file exists $env(ICEM_ACN)/release_date]} {
    set fp [open $env(ICEM_ACN)/release_date r]
    set extra_startup_message "Release date [gets $fp]"
    close $fp
}

set tool_logotext "ICEM CFD 11.0 \nAutoHexa"
set tool_logo_relief flat
set tool_logo "$app_dir/autohex-logo-bits.xbm \#0000ff \
	$app_dir/autohex-logo-mask.xbm \#547eff"
set tool_logo_small "$app_dir/autohex-smlogo-bits.xbm \#0000ff \
	$app_dir/autohex-smlogo-mask.xbm \#547eff"

set help_base autohex/autohex

if ![info exists default_fluid_family] {
    set default_fluid_family FLUID
}
if ![info exists default_side_family] {
    set default_side_family WALL
}

# This means that instead of WALL, etc we just use the object name
set default_families_from_object_names 1

set groups_can_provide_default_families 1
set grid_allow_convert_multi 1

set solve_solver none

proc directory {{what ""} {do_back 1}} {
    global job_name
    
    if [file exists $job_name/mesh] {
	switch -glob $what {
	    mesh    { set dir $job_name/autohex }
	    tetin   { set dir $job_name/mesh }
	    domain  { set dir $job_name/domains }
	    output  { set dir $job_name/transfer }
	    parent  { set dir [file dirname $job_name] }
	    subproj { set dir $job_name }
	    job*    { set dir [string range $what 4 end]/autohex }
	    default { set dir $job_name/autohex }
	}
    } else {
	switch -glob $what {
	    parent  { set dir [file dirname $job_name] }
	    job*    { set dir [lindex $what 1] }
	    default { set dir $job_name }
	}
    }
    
    return $dir
}

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

set generic_files {
    params_generic
    objects_generic
    objects_special
    form_auto
    file_generic
    polyduct
}

if ![info exists object_type_layout] {
    lappend generic_files obparams_generic obparams_special
}

load_fileset $app_dir $generic_files ""

# Random variables that need to be initialized.

set from_library_flag 0
set job_directory .
set edit_no_units 1
set use_indomain_button 1
set use_display_edges 1
set want_bar_elements 1
set dont_remove_faces_between_solids 1

if {$tcl_platform(platform) == "windows"} {
    set env(PATH) $env(PATH)\;[join [split $bindir /] \\]
} else {
    set env(PATH) $env(PATH):$bindir
}

if [info exists env(HOME)] {
    set global_def_file $env(HOME)/.autohex_defaults
} else {
    puts "Warning: can't find $HOME variable"
    set global_def_file [pwd]/.autohex_defaults
}

if [info exists env(HOME)] {
    set global_pref_file $env(HOME)/.autohex_config
} else {
    puts "Warning: can't find $HOME variable"
    set global_pref_file [pwd]/.autohex_config
}

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

if [info exists env(ICEM_USE_MENUBAR)] {
    set mainwindow_menubar 1
    set screen_select_all_types 1
    set tdv_pickable_tags(.v.view) "obtype_all anno_pickable"
    set current_phase model
    
    #lappend auto_path $tool_dir/../BWidget-1.2.1
    #package require BWidget

} elseif ![info exists tool_phases] {
    if ![info exists tool_phases_list] {
        set tool_phases {
	    {File   file}
	    {Model  model}
	    {Params params}
        }
    } else {
	set tool_phases $tool_phases_list
    }
    
    set tool_phase_info(params) {
	{params   button "Edit params"   0,1 "expression_edit"}
	{trials   button "Define trials" 0,2 "expression_trials"}
    }
    
    if ![info exists tool_phase_info(file)] {
	set tool_phase_info(file) {
	    {job      button "Project"       0,1 file_job}
	    {notes    button "Title/notes"   0,2 file_notes}
	    {conf     button "Options"       0,3 file_options}
	    {save     button "Save"          0,4 auto_save_all}
	    {quit     button "Quit"          0,5 "file_quit 1"}
	    {merge    button "Merge"         1,1 file_merge}
	    {filecopy button "File copy"     1,2 file_hardcopy}
	    {hardcopy button "Hardcopy"      1,3 print_hardcopy}
	    {ssi      button "S/S intersect" 1,4 "auto_save_tetin 1"}
	    {input    button "Write input"   1,5 file_write_input}
	}
    }
    
    #{formfact button "Form factors" 1,4 write_formfactors}
    
    set tool_phase_info(model) {}
    
    set r 0; set c 1
    foreach ot $object_type_layout {
	if {$ot == "nl"} { incr r; set c 1; continue }
	
	set name $object_type_title($ot)
	if [info exists object_type_title_short($ot)] {
	    set name $object_type_title_short($ot)
	} else {
	    set object_type_title_short($ot) $name
	}
	lappend tool_phase_info(model) \
	    [list $ot radiobutton $name $r,$c current_mtype $ot update_mtype]
	incr c
    }
    incr r
    
    if ![info exists auto_boco_edit_cmd] {
	set auto_boco_edit_cmd auto_bocos_edit
    }
    
    if {$auto_boco_edit_cmd != ""} {
	lappend tool_phase_info(model) \
	    [list bocos button "Bound conds" 2,2 $auto_boco_edit_cmd]
    }
    
    if ![info exists model_extra_commands] {
	set model_extra_commands {
	    {summary  button      "Summary"      2,0 "summary_form"}
	    {groups   button      "Groups"       2,0 "coll_edit group"}
	    {priority button      "Priorities"   2,0 "model_edit_priority"}
	    {macro    menu        "Special"      2,0 {
		{ command -label "Person" -command "update_mtype person" }
		{ command -label "Hood"   -command "update_mtype hood" }
		separator
		{ command -label "Polygonal ducts" -command make_polyduct }
	    } }
	}
	lappend model_extra_commands [cad_get_menu 2,0]
	lappend model_extra_commands {
	    util    menu        "Utilities"       1,7 {
		{ command -label "Assign face families" \
		      -command assign_face_families }
		{ command -label "Check gaps" \
		      -command model_check }
		{ command -label "Fluid family" \
		      -command tetin_set_fluid_family }
	    }
	}
    }
    foreach b $model_extra_commands {
	lappend tool_phase_info(model) $b
    }
    if ![info exists already_made_mesh_button] {
	add_mesh_button $r 1
    }
    set num_panel_spaces 7
}

if {($app_name == "autohex_generic") && [info exists env(ICEM_USE_MENUBAR)]} {
    source $guibase_dir/commands_guibase.tcl
    source $autohex_dir/commands_autohex.tcl
    source $app_dir/menus_generic.tcl
}

# Here is some junk that ought to get redefined eventually.

proc post_clear {} {}
proc ff_invalidate {} {}
proc set_current_post_object args {}

