summaryrefslogtreecommitdiff
path: root/gerber
diff options
context:
space:
mode:
Diffstat (limited to 'gerber')
-rw-r--r--gerber/__main__.py1
-rwxr-xr-xgerber/excellon.py28
-rw-r--r--gerber/gerber.py25
3 files changed, 42 insertions, 12 deletions
diff --git a/gerber/__main__.py b/gerber/__main__.py
index ab0f377..1af4c0f 100644
--- a/gerber/__main__.py
+++ b/gerber/__main__.py
@@ -30,6 +30,7 @@ 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/excellon.py b/gerber/excellon.py
index 1a498dc..f5d6c29 100755
--- a/gerber/excellon.py
+++ b/gerber/excellon.py
@@ -30,6 +30,15 @@ import math
def read(filename):
""" Read data from filename and return an ExcellonFile
+ Parameters
+ ----------
+ filename : string
+ Filename of file to parse
+
+ Returns
+ -------
+ file : :class:`gerber.excellon.ExcellonFile`
+ An ExcellonFile created from the specified file.
"""
detected_settings = detect_excellon_format(filename)
settings = FileSettings(**detected_settings)
@@ -75,6 +84,14 @@ class ExcellonFile(CamFile):
def render(self, ctx, filename=None):
""" Generate image of file
+
+ Parameters
+ ----------
+ ctx : :class:`gerber.render.GerberContext`
+ GerberContext subclass used for rendering the image
+
+ filename : string <optional>
+ If provided, the rendered image will be saved to `filename`
"""
for tool, pos in self.hits:
ctx.drill(pos[0], pos[1], tool.diameter)
@@ -89,7 +106,7 @@ class ExcellonFile(CamFile):
class ExcellonParser(object):
""" Excellon File Parser
-
+
Parameters
----------
settings : FileSettings or dict-like
@@ -129,15 +146,15 @@ class ExcellonParser(object):
ymin = y if y < ymin else ymin
ymax = y if y > ymax else ymax
return ((xmin, xmax), (ymin, ymax))
-
+
@property
def hole_sizes(self):
return [stmt.diameter for stmt in self.statements if isinstance(stmt, ExcellonTool)]
-
+
@property
def hole_count(self):
return len(self.hits)
-
+
def parse(self, filename):
with open(filename, 'r') as f:
for line in f:
@@ -316,7 +333,7 @@ def detect_excellon_format(filename):
# Bail out here if we got everything....
if detected_format is not None and detected_zeros is not None:
return {'format': detected_format, 'zero_suppression': detected_zeros}
-
+
# Otherwise score each option and pick the best candidate
else:
scores = {}
@@ -338,4 +355,3 @@ def _layer_size_score(size, hole_count, hole_area):
hole_score = (hole_percentage - 0.25) ** 2
size_score = (board_area - 8) **2
return hole_score * size_score
- \ No newline at end of file
diff --git a/gerber/gerber.py b/gerber/gerber.py
index 215b970..335b443 100644
--- a/gerber/gerber.py
+++ b/gerber/gerber.py
@@ -15,12 +15,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
-"""
-Gerber File module
-==================
-**Gerber File module**
-
-This module provides an RS-274-X class and parser
+""" This module provides an RS-274-X class and parser.
"""
@@ -34,6 +29,16 @@ from .cam import CamFile, FileSettings
def read(filename):
""" Read data from filename and return a GerberFile
+
+ Parameters
+ ----------
+ filename : string
+ Filename of file to parse
+
+ Returns
+ -------
+ file : :class:`gerber.gerber.GerberFile`
+ A GerberFile created from the specified file.
"""
return GerberParser().parse(filename)
@@ -113,6 +118,14 @@ class GerberFile(CamFile):
def render(self, ctx, filename=None):
""" Generate image of layer.
+
+ Parameters
+ ----------
+ ctx : :class:`GerberContext`
+ GerberContext subclass used for rendering the image
+
+ filename : string <optional>
+ If provided, the rendered image will be saved to `filename`
"""
ctx.set_bounds(self.bounds)
for statement in self.statements: