summaryrefslogtreecommitdiff
path: root/gerber/render
diff options
context:
space:
mode:
authorGarret Fick <garret@ficksworkshop.com>2016-03-26 15:59:42 +0800
committerGarret Fick <garret@ficksworkshop.com>2016-03-26 15:59:42 +0800
commitacde19f205898188c03a46e5d8a7a6a4d4637a2d (patch)
treef1c11657ecf104fa86d33c233d2c67dd7d40cd96 /gerber/render
parentd12f6385a434c02677bfbb7b075dd9d8e49627fe (diff)
downloadgerbonara-acde19f205898188c03a46e5d8a7a6a4d4637a2d.tar.gz
gerbonara-acde19f205898188c03a46e5d8a7a6a4d4637a2d.tar.bz2
gerbonara-acde19f205898188c03a46e5d8a7a6a4d4637a2d.zip
Support for the G85 slot statement
Diffstat (limited to 'gerber/render')
-rw-r--r--gerber/render/cairo_backend.py14
-rw-r--r--gerber/render/excellon_backend.py33
-rw-r--r--gerber/render/render.py5
3 files changed, 48 insertions, 4 deletions
diff --git a/gerber/render/cairo_backend.py b/gerber/render/cairo_backend.py
index 7be7e6a..d895e5c 100644
--- a/gerber/render/cairo_backend.py
+++ b/gerber/render/cairo_backend.py
@@ -173,6 +173,20 @@ class GerberCairoContext(GerberContext):
def _render_drill(self, circle, color):
self._render_circle(circle, color)
+ def _render_slot(self, slot, color):
+ start = map(mul, slot.start, self.scale)
+ end = map(mul, slot.end, self.scale)
+
+ width = slot.diameter
+
+ self.ctx.set_source_rgba(color[0], color[1], color[2], self.alpha)
+ self.ctx.set_operator(cairo.OPERATOR_OVER if (slot.level_polarity == "dark" and not self.invert) else cairo.OPERATOR_CLEAR)
+ self.ctx.set_line_width(width * self.scale[0])
+ self.ctx.set_line_cap(cairo.LINE_CAP_ROUND)
+ self.ctx.move_to(*start)
+ self.ctx.line_to(*end)
+ self.ctx.stroke()
+
def _render_amgroup(self, amgroup, color):
for primitive in amgroup.primitives:
self.render(primitive)
diff --git a/gerber/render/excellon_backend.py b/gerber/render/excellon_backend.py
index f5cec1a..eb79f1b 100644
--- a/gerber/render/excellon_backend.py
+++ b/gerber/render/excellon_backend.py
@@ -9,6 +9,7 @@ class ExcellonContext(GerberContext):
self.comments = []
self.header = []
self.tool_def = []
+ self.body_start = [RewindStopStmt()]
self.body = []
self.start = [HeaderBeginStmt()]
self.end = [EndOfProgramStmt()]
@@ -19,14 +20,22 @@ class ExcellonContext(GerberContext):
self.settings = settings
- self._start_header(settings)
+ self._start_header()
+ self._start_comments()
- def _start_header(self, settings):
- pass
+ def _start_header(self):
+ """Create the header from the settings"""
+
+ self.header.append(UnitStmt.from_settings(self.settings))
+
+ def _start_comments(self):
+
+ # Write the digits used - this isn't valid Excellon statement, so we write as a comment
+ self.comments.append(CommentStmt('FILE_FORMAT=%d:%d' % (self.settings.format[0], self.settings.format[1])))
@property
def statements(self):
- return self.start + self.comments + self.header + self.body + self.end
+ return self.start + self.comments + self.header + self.body_start + self.body + self.end
def set_bounds(self, bounds):
pass
@@ -69,10 +78,26 @@ class ExcellonContext(GerberContext):
if tool != self.cur_tool:
self.body.append(ToolSelectionStmt(tool.number))
+ self.cur_tool = tool
point = self._simplify_point(drill.position)
self._pos = drill.position
self.body.append(CoordinateStmt.from_point(point))
+
+ def _render_slot(self, slot, color):
+
+ tool = slot.hit.tool
+ if not tool in self.handled_tools:
+ self.handled_tools.add(tool)
+ self.header.append(ExcellonTool.from_tool(tool))
+
+ if tool != self.cur_tool:
+ self.body.append(ToolSelectionStmt(tool.number))
+ self.cur_tool = tool
+
+ # Slots don't use simplified points
+ self._pos = slot.end
+ self.body.append(SlotStmt.from_points(slot.start, slot.end))
def _render_inverted_layer(self):
pass
diff --git a/gerber/render/render.py b/gerber/render/render.py
index b518385..a5ae38e 100644
--- a/gerber/render/render.py
+++ b/gerber/render/render.py
@@ -150,6 +150,8 @@ class GerberContext(object):
self._render_polygon(primitive, color)
elif isinstance(primitive, Drill):
self._render_drill(primitive, self.drill_color)
+ elif isinstance(primitive, Slot):
+ self._render_slot(primitive, self.drill_color)
elif isinstance(primitive, AMGroup):
self._render_amgroup(primitive, color)
elif isinstance(primitive, Outline):
@@ -183,6 +185,9 @@ class GerberContext(object):
def _render_drill(self, primitive, color):
pass
+ def _render_slot(self, primitive, color):
+ pass
+
def _render_amgroup(self, primitive, color):
pass