145 lines
4.4 KiB
Markdown
145 lines
4.4 KiB
Markdown
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 loaded PCB data (original pcb-tools does not work in some condition)
|
|
- 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
|
|
```shell
|
|
$ pip install 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
|
|
|
|
### PCB Outline
|
|
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 ```draw_mode``` property. In this mode, All object except closed shapes listed below are ignored.
|
|
|
|
- circle
|
|
- closed polyline
|
|
- closed path which consists of lines and arcs
|
|
|
|
```python
|
|
import gerberex
|
|
|
|
dxf = gerberex.read('outline.dxf')
|
|
dxf.draw_mode = dxf.DM_FILL
|
|
dxf.write('outline.gml')
|
|
```
|
|
|
|
If you want to arrange simple rectangle for PCB outline, ```gerberex.rectangle()``` is better solution. This generate a object representing a rectangle compatible with DXF file object.<br>
|
|
|
|
```python
|
|
import gerberex
|
|
|
|
outline = gerberex.rectangle(width=100, height=100, units='metric')
|
|
outline.write('outline.gml')
|
|
```
|
|
|
|
### Mouse bites
|
|
|
|
<img alt="mouse bites" src="https://raw.githubusercontent.com/wiki/opiopan/pcb-tools-extension/images/mousebites.png" width=200 align="right">
|
|
|
|
|
|
If ```DM_MOUSE_BITES``` is specified for ```draw_mode```, filled circles are arranged along a DXF line object at equal intervals. <br>
|
|
DXF file object in this state can be merged to excellon file also. That means you can arrange mouse bites easily.
|
|
|
|
```python
|
|
import gerberex
|
|
|
|
ctx = gerberex.DrillComposition()
|
|
drill = gerberex.read('drill.txt')
|
|
ctx.merge(drill)
|
|
|
|
dxf = gerberex.read('mousebites.dxf')
|
|
dxf.draw_mode = dxf.DM_MOUSE_BITES
|
|
dxf.to_metric()
|
|
dxf.width = 0.5
|
|
dxf.pitch = 1
|
|
ctx.merge(dxf)
|
|
|
|
ctx.dump('merged_drill.txt')
|
|
```
|
|
|
|
## Panelizing Example
|
|
This example board image is generated by following scripts from [these source data](https://github.com/opiopan/pcb-tools-extension/tree/master/examples/inputs).
|
|
|
|
- [panelizing script](https://github.com/opiopan/pcb-tools-extension/blob/master/examples/panelize.py)
|
|
- [imaging script](https://github.com/opiopan/pcb-tools-extension/blob/master/examples/genimage.py)
|
|
|
|
<p align="center">
|
|
<img alt="description" src="https://raw.githubusercontent.com/wiki/opiopan/pcb-tools-extension/images/panelized.jpg" width=750>
|
|
</p>
|