Mail Archives: geda-user/2015/12/28/21:49:08
Moin,
A tool to perform DRC on Gerber files.
This new project is working for me now. Not much documentation yet, but
it's not a lot of code, and includes a test case.
http://www.psjt.org/code/
http://www.psjt.org/code/drc
http://www.psjt.org/code/drc.tar.gz
The Clipper library can do polygon operations, including offsetting. I
am using the C++ version.
http://angusj.com/delphi/clipper.php
Libgerbv is used to read Gerber and drill files into Clipper polygons,
and to write Clipper polygons to Gerber files. I needed to patch
gerbv a bit:
http://www.psjt.org/code/drc/gerbv-create-polygon.patch
* utility functions to create libgerbv polygons
* implement gerbv_image_create_rectangle_object() using those
functions
* fix a buf in gerbv_export_rs274x_file_from_image() (pointer lifetime)
Clipper is also patched to make it accept a single point as a polygon,
that can then be offset into a circle.
http://www.psjt.org/code/drc/polyclipping-degenerate-ploynoms.patch
All that is wrapped into Python bindings.
As I said, it works for me, but I don't know why. I know next to
nothing about Gerber, and I looked at the Gerbv code just enough to make
it do what I want. The Gerber export is broken as soon as there are
holes in the exported polygons. Most DRC violations don't have holes,
and when they do, they are drawn without.
Four generic tests are included in the main program. The idea is that
special tests can be easily added by the user, in Python.
Here's a screenshot with some clearance and width violations:
http://www.psjt.org/code/drc/screenshot.png
* minimum drill size.
- shrink the drill layer by the minimum radius
- rebloat the layer
- subtract the rebloated layer from the drill layer
Small holes will be lost when shrinking and remain on the result layer.
* minimum annular ring size.
- bloat the plated drill layer
- subtract the routing layer
What is left is missing annular ring
* minimum trace width.
This one gives false positives at pointy
angles. Those can be reduced with a --min_area parameter.
- shring the routing layer by half the trace width
- rebloat the layer
- subtract the rebloatd layer from the routing layer
- discard violations smaller that min_area
When a trace is to thin it will be lost while shrinking, and the
subtraction leaves the original trace in place.
The bloating uses circle segments at the corners. So there will be
a small remaining area in all corners. The check has a min_area
parameter, all residue smaller than this area will be discarded.
* minimun clearance.
This test is slow, because it works on each
individual outer shape of the routing layer.
- bloat the shape
- compute the intersection of the bloated shape with the rest of the
layer
Anything left is a clearance violation.
Next steps: write a script that extracts center coordinates of pins and
pads, netnames and layer names from a pcb file, and find a way to import
that for net-specific rules.
Stephan
geda AT psjt DOT org (Stephan Böttcher) writes:
>>> I am playing with the idea to build a DRC tool that works on the gerber
>>> output, using libgerbv and the clipper library (C++)
>>>
>>> http://angusj.com/delphi/clipper.php
>>>
>>> I have made Python bindings for importing gerbers into clipper polygon
>>> data structures, perform bloating/shrinking and clipping operations.
>>>
>>> Design rules would be specified as boolean operations on suitably bloated
>>> layer data, and anything left in the end is a violation.
>>>
>>> An example that I have working now:
>>>
>>> from pyclipper import Clipper, gerbv, OffsetPolygons
>>> proj = gerbv.project()
>>> proj.load("v01.front.gbr")
>>> proj.load("v01.plated-drill.cnc")
>>> scale=10000
>>> raw = proj[0].polygons(scale)
>>> drill = proj[1].polygons(scale)
>>> clip = Clipper()
>>> clip.clear()
>>> clip.addsubject(raw)
>>> # clean up, and remove keyholes
>>> routing = OffsetPolygons(clip.union(),1)
>>> # require 12 mil annuklar rings
>>> annular = OffsetPolygons(drill, 120)
>>> clip.clear()
>>> clip.addsubject(annular)
>>> clip.addclip(routing)
>>> annular = clip.difference()
>>>
>>> Any polygon left in annular is a violation.
>>>
>>> For net specific rules I'd need to add some input that gives for each
>>> net at least one coordinate (per relevant layer). And some code to find
>>> the polygon at the given coordinate. Some rules, like clearance checks,
>>> require iterations over the individual ploygons in a layer. At that
>>> point they could be tagged with a netname by the given coordinates. And
>>> then there could be overrides of bloat values for specifiv nets.
>>>
>>> I plot the ploygons with gnuplot right now. A gerber export may be
>>> usefull to visualize the violations in gerbv. Or some gui.
>>
>> Great!
>>
>> I think your work will would be useful within pcb to.
>>
>> Simple scale will give a little bit to large distance value in outer
>> corner, attached picture, there need to be a circle segment but it
>> could be fixed later at any point and to large distance is usually
>> less of a problem than to small distance.
>
> Currently my Python bindings only support circle segments, but the
> Clipper library can do other corner handling as well :-)
>
>> Nicklas Karlsson
--
Stephan
- Raw text -