PCB stuff started

This commit is contained in:
Bán Dénes 2020-07-11 20:30:20 +02:00
parent 827cfeea21
commit a6ed52b4bd
5 changed files with 108 additions and 1 deletions

View file

@ -13,6 +13,7 @@ const u = require('./utils')
const io = require('./io')
const points_lib = require('./points')
const outline_lib = require('./outline')
const pcb_lib = require('./pcb')
// command line args
@ -67,6 +68,12 @@ for (const [name, outline] of Object.entries(outlines)) {
io.dump_model(outline, path.join(args.o, `outline/${name}`), args.debug)
}
// pcb
console.log('Scaffolding PCB...')
const pcb = pcb_lib.parse(config.pcb, points, outlines)
fs.writeFileSync(path.join(args.o, `pcb/pcb.kicad_pcb`, pcb))
// goodbye
console.log('Done.')

View file

@ -249,6 +249,8 @@ exports.parse = (config = {}, points = {}) => {
result = op(result, arg)
}
m.model.originate(result)
m.model.simplify(result)
outlines[key] = result
}

42
src/pcb.js Normal file
View file

@ -0,0 +1,42 @@
const m = require('makerjs')
const u = require('./utils')
const a = require('./assert')
const makerjs2kicad = exports._makerjs2kicad = model => {
const grs = []
const xy = val => `${val[0]} ${val[1]}`
m.model.walk(model, {
onPath: wp => {
const p = wp.pathContext
switch (p.type) {
case 'line':
grs.push(`(gr_line (start ${xy(p.origin)}) (end ${xy(p.end)}) (angle 90) (layer Edge.Cuts) (width 0.15))`)
break
case 'arc':
// console.log(require('util').inspect(p, false, 200))
// throw 2
const center = p.origin
const angle_start = Math.min(p.startAngle, p.endAngle)
const angle_diff = Math.abs(p.endAngle - p.startAngle)
const end = m.point.rotate(m.point.add(center, [p.radius, 0]), angle_start, center)
grs.push(`(gr_arc (start ${xy(center)}) (end ${xy(end)}) (angle ${angle_diff}) (layer Edge.Cuts) (width 0.15))`)
break
case 'circle':
break
default:
throw new Error(`Can't convert path type "${p.type}" to kicad!`)
}
}
})
return grs
}
exports.parse = (config, points, outlines) => {
a.detect_unexpected(config, 'pcb', ['edge', 'footprints'])
const edge = outlines[config.edge]
if (!edge) throw new Error(`Field "pcb.edge" doesn't name a valid outline!`)
const kicad_edge = makerjs2kicad(edge)
console.log(kicad_edge.join('\n'))
throw 28
}