Skip to content

Creates PCB stackup (top and bottom view) SVG renders given SVG objects as output by mcous/gerber-to-svg

License

Notifications You must be signed in to change notification settings

kasbah/pcb-stackup

 
 

Repository files navigation

pcb stackup

npm Travis Coveralls David David

This module takes individual printed circuit board layers output by gerber-to-svg and uses them to build SVG renders of what the manufactured PCB will look like from the top and the bottom.

Install with:

$ npm install pcb-stackup

usage

This module is designed to work in Node or in the browser with Browserify.

var pcbStackup = require('pcb-stackup');
var myBoardStackup = pcbStackup(layersArray, 'my-board');

input

The pcbStackup function takes two parameters: an array of layer objects and a board ID. The board ID is a string that is prepended to various IDs and class-names. A layer object is an object with a layer type and the SVG object output from gerber-to-svg:

var topCopperLayer = {
  type: 'tcu',
  svg: {svg: {...}}
};

output

The function will output an object containing two keys: 'top' and 'bottom'. Both keys refer to an SVG object that can be run through gerberToSvg to obtain an SVG string of the top and bottom render, respectively. The SVG will be unstyled, but each component of the stackup has a class you can use to color it appropriately:

component classname
Substrate ID + '_board-fr4'
Copper (masked) ID + '_board-cu'
Copper (finished) ID + '_board-cf'
Soldermask ID + '_board-sm'
Silkscreen ID + '_board-ss'
Solderpaste ID + '_board-sp'

The classnames have the board ID prefixed so that, if you inline a stylesheet, the styles won't leak (as they are wont to do with inline stylesheets) to other PCB renders on the page.

layer types

For each type of PCB layer, this module expects a three character abbreviation:

layer type abbreviation
top / inner / bottom copper tcu / icu / bcu
top / bottom soldermask tsm / bsm
top / bottom silkscreen tss / bss
top / bottom solderpaste tsp / bsp
board outline out
drill hits drl
generic drawing drw

As a convenience, this module contains a function to try to identify a layer type by its filename using common naming patterns from various EDA packages (Eagle, KiCad, Orcad, and Altium). For example:

var idLayer = require('pcb-stackup/lib/layer-types').identify;
var filename = "some-project-F_Cu.gbr";
var layerType = idLayer(filename);

console.log(layerType); // logs 'tcu'

stackup example

var fs = require('fs');
var gerberToSvg = require('gerber-to-svg');
var pcbStackup = require('pcb-stackup');
var idLayer = require('pcb-stackup/lib/layer-types').identify;

var gerbersPaths = [
  'path/to/board-F_Cu.gbr',
  'path/to/board-F_Mask.gbr',
  'path/to/board-F_SilkS.gbr',
  'path/to/board-F_Paste.gbr',
  'path/to/board-B_Cu.gbr',
  'path/to/board-B_Mask.gbr',
  'path/to/board-B_SilkS.gbr',
  'path/to/board-B_Paste.gbr',
  'path/to/board-Edge_Cuts.gbr',
  'path/to/board.drl'
];
var layers = [];

gerberPaths.forEach(function(filename) {
  var gerberString = fs.readFileSync(filename, 'utf-8');
  var layerType = idLayer(filename);
  var options = {object: true, drill: (layerType === 'drl')};
  var svgObj = gerberToSvg(gerberString, options);

  layers.push({type: layerType, svg: svgObj});
});

var stackup = pcbStackup(layers, 'my-board');
fs.writeFileSync('path/to/top.svg', gerberToSvg(stackup.top));
fs.writeFileSync('path/to/bottom.svg', gerberToSvg(stackup.bottom));

developing

This module is written in CoffeeScript and uses Make to manage building and testing.

  • $ make - build the JavaScript
  • $ make clean - delete the JavaScript lib folder
  • $ make watch - watch the source and recompile on changes
  • $ make test - run the unit tests
  • $ make test-watch - run the unit tests and rerun on changes
  • $ make test-phantom - run the unit tests in PhantomJS
  • $ make test-browsers - run the unit tests on SauceLabs
  • $ make lint - lint the source and tests

contributing

Please ensure all feature and bug-fix pull-requests include unit tests. There is a pre-commit hook that will automatically lint, compile, and add any changed lib files to the commit. Files in lib are source-controlled so you can npm install the module from GitHub.

About

Creates PCB stackup (top and bottom view) SVG renders given SVG objects as output by mcous/gerber-to-svg

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • CoffeeScript 98.3%
  • Makefile 1.7%