From 3bbea6d4c21f1059440dcf06867b9cb4539ec9d2 Mon Sep 17 00:00:00 2001 From: Enoch Riese Date: Sun, 19 Feb 2023 16:24:46 +0200 Subject: [PATCH] mirror on fold macro --- packages/core/src/store.mjs | 2 + .../workbench/exporting/export-handler.mjs | 2 +- .../components/workbench/layout/cut/index.mjs | 8 ++- .../layout/cut/plugin-cut-layout.mjs | 52 +++++++++++++++++++ ...part-plugin.mjs => plugin-layout-part.mjs} | 0 .../workbench/layout/print/index.mjs | 2 +- 6 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 sites/shared/components/workbench/layout/cut/plugin-cut-layout.mjs rename sites/shared/components/workbench/layout/{layout-part-plugin.mjs => plugin-layout-part.mjs} (100%) diff --git a/packages/core/src/store.mjs b/packages/core/src/store.mjs index db0bfbffeee..1ae9e5f0f29 100644 --- a/packages/core/src/store.mjs +++ b/packages/core/src/store.mjs @@ -35,9 +35,11 @@ export function Store(methods = []) { logs.info.push(...data) }, warning: function (...data) { + console.warn(...data) logs.warning.push(...data) }, error: function (...data) { + console.error(...data) logs.error.push(...data) }, } diff --git a/sites/shared/components/workbench/exporting/export-handler.mjs b/sites/shared/components/workbench/exporting/export-handler.mjs index 4c8174c8083..4a332c7dcf9 100644 --- a/sites/shared/components/workbench/exporting/export-handler.mjs +++ b/sites/shared/components/workbench/exporting/export-handler.mjs @@ -1,7 +1,7 @@ import Worker from 'web-worker' import fileSaver from 'file-saver' import { themePlugin } from '@freesewing/plugin-theme' -import { pagesPlugin } from '../layout/layout-part-plugin.mjs' +import { pagesPlugin } from '../layout/plugin-layout-part.mjs' import { capitalize } from 'shared/utils.mjs' export const exportTypes = { diff --git a/sites/shared/components/workbench/layout/cut/index.mjs b/sites/shared/components/workbench/layout/cut/index.mjs index 18a72ffbde2..eb5355d68ae 100644 --- a/sites/shared/components/workbench/layout/cut/index.mjs +++ b/sites/shared/components/workbench/layout/cut/index.mjs @@ -1,7 +1,9 @@ import { useTranslation } from 'next-i18next' import { CutLayoutSettings } from './settings.mjs' import { Draft } from '../draft/index.mjs' -import { fabricPlugin } from '../layout-part-plugin.mjs' +import { fabricPlugin } from '../plugin-layout-part.mjs' +import { cutLayoutPlugin } from './plugin-cut-layout.mjs' +import { pluginCutlist } from '@freesewing/plugin-cutlist' import { useEffect } from 'react' import { measurementAsMm } from 'shared/utils.mjs' @@ -19,11 +21,13 @@ export const CutLayout = (props) => { // add the pages plugin to the draft const layoutSettings = { - sheetWidth: gistSettings.sheetWidth || measurementAsMm(isImperial ? 54 : 50, props.gist.units), + sheetWidth: gistSettings.sheetWidth || measurementAsMm(isImperial ? 54 : 120, props.gist.units), sheetHeight: gistSettings.sheetHeight || measurementAsMm(isImperial ? 36 : 100, props.gist.units), } draft.use(fabricPlugin(layoutSettings)) + draft.use(pluginCutlist) + draft.use(cutLayoutPlugin) let patternProps try { diff --git a/sites/shared/components/workbench/layout/cut/plugin-cut-layout.mjs b/sites/shared/components/workbench/layout/cut/plugin-cut-layout.mjs new file mode 100644 index 00000000000..a1a3430b45a --- /dev/null +++ b/sites/shared/components/workbench/layout/cut/plugin-cut-layout.mjs @@ -0,0 +1,52 @@ +const prefix = 'mirroredOnFold' + +export const cutLayoutPlugin = { + hooks: { + postPartDraft: (pattern) => { + const partCutlist = pattern.setStores[pattern.activeSet].get(['cutlist', pattern.activePart]) + if (!partCutlist) return + + const { macro } = pattern.parts[pattern.activeSet][pattern.activePart].shorthand() + if (partCutlist.cutOnFold) macro('mirrorOnFold', { fold: partCutlist.cutOnFold }) + }, + }, + macros: { + mirrorOnFold: ({ fold }, { paths, snippets, utils, macro, points }) => { + const mirrorPaths = [] + for (const p in paths) { + if (!paths[p].hidden) mirrorPaths.push(paths[p]) + } + + const mirrorPoints = [] + const snippetsByType = {} + for (var s in snippets) { + const snip = snippets[s] + if (['logo'].indexOf(snip.def) > -1) continue + + snippetsByType[snip.def] = snippetsByType[snip.def] || [] + + mirrorPoints.push(snip.anchor) + for (var pName in points) { + if (points[pName] === snip.anchor) { + snippetsByType[snip.def].push(prefix + utils.capitalize(pName)) + break + } + } + } + + macro('mirror', { + paths: mirrorPaths, + points: mirrorPoints, + mirror: fold, + prefix, + }) + + for (var def in snippetsByType) { + macro('sprinkle', { + snippet: def, + on: snippetsByType[def], + }) + } + }, + }, +} diff --git a/sites/shared/components/workbench/layout/layout-part-plugin.mjs b/sites/shared/components/workbench/layout/plugin-layout-part.mjs similarity index 100% rename from sites/shared/components/workbench/layout/layout-part-plugin.mjs rename to sites/shared/components/workbench/layout/plugin-layout-part.mjs diff --git a/sites/shared/components/workbench/layout/print/index.mjs b/sites/shared/components/workbench/layout/print/index.mjs index 3c5412649e7..9cd19287a14 100644 --- a/sites/shared/components/workbench/layout/print/index.mjs +++ b/sites/shared/components/workbench/layout/print/index.mjs @@ -2,7 +2,7 @@ import { useEffect, useState } from 'react' import { useTranslation } from 'next-i18next' import { PrintLayoutSettings } from './settings.mjs' import { Draft } from '../draft/index.mjs' -import { pagesPlugin } from '../layout-part-plugin.mjs' +import { pagesPlugin } from '../plugin-layout-part.mjs' import { handleExport, defaultPdfSettings,