summaryrefslogtreecommitdiff
path: root/README.md
blob: d44593e3f495c734728ae38b7802670f5f9b3efb (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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
PCB tools extension
===
PCB tools extension is a Python library to panelize gerber files.
This library is designed based on [PCB tools](https://github.com/curtacircuitos/pcb-tools) which provides cool functionality to handle PCB such as generationg PCB image from gerber files.

PCB tools extension adds following function  to PCB tools.

- Rotate PCB data
- Write back loded PCB data (original PCB tools does not work completely)
- Merge multiple PCB data
- Translate DXF file to gerber data

Only RS-274x format and Excellon drill format data can be handled by current version of this library.

## Install
PCB tools extension is not registerd to PyPI repository.<br>
Please install from GitHub repository as below.
```shell
$ pip install git+https://github.com/opiopan/pcb-tools-extension
```

## How to panelize
Following code is a example to panelize two top metal layer files.

``` python
import gerberex

ctx = gerberex.GerberComposition()

metal1 = gerberex.read('board1.gtl')
ctx.merge(metal1)

metal2 = gerberex.read('board2.gtl')
metal2.to_metric()
metal2.rotate(-20)
metal2.offset(30, 0)
ctx.merge(metal2)

ctx.dump('panelized-board.gtl')
```

```rotate()``` method can be used to rotate PCB data counterclockwise. you have to specify angle in degree<br>
```offset()``` method can be used to move PCB data. Specified offset values are interpreted according to unit setting of PCB data. In case of the above code, ```board2.gtl``` move to 30mm left since ```to_metric()``` is called.

In case of Excellon drill data, you have to use ```DrillCompositon``` instead of ```GerberComposition```.

```python
import gerberex

ctx = gerberex.DrillComposition()

drill1 = gerberex.read('board1.txt')
ctx.merge(drill1)

drill2 = gerberex.read('board2.txt')
drill2.to_metric()
drill2.rotate(-20)
drill2.offset(30, 0)
ctx.merge(drill2)

ctx.dump('panelized-board.txt')
```

## DXF file translation
You can also load a dxf file and handle that as same as RX-274x gerber file.<br>
This function is useful to generate outline data of pnanelized PCB boad.

```python
import gerberex

ctx = gerberex.GerberComposition()
dxf = gerberex.read('outline.dxf')
ctx.merge(dxf)
```
Circle object, Arc object, Line object and Polyline object are supported. Other kind of objects in DXF file are ignored when translating to gerber data.

You can specify line width (default 0). PCB tools extension will translate DXF primitive shape to RX-274x line or arc sequense using circle aperture with diamater as same as specified line width.<br>

```python
import gerberex

dxf = gerberex.read('outline.dxf')
dxf.to_inch()
dxf.width = 0.004
dxf.write('outline.gml')
```

You can also translate DXF closed shape such as circle to RX-274x polygon fill sequence.<br>
In order to fill closed shape, ```DM_FILL``` has to be set to ```drawing_mode``` property. In this mode, All object except circle and closed polyline will be ignored.<br>

```python
import gerberex

dxf = gerberex.read('outline.dxf')
dxf.draw_mode = gerberex.DxfFile.DM_FILL
dxf.write('outline.gml')
```

## Panelized board image Example
This image is generated by original [PCB tools](https://github.com/curtacircuitos/pcb-tools) fucntion.

<p align="center">
<img alt="description" src="https://raw.githubusercontent.com/wiki/opiopan/pcb-tools-extension/images/panelized.jpg" width=750>
</p>