1
0
Fork 0
freesewing/packages/hortensia/src/frontpanel.js

138 lines
3.5 KiB
JavaScript
Raw Normal View History

export default function (part) {
let {
store,
options,
Point,
Path,
points,
paths,
Snippet,
snippets,
complete,
sa,
paperless,
2021-01-31 09:22:15 +01:00
macro
} = part.shorthand()
2021-01-31 09:22:15 +01:00
let w = store.get('frontPanelLength')
let h = store.get('depth')
2021-01-31 09:22:15 +01:00
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')
2021-01-31 09:22:15 +01:00
.attr('data-text-class', 'center text-xs')
paths.top = new Path()
.move(points.bottomRight)
.line(points.topRight)
.attr('data-text', 'Top')
2021-01-31 09:22:15 +01:00
.attr('data-text-class', 'center text-xs')
//paths.seam = new Path()
paths.seam = paths.bottom
.line(points.bottomRight)
.join(paths.top)
.line(points.topLeft)
.close()
2021-01-31 09:22:15 +01:00
.attr('class', 'fabric')
2021-01-31 09:22:15 +01:00
let pctHandleVert = options.pctHandleVert
let handleWidth = options.handleWidth
let handleSpace = (h - handleWidth * 2) * (options.pctHandleSpace / 100)
if (handleSpace > options.maxHandleSpaceWidth) {
2021-01-31 09:22:15 +01:00
handleSpace = options.maxHandleSpaceWidth
} else if (handleSpace < options.minHandleSpaceWidth) {
2021-01-31 09:22:15 +01:00
handleSpace = options.minHandleSpaceWidth
if (handleSpace < h - handleWidth * 2) {
2021-01-31 09:22:15 +01:00
handleSpace = h - handleWidth * 2
}
}
2021-01-31 09:22:15 +01:00
let handleVertPos = w * (pctHandleVert / 100)
if (handleVertPos + handleWidth * 2 > w) {
2021-01-31 09:22:15 +01:00
handleVertPos = w - handleWidth * 2
}
2021-01-31 09:22:15 +01:00
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
2021-01-31 09:22:15 +01:00
)
points.attachPoint2BR = new Point(handleVertPos + handleWidth * 2, h - h / 2 + handleSpace / 2)
2021-01-31 09:22:15 +01:00
macro('crossBox', {
from: points.attachPoint1TL,
to: points.attachPoint1BR,
2021-01-31 09:22:15 +01:00
text: 'attachment'
})
2021-01-31 09:22:15 +01:00
macro('crossBox', {
from: points.attachPoint2TL,
to: points.attachPoint2BR,
2021-01-31 09:22:15 +01:00
text: 'attachment'
})
// Complete?
if (complete) {
2021-01-31 09:22:15 +01:00
points.logo = points.topLeft.shiftFractionTowards(points.bottomRight, 0.5)
snippets.logo = new Snippet('logo', points.logo)
points.title = points.logo.shift(-90, 50).attr('data-text-class', 'center')
2021-01-31 09:22:15 +01:00
macro('title', {
at: points.title,
nr: 2,
2021-01-31 09:22:15 +01:00
title: 'FrontBackPanel'
})
points.__titleNr.attr('data-text-class', 'center')
points.__titleName.attr('data-text-class', 'center')
points.__titlePattern.attr('data-text-class', 'center')
if (sa) {
2021-01-31 09:22:15 +01:00
paths.sa = paths.seam.offset(sa).attr('class', 'fabric sa')
}
}
// Paperless?
if (paperless) {
2021-01-31 09:22:15 +01:00
macro('hd', {
from: points.bottomLeft,
to: points.bottomRight,
2021-01-31 09:22:15 +01:00
y: points.bottomLeft.y + sa + 15
})
macro('hd', {
from: points.topLeft,
to: points.attachPoint1TL,
2021-01-31 09:22:15 +01:00
y: points.attachPoint1TL.y
})
macro('hd', {
from: points.topLeft,
to: points.attachPoint2TLtemp,
2021-01-31 09:22:15 +01:00
y: points.attachPoint2TLtemp.y
})
macro('vd', {
from: points.bottomRight,
to: points.topRight,
2021-01-31 09:22:15 +01:00
x: points.topRight.x + sa + 15
})
macro('vd', {
from: points.topLeft,
to: points.attachPoint1TL,
2021-01-31 09:22:15 +01:00
x: points.attachPoint1TL.x
})
macro('vd', {
from: points.attachPoint2TLtemp,
to: points.bottomLeft,
2021-01-31 09:22:15 +01:00
x: points.attachPoint2TLtemp.x
})
}
2021-01-31 09:22:15 +01:00
return part
}