Initial case progres
This commit is contained in:
parent
ad24f0a533
commit
549b5b0514
2 changed files with 82 additions and 7 deletions
75
src/cases.js
Normal file
75
src/cases.js
Normal file
|
@ -0,0 +1,75 @@
|
||||||
|
const m = require('makerjs')
|
||||||
|
const u = require('./utils')
|
||||||
|
const a = require('./assert')
|
||||||
|
|
||||||
|
const Point = require('./point')
|
||||||
|
|
||||||
|
const makerjs2jscad = exports._makerjs2jscad = (model, resolution = 32) => {
|
||||||
|
const commands = []
|
||||||
|
m.model.walk(model, {
|
||||||
|
onPath: wp => {
|
||||||
|
const p = wp.pathContext
|
||||||
|
switch (p.type) {
|
||||||
|
case 'line':
|
||||||
|
commands.push(`new CSG.Path2D([ ${p.origin}, ${p.end} ]);`)
|
||||||
|
break
|
||||||
|
case 'arc':
|
||||||
|
const angle_start = p.startAngle > p.endAngle ? p.startAngle - 360 : p.startAngle
|
||||||
|
commands.push(`CSG.Path2D.arc({
|
||||||
|
center: ${p.origin},
|
||||||
|
radius: ${p.radius},
|
||||||
|
startangle: ${angle_start},
|
||||||
|
endangle: ${p.endAngle},
|
||||||
|
resolution: ${resolution}
|
||||||
|
});`)
|
||||||
|
break
|
||||||
|
case 'circle':
|
||||||
|
commands.push(`CSG.Path2D.arc({
|
||||||
|
center: ${p.origin},
|
||||||
|
radius: ${p.radius},
|
||||||
|
startangle: 0,
|
||||||
|
endangle: 360,
|
||||||
|
resolution: ${resolution}
|
||||||
|
});`)
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
throw new Error(`Can't convert path type "${p.type}" to jscad!`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return commands
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
exports.parse = (config, points, outlines) => {
|
||||||
|
|
||||||
|
const cases = a.sane(config, 'cases', 'object')
|
||||||
|
const results = {}
|
||||||
|
|
||||||
|
for (const [case_name, case_config] of Object.entries(cases)) {
|
||||||
|
|
||||||
|
// config sanitization
|
||||||
|
parts = a.sane(case_config, `cases.${case_name}`, 'array')
|
||||||
|
|
||||||
|
let part_index = 0
|
||||||
|
for (const part of parts) {
|
||||||
|
const part_name = `cases.${case_name}[${++part_index}]`
|
||||||
|
a.detect_unexpected(part, part_name, ['outline', 'extrude', 'shift', 'rotate', 'operation'])
|
||||||
|
const outline = outlines[part.outline]
|
||||||
|
a.assert(outline, `Field ${part_name}.outline does not name a valid outline!`)
|
||||||
|
const extrude = a.sane(part.extrude || 1, `${part_name}.extrude`, 'number')
|
||||||
|
const shift = a.numarr(part.shift || [0, 0, 0], `${part_name}.shift`, 3)
|
||||||
|
const rotate = a.numarr(part.rotate || [0, 0, 0], `${part_name}.rotate`, 3)
|
||||||
|
const operation = a.in(part.operation || 'add', `${part_name}.operation`, ['add', 'subtract', 'intersect', 'stack'])
|
||||||
|
|
||||||
|
let op = u.union
|
||||||
|
if (operation == 'subtract') op = u.subtract
|
||||||
|
else if (operation == 'intersect') op = u.intersect
|
||||||
|
else if (operation == 'stack') op = u.stack
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return results
|
||||||
|
}
|
14
src/pcbs.js
14
src/pcbs.js
|
@ -206,20 +206,20 @@ const footprint = exports._footprint = (config, name, points, point, net_indexer
|
||||||
|
|
||||||
exports.parse = (config, points, outlines) => {
|
exports.parse = (config, points, outlines) => {
|
||||||
|
|
||||||
const pcbs = a.sane(config, 'pcb', 'object')
|
const pcbs = a.sane(config, 'pcbs', 'object')
|
||||||
const results = {}
|
const results = {}
|
||||||
|
|
||||||
for (const [pcb_name, pcb_config] of Object.entries(pcbs)) {
|
for (const [pcb_name, pcb_config] of Object.entries(pcbs)) {
|
||||||
|
|
||||||
// config sanitization
|
// config sanitization
|
||||||
a.detect_unexpected(pcb_config, `pcb.${pcb_name}`, ['outlines', 'footprints'])
|
a.detect_unexpected(pcb_config, `pcbs.${pcb_name}`, ['outlines', 'footprints'])
|
||||||
|
|
||||||
// outline conversion
|
// outline conversion
|
||||||
const config_outlines = a.sane(pcb_config.outlines, `pcb.${pcb_name}.outlines`, 'object')
|
const config_outlines = a.sane(pcb_config.outlines, `pcbs.${pcb_name}.outlines`, 'object')
|
||||||
const kicad_outlines = {}
|
const kicad_outlines = {}
|
||||||
for (const [outline_name, outline] of Object.entries(config_outlines)) {
|
for (const [outline_name, outline] of Object.entries(config_outlines)) {
|
||||||
const ref = a.in(outline.outline, `pcb.${pcb_name}.outlines.${outline_name}.outline`, Object.keys(outlines))
|
const ref = a.in(outline.outline, `pcbs.${pcb_name}.outlines.${outline_name}.outline`, Object.keys(outlines))
|
||||||
const layer = a.sane(outline.layer || 'Edge.Cuts', `pcb.${pcb_name}.outlines.${outline_name}.outline`, 'string')
|
const layer = a.sane(outline.layer || 'Edge.Cuts', `pcbs.${pcb_name}.outlines.${outline_name}.outline`, 'string')
|
||||||
kicad_outlines[outline_name] = makerjs2kicad(outlines[ref], layer)
|
kicad_outlines[outline_name] = makerjs2kicad(outlines[ref], layer)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -250,9 +250,9 @@ exports.parse = (config, points, outlines) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// global one-off footprints
|
// global one-off footprints
|
||||||
const global_footprints = a.sane(pcb_config.footprints || {}, `pcb.${pcb_name}.footprints`, 'object')
|
const global_footprints = a.sane(pcb_config.footprints || {}, `pcbs.${pcb_name}.footprints`, 'object')
|
||||||
for (const [gf_name, gf] of Object.entries(global_footprints)) {
|
for (const [gf_name, gf] of Object.entries(global_footprints)) {
|
||||||
footprints.push(footprint(gf, `pcb.${pcb_name}.footprints.${gf_name}`, points, undefined, net_indexer, component_indexer))
|
footprints.push(footprint(gf, `pcbs.${pcb_name}.footprints.${gf_name}`, points, undefined, net_indexer, component_indexer))
|
||||||
}
|
}
|
||||||
|
|
||||||
// finalizing nets
|
// finalizing nets
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue