WIP: experimenting with Loft UI

Relates to #4470
This commit is contained in:
Pierre Jacquier
2024-11-27 15:55:01 -05:00
parent 412d1b7a99
commit 647ca11e08
3 changed files with 65 additions and 2 deletions

View File

@ -31,6 +31,9 @@ export type ModelingCommandSchema = {
// result: (typeof EXTRUSION_RESULTS)[number] // result: (typeof EXTRUSION_RESULTS)[number]
distance: KclCommandValue distance: KclCommandValue
} }
Loft: {
selection: Selections
}
Revolve: { Revolve: {
selection: Selections selection: Selections
angle: KclCommandValue angle: KclCommandValue
@ -260,6 +263,20 @@ export const modelingMachineCommandConfig: StateMachineCommandSetConfig<
}, },
}, },
}, },
Loft: {
description: 'Create a 3D body by blending between two or more sketches',
icon: 'loft',
needsReview: true,
args: {
selection: {
inputType: 'selection',
selectionTypes: ['solid2D', 'segment'],
multiple: true,
required: true,
skip: true,
},
},
},
// TODO: Update this configuration, copied from extrude for MVP of revolve, specifically the args.selection // TODO: Update this configuration, copied from extrude for MVP of revolve, specifically the args.selection
Revolve: { Revolve: {
description: 'Create a 3D body by rotating a sketch region about an axis.', description: 'Create a 3D body by rotating a sketch region about an axis.',

View File

@ -139,9 +139,14 @@ export const toolbarConfig: Record<ToolbarModeName, ToolbarMode> = {
}, },
{ {
id: 'loft', id: 'loft',
onClick: () => console.error('Loft not yet implemented'), onClick: ({ commandBarSend }) =>
commandBarSend({
type: 'Find and select command',
data: { name: 'Loft', groupId: 'modeling' },
}),
disabled: (state) => !state.can({ type: 'Extrude' }),
icon: 'loft', icon: 'loft',
status: 'kcl-only', status: 'available',
title: 'Loft', title: 'Loft',
hotkey: 'L', hotkey: 'L',
description: description:

View File

@ -252,6 +252,7 @@ export type ModelingMachineEvent =
| { type: 'Export'; data: ModelingCommandSchema['Export'] } | { type: 'Export'; data: ModelingCommandSchema['Export'] }
| { type: 'Make'; data: ModelingCommandSchema['Make'] } | { type: 'Make'; data: ModelingCommandSchema['Make'] }
| { type: 'Extrude'; data?: ModelingCommandSchema['Extrude'] } | { type: 'Extrude'; data?: ModelingCommandSchema['Extrude'] }
| { type: 'Loft'; data?: ModelingCommandSchema['Loft'] }
| { type: 'Revolve'; data?: ModelingCommandSchema['Revolve'] } | { type: 'Revolve'; data?: ModelingCommandSchema['Revolve'] }
| { type: 'Fillet'; data?: ModelingCommandSchema['Fillet'] } | { type: 'Fillet'; data?: ModelingCommandSchema['Fillet'] }
| { type: 'Offset plane'; data: ModelingCommandSchema['Offset plane'] } | { type: 'Offset plane'; data: ModelingCommandSchema['Offset plane'] }
@ -705,6 +706,39 @@ export const modelingMachine = setup({
} }
})().catch(reportRejection) })().catch(reportRejection)
}, },
'AST loft': ({ context: { store }, event }) => {
if (event.type !== 'Loft') return
;(async () => {
if (!event.data) return
const { selection } = event.data
let ast = kclManager.ast
const pathToNode = getNodePathFromSourceRange(
ast,
selection.graphSelections[0]?.codeRef.range
)
const loftSketchesRes = loftSketches(
ast,
pathToNode,
)
if (trap(loftSketchesRes)) return
const { modifiedAst, pathToLoftArg } = loftSketchesRes
const updatedAst = await kclManager.updateAst(modifiedAst, true, {
focusPath: [pathToLoftArg],
zoomToFit: true,
zoomOnRangeAndType: {
range: selection.graphSelections[0]?.codeRef.range,
type: 'path',
},
})
await codeManager.updateEditorWithAstAndWriteToFile(updatedAst.newAst)
if (updatedAst?.selections) {
editorManager.selectRange(updatedAst?.selections)
}
})().catch(reportRejection)
},
'AST delete selection': ({ context: { selectionRanges } }) => { 'AST delete selection': ({ context: { selectionRanges } }) => {
;(async () => { ;(async () => {
let ast = kclManager.ast let ast = kclManager.ast
@ -1561,6 +1595,13 @@ export const modelingMachine = setup({
reenter: false, reenter: false,
}, },
Loft: {
target: 'idle',
guard: 'has valid sweep selection',
actions: ['AST loft'],
reenter: false,
},
Fillet: { Fillet: {
target: 'idle', target: 'idle',
guard: 'has valid fillet selection', // TODO: fix selections guard: 'has valid fillet selection', // TODO: fix selections