summaryrefslogtreecommitdiff
path: root/gerbonara/gerber/panelize/common.py
blob: aa3ba0e3b4f8e13cab6b4a848d8a970d0c409548 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/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 excellon

def read(filename, format=None):
    with open(filename, 'r') 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 == '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)