From 0986ef143cd434d680af83d12c79b38236dd0a14 Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Thu, 4 Mar 2021 17:45:47 +0200 Subject: [PATCH] - aperture keys in the gerber 'tools' dictionary are now stored as integers instead of strings as before; need to check the application especially the Gerber Editor - fixed issues in Gerber Editor (using the '0' insteadd of 'REG' type for apertures) --- CHANGELOG.md | 18 +++-- appEditors/AppGerberEditor.py | 87 +++++++++++----------- appObjects/FlatCAMExcellon.py | 24 +++--- appObjects/FlatCAMGerber.py | 18 +++-- appParsers/ParseGerber.py | 123 ++++++++++++++++--------------- appParsers/ParsePDF.py | 42 +++++------ appPlugins/ToolCopperThieving.py | 30 ++++---- appPlugins/ToolCorners.py | 2 +- appPlugins/ToolExtract.py | 2 +- appPlugins/ToolFiducials.py | 6 +- appPlugins/ToolInvertGerber.py | 8 +- appPlugins/ToolOptimal.py | 4 +- appPlugins/ToolPDF.py | 8 +- appPlugins/ToolPanelize.py | 4 +- appPlugins/ToolQRCode.py | 12 +-- appPlugins/ToolSub.py | 20 ++--- app_Main.py | 10 +-- preprocessors/Roland_MDX_20.py | 2 +- tclCommands/TclCommandNew.py | 2 +- 19 files changed, 217 insertions(+), 205 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fc434af5..31104284 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ CHANGELOG for FlatCAM beta 3.03.2021 - fixed errors on project load, in ParseGerber and Extract and Punch Gerber Plugins due of refactoring the 'apertures' attribute to 'tools' +- aperture keys in the gerber 'tools' dictionary are now stored as integers instead of strings as before; need to check the application especially the Gerber Editor +- fixed issues in Gerber Editor (using the '0' insteadd of 'REG' type for apertures) 2.03.2021 @@ -4005,7 +4007,7 @@ RELEASE 8.993 23.05.2019 -- fixed bug in Gerber editor FCDisk and DiscSemiEditorGrb that the resulting geometry was not stored into the '0' aperture where all the solids are stored +- fixed bug in Gerber editor FCDisk and DiscSemiEditorGrb that the resulting geometry was not stored into the 0 aperture where all the solids are stored - fixed minor issue in Gerber Editor where apertures were included in the saved object even if there was no geometric data for that aperture - some PEP8 cleanup in FlatCAMApp.py @@ -4171,7 +4173,7 @@ RELEASE 8.993 29.04.2019 -- solved bug in Gerber Editor: the '0' aperture (the region aperture) had no size which created errors. Made the size to be zero. +- solved bug in Gerber Editor: the 0 aperture (the region aperture) had no size which created errors. Made the size to be zero. - solved bug in editors: the canvas selection shape was not deleted on mouse release if the grid snap was OFF - solved bug in Excellon Editor: when selecting a drill hole on canvas the selected row in the Tools Table was not the correct one but the next highest row - finished the Silkscreen Tool but there are some limitations (some wires fragments from silkscreen are lost) @@ -4184,7 +4186,7 @@ RELEASE 8.993 - fixed some bugs recently introduced in Editors due of the changes done to the way mouse panning is detected - cleaned up the context menu's when in Editors; made some structural changes - updated the code in camlib.CNCJob.generate_from_excellon_by_tools() to work with the new API from Google OR-Tools -- all Gerber regions (G36 G37) are stored in the '0' aperture +- all Gerber regions (G36 G37) are stored in the 0 aperture - fixed a bug that added geometry with clear polarity in the apertures where was not supposed to be 25.04.2019 @@ -4241,8 +4243,8 @@ RELEASE 8.993 18.04.2019 - Gerber Editor: added custom mouse cursors for each mode in Add Track Tool -- Gerber Editor: Poligonize Tool will first fuse polygons that touch each other and at a second try will create a polygon. The polygon will be automatically moved to Aperture '0' (regions). -- Gerber Editor: Region Tool will add regions only in '0' aperture +- Gerber Editor: Poligonize Tool will first fuse polygons that touch each other and at a second try will create a polygon. The polygon will be automatically moved to Aperture 0 (regions). +- Gerber Editor: Region Tool will add regions only in 0 aperture - Gerber Editor: the bending mode will now survive until the tool is exited - Gerber Editor: solved some bugs related with deleting an aperture and updating the last_selected_aperture @@ -4272,7 +4274,7 @@ RELEASE 8.993 - Excellon Editor: update so always there is a tool selected even after the Excellon object was just edited; before it always required a click inside of the tool table, not you do it only if needed. - fixed the menu File -> Edit -> Edit/Close Editor entry to reflect the status of the app (Editor active or not) - added support in Excellon parser for autodetection of Excellon file format for the Excellon files generated by the following ECAD sw: DipTrace, Eagle, Altium, Sprint Layout -- Gerber Editor: finished a new tool: Poligonize Tool (Alt+N in Editor). It will fuse a selection of tracks into a polygon. It will fill a selection of polygons if they are apart and it will make a single polygon if the selection is overlapped. All the newly created filled polygons will be stored in aperture '0' (if it does not exist it will be automatically created) +- Gerber Editor: finished a new tool: Poligonize Tool (Alt+N in Editor). It will fuse a selection of tracks into a polygon. It will fill a selection of polygons if they are apart and it will make a single polygon if the selection is overlapped. All the newly created filled polygons will be stored in aperture 0 (if it does not exist it will be automatically created) - fixed a bug in Move command in context menu who crashed the app when triggered - Gerber Editor: when adding a new aperture it will be store as the last selected and it will be used for any tools that are triggered until a new aperture is selected. @@ -4308,7 +4310,7 @@ RELEASE 8.993 - Gerber Editor: added shortcut for Transform Tool and also toggle effect here, too - updated the shortcut list with the Gerber Editor shortcut keys - Gerber Editor: fixed error when adding an aperture with code value lower than the ones that already exists -- when adding an aperture with code '0' (zero) it will automatically be set with size zero and type: 'REG' (from region); here we store all the regions from a Gerber file, the ones without a declared aperture +- when adding an aperture with code 0 (zero) it will automatically be set with size zero and type: 'REG' (from region); here we store all the regions from a Gerber file, the ones without a declared aperture - Gerber Editor: added support for Gerber polarity change commands (LPD, LPC) - moved the polarity change processing from AppGerberEditor() class to camlib.Gerber().parse_lines() - made optional the saving of an edited object. Now the user can cancel the changes to the object. @@ -4591,7 +4593,7 @@ RELEASE 8.993 26.02.2019 - added a function to read the parameters from ToolChange macro Text Box (I need to move it from CNCJob to Excellon and Geometry) -- fixed the geometry adding to the self.apertures in the case when regions are done without declaring any aperture first (Allegro does that). Now, that geometry will be stored in the '0' aperture with type REG +- fixed the geometry adding to the self.apertures in the case when regions are done without declaring any aperture first (Allegro does that). Now, that geometry will be stored in the 0 aperture with type REG - work in progress to Toolchange_Custom code replacement -> finished the parse and replace function - fixed mouse selection on canvas, mouse drag, mouse click and mouse double click - fixed Gerber Aperture Table dimensions diff --git a/appEditors/AppGerberEditor.py b/appEditors/AppGerberEditor.py index 29909c3d..cb9226d7 100644 --- a/appEditors/AppGerberEditor.py +++ b/appEditors/AppGerberEditor.py @@ -311,7 +311,7 @@ class PadEditorGrb(ShapeToolEditorGrb): new_geo_el['solid'] = Polygon([p1, p2, p3, p4, p1]) new_geo_el['follow'] = center return new_geo_el - elif ap_type == 'O': + elif ap_type == 'REG': geo = [] new_geo_el = {} @@ -666,7 +666,7 @@ class PadArrayEditorGrb(ShapeToolEditorGrb): new_geo_el['solid'] = Polygon([p1, p2, p3, p4, p1]) new_geo_el['follow'] = Point([point_x, point_y]) return new_geo_el - elif ap_type == 'O': + elif ap_type == 'REG': geo = [] new_geo_el = {} @@ -912,10 +912,10 @@ class PoligonizeEditorGrb(ShapeToolEditorGrb): if len(geo.interiors) == 0: try: - current_storage = self.draw_app.storage_dict['0']['geometry'] + current_storage = self.draw_app.storage_dict[0]['geometry'] except KeyError: - self.draw_app.on_aperture_add(apcode='0') - current_storage = self.draw_app.storage_dict['0']['geometry'] + self.draw_app.on_aperture_add(apcode=0) + current_storage = self.draw_app.storage_dict[0]['geometry'] new_el = {'solid': geo, 'follow': geo.exterior} self.draw_app.on_grb_shape_complete(current_storage, specific_shape=DrawToolShape(deepcopy(new_el))) else: @@ -924,10 +924,10 @@ class PoligonizeEditorGrb(ShapeToolEditorGrb): if len(fused_geo.interiors) == 0 and len(exterior_geo) == 1: try: - current_storage = self.draw_app.storage_dict['0']['geometry'] + current_storage = self.draw_app.storage_dict[0]['geometry'] except KeyError: - self.draw_app.on_aperture_add(apcode='0') - current_storage = self.draw_app.storage_dict['0']['geometry'] + self.draw_app.on_aperture_add(apcode=0) + current_storage = self.draw_app.storage_dict[0]['geometry'] new_el = {'solid': fused_geo, 'follow': fused_geo.exterior} self.draw_app.on_grb_shape_complete(current_storage, specific_shape=DrawToolShape(deepcopy(new_el))) @@ -1232,11 +1232,11 @@ class RegionEditorGrb(ShapeToolEditorGrb): # self.geometry = LinearRing(self.points) if len(self.points) > 2: - # regions are added always in the '0' aperture - if '0' not in self.draw_app.storage_dict: - self.draw_app.on_aperture_add(apcode='0') + # regions are added always in the 0 aperture + if 0 not in self.draw_app.storage_dict: + self.draw_app.on_aperture_add(apcode=0) else: - self.draw_app.last_aperture_selected = '0' + self.draw_app.last_aperture_selected = 0 new_geo_el = { 'solid': Polygon(self.points).buffer(self.buf_val, int(self.steps_per_circle / 4), join_style=2), @@ -1653,15 +1653,15 @@ class DiscEditorGrb(ShapeToolEditorGrb): self.buf_val = (size_ap / 2) if size_ap > 0 else 0.0000001 - if '0' in self.draw_app.storage_dict: - self.storage_obj = self.draw_app.storage_dict['0']['geometry'] + if 0 in self.draw_app.storage_dict: + self.storage_obj = self.draw_app.storage_dict[0]['geometry'] else: - self.draw_app.storage_dict['0'] = { + self.draw_app.storage_dict[0] = { 'type': 'C', 'size': 0.0, 'geometry': [] } - self.storage_obj = self.draw_app.storage_dict['0']['geometry'] + self.storage_obj = self.draw_app.storage_dict[0]['geometry'] self.draw_app.app.inform.emit(_("Click on Center point ...")) @@ -1777,15 +1777,15 @@ class DiscSemiEditorGrb(ShapeToolEditorGrb): self.buf_val = (size_ap / 2) if size_ap > 0 else 0.0000001 - if '0' in self.draw_app.storage_dict: - self.storage_obj = self.draw_app.storage_dict['0']['geometry'] + if 0 in self.draw_app.storage_dict: + self.storage_obj = self.draw_app.storage_dict[0]['geometry'] else: - self.draw_app.storage_dict['0'] = { + self.draw_app.storage_dict[0] = { 'type': 'C', 'size': 0.0, 'geometry': [] } - self.storage_obj = self.draw_app.storage_dict['0']['geometry'] + self.storage_obj = self.draw_app.storage_dict[0]['geometry'] self.steps_per_circ = self.draw_app.app.defaults["gerber_circle_steps"] self.draw_app.app.jump_signal.connect(lambda x: self.draw_app.update_utility_geometry(data=x)) @@ -3150,7 +3150,7 @@ class ImportEditorGrb(QtCore.QObject, DrawTool): break if added_flag is False: - st_dict['0'] = { + st_dict[0] = { 'type': 'REG', 'size': 0.0, 'geometry': ap_dict['geometry'] @@ -3165,7 +3165,7 @@ class ImportEditorGrb(QtCore.QObject, DrawTool): break if added_flag is False: - st_dict[str(new_apid)] = { + st_dict[new_apid] = { 'type': ap_dict['type'], 'size': ap_dict['size'], 'geometry': ap_dict['geometry'] @@ -3182,7 +3182,7 @@ class ImportEditorGrb(QtCore.QObject, DrawTool): break if added_flag is False: - st_dict[str(new_apid)] = { + st_dict[new_apid] = { 'type': ap_dict['type'], 'size': ap_dict['size'], 'width': ap_dict['width'], @@ -3191,12 +3191,12 @@ class ImportEditorGrb(QtCore.QObject, DrawTool): } new_apid += 1 else: - st_dict[str(new_apid)] = {} + st_dict[new_apid] = {} for k in ap_dict: if k in ['geometry', 'shape_id']: continue - st_dict[str(new_apid)][k] = ap_dict[k] - st_dict[str(new_apid)]['geometry'] = ap_dict['geometry'] + st_dict[new_apid][k] = ap_dict[k] + st_dict[new_apid]['geometry'] = ap_dict['geometry'] new_apid += 1 self.draw_app.plot_object.emit(None) @@ -3596,7 +3596,7 @@ class AppGerberEditor(QtCore.QObject): self.ui.apertures_table.setRowCount(n) for ap_code in sorted_apertures: - ap_code = str(ap_code) + ap_code = ap_code ap_code_item = QtWidgets.QTableWidgetItem('%d' % int(self.apertures_row + 1)) ap_code_item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) @@ -3608,7 +3608,7 @@ class AppGerberEditor(QtCore.QObject): ap_type_item = QtWidgets.QTableWidgetItem(str(self.storage_dict[ap_code]['type'])) ap_type_item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) - if str(self.storage_dict[ap_code]['type']) == 'R' or str(self.storage_dict[ap_code]['type']) == 'O': + if str(self.storage_dict[ap_code]['type']) == 'R' or str(self.storage_dict[ap_code]['type']) == '0': ap_dim_item = QtWidgets.QTableWidgetItem( '%.*f, %.*f' % (self.decimals, self.storage_dict[ap_code]['width'], self.decimals, self.storage_dict[ap_code]['height'] @@ -3650,7 +3650,7 @@ class AppGerberEditor(QtCore.QObject): self.last_aperture_selected = ap_code # for ap_code in sorted_macros: - # ap_code = str(ap_code) + # ap_code = ap_code # # ap_code_item = QtWidgets.QTableWidgetItem('%d' % int(self.apertures_row + 1)) # ap_code_item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) @@ -3720,7 +3720,7 @@ class AppGerberEditor(QtCore.QObject): ap_code = apcode else: try: - ap_code = str(self.ui.apcode_entry.get_value()) + ap_code = int(self.ui.apcode_entry.get_value()) except ValueError: self.app.inform.emit('[WARNING_NOTCL] %s' % _("Aperture code value is missing or wrong format. Add it and retry.")) @@ -3730,7 +3730,7 @@ class AppGerberEditor(QtCore.QObject): _("Aperture code value is missing or wrong format. Add it and retry.")) return - if ap_code == '0': + if ap_code == 0: if ap_code not in self.tid2apcode: self.storage_dict[ap_code] = { 'type': 'REG', @@ -3745,7 +3745,7 @@ class AppGerberEditor(QtCore.QObject): else: if ap_code not in self.oldapcode_newapcode: type_val = self.ui.aptype_cb.currentText() - if type_val == 'R' or type_val == 'O': + if type_val == 'R' or type_val == 'REG': try: dims = self.ui.apdim_entry.get_value() size_val = np.sqrt((dims[0] ** 2) + (dims[1] ** 2)) @@ -3761,8 +3761,9 @@ class AppGerberEditor(QtCore.QObject): self.ui.apsize_entry.set_value(size_val) except Exception as e: - self.app.log.error("AppGerberEditor.on_aperture_add() --> the R or O aperture dims has to be in a " - "tuple format (x,y)\nError: %s" % str(e)) + self.app.log.error("AppGerberEditor.on_aperture_add() --> " + "the R or O aperture dims has to be in a " + "tuple format (x,y)\nError: %s" % str(e)) self.app.inform.emit('[WARNING_NOTCL] %s' % _("Aperture dimensions value is missing or wrong format. " "Add it in format (width, height) and retry.")) @@ -3861,8 +3862,8 @@ class AppGerberEditor(QtCore.QObject): # if there is no aperture left, then add a default one :) if self.last_aperture_selected in deleted_apcode_list: if self.ui.apertures_table.rowCount() == 0: - self.on_aperture_add('10') - self.last_aperture_selected = '10' + self.on_aperture_add(10) + self.last_aperture_selected = 10 else: self.last_aperture_selected = self.ui.apertures_table.item(0, 1).text() @@ -3882,7 +3883,7 @@ class AppGerberEditor(QtCore.QObject): # rows start with 0, tools start with 1 so we adjust the value by 1 key_in_tid2apcode = row_of_item_changed + 1 - ap_code_old = str(self.tid2apcode[key_in_tid2apcode]) + ap_code_old = self.tid2apcode[key_in_tid2apcode] ap_code_new = self.ui.apertures_table.item(row_of_item_changed, 1).text() @@ -4000,7 +4001,8 @@ class AppGerberEditor(QtCore.QObject): # It will happen only for the Aperture Type in ['R', 'O'] - I make sure of that in the self.build_ui() # and below elif col_of_item_changed == 4: - if str(self.storage_dict[ap_code_old]['type']) == 'R' or str(self.storage_dict[ap_code_old]['type']) == 'O': + if str(self.storage_dict[ap_code_old]['type']) == 'R' or \ + str(self.storage_dict[ap_code_old]['type']) == 'REG': # use the biggest from them buff_val_lines = max(val_edited) new_width = val_edited[0] @@ -4606,7 +4608,7 @@ class AppGerberEditor(QtCore.QObject): # # now that we have data (empty data actually), create the GUI interface and add it to the Tool Tab # self.build_ui(first_run=True) # # and add the first aperture to have something to play with - # self.on_aperture_add('10') + # self.on_aperture_add(10) # self.app.worker_task.emit({'fcn': worker_job, 'params': [self]}) @@ -4684,10 +4686,9 @@ class AppGerberEditor(QtCore.QObject): pass else: for clear_geo in global_clear_geo: - # Make sure that the clear_geo is within the solid_geo otherwise we loose - # Make sure that the clear_geo is within the solid_geo otherwise we loose - # the solid_geometry. We want for clear_geometry just to cut into - # solid_geometry not to delete it + # Make sure that the clear_geo is within the solid_geo otherwise + # we loose the solid_geometry. We want for clear_geometry just to + # cut into solid_geometry not to delete it if clear_geo.within(solid_geo): solid_geo = solid_geo.difference(clear_geo) diff --git a/appObjects/FlatCAMExcellon.py b/appObjects/FlatCAMExcellon.py index 3d393948..15ce86fd 100644 --- a/appObjects/FlatCAMExcellon.py +++ b/appObjects/FlatCAMExcellon.py @@ -752,8 +752,8 @@ class ExcellonObject(FlatCAMObj, Excellon): exc_y_formatted = exc_y_formatted.partition('.') # left padd the 'whole' part with zeros - x_whole = exc_x_formatted[0].rjust(whole, '0') - y_whole = exc_y_formatted[0].rjust(whole, '0') + x_whole = exc_x_formatted[0].rjust(whole, 0) + y_whole = exc_y_formatted[0].rjust(whole, 0) # restore the coordinate padded in the left with 0 and added the decimal part # without the decinal dot @@ -770,8 +770,8 @@ class ExcellonObject(FlatCAMObj, Excellon): exc_y_formatted = "{:.{dec}f}".format(drill_y, dec=fract).replace('.', '') # pad with rear zeros - exc_x_formatted.ljust(length, '0') - exc_y_formatted.ljust(length, '0') + exc_x_formatted.ljust(length, 0) + exc_y_formatted.ljust(length, 0) excellon_code += "X{xform}Y{yform}\n".format(xform=exc_x_formatted, yform=exc_y_formatted) @@ -825,10 +825,10 @@ class ExcellonObject(FlatCAMObj, Excellon): stop_slot_y_formatted = stop_slot_y_formatted.partition('.') # left padd the 'whole' part with zeros - start_x_whole = start_slot_x_formatted[0].rjust(whole, '0') - start_y_whole = start_slot_y_formatted[0].rjust(whole, '0') - stop_x_whole = stop_slot_x_formatted[0].rjust(whole, '0') - stop_y_whole = stop_slot_y_formatted[0].rjust(whole, '0') + start_x_whole = start_slot_x_formatted[0].rjust(whole, 0) + start_y_whole = start_slot_y_formatted[0].rjust(whole, 0) + stop_x_whole = stop_slot_x_formatted[0].rjust(whole, 0) + stop_y_whole = stop_slot_y_formatted[0].rjust(whole, 0) # restore the coordinate padded in the left with 0 and added the decimal part # without the decinal dot @@ -860,10 +860,10 @@ class ExcellonObject(FlatCAMObj, Excellon): stop_slot_y_formatted = "{:.{dec}f}".format(stop_slot_y, dec=fract).replace('.', '') # pad with rear zeros - start_slot_x_formatted.ljust(length, '0') - start_slot_y_formatted.ljust(length, '0') - stop_slot_x_formatted.ljust(length, '0') - stop_slot_y_formatted.ljust(length, '0') + start_slot_x_formatted.ljust(length, 0) + start_slot_y_formatted.ljust(length, 0) + stop_slot_x_formatted.ljust(length, 0) + stop_slot_y_formatted.ljust(length, 0) if slot_type == 'routing': excellon_code += "G00X{xstart}Y{ystart}\nM15\n".format(xstart=start_slot_x_formatted, diff --git a/appObjects/FlatCAMGerber.py b/appObjects/FlatCAMGerber.py index 6eff08e1..4136d691 100644 --- a/appObjects/FlatCAMGerber.py +++ b/appObjects/FlatCAMGerber.py @@ -1269,9 +1269,9 @@ class GerberObject(FlatCAMObj, Gerber): # apertures processing try: length = whole + fract - if '0' in self.tools: - if 'geometry' in self.tools['0']: - for geo_elem in self.tools['0']['geometry']: + if 0 in self.tools: + if 'geometry' in self.tools[0]: + for geo_elem in self.tools[0]['geometry']: if 'solid' in geo_elem: geo = geo_elem['solid'] if not geo.is_empty and not isinstance(geo, LineString) and \ @@ -1381,7 +1381,8 @@ class GerberObject(FlatCAMObj, Gerber): # gerber_code += "D02*\n" except Exception as e: self.app.log.error( - "FlatCAMObj.GerberObject.export_gerber() 'follow' --> %s" % str(e)) + "FlatCAMObj.GerberObject.export_gerber() 'follow' for 0 aperture --> %s" % + str(e)) if 'clear' in geo_elem: geo = geo_elem['clear'] if not geo.is_empty: @@ -1415,10 +1416,10 @@ class GerberObject(FlatCAMObj, Gerber): gerber_code += 'G37*\n' gerber_code += '%LPD*%\n' except Exception as e: - self.app.log.error("FlatCAMObj.GerberObject.export_gerber() '0' aperture --> %s" % str(e)) + self.app.log.error("FlatCAMObj.GerberObject.export_gerber() 0 aperture --> %s" % str(e)) for apid in self.tools: - if apid == '0': + if apid == 0: continue elif self.tools[apid]['type'] == 'AM': if 'geometry' in self.tools[apid]: @@ -1534,7 +1535,7 @@ class GerberObject(FlatCAMObj, Gerber): # gerber_code += "D02*\n" except Exception as e: self.app.log.error( - "FlatCAMObj.GerberObject.export_gerber() 'follow' --> %s" % str(e)) + "FlatCAMObj.GerberObject.export_gerber() 'follow' for AM --> %s" % str(e)) if 'clear' in geo_elem: geo = geo_elem['clear'] if not geo.is_empty: @@ -1613,7 +1614,8 @@ class GerberObject(FlatCAMObj, Gerber): # gerber_code += "D02*\n" except Exception as e: - self.app.log.error("FlatCAMObj.GerberObject.export_gerber() 'follow' --> %s" % str(e)) + self.app.log.error( + "FlatCAMObj.GerberObject.export_gerber() 'follow' normal aperture--> %s" % str(e)) try: if 'clear' in geo_elem: diff --git a/appParsers/ParseGerber.py b/appParsers/ParseGerber.py index e10440dc..97ccd0ae 100644 --- a/appParsers/ParseGerber.py +++ b/appParsers/ParseGerber.py @@ -30,7 +30,7 @@ class Gerber(Geometry): **ATTRIBUTES** - * ``apertures`` (dict): The keys are names/identifiers of each aperture. + * ``tools`` (dict): The keys are names/identifiers of each aperture. The values are dictionaries key/value pairs which describe the aperture. The type key is always present and the rest depend on the key: @@ -102,7 +102,7 @@ class Gerber(Geometry): # ## Gerber elements # ## ''' - apertures = { + tools = { 'id':{ 'type':string, 'size':float, @@ -111,7 +111,7 @@ class Gerber(Geometry): 'geometry': [], } } - apertures['geometry'] list elements are dicts + tools['geometry'] list elements are dicts dict = { 'solid': [], 'follow': [], @@ -257,7 +257,7 @@ class Gerber(Geometry): # Found some Gerber with a leading zero in the aperture id and the # referenced it without the zero, so this is a hack to handle that. - apid = str(int(apertureId)) + apid = int(apertureId) try: # Could be empty for aperture macros paramList = apParameters.split('X') @@ -265,38 +265,45 @@ class Gerber(Geometry): paramList = None if apertureType == "C": # Circle, example: %ADD11C,0.1*% - self.tools[apid] = {"type": "C", - "size": float(paramList[0])} + self.tools[apid] = { + "type": "C", + "size": float(paramList[0]) + } return apid if apertureType == "R": # Rectangle, example: %ADD15R,0.05X0.12*% - self.tools[apid] = {"type": "R", - "width": float(paramList[0]), - "height": float(paramList[1]), - "size": np.sqrt(float(paramList[0]) ** 2 + float(paramList[1]) ** 2)} # Hack + self.tools[apid] = { + "type": "R", + "width": float(paramList[0]), + "height": float(paramList[1]), + "size": np.sqrt(float(paramList[0]) ** 2 + float(paramList[1]) ** 2)} # Hack return apid if apertureType == "O": # Obround - self.tools[apid] = {"type": "O", - "width": float(paramList[0]), - "height": float(paramList[1]), - "size": np.sqrt(float(paramList[0]) ** 2 + float(paramList[1]) ** 2)} # Hack + self.tools[apid] = { + "type": "O", + "width": float(paramList[0]), + "height": float(paramList[1]), + "size": np.sqrt(float(paramList[0]) ** 2 + float(paramList[1]) ** 2)} # Hack return apid if apertureType == "P": # Polygon (regular) - self.tools[apid] = {"type": "P", - "diam": float(paramList[0]), - "nVertices": int(paramList[1]), - "size": float(paramList[0])} # Hack + self.tools[apid] = { + "type": "P", + "diam": float(paramList[0]), + "nVertices": int(paramList[1]), + "size": float(paramList[0])} # Hack if len(paramList) >= 3: self.tools[apid]["rotation"] = float(paramList[2]) return apid if apertureType in self.aperture_macros: - self.tools[apid] = {"type": "AM", - # "size": 0.0, - "macro": self.aperture_macros[apertureType], - "modifiers": paramList} + self.tools[apid] = { + "type": "AM", + # "size": 0.0, + "macro": self.aperture_macros[apertureType], + "modifiers": paramList + } return apid self.app.log.warning("Aperture not implemented: %s" % str(apertureType)) @@ -705,6 +712,7 @@ class Gerber(Geometry): if current_aperture not in self.tools: self.tools[current_aperture] = {} + if 'geometry' not in self.tools[current_aperture]: self.tools[current_aperture]['geometry'] = [] self.tools[current_aperture]['geometry'].append(deepcopy(geo_dict)) @@ -720,7 +728,7 @@ class Gerber(Geometry): # ################################################################ match = self.tool_re.search(gline) if match: - current_aperture = match.group(1) + current_aperture = int(match.group(1)) # self.app.log.debug("Line %d: Aperture change to (%s)" % (line_num, current_aperture)) @@ -847,11 +855,11 @@ class Gerber(Geometry): if self.regionoff_re.search(gline): making_region = False - if '0' not in self.tools: - self.tools['0'] = {} - self.tools['0']['type'] = 'REG' - self.tools['0']['size'] = 0.0 - self.tools['0']['geometry'] = [] + if 0 not in self.tools: + self.tools[0] = {} + self.tools[0]['type'] = 'REG' + self.tools[0]['size'] = 0.0 + self.tools[0]['geometry'] = [] # if D02 happened before G37 we now have a path with 1 element only; we have to add the current # geo to the poly_buffer otherwise we loose it @@ -882,7 +890,7 @@ class Gerber(Geometry): geo_dict['solid'] = geo_s if geo_s or geo_f: - self.tools['0']['geometry'].append(deepcopy(geo_dict)) + self.tools[0]['geometry'].append(deepcopy(geo_dict)) path = [[current_x, current_y]] # Start new path @@ -942,7 +950,7 @@ class Gerber(Geometry): geo_dict['solid'] = pol if not pol.is_empty: - self.tools['0']['geometry'].append(deepcopy(geo_dict)) + self.tools[0]['geometry'].append(deepcopy(geo_dict)) except TypeError: # is it possible that simplification creates an Empty Geometry ????? if self.app.defaults['gerber_simplification']: @@ -961,7 +969,7 @@ class Gerber(Geometry): geo_dict['solid'] = region_s if not region_s.is_empty: - self.tools['0']['geometry'].append(deepcopy(geo_dict)) + self.tools[0]['geometry'].append(deepcopy(geo_dict)) else: # is it possible that simplification creates an Empty Geometry ????? if self.app.defaults['gerber_simplification']: @@ -980,7 +988,7 @@ class Gerber(Geometry): geo_dict['solid'] = region_s if not region_s.is_empty: - self.tools['0']['geometry'].append(deepcopy(geo_dict)) + self.tools[0]['geometry'].append(deepcopy(geo_dict)) path = [[current_x, current_y]] # Start new path continue @@ -1119,12 +1127,12 @@ class Gerber(Geometry): last_path_aperture = current_aperture # we do this for the case that a region is done without having defined any aperture if last_path_aperture is None: - if '0' not in self.tools: - self.tools['0'] = {} - self.tools['0']['type'] = 'REG' - self.tools['0']['size'] = 0.0 - self.tools['0']['geometry'] = [] - last_path_aperture = '0' + if 0 not in self.tools: + self.tools[0] = {} + self.tools[0]['type'] = 'REG' + self.tools[0]['size'] = 0.0 + self.tools[0]['geometry'] = [] + last_path_aperture = 0 else: self.app.inform.emit('[WARNING] %s: %s' % (_("Coordinates missing, line ignored"), str(gline))) @@ -1146,12 +1154,12 @@ class Gerber(Geometry): if making_region: # we do this for the case that a region is done without having defined any aperture if last_path_aperture is None: - if '0' not in self.tools: - self.tools['0'] = {} - self.tools['0']['type'] = 'REG' - self.tools['0']['size'] = 0.0 - self.tools['0']['geometry'] = [] - last_path_aperture = '0' + if 0 not in self.tools: + self.tools[0] = {} + self.tools[0]['type'] = 'REG' + self.tools[0]['size'] = 0.0 + self.tools[0]['geometry'] = [] + last_path_aperture = 0 geo_f = Polygon() else: geo_f = LineString(path) @@ -1171,12 +1179,12 @@ class Gerber(Geometry): if making_region: # we do this for the case that a region is done without having defined any aperture if last_path_aperture is None: - if '0' not in self.tools: - self.tools['0'] = {} - self.tools['0']['type'] = 'REG' - self.tools['0']['size'] = 0.0 - self.tools['0']['geometry'] = [] - last_path_aperture = '0' + if 0 not in self.tools: + self.tools[0] = {} + self.tools[0]['type'] = 'REG' + self.tools[0]['size'] = 0.0 + self.tools[0]['geometry'] = [] + last_path_aperture = 0 try: geo_s = Polygon(path) @@ -1694,8 +1702,7 @@ class Gerber(Geometry): self.app.log.error("Gerber PARSING FAILED. Line %d: %s" % (line_num, gline)) loc = '%s #%d %s: %s\n' % (_("Gerber Line"), line_num, _("Gerber Line Content"), gline) + repr(err) - self.app.inform.emit('[ERROR] %s\n%s:' % - (_("Gerber Parser ERROR"), loc)) + self.app.inform.emit('[ERROR] %s\n%s:' % (_("Gerber Parser ERROR"), loc)) @staticmethod def create_flash_geometry(location, aperture, steps_per_circle=None): @@ -1960,8 +1967,8 @@ class Gerber(Geometry): except TypeError: self.solid_geometry = [self.solid_geometry] - if '0' not in self.tools: - self.tools['0'] = { + if 0 not in self.tools: + self.tools[0] = { 'type': 'REG', 'size': 0.0, 'geometry': [] @@ -1969,7 +1976,7 @@ class Gerber(Geometry): for pol in self.solid_geometry: new_el = {'solid': pol, 'follow': pol.exterior} - self.tools['0']['geometry'].append(new_el) + self.tools[0]['geometry'].append(new_el) def import_dxf_as_gerber(self, filename, units='MM'): """ @@ -2009,8 +2016,8 @@ class Gerber(Geometry): return "fail" # create the self.tools data structure - if '0' not in self.tools: - self.tools['0'] = { + if 0 not in self.tools: + self.tools[0] = { 'type': 'REG', 'size': 0.0, 'geometry': [] @@ -2018,7 +2025,7 @@ class Gerber(Geometry): for pol in flat_geo: new_el = {'solid': pol, 'follow': pol} - self.tools['0']['geometry'].append(deepcopy(new_el)) + self.tools[0]['geometry'].append(deepcopy(new_el)) def scale(self, xfactor, yfactor=None, point=None): """ diff --git a/appParsers/ParsePDF.py b/appParsers/ParsePDF.py index bb6f72c4..ad96b190 100644 --- a/appParsers/ParsePDF.py +++ b/appParsers/ParsePDF.py @@ -141,9 +141,9 @@ class PdfParser: # store the apertures with clear geometry here # we are interested only in the circular geometry (drill holes) therefore we target only Bezier subpaths - # everything will be stored in the '0' aperture since we are dealing with clear polygons not strokes + # everything will be stored in the 0 aperture since we are dealing with clear polygons not strokes clear_apertures_dict = { - '0': { + 0: { 'size': 0.0, 'type': 'C', 'geometry': [] @@ -683,17 +683,17 @@ class PdfParser: try: for g in path_geo: new_el = {'clear': g} - clear_apertures_dict['0']['geometry'].append(new_el) + clear_apertures_dict[0]['geometry'].append(new_el) except TypeError: new_el = {'clear': path_geo} - clear_apertures_dict['0']['geometry'].append(new_el) + clear_apertures_dict[0]['geometry'].append(new_el) # now that we finished searching for drill holes (this is not very precise because holes in the # polygon pours may appear as drill too, but .. hey you can't have it all ...) we add # clear_geometry - if '0' not in apertures_dict: + if 0 not in apertures_dict: # in case there is no stroke width yet therefore no aperture - apertures_dict['0'] = { + apertures_dict[0] = { 'size': applied_size, 'type': 'C', 'geometry': [] @@ -702,10 +702,10 @@ class PdfParser: if isinstance(pdf_geo, MultiPolygon): for poly in pdf_geo: new_el = {'clear': poly} - apertures_dict['0']['geometry'].append(deepcopy(new_el)) + apertures_dict[0]['geometry'].append(deepcopy(new_el)) else: new_el = {'clear': pdf_geo} - apertures_dict['0']['geometry'].append(deepcopy(new_el)) + apertures_dict[0]['geometry'].append(deepcopy(new_el)) continue else: # else, store the Geometry as usual @@ -713,9 +713,9 @@ class PdfParser: # ################################################################################################# # ############################### store the found geometry ######################################## # ################################################################################################# - if '0' not in apertures_dict: + if 0 not in apertures_dict: # in case there is no stroke width yet therefore no aperture - apertures_dict['0'] = { + apertures_dict[0] = { 'size': applied_size, 'type': 'C', 'geometry': [] @@ -724,10 +724,10 @@ class PdfParser: if isinstance(pdf_geo, MultiPolygon): for poly in pdf_geo: new_el = {'solid': poly, 'follow': poly.exterior} - apertures_dict['0']['geometry'].append(deepcopy(new_el)) + apertures_dict[0]['geometry'].append(deepcopy(new_el)) else: new_el = {'solid': pdf_geo, 'follow': pdf_geo.exterior} - apertures_dict['0']['geometry'].append(deepcopy(new_el)) + apertures_dict[0]['geometry'].append(deepcopy(new_el)) continue # Fill and Stroke the path @@ -919,9 +919,9 @@ class PdfParser: # in case that a color change to white (transparent) occurred if flag_clear_geo is True: - if '0' not in apertures_dict: + if 0 not in apertures_dict: # in case there is no stroke width yet therefore no aperture - apertures_dict['0'] = { + apertures_dict[0] = { 'size': round(applied_size, 5), 'type': 'C', 'geometry': [] @@ -930,15 +930,15 @@ class PdfParser: if isinstance(pdf_geo, MultiPolygon): for poly in pdf_geo: new_el = {'clear': poly} - apertures_dict['0']['geometry'].append(deepcopy(new_el)) + apertures_dict[0]['geometry'].append(deepcopy(new_el)) else: new_el = {'clear': pdf_geo} - apertures_dict['0']['geometry'].append(deepcopy(new_el)) + apertures_dict[0]['geometry'].append(deepcopy(new_el)) else: # in case there is no stroke width yet therefore no aperture - if '0' not in apertures_dict: - apertures_dict['0'] = { + if 0 not in apertures_dict: + apertures_dict[0] = { 'size': round(applied_size, 5), 'type': 'C', 'geometry': [] @@ -948,10 +948,10 @@ class PdfParser: if isinstance(pdf_geo, MultiPolygon): for poly in pdf_geo: new_el = {'solid': poly, 'follow': poly.exterior} - apertures_dict['0']['geometry'].append(deepcopy(new_el)) + apertures_dict[0]['geometry'].append(deepcopy(new_el)) else: new_el = {'solid': pdf_geo, 'follow': pdf_geo.exterior} - apertures_dict['0']['geometry'].append(deepcopy(new_el)) + apertures_dict[0]['geometry'].append(deepcopy(new_el)) continue @@ -959,7 +959,7 @@ class PdfParser: if apertures_dict: object_dict[layer_nr] = deepcopy(apertures_dict) - if clear_apertures_dict['0']['geometry']: + if clear_apertures_dict[0]['geometry']: object_dict[0] = deepcopy(clear_apertures_dict) # delete keys (layers) with empty values diff --git a/appPlugins/ToolCopperThieving.py b/appPlugins/ToolCopperThieving.py index 670cb0af..eeb41c4e 100644 --- a/appPlugins/ToolCopperThieving.py +++ b/appPlugins/ToolCopperThieving.py @@ -275,7 +275,7 @@ class ToolCopperThieving(AppTool): if ap_keys: new_apid = str(int(max(ap_keys)) + 1) else: - new_apid = '10' + new_apid = 10 new_apertures[new_apid] = { 'type': 'C', @@ -872,29 +872,29 @@ class ToolCopperThieving(AppTool): # create a new dictionary to hold the source object apertures allowing us to tamper with without altering # the original source object's apertures new_apertures = deepcopy(tool_obj.grb_object.tools) - if '0' not in new_apertures: - new_apertures['0'] = { + if 0 not in new_apertures: + new_apertures[0] = { 'type': 'REG', 'size': 0.0, 'geometry': [] } - # add the thieving geometry in the '0' aperture of the new_apertures dict + # add the thieving geometry in the 0 aperture of the new_apertures dict try: for poly in tool_obj.thief_solid_geometry: # append to the new solid geometry geo_list.append(poly) - # append into the '0' aperture + # append into the 0 aperture geo_elem = {'solid': poly, 'follow': poly.exterior} - new_apertures['0']['geometry'].append(deepcopy(geo_elem)) + new_apertures[0]['geometry'].append(deepcopy(geo_elem)) except TypeError: # append to the new solid geometry geo_list.append(tool_obj.thief_solid_geometry) - # append into the '0' aperture + # append into the 0 aperture geo_elem = {'solid': tool_obj.new_solid_geometry, 'follow': tool_obj.new_solid_geometry.exterior} - new_apertures['0']['geometry'].append(deepcopy(geo_elem)) + new_apertures[0]['geometry'].append(deepcopy(geo_elem)) # prepare also the solid_geometry for the new object having the thieving geometry new_solid_geo = MultiPolygon(geo_list).buffer(0.0000001).buffer(-0.0000001) @@ -1029,8 +1029,8 @@ class ToolCopperThieving(AppTool): for geo in thieving_solid_geo: plated_area += geo.area - if '0' not in new_apertures: - new_apertures['0'] = { + if 0 not in new_apertures: + new_apertures[0] = { 'type': 'REG', 'size': 0.0, 'geometry': [] @@ -1043,23 +1043,23 @@ class ToolCopperThieving(AppTool): # append to the new solid geometry geo_list.append(poly_b) - # append into the '0' aperture + # append into the 0 aperture geo_elem = { 'solid': poly_b, 'follow': poly_b.exterior } - new_apertures['0']['geometry'].append(deepcopy(geo_elem)) + new_apertures[0]['geometry'].append(deepcopy(geo_elem)) except TypeError: # append to the new solid geometry assert isinstance(thieving_solid_geo, Polygon) geo_list.append(thieving_solid_geo.buffer(ppm_clearance)) - # append into the '0' aperture + # append into the 0 aperture geo_elem = { 'solid': thieving_solid_geo.buffer(ppm_clearance), 'follow': thieving_solid_geo.buffer(ppm_clearance).exterior } - new_apertures['0']['geometry'].append(deepcopy(geo_elem)) + new_apertures[0]['geometry'].append(deepcopy(geo_elem)) # if we have robber bar geometry, add it if robber_solid_geo and geo_choice in ['b', 'r']: @@ -1084,7 +1084,7 @@ class ToolCopperThieving(AppTool): if ap_keys and max_apid != 0: new_apid = str(max_apid + 1) else: - new_apid = '10' + new_apid = 10 new_apertures[new_apid] = { 'type': 'C', diff --git a/appPlugins/ToolCorners.py b/appPlugins/ToolCorners.py index e680fd12..1c251b07 100644 --- a/appPlugins/ToolCorners.py +++ b/appPlugins/ToolCorners.py @@ -349,7 +349,7 @@ class ToolCorners(AppTool): if ap_keys: new_apid = str(int(max(ap_keys)) + 1) else: - new_apid = '10' + new_apid = 10 new_apertures[new_apid] = {} new_apertures[new_apid]['type'] = 'C' diff --git a/appPlugins/ToolExtract.py b/appPlugins/ToolExtract.py index d995b4ec..30f944ec 100644 --- a/appPlugins/ToolExtract.py +++ b/appPlugins/ToolExtract.py @@ -763,7 +763,7 @@ class ToolExtract(AppTool): return new_apertures = { - '10': { + 10: { 'type': 'C', 'size': thickness, 'geometry': [ diff --git a/appPlugins/ToolFiducials.py b/appPlugins/ToolFiducials.py index dd3be75c..f9eb9f3c 100644 --- a/appPlugins/ToolFiducials.py +++ b/appPlugins/ToolFiducials.py @@ -357,7 +357,7 @@ class ToolFiducials(AppTool): if ap_keys: new_apid = str(int(max(ap_keys)) + 1) else: - new_apid = '10' + new_apid = 10 new_apertures[new_apid] = { 'type': 'C', @@ -415,7 +415,7 @@ class ToolFiducials(AppTool): if ap_keys: new_apid = str(int(max(ap_keys)) + 1) else: - new_apid = '10' + new_apid = 10 new_apertures[new_apid] = { 'type': 'C', @@ -489,7 +489,7 @@ class ToolFiducials(AppTool): if ap_keys: new_apid = str(int(max(ap_keys)) + 1) else: - new_apid = '10' + new_apid = 10 new_apertures[new_apid] = { 'type': 'R', diff --git a/appPlugins/ToolInvertGerber.py b/appPlugins/ToolInvertGerber.py index e26fc650..26be49e5 100644 --- a/appPlugins/ToolInvertGerber.py +++ b/appPlugins/ToolInvertGerber.py @@ -148,8 +148,8 @@ class ToolInvertGerber(AppTool): new_apertures = {} - if '0' not in new_apertures: - new_apertures['0'] = { + if 0 not in new_apertures: + new_apertures[0] = { 'type': 'C', 'size': 0.0, 'geometry': [] @@ -158,10 +158,10 @@ class ToolInvertGerber(AppTool): try: for poly in new_solid_geometry: new_el = {'solid': poly, 'follow': poly.exterior} - new_apertures['0']['geometry'].append(new_el) + new_apertures[0]['geometry'].append(new_el) except TypeError: new_el = {'solid': new_solid_geometry, 'follow': new_solid_geometry.exterior} - new_apertures['0']['geometry'].append(new_el) + new_apertures[0]['geometry'].append(new_el) def init_func(new_obj, app_obj): new_obj.options.update(new_options) diff --git a/appPlugins/ToolOptimal.py b/appPlugins/ToolOptimal.py index 73af6669..f7d6cc24 100644 --- a/appPlugins/ToolOptimal.py +++ b/appPlugins/ToolOptimal.py @@ -122,7 +122,7 @@ class ToolOptimal(AppTool): def set_tool_ui(self): self.ui.result_entry.set_value(0.0) - self.ui.freq_entry.set_value('0') + self.ui.freq_entry.set_value(0) self.ui.precision_spinner.set_value(int(self.app.defaults["tools_opt_precision"])) self.ui.locations_textb.clear() @@ -139,7 +139,7 @@ class ToolOptimal(AppTool): self.ui.locate_button.setVisible(False) self.ui.result_entry.set_value(0.0) - self.ui.freq_entry.set_value('0') + self.ui.freq_entry.set_value(0) self.reset_fields() def find_minimum_distance(self): diff --git a/appPlugins/ToolPDF.py b/appPlugins/ToolPDF.py index 9dbae0c9..19333b99 100644 --- a/appPlugins/ToolPDF.py +++ b/appPlugins/ToolPDF.py @@ -237,7 +237,7 @@ class ToolPDF(AppTool): points = {} def obj_init(new_obj, app_obj): - clear_geo = [geo_el['clear'] for geo_el in ap_dict['0']['geometry']] + clear_geo = [geo_el['clear'] for geo_el in ap_dict[0]['geometry']] new_obj.tools = {} @@ -318,10 +318,10 @@ class ToolPDF(AppTool): follow_buf.append(geo_el['follow']) poly_buff = unary_union(poly_buff) - if '0' in grb_obj.tools: + if 0 in grb_obj.tools: global_clear_geo = [] - if 'geometry' in grb_obj.tools['0']: - for geo_el in ap_dict['0']['geometry']: + if 'geometry' in grb_obj.tools[0]: + for geo_el in ap_dict[0]['geometry']: if 'clear' in geo_el: global_clear_geo.append(geo_el['clear']) diff --git a/appPlugins/ToolPanelize.py b/appPlugins/ToolPanelize.py index 606cbd58..eed72bef 100644 --- a/appPlugins/ToolPanelize.py +++ b/appPlugins/ToolPanelize.py @@ -995,7 +995,7 @@ class Panelize(AppTool): new_solid_list.append(deepcopy(new_el)) new_obj.tools = { - '0': { + 0: { 'type': 'REG', 'size': 0.0, 'geometry': deepcopy(new_solid_list) @@ -1007,7 +1007,7 @@ class Panelize(AppTool): del new_obj.tools else: new_obj.tools = { - '0': { + 0: { 'type': 'REG', 'size': 0.0, 'geometry': deepcopy(new_obj.solid_geometry) diff --git a/appPlugins/ToolQRCode.py b/appPlugins/ToolQRCode.py index f7e8d773..15bca1b4 100644 --- a/appPlugins/ToolQRCode.py +++ b/appPlugins/ToolQRCode.py @@ -321,7 +321,7 @@ class QRCode(AppTool): box_size = float(self.ui.bsize_entry.get_value()) / 10.0 sort_apid = [] - new_apid = '10' + new_apid = 10 if self.grb_object.tools: for k, v in list(self.grb_object.tools.items()): sort_apid.append(int(k)) @@ -330,7 +330,7 @@ class QRCode(AppTool): if max_apid >= 10: new_apid = str(max_apid + 1) else: - new_apid = '10' + new_apid = 10 # don't know if the condition is required since I already made sure above that the new_apid is a new one if new_apid not in self.grb_object.tools: @@ -347,17 +347,17 @@ class QRCode(AppTool): self.grb_object.tools[new_apid]['width'] = deepcopy(box_size * 1.01) self.grb_object.tools[new_apid]['size'] = deepcopy(math.sqrt(box_size ** 2 + box_size ** 2)) - if '0' not in self.grb_object.tools: - self.grb_object.tools['0'] = { + if 0 not in self.grb_object.tools: + self.grb_object.tools[0] = { 'type': 'REG', 'size': 0.0, 'geometry': [] } - # in case that the QRCode geometry is dropped onto a copper region (found in the '0' aperture) + # in case that the QRCode geometry is dropped onto a copper region (found in the 0 aperture) # make sure that I place a cutout there zero_elem = {'clear': offset_mask_geo} - self.grb_object.tools['0']['geometry'].append(deepcopy(zero_elem)) + self.grb_object.tools[0]['geometry'].append(deepcopy(zero_elem)) try: a, b, c, d = self.grb_object.bounds() diff --git a/appPlugins/ToolSub.py b/appPlugins/ToolSub.py index 099909b3..0fa370eb 100644 --- a/appPlugins/ToolSub.py +++ b/appPlugins/ToolSub.py @@ -33,7 +33,7 @@ class ToolSub(AppTool): job_finished = QtCore.pyqtSignal(bool) # the string param is the outname and the list is a list of tuples each being formed from the new_aperture_geometry - # list and the second element is also a list with possible geometry that needs to be added to the '0' aperture + # list and the second element is also a list with possible geometry that needs to be added to the 0 aperture # meaning geometry that was deformed aperture_processing_finished = QtCore.pyqtSignal(str, list) @@ -393,11 +393,11 @@ class ToolSub(AppTool): grb_obj.tools = deepcopy(self.new_apertures) - if '0' not in grb_obj.tools: - grb_obj.tools['0'] = {} - grb_obj.tools['0']['type'] = 'REG' - grb_obj.tools['0']['size'] = 0.0 - grb_obj.tools['0']['geometry'] = [] + if 0 not in grb_obj.tools: + grb_obj.tools[0] = {} + grb_obj.tools[0]['type'] = 'REG' + grb_obj.tools[0]['size'] = 0.0 + grb_obj.tools[0]['geometry'] = [] for apid in list(grb_obj.tools.keys()): # output is a tuple in the format (apid, surviving_geo, modified_geo) @@ -412,15 +412,15 @@ class ToolSub(AppTool): grb_obj.tools[apid]['geometry'] += deepcopy(surving_geo) if modified_geo: - grb_obj.tools['0']['geometry'] += modified_geo + grb_obj.tools[0]['geometry'] += modified_geo # if the current aperture does not have geometry then get rid of it if not grb_obj.tools[apid]['geometry']: grb_obj.tools.pop(apid, None) - # delete the '0' aperture if it has no geometry - if not grb_obj.tools['0']['geometry']: - grb_obj.tools.pop('0', None) + # delete the 0 aperture if it has no geometry + if not grb_obj.tools[0]['geometry']: + grb_obj.tools.pop(0, None) poly_buff = [] follow_buff = [] diff --git a/app_Main.py b/app_Main.py index 29b53e11..a2b4e6f7 100644 --- a/app_Main.py +++ b/app_Main.py @@ -3625,7 +3625,7 @@ class App(QtCore.QObject): # or do the conversion :( # ) # and it is ordering them (actually I want that to make the defaults easy to search within) but making - # the '10' entry jsut after '1' therefore ordering as strings + # the '10' entry just after '1' therefore ordering as strings sorted_bookmarks = sorted(list(self.defaults["global_bookmarks"].items())[:bm_limit], key=lambda x: int(x[0])) @@ -5863,7 +5863,7 @@ class App(QtCore.QObject): def initialize_from_geometry(obj_init, app_obj): apertures = { - '0': { + 0: { 'size': 0.0, 'type': 'REG', 'geometry': [] @@ -5876,7 +5876,7 @@ class App(QtCore.QObject): new_elem['follow'] = obj_orig.exterior except AttributeError: pass - apertures['0']['geometry'].append(deepcopy(new_elem)) + apertures[0]['geometry'].append(deepcopy(new_elem)) obj_init.solid_geometry = deepcopy(obj.solid_geometry) obj_init.tools = deepcopy(apertures) @@ -5890,7 +5890,7 @@ class App(QtCore.QObject): apid = 10 for tool in obj.tools: - apertures[str(apid)] = { + apertures[apid] = { 'size': float(obj.tools[tool]['tooldia']), 'type': 'C', 'geometry': [] @@ -5901,7 +5901,7 @@ class App(QtCore.QObject): 'solid': geo, 'follow': geo.exterior } - apertures[str(apid)]['geometry'].append(deepcopy(new_el)) + apertures[apid]['geometry'].append(deepcopy(new_el)) apid += 1 diff --git a/preprocessors/Roland_MDX_20.py b/preprocessors/Roland_MDX_20.py index 199c76b0..3802606b 100644 --- a/preprocessors/Roland_MDX_20.py +++ b/preprocessors/Roland_MDX_20.py @@ -49,7 +49,7 @@ class Roland_MDX_20(PreProc): def up_to_zero_code(self, p): gcode = self.feedrate_code(p) + '\n' - gcode += self.position_code(p).format(**p) + ',' + '0' + ';' + gcode += self.position_code(p).format(**p) + ',' + 0 + ';' return gcode def position_code(self, p): diff --git a/tclCommands/TclCommandNew.py b/tclCommands/TclCommandNew.py index cf390ff8..6646af0f 100644 --- a/tclCommands/TclCommandNew.py +++ b/tclCommands/TclCommandNew.py @@ -46,7 +46,7 @@ class TclCommandNew(TclCommand): reset_tcl = True if 'reset' in args: - if args['reset'] and (args['reset'] == '0' or args['reset'].lower() == 'false'): + if args['reset'] and (args['reset'] == 0 or args['reset'].lower() == 'false'): reset_tcl = False self.app.f_handlers.on_file_new_project(cli=True, reset_tcl=reset_tcl)