chore(plugin-annotations): Prefer from over material and support multiple cuts
This commit is contained in:
parent
793512a4d0
commit
b8efc700e7
1 changed files with 14 additions and 7 deletions
|
@ -30,26 +30,33 @@ export const cutlistHooks = {
|
||||||
* @param {boolean} so.ignoreOnFold should these cutting instructions ignore any cutOnFold information set by the part
|
* @param {boolean} so.ignoreOnFold should these cutting instructions ignore any cutOnFold information set by the part
|
||||||
*/
|
*/
|
||||||
function addCut(store, so = {}) {
|
function addCut(store, so = {}) {
|
||||||
|
if (Array.isArray(so)) {
|
||||||
|
for (const cut of so) addCut(store, cut)
|
||||||
|
return store
|
||||||
|
}
|
||||||
const { cut = 2, identical = false, bias = false, ignoreOnFold = false } = so
|
const { cut = 2, identical = false, bias = false, ignoreOnFold = false } = so
|
||||||
// Make 'from' an alias for material
|
// Make 'material' an alias for 'from'
|
||||||
let { material = 'fabric' } = so
|
let { from = 'fabric' } = so
|
||||||
if (so.from) material = so.from
|
if (so.material) {
|
||||||
|
from = so.material
|
||||||
|
store.log.warn(`Using 'material' in cutlist is deprecated, please use 'from' instead'`)
|
||||||
|
}
|
||||||
|
|
||||||
const partName = store.get('activePart')
|
const partName = store.get('activePart')
|
||||||
if (cut === false) {
|
if (cut === false) {
|
||||||
if (material === false) store.unset(['cutlist', partName, 'materials'])
|
if (from === false) store.unset(['cutlist', partName, 'materials'])
|
||||||
else store.unset(['cutlist', partName, 'materials', material])
|
else store.unset(['cutlist', partName, 'materials', from])
|
||||||
return store
|
return store
|
||||||
}
|
}
|
||||||
if (!(Number.isInteger(cut) && cut > -1)) {
|
if (!(Number.isInteger(cut) && cut > -1)) {
|
||||||
store.log.error(`Tried to set cut to a value that is not a positive integer`)
|
store.log.error(`Tried to set cut to a value that is not a positive integer`)
|
||||||
return store
|
return store
|
||||||
}
|
}
|
||||||
if (typeof material !== 'string') {
|
if (typeof from !== 'string') {
|
||||||
store.log.warn(`Tried to set material to a value that is not a string`)
|
store.log.warn(`Tried to set material to a value that is not a string`)
|
||||||
return store
|
return store
|
||||||
}
|
}
|
||||||
const path = ['cutlist', partName, 'materials', material]
|
const path = ['cutlist', partName, 'materials', from]
|
||||||
const existing = store.get(path, [])
|
const existing = store.get(path, [])
|
||||||
store.set(path, existing.concat({ cut, identical, bias, ignoreOnFold }))
|
store.set(path, existing.concat({ cut, identical, bias, ignoreOnFold }))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue