- work in progress to Toolchange_Custom code replacememnt -> finished the parse and replace function

This commit is contained in:
Marius Stanciu
2019-02-26 17:03:57 +02:00
committed by Marius
parent 00340287a4
commit 874ce11d84
5 changed files with 35 additions and 60 deletions

View File

@@ -3829,7 +3829,7 @@ class App(QtCore.QObject):
if notebook_widget_name == 'selected_tab': if notebook_widget_name == 'selected_tab':
if str(type(self.collection.get_active())) == "<class 'FlatCAMObj.FlatCAMGeometry'>": if str(type(self.collection.get_active())) == "<class 'FlatCAMObj.FlatCAMGeometry'>":
# Tool add works for Geometry only if Advanced is True in Preferences # Tool add works for Geometry only if Advanced is True in Preferences
if self.defaults["global_advanced"] is True: if self.defaults["global_app_level"] == 'a':
tool_add_popup = FCInputDialog(title="New Tool ...", tool_add_popup = FCInputDialog(title="New Tool ...",
text='Enter a Tool Diameter:', text='Enter a Tool Diameter:',
min=0.0000, max=99.9999, decimals=4) min=0.0000, max=99.9999, decimals=4)

View File

@@ -1343,9 +1343,6 @@ class FlatCAMExcellon(FlatCAMObj, Excellon):
self.multigeo = True self.multigeo = True
# search for toolchange parameters in the Toolchange Custom Code
self.re_toolchange_custom = re.compile(r'^.*%([a-zA-Z0-9]+)%.*')
# Attributes to be included in serialization # Attributes to be included in serialization
# Always append to it because it carries contents # Always append to it because it carries contents
# from predecessors. # from predecessors.
@@ -2256,17 +2253,6 @@ class FlatCAMExcellon(FlatCAMObj, Excellon):
self.ui.feedrate_probe_entry.setVisible(False) self.ui.feedrate_probe_entry.setVisible(False)
self.ui.feedrate_probe_label.hide() self.ui.feedrate_probe_label.hide()
def parse_custom_toolchange_code(self, data):
toolchange_gcode = ''
lines = StringIO(data)
for line in lines:
match = self.re_toolchange_custom.search(line)
if match:
command = match.group(1)
print(globals()[command])
def on_create_cncjob_button_click(self, *args): def on_create_cncjob_button_click(self, *args):
self.app.report_usage("excellon_on_create_cncjob_button") self.app.report_usage("excellon_on_create_cncjob_button")
self.read_form() self.read_form()
@@ -2759,9 +2745,6 @@ class FlatCAMGeometry(FlatCAMObj, Geometry):
# the default value is False # the default value is False
self.multigeo = False self.multigeo = False
# search for toolchange parameters in the Toolchange Custom Code
self.re_toolchange_custom = re.compile(r'^.*%([a-zA-Z0-9]+)%.*')
# flag to store if the geometry is part of a special group of geometries that can't be processed by the default # flag to store if the geometry is part of a special group of geometries that can't be processed by the default
# engine of FlatCAM. Most likely are generated by some of tools and are special cases of geometries. # engine of FlatCAM. Most likely are generated by some of tools and are special cases of geometries.
self. special_group = None self. special_group = None
@@ -3866,17 +3849,6 @@ class FlatCAMGeometry(FlatCAMObj, Geometry):
self.ui.feedrate_probe_entry.setVisible(False) self.ui.feedrate_probe_entry.setVisible(False)
self.ui.feedrate_probe_label.hide() self.ui.feedrate_probe_label.hide()
def parse_custom_toolchange_code(self, data):
toolchange_gcode = ''
lines = StringIO(data)
for line in lines:
match = self.re_toolchange_custom.search(line)
if match:
command = match.group(1)
print(globals()[command])
def on_generatecnc_button_click(self, *args): def on_generatecnc_button_click(self, *args):
self.app.report_usage("geometry_on_generatecnc_button") self.app.report_usage("geometry_on_generatecnc_button")
@@ -5388,6 +5360,13 @@ class FlatCAMCNCjob(FlatCAMObj, CNCjob):
g = gcode[:g_idx] + preamble + '\n' + gcode[g_idx:] + postamble g = gcode[:g_idx] + preamble + '\n' + gcode[g_idx:] + postamble
# if toolchange custom is used, replace M6 code with the code from the Toolchange Custom Text box
if self.ui.toolchange_cb.get_value() is True:
# match = self.re_toolchange.search(g)
if 'M6' in g:
m6_code = self.parse_custom_toolchange_code(self.ui.toolchange_text.get_value())
g = g.replace('M6', m6_code)
# lines = StringIO(self.gcode) # lines = StringIO(self.gcode)
lines = StringIO(g) lines = StringIO(g)

View File

@@ -13,6 +13,7 @@ CAD program, and create G-Code for Isolation routing.
- added a function to read the parameters from ToolChange macro Text Box (I need to move it from CNCJob to Excellon and Geometry) - added a function to read the parameters from ToolChange macro Text Box (I need to move it from CNCJob to Excellon and Geometry)
- fixed the geometry adding to the self.apertures in the case when regions are done without declaring any aperture first (Allegro does that). Now, that geometry will be stored in the '0' aperture with type REG - fixed the geometry adding to the self.apertures in the case when regions are done without declaring any aperture first (Allegro does that). Now, that geometry will be stored in the '0' aperture with type REG
- work in progress to Toolchange_Custom code replacememnt -> finished the parse and replace function
25.02.2019 25.02.2019

View File

@@ -4602,6 +4602,8 @@ class CNCjob(Geometry):
self.toolchange_xy = toolchange_xy self.toolchange_xy = toolchange_xy
self.toolchange_xy_type = None self.toolchange_xy_type = None
self.toolC = tooldia
self.endz = endz self.endz = endz
self.depthpercut = depthpercut self.depthpercut = depthpercut
@@ -4648,6 +4650,12 @@ class CNCjob(Geometry):
self.tool = 0.0 self.tool = 0.0
# search for toolchange parameters in the Toolchange Custom Code
self.re_toolchange_custom = re.compile(r'(%[a-zA-Z0-9\-_]+%)')
# search for toolchange code: M6
self.re_toolchange = re.compile(r'^\s*(M6)$')
# Attributes to be included in serialization # Attributes to be included in serialization
# Always append to it because it carries contents # Always append to it because it carries contents
# from Geometry. # from Geometry.
@@ -4689,6 +4697,22 @@ class CNCjob(Geometry):
self.app.log.error('Exception occurred within a postprocessor: ' + traceback.format_exc()) self.app.log.error('Exception occurred within a postprocessor: ' + traceback.format_exc())
return '' return ''
def parse_custom_toolchange_code(self, data):
text = data
match_list = self.re_toolchange_custom.findall(text)
if match_list:
for match in match_list:
command = match.strip('%')
try:
value = getattr(self, command)
except AttributeError:
self.app.inform.emit("[ERROR] There is no such parameter: %s" % str(match))
log.debug("CNCJob.parse_custom_toolchange_code() --> AttributeError ")
return 'fail'
text = text.replace(match, str(value))
return text
def optimized_travelling_salesman(self, points, start=None): def optimized_travelling_salesman(self, points, start=None):
""" """
As solving the problem in the brute force way is too slow, As solving the problem in the brute force way is too slow,

View File

@@ -1,7 +1,7 @@
from FlatCAMPostProc import * from FlatCAMPostProc import *
class Toolchange_Probe_general(FlatCAMPostProc): class Toolchange_Custom(FlatCAMPostProc):
coordinate_format = "%.*f" coordinate_format = "%.*f"
feedrate_format = '%.*f' feedrate_format = '%.*f'
@@ -97,29 +97,13 @@ class Toolchange_Probe_general(FlatCAMPostProc):
if toolchangexy is not None: if toolchangexy is not None:
gcode = """ gcode = """
M5
G00 X{toolchangex} Y{toolchangey}
T{tool}
M6 M6
(MSG, Change to Tool Dia = {toolC} ||| Total drills for tool T{tool} = {t_drills})
M0
""".format(toolchangex=self.coordinate_format % (p.coords_decimals, toolchangex), """.format(toolchangex=self.coordinate_format % (p.coords_decimals, toolchangex),
toolchangey=self.coordinate_format % (p.coords_decimals, toolchangey), toolchangey=self.coordinate_format % (p.coords_decimals, toolchangey),
tool=int(p.tool), tool=int(p.tool),
t_drills=no_drills, t_drills=no_drills,
toolC=toolC_formatted) toolC=toolC_formatted)
else:
gcode = """
M5
T{tool}
M6
(MSG, Change to Tool Dia = {toolC} ||| Total drills for tool T{tool} = {t_drills})
M0
""".format(tool=int(p.tool),
t_drills=no_drills,
toolC=toolC_formatted)
if f_plunge is True: if f_plunge is True:
gcode += '\nG00 Z%.*f' % (p.coords_decimals, p.z_move) gcode += '\nG00 Z%.*f' % (p.coords_decimals, p.z_move)
return gcode return gcode
@@ -127,24 +111,11 @@ M0
else: else:
if toolchangexy is not None: if toolchangexy is not None:
gcode = """ gcode = """
M5
G00 X{toolchangex} Y{toolchangey}
T{tool}
M6 M6
(MSG, Change to Tool Dia = {toolC})
M0
""".format(toolchangex=self.coordinate_format % (p.coords_decimals, toolchangex), """.format(toolchangex=self.coordinate_format % (p.coords_decimals, toolchangex),
toolchangey=self.coordinate_format % (p.coords_decimals, toolchangey), toolchangey=self.coordinate_format % (p.coords_decimals, toolchangey),
tool=int(p.tool), tool=int(p.tool),
toolC=toolC_formatted) toolC=toolC_formatted)
else:
gcode = """
M5
T{tool}
M6
(MSG, Change to Tool Dia = {toolC})
M0""".format(tool=int(p.tool),
toolC=toolC_formatted)
if f_plunge is True: if f_plunge is True:
gcode += '\nG00 Z%.*f' % (p.coords_decimals, p.z_move) gcode += '\nG00 Z%.*f' % (p.coords_decimals, p.z_move)