Skip to content

Allow point-and-click Offset Plane to work from sweep faces #7882

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 19 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions e2e/playwright/feature-tree-pane.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,26 +381,23 @@ test.describe('Feature Tree pane', () => {
await cmdBar.expectState({
commandName: 'Offset plane',
stage: 'arguments',
currentArgKey: 'distance',
currentArgKey: 'offset',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed this to be more in line with KCL

currentArgValue: initialInput,
headerArguments: {
Plane: '1 plane',
Distance: initialInput,
Offset: initialInput,
},
highlightedHeaderArg: 'distance',
highlightedHeaderArg: 'offset',
})
})

await test.step('Edit the distance argument and submit', async () => {
await test.step('Edit the offset argument and submit', async () => {
await expect(cmdBar.currentArgumentInput).toBeVisible()
await cmdBar.currentArgumentInput.locator('.cm-content').fill(newInput)
await cmdBar.progressCmdBar()
await cmdBar.expectState({
stage: 'review',
headerArguments: {
Plane: '1 plane',
// We show the calculated value in the argument summary
Distance: '15',
Offset: '15',
},
commandName: 'Offset plane',
})
Expand Down
23 changes: 7 additions & 16 deletions e2e/playwright/point-click.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1083,18 +1083,10 @@ openSketch = startSketchOn(XY)
toolbar,
cmdBar,
}) => {
// One dumb hardcoded screen pixel value
const testPoint = { x: 700, y: 200 }
// TODO: replace the testPoint selection with a feature tree click once that's supported #7544
const [clickOnXzPlane] = scene.makeMouseHelpers(testPoint.x, testPoint.y)
const expectedOutput = `plane001 = offsetPlane(XZ, offset = 5)`

await homePage.goToModelingScene()
await scene.settled(cmdBar)

await test.step(`Look for the blue of the XZ plane`, async () => {
//await scene.expectPixelColor([50, 51, 96], testPoint, 15) // FIXME
})
await test.step(`Go through the command bar flow`, async () => {
await toolbar.offsetPlaneButton.click()
await expect
Expand All @@ -1104,30 +1096,30 @@ openSketch = startSketchOn(XY)
stage: 'arguments',
currentArgKey: 'plane',
currentArgValue: '',
headerArguments: { Plane: '', Distance: '' },
headerArguments: { Plane: '', Offset: '' },
highlightedHeaderArg: 'plane',
commandName: 'Offset plane',
})
await clickOnXzPlane()
const xz = await toolbar.getFeatureTreeOperation('Front plane', 0)
await xz.click()
Comment on lines +932 to +933
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And would like to keep these two tests as they aren't px dependent anymore

await cmdBar.expectState({
stage: 'arguments',
currentArgKey: 'distance',
currentArgKey: 'offset',
currentArgValue: '5',
headerArguments: { Plane: '1 plane', Distance: '' },
highlightedHeaderArg: 'distance',
headerArguments: { Plane: '1 plane', Offset: '' },
highlightedHeaderArg: 'offset',
commandName: 'Offset plane',
})
await cmdBar.progressCmdBar()
})

await test.step(`Confirm code is added to the editor, scene has changed`, async () => {
await test.step(`Confirm code is added to the editor`, async () => {
await editor.expectEditor.toContain(expectedOutput)
await editor.expectState({
diagnostics: [],
activeLines: [expectedOutput],
highlightedCode: '',
})
await scene.expectPixelColor([74, 74, 74], testPoint, 15)
})

await test.step('Delete offset plane via feature tree selection', async () => {
Expand All @@ -1138,7 +1130,6 @@ openSketch = startSketchOn(XY)
)
await operationButton.click({ button: 'left' })
await page.keyboard.press('Delete')
//await scene.expectPixelColor([50, 51, 96], testPoint, 15) // FIXME
})
})

Expand Down
57 changes: 1 addition & 56 deletions src/lang/modifyAst.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { BodyItem } from '@rust/kcl-lib/bindings/BodyItem'
import type { Name } from '@rust/kcl-lib/bindings/Name'
import type { Node } from '@rust/kcl-lib/bindings/Node'
import type { NonCodeMeta } from '@rust/kcl-lib/bindings/NonCodeMeta'

Expand Down Expand Up @@ -27,11 +26,7 @@ import {
isNodeSafeToReplace,
isNodeSafeToReplacePath,
} from '@src/lang/queryAst'
import {
ARG_INDEX_FIELD,
LABELED_ARG_FIELD,
UNLABELED_ARG,
} from '@src/lang/queryAstConstants'
import { ARG_INDEX_FIELD, LABELED_ARG_FIELD } from '@src/lang/queryAstConstants'
import { getNodePathFromSourceRange } from '@src/lang/queryAstNodePathUtils'
import {
addTagForSketchOnFace,
Expand Down Expand Up @@ -422,56 +417,6 @@ export function sketchOnExtrudedFace(
}
}

/**
* Append an offset plane to the AST
*/
export function addOffsetPlane({
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to faces.ts with the addShell codemod since they will share a few utils

node,
plane,
insertIndex,
offset,
planeName,
}: {
node: Node<Program>
plane: Node<Literal> | Node<Name> // Can be DefaultPlaneStr or string for offsetPlanes
insertIndex?: number
offset: Expr
planeName?: string
}): { modifiedAst: Node<Program>; pathToNode: PathToNode } {
const modifiedAst = structuredClone(node)
const newPlaneName =
planeName ?? findUniqueName(node, KCL_DEFAULT_CONSTANT_PREFIXES.PLANE)

const newPlane = createVariableDeclaration(
newPlaneName,
createCallExpressionStdLibKw('offsetPlane', plane, [
createLabeledArg('offset', offset),
])
)

const insertAt =
insertIndex !== undefined
? insertIndex
: modifiedAst.body.length
? modifiedAst.body.length
: 0

modifiedAst.body.length
? modifiedAst.body.splice(insertAt, 0, newPlane)
: modifiedAst.body.push(newPlane)
const pathToNode: PathToNode = [
['body', ''],
[insertAt, 'index'],
['declaration', 'VariableDeclaration'],
['init', 'VariableDeclarator'],
['unlabeled', UNLABELED_ARG],
]
return {
modifiedAst,
pathToNode,
}
}

/**
* Add an import call to load a part
*/
Expand Down
Loading
Loading