You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Mar 10, 2019. It is now read-only.
If you're looking for an easy way to generate beautiful SVG renders of printed circuit boards, check out [pcb-stackup](https://github.com/tracespace/pcb-stackup) first.
12
10
13
-
This is the low-level module that powers the rendering of pcb-stackup. It takes individual printed circuit board layer converters as output by [gerber-to-svg](https://github.com/mcous/gerber-to-svg) and identified as PCB layer types by [whats-that-gerber](https://www.npmjs.com/package/whats-that-gerber) and uses them to build SVG renders of what the manufactured PCB will look like from the top and the bottom.
11
+
This is the low-level module that powers the rendering of pcb-stackup. It takes individual printed circuit board layer converters as output by [gerber-to-svg](https://github.com/mcous/gerber-to-svg) and identified as PCB layer types by [whats-that-gerber](https://www.npmjs.com/package/whats-that-gerber) and uses them to build SVG renders of what the manufactured PCB will look like from the top and the bottom.
This module is designed to work in Node or in the browser with Browserify or Webpack. The function takes two parameters: an array of layer objects and an options object. It returns an object with a `top` key and a `bottom` key, each of which contains the SVG element and various properties of the render.
35
+
This module is designed to work in Node or in the browser with Browserify or Webpack. The function takes two parameters: an array of layer objects and an options object. It returns an object with a `top` key and a `bottom` key, each of which contains the SVG element and various properties of the render.
38
36
39
-
```javascript
37
+
```javascript
40
38
var pcbStackupCore =require('pcb-stackup-core')
41
39
var options = {id:'my-board'}
42
40
var stackup =pcbStackupCore(layersArray, options)
@@ -74,10 +72,10 @@ The first parameter to the function is an array of layer objects. A layer object
74
72
75
73
It is expected that the converters will have already finished before being passed to pcb-stackup-core. This can be done by listening for the converter's `end` event or by using gerber-to-svg in callback mode, as shown in the example.
76
74
77
-
```javascript
75
+
```javascript
78
76
var topCopperLayer = {
79
77
type:GERBER_FILE_TYPE,
80
-
converter:FINISHED_GERBER_TO_SVG_CONVERTER
78
+
converter:FINISHED_GERBER_TO_SVG_CONVERTER,
81
79
}
82
80
```
83
81
@@ -89,11 +87,11 @@ If you will be displaying the individual layers in the same page as the board re
89
87
90
88
You can tell the stackup function that a layer is stored externally by giving it a layer with an `externalId` attribute. This should be set to the `id` attribute of the layer's external `<g>`. This will prevent the stackup function from pushing the converters defs to the stackup image defs node.
@@ -103,20 +101,20 @@ Please note that when using the `maskWithOutline` option as described below, the
103
101
104
102
The second parameter of the pcb-stackup-core function is an options object. The only required option is the `id` options. For ease, if no other options are being specified, the id string may be passed as the second parameter directly.
105
103
106
-
```javascript
104
+
```javascript
107
105
// stackup 1 and 2 are equivalent
108
106
var stackup1 =pcbStackupCore(layers, 'my-unique-board-id')
109
107
var stackup2 =pcbStackupCore(layers, {id:'my-unique-board-id'})
|color | see below | Colors to apply to the board render by layer type|
114
+
|maskWithOutline |`false`| Use the board outline layer as a mask for the board shape|
115
+
|createElement | see below | Function used to create the XML element nodes|
116
+
|includeNamespace |`true`| Whether or not to include the `xmlns` attribute in the top level SVG node|
117
+
|attributes |`{}`| Map of additional attributes (e.g. `class`) to apply to the SVG nodes|
120
118
121
119
#### id
122
120
@@ -128,50 +126,50 @@ This option is required and the function will throw if it is missing.
128
126
129
127
The color object allows the user to override the default styling of the stackup. It consists of layer identifiers as the keys and CSS colors as the values. Any to all layers may be overridden. The default color object is:
130
128
131
-
```javascript
129
+
```javascript
132
130
varDEFAULT_COLOR= {
133
131
fr4:'#666',
134
132
cu:'#ccc',
135
133
cf:'#c93',
136
134
sm:'rgba(0, 66, 0, 0.75)',
137
135
ss:'#fff',
138
136
sp:'#999',
139
-
out:'#000'
137
+
out:'#000',
140
138
}
141
139
```
142
140
143
141
The keys represent the following layers:
144
142
145
-
layer | component
146
-
------|------------------
147
-
fr4 | Substrate
148
-
cu | Copper
149
-
cf | Copper (finished)
150
-
sm | Soldermask
151
-
ss | Silkscreen
152
-
sp | Solderpaste
153
-
out | Board outline
143
+
|layer | component |
144
+
|-----|-----------------|
145
+
|fr4 | Substrate|
146
+
|cu | Copper|
147
+
|cf | Copper (finished)|
148
+
|sm | Soldermask|
149
+
|ss | Silkscreen|
150
+
|sp | Solderpaste|
151
+
|out | Board outline|
154
152
155
153
If a value is falsey (e.g. an empty string), the layer will not be added to the style node. This is useful if you want to add styles with an external stylesheet. If applying colors with an external stylesheet, use the following class-names and specify the `color` attribute:
|fr4 | id + `_fr4`|`.my-board_fr4 {color: #666;}`|
158
+
|cu | id + `_cu`|`.my-board_cu {color: #ccc;}`|
159
+
|cf | id + `_cf`|`.my-board_cf {color: #c93;}`|
160
+
|sm | id + `_sm`|`.my-board_sm {color: #rgba(0, 66, 0, 0.75);}`|
161
+
|ss | id + `_ss`|`.my-board_ss {color: #fff;}`|
162
+
|sp | id + `_sp`|`.my-board_sp {color: #999;}`|
163
+
|out | id + `_out`|`.my-board_out {color: #000;}`|
166
164
167
165
#### mask board shape with outline
168
166
169
167
When constructing the stackup, a `<mask>` of all the drill layers is built and applied to the final image to remove the image wherever there are drill hits. If the `maskWithOutline` option is passed as true, the stackup function will _also_ create a `<clipPath>` with the contents of any included outline layers, and use that to remove any part of the image that falls outside of the board outline.
|`false` (default) | Board shape is a rectangle that fits all layers|
172
+
|`true`| Board shape is the shape of the outline layer|
175
173
176
174
To work, the outline layer must be one or more fully-enclosed loops. If it isn't, setting `maskWithOutline` to true will likely result in the final image being incorrect (or non-existent), because the `<path>`s won't clip the image properly. See the [MDN's documentation of `<clipPath>`](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/clipPath) for more details.
177
175
@@ -181,35 +179,35 @@ To improve your chances of a board outline layer working for `maskWithOutline`,
181
179
182
180
Both gerber-to-svg and pcb-stackup-core take a `createElement` function as an option. It defaults to [xml-element-string](https://github.com/tracespace/xml-element-string), which outputs a string. However, any function that takes a tag name, attributes object, and children array may be used. For example, you could pass in [React.createElement](https://facebook.github.io/react/docs/top-level-api.html#react.createelement) and create virtual DOM nodes instead.
183
181
184
-
If you choose to use this option, the function you pass into pcb-stackup-core __must__ be the same one you passed into gerber-to-svg.
182
+
If you choose to use this option, the function you pass into pcb-stackup-core **must** be the same one you passed into gerber-to-svg.
185
183
186
184
The `includeNamespace` option specifies whether or not to include the `xmlns` attribute in the top level SVG node. Some VDOM implementations get angry when you pass the `xmlns` attribute, so you may need to set it to `false`.
187
185
188
186
#### attributes
189
187
190
188
If you want to add more attributes to the SVG nodes than are there by default, this is where you do it. For example, to add some classes:
191
189
192
-
```javascript
190
+
```javascript
193
191
var stackup =pcbStackupCore(layers, {
194
192
id:'board-id',
195
193
attributes: {
196
-
class:'w-100 h-100'
197
-
}
194
+
class:'w-100 h-100',
195
+
},
198
196
})
199
197
```
200
198
201
199
### layer types
202
200
203
201
The stackup can be made up of the following layer types:
204
202
205
-
layer type | abbreviation
206
-
-------------------------|--------------
207
-
top / bottom copper | tcu / bcu
208
-
top / bottom soldermask | tsm / bsm
209
-
top / bottom silkscreen | tss / bss
210
-
top / bottom solderpaste | tsp / bsp
211
-
board outline | out
212
-
drill hits | drl
203
+
|layer type | abbreviation|
204
+
|------------------------|------------|
205
+
|top / bottom copper | tcu / bcu|
206
+
|top / bottom soldermask | tsm / bsm|
207
+
|top / bottom silkscreen | tss / bss|
208
+
|top / bottom solderpaste | tsp / bsp|
209
+
|board outline | out |
210
+
|drill hits | drl |
213
211
214
212
## developing and contributing
215
213
@@ -219,12 +217,12 @@ Clone and then `$ npm install`. Please accompany all PRs with applicable tests.
219
217
220
218
This module uses [Mocha](http://mochajs.org/) and [Chai](http://chaijs.com/) for unit testing, [nyc](https://github.com/istanbuljs/nyc) for coverage, and [standard](http://standardjs.com) for linting.
221
219
222
-
*`$ npm test` - run the tests, calculate coverage, and lint
223
-
*`$ npm run test:watch` - run the tests on code changes (does not lint nor cover)
224
-
*`$ npm run coverage` - print the coverage report of the last test run
225
-
*`$ npm run coverage:html` - generate an html report for the last test run
226
-
*`$ npm run lint` - lint the code
227
-
*`$ npm run fix` - try and fix the linting errors in the code
220
+
-`$ npm test` - run the tests, calculate coverage, and lint
221
+
-`$ npm run test:watch` - run the tests on code changes (does not lint nor cover)
222
+
-`$ npm run coverage` - print the coverage report of the last test run
223
+
-`$ npm run coverage:html` - generate an html report for the last test run
224
+
-`$ npm run lint` - lint the code
225
+
-`$ npm run fix` - try and fix the linting errors in the code
228
226
229
227
### integration testing
230
228
@@ -237,5 +235,5 @@ The integration tests run the example code on a variety of gerber files to ensur
237
235
238
236
Browser tests are run with [Zuul](https://github.com/defunctzombie/zuul) and [Sauce Labs](https://saucelabs.com/opensauce/) on the latest two versions of Chrome, Firefox, Safari, and Internet Explorer, as well as the latest version of Edge.
239
237
240
-
*`$ npm run test:browser` - run the unit tests in a local browser
241
-
*`$ npm run test:sauce` - run the units tests in several browsers using Sauce Labs (free [Open Sauce account](https://saucelabs.com/opensauce/), free [ngrok account](https://ngrok.com/), and local [.zuulrc](https://github.com/defunctzombie/zuul/wiki/Zuulrc) required)
238
+
-`$ npm run test:browser` - run the unit tests in a local browser
239
+
-`$ npm run test:sauce` - run the units tests in several browsers using Sauce Labs (free [Open Sauce account](https://saucelabs.com/opensauce/), free [ngrok account](https://ngrok.com/), and local [.zuulrc](https://github.com/defunctzombie/zuul/wiki/Zuulrc) required)
0 commit comments