Fix edit insert order
This commit is contained in:
@ -81,13 +81,14 @@ export function getAxisExpressionAndIndex(
|
|||||||
export function revolveSketch(
|
export function revolveSketch(
|
||||||
ast: Node<Program>,
|
ast: Node<Program>,
|
||||||
pathToSketchNode: PathToNode,
|
pathToSketchNode: PathToNode,
|
||||||
variableName: string | undefined,
|
angle: Expr,
|
||||||
angle: Expr = createLiteral(4),
|
|
||||||
axisOrEdge: 'Axis' | 'Edge',
|
axisOrEdge: 'Axis' | 'Edge',
|
||||||
axis: string | undefined,
|
axis: string | undefined,
|
||||||
edge: Selections | undefined,
|
edge: Selections | undefined,
|
||||||
artifactGraph: ArtifactGraph,
|
artifactGraph: ArtifactGraph,
|
||||||
artifact?: Artifact
|
artifact?: Artifact,
|
||||||
|
variableName?: string,
|
||||||
|
insertIndex?: number
|
||||||
):
|
):
|
||||||
| {
|
| {
|
||||||
modifiedAst: Node<Program>
|
modifiedAst: Node<Program>
|
||||||
@ -134,20 +135,27 @@ export function revolveSketch(
|
|||||||
const name =
|
const name =
|
||||||
variableName ??
|
variableName ??
|
||||||
findUniqueName(clonedAst, KCL_DEFAULT_CONSTANT_PREFIXES.REVOLVE)
|
findUniqueName(clonedAst, KCL_DEFAULT_CONSTANT_PREFIXES.REVOLVE)
|
||||||
const VariableDeclaration = createVariableDeclaration(name, revolveCall)
|
const declaration = createVariableDeclaration(name, revolveCall)
|
||||||
const lastSketchNodePath =
|
|
||||||
orderedSketchNodePaths[orderedSketchNodePaths.length - 1]
|
let sketchIndexInBody: number | undefined
|
||||||
let sketchIndexInBody = Number(lastSketchNodePath[1][0])
|
// If it's an edit flow (no change on selection yet)
|
||||||
if (typeof sketchIndexInBody !== 'number') {
|
if (insertIndex) {
|
||||||
return new Error('expected sketchIndexInBody to be a number')
|
sketchIndexInBody = insertIndex
|
||||||
|
} else {
|
||||||
|
const lastSketchNodePath =
|
||||||
|
orderedSketchNodePaths[orderedSketchNodePaths.length - 1]
|
||||||
|
sketchIndexInBody = Number(lastSketchNodePath[1][0])
|
||||||
|
if (typeof sketchIndexInBody !== 'number') {
|
||||||
|
return new Error('expected sketchIndexInBody to be a number')
|
||||||
|
}
|
||||||
|
|
||||||
|
// If an axis was selected in KCL, find the max index to insert the revolve command
|
||||||
|
if (axisIndexIfAxis) {
|
||||||
|
sketchIndexInBody = Math.max(sketchIndexInBody, axisIndexIfAxis)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If an axis was selected in KCL, find the max index to insert the revolve command
|
clonedAst.body.splice(sketchIndexInBody + 1, 0, declaration)
|
||||||
if (axisIndexIfAxis) {
|
|
||||||
sketchIndexInBody = Math.max(sketchIndexInBody, axisIndexIfAxis)
|
|
||||||
}
|
|
||||||
|
|
||||||
clonedAst.body.splice(sketchIndexInBody + 1, 0, VariableDeclaration)
|
|
||||||
|
|
||||||
const pathToRevolveArg: PathToNode = [
|
const pathToRevolveArg: PathToNode = [
|
||||||
['body', ''],
|
['body', ''],
|
||||||
|
|||||||
@ -1791,6 +1791,7 @@ export const modelingMachine = setup({
|
|||||||
const { nodeToEdit, selection, angle, axis, edge, axisOrEdge } = input
|
const { nodeToEdit, selection, angle, axis, edge, axisOrEdge } = input
|
||||||
let ast = kclManager.ast
|
let ast = kclManager.ast
|
||||||
let variableName: string | undefined = undefined
|
let variableName: string | undefined = undefined
|
||||||
|
let insertIndex: number | undefined = undefined
|
||||||
|
|
||||||
// If this is an edit flow, first we're going to remove the old extrusion
|
// If this is an edit flow, first we're going to remove the old extrusion
|
||||||
if (nodeToEdit && typeof nodeToEdit[1][0] === 'number') {
|
if (nodeToEdit && typeof nodeToEdit[1][0] === 'number') {
|
||||||
@ -1810,6 +1811,7 @@ export const modelingMachine = setup({
|
|||||||
const newBody = [...ast.body]
|
const newBody = [...ast.body]
|
||||||
newBody.splice(nodeToEdit[1][0], 1)
|
newBody.splice(nodeToEdit[1][0], 1)
|
||||||
ast.body = newBody
|
ast.body = newBody
|
||||||
|
insertIndex = nodeToEdit[1][0]
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
@ -1831,13 +1833,14 @@ export const modelingMachine = setup({
|
|||||||
const revolveSketchRes = revolveSketch(
|
const revolveSketchRes = revolveSketch(
|
||||||
ast,
|
ast,
|
||||||
pathToNode,
|
pathToNode,
|
||||||
variableName,
|
|
||||||
'variableName' in angle ? angle.variableIdentifierAst : angle.valueAst,
|
'variableName' in angle ? angle.variableIdentifierAst : angle.valueAst,
|
||||||
axisOrEdge,
|
axisOrEdge,
|
||||||
axis,
|
axis,
|
||||||
edge,
|
edge,
|
||||||
engineCommandManager.artifactGraph,
|
engineCommandManager.artifactGraph,
|
||||||
selection.graphSelections[0]?.artifact
|
selection.graphSelections[0]?.artifact,
|
||||||
|
variableName,
|
||||||
|
insertIndex
|
||||||
)
|
)
|
||||||
if (trap(revolveSketchRes)) return
|
if (trap(revolveSketchRes)) return
|
||||||
const { modifiedAst, pathToRevolveArg } = revolveSketchRes
|
const { modifiedAst, pathToRevolveArg } = revolveSketchRes
|
||||||
|
|||||||
Reference in New Issue
Block a user