Commit e2a16fb8 authored by Neil Gershenfeld's avatar Neil Gershenfeld
Browse files

Excellon working?

parent 9e8c1f4c
......@@ -84,7 +84,6 @@ var interface = function(div){
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'))
......@@ -93,37 +92,44 @@ var interface = function(div){
//
// local functions
//
function format(x) {
function gformat(x) {
// 6.6 omit leading
var s = x.toFixed(6)
s = s.substr(0,s.length-7)+s.substr(-6,6)
return s
}
//
function eformat(x) {
// 2.4 omit trailing
var s = (x/100).toFixed(6).substr(2)
return s
}
//
function plot() {
var imgwidth = mod.imageInfo.width/parseFloat(mod.imageInfo.dpi)
var imgheight = mod.imageInfo.height/parseFloat(mod.imageInfo.dpi)
var x,y
//
str = ''
//
if (mod.fill.checked == true) {
str += "%MOIN*%\n" // inch units
str += "%LPD*%\n" // layer dark
str += "%FSLAX66Y66*%\n" // format absolute 6.6
str += "G01*\n" // linear interpolation
//
if (mod.fill.checked == true) {
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'
str += 'X'+gformat(x)+'Y'+gformat(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'
str += 'X'+gformat(x)+'Y'+gformat(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 += 'X'+gformat(x)+'Y'+gformat(y)+'D01*\n'
str += "G37*\n"
}
str += "M02*\n"
......@@ -134,20 +140,24 @@ function plot() {
outputs.Gerber.event(obj)
}
else if (mod.outline.checked == true) {
str += "%MOIN*%\n" // inch units
str += "%LPD*%\n" // layer dark
str += "%FSLAX66Y66*%\n" // format absolute 6.6
str += "G01*\n" // linear interpolation
str += "%ADD10C,0.001*%\n"
str += "D10*\n"
for (var seg = 0; seg < mod.path.length; ++seg) {
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'
str += 'X'+gformat(x)+'Y'+gformat(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'
str += 'X'+gformat(x)+'Y'+gformat(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 += 'X'+gformat(x)+'Y'+gformat(y)+'D01*\n'
}
str += "M02*\n"
var obj = {}
......@@ -167,7 +177,7 @@ function plot() {
//
sx = sy = 0
for (var pt = 0; pt < mod.path[seg].length; ++pt) {
sx += imgwidth*mod.path[seg][pt][0]V/(mod.imageInfo.width-1)
sx += imgwidth*mod.path[seg][pt][0]/(mod.imageInfo.width-1)
sy += imgheight*mod.path[seg][pt][1]/(mod.imageInfo.height-1)
}
x0 = sx/mod.path[seg].length
......@@ -177,7 +187,7 @@ function plot() {
// find diameter
//
for (var pt = 0; pt < mod.path[seg].length; ++pt) {
x = imgwidth*mod.path[seg][pt][0]V/(mod.imageInfo.width-1)
x = imgwidth*mod.path[seg][pt][0]/(mod.imageInfo.width-1)
y = imgheight*mod.path[seg][pt][1]/(mod.imageInfo.height-1)
sd += 2*Math.sqrt((x-x0)*(x-x0)+(y-y0)*(y-y0))
}
......@@ -190,32 +200,39 @@ function plot() {
// sort diameters
//
var drills = {}
var tool = 0
for (var hole = 0; hole < ds.length; ++hole) {
key = str(ds[hole].toFixed(2)
key = ds[hole].toFixed(3).toString()
if (key in drills)
drills[key].push(hole)
else
drills[key] = [hole]
else {
tool += 1
drills[key] = [tool,hole]
}
}
//
// write file
//
str += "M48\n"
str += "INCH,LZ\n"
str += "T01C0.02\n"
str += "M95\n"
str += "G05\n"
str += "T01\n"
str += "X6500Y4500\n"
str += "M48\n" // start of header
str += "INCH,LZ\n" // inch units with leading zeros
str += "VER,1\n" // version 1
str += "FMAT,2\n" // format 2
for (var key in drills) {
str += 'T'+drills[key][0]+'C'+key+"\n" // define tools
}
str += "M95\n" // end of header
str += "G05\n" // drill mode
for (var key in drills) {
for (var hole in drills[key].length) {
str += key+' '+hole+'\n'
str += 'T'+drills[key][0]+'\n' // tool selection
for (var i = 1; i < drills[key].length; ++i) {
var hole = drills[key][i]
str += 'X'+eformat(xs[hole])+'Y'+eformat(ys[hole])+'\n'
}
}
str += "M30\n"
str += "M30\n" // end of program
var obj = {}
obj.type = 'file'
obj.name = mod.imageInfo.name+'-drill.gbr'
obj.name = mod.imageInfo.name+'-drill.xln'
obj.contents = str
outputs.Gerber.event(obj)
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment