www.delorie.com/archives/browse.cgi   search  
Mail Archives: geda-user/2015/12/28/21:49:08

X-Authentication-Warning: delorie.com: mail set sender to geda-user-bounces using -f
X-Recipient: geda-user AT delorie DOT com
From: geda AT psjt DOT org (Stephan =?utf-8?Q?B=C3=B6ttcher?=)
To: <geda-user AT delorie DOT com>
Subject: [geda-user] Gerber designrule checking with libgerbv and Clipper
References: <CAJXU7q-STU6GSxZSoes5DozwVVZunXCzWt8QVhU8iAXWwSt=dA AT mail DOT gmail DOT com>
<001a1134f920c49e910527d3a068 AT google DOT com>
<CAJXU7q-N=dNaK=3pV8t14pxDNFROqW4u4MjAc8EEWODmOYVYbA AT mail DOT gmail DOT com>
<s6n8u4frkhi DOT fsf AT blaulicht DOT dmz DOT brux>
<20151227173145 DOT 4f52bd9239ac5e14b8966e07 AT gmail DOT com>
<s6nio3jq19z DOT fsf AT blaulicht DOT dmz DOT brux>
Date: Tue, 29 Dec 2015 03:48:33 +0100
In-Reply-To: <s6nio3jq19z.fsf@blaulicht.dmz.brux> ("Stephan \=\?utf-8\?Q\?B\?\=
\=\?utf-8\?Q\?\=C3\=B6ttcher\=22's\?\=
message of "Sun, 27 Dec 2015 17:55:36 +0100")
Message-ID: <s6nr3i6hsvy.fsf_-_@blaulicht.dmz.brux>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)
MIME-Version: 1.0
X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id tBT2mmTU011744
Reply-To: geda-user AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: geda-user AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019