From 07d279f89faefde4793ae2de4d3a629dc87da63e Mon Sep 17 00:00:00 2001 From: jaseg Date: Sat, 22 Jan 2022 22:00:04 +0100 Subject: Fix last test failures --- gerbonara/gerber/aperture_macros/primitive.py | 16 ++++++++-------- gerbonara/gerber/apertures.py | 2 +- gerbonara/gerber/rs274x.py | 7 ++++--- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/gerbonara/gerber/aperture_macros/primitive.py b/gerbonara/gerber/aperture_macros/primitive.py index 7832960..13f462f 100644 --- a/gerbonara/gerber/aperture_macros/primitive.py +++ b/gerbonara/gerber/aperture_macros/primitive.py @@ -204,27 +204,27 @@ class Outline(Primitive): if len(args) > 5004: raise ValueError(f'Invalid aperture macro outline primitive, too many points ({len(args)//2-2}).') - self.exposure = args[0] + self.exposure = args.pop(0) # length arg must not contain variables (that would not make sense) - length_arg = args[1].calculate() + length_arg = args.pop(0).calculate() - if length_arg != len(args)//2 - 2: - raise ValueError(f'Invalid aperture macro outline primitive, given size does not match length of coordinate list({len(args)}).') + if length_arg != len(args)//2-1: + raise ValueError(f'Invalid aperture macro outline primitive, given size {length_arg} does not match length of coordinate list({len(args)//2-1}).') - if len(args) % 1 != 1: + if len(args) % 2 == 1: self.rotation = args.pop() else: self.rotation = ConstantExpression(0.0) - if args[2] != args[-2] or args[3] != args[-1]: + if args[0] != args[-2] or args[1] != args[-1]: raise ValueError(f'Invalid aperture macro outline primitive, polygon is not closed {args[2:4], args[-3:-1]}') - self.coords = [(UnitExpression(x, unit), UnitExpression(y, unit)) for x, y in zip(args[1::2], args[2::2])] + self.coords = [(UnitExpression(x, unit), UnitExpression(y, unit)) for x, y in zip(args[0::2], args[1::2])] def to_gerber(self, unit=None): coords = ','.join(coord.to_gerber(unit) for xy in self.coords for coord in xy) - return f'{self.code},{self.exposure.to_gerber()},{len(self.coords)//2-1},{coords},{self.rotation.to_gerber()}' + return f'{self.code},{self.exposure.to_gerber()},{len(self.coords)-1},{coords},{self.rotation.to_gerber()}' def to_graphic_primitives(self, offset, rotation, variable_binding={}, unit=None): with self.Calculator(self, variable_binding, unit) as calc: diff --git a/gerbonara/gerber/apertures.py b/gerbonara/gerber/apertures.py index 1e6c555..1b5aa2e 100644 --- a/gerbonara/gerber/apertures.py +++ b/gerbonara/gerber/apertures.py @@ -77,7 +77,7 @@ class Aperture: #print(f'aperture to gerber {self.unit=} {settings=} {unit=}') actual_inst = self._rotated() params = 'X'.join(f'{float(par):.4}' for par in actual_inst.params(unit) if par is not None) - return f'{actual_inst.gerber_shape_code},{params}' + return ','.join((actual_inst.gerber_shape_code, params)) def __eq__(self, other): # We need to choose some unit here. diff --git a/gerbonara/gerber/rs274x.py b/gerbonara/gerber/rs274x.py index 401047f..50de8ca 100644 --- a/gerbonara/gerber/rs274x.py +++ b/gerbonara/gerber/rs274x.py @@ -579,7 +579,8 @@ class GerberParser: elif match['interpolation'] == 'G75': self.multi_quadrant_mode = False - if match['interpolation'] in ('G74', 'G75') and (match['x'] or match['y'] or match['i'] or match['j']): + has_coord = (match['x'] or match['y'] or match['i'] or match['j']) + if match['interpolation'] in ('G74', 'G75') and has_coord: raise SyntaxError('G74/G75 combined with coord') x = self.file_settings.parse_gerber_value(match['x']) @@ -587,12 +588,12 @@ class GerberParser: i = self.file_settings.parse_gerber_value(match['i']) j = self.file_settings.parse_gerber_value(match['j']) - if not (op := match['operation']): + if not (op := match['operation']) and has_coord: if self.last_operation == 'D01': warnings.warn('Coordinate statement without explicit operation code. This is forbidden by spec.', SyntaxWarning) op = 'D01' - elif match['x'] or match['y'] or match['i'] or match['j']: + else: raise SyntaxError('Ambiguous coordinate statement. Coordinate statement does not have an operation '\ 'mode and the last operation statement was not D01.') -- cgit