WIP: initial shell code addition

This commit is contained in:
Pierre Jacquier
2024-12-04 16:38:44 -05:00
parent 5156b847f3
commit f4c54cbbe4
7 changed files with 89 additions and 2 deletions

View File

@ -7,6 +7,7 @@ export class ToolbarFixture {
extrudeButton!: Locator
loftButton!: Locator
shellButton!: Locator
offsetPlaneButton!: Locator
startSketchBtn!: Locator
lineBtn!: Locator
@ -28,6 +29,7 @@ export class ToolbarFixture {
this.page = page
this.extrudeButton = page.getByTestId('extrude')
this.loftButton = page.getByTestId('loft')
this.shellButton = page.getByTestId('shell')
this.offsetPlaneButton = page.getByTestId('plane-offset')
this.startSketchBtn = page.getByTestId('sketch')
this.lineBtn = page.getByTestId('line')

View File

@ -585,6 +585,22 @@ export const ModelingMachineProvider = ({
if (err(canLoft)) return false
return canLoft
},
'has valid shell selection': ({ context: { selectionRanges } }) => {
const hasNoSelection =
selectionRanges.graphSelections.length === 0 ||
isRangeBetweenCharacters(selectionRanges) ||
isSelectionLastLine(selectionRanges, codeManager.code)
if (hasNoSelection) {
// TODO: find extrude in ast
// return doesSceneHaveSweepableSketch(kclManager.ast, count)
}
// const canShell = canShellSelection(selectionRanges)
// if (err(canShell)) return false
// return canShell
return true
},
'has valid selection for deletion': ({
context: { selectionRanges },
}) => {

View File

@ -377,6 +377,38 @@ export function loftSketches(
}
}
export function shellExtrude(
node: Node<Program>,
declarators: VariableDeclarator[]
): {
modifiedAst: Node<Program>
pathToNode: PathToNode
} {
const modifiedAst = structuredClone(node)
const name = findUniqueName(node, KCL_DEFAULT_CONSTANT_PREFIXES.SHELL)
const elements = declarators.map((d) => createIdentifier(d.id.name))
// TODO: change to what's needed for shell
const shell = createCallExpressionStdLib('shell', [
createArrayExpression(elements),
])
const declaration = createVariableDeclaration(name, shell)
modifiedAst.body.push(declaration)
const pathToNode: PathToNode = [
['body', ''],
[modifiedAst.body.length - 1, 'index'],
['declarations', 'VariableDeclaration'],
['0', 'index'],
['init', 'VariableDeclarator'],
['arguments', 'CallExpression'],
[0, 'index'],
]
return {
modifiedAst,
pathToNode,
}
}
export function revolveSketch(
node: Node<Program>,
pathToNode: PathToNode,

View File

@ -34,6 +34,10 @@ export type ModelingCommandSchema = {
Loft: {
selection: Selections
}
Shell: {
selection: Selections
thickness: KclCommandValue
}
Revolve: {
selection: Selections
angle: KclCommandValue
@ -277,6 +281,25 @@ export const modelingMachineCommandConfig: StateMachineCommandSetConfig<
},
},
},
Shell: {
description: 'Hollow out a 3D solid.',
icon: 'loft',
needsReview: true,
args: {
selection: {
inputType: 'selection',
selectionTypes: ['face'],
multiple: true,
required: true,
skip: false,
},
thickness: {
inputType: 'kcl',
defaultValue: KCL_DEFAULT_LENGTH,
required: true,
},
},
},
// TODO: Update this configuration, copied from extrude for MVP of revolve, specifically the args.selection
Revolve: {
description: 'Create a 3D body by rotating a sketch region about an axis.',

View File

@ -53,6 +53,7 @@ export const KCL_DEFAULT_CONSTANT_PREFIXES = {
SKETCH: 'sketch',
EXTRUDE: 'extrude',
LOFT: 'loft',
SHELL: 'shell',
SEGMENT: 'seg',
REVOLVE: 'revolve',
PLANE: 'plane',

View File

@ -190,9 +190,16 @@ export const toolbarConfig: Record<ToolbarModeName, ToolbarMode> = {
},
{
id: 'shell',
onClick: () => console.error('Shell not yet implemented'),
onClick: ({ commandBarSend }) => {
commandBarSend({
type: 'Find and select command',
data: { name: 'Offset plane', groupId: 'modeling' },
})
},
disabled: (state) => !state.can({ type: 'Shell' }),
icon: 'shell',
status: 'kcl-only',
status: 'available',
hotkey: 'S',
title: 'Shell',
description: 'Hollow out a 3D solid.',
links: [{ label: 'KCL docs', url: 'https://zoo.dev/docs/kcl/shell' }],

View File

@ -390,6 +390,7 @@ export const modelingMachine = setup({
'Selection is on face': () => false,
'has valid sweep selection': () => false,
'has valid loft selection': () => false,
'has valid shell selection': () => false,
'has valid edge treatment selection': () => false,
'Has exportable geometry': () => false,
'has valid selection for deletion': () => false,
@ -1622,6 +1623,11 @@ export const modelingMachine = setup({
reenter: true,
},
Shell: {
target: 'Applying shell',
reenter: true,
},
Fillet: {
target: 'idle',
guard: 'has valid edge treatment selection',