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

# Customization: new solver
# To add a new solver, put the name in the list below that goes with the
# solver entry, and similarly for a new smoother.  If you want the pathname
# of this program to be a modal (and thus alterable by the user), you
# can include an entry similar to those for the "vsaero_output_path"
# and "plot3d_output_path" below (also you should add helpTopics entries
# for these modals in the file "helpinfo", similar to those already there).

global icem_fluent icem_powermesh env is_win is_aea

if { !$icem_fluent && !$icem_powermesh } {

set modal_data {
    {units {Units of Measurement} {English Metric} {} English 1}
    {draft {Drafting Standards} {"ANSI-82" DIN} {} "ANSI-82"  1}
    {partform {Part Storage Format} {ASCII Binary} {} Binary  1}
    {ddnterm {Graphics Type} {native x11 OpenGL} {} native 1}
    {default_geoname {Default Geometry Name} s {} parts_mesh  1}
    {ddn_mesher_license {DDN Mesher License} {
	Hexa
	Tetra
	Global} {} Hexa 1}
    {editor {Text Editor} {
	/usr/sbin/jot
	/usr/bin/ame
	/usr/bin/vi
	vuepad
	xedit
	/usr/local/bin/emacs} {} /usr/sbin/jot 1}
    {help_viewer {Help Viewer} {Hippo Default} {} Default 1}
    {padamm_terse {Run PADAMM with no queries} b {} false 0}
    {padamm_back {Run PADAMM in the background} b {} false    0}
    {n_processors {Number of availible processors} s {} 1   0}
    {max_binary_tetin {Maximum binary tetin file size } s {} 0 0 }
    {remotehost {Host for remote execution} s {} {}       0}
    {displayhost {Host for display} s {} {} 0 }
    {xterm_params {Window Parameters} s {} "-geometry =80x24+0+0\
                  -fn 9x15bold -sb -sl 10000" 1}
}

lappend modal_data $solver_modal_data

} else {

# fluent option processing
if $icem_fluent {
set modal_data {
    {units {Units of Measurement} {English Metric} {} English 1}
    {draft {Drafting Standards} {"ANSI-82" DIN} {} "ANSI-82"  1}
    {partform {Part Storage Format} {ASCII Binary} {} Binary  1}
    {ddnterm {Graphics Type} {native x11 OpenGL} {} native 1}
    {default_geoname {Default Geometry Name} s {} parts_mesh  0}
    {ddn_mesher_license {DDN Mesher License} {
	Hexa
	Tetra
	Global} {} Hexa 1}
    {editor {Text Editor} {
        /usr/sbin/jot
        /usr/bin/ame
        /usr/bin/vi
        vuepad
        xedit
        /usr/local/bin/emacs} {} /usr/sbin/jot 1}
    {help_viewer {Help Viewer} {Hippo Netscape} {} Hippo 1}
    {solver Solver {
	FLUENT_V4
	RAMPANT_V3
	FLUENT/UNS
        TGRID
        NEKTON
        FLUENT/UNS-V2
    } {} FLUENT_V4 0}
    {xterm_params {Window Parameters} s {} "-geometry =80x24+0+0\
                  -fn 9x15bold -fg black -cr black -bg wheat -sb -sl 10000" 1}
}
}
# powermesh option processing
if $icem_powermesh {
set modal_data {
    {units {Units of Measurement} {English Metric} {} English 1}
    {draft {Drafting Standards} {"ANSI-82" DIN} {} "ANSI-82"  1}
    {partform {Part Storage Format} {ASCII Binary} {} Binary  1}
    {ddnterm {Graphics Type} {native x11 OpenGL} {} native 1}
    {default_geoname {Default Geometry Name} s {} parts_mesh  1}
    {ddn_mesher_license {DDN Mesher License} {
	Hexa
	Tetra
	Global} {} Hexa 1}
    {editor {Text Editor} {
        /usr/sbin/jot
        /usr/bin/ame
        /usr/bin/vi
        vuepad
        xedit
        /usr/local/bin/emacs} {} /usr/sbin/jot 1}
    {help_viewer {Help Viewer} {Hippo Netscape} {} Hippo 1}
    {solver Solver {
        CFDS-FLOW3D
        TASCflow
        Polyflow
        Plot3d
    } {} Plot3d 1}
    {xterm_params {Window Parameters} s {} "-geometry =80x24+0+0\
                  -fn 9x15bold -fg black -cr black -bg wheat -sb -sl 10000" 1}
}
}


}



foreach modal $modal_data {
    set name [lindex $modal 0]
    set def [lindex $modal 4]
    set $name $def
}

if { !$icem_fluent && !$icem_powermesh }  {

set pathname_data {
    {med_path {MED} p {} "ICEM_ACN/bin/med" 1}
    {ddn_path {DDN} p {} "ICEM_ACN/bin/icemddn" 1}
    {pcube_path {P-Cube} p {} "ICEM_ACN/bin/pcube" 1}
    {padamm_path {PADAMM} p {} "ICEM_ACN/icemcfd/padamm" 1}
    {tetra_path {Tetra} p {} "ICEM_ACN/icemcfd/tetra" 1}
    {global_path {Global} p {} "ICEM_ACN/icemcfd/global" 0}
    {hex_path {Hex} p {} "ICEM_ACN/icemcfd/hexa" 0}
    {thex_path {Triangles -> Quads} p {} "ICEM_ACN/icemcfd/thex" 0}
    {unput_path {Unput} p {} "ICEM_ACN/icemcfd/unput" 0}
    {quad_path {Quad} p {} "ICEM_ACN/icemcfd/quad" 0}
    {prism_path {Prism} p {} "ICEM_ACN/icemcfd/prism" 0}
    {cutter_path {Cutter} p {} "ICEM_ACN/icemcfd/cutter" 1}
    {domain_viewer_path {Domain Viewer} p {} "ICEM_ACN/icemcfd/domain_view" 1}
    {tetra_smoother_path {Tetra Smoother} p {} "ICEM_ACN/icemcfd/smooth" 1}
    {tri_smoother_path {Triangle Smoother} p {} "ICEM_ACN/icemcfd/tsmooth" 1}
    {tri_coarse_path {Triangle Coarsener} p {} "ICEM_ACN/icemcfd/coarse" 1}
    {stamp_path {Stamping} p {} "ICEM_ACN/icemcfd/stamp-files/stamp" 0}
    {tagout_path {Tagging output} p {} "ICEM_ACN/icemcfd/output-interfaces/tagout" 0}
    {g2u_path {Global -> Unstructured} p {} "ICEM_ACN/icemcfd/g2u" 0}
    {s2u_path {Structured -> Unstructured} p {} "ICEM_ACN/icemcfd/str_to_unstr" 1}
    {merge_unstr_path {Merge Unstructured} p {} \
	"ICEM_ACN/icemcfd/merge_unstr" 1}
    {superdomain_path {Structured -> Super} p {} "ICEM_ACN/icemcfd/supdomain" 1}
    {qtet_path {Linear -> Quad Tetra} p {} "ICEM_ACN/icemcfd/qtet" 0}
    {uncouple_path {Uncouple Refinement} p {} "ICEM_ACN/icemcfd/uncouple" 0}
    
    {leo_path {Leo Grid Visualizer} p {} "ICEM_ACN/bin/leo" 1}
    {gplot_path {Gplot} p {} "ICEM_ACN/bin/gplot" 1}
    
    {pl3_domain_path {Plot3d -> Domain Converter} p {} \
	"ICEM_ACN/icemcfd/output-interfaces/pl3d2domain" 0}
    {patran_domain_path {Patran -> Domain Converter} p {} \
	"ICEM_ACN/icemcfd/output-interfaces/patran2df" 0}
    {nastran_domain_path {Nastran -> Domain Converter} p {} \
	"ICEM_ACN/icemcfd/output-interfaces/nastran2df" 0}
    {stl_domain_path {STL -> Domain Converter} p {} \
	    "ICEM_ACN/icemcfd/output-interfaces/stl2df" 0}
    {rampant_domain_path {Rampant -> Domain Converter} p {} \
	"ICEM_ACN/icemcfd/output-interfaces/rampant2df" 0}
}

set is_aea 0
if {([info exists env(TASC_DIR)] && ($is_win == "0")) || \
    ($is_win == "1")} {
    set test_lic_file test_licensing
    if $is_win {append test_lic_file ".exe"}
    catch {set is_aea [eval exec $env(ICEM_ACN)/bin/$test_lic_file -AEA]}
}

foreach sp $solver_interfaces {
    set sn [lindex [lindex $sp 0] 0]
    if {[info exists is_aea] && ($is_aea == "1")} {
        if { $sn == "CFX-4" || $sn == "CFX-5" || \
             $sn == "CFX-TASCflow" || $sn == "Plot3d"  } {
            lappend pathname_data [list [lindex $sp 1]_output_path \
	    "$sn Output Converter" p {} \
	    ICEM_ACN/icemcfd/output-interfaces/[lindex $sp 2] 0]
        }
    } else {
        lappend pathname_data [list [lindex $sp 1]_output_path \
	    "$sn Output Converter" p {} \
	    ICEM_ACN/icemcfd/output-interfaces/[lindex $sp 2] 0]
    }
}

} else {

# fluent processing
if { $icem_fluent } {

set pathname_data {
    {ddn_path {DDN} p {} "ICEM_ACN/bin/icemddn" 1}
    {pcube_path {P-Cube} p {} "ICEM_ACN/bin/pcube" 1}
    {s2u_path {Structured -> Unstructured} p {} "ICEM_ACN/icemcfd/str_to_unstr" 1}
    {merge_unstr_path {Merge Unstructured} p {} \
        "ICEM_ACN/icemcfd/merge_unstr" 1}
    {superdomain_path {Structured -> Super} p {} "ICEM_ACN/icemcfd/supdomain" 1}
    {fluent_output_path {FLUENT V4 Output Converter} p {} \
        "ICEM_ACN/icemcfd/output-interfaces/fluent" 1}
    {georampant_output_path {RAMPANT V3 Output Converter} p {} \
        "ICEM_ACN/icemcfd/output-interfaces/georampant" 1}
    {dave_output_path {FLUENT/UNS-V2 Output Converter} p {} \
        "ICEM_ACN/icemcfd/output-interfaces/dave" 1}
    {georampant_output_path {FLUENT/UNS Output Converter} p {} \
        "ICEM_ACN/icemcfd/output-interfaces/georampant" 1}
    {nekton_output_path {NEKTON Output Converter} p {} \
        "ICEM_ACN/icemcfd/output-interfaces/nekton" 1}
    {leo_path {Leo Grid Visualizer} p {} "ICEM_ACN/bin/leo" 1}
    {gplot_path {Gplot} p {} "ICEM_ACN/bin/gplot" 1}
}
}
# powermesh processing
if { $icem_powermesh } {

set pathname_data {
    {ddn_path {DDN} p {} "ICEM_ACN/bin/icemddn" 1}
    {pcube_path {P-Cube} p {} "ICEM_ACN/bin/pcube" 1}
    {s2u_path {Structured -> Unstructured} p {} "ICEM_ACN/icemcfd/str_to_unstr" 1}
    {merge_unstr_path {Merge Unstructured} p {} \
        "ICEM_ACN/icemcfd/merge_unstr" 1}
    {superdomain_path {Structured -> Super} p {} "ICEM_ACN/icemcfd/supdomain" 1}
    {flow3d_output_path {CFDS-FLOW3D Output Converter} p {} \
        "ICEM_ACN/icemcfd/output-interfaces/flow3d" 0}
    {plot3d_output_path {Plot3d Output Converter} p {} \
        "ICEM_ACN/icemcfd/output-interfaces/plot3d" 0}
    {pl3_domain_path {Plot3d -> Domain Converter} p {} \
        "ICEM_ACN/icemcfd/output-interfaces/pl3d2domain" 0}
    {leo_path {Leo Grid Visualizer} p {} "ICEM_ACN/bin/leo" 1}
    {gplot_path {Gplot} p {} "ICEM_ACN/bin/gplot" 1}
    {tascflow_output_path {TASCflow Output Converter} p {} \
	    "ICEM_ACN/icemcfd/output-interfaces/tascflow" 0}
    {polyflow_output_path {Polyflow Output Converter} p {} \
	    "ICEM_ACN/icemcfd/output-interfaces/polyflow" 0}
    
}
}


}

set fluent_output_path_old $env(ICEM_ACN)/icemcfd/output-interfaces/fluent_topo

proc update_pathnames {oldval newval} {
    global env pathname_data
    
    foreach path $pathname_data {
	set name [lindex $path 0]
	global $name
	if [info exists $name] {
	    set def [set $name]
	} else {
	    set def [lindex $path 4]
	}
	
	regsub $oldval $def $newval def

	set $name $def
    }
}

update_pathnames ICEM_ACN $env(ICEM_ACN)

proc dump_modals {} {
    global modal_data home
    
    set rc [open $home/.iceman_modals w]
    set num 0
    foreach m $modal_data {
	set name [lindex $m 0]
	set def [lindex $m 4]
	
	global $name
	set val [set $name]
	#puts stdout "val $val def $def"
	if {$val != $def} {
	    puts $rc "set $name \"$val\""
	    incr num
	}
    }
    close $rc
    infomsg "Saved $num non-default modals to ~/.iceman_modals"
}

proc dump_pathnames {} {
    global pathname_data env home

    set rc [open $home/.iceman_pathnames w]
    set num 0
    foreach m $pathname_data {
	set name [lindex $m 0]
	set def [lindex $m 4]
	regsub ICEM_ACN $def $env(ICEM_ACN) def
	
	global $name
	set val [set $name]
	#puts stdout "val $val def $def"
	if {$val != $def} {
	    puts $rc "set $name \"$val\""
	    incr num
	}
    }
    close $rc
    infomsg "Saved $num non-default pathnames to ~/.iceman_pathnames"
}

proc get_modal_choices {name} {
    global modal_data
#   puts stdout "get_modal_choices $name"
    foreach m $modal_data {
# special for solver
        if {[lindex $m 0] == "solver" && $name == "solver"} \
                {set m [util_parse_solvers $m]}
	if {$name == [lfirst $m]} {return [lindex $m 2]}
    }
    error "no such modal named $name"
}

proc get_modal_choices_presets {name} {
    global modal_data
#   puts stdout "get_modal_choices $name"
    foreach m $modal_data {
# special for solver
        if {[lindex $m 0] == "solver" && $name == "solver"} \
                {set m [util_parse_solvers $m]}
        if {$name == [lfirst $m]} {return [lindex $m 4]}
    }
    error "no such modal named $name"
}

set mods $home/.iceman_modals
if [file exists $mods] {source $mods}

set paths $home/.iceman_pathnames
if [file exists $paths] {source $paths}

switch $ddnterm {
    console { set ddnterm native }
    xterm   { set ddnterm x11 }
}

set westinghouse_output_path \
	$env(ICEM_ACN)/icemcfd/output-interfaces/westinghouse
set iflow_output_path \
	$env(ICEM_ACN)/icemcfd/output-interfaces/iflow
set georampant_output_path $env(ICEM_ACN)/icemcfd/output-interfaces/georampant

