1
0
Fork 0
freesewing/designs/hortensia/src/frontpanel.mjs

139 lines
4 KiB
JavaScript
Raw Normal View History

2022-09-05 17:42:47 -07:00
import { sidepanel } from './sidepanel.mjs'
2023-09-22 02:15:35 +00:00
export const frontpanel = {
name: 'hortensia.frontpanel',
after: sidepanel,
options: {
minHandleSpaceWidth: 80,
maxHandleSpaceWidth: 250,
pctHandleSpace: 50,
pctHandleVert: 42,
handleWidth: { pct: 8.6, min: 4, max: 25, menu: 'style' },
},
draft: ({ store, options, Point, Path, points, paths, Snippet, snippets, sa, macro, part }) => {
const w = store.get('frontPanelLength')
const h = store.get('depth')
points.topLeft = new Point(0, 0)
points.topRight = new Point(w, 0)
points.bottomLeft = new Point(0, h)
points.bottomRight = new Point(w, h)
paths.bottom = new Path()
.move(points.topLeft)
.line(points.bottomLeft)
.attr('data-text', 'Bottom')
.attr('data-text-class', 'center text-xs')
paths.top = new Path()
.move(points.bottomRight)
.line(points.topRight)
.attr('data-text', 'Top')
.attr('data-text-class', 'center text-xs')
paths.seam = paths.bottom
.line(points.bottomRight)
.join(paths.top)
.line(points.topLeft)
.close()
.attr('class', 'fabric')
const handleWidth = options.width * options.handleWidth
let handleSpace = (h - handleWidth * 2) * (options.pctHandleSpace / 100)
if (handleSpace > options.maxHandleSpaceWidth) {
handleSpace = options.maxHandleSpaceWidth
} else if (handleSpace < options.minHandleSpaceWidth) {
handleSpace = options.minHandleSpaceWidth
if (handleSpace < h - handleWidth * 2) {
handleSpace = h - handleWidth * 2
}
}
2023-09-22 02:15:35 +00:00
let handleVertPos = w * (options.pctHandleVert / 100)
if (handleVertPos + handleWidth * 2 > w) {
handleVertPos = w - handleWidth * 2
}
points.attachPoint1TL = new Point(handleVertPos, 0 + h / 2 - handleSpace / 2)
points.attachPoint2TL = new Point(handleVertPos, h - h / 2 + handleSpace / 2 - handleWidth)
points.attachPoint2TLtemp = new Point(handleVertPos, h - h / 2 + handleSpace / 2)
points.attachPoint1BR = new Point(
handleVertPos + handleWidth * 2,
0 + h / 2 - handleSpace / 2 + handleWidth
)
points.attachPoint2BR = new Point(handleVertPos + handleWidth * 2, h - h / 2 + handleSpace / 2)
macro('crossbox', {
topLeft: points.attachPoint1TL,
bottomRight: points.attachPoint1BR,
text: 'strapAttachment',
id: 'att1',
})
macro('crossbox', {
topLeft: points.attachPoint2TL,
bottomRight: points.attachPoint2BR,
text: 'strapAttachment',
id: 'att2',
})
store.cutlist.addCut({ cut: 2, from: 'fabric' })
store.cutlist.addCut({ cut: 2, material: 'lining' })
2021-01-31 09:22:15 +01:00
points.logo = points.topLeft.shiftFractionTowards(points.bottomRight, 0.5)
snippets.logo = new Snippet('logo', points.logo)
2023-09-22 02:15:35 +00:00
points.title = points.logo.shift(-90, h / 4).attr('data-text-class', 'center')
points.gridAnchor = points.logo.clone()
2021-01-31 09:22:15 +01:00
macro('title', {
at: points.title,
nr: 2,
2023-09-22 02:15:35 +00:00
title: 'FrontPanel',
2023-09-08 11:48:45 +02:00
align: 'center',
2021-01-31 09:22:15 +01:00
})
if (sa) {
2021-01-31 09:22:15 +01:00
paths.sa = paths.seam.offset(sa).attr('class', 'fabric sa')
}
2021-01-31 09:22:15 +01:00
macro('hd', {
from: points.bottomLeft,
to: points.bottomRight,
2021-04-24 10:16:31 +02:00
y: points.bottomLeft.y + sa + 15,
2023-09-22 02:15:35 +00:00
id: 'width',
2021-01-31 09:22:15 +01:00
})
macro('hd', {
from: points.topLeft,
to: points.attachPoint1TL,
2021-04-24 10:16:31 +02:00
y: points.attachPoint1TL.y,
2023-09-22 02:15:35 +00:00
id: 'attachPoint1',
2021-01-31 09:22:15 +01:00
})
macro('hd', {
from: points.topLeft,
to: points.attachPoint2TLtemp,
2021-04-24 10:16:31 +02:00
y: points.attachPoint2TLtemp.y,
2023-09-22 02:15:35 +00:00
id: 'attachPoint2',
2021-01-31 09:22:15 +01:00
})
macro('vd', {
from: points.bottomRight,
to: points.topRight,
2021-04-24 10:16:31 +02:00
x: points.topRight.x + sa + 15,
2023-09-22 02:15:35 +00:00
id: 'height',
2021-01-31 09:22:15 +01:00
})
macro('vd', {
from: points.topLeft,
to: points.attachPoint1TL,
2021-04-24 10:16:31 +02:00
x: points.attachPoint1TL.x,
2023-09-22 02:15:35 +00:00
id: 'attachPoint1',
2021-01-31 09:22:15 +01:00
})
macro('vd', {
from: points.attachPoint2TLtemp,
to: points.bottomLeft,
2021-04-24 10:16:31 +02:00
x: points.attachPoint2TLtemp.x,
2023-09-22 02:15:35 +00:00
id: 'attachPoint2',
2021-01-31 09:22:15 +01:00
})
2023-09-22 02:15:35 +00:00
return part
2022-09-05 17:42:47 -07:00
},
}