- solved issue #381 where there was an error when trying to generate CNCJob out of an Excellon file that have a tool with only slots and no drills

- solved some issues in the preprocessors regarding the newly introduced feature that allow control of the final move X,Y positions
This commit is contained in:
Marius Stanciu
2020-02-28 17:59:15 +02:00
committed by Marius
parent 69607816d0
commit c5e4d72db8
16 changed files with 73 additions and 45 deletions

View File

@@ -12,6 +12,8 @@ CAD program, and create G-Code for Isolation routing.
28.02.2020
- some small changes in preprocessors
- solved issue #381 where there was an error when trying to generate CNCJob out of an Excellon file that have a tool with only slots and no drills
- solved some issues in the preprocessors regarding the newly introduced feature that allow control of the final move X,Y positions
25.02.2020

View File

@@ -2647,8 +2647,8 @@ class CNCjob(Geometry):
if self.xy_toolchange == '':
self.xy_toolchange = None
else:
self.xy_toolchange = [float(eval(a)) for a in self.xy_toolchange.split(",")]
if len(self.xy_toolchange) < 2:
self.xy_toolchange = [float(eval(a)) for a in self.xy_toolchange.split(",") if self.xy_toolchange != '']
if self.xy_toolchange and len(self.xy_toolchange) < 2:
self.app.inform.emit('[ERROR]%s' %
_("The Toolchange X,Y field in Edit -> Preferences has to be "
"in the format (x, y) \nbut now there is only one value, not two. "))
@@ -2657,8 +2657,8 @@ class CNCjob(Geometry):
log.debug("camlib.CNCJob.generate_from_excellon_by_tool() --> %s" % str(e))
pass
self.xy_end = [float(eval(a)) for a in self.xy_end.split(",")]
if len(self.xy_end) < 2:
self.xy_end = [float(eval(a)) for a in self.xy_end.split(",") if self.xy_end != '']
if self.xy_end and len(self.xy_end) < 2:
self.app.inform.emit('[ERROR] %s' % _("The End Move X,Y field in Edit -> Preferences has to be "
"in the format (x, y) but now there is only one value, not two."))
return 'fail'
@@ -2783,12 +2783,14 @@ class CNCjob(Geometry):
class CreateDistanceCallback(object):
"""Create callback to calculate distances between points."""
def __init__(self):
def __init__(self, tool):
"""Initialize distance array."""
locations = create_data_array()
size = len(locations)
locations = create_data_array(tool)
self.matrix = dict()
if locations:
size = len(locations)
for from_node in range(size):
self.matrix[from_node] = {}
for to_node in range(size):
@@ -2810,11 +2812,15 @@ class CNCjob(Geometry):
return self.matrix[from_node][to_node]
# Create the data.
def create_data_array():
locations = []
def create_data_array(tool):
loc_list = list()
if tool not in points:
return None
for point in points[tool]:
locations.append((point.coords.xy[0][0], point.coords.xy[1][0]))
return locations
loc_list.append((point.coords.xy[0][0], point.coords.xy[1][0]))
return loc_list
if self.xy_toolchange is not None:
self.oldx = self.xy_toolchange[0]
@@ -2884,7 +2890,12 @@ class CNCjob(Geometry):
# ###############################################
node_list = []
locations = create_data_array()
locations = create_data_array(tool=tool)
# if there are no locations then go to the next tool
if not locations:
continue
tsp_size = len(locations)
num_routes = 1 # The number of routes, which is 1 in the TSP.
# Nodes are indexed from 0 to tsp_size - 1. The depot is the starting node of the route.
@@ -2906,7 +2917,12 @@ class CNCjob(Geometry):
# Callback to the distance function. The callback takes two
# arguments (the from and to node indices) and returns the distance between them.
dist_between_locations = CreateDistanceCallback()
dist_between_locations = CreateDistanceCallback(tool=tool)
# if there are no distances then go to the next tool
if not dist_between_locations:
continue
dist_callback = dist_between_locations.Distance
transit_callback_index = routing.RegisterTransitCallback(dist_callback)
routing.SetArcCostEvaluatorOfAllVehicles(transit_callback_index)
@@ -3088,7 +3104,7 @@ class CNCjob(Geometry):
old_zcut = deepcopy(self.z_cut)
self.z_move = exobj.tools[tool]['data']['travelz']
print(self.z_move)
self.spindlespeed = exobj.tools[tool]['data']['spindlespeed']
self.dwell = exobj.tools[tool]['data']['dwell']
self.dwelltime = exobj.tools[tool]['data']['dwelltime']
@@ -3100,7 +3116,12 @@ class CNCjob(Geometry):
# ###############################################
node_list = []
locations = create_data_array()
locations = create_data_array(tool=tool)
# if there are no locations then go to the next tool
if not locations:
continue
tsp_size = len(locations)
num_routes = 1 # The number of routes, which is 1 in the TSP.
@@ -3115,7 +3136,12 @@ class CNCjob(Geometry):
# Callback to the distance function. The callback takes two
# arguments (the from and to node indices) and returns the distance between them.
dist_between_locations = CreateDistanceCallback()
dist_between_locations = CreateDistanceCallback(tool=tool)
# if there are no distances then go to the next tool
if not dist_between_locations:
continue
dist_callback = dist_between_locations.Distance
transit_callback_index = routing.RegisterTransitCallback(dist_callback)
routing.SetArcCostEvaluatorOfAllVehicles(transit_callback_index)
@@ -3519,8 +3545,8 @@ class CNCjob(Geometry):
self.startz = float(startz) if startz is not None else None
self.z_end = float(endz) if endz is not None else None
self.xy_end = [float(eval(a)) for a in endxy.split(",")]
if len(self.xy_end) < 2:
self.xy_end = [float(eval(a)) for a in endxy.split(",") if endxy != '']
if self.xy_end and len(self.xy_end) < 2:
self.app.inform.emit('[ERROR] %s' % _("The End Move X,Y field in Edit -> Preferences has to be "
"in the format (x, y) but now there is only one value, not two."))
return 'fail'
@@ -3887,8 +3913,8 @@ class CNCjob(Geometry):
self.startz = float(startz) if startz is not None else self.app.defaults["geometry_startz"]
self.z_end = float(endz) if endz is not None else self.app.defaults["geometry_endz"]
self.xy_end = endxy if endxy != '' else self.app.defaults["geometry_endxy"]
self.xy_end = [float(eval(a)) for a in self.xy_end.split(",")]
if len(self.xy_end) < 2:
self.xy_end = [float(eval(a)) for a in self.xy_end.split(",") if self.xy_end != '']
if self.xy_end and len(self.xy_end) < 2:
self.app.inform.emit('[ERROR] %s' % _("The End Move X,Y field in Edit -> Preferences has to be "
"in the format (x, y) but now there is only one value, not two."))
return 'fail'

View File

@@ -230,7 +230,7 @@ M0""".format(z_toolchange=self.coordinate_format % (p.coords_decimals, z_toolcha
coords_xy = p['xy_end']
gcode = ('G00 Z' + self.feedrate_format % (p.fr_decimals, p.z_end) + "\n")
if coords_xy != '':
if coords_xy and coords_xy != '':
gcode += 'G00 X{x} Y{y}'.format(x=coords_xy[0], y=coords_xy[1]) + "\n"
gcode += '(Berta)\n'

View File

@@ -86,7 +86,7 @@ class GRBL_laser(FlatCAMPostProc):
coords_xy = p['xy_end']
gcode = ('G00 Z' + self.feedrate_format % (p.fr_decimals, p.z_end) + "\n")
if coords_xy != '':
if coords_xy and coords_xy != '':
gcode += 'G00 X{x} Y{y}'.format(x=coords_xy[0], y=coords_xy[1]) + "\n"
return gcode

View File

@@ -160,7 +160,7 @@ M01""".format(tool=int(p.tool), toolC=toolC_formatted)
coords_xy = p['xy_end']
gcode = ('G00 Z' + self.feedrate_format % (p.fr_decimals, p.z_end) + "\n")
if coords_xy != '':
if coords_xy and coords_xy != '':
gcode += 'G00 X{x} Y{y}'.format(x=coords_xy[0], y=coords_xy[1]) + "\n"
return gcode

View File

@@ -218,7 +218,7 @@ G0 Z{z_toolchange}
coords_xy = p['xy_end']
gcode = ('G0 Z' + self.feedrate_format % (p.fr_decimals, p.z_end) + " " + self.feedrate_rapid_code(p) + "\n")
if coords_xy != '':
if coords_xy and coords_xy != '':
gcode += 'G0 X{x} Y{y}'.format(x=coords_xy[0], y=coords_xy[1]) + " " + self.feedrate_rapid_code(p) + "\n"
return gcode

View File

@@ -88,7 +88,7 @@ class Marlin_laser_FAN_pin(FlatCAMPostProc):
coords_xy = p['xy_end']
gcode = ('G0 Z' + self.feedrate_format % (p.fr_decimals, p.z_end) + " " + self.feedrate_rapid_code(p) + "\n")
if coords_xy != '':
if coords_xy and coords_xy != '':
gcode += 'G0 X{x} Y{y}'.format(x=coords_xy[0], y=coords_xy[1]) + " " + self.feedrate_rapid_code(p) + "\n"
return gcode

View File

@@ -89,7 +89,7 @@ class Marlin_laser_Spindle_pin(FlatCAMPostProc):
coords_xy = p['xy_end']
gcode = ('G0 Z' + self.feedrate_format % (p.fr_decimals, p.z_end) + " " + self.feedrate_rapid_code(p) + "\n")
if coords_xy != '':
if coords_xy and coords_xy != '':
gcode += 'G0 X{x} Y{y}'.format(x=coords_xy[0], y=coords_xy[1]) + " " + self.feedrate_rapid_code(p) + "\n"
return gcode

View File

@@ -125,7 +125,7 @@ G00 Z{z_toolchange}
coords_xy = [float(eval(a)) for a in p['xy_end'].split(",") if a != '']
gcode = ('G00 Z' + self.feedrate_format % (p.fr_decimals, float(p['z_toolchange'])) + "\n")
if coords_xy != '':
if coords_xy and coords_xy != '':
gcode += 'G00 X{x} Y{y}'.format(x=coords_xy[0], y=coords_xy[1]) + "\n"
return gcode

View File

@@ -209,7 +209,7 @@ G0 Z{z_toolchange}
coords_xy = p['xy_end']
gcode = ('G0 Z' + self.feedrate_format % (p.fr_decimals, p.z_end) + " " + self.feedrate_rapid_code(p) + "\n")
if coords_xy != '':
if coords_xy and coords_xy != '':
gcode += 'G0 X{x} Y{y}'.format(x=coords_xy[0], y=coords_xy[1]) + " " + self.feedrate_rapid_code(p) + "\n"
return gcode

View File

@@ -176,7 +176,7 @@ M6
coords_xy = p['xy_end']
gcode = ('G00 Z' + self.feedrate_format % (p.fr_decimals, p.z_end) + "\n")
if coords_xy != '':
if coords_xy and coords_xy != '':
gcode += 'G00 X{x} Y{y}'.format(x=coords_xy[0], y=coords_xy[1]) + "\n"
return gcode

View File

@@ -238,7 +238,7 @@ M0
coords_xy = p['xy_end']
gcode = ('G00 Z' + self.feedrate_format % (p.fr_decimals, p.z_end) + "\n")
if coords_xy != '':
if coords_xy and coords_xy != '':
gcode += 'G00 X{x} Y{y}'.format(x=coords_xy[0], y=coords_xy[1]) + "\n"
return gcode

View File

@@ -275,7 +275,7 @@ M0
coords_xy = p['xy_end']
gcode = ('G00 Z' + self.feedrate_format % (p.fr_decimals, p.z_end) + "\n")
if coords_xy != '':
if coords_xy and coords_xy != '':
gcode += 'G00 X{x} Y{y}'.format(x=coords_xy[0], y=coords_xy[1]) + "\n"
return gcode

View File

@@ -220,7 +220,7 @@ G00 Z{z_toolchange}
end_coords_xy = p['xy_end']
gcode = ('G00 Z' + self.feedrate_format % (p.fr_decimals, p.z_end) + "\n")
if end_coords_xy != '':
if end_coords_xy and end_coords_xy != '':
gcode += 'G00 X{x} Y{y}'.format(x=end_coords_xy[0], y=end_coords_xy[1]) + "\n"
return gcode

View File

@@ -221,7 +221,7 @@ G00 Z{z_toolchange}
coords_xy = p['xy_end']
gcode = ('G00 Z' + self.feedrate_format % (p.fr_decimals, p.z_end) + "\n")
if coords_xy != '':
if coords_xy and coords_xy != '':
gcode += 'G00 X{x} Y{y}'.format(x=coords_xy[0], y=coords_xy[1]) + "\n"
return gcode

View File

@@ -207,7 +207,7 @@ M0""".format(x_toolchange=self.coordinate_format % (p.coords_decimals, x_toolcha
def end_code(self, p):
coords_xy = p['xy_end']
if coords_xy != '':
if coords_xy and coords_xy != '':
g = 'G00 X{x} Y{y}'.format(x=coords_xy[0], y=coords_xy[1]) + "\n"
else:
g = ('G00 ' + self.position_code(p)).format(**p)