import { useStore, toolTips, Selections } from './useStore' import { extrudeSketch, sketchOnExtrudedFace } from './lang/modifyAst' import { getNodePathFromSourceRange } from './lang/queryAst' import { HorzVert } from './components/Toolbar/HorzVert' import { RemoveConstrainingValues } from './components/Toolbar/RemoveConstrainingValues' import { EqualLength } from './components/Toolbar/EqualLength' import { EqualAngle } from './components/Toolbar/EqualAngle' import { Intersect } from './components/Toolbar/Intersect' import { SetHorzVertDistance } from './components/Toolbar/SetHorzVertDistance' import { SetAngleLength } from './components/Toolbar/setAngleLength' import { SetAbsDistance } from './components/Toolbar/SetAbsDistance' import { SetAngleBetween } from './components/Toolbar/SetAngleBetween' import { Fragment, useEffect } from 'react' import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import { faSearch, faX } from '@fortawesome/free-solid-svg-icons' import { Popover, Transition } from '@headlessui/react' import styles from './Toolbar.module.css' import { v4 as uuidv4 } from 'uuid' import { useAppMode } from 'hooks/useAppMode' export const Toolbar = () => { const { setGuiMode, guiMode, selectionRanges, ast, updateAst, programMemory, engineCommandManager, } = useStore((s) => ({ guiMode: s.guiMode, setGuiMode: s.setGuiMode, selectionRanges: s.selectionRanges, ast: s.ast, updateAst: s.updateAst, programMemory: s.programMemory, engineCommandManager: s.engineCommandManager, })) useAppMode() useEffect(() => { console.log('guiMode', guiMode) }, [guiMode]) function ToolbarButtons() { return ( {guiMode.mode === 'default' && ( { setGuiMode({ mode: 'sketch', sketchMode: 'selectFace', }) }} > Start Sketch )} {guiMode.mode === 'canEditExtrude' && ( { if (!ast) return const pathToNode = getNodePathFromSourceRange( ast, selectionRanges.codeBasedSelections[0].range ) const { modifiedAst } = sketchOnExtrudedFace( ast, pathToNode, programMemory ) updateAst(modifiedAst) }} > SketchOnFace )} {guiMode.mode === 'canEditSketch' && ( { console.log('guiMode.pathId', guiMode.pathId) engineCommandManager?.sendSceneCommand({ type: 'modeling_cmd_req', cmd_id: uuidv4(), cmd: { type: 'edit_mode_enter', target: guiMode.pathId, }, }) setGuiMode({ mode: 'sketch', sketchMode: 'sketchEdit', pathToNode: guiMode.pathToNode, rotation: guiMode.rotation, position: guiMode.position, }) }} > Edit Sketch )} {guiMode.mode === 'canEditSketch' && ( <> { if (!ast) return const pathToNode = getNodePathFromSourceRange( ast, selectionRanges.codeBasedSelections[0].range ) const { modifiedAst, pathToExtrudeArg } = extrudeSketch( ast, pathToNode ) updateAst(modifiedAst, { focusPath: pathToExtrudeArg }) }} > ExtrudeSketch { if (!ast) return const pathToNode = getNodePathFromSourceRange( ast, selectionRanges.codeBasedSelections[0].range ) const { modifiedAst, pathToExtrudeArg } = extrudeSketch( ast, pathToNode, false ) updateAst(modifiedAst, { focusPath: pathToExtrudeArg }) }} > ExtrudeSketch (w/o pipe) > )} {guiMode.mode === 'sketch' && ( { engineCommandManager?.sendSceneCommand({ type: 'modeling_cmd_req', cmd_id: uuidv4(), cmd: { type: 'edit_mode_exit' }, }) setGuiMode({ mode: 'default' }) }} > Exit sketch )} {toolTips .filter( // (sketchFnName) => !['angledLineThatIntersects'].includes(sketchFnName) (sketchFnName) => ['sketch_line', 'move'].includes(sketchFnName) ) .map((sketchFnName) => { if ( guiMode.mode !== 'sketch' || !('isTooltip' in guiMode || guiMode.sketchMode === 'sketchEdit') ) return null return ( { engineCommandManager?.sendSceneCommand({ type: 'modeling_cmd_req', cmd_id: uuidv4(), cmd: { type: 'set_tool', tool: guiMode.sketchMode === sketchFnName ? 'select' : (sketchFnName as any), }, }) setGuiMode({ ...guiMode, ...(guiMode.sketchMode === sketchFnName ? { sketchMode: 'sketchEdit', // todo: ...guiMod is adding isTooltip: true, will probably just fix with xstate migtaion } : { sketchMode: sketchFnName, waitingFirstClick: true, isTooltip: true, }), }) }} > {sketchFnName} {guiMode.sketchMode === sketchFnName && '✅'} ) })} ) } return ( {guiMode.mode === 'sketch' ? '2D' : '3D'} You're in {guiMode.mode === 'sketch' ? '2D' : '3D'} ) }
You're in {guiMode.mode === 'sketch' ? '2D' : '3D'}