diff options
Diffstat (limited to 'gerber')
-rw-r--r-- | gerber/am_statements.py | 4 | ||||
-rw-r--r-- | gerber/primitives.py | 15 | ||||
-rw-r--r-- | gerber/render/cairo_backend.py | 16 |
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)
|