pcb-rnd knowledge pool


Padstack implementation details

padstack_imp by Tibor 'Igor2' Palinkas on 2017-11-04

Tags: dev, padstack, via, pin, hole, pad

node source



Abstract: Some basic implementation details about padstacks, for developers.

  A padstack put on a board is really just a reference to a padstack prototype, sort of "copy that prototype to this x;y location, with this rotation angle and mirror it". The prototypes are kept in a transparent cache.

Since prototypes have to be retrieved during drawing, the above process shall be fast. It would be suboptimal to perform the rotation and mirroring on each draw. Instead, each rotated/mirrored ("transformed") version ever referenced are kept in the cache and are referenced directly by the padstack reference. These tranformed variants are not saved in files but are always generated runtime, upon the first request. If the shape needs to be changed, e.g. bloat or shrink, all the cached tranformed variants need to go under the same operation.

The non-transformed version of each prototype is called the "canonical form" and is saved/loaded on file IO. (Padstacks are obviously accessible only in our native format at the moment; later on alien formats that also support some sort of pad stacks will catch up; we are not going to change the .pcb format, tho, so padstacks will not be available there)

A low level of the padstack code uses a hash algorithm for being able to rapidly detect if the canonical variant of a prototype to be added already presents in the cache - if so the, duplicate is not added, but the existing item is referenced.