From cead702f4d7094c3cec1419d6fd79b23cc4196c4 Mon Sep 17 00:00:00 2001 From: Paulo Henrique Silva Date: Fri, 13 Nov 2015 13:18:50 -0200 Subject: Add fix to work with excellon with no tool definition. I found out that Proteus generate some strange Excellon without any tool definition. Gerbv renders it correctly and after digging in I found the heuristic that they use to "guess" the tool diameter. This change replicates this behavior on pcb-tools. --- gerber/excellon.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/gerber/excellon.py b/gerber/excellon.py index c953e55..101c6ea 100755 --- a/gerber/excellon.py +++ b/gerber/excellon.py @@ -476,10 +476,27 @@ class ExcellonParser(object): elif line[0] == 'T' and self.state != 'HEADER': stmt = ToolSelectionStmt.from_excellon(line) + self.statements.append(stmt) + # T0 is used as END marker, just ignore if stmt.tool != 0: + # FIXME: for weird files with no tools defined, original calc from gerbv + if stmt.tool not in self.tools: + if self._settings().units == "inch": + diameter = (16 + 8 * stmt.tool) / 1000.0; + else: + diameter = metric((16 + 8 * stmt.tool) / 1000.0); + + tool = ExcellonTool(self._settings(), number=stmt.tool, diameter=diameter) + self.tools[tool.number] = tool + + # FIXME: need to add this tool definition inside header to make sure it is properly written + for i, s in enumerate(self.statements): + if isinstance(s, ToolSelectionStmt) or isinstance(s, ExcellonTool): + self.statements.insert(i, tool) + break + self.active_tool = self.tools[stmt.tool] - self.statements.append(stmt) elif line[0] == 'R' and self.state != 'HEADER': stmt = RepeatHoleStmt.from_excellon(line, self._settings()) -- cgit