cutting layout renders at the most basic level
This commit is contained in:
parent
150b9f49d2
commit
6dbe15a862
7 changed files with 76 additions and 7 deletions
|
@ -1,7 +1,7 @@
|
||||||
import Worker from 'web-worker'
|
import Worker from 'web-worker'
|
||||||
import fileSaver from 'file-saver'
|
import fileSaver from 'file-saver'
|
||||||
import { themePlugin } from '@freesewing/plugin-theme'
|
import { themePlugin } from '@freesewing/plugin-theme'
|
||||||
import { pagesPlugin } from '../layout/print/plugin.mjs'
|
import { pagesPlugin } from '../layout/layout-part-plugin.mjs'
|
||||||
import { capitalize } from 'shared/utils.mjs'
|
import { capitalize } from 'shared/utils.mjs'
|
||||||
|
|
||||||
export const exportTypes = {
|
export const exportTypes = {
|
||||||
|
|
|
@ -1,15 +1,54 @@
|
||||||
import { useTranslation } from 'next-i18next'
|
import { useTranslation } from 'next-i18next'
|
||||||
import { CutLayoutSettings } from './settings.mjs'
|
import { CutLayoutSettings } from './settings.mjs'
|
||||||
|
import { Draft } from '../draft/index.mjs'
|
||||||
|
import { fabricPlugin } from '../layout-part-plugin.mjs'
|
||||||
|
import { useEffect } from 'react'
|
||||||
|
|
||||||
export const CutLayout = (props) => {
|
export const CutLayout = (props) => {
|
||||||
const { t } = useTranslation(['workbench'])
|
const { t } = useTranslation(['workbench'])
|
||||||
|
|
||||||
|
// disable xray
|
||||||
|
useEffect(() => {
|
||||||
|
if (props.gist?._state?.xray?.enabled) props.updateGist(['_state', 'xray', 'enabled'], false)
|
||||||
|
})
|
||||||
|
|
||||||
|
const draft = props.draft
|
||||||
|
|
||||||
|
// add the pages plugin to the draft
|
||||||
|
const layoutSettings = {
|
||||||
|
sheetWidth: 500,
|
||||||
|
sheetHeight: 1000,
|
||||||
|
...props.gist?._state?.layout?.forCutting?.fabric,
|
||||||
|
}
|
||||||
|
|
||||||
|
draft.use(fabricPlugin(layoutSettings))
|
||||||
|
|
||||||
|
let patternProps
|
||||||
|
try {
|
||||||
|
// draft the pattern
|
||||||
|
draft.draft()
|
||||||
|
patternProps = draft.getRenderProps()
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err, props.gist)
|
||||||
|
}
|
||||||
|
const bgProps = { fill: 'url(#page)' }
|
||||||
|
|
||||||
let name = props.design.designConfig.data.name
|
let name = props.design.designConfig.data.name
|
||||||
name = name.replace('@freesewing/', '')
|
name = name.replace('@freesewing/', '')
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<h2 className="capitalize">{t('layoutThing', { thing: name }) + ': ' + t('forCutting')}</h2>
|
<h2 className="capitalize">{t('layoutThing', { thing: name }) + ': ' + t('forCutting')}</h2>
|
||||||
<CutLayoutSettings {...props} />
|
<CutLayoutSettings {...props} />
|
||||||
|
<Draft
|
||||||
|
draft={draft}
|
||||||
|
gist={props.gist}
|
||||||
|
updateGist={props.updateGist}
|
||||||
|
patternProps={patternProps}
|
||||||
|
bgProps={bgProps}
|
||||||
|
gistReady={props.gistReady}
|
||||||
|
layoutPart="fabric"
|
||||||
|
layoutType="cuttingLayout"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,27 @@
|
||||||
export const CutLayoutSettings = () => {
|
import { ClearIcon } from 'shared/components/icons.mjs'
|
||||||
|
import { useTranslation } from 'next-i18next'
|
||||||
|
|
||||||
|
export const CutLayoutSettings = (props) => {
|
||||||
|
const { t } = useTranslation(['workbench'])
|
||||||
|
let fabric = props.draft?.setStores[0].get('fabric')
|
||||||
|
if (!fabric) return null
|
||||||
|
const { cols, rows, count } = fabric
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<p>Fixme: Cut layout settings here</p>
|
<div
|
||||||
|
className="flex flex-row justify-between
|
||||||
|
mb-2"
|
||||||
|
>
|
||||||
|
<button
|
||||||
|
key="reset"
|
||||||
|
onClick={() => props.unsetGist(['layouts', 'cuttingLayout'])}
|
||||||
|
className="btn btn-primary btn-outline"
|
||||||
|
>
|
||||||
|
<ClearIcon className="h-6 w-6 mr-2" />
|
||||||
|
{t('reset')}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ export const Draft = (props) => {
|
||||||
const svgRef = useRef(null)
|
const svgRef = useRef(null)
|
||||||
if (!patternProps) return null
|
if (!patternProps) return null
|
||||||
// keep a fresh copy of the layout because we might manipulate it without saving to the gist
|
// keep a fresh copy of the layout because we might manipulate it without saving to the gist
|
||||||
let layout = draft.settings[0].layouts?.printingLayout || {
|
let layout = draft.settings[0].layouts?.[layoutType] || {
|
||||||
...patternProps.autoLayout,
|
...patternProps.autoLayout,
|
||||||
width: patternProps.width,
|
width: patternProps.width,
|
||||||
height: patternProps.height,
|
height: patternProps.height,
|
||||||
|
|
|
@ -50,6 +50,14 @@ export const pagesPlugin = ({ size = 'a4', ...settings }) => {
|
||||||
return basePlugin({ ...settings, sheetWidth, sheetHeight })
|
return basePlugin({ ...settings, sheetWidth, sheetHeight })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const fabricPlugin = (settings) => {
|
||||||
|
return basePlugin({
|
||||||
|
...settings,
|
||||||
|
partName: 'fabric',
|
||||||
|
responsiveColumns: false,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/** check if there is anything to render on the given section of the svg so that we can skip empty pages */
|
/** check if there is anything to render on the given section of the svg so that we can skip empty pages */
|
||||||
const doScanForBlanks = (stacks, layout, x, y, w, h) => {
|
const doScanForBlanks = (stacks, layout, x, y, w, h) => {
|
||||||
let hasContent = false
|
let hasContent = false
|
||||||
|
@ -92,7 +100,7 @@ const doScanForBlanks = (stacks, layout, x, y, w, h) => {
|
||||||
* sheetHeight: the height of the helper part
|
* sheetHeight: the height of the helper part
|
||||||
* boundary: should the helper part calculate its boundary?
|
* boundary: should the helper part calculate its boundary?
|
||||||
* responsiveColumns: should the part make more columns if the pattern exceed its width? (for pages you want this, for fabric you don't)
|
* responsiveColumns: should the part make more columns if the pattern exceed its width? (for pages you want this, for fabric you don't)
|
||||||
* printStyle: hould the pages be rendered for printing or for screen viewing?
|
* printStyle: should the pages be rendered for printing or for screen viewing?
|
||||||
* */
|
* */
|
||||||
const basePlugin = ({
|
const basePlugin = ({
|
||||||
sheetWidth,
|
sheetWidth,
|
|
@ -2,7 +2,7 @@ import { useEffect, useState } from 'react'
|
||||||
import { useTranslation } from 'next-i18next'
|
import { useTranslation } from 'next-i18next'
|
||||||
import { PrintLayoutSettings } from './settings.mjs'
|
import { PrintLayoutSettings } from './settings.mjs'
|
||||||
import { Draft } from '../draft/index.mjs'
|
import { Draft } from '../draft/index.mjs'
|
||||||
import { pagesPlugin } from './plugin.mjs'
|
import { pagesPlugin } from '../layout-part-plugin.mjs'
|
||||||
import {
|
import {
|
||||||
handleExport,
|
handleExport,
|
||||||
defaultPdfSettings,
|
defaultPdfSettings,
|
||||||
|
|
|
@ -119,7 +119,9 @@ export const WorkbenchWrapper = ({
|
||||||
|
|
||||||
// Generate the draft here so we can pass it down to both the view and the options menu
|
// Generate the draft here so we can pass it down to both the view and the options menu
|
||||||
let draft = false
|
let draft = false
|
||||||
if (['draft', 'logs', 'test', 'printingLayout'].indexOf(gist._state?.view) !== -1) {
|
if (
|
||||||
|
['draft', 'logs', 'test', 'printingLayout', 'cuttingLayout'].indexOf(gist._state?.view) !== -1
|
||||||
|
) {
|
||||||
gist.embed = true
|
gist.embed = true
|
||||||
// get the appropriate layout for the view
|
// get the appropriate layout for the view
|
||||||
const layout = gist.layouts?.[gist._state.view] || gist.layout || true
|
const layout = gist.layouts?.[gist._state.view] || gist.layout || true
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue