Negative Gerber converter
Convert copper lanes in Gerber format (e.g. from Fritzing) to a negative representation suitable for easy PCB CNC milling with rectangular routing.
Typically, Gerber files produce positive output layers, i.e. describe a PCB’s copper lanes to be exposed before etching. However, for PCB milling, one needs to represent the excess copper to be removed instead. Full layer inversion and thus large-area machining is not necessary though, as removing the copper layer outlines for insulation is enough.
Defining the insulation traces to be milled could be done by some graphical edge detection on the conductor layer, giving needlessly complicated CNC movements. Those can be minimized by algorithmically separating each copper lane from its neighbors by a single straight line only. That is why this tool will:
- Detect, merge, and consistently raster-align copper lanes and pads
- Trace border outlines in-between raster units, using only straight movements
- Heuristically optimize the output for longest straight lines and shortest idle positioning movement distances
Copper pads should be aligned according to the standard 2.54 raster and lanes should be straight and rectangularly routed, as exemplarily depicted below.
The resulting outlines to be milled are shown in black. For reference, the copper lane input layer and the drilling layer are shown as well.
Tracing copper lanes: Usage
Use the 64bit debian package provided below or build the binary for example with:
g++ -o pcb_gerber_trace main.cpp
Gerber files can then simply be converted using standard redirections:
./pcb_gerber_trace < in_copperBottom.gbl > out_copperBottom.gbl
loaded input with 121 pads, 104 lines
best 100 mil raster offset: 91x81 mil
aligned pads, max rounding error: -3 mil
ignored 3 duplicate pads
max. line rounding error: -3
converted to 720 rectangular border lines
added standalone pads, now 728 lines
postprocessing: coalesced to 156 lines
drawing lines: 156 busy movements (74200 mil), 97 idle movements (28152 mil)
done: success
Supported is Gerber RS-274-X input with absolute coordinates in inches/mil, as typically exported to e.g. by Fritzing.