#
# Library functions for the scripting library (scrib)
#
# File: scrib/lib/catia.tcl
#
# $Revision$ on $Date$
# 
# Copyright (c) 1993-2003 ICEM CFD Engineering
#
#--------------------------------------------------------------------
#
# --> if the name of the first proc already exists in interp, return
#
if {"" != [info commands scrib_lib_catia_import]} { return }
#
# --> procs in this file depend on the following scrib/lib/ files--source them
#     I guess we could do this by proc, too, not sure waht's best
#
if 0 {
    # none required
    set required_files ""
    scrib_lib_setup_source_files $required_files
}

## import the catia file <em>layers</em> of <em>model</em> to a
## tetin file <em>tetin</em>

proc scrib_lib_catia_import {model tetin {layers ""} {offset 0} {noshow 0} } {
    global env
    
    set c4args "-tcl --overwrite --family-by-layer  --fix-icemcfd-face-surface-nloops-bug \
	    --one-tetin-file=$tetin"
    if !$offset {
	append c4args " --suppress-points --suppress-curves"
    } else {append c4args " --suppress-points "}

    if {$layers != ""} {append c4args " --layer=$layers "}
    if $noshow {
	append c4args " --triangulation-tolerance=0.001  +show +noshow +pick +nopick \
	     $model"
    } else {
	append c4args " --triangulation-tolerance=0.001  +show -noshow +pick +nopick \
	     $model"
    }
    
    if {[info exists env(SCRIB_CATIA)] && ("" != $env(SCRIB_CATIA))} {
	set catia_cmd [file join $env(SCRIB_CATIA) bin c4tetin]
    } else {
	set catia_cmd [file join $env(ICEM_ACN) bin c4tetin]
    }
    ic_run_application_exec . {} $catia_cmd $c4args
    
    set stat ![file exists $tetin]
    if $stat {
	mess "couldn't import catia file $model"
    }
    
    return $stat
}

## extract and return a nastran-shell-pid from the catia filename <em>file</em>.

proc scrib_lib_catia_file_pid_get {file} {
    #
    # this is probably way to Chrysler specific
    # note generalized proc scrib_lib_geo_filename_naspid_get!
    # it amounts to this:
    # scrib_lib_geo_filename_naspid_get $file "AA AB BB" 7 -1
    #
    foreach str {AA_ BB_ AB_} {
	set loc [string first $str $file]
	if {$loc != -1} {
	    return [string range $file [expr $loc - 7] [expr $loc - 1 ]]
	}
    }
    return 1
}



