From 5b663c5f2087aa9ec0271bf9ed574f958b8d9893 Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Wed, 8 May 2019 04:21:34 +0300 Subject: [PATCH] - work in Gerber Export: finished the body export but have some errors with clear geometry (LPC) --- FlatCAMObj.py | 53 ++++++++++++++++++++++++++------------------------- README.md | 1 + camlib.py | 13 ++++++++----- 3 files changed, 36 insertions(+), 31 deletions(-) diff --git a/FlatCAMObj.py b/FlatCAMObj.py index 62905b2e..c817856b 100644 --- a/FlatCAMObj.py +++ b/FlatCAMObj.py @@ -1330,33 +1330,34 @@ class FlatCAMGerber(FlatCAMObj, Gerber): gerber_code += 'D02*\n' gerber_code += 'G37*\n' - if 'clear_geometry' in self.apertures['0']: - gerber_code += '%LPC*%\n' - for geo in self.apertures['0']['clear_geometry']: - gerber_code += 'G36*\n' - geo_coords = list(geo.exterior.coords) + clear_list = list(geo.interiors) + if clear_list: + gerber_code += '%LPC*%\n' + for clear_geo in clear_list: + gerber_code += 'G36*\n' + geo_coords = list(clear_geo.coords) - # first command is a move with pen-up D02 at the beginning of the geo - if g_zeros == 'T': - x_formatted, y_formatted = tz_format(geo_coords[0][0], geo_coords[0][1], factor) - gerber_code += "X{xform}Y{yform}D02*\n".format(xform=x_formatted, - yform=y_formatted) - else: - x_formatted, y_formatted = lz_format(geo_coords[0][0], geo_coords[0][1], factor) - gerber_code += "X{xform}Y{yform}D02*\n".format(xform=x_formatted, - yform=y_formatted) - for coord in geo_coords[1:]: - if g_zeros == 'T': - x_formatted, y_formatted = tz_format(coord[0], coord[1], factor) - gerber_code += "X{xform}Y{yform}D01*\n".format(xform=x_formatted, - yform=y_formatted) - else: - x_formatted, y_formatted = lz_format(coord[0], coord[1], factor) - gerber_code += "X{xform}Y{yform}D01*\n".format(xform=x_formatted, - yform=y_formatted) - gerber_code += 'D02*\n' - gerber_code += 'G37*\n' - gerber_code += '%LPD*%\n' + # first command is a move with pen-up D02 at the beginning of the geo + if g_zeros == 'T': + x_formatted, y_formatted = tz_format(geo_coords[0][0], geo_coords[0][1], factor) + gerber_code += "X{xform}Y{yform}D02*\n".format(xform=x_formatted, + yform=y_formatted) + else: + x_formatted, y_formatted = lz_format(geo_coords[0][0], geo_coords[0][1], factor) + gerber_code += "X{xform}Y{yform}D02*\n".format(xform=x_formatted, + yform=y_formatted) + for coord in geo_coords[1:]: + if g_zeros == 'T': + x_formatted, y_formatted = tz_format(coord[0], coord[1], factor) + gerber_code += "X{xform}Y{yform}D01*\n".format(xform=x_formatted, + yform=y_formatted) + else: + x_formatted, y_formatted = lz_format(coord[0], coord[1], factor) + gerber_code += "X{xform}Y{yform}D01*\n".format(xform=x_formatted, + yform=y_formatted) + gerber_code += 'D02*\n' + gerber_code += 'G37*\n' + gerber_code += '%LPD*%\n' for apid in self.apertures: if apid == '0': diff --git a/README.md b/README.md index 6743881b..02ddebc7 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,7 @@ CAD program, and create G-Code for Isolation routing. - work in Gerber Export: finished the header export - fixed the Gerber Object and Gerber Editor Apertures Table to not show extra rows when there are aperture macros in the object - work in Gerber Export: finished the body export but have some errors with clear geometry (LPC) +- Gerber Export - finished 6.05.2019 diff --git a/camlib.py b/camlib.py index 45475306..5eed2efc 100644 --- a/camlib.py +++ b/camlib.py @@ -3219,7 +3219,7 @@ class Gerber (Geometry): if 'clear_geometry' in self.apertures[apid]: for pol in self.apertures[apid]['clear_geometry']: global_clear_geo.append(pol) - # self.apertures[apid].pop('clear_geometry', None) + self.apertures[apid].pop('clear_geometry', None) log.warning("Found %d clear polygons." % len(global_clear_geo)) temp_geo = [] @@ -3497,11 +3497,14 @@ class Gerber (Geometry): # we need to scale the geometry stored in the Gerber apertures, too try: for apid in self.apertures: - self.apertures[apid]['solid_geometry'] = scale_geom(self.apertures[apid]['solid_geometry']) - self.apertures[apid]['clear_geometry'] = scale_geom(self.apertures[apid]['clear_geometry']) - + if 'solid_geometry' in self.apertures[apid]: + self.apertures[apid]['solid_geometry'] = scale_geom(self.apertures[apid]['solid_geometry']) + if 'follow_geometry' in self.apertures[apid]: + self.apertures[apid]['follow_geometry'] = scale_geom(self.apertures[apid]['follow_geometry']) + if 'clear_geometry' in self.apertures[apid]: + self.apertures[apid]['clear_geometry'] = scale_geom(self.apertures[apid]['clear_geometry']) except Exception as e: - log.debug('FlatCAMGeometry.scale() --> %s' % str(e)) + log.debug('camlib.Gerber.scale() Exception --> %s' % str(e)) self.app.inform.emit(_("[success] Gerber Scale done."))