diff options
-rw-r--r-- | gerber/excellon_statements.py | 21 | ||||
-rw-r--r-- | gerber/render/excellon_backend.py | 17 |
2 files changed, 29 insertions, 9 deletions
diff --git a/gerber/excellon_statements.py b/gerber/excellon_statements.py index 18eaea1..cabdf6c 100644 --- a/gerber/excellon_statements.py +++ b/gerber/excellon_statements.py @@ -116,6 +116,21 @@ class ExcellonTool(ExcellonStatement): PLATED_YES = 'plated' PLATED_NO = 'nonplated' PLATED_OPTIONAL = 'optional' + + @classmethod + def from_tool(cls, tool): + args = {} + + args['depth_offset'] = tool.depth_offset + args['diameter'] = tool.diameter + args['feed_rate'] = tool.feed_rate + args['max_hit_count'] = tool.max_hit_count + args['number'] = tool.number + args['plated'] = tool.plated + args['retract_rate'] = tool.retract_rate + args['rpm'] = tool.rpm + + return cls(None, **args) @classmethod def from_excellon(cls, line, settings, id=None, plated=None): @@ -196,8 +211,10 @@ class ExcellonTool(ExcellonStatement): self.hit_count = 0 def to_excellon(self, settings=None): - fmt = self.settings.format - zs = self.settings.zero_suppression + if self.settings and not settings: + settings = self.settings + fmt = settings.format + zs = settings.zero_suppression stmt = 'T%02d' % self.number if self.retract_rate is not None: stmt += 'B%s' % write_gerber_value(self.retract_rate, fmt, zs) diff --git a/gerber/render/excellon_backend.py b/gerber/render/excellon_backend.py index bec8367..f5cec1a 100644 --- a/gerber/render/excellon_backend.py +++ b/gerber/render/excellon_backend.py @@ -10,11 +10,12 @@ class ExcellonContext(GerberContext): self.header = [] self.tool_def = [] self.body = [] + self.start = [HeaderBeginStmt()] self.end = [EndOfProgramStmt()] self.handled_tools = set() self.cur_tool = None - self.pos = (None, None) + self._pos = (None, None) self.settings = settings @@ -25,7 +26,7 @@ class ExcellonContext(GerberContext): @property def statements(self): - return self.comments + self.header + self.body + self.end + return self.start + self.comments + self.header + self.body + self.end def set_bounds(self, bounds): pass @@ -61,15 +62,17 @@ class ExcellonContext(GerberContext): def _render_drill(self, drill, color): - if not drill in self.handled_tools: - self.tool_def.append(drill.tool) + tool = drill.hit.tool + if not tool in self.handled_tools: + self.handled_tools.add(tool) + self.header.append(ExcellonTool.from_tool(tool)) - if drill.tool != self.cur_tool: - self.body.append(ToolSelectionStmt(drill.tool.number)) + if tool != self.cur_tool: + self.body.append(ToolSelectionStmt(tool.number)) point = self._simplify_point(drill.position) self._pos = drill.position - self.body.append(CoordinateStmt.from_point()) + self.body.append(CoordinateStmt.from_point(point)) def _render_inverted_layer(self): pass |