# *TOOL_MACHINING_DATA.TCL ############################################################################### # tool_machining_data.tcl - DBC Event Handler for database stored as ascii file ############################################################################### # Revisions # Date Who Reason # 12Dec2003 rlm Initial # 30Jan2004 rlm Move ASC_write to dbc_ascii_general # 12Feb2004 rlm Add library revision information # 26Oct2018 Shorbojeet Das PR8340732: Add customization support for double precision control. # 08Nov2018 Updates # 22Aug2023 Jenny Zhang Add new attributes # 13Sep2023 Romy Shi MFEC-42148: Modify DBC_retrieve for support retrieve enhanced machining data # 26Oct2023 Romy Shi MFEC-45967: Adjust wrong paramters # 31Oct2023 Romy Shi MFEC-45968: Refactor logic for retrieve enhanced machining data # 02Nov2023 Xi Wang MFEC-45912: Change format after output new header # 09Nov2023 Jingzhao Zhang MFEC-46854: Return name when auto set preset record # 09Nov2023 Xi Wang MFEC-46624: Add DBC_find_select # 28Nov2023 Romy Shi MFEC-47510: Modify logic for retrieve enhanced machining data # 04Feb2024 Jingzhao Zhang MFEC-48916: Remove EnhancedToolMachiningData # 01Mar2024 Xi Wang MFEC-50674: Support old dat with no preset in mach data # 29Mar2024 XI Wang MFEC-52010: In retrieve, return error if no machining data in library # 18Jun2024 Jingzhao Zhang MFEC-54164: Correct comments ################################################################################ # # The format of each line in the text file is: # # libref depth_in depth_mm stepover_in stepover_mm speed_in speed_mm # feed_in feed_mm approach_pct engage_pct frstcut_pct # stepover_pct retract_pct return_pct depart_pct # # libref is a string # depth_in is a double # depth_mm is a double # stepover_in is a double # stepover_mm is a double # speed_in is a double # speed_mm is a double # feed_in is a double # feed_mm is a double # approach_pct is an integer # engage_pct is an integer # frstcut_pct is an integer # stepover_pct is an integer # retract_pct is an integer # return_pct is an integer # depart_pct is an integer # # The DB_ID of a DB_ALIAS is its field number in the line (0-based) ############################################################################### #MOM_set_debug_mode ON #--------------------------------------------- # Non DBC Global Variables #--------------------------------------------- #set dbFileName "[MOM_ask_env_var UGII_CAM_LIBRARY_FEEDS_SPEEDS_DATA_DIR]tool_machining_data.dat" ; # The ASCII Database File set DEBUG 1 set fPointer "" #--------------------------------------------- # Global variables set by DBC for Input/Output #--------------------------------------------- set dbc_lhs_exp "" set dbc_rhs_exp "" set dbc_relop "" set dbc_query "" set dbc_subqry1 "" set dbc_subqry2 "" set dbc_boolop "" set dbc_class_name "" set dbc_attr_count 0 set dbc_attr_id "" set dbc_query_count 0 set dbc_libref "" set dbc_var_list "" set dbc_tool_diameter "" set dbc_tool_height "" set dbc_name "" set dbc_part_units "english" ; # ( english : 0 , metric : 1) # Default double precision value format. set double_precision_format "g" # # Express feedrates for the following feed types # as percentages of Cut feedrate. # A value of 0 indicates no relation to Cut feedrate. # set dbc_engage_percent 90 set dbc_first_cut_percent 60 set dbc_approach_percent 0 set dbc_stepover_percent 0 set dbc_retract_percent 0 set dbc_departure_percent 0 set dbc_return_percent 0 set asc_debug 0 proc ASC_t_create_filename {env_var_name filename} \ { # # Creates a complete filename by evaluating an environment variable # for the directory information # set env_var [MOM_ask_env_var $env_var_name] if { $env_var == "" } \ { set message "Can't read environment variable $env_var_name" MOM_abort "\n $message" } set fname "" set fname [append fname $env_var $filename] return $fname } #--------------------------------------------- proc MOM__boot {} { #--------------------------------------------- # source some general procedures # # dbc_ascii_general.tcl # set filename \ [ASC_t_create_filename "UGII_UG_LIBRARY_DIR" "dbc_ascii_general.tcl"] if { [catch {source $filename}] == "1" } \ { set message "Can't load .tcl file: $filename" MOM_abort "\n $message" } } proc MOM__halt {} \ { } #--------------------------------------------- proc DBC_init_db {} { #--------------------------------------------- global DEBUG global dataBase global dbFileName global fPointer global asc_file_name global asc_database_count set asc_file_name "" set asc_part_units "" set data_unit 0 set mode 0 # # Set the filename for ASCII Data File # ASC_set_data_file_name # Changed to improve performance # And load the file into memory # ASC_load_data_file $asc_file_name $data_unit $mode } #--------------------------------------------- proc ASC_set_data_file_name {} { #--------------------------------------------- global dbc_part_units global asc_file_name global asc_part_units MOM_ask_part_units ;# writes to dbc_part_units set env_var UGII_CAM_LIBRARY_FEEDS_SPEEDS_DATA_DIR set asc_file_name [ASC_t_create_filename "$env_var" "tool_machining_data.dat"] set asc_part_units $dbc_part_units } #--------------------------------------------- proc ASC_get_machining_data { DB_ROW CUT_DEPTH STEPOVER FEED_VALUE SPEED_VALUE } { #--------------------------------------------- upvar $DB_ROW db_row upvar $CUT_DEPTH asc_cut_value upvar $STEPOVER asc_stepover upvar $FEED_VALUE asc_feed_value upvar $SPEED_VALUE asc_speed_value global dbc_part_units if { $dbc_part_units == "english"} \ { set asc_cut_value [ASC_ask_att_val DPT_CUT_IN $db_row \ "%$::double_precision_format" 0 flag] set asc_stepover [ASC_ask_att_val STEPOVER_IN $db_row \ "%$::double_precision_format" 0 flag] set asc_speed_value [ASC_ask_att_val SURF_SPEED_FPM $db_row \ "%$::double_precision_format" 0 flag] set asc_feed_value [ASC_ask_att_val FEED_IPT $db_row \ "%$::double_precision_format" 0 flag] } else \ { set asc_cut_value [ASC_ask_att_val DPT_CUT_MM $db_row \ "%$::double_precision_format" 0 flag] set asc_stepover [ASC_ask_att_val STEPOVER_MM $db_row \ "%$::double_precision_format" 0 flag] set asc_speed_value [ASC_ask_att_val SURF_SPEED_MPM $db_row \ "%$::double_precision_format" 0 flag] set asc_feed_value [ASC_ask_att_val FEED_MMPT $db_row \ "%$::double_precision_format" 0 flag] } } #--------------------------------------------- proc ASC_get_feedrate_percentages { DB_ROW APPROACH_PERCENT ENGAGE_PERCENT \ FIRSTCUT_PERCENT STEPOVER_PERCENT RETRACT_PERCENT RETURN_PERCENT DEPART_PERCENT } { #--------------------------------------------- upvar $DB_ROW db_row upvar $APPROACH_PERCENT asc_approach_pct upvar $ENGAGE_PERCENT asc_engage_pct upvar $FIRSTCUT_PERCENT asc_firstcut_pct upvar $STEPOVER_PERCENT asc_stepover_pct upvar $RETRACT_PERCENT asc_retract_pct upvar $RETURN_PERCENT asc_return_pct upvar $DEPART_PERCENT asc_depart_pct set asc_approach_pct [ASC_ask_att_val APPROACH_PCT $db_row \ "%d" 0 flag] set asc_engage_pct [ASC_ask_att_val ENGAGE_PCT $db_row \ "%d" 0 flag] set asc_firstcut_pct [ASC_ask_att_val FRSTCUT_PCT $db_row \ "%d" 0 flag] set asc_stepover_pct [ASC_ask_att_val STEPOVER_PCT $db_row \ "%d" 0 flag] set asc_retract_pct [ASC_ask_att_val RETRACT_PCT $db_row \ "%d" 0 flag] set asc_return_pct [ASC_ask_att_val RETURN_PCT $db_row \ "%d" 0 flag] set asc_depart_pct [ASC_ask_att_val DEPART_PCT $db_row \ "%d" 0 flag] if { $asc_engage_pct == 0 } \ { set asc_engage_pct "RAPID" } if { $asc_retract_pct == 0 } \ { set asc_retract_pct "RAPID" } } proc ASC_get_engage_data { DB_ROW ENGAGE_SPEED ENGAGE_FEED ENGAGE_DIA ENGAGE_ANG } { #--------------------------------------------- upvar $DB_ROW db_row upvar $ENGAGE_SPEED asc_engage_speed upvar $ENGAGE_FEED asc_engage_feed upvar $ENGAGE_DIA asc_engage_dia upvar $ENGAGE_ANG asc_engage_ang global dbc_part_units if { $dbc_part_units == "english"} \ { set asc_engage_speed [ASC_ask_att_val ENGAGE_SPEED_FPM $db_row \ "%$::double_precision_format" 0 flag] set asc_engage_feed [ASC_ask_att_val ENGAGE_FEED_IPT $db_row \ "%$::double_precision_format" 0 flag] set asc_engage_dia [ASC_ask_att_val ENGAGE_DIA_IN $db_row \ "%$::double_precision_format" 0 flag] } else \ { set asc_engage_speed [ASC_ask_att_val ENGAGE_SPEED_MPM $db_row \ "%$::double_precision_format" 0 flag] set asc_engage_feed [ASC_ask_att_val ENGAGE_FEED_MMPT $db_row \ "%$::double_precision_format" 0 flag] set asc_engage_dia [ASC_ask_att_val ENGAGE_DIA_MM $db_row \ "%$::double_precision_format" 0 flag] } set asc_engage_ang [ASC_ask_att_val ENGAGE_ANG $db_row \ "%$::double_precision_format" 0 flag] } #------------------------------------------------------------------------ proc DBC_create_query { } { #------------------------------------------------------------------------ global DEBUG global dbc_query global dbc_subqry1 global dbc_subqry2 global dbc_boolop # set dbc_query "$dbc_subqry1 $dbc_boolop $dbc_subqry2" ASC_create_query } #------------------------------------------------------------------------ proc DBC_execute_query { } { #------------------------------------------------------------------------ global asc_database_count ASC_execute_query } proc DBC_find_select {} { global DEBUG global dbc_event_error global dbc_part_units global dbc_surface_speed global dbc_feed_per_tooth global dbc_depth_of_cut global dbc_stepover global dbc_approach_percent global dbc_engage_percent global dbc_first_cut_percent global dbc_stepover_percent global dbc_retract_percent global dbc_return_percent global dbc_departure_percent global fPointer global dbFileName global asc_database_count global asc_database global asc_file_name global file_unit global asc_units global asc_next_line global dbc_libref global dbc_engage_speed global dbc_engage_feed global dbc_engage_dia global dbc_engage_ang global dbc_cutmthd_libref global dbc_part_material_libref global dbc_selected_name set index 0 set initialize_flag 1 set asc_data_file_name $asc_file_name set asc_next_line "" if { $dbc_part_units == "english" } \ { set file_unit $asc_units(inch) } else \ { set file_unit $asc_units(mm) } if { [info exists dbc_selected_name] && $dbc_selected_name != "" } \ { set db_row 0 while { $db_row < $asc_database_count } \ { set ascii_libref [ ASC_ask_att_val LIBRF $db_row "" 0 flag] set ascii_name [ ASC_ask_att_val NAME $db_row "" 0 flag] # See if row matches requested conditions if {$dbc_libref == $ascii_libref && $dbc_selected_name == $ascii_name} \ { # Got a matching record, get remaining data and return ASC_get_machining_data db_row dbc_depth_of_cut dbc_stepover \ dbc_feed_per_tooth dbc_surface_speed ASC_get_feedrate_percentages db_row dbc_approach_percent \ dbc_engage_percent dbc_first_cut_percent dbc_stepover_percent \ dbc_retract_percent dbc_return_percent dbc_departure_percent ASC_get_engage_data db_row dbc_engage_speed dbc_engage_feed \ dbc_engage_dia dbc_engage_ang return 0 } incr db_row } } set dbc_event_error "No appropriate machining data found" } #--------------------------------------------- proc DBC_retrieve {} { #--------------------------------------------- global DEBUG global dbc_event_error global dbc_part_units global dbc_surface_speed global dbc_feed_per_tooth global dbc_depth_of_cut global dbc_stepover global dbc_approach_percent global dbc_engage_percent global dbc_first_cut_percent global dbc_stepover_percent global dbc_retract_percent global dbc_return_percent global dbc_departure_percent global fPointer global dbFileName global asc_database_count global asc_database global asc_file_name global file_unit global asc_units global asc_next_line global dbc_libref global dbc_engage_speed global dbc_engage_feed global dbc_engage_dia global dbc_engage_ang global dbc_cutmthd_libref global dbc_part_material_libref global dbc_name set index 0 set initialize_flag 1 set asc_data_file_name $asc_file_name set asc_next_line "" set dbc_name "" if { $dbc_part_units == "english" } \ { set file_unit $asc_units(inch) } else \ { set file_unit $asc_units(mm) } ## Changed function to improve performance # set ret_code [catch {open $asc_data_file_name "r"} fp] # if { $ret_code } \ # { # return 1 # } # ASC_init_database # # Loop over all the DATA records # # The db_row variable has to be initialized (see also ASC_translate_att_alias if { $asc_database_count == 0 } \ { set dbc_event_error "No appropriate machining data found" return 0; } set ascii_preset [ ASC_ask_att_val PRESET 0 "" -1 flag] if { $ascii_preset == "-1" } \ { set db_row 0 while { $db_row < $asc_database_count } \ { set ascii_libref [ ASC_ask_att_val LIBRF $db_row "" 0 flag] # See if row matches requested libref if { $dbc_libref == $ascii_libref } \ { # Got a matching record, get remaining data and return ASC_get_machining_data db_row dbc_depth_of_cut dbc_stepover \ dbc_feed_per_tooth dbc_surface_speed ASC_get_feedrate_percentages db_row dbc_approach_percent \ dbc_engage_percent dbc_first_cut_percent dbc_stepover_percent \ dbc_retract_percent dbc_return_percent dbc_departure_percent return 0 } incr db_row } } else \ { #First check part material and cut method if { [info exists dbc_part_material_libref] && [info exists dbc_cutmthd_libref]} \ { set db_row 0 while { $db_row < $asc_database_count } \ { set ascii_libref [ ASC_ask_att_val LIBRF $db_row "" 0 flag] set ascii_part_material_libref [ ASC_ask_att_val PARTMAT $db_row "" 0 flag] set ascii_cut_method_libref [ ASC_ask_att_val CUTMTD $db_row "" 0 flag] # See if row matches requested conditions if {$dbc_libref == $ascii_libref && \ $dbc_part_material_libref == $ascii_part_material_libref && \ $dbc_cutmthd_libref == $ascii_cut_method_libref } \ { # Got a matching record, get remaining data and return ASC_get_machining_data db_row dbc_depth_of_cut dbc_stepover \ dbc_feed_per_tooth dbc_surface_speed ASC_get_feedrate_percentages db_row dbc_approach_percent \ dbc_engage_percent dbc_first_cut_percent dbc_stepover_percent \ dbc_retract_percent dbc_return_percent dbc_departure_percent ASC_get_engage_data db_row dbc_engage_speed dbc_engage_feed \ dbc_engage_dia dbc_engage_ang set dbc_name [ ASC_ask_att_val NAME $db_row "" 0 flag] return 0 } incr db_row } } #If part material and cut method not matched then check preset set db_row 0 while { $db_row < $asc_database_count } \ { set ascii_libref [ ASC_ask_att_val LIBRF $db_row "" 0 flag] set ascii_preset [ ASC_ask_att_val PRESET $db_row "" 0 flag] # See if row matches requested conditions if { $dbc_libref == $ascii_libref && $ascii_preset == "1"} \ { # Got a matching record, get remaining data and return ASC_get_machining_data db_row dbc_depth_of_cut dbc_stepover \ dbc_feed_per_tooth dbc_surface_speed ASC_get_feedrate_percentages db_row dbc_approach_percent \ dbc_engage_percent dbc_first_cut_percent dbc_stepover_percent \ dbc_retract_percent dbc_return_percent dbc_departure_percent ASC_get_engage_data db_row dbc_engage_speed dbc_engage_feed \ dbc_engage_dia dbc_engage_ang set dbc_name [ ASC_ask_att_val NAME $db_row "" 0 flag] return 0 } incr db_row } } # no match found at all -- return error message set dbc_event_error "No appropriate machining data found" } #------------------------------------------------------------------------ proc DBC_write { } { #------------------------------------------------------------------------ global asc_database_name set asc_database_name "tool_machining_data.dat" ASC_write } #------------------------------------------------------------------------ proc ASC_output_header { fileid } { #------------------------------------------------------------------------ global dbc_attr_count global dbc_attr_aliases global dbc_attr_id global dbc_logname global asc_database_fmt set daytime [clock seconds] set out_daytime [clock format $daytime -format "%a %b %d %Y %I:%M %p"] set headerMessage "# TOOL_MACHINING_DATA.DAT ########################################################################## # # PURPOSE: # # This is the database file used for defining Machining Data in # an operation based only on the selected tool. # # REVISED: # $dbc_logname $out_daytime # ########################################################################## # The data is organized in the following format separated by | # The fields in the database are in the following order: # # LIBRF - library reference of cutter # DPT_CUT_IN - dpth_of_cut Depth_of_cut(inch) # DPT_CUT_MM - dpth_of_cut Depth_of_cut(mm) # STEPOVER_IN - stepover distance (inch) # STEPOVER_MM - stepover distance (mm) # SURF_SPEED_FPM - surface_speed Suface Speed(FPM) # SURF_SPEED_MPM - surface_speed Suface Speed(MPM) # FEED_IPT - feed_per_tooth Feed per Tooth(IPT) # FEED_MMPT - feed_per_tooth Feed per Tooth(MMPT) # APPROACH_PCT - approach feedrate percentage of cut feedrate # ENGAGE_PCT - engage feedrate percentage of cut feedrate # FRSTCUT_PCT - first cut feedrate percentage of cut feedrate # STEPOVER_PCT - stepover feedrate percentage of cut feedrate # RETRACT_PCT - retract feedrate percentage of cut feedrate # RETURN_PCT - return feedrate percentage of cut feedrate # DEPART_PCT - departure feedrate percentage of cut feedrate # NAME - unique record identifier # DESCR - description # PARTMAT - library reference of part material # CUTMTD - library reference of cut method # ENGAGE_SPEED_MPM - engage surface speeed Engage Suface Speed(MPM) # ENGAGE_SPEED_FPM - engage surface speeed Engage Suface Speed(IPM) # ENGAGE_FEED_MMPT - engage feed per tooth Engage Feed per Tooth(MPT) # ENGAGE_FEED_IPT - engage feed per tooth Engage Feed per Tooth(IPT) # ENGAGE_DIA_MM - engage diameter Engage Diameter (mm) # ENGAGE_DIA_IN - engage diameter Engage Diameter (inch) # ENGAGE_ANG - engage ramp angle # PRESET - preset record #--------------------------------------------------------------------------------" puts $fileid "$headerMessage" # load the database structure DBC_load_rset_data # Xi Wang 6-Nov-2023 # Update asc_database_fmt, it is used in ASC_output_data to output data # set fmt {} # output FORMAT line set format_line "FORMAT" for {set i 0} {$i < $dbc_attr_count} {incr i} \ { DBC_ask_attr_id $dbc_attr_aliases($i) set format_line "$format_line $dbc_attr_id" lappend fmt $dbc_attr_id } set asc_database_fmt(0) $fmt puts $fileid $format_line puts $fileid "#--------------------------------------------------------------------------------" } # Xi Wang 6-Nov-2023 # Add following functions to support query, #--------------------------------------------- proc DBC_translate_att_alias {} { #--------------------------------------------- ASC_translate_att_alias } #--------------------------------------------- proc DBC_create_criterion {} { #--------------------------------------------- ASC_create_criterion } #--------------------------------------------- proc DBC_create_query {} { #--------------------------------------------- ASC_create_query } # To enable the new customization mechanism. # This should ALWAYS be the last line in the file. MOM_extend_for_customization UGII_CAM_CUSTOM_LIBRARY_FEEDS_SPEEDS_ASCII_DIR dbc_custom_ascii_tool_machining_data.tcl