- upgraded the Drilling Plugin and all the related parts in the CNCJob Object and in all preprocessors. Now, the parent 'tools' attribute is inherited and also the GCode is stored here

This commit is contained in:
Marius Stanciu
2021-03-14 13:05:19 +02:00
committed by Marius
parent 2f64ca99b1
commit 95fb418966
27 changed files with 290 additions and 456 deletions

View File

@@ -119,7 +119,10 @@ class CNCJobObject(FlatCAMObj, CNCjob):
it's done in camlib.CNCJob.generate_from_excellon_by_tool()
BEWARE: I rely on the ordered nature of the Python 3.7 dictionary. Things might change ...
'''
self.exc_cnc_tools = {}
self.tools = {}
# the current tool that is used to generate GCode
self.tool = None
# flag to store if the CNCJob is part of a special group of CNCJob objects that can't be processed by the
# default engine of FlatCAM. They generated by some of tools and are special cases of CNCJob objects.
@@ -129,9 +132,6 @@ class CNCJobObject(FlatCAMObj, CNCjob):
# (like the one in the TCL Command), False
self.multitool = False
# determine if the GCode was generated out of a Excellon object or a Geometry object
self.origin_kind = None
self.coords_decimals = 4
self.fr_decimals = 2
@@ -186,12 +186,13 @@ class CNCJobObject(FlatCAMObj, CNCjob):
# if the FlatCAM object is Excellon don't build the CNC Tools Table but hide it
self.ui.cnc_tools_table.hide()
if self.cnc_tools:
self.ui.exc_cnc_tools_table.hide()
if self.options['type'].lower() == 'geometry':
self.ui.cnc_tools_table.show()
self.build_cnc_tools_table()
self.ui.exc_cnc_tools_table.hide()
if self.exc_cnc_tools:
if self.options['type'].lower() == 'excellon':
self.ui.exc_cnc_tools_table.show()
self.build_excellon_cnc_tools()
@@ -296,18 +297,18 @@ class CNCJobObject(FlatCAMObj, CNCjob):
self.ui.cnc_tools_table.setMaximumHeight(self.ui.cnc_tools_table.getHeight())
def build_excellon_cnc_tools(self):
tool_idx = 0
n = len(self.exc_cnc_tools)
n = len(self.tools)
self.ui.exc_cnc_tools_table.setRowCount(n)
for tooldia_key, dia_value in self.exc_cnc_tools.items():
row_no = 1
for t_id, dia_value in self.tools.items():
tooldia = self.tools[t_id]['tooldia']
tool_idx += 1
row_no = tool_idx - 1
row_no = t_id - 1
t_id = QtWidgets.QTableWidgetItem('%d' % int(tool_idx))
dia_item = QtWidgets.QTableWidgetItem('%.*f' % (self.decimals, float(tooldia_key)))
t_id_item = QtWidgets.QTableWidgetItem('%d' % int(t_id))
dia_item = QtWidgets.QTableWidgetItem('%.*f' % (self.decimals, float(tooldia)))
nr_drills_item = QtWidgets.QTableWidgetItem('%d' % int(dia_value['nr_drills']))
nr_slots_item = QtWidgets.QTableWidgetItem('%d' % int(dia_value['nr_slots']))
try:
@@ -317,7 +318,7 @@ class CNCJobObject(FlatCAMObj, CNCjob):
cutz_item = QtWidgets.QTableWidgetItem('%f' % offset_val)
t_id.setFlags(QtCore.Qt.ItemIsEnabled)
t_id_item.setFlags(QtCore.Qt.ItemIsEnabled)
dia_item.setFlags(QtCore.Qt.ItemIsEnabled)
nr_drills_item.setFlags(QtCore.Qt.ItemIsEnabled)
nr_slots_item.setFlags(QtCore.Qt.ItemIsEnabled)
@@ -336,21 +337,21 @@ class CNCJobObject(FlatCAMObj, CNCjob):
plot_item = FCCheckBox()
plot_item.setLayoutDirection(QtCore.Qt.RightToLeft)
tool_uid_item = QtWidgets.QTableWidgetItem(str(dia_value['tool']))
if self.ui.plot_cb.isChecked():
plot_item.setChecked(True)
self.ui.exc_cnc_tools_table.setItem(row_no, 0, t_id) # Tool name/id
self.ui.exc_cnc_tools_table.setItem(row_no, 0, t_id_item) # Tool name/id
self.ui.exc_cnc_tools_table.setItem(row_no, 1, dia_item) # Diameter
self.ui.exc_cnc_tools_table.setItem(row_no, 2, nr_drills_item) # Nr of drills
self.ui.exc_cnc_tools_table.setItem(row_no, 3, nr_slots_item) # Nr of slots
# ## REMEMBER: THIS COLUMN IS HIDDEN IN OBJECTUI.PY # ##
self.ui.exc_cnc_tools_table.setItem(row_no, 4, tool_uid_item) # Tool unique ID)
self.ui.exc_cnc_tools_table.setItem(row_no, 4, t_id_item) # Tool unique ID)
self.ui.exc_cnc_tools_table.setItem(row_no, 5, cutz_item)
self.ui.exc_cnc_tools_table.setCellWidget(row_no, 6, plot_item)
for row in range(tool_idx):
for row in range(row_no):
self.ui.exc_cnc_tools_table.item(row, 0).setFlags(
self.ui.exc_cnc_tools_table.item(row, 0).flags() ^ QtCore.Qt.ItemIsSelectable)
@@ -832,9 +833,6 @@ class CNCJobObject(FlatCAMObj, CNCjob):
gcode += ';Name: ' + str(self.options['name']) + '\n'
gcode += ';Type: ' + "G-code from " + str(self.options['type']) + '\n'
# if str(p['options']['type']) == 'Excellon' or str(p['options']['type']) == 'Excellon Geometry':
# gcode += '(Tools in use: ' + str(p['options']['Tools_in_use']) + ')\n'
gcode += ';Units: ' + self.units.upper() + '\n' + "\n"
gcode += ';Created on ' + time_str + '\n' + '\n'
elif hpgl is True:
@@ -844,9 +842,6 @@ class CNCJobObject(FlatCAMObj, CNCjob):
gcode += 'CO "Name: ' + str(self.options['name']) + '";\n'
gcode += 'CO "Type: ' + "HPGL code from " + str(self.options['type']) + '";\n'
# if str(p['options']['type']) == 'Excellon' or str(p['options']['type']) == 'Excellon Geometry':
# gcode += '(Tools in use: ' + str(p['options']['Tools_in_use']) + ')\n'
gcode += 'CO "Units: ' + self.units.upper() + '";\n'
gcode += 'CO "Created on ' + time_str + '";\n'
elif probe_pp is True:
@@ -862,9 +857,6 @@ class CNCJobObject(FlatCAMObj, CNCjob):
gcode += '(Name: ' + str(self.options['name']) + ')\n'
gcode += '(Type: ' + "G-code from " + str(self.options['type']) + ')\n'
# if str(p['options']['type']) == 'Excellon' or str(p['options']['type']) == 'Excellon Geometry':
# gcode += '(Tools in use: ' + str(p['options']['Tools_in_use']) + ')\n'
gcode += '(Units: ' + self.units.upper() + ')\n' + "\n"
gcode += '(Created on ' + time_str + ')\n' + '\n'
else:
@@ -874,9 +866,6 @@ class CNCJobObject(FlatCAMObj, CNCjob):
gcode += '%sName: ' % start_comment + str(self.options['name']) + '%s\n' % stop_comment
gcode += '%sType: ' % start_comment + "G-code from " + str(self.options['type']) + '%s\n' % stop_comment
# if str(p['options']['type']) == 'Excellon' or str(p['options']['type']) == 'Excellon Geometry':
# gcode += '(Tools in use: ' + str(p['options']['Tools_in_use']) + ')\n'
gcode += '%sUnits: ' % start_comment + self.units.upper() + '%s\n' % stop_comment + "\n"
gcode += '%sCreated on ' % start_comment + time_str + '%s\n' % stop_comment + '\n'
@@ -935,16 +924,16 @@ class CNCJobObject(FlatCAMObj, CNCjob):
include_header = include_header.include_header
# if this dict is not empty then the object is an Excellon object
if self.exc_cnc_tools:
first_key = next(iter(self.exc_cnc_tools))
if self.options['type'].lower() == 'excellon':
first_key = next(iter(self.tools))
try:
include_header = self.app.preprocessors[
self.exc_cnc_tools[first_key]['data']['tools_drill_ppname_e']
self.tools[first_key]['data']['tools_drill_ppname_e']
].include_header
except KeyError:
# for older loaded projects
include_header = self.app.preprocessors[
self.exc_cnc_tools[first_key]['data']['ppname_e']
self.tools[first_key]['data']['ppname_e']
].include_header
gcode = ''
@@ -976,9 +965,9 @@ class CNCJobObject(FlatCAMObj, CNCjob):
# detect if using multi-tool and make the Gcode summation correctly for each case
if self.multitool is True:
if self.origin_kind == 'excellon':
for tooluid_key in self.exc_cnc_tools:
for key, value in self.exc_cnc_tools[tooluid_key].items():
if self.options['type'].lower() == 'excellon':
for tooluid_key in self.tools:
for key, value in self.tools[tooluid_key].items():
if key == 'gcode' and value:
gcode += value
break
@@ -995,16 +984,16 @@ class CNCJobObject(FlatCAMObj, CNCjob):
# detect if using a HPGL preprocessor
hpgl = False
if self.cnc_tools:
if self.options['type'].lower() == 'geometry':
for key in self.cnc_tools:
if 'tools_mill_ppname_g' in self.cnc_tools[key]['data']:
if 'hpgl' in self.cnc_tools[key]['data']['tools_mill_ppname_g']:
hpgl = True
break
elif self.exc_cnc_tools:
for key in self.cnc_tools:
if 'ppname_e' in self.cnc_tools[key]['data']:
if 'hpgl' in self.cnc_tools[key]['data']['ppname_e']:
elif self.options['type'].lower() == 'excellon':
for key in self.tools:
if 'ppname_e' in self.tools[key]['data']:
if 'hpgl' in self.tools[key]['data']['ppname_e']:
hpgl = True
break
@@ -1184,13 +1173,13 @@ class CNCJobObject(FlatCAMObj, CNCjob):
kind = self.ui.cncplot_method_combo.get_value()
self.shapes.clear(update=True)
if self.origin_kind == "excellon":
if self.options['type'].lower() == "excellon":
for r in range(self.ui.exc_cnc_tools_table.rowCount()):
row_dia = float('%.*f' % (self.decimals, float(self.ui.exc_cnc_tools_table.item(r, 1).text())))
for tooluid_key in self.exc_cnc_tools:
tooldia = float('%.*f' % (self.decimals, float(tooluid_key)))
for tooluid_key in self.tools:
tooldia = float('%.*f' % (self.decimals, float(self.tools[tooluid_key]['tooldia'])))
if row_dia == tooldia:
gcode_parsed = self.exc_cnc_tools[tooluid_key]['gcode_parsed']
gcode_parsed = self.tools[tooluid_key]['gcode_parsed']
if self.ui.exc_cnc_tools_table.cellWidget(r, 6).isChecked():
self.plot2(tooldia=tooldia, obj=self, visible=True, gcode_parsed=gcode_parsed, kind=kind)
else:
@@ -1238,7 +1227,7 @@ class CNCJobObject(FlatCAMObj, CNCjob):
# Geometry shapes plotting
try:
if self.multitool is False: # single tool usage
if self.origin_kind == "excellon":
if self.options['type'].lower() == "excellon":
try:
dia_plot = float(self.options["tooldia"])
except ValueError:
@@ -1255,11 +1244,11 @@ class CNCJobObject(FlatCAMObj, CNCjob):
# I do this so the travel lines thickness will reflect the tool diameter
# may work only for objects created within the app and not Gcode imported from elsewhere for which we
# don't know the origin
if self.origin_kind == "excellon":
if self.exc_cnc_tools:
for tooldia_key in self.exc_cnc_tools:
tooldia = self.app.dec_format(float(tooldia_key), self.decimals)
gcode_parsed = self.exc_cnc_tools[tooldia_key]['gcode_parsed']
if self.options['type'].lower() == "excellon":
if self.tools:
for toolid_key in self.tools:
tooldia = self.app.dec_format(float(self.tools[toolid_key]['tooldia']), self.decimals)
gcode_parsed = self.tools[toolid_key]['gcode_parsed']
if not gcode_parsed:
continue
# gcode_parsed = self.gcode_parsed

View File

@@ -956,12 +956,6 @@ class ExcellonObject(FlatCAMObj, Excellon):
# ## Add properties to the object
# get the plugin_table items in a list of row items
plugin_table_items = self.get_selected_tools_table_items()
# insert an information only element in the front
plugin_table_items.insert(0, [_("Tool_nr"), _("Diameter"), _("Drills_Nr"), _("Slots_Nr")])
geo_obj.options['Tools_in_use'] = plugin_table_items
geo_obj.options['type'] = 'Excellon Geometry'
geo_obj.options["tools_mill_tooldia"] = str(tooldia)
geo_obj.options["multidepth"] = app_obj.defaults["tools_mill_multidepth"]
@@ -1056,12 +1050,6 @@ class ExcellonObject(FlatCAMObj, Excellon):
# ## Add properties to the object
# get the plugin_table items in a list of row items
plugin_table_items = self.get_selected_tools_table_items()
# insert an information only element in the front
plugin_table_items.insert(0, [_("Tool_nr"), _("Diameter"), _("Drills_Nr"), _("Slots_Nr")])
geo_obj.options['Tools_in_use'] = plugin_table_items
geo_obj.options['type'] = 'Excellon Geometry'
geo_obj.options["tools_mill_tooldia"] = str(tooldia)
geo_obj.options["tools_mill_multidepth"] = app_obj.defaults["tools_mill_multidepth"]

View File

@@ -2221,7 +2221,7 @@ class GeometryObject(FlatCAMObj, Geometry):
else:
self.app.inform.emit('[ERROR_NOTCL] %s' % _("Failed. No tool selected in the tool table ..."))
def mtool_gen_cncjob(self, outname=None, tools_dict=None, tools_in_use=None, segx=None, segy=None,
def mtool_gen_cncjob(self, outname=None, tools_dict=None, segx=None, segy=None,
plot=True, use_thread=True):
"""
Creates a multi-tool CNCJob out of this Geometry object.
@@ -2232,7 +2232,6 @@ class GeometryObject(FlatCAMObj, Geometry):
:param tools_dict: a dictionary that holds the whole data needed to create the Gcode
(including the solid_geometry)
:param tools_in_use: the tools that are used, needed by some preprocessors
:type tools_in_use list of lists, each list in the list is made out of row elements of tools table from GUI
:param segx: number of segments on the X axis, for auto-levelling
:param segy: number of segments on the Y axis, for auto-levelling
:param plot: if True the generated object will be plotted; if False will not be plotted
@@ -2244,7 +2243,6 @@ class GeometryObject(FlatCAMObj, Geometry):
outname = "%s_%s" % (self.options["name"], 'cnc') if outname is None else outname
tools_dict = self.sel_tools if tools_dict is None else tools_dict
tools_in_use = tools_in_use if tools_in_use is not None else self.get_selected_tools_table_items()
segx = segx if segx is not None else float(self.app.defaults['geometry_segx'])
segy = segy if segy is not None else float(self.app.defaults['geometry_segy'])
@@ -2286,7 +2284,6 @@ class GeometryObject(FlatCAMObj, Geometry):
job_obj.multigeo = False
job_obj.cnc_tools.clear()
job_obj.options['Tools_in_use'] = tools_in_use
job_obj.segx = segx if segx else float(self.app.defaults["geometry_segx"])
job_obj.segy = segy if segy else float(self.app.defaults["geometry_segy"])
@@ -2390,10 +2387,6 @@ class GeometryObject(FlatCAMObj, Geometry):
total_gcode += res
# tell gcode_parse from which point to start drawing the lines depending on what kind of
# object is the source of gcode
job_obj.toolchange_xy_type = "geometry"
self.app.inform.emit('[success] %s' % _("G-Code parsing in progress..."))
dia_cnc_dict['gcode_parsed'] = job_obj.gcode_parse()
app_obj.inform.emit('[success] %s' % _("G-Code parsing finished..."))
@@ -2435,7 +2428,6 @@ class GeometryObject(FlatCAMObj, Geometry):
job_obj.multigeo = True
job_obj.cnc_tools.clear()
job_obj.options['Tools_in_use'] = tools_in_use
job_obj.segx = segx if segx else float(self.app.defaults["geometry_segx"])
job_obj.segy = segy if segy else float(self.app.defaults["geometry_segy"])
@@ -2560,10 +2552,6 @@ class GeometryObject(FlatCAMObj, Geometry):
except Exception as ee:
app_obj.inform.emit('[ERROR] %s: %s' % (_("G-Code processing failed with error"), str(ee)))
# tell gcode_parse from which point to start drawing the lines depending on what kind of
# object is the source of gcode
job_obj.toolchange_xy_type = "geometry"
job_obj.cnc_tools.update({
tooluid_key: deepcopy(dia_cnc_dict)
})
@@ -2723,9 +2711,6 @@ class GeometryObject(FlatCAMObj, Geometry):
job_obj.gc_start = start_gcode
job_obj.source_file = start_gcode + res
# tell gcode_parse from which point to start drawing the lines depending on what kind of object is the
# source of gcode
job_obj.toolchange_xy_type = "geometry"
job_obj.gcode_parse()
app_obj.inform.emit('[success] %s...' % _("Finished G-Code processing"))

View File

@@ -547,8 +547,9 @@ class FlatCAMObj(QtCore.QObject):
if obj_prop.kind.lower() == 'cncjob':
try:
for tool_k in obj_prop.exc_cnc_tools:
x0, y0, x1, y1 = unary_union(obj_prop.exc_cnc_tools[tool_k]['solid_geometry']).bounds
# created from Excellon object
for tool_k in obj_prop.tools:
x0, y0, x1, y1 = unary_union(obj_prop.tools[tool_k]['solid_geometry']).bounds
xmin.append(x0)
ymin.append(y0)
xmax.append(x1)
@@ -556,6 +557,7 @@ class FlatCAMObj(QtCore.QObject):
except Exception as ee:
log.error("FlatCAMObj.add_properties_items() cncjob --> %s" % str(ee))
# created from Geometry object
try:
for tool_k in obj_prop.cnc_tools:
x0, y0, x1, y1 = unary_union(obj_prop.cnc_tools[tool_k]['solid_geometry']).bounds
@@ -771,10 +773,11 @@ class FlatCAMObj(QtCore.QObject):
for data_k, data_v in v.items():
self.treeWidget.addChild(tool_data, [str(data_k).capitalize(), str(data_v)], True)
# for cncjob objects made from excellon
for tool_dia, value in obj.exc_cnc_tools.items():
# for CNCJob objects made from Excellon
for tool_id, value in obj.tools.items():
tool_dia = value['tooldia']
exc_tool = self.treeWidget.addParent(
tools, str(value['tool']), expanded=False, color=p_color, font=font
tools, str(tool_id), expanded=False, color=p_color, font=font
)
self.treeWidget.addChild(
exc_tool,