Fix: inserting revolve command accounts for axis dependency (#5231)

fix: inserting revolve with axis dependency
This commit is contained in:
Kevin Nadro
2025-02-10 14:01:06 -06:00
committed by GitHub
parent 1bb372b642
commit e2be66b024

View File

@ -46,6 +46,7 @@ export function revolveSketch(
if (err(sketchNode)) return sketchNode if (err(sketchNode)) return sketchNode
let generatedAxis let generatedAxis
let axisDeclaration: PathToNode | null = null
if (axisOrEdge === 'Edge') { if (axisOrEdge === 'Edge') {
const pathToAxisSelection = getNodePathFromSourceRange( const pathToAxisSelection = getNodePathFromSourceRange(
@ -70,6 +71,13 @@ export function revolveSketch(
const axisSelection = edge?.graphSelections[0]?.artifact const axisSelection = edge?.graphSelections[0]?.artifact
if (!axisSelection) return new Error('Generated axis selection is missing.') if (!axisSelection) return new Error('Generated axis selection is missing.')
generatedAxis = getEdgeTagCall(tag, axisSelection) generatedAxis = getEdgeTagCall(tag, axisSelection)
if (
axisSelection.type === 'segment' ||
axisSelection.type === 'path' ||
axisSelection.type === 'edgeCut'
) {
axisDeclaration = axisSelection.codeRef.pathToNode
}
} else { } else {
generatedAxis = createLiteral(axis) generatedAxis = createLiteral(axis)
} }
@ -139,18 +147,34 @@ export function revolveSketch(
const sketchIndexInPathToNode = const sketchIndexInPathToNode =
sketchPathToDecleration.findIndex((a) => a[0] === 'body') + 1 sketchPathToDecleration.findIndex((a) => a[0] === 'body') + 1
const sketchIndexInBody = sketchPathToDecleration[sketchIndexInPathToNode][0] const sketchIndexInBody = sketchPathToDecleration[sketchIndexInPathToNode][0]
if (typeof sketchIndexInBody !== 'number') let insertIndex = sketchIndexInBody
return new Error('expected sketchIndexInBody to be a number')
clonedAst.body.splice(sketchIndexInBody + 1, 0, VariableDeclaration) if (typeof insertIndex !== 'number')
return new Error('expected insertIndex to be a number')
// If an axis was selected in KCL, find the max index to insert the revolve command
if (axisDeclaration) {
const axisIndexInPathToNode =
axisDeclaration.findIndex((a) => a[0] === 'body') + 1
const axisIndex = axisDeclaration[axisIndexInPathToNode][0]
if (typeof axisIndex !== 'number')
return new Error('expected axisIndex to be a number')
insertIndex = Math.max(insertIndex, axisIndex)
}
clonedAst.body.splice(insertIndex + 1, 0, VariableDeclaration)
const pathToRevolveArg: PathToNode = [ const pathToRevolveArg: PathToNode = [
['body', ''], ['body', ''],
[sketchIndexInBody + 1, 'index'], [insertIndex + 1, 'index'],
['declaration', 'VariableDeclaration'], ['declaration', 'VariableDeclaration'],
['init', 'VariableDeclarator'], ['init', 'VariableDeclarator'],
['arguments', 'CallExpression'], ['arguments', 'CallExpression'],
[0, 'index'], [0, 'index'],
] ]
return { return {
modifiedAst: clonedAst, modifiedAst: clonedAst,
pathToSketchNode: [...pathToSketchNode.slice(0, -1), [-1, 'index']], pathToSketchNode: [...pathToSketchNode.slice(0, -1), [-1, 'index']],