diff --git a/e2e/playwright/snapshot-tests.spec.ts-snapshots/Grid-visibility-Grid-turned-off-to-on-via-command-bar-1-Google-Chrome-win32.png b/e2e/playwright/snapshot-tests.spec.ts-snapshots/Grid-visibility-Grid-turned-off-to-on-via-command-bar-1-Google-Chrome-win32.png new file mode 100644 index 000000000..872574dd8 Binary files /dev/null and b/e2e/playwright/snapshot-tests.spec.ts-snapshots/Grid-visibility-Grid-turned-off-to-on-via-command-bar-1-Google-Chrome-win32.png differ diff --git a/e2e/playwright/snapshot-tests.spec.ts-snapshots/Zoom-to-fit-on-load---solid-2d-1-Google-Chrome-win32.png b/e2e/playwright/snapshot-tests.spec.ts-snapshots/Zoom-to-fit-on-load---solid-2d-1-Google-Chrome-win32.png new file mode 100644 index 000000000..313aea3c0 Binary files /dev/null and b/e2e/playwright/snapshot-tests.spec.ts-snapshots/Zoom-to-fit-on-load---solid-2d-1-Google-Chrome-win32.png differ diff --git a/src/lang/modifyAst/addRevolve.ts b/src/lang/modifyAst/addRevolve.ts index d9af1917a..2ac2a90c3 100644 --- a/src/lang/modifyAst/addRevolve.ts +++ b/src/lang/modifyAst/addRevolve.ts @@ -29,7 +29,9 @@ export function revolveSketch( pathToSketchNode: PathToNode, shouldPipe = false, angle: Expr = createLiteral(4), - axis: Selections + axisOrEdge: string, + axis: string, + edge: Selections ): | { modifiedAst: Node @@ -41,31 +43,34 @@ export function revolveSketch( const sketchNode = getNodeFromPath(clonedAst, pathToSketchNode) if (err(sketchNode)) return sketchNode - // testing code - const pathToAxisSelection = getNodePathFromSourceRange( - clonedAst, - axis.graphSelections[0]?.codeRef.range - ) + let generatedAxis - const lineNode = getNodeFromPath( - clonedAst, - pathToAxisSelection, - 'CallExpression' - ) - if (err(lineNode)) return lineNode + if (axisOrEdge === 'Edge') { + const pathToAxisSelection = getNodePathFromSourceRange( + clonedAst, + edge.graphSelections[0]?.codeRef.range + ) + const lineNode = getNodeFromPath( + clonedAst, + pathToAxisSelection, + 'CallExpression' + ) + if (err(lineNode)) return lineNode - // TODO Kevin: What if |> close(%)? - // TODO Kevin: What if opposite edge - // TODO Kevin: What if the edge isn't planar to the sketch? - // TODO Kevin: add a tag. - const tagResult = mutateAstWithTagForSketchSegment( - clonedAst, - pathToAxisSelection - ) + const tagResult = mutateAstWithTagForSketchSegment( + clonedAst, + pathToAxisSelection + ) - // Have the tag whether it is already created or a new one is generated - if (err(tagResult)) return tagResult - const { tag } = tagResult + // Have the tag whether it is already created or a new one is generated + if (err(tagResult)) return tagResult + const { tag } = tagResult + const axisSelection = edge?.graphSelections[0]?.artifact + if (!axisSelection) return new Error('Generated axis selection is missing.') + generatedAxis = getEdgeTagCall(tag, axisSelection) + } else { + generatedAxis = createLiteral(axis) + } /* Original Code */ const { node: sketchExpression } = sketchNode @@ -91,14 +96,12 @@ export function revolveSketch( shallowPath: sketchPathToDecleration, } = sketchVariableDeclaratorNode - const axisSelection = axis?.graphSelections[0]?.artifact - - if (!axisSelection) return new Error('Axis selection is missing.') + if (!generatedAxis) return new Error('Generated axis selection is missing.') const revolveCall = createCallExpressionStdLib('revolve', [ createObjectExpression({ angle: angle, - axis: getEdgeTagCall(tag, axisSelection), + axis: generatedAxis, }), createIdentifier(sketchVariableDeclarator.id.name), ]) diff --git a/src/lib/commandBarConfigs/modelingCommandConfig.ts b/src/lib/commandBarConfigs/modelingCommandConfig.ts index d7d79beb3..2f15cd67f 100644 --- a/src/lib/commandBarConfigs/modelingCommandConfig.ts +++ b/src/lib/commandBarConfigs/modelingCommandConfig.ts @@ -47,7 +47,9 @@ export type ModelingCommandSchema = { Revolve: { selection: Selections angle: KclCommandValue - axis: Selections + axisOrEdge: string + axis: string + edge: Selections } Fillet: { // todo @@ -324,7 +326,6 @@ export const modelingMachineCommandConfig: StateMachineCommandSetConfig< }, }, }, - // 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.', icon: 'revolve', @@ -337,8 +338,31 @@ export const modelingMachineCommandConfig: StateMachineCommandSetConfig< required: true, skip: true, }, - axis: { + axisOrEdge: { + inputType: 'options', required: true, + defaultValue: 'Axis', + options: [ + { name: 'Axis', isCurrent: true, value: 'Axis' }, + { name: 'Edge', isCurrent: false, value: 'Edge' }, + ], + }, + axis: { + required: (commandContext) => + ['Axis'].includes( + commandContext.argumentsToSubmit.axisOrEdge as string + ), + inputType: 'options', + options: [ + { name: 'X Axis', isCurrent: true, value: 'X' }, + { name: 'Y Axis', isCurrent: false, value: 'Y' }, + ], + }, + edge: { + required: (commandContext) => + ['Edge'].includes( + commandContext.argumentsToSubmit.axisOrEdge as string + ), inputType: 'selection', selectionTypes: ['segment', 'sweepEdge', 'edgeCutEdge'], multiple: false, diff --git a/src/lib/commandBarConfigs/validators.ts b/src/lib/commandBarConfigs/validators.ts index 41522c25c..dd161aa85 100644 --- a/src/lib/commandBarConfigs/validators.ts +++ b/src/lib/commandBarConfigs/validators.ts @@ -68,7 +68,7 @@ export const revolveAxisValidator = async ({ } const sketchSelection = artifact.pathId - let edgeSelection = data.axis.graphSelections[0].artifact?.id + let edgeSelection = data.edge.graphSelections[0].artifact?.id if (!sketchSelection) { return 'Unable to revolve, sketch is missing' @@ -101,7 +101,7 @@ export const revolveAxisValidator = async ({ return true } else { // return error message for the toast - return 'Unable to revolve with selected axis' + return 'Unable to revolve with selected edge' } } diff --git a/src/machines/modelingMachine.ts b/src/machines/modelingMachine.ts index 3399c507d..aa8726772 100644 --- a/src/machines/modelingMachine.ts +++ b/src/machines/modelingMachine.ts @@ -685,7 +685,7 @@ export const modelingMachine = setup({ if (event.type !== 'Revolve') return ;(async () => { if (!event.data) return - const { selection, angle, axis } = event.data + const { selection, angle, axis, edge, axisOrEdge } = event.data let ast = kclManager.ast if ( 'variableName' in angle && @@ -710,7 +710,9 @@ export const modelingMachine = setup({ 'variableName' in angle ? angle.variableIdentifierAst : angle.valueAst, - axis + axisOrEdge, + axis, + edge ) if (trap(revolveSketchRes)) return const { modifiedAst, pathToRevolveArg } = revolveSketchRes