From 95fb41896696efc52e3a316fad611e87d1de38e6 Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Sun, 14 Mar 2021 13:05:19 +0200 Subject: [PATCH] - 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 --- CHANGELOG.md | 5 +- appEditors/appGCodeEditor.py | 44 ++--- appObjects/FlatCAMCNCJob.py | 95 +++++------ appObjects/FlatCAMExcellon.py | 12 -- appObjects/FlatCAMGeometry.py | 17 +- appObjects/FlatCAMObj.py | 13 +- appPlugins/ToolDrilling.py | 205 ++++++++---------------- appPlugins/ToolMilling.py | 19 --- appPlugins/ToolReport.py | 12 +- appPlugins/ToolSolderPaste.py | 7 - camlib.py | 52 ++---- preprocessors/Berta_CNC.py | 20 ++- preprocessors/Check_points.py | 16 +- preprocessors/Default_no_M6.py | 22 ++- preprocessors/GRBL_11.py | 18 +-- preprocessors/GRBL_11_no_M6.py | 20 ++- preprocessors/ISEL_CNC.py | 18 +-- preprocessors/ISEL_ICP_CNC.py | 14 +- preprocessors/Line_xyz.py | 21 ++- preprocessors/Marlin.py | 20 ++- preprocessors/Paste_1.py | 2 +- preprocessors/Repetier.py | 18 +-- preprocessors/Toolchange_Manual.py | 21 ++- preprocessors/Toolchange_Probe_MACH3.py | 18 +-- preprocessors/default.py | 20 ++- preprocessors/grbl_laser_eleks_drd.py | 4 +- tclCommands/TclCommandDrillcncjob.py | 13 +- 27 files changed, 290 insertions(+), 456 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d9e451e..4d3edbf0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,16 +10,17 @@ CHANGELOG for FlatCAM beta 14.03.2021 - Geometry Editor can now modify the edited tool diameter +- 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 13.03.2021 - fixed a bug in Gerber merge -- bypassed a bug in FlatCAM Gerber UI - its not really fixed (it's a crash in build UI when disconnecting signals due of the wrapped C++ object already destroyed) +- bypassed a bug in FlatCAM Gerber UI - it's not really fixed (it's a crash in build UI when disconnecting signals due of the wrapped C++ object already destroyed) 11.03.2021 - fixed issue when exporting DXF and not settings the units -- added the posibility to export the Geometry in different DXF formats (previously it was hard coded to the AutoCAD 2010): R12, R2000, R2004, R2007, R2010, R2013, R2018 +- added the possibility to export the Geometry in different DXF formats (previously it was hard coded to the AutoCAD 2010): R12, R2000, R2004, R2007, R2010, R2013, R2018 - fixed the camlib.Geometry.bounds() method such that it is calculated correctly for Geometry objects created in the Geometry Editor 7.03.2021 diff --git a/appEditors/appGCodeEditor.py b/appEditors/appGCodeEditor.py index 6352949b..aa272376 100644 --- a/appEditors/appGCodeEditor.py +++ b/appEditors/appGCodeEditor.py @@ -135,12 +135,12 @@ class AppGCodeEditor(QtCore.QObject): # if the FlatCAM object is Excellon don't build the CNC Tools Table but hide it self.ui.cnc_tools_table.hide() - if self.gcode_obj.cnc_tools: + if self.gcode_obj.options['type'].lower() == 'geometry': self.ui.cnc_tools_table.show() self.build_cnc_tools_table() self.ui.exc_cnc_tools_table.hide() - if self.gcode_obj.exc_cnc_tools: + if self.gcode_obj.options['type'].lower() == 'excellon': self.ui.exc_cnc_tools_table.show() self.build_excellon_cnc_tools() @@ -242,7 +242,7 @@ class AppGCodeEditor(QtCore.QObject): tool_idx = 0 row_no = 0 - n = len(self.gcode_obj.exc_cnc_tools) + 3 + n = len(self.gcode_obj.tools) + 3 self.ui.exc_cnc_tools_table.setRowCount(n) # add the All Gcode selection @@ -262,17 +262,17 @@ class AppGCodeEditor(QtCore.QObject): start_item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) self.ui.exc_cnc_tools_table.setItem(row_no, 1, start_item) - for tooldia_key, dia_value in self.gcode_obj.exc_cnc_tools.items(): - + for toolid_key, t_value in self.gcode_obj.tools.items(): + tooldia = self.gcode_obj.tools[toolid_key]['tooldia'] tool_idx += 1 row_no += 1 t_id = QtWidgets.QTableWidgetItem('%d' % int(tool_idx)) - dia_item = QtWidgets.QTableWidgetItem('%.*f' % (self.decimals, float(tooldia_key))) - nr_drills_item = QtWidgets.QTableWidgetItem('%d' % int(dia_value['nr_drills'])) - nr_slots_item = QtWidgets.QTableWidgetItem('%d' % int(dia_value['nr_slots'])) + dia_item = QtWidgets.QTableWidgetItem('%.*f' % (self.decimals, float(tooldia))) + nr_drills_item = QtWidgets.QTableWidgetItem('%d' % int(t_value['nr_drills'])) + nr_slots_item = QtWidgets.QTableWidgetItem('%d' % int(t_value['nr_slots'])) cutz_item = QtWidgets.QTableWidgetItem('%.*f' % ( - self.decimals, float(dia_value['offset']) + float(dia_value['data']['tools_drill_cutz']))) + self.decimals, float(t_value['offset']) + float(t_value['data']['tools_drill_cutz']))) t_id.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) dia_item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) @@ -285,7 +285,7 @@ class AppGCodeEditor(QtCore.QObject): 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 - tool_uid_item = QtWidgets.QTableWidgetItem(str(dia_value['tool'])) + tool_uid_item = QtWidgets.QTableWidgetItem(str(toolid_key)) # ## 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, 5, cutz_item) @@ -323,10 +323,11 @@ class AppGCodeEditor(QtCore.QObject): :rtype: """ # rows selected - if self.gcode_obj.cnc_tools: + if self.gcode_obj.options['type'].lower() == 'geometry': self.ui.cnc_tools_table.clicked.connect(self.on_row_selection_change) self.ui.cnc_tools_table.horizontalHeader().sectionClicked.connect(self.on_toggle_all_rows) - if self.gcode_obj.exc_cnc_tools: + + if self.gcode_obj.options['type'].lower() == 'excellon': self.ui.exc_cnc_tools_table.clicked.connect(self.on_row_selection_change) self.ui.exc_cnc_tools_table.horizontalHeader().sectionClicked.connect(self.on_toggle_all_rows) @@ -347,7 +348,7 @@ class AppGCodeEditor(QtCore.QObject): except (TypeError, AttributeError): pass - if self.gcode_obj.exc_cnc_tools: + if self.gcode_obj.options['type'].lower() == 'excellon': try: self.ui.exc_cnc_tools_table.clicked.disconnect(self.on_row_selection_change) except (TypeError, AttributeError): @@ -366,9 +367,9 @@ class AppGCodeEditor(QtCore.QObject): flags = QtGui.QTextDocument.FindCaseSensitively self.edit_area.moveCursor(QtGui.QTextCursor.Start) - if self.gcode_obj.cnc_tools: + if self.gcode_obj.options['type'].lower() == 'geometry': t_table = self.ui.cnc_tools_table - elif self.gcode_obj.exc_cnc_tools: + elif self.gcode_obj.options['type'].lower() == 'excellon': t_table = self.ui.exc_cnc_tools_table else: return @@ -432,13 +433,14 @@ class AppGCodeEditor(QtCore.QObject): tool_no = int(t_table.item(row, 0).text()) text_to_be_found = None - if self.gcode_obj.cnc_tools: + if self.gcode_obj.options['type'].lower() == 'geometry': text_to_be_found = self.gcode_obj.cnc_tools[tool_no]['gcode'] - elif self.gcode_obj.exc_cnc_tools: + elif self.gcode_obj.options['type'].lower() == 'excellon': tool_dia = self.app.dec_format(float(t_table.item(row, 1).text()), dec=self.decimals) - for tool_d in self.gcode_obj.exc_cnc_tools: + for tool_id in self.gcode_obj.tools: + tool_d = self.gcode_obj.tools[tool_id]['tooldia'] if self.app.dec_format(tool_d, dec=self.decimals) == tool_dia: - text_to_be_found = self.gcode_obj.exc_cnc_tools[tool_d]['gcode'] + text_to_be_found = self.gcode_obj.tools[tool_id]['gcode'] if text_to_be_found is None: continue else: @@ -541,9 +543,9 @@ class AppGCodeEditor(QtCore.QObject): :return: :rtype: """ - if self.gcode_obj.cnc_tools: + if self.gcode_obj.options['type'].lower() == 'geometry': t_table = self.ui.cnc_tools_table - elif self.gcode_obj.exc_cnc_tools: + elif self.gcode_obj.options['type'].lower() == 'excellon': t_table = self.ui.exc_cnc_tools_table else: return diff --git a/appObjects/FlatCAMCNCJob.py b/appObjects/FlatCAMCNCJob.py index 1e833b01..29ce415e 100644 --- a/appObjects/FlatCAMCNCJob.py +++ b/appObjects/FlatCAMCNCJob.py @@ -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 diff --git a/appObjects/FlatCAMExcellon.py b/appObjects/FlatCAMExcellon.py index 15ce86fd..a72e7806 100644 --- a/appObjects/FlatCAMExcellon.py +++ b/appObjects/FlatCAMExcellon.py @@ -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"] diff --git a/appObjects/FlatCAMGeometry.py b/appObjects/FlatCAMGeometry.py index f056ae74..b12cb2f0 100644 --- a/appObjects/FlatCAMGeometry.py +++ b/appObjects/FlatCAMGeometry.py @@ -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")) diff --git a/appObjects/FlatCAMObj.py b/appObjects/FlatCAMObj.py index 0e6d2db9..0f726f6c 100644 --- a/appObjects/FlatCAMObj.py +++ b/appObjects/FlatCAMObj.py @@ -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, diff --git a/appPlugins/ToolDrilling.py b/appPlugins/ToolDrilling.py index 5ee8a7a5..e6d78afd 100644 --- a/appPlugins/ToolDrilling.py +++ b/appPlugins/ToolDrilling.py @@ -941,7 +941,7 @@ class ToolDrilling(AppTool, Excellon): self.excellon_tools = self.excellon_obj.tools self.build_tool_ui() - self.update_ui() + self.update_ui() sel_rows = set() table_items = self.ui.tools_table.selectedItems() @@ -1263,22 +1263,21 @@ class ToolDrilling(AppTool, Excellon): "%s: %s" % (_('Parameters for'), _("Multiple Tools")) ) - for c_row in sel_rows: - # populate the form with the data from the tool associated with the row parameter - try: - item = self.ui.tools_table.item(c_row, 3) - if type(item) is not None: - tooluid = int(item.text()) - self.storage_to_form(self.excellon_tools[tooluid]['data']) - else: - self.blockSignals(False) - self.ui_connect() - return - except Exception as e: - log.error("Tool missing. Add a tool in the Tool Table. %s" % str(e)) + # populate the form with the data from the tool associated with the row parameter for the last row selected + try: + item = self.ui.tools_table.item(sel_rows[-1], 3) + if type(item) is not None: + tooluid = int(item.text()) + self.storage_to_form(self.excellon_tools[tooluid]['data']) + else: self.blockSignals(False) self.ui_connect() return + except Exception as e: + log.error("Tool missing. Add a tool in the Tool Table. %s" % str(e)) + self.blockSignals(False) + self.ui_connect() + return self.blockSignals(False) self.ui_connect() @@ -1292,21 +1291,23 @@ class ToolDrilling(AppTool, Excellon): :rtype: """ + general_keys = list(self.general_form_fields.keys()) + tool_keys = list(self.tool_form_fields.keys()) + # update the Tool parameters for form_key in self.tool_form_fields: for storage_key in dict_storage: - if form_key == storage_key and form_key not in \ - ["tools_drill_toolchange", "tools_drill_toolchangez", "startz", "endz", "tools_drill_ppname_e"]: + if form_key == storage_key and form_key not in general_keys: try: self.tool_form_fields[form_key].set_value(dict_storage[form_key]) except Exception as e: - log.error("ToolDrilling.storage_to_form() --> %s" % str(e)) + log.error("ToolDrilling.storage_to_form() tool parameters --> %s" % str(e)) pass # update the Common parameters for form_key in self.general_form_fields: for storage_key in dict_storage: - if form_key == storage_key: + if form_key == storage_key and form_key not in tool_keys: try: self.general_form_fields[form_key].set_value(dict_storage[form_key]) except Exception as e: @@ -1360,17 +1361,6 @@ class ToolDrilling(AppTool, Excellon): self.ui_connect() - def get_selected_tools_list(self): - """ - Returns the keys to the self.tools dictionary corresponding - to the selections on the tool list in the appGUI. - - :return: List of tools. - :rtype: list - """ - - return [str(x.text()) for x in self.ui.tools_table.selectedItems()] - def get_selected_tools_table_items(self): """ Returns a list of lists, each list in the list is made out of row elements @@ -1901,7 +1891,7 @@ class ToolDrilling(AppTool, Excellon): # if there is a single tool in the table (remember that the last 2 rows are for totals and do not count in # tool number) it means that there are 3 rows (1 tool and 2 totals). # in this case regardless of the selection status of that tool, use it. - if self.ui.tools_table.rowCount() >= 3: + if self.ui.tools_table.rowCount() == 3: selected_tools_id.append(int(self.ui.tools_table.item(0, 3).text())) else: msg = '[ERROR_NOTCL] %s' % _("Please select one or more tools from the list and try again.") @@ -1969,78 +1959,55 @@ class ToolDrilling(AppTool, Excellon): # ######################################################################################################### # ######################################################################################################### - # build a self.options['Tools_in_use'] list from scratch if we don't have one like in the case of - # running this method from a Tcl Command + # fill the data into the self.tools dictionary attribute of the CNCJob object # ######################################################################################################### # ######################################################################################################### - build_tools_in_use_list = False - if 'Tools_in_use' not in job_obj.options: - job_obj.options['Tools_in_use'] = [] - # if the list is empty (either we just added the key or it was already there but empty) signal to build it - if not job_obj.options['Tools_in_use']: - build_tools_in_use_list = True + job_obj.tools = {} + for sel_id in sorted_tools: + for t_id in self.excellon_tools: + selected_id = sel_id[0] + selected_tooldia = sel_id[1] - # ######################################################################################################### - # ######################################################################################################### - # fill the data into the self.exc_cnc_tools dictionary - # ######################################################################################################### - # ######################################################################################################### - for it in all_tools: - for to_ol in sel_tools: - if to_ol == it[0]: + if selected_id == t_id: + job_obj.tools[selected_id] = deepcopy(self.excellon_tools[selected_id]) sol_geo = [] # solid geometry addition; we look into points because we may have slots converted to drills # therefore more drills than there were originally in # the self.excellon_tools[to_ol]['drills'] list drill_no = 0 - if to_ol in points and points[to_ol]: - drill_no = len(points[to_ol]) - for drill in points[to_ol]: - sol_geo.append(drill.buffer((it[1] / 2.0), resolution=job_obj.geo_steps_per_circle)) + if selected_id in points and points[selected_id]: + drill_no = len(points[selected_id]) + for drill in points[selected_id]: + sol_geo.append( + drill.buffer((selected_tooldia / 2.0), resolution=job_obj.geo_steps_per_circle) + ) slot_no = 0 - convert_slots = self.excellon_tools[to_ol]['data']['tools_drill_drill_slots'] - if 'slots' in self.excellon_tools[to_ol] and convert_slots is False: - slot_no = len(self.excellon_tools[to_ol]['slots']) - for eslot in self.excellon_tools[to_ol]['slots']: + convert_slots = self.excellon_tools[selected_id]['data']['tools_drill_drill_slots'] + if 'slots' in self.excellon_tools[selected_id] and convert_slots is False: + slot_no = len(self.excellon_tools[selected_id]['slots']) + for eslot in self.excellon_tools[selected_id]['slots']: start = (eslot[0].x, eslot[0].y) stop = (eslot[1].x, eslot[1].y) + line_geo = LineString([start, stop]) sol_geo.append( - LineString([start, stop]).buffer((it[1] / 2.0), - resolution=job_obj.geo_steps_per_circle) + line_geo.buffer((selected_tooldia / 2.0), resolution=job_obj.geo_steps_per_circle) ) # adjust Offset for current tool try: - z_off = float(self.excellon_tools[it[0]]['data']['offset']) * (-1) + z_off = float(self.excellon_tools[selected_id]['data']['offset']) * (-1) except KeyError: z_off = 0 - # default tool data - default_data = {} - for kk, vv in list(obj.options.items()): - default_data[kk] = deepcopy(vv) - default_data['tools_drill_cutz'] = float(self.excellon_tools[it[0]]['data']['tools_drill_cutz']) - - # populate the Excellon CNC tools storage - job_obj.exc_cnc_tools[it[1]] = {} - job_obj.exc_cnc_tools[it[1]]['tool'] = it[0] - job_obj.exc_cnc_tools[it[1]]['nr_drills'] = drill_no - job_obj.exc_cnc_tools[it[1]]['nr_slots'] = slot_no - job_obj.exc_cnc_tools[it[1]]['offset'] = z_off - job_obj.exc_cnc_tools[it[1]]['data'] = default_data - job_obj.exc_cnc_tools[it[1]]['gcode'] = '' - job_obj.exc_cnc_tools[it[1]]['gcode_parsed'] = [] - job_obj.exc_cnc_tools[it[1]]['solid_geometry'] = deepcopy(sol_geo) - - # build a self.options['Tools_in_use'] list from scratch if we don't have one like in the case - # of running this method from a Tcl Command - if build_tools_in_use_list is True: - job_obj.options['Tools_in_use'].append( - [it[0], it[1], drill_no, slot_no] - ) + job_obj.tools[selected_id]['nr_drills'] = drill_no + job_obj.tools[selected_id]['nr_slots'] = slot_no + job_obj.tools[selected_id]['offset'] = z_off + job_obj.tools[selected_id]['gcode'] = '' + job_obj.tools[selected_id]['gcode_parsed'] = [] + job_obj.tools[selected_id]['solid_geometry'] = deepcopy(sol_geo) # ######################################################################################################### # ######################################################################################################### @@ -2051,13 +2018,6 @@ class ToolDrilling(AppTool, Excellon): job_obj.pp_excellon_name = self.ui.pp_excellon_name_cb.get_value() job_obj.pp_excellon = self.app.preprocessors[job_obj.pp_excellon_name] - # 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")]) - - # ## Add properties to the object - job_obj.options['Tools_in_use'] = plugin_table_items job_obj.options['type'] = 'Excellon' job_obj.options['ppname_e'] = obj.pp_excellon_name @@ -2066,9 +2026,8 @@ class ToolDrilling(AppTool, Excellon): job_obj.options['xmax'] = xmax job_obj.options['ymax'] = ymax - job_obj.origin_kind = 'excellon' job_obj.use_ui = True - job_obj.toolchange_xy_type = "excellon" + job_obj.coords_decimals = int(self.app.defaults["cncjob_coords_decimals"]) job_obj.fr_decimals = int(self.app.defaults["cncjob_fr_decimals"]) job_obj.multitool = True @@ -2107,29 +2066,12 @@ class ToolDrilling(AppTool, Excellon): used_tooldia = self.excellon_tools[used_tool]['tooldia'] # those are used by the preprocessors to display data on the toolchange line - job_obj.tool = str(used_tool) + job_obj.tool = used_tool job_obj.postdata['toolC'] = used_tooldia - # reconstitute the plugin_table_items to hold the total number of drills and slots since we are going to - # process all in one go with no toolchange and with only one tool - nr_drills = 0 - nr_slots = 0 - total_solid_geo = [] - - # calculate the total number of drills and of slots - for e_tool_dia in job_obj.exc_cnc_tools: - nr_drills += int(job_obj.exc_cnc_tools[e_tool_dia]['nr_drills']) - nr_slots += int(job_obj.exc_cnc_tools[e_tool_dia]['nr_slots']) - total_solid_geo += job_obj.exc_cnc_tools[e_tool_dia]['solid_geometry'] - - plugin_table_items.clear() - plugin_table_items = [[str(used_tool), str(used_tooldia), str(nr_drills), str(nr_slots)]] - plugin_table_items.insert(0, [_("Tool_nr"), _("Diameter"), _("Drills_Nr"), _("Slots_Nr")]) - job_obj.options['Tools_in_use'] = plugin_table_items - # generate GCode tool_gcode, __, start_gcode = job_obj.excellon_tool_gcode_gen(used_tool, tool_points, - self.excellon_tools, + job_obj.tools, first_pt=first_drill_point, is_first=True, is_last=True, @@ -2141,16 +2083,8 @@ class ToolDrilling(AppTool, Excellon): start_pt=first_drill_point) # store the results in Excellon CNC tools storage - job_obj.exc_cnc_tools[used_tooldia]['nr_drills'] = nr_drills - job_obj.exc_cnc_tools[used_tooldia]['nr_slots'] = nr_slots - job_obj.exc_cnc_tools[used_tooldia]['gcode'] = tool_gcode - job_obj.exc_cnc_tools[used_tooldia]['gcode_parsed'] = tool_gcode_parsed - job_obj.exc_cnc_tools[used_tooldia]['solid_geometry'] = total_solid_geo - - # delete all tools from the Excellon CNC tools storage except the used one - for e_tool_dia in list(job_obj.exc_cnc_tools.keys()): - if e_tool_dia != used_tooldia: - job_obj.exc_cnc_tools.pop(e_tool_dia, None) + job_obj.tools[used_tool]['gcode'] = tool_gcode + job_obj.tools[used_tool]['gcode_parsed'] = tool_gcode_parsed if start_gcode != '': job_obj.gc_start = start_gcode @@ -2160,32 +2094,31 @@ class ToolDrilling(AppTool, Excellon): # ####################### TOOLCHANGE ACTIVE ###################################################### else: - for tool in sel_tools: - tool_points = points[tool] - used_tooldia = self.excellon_tools[tool]['tooldia'] + for tool_id in sel_tools: + tool_points = points[tool_id] + used_tooldia = self.excellon_tools[tool_id]['tooldia'] + + # those are used by the preprocessors to display data on the toolchange line + job_obj.tool = tool_id + job_obj.postdata['toolC'] = used_tooldia # if slots are converted to drill for this tool, update the number of drills and make slots nr zero - convert_slots = self.excellon_tools[tool]['data']['tools_drill_drill_slots'] + convert_slots = self.excellon_tools[tool_id]['data']['tools_drill_drill_slots'] if convert_slots is True: - nr_drills = len(points[tool]) + nr_drills = len(points[tool_id]) nr_slots = 0 - job_obj.exc_cnc_tools[used_tooldia]['nr_drills'] = nr_drills - job_obj.exc_cnc_tools[used_tooldia]['nr_slots'] = nr_slots + job_obj.tools[used_tooldia]['nr_drills'] = nr_drills + job_obj.tools[used_tooldia]['nr_slots'] = nr_slots - for line in range(1, len(job_obj.options['Tools_in_use'])): - if self.dec_format(float(job_obj.options['Tools_in_use'][line][1])) == \ - self.dec_format(used_tooldia): - job_obj.options['Tools_in_use'][line][2] = str(nr_drills) - job_obj.options['Tools_in_use'][line][3] = str(nr_slots) # calculate if the current tool is the first one or if it is the last one # for the first tool we add some extra GCode (start Gcode, header etc) # for the last tool we add other GCode (the end code, what is happening at the end of the job) - is_last_tool = True if tool == sel_tools[-1] else False - is_first_tool = True if tool == sel_tools[0] else False + is_last_tool = True if tool_id == sel_tools[-1] else False + is_first_tool = True if tool_id == sel_tools[0] else False # Generate Gcode for the current tool - tool_gcode, last_pt, start_gcode = job_obj.excellon_tool_gcode_gen(tool, tool_points, + tool_gcode, last_pt, start_gcode = job_obj.excellon_tool_gcode_gen(tool_id, tool_points, self.excellon_tools, first_pt=first_drill_point, is_first=is_first_tool, @@ -2199,8 +2132,8 @@ class ToolDrilling(AppTool, Excellon): first_drill_point = last_pt # store the results of GCode generation and parsing - job_obj.exc_cnc_tools[used_tooldia]['gcode'] = tool_gcode - job_obj.exc_cnc_tools[used_tooldia]['gcode_parsed'] = tool_gcode_parsed + job_obj.tools[tool_id]['gcode'] = tool_gcode + job_obj.tools[tool_id]['gcode_parsed'] = tool_gcode_parsed if start_gcode != '': job_obj.gc_start = start_gcode @@ -2215,7 +2148,7 @@ class ToolDrilling(AppTool, Excellon): return 'fail' # create Geometry for plotting - # FIXME is it necessary? didn't we do it previously when filling data in self.exc_cnc_tools dictionary? + # FIXME is it necessary? didn't we do it previously when filling data in self.tools dictionary? job_obj.create_geometry() if used_exc_optim_type == 'M': diff --git a/appPlugins/ToolMilling.py b/appPlugins/ToolMilling.py index d717ab5a..0d218cfd 100644 --- a/appPlugins/ToolMilling.py +++ b/appPlugins/ToolMilling.py @@ -2510,12 +2510,6 @@ class ToolMilling(AppTool, 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"] = self.target_obj.options["tools_mill_multidepth"] @@ -2614,12 +2608,7 @@ class ToolMilling(AppTool, Excellon): app_obj.inform.emit(_("Generating slot milling geometry...")) # ## 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"] = self.target_obj.options["tools_mill_multidepth"] @@ -2913,8 +2902,6 @@ class ToolMilling(AppTool, Excellon): new_cncjob_obj.multigeo = False new_cncjob_obj.cnc_tools.clear() - new_cncjob_obj.options['Tools_in_use'] = tools_in_use - new_cncjob_obj.segx = segx new_cncjob_obj.segy = segy @@ -3021,10 +3008,6 @@ class ToolMilling(AppTool, Excellon): 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 - new_cncjob_obj.toolchange_xy_type = "geometry" - self.app.inform.emit('[success] %s' % _("G-Code parsing in progress...")) dia_cnc_dict['gcode_parsed'] = new_cncjob_obj.gcode_parse() app_obj.inform.emit('[success] %s' % _("G-Code parsing finished...")) @@ -3066,7 +3049,6 @@ class ToolMilling(AppTool, Excellon): new_cncjob_obj.multigeo = True new_cncjob_obj.cnc_tools.clear() - new_cncjob_obj.options['Tools_in_use'] = tools_in_use new_cncjob_obj.segx = segx new_cncjob_obj.segy = segy @@ -3197,7 +3179,6 @@ class ToolMilling(AppTool, Excellon): # tell gcode_parse from which point to start drawing the lines depending on what kind of # object is the source of gcode - new_cncjob_obj.toolchange_xy_type = "geometry" # Update the CNCJob tools dictionary new_cncjob_obj.cnc_tools.update({ diff --git a/appPlugins/ToolReport.py b/appPlugins/ToolReport.py index 0465c22e..b5935d0c 100644 --- a/appPlugins/ToolReport.py +++ b/appPlugins/ToolReport.py @@ -251,8 +251,9 @@ class ObjectReport(AppTool): 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 + # for CNCJob objects created from Excellon + 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) @@ -484,10 +485,11 @@ class ObjectReport(AppTool): 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 = obj.tools[tool_id]['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, diff --git a/appPlugins/ToolSolderPaste.py b/appPlugins/ToolSolderPaste.py index d3a3c5da..2823e51d 100644 --- a/appPlugins/ToolSolderPaste.py +++ b/appPlugins/ToolSolderPaste.py @@ -970,7 +970,6 @@ class SolderPaste(AppTool): # tell gcode_parse from which point to start drawing the lines depending on what kind of # object is the source of gcode - new_obj.toolchange_xy_type = "geometry" new_obj.cnc_tools.update({ tooluid_key: deepcopy(tool_cnc_dict) }) @@ -1029,9 +1028,6 @@ class SolderPaste(AppTool): gcode += '(Name: ' + str(name) + ')\n' gcode += '(Type: ' + "G-code from " + str(obj.options['type']) + " for Solder Paste dispenser" + ')\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' @@ -1102,9 +1098,6 @@ class SolderPaste(AppTool): gcode += '(Name: ' + str(name) + ')\n' gcode += '(Type: ' + "G-code from " + str(obj.options['type']) + " for Solder Paste dispenser" + ')\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' diff --git a/camlib.py b/camlib.py index ad92bd72..b165cef1 100644 --- a/camlib.py +++ b/camlib.py @@ -2723,7 +2723,6 @@ class CNCjob(Geometry): self.toolchange = False self.z_toolchange = toolchangez self.xy_toolchange = toolchange_xy - self.toolchange_xy_type = None self.startz = None self.z_end = endz @@ -3973,21 +3972,7 @@ class CNCjob(Geometry): # ############################################################################################################# # ############################################################################################################# - # build a self.options['Tools_in_use'] list from scratch if we don't have one like in the case of - # running this method from a Tcl Command - # ############################################################################################################# - # ############################################################################################################# - build_tools_in_use_list = False - if 'Tools_in_use' not in self.options: - self.options['Tools_in_use'] = [] - - # if the list is empty (either we just added the key or it was already there but empty) signal to build it - if not self.options['Tools_in_use']: - build_tools_in_use_list = True - - # ############################################################################################################# - # ############################################################################################################# - # fill the data into the self.exc_cnc_tools dictionary + # fill the data into the self.tools dictionary attribute of Excellon object # ############################################################################################################# # ############################################################################################################# for it in all_tools: @@ -4024,20 +4009,13 @@ class CNCjob(Geometry): default_data[k] = deepcopy(v) # it[1] is the tool diameter - self.exc_cnc_tools[it[1]] = {} - self.exc_cnc_tools[it[1]]['tool'] = it[0] - self.exc_cnc_tools[it[1]]['nr_drills'] = drill_no - self.exc_cnc_tools[it[1]]['nr_slots'] = slot_no - self.exc_cnc_tools[it[1]]['offset_z'] = z_off - self.exc_cnc_tools[it[1]]['data'] = default_data - self.exc_cnc_tools[it[1]]['solid_geometry'] = deepcopy(sol_geo) - - # build a self.options['Tools_in_use'] list from scratch if we don't have one like in the case of - # running this method from a Tcl Command - if build_tools_in_use_list is True: - self.options['Tools_in_use'].append( - [it[0], it[1], drill_no, slot_no] - ) + self.tools[to_ol] = {} + self.tools[to_ol]['tooldia'] = it[1] + self.tools[to_ol]['nr_drills'] = drill_no + self.tools[to_ol]['nr_slots'] = slot_no + self.tools[to_ol]['offset_z'] = z_off + self.tools[to_ol]['data'] = default_data + self.tools[to_ol]['solid_geometry'] = deepcopy(sol_geo) self.app.inform.emit(_("Creating a list of points to drill...")) @@ -6414,7 +6392,7 @@ class CNCjob(Geometry): # Current path: temporary storage until tool is # lifted or lowered. - if self.toolchange_xy_type == "excellon": + if self.options['type'].lower() == "excellon": if self.app.defaults["tools_drill_toolchangexy"] == '' or \ self.app.defaults["tools_drill_toolchangexy"] is None: pos_xy = (0, 0) @@ -6483,7 +6461,7 @@ class CNCjob(Geometry): path = [path[-1]] # Start with the last point of last path. # create the geometry for the holes created when drilling Excellon drills - if self.origin_kind == 'excellon': + if self.options['type'].lower() == 'excellon': if current['Z'] < 0: current_drill_point_coords = ( float('%.*f' % (self.decimals, current['X'])), @@ -6570,7 +6548,7 @@ class CNCjob(Geometry): def excellon_tool_gcode_parse(self, dia, gcode, start_pt=(0, 0), force_parsing=None): """ - G-Code parser (from self.exc_cnc_tools['tooldia']['gcode']). Generates dictionary with + G-Code parser (from self.tools['tool_id']['gcode']). For Excellon. Generates dictionary with single-segment LineString's and "kind" indicating cut or travel, fast or feedrate speed. @@ -6581,7 +6559,7 @@ class CNCjob(Geometry): } where kind can be either ["C", "F"] # T=travel, C=cut, F=fast, S=slow - :param dia: the dia is a tool diameter which is the key in self.exc_cnc_tools dict + :param dia: the dia is a tool diameter which is the key in self.tools dict attribute of Excellon :type dia: float :param gcode: Gcode to parse :type gcode: str @@ -6834,7 +6812,7 @@ class CNCjob(Geometry): obj.annotations_dict[tooldia]['text'].append(str(path_num)) # plot the geometry of Excellon objects - if self.origin_kind == 'excellon': + if self.options['type'].lower() == 'excellon': try: # if the geos are travel lines if geo['kind'][0] == 'T': @@ -7647,8 +7625,8 @@ class CNCjob(Geometry): maxx = max(maxx, maxx_) maxy = max(maxy, maxy_) - if self.exc_cnc_tools: - for k, v in self.exc_cnc_tools.items(): + if self.options['type'].lower() == 'excellon': + for k, v in self.tools.items(): minx = np.Inf miny = np.Inf maxx = -np.Inf diff --git a/preprocessors/Berta_CNC.py b/preprocessors/Berta_CNC.py index 21cac758..652e07a2 100644 --- a/preprocessors/Berta_CNC.py +++ b/preprocessors/Berta_CNC.py @@ -48,36 +48,36 @@ class Berta_CNC(PreProc): elif str(p['options']['type']) == 'Excellon' and p['use_ui'] is True: gcode += '\n(TOOLS DIAMETER: )\n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += '(Tool: %s -> ' % str(tool) + 'Dia: %s' % str(val["tooldia"]) + ')\n' gcode += '\n(FEEDRATE Z: )\n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += '(Tool: %s -> ' % str(tool) + 'Feedrate: %s' % \ str(val['data']["tools_drill_feedrate_z"]) + ')\n' gcode += '\n(FEEDRATE RAPIDS: )\n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += '(Tool: %s -> ' % str(tool) + 'Feedrate Rapids: %s' % \ str(val['data']["tools_drill_feedrate_rapid"]) + ')\n' gcode += '\n(Z_CUT: )\n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += '(Tool: %s -> ' % str(tool) + 'Z_Cut: %s' % str(val['data']["tools_drill_cutz"]) + ')\n' gcode += '\n(Tools Offset: )\n' - for tool, val in p['exc_cnc_tools'].items(): - gcode += '(Tool: %s -> ' % str(val['tool']) + 'Offset Z: %s' % \ + for tool, val in p['tools'].items(): + gcode += '(Tool: %s -> ' % str(tool) + 'Offset Z: %s' % \ str(val['data']["tools_drill_offset"]) + ')\n' if p['multidepth'] is True: gcode += '\n(DEPTH_PER_CUT: )\n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += '(Tool: %s -> ' % str(tool) + 'DeptPerCut: %s' % \ str(val['data']["tools_drill_depthperpass"]) + ')\n' gcode += '\n(Z_MOVE: )\n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += '(Tool: %s -> ' % str(tool) + 'Z_Move: %s' % str(val['data']["tools_drill_travelz"]) + ')\n' gcode += '\n' @@ -158,9 +158,7 @@ class Berta_CNC(PreProc): toolC_formatted = '%.*f' % (p.decimals, p.toolC) if str(p['options']['type']) == 'Excellon': - for i in p['options']['Tools_in_use']: - if i[0] == p.tool: - no_drills = i[2] + no_drills = p['tools'][int(p['tool'])]['nr_drills'] if toolchangexy is not None: gcode = """ diff --git a/preprocessors/Check_points.py b/preprocessors/Check_points.py index fe5c6a6b..096fabc8 100644 --- a/preprocessors/Check_points.py +++ b/preprocessors/Check_points.py @@ -41,36 +41,36 @@ class Check_points(PreProc): elif str(p['options']['type']) == 'Excellon' and p['use_ui'] is True: gcode += '\n(TOOLS DIAMETER: )\n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += '(Tool: %s -> ' % str(tool) + 'Dia: %s' % str(val["tooldia"]) + ')\n' gcode += '\n(FEEDRATE Z: )\n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += '(Tool: %s -> ' % str(tool) + 'Feedrate: %s' % \ str(val['data']["tools_drill_feedrate_z"]) + ')\n' gcode += '\n(FEEDRATE RAPIDS: )\n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += '(Tool: %s -> ' % str(tool) + 'Feedrate Rapids: %s' % \ str(val['data']["tools_drill_feedrate_rapid"]) + ')\n' gcode += '\n(Z_CUT: )\n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += '(Tool: %s -> ' % str(tool) + 'Z_Cut: %s' % str(val['data']["tools_drill_cutz"]) + ')\n' gcode += '\n(Tools Offset: )\n' - for tool, val in p['exc_cnc_tools'].items(): - gcode += '(Tool: %s -> ' % str(val['tool']) + 'Offset Z: %s' % \ + for tool, val in p['tools'].items(): + gcode += '(Tool: %s -> ' % str(tool) + 'Offset Z: %s' % \ str(val['data']["tools_drill_offset"]) + ')\n' if p['multidepth'] is True: gcode += '\n(DEPTH_PER_CUT: )\n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += '(Tool: %s -> ' % str(tool) + 'DeptPerCut: %s' % \ str(val['data']["tools_drill_depthperpass"]) + ')\n' gcode += '\n(Z_MOVE: )\n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += '(Tool: %s -> ' % str(tool) + 'Z_Move: %s' % str(val['data']["tools_drill_travelz"]) + ')\n' gcode += '\n' diff --git a/preprocessors/Default_no_M6.py b/preprocessors/Default_no_M6.py index 9f257dbd..7426f9b0 100644 --- a/preprocessors/Default_no_M6.py +++ b/preprocessors/Default_no_M6.py @@ -20,7 +20,7 @@ class Default_no_M6(PreProc): coords_xy = p['xy_toolchange'] end_coords_xy = p['xy_end'] gcode = '(This preprocessor is the default preprocessor used by FlatCAM.)\n' - gcode += '(It is made to work with MACH3 compatible motion controllers.)\n\n' + gcode += '(It is made to work with MACH3 compatible motion controllers and has no M6 coommand)\n\n' xmin = '%.*f' % (p.coords_decimals, p['options']['xmin']) xmax = '%.*f' % (p.coords_decimals, p['options']['xmax']) @@ -40,36 +40,36 @@ class Default_no_M6(PreProc): elif str(p['options']['type']) == 'Excellon' and p['use_ui'] is True: gcode += '\n(TOOLS DIAMETER: )\n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += '(Tool: %s -> ' % str(tool) + 'Dia: %s' % str(val["tooldia"]) + ')\n' gcode += '\n(FEEDRATE Z: )\n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += '(Tool: %s -> ' % str(tool) + 'Feedrate: %s' % \ str(val['data']["tools_drill_feedrate_z"]) + ')\n' gcode += '\n(FEEDRATE RAPIDS: )\n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += '(Tool: %s -> ' % str(tool) + 'Feedrate Rapids: %s' % \ str(val['data']["tools_drill_feedrate_rapid"]) + ')\n' gcode += '\n(Z_CUT: )\n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += '(Tool: %s -> ' % str(tool) + 'Z_Cut: %s' % str(val['data']["tools_drill_cutz"]) + ')\n' gcode += '\n(Tools Offset: )\n' - for tool, val in p['exc_cnc_tools'].items(): - gcode += '(Tool: %s -> ' % str(val['tool']) + 'Offset Z: %s' % \ + for tool, val in p['tools'].items(): + gcode += '(Tool: %s -> ' % str(tool) + 'Offset Z: %s' % \ str(val['data']["tools_drill_offset"]) + ')\n' if p['multidepth'] is True: gcode += '\n(DEPTH_PER_CUT: )\n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += '(Tool: %s -> ' % str(tool) + 'DeptPerCut: %s' % \ str(val['data']["tools_drill_depthperpass"]) + ')\n' gcode += '\n(Z_MOVE: )\n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += '(Tool: %s -> ' % str(tool) + 'Z_Move: %s' % str(val['data']["tools_drill_travelz"]) + ')\n' gcode += '\n' @@ -139,9 +139,7 @@ class Default_no_M6(PreProc): toolC_formatted = '%.*f' % (p.decimals, p.toolC) if str(p['options']['type']) == 'Excellon': - for i in p['options']['Tools_in_use']: - if i[0] == p.tool: - no_drills = i[2] + no_drills = p['tools'][int(p['tool'])]['nr_drills'] if toolchangexy is not None: gcode = """ diff --git a/preprocessors/GRBL_11.py b/preprocessors/GRBL_11.py index 11e652c8..fb0aaaaf 100644 --- a/preprocessors/GRBL_11.py +++ b/preprocessors/GRBL_11.py @@ -40,36 +40,36 @@ class GRBL_11(PreProc): elif str(p['options']['type']) == 'Excellon' and p['use_ui'] is True: gcode += '\n(TOOLS DIAMETER: )\n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += '(Tool: %s -> ' % str(tool) + 'Dia: %s' % str(val["tooldia"]) + ')\n' gcode += '\n(FEEDRATE Z: )\n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += '(Tool: %s -> ' % str(tool) + 'Feedrate: %s' % \ str(val['data']["tools_drill_feedrate_z"]) + ')\n' gcode += '\n(FEEDRATE RAPIDS: )\n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += '(Tool: %s -> ' % str(tool) + 'Feedrate Rapids: %s' % \ str(val['data']["tools_drill_feedrate_rapid"]) + ')\n' gcode += '\n(Z_CUT: )\n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += '(Tool: %s -> ' % str(tool) + 'Z_Cut: %s' % str(val['data']["tools_drill_cutz"]) + ')\n' gcode += '\n(Tools Offset: )\n' for tool, val in p['exc_cnc_tools'].items(): - gcode += '(Tool: %s -> ' % str(val['tool']) + 'Offset Z: %s' % \ + gcode += '(Tool: %s -> ' % str(tool) + 'Offset Z: %s' % \ str(val['data']["tools_drill_offset"]) + ')\n' if p['multidepth'] is True: gcode += '\n(DEPTH_PER_CUT: )\n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += '(Tool: %s -> ' % str(tool) + 'DeptPerCut: %s' % \ str(val['data']["tools_drill_depthperpass"]) + ')\n' gcode += '\n(Z_MOVE: )\n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += '(Tool: %s -> ' % str(tool) + 'Z_Move: %s' % str(val['data']["tools_drill_travelz"]) + ')\n' gcode += '\n' @@ -141,9 +141,7 @@ class GRBL_11(PreProc): toolC_formatted = '%.*f' % (p.decimals, p.toolC) if str(p['options']['type']) == 'Excellon': - for i in p['options']['Tools_in_use']: - if i[0] == p.tool: - no_drills = i[2] + no_drills = p['tools'][int(p['tool'])]['nr_drills'] if toolchangexy is not None: gcode = """ diff --git a/preprocessors/GRBL_11_no_M6.py b/preprocessors/GRBL_11_no_M6.py index f6015a51..c4d8c26b 100644 --- a/preprocessors/GRBL_11_no_M6.py +++ b/preprocessors/GRBL_11_no_M6.py @@ -20,7 +20,7 @@ class GRBL_11_no_M6(PreProc): coords_xy = p['xy_toolchange'] end_coords_xy = p['xy_end'] gcode = '(This preprocessor is used with a motion controller loaded with GRBL firmware.)\n' - gcode += '(It is configured to be compatible with almost any version of GRBL firmware.)\n\n' + gcode += '(It is configured to be compatible with almost any version of GRBL firmware. No M6 command.)\n\n' xmin = '%.*f' % (p.coords_decimals, p['options']['xmin']) xmax = '%.*f' % (p.coords_decimals, p['options']['xmax']) @@ -40,36 +40,36 @@ class GRBL_11_no_M6(PreProc): elif str(p['options']['type']) == 'Excellon' and p['use_ui'] is True: gcode += '\n(TOOLS DIAMETER: )\n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += '(Tool: %s -> ' % str(tool) + 'Dia: %s' % str(val["tooldia"]) + ')\n' gcode += '\n(FEEDRATE Z: )\n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += '(Tool: %s -> ' % str(tool) + 'Feedrate: %s' % \ str(val['data']["tools_drill_feedrate_z"]) + ')\n' gcode += '\n(FEEDRATE RAPIDS: )\n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += '(Tool: %s -> ' % str(tool) + 'Feedrate Rapids: %s' % \ str(val['data']["tools_drill_feedrate_rapid"]) + ')\n' gcode += '\n(Z_CUT: )\n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += '(Tool: %s -> ' % str(tool) + 'Z_Cut: %s' % str(val['data']["tools_drill_cutz"]) + ')\n' gcode += '\n(Tools Offset: )\n' for tool, val in p['exc_cnc_tools'].items(): - gcode += '(Tool: %s -> ' % str(val['tool']) + 'Offset Z: %s' % \ + gcode += '(Tool: %s -> ' % str(tool) + 'Offset Z: %s' % \ str(val['data']["tools_drill_offset"]) + ')\n' if p['multidepth'] is True: gcode += '\n(DEPTH_PER_CUT: )\n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += '(Tool: %s -> ' % str(tool) + 'DeptPerCut: %s' % \ str(val['data']["tools_drill_depthperpass"]) + ')\n' gcode += '\n(Z_MOVE: )\n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += '(Tool: %s -> ' % str(tool) + 'Z_Move: %s' % str(val['data']["tools_drill_travelz"]) + ')\n' gcode += '\n' @@ -141,9 +141,7 @@ class GRBL_11_no_M6(PreProc): toolC_formatted = '%.*f' % (p.decimals, p.toolC) if str(p['options']['type']) == 'Excellon': - for i in p['options']['Tools_in_use']: - if i[0] == p.tool: - no_drills = i[2] + no_drills = p['tools'][int(p['tool'])]['nr_drills'] if toolchangexy is not None: gcode = """ diff --git a/preprocessors/ISEL_CNC.py b/preprocessors/ISEL_CNC.py index 9825c6c2..13278134 100644 --- a/preprocessors/ISEL_CNC.py +++ b/preprocessors/ISEL_CNC.py @@ -38,36 +38,36 @@ class ISEL_CNC(PreProc): elif str(p['options']['type']) == 'Excellon' and p['use_ui'] is True: gcode += '\n(TOOLS DIAMETER: )\n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += '(Tool: %s -> ' % str(tool) + 'Dia: %s' % str(val["tooldia"]) + ')\n' gcode += '\n(FEEDRATE Z: )\n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += '(Tool: %s -> ' % str(tool) + 'Feedrate: %s' % \ str(val['data']["tools_drill_feedrate_z"]) + ')\n' gcode += '\n(FEEDRATE RAPIDS: )\n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += '(Tool: %s -> ' % str(tool) + 'Feedrate Rapids: %s' % \ str(val['data']["tools_drill_feedrate_rapid"]) + ')\n' gcode += '\n(Z_CUT: )\n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += '(Tool: %s -> ' % str(tool) + 'Z_Cut: %s' % str(val['data']["tools_drill_cutz"]) + ')\n' gcode += '\n(Tools Offset: )\n' for tool, val in p['exc_cnc_tools'].items(): - gcode += '(Tool: %s -> ' % str(val['tool']) + 'Offset Z: %s' % \ + gcode += '(Tool: %s -> ' % str(tool) + 'Offset Z: %s' % \ str(val['data']["tools_drill_offset"]) + ')\n' if p['multidepth'] is True: gcode += '\n(DEPTH_PER_CUT: )\n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += '(Tool: %s -> ' % str(tool) + 'DeptPerCut: %s' % \ str(val['data']["tools_drill_depthperpass"]) + ')\n' gcode += '\n(Z_MOVE: )\n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += '(Tool: %s -> ' % str(tool) + 'Z_Move: %s' % str(val['data']["tools_drill_travelz"]) + ')\n' gcode += '\n' @@ -125,9 +125,7 @@ class ISEL_CNC(PreProc): toolC_formatted = '%.*f' % (p.decimals, p.toolC) if str(p['options']['type']) == 'Excellon': - for i in p['options']['Tools_in_use']: - if i[0] == p.tool: - no_drills = i[2] + no_drills = p['tools'][int(p['tool'])]['nr_drills'] gcode = """ M05 diff --git a/preprocessors/ISEL_ICP_CNC.py b/preprocessors/ISEL_ICP_CNC.py index 3f08807f..86e83473 100644 --- a/preprocessors/ISEL_ICP_CNC.py +++ b/preprocessors/ISEL_ICP_CNC.py @@ -38,36 +38,36 @@ class ISEL_ICP_CNC(PreProc): elif str(p['options']['type']) == 'Excellon' and p['use_ui'] is True: gcode += '\n;TOOLS DIAMETER: \n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += ';Tool: %s -> ' % str(tool) + 'Dia: %s' % str(val["tooldia"]) + '\n' gcode += '\n;FEEDRATE Z: \n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += ';Tool: %s -> ' % str(tool) + 'Feedrate: %s' % \ str(val['data']["tools_drill_feedrate_z"]) + '\n' gcode += '\n;FEEDRATE RAPIDS: \n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += ';Tool: %s -> ' % str(tool) + 'Feedrate Rapids: %s' % \ str(val['data']["tools_drill_feedrate_rapid"]) + '\n' gcode += '\n;Z_CUT: \n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += ';Tool: %s -> ' % str(tool) + 'Z_Cut: %s' % str(val['data']["tools_drill_cutz"]) + '\n' gcode += '\n;Tools Offset: \n' for tool, val in p['exc_cnc_tools'].items(): - gcode += ';Tool: %s -> ' % str(val['tool']) + 'Offset Z: %s' % \ + gcode += ';Tool: %s -> ' % str(tool) + 'Offset Z: %s' % \ str(val['data']["tools_drill_offset"]) + '\n' if p['multidepth'] is True: gcode += '\n;DEPTH_PER_CUT: \n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += ';Tool: %s -> ' % str(tool) + 'DeptPerCut: %s' % \ str(val['data']["tools_drill_depthperpass"]) + '\n' gcode += '\n;Z_MOVE: \n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += ';Tool: %s -> ' % str(tool) + 'Z_Move: %s' % str(val['data']["tools_drill_travelz"]) + '\n' gcode += '\n' diff --git a/preprocessors/Line_xyz.py b/preprocessors/Line_xyz.py index 9148903f..563a4d8d 100644 --- a/preprocessors/Line_xyz.py +++ b/preprocessors/Line_xyz.py @@ -19,7 +19,7 @@ class Line_xyz(PreProc): units = ' ' + str(p['units']).lower() coords_xy = p['xy_toolchange'] end_coords_xy = p['end_xy'] - gcode = '' + gcode = '(This preprocessor has all the coordinates on the same line: X, Y, Z.)\n\n' xmin = '%.*f' % (p.coords_decimals, p['options']['xmin']) xmax = '%.*f' % (p.coords_decimals, p['options']['xmax']) @@ -39,36 +39,36 @@ class Line_xyz(PreProc): elif str(p['options']['type']) == 'Excellon' and p['use_ui'] is True: gcode += '\n(TOOLS DIAMETER: )\n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += '(Tool: %s -> ' % str(tool) + 'Dia: %s' % str(val["tooldia"]) + ')\n' gcode += '\n(FEEDRATE Z: )\n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += '(Tool: %s -> ' % str(tool) + 'Feedrate: %s' % \ str(val['data']["tools_drill_feedrate_z"]) + ')\n' gcode += '\n(FEEDRATE RAPIDS: )\n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += '(Tool: %s -> ' % str(tool) + 'Feedrate Rapids: %s' % \ str(val['data']["tools_drill_feedrate_rapid"]) + ')\n' gcode += '\n(Z_CUT: )\n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += '(Tool: %s -> ' % str(tool) + 'Z_Cut: %s' % str(val['data']["tools_drill_cutz"]) + ')\n' gcode += '\n(Tools Offset: )\n' for tool, val in p['exc_cnc_tools'].items(): - gcode += '(Tool: %s -> ' % str(val['tool']) + 'Offset Z: %s' % \ + gcode += '(Tool: %s -> ' % str(tool) + 'Offset Z: %s' % \ str(val['data']["tools_drill_offset"]) + ')\n' if p['multidepth'] is True: gcode += '\n(DEPTH_PER_CUT: )\n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += '(Tool: %s -> ' % str(tool) + 'DeptPerCut: %s' % \ str(val['data']["tools_drill_depthperpass"]) + ')\n' gcode += '\n(Z_MOVE: )\n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += '(Tool: %s -> ' % str(tool) + 'Z_Move: %s' % str(val['data']["tools_drill_travelz"]) + ')\n' gcode += '\n' @@ -152,9 +152,8 @@ class Line_xyz(PreProc): toolC_formatted = '%.*f' % (p.decimals, p.toolC) if str(p['options']['type']) == 'Excellon': - for i in p['options']['Tools_in_use']: - if i[0] == p.tool: - no_drills = i[2] + no_drills = p['tools'][int(p['tool'])]['nr_drills'] + gcode = """ M5 G00 X{x_toolchange} Y{x_toolchange} Z{z_toolchange} diff --git a/preprocessors/Marlin.py b/preprocessors/Marlin.py index 55468a41..c10868b4 100644 --- a/preprocessors/Marlin.py +++ b/preprocessors/Marlin.py @@ -20,7 +20,7 @@ class Marlin(PreProc): units = ' ' + str(p['units']).lower() coords_xy = p['xy_toolchange'] end_coords_xy = p['xy_end'] - gcode = '' + gcode = ';This preprocessor works with controllers with Marlin firmware.' xmin = '%.*f' % (p.coords_decimals, p['options']['xmin']) xmax = '%.*f' % (p.coords_decimals, p['options']['xmax']) @@ -40,36 +40,36 @@ class Marlin(PreProc): elif str(p['options']['type']) == 'Excellon' and p['use_ui'] is True: gcode += '\n;TOOLS DIAMETER: \n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += ';Tool: %s -> ' % str(tool) + 'Dia: %s' % str(val["tooldia"]) + '\n' gcode += '\n;FEEDRATE Z: \n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += ';Tool: %s -> ' % str(tool) + 'Feedrate: %s' % \ str(val['data']["tools_drill_feedrate_z"]) + '\n' gcode += '\n;FEEDRATE RAPIDS: \n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += ';Tool: %s -> ' % str(tool) + 'Feedrate Rapids: %s' % \ str(val['data']["tools_drill_feedrate_rapid"]) + '\n' gcode += '\n;Z_CUT: \n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += ';Tool: %s -> ' % str(tool) + 'Z_Cut: %s' % str(val['data']["tools_drill_cutz"]) + '\n' gcode += '\n;Tools Offset: \n' for tool, val in p['exc_cnc_tools'].items(): - gcode += ';Tool: %s -> ' % str(val['tool']) + 'Offset Z: %s' % \ + gcode += ';Tool: %s -> ' % str(tool) + 'Offset Z: %s' % \ str(val['data']["tools_drill_offset"]) + '\n' if p['multidepth'] is True: gcode += '\n;DEPTH_PER_CUT: \n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += ';Tool: %s -> ' % str(tool) + 'DeptPerCut: %s' % \ str(val['data']["tools_drill_depthperpass"]) + '\n' gcode += '\n;Z_MOVE: \n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += ';Tool: %s -> ' % str(tool) + 'Z_Move: %s' % str(val['data']["tools_drill_travelz"]) + '\n' gcode += '\n' @@ -139,9 +139,7 @@ class Marlin(PreProc): toolC_formatted = '%.*f' % (p.decimals, p.toolC) if str(p['options']['type']) == 'Excellon': - for i in p['options']['Tools_in_use']: - if i[0] == p.tool: - no_drills = i[2] + no_drills = p['tools'][int(p['tool'])]['nr_drills'] if toolchangexy is not None: gcode = """ diff --git a/preprocessors/Paste_1.py b/preprocessors/Paste_1.py index 9cff6016..b4f8805e 100644 --- a/preprocessors/Paste_1.py +++ b/preprocessors/Paste_1.py @@ -19,7 +19,7 @@ class Paste_1(AppPreProcTools): units = ' ' + str(p['units']).lower() coords_xy = [float(eval(a)) for a in p['xy_toolchange'].split(",") if a != ''] - gcode = '' + gcode = '(This preprocessor is to be used only with the SolderPaste Plugin.)\n\n' xmin = '%.*f' % (p.coords_decimals, p['options']['xmin']) xmax = '%.*f' % (p.coords_decimals, p['options']['xmax']) diff --git a/preprocessors/Repetier.py b/preprocessors/Repetier.py index a1df5efc..0680f0a8 100644 --- a/preprocessors/Repetier.py +++ b/preprocessors/Repetier.py @@ -40,36 +40,36 @@ class Repetier(PreProc): elif str(p['options']['type']) == 'Excellon' and p['use_ui'] is True: gcode += '\n;TOOLS DIAMETER: \n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += ';Tool: %s -> ' % str(tool) + 'Dia: %s' % str(val["tooldia"]) + '\n' gcode += '\n;FEEDRATE Z: \n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += ';Tool: %s -> ' % str(tool) + 'Feedrate: %s' % \ str(val['data']["tools_drill_feedrate_z"]) + '\n' gcode += '\n;FEEDRATE RAPIDS: \n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += ';Tool: %s -> ' % str(tool) + 'Feedrate Rapids: %s' % \ str(val['data']["tools_drill_feedrate_rapid"]) + '\n' gcode += '\n;Z_CUT: \n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += ';Tool: %s -> ' % str(tool) + 'Z_Cut: %s' % str(val['data']["tools_drill_cutz"]) + '\n' gcode += '\n;Tools Offset: \n' for tool, val in p['exc_cnc_tools'].items(): - gcode += ';Tool: %s -> ' % str(val['tool']) + 'Offset Z: %s' % \ + gcode += ';Tool: %s -> ' % str(tool) + 'Offset Z: %s' % \ str(val['data']["tools_drill_offset"]) + '\n' if p['multidepth'] is True: gcode += '\n;DEPTH_PER_CUT: \n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += ';Tool: %s -> ' % str(tool) + 'DeptPerCut: %s' % \ str(val['data']["tools_drill_depthperpass"]) + '\n' gcode += '\n;Z_MOVE: \n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += ';Tool: %s -> ' % str(tool) + 'Z_Move: %s' % str(val['data']["tools_drill_travelz"]) + '\n' gcode += '\n' @@ -139,9 +139,7 @@ class Repetier(PreProc): toolC_formatted = '%.*f' % (p.decimals, p.toolC) if str(p['options']['type']) == 'Excellon': - for i in p['options']['Tools_in_use']: - if i[0] == p.tool: - no_drills = i[2] + no_drills = p['tools'][int(p['tool'])]['nr_drills'] if toolchangexy is not None: gcode = """ diff --git a/preprocessors/Toolchange_Manual.py b/preprocessors/Toolchange_Manual.py index 13038433..13d08da7 100644 --- a/preprocessors/Toolchange_Manual.py +++ b/preprocessors/Toolchange_Manual.py @@ -19,7 +19,8 @@ class Toolchange_Manual(PreProc): units = ' ' + str(p['units']).lower() coords_xy = p['xy_toolchange'] end_coords_xy = p['xy_end'] - gcode = '' + gcode = '(This preprocessor has a special sequence when doing a toolchange.)\n' + gcode += '(Compatible with MACH3,)\n\n' xmin = '%.*f' % (p.coords_decimals, p['options']['xmin']) xmax = '%.*f' % (p.coords_decimals, p['options']['xmax']) @@ -39,36 +40,36 @@ class Toolchange_Manual(PreProc): elif str(p['options']['type']) == 'Excellon' and p['use_ui'] is True: gcode += '\n(TOOLS DIAMETER: )\n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += '(Tool: %s -> ' % str(tool) + 'Dia: %s' % str(val["tooldia"]) + ')\n' gcode += '\n(FEEDRATE Z: )\n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += '(Tool: %s -> ' % str(tool) + 'Feedrate: %s' % \ str(val['data']["tools_drill_feedrate_z"]) + ')\n' gcode += '\n(FEEDRATE RAPIDS: )\n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += '(Tool: %s -> ' % str(tool) + 'Feedrate Rapids: %s' % \ str(val['data']["tools_drill_feedrate_rapid"]) + ')\n' gcode += '\n(Z_CUT: )\n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += '(Tool: %s -> ' % str(tool) + 'Z_Cut: %s' % str(val['data']["tools_drill_cutz"]) + ')\n' gcode += '\n(Tools Offset: )\n' for tool, val in p['exc_cnc_tools'].items(): - gcode += '(Tool: %s -> ' % str(val['tool']) + 'Offset Z: %s' % \ + gcode += '(Tool: %s -> ' % str(tool) + 'Offset Z: %s' % \ str(val['data']["tools_drill_offset"]) + ')\n' if p['multidepth'] is True: gcode += '\n(DEPTH_PER_CUT: )\n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += '(Tool: %s -> ' % str(tool) + 'DeptPerCut: %s' % \ str(val['data']["tools_drill_depthperpass"]) + ')\n' gcode += '\n(Z_MOVE: )\n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += '(Tool: %s -> ' % str(tool) + 'Z_Move: %s' % str(val['data']["tools_drill_travelz"]) + ')\n' gcode += '\n' @@ -139,9 +140,7 @@ class Toolchange_Manual(PreProc): toolC_formatted = '%.*f' % (p.decimals, p.toolC) if str(p['options']['type']) == 'Excellon': - for i in p['options']['Tools_in_use']: - if i[0] == p.tool: - no_drills = i[2] + no_drills = p['tools'][int(p['tool'])]['nr_drills'] if toolchangexy is not None: gcode = """ diff --git a/preprocessors/Toolchange_Probe_MACH3.py b/preprocessors/Toolchange_Probe_MACH3.py index d23d5264..f392a1d5 100644 --- a/preprocessors/Toolchange_Probe_MACH3.py +++ b/preprocessors/Toolchange_Probe_MACH3.py @@ -39,36 +39,36 @@ class Toolchange_Probe_MACH3(PreProc): elif str(p['options']['type']) == 'Excellon' and p['use_ui'] is True: gcode += '\n(TOOLS DIAMETER: )\n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += '(Tool: %s -> ' % str(tool) + 'Dia: %s' % str(val["tooldia"]) + ')\n' gcode += '\n(FEEDRATE Z: )\n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += '(Tool: %s -> ' % str(tool) + 'Feedrate: %s' % \ str(val['data']["tools_drill_feedrate_z"]) + ')\n' gcode += '\n(FEEDRATE RAPIDS: )\n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += '(Tool: %s -> ' % str(tool) + 'Feedrate Rapids: %s' % \ str(val['data']["tools_drill_feedrate_rapid"]) + ')\n' gcode += '\n(Z_CUT: )\n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += '(Tool: %s -> ' % str(tool) + 'Z_Cut: %s' % str(val['data']["tools_drill_cutz"]) + ')\n' gcode += '\n(Tools Offset: )\n' for tool, val in p['exc_cnc_tools'].items(): - gcode += '(Tool: %s -> ' % str(val['tool']) + 'Offset Z: %s' % \ + gcode += '(Tool: %s -> ' % str(tool) + 'Offset Z: %s' % \ str(val['data']["tools_drill_offset"]) + ')\n' if p['multidepth'] is True: gcode += '\n(DEPTH_PER_CUT: )\n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += '(Tool: %s -> ' % str(tool) + 'DeptPerCut: %s' % \ str(val['data']["tools_drill_depthperpass"]) + ')\n' gcode += '\n(Z_MOVE: )\n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += '(Tool: %s -> ' % str(tool) + 'Z_Move: %s' % str(val['data']["tools_drill_travelz"]) + ')\n' gcode += '\n' @@ -139,9 +139,7 @@ class Toolchange_Probe_MACH3(PreProc): toolC_formatted = '%.*f' % (p.decimals, p.toolC) if str(p['options']['type']) == 'Excellon': - for i in p['options']['Tools_in_use']: - if i[0] == p.tool: - no_drills = i[2] + no_drills = p['tools'][int(p['tool'])]['nr_drills'] if toolchangexy is not None: gcode = """ diff --git a/preprocessors/default.py b/preprocessors/default.py index 20059967..43f95c13 100644 --- a/preprocessors/default.py +++ b/preprocessors/default.py @@ -40,36 +40,36 @@ class default(PreProc): elif str(p['options']['type']) == 'Excellon' and p['use_ui'] is True: gcode += '\n(TOOLS DIAMETER: )\n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += '(Tool: %s -> ' % str(tool) + 'Dia: %s' % str(val["tooldia"]) + ')\n' gcode += '\n(FEEDRATE Z: )\n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += '(Tool: %s -> ' % str(tool) + 'Feedrate: %s' % \ str(val['data']["tools_drill_feedrate_z"]) + ')\n' gcode += '\n(FEEDRATE RAPIDS: )\n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += '(Tool: %s -> ' % str(tool) + 'Feedrate Rapids: %s' % \ str(val['data']["tools_drill_feedrate_rapid"]) + ')\n' gcode += '\n(Z_CUT: )\n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += '(Tool: %s -> ' % str(tool) + 'Z_Cut: %s' % str(val['data']["tools_drill_cutz"]) + ')\n' gcode += '\n(Tools Offset: )\n' - for tool, val in p['exc_cnc_tools'].items(): - gcode += '(Tool: %s -> ' % str(val['tool']) + 'Offset Z: %s' % \ + for tool, val in p['tools'].items(): + gcode += '(Tool: %s -> ' % str(tool) + 'Offset Z: %s' % \ str(val['data']["tools_drill_offset"]) + ')\n' if p['multidepth'] is True: gcode += '\n(DEPTH_PER_CUT: )\n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += '(Tool: %s -> ' % str(tool) + 'DeptPerCut: %s' % \ str(val['data']["tools_drill_depthperpass"]) + ')\n' gcode += '\n(Z_MOVE: )\n' - for tool, val in p['exc_tools'].items(): + for tool, val in p['tools'].items(): gcode += '(Tool: %s -> ' % str(tool) + 'Z_Move: %s' % str(val['data']["tools_drill_travelz"]) + ')\n' gcode += '\n' @@ -139,9 +139,7 @@ class default(PreProc): toolC_formatted = '%.*f' % (p.decimals, p.toolC) if str(p['options']['type']) == 'Excellon': - for i in p['options']['Tools_in_use']: - if i[0] == p.tool: - no_drills = i[2] + no_drills = p['tools'][int(p['tool'])]['nr_drills'] if toolchangexy is not None: gcode = """ diff --git a/preprocessors/grbl_laser_eleks_drd.py b/preprocessors/grbl_laser_eleks_drd.py index f6b5371e..068737bd 100644 --- a/preprocessors/grbl_laser_eleks_drd.py +++ b/preprocessors/grbl_laser_eleks_drd.py @@ -22,7 +22,9 @@ class grbl_laser_eleks_drd(PreProc): def start_code(self, p): units = ' ' + str(p['units']).lower() - gcode = '' + gcode = '(This preprocessor is made to work with Laser cutters.)\n' + gcode += '(It allows movement on the Z axis.)\n\n' + xmin = '%.*f' % (p.coords_decimals, p['options']['xmin']) xmax = '%.*f' % (p.coords_decimals, p['options']['xmax']) ymin = '%.*f' % (p.coords_decimals, p['options']['ymin']) diff --git a/tclCommands/TclCommandDrillcncjob.py b/tclCommands/TclCommandDrillcncjob.py index 40cb29c6..558077b2 100644 --- a/tclCommands/TclCommandDrillcncjob.py +++ b/tclCommands/TclCommandDrillcncjob.py @@ -263,9 +263,6 @@ class TclCommandDrillcncjob(TclCommandSignaled): # ########################################################################################## # ################# Set parameters ######################################################### # ########################################################################################## - job_obj.origin_kind = 'excellon' - - job_obj.options['Tools_in_use'] = used_tools_info job_obj.options['type'] = 'Excellon' pp_excellon_name = args["pp"] if "pp" in args and args["pp"] else self.app.defaults["tools_drill_ppname_e"] @@ -306,7 +303,6 @@ class TclCommandDrillcncjob(TclCommandSignaled): job_obj.dwell = self.app.defaults["tools_drill_dwell"] job_obj.dwelltime = self.app.defaults["tools_drill_dwelltime"] - job_obj.toolchange_xy_type = "excellon" job_obj.coords_decimals = int(self.app.defaults["cncjob_coords_decimals"]) job_obj.fr_decimals = int(self.app.defaults["cncjob_fr_decimals"]) @@ -340,10 +336,11 @@ class TclCommandDrillcncjob(TclCommandSignaled): return 'fail' job_obj.gc_start = ret_val[1] - for t_item in job_obj.exc_cnc_tools: - job_obj.exc_cnc_tools[t_item]['data']['tools_drill_offset'] = \ - float(job_obj.exc_cnc_tools[t_item]['offset_z']) + float(drillz) - job_obj.exc_cnc_tools[t_item]['data']['tools_drill_ppname_e'] = job_obj.options['ppname_e'] + # from Excellon attribute self.tools + for t_item in job_obj.tools: + job_obj.tools[t_item]['data']['tools_drill_offset'] = \ + float(job_obj.tools[t_item]['offset_z']) + float(drillz) + job_obj.tools[t_item]['data']['tools_drill_ppname_e'] = job_obj.options['ppname_e'] job_obj.gcode_parse() job_obj.create_geometry()