Render polygon flashes
This commit is contained in:
parent
ff1ad704d5
commit
f61eee807f
3 changed files with 32 additions and 3 deletions
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue