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, sketches,
length, length,
bidirectionalLength, bidirectionalLength,
twistAngle,
symmetric, symmetric,
nodeToEdit, nodeToEdit,
}: { }: {
@ -45,6 +46,7 @@ export function addExtrude({
sketches: Selections sketches: Selections
length: KclCommandValue length: KclCommandValue
bidirectionalLength?: KclCommandValue bidirectionalLength?: KclCommandValue
twistAngle?: KclCommandValue
symmetric?: boolean symmetric?: boolean
nodeToEdit?: PathToNode nodeToEdit?: PathToNode
}): }):
@ -76,6 +78,9 @@ export function addExtrude({
), ),
] ]
: [] : []
const twistAngleExpr = twistAngle
? [createLabeledArg('twistAngle', valueOrVariable(twistAngle))]
: []
const symmetricExpr = symmetric const symmetricExpr = symmetric
? [createLabeledArg('symmetric', createLiteral(symmetric))] ? [createLabeledArg('symmetric', createLiteral(symmetric))]
: [] : []
@ -84,6 +89,7 @@ export function addExtrude({
const call = createCallExpressionStdLibKw('extrude', sketchesExpr, [ const call = createCallExpressionStdLibKw('extrude', sketchesExpr, [
createLabeledArg('length', valueOrVariable(length)), createLabeledArg('length', valueOrVariable(length)),
...bidirectionalLengthExpr, ...bidirectionalLengthExpr,
...twistAngleExpr,
...symmetricExpr, ...symmetricExpr,
]) ])

View File

@ -62,6 +62,7 @@ export type ModelingCommandSchema = {
length: KclCommandValue length: KclCommandValue
symmetric?: boolean symmetric?: boolean
bidirectionalLength?: KclCommandValue bidirectionalLength?: KclCommandValue
twistAngle?: KclCommandValue
} }
Sweep: { Sweep: {
// Enables editing workflow // Enables editing workflow
@ -410,6 +411,11 @@ export const modelingMachineCommandConfig: StateMachineCommandSetConfig<
skip: true, skip: true,
required: false, required: false,
}, },
twistAngle: {
inputType: 'kcl',
skip: true,
required: false,
},
}, },
}, },
Sweep: { Sweep: {

View File

@ -116,6 +116,23 @@ const prepareToEditExtrude: PrepareToEditCallback = async ({ operation }) => {
return { reason: "Couldn't retrieve bidirectionalLength argument" } 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 // symmetric argument from a string to boolean
let symmetric: boolean | undefined let symmetric: boolean | undefined
if ('symmetric' in operation.labeledArgs && operation.labeledArgs.symmetric) { if ('symmetric' in operation.labeledArgs && operation.labeledArgs.symmetric) {
@ -133,6 +150,7 @@ const prepareToEditExtrude: PrepareToEditCallback = async ({ operation }) => {
sketches, sketches,
length, length,
bidirectionalLength, bidirectionalLength,
twistAngle,
symmetric, symmetric,
nodeToEdit: pathToNodeFromRustNodePath(operation.nodePath), nodeToEdit: pathToNodeFromRustNodePath(operation.nodePath),
} }

View File

@ -2429,14 +2429,21 @@ export const modelingMachine = setup({
return Promise.reject(new Error(NO_INPUT_PROVIDED_MESSAGE)) return Promise.reject(new Error(NO_INPUT_PROVIDED_MESSAGE))
} }
const { nodeToEdit, sketches, length, bidirectionalLength, symmetric } = const {
input nodeToEdit,
sketches,
length,
bidirectionalLength,
twistAngle,
symmetric,
} = input
const { ast } = kclManager const { ast } = kclManager
const astResult = addExtrude({ const astResult = addExtrude({
ast, ast,
sketches, sketches,
length, length,
bidirectionalLength, bidirectionalLength,
twistAngle,
symmetric, symmetric,
nodeToEdit, nodeToEdit,
}) })