summaryrefslogtreecommitdiff
path: root/gerber
diff options
context:
space:
mode:
authorPaulo Henrique Silva <ph.silva@gmail.com>2015-04-07 18:22:02 -0300
committerPaulo Henrique Silva <ph.silva@gmail.com>2015-04-07 18:22:02 -0300
commitb93804ed9a3400099afceacfe5a809ae8bded2a4 (patch)
tree572889ae424748dbb8e0d015aa42b76ca6b20c69 /gerber
parentb9b20a9644ca7b87493ca5786e2a25ecab132b75 (diff)
downloadgerbonara-b93804ed9a3400099afceacfe5a809ae8bded2a4.tar.gz
gerbonara-b93804ed9a3400099afceacfe5a809ae8bded2a4.tar.bz2
gerbonara-b93804ed9a3400099afceacfe5a809ae8bded2a4.zip
Add unspecified FS D leading zeros format
FS D leading zero format (probably form Direct) is an unspecified coordinate format where all numbers are specified with both leading and trailing zeros.
Diffstat (limited to 'gerber')
-rw-r--r--gerber/gerber_statements.py11
-rw-r--r--gerber/rs274x.py7
-rw-r--r--gerber/utils.py17
3 files changed, 21 insertions, 14 deletions
diff --git a/gerber/gerber_statements.py b/gerber/gerber_statements.py
index 99672de..39cecf2 100644
--- a/gerber/gerber_statements.py
+++ b/gerber/gerber_statements.py
@@ -97,7 +97,14 @@ class FSParamStmt(ParamStmt):
"""
"""
param = stmt_dict.get('param')
- zeros = 'leading' if stmt_dict.get('zero') == 'L' else 'trailing'
+
+ if stmt_dict.get('zero') == 'L':
+ zeros = 'leading'
+ elif stmt_dict.get('zero') == 'T':
+ zeros = 'trailing'
+ else:
+ zeros = 'none'
+
notation = 'absolute' if stmt_dict.get('notation') == 'A' else 'incremental'
fmt = tuple(map(int, stmt_dict.get('x')))
return cls(param, zeros, notation, fmt)
@@ -117,7 +124,7 @@ class FSParamStmt(ParamStmt):
Parameter.
zero_suppression : string
- Zero-suppression mode. May be either 'leading' or 'trailing'
+ Zero-suppression mode. May be either 'leading', 'trailing' or 'none' (all zeros are present)
notation : string
Notation mode. May be either 'absolute' or 'incremental'
diff --git a/gerber/rs274x.py b/gerber/rs274x.py
index a3a27e9..07fce17 100644
--- a/gerber/rs274x.py
+++ b/gerber/rs274x.py
@@ -139,12 +139,9 @@ class GerberParser(object):
NUMBER = r"[\+-]?\d+"
DECIMAL = r"[\+-]?\d+([.]?\d+)?"
STRING = r"[a-zA-Z0-9_+\-/!?<>”’(){}.\|&@# :]+"
- NAME = r"[a-zA-Z_$][a-zA-Z_$0-9]+"
- FUNCTION = r"G\d{2}"
+ NAME = r"[a-zA-Z_$\.][a-zA-Z_$\.0-9+\-]+"
- COORD_OP = r"D[0]?[123]"
-
- FS = r"(?P<param>FS)(?P<zero>(L|T))?(?P<notation>(A|I))X(?P<x>[0-7][0-7])Y(?P<y>[0-7][0-7])"
+ FS = r"(?P<param>FS)(?P<zero>(L|T|D))?(?P<notation>(A|I))X(?P<x>[0-7][0-7])Y(?P<y>[0-7][0-7])"
MO = r"(?P<param>MO)(?P<mo>(MM|IN))"
LP = r"(?P<param>LP)(?P<lp>(D|C))"
AD_CIRCLE = r"(?P<param>AD)D(?P<d>\d+)(?P<shape>C)[,]?(?P<modifiers>[^,]*)?"
diff --git a/gerber/utils.py b/gerber/utils.py
index 1c43550..df26516 100644
--- a/gerber/utils.py
+++ b/gerber/utils.py
@@ -54,7 +54,7 @@ def parse_gerber_value(value, format=(2, 5), zero_suppression='trailing'):
(number of integer-part digits, number of decimal-part digits)
zero_suppression : string
- Zero-suppression mode. May be 'leading' or 'trailing'
+ Zero-suppression mode. May be 'leading', 'trailing' or 'none'
Returns
-------
@@ -82,11 +82,14 @@ def parse_gerber_value(value, format=(2, 5), zero_suppression='trailing'):
if negative:
value = value.lstrip('-')
+ missing_digits = MAX_DIGITS - len(value)
- digits = list('0' * MAX_DIGITS)
- offset = 0 if zero_suppression == 'trailing' else (MAX_DIGITS - len(value))
- for i, digit in enumerate(value):
- digits[i + offset] = digit
+ if zero_suppression == 'trailing':
+ digits = list(value + ('0' * missing_digits))
+ elif zero_suppression == 'leading':
+ digits = list(('0' * missing_digits) + value)
+ else:
+ digits = list(value)
result = float(''.join(digits[:integer_digits] + ['.'] + digits[integer_digits:]))
return -result if negative else result
@@ -114,7 +117,7 @@ def write_gerber_value(value, format=(2, 5), zero_suppression='trailing'):
(number of integer-part digits, number of decimal-part digits)
zero_suppression : string
- Zero-suppression mode. May be 'leading' or 'trailing'
+ Zero-suppression mode. May be 'leading', 'trailing' or 'none'
Returns
-------
@@ -150,7 +153,7 @@ def write_gerber_value(value, format=(2, 5), zero_suppression='trailing'):
if zero_suppression == 'trailing':
while digits and digits[-1] == '0':
digits.pop()
- else:
+ elif zero_suppression == 'leading':
while digits and digits[0] == '0':
digits.pop(0)