Update point-and-click sketch close code generation to use explicit lines (#2489)

* Modify sketch profile completion to use `profileStart` utilties

* Fix up playwright tests

* Rerun CI
This commit is contained in:
Frank Noirot
2024-05-23 00:53:15 -04:00
committed by GitHub
parent 0a7f1a41fc
commit 25f18845c7
3 changed files with 67 additions and 8 deletions

View File

@ -2011,6 +2011,7 @@ const doSnapAtDifferentScales = async (
|> startProfileAt([${roundOff(scale * 87.68)}, ${roundOff(scale * 43.84)}], %) |> startProfileAt([${roundOff(scale * 87.68)}, ${roundOff(scale * 43.84)}], %)
|> line([${roundOff(scale * 175.36)}, 0], %) |> line([${roundOff(scale * 175.36)}, 0], %)
|> line([0, -${roundOff(scale * 175.36) + fudge}], %) |> line([0, -${roundOff(scale * 175.36) + fudge}], %)
|> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%)` |> close(%)`
await expect( await expect(
@ -2063,6 +2064,11 @@ const doSnapAtDifferentScales = async (
prevContent = await page.locator('.cm-content').innerText() prevContent = await page.locator('.cm-content').innerText()
await expect(page.locator('.cm-content')).toHaveText(code) await expect(page.locator('.cm-content')).toHaveText(code)
// Assert the tool was unequipped
await expect(page.getByRole('button', { name: 'Line' })).not.toHaveAttribute(
'aria-pressed',
'true'
)
// exit sketch // exit sketch
await u.openAndClearDebugPanel() await u.openAndClearDebugPanel()
@ -2151,6 +2157,7 @@ test('Sketch on face', async ({ page }) => {
|> startProfileAt([-12.83, 6.7], %) |> startProfileAt([-12.83, 6.7], %)
|> line([2.87, -0.23], %) |> line([2.87, -0.23], %)
|> line([-3.05, -1.47], %) |> line([-3.05, -1.47], %)
|> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%)`) |> close(%)`)
await u.openAndClearDebugPanel() await u.openAndClearDebugPanel()
@ -2189,6 +2196,7 @@ test('Sketch on face', async ({ page }) => {
|> startProfileAt([-12.83, 6.7], %) |> startProfileAt([-12.83, 6.7], %)
|> line([${[2.28, 2.35]}, -${0.07}], %) |> line([${[2.28, 2.35]}, -${0.07}], %)
|> line([-3.05, -1.47], %) |> line([-3.05, -1.47], %)
|> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%)` |> close(%)`
await expect(page.locator('.cm-content')).toHaveText(result.regExp) await expect(page.locator('.cm-content')).toHaveText(result.regExp)

View File

@ -69,6 +69,7 @@ import {
tangentialArcToSegment, tangentialArcToSegment,
} from './segments' } from './segments'
import { import {
addCallExpressionsToPipe,
addCloseToPipe, addCloseToPipe,
addNewSketchLn, addNewSketchLn,
changeSketchArguments, changeSketchArguments,
@ -536,10 +537,34 @@ export class SceneEntities {
let modifiedAst let modifiedAst
if (profileStart) { if (profileStart) {
modifiedAst = addCloseToPipe({ const lastSegment = sketchGroup.value.slice(-1)[0]
modifiedAst = addCallExpressionsToPipe({
node: kclManager.ast, node: kclManager.ast,
programMemory: kclManager.programMemory, programMemory: kclManager.programMemory,
pathToNode: sketchPathToNode, pathToNode: sketchPathToNode,
expressions: [
createCallExpressionStdLib(
lastSegment.type === 'TangentialArcTo'
? 'tangentialArcTo'
: 'lineTo',
[
createArrayExpression([
createCallExpressionStdLib('profileStartX', [
createPipeSubstitution(),
]),
createCallExpressionStdLib('profileStartY', [
createPipeSubstitution(),
]),
]),
createPipeSubstitution(),
]
),
],
})
modifiedAst = addCloseToPipe({
node: modifiedAst,
programMemory: kclManager.programMemory,
pathToNode: sketchPathToNode,
}) })
} else if (intersection2d) { } else if (intersection2d) {
const lastSegment = sketchGroup.value.slice(-1)[0] const lastSegment = sketchGroup.value.slice(-1)[0]
@ -560,13 +585,17 @@ export class SceneEntities {
} }
await kclManager.executeAstMock(modifiedAst) await kclManager.executeAstMock(modifiedAst)
this.setUpDraftSegment( if (profileStart) {
sketchPathToNode, sceneInfra.modelingSend({ type: 'CancelSketch' })
forward, } else {
up, this.setUpDraftSegment(
origin, sketchPathToNode,
segmentName forward,
) up,
origin,
segmentName
)
}
}, },
onMove: (args) => { onMove: (args) => {
this.onDragSegment({ this.onDragSegment({

View File

@ -1114,6 +1114,28 @@ export function addNewSketchLn({
}) })
} }
export function addCallExpressionsToPipe({
node,
pathToNode,
expressions,
}: {
node: Program
programMemory: ProgramMemory
pathToNode: PathToNode
expressions: CallExpression[]
}) {
const _node = { ...node }
const pipeExpression = getNodeFromPath<PipeExpression>(
_node,
pathToNode,
'PipeExpression'
).node
if (pipeExpression.type !== 'PipeExpression')
throw new Error('not a pipe expression')
pipeExpression.body = [...pipeExpression.body, ...expressions]
return _node
}
export function addCloseToPipe({ export function addCloseToPipe({
node, node,
pathToNode, pathToNode,