Skip to main content

Extension for pcb-tools package to panelize gerber files

Project description

pcb-tools-extension

pcb-tools-extension is a Python library to panelize gerber files. This library is designed based on 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 PCB data

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

Installation

You can install a stable version by following step.

$ pip install pcb-tools-extension

If you have a intention to try latest developing version, please install as follows.

$ pip install git+https://github.com/opiopan/pcb-tools-extension.git

How to panelize

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

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.
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.

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.
This function is useful to generate outline data of pnanelized PCB boad.

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.

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.
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
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.

import gerberex

outline = gerberex.rectangle(width=100, height=100, units='metric')
outline.write('outline.gml')

Mouse bites

mouse bites

If DM_MOUSE_BITES is specified for draw_mode, filled circles are arranged along a DXF line object at equal intervals.
DXF file object in this state can be merged to excellon file also. That means you can arrange mouse bites easily.

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.

description

Notes

Equivalence of output

pcb-tools-extension generate data block stream to focus equivalence of final image, but not focus equivalence of data block sequence. There are some difference between input data and output data as below.

  • File Scope Modifier [RS-274x]
    Sometimes, commands that affect entire image and should be specified only once in a file, such as MI (Mirror Image) command, cause contradiction when multiple gerber file are merged.
    For example, when mergeing a file containing %MIA1B0*% command and a file containing %MIA0B1* command, which command should remain as output? Of cause, it is impossible that generate correct merged image by specifiing any MI command.
    pcb-tools-extension translate coordinate data reflecting these file socpe modifier to address this probrem, then ommit these modifier command.
    MI, OF, SF, AS, IP, and IR are in a this category.

  • Coodinate Normalizing [RS-274x, Excellon]
    RS-274x specification and Excellon specification allow various notation to express a coordinate. However pcb-tools-extension normalize coordinate notation in order to correct deprecated notation and ease internal process as below.

    • Relative coordinates are translated to absolute coordinates.
    • Ommited coordinate values are compensated.
    • Leading zeros are ommited.
  • Unimportant Command [RS-274x, Excellon]
    Commands not affecting final image such as comment are ommited.

Negative image polarity

Sometimes, %IPNEG*% is specified at header of RS-274x file to create negative image.
As mentioned above, IP command is ommited when pcb-tools-extension generate output file. In this case, image polarity is nagated by using LP command. However this generated file doesn't equal to original file since it does'nt contain base dark image.
Please merge base dark rectangle explicitly when you handle negative image file as below.

import gerberex

ctx = gerberex.GerberComposition()
base = gerberex.rectangle(width=30, height=30, left=-5, bottom=-5, units='metric')
base.draw_mode = base.DM_FILL
ctx.merge(base)
metal = gerberex.read('negative_image.gtl')
ctx.merge(metal)

Limitations

RS-274x

pcb-tools-extension cannot handle all commands that the RS-274x parser implemented in pcb-tool doesn't handle so far.
From the imaging point of view, pcb-tools-extension has following limitations.

  • Files contains IJ and IO commands, that affect entire image, cannot be handled correctly.
  • Files contains SR command to specify repeated pattern cannot be handled correctly.
  • Aperture block defined by AB command cannot be handled correctly.

Excellon

pcb-tools-extension extends excellon parser in pcb-tool to support routing operation. However following limitations still remain.

  • User defined stored pattern defined by M99 command cannot be handled.
  • Canned text specified by M97 command cannot be handled.
  • Patten defined by M25 command cannot be handled.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for pcb-tools-extension, version 0.9.0
Filename, size File type Python version Upload date Hashes
Filename, size pcb_tools_extension-0.9.0-py3-none-any.whl (28.9 kB) File type Wheel Python version py3 Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page