summaryrefslogtreecommitdiff
path: root/gerberex/common.py
diff options
context:
space:
mode:
authorjaseg <git@jaseg.de>2021-06-06 13:28:42 +0200
committerjaseg <git@jaseg.de>2021-06-06 13:28:42 +0200
commit889ea37d9b66cbfb7a61795c7750b9f4311faa3f (patch)
tree34db36bcdf0501445aaec30c845ed644537e638a /gerberex/common.py
parent5a5ba2b709f01b2100cd767a25a41737541ad53c (diff)
parent71c371ca680483aa9ef18d2998832460dd43abdf (diff)
downloadgerbonara-889ea37d9b66cbfb7a61795c7750b9f4311faa3f.tar.gz
gerbonara-889ea37d9b66cbfb7a61795c7750b9f4311faa3f.tar.bz2
gerbonara-889ea37d9b66cbfb7a61795c7750b9f4311faa3f.zip
Graft pcb-tools-extension master onto gerbonara main
Diffstat (limited to 'gerberex/common.py')
-rw-r--r--gerberex/common.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/gerberex/common.py b/gerberex/common.py
new file mode 100644
index 0000000..6e8a832
--- /dev/null
+++ b/gerberex/common.py
@@ -0,0 +1,40 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# Copyright 2019 Hiroshi Murayama <opiopan@gmail.com>
+
+import os
+from gerber.common import loads as loads_org
+from gerber.exceptions import ParseError
+from gerber.utils import detect_file_format
+import gerber.rs274x
+import gerber.ipc356
+import gerberex.rs274x
+import gerberex.excellon
+import gerberex.dxf
+
+def read(filename, format=None):
+ with open(filename, 'rU') as f:
+ data = f.read()
+ return loads(data, filename, format=format)
+
+
+def loads(data, filename=None, format=None):
+ if os.path.splitext(filename if filename else '')[1].lower() == '.dxf':
+ return gerberex.dxf.loads(data, filename)
+
+ fmt = detect_file_format(data)
+ if fmt == 'rs274x':
+ file = gerberex.rs274x.loads(data, filename=filename)
+ return gerberex.rs274x.GerberFile.from_gerber_file(file)
+ elif fmt == 'excellon':
+ return gerberex.excellon.loads(data, filename=filename, format=format)
+ elif fmt == 'ipc_d_356':
+ return ipc356.loads(data, filename=filename)
+ else:
+ raise ParseError('Unable to detect file format')
+
+
+def rectangle(width, height, left=0, bottom=0, units='metric', draw_mode=None, filename=None):
+ return gerberex.dxf.DxfFile.rectangle(
+ width, height, left, bottom, units, draw_mode, filename)