From 0974e54d98454d7fb1766125dfdb25e762f52ce1 Mon Sep 17 00:00:00 2001 From: Juan Pablo Caram Date: Sun, 31 Aug 2014 16:40:07 -0400 Subject: [PATCH] Some fixes (hacks) to load certain malformed gerber. --- camlib.py | 21 +++++++++++++++------ recent.json | 2 +- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/camlib.py b/camlib.py index 50a62fda..64389972 100644 --- a/camlib.py +++ b/camlib.py @@ -834,19 +834,22 @@ class Gerber (Geometry): if apertureType == "R": # Rectangle, example: %ADD15R,0.05X0.12*% self.apertures[apid] = {"type": "R", "width": float(paramList[0]), - "height": float(paramList[1])} + "height": float(paramList[1]), + "size": sqrt(float(paramList[0])**2 + float(paramList[1])**2)} # Hack return apid if apertureType == "O": # Obround self.apertures[apid] = {"type": "O", "width": float(paramList[0]), - "height": float(paramList[1])} + "height": float(paramList[1]), + "size": sqrt(float(paramList[0])**2 + float(paramList[1])**2)} # Hack return apid if apertureType == "P": # Polygon (regular) self.apertures[apid] = {"type": "P", "diam": float(paramList[0]), - "nVertices": int(paramList[1])} + "nVertices": int(paramList[1]), + "size": float(paramList[0])} # Hack if len(paramList) >= 3: self.apertures[apid]["rotation"] = float(paramList[2]) return apid @@ -1107,15 +1110,20 @@ class Gerber (Geometry): log.warning("Single quadrant arc are not implemented yet. (%d)" % line_num) ### Operation code alone + # Operation code alone, usually just D03 (Flash) + # self.opcode_re = re.compile(r'^D0?([123])\*$') match = self.opcode_re.search(gline) if match: current_operation_code = int(match.group(1)) if current_operation_code == 3: ## --- Buffered --- - flash = Gerber.create_flash_geometry(Point(path[-1]), - self.apertures[current_aperture]) - poly_buffer.append(flash) + try: + flash = Gerber.create_flash_geometry(Point(path[-1]), + self.apertures[current_aperture]) + poly_buffer.append(flash) + except IndexError: + log.warning("Line %d: %s -> Nothing there to flash!" % (line_num, gline)) continue @@ -1900,6 +1908,7 @@ class CNCjob(Geometry): continue if type(geo) == Point: + # TODO: point2gcode does not return anything... self.gcode += self.point2gcode(geo) continue diff --git a/recent.json b/recent.json index 86235ef4..fc7000f2 100644 --- a/recent.json +++ b/recent.json @@ -1 +1 @@ -[{"kind": "gerber", "filename": "C:/Users/jpcaram/Dropbox/CNC/pcbcam/cirkuix/tests/CBS-F_Cu.gtl"}, {"kind": "excellon", "filename": "C:/Users/jpcaram/Dropbox/CNC/pcbcam/test_files/BLDC2003Through.drl"}, {"kind": "gerber", "filename": "C:/Users/jpcaram/Dropbox/CNC/pcbcam/cirkuix/tests/CBS-B_Cu.gbl"}, {"kind": "project", "filename": "C:/Users/jpcaram/Dropbox/CNC/pcbcam/test_files/gerber_project.fcam"}, {"kind": "project", "filename": "C:/Users/jpcaram/Dropbox/CNC/pcbcam/test_files/drill_project.fcam"}, {"kind": "excellon", "filename": "C:/Users/jpcaram/Dropbox/CNC/pcbcam/test_files/TFTadapter.drl"}, {"kind": "gerber", "filename": "C:/Users/jpcaram/Dropbox/CNC/pcbcam/test_files/WindMills - Bottom Copper 2.gbr"}, {"kind": "gerber", "filename": "C:/Users/jpcaram/Dropbox/CNC/pcbcam/test_files/Example1_copper_bottom.gbr"}, {"kind": "gerber", "filename": "C:/Users/jpcaram/Dropbox/CNC/pcbcam/test_files/7V-PSU.zip"}, {"kind": "gerber", "filename": "C:/Users/jpcaram/Dropbox/CNC/pcbcam/test_files/Gerbers/AVR_Transistor_Tester_copper_top.GTL"}] \ No newline at end of file +[{"kind": "gerber", "filename": "C:/Users/jpcaram/Dropbox/CNC/pcbcam/test_files/not_loaded.gtl"}, {"kind": "gerber", "filename": "C:/Users/jpcaram/Dropbox/CNC/pcbcam/test_files/diag_1TOP.art"}, {"kind": "gerber", "filename": "C:/Users/jpcaram/Dropbox/CNC/pcbcam/test_files/22TOP.art"}, {"kind": "gerber", "filename": "C:/Users/jpcaram/Dropbox/CNC/pcbcam/test_files/Top.gbr"}, {"kind": "excellon", "filename": "C:/Users/jpcaram/Dropbox/CNC/pcbcam/test_files/holes.drl"}, {"kind": "gerber", "filename": "C:/Users/jpcaram/Dropbox/CNC/pcbcam/cirkuix/tests/CBS-F_Cu.gtl"}, {"kind": "excellon", "filename": "C:/Users/jpcaram/Dropbox/CNC/pcbcam/test_files/BLDC2003Through.drl"}, {"kind": "gerber", "filename": "C:/Users/jpcaram/Dropbox/CNC/pcbcam/cirkuix/tests/CBS-B_Cu.gbl"}, {"kind": "project", "filename": "C:/Users/jpcaram/Dropbox/CNC/pcbcam/test_files/gerber_project.fcam"}, {"kind": "project", "filename": "C:/Users/jpcaram/Dropbox/CNC/pcbcam/test_files/drill_project.fcam"}] \ No newline at end of file