X-Authentication-Warning: delorie.com: mail set sender to geda-user-bounces using -f X-Recipient: geda-user AT delorie DOT com X-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:subject:message-id:in-reply-to:references:mime-version :content-type:content-transfer-encoding; bh=DFT1A7/SUBw0ECHkJ/IRvuqxS28NKo+bXaLFL9EvoPg=; b=u9qQj5/RT+Z1dWozw4dnk2nDPx09QiCyb55hvOrScQmoZSgrdYYhPJVYIJ5SNwXzsa f9RTCJpxbU41CNgQIEUTUEiD0wWnuBgnIrfWGj0eupoMpgpRVBkPZk0jjXuJEyzoeNpy nx08meejiX53gFygasPZQChn8Zps9Y/UZZeiiyC1X4dHXTSiZYiuyPQ7NVdbiVgg6zQ8 ekS8lFXpX22aRNi/mty3FiwNmCqrH21R389+j4FzJREoBEPL7tCp3Q7KFB21ob6u25PR Nnl/nv2+zOti2lFgIJfJCG/VaGo0rB7H/oZWNw/XORMSQ62uhLoLZIldQgauTIjvcF34 onoQ== X-Received: by 10.28.22.199 with SMTP id 190mr21389774wmw.54.1451378416153; Tue, 29 Dec 2015 00:40:16 -0800 (PST) Date: Tue, 29 Dec 2015 09:40:14 +0100 From: "Nicklas Karlsson (nicklas DOT karlsson17 AT gmail DOT com) [via geda-user AT delorie DOT com]" To: geda-user AT delorie DOT com Subject: Re: [geda-user] Gerber designrule checking with libgerbv and Clipper Message-Id: <20151229094014.33731b1cbe1c3f48673c42ea@gmail.com> In-Reply-To: References: <001a1134f920c49e910527d3a068 AT google DOT com> <20151227173145 DOT 4f52bd9239ac5e14b8966e07 AT gmail DOT com> X-Mailer: Sylpheed 3.5.0beta1 (GTK+ 2.24.25; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id tBT8eM07016729 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 Precedence: bulk You are spot on! This is the way to do it. It should work equally if part of pcb. > > 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 >