summaryrefslogtreecommitdiff
path: root/test/data/merge.py
blob: b3b50d6c9bc058f05d16632d20f2a403f34046d8 (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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python
import os
import gerberex
from gerberex.dxf import DxfFile

exts = ['GTL', 'GTO', 'GTP', 'GTS', 'GBL', 'GBO', 'GBP', 'GBS', 'TXT']
boards=[
    ('../../sonopi-digi/pcb/CAMOutputs/sonopi-digi.', 0, 0),
    ('../../sonopi-digi/pcb/CAMOutputs/sonopi-digi.', 0, 22.5),
    ('../../rcstick-f/pcb/small/CAMOutputs/rcstick-f-small.', 0, 60),
    ('../../rcstick-f/pcb/small/CAMOutputs/rcstick-f-small.', 20, 60),
    ('../../rcstick-f/pcb/small/CAMOutputs/rcstick-f-small.', 40, 60),
    ('../../rcstick-f/pcb/large/CAMOutputs/rcstick-f.', 72.4, 0),
    ('../../rcstick-f/pcb/jig/CAMOutputs/rcstick-jig.', 0, 44),
    ('../../stm32breakout/pcb/CAMOutputs/stm32breakout.', 78.0, 59.36),
    ('../../stm32breakout/pcb/CAMOutputs/stm32breakout.', 100.0, 59.36),
]
outline = 'outline.dxf'
fill = 'fill.dxf'

outputs = 'outputs/elecrow-panelized'

os.chdir(os.path.dirname(__file__))

for ext in exts:
    print('merging %s: ' % ext ,end='', flush=True)
    if ext == 'TXT':
        ctx = gerberex.DrillComposition()
    else:
        ctx = gerberex.GerberComposition()
    for board in boards:
        file = gerberex.read(board[0] + ext)
        file.to_metric()
        file.offset(board[1], board[2])
        ctx.merge(file)
        print('.', end='', flush=True)
    if ext != 'TXT':
        file = gerberex.read(outline)
        ctx.merge(file)
    ctx.dump(outputs + '.' + ext)
    print(' end', flush=True)

print('generating GML: ', end='', flush=True)
file = gerberex.read(outline)
file.write(outputs + '.GML')
print('.', end='', flush=True)
file = gerberex.read(fill)
file.to_metric()
file.draw_mode = DxfFile.DM_FILL
file.write(outputs + '-fill.GML')
print('. end', flush=True)