diff options
author | jaseg <git@jaseg.de> | 2021-06-13 15:00:17 +0200 |
---|---|---|
committer | jaseg <git@jaseg.de> | 2021-06-13 15:00:17 +0200 |
commit | 4eb0e063bcd34c21b737023aa6ed5baed80658d1 (patch) | |
tree | 3a56ef7d05f4f64cde930f2432119986e4aab49d /gerbonara/gerber/panelize/common.py | |
parent | 889ea37d9b66cbfb7a61795c7750b9f4311faa3f (diff) | |
download | gerbonara-4eb0e063bcd34c21b737023aa6ed5baed80658d1.tar.gz gerbonara-4eb0e063bcd34c21b737023aa6ed5baed80658d1.tar.bz2 gerbonara-4eb0e063bcd34c21b737023aa6ed5baed80658d1.zip |
Repo re-org, make gerberex tests run
Diffstat (limited to 'gerbonara/gerber/panelize/common.py')
-rw-r--r-- | gerbonara/gerber/panelize/common.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/gerbonara/gerber/panelize/common.py b/gerbonara/gerber/panelize/common.py new file mode 100644 index 0000000..03bf9b0 --- /dev/null +++ b/gerbonara/gerber/panelize/common.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# Copyright 2019 Hiroshi Murayama <opiopan@gmail.com> + +import os +from ..common import loads as loads_org +from ..exceptions import ParseError +from ..utils import detect_file_format +from .. import rs274x +from .. import ipc356 + +from . import rs274x as ex_rs274x +from . import excellon +from . import 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 dxf.loads(data, filename) + + fmt = detect_file_format(data) + if fmt == 'rs274x': + file = ex_rs274x.loads(data, filename=filename) + return ex_rs274x.GerberFile.from_gerber_file(file) + elif fmt == 'excellon': + return 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 dxf.DxfFile.rectangle( + width, height, left, bottom, units, draw_mode, filename) |