Render primitives for some aperture macros
This commit is contained in:
parent
4a815bf25d
commit
96692b2221
3 changed files with 56 additions and 5 deletions
|
|
@ -16,9 +16,9 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from math import pi
|
||||
from .utils import validate_coordinates, inch, metric
|
||||
from .primitives import Circle, Line, Rectangle
|
||||
import math
|
||||
from .utils import validate_coordinates, inch, metric, rotate_point
|
||||
from .primitives import Circle, Line, Outline, Rectangle
|
||||
|
||||
|
||||
# TODO: Add support for aperture macro variables
|
||||
|
|
@ -382,7 +382,15 @@ class AMOutlinePrimitive(AMPrimitive):
|
|||
return "{code},{exposure},{n_points},{start_point},{points},{rotation}*".format(**data)
|
||||
|
||||
def to_primitive(self, units):
|
||||
raise NotImplementedError()
|
||||
|
||||
lines = []
|
||||
prev_point = rotate_point(self.points[0], self.rotation)
|
||||
for point in self.points[1:]:
|
||||
cur_point = rotate_point(self.points[0], self.rotation)
|
||||
|
||||
lines.append(Line(prev_point, cur_point, Circle((0,0), 0)))
|
||||
|
||||
return Outline(lines, units=units)
|
||||
|
||||
|
||||
class AMPolygonPrimitive(AMPrimitive):
|
||||
|
|
@ -762,7 +770,7 @@ class AMCenterLinePrimitive(AMPrimitive):
|
|||
return fmt.format(**data)
|
||||
|
||||
def to_primitive(self, units):
|
||||
return Rectangle(self.center, self.width, self.height, rotation=self.rotation * pi / 180.0, units=units)
|
||||
return Rectangle(self.center, self.width, self.height, rotation=math.radians(self.rotation), units=units)
|
||||
|
||||
|
||||
class AMLowerLeftLinePrimitive(AMPrimitive):
|
||||
|
|
|
|||
|
|
@ -758,6 +758,47 @@ class AMGroup(Primitive):
|
|||
primitive.offset(dx, dy)
|
||||
|
||||
self._position = new_pos
|
||||
|
||||
|
||||
class Outline(Primitive):
|
||||
"""
|
||||
Outlines only exist as the rendering for a apeture macro outline.
|
||||
They don't exist outside of AMGroup objects
|
||||
"""
|
||||
def __init__(self, primitives, **kwargs):
|
||||
super(Outline, self).__init__(**kwargs)
|
||||
self.primitives = primitives
|
||||
self._to_convert = ['primitives']
|
||||
|
||||
@property
|
||||
def flashed(self):
|
||||
return True
|
||||
|
||||
@property
|
||||
def bounding_box(self):
|
||||
xlims, ylims = zip(*[p.bounding_box for p in self.primitives])
|
||||
minx, maxx = zip(*xlims)
|
||||
miny, maxy = zip(*ylims)
|
||||
min_x = min(minx)
|
||||
max_x = max(maxx)
|
||||
min_y = min(miny)
|
||||
max_y = max(maxy)
|
||||
return ((min_x, max_x), (min_y, max_y))
|
||||
|
||||
def offset(self, x_offset=0, y_offset=0):
|
||||
for p in self.primitives:
|
||||
p.offset(x_offset, y_offset)
|
||||
|
||||
@property
|
||||
def width(self):
|
||||
bounding_box = self.bounding_box()
|
||||
return bounding_box[0][1] - bounding_box[0][0]
|
||||
|
||||
@property
|
||||
def width(self):
|
||||
bounding_box = self.bounding_box()
|
||||
return bounding_box[1][1] - bounding_box[1][0]
|
||||
|
||||
|
||||
class Region(Primitive):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -152,6 +152,8 @@ class GerberContext(object):
|
|||
self._render_drill(primitive, self.drill_color)
|
||||
elif isinstance(primitive, AMGroup):
|
||||
self._render_amgroup(primitive, color)
|
||||
elif isinstance(primitive, Outline):
|
||||
self._render_region(primitive, color)
|
||||
elif isinstance(primitive, TestRecord):
|
||||
self._render_test_record(primitive, color)
|
||||
else:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue