Skip to content

Commit 03f2a35

Browse files
committed
P&C Sweep from Sketch Solve
Towards #10728. Stacked on #10832
1 parent d94d8ac commit 03f2a35

File tree

3 files changed

+63
-6
lines changed

3 files changed

+63
-6
lines changed

src/lang/modifyAst/sweeps.spec.ts

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,8 +1016,62 @@ sketch002 = sketch(on = XZ) {
10161016
`region001 = region(point = [1mm, 1mm], sketch = s)
10171017
sweep001 = sweep(region001, path = sketch002.line1)`
10181018
)
1019-
// TODO: enable once KCL is updated
1020-
// await runNewAstAndCheckForSweep(result.modifiedAst, rustContextInThisFile)
1019+
await runNewAstAndCheckForSweep(result.modifiedAst, rustContextInThisFile)
1020+
})
1021+
1022+
it('should add a sweep call from region001 with sketch solve line and arc path segments', async () => {
1023+
const code = `@settings(experimentalFeatures = allow)
1024+
1025+
sketch001 = sketch(on = XY) {
1026+
circle1 = circle(start = [var -2.38mm, var 2.51mm], center = [var 0mm, var 0mm])
1027+
coincident([circle1.center, ORIGIN])
1028+
}
1029+
sketch002 = sketch(on = YZ) {
1030+
line1 = line(start = [var 0mm, var 0mm], end = [var 0mm, var 10mm])
1031+
coincident([line1.start, ORIGIN])
1032+
arc1 = arc(start = [var 6.66mm, var 22.81mm], end = [var 0mm, var 10mm], center = [var 15.65mm, var 10mm])
1033+
coincident([line1.end, arc1.end])
1034+
tangent([line1, arc1])
1035+
vertical(line1)
1036+
verticalDistance([line1.start, line1.end]) == 10
1037+
}
1038+
region001 = region(point = [2.3783mm, -2.5082mm], sketch = sketch001)
1039+
region002 = region(point = [2.3783mm, -2.5082mm], sketch = sketch001)`
1040+
const { ast, artifactGraph } = await getAstAndArtifactGraphEngineless(
1041+
code,
1042+
instanceInThisFile,
1043+
rustContextInThisFile
1044+
)
1045+
1046+
const regionArtifacts = [...artifactGraph.values()]
1047+
.filter((artifact) => artifact.type === 'path')
1048+
.slice(-2, -1)
1049+
expect(regionArtifacts).toHaveLength(1)
1050+
const sketches = createSelectionFromArtifacts(
1051+
regionArtifacts,
1052+
artifactGraph
1053+
)
1054+
1055+
const pathArtifacts = [...artifactGraph.values()]
1056+
.filter((artifact) => artifact.type === 'segment')
1057+
.slice(-2)
1058+
expect(pathArtifacts).toHaveLength(2)
1059+
const path = createSelectionFromArtifacts(pathArtifacts, artifactGraph)
1060+
1061+
const result = addSweep({
1062+
ast,
1063+
artifactGraph,
1064+
sketches,
1065+
path,
1066+
wasmInstance: instanceInThisFile,
1067+
})
1068+
if (err(result)) throw result
1069+
1070+
const newCode = recast(result.modifiedAst, instanceInThisFile)
1071+
expect(newCode).toContain(
1072+
`sweep001 = sweep(region001, path = [sketch002.line1, sketch002.arc1])`
1073+
)
1074+
await runNewAstAndCheckForSweep(result.modifiedAst, rustContextInThisFile)
10211075
})
10221076

10231077
it('should edit a sweep call from a sketch region selection', async () => {

src/lang/modifyAst/sweeps.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,12 @@ export function addSweep({
362362
return pathVars
363363
}
364364

365+
const pathExpr = createVariableExpressionsArray(pathVars.exprs)
366+
if (!pathExpr) {
367+
return new Error("Couldn't retrieve path selection")
368+
}
369+
365370
// Extra labeled args expressions
366-
const pathExpr = pathVars.exprs[0]
367371
const sectionalExpr =
368372
sectional !== undefined
369373
? [createLabeledArg('sectional', createLiteral(sectional, wasmInstance))]

src/lib/commandBarConfigs/modelingCommandConfig.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -824,10 +824,9 @@ export const modelingMachineCommandConfig: StateMachineCommandSetConfig<
824824
},
825825
path: {
826826
inputType: 'selection',
827-
selectionTypes: ['path', 'helix'],
828-
selectionFilter: ['object'],
827+
selectionTypes: ['segment', 'path', 'helix'],
829828
required: true,
830-
multiple: false,
829+
multiple: true,
831830
hidden: (context) => Boolean(context.argumentsToSubmit.nodeToEdit),
832831
},
833832
sectional: {

0 commit comments

Comments
 (0)