summaryrefslogtreecommitdiff
path: root/gerber
diff options
context:
space:
mode:
authorGarret Fick <garret@ficksworkshop.com>2015-12-30 18:44:07 +0800
committerGarret Fick <garret@ficksworkshop.com>2015-12-30 18:44:07 +0800
commitf61eee807f87c329f6f88645ecdb48f01b887c52 (patch)
tree9c1422fac612c4bca82968c278540875ae9307e2 /gerber
parentff1ad704d5bb7814fdaebc156b727ec3c5f2d1a8 (diff)
downloadgerbonara-f61eee807f87c329f6f88645ecdb48f01b887c52.tar.gz
gerbonara-f61eee807f87c329f6f88645ecdb48f01b887c52.tar.bz2
gerbonara-f61eee807f87c329f6f88645ecdb48f01b887c52.zip
Render polygon flashes
Diffstat (limited to 'gerber')
-rw-r--r--gerber/am_statements.py4
-rw-r--r--gerber/primitives.py15
-rw-r--r--gerber/render/cairo_backend.py16
3 files changed, 32 insertions, 3 deletions
diff --git a/gerber/am_statements.py b/gerber/am_statements.py
index 599d19d..e484b10 100644
--- a/gerber/am_statements.py
+++ b/gerber/am_statements.py
@@ -18,7 +18,7 @@
import math
from .utils import validate_coordinates, inch, metric, rotate_point
-from .primitives import Circle, Line, Outline, Rectangle
+from .primitives import Circle, Line, Outline, Polygon, Rectangle
# TODO: Add support for aperture macro variables
@@ -483,7 +483,7 @@ class AMPolygonPrimitive(AMPrimitive):
return fmt.format(**data)
def to_primitive(self, units):
- raise NotImplementedError()
+ return Polygon(self.position, self.vertices, self.diameter / 2.0, rotation=math.radians(self.rotation), units=units)
class AMMoirePrimitive(AMPrimitive):
diff --git a/gerber/primitives.py b/gerber/primitives.py
index 86fd322..b0e17e9 100644
--- a/gerber/primitives.py
+++ b/gerber/primitives.py
@@ -17,7 +17,7 @@
import math
from operator import add, sub
-from .utils import validate_coordinates, inch, metric
+from .utils import validate_coordinates, inch, metric, rotate_point
from jsonpickle.util import PRIMITIVES
@@ -683,6 +683,7 @@ class Obround(Primitive):
class Polygon(Primitive):
"""
+ Polygon flash defined by a set number of sized.
"""
def __init__(self, position, sides, radius, **kwargs):
super(Polygon, self).__init__(**kwargs)
@@ -706,6 +707,18 @@ class Polygon(Primitive):
def offset(self, x_offset=0, y_offset=0):
self.position = tuple(map(add, self.position, (x_offset, y_offset)))
+
+ @property
+ def vertices(self):
+
+ offset = math.degrees(self.rotation)
+ da = 360.0 / self.sides
+
+ points = []
+ for i in xrange(self.sides):
+ points.append(rotate_point((self.position[0] + self.radius, self.position[1]), offset + da * i, self.position))
+
+ return points
class AMGroup(Primitive):
"""
diff --git a/gerber/render/cairo_backend.py b/gerber/render/cairo_backend.py
index 3ee38ae..68e9e98 100644
--- a/gerber/render/cairo_backend.py
+++ b/gerber/render/cairo_backend.py
@@ -148,6 +148,22 @@ class GerberCairoContext(GerberContext):
self._render_circle(obround.subshapes['circle1'], color)
self._render_circle(obround.subshapes['circle2'], color)
self._render_rectangle(obround.subshapes['rectangle'], color)
+
+ def _render_polygon(self, polygon, color):
+ vertices = polygon.vertices
+
+ self.ctx.set_source_rgba(color[0], color[1], color[2], self.alpha)
+ self.ctx.set_operator(cairo.OPERATOR_OVER if (polygon.level_polarity == "dark" and not self.invert) else cairo.OPERATOR_CLEAR)
+ self.ctx.set_line_width(0)
+ self.ctx.set_line_cap(cairo.LINE_CAP_ROUND)
+
+ # Start from before the end so it is easy to iterate and make sure it is closed
+ self.ctx.move_to(*map(mul, vertices[-1], self.scale))
+ for v in vertices:
+ self.ctx.line_to(*map(mul, v, self.scale))
+
+ self.ctx.fill()
+
def _render_drill(self, circle, color):
self._render_circle(circle, color)