From d8c168e7f8d56c78e50d0f126ced35a9b40646f3 Mon Sep 17 00:00:00 2001 From: Pierre Jacquier Date: Mon, 16 Jun 2025 15:50:56 -0400 Subject: [PATCH] Add twistAng --- src/lang/modifyAst/addSweep.ts | 6 ++++++ .../commandBarConfigs/modelingCommandConfig.ts | 6 ++++++ src/lib/operations.ts | 18 ++++++++++++++++++ src/machines/modelingMachine.ts | 11 +++++++++-- 4 files changed, 39 insertions(+), 2 deletions(-) diff --git a/src/lang/modifyAst/addSweep.ts b/src/lang/modifyAst/addSweep.ts index 8dbf2ad02..88a7e4d61 100644 --- a/src/lang/modifyAst/addSweep.ts +++ b/src/lang/modifyAst/addSweep.ts @@ -38,6 +38,7 @@ export function addExtrude({ sketches, length, bidirectionalLength, + twistAngle, symmetric, nodeToEdit, }: { @@ -45,6 +46,7 @@ export function addExtrude({ sketches: Selections length: KclCommandValue bidirectionalLength?: KclCommandValue + twistAngle?: KclCommandValue symmetric?: boolean nodeToEdit?: PathToNode }): @@ -76,6 +78,9 @@ export function addExtrude({ ), ] : [] + const twistAngleExpr = twistAngle + ? [createLabeledArg('twistAngle', valueOrVariable(twistAngle))] + : [] const symmetricExpr = symmetric ? [createLabeledArg('symmetric', createLiteral(symmetric))] : [] @@ -84,6 +89,7 @@ export function addExtrude({ const call = createCallExpressionStdLibKw('extrude', sketchesExpr, [ createLabeledArg('length', valueOrVariable(length)), ...bidirectionalLengthExpr, + ...twistAngleExpr, ...symmetricExpr, ]) diff --git a/src/lib/commandBarConfigs/modelingCommandConfig.ts b/src/lib/commandBarConfigs/modelingCommandConfig.ts index 19574130e..d678120a8 100644 --- a/src/lib/commandBarConfigs/modelingCommandConfig.ts +++ b/src/lib/commandBarConfigs/modelingCommandConfig.ts @@ -62,6 +62,7 @@ export type ModelingCommandSchema = { length: KclCommandValue symmetric?: boolean bidirectionalLength?: KclCommandValue + twistAngle?: KclCommandValue } Sweep: { // Enables editing workflow @@ -410,6 +411,11 @@ export const modelingMachineCommandConfig: StateMachineCommandSetConfig< skip: true, required: false, }, + twistAngle: { + inputType: 'kcl', + skip: true, + required: false, + }, }, }, Sweep: { diff --git a/src/lib/operations.ts b/src/lib/operations.ts index a99041c1f..643ab17db 100644 --- a/src/lib/operations.ts +++ b/src/lib/operations.ts @@ -116,6 +116,23 @@ const prepareToEditExtrude: PrepareToEditCallback = async ({ operation }) => { return { reason: "Couldn't retrieve bidirectionalLength argument" } } + // twistAngle argument from a string to a KCL expression + let twistAngle: KclCommandValue | Error | ParseResult | undefined + if ( + 'twistAngle' in operation.labeledArgs && + operation.labeledArgs.twistAngle + ) { + twistAngle = await stringToKclExpression( + codeManager.code.slice( + operation.labeledArgs.twistAngle.sourceRange[0], + operation.labeledArgs.twistAngle.sourceRange[1] + ) + ) + } + if (err(twistAngle) || (twistAngle && 'errors' in twistAngle)) { + return { reason: "Couldn't retrieve twistAngle argument" } + } + // symmetric argument from a string to boolean let symmetric: boolean | undefined if ('symmetric' in operation.labeledArgs && operation.labeledArgs.symmetric) { @@ -133,6 +150,7 @@ const prepareToEditExtrude: PrepareToEditCallback = async ({ operation }) => { sketches, length, bidirectionalLength, + twistAngle, symmetric, nodeToEdit: pathToNodeFromRustNodePath(operation.nodePath), } diff --git a/src/machines/modelingMachine.ts b/src/machines/modelingMachine.ts index 924e74743..177df3741 100644 --- a/src/machines/modelingMachine.ts +++ b/src/machines/modelingMachine.ts @@ -2429,14 +2429,21 @@ export const modelingMachine = setup({ return Promise.reject(new Error(NO_INPUT_PROVIDED_MESSAGE)) } - const { nodeToEdit, sketches, length, bidirectionalLength, symmetric } = - input + const { + nodeToEdit, + sketches, + length, + bidirectionalLength, + twistAngle, + symmetric, + } = input const { ast } = kclManager const astResult = addExtrude({ ast, sketches, length, bidirectionalLength, + twistAngle, symmetric, nodeToEdit, })