2023-02-12 10:56:45 +11:00
|
|
|
import { useStore, toolTips } from './useStore'
|
2023-01-09 13:19:14 +11:00
|
|
|
import { extrudeSketch, sketchOnExtrudedFace } from './lang/modifyAst'
|
2023-03-03 20:35:48 +11:00
|
|
|
import { getNodePathFromSourceRange } from './lang/queryAst'
|
2023-02-21 10:50:45 +11:00
|
|
|
import { HorzVert } from './components/Toolbar/HorzVert'
|
2023-03-22 03:02:37 +11:00
|
|
|
import { RemoveConstrainingValues } from './components/Toolbar/RemoveConstrainingValues'
|
2023-03-17 21:15:46 +11:00
|
|
|
import { EqualLength } from './components/Toolbar/EqualLength'
|
|
|
|
import { EqualAngle } from './components/Toolbar/EqualAngle'
|
2023-03-19 18:46:39 +11:00
|
|
|
import { Intersect } from './components/Toolbar/Intersect'
|
2023-04-05 15:08:46 +10:00
|
|
|
import { SetHorzVertDistance } from './components/Toolbar/SetHorzVertDistance'
|
2023-03-10 08:48:50 +11:00
|
|
|
import { SetAngleLength } from './components/Toolbar/SetAngleLength'
|
2023-04-01 16:47:00 +11:00
|
|
|
import { ConvertToVariable } from './components/Toolbar/ConvertVariable'
|
2023-04-05 15:08:46 +10:00
|
|
|
import { SetAbsDistance } from './components/Toolbar/SetAbsDistance'
|
2023-04-05 21:06:20 +10:00
|
|
|
import { SetAngleBetween } from './components/Toolbar/setAngleBetween'
|
2022-11-27 14:06:33 +11:00
|
|
|
|
|
|
|
export const Toolbar = () => {
|
2023-02-21 10:28:34 +11:00
|
|
|
const {
|
|
|
|
setGuiMode,
|
|
|
|
guiMode,
|
|
|
|
selectionRanges,
|
|
|
|
ast,
|
|
|
|
updateAst,
|
|
|
|
programMemory,
|
|
|
|
} = useStore((s) => ({
|
|
|
|
guiMode: s.guiMode,
|
|
|
|
setGuiMode: s.setGuiMode,
|
|
|
|
selectionRanges: s.selectionRanges,
|
|
|
|
ast: s.ast,
|
|
|
|
updateAst: s.updateAst,
|
|
|
|
programMemory: s.programMemory,
|
|
|
|
}))
|
2023-02-12 10:56:45 +11:00
|
|
|
|
2022-11-27 14:06:33 +11:00
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
{guiMode.mode === 'default' && (
|
|
|
|
<button
|
|
|
|
onClick={() => {
|
|
|
|
setGuiMode({
|
|
|
|
mode: 'sketch',
|
|
|
|
sketchMode: 'selectFace',
|
|
|
|
})
|
|
|
|
}}
|
2023-03-07 15:45:59 +11:00
|
|
|
className="border m-1 px-1 rounded text-xs"
|
2022-11-27 14:06:33 +11:00
|
|
|
>
|
2023-02-12 10:56:45 +11:00
|
|
|
Start Sketch
|
2022-11-27 14:06:33 +11:00
|
|
|
</button>
|
|
|
|
)}
|
2023-01-09 13:19:14 +11:00
|
|
|
{guiMode.mode === 'canEditExtrude' && (
|
2022-12-06 05:40:05 +11:00
|
|
|
<button
|
2023-01-09 13:19:14 +11:00
|
|
|
onClick={() => {
|
|
|
|
if (!ast) return
|
2023-02-21 10:28:34 +11:00
|
|
|
const pathToNode = getNodePathFromSourceRange(
|
|
|
|
ast,
|
2023-04-03 16:05:25 +10:00
|
|
|
selectionRanges.codeBasedSelections[0].range
|
2023-02-21 10:28:34 +11:00
|
|
|
)
|
2023-02-12 10:56:45 +11:00
|
|
|
const { modifiedAst } = sketchOnExtrudedFace(
|
|
|
|
ast,
|
|
|
|
pathToNode,
|
|
|
|
programMemory
|
|
|
|
)
|
2023-01-09 13:19:14 +11:00
|
|
|
updateAst(modifiedAst)
|
|
|
|
}}
|
2023-03-07 15:45:59 +11:00
|
|
|
className="border m-1 px-1 rounded text-xs"
|
2023-01-09 13:19:14 +11:00
|
|
|
>
|
|
|
|
SketchOnFace
|
|
|
|
</button>
|
|
|
|
)}
|
|
|
|
{(guiMode.mode === 'canEditSketch' || false) && (
|
2023-02-12 10:56:45 +11:00
|
|
|
<button
|
2022-12-06 05:40:05 +11:00
|
|
|
onClick={() => {
|
|
|
|
setGuiMode({
|
|
|
|
mode: 'sketch',
|
|
|
|
sketchMode: 'sketchEdit',
|
|
|
|
pathToNode: guiMode.pathToNode,
|
2023-01-08 16:37:31 +11:00
|
|
|
rotation: guiMode.rotation,
|
2023-01-04 01:28:26 +11:00
|
|
|
position: guiMode.position,
|
2022-12-06 05:40:05 +11:00
|
|
|
})
|
|
|
|
}}
|
2023-03-07 15:45:59 +11:00
|
|
|
className="border m-1 px-1 rounded text-xs"
|
2022-12-06 05:40:05 +11:00
|
|
|
>
|
2023-02-12 10:56:45 +11:00
|
|
|
Edit Sketch
|
2022-12-06 05:40:05 +11:00
|
|
|
</button>
|
2022-11-28 09:37:46 +11:00
|
|
|
)}
|
2023-01-06 12:45:34 +11:00
|
|
|
{guiMode.mode === 'canEditSketch' && (
|
|
|
|
<>
|
|
|
|
<button
|
|
|
|
onClick={() => {
|
|
|
|
if (!ast) return
|
2023-02-21 10:28:34 +11:00
|
|
|
const pathToNode = getNodePathFromSourceRange(
|
|
|
|
ast,
|
2023-04-03 16:05:25 +10:00
|
|
|
selectionRanges.codeBasedSelections[0].range
|
2023-02-21 10:28:34 +11:00
|
|
|
)
|
2023-01-13 17:58:37 +11:00
|
|
|
const { modifiedAst, pathToExtrudeArg } = extrudeSketch(
|
|
|
|
ast,
|
|
|
|
pathToNode
|
|
|
|
)
|
|
|
|
updateAst(modifiedAst, pathToExtrudeArg)
|
2023-01-06 12:45:34 +11:00
|
|
|
}}
|
2023-03-07 15:45:59 +11:00
|
|
|
className="border m-1 px-1 rounded text-xs"
|
2023-01-06 12:45:34 +11:00
|
|
|
>
|
|
|
|
ExtrudeSketch
|
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
onClick={() => {
|
|
|
|
if (!ast) return
|
2023-02-21 10:28:34 +11:00
|
|
|
const pathToNode = getNodePathFromSourceRange(
|
|
|
|
ast,
|
2023-04-03 16:05:25 +10:00
|
|
|
selectionRanges.codeBasedSelections[0].range
|
2023-02-21 10:28:34 +11:00
|
|
|
)
|
2023-01-13 17:58:37 +11:00
|
|
|
const { modifiedAst, pathToExtrudeArg } = extrudeSketch(
|
|
|
|
ast,
|
|
|
|
pathToNode,
|
|
|
|
false
|
|
|
|
)
|
|
|
|
updateAst(modifiedAst, pathToExtrudeArg)
|
2023-01-06 12:45:34 +11:00
|
|
|
}}
|
2023-03-07 15:45:59 +11:00
|
|
|
className="border m-1 px-1 rounded text-xs"
|
2023-01-06 12:45:34 +11:00
|
|
|
>
|
|
|
|
ExtrudeSketch (w/o pipe)
|
|
|
|
</button>
|
|
|
|
</>
|
|
|
|
)}
|
2022-12-06 05:40:05 +11:00
|
|
|
|
2023-01-09 13:19:14 +11:00
|
|
|
{guiMode.mode === 'sketch' && (
|
2022-12-06 05:40:05 +11:00
|
|
|
<button
|
|
|
|
onClick={() => setGuiMode({ mode: 'default' })}
|
2023-03-07 15:45:59 +11:00
|
|
|
className="border m-1 px-1 rounded text-xs"
|
2022-12-06 05:40:05 +11:00
|
|
|
>
|
|
|
|
Exit sketch
|
|
|
|
</button>
|
2022-11-27 14:06:33 +11:00
|
|
|
)}
|
2023-03-19 18:46:39 +11:00
|
|
|
{toolTips
|
|
|
|
.filter(
|
2023-04-03 21:01:26 +10:00
|
|
|
// (sketchFnName) => !['angledLineThatIntersects'].includes(sketchFnName)
|
|
|
|
(sketchFnName) => ['line'].includes(sketchFnName)
|
2023-02-21 10:28:34 +11:00
|
|
|
)
|
2023-03-19 18:46:39 +11:00
|
|
|
.map((sketchFnName) => {
|
|
|
|
if (
|
|
|
|
guiMode.mode !== 'sketch' ||
|
|
|
|
!('isTooltip' in guiMode || guiMode.sketchMode === 'sketchEdit')
|
|
|
|
)
|
|
|
|
return null
|
|
|
|
return (
|
|
|
|
<button
|
|
|
|
key={sketchFnName}
|
|
|
|
className={`border m-0.5 px-0.5 rounded text-xs ${
|
|
|
|
guiMode.sketchMode === sketchFnName && 'bg-gray-400'
|
|
|
|
}`}
|
|
|
|
onClick={() =>
|
|
|
|
setGuiMode({
|
|
|
|
...guiMode,
|
|
|
|
...(guiMode.sketchMode === sketchFnName
|
|
|
|
? {
|
|
|
|
sketchMode: 'sketchEdit',
|
|
|
|
// todo: ...guiMod is adding isTooltip: true, will probably just fix with xstate migtaion
|
|
|
|
}
|
|
|
|
: {
|
|
|
|
sketchMode: sketchFnName,
|
|
|
|
isTooltip: true,
|
|
|
|
}),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
>
|
|
|
|
{sketchFnName}
|
|
|
|
{guiMode.sketchMode === sketchFnName && '✅'}
|
|
|
|
</button>
|
|
|
|
)
|
|
|
|
})}
|
2023-02-21 10:50:45 +11:00
|
|
|
<br></br>
|
2023-04-01 16:47:00 +11:00
|
|
|
<ConvertToVariable />
|
2023-03-02 21:19:11 +11:00
|
|
|
<HorzVert horOrVert="horizontal" />
|
|
|
|
<HorzVert horOrVert="vertical" />
|
2023-03-17 21:15:46 +11:00
|
|
|
<EqualLength />
|
|
|
|
<EqualAngle />
|
2023-04-06 12:45:56 +10:00
|
|
|
<SetHorzVertDistance buttonType="alignEndsVertically" />
|
|
|
|
<SetHorzVertDistance buttonType="setHorzDistance" />
|
|
|
|
<SetAbsDistance buttonType="snapToYAxis" />
|
|
|
|
<SetAbsDistance buttonType="xAbs" />
|
|
|
|
<SetHorzVertDistance buttonType="alignEndsHorizontally" />
|
|
|
|
<SetAbsDistance buttonType="snapToXAxis" />
|
|
|
|
<SetHorzVertDistance buttonType="setVertDistance" />
|
|
|
|
<SetAbsDistance buttonType="yAbs" />
|
2023-03-10 08:48:50 +11:00
|
|
|
<SetAngleLength angleOrLength="setAngle" />
|
|
|
|
<SetAngleLength angleOrLength="setLength" />
|
2023-03-19 18:46:39 +11:00
|
|
|
<Intersect />
|
2023-03-22 03:02:37 +11:00
|
|
|
<RemoveConstrainingValues />
|
2023-04-05 21:06:20 +10:00
|
|
|
<SetAngleBetween />
|
2022-11-27 14:06:33 +11:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|