Refactor Fillet AST Mod to Async Actor (#4803)
This commit is contained in:
@ -61,19 +61,18 @@ export interface FilletParameters {
|
|||||||
export type EdgeTreatmentParameters = ChamferParameters | FilletParameters
|
export type EdgeTreatmentParameters = ChamferParameters | FilletParameters
|
||||||
|
|
||||||
// Apply Edge Treatment (Fillet or Chamfer) To Selection
|
// Apply Edge Treatment (Fillet or Chamfer) To Selection
|
||||||
export function applyEdgeTreatmentToSelection(
|
export async function applyEdgeTreatmentToSelection(
|
||||||
ast: Node<Program>,
|
ast: Node<Program>,
|
||||||
selection: Selections,
|
selection: Selections,
|
||||||
parameters: EdgeTreatmentParameters
|
parameters: EdgeTreatmentParameters
|
||||||
): void | Error {
|
): Promise<void | Error> {
|
||||||
// 1. clone and modify with edge treatment and tag
|
// 1. clone and modify with edge treatment and tag
|
||||||
const result = modifyAstWithEdgeTreatmentAndTag(ast, selection, parameters)
|
const result = modifyAstWithEdgeTreatmentAndTag(ast, selection, parameters)
|
||||||
if (err(result)) return result
|
if (err(result)) return result
|
||||||
const { modifiedAst, pathToEdgeTreatmentNode } = result
|
const { modifiedAst, pathToEdgeTreatmentNode } = result
|
||||||
|
|
||||||
// 2. update ast
|
// 2. update ast
|
||||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
await updateAstAndFocus(modifiedAst, pathToEdgeTreatmentNode)
|
||||||
updateAstAndFocus(modifiedAst, pathToEdgeTreatmentNode)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function modifyAstWithEdgeTreatmentAndTag(
|
export function modifyAstWithEdgeTreatmentAndTag(
|
||||||
@ -291,7 +290,7 @@ export function getPathToExtrudeForSegmentSelection(
|
|||||||
async function updateAstAndFocus(
|
async function updateAstAndFocus(
|
||||||
modifiedAst: Node<Program>,
|
modifiedAst: Node<Program>,
|
||||||
pathToEdgeTreatmentNode: Array<PathToNode>
|
pathToEdgeTreatmentNode: Array<PathToNode>
|
||||||
) {
|
): Promise<void> {
|
||||||
const updatedAst = await kclManager.updateAst(modifiedAst, true, {
|
const updatedAst = await kclManager.updateAst(modifiedAst, true, {
|
||||||
focusPath: pathToEdgeTreatmentNode,
|
focusPath: pathToEdgeTreatmentNode,
|
||||||
})
|
})
|
||||||
|
@ -763,30 +763,6 @@ export const modelingMachine = setup({
|
|||||||
await codeManager.updateEditorWithAstAndWriteToFile(modifiedAst)
|
await codeManager.updateEditorWithAstAndWriteToFile(modifiedAst)
|
||||||
})().catch(reportRejection)
|
})().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': () => {
|
'set selection filter to curves only': () => {
|
||||||
;(async () => {
|
;(async () => {
|
||||||
await engineCommandManager.sendSceneCommand({
|
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(
|
'submit-prompt-edit': fromPromise(
|
||||||
async ({ input }: { input: ModelingCommandSchema['Prompt-to-edit'] }) => {
|
async ({ input }: { input: ModelingCommandSchema['Prompt-to-edit'] }) => {
|
||||||
console.log('doing thing', input)
|
console.log('doing thing', input)
|
||||||
@ -1745,9 +1748,8 @@ export const modelingMachine = setup({
|
|||||||
},
|
},
|
||||||
|
|
||||||
Fillet: {
|
Fillet: {
|
||||||
target: 'idle',
|
target: 'Applying fillet',
|
||||||
actions: ['AST fillet'],
|
reenter: true,
|
||||||
reenter: false,
|
|
||||||
},
|
},
|
||||||
|
|
||||||
Export: {
|
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': {
|
'Applying Prompt-to-edit': {
|
||||||
invoke: {
|
invoke: {
|
||||||
src: 'submit-prompt-edit',
|
src: 'submit-prompt-edit',
|
||||||
|
Reference in New Issue
Block a user