summaryrefslogtreecommitdiff
path: root/gerber/render
diff options
context:
space:
mode:
authorHamilton Kibbe <hamilton.kibbe@gmail.com>2014-09-28 21:17:13 -0400
committerHamilton Kibbe <hamilton.kibbe@gmail.com>2014-09-28 21:17:13 -0400
commit3a5dbcf1e13704b7352d5fb3c4777d7df3fed081 (patch)
treef138c8e1503dfff6d1eae69f1ddb6b802420478f /gerber/render
parent695e3d9220be8773f6630bb5c512d122b8576742 (diff)
downloadgerbonara-3a5dbcf1e13704b7352d5fb3c4777d7df3fed081.tar.gz
gerbonara-3a5dbcf1e13704b7352d5fb3c4777d7df3fed081.tar.bz2
gerbonara-3a5dbcf1e13704b7352d5fb3c4777d7df3fed081.zip
added ExcellonFile class
Diffstat (limited to 'gerber/render')
-rw-r--r--gerber/render/apertures.py9
-rw-r--r--gerber/render/render.py12
-rw-r--r--gerber/render/svg.py50
3 files changed, 34 insertions, 37 deletions
diff --git a/gerber/render/apertures.py b/gerber/render/apertures.py
index 55e6a30..f163b1f 100644
--- a/gerber/render/apertures.py
+++ b/gerber/render/apertures.py
@@ -29,7 +29,7 @@ class Aperture(object):
"""
def draw(self, ctx, x, y):
raise NotImplementedError('The draw method must be implemented in an Aperture subclass.')
-
+
def flash(self, ctx, x, y):
raise NotImplementedError('The flash method must be implemented in an Aperture subclass.')
@@ -40,19 +40,22 @@ class Circle(Aperture):
def __init__(self, diameter=0.0):
self.diameter = diameter
+
class Rect(Aperture):
""" Rectangular Aperture base class
"""
def __init__(self, size=(0, 0)):
self.size = size
+
class Obround(Aperture):
""" Obround Aperture base class
"""
def __init__(self, size=(0, 0)):
self.size = size
-
+
+
class Polygon(Aperture):
""" Polygon Aperture base class
"""
- pass \ No newline at end of file
+ pass
diff --git a/gerber/render/render.py b/gerber/render/render.py
index e15a36f..c372783 100644
--- a/gerber/render/render.py
+++ b/gerber/render/render.py
@@ -34,11 +34,11 @@ class GerberContext(object):
level_polarity = 'dark'
def __init__(self):
- pass
+ pass
def set_format(self, settings):
self.settings = settings
-
+
def set_coord_format(self, zero_suppression, format, notation):
self.settings['zero_suppression'] = zero_suppression
self.settings['format'] = format
@@ -52,9 +52,9 @@ class GerberContext(object):
def set_image_polarity(self, polarity):
self.image_polarity = polarity
-
+
def set_level_polarity(self, polarity):
- self.level_polarity = polarity
+ self.level_polarity = polarity
def set_interpolation(self, interpolation):
self.interpolation = 'linear' if interpolation in ("G01", "G1") else 'arc'
@@ -63,8 +63,8 @@ class GerberContext(object):
self.aperture = d
def resolve(self, x, y):
- return x or self.x, y or self.y
-
+ return x or self.x, y or self.y
+
def define_aperture(self, d, shape, modifiers):
pass
diff --git a/gerber/render/svg.py b/gerber/render/svg.py
index b16e534..7d5c8fd 100644
--- a/gerber/render/svg.py
+++ b/gerber/render/svg.py
@@ -33,8 +33,8 @@ class SvgCircle(Circle):
def flash(self, ctx, x, y):
return [ctx.dwg.circle(center=(x * SCALE, -y * SCALE),
- r = SCALE * (self.diameter / 2.0),
- fill='rgb(184, 115, 51)'),]
+ r = SCALE * (self.diameter / 2.0),
+ fill='rgb(184, 115, 51)'), ]
class SvgRect(Rect):
@@ -47,41 +47,42 @@ class SvgRect(Rect):
def flash(self, ctx, x, y):
xsize, ysize = self.size
return [ctx.dwg.rect(insert=(SCALE * (x - (xsize / 2)),
- -SCALE * (y + (ysize / 2))),
- size=(SCALE * xsize, SCALE * ysize),
- fill="rgb(184, 115, 51)"),]
+ -SCALE * (y + (ysize / 2))),
+ size=(SCALE * xsize, SCALE * ysize),
+ fill="rgb(184, 115, 51)"), ]
+
class SvgObround(Obround):
def draw(self, ctx, x, y):
pass
-
+
def flash(self, ctx, x, y):
xsize, ysize = self.size
-
+
# horizontal obround
if xsize == ysize:
return [ctx.dwg.circle(center=(x * SCALE, -y * SCALE),
- r = SCALE * (x / 2.0),
- fill='rgb(184, 115, 51)'),]
+ r = SCALE * (x / 2.0),
+ fill='rgb(184, 115, 51)'), ]
if xsize > ysize:
rectx = xsize - ysize
recty = ysize
lcircle = ctx.dwg.circle(center=((x - (rectx / 2.0)) * SCALE,
- -y * SCALE),
+ -y * SCALE),
r = SCALE * (ysize / 2.0),
fill='rgb(184, 115, 51)')
-
+
rcircle = ctx.dwg.circle(center=((x + (rectx / 2.0)) * SCALE,
- -y * SCALE),
+ -y * SCALE),
r = SCALE * (ysize / 2.0),
fill='rgb(184, 115, 51)')
-
+
rect = ctx.dwg.rect(insert=(SCALE * (x - (xsize / 2.)),
-SCALE * (y + (ysize / 2.))),
size=(SCALE * xsize, SCALE * ysize),
fill='rgb(184, 115, 51)')
- return [lcircle, rcircle, rect,]
-
+ return [lcircle, rcircle, rect, ]
+
# Vertical obround
else:
rectx = xsize
@@ -90,18 +91,18 @@ class SvgObround(Obround):
(y - (recty / 2.)) * -SCALE),
r = SCALE * (xsize / 2.),
fill='rgb(184, 115, 51)')
-
+
ucircle = ctx.dwg.circle(center=(x * SCALE,
(y + (recty / 2.)) * -SCALE),
r = SCALE * (xsize / 2.),
fill='rgb(184, 115, 51)')
-
+
rect = ctx.dwg.rect(insert=(SCALE * (x - (xsize / 2.)),
-SCALE * (y + (ysize / 2.))),
size=(SCALE * xsize, SCALE * ysize),
fill='rgb(184, 115, 51)')
- return [lcircle, ucircle, rect,]
-
+ return [lcircle, ucircle, rect, ]
+
class GerberSvgContext(GerberContext):
def __init__(self):
@@ -112,10 +113,9 @@ class GerberSvgContext(GerberContext):
#self.dwg.add(self.dwg.rect(insert=(0, 0), size=(2000, 2000), fill="black"))
def set_bounds(self, bounds):
- xbounds, ybounds = bounds
+ xbounds, ybounds = bounds
size = (SCALE * (xbounds[1] - xbounds[0]), SCALE * (ybounds[1] - ybounds[0]))
self.dwg.add(self.dwg.rect(insert=(SCALE * xbounds[0], -SCALE * ybounds[1]), size=size, fill="black"))
-
def define_aperture(self, d, shape, modifiers):
aperture = None
@@ -133,8 +133,7 @@ class GerberSvgContext(GerberContext):
if self.interpolation == 'linear':
self.line(x, y)
elif self.interpolation == 'arc':
- #self.arc(x, y)
- self.line(x,y)
+ self.arc(x, y)
def line(self, x, y):
super(GerberSvgContext, self).line(x, y)
@@ -145,11 +144,9 @@ class GerberSvgContext(GerberContext):
self.dwg.add(ap.draw(self, x, y))
self.move(x, y, resolve=False)
-
def arc(self, x, y):
super(GerberSvgContext, self).arc(x, y)
-
def flash(self, x, y):
super(GerberSvgContext, self).flash(x, y)
x, y = self.resolve(x, y)
@@ -160,12 +157,9 @@ class GerberSvgContext(GerberContext):
self.dwg.add(shape)
self.move(x, y, resolve=False)
-
def drill(self, x, y, diameter):
hit = self.dwg.circle(center=(x*SCALE, -y*SCALE), r=SCALE*(diameter/2.0), fill='gray')
self.dwg.add(hit)
def dump(self, filename):
self.dwg.saveas(filename)
-
-