Fix point-and-click sketch mode to use kwargs

This commit is contained in:
Adam Chalmers
2025-01-21 15:25:30 -06:00
committed by Nick Cameron
parent 1227b38e12
commit cb4a47705c
2 changed files with 26 additions and 20 deletions

View File

@ -89,6 +89,8 @@ import {
addStartProfileAt,
createArrayExpression,
createCallExpressionStdLib,
createCallExpressionStdLibKw,
createLabeledArg,
createLiteral,
createObjectExpression,
createPipeExpression,
@ -785,29 +787,32 @@ export class SceneEntities {
let modifiedAst
// Snapping logic for the profile start handle
// ADAM: Should generate line calls with endAbsolute.
if (intersectsProfileStart) {
const lastSegment = sketch.paths.slice(-1)[0]
const originCoords = createArrayExpression([
createCallExpressionStdLib('profileStartX', [
createPipeSubstitution(),
]),
createCallExpressionStdLib('profileStartY', [
createPipeSubstitution(),
]),
])
modifiedAst = addCallExpressionsToPipe({
node: kclManager.ast,
programMemory: kclManager.programMemory,
pathToNode: sketchPathToNode,
expressions: [
createCallExpressionStdLib(
lastSegment.type === 'TangentialArcTo'
? 'tangentialArcTo'
: 'lineTo',
[
createArrayExpression([
createCallExpressionStdLib('profileStartX', [
createPipeSubstitution(),
]),
createCallExpressionStdLib('profileStartY', [
createPipeSubstitution(),
]),
]),
createPipeSubstitution(),
]
),
lastSegment.type === 'TangentialArcTo'
? createCallExpressionStdLib('tangentialArcTo', [
originCoords,
createPipeSubstitution(),
])
: createCallExpressionStdLibKw(
'line',
createPipeSubstitution(),
[createLabeledArg('endAbsolute', originCoords)]
),
],
})
if (trap(modifiedAst)) return Promise.reject(modifiedAst)

View File

@ -2110,9 +2110,10 @@ export function addNewSketchLn({
}
| Error {
const node = structuredClone(_node)
const { add, updateArgs } = sketchLineHelperMap?.[fnName] || {}
const { add, updateArgs } =
sketchLineHelperMap?.[fnName] || sketchLineHelperMapKw?.[fnName] || {}
if (!add || !updateArgs) {
return new Error('not a sketch line helper')
return new Error(`${fnName} is not a sketch line helper`)
}
getNodeFromPath<Node<VariableDeclarator>>(
@ -2120,7 +2121,7 @@ export function addNewSketchLn({
pathToNode,
'VariableDeclarator'
)
getNodeFromPath<Node<PipeExpression | CallExpression>>(
getNodeFromPath<Node<PipeExpression | CallExpression | CallExpressionKw>>(
node,
pathToNode,
'PipeExpression'
@ -2142,7 +2143,7 @@ export function addCallExpressionsToPipe({
node: Node<Program>
programMemory: ProgramMemory
pathToNode: PathToNode
expressions: Node<CallExpression>[]
expressions: Node<CallExpression | CallExpressionKw>[]
}) {
const _node = { ...node }
const pipeExpression = getNodeFromPath<Node<PipeExpression>>(