1
0

Generalize asym usage

This commit is contained in:
Bán Dénes 2022-12-03 12:38:07 +01:00
parent 40406fbc03
commit cf9007aa50
9 changed files with 36 additions and 19 deletions

View File

@ -35,6 +35,7 @@
- Maybe a partial markdown preprocess to support bold and italic?
- Look into gr_curve to possibly add beziers to the kicad conversion
- Support curves (arcs as well as Béziers) in polygons
- Also, three point arcs, tangents, earier "circle tools" in general
- Add snappable line footprint
- Figure out a manual, but still reasonably comfortable routing method directly from the config
- Eeschema support for pcbs

View File

@ -67,3 +67,14 @@ exports.trbl = (raw, name, _default=0) => units => {
if (raw.length == 2) raw = [raw[1], raw[0], raw[1], raw[0]]
return arr(raw, name, 4, 'number', _default)(units)
}
exports.asym = (raw, name) => {
// allow different aliases
source_aliases = ['source', 'origin', 'base', 'primary', 'left']
clone_aliases = ['clone', 'image', 'derived', 'secondary', 'right']
_in(raw, name, ['both'].concat(source_aliases, clone_aliases))
// return aliases to canonical names
if (source_aliases.includes(raw)) return 'source'
if (clone_aliases.includes(raw)) return 'clone'
return raw
}

View File

@ -108,7 +108,7 @@ const contains_object = (val) => {
return false
}
exports.parse = (config, name, points={}, units={}, include_mirrors=false) => {
exports.parse = (config, name, points={}, units={}, asym='source') => {
let result = []
@ -118,18 +118,23 @@ exports.parse = (config, name, points={}, units={}, include_mirrors=false) => {
// if a filter decl is an object, or an array that contains an object at any depth, it is an anchor
} else if (contains_object(config)) {
result.push(anchor(config, name, points)(units))
if (include_mirrors) {
if (['source', 'both'].includes(asym)) {
result.push(anchor(config, name, points)(units))
}
if (['clone', 'both'].includes(asym)) {
// this is strict: if the ref of the anchor doesn't have a mirror pair, it will error out
result.push(anchor(config, name, points, undefined, true)(units))
}
// otherwise, it is treated as a condition to filter all available points
// otherwise, it is treated as a condition to filter all available points
} else {
result = Object.values(points).filter(complex(config, name, units))
if (include_mirrors) {
source = Object.values(points).filter(complex(config, name, units))
if (['source', 'both'].includes(asym)) {
result = result.concat(source)
}
if (['source', 'both'].includes(asym)) {
// this is permissive: we only include mirrored versions if they exist, and don't fuss if they don't
result = result.concat(result.map(p => points[anchor_lib.mirror(p.meta.name)]).filter(p => !!p))
result = result.concat(source.map(p => points[anchor_lib.mirror(p.meta.name)]).filter(p => !!p))
}
}

View File

@ -191,12 +191,12 @@ exports.parse = (config = {}, points = {}, units = {}) => {
const operation = u[a.in(part.operation || 'add', `${name}.operation`, ['add', 'subtract', 'intersect', 'stack'])]
const what = a.in(part.what || 'outline', `${name}.what`, ['rectangle', 'circle', 'polygon', 'outline'])
const bound = !!part.bound
const mirror = a.sane(part.mirror || false, `${name}.mirror`, 'boolean')()
const asym = a.asym(part.asym || 'source', `${name}.asym`)
// `where` is delayed until we have all, potentially what-dependent units
// default where is [0, 0], as per filter parsing
const original_where = part.where // need to save, so the delete's don't get rid of it below
const where = units => filter(original_where, `${name}.where`, points, units, mirror)
const where = units => filter(original_where, `${name}.where`, points, units, asym)
const adjust = anchor(part.adjust || {}, `${name}.adjust`, points)(units)
const fillet = a.sane(part.fillet || 0, `${name}.fillet`, 'number')(units)
@ -209,7 +209,7 @@ exports.parse = (config = {}, points = {}, units = {}) => {
delete part.operation
delete part.what
delete part.bound
delete part.mirror
delete part.asym
delete part.where
delete part.adjust
delete part.fillet

View File

@ -281,9 +281,9 @@ exports.parse = (config, points, outlines, units) => {
for (const [f_name, f] of Object.entries(footprints_config)) {
const name = `pcbs.${pcb_name}.footprints.${f_name}`
a.sane(f, name, 'object')()
const mirror = a.sane(f.mirror || false, `${name}.mirror`, 'boolean')()
const where = filter(f.where, `${name}.where`, points, units, mirror)
delete f.mirror
const asym = a.asym(f.asym || 'source', `${name}.asym`)
const where = filter(f.where, `${name}.where`, points, units, asym)
delete f.asym
delete f.where
for (const w of where) {
footprints.push(footprint_factory(f, name, w))

View File

@ -128,7 +128,7 @@ const render_zone = exports._render_zone = (zone_name, zone, anchor, global_key,
key.height = a.sane(key.height, `${key.name}.height`, 'number')(units)
key.padding = a.sane(key.padding, `${key.name}.padding`, 'number')(units)
key.skip = a.sane(key.skip, `${key.name}.skip`, 'boolean')()
key.asym = a.in(key.asym, `${key.name}.asym`, ['left', 'right', 'both'])
key.asym = a.asym(key.asym, `${key.name}.asym`)
// templating support
for (const [k, v] of Object.entries(key)) {
@ -256,14 +256,14 @@ const parse_axis = exports._parse_axis = (config, name, points, units) => {
const perform_mirror = exports._perform_mirror = (point, axis) => {
if (axis !== undefined) {
point.meta.mirrored = false
if (point.meta.asym == 'left') return ['', null]
if (point.meta.asym == 'source') return ['', null]
const mp = point.clone().mirror(axis)
const mirrored_name = `mirror_${point.meta.name}`
mp.meta = prep.extend(mp.meta, mp.meta.mirror || {})
mp.meta.name = mirrored_name
mp.meta.colrow = `mirror_${mp.meta.colrow}`
mp.meta.mirrored = true
if (point.meta.asym == 'right') {
if (point.meta.asym == 'clone') {
point.meta.skip = true
}
return [mirrored_name, mp]

View File

@ -22,4 +22,4 @@ outlines:
ref: matrix
shift: [-10, 10]
radius: 5
mirror: true
asym: both

View File

@ -25,4 +25,4 @@ outlines:
- shift: [-10, 15]
- shift: [5, -10]
- shift: [-10, 0]
mirror: true
asym: both

View File

@ -23,4 +23,4 @@ outlines:
ref: matrix
shift: [-10, 10]
size: 10
mirror: true
asym: both