diff --git a/src/Toolbar.tsx b/src/Toolbar.tsx index 6f001653e..5e8804d37 100644 --- a/src/Toolbar.tsx +++ b/src/Toolbar.tsx @@ -1,26 +1,13 @@ -import { useStore, toolTips, ToolTip } 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 { ToolTip } from './useStore' import { Fragment, WheelEvent, useRef, useMemo } 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 { isCursorInSketchCommandRange } from 'lang/util' import { ActionIcon } from 'components/ActionIcon' import { engineCommandManager } from './lang/std/engineConnection' import { useModelingContext } from 'hooks/useModelingContext' -import { kclManager } from 'lang/KclSinglton' export const sketchButtonClassnames = { background: @@ -178,24 +165,6 @@ export const Toolbar = () => { Extrude )} - - {/* - - - - - - - - - - - - - - - - */} ) } diff --git a/src/components/ModelingMachineProvider.tsx b/src/components/ModelingMachineProvider.tsx index c849553c0..683aa6b54 100644 --- a/src/components/ModelingMachineProvider.tsx +++ b/src/components/ModelingMachineProvider.tsx @@ -41,6 +41,7 @@ import { setCodeMirrorCursor, useStore, } from 'useStore' +import { applyConstraintIntersect } from './Toolbar/Intersect' type MachineContext = { state: StateFrom @@ -372,6 +373,22 @@ export const ModelingMachineProvider = ({ ), } }, + 'Get perpendicular distance info': async ({ + selectionRanges, + }): Promise => { + const { modifiedAst, pathToNodeMap } = await applyConstraintIntersect({ + selectionRanges, + }) + await kclManager.updateAst(modifiedAst, true) + return { + selectionType: 'completeSelection', + selection: pathMapToSelections( + kclManager.ast, + selectionRanges, + pathToNodeMap + ), + } + }, }, devTools: true, }) diff --git a/src/components/SetAngleLengthModal.tsx b/src/components/SetAngleLengthModal.tsx index 3f44be534..fe8734b5e 100644 --- a/src/components/SetAngleLengthModal.tsx +++ b/src/components/SetAngleLengthModal.tsx @@ -1,5 +1,6 @@ import { Dialog, Transition } from '@headlessui/react' import { Fragment, useState } from 'react' +import { type InstanceProps, create } from 'react-modal-promise' import { Value } from '../lang/wasm' import { AvailableVars, @@ -9,6 +10,28 @@ import { CreateNewVariable, } from './AvailableVarsHelpers' +type ModalResolve = { + value: string + sign: number + valueNode: Value + variableName?: string + newVariableInsertIndex: number +} + +type ModalReject = boolean + +type SetAngleLengthModalProps = InstanceProps & { + value: number + valueName: string + shouldCreateVariable?: boolean +} + +export const createSetAngleLengthModal = create< + SetAngleLengthModalProps, + ModalResolve, + ModalReject +> + export const SetAngleLengthModal = ({ isOpen, onResolve, @@ -16,20 +39,7 @@ export const SetAngleLengthModal = ({ value: initialValue, valueName, shouldCreateVariable: initialShouldCreateVariable = false, -}: { - isOpen: boolean - onResolve: (a: { - value: string - sign: number - valueNode: Value - variableName?: string - newVariableInsertIndex: number - }) => void - onReject: (a: any) => void - value: number - valueName: string - shouldCreateVariable: boolean -}) => { +}: SetAngleLengthModalProps) => { const [sign, setSign] = useState(Math.sign(Number(initialValue))) const [value, setValue] = useState(String(initialValue * sign)) const [shouldCreateVariable, setShouldCreateVariable] = useState( diff --git a/src/components/SetHorVertDistanceModal.tsx b/src/components/SetHorVertDistanceModal.tsx index 738bf219a..633409885 100644 --- a/src/components/SetHorVertDistanceModal.tsx +++ b/src/components/SetHorVertDistanceModal.tsx @@ -1,5 +1,6 @@ import { Dialog, Transition } from '@headlessui/react' import { Fragment, useState } from 'react' +import { type InstanceProps, create } from 'react-modal-promise' import { Value } from '../lang/wasm' import { AvailableVars, @@ -9,6 +10,30 @@ import { CreateNewVariable, } from './AvailableVarsHelpers' +type ModalResolve = { + value: string + segName: string + valueNode: Value + variableName?: string + newVariableInsertIndex: number + sign: number +} + +type ModalReject = boolean + +type GetInfoModalProps = InstanceProps & { + segName: string + isSegNameEditable: boolean + value?: number + initialVariableName: string +} + +export const createInfoModal = create< + GetInfoModalProps, + ModalResolve, + ModalReject +> + export const GetInfoModal = ({ isOpen, onResolve, @@ -17,25 +42,12 @@ export const GetInfoModal = ({ isSegNameEditable, value: initialValue, initialVariableName, -}: { - isOpen: boolean - onResolve: (a: { - value: string - segName: string - valueNode: Value - variableName?: string - newVariableInsertIndex: number - sign: number - }) => void - onReject: (a: any) => void - segName: string - isSegNameEditable: boolean - value: number - initialVariableName: string -}) => { +}: GetInfoModalProps) => { const [sign, setSign] = useState(Math.sign(Number(initialValue))) const [segName, setSegName] = useState(initialSegName) - const [value, setValue] = useState(String(Math.abs(initialValue))) + const [value, setValue] = useState( + initialValue === undefined ? '' : String(Math.abs(initialValue)) + ) const [shouldCreateVariable, setShouldCreateVariable] = useState(false) const { diff --git a/src/components/SetVarNameModal.tsx b/src/components/SetVarNameModal.tsx index 1b3509c1a..68a83d0c0 100644 --- a/src/components/SetVarNameModal.tsx +++ b/src/components/SetVarNameModal.tsx @@ -4,19 +4,26 @@ import { useCalc, CreateNewVariable } from './AvailableVarsHelpers' import { ActionButton } from './ActionButton' import { faPlus } from '@fortawesome/free-solid-svg-icons' import { toast } from 'react-hot-toast' +import { type InstanceProps, create } from 'react-modal-promise' + +type ModalResolve = { variableName: string } +type ModalReject = boolean +type SetVarNameModalProps = InstanceProps & { + valueName: string +} + +export const createSetVarNameModal = create< + SetVarNameModalProps, + ModalResolve, + ModalReject +> export const SetVarNameModal = ({ isOpen, onResolve, onReject, valueName, -}: { - isOpen: boolean - onResolve: (a: { variableName?: string }) => void - onReject: (a: any) => void - value: number - valueName: string -}) => { +}: SetVarNameModalProps) => { const { isNewVariableNameUnique, newVariableName, setNewVariableName } = useCalc({ value: '', initialVariableName: valueName }) diff --git a/src/components/Toolbar/EqualAngle.tsx b/src/components/Toolbar/EqualAngle.tsx index 096ef4760..9e783e2a0 100644 --- a/src/components/Toolbar/EqualAngle.tsx +++ b/src/components/Toolbar/EqualAngle.tsx @@ -1,102 +1,78 @@ -import { useState, useEffect } from 'react' -import { toolTips, useStore } from '../../useStore' -import { Value, VariableDeclarator } from '../../lang/wasm' +import { Selections, toolTips } from '../../useStore' +import { Program, Value, VariableDeclarator } from '../../lang/wasm' import { getNodePathFromSourceRange, getNodeFromPath, } from '../../lang/queryAst' import { isSketchVariablesLinked } from '../../lang/std/sketchConstraints' import { - TransformInfo, transformSecondarySketchLinesTagFirst, getTransformInfos, + PathToNodeMap, } from '../../lang/std/sketchcombos' -import { ActionIcon } from 'components/ActionIcon' -import { sketchButtonClassnames } from 'Toolbar' import { kclManager } from 'lang/KclSinglton' -/* -export const EqualAngle = () => { - const { guiMode, selectionRanges, setCursor } = useStore((s) => ({ - guiMode: s.guiMode, - selectionRanges: s.selectionRanges, - setCursor: s.setCursor, - })) - const [enableEqual, setEnableEqual] = useState(false) - const [transformInfos, setTransformInfos] = useState() - useEffect(() => { - const paths = selectionRanges.codeBasedSelections.map(({ range }) => - getNodePathFromSourceRange(kclManager.ast, range) - ) - const nodes = paths.map( - (pathToNode) => getNodeFromPath(kclManager.ast, pathToNode).node - ) - const varDecs = paths.map( - (pathToNode) => - getNodeFromPath( - kclManager.ast, - pathToNode, - 'VariableDeclarator' - )?.node - ) - const primaryLine = varDecs[0] - const secondaryVarDecs = varDecs.slice(1) - const isOthersLinkedToPrimary = secondaryVarDecs.every((secondary) => - isSketchVariablesLinked(secondary, primaryLine, kclManager.ast) - ) - const isAllTooltips = nodes.every( - (node) => - node?.type === 'CallExpression' && - toolTips.includes(node.callee.name as any) - ) - - const theTransforms = getTransformInfos( - { - ...selectionRanges, - codeBasedSelections: selectionRanges.codeBasedSelections.slice(1), - }, - kclManager.ast, - 'equalAngle' - ) - setTransformInfos(theTransforms) - - const _enableEqual = - !!secondaryVarDecs.length && - isAllTooltips && - isOthersLinkedToPrimary && - theTransforms.every(Boolean) - setEnableEqual(_enableEqual) - }, [guiMode, selectionRanges]) - if (guiMode.mode !== 'sketch') return null - - return ( - +export function equalAngleInfo({ + selectionRanges, +}: { + selectionRanges: Selections +}) { + const paths = selectionRanges.codeBasedSelections.map(({ range }) => + getNodePathFromSourceRange(kclManager.ast, range) ) + const nodes = paths.map( + (pathToNode) => getNodeFromPath(kclManager.ast, pathToNode).node + ) + const varDecs = paths.map( + (pathToNode) => + getNodeFromPath( + kclManager.ast, + pathToNode, + 'VariableDeclarator' + )?.node + ) + const primaryLine = varDecs[0] + const secondaryVarDecs = varDecs.slice(1) + const isOthersLinkedToPrimary = secondaryVarDecs.every((secondary) => + isSketchVariablesLinked(secondary, primaryLine, kclManager.ast) + ) + const isAllTooltips = nodes.every( + (node) => + node?.type === 'CallExpression' && + toolTips.includes(node.callee.name as any) + ) + + const transforms = getTransformInfos( + { + ...selectionRanges, + codeBasedSelections: selectionRanges.codeBasedSelections.slice(1), + }, + kclManager.ast, + 'equalAngle' + ) + + const enabled = + !!secondaryVarDecs.length && + isAllTooltips && + isOthersLinkedToPrimary && + transforms.every(Boolean) + return { enabled, transforms } +} + +export function applyConstraintEqualAngle({ + selectionRanges, +}: { + selectionRanges: Selections +}): { + modifiedAst: Program + pathToNodeMap: PathToNodeMap +} { + const { transforms } = equalAngleInfo({ selectionRanges }) + const { modifiedAst, pathToNodeMap } = transformSecondarySketchLinesTagFirst({ + ast: kclManager.ast, + selectionRanges, + transformInfos: transforms, + programMemory: kclManager.programMemory, + }) + return { modifiedAst, pathToNodeMap } } -*/ diff --git a/src/components/Toolbar/EqualLength.tsx b/src/components/Toolbar/EqualLength.tsx index 6c927dd2d..32e715f5f 100644 --- a/src/components/Toolbar/EqualLength.tsx +++ b/src/components/Toolbar/EqualLength.tsx @@ -1,5 +1,4 @@ -import { useState, useEffect } from 'react' -import { Selections, toolTips, useStore } from '../../useStore' +import { Selections, toolTips } from '../../useStore' import { Program, Value, VariableDeclarator } from '../../lang/wasm' import { getNodePathFromSourceRange, @@ -7,63 +6,12 @@ import { } from '../../lang/queryAst' import { isSketchVariablesLinked } from '../../lang/std/sketchConstraints' import { - TransformInfo, transformSecondarySketchLinesTagFirst, getTransformInfos, PathToNodeMap, } from '../../lang/std/sketchcombos' -import { ActionIcon } from 'components/ActionIcon' -import { sketchButtonClassnames } from 'Toolbar' import { kclManager } from 'lang/KclSinglton' -/* -export const EqualLength = () => { - const { guiMode, selectionRanges, setCursor } = useStore((s) => ({ - guiMode: s.guiMode, - selectionRanges: s.selectionRanges, - setCursor: s.setCursor, - })) - const [enableEqual, setEnableEqual] = useState(false) - const [transformInfos, setTransformInfos] = useState() - useEffect(() => { - const { enabled, transforms } = setEqualLengthInfo({ selectionRanges }) - - setTransformInfos(transforms) - setEnableEqual(enabled) - }, [guiMode, selectionRanges]) - if (guiMode.mode !== 'sketch') return null - - return ( - - ) -} -*/ export function setEqualLengthInfo({ selectionRanges, }: { diff --git a/src/components/Toolbar/HorzVert.tsx b/src/components/Toolbar/HorzVert.tsx index 85b2a2788..0de799b69 100644 --- a/src/components/Toolbar/HorzVert.tsx +++ b/src/components/Toolbar/HorzVert.tsx @@ -1,5 +1,4 @@ -import { useState, useEffect } from 'react' -import { toolTips, useStore } from '../../useStore' +import { toolTips } from '../../useStore' import { Program, ProgramMemory, Value } from '../../lang/wasm' import { getNodePathFromSourceRange, @@ -7,67 +6,12 @@ import { } from '../../lang/queryAst' import { PathToNodeMap, - TransformInfo, getTransformInfos, transformAstSketchLines, } from '../../lang/std/sketchcombos' -import { ActionIcon } from 'components/ActionIcon' -import { sketchButtonClassnames } from 'Toolbar' import { kclManager } from 'lang/KclSinglton' import { Selections } from 'useStore' -/* -export const HorzVert = ({ - horOrVert, -}: { - horOrVert: 'vertical' | 'horizontal' -}) => { - const { guiMode, selectionRanges, setCursor } = useStore((s) => ({ - guiMode: s.guiMode, - selectionRanges: s.selectionRanges, - setCursor: s.setCursor, - })) - const [enableHorz, setEnableHorz] = useState(false) - const [transformInfos, setTransformInfos] = useState() - useEffect(() => { - const { enabled, transforms } = horzVertInfo(selectionRanges, horOrVert) - setTransformInfos(transforms) - setEnableHorz(enabled) - }, [guiMode, selectionRanges]) - if (guiMode.mode !== 'sketch') return null - - return ( - - ) -} -*/ - export function horzVertInfo( selectionRanges: Selections, horOrVert: 'vertical' | 'horizontal' @@ -110,7 +54,4 @@ export function applyConstraintHorzVert( programMemory, referenceSegName: '', }) - // kclManager.updateAst(modifiedAst, true, { - // callBack: updateCursors(setCursor, selectionRanges, pathToNodeMap), - // }) } diff --git a/src/components/Toolbar/Intersect.tsx b/src/components/Toolbar/Intersect.tsx index 6717382ab..c86761583 100644 --- a/src/components/Toolbar/Intersect.tsx +++ b/src/components/Toolbar/Intersect.tsx @@ -1,7 +1,5 @@ -import { useState, useEffect } from 'react' -import { create } from 'react-modal-promise' -import { toolTips, useStore } from '../../useStore' -import { BinaryPart, Value, VariableDeclarator } from '../../lang/wasm' +import { Selections, toolTips } from '../../useStore' +import { BinaryPart, Program, Value, VariableDeclarator } from '../../lang/wasm' import { getNodePathFromSourceRange, getNodeFromPath, @@ -9,181 +7,170 @@ import { } from '../../lang/queryAst' import { isSketchVariablesLinked } from '../../lang/std/sketchConstraints' import { - TransformInfo, transformSecondarySketchLinesTagFirst, getTransformInfos, + PathToNodeMap, } from '../../lang/std/sketchcombos' -import { GetInfoModal } from '../SetHorVertDistanceModal' +import { GetInfoModal, createInfoModal } from '../SetHorVertDistanceModal' import { createVariableDeclaration } from '../../lang/modifyAst' import { removeDoubleNegatives } from '../AvailableVarsHelpers' import { kclManager } from 'lang/KclSinglton' -const getModalInfo = create(GetInfoModal as any) +const getModalInfo = createInfoModal(GetInfoModal) -/* -export const Intersect = () => { - const { guiMode, selectionRanges, setCursor } = useStore((s) => ({ - guiMode: s.guiMode, - selectionRanges: s.selectionRanges, - setCursor: s.setCursor, - })) - const [enable, setEnable] = useState(false) - const [transformInfos, setTransformInfos] = useState() - const [forecdSelectionRanges, setForcedSelectionRanges] = - useState() - useEffect(() => { - if (selectionRanges.codeBasedSelections.length < 2) { - setEnable(false) - setForcedSelectionRanges({ ...selectionRanges }) - return +export function intersectInfo({ + selectionRanges, +}: { + selectionRanges: Selections +}) { + if (selectionRanges.codeBasedSelections.length < 2) { + return { + enabled: false, + transforms: [], + forcedSelectionRanges: { ...selectionRanges }, } + } - const previousSegment = - selectionRanges.codeBasedSelections.length > 1 && - isLinesParallelAndConstrained( - kclManager.ast, - kclManager.programMemory, - selectionRanges.codeBasedSelections[0], - selectionRanges.codeBasedSelections[1] - ) - const shouldUsePreviousSegment = - selectionRanges.codeBasedSelections?.[1]?.type !== 'line-end' && - previousSegment && - previousSegment.isParallelAndConstrained - - const _forcedSelectionRanges: typeof selectionRanges = { - ...selectionRanges, - codeBasedSelections: [ - selectionRanges.codeBasedSelections?.[0], - shouldUsePreviousSegment - ? { - range: previousSegment.sourceRange, - type: 'line-end', - } - : selectionRanges.codeBasedSelections?.[1], - ], - } - setForcedSelectionRanges(_forcedSelectionRanges) - - const paths = _forcedSelectionRanges.codeBasedSelections.map(({ range }) => - getNodePathFromSourceRange(kclManager.ast, range) - ) - const nodes = paths.map( - (pathToNode) => getNodeFromPath(kclManager.ast, pathToNode).node - ) - const varDecs = paths.map( - (pathToNode) => - getNodeFromPath( - kclManager.ast, - pathToNode, - 'VariableDeclarator' - )?.node - ) - const primaryLine = varDecs[0] - const secondaryVarDecs = varDecs.slice(1) - const isOthersLinkedToPrimary = secondaryVarDecs.every((secondary) => - isSketchVariablesLinked(secondary, primaryLine, kclManager.ast) - ) - const isAllTooltips = nodes.every( - (node) => - node?.type === 'CallExpression' && - [ - ...toolTips, - 'startSketchAt', // TODO probably a better place for this to live - ].includes(node.callee.name as any) - ) - - const theTransforms = getTransformInfos( - { - ...selectionRanges, - codeBasedSelections: - _forcedSelectionRanges.codeBasedSelections.slice(1), - }, + const previousSegment = + selectionRanges.codeBasedSelections.length > 1 && + isLinesParallelAndConstrained( kclManager.ast, - 'intersect' + kclManager.programMemory, + selectionRanges.codeBasedSelections[0], + selectionRanges.codeBasedSelections[1] ) - setTransformInfos(theTransforms) + const shouldUsePreviousSegment = + selectionRanges.codeBasedSelections?.[1]?.type !== 'line-end' && + previousSegment && + previousSegment.isParallelAndConstrained - const _enableEqual = - secondaryVarDecs.length === 1 && - isAllTooltips && - isOthersLinkedToPrimary && - theTransforms.every(Boolean) && - _forcedSelectionRanges?.codeBasedSelections?.[1]?.type === 'line-end' - setEnable(_enableEqual) - }, [guiMode, selectionRanges]) - if (guiMode.mode !== 'sketch') return null - - return ( - + : selectionRanges.codeBasedSelections?.[1], + ], + } + + const paths = _forcedSelectionRanges.codeBasedSelections.map(({ range }) => + getNodePathFromSourceRange(kclManager.ast, range) ) + const nodes = paths.map( + (pathToNode) => getNodeFromPath(kclManager.ast, pathToNode).node + ) + const varDecs = paths.map( + (pathToNode) => + getNodeFromPath( + kclManager.ast, + pathToNode, + 'VariableDeclarator' + )?.node + ) + const primaryLine = varDecs[0] + const secondaryVarDecs = varDecs.slice(1) + const isOthersLinkedToPrimary = secondaryVarDecs.every((secondary) => + isSketchVariablesLinked(secondary, primaryLine, kclManager.ast) + ) + const isAllTooltips = nodes.every( + (node) => + node?.type === 'CallExpression' && + [ + ...toolTips, + 'startSketchAt', // TODO probably a better place for this to live + ].includes(node.callee.name as any) + ) + + const theTransforms = getTransformInfos( + { + ...selectionRanges, + codeBasedSelections: _forcedSelectionRanges.codeBasedSelections.slice(1), + }, + kclManager.ast, + 'intersect' + ) + + const _enableEqual = + secondaryVarDecs.length === 1 && + isAllTooltips && + isOthersLinkedToPrimary && + theTransforms.every(Boolean) && + _forcedSelectionRanges?.codeBasedSelections?.[1]?.type === 'line-end' + + return { + enabled: _enableEqual, + transforms: theTransforms, + forcedSelectionRanges: _forcedSelectionRanges, + } +} + +export async function applyConstraintIntersect({ + selectionRanges, +}: { + selectionRanges: Selections +}): Promise<{ + modifiedAst: Program + pathToNodeMap: PathToNodeMap +}> { + const { transforms, forcedSelectionRanges } = intersectInfo({ + selectionRanges, + }) + const { modifiedAst, tagInfo, valueUsedInTransform, pathToNodeMap } = + transformSecondarySketchLinesTagFirst({ + ast: JSON.parse(JSON.stringify(kclManager.ast)), + selectionRanges: forcedSelectionRanges, + transformInfos: transforms, + programMemory: kclManager.programMemory, + }) + const { + segName, + value, + valueNode, + variableName, + newVariableInsertIndex, + sign, + } = await getModalInfo({ + segName: tagInfo?.tag, + isSegNameEditable: !tagInfo?.isTagExisting, + value: valueUsedInTransform, + initialVariableName: 'offset', + }) + if (segName === tagInfo?.tag && Number(value) === valueUsedInTransform) { + return { + modifiedAst, + pathToNodeMap, + } + } + // transform again but forcing certain values + const finalValue = removeDoubleNegatives( + valueNode as BinaryPart, + sign, + variableName + ) + const { modifiedAst: _modifiedAst, pathToNodeMap: _pathToNodeMap } = + transformSecondarySketchLinesTagFirst({ + ast: kclManager.ast, + selectionRanges: forcedSelectionRanges, + transformInfos: transforms, + programMemory: kclManager.programMemory, + forceSegName: segName, + forceValueUsedInTransform: finalValue, + }) + if (variableName) { + const newBody = [..._modifiedAst.body] + newBody.splice( + newVariableInsertIndex, + 0, + createVariableDeclaration(variableName, valueNode) + ) + _modifiedAst.body = newBody + } + return { + modifiedAst: _modifiedAst, + pathToNodeMap: _pathToNodeMap, + } } -*/ diff --git a/src/components/Toolbar/RemoveConstrainingValues.tsx b/src/components/Toolbar/RemoveConstrainingValues.tsx index c61bcba11..fbe6983ed 100644 --- a/src/components/Toolbar/RemoveConstrainingValues.tsx +++ b/src/components/Toolbar/RemoveConstrainingValues.tsx @@ -1,75 +1,62 @@ -import { useState, useEffect } from 'react' -import { toolTips, useStore } from '../../useStore' -import { Value } from '../../lang/wasm' +import { Selections, toolTips } from '../../useStore' +import { Program, Value } from '../../lang/wasm' import { getNodePathFromSourceRange, getNodeFromPath, } from '../../lang/queryAst' import { - TransformInfo, + PathToNodeMap, getRemoveConstraintsTransforms, transformAstSketchLines, } from '../../lang/std/sketchcombos' import { kclManager } from 'lang/KclSinglton' -/* -export const RemoveConstrainingValues = () => { - const { guiMode, selectionRanges, setCursor } = useStore((s) => ({ - guiMode: s.guiMode, - selectionRanges: s.selectionRanges, - setCursor: s.setCursor, - })) - const [enableHorz, setEnableHorz] = useState(false) - const [transformInfos, setTransformInfos] = useState() - useEffect(() => { - const paths = selectionRanges.codeBasedSelections.map(({ range }) => - getNodePathFromSourceRange(kclManager.ast, range) - ) - const nodes = paths.map( - (pathToNode) => getNodeFromPath(kclManager.ast, pathToNode).node - ) - const isAllTooltips = nodes.every( - (node) => - node?.type === 'CallExpression' && - toolTips.includes(node.callee.name as any) - ) - - try { - const theTransforms = getRemoveConstraintsTransforms( - selectionRanges, - kclManager.ast, - 'removeConstrainingValues' - ) - setTransformInfos(theTransforms) - - const _enableHorz = isAllTooltips && theTransforms.every(Boolean) - setEnableHorz(_enableHorz) - } catch (e) { - console.error(e) - } - }, [guiMode, selectionRanges]) - if (guiMode.mode !== 'sketch') return null - - return ( - +export function removeConstrainingValuesInfo({ + selectionRanges, +}: { + selectionRanges: Selections +}) { + const paths = selectionRanges.codeBasedSelections.map(({ range }) => + getNodePathFromSourceRange(kclManager.ast, range) ) + const nodes = paths.map( + (pathToNode) => getNodeFromPath(kclManager.ast, pathToNode).node + ) + const isAllTooltips = nodes.every( + (node) => + node?.type === 'CallExpression' && + toolTips.includes(node.callee.name as any) + ) + + try { + const transforms = getRemoveConstraintsTransforms( + selectionRanges, + kclManager.ast, + 'removeConstrainingValues' + ) + + const enabled = isAllTooltips && transforms.every(Boolean) + return { enabled, transforms } + } catch (e) { + console.error(e) + return { enabled: false, transforms: [] } + } +} + +export function applyRemoveConstrainingValues({ + selectionRanges, +}: { + selectionRanges: Selections +}): { + modifiedAst: Program + pathToNodeMap: PathToNodeMap +} { + const { transforms } = removeConstrainingValuesInfo({ selectionRanges }) + return transformAstSketchLines({ + ast: kclManager.ast, + selectionRanges, + transformInfos: transforms, + programMemory: kclManager.programMemory, + referenceSegName: '', + }) } -*/ diff --git a/src/components/Toolbar/SetAbsDistance.tsx b/src/components/Toolbar/SetAbsDistance.tsx index 80c6e5fc3..39fce64ee 100644 --- a/src/components/Toolbar/SetAbsDistance.tsx +++ b/src/components/Toolbar/SetAbsDistance.tsx @@ -1,18 +1,18 @@ -import { useState, useEffect } from 'react' -import { create } from 'react-modal-promise' -import { toolTips, useStore } from '../../useStore' -import { Value } from '../../lang/wasm' +import { Selections, toolTips } from '../../useStore' +import { BinaryPart, Program, Value } from '../../lang/wasm' import { getNodePathFromSourceRange, getNodeFromPath, } from '../../lang/queryAst' import { - TransformInfo, getTransformInfos, transformAstSketchLines, - ConstraintType, + PathToNodeMap, } from '../../lang/std/sketchcombos' -import { SetAngleLengthModal } from '../SetAngleLengthModal' +import { + SetAngleLengthModal, + createSetAngleLengthModal, +} from '../SetAngleLengthModal' import { createIdentifier, createVariableDeclaration, @@ -20,128 +20,132 @@ import { import { removeDoubleNegatives } from '../AvailableVarsHelpers' import { kclManager } from 'lang/KclSinglton' -const getModalInfo = create(SetAngleLengthModal as any) +const getModalInfo = createSetAngleLengthModal(SetAngleLengthModal) -type ButtonType = 'xAbs' | 'yAbs' | 'snapToYAxis' | 'snapToXAxis' +type Constraint = 'xAbs' | 'yAbs' | 'snapToYAxis' | 'snapToXAxis' -const buttonLabels: Record = { - xAbs: 'Set distance from X Axis', - yAbs: 'Set distance from Y Axis', - snapToYAxis: 'Snap To Y Axis', - snapToXAxis: 'Snap To X Axis', -} - -/* -export const SetAbsDistance = ({ buttonType }: { buttonType: ButtonType }) => { - const { guiMode, selectionRanges, setCursor } = useStore((s) => ({ - guiMode: s.guiMode, - selectionRanges: s.selectionRanges, - setCursor: s.setCursor, - })) - const disType: ConstraintType = - buttonType === 'xAbs' || buttonType === 'yAbs' - ? buttonType - : buttonType === 'snapToYAxis' +export function absDistanceInfo({ + selectionRanges, + constraint, +}: { + selectionRanges: Selections + constraint: Constraint +}) { + const disType = + constraint === 'xAbs' || constraint === 'yAbs' + ? constraint + : constraint === 'snapToYAxis' ? 'xAbs' : 'yAbs' - const [enableAngLen, setEnableAngLen] = useState(false) - const [transformInfos, setTransformInfos] = useState() - useEffect(() => { - const paths = selectionRanges.codeBasedSelections.map(({ range }) => - getNodePathFromSourceRange(kclManager.ast, range) - ) - const nodes = paths.map( - (pathToNode) => - getNodeFromPath(kclManager.ast, pathToNode, 'CallExpression') - .node - ) - const isAllTooltips = nodes.every( - (node) => - node?.type === 'CallExpression' && - toolTips.includes(node.callee.name as any) - ) - - const theTransforms = getTransformInfos( - selectionRanges, - kclManager.ast, - disType - ) - setTransformInfos(theTransforms) - - const enableY = - disType === 'yAbs' && - selectionRanges.otherSelections.length === 1 && - selectionRanges.otherSelections[0] === 'x-axis' // select the x axis to set the distance from it i.e. y - const enableX = - disType === 'xAbs' && - selectionRanges.otherSelections.length === 1 && - selectionRanges.otherSelections[0] === 'y-axis' // select the y axis to set the distance from it i.e. x - - const _enableHorz = - isAllTooltips && - theTransforms.every(Boolean) && - selectionRanges.codeBasedSelections.length === 1 && - (enableX || enableY) - setEnableAngLen(_enableHorz) - }, [guiMode, selectionRanges]) - if (guiMode.mode !== 'sketch') return null - - const isAlign = buttonType === 'snapToYAxis' || buttonType === 'snapToXAxis' - - return ( - + const paths = selectionRanges.codeBasedSelections.map(({ range }) => + getNodePathFromSourceRange(kclManager.ast, range) ) + const nodes = paths.map( + (pathToNode) => + getNodeFromPath(kclManager.ast, pathToNode, 'CallExpression').node + ) + const isAllTooltips = nodes.every( + (node) => + node?.type === 'CallExpression' && + toolTips.includes(node.callee.name as any) + ) + + const transforms = getTransformInfos(selectionRanges, kclManager.ast, disType) + + const enableY = + disType === 'yAbs' && + selectionRanges.otherSelections.length === 1 && + selectionRanges.otherSelections[0] === 'x-axis' // select the x axis to set the distance from it i.e. y + const enableX = + disType === 'xAbs' && + selectionRanges.otherSelections.length === 1 && + selectionRanges.otherSelections[0] === 'y-axis' // select the y axis to set the distance from it i.e. x + + const enabled = + isAllTooltips && + transforms.every(Boolean) && + selectionRanges.codeBasedSelections.length === 1 && + (enableX || enableY) + + return { enabled, transforms } +} + +export async function applyConstraintAbsDistance({ + selectionRanges, + constraint, +}: { + selectionRanges: Selections + constraint: 'xAbs' | 'yAbs' +}): Promise<{ + modifiedAst: Program + pathToNodeMap: PathToNodeMap +}> { + const transformInfos = absDistanceInfo({ + selectionRanges, + constraint, + }).transforms + const { valueUsedInTransform } = transformAstSketchLines({ + ast: JSON.parse(JSON.stringify(kclManager.ast)), + selectionRanges: selectionRanges, + transformInfos, + programMemory: kclManager.programMemory, + referenceSegName: '', + }) + let forceVal = valueUsedInTransform || 0 + const { valueNode, variableName, newVariableInsertIndex, sign } = + await getModalInfo({ + value: forceVal, + valueName: constraint === 'yAbs' ? 'yDis' : 'xDis', + }) + let finalValue = removeDoubleNegatives( + valueNode as BinaryPart, + sign, + variableName + ) + + const { modifiedAst: _modifiedAst, pathToNodeMap } = transformAstSketchLines({ + ast: JSON.parse(JSON.stringify(kclManager.ast)), + selectionRanges: selectionRanges, + transformInfos, + programMemory: kclManager.programMemory, + referenceSegName: '', + forceValueUsedInTransform: finalValue, + }) + if (variableName) { + const newBody = [..._modifiedAst.body] + newBody.splice( + newVariableInsertIndex, + 0, + createVariableDeclaration(variableName, valueNode) + ) + _modifiedAst.body = newBody + } + return { modifiedAst: _modifiedAst, pathToNodeMap } +} + +export function applyConstraintAxisAlign({ + selectionRanges, + constraint, +}: { + selectionRanges: Selections + constraint: 'snapToYAxis' | 'snapToXAxis' +}): { + modifiedAst: Program + pathToNodeMap: PathToNodeMap +} { + const transformInfos = absDistanceInfo({ + selectionRanges, + constraint, + }).transforms + + let finalValue = createIdentifier('_0') + + return transformAstSketchLines({ + ast: JSON.parse(JSON.stringify(kclManager.ast)), + selectionRanges: selectionRanges, + transformInfos, + programMemory: kclManager.programMemory, + referenceSegName: '', + forceValueUsedInTransform: finalValue, + }) } -*/ diff --git a/src/components/Toolbar/SetAngleBetween.tsx b/src/components/Toolbar/SetAngleBetween.tsx index 74d271563..024fb68d4 100644 --- a/src/components/Toolbar/SetAngleBetween.tsx +++ b/src/components/Toolbar/SetAngleBetween.tsx @@ -1,6 +1,4 @@ -import { useState, useEffect } from 'react' -import { create } from 'react-modal-promise' -import { Selections, toolTips, useStore } from '../../useStore' +import { Selections, toolTips } from '../../useStore' import { BinaryPart, Program, Value, VariableDeclarator } from '../../lang/wasm' import { getNodePathFromSourceRange, @@ -8,107 +6,16 @@ import { } from '../../lang/queryAst' import { isSketchVariablesLinked } from '../../lang/std/sketchConstraints' import { - TransformInfo, transformSecondarySketchLinesTagFirst, getTransformInfos, PathToNodeMap, } from '../../lang/std/sketchcombos' -import { GetInfoModal } from '../SetHorVertDistanceModal' +import { GetInfoModal, createInfoModal } from '../SetHorVertDistanceModal' import { createVariableDeclaration } from '../../lang/modifyAst' import { removeDoubleNegatives } from '../AvailableVarsHelpers' import { kclManager } from 'lang/KclSinglton' -const getModalInfo = create(GetInfoModal as any) - -/* -export const SetAngleBetween = () => { - const { guiMode, selectionRanges, setCursor } = useStore((s) => ({ - guiMode: s.guiMode, - selectionRanges: s.selectionRanges, - setCursor: s.setCursor, - })) - const [enable, setEnable] = useState(false) - const [transformInfos, setTransformInfos] = useState() - useEffect(() => { - const { enabled, transforms } = angleBetweenInfo({ selectionRanges }) - setTransformInfos(transforms) - setEnable(enabled) - }, [guiMode, selectionRanges]) - if (guiMode.mode !== 'sketch') return null - - return ( - - ) -} -*/ +const getModalInfo = createInfoModal(GetInfoModal) export function angleBetweenInfo({ selectionRanges, @@ -183,28 +90,17 @@ export async function applyConstraintAngleBetween({ variableName, newVariableInsertIndex, sign, - }: { - segName: string - value: number - valueNode: Value - variableName?: string - newVariableInsertIndex: number - sign: number } = await getModalInfo({ segName: tagInfo?.tag, isSegNameEditable: !tagInfo?.isTagExisting, value: valueUsedInTransform, initialVariableName: 'angle', } as any) - if (segName === tagInfo?.tag && value === valueUsedInTransform) { + if (segName === tagInfo?.tag && Number(value) === valueUsedInTransform) { return { modifiedAst, pathToNodeMap, } - // kclManager.updateAst(modifiedAst, true, { - // TODO handle cursor - // callBack: updateCursors(setCursor, selectionRanges, pathToNodeMap), - // }) } const finalValue = removeDoubleNegatives( @@ -235,8 +131,4 @@ export async function applyConstraintAngleBetween({ modifiedAst: _modifiedAst, pathToNodeMap: _pathToNodeMap, } - // kclManager.updateAst(_modifiedAst, true, { - // TODO handle cursor - // callBack: updateCursors(setCursor, selectionRanges, pathToNodeMap), - // }) } diff --git a/src/components/Toolbar/SetHorzVertDistance.tsx b/src/components/Toolbar/SetHorzVertDistance.tsx index 70fb19f0c..fa57da98c 100644 --- a/src/components/Toolbar/SetHorzVertDistance.tsx +++ b/src/components/Toolbar/SetHorzVertDistance.tsx @@ -1,6 +1,4 @@ -import { useState, useEffect } from 'react' -import { create } from 'react-modal-promise' -import { toolTips, useStore } from '../../useStore' +import { toolTips } from '../../useStore' import { BinaryPart, Program, Value, VariableDeclarator } from '../../lang/wasm' import { getNodePathFromSourceRange, @@ -8,139 +6,17 @@ import { } from '../../lang/queryAst' import { isSketchVariablesLinked } from '../../lang/std/sketchConstraints' import { - TransformInfo, transformSecondarySketchLinesTagFirst, getTransformInfos, - ConstraintType, PathToNodeMap, } from '../../lang/std/sketchcombos' -import { GetInfoModal } from '../SetHorVertDistanceModal' +import { GetInfoModal, createInfoModal } from '../SetHorVertDistanceModal' import { createLiteral, createVariableDeclaration } from '../../lang/modifyAst' import { removeDoubleNegatives } from '../AvailableVarsHelpers' import { kclManager } from 'lang/KclSinglton' import { Selections } from 'useStore' -const getModalInfo = create(GetInfoModal as any) - -type ButtonType = - | 'setHorzDistance' - | 'setVertDistance' - | 'alignEndsHorizontally' - | 'alignEndsVertically' - -const buttonLabels: Record = { - setHorzDistance: 'Set Horizontal Distance', - setVertDistance: 'Set Vertical Distance', - alignEndsHorizontally: 'Align Ends Horizontally', - alignEndsVertically: 'Align Ends Vertically', -} - -/* -export const SetHorzVertDistance = ({ - buttonType, -}: { - buttonType: ButtonType -}) => { - const { guiMode, selectionRanges, setCursor } = useStore((s) => ({ - guiMode: s.guiMode, - selectionRanges: s.selectionRanges, - setCursor: s.setCursor, - })) - const constraint: ConstraintType = - buttonType === 'setHorzDistance' || buttonType === 'setVertDistance' - ? buttonType - : buttonType === 'alignEndsHorizontally' - ? 'setVertDistance' - : 'setHorzDistance' - const [enable, setEnable] = useState(false) - const [transformInfos, setTransformInfos] = useState() - useEffect(() => { - const { transforms, enabled } = horzVertDistanceInfo({ - selectionRanges, - constraint, - }) - setTransformInfos(transforms) - setEnable(enabled) - }, [guiMode, selectionRanges]) - if (guiMode.mode !== 'sketch') return null - - const isAlign = - buttonType === 'alignEndsHorizontally' || - buttonType === 'alignEndsVertically' - - return ( - - ) -} -*/ +const getModalInfo = createInfoModal(GetInfoModal) export function horzVertDistanceInfo({ selectionRanges, @@ -201,7 +77,7 @@ export async function applyConstraintHorzVertDistance({ }: { selectionRanges: Selections constraint: 'setHorzDistance' | 'setVertDistance' - isAlign?: boolean + isAlign?: false }): Promise<{ modifiedAst: Program pathToNodeMap: PathToNodeMap @@ -224,29 +100,17 @@ export async function applyConstraintHorzVertDistance({ variableName, newVariableInsertIndex, sign, - }: { - segName: string - value: number - valueNode: Value - variableName?: string - newVariableInsertIndex: number - sign: number - } = await (!isAlign && - getModalInfo({ - segName: tagInfo?.tag, - isSegNameEditable: !tagInfo?.isTagExisting, - value: valueUsedInTransform, - initialVariableName: constraint === 'setHorzDistance' ? 'xDis' : 'yDis', - } as any)) - if (segName === tagInfo?.tag && value === valueUsedInTransform) { + } = await getModalInfo({ + segName: tagInfo?.tag, + isSegNameEditable: !tagInfo?.isTagExisting, + value: valueUsedInTransform, + initialVariableName: constraint === 'setHorzDistance' ? 'xDis' : 'yDis', + } as any) + if (segName === tagInfo?.tag && Number(value) === valueUsedInTransform) { return { modifiedAst, pathToNodeMap, } - // TODO handle cursor stuff - // kclManager.updateAst(modifiedAst, true, { - // callBack: updateCursors(setCursor, selectionRanges, pathToNodeMap), - // }) } else { let finalValue = isAlign ? createLiteral(0) @@ -274,10 +138,6 @@ export async function applyConstraintHorzVertDistance({ modifiedAst: _modifiedAst, pathToNodeMap, } - // TODO handle cursor stuff - // kclManager.updateAst(_modifiedAst, true, { - // callBack: updateCursors(setCursor, selectionRanges, pathToNodeMap), - // }) } } @@ -307,8 +167,4 @@ export function applyConstraintHorzVertAlign({ modifiedAst: modifiedAst, pathToNodeMap, } - // TODO handle cursor stuff - // kclManager.updateAst(_modifiedAst, true, { - // callBack: updateCursors(setCursor, selectionRanges, pathToNodeMap), - // }) } diff --git a/src/components/Toolbar/setAngleLength.tsx b/src/components/Toolbar/setAngleLength.tsx index d6c005198..5bde35cf2 100644 --- a/src/components/Toolbar/setAngleLength.tsx +++ b/src/components/Toolbar/setAngleLength.tsx @@ -1,18 +1,18 @@ -import { useState, useEffect } from 'react' -import { create } from 'react-modal-promise' -import { Selections, toolTips, useStore } from '../../useStore' -import { Program, Value } from '../../lang/wasm' +import { Selections, toolTips } from '../../useStore' +import { BinaryPart, Program, Value } from '../../lang/wasm' import { getNodePathFromSourceRange, getNodeFromPath, } from '../../lang/queryAst' import { PathToNodeMap, - TransformInfo, getTransformInfos, transformAstSketchLines, } from '../../lang/std/sketchcombos' -import { SetAngleLengthModal } from '../SetAngleLengthModal' +import { + SetAngleLengthModal, + createSetAngleLengthModal, +} from '../SetAngleLengthModal' import { createBinaryExpressionWithUnary, createIdentifier, @@ -22,128 +22,7 @@ import { removeDoubleNegatives } from '../AvailableVarsHelpers' import { normaliseAngle } from '../../lib/utils' import { kclManager } from 'lang/KclSinglton' -const getModalInfo = create(SetAngleLengthModal as any) - -type ButtonType = 'setAngle' | 'setLength' - -const buttonLabels: Record = { - setAngle: 'Set Angle', - setLength: 'Set Length', -} - -/* -export const SetAngleLength = ({ - angleOrLength, -}: { - angleOrLength: ButtonType -}) => { - const { guiMode, selectionRanges, setCursor } = useStore((s) => ({ - guiMode: s.guiMode, - selectionRanges: s.selectionRanges, - setCursor: s.setCursor, - })) - const [enableAngLen, setEnableAngLen] = useState(false) - const [transformInfos, setTransformInfos] = useState() - useEffect(() => { - const { enabled, transforms } = setAngleLengthInfo({ - selectionRanges, - angleOrLength, - }) - - setTransformInfos(transforms) - setEnableAngLen(enabled) - }, [guiMode, selectionRanges]) - if (guiMode.mode !== 'sketch') return null - - return ( - - ) -} -*/ +const getModalInfo = createSetAngleLengthModal(SetAngleLengthModal) export function setAngleLengthInfo({ selectionRanges, @@ -220,8 +99,13 @@ export async function applyConstraintAngleLength({ value: forceVal, valueName: angleOrLength === 'setAngle' ? 'angle' : 'length', shouldCreateVariable: true, - } as any) - let finalValue = removeDoubleNegatives(valueNode, sign, variableName) + }) + + let finalValue = removeDoubleNegatives( + valueNode as BinaryPart, + sign, + variableName + ) if ( isReferencingYAxisAngle || (isReferencingXAxisAngle && calcIdentifier.name !== '_0') @@ -251,9 +135,6 @@ export async function applyConstraintAngleLength({ modifiedAst: _modifiedAst, pathToNodeMap, } - // kclManager.updateAst(_modifiedAst, true, { - // callBack: updateCursors(setCursor, selectionRanges, pathToNodeMap), - // }) } catch (e) { console.log('erorr', e) throw e diff --git a/src/hooks/useToolbarGuards.ts b/src/hooks/useToolbarGuards.ts index 71c8ffca0..5ec05e14f 100644 --- a/src/hooks/useToolbarGuards.ts +++ b/src/hooks/useToolbarGuards.ts @@ -1,12 +1,14 @@ -import { SetVarNameModal } from 'components/SetVarNameModal' +import { + SetVarNameModal, + createSetVarNameModal, +} from 'components/SetVarNameModal' import { kclManager } from 'lang/KclSinglton' import { moveValueIntoNewVariable } from 'lang/modifyAst' import { isNodeSafeToReplace } from 'lang/queryAst' import { useEffect, useState } from 'react' -import { create } from 'react-modal-promise' import { useModelingContext } from './useModelingContext' -const getModalInfo = create(SetVarNameModal as any) +const getModalInfo = createSetVarNameModal(SetVarNameModal) export function useConvertToVariable() { const { context } = useModelingContext() @@ -28,7 +30,7 @@ export function useConvertToVariable() { try { const { variableName } = await getModalInfo({ valueName: 'var', - } as any) + }) const { modifiedAst: _modifiedAst } = moveValueIntoNewVariable( kclManager.ast, diff --git a/src/machines/modelingMachine.ts b/src/machines/modelingMachine.ts index e82247614..1c0a66ec9 100644 --- a/src/machines/modelingMachine.ts +++ b/src/machines/modelingMachine.ts @@ -29,6 +29,15 @@ import { extrudeSketch } from 'lang/modifyAst' import { getNodeFromPath } from '../lang/queryAst' import { CallExpression, PipeExpression } from '../lang/wasm' import { getConstraintLevelFromSourceRange } from 'lang/std/sketchcombos' +import { + applyConstraintEqualAngle, + equalAngleInfo, +} from 'components/Toolbar/EqualAngle' +import { + applyRemoveConstrainingValues, + removeConstrainingValuesInfo, +} from 'components/Toolbar/RemoveConstrainingValues' +import { intersectInfo } from 'components/Toolbar/Intersect' export const MODELING_PERSIST_KEY = 'MODELING_PERSIST_KEY' @@ -52,7 +61,7 @@ export type SetSelections = export const modelingMachine = createMachine( { - /** @xstate-layout N4IgpgJg5mDOIC5QFkD2EwBsCWA7KAxAMICGuAxlgNoAMAuoqAA6qzYAu2qujIAHogDMAVgDsAOmEiAjLMGCAHIIAsAJlHKANCACeiaQDZBEsctGrVATmmiaNQQF8H2tBhz5x2CJjAEAymDsAASwWGDknNy0DEggLGyRPLECCMrCCuL20qrCRpYagvnaegjZBtLiBqLploIGCtZVyk4u6Fh4UJ7evgAicGERQSx47NG88RxcSaApdcKSNKIKi8ppwsrLwsX60oriqgaWBgbKImpWqi0gru0eXj4EfaE+g5AwY7ETibyzx5lLu1sygM61ERV0+ho0mU4gURlOwihlis2SuN3cnXuvX6L2CJD42FgH2YrEm3B+QnM4mqdhoyPUILqBm2CAaFTS5houQUCMczmubQxXQeAVxQ1QI2JcVJ32SiGUXPEhjBtWklgaokMzIhq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EVQO+P9BLVdA6XAuQ-HShMHWg0nUPFcgxWzXRLSZacoLSWPUVfIbMXnJ5H-TCRi4PFXD3NQsnDi6rakOkdYSsGeEQUxccixPsIRNTbk00jPNI4yQfeg9il86s-onRMQLSMwaWC1JSERGoj0FQEk-JV5E8o-fS4A9XOS2QC8KQOkF8EMbcpSR+EmC5WwUMU4IgnvWmUghQygpQjg1iz3YyqsyvLbDIFQWoqEKQHTOwsXJ+avDvfjHSucg8dwzwtsZ8lK7WI4UWM1TGcNQsKilCRYc2HYukCxeyWWVI67DoxYuaLWN0XKC8CFYkpdTUqo4JbKJYAofKVE2WWY+YqATonlAazmbA4bFAjaHkWoPY0odIBPKcGwWvHsHCJwIAA */ id: 'Modeling', tsTypes: {} as import('./modelingMachine.typegen').Typegen0, @@ -122,10 +131,13 @@ export const modelingMachine = createMachine( | { type: 'Constrain horizontal distance' } | { type: 'Constrain vertical distance' } | { type: 'Constrain angle' } + | { type: 'Constrain perpendicular distance' } | { type: 'Constrain horizontally align' } | { type: 'Constrain vertically align' } | { type: 'Constrain length' } | { type: 'Constrain equal length' } + | { type: 'Constrain parallel' } + | { type: 'Constrain remove constraints' } | { type: 'extrude intent' }, // , }, @@ -356,6 +368,11 @@ export const modelingMachine = createMachine( cond: 'Can constrain length', }, + 'Constrain perpendicular distance': { + target: 'Await perpendicular distance info', + cond: 'Can constrain perpendicular distance', + }, + 'Constrain horizontally align': { cond: 'Can constrain horizontally align', target: 'SketchIdle', @@ -376,6 +393,20 @@ export const modelingMachine = createMachine( internal: true, actions: ['Constrain equal length'], }, + + 'Constrain parallel': { + target: 'SketchIdle', + internal: true, + cond: 'Can canstrain parallel', + actions: ['Constrain parallel'], + }, + + 'Constrain remove constraints': { + target: 'SketchIdle', + internal: true, + cond: 'Can constrain remove constraints', + actions: ['Constrain remove constraints'], + }, }, entry: 'equip select', @@ -528,6 +559,18 @@ export const modelingMachine = createMachine( onError: 'SketchIdle', }, }, + + 'Await perpendicular distance info': { + invoke: { + src: 'Get perpendicular distance info', + id: 'get-perpendicular-distance-info', + onDone: { + target: 'SketchIdle', + actions: 'Set selection', + }, + onError: 'SketchIdle', + }, + }, }, initial: 'SketchIdle', @@ -613,6 +656,8 @@ export const modelingMachine = createMachine( angleBetweenInfo({ selectionRanges }).enabled, 'Can constrain length': ({ selectionRanges }) => setAngleLengthInfo({ selectionRanges }).enabled, + 'Can constrain perpendicular distance': ({ selectionRanges }) => + intersectInfo({ selectionRanges }).enabled, 'Can constrain horizontally align': ({ selectionRanges }) => horzVertDistanceInfo({ selectionRanges, constraint: 'setHorzDistance' }) .enabled, @@ -621,6 +666,10 @@ export const modelingMachine = createMachine( .enabled, 'Can constrain equal length': ({ selectionRanges }) => setEqualLengthInfo({ selectionRanges }).enabled, + 'Can canstrain parallel': ({ selectionRanges }) => + equalAngleInfo({ selectionRanges }).enabled, + 'Can constrain remove constraints': ({ selectionRanges }) => + removeConstrainingValuesInfo({ selectionRanges }).enabled, 'has no selection': ({ selectionRanges }) => { if (selectionRanges?.codeBasedSelections?.length < 1) return true const selection = selectionRanges?.codeBasedSelections?.[0] || {} @@ -825,6 +874,8 @@ export const modelingMachine = createMachine( tool: 'move', }, }), + // TODO implement source ranges for all of these constraints + // need to make the async like the modal constraints 'Make selection horizontal': ({ selectionRanges }) => { const { modifiedAst, pathToNodeMap } = applyConstraintHorzVert( selectionRanges, @@ -832,10 +883,7 @@ export const modelingMachine = createMachine( kclManager.ast, kclManager.programMemory ) - kclManager.updateAst(modifiedAst, true, { - // TODO re implement cursor shit - // callBack: updateCursors(setCursor, selectionRanges, pathToNodeMap), - }) + kclManager.updateAst(modifiedAst, true) }, 'Make selection vertical': ({ selectionRanges }) => { const { modifiedAst, pathToNodeMap } = applyConstraintHorzVert( @@ -844,39 +892,39 @@ export const modelingMachine = createMachine( kclManager.ast, kclManager.programMemory ) - kclManager.updateAst(modifiedAst, true, { - // TODO re implement cursor shit - // callBack: updateCursors(setCursor, selectionRanges, pathToNodeMap), - }) + kclManager.updateAst(modifiedAst, true) }, 'Constrain horizontally align': ({ selectionRanges }) => { const { modifiedAst, pathToNodeMap } = applyConstraintHorzVertAlign({ selectionRanges, constraint: 'setVertDistance', }) - kclManager.updateAst(modifiedAst, true, { - // TODO re implement cursor shit - // callBack: updateCursors(setCursor, selectionRanges, pathToNodeMap), - }) + kclManager.updateAst(modifiedAst, true) }, 'Constrain vertically align': ({ selectionRanges }) => { const { modifiedAst, pathToNodeMap } = applyConstraintHorzVertAlign({ selectionRanges, constraint: 'setHorzDistance', }) - kclManager.updateAst(modifiedAst, true, { - // TODO re implement cursor shit - // callBack: updateCursors(setCursor, selectionRanges, pathToNodeMap), - }) + kclManager.updateAst(modifiedAst, true) }, 'Constrain equal length': ({ selectionRanges }) => { const { modifiedAst, pathToNodeMap } = applyConstraintEqualLength({ selectionRanges, }) - kclManager.updateAst(modifiedAst, true, { - // TODO re implement cursor shit - // callBack: updateCursors(setCursor, selectionRanges, pathToNodeMap), + kclManager.updateAst(modifiedAst, true) + }, + 'Constrain parallel': ({ selectionRanges }) => { + const { modifiedAst, pathToNodeMap } = applyConstraintEqualAngle({ + selectionRanges, }) + kclManager.updateAst(modifiedAst, true) + }, + 'Constrain remove constraints': ({ selectionRanges }) => { + const { modifiedAst, pathToNodeMap } = applyRemoveConstrainingValues({ + selectionRanges, + }) + kclManager.updateAst(modifiedAst, true) }, 'AST extrude': ({ selectionRanges }) => { const pathToNode = getNodePathFromSourceRange( diff --git a/src/machines/modelingMachine.typegen.ts b/src/machines/modelingMachine.typegen.ts index 60f59b8b2..18ed70ebd 100644 --- a/src/machines/modelingMachine.typegen.ts +++ b/src/machines/modelingMachine.typegen.ts @@ -8,10 +8,12 @@ "done.invoke.get-angle-info": { type: "done.invoke.get-angle-info"; data: unknown; __tip: "See the XState TS docs to learn how to strongly type this." }; "done.invoke.get-horizontal-info": { type: "done.invoke.get-horizontal-info"; data: unknown; __tip: "See the XState TS docs to learn how to strongly type this." }; "done.invoke.get-length-info": { type: "done.invoke.get-length-info"; data: unknown; __tip: "See the XState TS docs to learn how to strongly type this." }; +"done.invoke.get-perpendicular-distance-info": { type: "done.invoke.get-perpendicular-distance-info"; data: unknown; __tip: "See the XState TS docs to learn how to strongly type this." }; "done.invoke.get-vertical-info": { type: "done.invoke.get-vertical-info"; data: unknown; __tip: "See the XState TS docs to learn how to strongly type this." }; "error.platform.get-angle-info": { type: "error.platform.get-angle-info"; data: unknown }; "error.platform.get-horizontal-info": { type: "error.platform.get-horizontal-info"; data: unknown }; "error.platform.get-length-info": { type: "error.platform.get-length-info"; data: unknown }; +"error.platform.get-perpendicular-distance-info": { type: "error.platform.get-perpendicular-distance-info"; data: unknown }; "error.platform.get-vertical-info": { type: "error.platform.get-vertical-info"; data: unknown }; "xstate.init": { type: "xstate.init" }; "xstate.stop": { type: "xstate.stop" }; @@ -20,13 +22,14 @@ "Get angle info": "done.invoke.get-angle-info"; "Get horizontal info": "done.invoke.get-horizontal-info"; "Get length info": "done.invoke.get-length-info"; +"Get perpendicular distance info": "done.invoke.get-perpendicular-distance-info"; "Get vertical info": "done.invoke.get-vertical-info"; }; missingImplementations: { actions: "AST add line segment" | "AST start new sketch" | "Modify AST" | "Set selection" | "Update code selection cursors" | "create path" | "set tool" | "show default planes" | "sketch exit execute" | "toast extrude failed"; delays: never; guards: "Selection contains axis" | "Selection contains edge" | "Selection contains face" | "Selection contains line" | "Selection contains point" | "Selection is not empty" | "Selection is one face"; - services: "Get angle info" | "Get horizontal info" | "Get length info" | "Get vertical info"; + services: "Get angle info" | "Get horizontal info" | "Get length info" | "Get perpendicular distance info" | "Get vertical info"; }; eventsCausingActions: { "AST add line segment": "Add point"; @@ -37,19 +40,21 @@ "Clear selection": "Deselect all"; "Constrain equal length": "Constrain equal length"; "Constrain horizontally align": "Constrain horizontally align"; +"Constrain parallel": "Constrain parallel"; +"Constrain remove constraints": "Constrain remove constraints"; "Constrain vertically align": "Constrain vertically align"; "Make selection horizontal": "Make segment horizontal"; "Make selection vertical": "Make segment vertical"; "Modify AST": "Complete line"; "Remove from code-based selection": "Deselect edge" | "Deselect face" | "Deselect point"; "Remove from other selection": "Deselect axis"; -"Set selection": "Set selection" | "done.invoke.get-angle-info" | "done.invoke.get-horizontal-info" | "done.invoke.get-length-info" | "done.invoke.get-vertical-info"; +"Set selection": "Set selection" | "done.invoke.get-angle-info" | "done.invoke.get-horizontal-info" | "done.invoke.get-length-info" | "done.invoke.get-perpendicular-distance-info" | "done.invoke.get-vertical-info"; "Update code selection cursors": "Complete line" | "Deselect all" | "Deselect axis" | "Deselect edge" | "Deselect face" | "Deselect point" | "Deselect segment" | "Select edge" | "Select face" | "Select point" | "Select segment"; "create path": "Select default plane"; "default_camera_disable_sketch_mode": "Cancel"; "edit mode enter": "Enter sketch"; "edit_mode_exit": "Cancel"; -"equip select": "CancelSketch" | "Constrain equal length" | "Constrain horizontally align" | "Constrain vertically align" | "Deselect point" | "Deselect segment" | "Enter sketch" | "Make segment horizontal" | "Make segment vertical" | "Select default plane" | "Select point" | "Select segment" | "Set selection" | "done.invoke.get-angle-info" | "done.invoke.get-horizontal-info" | "done.invoke.get-length-info" | "done.invoke.get-vertical-info" | "error.platform.get-angle-info" | "error.platform.get-horizontal-info" | "error.platform.get-length-info" | "error.platform.get-vertical-info"; +"equip select": "CancelSketch" | "Constrain equal length" | "Constrain horizontally align" | "Constrain parallel" | "Constrain remove constraints" | "Constrain vertically align" | "Deselect point" | "Deselect segment" | "Enter sketch" | "Make segment horizontal" | "Make segment vertical" | "Select default plane" | "Select point" | "Select segment" | "Set selection" | "done.invoke.get-angle-info" | "done.invoke.get-horizontal-info" | "done.invoke.get-length-info" | "done.invoke.get-perpendicular-distance-info" | "done.invoke.get-vertical-info" | "error.platform.get-angle-info" | "error.platform.get-horizontal-info" | "error.platform.get-length-info" | "error.platform.get-perpendicular-distance-info" | "error.platform.get-vertical-info"; "hide default planes": "Cancel" | "Select default plane" | "xstate.stop"; "reset sketch metadata": "Cancel" | "Select default plane"; "set default plane id": "Select default plane"; @@ -66,11 +71,14 @@ }; eventsCausingGuards: { - "Can constrain angle": "Constrain angle"; + "Can canstrain parallel": "Constrain parallel"; +"Can constrain angle": "Constrain angle"; "Can constrain equal length": "Constrain equal length"; "Can constrain horizontal distance": "Constrain horizontal distance"; "Can constrain horizontally align": "Constrain horizontally align"; "Can constrain length": "Constrain length"; +"Can constrain perpendicular distance": "Constrain perpendicular distance"; +"Can constrain remove constraints": "Constrain remove constraints"; "Can constrain vertical distance": "Constrain vertical distance"; "Can constrain vertically align": "Constrain vertically align"; "Can make selection horizontal": "Make segment horizontal"; @@ -92,9 +100,10 @@ "Get angle info": "Constrain angle"; "Get horizontal info": "Constrain horizontal distance"; "Get length info": "Constrain length"; +"Get perpendicular distance info": "Constrain perpendicular distance"; "Get vertical info": "Constrain vertical distance"; }; - matchesStates: "Sketch" | "Sketch no face" | "Sketch.Await angle info" | "Sketch.Await horizontal distance info" | "Sketch.Await length info" | "Sketch.Await vertical distance info" | "Sketch.Line Tool" | "Sketch.Line Tool.Done" | "Sketch.Line Tool.Init" | "Sketch.Line Tool.No Points" | "Sketch.Line Tool.Point Added" | "Sketch.Line Tool.Segment Added" | "Sketch.Move Tool" | "Sketch.Move Tool.Move init" | "Sketch.Move Tool.Move with execute" | "Sketch.Move Tool.Move without re-execute" | "Sketch.Move Tool.No move" | "Sketch.SketchIdle" | "awaiting selection" | "checking selection" | "idle" | { "Sketch"?: "Await angle info" | "Await horizontal distance info" | "Await length info" | "Await vertical distance info" | "Line Tool" | "Move Tool" | "SketchIdle" | { "Line Tool"?: "Done" | "Init" | "No Points" | "Point Added" | "Segment Added"; + matchesStates: "Sketch" | "Sketch no face" | "Sketch.Await angle info" | "Sketch.Await horizontal distance info" | "Sketch.Await length info" | "Sketch.Await perpendicular distance info" | "Sketch.Await vertical distance info" | "Sketch.Line Tool" | "Sketch.Line Tool.Done" | "Sketch.Line Tool.Init" | "Sketch.Line Tool.No Points" | "Sketch.Line Tool.Point Added" | "Sketch.Line Tool.Segment Added" | "Sketch.Move Tool" | "Sketch.Move Tool.Move init" | "Sketch.Move Tool.Move with execute" | "Sketch.Move Tool.Move without re-execute" | "Sketch.Move Tool.No move" | "Sketch.SketchIdle" | "awaiting selection" | "checking selection" | "idle" | { "Sketch"?: "Await angle info" | "Await horizontal distance info" | "Await length info" | "Await perpendicular distance info" | "Await vertical distance info" | "Line Tool" | "Move Tool" | "SketchIdle" | { "Line Tool"?: "Done" | "Init" | "No Points" | "Point Added" | "Segment Added"; "Move Tool"?: "Move init" | "Move with execute" | "Move without re-execute" | "No move"; }; }; tags: never; }