make delete key work for solids (#2752)
* failing test Signed-off-by: Jess Frazelle <github@jessfraz.com> * failing test Signed-off-by: Jess Frazelle <github@jessfraz.com> * push up progress Signed-off-by: Jess Frazelle <github@jessfraz.com> * improve travers * basic deleteFromSelection * remove .only * delete depended on extrude * fix * fix selection override * add selection test * Revert "add selection test" This reverts commit40a414b612
. * Revert "fix selection override" This reverts commit68e66e2980
. * more progress * add toast message when we're not able to delet * add e2e tests * tweak test timeout * more test tweaks * fix back space cmd bar conflic * clean up --------- Signed-off-by: Jess Frazelle <github@jessfraz.com> Co-authored-by: Kurt Hutten Irev-Dev <k.hutten@protonmail.ch>
This commit is contained in:
@ -15,6 +15,7 @@ import {
|
||||
sketchOnExtrudedFace,
|
||||
deleteSegmentFromPipeExpression,
|
||||
removeSingleConstraintInfo,
|
||||
deleteFromSelection,
|
||||
} from './modifyAst'
|
||||
import { enginelessExecutor } from '../lib/testHelpers'
|
||||
import { findUsesOfTagInPipe, getNodePathFromSourceRange } from './queryAst'
|
||||
@ -696,3 +697,196 @@ describe('Testing removeSingleConstraintInfo', () => {
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('Testing deleteFromSelection', () => {
|
||||
const cases = [
|
||||
[
|
||||
'basicCase',
|
||||
{
|
||||
codeBefore: `const myVar = 5
|
||||
const sketch003 = startSketchOn('XZ')
|
||||
|> startProfileAt([3.82, 13.6], %)
|
||||
|> line([-2.94, 2.7], %)
|
||||
|> line([7.7, 0.16], %)
|
||||
|> lineTo([profileStartX(%), profileStartY(%)], %)
|
||||
|> close(%)`,
|
||||
codeAfter: `const myVar = 5\n`,
|
||||
lineOfInterest: 'line([-2.94, 2.7], %)',
|
||||
type: 'default',
|
||||
},
|
||||
],
|
||||
[
|
||||
'delete extrude',
|
||||
{
|
||||
codeBefore: `const sketch001 = startSketchOn('XZ')
|
||||
|> startProfileAt([3.29, 7.86], %)
|
||||
|> line([2.48, 2.44], %)
|
||||
|> line([2.66, 1.17], %)
|
||||
|> line([3.75, 0.46], %)
|
||||
|> line([4.99, -0.46], %, $seg01)
|
||||
|> line([-3.86, -2.73], %)
|
||||
|> line([-17.67, 0.85], %)
|
||||
|> close(%)
|
||||
const extrude001 = extrude(10, sketch001)`,
|
||||
codeAfter: `const sketch001 = startSketchOn('XZ')
|
||||
|> startProfileAt([3.29, 7.86], %)
|
||||
|> line([2.48, 2.44], %)
|
||||
|> line([2.66, 1.17], %)
|
||||
|> line([3.75, 0.46], %)
|
||||
|> line([4.99, -0.46], %, $seg01)
|
||||
|> line([-3.86, -2.73], %)
|
||||
|> line([-17.67, 0.85], %)
|
||||
|> close(%)\n`,
|
||||
lineOfInterest: 'line([2.66, 1.17], %)',
|
||||
type: 'extrude-wall',
|
||||
},
|
||||
],
|
||||
[
|
||||
'delete extrude with sketch on it',
|
||||
{
|
||||
codeBefore: `const myVar = 5
|
||||
const sketch001 = startSketchOn('XZ')
|
||||
|> startProfileAt([4.46, 5.12], %, $tag)
|
||||
|> line([0.08, myVar], %)
|
||||
|> line([13.03, 2.02], %, $seg01)
|
||||
|> line([3.9, -7.6], %)
|
||||
|> line([-11.18, -2.15], %)
|
||||
|> line([5.41, -9.61], %)
|
||||
|> line([-8.54, -2.51], %)
|
||||
|> lineTo([profileStartX(%), profileStartY(%)], %)
|
||||
|> close(%)
|
||||
const extrude001 = extrude(5, sketch001)
|
||||
const sketch002 = startSketchOn(extrude001, seg01)
|
||||
|> startProfileAt([-12.55, 2.89], %)
|
||||
|> line([3.02, 1.9], %)
|
||||
|> line([1.82, -1.49], %, $seg02)
|
||||
|> angledLine([-86, segLen(seg02, %)], %)
|
||||
|> line([-3.97, -0.53], %)
|
||||
|> line([0.3, 0.84], %)
|
||||
|> lineTo([profileStartX(%), profileStartY(%)], %)
|
||||
|> close(%)`,
|
||||
codeAfter: `const myVar = 5
|
||||
const sketch001 = startSketchOn('XZ')
|
||||
|> startProfileAt([4.46, 5.12], %, $tag)
|
||||
|> line([0.08, myVar], %)
|
||||
|> line([13.03, 2.02], %, $seg01)
|
||||
|> line([3.9, -7.6], %)
|
||||
|> line([-11.18, -2.15], %)
|
||||
|> line([5.41, -9.61], %)
|
||||
|> line([-8.54, -2.51], %)
|
||||
|> lineTo([profileStartX(%), profileStartY(%)], %)
|
||||
|> close(%)
|
||||
const sketch002 = startSketchOn({
|
||||
plane: {
|
||||
origin: { x: 1, y: 2, z: 3 },
|
||||
x_axis: { x: 4, y: 5, z: 6 },
|
||||
y_axis: { x: 7, y: 8, z: 9 },
|
||||
z_axis: { x: 10, y: 11, z: 12 }
|
||||
}
|
||||
})
|
||||
|> startProfileAt([-12.55, 2.89], %)
|
||||
|> line([3.02, 1.9], %)
|
||||
|> line([1.82, -1.49], %, $seg02)
|
||||
|> angledLine([-86, segLen(seg02, %)], %)
|
||||
|> line([-3.97, -0.53], %)
|
||||
|> line([0.3, 0.84], %)
|
||||
|> lineTo([profileStartX(%), profileStartY(%)], %)
|
||||
|> close(%)
|
||||
`,
|
||||
lineOfInterest: 'line([-11.18, -2.15], %)',
|
||||
type: 'extrude-wall',
|
||||
},
|
||||
],
|
||||
[
|
||||
'delete extrude with sketch on it',
|
||||
{
|
||||
codeBefore: `const myVar = 5
|
||||
const sketch001 = startSketchOn('XZ')
|
||||
|> startProfileAt([4.46, 5.12], %, $tag)
|
||||
|> line([0.08, myVar], %)
|
||||
|> line([13.03, 2.02], %, $seg01)
|
||||
|> line([3.9, -7.6], %)
|
||||
|> line([-11.18, -2.15], %)
|
||||
|> line([5.41, -9.61], %)
|
||||
|> line([-8.54, -2.51], %)
|
||||
|> lineTo([profileStartX(%), profileStartY(%)], %)
|
||||
|> close(%)
|
||||
const extrude001 = extrude(5, sketch001)
|
||||
const sketch002 = startSketchOn(extrude001, seg01)
|
||||
|> startProfileAt([-12.55, 2.89], %)
|
||||
|> line([3.02, 1.9], %)
|
||||
|> line([1.82, -1.49], %, $seg02)
|
||||
|> angledLine([-86, segLen(seg02, %)], %)
|
||||
|> line([-3.97, -0.53], %)
|
||||
|> line([0.3, 0.84], %)
|
||||
|> lineTo([profileStartX(%), profileStartY(%)], %)
|
||||
|> close(%)`,
|
||||
codeAfter: `const myVar = 5
|
||||
const sketch001 = startSketchOn('XZ')
|
||||
|> startProfileAt([4.46, 5.12], %, $tag)
|
||||
|> line([0.08, myVar], %)
|
||||
|> line([13.03, 2.02], %, $seg01)
|
||||
|> line([3.9, -7.6], %)
|
||||
|> line([-11.18, -2.15], %)
|
||||
|> line([5.41, -9.61], %)
|
||||
|> line([-8.54, -2.51], %)
|
||||
|> lineTo([profileStartX(%), profileStartY(%)], %)
|
||||
|> close(%)
|
||||
const sketch002 = startSketchOn({
|
||||
plane: {
|
||||
origin: { x: 1, y: 2, z: 3 },
|
||||
x_axis: { x: 4, y: 5, z: 6 },
|
||||
y_axis: { x: 7, y: 8, z: 9 },
|
||||
z_axis: { x: 10, y: 11, z: 12 }
|
||||
}
|
||||
})
|
||||
|> startProfileAt([-12.55, 2.89], %)
|
||||
|> line([3.02, 1.9], %)
|
||||
|> line([1.82, -1.49], %, $seg02)
|
||||
|> angledLine([-86, segLen(seg02, %)], %)
|
||||
|> line([-3.97, -0.53], %)
|
||||
|> line([0.3, 0.84], %)
|
||||
|> lineTo([profileStartX(%), profileStartY(%)], %)
|
||||
|> close(%)
|
||||
`,
|
||||
lineOfInterest: 'startProfileAt([4.46, 5.12], %, $tag)',
|
||||
type: 'end-cap',
|
||||
},
|
||||
],
|
||||
] as const
|
||||
test.each(cases)(
|
||||
'%s',
|
||||
async (name, { codeBefore, codeAfter, lineOfInterest, type }) => {
|
||||
// const lineOfInterest = 'line([-2.94, 2.7], %)'
|
||||
const ast = parse(codeBefore)
|
||||
if (err(ast)) throw ast
|
||||
const programMemory = await enginelessExecutor(ast)
|
||||
|
||||
// deleteFromSelection
|
||||
const range: [number, number] = [
|
||||
codeBefore.indexOf(lineOfInterest),
|
||||
codeBefore.indexOf(lineOfInterest) + lineOfInterest.length,
|
||||
]
|
||||
const newAst = await deleteFromSelection(
|
||||
ast,
|
||||
{
|
||||
range,
|
||||
type,
|
||||
},
|
||||
programMemory,
|
||||
async () => {
|
||||
await new Promise((resolve) => setTimeout(resolve, 100))
|
||||
return {
|
||||
origin: { x: 1, y: 2, z: 3 },
|
||||
x_axis: { x: 4, y: 5, z: 6 },
|
||||
y_axis: { x: 7, y: 8, z: 9 },
|
||||
z_axis: { x: 10, y: 11, z: 12 },
|
||||
}
|
||||
}
|
||||
)
|
||||
if (err(newAst)) throw newAst
|
||||
const newCode = recast(newAst)
|
||||
expect(newCode).toBe(codeAfter)
|
||||
}
|
||||
)
|
||||
})
|
||||
|
Reference in New Issue
Block a user