Initial commit
This commit is contained in:
473
feeds_speeds/ascii/part_materials.tcl
Normal file
473
feeds_speeds/ascii/part_materials.tcl
Normal file
@@ -0,0 +1,473 @@
|
||||
##############################################################################
|
||||
# REVISIONS
|
||||
# Date Who Reason
|
||||
# 03/24/99 mrm Initial
|
||||
# 05/19/99 mrm New Environment Variable
|
||||
# 07/21/99 Subhash Included dbc_general_ascii.tcl file
|
||||
# 07/21/99 Subhash Used general functions for
|
||||
# opening and reading dat files.
|
||||
# 08/06/99 Subhash Changed some functions to improve performance
|
||||
# 11/11/2003 rlm Add ASC_output_header
|
||||
# 01/30/2004 rlm Move ASC_write to dbc_ascii_general
|
||||
# 02/12/2004 rlm Add library revision information
|
||||
# 07/01/2004 rlm 1339644 Add proc DBC_ask_library_values
|
||||
# 12/06/2004 rlm 1369488 Add proc DBC_execute_query_for_count
|
||||
# 08/25/2005 rlm 5302379 Add proc DBC_translate_att_alias
|
||||
##############################################################################
|
||||
#
|
||||
# The format of each line in the text file is:
|
||||
#
|
||||
# libref Type Manufacturer Designation Control config_file
|
||||
#
|
||||
# partmat is a string
|
||||
# matcode is a string
|
||||
# matname is a string
|
||||
# description is a string
|
||||
# hardness is a string
|
||||
# libref is a string
|
||||
#
|
||||
# The DB_ID of a DB_ALIAS is its field number in the line (0-based)
|
||||
###############################################################################
|
||||
|
||||
|
||||
#---------------------------------------------
|
||||
# Non DBC Global Variables
|
||||
#---------------------------------------------
|
||||
#MOM_set_debug_mode ON
|
||||
#set dbFileName "[MOM_ask_env_var UGII_CAM_LIBRARY_FEEDS_SPEEDS_DATA_DIR]part_materials.dat"
|
||||
set DEBUG 0
|
||||
set fPointer ""
|
||||
|
||||
#---------------------------------------------
|
||||
# Global variables set by DBC for Input/Output
|
||||
#---------------------------------------------
|
||||
set dbc_lhs_exp ""
|
||||
set dbc_rhs_exp ""
|
||||
set dbc_relop ""
|
||||
set dbc_query ""
|
||||
set dbc_subqry1 ""
|
||||
set dbc_subqry2 ""
|
||||
set dbc_boolop ""
|
||||
set dbc_class_name ""
|
||||
set dbc_attr_count 0
|
||||
set dbc_attr_id ""
|
||||
set dbc_query_count 0
|
||||
set dbc_libref ""
|
||||
set dbc_var_list ""
|
||||
set asc_debug 0
|
||||
|
||||
#---------------------------------------------
|
||||
proc ASC_t_create_filename {env_var_name filename} \
|
||||
{
|
||||
#
|
||||
# Creates a complete filename by evaluating an environment variable
|
||||
# for the directory information
|
||||
#
|
||||
set env_var [MOM_ask_env_var $env_var_name]
|
||||
if { $env_var == "" } \
|
||||
{
|
||||
set message "Can't read environment variable $env_var_name"
|
||||
MOM_abort "\n $message"
|
||||
}
|
||||
|
||||
set fname ""
|
||||
set fname [append fname $env_var $filename]
|
||||
|
||||
return $fname
|
||||
|
||||
}
|
||||
|
||||
#---------------------------------------------
|
||||
proc MOM__boot {} {
|
||||
#---------------------------------------------
|
||||
|
||||
# source some general procedures
|
||||
|
||||
#
|
||||
# dbc_ascii_general.tcl
|
||||
#
|
||||
set filename \
|
||||
[ASC_t_create_filename "UGII_UG_LIBRARY_DIR" "dbc_ascii_general.tcl"]
|
||||
|
||||
|
||||
if { [catch {source $filename}] == "1" } \
|
||||
{
|
||||
set message "Can't load .tcl file: $filename"
|
||||
MOM_abort "\n $message"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
proc MOM__halt {} \
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#------------------------------------------------------------
|
||||
proc DBC_init_db { } \
|
||||
{
|
||||
global DEBUG
|
||||
global dataBase
|
||||
global lastRowNumber
|
||||
global dbFileName
|
||||
global fPointer
|
||||
|
||||
set asc_file_name ""
|
||||
set asc_part_units ""
|
||||
|
||||
set data_unit 0
|
||||
set mode 0
|
||||
|
||||
set env_var UGII_CAM_LIBRARY_FEEDS_SPEEDS_DATA_DIR
|
||||
set data_file_name [ASC_t_create_filename "$env_var" "part_materials.dat"]
|
||||
|
||||
|
||||
#
|
||||
# Set the filename for ASCII Data File
|
||||
#
|
||||
ASC_set_data_file_name
|
||||
|
||||
#
|
||||
# And load the file into memory
|
||||
#
|
||||
ASC_load_data_file $data_file_name $data_unit $mode
|
||||
|
||||
|
||||
}
|
||||
|
||||
#---------------------------------------------
|
||||
proc ASC_set_data_file_name {} {
|
||||
#---------------------------------------------
|
||||
global dbc_part_units
|
||||
global asc_file_name
|
||||
global asc_part_units
|
||||
|
||||
MOM_ask_part_units ;# writes to dbc_part_units
|
||||
|
||||
set env_var UGII_CAM_LIBRARY_FEEDS_SPEEDS_DATA_DIR
|
||||
set asc_file_name [ASC_t_create_filename "$env_var" "part_materials.dat"]
|
||||
set asc_part_units $dbc_part_units
|
||||
|
||||
}
|
||||
|
||||
|
||||
#---------------------------------------------
|
||||
proc ExtractExpression {DBC_EXP} {
|
||||
#---------------------------------------------
|
||||
upvar $DBC_EXP dbc_exp
|
||||
global dbc_db_prefix
|
||||
global dbc_db_suffix
|
||||
global dbc_ess_prefix
|
||||
global dbc_ess_suffix
|
||||
|
||||
DBC_ask_db_ess_prefix_suffix
|
||||
|
||||
#Removing DB Prefix and Suffix
|
||||
set pref_flag 0
|
||||
RemovePrefixSuffix dbc_exp dbc_db_prefix dbc_db_suffix pref_flag
|
||||
|
||||
#Removing ESS Prefix and Suffix
|
||||
set pref_flag 1
|
||||
RemovePrefixSuffix dbc_exp dbc_ess_prefix dbc_ess_suffix pref_flag
|
||||
}
|
||||
|
||||
#---------------------------------------------
|
||||
proc RemovePrefixSuffix {DBC_EXP PREFIX SUFFIX PREF_FLAG} {
|
||||
#---------------------------------------------
|
||||
upvar $DBC_EXP dbc_exp
|
||||
upvar $PREFIX prefix
|
||||
upvar $SUFFIX suffix
|
||||
upvar $PREF_FLAG pref_flag
|
||||
|
||||
set pref_len [string length $prefix]
|
||||
set ind 0
|
||||
set prefix_test [string first $prefix $dbc_exp]
|
||||
while {$prefix_test != -1}\
|
||||
{
|
||||
if {$prefix_test > 0}\
|
||||
{
|
||||
append temp_var [string range $dbc_exp 0 [expr $prefix_test - 1]]
|
||||
set dbc_exp [string range $dbc_exp $prefix_test end]
|
||||
set prefix_test [string first $prefix $dbc_exp]
|
||||
}
|
||||
|
||||
set end_val [string first $suffix $dbc_exp]
|
||||
set strt_len [expr $prefix_test + $pref_len]
|
||||
set end_len $end_val
|
||||
|
||||
if {$pref_flag}\
|
||||
{
|
||||
append temp_var [string range $dbc_exp $strt_len [expr $end_len - 1]]
|
||||
set dbc_exp [string range $dbc_exp [expr $end_val + 1] end]
|
||||
} else\
|
||||
{
|
||||
append temp_var [string range $dbc_exp $strt_len $end_len]
|
||||
set dbc_exp [string range $dbc_exp [expr $end_val + 2] end]
|
||||
}
|
||||
set prefix_test [string first $prefix $dbc_exp]
|
||||
|
||||
if {$prefix_test != -1}\
|
||||
{
|
||||
append temp_var [string range $dbc_exp 0 [expr $prefix_test - 1]]
|
||||
set dbc_exp [string range $dbc_exp $prefix_test end]
|
||||
set prefix_test [string first $prefix $dbc_exp]
|
||||
} else\
|
||||
{
|
||||
if {[string length $dbc_exp] > 0}\
|
||||
{
|
||||
append temp_var $dbc_exp
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if {[info exists temp_var]}\
|
||||
{
|
||||
set dbc_exp $temp_var
|
||||
unset temp_var
|
||||
}
|
||||
}
|
||||
|
||||
#------------------------------------------------------------
|
||||
proc DBC_translate_att_alias { } {
|
||||
#------------------------------------------------------------
|
||||
|
||||
ASC_translate_att_alias
|
||||
|
||||
|
||||
}
|
||||
|
||||
#------------------------------------------------------------
|
||||
proc DBC_create_criterion { } {
|
||||
#------------------------------------------------------------
|
||||
global DEBUG
|
||||
global dbc_lhs_exp
|
||||
global dbc_rhs_exp
|
||||
global dbc_relop
|
||||
global dbc_query
|
||||
|
||||
if { "$DEBUG" == "1" } {
|
||||
}
|
||||
|
||||
# set dbc_query "\[$dbc_lhs_exp\] $dbc_relop \[$dbc_rhs_exp\]"
|
||||
|
||||
ASC_create_criterion
|
||||
|
||||
|
||||
}
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
proc DBC_create_query { } {
|
||||
#------------------------------------------------------------------------
|
||||
global DEBUG
|
||||
global dbc_query
|
||||
global dbc_subqry1
|
||||
global dbc_subqry2
|
||||
global dbc_boolop
|
||||
|
||||
# set dbc_query "$dbc_subqry1 $dbc_boolop $dbc_subqry2"
|
||||
|
||||
ASC_create_query
|
||||
}
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
proc DBC_execute_query { } {
|
||||
#------------------------------------------------------------------------
|
||||
global asc_database_count
|
||||
|
||||
ASC_execute_query
|
||||
|
||||
}
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
proc DBC_execute_query_for_count { } {
|
||||
#------------------------------------------------------------------------
|
||||
global asc_database_count
|
||||
|
||||
ASC_execute_query_for_count
|
||||
|
||||
}
|
||||
|
||||
#---------------------------------------------------------------------
|
||||
proc DBC_retrieve { } {
|
||||
#---------------------------------------------------------------------
|
||||
global DEBUG
|
||||
global dbc_libref
|
||||
global dbc_retrieve_var_list
|
||||
global dataBase
|
||||
|
||||
global dbc_material_code
|
||||
global dbc_material_name
|
||||
global dbc_material_description
|
||||
global dbc_material_hardness
|
||||
global fPointer
|
||||
global asc_debug
|
||||
global asc_database_count
|
||||
global asc_file_name
|
||||
|
||||
if { $asc_debug == "1" } \
|
||||
{
|
||||
puts " =========================================="
|
||||
puts " procedure DBC_retrieve for cut methods"
|
||||
puts " libref -> $dbc_libref"
|
||||
}
|
||||
|
||||
#
|
||||
# Look for the desired libref
|
||||
#
|
||||
for {set db_row 0} {$db_row < $asc_database_count} {incr db_row 1} \
|
||||
{
|
||||
# Find the row for the desired LibRef
|
||||
set partmaterial_libref [ASC_ask_att_val LIBRF $db_row \
|
||||
"" 0 flag]
|
||||
if { $dbc_libref == $partmaterial_libref } \
|
||||
{
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if { $db_row >= $asc_database_count } \
|
||||
{
|
||||
set message "Error retrieving Part material from external library."
|
||||
set message "$message \n Cut Method with the library reference $dbc_libref"
|
||||
set message "$message \n does not exist in the"
|
||||
set message "$message \n ASCII Data File: $asc_file_name"
|
||||
MOM_abort "\n $message"
|
||||
}
|
||||
|
||||
|
||||
#
|
||||
# Get the part material code
|
||||
#
|
||||
|
||||
set dbc_material_code [ASC_ask_att_val MATCODE $db_row "%s" "" flag]
|
||||
|
||||
#
|
||||
# Get the Part Material Name
|
||||
#
|
||||
|
||||
set dbc_material_name [ASC_ask_att_val MATNAME $db_row "%s" "" flag]
|
||||
|
||||
#
|
||||
# Get Part material Description
|
||||
#
|
||||
|
||||
set dbc_material_description [ASC_ask_att_val PARTMAT $db_row "%s" "" flag]
|
||||
|
||||
#
|
||||
# Get Part Material Hardness
|
||||
#
|
||||
|
||||
set dbc_material_hardness [ASC_ask_att_val HARDNESS $db_row "%s" "" flag]
|
||||
|
||||
}
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
proc DBC_write { } {
|
||||
#------------------------------------------------------------------------
|
||||
global asc_database_name
|
||||
|
||||
set asc_database_name "part_materials.dat"
|
||||
ASC_write
|
||||
}
|
||||
|
||||
#---------------------------------------------------------------------
|
||||
proc ASC_output_header { fileid } {
|
||||
#---------------------------------------------------------------------
|
||||
global dbc_attr_count
|
||||
global dbc_attr_aliases
|
||||
global dbc_attr_id
|
||||
global dbc_logname
|
||||
|
||||
|
||||
set daytime [clock seconds]
|
||||
set out_daytime [clock format $daytime -format "%a %b %d %Y %I:%M %p"]
|
||||
|
||||
set headerMessage "# PART_MATERIALS.DAT
|
||||
##########################################################################
|
||||
#
|
||||
# PURPOSE:
|
||||
#
|
||||
# This is the database file used for defining Part Material.
|
||||
#
|
||||
# REVISED:
|
||||
# $dbc_logname $out_daytime
|
||||
#
|
||||
##########################################################################
|
||||
##########################################################################
|
||||
##
|
||||
## The following key words for Attribute ids are defined
|
||||
##
|
||||
## MATCODE material_code - Material Code
|
||||
## MATNAME material_name - Material Name (appears on the label)
|
||||
## PARTMAT material_description - Material Description
|
||||
## HARDNESS material_hardness - Material Hardness
|
||||
## LIBREF partmaterial_libref - Unique record identifier
|
||||
## (Library Reference)
|
||||
#########################################################################
|
||||
|
||||
#-----------------+--------------------------------------------+----------------"
|
||||
|
||||
puts $fileid "$headerMessage"
|
||||
|
||||
# load the database structure
|
||||
DBC_load_rset_data
|
||||
|
||||
|
||||
# output FORMAT line
|
||||
set format_line "FORMAT"
|
||||
for {set i 0} {$i < $dbc_attr_count} {incr i} \
|
||||
{
|
||||
DBC_ask_attr_id $dbc_attr_aliases($i)
|
||||
set format_line "$format_line $dbc_attr_id"
|
||||
}
|
||||
puts $fileid $format_line
|
||||
puts $fileid "#--------------------------------------------------------------------------------"
|
||||
}
|
||||
|
||||
proc DBC_ask_library_values {} \
|
||||
{
|
||||
#
|
||||
# global input
|
||||
global dbc_libref
|
||||
global dbc_db_ids_count
|
||||
global dbc_db_ids
|
||||
global dbc_event_error
|
||||
global asc_database_count
|
||||
|
||||
#
|
||||
# global output
|
||||
global dbc_return_status
|
||||
global dbc_db_ids_value
|
||||
|
||||
# Do not change this string
|
||||
set NO_MATCH "No matching record found for $dbc_libref"
|
||||
|
||||
set dbc_return_status 0
|
||||
#
|
||||
# Look for the desired libref
|
||||
#
|
||||
for {set db_row 0} {$db_row < $asc_database_count} {incr db_row 1} \
|
||||
{
|
||||
set partmaterial_libref [ASC_ask_att_val LIBRF $db_row \
|
||||
"" 0 flag]
|
||||
if { $dbc_libref == $partmaterial_libref } \
|
||||
{
|
||||
break
|
||||
}
|
||||
}
|
||||
#
|
||||
# and set the desired values
|
||||
#
|
||||
if { $db_row < $asc_database_count } \
|
||||
{
|
||||
for { set inx 0 } { $inx < $dbc_db_ids_count } { incr inx } \
|
||||
{
|
||||
set dbc_db_ids_value($dbc_db_ids($inx)) \
|
||||
[ASC_ask_att_val $dbc_db_ids($inx) $db_row "" "" flag]
|
||||
}
|
||||
} else \
|
||||
{
|
||||
set dbc_event_error $NO_MATCH
|
||||
set dbc_return_status 1
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user