diff --git a/src/lang/modifyAst/addEdgeTreatment.ts b/src/lang/modifyAst/addEdgeTreatment.ts index baa0f702f..ccabe905b 100644 --- a/src/lang/modifyAst/addEdgeTreatment.ts +++ b/src/lang/modifyAst/addEdgeTreatment.ts @@ -61,19 +61,18 @@ export interface FilletParameters { export type EdgeTreatmentParameters = ChamferParameters | FilletParameters // Apply Edge Treatment (Fillet or Chamfer) To Selection -export function applyEdgeTreatmentToSelection( +export async function applyEdgeTreatmentToSelection( ast: Node, selection: Selections, parameters: EdgeTreatmentParameters -): void | Error { +): Promise { // 1. clone and modify with edge treatment and tag const result = modifyAstWithEdgeTreatmentAndTag(ast, selection, parameters) if (err(result)) return result const { modifiedAst, pathToEdgeTreatmentNode } = result // 2. update ast - // eslint-disable-next-line @typescript-eslint/no-floating-promises - updateAstAndFocus(modifiedAst, pathToEdgeTreatmentNode) + await updateAstAndFocus(modifiedAst, pathToEdgeTreatmentNode) } export function modifyAstWithEdgeTreatmentAndTag( @@ -291,7 +290,7 @@ export function getPathToExtrudeForSegmentSelection( async function updateAstAndFocus( modifiedAst: Node, pathToEdgeTreatmentNode: Array -) { +): Promise { const updatedAst = await kclManager.updateAst(modifiedAst, true, { focusPath: pathToEdgeTreatmentNode, }) diff --git a/src/machines/modelingMachine.ts b/src/machines/modelingMachine.ts index bf720e794..3399c507d 100644 --- a/src/machines/modelingMachine.ts +++ b/src/machines/modelingMachine.ts @@ -763,30 +763,6 @@ export const modelingMachine = setup({ await codeManager.updateEditorWithAstAndWriteToFile(modifiedAst) })().catch(reportRejection) }, - 'AST fillet': ({ event }) => { - if (event.type !== 'Fillet') return - if (!event.data) return - - // Extract inputs - const ast = kclManager.ast - const { selection, radius } = event.data - const parameters: FilletParameters = { - type: EdgeTreatmentType.Fillet, - radius, - } - - // Apply fillet to selection - const applyEdgeTreatmentToSelectionResult = applyEdgeTreatmentToSelection( - ast, - selection, - parameters - ) - if (err(applyEdgeTreatmentToSelectionResult)) - return applyEdgeTreatmentToSelectionResult - - // eslint-disable-next-line @typescript-eslint/no-floating-promises - codeManager.updateEditorWithAstAndWriteToFile(kclManager.ast) - }, 'set selection filter to curves only': () => { ;(async () => { await engineCommandManager.sendSceneCommand({ @@ -1670,6 +1646,33 @@ export const modelingMachine = setup({ } } ), + filletAstMod: fromPromise( + async ({ + input, + }: { + input: ModelingCommandSchema['Fillet'] | undefined + }) => { + if (!input) { + return new Error('No input provided') + } + + // Extract inputs + const ast = kclManager.ast + const { selection, radius } = input + const parameters: FilletParameters = { + type: EdgeTreatmentType.Fillet, + radius, + } + + // Apply fillet to selection + const filletResult = await applyEdgeTreatmentToSelection( + ast, + selection, + parameters + ) + if (err(filletResult)) return filletResult + } + ), 'submit-prompt-edit': fromPromise( async ({ input }: { input: ModelingCommandSchema['Prompt-to-edit'] }) => { console.log('doing thing', input) @@ -1745,9 +1748,8 @@ export const modelingMachine = setup({ }, Fillet: { - target: 'idle', - actions: ['AST fillet'], - reenter: false, + target: 'Applying fillet', + reenter: true, }, Export: { @@ -2553,6 +2555,19 @@ export const modelingMachine = setup({ }, }, + 'Applying fillet': { + invoke: { + src: 'filletAstMod', + id: 'filletAstMod', + input: ({ event }) => { + if (event.type !== 'Fillet') return undefined + return event.data + }, + onDone: ['idle'], + onError: ['idle'], + }, + }, + 'Applying Prompt-to-edit': { invoke: { src: 'submit-prompt-edit',