summaryrefslogtreecommitdiff
path: root/gerber/render
diff options
context:
space:
mode:
Diffstat (limited to 'gerber/render')
-rw-r--r--gerber/render/cairo_backend.py15
-rw-r--r--gerber/render/rs274x_backend.py26
2 files changed, 37 insertions, 4 deletions
diff --git a/gerber/render/cairo_backend.py b/gerber/render/cairo_backend.py
index c1bd60c..2b7c2ff 100644
--- a/gerber/render/cairo_backend.py
+++ b/gerber/render/cairo_backend.py
@@ -159,6 +159,9 @@ class GerberCairoContext(GerberContext):
self._render_rectangle(obround.subshapes['rectangle'], color)
def _render_polygon(self, polygon, color):
+ if polygon.hole_radius > 0:
+ self.ctx.push_group()
+
vertices = polygon.vertices
self.ctx.set_source_rgba(color[0], color[1], color[2], self.alpha)
@@ -172,6 +175,18 @@ class GerberCairoContext(GerberContext):
self.ctx.line_to(*map(mul, v, self.scale))
self.ctx.fill()
+
+ if polygon.hole_radius > 0:
+ # Render the center clear
+ center = tuple(map(mul, polygon.position, self.scale))
+ self.ctx.set_source_rgba(color[0], color[1], color[2], self.alpha)
+ self.ctx.set_operator(cairo.OPERATOR_CLEAR)
+ self.ctx.set_line_width(0)
+ self.ctx.arc(center[0], center[1], polygon.hole_radius * self.scale[0], 0, 2 * math.pi)
+ self.ctx.fill()
+
+ self.ctx.pop_group_to_source()
+ self.ctx.paint_with_alpha(1)
def _render_drill(self, circle, color):
self._render_circle(circle, color)
diff --git a/gerber/render/rs274x_backend.py b/gerber/render/rs274x_backend.py
index bb784b1..c37529e 100644
--- a/gerber/render/rs274x_backend.py
+++ b/gerber/render/rs274x_backend.py
@@ -310,7 +310,7 @@ class Rs274xContext(GerberContext):
self._next_dcode = max(dcode + 1, self._next_dcode)
aper = ADParamStmt.obround(dcode, width, height)
- self._obrounds[(width, height)] = aper
+ self._obrounds[key] = aper
self.header.append(aper)
return aper
@@ -320,10 +320,28 @@ class Rs274xContext(GerberContext):
aper = self._get_obround(obround.width, obround.height)
self._render_flash(obround, aper)
- pass
-
def _render_polygon(self, polygon, color):
- raise ValueError('Polygons can only exist in the context of aperture macro')
+
+ aper = self._get_polygon(polygon.radius, polygon.sides, polygon.rotation, polygon.hole_radius)
+ self._render_flash(polygon, aper)
+
+ def _get_polygon(self, radius, num_vertices, rotation, hole_radius, dcode = None):
+
+ key = (radius, num_vertices, rotation, hole_radius)
+ aper = self._polygons.get(key, None)
+
+ if not aper:
+ if not dcode:
+ dcode = self._next_dcode
+ self._next_dcode += 1
+ else:
+ self._next_dcode = max(dcode + 1, self._next_dcode)
+
+ aper = ADParamStmt.polygon(dcode, radius * 2, num_vertices, rotation, hole_radius * 2)
+ self._polygons[key] = aper
+ self.header.append(aper)
+
+ return aper
def _render_drill(self, drill, color):
raise ValueError('Drills are not valid in RS274X files')