feat(plugin-annotations): Check complete in title macro
This commit is contained in:
parent
5c00551bca
commit
637b2ecaba
1 changed files with 51 additions and 46 deletions
|
@ -7,6 +7,7 @@ const macroDefaults = {
|
||||||
cutlist: true,
|
cutlist: true,
|
||||||
dy: 8,
|
dy: 8,
|
||||||
id: 'title',
|
id: 'title',
|
||||||
|
force: false,
|
||||||
nr: 1,
|
nr: 1,
|
||||||
rotation: 0,
|
rotation: 0,
|
||||||
scale: 1,
|
scale: 1,
|
||||||
|
@ -33,10 +34,6 @@ const getIds = (id) => ({
|
||||||
title: `__macro_title_${id}_title`,
|
title: `__macro_title_${id}_title`,
|
||||||
})
|
})
|
||||||
|
|
||||||
/*
|
|
||||||
* Helper method to calculate the title transform
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Removing all this is easy as all IDs are available in the store
|
* Removing all this is easy as all IDs are available in the store
|
||||||
* and all we need to remove are points.
|
* and all we need to remove are points.
|
||||||
|
@ -51,36 +48,44 @@ const removeTitleMacro = function (id = macroDefaults.id, { points, store, part
|
||||||
/*
|
/*
|
||||||
* The title macro
|
* The title macro
|
||||||
*/
|
*/
|
||||||
const addTitleMacro = function (config, { Point, points, scale, locale, store, part, log }) {
|
const addTitleMacro = function (
|
||||||
|
config,
|
||||||
|
{ Point, points, scale, locale, store, part, log, complete }
|
||||||
|
) {
|
||||||
/*
|
/*
|
||||||
* Merge macro defaults with user-provided config
|
* Don't add a title when complete is false, unless force is true
|
||||||
*/
|
*/
|
||||||
const so = {
|
if (!complete && !config.force) return
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Merge macro defaults with user-provided config to create the macro config (mc)
|
||||||
|
*/
|
||||||
|
const mc = {
|
||||||
...macroDefaults,
|
...macroDefaults,
|
||||||
...config,
|
...config,
|
||||||
classes: macroDefaults.classes,
|
classes: macroDefaults.classes,
|
||||||
}
|
}
|
||||||
if (config.classes) so.classes = { ...so.classes, ...config.classes }
|
if (config.classes) mc.classes = { ...mc.classes, ...config.classes }
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Take global scale setting into account
|
* Take global scale setting into account
|
||||||
*/
|
*/
|
||||||
so.scale = so.scale * scale
|
mc.scale = mc.scale * scale
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Make sure so.at is a Point so we can anchor the title
|
* Make sure mc.at is a Point so we can anchor the title
|
||||||
*/
|
*/
|
||||||
if (typeof so.at.attr !== 'function') {
|
if (!mc.at || typeof mc.at.attr !== 'function') {
|
||||||
log.warn(`Title macro called without a valid anchor point. Anchoring title at (0,0).`)
|
log.warn(`Title macro called without a valid anchor point. Anchoring title at (0,0).`)
|
||||||
so.at = new Point(0, 0)
|
mc.at = new Point(0, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Make sure so.align is a valid alignment
|
* Make sure mc.align is a valid alignment
|
||||||
*/
|
*/
|
||||||
if (!['left', 'right', 'center'].includes(so.align)) {
|
if (!['left', 'right', 'center'].includes(mc.align)) {
|
||||||
log.warn(`Title macro called with invalid alignement (${so.align}). Left-aligning title.`)
|
log.warn(`Title macro called with invalid alignement (${mc.align}). Left-aligning title.`)
|
||||||
so.align = 'left'
|
mc.align = 'left'
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -88,48 +93,48 @@ const addTitleMacro = function (config, { Point, points, scale, locale, store, p
|
||||||
*/
|
*/
|
||||||
const transform =
|
const transform =
|
||||||
'matrix(' +
|
'matrix(' +
|
||||||
`${so.scale}, 0, 0, ${so.scale}, ` +
|
`${mc.scale}, 0, 0, ${mc.scale}, ` +
|
||||||
`${so.at.x - so.scale * so.at.x}, ` +
|
`${mc.at.x - mc.scale * mc.at.x}, ` +
|
||||||
`${so.at.y - so.scale * so.at.y}` +
|
`${mc.at.y - mc.scale * mc.at.y}` +
|
||||||
`) rotate(${so.rotation} ${so.at.x} ${so.at.y})`
|
`) rotate(${mc.rotation} ${mc.at.x} ${mc.at.y})`
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get the list of IDs
|
* Get the list of IDs
|
||||||
* Initialize the verticle cadence
|
* Initialize the verticle cadence
|
||||||
*/
|
*/
|
||||||
const ids = getIds(so.id)
|
const ids = getIds(mc.id)
|
||||||
let shift = so.dy
|
let shift = mc.dy
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Title: nr
|
* Title: nr
|
||||||
*/
|
*/
|
||||||
if (typeof so.nr !== 'undefined') {
|
if (typeof mc.nr !== 'undefined') {
|
||||||
points[ids.nr] = so.at
|
points[ids.nr] = mc.at
|
||||||
.clone()
|
.clone()
|
||||||
.attr('data-text', so.nr, so.append ? false : true)
|
.attr('data-text', mc.nr, mc.append ? false : true)
|
||||||
.attr('data-text-class', `${so.classes.nr} ${so.align}`)
|
.attr('data-text-class', `${mc.classes.nr} ${mc.align}`)
|
||||||
.attr('data-text-transform', transform)
|
.attr('data-text-transform', transform)
|
||||||
store.set(['partNumbers', part.name], so.nr)
|
store.set(['partNumbers', part.name], mc.nr)
|
||||||
} else delete ids.nr
|
} else delete ids.nr
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Title: title
|
* Title: title
|
||||||
*/
|
*/
|
||||||
if (so.title) {
|
if (mc.title) {
|
||||||
points[ids.title] = so.at
|
points[ids.title] = mc.at
|
||||||
.clone()
|
.clone()
|
||||||
.shift(-90, shift)
|
.shift(-90, shift)
|
||||||
.attr('data-text', so.title, so.append ? false : true)
|
.attr('data-text', mc.title, mc.append ? false : true)
|
||||||
.attr('data-text-class', `${so.classes.title} ${so.align}`)
|
.attr('data-text-class', `${mc.classes.title} ${mc.align}`)
|
||||||
.attr('data-text-transform', transform)
|
.attr('data-text-transform', transform)
|
||||||
shift += so.dy
|
shift += mc.dy
|
||||||
store.set(['partTitles', part.name], so.title)
|
store.set(['partTitles', part.name], mc.title)
|
||||||
} else delete ids.title
|
} else delete ids.title
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Title: cutlist
|
* Title: cutlist
|
||||||
*/
|
*/
|
||||||
if (so.cutlist) {
|
if (mc.cutlist) {
|
||||||
/*
|
/*
|
||||||
* Get cutlist instructions from the store, only proceed if the list is available
|
* Get cutlist instructions from the store, only proceed if the list is available
|
||||||
*/
|
*/
|
||||||
|
@ -145,14 +150,14 @@ const addTitleMacro = function (config, { Point, points, scale, locale, store, p
|
||||||
*/
|
*/
|
||||||
const id = `${ids.cutlist}_${material}_${c}`
|
const id = `${ids.cutlist}_${material}_${c}`
|
||||||
ids[`cutlist_${material}_${c}`] = id
|
ids[`cutlist_${material}_${c}`] = id
|
||||||
points[id] = so.at
|
points[id] = mc.at
|
||||||
.clone()
|
.clone()
|
||||||
.shift(-90, shift)
|
.shift(-90, shift)
|
||||||
.attr('data-text', 'plugin:cut')
|
.attr('data-text', 'plugin:cut')
|
||||||
.attr('data-text-class', `${so.classes.cutlist} ${so.align}`)
|
.attr('data-text-class', `${mc.classes.cutlist} ${mc.align}`)
|
||||||
.attr('data-text-transform', transform)
|
.attr('data-text-transform', transform)
|
||||||
.addText(cut)
|
.addText(cut)
|
||||||
shift += so.dy
|
shift += mc.dy
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Add instructions if parts are mirrored
|
* Add instructions if parts are mirrored
|
||||||
|
@ -180,7 +185,7 @@ const addTitleMacro = function (config, { Point, points, scale, locale, store, p
|
||||||
/*
|
/*
|
||||||
* Title: Design name
|
* Title: Design name
|
||||||
*/
|
*/
|
||||||
points[ids.name] = so.at
|
points[ids.name] = mc.at
|
||||||
.clone()
|
.clone()
|
||||||
.shift(-90, shift)
|
.shift(-90, shift)
|
||||||
.attr(
|
.attr(
|
||||||
|
@ -189,25 +194,25 @@ const addTitleMacro = function (config, { Point, points, scale, locale, store, p
|
||||||
store.data?.version || 'noVersion'
|
store.data?.version || 'noVersion'
|
||||||
}`
|
}`
|
||||||
)
|
)
|
||||||
.attr('data-text-class', `${so.classes.name} ${so.align}`)
|
.attr('data-text-class', `${mc.classes.name} ${mc.align}`)
|
||||||
.attr('data-text-transform', transform)
|
.attr('data-text-transform', transform)
|
||||||
shift += so.dy
|
shift += mc.dy
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Title: For (measurements set)
|
* Title: For (measurements set)
|
||||||
*/
|
*/
|
||||||
if (store.data.for) {
|
if (store.data.for) {
|
||||||
points[ids.for] = so.at
|
points[ids.for] = mc.at
|
||||||
.shift(-90, shift)
|
.shift(-90, shift)
|
||||||
.attr('data-text', `(${store.data.for})`)
|
.attr('data-text', `(${store.data.for})`)
|
||||||
.attr('data-text-class', `${so.classes.for} ${so.align}`)
|
.attr('data-text-class', `${mc.classes.for} ${mc.align}`)
|
||||||
shift += so.dy
|
shift += mc.dy
|
||||||
} else delete ids.for
|
} else delete ids.for
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Title: Date
|
* Title: Date
|
||||||
*/
|
*/
|
||||||
points[ids.date] = so.at
|
points[ids.date] = mc.at
|
||||||
.shift(-90, shift)
|
.shift(-90, shift)
|
||||||
.attr(
|
.attr(
|
||||||
'data-text',
|
'data-text',
|
||||||
|
@ -218,12 +223,12 @@ const addTitleMacro = function (config, { Point, points, scale, locale, store, p
|
||||||
day: 'numeric',
|
day: 'numeric',
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
.attr('data-text-class', `${so.classes.date} ${so.align}`)
|
.attr('data-text-class', `${mc.classes.date} ${mc.align}`)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Store all IDs in the store so we can remove this macro with rmtitle
|
* Store all IDs in the store so we can remove this macro with rmtitle
|
||||||
*/
|
*/
|
||||||
store.set(['parts', part.name, 'macros', 'title', 'ids', so.id, 'points'], ids)
|
store.set(['parts', part.name, 'macros', 'title', 'ids', mc.id, 'points'], ids)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Export macros
|
// Export macros
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue