fix changing tools part way through circle/rect tools

This commit is contained in:
Kurt Hutten Irev-Dev
2025-02-13 19:01:28 +11:00
parent b390e3e083
commit 9999e4e62f
3 changed files with 94 additions and 24 deletions

View File

@ -825,7 +825,7 @@ export class SceneEntities {
if (err(sg)) return Promise.reject(sg)
const lastSeg = sg?.paths?.slice(-1)[0] || sg.start
const index = sg.paths.length // because we've added a new segment that's not in the memory yet, no need for `-1`
const index = sg.paths.length // because we've added a new segment that's not in the memory yet, no need for `.length -1`
const mod = addNewSketchLn({
node: _ast,
variables: kclManager.variables,
@ -1203,7 +1203,11 @@ export class SceneEntities {
await codeManager.updateEditorWithAstAndWriteToFile(_ast)
},
})
return { updatedEntryNodePath, updatedSketchNodePaths }
return {
updatedEntryNodePath,
updatedSketchNodePaths,
expressionIndexToDelete: insertIndex,
}
}
setupDraftCenterRectangle = async (
sketchEntryNodePath: PathToNode,
@ -1391,7 +1395,11 @@ export class SceneEntities {
}
},
})
return { updatedEntryNodePath, updatedSketchNodePaths }
return {
updatedEntryNodePath,
updatedSketchNodePaths,
expressionIndexToDelete: insertIndex,
}
}
setupDraftCircleThreePoint = async (
sketchEntryNodePath: PathToNode,
@ -1569,7 +1577,11 @@ export class SceneEntities {
}
},
})
return { updatedEntryNodePath, updatedSketchNodePaths }
return {
updatedEntryNodePath,
updatedSketchNodePaths,
expressionIndexToDelete: insertIndex,
}
}
setupDraftCircle = async (
sketchEntryNodePath: PathToNode,
@ -1750,7 +1762,11 @@ export class SceneEntities {
}
},
})
return { updatedEntryNodePath, updatedSketchNodePaths }
return {
updatedEntryNodePath,
updatedSketchNodePaths,
expressionIndexToDelete: insertIndex,
}
}
setupSketchIdleCallbacks = ({
sketchEntryNodePath,

View File

@ -1508,6 +1508,7 @@ export const ModelingMachineProvider = ({
updatedEntryNodePath: sketchDetails.sketchEntryNodePath,
updatedSketchNodePaths: sketchDetails.sketchNodePaths,
updatedPlaneNodePath: sketchDetails.planeNodePath,
expressionIndexToDelete: -1,
} as const
if (
!sketchDetails.sketchNodePaths.length &&
@ -1521,22 +1522,44 @@ export const ModelingMachineProvider = ({
sketchDetails.sketchEntryNodePath
)
if (err(doesNeedSplitting)) return reject(doesNeedSplitting)
if (!doesNeedSplitting) return existingSketchInfoNoOp
let moddedAst: Program = structuredClone(kclManager.ast)
let pathToProfile = sketchDetails.sketchEntryNodePath
let updatedSketchNodePaths = sketchDetails.sketchNodePaths
if (doesNeedSplitting) {
const splitResult = splitPipedProfile(
moddedAst,
sketchDetails.sketchEntryNodePath
)
if (err(splitResult)) return reject(splitResult)
moddedAst = splitResult.modifiedAst
pathToProfile = splitResult.pathToProfile
updatedSketchNodePaths = [pathToProfile]
}
const splitResult = splitPipedProfile(
kclManager.ast,
sketchDetails.sketchEntryNodePath
)
if (err(splitResult)) return reject(splitResult)
await kclManager.executeAstMock(splitResult.modifiedAst)
await codeManager.updateEditorWithAstAndWriteToFile(
splitResult.modifiedAst
)
const indexToDelete = sketchDetails?.expressionIndexToDelete || -1
if (indexToDelete >= 0) {
// this is the expression that was added when as sketch tool was used but not completed
// i.e first click for the center of the circle, but not the second click for the radius
// we added a circle to editor, but they bailed out early so we should remove it
moddedAst.body.splice(indexToDelete, 1)
// make sure the deleted expression is removed from the sketchNodePaths
updatedSketchNodePaths = updatedSketchNodePaths.filter(
(path) => path[1][0] !== indexToDelete
)
// if the deleted expression was the entryNodePath, we should just make it the first sketchNodePath
// as a safe default
pathToProfile =
pathToProfile[1][0] !== indexToDelete
? pathToProfile
: updatedSketchNodePaths[0]
}
await kclManager.executeAstMock(moddedAst)
await codeManager.updateEditorWithAstAndWriteToFile(moddedAst)
return {
updatedEntryNodePath: splitResult.pathToProfile,
updatedSketchNodePaths: [splitResult.pathToProfile],
updatedEntryNodePath: pathToProfile,
updatedSketchNodePaths: updatedSketchNodePaths,
updatedPlaneNodePath: sketchDetails.planeNodePath,
expressionIndexToDelete: -1,
}
}
),

File diff suppressed because one or more lines are too long