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.
This commit is contained in:
parent
b9b20a9644
commit
b93804ed9a
3 changed files with 21 additions and 14 deletions
|
|
@ -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'
|
||||
|
|
|
|||
|
|
@ -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>[^,]*)?"
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue