summaryrefslogtreecommitdiff
path: root/gerber
diff options
context:
space:
mode:
Diffstat (limited to 'gerber')
-rw-r--r--gerber/__main__.py1
-rw-r--r--gerber/common.py4
-rwxr-xr-xgerber/excellon.py3
-rw-r--r--gerber/render/render.py19
-rw-r--r--gerber/render/svgwrite_backend.py7
-rw-r--r--gerber/rs274x.py (renamed from gerber/gerber.py)29
6 files changed, 41 insertions, 22 deletions
diff --git a/gerber/__main__.py b/gerber/__main__.py
index 1af4c0f..ab0f377 100644
--- a/gerber/__main__.py
+++ b/gerber/__main__.py
@@ -30,7 +30,6 @@ if __name__ == '__main__':
print "parsing %s" % filename
gerberfile = read(filename)
gerberfile.render(ctx)
- ctx.set_color(tuple([color * 0.4 for color in ctx.color]))
print('Saving image to test.svg')
ctx.dump('test.svg')
diff --git a/gerber/common.py b/gerber/common.py
index 0092ec8..6e8c862 100644
--- a/gerber/common.py
+++ b/gerber/common.py
@@ -30,12 +30,12 @@ def read(filename):
CncFile object representing the file, either GerberFile or
ExcellonFile. Returns None if file is not an Excellon or Gerber file.
"""
- import gerber
+ import rs274x
import excellon
from utils import detect_file_format
fmt = detect_file_format(filename)
if fmt == 'rs274x':
- return gerber.read(filename)
+ return rs274x.read(filename)
elif fmt == 'excellon':
return excellon.read(filename)
else:
diff --git a/gerber/excellon.py b/gerber/excellon.py
index f5d6c29..13aacc6 100755
--- a/gerber/excellon.py
+++ b/gerber/excellon.py
@@ -39,6 +39,7 @@ def read(filename):
-------
file : :class:`gerber.excellon.ExcellonFile`
An ExcellonFile created from the specified file.
+
"""
detected_settings = detect_excellon_format(filename)
settings = FileSettings(**detected_settings)
@@ -317,7 +318,7 @@ def detect_excellon_format(filename):
hole_area = 0.0
for hit in p.hits:
tool = hit[0]
- hole_area += math.pow(math.pi * tool.diameter, 2)
+ hole_area += math.pow(math.pi * tool.diameter / 2., 2)
results[key] = (size, p.hole_count, hole_area)
except:
pass
diff --git a/gerber/render/render.py b/gerber/render/render.py
index 48a53f8..f7e4485 100644
--- a/gerber/render/render.py
+++ b/gerber/render/render.py
@@ -83,6 +83,9 @@ class GerberContext(object):
background_color : tuple (<float>, <float>, <float>)
Color of the background. Used when exposing areas in 'clear' level
polarity mode. Format is the same as for `color`.
+
+ alpha : float
+ Rendering opacity. Between 0.0 (transparent) and 1.0 (opaque.)
"""
def __init__(self):
self.settings = {}
@@ -100,7 +103,8 @@ class GerberContext(object):
self.color = (0.7215, 0.451, 0.200)
self.drill_color = (0.25, 0.25, 0.25)
self.background_color = (0.0, 0.0, 0.0)
-
+ self.alpha = 1.0
+
def set_format(self, settings):
""" Set source file format.
@@ -260,6 +264,19 @@ class GerberContext(object):
"""
self.background_color = color
+ def set_alpha(self, alpha):
+ """ Set layer rendering opacity
+
+ .. note::
+ Not all backends/rendering devices support this parameter.
+
+ Parameters
+ ----------
+ alpha : float
+ Rendering opacity. must be between 0.0 (transparent) and 1.0 (opaque)
+ """
+ self.alpha = alpha
+
def resolve(self, x, y):
""" Resolve missing x or y coordinates in a coordinate command.
diff --git a/gerber/render/svgwrite_backend.py b/gerber/render/svgwrite_backend.py
index 886b4f8..78961da 100644
--- a/gerber/render/svgwrite_backend.py
+++ b/gerber/render/svgwrite_backend.py
@@ -117,6 +117,7 @@ class GerberSvgContext(GerberContext):
self.apertures = {}
self.dwg = svgwrite.Drawing()
+ self.dwg.transform = 'scale 1 -1'
self.background = False
self.region_path = None
@@ -124,11 +125,17 @@ class GerberSvgContext(GerberContext):
xbounds, ybounds = bounds
size = (SCALE * (xbounds[1] - xbounds[0]), SCALE * (ybounds[1] - ybounds[0]))
if not self.background:
+ self.dwg = svgwrite.Drawing(viewBox='%f, %f, %f, %f' % (SCALE*xbounds[0], -SCALE*ybounds[1],size[0], size[1]))
self.dwg.add(self.dwg.rect(insert=(SCALE * xbounds[0],
-SCALE * ybounds[1]),
size=size, fill=convert_color(self.background_color)))
self.background = True
+ def set_alpha(self, alpha):
+ super(GerberSvgContext, self).set_alpha(alpha)
+ import warnings
+ warnings.warn('SVG output does not support transparency')
+
def define_aperture(self, d, shape, modifiers):
aperture = None
if shape == 'C':
diff --git a/gerber/gerber.py b/gerber/rs274x.py
index 335b443..4076f77 100644
--- a/gerber/gerber.py
+++ b/gerber/rs274x.py
@@ -37,7 +37,7 @@ def read(filename):
Returns
-------
- file : :class:`gerber.gerber.GerberFile`
+ file : :class:`gerber.rs274x.GerberFile`
A GerberFile created from the specified file.
"""
return GerberParser().parse(filename)
@@ -91,24 +91,19 @@ class GerberFile(CamFile):
ybounds = [0.0, 0.0]
for stmt in [stmt for stmt in self.statements
if isinstance(stmt, CoordStmt)]:
- if stmt.x is not None and stmt.x < xbounds[0]:
- xbounds[0] = stmt.x
- if stmt.x is not None and stmt.x > xbounds[1]:
- xbounds[1] = stmt.x
- if stmt.i is not None and stmt.i < xbounds[0]:
- xbounds[0] = stmt.i
- if stmt.i is not None and stmt.i > xbounds[1]:
- xbounds[1] = stmt.i
- if stmt.y is not None and stmt.y < ybounds[0]:
- ybounds[0] = stmt.y
- if stmt.y is not None and stmt.y > ybounds[1]:
- ybounds[1] = stmt.y
- if stmt.j is not None and stmt.j < ybounds[0]:
- ybounds[0] = stmt.j
- if stmt.j is not None and stmt.j > ybounds[1]:
- ybounds[1] = stmt.j
+ if stmt.x is not None:
+ if stmt.x < xbounds[0]:
+ xbounds[0] = stmt.x
+ elif stmt.x > xbounds[1]:
+ xbounds[1] = stmt.x
+ if stmt.y is not None:
+ if stmt.y < ybounds[0]:
+ ybounds[0] = stmt.y
+ elif stmt.y > ybounds[1]:
+ ybounds[1] = stmt.y
return (xbounds, ybounds)
+
def write(self, filename):
""" Write data out to a gerber file
"""