Clean up extrude specific changes
This commit is contained in:
@ -37,17 +37,11 @@ export function addExtrude({
|
|||||||
ast,
|
ast,
|
||||||
sketches,
|
sketches,
|
||||||
length,
|
length,
|
||||||
bidirectionalLength,
|
|
||||||
twistAngle,
|
|
||||||
symmetric,
|
|
||||||
nodeToEdit,
|
nodeToEdit,
|
||||||
}: {
|
}: {
|
||||||
ast: Node<Program>
|
ast: Node<Program>
|
||||||
sketches: Selections
|
sketches: Selections
|
||||||
length: KclCommandValue
|
length: KclCommandValue
|
||||||
bidirectionalLength?: KclCommandValue
|
|
||||||
twistAngle?: KclCommandValue
|
|
||||||
symmetric?: boolean
|
|
||||||
nodeToEdit?: PathToNode
|
nodeToEdit?: PathToNode
|
||||||
}):
|
}):
|
||||||
| {
|
| {
|
||||||
@ -69,45 +63,15 @@ export function addExtrude({
|
|||||||
return sketchesExprList
|
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 sketchesExpr = createSketchExpression(sketchesExprList)
|
||||||
const call = createCallExpressionStdLibKw('extrude', sketchesExpr, [
|
const call = createCallExpressionStdLibKw('extrude', sketchesExpr, [
|
||||||
createLabeledArg('length', valueOrVariable(length)),
|
createLabeledArg('length', valueOrVariable(length)),
|
||||||
...bidirectionalLengthExpr,
|
|
||||||
...twistAngleExpr,
|
|
||||||
...symmetricExpr,
|
|
||||||
])
|
])
|
||||||
|
|
||||||
// Insert variables for labeled arguments if provided
|
// Insert variables for labeled arguments if provided
|
||||||
if ('variableName' in length && length.variableName) {
|
if ('variableName' in length && length.variableName) {
|
||||||
insertVariableAndOffsetPathToNode(length, modifiedAst, nodeToEdit)
|
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,
|
// 3. If edit, we assign the new function call declaration to the existing node,
|
||||||
// otherwise just push to the end
|
// otherwise just push to the end
|
||||||
|
@ -60,9 +60,6 @@ export type ModelingCommandSchema = {
|
|||||||
// KCL stdlib arguments
|
// KCL stdlib arguments
|
||||||
sketches: Selections
|
sketches: Selections
|
||||||
length: KclCommandValue
|
length: KclCommandValue
|
||||||
symmetric?: boolean
|
|
||||||
bidirectionalLength?: KclCommandValue
|
|
||||||
twistAngle?: KclCommandValue
|
|
||||||
}
|
}
|
||||||
Sweep: {
|
Sweep: {
|
||||||
// Enables editing workflow
|
// Enables editing workflow
|
||||||
@ -397,25 +394,6 @@ export const modelingMachineCommandConfig: StateMachineCommandSetConfig<
|
|||||||
defaultValue: KCL_DEFAULT_LENGTH,
|
defaultValue: KCL_DEFAULT_LENGTH,
|
||||||
required: true,
|
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: {
|
Sweep: {
|
||||||
|
@ -20,13 +20,12 @@ import {
|
|||||||
type Program,
|
type Program,
|
||||||
pathToNodeFromRustNodePath,
|
pathToNodeFromRustNodePath,
|
||||||
type VariableDeclaration,
|
type VariableDeclaration,
|
||||||
type ParseResult,
|
|
||||||
} from '@src/lang/wasm'
|
} from '@src/lang/wasm'
|
||||||
import type {
|
import type {
|
||||||
HelixModes,
|
HelixModes,
|
||||||
ModelingCommandSchema,
|
ModelingCommandSchema,
|
||||||
} from '@src/lib/commandBarConfigs/modelingCommandConfig'
|
} from '@src/lib/commandBarConfigs/modelingCommandConfig'
|
||||||
import type { KclCommandValue, KclExpression } from '@src/lib/commandTypes'
|
import type { KclExpression } from '@src/lib/commandTypes'
|
||||||
import {
|
import {
|
||||||
stringToKclExpression,
|
stringToKclExpression,
|
||||||
retrieveArgFromPipedCallExpression,
|
retrieveArgFromPipedCallExpression,
|
||||||
@ -96,62 +95,12 @@ const prepareToEditExtrude: PrepareToEditCallback = async ({ operation }) => {
|
|||||||
return { reason: "Couldn't retrieve length argument" }
|
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,
|
// 3. Assemble the default argument values for the command,
|
||||||
// with `nodeToEdit` set, which will let the actor know
|
// with `nodeToEdit` set, which will let the actor know
|
||||||
// to edit the node that corresponds to the StdLibCall.
|
// to edit the node that corresponds to the StdLibCall.
|
||||||
const argDefaultValues: ModelingCommandSchema['Extrude'] = {
|
const argDefaultValues: ModelingCommandSchema['Extrude'] = {
|
||||||
sketches,
|
sketches,
|
||||||
length,
|
length,
|
||||||
bidirectionalLength,
|
|
||||||
twistAngle,
|
|
||||||
symmetric,
|
|
||||||
nodeToEdit: pathToNodeFromRustNodePath(operation.nodePath),
|
nodeToEdit: pathToNodeFromRustNodePath(operation.nodePath),
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
|
@ -2429,22 +2429,12 @@ export const modelingMachine = setup({
|
|||||||
return Promise.reject(new Error(NO_INPUT_PROVIDED_MESSAGE))
|
return Promise.reject(new Error(NO_INPUT_PROVIDED_MESSAGE))
|
||||||
}
|
}
|
||||||
|
|
||||||
const {
|
const { nodeToEdit, sketches, length } = 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,
|
|
||||||
twistAngle,
|
|
||||||
symmetric,
|
|
||||||
nodeToEdit,
|
nodeToEdit,
|
||||||
})
|
})
|
||||||
if (err(astResult)) {
|
if (err(astResult)) {
|
||||||
|
Reference in New Issue
Block a user