1
0

Initial commit

This commit is contained in:
2026-02-22 14:16:24 +01:00
commit 1692d191fa
3684 changed files with 10817616 additions and 0 deletions

View File

@@ -0,0 +1,146 @@
################################################################################
# This is the definition file for tool assembly with an ASCII File as the
# database
#
#=======================================================================
#
DB_PREFIX "DB("
DB_SUFFIX ")"
ESS_PREFIX "ESS("
ESS_SUFFIX ")"
#############################################################################
# The list of DB_ALIAS
#
# All the <alias> defined here can be used in the class description at the end
# of this file in order to define the fields that should appear in
# the search criteria and search result dialogs within UG for every class.
#
# DB_ALIAS <alias>
# {
# DB_ID < Attribute Identifier defined in the ASCII Data File >
# DB_ID_TYPE < Type of the identifier >
# d _ double
# i _ integer
# s _ string
# OPTIONS "opt1" "opt2 " "opt3"
# OPTIONS_IDS "val1" "val2" "val3"
# DIALOG_NAME "label in search criteria dialog"
# RSET_NAME "label in search result dialog"
# }
#
# OPTIONS and OPTIONS_IDS can be ommitted, If they are specified
# then a corresponding option menu is created in the Search Criteria Dialog
# instead of a simple search field.
#############################################################################
# The DB_ALIAS of the library reference. It is mandatory that this DB_ALIAS
# appears in the alias list
#
DB_ALIAS libref
{
DB_ID LIBRF
DB_ID_TYPE s
DIALOG_NAME "Libref"
RSET_NAME "Libref"
}
DB_ALIAS Description
{
DB_ID DESCR
DB_ID_TYPE s
DIALOG_NAME "Description"
RSET_NAME "Description"
}
DB_ALIAS Toolref
{
DB_ID TOOLREF
DB_ID_TYPE s
DIALOG_NAME "Tool Reference"
RSET_NAME "Tool Reference"
}
DB_ALIAS ToolType
{
DB_ID TOOLT
DB_ID_TYPE s
DIALOG_NAME "Tool Type"
RSET_NAME "Tool Type"
}
DB_ALIAS ToolSubtype
{
DB_ID TOOLST
DB_ID_TYPE s
DIALOG_NAME "Tool Subtype"
RSET_NAME "Tool Subtype"
}
DB_ALIAS HolderRef
{
DB_ID HOLDREF
DB_ID_TYPE s
DIALOG_NAME "Holder Reference"
RSET_NAME "Holder Reference"
}
DB_ALIAS ShankRef
{
DB_ID SHANKREF
DB_ID_TYPE s
DIALOG_NAME "Shank Reference"
RSET_NAME "Shank Reference"
}
DB_ALIAS ZMount
{
DB_ID ZMOUNT
DB_ID_TYPE d
DIALOG_NAME "(Z) ZMount"
RSET_NAME "(Z) ZMount"
}
DB_ALIAS ToolNum
{
DB_ID TLNUM
DB_ID_TYPE i
DIALOG_NAME "Tool Number"
RSET_NAME "Tool Number"
}
DB_ALIAS AdjReg
{
DB_ID ADJREG
DB_ID_TYPE i
DIALOG_NAME "Adjust Register"
RSET_NAME "Adjust Register"
}
DB_ALIAS CutcomReg
{
DB_ID CUTCOMREG
DB_ID_TYPE i
DIALOG_NAME "Cutcom Register"
RSET_NAME "Cutcom Register"
}
###################################################################
#################################################################
LIBREF libref
#########################################################################
# The Class Hierarchy #
#########################################################################
CLASS ASSEMBLY
{
TYPE QRY
QUERY "[DB(libref)] != [0]"
DIALOG libref Description Toolref ToolType ToolSubtype HolderRef ShankRef ZMount ToolNum AdjReg CutcomReg
RSET libref Description Toolref ToolType ToolSubtype HolderRef ShankRef ZMount ToolNum AdjReg CutcomReg
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,196 @@
###############################################################################
# dbc_tool_ud_data_sample.tcl - Sample to add user defined tool parameters
###############################################################################
###############################################################################
# REVISIONS
# Date Who Reason
# 27-jan-2014 Gopal Srinath & Mark Rief Initial
#
###############################################################################
#
# This is a sample of dbc_tool_ud_data.tcl.
# To demonstrate, rename this file to dbc_tool_ud_data.tcl and retrieve a mill tool.
#
# This is called from dbc_tool_ascii.tcl, and if found, will add user defined
# tool parameters to a tool during retrieval from the library.
#
# This sample will add one user parameter for each type available; and add
# two user parameters based on tool library fields, if they exist.
#
# To see the parameters when editing the tool, the customizable item "user parameters"
# must be added to the tool dialog. To do this for all retrieved tools, add it
# to the tool dialogs in the library_dialogs template parts.
#
###############################################################################
#
#######
# Procedure to initialize the variables for parameters of all types except Option ("o") type
# This procedure will also increment the number of parameters
######
proc SetParameter { name pType value label } {
global dbc_ud_num_parameters
global dbc_ud_param_name
global dbc_ud_param_type
global dbc_ud_param_value
global dbc_ud_param_label
global dbc_ud_grouping_label
set parameterIndex $dbc_ud_num_parameters
set dbc_ud_param_name($parameterIndex) $name ;# Name used for mom variable
set dbc_ud_param_type($parameterIndex) $pType ;# String
set dbc_ud_param_value($parameterIndex) $value
set dbc_ud_param_label($parameterIndex) $label ;# Dialog Label
set dbc_ud_num_parameters [expr $dbc_ud_num_parameters + 1]
}
#######
# Procedure to initialize the variables for parameters of the Option("o") type
# This procedure will also increment the number of parameters
######
proc SetOptionParameter { name value values label } {
global dbc_ud_num_parameters
global dbc_ud_param_option_count
global dbc_ud_param_options
set parameterIndex $dbc_ud_num_parameters
set numOptions [llength $values]
set dbc_ud_param_option_count($parameterIndex) $numOptions
for {set indx 0} {$indx < $numOptions} {incr indx} \
{
set dbc_ud_param_options($parameterIndex,$indx) [lindex $values $indx]
}
SetParameter $name "o" $value $label
}
##############################################
# This procedure will read the data for the libref and find the
# value for a given attribute id (the name of the column)
# The last argument to this procedure will indicate if the attribute id
# was found or not
#
# The possible values for this indicator are
# 0 - The attribute was not found
# 1 - Attribute was found but the value is "" in the database and so the return value will be set to
# the input default value
# 2 - Attribute found and has a value
#################################################
proc AskAttVal { attId dbRow outputFormat defaultValue flagRef } {
upvar $flagRef flag
global asc_database
set cret [catch {set retValue $asc_database($dbRow,$attId)}]
if { $cret } \
{
set retValue $defaultValue
set flag 0
} \
else \
{
set retValue [string trim $retValue]
if { $retValue == "" } \
{
set retValue $defaultValue
set flag 1
} \
else \
{
set flag 2
}
}
if { $outputFormat != "" } {set retValue [format $outputFormat $retValue] }
return $retValue
}
###############################################################
# This procedure will read the data array or the data file for the entry
# of the libref and return the row with the data
############################################################
proc FindEntry { } {
global asc_file_loaded
global dbc_libref
# This section is reading
if { $asc_file_loaded == 1 } \
{
ASC_array_search_libref $dbc_libref db_row
} \
else \
{
ASC_file_search_libref $dbc_libref db_row
}
return $db_row
}
####################################################
# The procedure that adds User Defined Parameters
####################################################
proc DBC_ud_data {} {
global dbc_ud_num_parameters
global dbc_ud_param_name
global dbc_ud_param_type
global dbc_ud_param_value
global dbc_ud_param_option_count
global dbc_ud_param_options
global dbc_ud_param_label
global dbc_ud_grouping_label
# Initialize number of parameters
set dbc_ud_num_parameters 0
# Label for the UI group
set dbc_ud_grouping_label "User Tool Parameters" ;
# Define some sample parameters directly
# Define integer parameter
SetParameter "sample_int" "i" -1 "Sample Integer"
# Define double parameter
SetParameter "sample_dbl" "d" -1 "Sample Double"
# Define boolean parameter
SetParameter "sample_bool" "b" "True" "Sample Toggle (Boolean)"
# Define string parameter
SetParameter "sample_str" "s" "default text" "Sample Text (String)"
# Define option list parameter
set values { "Yes" "No" "Maybe" }
set value [lindex $values 0]
SetOptionParameter "sample_opt" $value $values "Sample Option List"
# Define some sample parameters based on tool database fields
# Read the database to find the data of the libref
set dbRow [FindEntry]
#####
# The following is an example of reading 2 Attributes from the database
# and then deciding if a parameter has to be added. In order to see the different behavior
# retrieve tools from the following classes
#
# Tool->Milling->End Mill - TAPA and TIPA are both valid and so there will be 2 additional
# Tool->Milling->Ball Mill - TAPA is valid so only 1 additional parameter
# Tool->Milling->Mill Form Tool - Both TAPA and TIPA are not valid so no additional parameters
#
######
# Search for an Attribute TAPA (Taper Angle) for the OOTB database
set angle [AskAttVal TAPA $dbRow "%g" 0 flag]
# If this attribute exists for the tool selected then take the value and convert it to degrees
# and add a parameter called TAPA
if { $flag == 1 || $flag == 2 } {
UGLIB_convert_deg_to_rad $angle
SetParameter "TAPA" "d" $angle "Taper Angle (Library TAPA)"
}
# Search for an Attribute TIPA (Tip Angle) for the OOTB database
set angle [AskAttVal TIPA $dbRow "%g" 0 flag]
# If this attribute exists for the tool selected then take the value and convert it to degrees
# and add a parameter called TIPA
if { $flag == 1 || $flag == 2 } {
UGLIB_convert_deg_to_rad $angle
SetParameter "TIPA" "d" $angle "Tip Angle (Library TIPA)"
}
}

688
tool/ascii/holder_ascii.def Normal file
View File

@@ -0,0 +1,688 @@
################################################################################
# This is the definition file for tool holders with an ASCII File as the
# database
#
###############################################################################
DB_PREFIX "DB("
DB_SUFFIX ")"
ESS_PREFIX "ESS("
ESS_SUFFIX ")"
#############################################################################
# The list of DB_ALIAS
#
# All the <alias> defined here can be used in the class description at the end
# of this file in order to define the fields that should appear in
# the search criteria and search result dialogs within UG for every class.
#
# DB_ALIAS <alias>
# {
# DB_ID < Attribute Identifier defined in the ASCII Data File >
# DB_ID_TYPE < Type of the identifier >
# d _ double
# i _ integer
# s _ string
# OPTIONS "opt1" "opt2 " "opt3"
# OPTIONS_IDS "val1" "val2" "val3"
# DIALOG_NAME "label in search criteria dialog"
# RSET_NAME "label in search result dialog"
# }
#
# OPTIONS and OPTIONS_IDS can be ommitted, If they are specified
# then a corresponding option menu is created in the Search Criteria Dialog
# instead of a simple search field.
#############################################################################
# The DB_ALIAS of the library reference. It is mandatory that this DB_ALIAS
# appears in the alias list
#
DB_ALIAS libref
{
DB_ID LIBRF
DB_ID_TYPE s
DIALOG_NAME "Libref"
RSET_NAME "Libref"
}
DB_ALIAS RecType
{
DB_ID RTYPE
DB_ID_TYPE i
}
##################################################################
DB_ALIAS Type
{
DB_ID HTYPE
DB_ID_TYPE i
}
DB_ALIAS SubType
{
DB_ID STYPE
DB_ID_TYPE i
}
DB_ALIAS N_Sections
{
DB_ID SNUM
DB_ID_TYPE i
}
DB_ALIAS Max_offset
{
DB_ID MAXOFF
DB_ID_TYPE d
}
DB_ALIAS Min_diameter
{
DB_ID MINDIA
DB_ID_TYPE d
}
DB_ALIAS Max_diameter
{
DB_ID MAXDIA
DB_ID_TYPE d
}
DB_ALIAS Description
{
DB_ID DESCR
DB_ID_TYPE s
}
DB_ALIAS MountingStyle
{
DB_ID MTS
DB_ID_TYPE s
OPTIONS "none" "BT30" "BT40" "BT50" "CAT30" "CAT40" "CAT50" "CAT60" "HSK_32A" "HSK_40A" "HSK_50A" "HSK_63A" "HSK_80A" "HSK_100A" "HSK_125A" "HSK_160A" "HSK_25E" "HSK_32E" "HSK_40E" "HSK_50E" "HSK_63E" "SK30" "SK40" "SK50"
OPTIONS_IDS "none" "BT30" "BT40" "BT50" "CAT30" "CAT40" "CAT50" "CAT60" "HSK_32A" "HSK_40A" "HSK_50A" "HSK_63A" "HSK_80A" "HSK_100A" "HSK_125A" "HSK_160A" "HSK_25E" "HSK_32E" "HSK_40E" "HSK_50E" "HSK_63E" "SK30" "SK40" "SK50"
DIALOG_NAME "Mounting Style"
RSET_NAME "Mounting Style"
}
#######################################################################
DB_ALIAS Seq_no
{
DB_ID SEQ
DB_ID_TYPE i
}
DB_ALIAS Diameter
{
DB_ID DIAM
DB_ID_TYPE d
DIALOG_NAME "(D) Diameter "
RSET_NAME "(D) Diameter "
}
DB_ALIAS Height
{
DB_ID LENGTH
DB_ID_TYPE d
DIALOG_NAME "(L) Height"
RSET_NAME "(L) Height"
}
DB_ALIAS TaperAngle
{
DB_ID TAPER
DB_ID_TYPE d
DIALOG_NAME "(B) Taper Angle"
RSET_NAME "(B) Taper Angle"
}
DB_ALIAS CornerRadius
{
DB_ID CRAD
DB_ID_TYPE d
DIALOG_NAME "(R1) Corner Radius"
RSET_NAME "(R1) Corner Radius"
}
# for standard turning tool holder
DB_ALIAS HolderStyle
{
DB_ID HSTYLE
DB_ID_TYPE s
OPTIONS "All" "A-Style" "B-Style" "C-Style" "D-Style" "E-Style" "F-Style" "G-Style" "H-Style" "I-Style" "J-Style" "K-Style" "L-Style" "M-Style" "N-Style" "O-Style" "P-Style" "Q-Style" "R-Style" "S-Style" "T-Style" "U-Style" "V-Style" "UD-Style"
OPTIONS_IDS "%" "0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "10" "11" "12" "13" "14" "15" "16" "17" "18" "19" "20" "21" "22"
DIALOG_NAME "Holder Style"
RSET_NAME "Holder Style"
}
DB_ALIAS HolderHand
{
DB_ID HHAND
DB_ID_TYPE s
OPTIONS "All" "Hand-Left" "Hand-Neutral" "Hand-Right"
OPTIONS_IDS "%" "0" "1" "2"
DIALOG_NAME "Holder Hand"
RSET_NAME "Holder Hand"
}
DB_ALIAS HolderLength
{
DB_ID HLENGTH
DB_ID_TYPE d
DIALOG_NAME "(L) Holder Length"
RSET_NAME "(L) Holder Length"
}
DB_ALIAS HolderWidth
{
DB_ID HWIDTH
DB_ID_TYPE d
DIALOG_NAME "(W) Holder Width"
RSET_NAME "(W) Holder Width"
}
DB_ALIAS ShankType
{
DB_ID SHANKT
DB_ID_TYPE s
OPTIONS "All" "Square-Shank" "Round-Shank"
OPTIONS_IDS "%" "0" "1"
DIALOG_NAME "Shank Type"
RSET_NAME "Shank Type"
}
DB_ALIAS ShankWidth
{
DB_ID SHANKW
DB_ID_TYPE d
DIALOG_NAME "(SW) Shank Width"
RSET_NAME "(SW) Shank Width"
}
DB_ALIAS ShankLine
{
DB_ID SHANKL
DB_ID_TYPE d
DIALOG_NAME "(SL) Shank Line"
RSET_NAME "(SL) Shank Line"
}
DB_ALIAS HolderAngle
{
DB_ID HANGLE
DB_ID_TYPE d
DIALOG_NAME "(HA) Holder Angle"
RSET_NAME "(HA) Holder Angle"
}
DB_ALIAS ShankHeight
{
DB_ID SHANKH
DB_ID_TYPE d
DIALOG_NAME "(SH) Shank Height"
RSET_NAME "(SH) Shank Height"
}
DB_ALIAS ShankDefinitionMode
{
DB_ID SDEFMODE
DB_ID_TYPE s
OPTIONS "All" "Insert And Holder" "Cutting Edge Angle"
OPTIONS_IDS "%" "0" "1"
DIALOG_NAME "Shank Definition Mode"
RSET_NAME "Shank Definition Mode"
}
DB_ALIAS CuttingEdgeAngle
{
DB_ID CEA
DB_ID_TYPE d
DIALOG_NAME "(CEA) Cutting Edge Angle"
RSET_NAME "(CEA) Cutting Edge Angle"
}
DB_ALIAS AdapterUse
{
DB_ID ADAPTER
DB_ID_TYPE s
OPTIONS "All" "No" "Yes"
OPTIONS_IDS "%" "0" "1"
DIALOG_NAME "Adapter Use"
RSET_NAME "Adapter Use"
}
DB_ALIAS AdapterStyle
{
DB_ID ASTYLE
DB_ID_TYPE s
OPTIONS "All" "Axial" "Radial"
OPTIONS_IDS "%" "0" "1"
DIALOG_NAME "Adapter Style"
RSET_NAME "Adapter Style"
}
DB_ALIAS AdapterLength
{
DB_ID ALENGTH
DB_ID_TYPE d
DIALOG_NAME "(L) Adapter Length"
RSET_NAME "(L) Adapter Length"
}
DB_ALIAS AdapterWidth
{
DB_ID AWIDTH
DB_ID_TYPE d
DIALOG_NAME "(W) Adapter Width"
RSET_NAME "(W) Adapter Width"
}
DB_ALIAS AdapterHeight
{
DB_ID AHEIGHT
DB_ID_TYPE d
DIALOG_NAME "(H) Adapter Height"
RSET_NAME "(H) Adapter Height"
}
DB_ALIAS AdapterDiameter
{
DB_ID ADIAM
DB_ID_TYPE d
DIALOG_NAME "(DIA) Adapter Diameter"
RSET_NAME "(DIA) Adapter Diameter"
}
DB_ALIAS AdapterZOffset
{
DB_ID AZOFF
DB_ID_TYPE d
DIALOG_NAME "(Z-OFF) Adapter Z-Offset"
RSET_NAME "(Z-OFF) Adapter Z-Offset"
}
DB_ALIAS AdapterStepLength
{
DB_ID ASTEPLEN
DB_ID_TYPE d
DIALOG_NAME "(SL) Adapter Step Length"
RSET_NAME "(SL) Adapter Step Length"
}
DB_ALIAS AdapterStepDiameter
{
DB_ID ASTEPDIAM
DB_ID_TYPE d
DIALOG_NAME "(SDIA) Adapter Step Diameter"
RSET_NAME "(SDIA) Adapter Step Diameter"
}
DB_ALIAS AdapterTaperLength
{
DB_ID ATAPERLEN
DB_ID_TYPE d
DIALOG_NAME "(TL) Adapter Taper Length"
RSET_NAME "(TL) Adapter Taper Length"
}
DB_ALIAS AdapterTaperAngle
{
DB_ID ATAPERANG
DB_ID_TYPE d
DIALOG_NAME "(TA) Adapter Taper Angle"
RSET_NAME "(TA) Adapter Taper Angle"
}
DB_ALIAS AdapterBlockLength
{
DB_ID ABLCKLEN
DB_ID_TYPE d
DIALOG_NAME "(BL) Adapter Block Length"
RSET_NAME "(BL) Adapter Block Length"
}
DB_ALIAS AdapterBlockWidth
{
DB_ID ABLCKWID
DB_ID_TYPE d
DIALOG_NAME "(BW) Adapter Block Width"
RSET_NAME "(BW) Adapter Block Width"
}
DB_ALIAS AdapterBlockHeight
{
DB_ID ABLCKHGHT
DB_ID_TYPE d
DIALOG_NAME "(BH) Adapter Block Height"
RSET_NAME "(BH) Adapter Block Height"
}
# for grooving tool holder
DB_ALIAS GrooveStyle
{
DB_ID GSTYLE
DB_ID_TYPE s
OPTIONS "All" "Groove-0" "Groove-45" "Groove-90" "Groove-UD"
OPTIONS_IDS "%" "23" "24" "25" "26"
DIALOG_NAME "Holder Style"
RSET_NAME "Holder Style"
}
DB_ALIAS InsertExtension
{
DB_ID INSERTX
DB_ID_TYPE d
DIALOG_NAME "(IE) Insert Extension"
RSET_NAME "(IE) Insert Extension"
}
###################################################################
#################################################################
LIBREF libref
#########################################################################
# The Class Hierarchy #
#########################################################################
CLASS HOLDER
{
TYPE QRY
QUERY "[DB(libref)] != [0] && DB(RecType) == [1]"
DIALOG libref
RSET libref Type SubType
UI_NAME "Holder"
CLASS MILLING_DRILLING
{
TYPE QRY
QUERY "[DB(Type)] == [01]"
DIALOG libref Type
RSET libref Description N_Sections Max_offset
UI_NAME "Milling_Drilling"
CLASS BT30
{
TYPE QRY
QUERY "[DB(MountingStyle)] == [BT30]"
DIALOG libref Description
RSET libref Description N_Sections Max_offset
UI_NAME "BT30"
}
CLASS BT40
{
TYPE QRY
QUERY "[DB(MountingStyle)] == [BT40]"
DIALOG libref Description
RSET libref Description N_Sections Max_offset
UI_NAME "BT40"
}
CLASS BT50
{
TYPE QRY
QUERY "[DB(MountingStyle)] == [BT50]"
DIALOG libref Description
RSET libref Description N_Sections Max_offset
UI_NAME "BT50"
}
CLASS CAT30
{
TYPE QRY
QUERY "[DB(MountingStyle)] == [CAT30]"
DIALOG libref Description
RSET libref Description N_Sections Max_offset
UI_NAME "CAT30"
}
CLASS CAT40
{
TYPE QRY
QUERY "[DB(MountingStyle)] == [CAT40]"
DIALOG libref Description
RSET libref Description N_Sections Max_offset
UI_NAME "CAT40"
}
CLASS CAT50
{
TYPE QRY
QUERY "[DB(MountingStyle)] == [CAT50]"
DIALOG libref Description
RSET libref Description N_Sections Max_offset
UI_NAME "CAT50"
}
CLASS CAT60
{
TYPE QRY
QUERY "[DB(MountingStyle)] == [CAT60]"
DIALOG libref Description
RSET libref Description N_Sections Max_offset
UI_NAME "CAT60"
}
CLASS HSK_32A
{
TYPE QRY
QUERY "[DB(MountingStyle)] == [HSK_32A]"
DIALOG libref Description
RSET libref Description N_Sections Max_offset
UI_NAME "HSK_32A"
}
CLASS HSK_40A
{
TYPE QRY
QUERY "[DB(MountingStyle)] == [HSK_40A]"
DIALOG libref Description
RSET libref Description N_Sections Max_offset
UI_NAME "HSK_40A"
}
CLASS HSK_50A
{
TYPE QRY
QUERY "[DB(MountingStyle)] == [HSK_50A]"
DIALOG libref Description
RSET libref Description N_Sections Max_offset
UI_NAME "HSK_50A"
}
CLASS HSK_63A
{
TYPE QRY
QUERY "[DB(MountingStyle)] == [HSK_63A]"
DIALOG libref Description
RSET libref Description N_Sections Max_offset
UI_NAME "HSK_63A"
}
CLASS HSK_80A
{
TYPE QRY
QUERY "[DB(MountingStyle)] == [HSK_80A]"
DIALOG libref Description
RSET libref Description N_Sections Max_offset
UI_NAME "HSK_80A"
}
CLASS HSK_100A
{
TYPE QRY
QUERY "[DB(MountingStyle)] == [HSK_100A]"
DIALOG libref Description
RSET libref Description N_Sections Max_offset
UI_NAME "HSK_100A"
}
CLASS HSK_125A
{
TYPE QRY
QUERY "[DB(MountingStyle)] == [HSK_125A]"
DIALOG libref Description
RSET libref Description N_Sections Max_offset
UI_NAME "HSK_125A"
}
CLASS HSK_160A
{
TYPE QRY
QUERY "[DB(MountingStyle)] == [HSK_160A]"
DIALOG libref Description
RSET libref Description N_Sections Max_offset
UI_NAME "HSK_160A"
}
CLASS HSK_25E
{
TYPE QRY
QUERY "[DB(MountingStyle)] == [HSK_25E]"
DIALOG libref Description
RSET libref Description N_Sections Max_offset
UI_NAME "HSK_25E"
}
CLASS HSK_32E
{
TYPE QRY
QUERY "[DB(MountingStyle)] == [HSK_32E]"
DIALOG libref Description
RSET libref Description N_Sections Max_offset
UI_NAME "HSK_32E"
}
CLASS HSK_40E
{
TYPE QRY
QUERY "[DB(MountingStyle)] == [HSK_40E]"
DIALOG libref Description
RSET libref Description N_Sections Max_offset
UI_NAME "HSK_40E"
}
CLASS HSK_50E
{
TYPE QRY
QUERY "[DB(MountingStyle)] == [HSK_50E]"
DIALOG libref Description
RSET libref Description N_Sections Max_offset
UI_NAME "HSK_50E"
}
CLASS HSK_63E
{
TYPE QRY
QUERY "[DB(MountingStyle)] == [HSK_63E]"
DIALOG libref Description
RSET libref Description N_Sections Max_offset
UI_NAME "HSK_63E"
}
CLASS SK30
{
TYPE QRY
QUERY "[DB(MountingStyle)] == [SK30]"
DIALOG libref Description
RSET libref Description N_Sections Max_offset
UI_NAME "SK30"
}
CLASS SK40
{
TYPE QRY
QUERY "[DB(MountingStyle)] == [SK40]"
DIALOG libref Description
RSET libref Description N_Sections Max_offset
UI_NAME "SK40"
}
CLASS SK50
{
TYPE QRY
QUERY "[DB(MountingStyle)] == [SK50]"
DIALOG libref Description
RSET libref Description N_Sections Max_offset
UI_NAME "SK50"
}
}
CLASS TURNING
{
TYPE QRY
QUERY "[DB(Type)] == [02]"
DIALOG libref Type
RSET libref Description SubType
UI_NAME "Turning"
CLASS TURNING_STD
{
TYPE QRY
QUERY "[DB(SubType)] == [0]"
DIALOG libref Description
RSET libref Description
UI_NAME "Std_Turning_Tool_Holder"
}
CLASS GROOVE
{
TYPE QRY
QUERY "[DB(SubType)] == [1]"
DIALOG libref Description
RSET libref Description
UI_NAME "Grooving_Tool_Holder"
}
CLASS THREAD
{
TYPE QRY
QUERY "[DB(SubType)] == [2]"
DIALOG libref Description
RSET libref Description
UI_NAME "Threading_Tool_Holder"
}
}
CLASS LASER
{
TYPE QRY
QUERY "[DB(Type)] == [03]"
DIALOG libref Type
RSET libref Description N_Sections Max_offset
UI_NAME "Laser"
}
CLASS WEDM
{
TYPE QRY
QUERY "[DB(Type)] == [04]"
DIALOG libref Type
RSET libref Description N_Sections
UI_NAME "Wire EDM"
}
CLASS FDM
{
TYPE QRY
QUERY "[DB(Type)] == [05]"
DIALOG libref Type
RSET libref Description N_Sections
UI_NAME "FDM"
}
CLASS ADDITIVE_TAPE
{
TYPE QRY
QUERY "[DB(Type)] == [06]"
DIALOG libref Type
RSET libref Description N_Sections
UI_NAME "TAPE"
}
}

1382
tool/ascii/holder_ascii.tcl Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,132 @@
DB_PREFIX "DB("
DB_SUFFIX ")"
ESS_PREFIX "ESS("
ESS_SUFFIX ")"
# This is the definition file for multitools with an ASCII File
# as the database
#
#
#=======================================================================
# REVISIONS
# Date Name Description of Change
#
# 12-Oct-2016 JM Initial Release
#
###############################################################################
#############################################################################
# The list of DB_ALIAS
#
# All the <alias> defined here can be used in the class description at the
# end of this file in order to define the fields that should appear in
# the search criteria and search result dialogs within UG for every class.
#
# DB_ALIAS <alias>
# {
# DB_ID < Attribute Identifier defined in the ASCII Data File >
# DB_ID_TYPE < Type of the identifier >
# d _ double
# i _ integer
# s _ string
# OPTIONS "opt1" "opt2 " "opt3"
# OPTIONS_IDS "val1" "val2" "val3"
# DIALOG_NAME "label in search criteria dialog"
# RSET_NAME "label in search result dialog"
# }
#
# OPTIONS and OPTIONS_IDS can be ommitted, If they are specified
# then a corresponding option menu is created in the Search Criteria Dialog
# instead of a simple search field.
#############################################################################
# The DB_ALIAS of the library reference. It is mandatory that this DB_ALIAS
# appears in the alias list
#
DB_ALIAS libref
{
DB_ID LIBRF
DB_ID_TYPE s
DIALOG_NAME "Libref"
RSET_NAME "Libref"
}
##################################################################
#
# General Attributes
#
##################################################################
DB_ALIAS Type
{
DB_ID T
DB_ID_TYPE i
}
DB_ALIAS SubType
{
DB_ID STYPE
DB_ID_TYPE i
}
DB_ALIAS Seq_no
{
DB_ID SEQ
DB_ID_TYPE i
}
#######################################################################
#
# multi-tool Attributes
#
#######################################################################
DB_ALIAS CutterID
{
DB_ID CUTTERID
DB_ID_TYPE s
}
DB_ALIAS CutterLibref
{
DB_ID CUTTERLIBRF
DB_ID_TYPE s
}
###################################################################
#################################################################
LIBREF libref
#########################################################################
# The Class Hierarchy #
#########################################################################
CLASS MULTITOOL
{
TYPE QRY
QUERY "[DB(libref)] != [0]"
DIALOG libref
RSET libref Type SubType
UI_NAME "Multi_tool"
}

View File

@@ -0,0 +1,861 @@
###############################################################################
# multitool_ascii.tcl - DBC Event Handler for database stored as ascii file
###############################################################################
##############################################################################
# REVISIONS
# Date Who Reason
# 12-Oct-2016 JM initial release
##############################################################################
#
# the variable below will control the output format for angle in segment data
set dbc_segment_angle_decimal_place 5
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 asc_debug
global asc_file_name
global asc_units
global asc_part_units
global asc_mm_file_name
global asc_inch_file_name
global asc_file_loaded
global asc_file_load_limit
#
# Global variables set by DBC for Input/Output
#
global dbc_lhs_exp
global dbc_rhs_exp
global dbc_relop
global dbc_query
global dbc_subqry1
global dbc_subqry2
global dbc_boolop
global dbc_class_name
global dbc_attr_count
global dbc_attr_id
global dbc_query_count
global dbc_libref
global dbc_var_list
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
set asc_file_name ""
set asc_part_units ""
set dbc_cutter_ass_units ""
#
# Set the unit for tool search to the part unit
#
ASC_set_part_unit
#
# ask the mm and inch filenames
#
set asc_mm_file_name [ASC_get_data_file_name $asc_units(mm)]
set asc_inch_file_name [ASC_get_data_file_name $asc_units(inch)]
if { $asc_mm_file_name == "" && $asc_inch_file_name == "" } \
{
set message "Error looking for a multitool_database.dat file."
set message "$message \n Neither of the environment variables"
set message "$message \n UGII_CAM_LIBRARY_TOOL_METRIC_DIR,"
set message "$message \n UGII_CAM_LIBRARY_TOOL_ENGLISH_DIR"
set message "$message \n is defined."
MOM_abort "\n $message"
}
#
# mm file
#
set app 0
set mm_file_loaded 0
#MOM_output_to_listing_device "xxxxxxxxxxxxxxxxxxxxxxxx init_db xxxxxxxxxxxxxxxxxxxx"
set ret_cd [ASC_load_data_file $asc_mm_file_name $asc_units(mm) $app]
if { $ret_cd != 0 } \
{
set message "Error, can't open file:"
set message "$message \n $asc_mm_file_name"
MOM_abort "\n $message"
}
set app 1
set mm_file_loaded 1
#
# and then inch file
#
set inch_file_loaded 0
set ret_cd [ASC_load_data_file $asc_inch_file_name $asc_units(inch) $app]
if { $ret_cd != 0 } \
{
set message "Error, can't open file:"
set message "$message \n $asc_inch_file_name"
MOM_abort "\n $message"
}
set inch_file_loaded 1
#
# if mm or inch or both files are loaded set the flag
#
if { $inch_file_loaded == 1 || $mm_file_loaded == 1 } \
{
set asc_file_loaded 1
}
#
# This variable is only used for error messages
#
set asc_file_name " $asc_mm_file_name"
set asc_file_name "$asc_file_name \n $asc_inch_file_name"
}
proc ASC_get_data_file_name { unit } \
{
#
# Returns the filename for ASCII Data File depending on the
# specified unit.
#
global asc_units
if {$unit == $asc_units(mm)} \
{
set env_var_name UGII_CAM_LIBRARY_TOOL_METRIC_DIR
} \
else \
{
set env_var_name UGII_CAM_LIBRARY_TOOL_ENGLISH_DIR
}
set env_var [MOM_ask_env_var $env_var_name]
if { $env_var == "" } \
{
return ""
}
set fname ""
set fname [append fname $env_var "multitool_database.dat"]
return $fname
}
proc ASC_set_part_unit {} \
{
global dbc_part_units
global dbc_search_units
global asc_units
MOM_ask_part_units ;# writes to dbc_part_units
if {$dbc_part_units == "metric"} \
{
set dbc_search_units $asc_units(mm)
} \
else \
{
set dbc_search_units $asc_units(inch)
}
}
#---------------------------------------------
proc DBC_retrieve {} {
#---------------------------------------------
global dbc_libref
ASC_retrieve
}
#---------------------------------------------
proc ASC_retrieve {} {
#---------------------------------------------
#
# global input
# ------------
global asc_debug
global asc_units
global dbc_search_units
global dbc_libref
global db_row
global asc_file_loaded
global asc_database
global asc_database_count
global asc_file_name
#
# global output
# -------------
global dbc_multitool_is_multitool
set dbc_multitool_is_multitool 0
global dbc_multitool_cutterlibref
global dbc_multitool_cutterid
global dbc_multitool_type
global dbc_multitool_subtype
#
# Look for the desired libref
#
if { $asc_file_loaded == 1 } \
{
ASC_array_search_libref $dbc_libref db_row
} \
else \
{
ASC_file_search_libref $dbc_libref db_row
}
if {$db_row >= 0} \
{
set dbc_multitool_type [ASC_ask_att_val T $db_row "%d" 0 flag]
set dbc_multitool_type [ASC_ask_att_val STYPE $db_row "%d" 0 flag]
ASC_load_multitool_data
}
}
proc ASC_load_multitool_data {} \
{
global dbc_attr_count
global dbc_attr_aliases
global dbc_attr_id
global dbc_libref
global dbc_query_count
global dbc_multitool_is_multitool
set dbc_multitool_is_multitool 0
global dbc_multitool_cutterlibref
global dbc_multitool_cutterid
global dbc_multitool_cutter_count
global asc_database_count
#MOM_output_to_listing_device "asc_database_count = $asc_database_count"
# Initialize environment
set dbc_multitool_cutter_count 0
set indx 0
# Cycle database looking for matching data records
for {set db_row 0} {$db_row < $asc_database_count} { incr db_row 1} \
{
set tmp_libref [ASC_ask_att_val LIBRF $db_row "" 0 flag]
if {$tmp_libref == $dbc_libref} \
{
set dbc_multitool_is_multitool 1
set dbc_multitool_cutterlibref($indx) \
[ASC_ask_att_val CUTTERLIBRF $db_row "%s" 0 flag]
set dbc_multitool_cutterid($indx) \
[ASC_ask_att_val CUTTERID $db_row "%s" 0 flag]
incr indx
set dbc_multitool_cutter_count $indx
}
}
}
proc DBC_ask_library_values {} \
{
#
# global input
global dbc_libref
global dbc_db_ids_count
global dbc_db_ids
global asc_file_loaded
#
# global output
global dbc_db_ids_value
#
# Look for the desired libref
#
if { $asc_file_loaded == 1 } \
{
ASC_array_search_libref $dbc_libref db_row
} \
else \
{
ASC_file_search_libref $dbc_libref db_row
}
#
# and set the desired values
#
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]
}
}
#---------------------------------------------
proc DBC_translate_att_alias {} {
#---------------------------------------------
ASC_translate_att_alias
}
#---------------------------------------------
proc DBC_create_criterion {} {
#---------------------------------------------
ASC_create_criterion
}
#---------------------------------------------
proc DBC_create_query {} {
#---------------------------------------------
ASC_create_query
}
#---------------------------------------------
proc DBC_execute_query {} {
#---------------------------------------------
global asc_file_loaded
global dbc_query
global dbc_search_units
if { $asc_file_loaded == 0 } \
{
ASC_file_exec_qry 0
} \
else \
{
ASC_append_unit_to_query
ASC_execute_query
}
}
#---------------------------------------------
proc DBC_execute_query_for_count {} {
#---------------------------------------------
global asc_file_loaded
global dbc_query
if { $asc_file_loaded == 0 } \
{
ASC_file_exec_qry 1
} \
else \
{
ASC_append_unit_to_query
ASC_execute_query_for_count
}
}
#--------------------------------------------
proc DBC_insert {} {
#--------------------------------------------
ASC_insert
}
proc ASC_append_unit_to_query {} \
{
global dbc_search_units
global dbc_query
global asc_units
set lhs "\$asc_database(\$db_row,_unitt)"
set subquery1 "($lhs == \"$asc_units(unknown)\")"
set subquery2 "($lhs == \"$dbc_search_units\")"
set subquery "($subquery1 || $subquery2)"
set dbc_query "$dbc_query && $subquery"
}
proc ASC_file_exec_qry { for_count } \
{
#
# Executes the query on a file depending on the current setting
# of the dbc_search_units
#
# for_count = 1 => do only execute_query_for_count
global dbc_search_units
global asc_units
global asc_mm_file_name
global asc_inch_file_name
global dbc_query_count
global dbc_query
global units_from_query
if {[info exists units_from_query]} {
set dbc_search_units $units_from_query
unset units_from_query
}
if { $dbc_search_units == $asc_units(mm) } \
{
set file_name $asc_mm_file_name
set units $asc_units(mm)
} \
else \
{
set file_name $asc_inch_file_name
set units $asc_units(inch)
}
set dbc_query_count 0
if { $for_count == 1 } \
{
set ret_cd [ASC_file_execute_query_for_count $file_name $units]
} \
else \
{
set ret_cd [ASC_file_execute_query $file_name $units]
}
if { $ret_cd != 0 } \
{
set message "Error, can't open file:"
set message "$message \n $file_name"
MOM_abort "\n $message"
}
}
proc ASC_file_search_libref { libref db_row_ref } \
{
upvar $db_row_ref db_row
global dbc_search_units
global asc_units
global asc_mm_file_name
global asc_inch_file_name
global asc_file_name
#
# We search in mm and inch file for the desired libref
#
set found 2
if { $dbc_search_units == $asc_units(mm) } \
{
#
# Start with the mm file
if { $asc_mm_file_name != "" } \
{
set found [ASC_file_find_object_by_att \
$asc_mm_file_name $asc_units(mm) \
LIBRF $libref db_row]
if { $found != 0 } \
{
# Not found -> Try again with the inch file
if { $asc_inch_file_name != "" } \
{
set found [ASC_file_find_object_by_att \
$asc_inch_file_name $asc_units(inch) \
LIBRF $libref db_row]
}
}
}
} \
else \
{
#
# Start with the inch file
if { $asc_inch_file_name != "" } \
{
set found [ASC_file_find_object_by_att \
$asc_inch_file_name $asc_units(inch) \
LIBRF $libref db_row]
if { $found != 0 } \
{
# Not found -> Try again with the mm file
if { $asc_mm_file_name != "" } \
{
set found [ASC_file_find_object_by_att \
$asc_mm_file_name $asc_units(mm) \
LIBRF $libref db_row]
}
}
}
}
if { $found == 2 } \
{
set message "Error retrieving segmented tool from external library."
set message "$message \n Tool with the library reference $libref"
set message "$message \n does not exist in the"
set message "$message \n ASCII Data File(s):"
set message "$message \n $asc_file_name"
MOM_abort "\n $message"
}
if { $found == 1 } \
{
set message "Error retrieving segmented tool from external library."
set message "$message \n Neither of the files"
set message "$message \n $asc_mm_file_name"
set message "$message \n $asc_inch_file_name"
set message "$message \n can be read."
MOM_abort "\n $message"
}
}
proc ASC_array_search_libref { libref db_row_ref } \
{
upvar $db_row_ref db_row
global asc_file_name
set found [ASC_array_find_object_by_att LIBRF $libref db_row ]
if { $found == 2 } \
{
set db_row -1
}
}
proc ASC_insert {} \
{
global asc_database_name
global asc_file_name
global asc_units
global dbc_part_units
global dbc_event_error
global dbc_logname
global dbc_class
# In this multitool interp the class is always multitool
set dbc_class "MULTITOOL"
global dbc_libref
global dbc_segment_count
global dbc_clsf_decimal_places
global mom_clsf_decimal_places
global asc_cur_line
global asc_record_type
global asc_class
global asc_record_libref
global num_formats_processed
if {$dbc_part_units == "metric"} \
{
set base_filename [ASC_get_data_file_name $asc_units(mm)]
} else \
{
set base_filename [ASC_get_data_file_name $asc_units(inch)]
}
set asc_tempname $base_filename
append asc_tempname "_tmp"
set asc_backupname $base_filename
append asc_backupname "_bak"
# back up the existing version of the library
if [catch {file copy -force $base_filename $asc_backupname} ] \
{
set dbc_event_error "Can't create backup file $asc_backupname."
return
}
# open temp file and current library file
if [catch {open $asc_tempname w} tmp_fileid] \
{
set dbc_event_error "Error opening $asc_tempname"
return
}
if [catch {open $base_filename r} input_fileid] \
{
set dbc_event_error "Error opening $base_filename"
return
}
# Cycle over all the records in the input file looking for the spot
# to insert the input segment set
set segments_output 0
while {[gets $input_fileid asc_cur_line] >= 0} \
{
ASC_classify_line
switch -- $asc_record_type \
{
"Comment"
{
puts $tmp_fileid $asc_cur_line
}
"Revision"
{
# output a new revision line for the new entry and then the input record
set daytime [clock seconds]
set out_daytime [clock format $daytime -format "%a %b %d %Y %I:%M %p"]
set cur_rev "# $dbc_logname $out_daytime"
append cur_rev " Saving $dbc_libref"
puts $tmp_fileid $cur_rev
puts $tmp_fileid $asc_cur_line
}
"Class"
{
# Save indicator for this class matching the input class
set class_match [string compare $dbc_class $asc_class]
puts $tmp_fileid $asc_cur_line
}
"Format"
{
puts $tmp_fileid $asc_cur_line
}
"Data"
{
set libref_cmp [string compare $asc_record_libref $dbc_libref]
# If this data record isn't for the class we're trying to insert, just
# pass it to the output file. Otherwise, compare the librefs and
# determine if it needs to be output yet.
if { $class_match != 0 } \
{
puts $tmp_fileid $asc_cur_line
} elseif { $libref_cmp == -1 } \
{
puts $tmp_fileid $asc_cur_line
} elseif { $libref_cmp == 0 } \
{
if { $segments_output == 0 } \
{
ASC_output_segments $tmp_fileid
incr segments_output
}
} else \
{
if { $segments_output == 0 } \
{
ASC_output_segments $tmp_fileid
incr segments_output
}
puts $tmp_fileid $asc_cur_line
}
}
"End Data"
{
# If this End Data record is for the class we're trying to insert,
# check if the segments have been output yet. If not,
# output them now and then this record.
if { $class_match == 0 } \
{
if { $segments_output == 0 } \
{
ASC_output_segments $tmp_fileid
incr segments_output
}
}
puts $tmp_fileid $asc_cur_line
}
}
}
# Close the input and output files
if [catch {close $tmp_fileid} ] \
{
set dbc_event_error "Error closing $asc_tempname"
return
}
if [catch {close $input_fileid} ] \
{
set dbc_event_error "Error closing $base_filename"
return
}
# Rename the output file to the current file name, since we have already
# copied the current library into a backup file.
if [catch {file rename -force $asc_tempname $base_filename} ] \
{
global errorInfo
set dbc_event_error "Can't update library file $base_filename."
}
# Reinitialize the database to update the run-time data since this doesn't
# automatically happen on subsequent access attempts.
DBC_init_db
}
proc ASC_output_segments { fileid } \
{
global dbc_libref
global dbc_class
global dbc_segment_seqno
global dbc_multitool_cutter_count
global dbc_multitool_cutterlibref
global dbc_segment_seqno
global dbc_multitool_cutterid
#FORMAT LIBRF T STYPE SEQ CUTTERID CUTTERLIBRF
#-------------------------------------------------------------------------------
#DATA | ugt0801_001 | 1 | 0 | 0 | 1 | ugt0101_2003
for {set mCount 0 } { $mCount < $dbc_multitool_cutter_count} {incr mCount} \
{
set data_line [format "DATA | %s | 1 | 0 | %d | %d | %s" \
$dbc_libref \
$dbc_segment_seqno($mCount) \
$dbc_multitool_cutterid($mCount) $dbc_multitool_cutterlibref($mCount)]
puts $fileid $data_line
}
}
proc ASC_classify_line { } \
{
global asc_cur_line
global asc_class
global asc_record_libref
global asc_record_type
# First check if record is some form of comment
if {[string match {#*} $asc_cur_line] == 1} \
{
# It does. Sort out what kind
if {[string match #END_DATA $asc_cur_line] == 1} \
{
set asc_record_type "End Data"
} elseif {[string match *CLASS* $asc_cur_line] == 1} \
{
# We have a Class specification. Extract the class
set asc_record_type "Class"
set asc_class [string trimright $asc_cur_line]
set tmp_ix [string first CLASS $asc_class]
set tmp_iy [string wordend $asc_class $tmp_ix]
set asc_class [string range $asc_class $tmp_iy end]
set asc_class [string trimleft $asc_class]
} elseif {[string match *dbc_logname* $asc_cur_line] == 1} \
{
set asc_record_type "Revision"
} else \
{
set asc_record_type "Comment"
}
} elseif {[string match {FORMAT*} $asc_cur_line] == 1 } \
{
set asc_record_type "Format"
} elseif {[string match {DATA*} $asc_cur_line] ==1} \
{
# We have a DATA record.
set asc_record_type "Data"
# Extract the libref from this data record
set tmp_ix [string first | $asc_cur_line]
incr tmp_ix
set asc_record_libref [string range $asc_cur_line $tmp_ix end]
set tmp_iy [string first | $asc_record_libref]
incr tmp_iy -1
set asc_record_libref [string range $asc_record_libref 0 $tmp_iy]
set asc_record_libref [string trim $asc_record_libref]
} else \
{
# This doesn't match any previous types, so it is probably a blank line.
# Whatever it is, treat it as a comment and pass it through.
set asc_record_type "Comment"
}
}

View File

@@ -0,0 +1,207 @@
################################################################################
# This is the definition file for segmented tools with an ASCII File
# as the database
#
#
#=======================================================================
# REVISIONS
# Date Name Description of Change
#
# 03Mar2006 rlm Initial Release
#
###############################################################################
DB_PREFIX "DB("
DB_SUFFIX ")"
ESS_PREFIX "ESS("
ESS_SUFFIX ")"
#############################################################################
# The list of DB_ALIAS
#
# All the <alias> defined here can be used in the class description at the
# end of this file in order to define the fields that should appear in
# the search criteria and search result dialogs within UG for every class.
#
# DB_ALIAS <alias>
# {
# DB_ID < Attribute Identifier defined in the ASCII Data File >
# DB_ID_TYPE < Type of the identifier >
# d _ double
# i _ integer
# s _ string
# OPTIONS "opt1" "opt2 " "opt3"
# OPTIONS_IDS "val1" "val2" "val3"
# DIALOG_NAME "label in search criteria dialog"
# RSET_NAME "label in search result dialog"
# }
#
# OPTIONS and OPTIONS_IDS can be ommitted, If they are specified
# then a corresponding option menu is created in the Search Criteria Dialog
# instead of a simple search field.
#############################################################################
# The DB_ALIAS of the library reference. It is mandatory that this DB_ALIAS
# appears in the alias list
#
DB_ALIAS libref
{
DB_ID LIBRF
DB_ID_TYPE s
DIALOG_NAME "Libref"
RSET_NAME "Libref"
}
##################################################################
#
# General Attributes
#
##################################################################
DB_ALIAS Type
{
DB_ID T
DB_ID_TYPE i
}
DB_ALIAS SubType
{
DB_ID STYPE
DB_ID_TYPE i
}
DB_ALIAS Seq_no
{
DB_ID SEQ
DB_ID_TYPE i
}
#######################################################################
#
# Mill Form Tool Attributes
#
#######################################################################
DB_ALIAS Seg_length
{
DB_ID LEN
DB_ID_TYPE d
}
DB_ALIAS Seg_angle
{
DB_ID ANGLE
DB_ID_TYPE d
}
DB_ALIAS Seg_radius
{
DB_ID RAD
DB_ID_TYPE d
}
DB_ALIAS Seg_sweep_angle
{
DB_ID SWEEP
DB_ID_TYPE d
}
#######################################################################
#
# Step Drill Attributes
#
#######################################################################
DB_ALIAS Seg_diameter
{
DB_ID DIAM
DB_ID_TYPE d
}
DB_ALIAS Seg_height
{
DB_ID HEI
DB_ID_TYPE d
}
#######################################################################
#
# Turning Form Tool Attributes
#
#######################################################################
DB_ALIAS Tracking_point
{
DB_ID TP
DB_ID_TYPE i
}
DB_ALIAS Nose_radius
{
DB_ID RADIUS
DB_ID_TYPE d
}
DB_ALIAS Nose_angle
{
DB_ID ANGLE
DB_ID_TYPE d
}
DB_ALIAS Edge_length
{
DB_ID LENGTH
DB_ID_TYPE d
}
###################################################################
#################################################################
LIBREF libref
#########################################################################
# The Class Hierarchy #
#########################################################################
CLASS SEGMENTED_TOOL
{
TYPE QRY
QUERY "[DB(libref)] != [0]"
DIALOG libref
RSET libref Type SubType
UI_NAME "Segmented_tool"
CLASS MILL_FORM
{
TYPE QRY
QUERY "[DB(Type)] == [1] && [DB(SubType)] == [0]"
DIALOG libref Type
RSET libref Seg_length Seg_angle Seg_radius Seg_sweep_angle
UI_NAME "Mill_Form"
}
CLASS STEP_DRILL
{
TYPE QRY
QUERY "[DB(Type)] == [1] && [DB(SubType)] == [1]"
DIALOG libref Type
RSET libref Seg_diameter Seg_height Seg_angle Seg_radius
UI_NAME "Step_Drill"
}
CLASS TURN_FORM
{
TYPE QRY
QUERY "[DB(Type)] == [1] && [DB(SubType)] == [2]"
DIALOG libref Type
RSET libref Tracking_point Nose_radius Nose_angle Edge_length
UI_NAME "Turn_Form"
}
}

View File

@@ -0,0 +1,930 @@
###############################################################################
# segmented_tool_ascii.tcl - DBC Event Handler for database stored as ascii file
###############################################################################
# The customization mechanism needs these two variable to be set
# The following variable indicates where this file originally resides in
# the NX installation relative to the mach->resource folder
set dbc_original_dir "library,tool,ascii"
# The following variable is the environment variable that points to where
# the custom file for this file resides
# NOTE: the name of the custom file is <current file name>_custom.tcl
# So in this case it will be "segmented_tool_ascii_custom.tcl" and the file has to reside in the
# directory/folder pointed to by UGII_CAM_CUSTOM_LIBRARY_TOOL_ASCII_DIR
#
# If the env is not set or if the env is pointing to the UGII_BASE_DIR->mach->resource->library->tool->ascii
# customization will not take effect. The file "segmented_tool_ascii_custom.tcl" that is in the system folder is only
# an example of how to customize and this file may/will be modified as necessary by the system
set dbc_custom_file_dir "UGII_CAM_CUSTOM_LIBRARY_TOOL_ASCII_DIR"
# the variable below will control the output format for angle in segment data
set dbc_segment_angle_decimal_place 5
# Default double precision value format.
set double_precision_format "g"
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 asc_debug
global asc_file_name
global asc_units
global asc_part_units
global asc_mm_file_name
global asc_inch_file_name
global asc_file_loaded
global asc_file_load_limit
#
# Global variables set by DBC for Input/Output
#
global dbc_lhs_exp
global dbc_rhs_exp
global dbc_relop
global dbc_query
global dbc_subqry1
global dbc_subqry2
global dbc_boolop
global dbc_class_name
global dbc_attr_count
global dbc_attr_id
global dbc_query_count
global dbc_libref
global dbc_var_list
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
set asc_file_name ""
set asc_part_units ""
set dbc_cutter_ass_units ""
#
# Set the unit for tool search to the part unit
#
ASC_set_part_unit
#
# ask the mm and inch filenames
#
set asc_mm_file_name [ASC_get_data_file_name $asc_units(mm)]
set asc_inch_file_name [ASC_get_data_file_name $asc_units(inch)]
if { $asc_mm_file_name == "" && $asc_inch_file_name == "" } \
{
set message "Error looking for a segmented_tool_database.dat file."
set message "$message \n Neither of the environment variables"
set message "$message \n UGII_CAM_LIBRARY_TOOL_METRIC_DIR,"
set message "$message \n UGII_CAM_LIBRARY_TOOL_ENGLISH_DIR"
set message "$message \n is defined."
MOM_abort "\n $message"
}
#
# mm file
#
set app 0
set mm_file_loaded 0
set ret_cd [ASC_load_data_file $asc_mm_file_name $asc_units(mm) $app]
if { $ret_cd != 0 } \
{
set message "Error, can't open file:"
set message "$message \n $asc_mm_file_name"
MOM_abort "\n $message"
}
set app 1
set mm_file_loaded 1
#
# and then inch file
#
set inch_file_loaded 0
set ret_cd [ASC_load_data_file $asc_inch_file_name $asc_units(inch) $app]
if { $ret_cd != 0 } \
{
set message "Error, can't open file:"
set message "$message \n $asc_inch_file_name"
MOM_abort "\n $message"
}
set inch_file_loaded 1
#
# if mm or inch or both files are loaded set the flag
#
if { $inch_file_loaded == 1 || $mm_file_loaded == 1 } \
{
set asc_file_loaded 1
}
#
# This variable is only used for error messages
#
set asc_file_name " $asc_mm_file_name"
set asc_file_name "$asc_file_name \n $asc_inch_file_name"
}
proc ASC_get_data_file_name { unit } \
{
#
# Returns the filename for ASCII Data File depending on the
# specified unit.
#
global asc_units
if {$unit == $asc_units(mm)} \
{
set env_var_name UGII_CAM_LIBRARY_TOOL_METRIC_DIR
} \
else \
{
set env_var_name UGII_CAM_LIBRARY_TOOL_ENGLISH_DIR
}
set env_var [MOM_ask_env_var $env_var_name]
if { $env_var == "" } \
{
return ""
}
set fname ""
set fname [append fname $env_var "segmented_tool_database.dat"]
return $fname
}
proc ASC_set_part_unit {} \
{
global dbc_part_units
global dbc_search_units
global asc_units
MOM_ask_part_units ;# writes to dbc_part_units
if {$dbc_part_units == "metric"} \
{
set dbc_search_units $asc_units(mm)
} \
else \
{
set dbc_search_units $asc_units(inch)
}
}
#---------------------------------------------
proc DBC_retrieve {} {
#---------------------------------------------
global dbc_libref
ASC_retrieve
}
#---------------------------------------------
proc ASC_retrieve {} {
#---------------------------------------------
#
# global input
# ------------
global asc_debug
global asc_units
global dbc_search_units
global dbc_libref
global db_row
global asc_file_loaded
global asc_database
global asc_database_count
global asc_file_name
#
# global output
# -------------
global dbc_segment_count
global dbc_segment_type
global dbc_segment_subtype
global dbc_query
global dbc_query_count
if { $asc_debug == "1" } \
{
puts " =========================================="
puts " procedure DBC_retrieve for segmented tool segments."
puts " libref -> $dbc_libref"
}
# initialize segment count so we can detect if retrieval failed
set dbc_segment_count 0
#
# Look for the desired libref
#
if { $asc_file_loaded == 1 } \
{
ASC_array_search_libref $dbc_libref db_row
} \
else \
{
ASC_file_search_libref $dbc_libref db_row
}
if {$db_row >= 0} \
{
set dbc_segment_type [ASC_ask_att_val T $db_row "%d" 0 flag]
set dbc_segment_subtype [ASC_ask_att_val STYPE $db_row "%d" 0 flag]
ASC_load_segment_data
}
}
proc DBC_ask_library_values {} \
{
#
# global input
global dbc_libref
global dbc_db_ids_count
global dbc_db_ids
global asc_file_loaded
#
# global output
global dbc_db_ids_value
#
# Look for the desired libref
#
if { $asc_file_loaded == 1 } \
{
ASC_array_search_libref $dbc_libref db_row
} \
else \
{
ASC_file_search_libref $dbc_libref db_row
}
#
# and set the desired values
#
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]
}
}
#---------------------------------------------
proc DBC_translate_att_alias {} {
#---------------------------------------------
ASC_translate_att_alias
}
#---------------------------------------------
proc DBC_create_criterion {} {
#---------------------------------------------
ASC_create_criterion
}
#---------------------------------------------
proc DBC_create_query {} {
#---------------------------------------------
ASC_create_query
}
#---------------------------------------------
proc DBC_execute_query {} {
#---------------------------------------------
global asc_file_loaded
global dbc_query
global dbc_search_units
if { $asc_file_loaded == 0 } \
{
ASC_file_exec_qry 0
} \
else \
{
ASC_append_unit_to_query
ASC_execute_query
}
}
#---------------------------------------------
proc DBC_execute_query_for_count {} {
#---------------------------------------------
global asc_file_loaded
global dbc_query
if { $asc_file_loaded == 0 } \
{
ASC_file_exec_qry 1
} \
else \
{
ASC_append_unit_to_query
ASC_execute_query_for_count
}
}
#--------------------------------------------
proc DBC_insert {} {
#--------------------------------------------
ASC_insert
}
proc ASC_append_unit_to_query {} \
{
global dbc_search_units
global dbc_query
global asc_units
set lhs "\$asc_database(\$db_row,_unitt)"
set subquery1 "($lhs == \"$asc_units(unknown)\")"
set subquery2 "($lhs == \"$dbc_search_units\")"
set subquery "($subquery1 || $subquery2)"
set dbc_query "$dbc_query && $subquery"
}
proc ASC_file_exec_qry { for_count } \
{
#
# Executes the query on a file depending on the current setting
# of the dbc_search_units
#
# for_count = 1 => do only execute_query_for_count
global dbc_search_units
global asc_units
global asc_mm_file_name
global asc_inch_file_name
global dbc_query_count
global dbc_query
global units_from_query
if {[info exists units_from_query]} {
set dbc_search_units $units_from_query
unset units_from_query
}
if { $dbc_search_units == $asc_units(mm) } \
{
set file_name $asc_mm_file_name
set units $asc_units(mm)
} \
else \
{
set file_name $asc_inch_file_name
set units $asc_units(inch)
}
set dbc_query_count 0
if { $for_count == 1 } \
{
set ret_cd [ASC_file_execute_query_for_count $file_name $units]
} \
else \
{
set ret_cd [ASC_file_execute_query $file_name $units]
}
if { $ret_cd != 0 } \
{
set message "Error, can't open file:"
set message "$message \n $file_name"
MOM_abort "\n $message"
}
}
proc ASC_file_search_libref { libref db_row_ref } \
{
upvar $db_row_ref db_row
global dbc_search_units
global asc_units
global asc_mm_file_name
global asc_inch_file_name
global asc_file_name
#
# We search in mm and inch file for the desired libref
#
set found 2
if { $dbc_search_units == $asc_units(mm) } \
{
#
# Start with the mm file
if { $asc_mm_file_name != "" } \
{
set found [ASC_file_find_object_by_att \
$asc_mm_file_name $asc_units(mm) \
LIBRF $libref db_row]
if { $found != 0 } \
{
# Not found -> Try again with the inch file
if { $asc_inch_file_name != "" } \
{
set found [ASC_file_find_object_by_att \
$asc_inch_file_name $asc_units(inch) \
LIBRF $libref db_row]
}
}
}
} \
else \
{
#
# Start with the inch file
if { $asc_inch_file_name != "" } \
{
set found [ASC_file_find_object_by_att \
$asc_inch_file_name $asc_units(inch) \
LIBRF $libref db_row]
if { $found != 0 } \
{
# Not found -> Try again with the mm file
if { $asc_mm_file_name != "" } \
{
set found [ASC_file_find_object_by_att \
$asc_mm_file_name $asc_units(mm) \
LIBRF $libref db_row]
}
}
}
}
if { $found == 2 } \
{
set message "Error retrieving segmented tool from external library."
set message "$message \n Tool with the library reference $libref"
set message "$message \n does not exist in the"
set message "$message \n ASCII Data File(s):"
set message "$message \n $asc_file_name"
MOM_abort "\n $message"
}
if { $found == 1 } \
{
set message "Error retrieving segmented tool from external library."
set message "$message \n Neither of the files"
set message "$message \n $asc_mm_file_name"
set message "$message \n $asc_inch_file_name"
set message "$message \n can be read."
MOM_abort "\n $message"
}
}
proc ASC_array_search_libref { libref db_row_ref } \
{
upvar $db_row_ref db_row
global asc_file_name
set found [ASC_array_find_object_by_att LIBRF $libref db_row ]
if { $found == 2 } \
{
set db_row -1
}
}
proc ASC_load_segment_data {} \
{
global dbc_attr_count
global dbc_attr_aliases
global dbc_attr_id
global dbc_libref
global dbc_query_count
global dbc_segment_count
global dbc_segment_seqno
global dbc_segment_length
global dbc_segment_diameter
global dbc_segment_height
global dbc_segment_angle
global dbc_segment_radius
global dbc_segment_sweep_angle
global dbc_segment_tracking_point
global asc_database_count
# Initialize environment
set dbc_segment_count 0
# Cycle database looking for matching data records
for {set db_row 0} {$db_row < $asc_database_count} { incr db_row 1} \
{
set tmp_libref [ASC_ask_att_val LIBRF $db_row "" 0 flag]
if {$tmp_libref == $dbc_libref} \
{
# Set common data
set dbc_segment_seqno($dbc_segment_count) [ASC_ask_att_val \
SEQ $db_row "%d" 0 flag]
# Get type of segment
set type [ASC_ask_att_val STYPE $db_row "" 0 flag]
# Mill Form
if {$type == "0" } \
{
set dbc_segment_length($dbc_segment_count) [ASC_ask_att_val \
LEN $db_row "%$::double_precision_format" 0 flag]
set dbc_segment_angle($dbc_segment_count) [ASC_ask_att_val \
ANGLE $db_row "%s" 0 flag]
set dbc_segment_radius($dbc_segment_count) [ASC_ask_att_val \
RAD $db_row "%$::double_precision_format" 0 flag]
set dbc_segment_sweep_angle($dbc_segment_count) [ASC_ask_att_val \
SWEEP $db_row "%s" 0 flag]
} elseif {$type == "1" } \
{
# Step Drill
set dbc_segment_diameter($dbc_segment_count) [ASC_ask_att_val \
DIAM $db_row "%$::double_precision_format" 0 flag]
set dbc_segment_height($dbc_segment_count) [ASC_ask_att_val \
HEI $db_row "%$::double_precision_format" 0 flag]
set dbc_segment_angle($dbc_segment_count) [ASC_ask_att_val \
ANGLE $db_row "%s" 0 flag]
set dbc_segment_radius($dbc_segment_count) [ASC_ask_att_val \
RAD $db_row "%$::double_precision_format" 0 flag]
} elseif {$type == "2" } \
{
# Turn Form
set dbc_segment_tracking_point($dbc_segment_count) [ASC_ask_att_val \
TP $db_row "%d" 0 flag]
set dbc_segment_radius($dbc_segment_count) [ASC_ask_att_val \
RADIUS $db_row "%$::double_precision_format" 0 flag]
set dbc_segment_angle($dbc_segment_count) [ASC_ask_att_val \
ANGLE $db_row "%s" 0 flag]
set dbc_segment_length($dbc_segment_count) [ASC_ask_att_val \
LENGTH $db_row "%$::double_precision_format" 0 flag]
}
incr dbc_segment_count
}
}
}
proc ASC_insert {} \
{
global asc_database_name
global asc_file_name
global asc_units
global dbc_part_units
global dbc_event_error
global dbc_logname
global dbc_class
global dbc_libref
global dbc_segment_count
global dbc_clsf_decimal_places
global mom_clsf_decimal_places
global asc_cur_line
global asc_record_type
global asc_class
global asc_record_libref
global num_formats_processed
if {$dbc_part_units == "metric"} \
{
set base_filename [ASC_get_data_file_name $asc_units(mm)]
} else \
{
set base_filename [ASC_get_data_file_name $asc_units(inch)]
}
set asc_tempname $base_filename
append asc_tempname "_tmp"
set asc_backupname $base_filename
append asc_backupname "_bak"
# back up the existing version of the library
if [catch {file copy -force $base_filename $asc_backupname} ] \
{
set dbc_event_error "Can't create backup file $asc_backupname."
return
}
# open temp file and current library file
if [catch {open $asc_tempname w} tmp_fileid] \
{
set dbc_event_error "Error opening $asc_tempname"
return
}
if [catch {open $base_filename r} input_fileid] \
{
set dbc_event_error "Error opening $base_filename"
return
}
# Cycle over all the records in the input file looking for the spot
# to insert the input segment set
set segments_output 0
while {[gets $input_fileid asc_cur_line] >= 0} \
{
ASC_classify_line
switch -- $asc_record_type \
{
"Comment"
{
puts $tmp_fileid $asc_cur_line
}
"Revision"
{
# output a new revision line for the new entry and then the input record
set daytime [clock seconds]
set out_daytime [clock format $daytime -format "%a %b %d %Y %I:%M %p"]
set cur_rev "# $dbc_logname $out_daytime"
append cur_rev " Saving $dbc_libref"
puts $tmp_fileid $cur_rev
puts $tmp_fileid $asc_cur_line
}
"Class"
{
# Save indicator for this class matching the input class
set class_match [string compare $dbc_class $asc_class]
puts $tmp_fileid $asc_cur_line
}
"Format"
{
puts $tmp_fileid $asc_cur_line
}
"Data"
{
set libref_cmp [string compare $asc_record_libref $dbc_libref]
# If this data record isn't for the class we're trying to insert, just
# pass it to the output file. Otherwise, compare the librefs and
# determine if it needs to be output yet.
if { $class_match != 0 } \
{
puts $tmp_fileid $asc_cur_line
} elseif { $libref_cmp == -1 } \
{
puts $tmp_fileid $asc_cur_line
} elseif { $libref_cmp == 0 } \
{
if { $segments_output == 0 } \
{
ASC_output_segments $tmp_fileid
incr segments_output
}
} else \
{
if { $segments_output == 0 } \
{
ASC_output_segments $tmp_fileid
incr segments_output
}
puts $tmp_fileid $asc_cur_line
}
}
"End Data"
{
# If this End Data record is for the class we're trying to insert,
# check if the segments have been output yet. If not,
# output them now and then this record.
if { $class_match == 0 } \
{
if { $segments_output == 0 } \
{
ASC_output_segments $tmp_fileid
incr segments_output
}
}
puts $tmp_fileid $asc_cur_line
}
}
}
# Close the input and output files
if [catch {close $tmp_fileid} ] \
{
set dbc_event_error "Error closing $asc_tempname"
return
}
if [catch {close $input_fileid} ] \
{
set dbc_event_error "Error closing $base_filename"
return
}
# Rename the output file to the current file name, since we have already
# copied the current library into a backup file.
if [catch {file rename -force $asc_tempname $base_filename} ] \
{
global errorInfo
set dbc_event_error "Can't update library file $base_filename."
}
# Reinitialize the database to update the run-time data since this doesn't
# automatically happen on subsequent access attempts.
DBC_init_db
}
proc ASC_output_segments { fileid } \
{
global dbc_libref
global dbc_class
global dbc_segment_count
global dbc_segment_seqno
global dbc_segment_length
global dbc_segment_angle
global dbc_segment_radius
global dbc_segment_sweep_angle
global dbc_segment_diameter
global dbc_segment_height
global dbc_segment_tracking_point
global dbc_segment_angle_decimal_place
set dp $dbc_segment_angle_decimal_place
switch -- $dbc_class \
{
"MILL_FORM"
{
for {set segment_count 0 } { $segment_count < $dbc_segment_count} {incr segment_count} \
{
set data_line [format "DATA | %s | 1 | 0 | %d | %9.5f | %9.${dp}f | %9.5f | %9.${dp}f" \
$dbc_libref \
$dbc_segment_seqno($segment_count) \
$dbc_segment_length($segment_count) $dbc_segment_angle($segment_count) \
$dbc_segment_radius($segment_count) $dbc_segment_sweep_angle($segment_count)]
puts $fileid $data_line
}
}
"STEP_DRILL"
{
for {set segment_count 0 } { $segment_count < $dbc_segment_count} {incr segment_count} \
{
set data_line [format "DATA | %s | 1 | 1 | %d | %9.5f | %9.5f | %9.${dp}f | %9.5f" \
$dbc_libref \
$dbc_segment_seqno($segment_count) \
$dbc_segment_diameter($segment_count) $dbc_segment_height($segment_count) \
$dbc_segment_angle($segment_count) $dbc_segment_radius($segment_count)]
puts $fileid $data_line
}
}
"TURN_FORM"
{
for {set segment_count 0 } { $segment_count < $dbc_segment_count} {incr segment_count} \
{
set data_line [format "DATA | %s | 1 | 2 | %d | %d | %9.5f | %9.${dp}f | %9.5f" \
$dbc_libref \
$dbc_segment_seqno($segment_count) \
$dbc_segment_tracking_point($segment_count) $dbc_segment_radius($segment_count) \
$dbc_segment_angle($segment_count) $dbc_segment_length($segment_count) ]
puts $fileid $data_line
}
}
}
}
proc ASC_classify_line { } \
{
global asc_cur_line
global asc_class
global asc_record_libref
global asc_record_type
# First check if record is some form of comment
if {[string match {#*} $asc_cur_line] == 1} \
{
# It does. Sort out what kind
if {[string match #END_DATA $asc_cur_line] == 1} \
{
set asc_record_type "End Data"
} elseif {[string match *CLASS* $asc_cur_line] == 1} \
{
# We have a Class specification. Extract the class
set asc_record_type "Class"
set asc_class [string trimright $asc_cur_line]
set tmp_ix [string first CLASS $asc_class]
set tmp_iy [string wordend $asc_class $tmp_ix]
set asc_class [string range $asc_class $tmp_iy end]
set asc_class [string trimleft $asc_class]
} elseif {[string match *dbc_logname* $asc_cur_line] == 1} \
{
set asc_record_type "Revision"
} else \
{
set asc_record_type "Comment"
}
} elseif {[string match {FORMAT*} $asc_cur_line] == 1 } \
{
set asc_record_type "Format"
} elseif {[string match {DATA*} $asc_cur_line] ==1} \
{
# We have a DATA record.
set asc_record_type "Data"
# Extract the libref from this data record
set tmp_ix [string first | $asc_cur_line]
incr tmp_ix
set asc_record_libref [string range $asc_cur_line $tmp_ix end]
set tmp_iy [string first | $asc_record_libref]
incr tmp_iy -1
set asc_record_libref [string range $asc_record_libref 0 $tmp_iy]
set asc_record_libref [string trim $asc_record_libref]
} else \
{
# This doesn't match any previous types, so it is probably a blank line.
# Whatever it is, treat it as a comment and pass it through.
set asc_record_type "Comment"
}
}
# To enable the new customization mechanism.
# This should ALWAYS be the last line in the file.
MOM_extend_for_customization UGII_CAM_CUSTOM_LIBRARY_TOOL_ASCII_DIR dbc_custom_segmented_tool_ascii.tcl

View File

@@ -0,0 +1,25 @@
###############################################################################
# segmented_tool_ascii_custom.tcl - This is the customization file that will be sourced in
# after the segmented_tool_ascii.tcl is sourced in. This file is supplied as a sample and should be
# copied and modified and placed in a different location than the NX installation and the directory
# should be pointed to by the environment variable UGII_CAM_CUSTOM_LIBRARY_TOOL_ASCII_DIR
###############################################################################
# Global variable override
set ::dbc_segment_angle_decimal_place 8
namespace eval CUSTOM \
{
# The proc in the CUSTOM namespace will be called instead of the system DBC_retrieve to enable
# user customization
proc DBC_retrieve {} \
{
# Take custom action before the system/global namespace DBC_retrieve
#Call to the system/global DBC_retrieve
::DBC_retrieve
# Take custom action after the system/global namespace DBC_retrieve
}
}

145
tool/ascii/shank_ascii.def Normal file
View File

@@ -0,0 +1,145 @@
################################################################################
# This is the definition file for tool shanks with an ASCII File as the
# database
#
###############################################################################
DB_PREFIX "DB("
DB_SUFFIX ")"
ESS_PREFIX "ESS("
ESS_SUFFIX ")"
#############################################################################
# The list of DB_ALIAS
#
# All the <alias> defined here can be used in the class description at the end
# of this file in order to define the fields that should appear in
# the search criteria and search result dialogs within UG for every class.
#
# DB_ALIAS <alias>
# {
# DB_ID < Attribute Identifier defined in the ASCII Data File >
# DB_ID_TYPE < Type of the identifier >
# d _ double
# i _ integer
# s _ string
# OPTIONS "opt1" "opt2 " "opt3"
# OPTIONS_IDS "val1" "val2" "val3"
# DIALOG_NAME "label in search criteria dialog"
# RSET_NAME "label in search result dialog"
# }
#
# OPTIONS and OPTIONS_IDS can be ommitted, If they are specified
# then a corresponding option menu is created in the Search Criteria Dialog
# instead of a simple search field.
#############################################################################
# The DB_ALIAS of the library reference. It is mandatory that this DB_ALIAS
# appears in the alias list
#
DB_ALIAS libref
{
DB_ID LIBRF
DB_ID_TYPE s
DIALOG_NAME "Libref"
RSET_NAME "Libref"
}
DB_ALIAS RecType
{
DB_ID RTYPE
DB_ID_TYPE i
}
##################################################################
DB_ALIAS Type
{
DB_ID STYPE
DB_ID_TYPE i
}
DB_ALIAS N_Sections
{
DB_ID SNUM
DB_ID_TYPE i
}
DB_ALIAS Description
{
DB_ID DESCR
DB_ID_TYPE s
}
#######################################################################
DB_ALIAS Seq_no
{
DB_ID SEQ
DB_ID_TYPE i
}
DB_ALIAS Diameter
{
DB_ID DIAM
DB_ID_TYPE d
DIALOG_NAME "(D) Diameter "
RSET_NAME "(D) Diameter "
}
DB_ALIAS Height
{
DB_ID LENGTH
DB_ID_TYPE d
DIALOG_NAME "(L) Height"
RSET_NAME "(L) Height"
}
DB_ALIAS TaperAngle
{
DB_ID TAPER
DB_ID_TYPE d
DIALOG_NAME "(B) Taper Angle"
RSET_NAME "(B) Taper Angle"
}
DB_ALIAS CornerRadius
{
DB_ID CRAD
DB_ID_TYPE d
DIALOG_NAME "(R1) Corner Radius"
RSET_NAME "(R1) Corner Radius"
}
###################################################################
#################################################################
LIBREF libref
#########################################################################
# The Class Hierarchy #
#########################################################################
CLASS SHANK
{
TYPE QRY
QUERY "[DB(libref)] != [0] && DB(RecType) == [1]"
DIALOG libref
RSET libref Type
UI_NAME "Shank"
CLASS MILLING_DRILLING
{
TYPE QRY
QUERY "[DB(Type)] == [01]"
DIALOG libref Type
RSET libref Description N_Sections
UI_NAME "Milling_Drilling"
}
}

949
tool/ascii/shank_ascii.tcl Normal file
View File

@@ -0,0 +1,949 @@
###############################################################################
# shank.tcl - DBC Event Handler for database stored as ascii file
###############################################################################
#
# Default double precision value format.
set double_precision_format "g"
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 asc_debug
global asc_file_name
global asc_units
global asc_part_units
global asc_mm_file_name
global asc_inch_file_name
global asc_file_loaded
global asc_file_load_limit
#
# Global variables set by DBC for Input/Output
#
global dbc_lhs_exp
global dbc_rhs_exp
global dbc_relop
global dbc_query
global dbc_subqry1
global dbc_subqry2
global dbc_boolop
global dbc_class_name
global dbc_attr_count
global dbc_attr_id
global dbc_query_count
global dbc_libref
global dbc_var_list
#
# This is path+name of the shank_database.dat file
# where a shank gets exported.
# It is used within NX CAM to provide feedback
# to the user about tool export
#
global dbc_export_file_name
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
set asc_file_name ""
set dbc_export_file_name ""
set asc_part_units ""
set dbc_cutter_ass_units ""
#
# Set the unit for tool search to the part unit
#
ASC_set_part_unit
#
# ask the mm and inch filenames
#
set asc_mm_file_name [ASC_get_data_file_name $asc_units(mm)]
set asc_inch_file_name [ASC_get_data_file_name $asc_units(inch)]
if { $asc_mm_file_name == "" && $asc_inch_file_name == "" } \
{
set message "Error looking for a shank_database.dat file."
set message "$message \n Neither of the environment variables"
set message "$message \n UGII_CAM_LIBRARY_TOOL_METRIC_DIR,"
set message "$message \n UGII_CAM_LIBRARY_TOOL_ENGLISH_DIR"
set message "$message \n is defined."
MOM_abort "\n $message"
}
#
# mm file
#
set app 0
set mm_file_loaded 0
set ret_cd [ASC_load_data_file $asc_mm_file_name $asc_units(mm) $app]
if { $ret_cd != 0 } \
{
set message "Error, can't open file:"
set message "$message \n $asc_mm_file_name"
MOM_abort "\n $message"
}
set app 1
set mm_file_loaded 1
#
# and then inch file
#
set inch_file_loaded 0
set ret_cd [ASC_load_data_file $asc_inch_file_name $asc_units(inch) $app]
if { $ret_cd != 0 } \
{
set message "Error, can't open file:"
set message "$message \n $asc_inch_file_name"
MOM_abort "\n $message"
}
set inch_file_loaded 1
#
# if mm or inch or both files are loaded set the flag
#
if { $inch_file_loaded == 1 || $mm_file_loaded == 1 } \
{
set asc_file_loaded 1
}
#
# This variable is only used for error messages
#
set asc_file_name " $asc_mm_file_name"
set asc_file_name "$asc_file_name \n $asc_inch_file_name"
}
proc ASC_get_data_file_name { unit } \
{
#
# Returns the filename for ASCII Data File depending on the
# specified unit.
#
global asc_units
if {$unit == $asc_units(mm)} \
{
set env_var_name UGII_CAM_LIBRARY_TOOL_METRIC_DIR
} \
else \
{
set env_var_name UGII_CAM_LIBRARY_TOOL_ENGLISH_DIR
}
set env_var [MOM_ask_env_var $env_var_name]
if { $env_var == "" } \
{
return ""
}
set fname ""
set fname [append fname $env_var "shank_database.dat"]
return $fname
}
proc ASC_set_part_unit {} \
{
global dbc_part_units
global dbc_search_units
global asc_units
MOM_ask_part_units ;# writes to dbc_part_units
if {$dbc_part_units == "metric"} \
{
set dbc_search_units $asc_units(mm)
} \
else \
{
set dbc_search_units $asc_units(inch)
}
}
#---------------------------------------------
proc DBC_retrieve {} {
#---------------------------------------------
ASC_retrieve
}
#---------------------------------------------
proc ASC_retrieve {} {
#---------------------------------------------
#
# global input
# ------------
global asc_debug
global asc_units
global dbc_search_units
global dbc_libref
global db_row
global asc_file_loaded
global asc_database
global asc_database_count
global asc_file_name
global uglib_shank_type ;# UG/Library shank type
#
# global output
# -------------
global dbc_shank_count
global dbc_shank_type
global dbc_shank_num_sections
global dbc_shank_description
global dbc_query
global dbc_query_count
global dbc_cutter_ass_units
if { $asc_debug == "1" } \
{
puts " =========================================="
puts " procedure DBC_retrieve for tool shank"
puts " libref -> $dbc_libref"
}
# initialize section count so we can detect if retrieval failed
set dbc_shank_num_sections 0
#
# Look for the desired libref
#
if { $asc_file_loaded == 1 } \
{
ASC_array_search_libref $dbc_libref db_row
} \
else \
{
ASC_file_search_libref $dbc_libref db_row
}
if {$db_row >= 0} \
{
set units [ASC_ask_att_val _unitt $db_row "" $asc_units(mm) flag]
if { "$units" == "$asc_units(mm)" } \
{
set dbc_cutter_ass_units 0
} \
else \
{
set dbc_cutter_ass_units 1
}
set dbc_shank_type [ASC_ask_att_val STYPE $db_row "%d" 0 flag]
set dbc_shank_description [ASC_ask_att_val DESCR $db_row "" "" flag]
if {$dbc_shank_type == 1 } {
set dbc_shank_num_sections [ASC_ask_att_val SNUM $db_row "%d" 0 flag]
}
ASC_load_shank_data
}
}
proc DBC_ask_library_values {} \
{
#
# global input
global dbc_libref
global dbc_db_ids_count
global dbc_db_ids
global asc_file_loaded
#
# global output
global dbc_db_ids_value
#
# Look for the desired libref
#
if { $asc_file_loaded == 1 } \
{
ASC_array_search_libref $dbc_libref db_row
} \
else \
{
ASC_file_search_libref $dbc_libref db_row
}
#
# and set the desired values
#
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]
}
}
#---------------------------------------------
proc DBC_translate_att_alias {} {
#---------------------------------------------
ASC_translate_att_alias
}
#---------------------------------------------
proc DBC_create_criterion {} {
#---------------------------------------------
ASC_create_criterion
}
#---------------------------------------------
proc DBC_create_query {} {
#---------------------------------------------
ASC_create_query
}
#---------------------------------------------
proc DBC_execute_query {} {
#---------------------------------------------
global asc_file_loaded
global dbc_query
global dbc_search_units
if { $asc_file_loaded == 0 } \
{
ASC_file_exec_qry 0
} \
else \
{
ASC_append_unit_to_query
ASC_execute_query
}
}
#---------------------------------------------
proc DBC_execute_query_for_count {} {
#---------------------------------------------
global asc_file_loaded
global dbc_query
if { $asc_file_loaded == 0 } \
{
ASC_file_exec_qry 1
} \
else \
{
ASC_append_unit_to_query
ASC_execute_query_for_count
}
}
#--------------------------------------------
proc DBC_insert {} {
#--------------------------------------------
ASC_insert
}
proc ASC_append_unit_to_query {} \
{
global dbc_search_units
global dbc_query
global asc_units
set lhs "\$asc_database(\$db_row,_unitt)"
set subquery1 "($lhs == \"$asc_units(unknown)\")"
set subquery2 "($lhs == \"$dbc_search_units\")"
set subquery "($subquery1 || $subquery2)"
set dbc_query "$dbc_query && $subquery"
}
proc ASC_file_exec_qry { for_count } \
{
#
# Executes the query on a file depending on the current setting
# of the dbc_search_units
#
# for_count = 1 => do only execute_query_for_count
global dbc_search_units
global asc_units
global asc_mm_file_name
global asc_inch_file_name
global dbc_query_count
global dbc_query
global units_from_query
if {[info exists units_from_query]} {
set dbc_search_units $units_from_query
unset units_from_query
}
if { $dbc_search_units == $asc_units(mm) } \
{
set file_name $asc_mm_file_name
set units $asc_units(mm)
} \
else \
{
set file_name $asc_inch_file_name
set units $asc_units(inch)
}
set dbc_query_count 0
if { $for_count == 1 } \
{
set ret_cd [ASC_file_execute_query_for_count $file_name $units]
} \
else \
{
set ret_cd [ASC_file_execute_query $file_name $units]
}
if { $ret_cd != 0 } \
{
set message "Error, can't open file:"
set message "$message \n $file_name"
MOM_abort "\n $message"
}
}
proc ASC_file_search_libref { libref db_row_ref } \
{
upvar $db_row_ref db_row
global dbc_search_units
global asc_units
global asc_mm_file_name
global asc_inch_file_name
global asc_file_name
#
# We search in mm and inch file for the desired libref
#
set found 2
if { $dbc_search_units == $asc_units(mm) } \
{
#
# Start with the mm file
if { $asc_mm_file_name != "" } \
{
set found [ASC_file_find_object_by_att \
$asc_mm_file_name $asc_units(mm) \
LIBRF $libref db_row]
if { $found != 0 } \
{
# Not found -> Try again with the inch file
if { $asc_inch_file_name != "" } \
{
set found [ASC_file_find_object_by_att \
$asc_inch_file_name $asc_units(inch) \
LIBRF $libref db_row]
}
}
}
} \
else \
{
#
# Start with the inch file
if { $asc_inch_file_name != "" } \
{
set found [ASC_file_find_object_by_att \
$asc_inch_file_name $asc_units(inch) \
LIBRF $libref db_row]
if { $found != 0 } \
{
# Not found -> Try again with the mm file
if { $asc_mm_file_name != "" } \
{
set found [ASC_file_find_object_by_att \
$asc_mm_file_name $asc_units(mm) \
LIBRF $libref db_row]
}
}
}
}
if { $found == 2 } \
{
set message "Error retrieving shank from external library."
set message "$message \n Shank with the library reference $libref"
set message "$message \n does not exist in the"
set message "$message \n ASCII Data File(s):"
set message "$message \n $asc_file_name"
MOM_abort "\n $message"
}
if { $found == 1 } \
{
set message "Error retrieving shank from external library."
set message "$message \n Neither of the files"
set message "$message \n $asc_mm_file_name"
set message "$message \n $asc_inch_file_name"
set message "$message \n can be read."
MOM_abort "\n $message"
}
}
proc ASC_array_search_libref { libref db_row_ref } \
{
upvar $db_row_ref db_row
global asc_file_name
set found [ASC_array_find_object_by_att LIBRF $libref db_row ]
if { $found == 2 } \
{
set db_row -1
}
}
proc ASC_load_shank_data {} \
{
global dbc_shank_type
if {$dbc_shank_type == 1} {
ASC_load_milling_shank_data
}
}
proc ASC_load_milling_shank_data {} \
{
global dbc_attr_count
global dbc_attr_aliases
global dbc_attr_id
global dbc_libref
global dbc_query_count
global dbc_seqno
global dbc_hld_diam
global dbc_hld_hgt
global dbc_hld_taper
global dbc_hld_corner
global asc_database_count
# Initialize environment
set dbc_query_count 0
# Cycle database looking for matching data records
for {set db_row 0} {$db_row < $asc_database_count} { incr db_row 1} \
{
set tmp_libref [ASC_ask_att_val LIBRF $db_row "" 0 flag]
if {$tmp_libref == $dbc_libref} \
{
set rtype [ASC_ask_att_val RTYPE $db_row "" 0 flag]
if {$rtype == "2" } \
{
set dbc_seqno($dbc_query_count) [ASC_ask_att_val SEQ $db_row "" 0 flag]
set dbc_hld_diam($dbc_query_count) [ASC_ask_att_val DIAM $db_row "" 0 flag]
set dbc_hld_hgt($dbc_query_count) [ASC_ask_att_val LENGTH $db_row "" 0 flag]
set dbc_hld_taper($dbc_query_count) [ASC_ask_att_val TAPER $db_row "" 0 flag]
set dbc_hld_corner($dbc_query_count) [ASC_ask_att_val CRAD $db_row "" 0 flag]
incr dbc_query_count
}
}
}
}
proc ASC_insert {} \
{
global asc_database_name
global asc_file_name
global asc_units
global dbc_part_units
global dbc_event_error
global dbc_logname
global dbc_class
global dbc_cutter_shank_libref
global dbc_shank_count
global dbc_shank_num_sections
global dbc_shank_description
global dbc_shank_type
global dbc_clsf_decimal_places
global mom_clsf_decimal_places
global asc_cur_line
global asc_record_type
global asc_class
global asc_record_libref
global num_formats_processed
global dbc_export_file_name
if {$dbc_part_units == "metric"} \
{
set base_filename [ASC_get_data_file_name $asc_units(mm)]
} else \
{
set base_filename [ASC_get_data_file_name $asc_units(inch)]
}
set asc_tempname $base_filename
append asc_tempname "_tmp"
set asc_backupname $base_filename
append asc_backupname "_bak"
# back up the existing version of the library
if [catch {file copy -force $base_filename $asc_backupname} ] \
{
set dbc_event_error "Can't create backup file $asc_backupname."
return
}
# open temp file and current library file
if [catch {open $asc_tempname w} tmp_fileid] \
{
set dbc_event_error "Error opening $asc_tempname"
return
}
if [catch {open $base_filename r} input_fileid] \
{
set dbc_event_error "Error opening $base_filename"
return
}
# initialize processing flags
set num_formats_processed 0
set directory_record_output 0
set section_records_output 0
set new_record \
[format "DATA | %s | 1 | %d | %d | %s" \
$dbc_cutter_shank_libref $dbc_shank_type $dbc_shank_num_sections $dbc_shank_description]
# Cycle over all the records in the input file looking for the spot
# to insert the input shank
while {[gets $input_fileid asc_cur_line] >= 0} \
{
ASC_classify_line
switch -- $asc_record_type \
{
"Comment"
{
puts $tmp_fileid $asc_cur_line
}
"Revision"
{
# output a new revision line for the new entry and then the input record
set daytime [clock seconds]
set out_daytime [clock format $daytime -format "%a %b %d %Y %I:%M %p"]
set cur_rev "# $dbc_logname $out_daytime"
append cur_rev " Saving $dbc_cutter_shank_libref"
puts $tmp_fileid $cur_rev
puts $tmp_fileid $asc_cur_line
}
"Class"
{
puts $tmp_fileid $asc_cur_line
}
"Format"
{
incr num_formats_processed
puts $tmp_fileid $asc_cur_line
}
"Directory Data"
{
set libref_cmp [string compare $asc_record_libref $dbc_cutter_shank_libref]
# If the libref is greater than the current record, output the current record
if { $libref_cmp == -1 } \
{
puts $tmp_fileid $asc_cur_line
} elseif { $libref_cmp == 0 } \
{
# We have a matching directory record. Set the directory record output flag
# and output the new record
if { $directory_record_output == 0 } \
{
puts $tmp_fileid $new_record
incr directory_record_output
}
} else \
{
# The new record belongs between the previous and current record. Output
# it here and then the current one.
if { $directory_record_output == 0 } \
{
puts $tmp_fileid $new_record
incr directory_record_output
}
puts $tmp_fileid $asc_cur_line
}
}
"End Directory Data"
{
# If we haven't output the directory record yet, do it now. Then this rec
if { $directory_record_output == 0} \
{
puts $tmp_fileid $new_record
}
puts $tmp_fileid $asc_cur_line
}
"Section Data"
{
set libref_cmp [string compare $asc_record_libref $dbc_cutter_shank_libref]
# If this data record isn't for the class we're trying to insert, just
# pass it to the output file. Otherwise, compare the librefs and
# determine if it needs to be output yet.
if { [string compare $dbc_class $asc_class] != 0 } \
{
puts $tmp_fileid $asc_cur_line
} elseif { $libref_cmp == -1 } \
{
puts $tmp_fileid $asc_cur_line
} elseif { $libref_cmp == 0 } \
{
if { $section_records_output == 0 } \
{
ASC_insert_shank_data $tmp_fileid section_records_output
}
} else \
{
if { $section_records_output == 0 } \
{
ASC_insert_shank_data $tmp_fileid section_records_output
}
puts $tmp_fileid $asc_cur_line
}
}
"End Section Data"
{
# If we haven't output the section records, do it now and then this rec
if { $section_records_output == 0 && [string compare $dbc_class $asc_class] == 0} \
{
ASC_insert_shank_data $tmp_fileid section_records_output
}
puts $tmp_fileid $asc_cur_line
}
}
}
# Close the input and output files
if [catch {close $tmp_fileid} ] \
{
set dbc_event_error "Error closing $asc_tempname"
return
}
if [catch {close $input_fileid} ] \
{
set dbc_event_error "Error closing $base_filename"
return
}
# Rename the output file to the current file name, since we have already
# copied the current library into a backup file.
if [catch {file rename -force $asc_tempname $base_filename} ] \
{
global errorInfo
set dbc_event_error "Can't update library file $base_filename."
}
# Reinitialize the database to update the run-time data since this doesn't
# automatically happen on subsequent access attempts.
DBC_init_db
# Set this here because init_db sets everything to ""
set dbc_export_file_name $base_filename
}
proc ASC_insert_shank_data {fileId OUTPUT_MARK} {
global dbc_shank_type
upvar $OUTPUT_MARK output_mark
if {$dbc_shank_type == 1 } {
ASC_output_section_records $fileId
}
incr output_mark
}
proc ASC_output_section_records { fileid } \
{
global dbc_cutter_shank_libref
global dbc_class
global dbc_shank_num_sections
global dbc_seqno
global dbc_hld_diam
global dbc_hld_hgt
global dbc_hld_taper
global dbc_hld_corner
switch -- $dbc_class \
{
"MILLING_DRILLING"
{
for {set section_count 0 } { $section_count < $dbc_shank_num_sections} {incr section_count} \
{
set data_line [format "DATA | %s | 2 | %d |%9.5f |%9.5f |%9.5f |%9.5f" \
$dbc_cutter_shank_libref $dbc_seqno($section_count) \
$dbc_hld_diam($section_count) $dbc_hld_hgt($section_count) \
$dbc_hld_taper($section_count) $dbc_hld_corner($section_count)]
puts $fileid $data_line
}
}
}
}
proc ASC_classify_line { } \
{
global asc_cur_line
global asc_class
global num_formats_processed
global asc_record_libref
global asc_record_type
# First check if record is some form of comment
if {[string match {#*} $asc_cur_line] == 1} \
{
# It does. Sort out what kind
if {[string match #END_DATA $asc_cur_line] == 1} \
{
if {$num_formats_processed == 1} \
{
set asc_record_type "End Directory Data"
} else \
{
set asc_record_type "End Section Data"
}
} elseif {[string match *CLASS* $asc_cur_line] == 1} \
{
# We have a Class specification. Extract the class
set asc_record_type "Class"
set asc_class [string trimright $asc_cur_line]
set tmp_ix [string first CLASS $asc_class]
set tmp_iy [string wordend $asc_class $tmp_ix]
set asc_class [string range $asc_class $tmp_iy end]
set asc_class [string trimleft $asc_class]
} elseif {[string match *dbc_logname* $asc_cur_line] == 1} \
{
set asc_record_type "Revision"
} else \
{
set asc_record_type "Comment"
}
} elseif {[string match {FORMAT*} $asc_cur_line] == 1 } \
{
set asc_record_type "Format"
} elseif {[string match {DATA*} $asc_cur_line] ==1} \
{
# We have a DATA record. Check if we are in the directory
# or a shank section region
if {$num_formats_processed == 1} \
{
set asc_record_type "Directory Data"
} else \
{
set asc_record_type "Section Data"
}
# Extract the libref from this data record
set tmp_ix [string first | $asc_cur_line]
incr tmp_ix
set asc_record_libref [string range $asc_cur_line $tmp_ix end]
set tmp_iy [string first | $asc_record_libref]
incr tmp_iy -1
set asc_record_libref [string range $asc_record_libref 0 $tmp_iy]
set asc_record_libref [string trim $asc_record_libref]
} else \
{
# This doesn't match any previous types, so it is probably a blank line.
# Whatever it is, treat it as a comment and pass it through.
set asc_record_type "Comment"
}
}
# To enable the new customization mechanism.
# This should ALWAYS be the last line in the file.
MOM_extend_for_customization UGII_CAM_CUSTOM_LIBRARY_TOOL_ASCII_DIR dbc_custom_shank_ascii.tcl

View File

@@ -0,0 +1,242 @@
################################################################################
# This is the definition file for tool tracking points with an ASCII File
# as the database
#
#
#=======================================================================
# REVISIONS
# Date Name Description of Change
#
# 25Jan2006 rlm Initial Release
# 27Feb2014 Cheng Wang cam10008: Add Definition_type
###############################################################################
DB_PREFIX "DB("
DB_SUFFIX ")"
ESS_PREFIX "ESS("
ESS_SUFFIX ")"
#############################################################################
# The list of DB_ALIAS
#
# All the <alias> defined here can be used in the class description at the
# end of this file in order to define the fields that should appear in
# the search criteria and search result dialogs within UG for every class.
#
# DB_ALIAS <alias>
# {
# DB_ID < Attribute Identifier defined in the ASCII Data File >
# DB_ID_TYPE < Type of the identifier >
# d _ double
# i _ integer
# s _ string
# OPTIONS "opt1" "opt2 " "opt3"
# OPTIONS_IDS "val1" "val2" "val3"
# DIALOG_NAME "label in search criteria dialog"
# RSET_NAME "label in search result dialog"
# }
#
# OPTIONS and OPTIONS_IDS can be ommitted, If they are specified
# then a corresponding option menu is created in the Search Criteria Dialog
# instead of a simple search field.
#############################################################################
# The DB_ALIAS of the library reference. It is mandatory that this DB_ALIAS
# appears in the alias list
#
DB_ALIAS libref
{
DB_ID LIBRF
DB_ID_TYPE s
DIALOG_NAME "Libref"
RSET_NAME "Libref"
}
##################################################################
#
# General Attributes
#
##################################################################
DB_ALIAS Type
{
DB_ID T
DB_ID_TYPE i
}
DB_ALIAS SubType
{
DB_ID STYPE
DB_ID_TYPE i
}
DB_ALIAS Name
{
DB_ID NAME
DB_ID_TYPE s
}
DB_ALIAS Seq_no
{
DB_ID SEQ
DB_ID_TYPE i
}
DB_ALIAS Adjust
{
DB_ID ADJREG
DB_ID_TYPE i
}
DB_ALIAS Cutcom
{
DB_ID CUTREG
DB_ID_TYPE i
}
#######################################################################
#
# Milling Trackpoint Attributes
#
#######################################################################
DB_ALIAS Adjust_status
{
DB_ID ADJSTAT
DB_ID_TYPE i
}
DB_ALIAS Cutcom_status
{
DB_ID CUTSTAT
DB_ID_TYPE i
}
DB_ALIAS Diameter
{
DB_ID DIAM
DB_ID_TYPE d
DIALOG_NAME "Diameter "
RSET_NAME "Diameter "
}
DB_ALIAS Distance
{
DB_ID DIST
DB_ID_TYPE d
DIALOG_NAME "Distance"
RSET_NAME "Distance"
}
DB_ALIAS Z_offset
{
DB_ID ZOFF
DB_ID_TYPE d
DIALOG_NAME "Z Offset"
RSET_NAME "Z Offset"
}
DB_ALIAS Z_off_status
{
DB_ID ZOFFSTAT
DB_ID_TYPE i
}
DB_ALIAS Definition_type
{
DB_ID DEFTYPE
DB_ID_TYPE i
DIALOG_NAME "Definition"
RSET_NAME "Definition"
}
#######################################################################
#
# Turning Trackpoint Attributes
#
#######################################################################
DB_ALIAS X_offset
{
DB_ID XOFF
DB_ID_TYPE d
DIALOG_NAME "X Offset"
RSET_NAME "X Offset"
}
DB_ALIAS Y_offset
{
DB_ID YOFF
DB_ID_TYPE d
DIALOG_NAME "Y Offset"
RSET_NAME "Y Offset"
}
DB_ALIAS Radius_id
{
DB_ID RADID
DB_ID_TYPE i
}
DB_ALIAS Cluster_id
{
DB_ID CLUSTID
DB_ID_TYPE i
}
DB_ALIAS Angle
{
DB_ID ANGLE
DB_ID_TYPE d
DIALOG_NAME "Angle"
RSET_NAME "Angle"
}
DB_ALIAS Radius
{
DB_ID RAD
DB_ID_TYPE d
DIALOG_NAME "Radius"
RSET_NAME "Radius"
}
###################################################################
#################################################################
LIBREF libref
#########################################################################
# The Class Hierarchy #
#########################################################################
CLASS TRACKPOINT
{
TYPE QRY
QUERY "[DB(libref)] != [0]"
DIALOG libref
RSET libref Type SubType
UI_NAME "Trackpoint"
CLASS MILLING_DRILLING
{
TYPE QRY
QUERY "[DB(Type)] == [01]"
DIALOG libref Type
RSET libref
UI_NAME "Milling_Drilling"
}
CLASS TURNING
{
TYPE QRY
QUERY "[DB(Type)] == [02]"
DIALOG libref Type
RSET libref
UI_NAME "Turning"
}
}

View File

@@ -0,0 +1,991 @@
###############################################################################
# trackpoint_ascii.tcl - DBC Event Handler for database stored as ascii file
###############################################################################
##############################################################################
# REVISIONS
# Date Who Reason
# 25-Jan-2006 rlm initial release
# 14-Dec-2011 JM Add dbc_export_file_name
# 27-Feb-2014 Cheng Wang cam10008: Add definition type
# 13-Nov-2017 JM no export backup if multitool export
# 26-Oct-2018 Shorbojeet Das PR#8340732: Add customization support for double precision control.
##############################################################################
#
# Default double precision value format.
set double_precision_format "g"
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 asc_debug
global asc_file_name
global asc_units
global asc_part_units
global asc_mm_file_name
global asc_inch_file_name
global asc_file_loaded
global asc_file_load_limit
#
# Global variables set by DBC for Input/Output
#
global dbc_lhs_exp
global dbc_rhs_exp
global dbc_relop
global dbc_query
global dbc_subqry1
global dbc_subqry2
global dbc_boolop
global dbc_class_name
global dbc_attr_count
global dbc_attr_id
global dbc_query_count
global dbc_libref
global dbc_var_list
#
#
# This is path+name of the trackpoint_database.dat file
# where a tracking point gets exported.
# It is used within NX CAM to provide feedback
# to the user about tool export
#
global dbc_export_file_name
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
set asc_file_name ""
set dbc_export_file_name ""
set asc_part_units ""
set dbc_cutter_ass_units ""
#
# Set the unit for tool search to the part unit
#
ASC_set_part_unit
#
# ask the mm and inch filenames
#
set asc_mm_file_name [ASC_get_data_file_name $asc_units(mm)]
set asc_inch_file_name [ASC_get_data_file_name $asc_units(inch)]
if { $asc_mm_file_name == "" && $asc_inch_file_name == "" } \
{
set message "Error looking for a trackpoint_database.dat file."
set message "$message \n Neither of the environment variables"
set message "$message \n UGII_CAM_LIBRARY_TOOL_METRIC_DIR,"
set message "$message \n UGII_CAM_LIBRARY_TOOL_ENGLISH_DIR"
set message "$message \n is defined."
MOM_abort "\n $message"
}
#
# mm file
#
set app 0
set mm_file_loaded 0
set ret_cd [ASC_load_data_file $asc_mm_file_name $asc_units(mm) $app]
if { $ret_cd != 0 } \
{
set message "Error, can't open file:"
set message "$message \n $asc_mm_file_name"
MOM_abort "\n $message"
}
set app 1
set mm_file_loaded 1
#
# and then inch file
#
set inch_file_loaded 0
set ret_cd [ASC_load_data_file $asc_inch_file_name $asc_units(inch) $app]
if { $ret_cd != 0 } \
{
set message "Error, can't open file:"
set message "$message \n $asc_inch_file_name"
MOM_abort "\n $message"
}
set inch_file_loaded 1
#
# if mm or inch or both files are loaded set the flag
#
if { $inch_file_loaded == 1 || $mm_file_loaded == 1 } \
{
set asc_file_loaded 1
}
#
# This variable is only used for error messages
#
set asc_file_name " $asc_mm_file_name"
set asc_file_name "$asc_file_name \n $asc_inch_file_name"
}
proc ASC_get_data_file_name { unit } \
{
#
# Returns the filename for ASCII Data File depending on the
# specified unit.
#
global asc_units
if {$unit == $asc_units(mm)} \
{
set env_var_name UGII_CAM_LIBRARY_TOOL_METRIC_DIR
} \
else \
{
set env_var_name UGII_CAM_LIBRARY_TOOL_ENGLISH_DIR
}
set env_var [MOM_ask_env_var $env_var_name]
if { $env_var == "" } \
{
return ""
}
set fname ""
set fname [append fname $env_var "trackpoint_database.dat"]
return $fname
}
proc ASC_set_part_unit {} \
{
global dbc_part_units
global dbc_search_units
global asc_units
MOM_ask_part_units ;# writes to dbc_part_units
if {$dbc_part_units == "metric"} \
{
set dbc_search_units $asc_units(mm)
} \
else \
{
set dbc_search_units $asc_units(inch)
}
}
#---------------------------------------------
proc DBC_retrieve {} {
#---------------------------------------------
global dbc_libref
ASC_retrieve
}
#---------------------------------------------
proc ASC_retrieve {} {
#---------------------------------------------
#
# global input
# ------------
global asc_debug
global asc_units
global dbc_search_units
global dbc_libref
global db_row
global asc_file_loaded
global asc_database
global asc_database_count
global asc_file_name
#
# global output
# -------------
global dbc_trackpoint_count
global dbc_trackpoint_type
global dbc_trackpoint_subtype
global dbc_query
global dbc_query_count
if { $asc_debug == "1" } \
{
puts " =========================================="
puts " procedure DBC_retrieve for tool tracking points"
puts " libref -> $dbc_libref"
}
# initialize point count so we can detect if retrieval failed
set dbc_trackpoint_count 0
#
# Look for the desired libref
#
if { $asc_file_loaded == 1 } \
{
ASC_array_search_libref $dbc_libref db_row
} \
else \
{
ASC_file_search_libref $dbc_libref db_row
}
if {$db_row >= 0} \
{
set dbc_trackpoint_type [ASC_ask_att_val T $db_row "%d" 0 flag]
set dbc_trackpoint_subtype [ASC_ask_att_val STYPE $db_row "%d" 0 flag]
ASC_load_trackpoint_data
}
}
proc DBC_ask_library_values {} \
{
#
# global input
global dbc_libref
global dbc_db_ids_count
global dbc_db_ids
global asc_file_loaded
#
# global output
global dbc_db_ids_value
#
# Look for the desired libref
#
if { $asc_file_loaded == 1 } \
{
ASC_array_search_libref $dbc_libref db_row
} \
else \
{
ASC_file_search_libref $dbc_libref db_row
}
#
# and set the desired values
#
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]
}
}
#---------------------------------------------
proc DBC_translate_att_alias {} {
#---------------------------------------------
ASC_translate_att_alias
}
#---------------------------------------------
proc DBC_create_criterion {} {
#---------------------------------------------
ASC_create_criterion
}
#---------------------------------------------
proc DBC_create_query {} {
#---------------------------------------------
ASC_create_query
}
#---------------------------------------------
proc DBC_execute_query {} {
#---------------------------------------------
global asc_file_loaded
global dbc_query
global dbc_search_units
if { $asc_file_loaded == 0 } \
{
ASC_file_exec_qry 0
} \
else \
{
ASC_append_unit_to_query
ASC_execute_query
}
}
#---------------------------------------------
proc DBC_execute_query_for_count {} {
#---------------------------------------------
global asc_file_loaded
global dbc_query
if { $asc_file_loaded == 0 } \
{
ASC_file_exec_qry 1
} \
else \
{
ASC_append_unit_to_query
ASC_execute_query_for_count
}
}
#--------------------------------------------
proc DBC_insert {} {
#--------------------------------------------
ASC_insert
}
proc ASC_append_unit_to_query {} \
{
global dbc_search_units
global dbc_query
global asc_units
set lhs "\$asc_database(\$db_row,_unitt)"
set subquery1 "($lhs == \"$asc_units(unknown)\")"
set subquery2 "($lhs == \"$dbc_search_units\")"
set subquery "($subquery1 || $subquery2)"
set dbc_query "$dbc_query && $subquery"
}
proc ASC_file_exec_qry { for_count } \
{
#
# Executes the query on a file depending on the current setting
# of the dbc_search_units
#
# for_count = 1 => do only execute_query_for_count
global dbc_search_units
global asc_units
global asc_mm_file_name
global asc_inch_file_name
global dbc_query_count
global dbc_query
global units_from_query
if {[info exists units_from_query]} {
set dbc_search_units $units_from_query
unset units_from_query
}
if { $dbc_search_units == $asc_units(mm) } \
{
set file_name $asc_mm_file_name
set units $asc_units(mm)
} \
else \
{
set file_name $asc_inch_file_name
set units $asc_units(inch)
}
set dbc_query_count 0
if { $for_count == 1 } \
{
set ret_cd [ASC_file_execute_query_for_count $file_name $units]
} \
else \
{
set ret_cd [ASC_file_execute_query $file_name $units]
}
if { $ret_cd != 0 } \
{
set message "Error, can't open file:"
set message "$message \n $file_name"
MOM_abort "\n $message"
}
}
proc ASC_file_search_libref { libref db_row_ref } \
{
upvar $db_row_ref db_row
global dbc_search_units
global asc_units
global asc_mm_file_name
global asc_inch_file_name
global asc_file_name
#
# We search in mm and inch file for the desired libref
#
set found 2
if { $dbc_search_units == $asc_units(mm) } \
{
#
# Start with the mm file
if { $asc_mm_file_name != "" } \
{
set found [ASC_file_find_object_by_att \
$asc_mm_file_name $asc_units(mm) \
LIBRF $libref db_row]
if { $found != 0 } \
{
# Not found -> Try again with the inch file
if { $asc_inch_file_name != "" } \
{
set found [ASC_file_find_object_by_att \
$asc_inch_file_name $asc_units(inch) \
LIBRF $libref db_row]
}
}
}
} \
else \
{
#
# Start with the inch file
if { $asc_inch_file_name != "" } \
{
set found [ASC_file_find_object_by_att \
$asc_inch_file_name $asc_units(inch) \
LIBRF $libref db_row]
if { $found != 0 } \
{
# Not found -> Try again with the mm file
if { $asc_mm_file_name != "" } \
{
set found [ASC_file_find_object_by_att \
$asc_mm_file_name $asc_units(mm) \
LIBRF $libref db_row]
}
}
}
}
if { $found == 2 } \
{
set message "Error retrieving trackpoints from external library."
set message "$message \n Trackpoints with the library reference $libref"
set message "$message \n do not exist in the"
set message "$message \n ASCII Data File(s):"
set message "$message \n $asc_file_name"
MOM_abort "\n $message"
}
if { $found == 1 } \
{
set message "Error retrieving trackpoints from external library."
set message "$message \n Neither of the files"
set message "$message \n $asc_mm_file_name"
set message "$message \n $asc_inch_file_name"
set message "$message \n can be read."
MOM_abort "\n $message"
}
}
proc ASC_array_search_libref { libref db_row_ref } \
{
upvar $db_row_ref db_row
global asc_file_name
set found [ASC_array_find_object_by_att LIBRF $libref db_row ]
if { $found == 2 } \
{
set db_row -1
}
}
proc ASC_load_trackpoint_data {} \
{
global dbc_attr_count
global dbc_attr_aliases
global dbc_attr_id
global dbc_libref
global dbc_query_count
global dbc_trackpoint_count
global dbc_trackpoint_name
global dbc_trackpoint_seqno
global dbc_trackpoint_adjust
global dbc_trackpoint_adjust_status
global dbc_trackpoint_cutcom
global dbc_trackpoint_cutcom_status
global dbc_trackpoint_diam
global dbc_trackpoint_length
global dbc_trackpoint_z_offset
global dbc_trackpoint_zoff_status
global dbc_trackpoint_x_offset
global dbc_trackpoint_y_offset
global dbc_trackpoint_radius_id
global dbc_trackpoint_cluster_id
global dbc_trackpoint_tool_angle
global dbc_trackpoint_radius
global dbc_trackpoint_def_type
global asc_database_count
# Initialize environment
set dbc_trackpoint_count 0
# Cycle database looking for matching data records
for {set db_row 0} {$db_row < $asc_database_count} { incr db_row 1} \
{
set tmp_libref [ASC_ask_att_val LIBRF $db_row "" 0 flag]
if {$tmp_libref == $dbc_libref} \
{
# Set common data
set dbc_trackpoint_name($dbc_trackpoint_count) [ASC_ask_att_val \
NAME $db_row "%s" 0 flag]
set dbc_trackpoint_seqno($dbc_trackpoint_count) [ASC_ask_att_val \
SEQ $db_row "%d" 0 flag]
set dbc_trackpoint_adjust($dbc_trackpoint_count) [ASC_ask_att_val \
ADJREG $db_row "%d" 0 flag]
set dbc_trackpoint_cutcom($dbc_trackpoint_count) [ASC_ask_att_val \
CUTREG $db_row "%d" 0 flag]
# Get type of Tracking point
set type [ASC_ask_att_val T $db_row "" 0 flag]
# Milling_Drilling
if {$type == "1" } \
{
set dbc_trackpoint_adjust_status($dbc_trackpoint_count) [ASC_ask_att_val \
ADJSTAT $db_row "%d" 0 flag]
set dbc_trackpoint_cutcom_status($dbc_trackpoint_count) [ASC_ask_att_val \
CUTSTAT $db_row "%d" 0 flag]
set dbc_trackpoint_diam($dbc_trackpoint_count) [ASC_ask_att_val \
DIAM $db_row "%$::double_precision_format" 0 flag]
set dbc_trackpoint_length($dbc_trackpoint_count) [ASC_ask_att_val \
DIST $db_row "%$::double_precision_format" 0 flag]
set dbc_trackpoint_z_offset($dbc_trackpoint_count) [ASC_ask_att_val \
ZOFF $db_row "%$::double_precision_format" 0 flag]
set dbc_trackpoint_zoff_status($dbc_trackpoint_count) [ASC_ask_att_val \
ZOFFSTAT $db_row "%d" 0 flag]
set dbc_trackpoint_def_type($dbc_trackpoint_count) [ASC_ask_att_val \
DEFTYPE $db_row "%d" 0 flag]
} elseif {$type == "2" } \
{
# Turning
set dbc_trackpoint_x_offset($dbc_trackpoint_count) [ASC_ask_att_val \
XOFF $db_row "%$::double_precision_format" 0 flag]
set dbc_trackpoint_y_offset($dbc_trackpoint_count) [ASC_ask_att_val \
YOFF $db_row "%$::double_precision_format" 0 flag]
set dbc_trackpoint_radius_id($dbc_trackpoint_count) [ASC_ask_att_val \
RADID $db_row "%d" 0 flag]
set dbc_trackpoint_cluster_id($dbc_trackpoint_count) [ASC_ask_att_val \
CLUSTID $db_row "%d" 0 flag]
set dbc_trackpoint_tool_angle($dbc_trackpoint_count) [ASC_ask_att_val \
ANGLE $db_row "%$::double_precision_format" 0 flag]
set dbc_trackpoint_radius($dbc_trackpoint_count) [ASC_ask_att_val \
RAD $db_row "%$::double_precision_format" 0 flag]
}
incr dbc_trackpoint_count
}
}
}
proc DBC_create_backup_data_file {} \
{
global dbc_event_error
global dbc_part_units
global asc_units
if {$dbc_part_units == "metric"} \
{
set base_filename [ASC_get_data_file_name $asc_units(mm)]
} else \
{
set base_filename [ASC_get_data_file_name $asc_units(inch)]
}
set asc_backupname $base_filename
append asc_backupname "_bak"
if [catch {file copy -force $base_filename $asc_backupname} ] \
{
set dbc_event_error "Can't create backup file $asc_backupname."
return 1
}
return 0
}
proc ASC_insert {} \
{
global asc_database_name
global asc_file_name
global asc_units
global dbc_part_units
global dbc_event_error
global dbc_logname
global dbc_trackpoint_class
global dbc_cutter_trackpoint_libref
global dbc_trackpoint_count
global dbc_clsf_decimal_places
global mom_clsf_decimal_places
global asc_cur_line
global asc_record_type
global asc_class
global asc_record_libref
global num_formats_processed
global dbc_export_file_name
if {$dbc_part_units == "metric"} \
{
set base_filename [ASC_get_data_file_name $asc_units(mm)]
} else \
{
set base_filename [ASC_get_data_file_name $asc_units(inch)]
}
set asc_tempname $base_filename
append asc_tempname "_tmp"
global dbc_ongoing_multitool_export_flag
set create_backup_file 1
if { [info exists dbc_ongoing_multitool_export_flag] } \
{
if { $dbc_ongoing_multitool_export_flag == 1 } \
{
set create_backup_file 0
}
}
# back up the existing version of the library
if { $create_backup_file == 1 } \
{
set error_flag [DBC_create_backup_data_file]
if {$error_flag == 1} \
{
return
}
}
# open temp file and current library file
if [catch {open $asc_tempname w} tmp_fileid] \
{
set dbc_event_error "Error opening $asc_tempname"
return
}
if [catch {open $base_filename r} input_fileid] \
{
set dbc_event_error "Error opening $base_filename"
return
}
# Cycle over all the records in the input file looking for the spot
# to insert the input trackpoint set
set trackpoints_output 0
while {[gets $input_fileid asc_cur_line] >= 0} \
{
ASC_classify_line
switch -- $asc_record_type \
{
"Comment"
{
puts $tmp_fileid $asc_cur_line
}
"Revision"
{
# output a new revision line for the new entry and then the input record
set daytime [clock seconds]
set out_daytime [clock format $daytime -format "%a %b %d %Y %I:%M %p"]
set cur_rev "# $dbc_logname $out_daytime"
append cur_rev " Saving $dbc_cutter_trackpoint_libref"
puts $tmp_fileid $cur_rev
puts $tmp_fileid $asc_cur_line
}
"Class"
{
# Save indicator for this class matching the input class
set class_match [string compare $dbc_trackpoint_class $asc_class]
puts $tmp_fileid $asc_cur_line
}
"Format"
{
puts $tmp_fileid $asc_cur_line
}
"Data"
{
set libref_cmp [string compare $asc_record_libref $dbc_cutter_trackpoint_libref]
# If this data record isn't for the class we're trying to insert, just
# pass it to the output file. Otherwise, compare the librefs and
# determine if it needs to be output yet.
if { $class_match != 0 } \
{
puts $tmp_fileid $asc_cur_line
} elseif { $libref_cmp == -1 } \
{
puts $tmp_fileid $asc_cur_line
} elseif { $libref_cmp == 0 } \
{
if { $trackpoints_output == 0 } \
{
ASC_output_trackpoints $tmp_fileid
incr trackpoints_output
}
} else \
{
if { $trackpoints_output == 0 } \
{
ASC_output_trackpoints $tmp_fileid
incr trackpoints_output
}
puts $tmp_fileid $asc_cur_line
}
}
"End Data"
{
# If this End Data record is for the class we're trying to insert,
# check if the trackpoints have been output yet. If not,
# output them now and then this record.
if { $class_match == 0 } \
{
if { $trackpoints_output == 0 } \
{
ASC_output_trackpoints $tmp_fileid
incr trackpoints_output
}
}
puts $tmp_fileid $asc_cur_line
}
}
}
# Close the input and output files
if [catch {close $tmp_fileid} ] \
{
set dbc_event_error "Error closing $asc_tempname"
return
}
if [catch {close $input_fileid} ] \
{
set dbc_event_error "Error closing $base_filename"
return
}
# Rename the output file to the current file name, since we have already
# copied the current library into a backup file.
if [catch {file rename -force $asc_tempname $base_filename} ] \
{
global errorInfo
set dbc_event_error "Can't update library file $base_filename."
}
# Reinitialize the database to update the run-time data since this doesn't
# automatically happen on subsequent access attempts.
DBC_init_db
# Set this here because init_db sets everything to ""
set dbc_export_file_name $base_filename
}
proc ASC_output_trackpoints { fileid } \
{
global dbc_cutter_trackpoint_libref
global dbc_trackpoint_class
global dbc_trackpoint_count
global dbc_trackpoint_name
global dbc_trackpoint_seqno
global dbc_trackpoint_adjust
global dbc_trackpoint_adjust_status
global dbc_trackpoint_cutcom
global dbc_trackpoint_cutcom_status
global dbc_trackpoint_diam
global dbc_trackpoint_length
global dbc_trackpoint_z_offset
global dbc_trackpoint_zoff_status
global dbc_trackpoint_x_offset
global dbc_trackpoint_y_offset
global dbc_trackpoint_radius_id
global dbc_trackpoint_cluster_id
global dbc_trackpoint_tool_angle
global dbc_trackpoint_radius
global dbc_trackpoint_def_type
switch -- $dbc_trackpoint_class \
{
"MILLING_DRILLING"
{
for {set trackpoint_count 0 } { $trackpoint_count < $dbc_trackpoint_count} {incr trackpoint_count} \
{
set data_line [format "DATA | %s | 1 | 0 | %s | %d | %d | %d | %d | %d | %9.5f | %9.5f | %9.5f | %d | %d" \
$dbc_cutter_trackpoint_libref $dbc_trackpoint_name($trackpoint_count) \
$dbc_trackpoint_seqno($trackpoint_count) \
$dbc_trackpoint_adjust($trackpoint_count) $dbc_trackpoint_adjust_status($trackpoint_count) \
$dbc_trackpoint_cutcom($trackpoint_count) $dbc_trackpoint_cutcom_status($trackpoint_count) \
$dbc_trackpoint_diam($trackpoint_count) $dbc_trackpoint_length($trackpoint_count) \
$dbc_trackpoint_z_offset($trackpoint_count) $dbc_trackpoint_zoff_status($trackpoint_count) \
$dbc_trackpoint_def_type($trackpoint_count)]
puts $fileid $data_line
}
}
"TURNING"
{
for {set trackpoint_count 0 } { $trackpoint_count < $dbc_trackpoint_count} {incr trackpoint_count} \
{
set data_line [format "DATA | %s | 2 | 0 | %s | %d | %d | %d | %9.5f | %9.5f | %d | %d | %9.5f | %9.5f" \
$dbc_cutter_trackpoint_libref $dbc_trackpoint_name($trackpoint_count) \
$dbc_trackpoint_seqno($trackpoint_count) \
$dbc_trackpoint_adjust($trackpoint_count) $dbc_trackpoint_cutcom($trackpoint_count) \
$dbc_trackpoint_x_offset($trackpoint_count) $dbc_trackpoint_y_offset($trackpoint_count) \
$dbc_trackpoint_radius_id($trackpoint_count) $dbc_trackpoint_cluster_id($trackpoint_count) \
$dbc_trackpoint_tool_angle($trackpoint_count) $dbc_trackpoint_radius($trackpoint_count)]
puts $fileid $data_line
}
}
}
}
proc ASC_classify_line { } \
{
global asc_cur_line
global asc_class
global asc_record_libref
global asc_record_type
# First check if record is some form of comment
if {[string match {#*} $asc_cur_line] == 1} \
{
# It does. Sort out what kind
if {[string match #END_DATA $asc_cur_line] == 1} \
{
set asc_record_type "End Data"
} elseif {[string match *CLASS* $asc_cur_line] == 1} \
{
# We have a Class specification. Extract the class
set asc_record_type "Class"
set asc_class [string trimright $asc_cur_line]
set tmp_ix [string first CLASS $asc_class]
set tmp_iy [string wordend $asc_class $tmp_ix]
set asc_class [string range $asc_class $tmp_iy end]
set asc_class [string trimleft $asc_class]
} elseif {[string match *dbc_logname* $asc_cur_line] == 1} \
{
set asc_record_type "Revision"
} else \
{
set asc_record_type "Comment"
}
} elseif {[string match {FORMAT*} $asc_cur_line] == 1 } \
{
set asc_record_type "Format"
} elseif {[string match {DATA*} $asc_cur_line] ==1} \
{
# We have a DATA record.
set asc_record_type "Data"
# Extract the libref from this data record
set tmp_ix [string first | $asc_cur_line]
incr tmp_ix
set asc_record_libref [string range $asc_cur_line $tmp_ix end]
set tmp_iy [string first | $asc_record_libref]
incr tmp_iy -1
set asc_record_libref [string range $asc_record_libref 0 $tmp_iy]
set asc_record_libref [string trim $asc_record_libref]
} else \
{
# This doesn't match any previous types, so it is probably a blank line.
# Whatever it is, treat it as a comment and pass it through.
set asc_record_type "Comment"
}
}
# To enable the new customization mechanism.
# This should ALWAYS be the last line in the file.
MOM_extend_for_customization UGII_CAM_CUSTOM_LIBRARY_TOOL_ASCII_DIR dbc_custom_trackpoint_ascii.tcl