pcb-rnd knowledge pool
History: how the old element model was broken
old_elem by Tibor 'Igor2' Palinkas on 2017-05-30
Tags: insight, history, historic, element, footprint, subcircuit, rewrite, data, model
Abstract: What problems we had with the old element model inherited from PCB and how we got rid of these problems with the subcircuit upgrade.
old model: pcb elements (pre-2017)
There are a lot of feature requests out there about extending the footprint model. A few random example:
- polygon in footprint, 2009, 2010 http://archives.seul.org/geda/user/Sep-2010/msg00619.html http://archives.seul.org/geda/user/Jun-2009/msg00370.html
- arc in footprint, 2010: http://archives.seul.org/geda/user/Apr-2010/msg00613.html
- how to work around missing mask editing feature in footprints, 2004: https://firstname.lastname@example.org&q=subject:%22Re%3A+gEDA-user%3A+PCB%3A+how+to+clear+soldermask+from+entire+footprint%22&o=newest&f=1
It would be possible to add code just for these cases. However, each such example would introduce a new set of special cases in the code base, and these cases will always interact with almost all other such specil cases. Which means an exponential growth in special case vs. sepcial case interaction that would be rather hard to maintain long term. This is not the route we take in pcb-rnd.
Generally speaking, the problem is that our footprint model is a bag of special cases: footprints can have the special objects, for example:
- element-line, but that's only lines drawn on silk
- (smd) pad, which can't have arbitrary shape and must be on top or bottom copper
- pin, which is basically just an "element-via", with some pin number and pin name attached; mostly code dup of via plus code dup from smd pads for the number/name
- exactly 3 silk text objects, from which only 1 can be dispalyed at any given time (refdes, footprint description, value)
- a bunch of automatic side effects, like mask and paste on smd pads
There are some clever hacks to work around some of the limitations, usually by combining pads and pins. But this is not building from pure, orthogonal bricks, but building from fuzzy haystacks, mainly trying to combine and cancel side effects. I know this "works", I know we do this since forever, but this is far from the optimal solution.
new model: subcircuits (from mid 2017)
I am going to slowly replace this old mechanism in pcb-rnd with a new system called "subcircuits". From the user's point of view, a subcircuit takes the same role as a "footprint" (... in a lib, or "element", when placed on a board - as of gEDA/pcb terminology).
A subcircuit does not have special objects like "pins", "pads" or "element-lines". Instead, it has the same objects that the layout has: lines, arcs, polygons, text and vias. (In fact I am going to use the same C struct that the board uses, which is pcb_data_t in pcb-rnd).
Trick #1: flexible layer handling
Just like a board, a subcircuit also has a layer stack. When the subcircuit is a footprint, this layer stack is not a particular physical stack, rather a recipe. E.g. instead of fixed layer numbers, this stack would contain patterns like "this layer should be in the top copper physical layer on the board". It could indirectly reference any physical layer: copper, silk, mask, paste, outline; top, bottom or even inner layers. Once the subcircuit is placed on a board with an actual physicla layer stack, the layer binding is performed: with or without interactive user intervention, using the layer stack recipe, each layer the subcircuit uses is boud to one of the actual layers of the board.
Trick #2: flexible terminal handling
Just like in tEDAx, pins/pads are no special objects but plain drawing primitives tagged for a given terminal. Terminal is the "pin number, pin name" concept. A multiple vias, lines, arcs, polygons or even text objects can be tagged to be part of a terminal. The netlist sees terminals only.
In practice this means our new footprints will be capable of hosting:
- arbitrary shaped pads drawn as lines and polygons
- arbitrary shaped copper objects not being pads; a.k.a. pcb antenne; but this includes copper text or mask cutout text too; your company logo can really be a footprint
- arbitrary mask cutouts, mask cutouts that are not derived from pads
- arbitrary placement of paste; want a grid of paste blobbs on the center pad of your largish qfn? no need t emulate it with 10 pads, just draw them on the paste layer
- slots or other cutouts/edge-contour-patterns; even the whole board shape can be a footprint
- text and polygon on silk
This section is of historic interest only - we have implemented most of these already.
This will probably take a long time, spanning multiple development cyclces, just like the layer rewrite did.
We will start implementing it in the current cycle and will make it gradually grow until it reaches its full featured, final form. We will make sure that at every intermediate release subcircuits are usable and alreayd provide extra features over footprints. We will keep the original footprints in place during this process.
Lihata board v3 will have support for subcircuits. The subcircuit subtree will also be avaialble as a subcircuit file format for sharing footprints.
While we are in this stage, we'll encourage users to use subcricuits instead of footprints, and always save in lihata board v3 instead of other formats. However, the code will still be able to use the old footprints in parallel.
At some point in time subcircuits will be capable enough to replace footprints. At this point we will remove footprints, pins, pads, element-lines, element-arcs. We will also need to rewrite import code to convert old elements to subcricuits on load and rewrite export code to convert subcircuits back to elements for old formats.
We'll convert pcblib from the old, element based .fp files to lihata subcircuit files. We'll rewrite the parametric footprint scripts to generate lihata subcircuits instead of pcb elements. This will include extending some of the parametrics with features that was not possible with pcb elements because of the limitaiton of the model/format.
(This also means our parametric footprints won't be available for pcb mainline without a conversion or without mainline upgraded to lihata formats and the subcircuit model)