Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
52 changes: 37 additions & 15 deletions e2e/playwright/point-click.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2321,11 +2321,12 @@ extrude001 = extrude(sketch001, length = -12)
})
})

test(`Fillet point-and-click edit rejected when not in pipe`, async ({
test(`Fillet point-and-click edit standalone expression`, async ({
context,
page,
homePage,
scene,
editor,
toolbar,
cmdBar,
}) => {
Expand All @@ -2339,23 +2340,44 @@ profile001 = circle(
extrude001 = extrude(profile001, length = 100)
fillet001 = fillet(extrude001, radius = 5, tags = [getOppositeEdge(seg01)])
`
await context.addInitScript((initialCode) => {
localStorage.setItem('persistCode', initialCode)
}, initialCode)
await page.setBodyDimensions({ width: 1000, height: 500 })
await homePage.goToModelingScene()
await scene.settled(cmdBar)

await test.step('Double-click in feature tree and expect error toast', async () => {
await test.step(`Initial test setup`, async () => {
await context.addInitScript((initialCode) => {
localStorage.setItem('persistCode', initialCode)
}, initialCode)
await page.setBodyDimensions({ width: 1000, height: 500 })
await homePage.goToModelingScene()
await scene.settled(cmdBar)
})
await test.step('Edit fillet', async () => {
await toolbar.openPane('feature-tree')
await toolbar.closePane('code')
const operationButton = await toolbar.getFeatureTreeOperation('Fillet', 0)
await operationButton.dblclick({ button: 'left' })
await expect(
page.getByText(
'Only chamfer and fillet in pipe expressions are supported for edits'
)
).toBeVisible()
await page.waitForTimeout(1000)
await cmdBar.expectState({
commandName: 'Fillet',
currentArgKey: 'radius',
currentArgValue: '5',
headerArguments: {
Radius: '5',
},
highlightedHeaderArg: 'radius',
stage: 'arguments',
})
await page.keyboard.insertText('20')
await cmdBar.progressCmdBar()
await cmdBar.expectState({
stage: 'review',
headerArguments: {
Radius: '20',
},
commandName: 'Fillet',
})
await cmdBar.progressCmdBar()
})
await test.step('Confirm changes', async () => {
await toolbar.openPane('code')
await toolbar.closePane('feature-tree')
await editor.expectEditor.toContain('radius = 20')
})
})

Expand Down
2 changes: 1 addition & 1 deletion src/lang/modifyAst/addEdgeTreatment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ const runModifyAstCloneWithEdgeTreatmentAndTag = async (
}

// apply edge treatment to selection
const result = modifyAstWithEdgeTreatmentAndTag(
const result = await modifyAstWithEdgeTreatmentAndTag(
ast,
selection,
parameters,
Expand Down
90 changes: 48 additions & 42 deletions src/lang/modifyAst/addEdgeTreatment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
createLocalName,
createPipeExpression,
} from '@src/lang/create'
import { updateModelingState } from '@src/lang/modelingWorkflows'
import {
getNodeFromPath,
hasSketchPipeBeenExtruded,
Expand All @@ -39,7 +38,6 @@ import type {
VariableDeclarator,
} from '@src/lang/wasm'
import type { KclCommandValue } from '@src/lib/commandTypes'
import { EXECUTION_TYPE_REAL } from '@src/lib/constants'
import type { Selection, Selections } from '@src/lib/selections'
import { err } from '@src/lib/trap'
import { isArray } from '@src/lib/utils'
Expand All @@ -65,43 +63,7 @@ export interface FilletParameters {
export type EdgeTreatmentParameters = ChamferParameters | FilletParameters

// Apply Edge Treatment (Fillet or Chamfer) To Selection
export async function applyEdgeTreatmentToSelection(
ast: Node<Program>,
selection: Selections,
parameters: EdgeTreatmentParameters,
dependencies: {
kclManager: KclManager
engineCommandManager: EngineCommandManager
editorManager: EditorManager
codeManager: CodeManager
}
): Promise<void | Error> {
// 1. clone and modify with edge treatment and tag
const result = modifyAstWithEdgeTreatmentAndTag(
ast,
selection,
parameters,
dependencies
)
if (err(result)) return result
const { modifiedAst, pathToEdgeTreatmentNode } = result

// 2. update ast
await updateModelingState(
modifiedAst,
EXECUTION_TYPE_REAL,
{
kclManager: dependencies.kclManager,
editorManager: dependencies.editorManager,
codeManager: dependencies.codeManager,
},
{
focusPath: pathToEdgeTreatmentNode,
}
)
}

export function modifyAstWithEdgeTreatmentAndTag(
export async function modifyAstWithEdgeTreatmentAndTag(
ast: Node<Program>,
selections: Selections,
parameters: EdgeTreatmentParameters,
Expand All @@ -111,9 +73,9 @@ export function modifyAstWithEdgeTreatmentAndTag(
editorManager: EditorManager
codeManager: CodeManager
}
):
| { modifiedAst: Node<Program>; pathToEdgeTreatmentNode: Array<PathToNode> }
| Error {
): Promise<
{ modifiedAst: Node<Program>; pathToEdgeTreatmentNode: PathToNode[] } | Error
> {
let clonedAst = structuredClone(ast)
const clonedAstForGetExtrude = structuredClone(ast)

Expand Down Expand Up @@ -784,3 +746,47 @@ export async function deleteEdgeTreatment(

return Error('Delete fillets not implemented')
}

// Edit Edge Treatment
export async function editEdgeTreatment(
ast: Node<Program>,
selection: Selection,
parameters: EdgeTreatmentParameters
): Promise<
{ modifiedAst: Node<Program>; pathToEdgeTreatmentNode: PathToNode } | Error
> {
// 1. clone and modify with new value
const modifiedAst = structuredClone(ast)

// find the edge treatment call
const edgeTreatmentCall = getNodeFromPath<CallExpressionKw>(
modifiedAst,
selection?.codeRef?.pathToNode,
'CallExpressionKw'
)
if (err(edgeTreatmentCall)) return edgeTreatmentCall

// edge treatment parameter
const parameterResult = getParameterNameAndValue(parameters)
if (err(parameterResult)) return parameterResult
const { parameterName, parameterValue } = parameterResult

// find the index of an argument to update
const index = edgeTreatmentCall.node.arguments.findIndex(
(arg) => arg.label.name === parameterName
)

// create a new argument with the updated value
const newArg = createLabeledArg(parameterName, parameterValue)

// if the parameter doesn't exist, add it; otherwise replace it
if (index === -1) {
edgeTreatmentCall.node.arguments.push(newArg)
} else {
edgeTreatmentCall.node.arguments[index] = newArg
}

let pathToEdgeTreatmentNode = selection?.codeRef?.pathToNode

return { modifiedAst, pathToEdgeTreatmentNode }
}
9 changes: 0 additions & 9 deletions src/lib/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,6 @@ const prepareToEditEdgeTreatment: PrepareToEditCallback = async ({
kclManager.ast,
sourceRangeFromRust(operation.sourceRange)
)
const isPipeExpression = nodeToEdit.some(
([_, type]) => type === 'PipeExpression'
)
if (!isPipeExpression) {
return {
reason:
'Only chamfer and fillet in pipe expressions are supported for edits',
}
}

let argDefaultValues:
| ModelingCommandSchema['Chamfer']
Expand Down
Loading
Loading