fix(plugin-annotations): Ensure grainline is removed
This builds on the fix by @woutervdub in #5449 that ensures the rmcutonfold macro removes the cutonfold info from the store. However, the same problem applies to the grainline data which can be set by both cutonfold and grainline. So I've added that. And while I was at it also created explicit methods to remove this data instead of having to pass in false which I found counterintuitive and a throwback to the v2-ways. In addition, the grainline can be set by both grainline and cutonfold macros. So when we remove either of them, we should only remove the grainline info if it was actually set by them. But there's no way to know that at remove time. So I've also added the logic to set grainOrigin in the store which will be `cutonfold` or `grainline` depending on the macro that set the grain.
This commit is contained in:
parent
406ac84c2b
commit
bf0cd0f835
3 changed files with 44 additions and 8 deletions
|
@ -3,7 +3,10 @@ export const cutlistStores = [
|
|||
['cutlist.setCut', setCut],
|
||||
['cutlist.removeCut', removeCut],
|
||||
['cutlist.setGrain', setGrain],
|
||||
['cutlist.removeGrain', removeGrain],
|
||||
['cutlist.getGrainOrigin', getGrainOrigin],
|
||||
['cutlist.setCutOnFold', setCutOnFold],
|
||||
['cutlist.removeCutOnFold', removeCutOnFold],
|
||||
['cutlist.getCutFabrics', getCutFabrics],
|
||||
]
|
||||
|
||||
|
@ -70,22 +73,45 @@ function setCut(store, so) {
|
|||
}
|
||||
|
||||
/** Method to add the grain info (called by grainline and cutonfold macros) */
|
||||
function setGrain(store, grain = false) {
|
||||
function setGrain(store, grain = false, origin = 'grainline') {
|
||||
const partName = store.get('activePart')
|
||||
const path = ['cutlist', partName, 'grain']
|
||||
if (grain === false) return store.unset(path)
|
||||
if (grain === false) {
|
||||
store.log.warn('Using setGrain() to remove the grain is deprecated. Use removeGrain() instead')
|
||||
return store.unset(path)
|
||||
}
|
||||
if (typeof grain !== 'number') {
|
||||
store.log.error('Called part.setGrain() with a value that is not a number')
|
||||
return store
|
||||
}
|
||||
/*
|
||||
* Since both grainline and cutonfold macros can set the grainline
|
||||
* we need to keep track of who did what so they can remove the grainline
|
||||
* only when it's the one they set. So we store grainOrigin for this
|
||||
*/
|
||||
store.set(['cutlist', partName, 'grainOrigin'], origin)
|
||||
|
||||
return store.set(path, grain)
|
||||
}
|
||||
|
||||
/** Method to retrieve the grainOrigin */
|
||||
function getGrainOrigin(store) {
|
||||
return store.get(['cutlist', store.get('activePart'), partName, 'grainOrigin'])
|
||||
}
|
||||
|
||||
/** Method to remove the grain info (called by rmgrainline and rmcutonfold macros) */
|
||||
function removeGrain(store) {
|
||||
return store.unset(['cutlist', store.get('activePart'), 'grain'])
|
||||
}
|
||||
|
||||
/** Method to add the cutOnFold info (called by cutonfold macro) */
|
||||
function setCutOnFold(store, p1, p2) {
|
||||
const partName = store.get('activePart')
|
||||
const path = ['cutlist', partName, 'cutOnFold']
|
||||
if (p1 === false && typeof p2 === 'undefined') {
|
||||
store.log.warn(
|
||||
'Using setCutOnFold() to remove the cutonfold is deprecated. Use removeCutOnFold() instead'
|
||||
)
|
||||
return store.unset(path)
|
||||
}
|
||||
if (!isNaN(p1.x) && !isNaN(p1.y) && !isNaN(p2.x) && !isNaN(p2.y)) {
|
||||
|
@ -96,6 +122,11 @@ function setCutOnFold(store, p1, p2) {
|
|||
return store
|
||||
}
|
||||
|
||||
/** Method to add remove cutOnFold info (called by rmcutonfold macro) */
|
||||
function removeCutOnFold(store) {
|
||||
return store.unset(['cutlist', store.get('activePart'), 'cutOnFold'])
|
||||
}
|
||||
|
||||
/** Get a list of fabrics used by the pattern for the given settings */
|
||||
function getCutFabrics(store, settings) {
|
||||
const cutlist = store.get('cutlist')
|
||||
|
|
|
@ -35,8 +35,10 @@ export const cutonfoldDefs = [
|
|||
* The rmcutonfold macro
|
||||
*/
|
||||
const rmcutonfold = (id = macroDefaults.id, { store, part }) => {
|
||||
store.removeMacroNodes(id, 'cutonfold', part)
|
||||
store.cutlist.setCutOnFold(false)
|
||||
if (store.cutlist.getGrainOrigin() === 'cutonfold') store.cutlist.removeGrainline()
|
||||
store.cutlist.removeCutOnFold()
|
||||
|
||||
return store.removeMacroNodes(id, 'cutonfold', part)
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -77,7 +79,7 @@ const cutonfold = function (config, { paths, Path, complete, store, scale, log,
|
|||
* Store cutonfold and optional grainline angle for use in cutlist
|
||||
*/
|
||||
store.cutlist.setCutOnFold(mc.from, mc.to)
|
||||
if (mc.grainline) store.cutlist.setGrain(mc.from.angle(mc.to))
|
||||
if (mc.grainline) store.cutlist.setGrain(mc.from.angle(mc.to), 'cutonfold')
|
||||
|
||||
/*
|
||||
* Get the list of IDs
|
||||
|
|
|
@ -32,8 +32,11 @@ export const grainlineDefs = [
|
|||
/*
|
||||
* The rmgrainline macro
|
||||
*/
|
||||
const rmgrainline = (id = macroDefaults.id, { store, part }) =>
|
||||
store.removeMacroNodes(id, 'grainline', part)
|
||||
const rmgrainline = (id = macroDefaults.id, { store, part }) => {
|
||||
if (store.cutlist.getGrainOrigin() === 'grainline') store.cutlist.removeGrainline()
|
||||
|
||||
return store.removeMacroNodes(id, 'grainline', part)
|
||||
}
|
||||
|
||||
/*
|
||||
* The grainline macro
|
||||
|
@ -69,7 +72,7 @@ const grainline = function (config = {}, { paths, Path, Point, complete, store,
|
|||
/*
|
||||
* Store angle for use in cutlist
|
||||
*/
|
||||
store.cutlist.setGrain(mc.from.angle(mc.to))
|
||||
store.cutlist.setGrain(mc.from.angle(mc.to), 'grainline')
|
||||
|
||||
/*
|
||||
* Get the list of IDs
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue