mirror of
https://github.com/TECHNOFAB11/ergogen.git
synced 2025-12-14 00:43:49 +01:00
PCB stuff started
This commit is contained in:
parent
827cfeea21
commit
a6ed52b4bd
5 changed files with 108 additions and 1 deletions
42
src/pcb.js
Normal file
42
src/pcb.js
Normal 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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue