diff --git a/src/lang/modifyAst/addSweep.ts b/src/lang/modifyAst/addSweep.ts index 9468da62b..8dbf2ad02 100644 --- a/src/lang/modifyAst/addSweep.ts +++ b/src/lang/modifyAst/addSweep.ts @@ -37,12 +37,14 @@ export function addExtrude({ ast, sketches, length, + bidirectionalLength, symmetric, nodeToEdit, }: { ast: Node sketches: Selections length: KclCommandValue + bidirectionalLength?: KclCommandValue symmetric?: boolean nodeToEdit?: PathToNode }): @@ -66,6 +68,14 @@ export function addExtrude({ } // Extra labeled args expressions + const bidirectionalLengthExpr = bidirectionalLength + ? [ + createLabeledArg( + 'bidirectionalLength', + valueOrVariable(bidirectionalLength) + ), + ] + : [] const symmetricExpr = symmetric ? [createLabeledArg('symmetric', createLiteral(symmetric))] : [] @@ -73,6 +83,7 @@ export function addExtrude({ const sketchesExpr = createSketchExpression(sketchesExprList) const call = createCallExpressionStdLibKw('extrude', sketchesExpr, [ createLabeledArg('length', valueOrVariable(length)), + ...bidirectionalLengthExpr, ...symmetricExpr, ]) @@ -80,6 +91,17 @@ export function addExtrude({ if ('variableName' in length && length.variableName) { insertVariableAndOffsetPathToNode(length, modifiedAst, nodeToEdit) } + if ( + bidirectionalLength && + 'variableName' in bidirectionalLength && + bidirectionalLength.variableName + ) { + insertVariableAndOffsetPathToNode( + bidirectionalLength, + modifiedAst, + nodeToEdit + ) + } // 3. If edit, we assign the new function call declaration to the existing node, // otherwise just push to the end diff --git a/src/lib/commandBarConfigs/modelingCommandConfig.ts b/src/lib/commandBarConfigs/modelingCommandConfig.ts index 8da7b51bc..3c9b19151 100644 --- a/src/lib/commandBarConfigs/modelingCommandConfig.ts +++ b/src/lib/commandBarConfigs/modelingCommandConfig.ts @@ -61,7 +61,7 @@ export type ModelingCommandSchema = { sketches: Selections length: KclCommandValue symmetric?: boolean - // bidirectionalLength?: KclCommandValue + bidirectionalLength?: KclCommandValue } Sweep: { // Enables editing workflow @@ -405,13 +405,12 @@ export const modelingMachineCommandConfig: StateMachineCommandSetConfig< { name: 'True', value: true }, ], }, - // bidirectionalLength: { - // inputType: 'kcl', - // defaultValue: KCL_DEFAULT_LENGTH, - // skip: true, - // hidden: false, - // required: false, - // }, + bidirectionalLength: { + inputType: 'kcl', + defaultValue: KCL_DEFAULT_LENGTH, + skip: true, + required: false, + }, }, }, Sweep: { diff --git a/src/lib/operations.ts b/src/lib/operations.ts index bc1fc5657..a99041c1f 100644 --- a/src/lib/operations.ts +++ b/src/lib/operations.ts @@ -20,12 +20,13 @@ import { type Program, pathToNodeFromRustNodePath, type VariableDeclaration, + type ParseResult, } from '@src/lang/wasm' import type { HelixModes, ModelingCommandSchema, } from '@src/lib/commandBarConfigs/modelingCommandConfig' -import type { KclExpression } from '@src/lib/commandTypes' +import type { KclCommandValue, KclExpression } from '@src/lib/commandTypes' import { stringToKclExpression, retrieveArgFromPipedCallExpression, @@ -95,7 +96,27 @@ const prepareToEditExtrude: PrepareToEditCallback = async ({ operation }) => { return { reason: "Couldn't retrieve length argument" } } - // symmetric argument from a string to a KCL expression + // bidirectionalLength argument from a string to a KCL expression + let bidirectionalLength: KclCommandValue | Error | ParseResult | undefined + if ( + 'bidirectionalLength' in operation.labeledArgs && + operation.labeledArgs.bidirectionalLength + ) { + bidirectionalLength = await stringToKclExpression( + codeManager.code.slice( + operation.labeledArgs.bidirectionalLength.sourceRange[0], + operation.labeledArgs.bidirectionalLength.sourceRange[1] + ) + ) + } + if ( + err(bidirectionalLength) || + (bidirectionalLength && 'errors' in bidirectionalLength) + ) { + return { reason: "Couldn't retrieve bidirectionalLength argument" } + } + + // symmetric argument from a string to boolean let symmetric: boolean | undefined if ('symmetric' in operation.labeledArgs && operation.labeledArgs.symmetric) { symmetric = @@ -111,6 +132,7 @@ const prepareToEditExtrude: PrepareToEditCallback = async ({ operation }) => { const argDefaultValues: ModelingCommandSchema['Extrude'] = { sketches, length, + bidirectionalLength, symmetric, nodeToEdit: pathToNodeFromRustNodePath(operation.nodePath), } diff --git a/src/machines/modelingMachine.ts b/src/machines/modelingMachine.ts index f073500bb..924e74743 100644 --- a/src/machines/modelingMachine.ts +++ b/src/machines/modelingMachine.ts @@ -2429,12 +2429,14 @@ export const modelingMachine = setup({ return Promise.reject(new Error(NO_INPUT_PROVIDED_MESSAGE)) } - const { nodeToEdit, sketches, length, symmetric } = input + const { nodeToEdit, sketches, length, bidirectionalLength, symmetric } = + input const { ast } = kclManager const astResult = addExtrude({ ast, sketches, length, + bidirectionalLength, symmetric, nodeToEdit, })