summaryrefslogtreecommitdiff
path: root/gerbonara/tests/resources/zuken-emulated/scripts/zukenka_gerber.py
diff options
context:
space:
mode:
authorjaseg <git@jaseg.de>2022-02-06 01:10:17 +0100
committerjaseg <git@jaseg.de>2022-02-06 01:10:17 +0100
commit263617ca754fc7b3fc550a33934fcbcbe5ef8acf (patch)
tree48bee309f4311a030cae5ed518d6499a93edfb8b /gerbonara/tests/resources/zuken-emulated/scripts/zukenka_gerber.py
parent5c4e18031623207b31855ff58be6b4c907962474 (diff)
downloadgerbonara-263617ca754fc7b3fc550a33934fcbcbe5ef8acf.tar.gz
gerbonara-263617ca754fc7b3fc550a33934fcbcbe5ef8acf.tar.bz2
gerbonara-263617ca754fc7b3fc550a33934fcbcbe5ef8acf.zip
Add Zuken tests and fix parsing
Diffstat (limited to 'gerbonara/tests/resources/zuken-emulated/scripts/zukenka_gerber.py')
-rw-r--r--gerbonara/tests/resources/zuken-emulated/scripts/zukenka_gerber.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/gerbonara/tests/resources/zuken-emulated/scripts/zukenka_gerber.py b/gerbonara/tests/resources/zuken-emulated/scripts/zukenka_gerber.py
new file mode 100644
index 0000000..b3f9f51
--- /dev/null
+++ b/gerbonara/tests/resources/zuken-emulated/scripts/zukenka_gerber.py
@@ -0,0 +1,49 @@
+#!/usr/bin/env python3
+#
+# Mess up a Gerber file to look like it was generated by Zuken CR-8000.
+# Only meant to work with KiCAD Gerber files.
+#
+
+import re
+
+def map_line(line):
+ # strip layer polarity statement at start of header
+ if line == '%LPD*%':
+ return ''
+
+ # Replace end of aperture list comment with empty line and layer polarity statement
+ if line == 'G04 APERTURE END LIST*':
+ return '\n%LPD*%\n' # this is the last newline in this file
+
+ # strip comments
+ if line.startswith('G04'):
+ return ''
+
+ # add G54 prefix to aperture selection statements
+ if re.fullmatch(r'D[1-9][0-9]\*', line):
+ return f'G54{line}'
+
+ # make flash statements more complicated
+ if (m := re.fullmatch(r'(.*)D03\*', line)):
+ return f'{m[1]}D02*G55D03*'
+
+ # replace M02 EOF with M00 EOF, and insert X0Y0D02
+ if line == 'M02*':
+ return 'X0Y0D02*M00*'
+
+ # Merge G01/02/03 with following coordinate
+ if line in ('G01*', 'G02*', 'G03*'):
+ return line[:-1]
+
+ # Preserve line endings for header lines
+ if any(line.startswith(cmd) for cmd in ('%FS', '%MO', '%AD')):
+ return f'{line}\n'
+
+ return line
+
+def zukenka(data):
+ return ''.join(map_line(line) for line in data.splitlines())
+
+if __name__ == '__main__':
+ import sys
+ print(zukenka(sys.stdin.read()))