summaryrefslogtreecommitdiff
path: root/gerber/excellon.py
diff options
context:
space:
mode:
authorPaulo Henrique Silva <ph.silva@gmail.com>2015-01-26 00:20:01 -0200
committerPaulo Henrique Silva <ph.silva@gmail.com>2015-01-26 00:20:01 -0200
commit2586692a1700dcdcae65ed8342e36bb0dd01c166 (patch)
tree4528822d7187b2215a91e18361950ce608ccf569 /gerber/excellon.py
parentd5157c1d076360e3702a910f119b9fc44ff76df5 (diff)
parent939f782728a1b16f85ad2697b03ef026a88ad354 (diff)
downloadgerbonara-2586692a1700dcdcae65ed8342e36bb0dd01c166.tar.gz
gerbonara-2586692a1700dcdcae65ed8342e36bb0dd01c166.tar.bz2
gerbonara-2586692a1700dcdcae65ed8342e36bb0dd01c166.zip
Merge pull request #7 from curtacircuitos/zeros_convention
Zeros convention
Diffstat (limited to 'gerber/excellon.py')
-rwxr-xr-xgerber/excellon.py31
1 files changed, 16 insertions, 15 deletions
diff --git a/gerber/excellon.py b/gerber/excellon.py
index 17b870a..79a6e1f 100755
--- a/gerber/excellon.py
+++ b/gerber/excellon.py
@@ -43,7 +43,9 @@ def read(filename):
An ExcellonFile created from the specified file.
"""
- return ExcellonParser(None).parse(filename)
+ # File object should use settings from source file by default.
+ settings = FileSettings(**detect_excellon_format(filename))
+ return ExcellonParser(settings).parse(filename)
class ExcellonFile(CamFile):
@@ -116,7 +118,7 @@ class ExcellonParser(object):
def __init__(self, settings=None):
self.notation = 'absolute'
self.units = 'inch'
- self.zero_suppression = 'leading'
+ self.zeros = 'leading'
self.format = (2, 4)
self.state = 'INIT'
self.statements = []
@@ -126,7 +128,7 @@ class ExcellonParser(object):
self.pos = [0., 0.]
if settings is not None:
self.units = settings.units
- self.zero_suppression = settings.zero_suppression
+ self.zeros = settings.zeros
self.notation = settings.notation
self.format = settings.format
@@ -207,7 +209,7 @@ class ExcellonParser(object):
elif 'INCH' in line or 'METRIC' in line:
stmt = UnitStmt.from_excellon(line)
self.units = stmt.units
- self.zero_suppression = stmt.zero_suppression
+ self.zeros = stmt.zeros
self.statements.append(stmt)
elif line[:3] == 'M71' or line [:3] == 'M72':
@@ -270,8 +272,7 @@ class ExcellonParser(object):
def _settings(self):
return FileSettings(units=self.units, format=self.format,
- zero_suppression=self.zero_suppression,
- notation=self.notation)
+ zeros=self.zeros, notation=self.notation)
def detect_excellon_format(filename):
@@ -293,7 +294,7 @@ def detect_excellon_format(filename):
results = {}
detected_zeros = None
detected_format = None
- zs_options = ('leading', 'trailing', )
+ zeros_options = ('leading', 'trailing', )
format_options = ((2, 4), (2, 5), (3, 3),)
# Check for obvious clues:
@@ -301,7 +302,7 @@ def detect_excellon_format(filename):
p.parse(filename)
# Get zero_suppression from a unit statement
- zero_statements = [stmt.zero_suppression for stmt in p.statements
+ zero_statements = [stmt.zeros for stmt in p.statements
if isinstance(stmt, UnitStmt)]
# get format from altium comment
@@ -316,19 +317,19 @@ def detect_excellon_format(filename):
# Bail out here if possible
if detected_format is not None and detected_zeros is not None:
- return {'format': detected_format, 'zero_suppression': detected_zeros}
+ return {'format': detected_format, 'zeros': detected_zeros}
# Only look at remaining options
if detected_format is not None:
format_options = (detected_format,)
if detected_zeros is not None:
- zs_options = (detected_zeros,)
+ zeros_options = (detected_zeros,)
# Brute force all remaining options, and pick the best looking one...
- for zs in zs_options:
+ for zeros in zeros_options:
for fmt in format_options:
- key = (fmt, zs)
- settings = FileSettings(zero_suppression=zs, format=fmt)
+ key = (fmt, zeros)
+ settings = FileSettings(zeros=zeros, format=fmt)
try:
p = ExcellonParser(settings)
p.parse(filename)
@@ -351,7 +352,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}
+ return {'format': detected_format, 'zeros': detected_zeros}
# Otherwise score each option and pick the best candidate
else:
@@ -362,7 +363,7 @@ def detect_excellon_format(filename):
minscore = min(scores.values())
for key in scores.iterkeys():
if scores[key] == minscore:
- return {'format': key[0], 'zero_suppression': key[1]}
+ return {'format': key[0], 'zeros': key[1]}
def _layer_size_score(size, hole_count, hole_area):