Select Git revision
-
Neil Gershenfeld authoredNeil Gershenfeld authored
gerber 4.04 KiB
//
// path to Gerber
//
// Neil Gershenfeld
// (c) Massachusetts Institute of Technology 2021
//
// This work may be reproduced, modified, distributed, performed, and
// displayed for any purpose, but must acknowledge the mods
// project. Copyright is retained and must be preserved. The work is
// provided as is; no warranty is provided, and users accept all
// liability.
//
// closure
//
(function(){
//
// module globals
//
var mod = {}
//
// name
//
var name = 'path to Gerber'
//
// initialization
//
var init = function() {
mod.fill.checked = true
}
//
// inputs
//
var inputs = {
imageInfo:{type:'',
event:function(evt){
mod.imageInfo = evt.detail
}},
path:{type:'',
event:function(evt){
mod.path = evt.detail
}}}
//
// outputs
//
var outputs = {
Gerber:{type:'',
event:function(evt){
mods.output(mod,'Gerber',evt)
}}}
//
// interface
//
var interface = function(div){
mod.div = div
var btn = document.createElement('button')
btn.style.padding = mods.ui.padding
btn.style.margin = 1
btn.appendChild(document.createTextNode('plot'))
btn.addEventListener('click',function(){
plot()
})
div.appendChild(btn)
div.appendChild(document.createElement('br'))
div.appendChild(document.createTextNode('format:'))
div.appendChild(document.createElement('br'))
var formats = document.createElement('div');
formats.style.textAlign = 'left'
var input = document.createElement('input')
input.type = 'radio'
input.name = mod.div.id+'format'
input.id = mod.div.id+'fill'
formats.appendChild(input)
mod.fill = input
formats.appendChild(document.createTextNode('fill'))
formats.appendChild(document.createElement('br'))
var input = document.createElement('input')
input.type = 'radio'
input.name = mod.div.id+'format'
input.id = mod.div.id+'outline'
input.disabled = true
formats.appendChild(input)
mod.outline = input
formats.appendChild(document.createTextNode('outline'))
formats.appendChild(document.createElement('br'))
var input = document.createElement('input')
input.type = 'radio'
input.name = mod.div.id+'format'
input.id = mod.div.id+'outline'
input.disabled = true
formats.appendChild(input)
mod.drill = input
formats.appendChild(document.createTextNode('drill'))
div.appendChild(formats)
}
//
// local functions
//
function format(x) {
var s = x.toFixed(6)
s = s.substr(0,s.length-7)+s.substr(-6,6)
return s
}
//
function plot() {
var imgwidth = mod.imageInfo.width/parseFloat(mod.imageInfo.dpi)
var imgheight = mod.imageInfo.height/parseFloat(mod.imageInfo.dpi)
//
str = ''
str += "%MOIN*%\n" // inch units
str += "%LPD*%\n" // layer dark
str += "%FSLAX66Y66*%\n" // format absolute 6.6
//
var x,y
for (var seg = 0; seg < mod.path.length; ++seg) {
str += "G36*\n"
x = imgwidth*mod.path[seg][0][0]/(mod.imageInfo.width-1)
y = imgheight*mod.path[seg][0][1]/(mod.imageInfo.height-1)
str += 'X'+format(x)+'Y'+format(y)+'D02*\n'
for (var pt = 1; pt < mod.path[seg].length; ++pt) {
var x = imgwidth*mod.path[seg][pt][0]/(mod.imageInfo.width-1)
var y = imgheight*mod.path[seg][pt][1]/(mod.imageInfo.height-1)
str += 'X'+format(x)+'Y'+format(y)+'D01*\n'
}
x = imgwidth*mod.path[seg][0][0]/(mod.imageInfo.width-1)
y = imgheight*mod.path[seg][0][1]/(mod.imageInfo.height-1)
str += 'X'+format(x)+'Y'+format(y)+'D01*\n'
str += "G37*\n"
}
str += "M02*\n"
//
var obj = {}
obj.type = 'file'
obj.name = mod.imageInfo.name+'.gbr'
//var xml = new XMLSerializer().serializeToString(str)
//obj.contents = xml
obj.contents = str
outputs.Gerber.event(obj)
}
/*
%ADD11C,0.1*%
%LPC*%
G01*
D11*
X1000Y1000D02*
X1000Y2000D01*
X2000Y2000D01*
X1500Y1000D01*
M02*
*/
//
// return values
//
return ({
mod:mod,
name:name,
init:init,
inputs:inputs,
outputs:outputs,
interface:interface
})
}())