summaryrefslogtreecommitdiff
path: root/gerbonara/gerber/rs274x.py
diff options
context:
space:
mode:
Diffstat (limited to 'gerbonara/gerber/rs274x.py')
-rw-r--r--gerbonara/gerber/rs274x.py21
1 files changed, 13 insertions, 8 deletions
diff --git a/gerbonara/gerber/rs274x.py b/gerbonara/gerber/rs274x.py
index 6d373ba..2f41684 100644
--- a/gerbonara/gerber/rs274x.py
+++ b/gerbonara/gerber/rs274x.py
@@ -35,7 +35,7 @@ import textwrap
import dataclasses
from .cam import CamFile, FileSettings
-from .utils import sq_distance, rotate_point, MM, Inch, units, InterpMode
+from .utils import sq_distance, rotate_point, MM, Inch, units, InterpMode, UnknownStatementWarning
from .aperture_macros.parse import ApertureMacro, GenericMacros
from . import graphic_primitives as gp
from . import graphic_objects as go
@@ -171,6 +171,7 @@ class GerberFile(CamFile):
return obj
def generate_statements(self, settings, drop_comments=True):
+ yield 'G04 Gerber file generated by Gerbonara*'
yield '%MOMM*%' if (settings.unit == 'mm') else '%MOIN*%'
zeros = 'T' if settings.zeros == 'trailing' else 'L' # default to leading if "None" is specified
@@ -182,9 +183,9 @@ class GerberFile(CamFile):
yield '%LPD*%'
if not drop_comments:
- yield 'G04 File processed by Gerbonara. Original comments:'
+ yield 'G04 Comments from original gerber file:*'
for cmt in self.comments:
- yield f'G04{cmt}'
+ yield f'G04{cmt}*'
# Always emit gerbonara's generic, rotation-capable aperture macro replacements for the standard C/R/O/P shapes.
# Unconditionally emitting these here is easier than first trying to figure out if we need them later,
@@ -453,7 +454,7 @@ class GerberParser:
'region_end': r'G37$',
'coord': fr"(?P<interpolation>G0?[123]|G74|G75)?(X(?P<x>{NUMBER}))?(Y(?P<y>{NUMBER}))?" \
fr"(I(?P<i>{NUMBER}))?(J(?P<j>{NUMBER}))?" \
- fr"(?P<operation>D0?[123])$",
+ fr"(?P<operation>D0?[123])?$",
'aperture': r"(G54|G55)?D(?P<number>\d+)",
'comment': r"G0?4(?P<comment>[^*]*)",
# Allegro combines format spec and unit into one long illegal extended command.
@@ -549,7 +550,7 @@ class GerberParser:
if (match := le_regex.match(line)):
#print(f' match: {name} / {match}')
try:
- getattr(self, f'_parse_{name}')(match.groupdict())
+ getattr(self, f'_parse_{name}')(match)
except:
print(f'Line {lineno}: {line}')
print(f' match: {name} / {match}')
@@ -558,7 +559,7 @@ class GerberParser:
break
else:
- warnings.warn(f'Unknown statement found: "{line}", ignoring.', SyntaxWarning)
+ warnings.warn(f'Unknown statement found: "{line}", ignoring.', UnknownStatementWarning)
self.target.comments.append(f'Unknown statement found: "{line}", ignoring.')
self.target.apertures = list(self.aperture_map.values())
@@ -580,8 +581,12 @@ class GerberParser:
elif match['interpolation'] == 'G75':
self.multi_quadrant_mode = False
- if match['interpolation'] in ('G74', 'G75') and match[0] != match['interpolation']:
- raise SyntaxError('G74/G75 combined with coord')
+ if match['interpolation'] in ('G74', 'G75'):
+ if match[0] == match['interpolation']:
+ return # nothing else to do
+
+ else:
+ raise SyntaxError('G74/G75 combined with coord')
x = self.file_settings.parse_gerber_value(match['x'])
y = self.file_settings.parse_gerber_value(match['y'])