GithubHelp home page GithubHelp logo

kasbah / pcb-stackup Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tracespace/tracespace

0.0 3.0 0.0 623 KB

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

License: Other

Makefile 1.67% CoffeeScript 98.33%

pcb-stackup's Introduction

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.

pcb-stackup's People

Contributors

mcous avatar kasbah avatar

Watchers

 avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.