From f39b9477177eb4672384e1ab92fbb44f8a5e963b Mon Sep 17 00:00:00 2001 From: Enoch Riese Date: Thu, 9 Mar 2023 17:45:10 -0600 Subject: [PATCH] more documentation and cleanup --- designs/carlton/src/collar.mjs | 3 - markdown/dev/reference/macros/title/en.md | 5 +- .../locales/en/plugin/plugins/cutlist.yaml | 14 +- plugins/plugin-cutlist/tests/plugin.test.mjs | 22 ++- plugins/plugin-cutonfold/src/index.mjs | 2 +- plugins/plugin-title/src/index.mjs | 28 +++- sites/dev/components/navigation/aside.mjs | 3 +- .../components/workbench/exporting/index.mjs | 2 +- .../components/workbench/layout/cut/index.mjs | 7 +- .../layout/cut/plugin-cut-layout.mjs | 136 ++++++++++++++---- 10 files changed, 165 insertions(+), 57 deletions(-) diff --git a/designs/carlton/src/collar.mjs b/designs/carlton/src/collar.mjs index 8d49ba36f97..7f38719cb75 100644 --- a/designs/carlton/src/collar.mjs +++ b/designs/carlton/src/collar.mjs @@ -17,9 +17,6 @@ function draftCarltonCollar({ Path, part, addCut, - setGrain, - setCutOnFold, - store, }) { // We're going to slash and spread this collar. Slashing first: // Divide top in 5 parts diff --git a/markdown/dev/reference/macros/title/en.md b/markdown/dev/reference/macros/title/en.md index 6fbe9e3d57b..198b34b262b 100644 --- a/markdown/dev/reference/macros/title/en.md +++ b/markdown/dev/reference/macros/title/en.md @@ -11,6 +11,7 @@ It is provided by the [title plugin](/reference/plugins/title). macro('title', { Boolean append, Point at, + Boolean cutlist String nr, String prefix, Number rotation, @@ -50,11 +51,12 @@ macro('title', { | Property | Default | Type | Description | | ----------:| :-----: | ------------------- | ----------- | +| `append` | `false` | Boolean | Set this to `true` to append the `nr` to any text already set in Point `at`'s attributes, rather than overwrite it | | `at` | | [Point](/reference/api/point) | The point at which to insert the title | +| `cutlist` | `true` | Boolean | Whether to include cutting instructions | | `nr` | | String | The number of the pattern part | | `title` | | String | The name of the pattern part. If title is not set or is an empty string, this won't be rendered, and the version will go beneath the nr.| | `prefix` | | String | A prefix to add to the created points. This allow for more than 1 title per part, as long as you give them a different prefix.| -| `append` | `false` | Boolean | Set this to `true` to append the `nr` to any text already set in Point `at`'s attributes, rather than overwrite it | | `rotation` | 0 | Number | An optional rotation in degrees | | `scale` | 1 | Number | An optional scaling factor | @@ -64,6 +66,7 @@ macro('title', { |-------------------|-------------| | `points._${prefix}_titleNr` | Point anchoring the part number text | | `points._${prefix}_titleName` | Point anchoring the part name text | +| `points._${prefix}_titleCut_${material}_${i} | Points anchoring the cutting instructions, by material key and instruction index | | `points._${prefix}_titlePattern` | Point anchoring the pattern name text | | `points._${prefix}_titleFor` | Point anchoring the name of the person for whom the pattern was made, if that information exists | | `points._${prefix}_exportDate` | Point anchoring the pattern export date | diff --git a/packages/i18n/src/locales/en/plugin/plugins/cutlist.yaml b/packages/i18n/src/locales/en/plugin/plugins/cutlist.yaml index e5503d1a4cb..b35b0c444fe 100644 --- a/packages/i18n/src/locales/en/plugin/plugins/cutlist.yaml +++ b/packages/i18n/src/locales/en/plugin/plugins/cutlist.yaml @@ -1,9 +1,13 @@ -lmhCanvas: Light to Medium Hair Canvas -fabric: Main Fabric -lining: Lining +canvas: Canvas cut: Cut -paired: paired +fabric: Main Fabric +heavyCanvas: Heavy Canvas +interfacing: Interfacing +lining: Lining +lmhCanvas: Light to Medium Hair Canvas +mirrored: mirrored onFoldLower: on the fold onFoldAndBias: folded on the bias onBias: on the bias - +plastic: Plastic +ribbing: Ribbing diff --git a/plugins/plugin-cutlist/tests/plugin.test.mjs b/plugins/plugin-cutlist/tests/plugin.test.mjs index 7ea607d56c8..458d26bd6ec 100644 --- a/plugins/plugin-cutlist/tests/plugin.test.mjs +++ b/plugins/plugin-cutlist/tests/plugin.test.mjs @@ -38,15 +38,20 @@ describe('Cutlist Plugin Tests', () => { const Test = new Design({ parts: [part] }) const pattern = new Test() pattern.draft() - expect(pattern.setStores[0].cutlist.example_part.materials.fabric.cut).to.equal(2) - expect(pattern.setStores[0].cutlist.example_part.materials.fabric.identical).to.equal(false) + expect(pattern.setStores[0].cutlist.example_part.materials.fabric).to.have.lengthOf(1) + expect(pattern.setStores[0].cutlist.example_part.materials.fabric[0]).to.deep.equal({ + cut: 2, + identical: false, + bias: false, + ignoreOnFold: false, + }) }) it('Should handle addCut() with non-defaults', () => { const part = { name: 'example_part', draft: ({ addCut, part }) => { - addCut(3, 'lining', true) + addCut({ cut: 3, material: 'lining', identical: true }) return part }, @@ -55,8 +60,13 @@ describe('Cutlist Plugin Tests', () => { const Test = new Design({ parts: [part] }) const pattern = new Test() pattern.draft() - expect(pattern.setStores[0].cutlist.example_part.materials.lining.cut).to.equal(3) - expect(pattern.setStores[0].cutlist.example_part.materials.lining.identical).to.equal(true) + expect(pattern.setStores[0].cutlist.example_part.materials.lining).to.have.lengthOf(1) + expect(pattern.setStores[0].cutlist.example_part.materials.lining[0]).to.deep.equal({ + cut: 3, + identical: true, + bias: false, + ignoreOnFold: false, + }) }) it('Should remove cut info via addCut(false)', () => { @@ -93,7 +103,7 @@ describe('Cutlist Plugin Tests', () => { const pattern = new Test() pattern.draft() expect(typeof pattern.setStores[0].cutlist.example_part.materials.lining).to.equal('undefined') - expect(pattern.setStores[0].cutlist.example_part.materials.fabric.cut).to.equal(2) + expect(pattern.setStores[0].cutlist.example_part.materials.fabric[0].cut).to.equal(2) }) it('Should remove cut info for all materials via removeCut(true)', () => { diff --git a/plugins/plugin-cutonfold/src/index.mjs b/plugins/plugin-cutonfold/src/index.mjs index 7b932995e14..b3d18b421d7 100644 --- a/plugins/plugin-cutonfold/src/index.mjs +++ b/plugins/plugin-cutonfold/src/index.mjs @@ -24,7 +24,7 @@ export const plugin = { delete points.cutonfoldTo delete points.cutonfoldVia1 delete points.cutonfoldVia2 - delete paths.cutonfold + delete paths.cutonfoldCutonfold // setCutOnFold relies on plugin-cutlist if (typeof setCutOnFold === 'function') { setCutOnFold(false) // Restore default diff --git a/plugins/plugin-title/src/index.mjs b/plugins/plugin-title/src/index.mjs index ad20642a5d5..9f8d1d840eb 100644 --- a/plugins/plugin-title/src/index.mjs +++ b/plugins/plugin-title/src/index.mjs @@ -31,7 +31,7 @@ export const plugin = { }, }, macros: { - title: function (so, { points, scale, locale, store, part, getCutOnFold }) { + title: function (so, { points, scale, locale, store, part }) { const prefix = so.prefix || '' let overwrite = !so.append @@ -52,8 +52,10 @@ export const plugin = { } let shift = 8 const nextPoint = (text, textClass, shiftAmt = shift) => { - const newPoint = so.at.shift(-90 - so.rotation, shiftAmt * so.scale) - newPoint.attr('data-text-transform', transform(newPoint)).addText(text, textClass) + const newPoint = so.at + .shift(-90 - so.rotation, shiftAmt * so.scale) + .addText(text, textClass) + newPoint.attr('data-text-transform', transform(newPoint)) return newPoint } const defaults = { @@ -76,18 +78,32 @@ export const plugin = { shift += 8 } + // Cut List instructions const partCutlist = store.get(['cutlist', part.name]) + // if there's a cutlist and it should be included if (so.cutlist && partCutlist?.materials) { + // get the default cutonfold const cutonfold = partCutlist.cutOnFold + // each material for (const material in partCutlist.materials) { + // each set of instructions partCutlist.materials[material].forEach(({ cut, identical, bias, ignoreOnFold }, c) => { - const cutPoint = nextPoint('plugin:cut', 'text-md fill-current') - cutPoint.addText(cut) - if (!identical && cut > 1) cutPoint.addText('plugin:paired') + // make a new point for this set of instructions + const cutPoint = nextPoint('plugin:cut', 'text-md fill-current').addText(cut) + + // if they're not identical, add that to the point's text + if (!identical && cut > 1) cutPoint.addText('plugin:mirrored') + + // if they should be cut on the fold add that, with bias or without if (cutonfold && !ignoreOnFold) cutPoint.addText(bias ? 'plugin:onFoldAndBias' : 'plugin:onFoldLower') + // otherwise if they should be on the bias, say so else if (bias) cutPoint.addText('plugin:onBias') + + // add 'from' the material cutPoint.addText('plugin:from').addText('plugin:' + material) + + // save and shift points[`_${prefix}_titleCut_${material}_${c}`] = cutPoint shift += 8 }) diff --git a/sites/dev/components/navigation/aside.mjs b/sites/dev/components/navigation/aside.mjs index 43a9a0f292c..20c31e59fbc 100644 --- a/sites/dev/components/navigation/aside.mjs +++ b/sites/dev/components/navigation/aside.mjs @@ -3,7 +3,7 @@ import { MainSections, ActiveSection } from './primary.mjs' export const AsideNavigation = ({ app, slug, mobileOnly = false, before = [], after = [] }) => (