Write polygons to macros

This commit is contained in:
Garret Fick 2016-03-05 10:04:58 +08:00
parent 7b88509c4a
commit 7f47aea332
3 changed files with 29 additions and 1 deletions

View file

@ -461,6 +461,11 @@ class AMPolygonPrimitive(AMPrimitive):
------
ValueError, TypeError
"""
@classmethod
def from_primitive(cls, primitive):
return cls(5, 'on', primitive.sides, primitive.position, primitive.diameter, primitive.rotation)
@classmethod
def from_gerber(cls, primitive):
modifiers = primitive.strip(' *').split(",")

View file

@ -736,6 +736,10 @@ class Polygon(Primitive):
@property
def flashed(self):
return True
@property
def diameter(self):
return self.radius * 2
@property
def bounding_box(self):
@ -759,6 +763,20 @@ class Polygon(Primitive):
points.append(rotate_point((self.position[0] + self.radius, self.position[1]), offset + da * i, self.position))
return points
def equivalent(self, other, offset):
'''
Is this the outline the same as the other, ignoring the position offset?
'''
# Quick check if it even makes sense to compare them
if type(self) != type(other) or self.sides != other.sides or self.radius != other.radius:
return False
equiv_pos = tuple(map(add, other.position, offset))
return nearly_equal(self.position, equiv_pos)
class AMGroup(Primitive):
"""

View file

@ -2,7 +2,7 @@
from .render import GerberContext
from ..am_statements import *
from ..gerber_statements import *
from ..primitives import AMGroup, Arc, Circle, Line, Outline, Rectangle
from ..primitives import AMGroup, Arc, Circle, Line, Outline, Polygon, Rectangle
from copy import deepcopy
class AMGroupContext(object):
@ -28,6 +28,8 @@ class AMGroupContext(object):
self._render_rectangle(primitive)
elif isinstance(primitive, Line):
self._render_line(primitive)
elif isinstance(primitive, Polygon):
self._render_polygon(primitive)
else:
raise ValueError('amgroup')
@ -53,6 +55,9 @@ class AMGroupContext(object):
def _render_outline(self, outline):
self.statements.append(AMOutlinePrimitive.from_primitive(outline))
def _render_polygon(self, polygon):
self.statements.append(AMPolygonPrimitive.from_primitive(polygon))
def _render_thermal(self, thermal):
pass