Clean up extrude specific changes

This commit is contained in:
Pierre Jacquier
2025-06-17 10:48:47 -04:00
parent fc6a9e33e4
commit 78a47ab3e1
4 changed files with 2 additions and 121 deletions

View File

@ -37,17 +37,11 @@ export function addExtrude({
ast,
sketches,
length,
bidirectionalLength,
twistAngle,
symmetric,
nodeToEdit,
}: {
ast: Node<Program>
sketches: Selections
length: KclCommandValue
bidirectionalLength?: KclCommandValue
twistAngle?: KclCommandValue
symmetric?: boolean
nodeToEdit?: PathToNode
}):
| {
@ -69,45 +63,15 @@ export function addExtrude({
return sketchesExprList
}
// Extra labeled args expressions
const bidirectionalLengthExpr = bidirectionalLength
? [
createLabeledArg(
'bidirectionalLength',
valueOrVariable(bidirectionalLength)
),
]
: []
const twistAngleExpr = twistAngle
? [createLabeledArg('twistAngle', valueOrVariable(twistAngle))]
: []
const symmetricExpr = symmetric
? [createLabeledArg('symmetric', createLiteral(symmetric))]
: []
const sketchesExpr = createSketchExpression(sketchesExprList)
const call = createCallExpressionStdLibKw('extrude', sketchesExpr, [
createLabeledArg('length', valueOrVariable(length)),
...bidirectionalLengthExpr,
...twistAngleExpr,
...symmetricExpr,
])
// Insert variables for labeled arguments if provided
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

View File

@ -60,9 +60,6 @@ export type ModelingCommandSchema = {
// KCL stdlib arguments
sketches: Selections
length: KclCommandValue
symmetric?: boolean
bidirectionalLength?: KclCommandValue
twistAngle?: KclCommandValue
}
Sweep: {
// Enables editing workflow
@ -397,25 +394,6 @@ export const modelingMachineCommandConfig: StateMachineCommandSetConfig<
defaultValue: KCL_DEFAULT_LENGTH,
required: true,
},
symmetric: {
inputType: 'options',
skip: true,
required: false,
options: [
{ name: 'False', value: false },
{ name: 'True', value: true },
],
},
bidirectionalLength: {
inputType: 'kcl',
skip: true,
required: false,
},
twistAngle: {
inputType: 'kcl',
skip: true,
required: false,
},
},
},
Sweep: {

View File

@ -20,13 +20,12 @@ import {
type Program,
pathToNodeFromRustNodePath,
type VariableDeclaration,
type ParseResult,
} from '@src/lang/wasm'
import type {
HelixModes,
ModelingCommandSchema,
} from '@src/lib/commandBarConfigs/modelingCommandConfig'
import type { KclCommandValue, KclExpression } from '@src/lib/commandTypes'
import type { KclExpression } from '@src/lib/commandTypes'
import {
stringToKclExpression,
retrieveArgFromPipedCallExpression,
@ -96,62 +95,12 @@ const prepareToEditExtrude: PrepareToEditCallback = async ({ operation }) => {
return { reason: "Couldn't retrieve length argument" }
}
// 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" }
}
// 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) {
symmetric =
codeManager.code.slice(
operation.labeledArgs.symmetric.sourceRange[0],
operation.labeledArgs.symmetric.sourceRange[1]
) === 'true'
}
// 3. Assemble the default argument values for the command,
// with `nodeToEdit` set, which will let the actor know
// to edit the node that corresponds to the StdLibCall.
const argDefaultValues: ModelingCommandSchema['Extrude'] = {
sketches,
length,
bidirectionalLength,
twistAngle,
symmetric,
nodeToEdit: pathToNodeFromRustNodePath(operation.nodePath),
}
return {

View File

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