2023-05-18 10:37:47 +02:00
|
|
|
// Dependencies
|
2022-12-13 11:55:50 -06:00
|
|
|
import { forwardRef } from 'react'
|
2023-05-18 10:37:47 +02:00
|
|
|
import { round } from 'shared/utils.mjs'
|
|
|
|
import { getProps } from './utils.mjs'
|
|
|
|
// Hooks
|
|
|
|
import { useTranslation } from 'next-i18next'
|
|
|
|
// Components
|
2023-01-29 18:57:24 +01:00
|
|
|
import { Point } from './point.mjs'
|
|
|
|
import { Snippet } from './snippet.mjs'
|
|
|
|
import { Path, Tr, KeyTd, ValTd, Attributes, pointCoords } from './path.mjs'
|
2022-01-25 11:22:09 +01:00
|
|
|
|
2023-05-18 10:37:47 +02:00
|
|
|
const partInfo = ({ partName, part, settings, update }) => {
|
|
|
|
const { t } = useTranslation(['workbench'])
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="p-4 border bg-neutral bg-opacity-40 shadow rounded-lg">
|
|
|
|
<h5 className="text-neutral-content text-center pb-4">{t('partInfo')}</h5>
|
|
|
|
<table className="border-collapse h-fit">
|
|
|
|
<tbody>
|
|
|
|
<Tr>
|
|
|
|
<KeyTd>{t('name')})</KeyTd>
|
|
|
|
<ValTd>{partName}</ValTd>
|
|
|
|
</Tr>
|
|
|
|
<Tr>
|
|
|
|
<KeyTd>{t('width')}</KeyTd>
|
|
|
|
<ValTd>{round(part.width, 2)}mm</ValTd>
|
|
|
|
</Tr>
|
|
|
|
<Tr>
|
|
|
|
<KeyTd>{t('height')}</KeyTd>
|
|
|
|
<ValTd>{round(part.height, 2)}mm</ValTd>
|
|
|
|
</Tr>
|
|
|
|
<Tr>
|
|
|
|
<KeyTd>{t('topLeft')}</KeyTd>
|
|
|
|
<ValTd>{pointCoords(part.topLeft)}</ValTd>
|
|
|
|
</Tr>
|
|
|
|
<Tr>
|
|
|
|
<KeyTd>{t('bottomRight')}</KeyTd>
|
|
|
|
<ValTd>{pointCoords(part.bottomRight)}</ValTd>
|
|
|
|
</Tr>
|
|
|
|
<Tr>
|
|
|
|
<KeyTd>{t('attributes')}</KeyTd>
|
|
|
|
<ValTd>
|
|
|
|
<Attributes list={part.attributes.list} />
|
|
|
|
</ValTd>
|
|
|
|
</Tr>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
<div className="flex flex-row flex-wrap gap-2 mt-4">
|
|
|
|
{settings.only && settings.only.length > 0 ? (
|
|
|
|
<button className="btn btn-primary" onClick={() => update.settings(['only'])}>
|
|
|
|
{t('showAllParts')}
|
|
|
|
</button>
|
|
|
|
) : (
|
|
|
|
<button className="btn btn-primary" onClick={() => update.settings(['only'], [partName])}>
|
|
|
|
{t('showOnlyThisPart')}
|
|
|
|
</button>
|
|
|
|
)}
|
|
|
|
<button className="btn btn-success" onClick={() => console.log(part)}>
|
|
|
|
console.log(part)
|
|
|
|
</button>
|
|
|
|
<button className="btn btn-success" onClick={() => console.table(part.points)}>
|
|
|
|
console.table(part.points)
|
2022-12-13 11:55:50 -06:00
|
|
|
</button>
|
2023-05-18 10:37:47 +02:00
|
|
|
<button className="btn btn-success" onClick={() => console.table(part.paths)}>
|
|
|
|
console.table(part.paths)
|
2022-12-13 11:55:50 -06:00
|
|
|
</button>
|
2023-05-18 10:37:47 +02:00
|
|
|
</div>
|
2022-06-18 17:02:19 +02:00
|
|
|
</div>
|
2023-05-18 10:37:47 +02:00
|
|
|
)
|
|
|
|
}
|
2022-06-18 17:02:19 +02:00
|
|
|
|
2023-05-18 10:37:47 +02:00
|
|
|
const XrayPart = ({ partName, part, settings, showInfo, update }) => {
|
|
|
|
const { topLeft, bottomRight } = part
|
2022-01-30 12:21:08 +01:00
|
|
|
|
|
|
|
return (
|
|
|
|
<g>
|
2022-12-13 11:55:50 -06:00
|
|
|
<path
|
|
|
|
d={`
|
2022-01-30 12:21:08 +01:00
|
|
|
M ${topLeft.x} ${topLeft.y}
|
|
|
|
L ${topLeft.x} ${bottomRight.y}
|
|
|
|
L ${bottomRight.x} ${bottomRight.y}
|
|
|
|
L ${bottomRight.x} ${topLeft.y}
|
2022-06-18 17:02:19 +02:00
|
|
|
z
|
2022-12-13 11:55:50 -06:00
|
|
|
`}
|
|
|
|
className={`peer stroke-note lashed opacity-30 hover:opacity-90 fill-fabric hover:cursor-pointer hover:stroke-mark`}
|
|
|
|
style={{ fillOpacity: 0 }}
|
2023-05-18 10:37:47 +02:00
|
|
|
onClick={(evt) => showInfo(evt, partInfo({ partName, part, settings, update }))}
|
2022-06-18 17:02:19 +02:00
|
|
|
/>
|
2022-01-30 12:21:08 +01:00
|
|
|
</g>
|
|
|
|
)
|
|
|
|
}
|
2022-01-28 19:55:32 +01:00
|
|
|
|
2023-05-18 10:37:47 +02:00
|
|
|
export const PartInner = forwardRef(({ partName, part, settings, showInfo, ui, update }, ref) => {
|
2022-12-13 11:55:50 -06:00
|
|
|
const Grid =
|
2023-05-18 10:37:47 +02:00
|
|
|
settings.paperless && !ui.skipGrid ? (
|
2022-12-13 11:55:50 -06:00
|
|
|
<rect
|
|
|
|
x={part.topLeft.x}
|
|
|
|
y={part.topLeft.y}
|
|
|
|
width={part.width}
|
|
|
|
height={part.height}
|
|
|
|
className="grid"
|
|
|
|
fill={'url(#grid-' + partName + ')'}
|
2022-06-28 02:02:51 -05:00
|
|
|
/>
|
2022-12-13 11:55:50 -06:00
|
|
|
) : null
|
|
|
|
|
|
|
|
return (
|
|
|
|
<g ref={ref}>
|
|
|
|
{Grid}
|
2023-05-18 10:37:47 +02:00
|
|
|
{ui.xray?.enabled && <XrayPart {...{ partName, part, settings, showInfo, update }} />}
|
2022-12-13 11:55:50 -06:00
|
|
|
{Object.keys(part.paths).map((pathName) => (
|
|
|
|
<Path
|
|
|
|
key={pathName}
|
|
|
|
pathName={pathName}
|
|
|
|
path={part.paths[pathName]}
|
2023-05-18 10:37:47 +02:00
|
|
|
topLeft={part.topLeft}
|
|
|
|
bottomRight={part.bottomRight}
|
|
|
|
units={settings.units}
|
|
|
|
{...{ partName, part, showInfo, ui, update }}
|
2022-12-13 11:55:50 -06:00
|
|
|
/>
|
|
|
|
))}
|
2023-05-18 10:37:47 +02:00
|
|
|
{Object.keys(part.points).map((pointName) => (
|
2022-12-13 11:55:50 -06:00
|
|
|
<Point
|
|
|
|
key={pointName}
|
|
|
|
pointName={pointName}
|
2023-05-18 10:37:47 +02:00
|
|
|
point={part.points[pointName]}
|
|
|
|
topLeft={part.topLeft}
|
|
|
|
bottomRight={part.bottomRight}
|
|
|
|
{...{ partName, part, settings, showInfo, ui, update }}
|
2022-12-13 11:55:50 -06:00
|
|
|
/>
|
|
|
|
))}
|
2023-05-18 10:37:47 +02:00
|
|
|
{Object.keys(part.snippets).map((snippetName) => (
|
2022-12-13 11:55:50 -06:00
|
|
|
<Snippet
|
|
|
|
key={snippetName}
|
|
|
|
snippetName={snippetName}
|
2023-05-18 10:37:47 +02:00
|
|
|
snippet={part.snippets[snippetName]}
|
|
|
|
{...{ partName, part, settings, showInfo, ui, update }}
|
2022-12-13 11:55:50 -06:00
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</g>
|
|
|
|
)
|
2022-08-09 16:16:06 -05:00
|
|
|
})
|
2022-06-28 02:02:51 -05:00
|
|
|
|
2022-12-13 12:06:39 -06:00
|
|
|
PartInner.displayName = 'PartInner'
|
|
|
|
|
2023-05-18 10:37:47 +02:00
|
|
|
export const Part = ({ partName, part, settings, showInfo, ui, update }) => (
|
|
|
|
<g
|
|
|
|
{...getProps(part)}
|
|
|
|
id={`${part.context.settings.idPrefix || ''}part-${partName}`}
|
|
|
|
className={part.context.settings.idPrefix || ''}
|
|
|
|
>
|
|
|
|
<PartInner {...{ partName, part, settings, showInfo, ui, update }} />
|
|
|
|
</g>
|
|
|
|
)
|