Add twistAng

This commit is contained in:
Pierre Jacquier
2025-06-16 15:50:56 -04:00
parent 8706767b9f
commit d8c168e7f8
4 changed files with 39 additions and 2 deletions

View File

@ -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,
])

View File

@ -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: {

View File

@ -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),
}

View File

@ -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,
})