瀏覽代碼

- modified the Gerber export method to take care of the situation where the exported Gerber file is a SVG/DXF file imported as Gerber

Marius Stanciu 5 年之前
父節點
當前提交
27216c52e2
共有 2 個文件被更改,包括 50 次插入1 次删除
  1. 1 0
      CHANGELOG.md
  2. 49 1
      appObjects/FlatCAMGerber.py

+ 1 - 0
CHANGELOG.md

@@ -12,6 +12,7 @@ CHANGELOG for FlatCAM beta
 - trying to optimize the resulting geometry in DXF import (and in SVG import) by merging contiguous lines; reduced the lines to about one third of the original
 - fixed importing DXF file as Gerber method such that now the resulting Gerber object is correctly created having the geometry attributes like self.apertures and self.follow_geometry
 - added Turkish translation - courtesy of Mehmet Kaya
+- modified the Gerber export method to take care of the situation where the exported Gerber file is a SVG/DXF file imported as Gerber
 
 30.06.2020
 

+ 49 - 1
appObjects/FlatCAMGerber.py

@@ -1228,7 +1228,8 @@ class GerberObject(FlatCAMObj, Gerber):
                     for geo_elem in self.apertures['0']['geometry']:
                         if 'solid' in geo_elem:
                             geo = geo_elem['solid']
-                            if not geo.is_empty:
+                            if not geo.is_empty and not isinstance(geo, LineString) and \
+                                    not isinstance(geo, MultiLineString) and not isinstance(geo, Point):
                                 gerber_code += 'G36*\n'
                                 geo_coords = list(geo.exterior.coords)
                                 # first command is a move with pen-up D02 at the beginning of the geo
@@ -1287,6 +1288,53 @@ class GerberObject(FlatCAMObj, Gerber):
                                         gerber_code += 'D02*\n'
                                         gerber_code += 'G37*\n'
                                     gerber_code += '%LPD*%\n'
+                            elif isinstance(geo, LineString) or isinstance(geo, MultiLineString) or \
+                                    isinstance(geo, Point):
+                                try:
+                                    if not geo.is_empty:
+                                        if isinstance(geo, Point):
+                                            if g_zeros == 'T':
+                                                x_formatted, y_formatted = tz_format(geo.x, geo.y, factor)
+                                                gerber_code += "X{xform}Y{yform}D03*\n".format(xform=x_formatted,
+                                                                                               yform=y_formatted)
+                                            else:
+                                                x_formatted, y_formatted = lz_format(geo.x, geo.y, factor)
+                                                gerber_code += "X{xform}Y{yform}D03*\n".format(xform=x_formatted,
+                                                                                               yform=y_formatted)
+                                        else:
+                                            geo_coords = list(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)
+
+                                            prev_coord = geo_coords[0]
+                                            for coord in geo_coords[1:]:
+                                                if coord != prev_coord:
+                                                    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)
+                                                prev_coord = coord
+
+                                            # gerber_code += "D02*\n"
+                                except Exception as e:
+                                    log.debug("FlatCAMObj.GerberObject.export_gerber() 'follow' --> %s" % str(e))
                         if 'clear' in geo_elem:
                             geo = geo_elem['clear']
                             if not geo.is_empty: