Kwargs: startProfileAt (#6424)
Previous: ``` startProfileAt([x, y], %) startProfileAt([x, y], sketch001) ``` New: ``` startProfile(%, at = [x, y]) startProfile(sketch001, at = [x, y]) ```
This commit is contained in:
@ -100,10 +100,9 @@ import {
|
||||
import type EditorManager from '@src/editor/manager'
|
||||
import type { KclManager } from '@src/lang/KclSingleton'
|
||||
import type CodeManager from '@src/lang/codeManager'
|
||||
import { ARG_END, ARG_END_ABSOLUTE } from '@src/lang/constants'
|
||||
import { ARG_END, ARG_AT, ARG_END_ABSOLUTE } from '@src/lang/constants'
|
||||
import {
|
||||
createArrayExpression,
|
||||
createCallExpressionStdLib,
|
||||
createCallExpressionStdLibKw,
|
||||
createLabeledArg,
|
||||
createLiteral,
|
||||
@ -473,7 +472,7 @@ export class SceneEntities {
|
||||
scale,
|
||||
theme: this.sceneInfra._theme,
|
||||
// default is 12, this makes the draft point pop a bit more,
|
||||
// especially when snapping to the startProfileAt handle as it's it was the exact same size
|
||||
// especially when snapping to the startProfile handle as it's it was the exact same size
|
||||
size: 16,
|
||||
})
|
||||
draftPoint.layers.set(SKETCH_LAYER)
|
||||
@ -1212,13 +1211,19 @@ export class SceneEntities {
|
||||
const tag = findUniqueName(_ast, 'rectangleSegmentA')
|
||||
const newDeclaration = createVariableDeclaration(
|
||||
varName,
|
||||
createCallExpressionStdLib('startProfileAt', [
|
||||
createArrayExpression([
|
||||
createLiteral(roundOff(rectangleOrigin[0])),
|
||||
createLiteral(roundOff(rectangleOrigin[1])),
|
||||
]),
|
||||
createCallExpressionStdLibKw(
|
||||
'startProfile',
|
||||
createLocalName(varDec.node.id.name),
|
||||
])
|
||||
[
|
||||
createLabeledArg(
|
||||
ARG_AT,
|
||||
createArrayExpression([
|
||||
createLiteral(roundOff(rectangleOrigin[0])),
|
||||
createLiteral(roundOff(rectangleOrigin[1])),
|
||||
])
|
||||
),
|
||||
]
|
||||
)
|
||||
)
|
||||
|
||||
const insertIndex = getInsertIndex(sketchNodePaths, planeNodePath, 'end')
|
||||
@ -1413,15 +1418,22 @@ export class SceneEntities {
|
||||
// first create just the variable declaration, as that's
|
||||
// all we want the user to see in the editor
|
||||
const tag = findUniqueName(_ast, 'rectangleSegmentA')
|
||||
|
||||
const newDeclaration = createVariableDeclaration(
|
||||
varName,
|
||||
createCallExpressionStdLib('startProfileAt', [
|
||||
createArrayExpression([
|
||||
createLiteral(roundOff(rectangleOrigin[0])),
|
||||
createLiteral(roundOff(rectangleOrigin[1])),
|
||||
]),
|
||||
createCallExpressionStdLibKw(
|
||||
'startProfile',
|
||||
createLocalName(varDec.node.id.name),
|
||||
])
|
||||
[
|
||||
createLabeledArg(
|
||||
ARG_AT,
|
||||
createArrayExpression([
|
||||
createLiteral(roundOff(rectangleOrigin[0])),
|
||||
createLiteral(roundOff(rectangleOrigin[1])),
|
||||
])
|
||||
),
|
||||
]
|
||||
)
|
||||
)
|
||||
const insertIndex = getInsertIndex(sketchNodePaths, planeNodePath, 'end')
|
||||
|
||||
|
@ -18,13 +18,13 @@ describe('processMemory', () => {
|
||||
otherVar = myFn(5)
|
||||
|
||||
theExtrude = startSketchOn(XY)
|
||||
|> startProfileAt([0, 0], %)
|
||||
|> startProfile(at = [0, 0])
|
||||
|> line(endAbsolute = [-2.4, myVar])
|
||||
|> line(endAbsolute = [-0.76, otherVar])
|
||||
|> extrude(length = 4)
|
||||
|
||||
theSketch = startSketchOn(XY)
|
||||
|> startProfileAt([0, 0], %)
|
||||
|> startProfile(at = [0, 0])
|
||||
|> line(endAbsolute = [-3.35, 0.17])
|
||||
|> line(endAbsolute = [0.98, 5.16])
|
||||
|> line(endAbsolute = [2.15, 4.32])
|
||||
|
@ -11,7 +11,7 @@ describe('testing artifacts', () => {
|
||||
test('sketch artifacts', async () => {
|
||||
const code = `
|
||||
const mySketch001 = startSketchOn(XY)
|
||||
|> startProfileAt([0, 0], %)
|
||||
|> startProfile(at = [0, 0])
|
||||
|> line(endAbsolute = [-1.59, -1.54])
|
||||
|> line(endAbsolute = [0.46, -5.82])
|
||||
// |> rx(45, %)`
|
||||
@ -69,7 +69,7 @@ const mySketch001 = startSketchOn(XY)
|
||||
// Enable rotations #152
|
||||
const code = `
|
||||
const mySketch001 = startSketchOn(XY)
|
||||
|> startProfileAt([0, 0], %)
|
||||
|> startProfile(at = [0, 0])
|
||||
|> line(endAbsolute = [-1.59, -1.54])
|
||||
|> line(endAbsolute = [0.46, -5.82])
|
||||
// |> rx(45, %)
|
||||
@ -148,7 +148,7 @@ const mySketch001 = startSketchOn(XY)
|
||||
// TODO #153 in order for getExtrudeWallTransform to work we need to query the engine for the location of a face.
|
||||
const code = `
|
||||
const sk1 = startSketchOn(XY)
|
||||
|> startProfileAt([0, 0], %)
|
||||
|> startProfile(at = [0, 0])
|
||||
|> line(endAbsolute = [-2.5, 0])
|
||||
|> line(endAbsolute = [0, 10], tag = $p)
|
||||
|> line(endAbsolute = [2.5, 0])
|
||||
@ -158,7 +158,7 @@ const sk1 = startSketchOn(XY)
|
||||
const theExtrude = extrude(sk1, length = 2)
|
||||
// const theTransf = getExtrudeWallTransform('p', theExtrude)
|
||||
const sk2 = startSketchOn(XY)
|
||||
|> startProfileAt([0, 0], %)
|
||||
|> startProfile(at = [0, 0])
|
||||
|> line(endAbsolute = [-2.5, 0])
|
||||
|> line(endAbsolute = [0, 3], tag = $o)
|
||||
|> line(endAbsolute = [2.5, 0])
|
||||
|
@ -15,3 +15,4 @@ export const ARG_END_ABSOLUTE_X = 'endAbsoluteX'
|
||||
export const ARG_END_ABSOLUTE_Y = 'endAbsoluteY'
|
||||
export const ARG_INTERSECT_TAG = 'intersectTag'
|
||||
export const ARG_INTERIOR_ABSOLUTE = 'interiorAbsolute'
|
||||
export const ARG_AT = 'at'
|
||||
|
@ -48,7 +48,7 @@ const newVar = myVar + 1`
|
||||
})
|
||||
it('sketch declaration', async () => {
|
||||
let code = `const mySketch = startSketchOn(XY)
|
||||
|> startProfileAt([0,0], %)
|
||||
|> startProfile(at = [0,0])
|
||||
|> line(endAbsolute = [0,2], tag = $myPath)
|
||||
|> line(endAbsolute = [2,3])
|
||||
|> line(endAbsolute = [5,-1], tag = $rightPath)
|
||||
@ -151,7 +151,7 @@ const newVar = myVar + 1`
|
||||
// Enable rotations #152
|
||||
const code = [
|
||||
'const mySk1 = startSketchOn(XY)',
|
||||
' |> startProfileAt([0,0], %)',
|
||||
' |> startProfile(at = [0,0])',
|
||||
' |> line(endAbsolute = [1,1])',
|
||||
' |> line(endAbsolute = [0, 1], tag = $myPath)',
|
||||
' |> line(endAbsolute = [1,1])',
|
||||
@ -398,7 +398,7 @@ describe('testing math operators', () => {
|
||||
it('with unaryExpression in ArrayExpression in CallExpression, checking nothing funny happens when used in a sketch', async () => {
|
||||
const code = [
|
||||
'part001 = startSketchOn(XY)',
|
||||
' |> startProfileAt([0, 0], %)',
|
||||
' |> startProfile(at = [0, 0])',
|
||||
'|> line(end = [-2.21, -legLen(hypotenuse = 5, leg = min(3, 999))])',
|
||||
].join('\n')
|
||||
const mem = await exe(code)
|
||||
@ -411,7 +411,7 @@ describe('testing math operators', () => {
|
||||
const code = [
|
||||
`const myVar = 3`,
|
||||
`const part001 = startSketchOn(XY)`,
|
||||
` |> startProfileAt([0, 0], %)`,
|
||||
` |> startProfile(at = [0, 0])`,
|
||||
` |> line(end = [3, 4], tag = $seg01)`,
|
||||
` |> line(end = [`,
|
||||
` min(segLen(seg01), myVar),`,
|
||||
@ -454,7 +454,7 @@ describe('Testing Errors', () => {
|
||||
it('should throw an error when a variable is not defined', async () => {
|
||||
const code = `const myVar = 5
|
||||
const theExtrude = startSketchOn(XY)
|
||||
|> startProfileAt([0, 0], %)
|
||||
|> startProfile(at = [0, 0])
|
||||
|> line(end = [-2.4, 5])
|
||||
|> line(end = myVarZ)
|
||||
|> line(end = [5,5])
|
||||
|
@ -18,7 +18,7 @@ describe('testing getNodePathFromSourceRange', () => {
|
||||
const code = `
|
||||
const myVar = 5
|
||||
const sk3 = startSketchOn(XY)
|
||||
|> startProfileAt([0, 0], %)
|
||||
|> startProfile(at = [0, 0])
|
||||
|> line(endAbsolute = [1, 2])
|
||||
|> line(endAbsolute = [3, 4], tag = $yo)
|
||||
|> close()
|
||||
@ -42,7 +42,7 @@ const sk3 = startSketchOn(XY)
|
||||
it('gets path right for function definition params', () => {
|
||||
const code = `fn cube = (pos, scale) => {
|
||||
const sg = startSketchOn(XY)
|
||||
|> startProfileAt(pos, %)
|
||||
|> startProfile(at = pos)
|
||||
|> line(end = [0, scale])
|
||||
|> line(end = [scale, 0])
|
||||
|> line(end = [0, -scale])
|
||||
@ -75,7 +75,7 @@ const b1 = cube([0,0], 10)`
|
||||
it('gets path right for deep within function definition body', () => {
|
||||
const code = `fn cube = (pos, scale) => {
|
||||
const sg = startSketchOn(XY)
|
||||
|> startProfileAt(pos, %)
|
||||
|> startProfile(at = pos)
|
||||
|> line(end = [0, scale])
|
||||
|> line(end = [scale, 0])
|
||||
|> line(end = [0, -scale])
|
||||
|
@ -243,7 +243,7 @@ describe('Testing addSketchTo', () => {
|
||||
)
|
||||
const str = recast(result.modifiedAst)
|
||||
expect(str).toBe(`sketch001 = startSketchOn(YZ)
|
||||
|> startProfileAt('default', %)
|
||||
|> startProfile(at = 'default')
|
||||
|> line(end = 'default')
|
||||
`)
|
||||
})
|
||||
@ -269,7 +269,7 @@ function giveSketchFnCallTagTestHelper(
|
||||
|
||||
describe('Testing giveSketchFnCallTag', () => {
|
||||
const code = `part001 = startSketchOn(XY)
|
||||
|> startProfileAt([0, 0], %)
|
||||
|> startProfile(at = [0, 0])
|
||||
|> line(end = [-2.57, -0.13])
|
||||
|> line(end = [0, 0.83])
|
||||
|> line(end = [0.82, 0.34])`
|
||||
@ -321,7 +321,7 @@ const abc = 3
|
||||
const identifierGuy = 5
|
||||
yo = 5 + 6
|
||||
part001 = startSketchOn(XY)
|
||||
|> startProfileAt([-1.2, 4.83], %)
|
||||
|> startProfile(at = [-1.2, 4.83])
|
||||
|> line(end = [2.8, 0])
|
||||
|> angledLine(angle = 100 + 100, length = 3.09)
|
||||
|> angledLine(angle = abc, length = 3.09)
|
||||
@ -404,7 +404,7 @@ yo2 = hmm([identifierGuy + 5])`
|
||||
describe('testing sketchOnExtrudedFace', () => {
|
||||
test('it should be able to extrude on regular segments', async () => {
|
||||
const code = `part001 = startSketchOn(-XZ)
|
||||
|> startProfileAt([3.58, 2.06], %)
|
||||
|> startProfile(at = [3.58, 2.06])
|
||||
|> line(end = [9.7, 9.19])
|
||||
|> line(end = [8.62, -9.57])
|
||||
|> close()
|
||||
@ -434,7 +434,7 @@ describe('testing sketchOnExtrudedFace', () => {
|
||||
|
||||
const newCode = recast(modifiedAst)
|
||||
expect(newCode).toContain(`part001 = startSketchOn(-XZ)
|
||||
|> startProfileAt([3.58, 2.06], %)
|
||||
|> startProfile(at = [3.58, 2.06])
|
||||
|> line(end = [9.7, 9.19], tag = $seg01)
|
||||
|> line(end = [8.62, -9.57])
|
||||
|> close()
|
||||
@ -443,7 +443,7 @@ sketch001 = startSketchOn(part001, face = seg01)`)
|
||||
})
|
||||
test('it should be able to extrude on close segments', async () => {
|
||||
const code = `part001 = startSketchOn(-XZ)
|
||||
|> startProfileAt([3.58, 2.06], %)
|
||||
|> startProfile(at = [3.58, 2.06])
|
||||
|> line(end = [9.7, 9.19])
|
||||
|> line(end = [8.62, -9.57])
|
||||
|> close()
|
||||
@ -472,7 +472,7 @@ sketch001 = startSketchOn(part001, face = seg01)`)
|
||||
|
||||
const newCode = recast(modifiedAst)
|
||||
expect(newCode).toContain(`part001 = startSketchOn(-XZ)
|
||||
|> startProfileAt([3.58, 2.06], %)
|
||||
|> startProfile(at = [3.58, 2.06])
|
||||
|> line(end = [9.7, 9.19])
|
||||
|> line(end = [8.62, -9.57])
|
||||
|> close(tag = $seg01)
|
||||
@ -481,13 +481,13 @@ sketch001 = startSketchOn(part001, face = seg01)`)
|
||||
})
|
||||
test('it should be able to extrude on start-end caps', async () => {
|
||||
const code = `part001 = startSketchOn(-XZ)
|
||||
|> startProfileAt([3.58, 2.06], %)
|
||||
|> startProfile(at = [3.58, 2.06])
|
||||
|> line(end = [9.7, 9.19])
|
||||
|> line(end = [8.62, -9.57])
|
||||
|> close()
|
||||
|> extrude(length = 5 + 7)`
|
||||
const ast = assertParse(code)
|
||||
const sketchSnippet = `startProfileAt([3.58, 2.06], %)`
|
||||
const sketchSnippet = `startProfile(at = [3.58, 2.06])`
|
||||
const sketchRange = topLevelRange(
|
||||
code.indexOf(sketchSnippet),
|
||||
code.indexOf(sketchSnippet) + sketchSnippet.length
|
||||
@ -511,7 +511,7 @@ sketch001 = startSketchOn(part001, face = seg01)`)
|
||||
|
||||
const newCode = recast(modifiedAst)
|
||||
expect(newCode).toContain(`part001 = startSketchOn(-XZ)
|
||||
|> startProfileAt([3.58, 2.06], %)
|
||||
|> startProfile(at = [3.58, 2.06])
|
||||
|> line(end = [9.7, 9.19])
|
||||
|> line(end = [8.62, -9.57])
|
||||
|> close()
|
||||
@ -520,7 +520,7 @@ sketch001 = startSketchOn(part001, face = END)`)
|
||||
})
|
||||
test('it should ensure that the new sketch is inserted after the extrude', async () => {
|
||||
const code = `sketch001 = startSketchOn(-XZ)
|
||||
|> startProfileAt([3.29, 7.86], %)
|
||||
|> startProfile(at = [3.29, 7.86])
|
||||
|> line(end = [2.48, 2.44])
|
||||
|> line(end = [2.66, 1.17])
|
||||
|> line(end = [3.75, 0.46])
|
||||
@ -562,7 +562,7 @@ sketch002 = startSketchOn(part001, face = seg01)`)
|
||||
describe('Testing deleteSegmentFromPipeExpression', () => {
|
||||
it('Should delete a segment withOUT any dependent segments', async () => {
|
||||
const code = `part001 = startSketchOn(-XZ)
|
||||
|> startProfileAt([54.78, -95.91], %)
|
||||
|> startProfile(at = [54.78, -95.91])
|
||||
|> line(end = [306.21, 198.82])
|
||||
|> line(end = [306.21, 198.85], tag = $a)
|
||||
|> line(end = [306.21, 198.87])`
|
||||
@ -584,7 +584,7 @@ describe('Testing deleteSegmentFromPipeExpression', () => {
|
||||
if (err(modifiedAst)) throw modifiedAst
|
||||
const newCode = recast(modifiedAst)
|
||||
expect(newCode).toBe(`part001 = startSketchOn(-XZ)
|
||||
|> startProfileAt([54.78, -95.91], %)
|
||||
|> startProfile(at = [54.78, -95.91])
|
||||
|> line(end = [306.21, 198.82])
|
||||
|> line(end = [306.21, 198.87])
|
||||
`)
|
||||
@ -595,7 +595,7 @@ describe('Testing deleteSegmentFromPipeExpression', () => {
|
||||
replace1 = '',
|
||||
replace2 = ''
|
||||
) => `part001 = startSketchOn(-XZ)
|
||||
|> startProfileAt([54.78, -95.91], %)
|
||||
|> startProfile(at = [54.78, -95.91])
|
||||
|> line(end = [306.21, 198.82], tag = $b)
|
||||
${!replace1 ? ` |> ${line}\n` : ''} |> angledLine(angle = -65, length = ${
|
||||
!replace1 ? 'segLen(a)' : replace1
|
||||
@ -672,7 +672,7 @@ ${!replace1 ? ` |> ${line}\n` : ''} |> angledLine(angle = -65, length = ${
|
||||
describe('Testing removeSingleConstraintInfo', () => {
|
||||
describe('with mostly object notation', () => {
|
||||
const code = `part001 = startSketchOn(-XZ)
|
||||
|> startProfileAt([0, 0], %)
|
||||
|> startProfile(at = [0, 0])
|
||||
|> line(end = [3 + 0, 4 + 0])
|
||||
|> /*0*/ angledLine(angle = 3 + 0, length = 3.14 + 0)
|
||||
|> line(endAbsolute = [6.14 + 0, 3.14 + 0])
|
||||
@ -780,7 +780,7 @@ describe('Testing removeSingleConstraintInfo', () => {
|
||||
})
|
||||
describe('with array notation', () => {
|
||||
const code = `part001 = startSketchOn(-XZ)
|
||||
|> startProfileAt([0, 0], %)
|
||||
|> startProfile(at = [0, 0])
|
||||
|> /*0*/ angledLine(angle = 3.14 + 0, length = 3.14 + 0)
|
||||
|> /*1*/ angledLine(angle = 3 + 0, lengthX = 3.14 + 0)
|
||||
|> /*2*/ angledLine(angle = 30 + 0, lengthY = 3 + 0)
|
||||
@ -852,7 +852,7 @@ describe('Testing deleteFromSelection', () => {
|
||||
{
|
||||
codeBefore: `myVar = 5
|
||||
sketch003 = startSketchOn(XZ)
|
||||
|> startProfileAt([3.82, 13.6], %)
|
||||
|> startProfile(at = [3.82, 13.6])
|
||||
|> line(end = [-2.94, 2.7])
|
||||
|> line(end = [7.7, 0.16])
|
||||
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||
@ -868,7 +868,7 @@ sketch003 = startSketchOn(XZ)
|
||||
// 'delete extrude',
|
||||
// {
|
||||
// codeBefore: `sketch001 = startSketchOn(XZ)
|
||||
// |> startProfileAt([3.29, 7.86], %)
|
||||
// |> startProfile(at = [3.29, 7.86])
|
||||
// |> line(end = [2.48, 2.44])
|
||||
// |> line(end = [2.66, 1.17])
|
||||
// |> line(end = [3.75, 0.46])
|
||||
@ -878,7 +878,7 @@ sketch003 = startSketchOn(XZ)
|
||||
// |> close()
|
||||
// const extrude001 = extrude(sketch001, length = 10)`,
|
||||
// codeAfter: `sketch001 = startSketchOn(XZ)
|
||||
// |> startProfileAt([3.29, 7.86], %)
|
||||
// |> startProfile(at = [3.29, 7.86])
|
||||
// |> line(end = [2.48, 2.44])
|
||||
// |> line(end = [2.66, 1.17])
|
||||
// |> line(end = [3.75, 0.46])
|
||||
@ -895,7 +895,7 @@ sketch003 = startSketchOn(XZ)
|
||||
// {
|
||||
// codeBefore: `myVar = 5
|
||||
// sketch001 = startSketchOn(XZ)
|
||||
// |> startProfileAt([4.46, 5.12], %, $tag)
|
||||
// |> startProfile(at = [4.46, 5.12], tag = $tag)
|
||||
// |> line(end = [0.08, myVar])
|
||||
// |> line(end = [13.03, 2.02], tag = $seg01)
|
||||
// |> line(end = [3.9, -7.6])
|
||||
@ -906,7 +906,7 @@ sketch003 = startSketchOn(XZ)
|
||||
// |> close()
|
||||
// const extrude001 = extrude(sketch001, length = 5)
|
||||
// sketch002 = startSketchOn(extrude001, face = seg01)
|
||||
// |> startProfileAt([-12.55, 2.89], %)
|
||||
// |> startProfile(at = [-12.55, 2.89])
|
||||
// |> line(end = [3.02, 1.9])
|
||||
// |> line(end = [1.82, -1.49], tag = $seg02)
|
||||
// |> angledLine(angle = -86, length = segLen(seg02))
|
||||
@ -916,7 +916,7 @@ sketch003 = startSketchOn(XZ)
|
||||
// |> close()`,
|
||||
// codeAfter: `myVar = 5
|
||||
// sketch001 = startSketchOn(XZ)
|
||||
// |> startProfileAt([4.46, 5.12], %, $tag)
|
||||
// |> startProfile(at = [4.46, 5.12], tag = $tag)
|
||||
// |> line(end = [0.08, myVar])
|
||||
// |> line(end = [13.03, 2.02], tag = $seg01)
|
||||
// |> line(end = [3.9, -7.6])
|
||||
@ -931,7 +931,7 @@ sketch003 = startSketchOn(XZ)
|
||||
// yAxis = { x = 7, y = 8, z = 9 },
|
||||
// zAxis = { x = 10, y = 11, z = 12 }
|
||||
// })
|
||||
// |> startProfileAt([-12.55, 2.89], %)
|
||||
// |> startProfile(at = [-12.55, 2.89])
|
||||
// |> line(end = [3.02, 1.9])
|
||||
// |> line(end = [1.82, -1.49], tag = $seg02)
|
||||
// |> angledLine(angle = -86, length = segLen(seg02))
|
||||
@ -949,7 +949,7 @@ sketch003 = startSketchOn(XZ)
|
||||
// {
|
||||
// codeBefore: `myVar = 5
|
||||
// sketch001 = startSketchOn(XZ)
|
||||
// |> startProfileAt([4.46, 5.12], %, $tag)
|
||||
// |> startProfile(at = [4.46, 5.12], tag = $tag)
|
||||
// |> line(end = [0.08, myVar])
|
||||
// |> line(end = [13.03, 2.02], tag = $seg01)
|
||||
// |> line(end = [3.9, -7.6])
|
||||
@ -960,7 +960,7 @@ sketch003 = startSketchOn(XZ)
|
||||
// |> close()
|
||||
// const extrude001 = extrude(sketch001, length = 5)
|
||||
// sketch002 = startSketchOn(extrude001, face = seg01)
|
||||
// |> startProfileAt([-12.55, 2.89], %)
|
||||
// |> startProfile(at = [-12.55, 2.89])
|
||||
// |> line(end = [3.02, 1.9])
|
||||
// |> line(end = [1.82, -1.49], tag = $seg02)
|
||||
// |> angledLine(angle = -86, length = segLen(seg02))
|
||||
@ -970,7 +970,7 @@ sketch003 = startSketchOn(XZ)
|
||||
// |> close()`,
|
||||
// codeAfter: `myVar = 5
|
||||
// sketch001 = startSketchOn(XZ)
|
||||
// |> startProfileAt([4.46, 5.12], %, $tag)
|
||||
// |> startProfile(at = [4.46, 5.12], tag = $tag)
|
||||
// |> line(end = [0.08, myVar])
|
||||
// |> line(end = [13.03, 2.02], tag = $seg01)
|
||||
// |> line(end = [3.9, -7.6])
|
||||
@ -985,7 +985,7 @@ sketch003 = startSketchOn(XZ)
|
||||
// yAxis = { x = 7, y = 8, z = 9 },
|
||||
// zAxis = { x = 10, y = 11, z = 12 }
|
||||
// })
|
||||
// |> startProfileAt([-12.55, 2.89], %)
|
||||
// |> startProfile(at = [-12.55, 2.89])
|
||||
// |> line(end = [3.02, 1.9])
|
||||
// |> line(end = [1.82, -1.49], tag = $seg02)
|
||||
// |> angledLine(angle = -86, length = segLen(seg02))
|
||||
@ -994,7 +994,7 @@ sketch003 = startSketchOn(XZ)
|
||||
// |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||
// |> close()
|
||||
// `,
|
||||
// lineOfInterest: 'startProfileAt([4.46, 5.12], %, $tag)',
|
||||
// lineOfInterest: 'startProfile(at = [4.46, 5.12], tag = $tag)',
|
||||
// type: 'cap',
|
||||
// },
|
||||
// ],
|
||||
@ -1041,7 +1041,7 @@ describe('Testing splitPipedProfile', () => {
|
||||
it('should split the pipe expression correctly', () => {
|
||||
const codeBefore = `// comment 1
|
||||
part001 = startSketchOn(XZ)
|
||||
|> startProfileAt([1, 2], %)
|
||||
|> startProfile(at = [1, 2])
|
||||
// comment 2
|
||||
|> line([3, 4], %)
|
||||
|> line([5, 6], %)
|
||||
@ -1052,7 +1052,7 @@ extrude001 = extrude(5, part001)
|
||||
|
||||
const expectedCodeAfter = `// comment 1
|
||||
sketch001 = startSketchOn(XZ)
|
||||
part001 = startProfileAt([1, 2], sketch001)
|
||||
part001 = startProfile(sketch001, at = [1, 2])
|
||||
// comment 2
|
||||
|> line([3, 4], %)
|
||||
|> line([5, 6], %)
|
||||
@ -1081,7 +1081,7 @@ extrude001 = extrude(5, part001)
|
||||
})
|
||||
it('should return error for already split pipe', () => {
|
||||
const codeBefore = `sketch001 = startSketchOn(XZ)
|
||||
part001 = startProfileAt([1, 2], sketch001)
|
||||
part001 = startProfile(sketch001, at = [1, 2])
|
||||
|> line([3, 4], %)
|
||||
|> line([5, 6], %)
|
||||
|> close(%)
|
||||
@ -1090,7 +1090,7 @@ extrude001 = extrude(5, part001)
|
||||
|
||||
const ast = assertParse(codeBefore)
|
||||
|
||||
const codeOfInterest = `startProfileAt([1, 2], sketch001)`
|
||||
const codeOfInterest = `startProfile(sketch001, at = [1, 2])`
|
||||
const range: [number, number, number] = [
|
||||
codeBefore.indexOf(codeOfInterest),
|
||||
codeBefore.indexOf(codeOfInterest) + codeOfInterest.length,
|
||||
|
@ -18,7 +18,6 @@ import {
|
||||
createLocalName,
|
||||
createObjectExpression,
|
||||
createPipeExpression,
|
||||
createPipeSubstitution,
|
||||
createVariableDeclaration,
|
||||
findUniqueName,
|
||||
} from '@src/lang/create'
|
||||
@ -92,6 +91,7 @@ import type { Selection } from '@src/lib/selections'
|
||||
import { err, reportRejection, trap } from '@src/lib/trap'
|
||||
import { isArray, isOverlap, roundOff } from '@src/lib/utils'
|
||||
import type { ExtrudeFacePlane } from '@src/machines/modelingMachine'
|
||||
import { ARG_AT } from '@src/lang/constants'
|
||||
|
||||
export function startSketchOnDefault(
|
||||
node: Node<Program>,
|
||||
@ -150,13 +150,19 @@ export function insertNewStartProfileAt(
|
||||
|
||||
const newExpression = createVariableDeclaration(
|
||||
findUniqueName(node, 'profile'),
|
||||
createCallExpressionStdLib('startProfileAt', [
|
||||
createArrayExpression([
|
||||
createLiteral(roundOff(at[0])),
|
||||
createLiteral(roundOff(at[1])),
|
||||
]),
|
||||
createCallExpressionStdLibKw(
|
||||
'startProfile',
|
||||
createLocalName(varDec.node.id.name),
|
||||
])
|
||||
[
|
||||
createLabeledArg(
|
||||
ARG_AT,
|
||||
createArrayExpression([
|
||||
createLiteral(roundOff(at[0])),
|
||||
createLiteral(roundOff(at[1])),
|
||||
])
|
||||
),
|
||||
]
|
||||
)
|
||||
)
|
||||
const insertIndex = getInsertIndex(sketchNodePaths, planeNodePath, insertType)
|
||||
|
||||
@ -191,9 +197,8 @@ export function addSketchTo(
|
||||
createLiteral(axis.toUpperCase()),
|
||||
[]
|
||||
)
|
||||
const startProfileAt = createCallExpressionStdLib('startProfileAt', [
|
||||
createLiteral('default'),
|
||||
createPipeSubstitution(),
|
||||
const startProfile = createCallExpressionStdLibKw('startProfile', null, [
|
||||
createLabeledArg(ARG_AT, createLiteral('default')),
|
||||
])
|
||||
const initialLineTo = createCallExpressionStdLibKw(
|
||||
'line',
|
||||
@ -201,7 +206,7 @@ export function addSketchTo(
|
||||
[createLabeledArg('end', createLiteral('default'))]
|
||||
)
|
||||
|
||||
const pipeBody = [startSketchOn, startProfileAt, initialLineTo]
|
||||
const pipeBody = [startSketchOn, startProfile, initialLineTo]
|
||||
|
||||
const variableDeclaration = createVariableDeclaration(
|
||||
_name,
|
||||
@ -1423,6 +1428,7 @@ export async function deleteFromSelection(
|
||||
extrudeNameToDelete = dec.id.name
|
||||
}
|
||||
if (
|
||||
// TODO: This is wrong, loft is now a CallExpressionKw.
|
||||
dec.init.type === 'CallExpression' &&
|
||||
dec.init.callee.name.name === 'loft' &&
|
||||
dec.init.arguments?.[0].type === 'ArrayExpression' &&
|
||||
@ -1441,11 +1447,14 @@ export async function deleteFromSelection(
|
||||
pathToNode = selection.codeRef.pathToNode
|
||||
if (varDec.node.type === 'VariableDeclarator') {
|
||||
extrudeNameToDelete = varDec.node.id.name
|
||||
} else if (varDec.node.type === 'CallExpression') {
|
||||
const callExp = getNodeFromPath<CallExpression>(
|
||||
} else if (
|
||||
varDec.node.type === 'CallExpression' ||
|
||||
varDec.node.type === 'CallExpressionKw'
|
||||
) {
|
||||
const callExp = getNodeFromPath<CallExpression | CallExpressionKw>(
|
||||
astClone,
|
||||
pathToNode,
|
||||
'CallExpression'
|
||||
['CallExpression', 'CallExpressionKw']
|
||||
)
|
||||
if (err(callExp)) return callExp
|
||||
extrudeNameToDelete = callExp.node.callee.name.name
|
||||
@ -1646,7 +1655,7 @@ export async function deleteFromSelection(
|
||||
pipeBody[0].type === 'CallExpressionKw') &&
|
||||
doNotDeleteProfileIfItHasBeenExtruded &&
|
||||
(pipeBody[0].callee.name.name === 'startSketchOn' ||
|
||||
pipeBody[0].callee.name.name === 'startProfileAt')
|
||||
pipeBody[0].callee.name.name === 'startProfile')
|
||||
) {
|
||||
// remove varDec
|
||||
const varDecIndex = varDec.shallowPath[1][0] as number
|
||||
@ -1749,7 +1758,7 @@ export function updateSketchNodePathsWithInsertIndex({
|
||||
* Split the following pipe expression into
|
||||
* ```ts
|
||||
* part001 = startSketchOn(XZ)
|
||||
|> startProfileAt([1, 2], %)
|
||||
|> startProfile(at = [1, 2])
|
||||
|> line([3, 4], %)
|
||||
|> line([5, 6], %)
|
||||
|> close(%)
|
||||
@ -1758,7 +1767,7 @@ extrude001 = extrude(5, part001)
|
||||
into
|
||||
```ts
|
||||
sketch001 = startSketchOn(XZ)
|
||||
part001 = startProfileAt([1, 2], sketch001)
|
||||
part001 = startProfile(sketch001, at = [1, 2])
|
||||
|> line([3, 4], %)
|
||||
|> line([5, 6], %)
|
||||
|> close(%)
|
||||
@ -1796,7 +1805,7 @@ export function splitPipedProfile(
|
||||
if (!isCallExprWithName(firstCall, 'startSketchOn'))
|
||||
return new Error('First call is not startSketchOn')
|
||||
const secondCall = init.body[1]
|
||||
if (!isCallExprWithName(secondCall, 'startProfileAt'))
|
||||
if (!isCallExprWithName(secondCall, 'startProfile'))
|
||||
return new Error('Second call is not startProfileAt')
|
||||
|
||||
const varName = varDec.node.declaration.id.name
|
||||
@ -1821,14 +1830,14 @@ export function splitPipedProfile(
|
||||
if (
|
||||
!(
|
||||
profileBrokenIntoItsOwnVar.declaration.init.body[0].type ===
|
||||
'CallExpression' &&
|
||||
'CallExpressionKw' &&
|
||||
profileBrokenIntoItsOwnVar.declaration.init.body[0].callee.name.name ===
|
||||
'startProfileAt'
|
||||
'startProfile'
|
||||
)
|
||||
) {
|
||||
return new Error('problem breaking pipe, expect startProfileAt to be first')
|
||||
}
|
||||
profileBrokenIntoItsOwnVar.declaration.init.body[0].arguments[1] =
|
||||
profileBrokenIntoItsOwnVar.declaration.init.body[0].unlabeled =
|
||||
createLocalName(newVarName)
|
||||
profileBrokenIntoItsOwnVar.declaration.id.name = varName
|
||||
profileBrokenIntoItsOwnVar.preComments = [] // we'll duplicate the comments since the new variable will have it to
|
||||
|
@ -181,7 +181,7 @@ const runGetPathToExtrudeForSegmentSelectionTest = async (
|
||||
describe('Testing getPathToExtrudeForSegmentSelection', () => {
|
||||
it('should return the correct paths for a valid selection and extrusion', async () => {
|
||||
const code = `sketch001 = startSketchOn(XY)
|
||||
|> startProfileAt([-10, 10], %)
|
||||
|> startProfile(at = [-10, 10])
|
||||
|> line(end = [20, 0])
|
||||
|> line(end = [0, -20])
|
||||
|> line(end = [-20, 0])
|
||||
@ -198,7 +198,7 @@ extrude001 = extrude(sketch001, length = -15)`
|
||||
}, 5_000)
|
||||
it('should return the correct paths when extrusion occurs within the sketch pipe', async () => {
|
||||
const code = `sketch001 = startSketchOn(XY)
|
||||
|> startProfileAt([-10, 10], %)
|
||||
|> startProfile(at = [-10, 10])
|
||||
|> line(end = [20, 0])
|
||||
|> line(end = [0, -20])
|
||||
|> line(end = [-20, 0])
|
||||
@ -215,21 +215,21 @@ extrude001 = extrude(sketch001, length = -15)`
|
||||
}, 5_000)
|
||||
it('should return the correct paths for a valid selection and extrusion in case of several extrusions and sketches', async () => {
|
||||
const code = `sketch001 = startSketchOn(XY)
|
||||
|> startProfileAt([-30, 30], %)
|
||||
|> startProfile(at = [-30, 30])
|
||||
|> line(end = [15, 0])
|
||||
|> line(end = [0, -15])
|
||||
|> line(end = [-15, 0])
|
||||
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||
|> close()
|
||||
sketch002 = startSketchOn(XY)
|
||||
|> startProfileAt([30, 30], %)
|
||||
|> startProfile(at = [30, 30])
|
||||
|> line(end = [20, 0])
|
||||
|> line(end = [0, -20])
|
||||
|> line(end = [-20, 0])
|
||||
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||
|> close()
|
||||
sketch003 = startSketchOn(XY)
|
||||
|> startProfileAt([30, -30], %)
|
||||
|> startProfile(at = [30, -30])
|
||||
|> line(end = [25, 0])
|
||||
|> line(end = [0, -25])
|
||||
|> line(end = [-25, 0])
|
||||
@ -248,7 +248,7 @@ extrude003 = extrude(sketch003, length = -15)`
|
||||
})
|
||||
it('should return the correct paths for a (piped) extrude based on the other body (face)', async () => {
|
||||
const code = `sketch001 = startSketchOn(XY)
|
||||
|> startProfileAt([-25, -25], %)
|
||||
|> startProfile(at = [-25, -25])
|
||||
|> yLine(length = 50)
|
||||
|> xLine(length = 50)
|
||||
|> yLine(length = -50)
|
||||
@ -256,7 +256,7 @@ extrude003 = extrude(sketch003, length = -15)`
|
||||
|> close()
|
||||
|> extrude(length = 50)
|
||||
sketch002 = startSketchOn(sketch001, face = 'END')
|
||||
|> startProfileAt([-15, -15], %)
|
||||
|> startProfile(at = [-15, -15])
|
||||
|> yLine(length = 30)
|
||||
|> xLine(length = 30)
|
||||
|> yLine(length = -30)
|
||||
@ -273,7 +273,7 @@ sketch002 = startSketchOn(sketch001, face = 'END')
|
||||
})
|
||||
it('should return the correct paths for a (non-piped) extrude based on the other body (face)', async () => {
|
||||
const code = `sketch001 = startSketchOn(XY)
|
||||
|> startProfileAt([-25, -25], %)
|
||||
|> startProfile(at = [-25, -25])
|
||||
|> yLine(length = 50)
|
||||
|> xLine(length = 50)
|
||||
|> yLine(length = -50)
|
||||
@ -281,7 +281,7 @@ sketch002 = startSketchOn(sketch001, face = 'END')
|
||||
|> close()
|
||||
extrude001 = extrude(sketch001, length = 50)
|
||||
sketch002 = startSketchOn(extrude001, face = 'END')
|
||||
|> startProfileAt([-15, -15], %)
|
||||
|> startProfile(at = [-15, -15])
|
||||
|> yLine(length = 30)
|
||||
|> xLine(length = 30)
|
||||
|> yLine(length = -30)
|
||||
@ -298,21 +298,21 @@ extrude002 = extrude(sketch002, length = 30)`
|
||||
})
|
||||
it('should not return any path for missing extrusion', async () => {
|
||||
const code = `sketch001 = startSketchOn(XY)
|
||||
|> startProfileAt([-30, 30], %)
|
||||
|> startProfile(at = [-30, 30])
|
||||
|> line(end = [15, 0])
|
||||
|> line(end = [0, -15])
|
||||
|> line(end = [-15, 0])
|
||||
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||
|> close()
|
||||
sketch002 = startSketchOn(XY)
|
||||
|> startProfileAt([30, 30], %)
|
||||
|> startProfile(at = [30, 30])
|
||||
|> line(end = [20, 0])
|
||||
|> line(end = [0, -20])
|
||||
|> line(end = [-20, 0])
|
||||
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||
|> close()
|
||||
sketch003 = startSketchOn(XY)
|
||||
|> startProfileAt([30, -30], %)
|
||||
|> startProfile(at = [30, -30])
|
||||
|> line(end = [25, 0])
|
||||
|> line(end = [0, -25])
|
||||
|> line(end = [-25, 0])
|
||||
@ -458,7 +458,7 @@ Object.values(EdgeTreatmentType).forEach(
|
||||
describe(`Testing modifyAstCloneWithEdgeTreatmentAndTag with ${edgeTreatmentType}s`, () => {
|
||||
it(`should add a ${edgeTreatmentType} to a specific segment`, async () => {
|
||||
const code = `sketch001 = startSketchOn(XY)
|
||||
|> startProfileAt([-10, 10], %)
|
||||
|> startProfile(at = [-10, 10])
|
||||
|> line(end = [20, 0])
|
||||
|> line(end = [0, -20])
|
||||
|> line(end = [-20, 0])
|
||||
@ -467,7 +467,7 @@ Object.values(EdgeTreatmentType).forEach(
|
||||
extrude001 = extrude(sketch001, length = -15)`
|
||||
const segmentSnippets = ['line(end = [0, -20])']
|
||||
const expectedCode = `sketch001 = startSketchOn(XY)
|
||||
|> startProfileAt([-10, 10], %)
|
||||
|> startProfile(at = [-10, 10])
|
||||
|> line(end = [20, 0])
|
||||
|> line(end = [0, -20], tag = $seg01)
|
||||
|> line(end = [-20, 0])
|
||||
@ -485,7 +485,7 @@ extrude001 = extrude(sketch001, length = -15)
|
||||
})
|
||||
it(`should add a ${edgeTreatmentType} to the sketch pipe`, async () => {
|
||||
const code = `sketch001 = startSketchOn(XY)
|
||||
|> startProfileAt([-10, 10], %)
|
||||
|> startProfile(at = [-10, 10])
|
||||
|> line(end = [20, 0])
|
||||
|> line(end = [0, -20])
|
||||
|> line(end = [-20, 0])
|
||||
@ -494,7 +494,7 @@ extrude001 = extrude(sketch001, length = -15)
|
||||
|> extrude(length = -15)`
|
||||
const segmentSnippets = ['line(end = [0, -20])']
|
||||
const expectedCode = `sketch001 = startSketchOn(XY)
|
||||
|> startProfileAt([-10, 10], %)
|
||||
|> startProfile(at = [-10, 10])
|
||||
|> line(end = [20, 0])
|
||||
|> line(end = [0, -20], tag = $seg01)
|
||||
|> line(end = [-20, 0])
|
||||
@ -512,7 +512,7 @@ extrude001 = extrude(sketch001, length = -15)
|
||||
})
|
||||
it(`should add a ${edgeTreatmentType} to an already tagged segment`, async () => {
|
||||
const code = `sketch001 = startSketchOn(XY)
|
||||
|> startProfileAt([-10, 10], %)
|
||||
|> startProfile(at = [-10, 10])
|
||||
|> line(end = [20, 0])
|
||||
|> line(end = [0, -20], tag = $seg01)
|
||||
|> line(end = [-20, 0])
|
||||
@ -521,7 +521,7 @@ extrude001 = extrude(sketch001, length = -15)
|
||||
extrude001 = extrude(sketch001, length = -15)`
|
||||
const segmentSnippets = ['line(end = [0, -20], tag = $seg01)']
|
||||
const expectedCode = `sketch001 = startSketchOn(XY)
|
||||
|> startProfileAt([-10, 10], %)
|
||||
|> startProfile(at = [-10, 10])
|
||||
|> line(end = [20, 0])
|
||||
|> line(end = [0, -20], tag = $seg01)
|
||||
|> line(end = [-20, 0])
|
||||
@ -539,7 +539,7 @@ extrude001 = extrude(sketch001, length = -15)
|
||||
})
|
||||
it(`should add a ${edgeTreatmentType} with existing tag on other segment`, async () => {
|
||||
const code = `sketch001 = startSketchOn(XY)
|
||||
|> startProfileAt([-10, 10], %)
|
||||
|> startProfile(at = [-10, 10])
|
||||
|> line(end = [20, 0], tag = $seg01)
|
||||
|> line(end = [0, -20])
|
||||
|> line(end = [-20, 0])
|
||||
@ -548,7 +548,7 @@ extrude001 = extrude(sketch001, length = -15)
|
||||
extrude001 = extrude(sketch001, length = -15)`
|
||||
const segmentSnippets = ['line(end = [-20, 0])']
|
||||
const expectedCode = `sketch001 = startSketchOn(XY)
|
||||
|> startProfileAt([-10, 10], %)
|
||||
|> startProfile(at = [-10, 10])
|
||||
|> line(end = [20, 0], tag = $seg01)
|
||||
|> line(end = [0, -20])
|
||||
|> line(end = [-20, 0], tag = $seg02)
|
||||
@ -566,7 +566,7 @@ extrude001 = extrude(sketch001, length = -15)
|
||||
})
|
||||
it(`should add a ${edgeTreatmentType} with existing fillet on other segment`, async () => {
|
||||
const code = `sketch001 = startSketchOn(XY)
|
||||
|> startProfileAt([-10, 10], %)
|
||||
|> startProfile(at = [-10, 10])
|
||||
|> line(end = [20, 0], tag = $seg01)
|
||||
|> line(end = [0, -20])
|
||||
|> line(end = [-20, 0])
|
||||
@ -576,7 +576,7 @@ extrude001 = extrude(sketch001, length = -15)
|
||||
|> fillet( radius = 5, tags = [seg01] )`
|
||||
const segmentSnippets = ['line(end = [-20, 0])']
|
||||
const expectedCode = `sketch001 = startSketchOn(XY)
|
||||
|> startProfileAt([-10, 10], %)
|
||||
|> startProfile(at = [-10, 10])
|
||||
|> line(end = [20, 0], tag = $seg01)
|
||||
|> line(end = [0, -20])
|
||||
|> line(end = [-20, 0], tag = $seg02)
|
||||
@ -595,7 +595,7 @@ extrude001 = extrude(sketch001, length = -15)
|
||||
})
|
||||
it(`should add a ${edgeTreatmentType} with existing chamfer on other segment`, async () => {
|
||||
const code = `sketch001 = startSketchOn(XY)
|
||||
|> startProfileAt([-10, 10], %)
|
||||
|> startProfile(at = [-10, 10])
|
||||
|> line(end = [20, 0], tag = $seg01)
|
||||
|> line(end = [0, -20])
|
||||
|> line(end = [-20, 0])
|
||||
@ -605,7 +605,7 @@ extrude001 = extrude(sketch001, length = -15)
|
||||
|> chamfer(length = 5, tags = [seg01])`
|
||||
const segmentSnippets = ['line(end = [-20, 0])']
|
||||
const expectedCode = `sketch001 = startSketchOn(XY)
|
||||
|> startProfileAt([-10, 10], %)
|
||||
|> startProfile(at = [-10, 10])
|
||||
|> line(end = [20, 0], tag = $seg01)
|
||||
|> line(end = [0, -20])
|
||||
|> line(end = [-20, 0], tag = $seg02)
|
||||
@ -624,7 +624,7 @@ extrude001 = extrude(sketch001, length = -15)
|
||||
})
|
||||
it(`should add a ${edgeTreatmentType} to two segments of a single extrusion`, async () => {
|
||||
const code = `sketch001 = startSketchOn(XY)
|
||||
|> startProfileAt([-10, 10], %)
|
||||
|> startProfile(at = [-10, 10])
|
||||
|> line(end = [20, 0])
|
||||
|> line(end = [0, -20])
|
||||
|> line(end = [-20, 0])
|
||||
@ -633,7 +633,7 @@ extrude001 = extrude(sketch001, length = -15)
|
||||
extrude001 = extrude(sketch001, length = -15)`
|
||||
const segmentSnippets = ['line(end = [20, 0])', 'line(end = [-20, 0])']
|
||||
const expectedCode = `sketch001 = startSketchOn(XY)
|
||||
|> startProfileAt([-10, 10], %)
|
||||
|> startProfile(at = [-10, 10])
|
||||
|> line(end = [20, 0], tag = $seg01)
|
||||
|> line(end = [0, -20])
|
||||
|> line(end = [-20, 0], tag = $seg02)
|
||||
@ -651,7 +651,7 @@ extrude001 = extrude(sketch001, length = -15)
|
||||
})
|
||||
it(`should add ${edgeTreatmentType}s to two bodies`, async () => {
|
||||
const code = `sketch001 = startSketchOn(XY)
|
||||
|> startProfileAt([-10, 10], %)
|
||||
|> startProfile(at = [-10, 10])
|
||||
|> line(end = [20, 0])
|
||||
|> line(end = [0, -20])
|
||||
|> line(end = [-20, 0])
|
||||
@ -659,7 +659,7 @@ extrude001 = extrude(sketch001, length = -15)
|
||||
|> close()
|
||||
extrude001 = extrude(sketch001, length = -15)
|
||||
sketch002 = startSketchOn(XY)
|
||||
|> startProfileAt([30, 10], %)
|
||||
|> startProfile(at = [30, 10])
|
||||
|> line(end = [15, 0])
|
||||
|> line(end = [0, -15])
|
||||
|> line(end = [-15, 0])
|
||||
@ -672,7 +672,7 @@ extrude002 = extrude(sketch002, length = -25)` // <--- body 2
|
||||
'line(end = [0, -15])',
|
||||
]
|
||||
const expectedCode = `sketch001 = startSketchOn(XY)
|
||||
|> startProfileAt([-10, 10], %)
|
||||
|> startProfile(at = [-10, 10])
|
||||
|> line(end = [20, 0], tag = $seg01)
|
||||
|> line(end = [0, -20])
|
||||
|> line(end = [-20, 0], tag = $seg02)
|
||||
@ -681,7 +681,7 @@ extrude002 = extrude(sketch002, length = -25)` // <--- body 2
|
||||
extrude001 = extrude(sketch001, length = -15)
|
||||
|> ${edgeTreatmentType}(${parameterName} = 3, tags = [seg01, seg02])
|
||||
sketch002 = startSketchOn(XY)
|
||||
|> startProfileAt([30, 10], %)
|
||||
|> startProfile(at = [30, 10])
|
||||
|> line(end = [15, 0])
|
||||
|> line(end = [0, -15], tag = $seg03)
|
||||
|> line(end = [-15, 0])
|
||||
@ -702,7 +702,7 @@ extrude002 = extrude(sketch002, length = -25)
|
||||
// simple cases
|
||||
it(`should delete a piped ${edgeTreatmentType} from a single segment`, async () => {
|
||||
const code = `sketch001 = startSketchOn(XY)
|
||||
|> startProfileAt([-10, 10], %)
|
||||
|> startProfile(at = [-10, 10])
|
||||
|> line(end = [20, 0])
|
||||
|> line(end = [0, -20])
|
||||
|> line(end = [-20, 0], tag = $seg01)
|
||||
@ -712,7 +712,7 @@ extrude001 = extrude(sketch001, length = -15)
|
||||
|> ${edgeTreatmentType}(${parameterName} = 3, tags = [seg01])`
|
||||
const edgeTreatmentSnippet = `${edgeTreatmentType}(${parameterName} = 3, tags = [seg01])`
|
||||
const expectedCode = `sketch001 = startSketchOn(XY)
|
||||
|> startProfileAt([-10, 10], %)
|
||||
|> startProfile(at = [-10, 10])
|
||||
|> line(end = [20, 0])
|
||||
|> line(end = [0, -20])
|
||||
|> line(end = [-20, 0], tag = $seg01)
|
||||
@ -728,7 +728,7 @@ extrude001 = extrude(sketch001, length = -15)`
|
||||
})
|
||||
it(`should delete a non-piped ${edgeTreatmentType} from a single segment`, async () => {
|
||||
const code = `sketch001 = startSketchOn(XY)
|
||||
|> startProfileAt([-10, 10], %)
|
||||
|> startProfile(at = [-10, 10])
|
||||
|> line(end = [20, 0])
|
||||
|> line(end = [0, -20])
|
||||
|> line(end = [-20, 0], tag = $seg01)
|
||||
@ -738,7 +738,7 @@ extrude001 = extrude(sketch001, length = -15)
|
||||
fillet001 = ${edgeTreatmentType}(extrude001, ${parameterName} = 3, tags = [seg01])`
|
||||
const edgeTreatmentSnippet = `fillet001 = ${edgeTreatmentType}(extrude001, ${parameterName} = 3, tags = [seg01])`
|
||||
const expectedCode = `sketch001 = startSketchOn(XY)
|
||||
|> startProfileAt([-10, 10], %)
|
||||
|> startProfile(at = [-10, 10])
|
||||
|> line(end = [20, 0])
|
||||
|> line(end = [0, -20])
|
||||
|> line(end = [-20, 0], tag = $seg01)
|
||||
@ -755,7 +755,7 @@ extrude001 = extrude(sketch001, length = -15)`
|
||||
// getOppositeEdge and getNextAdjacentEdge cases
|
||||
it(`should delete a piped ${edgeTreatmentType} tagged with getOppositeEdge`, async () => {
|
||||
const code = `sketch001 = startSketchOn(XY)
|
||||
|> startProfileAt([-10, 10], %)
|
||||
|> startProfile(at = [-10, 10])
|
||||
|> line(end = [20, 0])
|
||||
|> line(end = [0, -20])
|
||||
|> line(end = [-20, 0], tag = $seg01)
|
||||
@ -765,7 +765,7 @@ extrude001 = extrude(sketch001, length = -15)
|
||||
fillet001 = ${edgeTreatmentType}(extrude001, ${parameterName} = 3, tags = [getOppositeEdge(seg01)])`
|
||||
const edgeTreatmentSnippet = `fillet001 = ${edgeTreatmentType}(extrude001, ${parameterName} = 3, tags = [getOppositeEdge(seg01)])`
|
||||
const expectedCode = `sketch001 = startSketchOn(XY)
|
||||
|> startProfileAt([-10, 10], %)
|
||||
|> startProfile(at = [-10, 10])
|
||||
|> line(end = [20, 0])
|
||||
|> line(end = [0, -20])
|
||||
|> line(end = [-20, 0], tag = $seg01)
|
||||
@ -781,7 +781,7 @@ extrude001 = extrude(sketch001, length = -15)`
|
||||
})
|
||||
it(`should delete a non-piped ${edgeTreatmentType} tagged with getNextAdjacentEdge`, async () => {
|
||||
const code = `sketch001 = startSketchOn(XY)
|
||||
|> startProfileAt([-10, 10], %)
|
||||
|> startProfile(at = [-10, 10])
|
||||
|> line(end = [20, 0])
|
||||
|> line(end = [0, -20])
|
||||
|> line(end = [-20, 0], tag = $seg01)
|
||||
@ -791,7 +791,7 @@ extrude001 = extrude(sketch001, length = -15)
|
||||
fillet001 = ${edgeTreatmentType}(extrude001, ${parameterName} = 3, tags = [getNextAdjacentEdge(seg01)])`
|
||||
const edgeTreatmentSnippet = `fillet001 = ${edgeTreatmentType}(extrude001, ${parameterName} = 3, tags = [getNextAdjacentEdge(seg01)])`
|
||||
const expectedCode = `sketch001 = startSketchOn(XY)
|
||||
|> startProfileAt([-10, 10], %)
|
||||
|> startProfile(at = [-10, 10])
|
||||
|> line(end = [20, 0])
|
||||
|> line(end = [0, -20])
|
||||
|> line(end = [-20, 0], tag = $seg01)
|
||||
@ -808,7 +808,7 @@ extrude001 = extrude(sketch001, length = -15)`
|
||||
// cases with several edge treatments
|
||||
it(`should delete a piped ${edgeTreatmentType} from a body with multiple treatments`, async () => {
|
||||
const code = `sketch001 = startSketchOn(XY)
|
||||
|> startProfileAt([-10, 10], %)
|
||||
|> startProfile(at = [-10, 10])
|
||||
|> line(end = [20, 0], tag = $seg01)
|
||||
|> line(end = [0, -20])
|
||||
|> line(end = [-20, 0], tag = $seg02)
|
||||
@ -821,7 +821,7 @@ fillet001 = ${edgeTreatmentType}(extrude001, ${parameterName} = 6, tags = [seg02
|
||||
chamfer001 = chamfer(extrude001, length = 5, tags = [getOppositeEdge(seg01)])`
|
||||
const edgeTreatmentSnippet = `${edgeTreatmentType}(${parameterName} = 3, tags = [seg01])`
|
||||
const expectedCode = `sketch001 = startSketchOn(XY)
|
||||
|> startProfileAt([-10, 10], %)
|
||||
|> startProfile(at = [-10, 10])
|
||||
|> line(end = [20, 0], tag = $seg01)
|
||||
|> line(end = [0, -20])
|
||||
|> line(end = [-20, 0], tag = $seg02)
|
||||
@ -840,7 +840,7 @@ chamfer001 = chamfer(extrude001, length = 5, tags = [getOppositeEdge(seg01)])`
|
||||
})
|
||||
it(`should delete a non-piped ${edgeTreatmentType} from a body with multiple treatments`, async () => {
|
||||
const code = `sketch001 = startSketchOn(XY)
|
||||
|> startProfileAt([-10, 10], %)
|
||||
|> startProfile(at = [-10, 10])
|
||||
|> line(end = [20, 0], tag = $seg01)
|
||||
|> line(end = [0, -20])
|
||||
|> line(end = [-20, 0], tag = $seg02)
|
||||
@ -853,7 +853,7 @@ fillet001 = ${edgeTreatmentType}(extrude001, ${parameterName} = 6, tags = [seg02
|
||||
chamfer001 = chamfer(extrude001, length = 5, tags = [getOppositeEdge(seg01)])`
|
||||
const edgeTreatmentSnippet = `fillet001 = ${edgeTreatmentType}(extrude001, ${parameterName} = 6, tags = [seg02])`
|
||||
const expectedCode = `sketch001 = startSketchOn(XY)
|
||||
|> startProfileAt([-10, 10], %)
|
||||
|> startProfile(at = [-10, 10])
|
||||
|> line(end = [20, 0], tag = $seg01)
|
||||
|> line(end = [0, -20])
|
||||
|> line(end = [-20, 0], tag = $seg02)
|
||||
@ -876,7 +876,7 @@ chamfer001 = chamfer(extrude001, length = 5, tags = [getOppositeEdge(seg01)])`
|
||||
|
||||
describe('Testing isTagUsedInEdgeTreatment', () => {
|
||||
const code = `sketch001 = startSketchOn(XZ)
|
||||
|> startProfileAt([7.72, 4.13], %)
|
||||
|> startProfile(at = [7.72, 4.13])
|
||||
|> line(end = [7.11, 3.48], tag = $seg01)
|
||||
|> line(end = [-3.29, -13.85])
|
||||
|> line(end = [-6.37, 3.88], tag = $seg02)
|
||||
@ -980,7 +980,7 @@ describe('Testing button states', () => {
|
||||
}
|
||||
const codeWithBody: string = `
|
||||
sketch001 = startSketchOn(XY)
|
||||
|> startProfileAt([-20, -5], %)
|
||||
|> startProfile(at = [-20, -5])
|
||||
|> line(end = [0, 10])
|
||||
|> line(end = [10, 0])
|
||||
|> line(end = [0, -10])
|
||||
@ -990,7 +990,7 @@ describe('Testing button states', () => {
|
||||
`
|
||||
const codeWithoutBodies: string = `
|
||||
sketch001 = startSketchOn(XY)
|
||||
|> startProfileAt([-20, -5], %)
|
||||
|> startProfile(at = [-20, -5])
|
||||
|> line(end = [0, 10])
|
||||
|> line(end = [10, 0])
|
||||
|> line(end = [0, -10])
|
||||
|
@ -45,7 +45,7 @@ arrExpShouldNotBeIncluded = [1, 2, 3]
|
||||
objExpShouldNotBeIncluded = { a: 1, b: 2, c: 3 }
|
||||
|
||||
part001 = startSketchOn(XY)
|
||||
|> startProfileAt([0, 0], %)
|
||||
|> startProfile(at = [0, 0])
|
||||
|> yLine(endAbsolute = 1)
|
||||
|> xLine(length = 3.84) // selection-range-7ish-before-this
|
||||
|
||||
@ -76,7 +76,7 @@ variableBelowShouldNotBeIncluded = 3
|
||||
|
||||
describe('testing argIsNotIdentifier', () => {
|
||||
const code = `part001 = startSketchOn(XY)
|
||||
|> startProfileAt([-1.2, 4.83], %)
|
||||
|> startProfile(at = [-1.2, 4.83])
|
||||
|> line(end = [2.8, 0])
|
||||
|> angledLine(angle = 100 + 100, length = 3.09)
|
||||
|> angledLine(angle = abc, length = 3.09)
|
||||
@ -236,7 +236,7 @@ yo2 = hmm([identifierGuy + 5])`
|
||||
|
||||
describe('testing getNodePathFromSourceRange', () => {
|
||||
const code = `part001 = startSketchOn(XY)
|
||||
|> startProfileAt([0.39, -0.05], %)
|
||||
|> startProfile(at = [0.39, -0.05])
|
||||
|> line(end = [0.94, 2.61])
|
||||
|> line(end = [-0.21, -1.4])`
|
||||
it('finds the second line when cursor is put at the end', () => {
|
||||
@ -380,7 +380,7 @@ describe('testing hasExtrudeSketch', () => {
|
||||
it('find sketch', async () => {
|
||||
const exampleCode = `length001 = 2
|
||||
part001 = startSketchOn(XY)
|
||||
|> startProfileAt([-1.41, 3.46], %)
|
||||
|> startProfile(at = [-1.41, 3.46])
|
||||
|> line(end = [19.49, 1.16], tag = $seg01)
|
||||
|> angledLine(angle = -35, length = length001)
|
||||
|> line(end = [-3.22, -7.36])
|
||||
@ -400,7 +400,7 @@ part001 = startSketchOn(XY)
|
||||
it('find solid', async () => {
|
||||
const exampleCode = `length001 = 2
|
||||
part001 = startSketchOn(XY)
|
||||
|> startProfileAt([-1.41, 3.46], %)
|
||||
|> startProfile(at = [-1.41, 3.46])
|
||||
|> line(end = [19.49, 1.16], tag = $seg01)
|
||||
|> angledLine(angle = -35, length = length001)
|
||||
|> line(end = [-3.22, -7.36])
|
||||
@ -436,7 +436,7 @@ part001 = startSketchOn(XY)
|
||||
|
||||
describe('Testing findUsesOfTagInPipe', () => {
|
||||
const exampleCode = `part001 = startSketchOn(-XZ)
|
||||
|> startProfileAt([68.12, 156.65], %)
|
||||
|> startProfile(at = [68.12, 156.65])
|
||||
|> line(end = [306.21, 198.82])
|
||||
|> line(end = [306.21, 198.85], tag = $seg01)
|
||||
|> angledLine(angle = -65, length = segLen(seg01))
|
||||
@ -475,7 +475,7 @@ describe('Testing findUsesOfTagInPipe', () => {
|
||||
|
||||
describe('Testing hasSketchPipeBeenExtruded', () => {
|
||||
const exampleCode = `sketch001 = startSketchOn(XZ)
|
||||
|> startProfileAt([3.29, 7.86], %)
|
||||
|> startProfile(at = [3.29, 7.86])
|
||||
|> line(end = [2.48, 2.44])
|
||||
|> line(end = [2.66, 1.17])
|
||||
|> line(end = [3.75, 0.46])
|
||||
@ -489,13 +489,13 @@ describe('Testing hasSketchPipeBeenExtruded', () => {
|
||||
|> close()
|
||||
extrude001 = extrude(sketch001, length = 10)
|
||||
sketch002 = startSketchOn(extrude001, face = seg01)
|
||||
|> startProfileAt([-12.94, 6.6], %)
|
||||
|> startProfile(at = [-12.94, 6.6])
|
||||
|> line(end = [2.45, -0.2])
|
||||
|> line(end = [-2, -1.25])
|
||||
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||
|> close()
|
||||
sketch003 = startSketchOn(extrude001, face = 'END')
|
||||
|> startProfileAt([8.14, 2.8], %)
|
||||
|> startProfile(at = [8.14, 2.8])
|
||||
|> line(end = [-1.24, 4.39])
|
||||
|> line(end = [3.79, 1.91])
|
||||
|> line(end = [1.77, -2.95])
|
||||
@ -559,14 +559,14 @@ sketch003 = startSketchOn(extrude001, face = 'END')
|
||||
describe('Testing doesSceneHaveSweepableSketch', () => {
|
||||
it('finds sketch001 pipe to be extruded', async () => {
|
||||
const exampleCode = `sketch001 = startSketchOn(XZ)
|
||||
|> startProfileAt([3.29, 7.86], %)
|
||||
|> startProfile(at = [3.29, 7.86])
|
||||
|> line(end = [2.48, 2.44])
|
||||
|> line(end = [-3.86, -2.73])
|
||||
|> line(end = [-17.67, 0.85])
|
||||
|> close()
|
||||
extrude001 = extrude(sketch001, length = 10)
|
||||
sketch002 = startSketchOn(extrude001, face = $seg01)
|
||||
|> startProfileAt([-12.94, 6.6], %)
|
||||
|> startProfile(at = [-12.94, 6.6])
|
||||
|> line(end = [2.45, -0.2])
|
||||
|> line(end = [-2, -1.25])
|
||||
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||
@ -589,7 +589,7 @@ sketch002 = startSketchOn(plane001)
|
||||
})
|
||||
it('should recognize that sketch001 has been extruded', async () => {
|
||||
const exampleCode = `sketch001 = startSketchOn(XZ)
|
||||
|> startProfileAt([3.29, 7.86], %)
|
||||
|> startProfile(at = [3.29, 7.86])
|
||||
|> line(end = [2.48, 2.44])
|
||||
|> line(end = [-3.86, -2.73])
|
||||
|> line(end = [-17.67, 0.85])
|
||||
@ -644,7 +644,7 @@ describe('Testing traverse and pathToNode', () => {
|
||||
])('testing %s', async (testName, literalOfInterest) => {
|
||||
const code = `myVar = 5
|
||||
sketch001 = startSketchOn(XZ)
|
||||
|> startProfileAt([3.29, 7.86], %)
|
||||
|> startProfile(at = [3.29, 7.86])
|
||||
|> line(end = [2.48, 2.44])
|
||||
|> line(end = [-3.86, -2.73])
|
||||
|> line(end = [-17.67, 0.85])
|
||||
@ -686,7 +686,7 @@ myNestedVar = [
|
||||
describe('Testing specific sketch getNodeFromPath workflow', () => {
|
||||
it('should parse the code', () => {
|
||||
const openSketch = `sketch001 = startSketchOn(XZ)
|
||||
|> startProfileAt([0.02, 0.22], %)
|
||||
|> startProfile(at = [0.02, 0.22])
|
||||
|> xLine(length = 0.39)
|
||||
|> line([0.02, -0.17], %)
|
||||
|> yLine(length = -0.15)
|
||||
@ -700,7 +700,7 @@ describe('Testing specific sketch getNodeFromPath workflow', () => {
|
||||
})
|
||||
it('should find the location to add new lineTo', () => {
|
||||
const openSketch = `sketch001 = startSketchOn(XZ)
|
||||
|> startProfileAt([0.02, 0.22], %)
|
||||
|> startProfile(at = [0.02, 0.22])
|
||||
|> xLine(length = 0.39)
|
||||
|> line([0.02, -0.17], %)
|
||||
|> yLine(length = -0.15)
|
||||
@ -710,7 +710,7 @@ describe('Testing specific sketch getNodeFromPath workflow', () => {
|
||||
|> line([-0.08, 0.05], %)`
|
||||
const ast = assertParse(openSketch)
|
||||
|
||||
const sketchSnippet = `startProfileAt([0.02, 0.22], %)`
|
||||
const sketchSnippet = `startProfile(at = [0.02, 0.22])`
|
||||
const sketchRange = topLevelRange(
|
||||
openSketch.indexOf(sketchSnippet),
|
||||
openSketch.indexOf(sketchSnippet) + sketchSnippet.length
|
||||
@ -740,7 +740,7 @@ describe('Testing specific sketch getNodeFromPath workflow', () => {
|
||||
if (err(modifiedAst)) throw modifiedAst
|
||||
const recasted = recast(modifiedAst)
|
||||
const expectedCode = `sketch001 = startSketchOn(XZ)
|
||||
|> startProfileAt([0.02, 0.22], %)
|
||||
|> startProfile(at = [0.02, 0.22])
|
||||
|> xLine(length = 0.39)
|
||||
|> line([0.02, -0.17], %)
|
||||
|> yLine(length = -0.15)
|
||||
@ -754,7 +754,7 @@ describe('Testing specific sketch getNodeFromPath workflow', () => {
|
||||
})
|
||||
it('it should find the location to add close', () => {
|
||||
const openSketch = `sketch001 = startSketchOn(XZ)
|
||||
|> startProfileAt([0.02, 0.22], %)
|
||||
|> startProfile(at = [0.02, 0.22])
|
||||
|> xLine(length = 0.39)
|
||||
|> line([0.02, -0.17], %)
|
||||
|> yLine(length = -0.15)
|
||||
@ -765,7 +765,7 @@ describe('Testing specific sketch getNodeFromPath workflow', () => {
|
||||
|> lineTo([profileStartX(%), profileStartY(%)], %)
|
||||
`
|
||||
const ast = assertParse(openSketch)
|
||||
const sketchSnippet = `startProfileAt([0.02, 0.22], %)`
|
||||
const sketchSnippet = `startProfile(at = [0.02, 0.22])`
|
||||
const sketchRange = topLevelRange(
|
||||
openSketch.indexOf(sketchSnippet),
|
||||
openSketch.indexOf(sketchSnippet) + sketchSnippet.length
|
||||
@ -780,7 +780,7 @@ describe('Testing specific sketch getNodeFromPath workflow', () => {
|
||||
if (err(modifiedAst)) throw modifiedAst
|
||||
const recasted = recast(modifiedAst)
|
||||
const expectedCode = `sketch001 = startSketchOn(XZ)
|
||||
|> startProfileAt([0.02, 0.22], %)
|
||||
|> startProfile(at = [0.02, 0.22])
|
||||
|> xLine(length = 0.39)
|
||||
|> line([0.02, -0.17], %)
|
||||
|> yLine(length = -0.15)
|
||||
|
@ -816,7 +816,7 @@ export function doesSceneHaveSweepableSketch(ast: Node<Program>, count = 1) {
|
||||
if (
|
||||
(pipe.type === 'CallExpressionKw' ||
|
||||
pipe.type === 'CallExpression') &&
|
||||
pipe.callee.name.name === 'startProfileAt'
|
||||
pipe.callee.name.name === 'startProfile'
|
||||
) {
|
||||
hasStartProfileAt = true
|
||||
}
|
||||
@ -964,7 +964,7 @@ export function doesSketchPipeNeedSplitting(
|
||||
if (!firstPipe || !secondPipe) return false
|
||||
if (
|
||||
isCallExprWithName(firstPipe, 'startSketchOn') &&
|
||||
isCallExprWithName(secondPipe, 'startProfileAt')
|
||||
isCallExprWithName(secondPipe, 'startProfile')
|
||||
)
|
||||
return true
|
||||
return false
|
||||
|
@ -16,7 +16,7 @@ z = x + y`)
|
||||
})
|
||||
it(`expression with no identifiers in longer program`, () => {
|
||||
const baseProgram = assertParse(`x = 5 + 2
|
||||
profile001 = startProfileAt([0.07, 0], sketch001)
|
||||
profile001 = startProfile(sketch001, at = [0.07, 0])
|
||||
|> angledLine(angle = 0, length = x, tag = $a)
|
||||
|> angledLine(angle = segAng(a) + 90, length = 5)
|
||||
|> angledLine(angle = segAng(a), length = -segLen(a))
|
||||
@ -41,7 +41,7 @@ z = x + y`)
|
||||
})
|
||||
it(`expression with a tag declarator add to end`, () => {
|
||||
const baseProgram = assertParse(`x = 5 + 2
|
||||
profile001 = startProfileAt([0.07, 0], sketch001)
|
||||
profile001 = startProfile(sketch001, at = [0.07, 0])
|
||||
|> angledLine(angle = 0, length = x, tag = $a)
|
||||
|> angledLine(angle = segAng(a) + 90, length = 5)
|
||||
|> angledLine(angle = segAng(a), length = -segLen(a))
|
||||
@ -52,7 +52,7 @@ z = x + y`)
|
||||
})
|
||||
it(`expression with a tag declarator and variable in the middle`, () => {
|
||||
const baseProgram = assertParse(`x = 5 + 2
|
||||
profile001 = startProfileAt([0.07, 0], sketch001)
|
||||
profile001 = startProfile(sketch001, at = [0.07, 0])
|
||||
|> angledLine(angle = 0, length = x, tag = $a)
|
||||
|> angledLine(angle = segAng(a) + 90, length = 5)
|
||||
|> angledLine(angle = segAng(a), length = -segLen(a))
|
||||
|
@ -32,14 +32,14 @@ describe(`getTagDeclaratorsInProgram`, () => {
|
||||
it(`finds a single tag declarators in a small program`, () => {
|
||||
const tagDeclarators = getTagDeclaratorsInProgram(
|
||||
assertParse(`sketch001 = startSketchOn(XZ)
|
||||
profile001 = startProfileAt([0, 0], sketch001)
|
||||
profile001 = startProfile(sketch001, at = [0, 0])
|
||||
|> angledLine(angle = 0, length = 11, tag = $a)`)
|
||||
)
|
||||
expect(tagDeclarators).toEqual([tagDeclaratorWithIndex('a', 123, 125, 1)])
|
||||
expect(tagDeclarators).toEqual([tagDeclaratorWithIndex('a', 126, 128, 1)])
|
||||
})
|
||||
it(`finds multiple tag declarators in a small program`, () => {
|
||||
const program = `sketch001 = startSketchOn(XZ)
|
||||
profile001 = startProfileAt([0.07, 0], sketch001)
|
||||
profile001 = startProfile(sketch001, at = [0.07, 0])
|
||||
|> angledLine(angle = 0, length = 11, tag = $a)
|
||||
|> angledLine(angle = segAng(a) + 90, length = 11.17, tag = $b)
|
||||
|> angledLine(angle = segAng(a), length = -segLen(a), tag = $c)
|
||||
@ -47,14 +47,14 @@ profile001 = startProfileAt([0.07, 0], sketch001)
|
||||
|> close()`
|
||||
const tagDeclarators = getTagDeclaratorsInProgram(assertParse(program))
|
||||
expect(tagDeclarators).toEqual([
|
||||
tagDeclaratorWithIndex('a', 126, 128, 1),
|
||||
tagDeclaratorWithIndex('b', 192, 194, 1),
|
||||
tagDeclaratorWithIndex('c', 258, 260, 1),
|
||||
tagDeclaratorWithIndex('a', 129, 131, 1),
|
||||
tagDeclaratorWithIndex('b', 195, 197, 1),
|
||||
tagDeclaratorWithIndex('c', 261, 263, 1),
|
||||
])
|
||||
})
|
||||
it(`finds tag declarators at different indices`, () => {
|
||||
const program = `sketch001 = startSketchOn(XZ)
|
||||
profile001 = startProfileAt([0.07, 0], sketch001)
|
||||
profile001 = startProfile(sketch001, at = [0.07, 0])
|
||||
|> angledLine(angle = 0, length = 11, tag = $a)
|
||||
profile002 = angledLine(profile001, angle = segAng(a) + 90, length = 11.17, tag = $b)
|
||||
|> angledLine(angle = segAng(a), length = -segLen(a), tag = $c)
|
||||
@ -62,9 +62,9 @@ profile002 = angledLine(profile001, angle = segAng(a) + 90, length = 11.17, tag
|
||||
|> close()`
|
||||
const tagDeclarators = getTagDeclaratorsInProgram(assertParse(program))
|
||||
expect(tagDeclarators).toEqual([
|
||||
tagDeclaratorWithIndex('a', 126, 128, 1),
|
||||
tagDeclaratorWithIndex('b', 212, 214, 2),
|
||||
tagDeclaratorWithIndex('c', 278, 280, 2),
|
||||
tagDeclaratorWithIndex('a', 129, 131, 1),
|
||||
tagDeclaratorWithIndex('b', 215, 217, 2),
|
||||
tagDeclaratorWithIndex('c', 281, 283, 2),
|
||||
])
|
||||
})
|
||||
})
|
||||
|
@ -79,7 +79,7 @@ log(5, myVar)
|
||||
})
|
||||
it('recast sketch declaration', () => {
|
||||
let code = `mySketch = startSketchOn(XY)
|
||||
|> startProfileAt([0, 0], %)
|
||||
|> startProfile(at = [0, 0])
|
||||
|> line(endAbsolute = [0, 1], tag = $myPath)
|
||||
|> line(endAbsolute = [1, 1])
|
||||
|> line(endAbsolute = [1, 0], tag = $rightPath)
|
||||
@ -93,7 +93,7 @@ log(5, myVar)
|
||||
it('sketch piped into callExpression', () => {
|
||||
const code = [
|
||||
'mySk1 = startSketchOn(XY)',
|
||||
' |> startProfileAt([0, 0], %)',
|
||||
' |> startProfile(at = [0, 0])',
|
||||
' |> line(endAbsolute = [1, 1])',
|
||||
' |> line(endAbsolute = [0, 1], tag = $myTag)',
|
||||
' |> line(endAbsolute = [1, 1])',
|
||||
@ -239,7 +239,7 @@ key = 'c'
|
||||
it('comments in a pipe expression', () => {
|
||||
const code = [
|
||||
'mySk1 = startSketchOn(XY)',
|
||||
' |> startProfileAt([0, 0], %)',
|
||||
' |> startProfile(at = [0, 0])',
|
||||
' |> line(endAbsolute = [1, 1])',
|
||||
' |> line(endAbsolute = [0, 1], tag = $myTag)',
|
||||
' |> line(endAbsolute = [1, 1])',
|
||||
@ -256,7 +256,7 @@ key = 'c'
|
||||
/* comment at start */
|
||||
|
||||
mySk1 = startSketchOn(XY)
|
||||
|> startProfileAt([0, 0], %)
|
||||
|> startProfile(at = [0, 0])
|
||||
|> line(endAbsolute = [1, 1])
|
||||
// comment here
|
||||
|> line(endAbsolute = [0, 1], tag = $myTag)
|
||||
@ -280,7 +280,7 @@ one more for good measure
|
||||
expect(recasted).toBe(`/* comment at start */
|
||||
|
||||
mySk1 = startSketchOn(XY)
|
||||
|> startProfileAt([0, 0], %)
|
||||
|> startProfile(at = [0, 0])
|
||||
|> line(endAbsolute = [1, 1])
|
||||
// comment here
|
||||
|> line(endAbsolute = [0, 1], tag = $myTag)
|
||||
@ -321,7 +321,7 @@ describe('testing call Expressions in BinaryExpressions and UnaryExpressions', (
|
||||
it('with unaryExpression in sketch situation', () => {
|
||||
const code = [
|
||||
'part001 = startSketchOn(XY)',
|
||||
' |> startProfileAt([0, 0])',
|
||||
' |> startProfile(at = [0, 0])',
|
||||
' |> line(end = [\n -2.21,\n -legLen(hypotenuse = 5, leg = min(3, 999))\n ])',
|
||||
].join('\n')
|
||||
const { ast } = code2ast(code)
|
||||
@ -334,7 +334,7 @@ describe('testing call Expressions in BinaryExpressions and UnaryExpressions', (
|
||||
describe('it recasts wrapped object expressions in pipe bodies with correct indentation', () => {
|
||||
it('with a single line', () => {
|
||||
const code = `part001 = startSketchOn(XY)
|
||||
|> startProfileAt([-0.01, -0.08], %)
|
||||
|> startProfile(at = [-0.01, -0.08])
|
||||
|> line(end = [0.62, 4.15], tag = $seg01)
|
||||
|> line(end = [2.77, -1.24])
|
||||
|> angledLineThatIntersects(angle = 201, offset = -1.35, intersectTag = $seg01)
|
||||
|
@ -108,7 +108,7 @@ describe('testing changeSketchArguments', () => {
|
||||
test('changeSketchArguments', async () => {
|
||||
// Enable rotations #152
|
||||
const genCode = (line: string) => `mySketch001 = startSketchOn(XY)
|
||||
|> startProfileAt([0, 0], %)
|
||||
|> startProfile(at = [0, 0])
|
||||
|> ${line}
|
||||
|> line(endAbsolute = [0.46, -5.82])
|
||||
// |> rx(45, %)
|
||||
@ -146,7 +146,7 @@ describe('testing addNewSketchLn', () => {
|
||||
// Enable rotations #152
|
||||
const code = `
|
||||
mySketch001 = startSketchOn(XY)
|
||||
|> startProfileAt([0, 0], %)
|
||||
|> startProfile(at = [0, 0])
|
||||
// |> rx(45, %)
|
||||
|> line(endAbsolute = [-1.59, -1.54])
|
||||
|> line(endAbsolute = [0.46, -5.82])`
|
||||
@ -175,7 +175,7 @@ mySketch001 = startSketchOn(XY)
|
||||
|
||||
// Enable rotations #152
|
||||
let expectedCode = `mySketch001 = startSketchOn(XY)
|
||||
|> startProfileAt([0, 0], %)
|
||||
|> startProfile(at = [0, 0])
|
||||
// |> rx(45, %)
|
||||
|> line(endAbsolute = [-1.59, -1.54])
|
||||
|> line(endAbsolute = [0.46, -5.82])
|
||||
@ -198,7 +198,7 @@ mySketch001 = startSketchOn(XY)
|
||||
if (err(modifiedAst2)) return modifiedAst2
|
||||
|
||||
expectedCode = `mySketch001 = startSketchOn(XY)
|
||||
|> startProfileAt([0, 0], %)
|
||||
|> startProfile(at = [0, 0])
|
||||
// |> rx(45, %)
|
||||
|> line(endAbsolute = [-1.59, -1.54])
|
||||
|> line(endAbsolute = [0.46, -5.82])
|
||||
@ -213,7 +213,7 @@ describe('testing addTagForSketchOnFace', () => {
|
||||
const originalLine = 'line(endAbsolute = [-1.59, -1.54])'
|
||||
// Enable rotations #152
|
||||
const genCode = (line: string) => `mySketch001 = startSketchOn(XY)
|
||||
|> startProfileAt([0, 0], %)
|
||||
|> startProfile(at = [0, 0])
|
||||
// |> rx(45, %)
|
||||
|> ${line}
|
||||
|> line(endAbsolute = [0.46, -5.82])
|
||||
@ -273,7 +273,7 @@ describe('testing addTagForSketchOnFace', () => {
|
||||
chamferTestCases.forEach(({ originalChamfer, expectedChamfer, desc }) => {
|
||||
it(`can break up chamfers in order to add tags - ${desc}`, async () => {
|
||||
const genCode = (insertCode: string) => `sketch001 = startSketchOn(XZ)
|
||||
|> startProfileAt([75.8, 317.2], %) // [$startCapTag, $EndCapTag]
|
||||
|> startProfile(at = [75.8, 317.2]) // [$startCapTag, $EndCapTag]
|
||||
|> angledLine(angle = 0, length = 268.43, tag = $rectangleSegmentA001)
|
||||
|> angledLine(angle = segAng(rectangleSegmentA001) - 90, length = 217.26, tag = $seg01)
|
||||
|> angledLine(angle = segAng(rectangleSegmentA001), length = -segLen(rectangleSegmentA001))
|
||||
@ -318,7 +318,7 @@ ${insertCode}
|
||||
describe('testing getConstraintInfo', () => {
|
||||
describe('object notation', () => {
|
||||
const code = `const part001 = startSketchOn(-XZ)
|
||||
|> startProfileAt([0,0], %)
|
||||
|> startProfile(at = [0,0])
|
||||
|> line(end = [3, 4])
|
||||
|> angledLine(angle = 3.14, length = 3.14)
|
||||
|> line(endAbsolute = [6.14, 3.14])
|
||||
@ -684,7 +684,7 @@ describe('testing getConstraintInfo', () => {
|
||||
})
|
||||
describe('array notation', () => {
|
||||
const code = `const part001 = startSketchOn(-XZ)
|
||||
|> startProfileAt([0, 0], %)
|
||||
|> startProfile(at = [0, 0])
|
||||
|> line(end = [3, 4])
|
||||
|> angledLine(angle = 3.14, length = 3.14)
|
||||
|> line(endAbsolute = [6.14, 3.14])
|
||||
@ -845,7 +845,7 @@ describe('testing getConstraintInfo', () => {
|
||||
})
|
||||
describe('constrained', () => {
|
||||
const code = `const part001 = startSketchOn(-XZ)
|
||||
|> startProfileAt([0, 0], %)
|
||||
|> startProfile(at = [0, 0])
|
||||
|> line(end = [3 + 0, 4 + 0])
|
||||
|> angledLine(angle = 3.14 + 0, length = 3.14 + 0 )
|
||||
|> line(endAbsolute = [6.14 + 0, 3.14 + 0])
|
||||
|
@ -5,6 +5,7 @@ import type { Node } from '@rust/kcl-lib/bindings/Node'
|
||||
import {
|
||||
ARG_ANGLE,
|
||||
ARG_ANGLE_END,
|
||||
ARG_AT,
|
||||
ARG_ANGLE_START,
|
||||
ARG_CIRCLE_CENTER,
|
||||
ARG_RADIUS,
|
||||
@ -37,9 +38,7 @@ import {
|
||||
import type { ToolTip } from '@src/lang/langHelpers'
|
||||
import { toolTips } from '@src/lang/langHelpers'
|
||||
import {
|
||||
mutateArrExp,
|
||||
mutateKwArg,
|
||||
mutateObjExpProp,
|
||||
removeKwArgs,
|
||||
splitPathAtPipeExpression,
|
||||
} from '@src/lang/modifyAst'
|
||||
@ -2956,7 +2955,7 @@ export const updateStartProfileAtArgs: SketchLineHelper['updateArgs'] = ({
|
||||
if (input.type !== 'straight-segment') return STRAIGHT_SEGMENT_ERR
|
||||
const { to } = input
|
||||
const _node = { ...node }
|
||||
const nodeMeta = getNodeFromPath<CallExpression>(_node, pathToNode)
|
||||
const nodeMeta = getNodeFromPath<CallExpressionKw>(_node, pathToNode)
|
||||
if (err(nodeMeta)) {
|
||||
console.error(nodeMeta)
|
||||
return {
|
||||
@ -2989,8 +2988,7 @@ export const updateStartProfileAtArgs: SketchLineHelper['updateArgs'] = ({
|
||||
createLiteral(roundOff(to[1])),
|
||||
])
|
||||
|
||||
mutateArrExp(callExpression.arguments?.[0], toArrExp) ||
|
||||
mutateObjExpProp(callExpression.arguments?.[0], toArrExp, 'to')
|
||||
mutateKwArg(ARG_AT, callExpression, toArrExp)
|
||||
return {
|
||||
modifiedAst: _node,
|
||||
pathToNode,
|
||||
|
@ -69,7 +69,7 @@ async function testingSwapSketchFnCall({
|
||||
describe('testing swapping out sketch calls with xLine/xLineTo', () => {
|
||||
const bigExampleArr = [
|
||||
`part001 = startSketchOn(XY)`,
|
||||
` |> startProfileAt([0, 0], %)`,
|
||||
` |> startProfile(at = [0, 0])`,
|
||||
` |> line(endAbsolute = [1, 1], tag = $abc1)`,
|
||||
` |> line(end = [-2.04, -0.7], tag = $abc2)`,
|
||||
` |> angledLine(angle = 157, length = 1.69, tag = $abc3)`,
|
||||
@ -264,7 +264,7 @@ describe('testing swapping out sketch calls with xLine/xLineTo while keeping var
|
||||
`angledLineToXx = -1.86`,
|
||||
`angledLineToYy = -0.76`,
|
||||
`part001 = startSketchOn(XY)`,
|
||||
` |> startProfileAt([0, 0], %)`,
|
||||
` |> startProfile(at = [0, 0])`,
|
||||
// ` |> rx(90, %)`,
|
||||
` |> line(endAbsolute = [1, 1])`,
|
||||
` |> line(end = [lineX, 2.13])`,
|
||||
@ -358,7 +358,7 @@ describe('testing swapping out sketch calls with xLine/xLineTo while keeping var
|
||||
describe('testing getSketchSegmentIndexFromSourceRange', () => {
|
||||
const code = `
|
||||
part001 = startSketchOn(XY)
|
||||
|> startProfileAt([0, 0.04], %) // segment-in-start
|
||||
|> startProfile(at = [0, 0.04]) // segment-in-start
|
||||
|> line(end = [0, 0.4])
|
||||
|> xLine(length = 3.48)
|
||||
|> line(end = [2.14, 1.35]) // normal-segment
|
||||
|
@ -95,7 +95,7 @@ export function isSketchVariablesLinked(
|
||||
to check or it finds a match.
|
||||
that way it can find fn calls that are linked to each other through variables eg:
|
||||
const part001 = startSketchOn(XY)
|
||||
|> startProfileAt([0, 0],%)
|
||||
|> startProfile(at=[0, 0])
|
||||
|> xLine(endAbsolute = 1.69)
|
||||
|> line(end = [myVar, 0.38]) // ❗️ <- cursor in this fn call (the primary)
|
||||
|> line(end = [0.41, baz])
|
||||
|
@ -179,14 +179,14 @@ function makeSelections(
|
||||
describe('testing transformAstForSketchLines for equal length constraint', () => {
|
||||
describe(`should always reorder selections to have the base selection first`, () => {
|
||||
const inputScript = `sketch001 = startSketchOn(XZ)
|
||||
|> startProfileAt([0, 0], %)
|
||||
|> startProfile(at = [0, 0])
|
||||
|> line(end = [5, 5])
|
||||
|> line(end = [-2, 5])
|
||||
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||
|> close()`
|
||||
|
||||
const expectedModifiedScript = `sketch001 = startSketchOn(XZ)
|
||||
|> startProfileAt([0, 0], %)
|
||||
|> startProfile(at = [0, 0])
|
||||
|> line(end = [5, 5], tag = $seg01)
|
||||
|> angledLine(angle = 112, length = segLen(seg01))
|
||||
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||
@ -267,7 +267,7 @@ myVar3 = 6
|
||||
myAng = 40
|
||||
myAng2 = 134
|
||||
part001 = startSketchOn(XY)
|
||||
|> startProfileAt([0, 0], %)
|
||||
|> startProfile(at = [0, 0])
|
||||
|> line(end = [1, 3.82]) // ln-should-get-tag
|
||||
|> line(endAbsolute = [2, 4]) // ln-lineTo-free should become angledLine
|
||||
|> angledLine(angle = 45, endAbsoluteX = 2.5) // ln-angledLineToX-free should become angledLine
|
||||
@ -299,7 +299,7 @@ myVar3 = 6
|
||||
myAng = 40
|
||||
myAng2 = 134
|
||||
part001 = startSketchOn(XY)
|
||||
|> startProfileAt([0, 0], %)
|
||||
|> startProfile(at = [0, 0])
|
||||
|> line(end = [1, 3.82], tag = $seg01) // ln-should-get-tag
|
||||
|> angledLine(angle = 10, length = segLen(seg01)) // ln-lineTo-free should become angledLine
|
||||
|> angledLine(angle = 45, length = segLen(seg01)) // ln-angledLineToX-free should become angledLine
|
||||
@ -376,7 +376,7 @@ describe('testing transformAstForSketchLines for vertical and horizontal constra
|
||||
myVar2 = 12
|
||||
myVar3 = -10
|
||||
part001 = startSketchOn(XY)
|
||||
|> startProfileAt([0, 0], %)
|
||||
|> startProfile(at = [0, 0])
|
||||
|> line(endAbsolute = [1, 1])
|
||||
|> line(end = [-6.28, 1.4]) // select for horizontal constraint 1
|
||||
|> line(end = [-1.07, myVar]) // select for vertical constraint 1
|
||||
@ -404,7 +404,7 @@ part001 = startSketchOn(XY)
|
||||
myVar2 = 12
|
||||
myVar3 = -10
|
||||
part001 = startSketchOn(XY)
|
||||
|> startProfileAt([0, 0], %)
|
||||
|> startProfile(at = [0, 0])
|
||||
|> line(endAbsolute = [1, 1])
|
||||
|> xLine(length = -6.28) // select for horizontal constraint 1
|
||||
|> line(end = [-1.07, myVar]) // select for vertical constraint 1
|
||||
@ -464,7 +464,7 @@ part001 = startSketchOn(XY)
|
||||
myVar2 = 12
|
||||
myVar3 = -10
|
||||
part001 = startSketchOn(XY)
|
||||
|> startProfileAt([0, 0], %)
|
||||
|> startProfile(at = [0, 0])
|
||||
|> line(endAbsolute = [1, 1])
|
||||
|> line(end = [-6.28, 1.4]) // select for horizontal constraint 1
|
||||
|> yLine(length = myVar) // select for vertical constraint 1
|
||||
@ -525,7 +525,7 @@ describe('testing transformAstForSketchLines for vertical and horizontal distanc
|
||||
describe('testing setHorzDistance for line', () => {
|
||||
const inputScript = `myVar = 1
|
||||
part001 = startSketchOn(XY)
|
||||
|> startProfileAt([0, 0], %)
|
||||
|> startProfile(at = [0, 0])
|
||||
|> line(end = [0.31, 1.67]) // base selection
|
||||
|> line(end = [0.45, 1.46])
|
||||
|> line(end = [0.45, 1.46]) // free
|
||||
@ -631,7 +631,7 @@ halfHeight = totalHeight / 2
|
||||
halfArmAngle = armAngle / 2
|
||||
|
||||
part001 = startSketchOn(XY)
|
||||
|> startProfileAt([-0.01, -0.05], %)
|
||||
|> startProfile(at = [-0.01, -0.05])
|
||||
|> line(end = [0.01, 0.94 + 0]) // partial
|
||||
|> xLine(length = 3.03) // partial
|
||||
|> angledLine({
|
||||
|
@ -1702,6 +1702,9 @@ function getTransformMapPathKw(
|
||||
}
|
||||
return false
|
||||
}
|
||||
if (name === 'startProfile') {
|
||||
return false
|
||||
}
|
||||
const tooltip = fnNameToTooltip(allLabels(sketchFnExp), name)
|
||||
if (err(tooltip)) {
|
||||
return false
|
||||
|
@ -9,7 +9,7 @@ beforeAll(async () => {
|
||||
describe('testing angledLineThatIntersects', () => {
|
||||
it('angledLineThatIntersects should intersect with another line', async () => {
|
||||
const code = (offset: string) => `part001 = startSketchOn(XY)
|
||||
|> startProfileAt([0, 0], %)
|
||||
|> startProfile(at = [0, 0])
|
||||
|> line(endAbsolute = [2, 2], tag = $yo)
|
||||
|> line(endAbsolute = [3, 1])
|
||||
|> angledLineThatIntersects(
|
||||
|
@ -78,7 +78,7 @@ export async function submitPromptToEditToQueue({
|
||||
if (artifact?.type === 'cap') {
|
||||
prompts.push({
|
||||
prompt: `The users main selection is the end cap of a general-sweep (that is an extrusion, revolve, sweep or loft).
|
||||
The source range most likely refers to "startProfileAt" simply because this is the start of the profile that was swept.
|
||||
The source range most likely refers to "startProfile" simply because this is the start of the profile that was swept.
|
||||
If you need to operate on this cap, for example for sketching on the face, you can use the special string ${
|
||||
artifact.subType === 'end' ? 'END' : 'START'
|
||||
} i.e. \`startSketchOn(someSweepVariable, face = ${
|
||||
|
@ -19,7 +19,7 @@ describe('library rectangleTool helper functions', () => {
|
||||
test('should update AST and source code', async () => {
|
||||
// Base source code that will be edited in place
|
||||
const sourceCode = `sketch001 = startSketchOn(XZ)
|
||||
profile001 = startProfileAt([120.37, 162.76], %)
|
||||
profile001 = startProfile(at = [120.37, 162.76])
|
||||
|> angledLine(angle = 0, length = 0, tag = $rectangleSegmentA001)
|
||||
|> angledLine(angle = segAng(rectangleSegmentA001) + 90, length = 0, tag = $rectangleSegmentB001)
|
||||
|> angledLine(angle = segAng(rectangleSegmentA001), length = -segLen(rectangleSegmentA001), tag = $rectangleSegmentC001)
|
||||
@ -31,7 +31,7 @@ profile001 = startProfileAt([120.37, 162.76], %)
|
||||
let ast = structuredClone(_ast)
|
||||
|
||||
// Find some nodes and paths to reference
|
||||
const sketchSnippet = `startProfileAt([120.37, 162.76], %)`
|
||||
const sketchSnippet = `startProfile(at = [120.37, 162.76])`
|
||||
const start = sourceCode.indexOf(sketchSnippet)
|
||||
expect(start).toBeGreaterThanOrEqual(0)
|
||||
const sketchRange = topLevelRange(start, start + sketchSnippet.length)
|
||||
@ -69,7 +69,7 @@ profile001 = startProfileAt([120.37, 162.76], %)
|
||||
|
||||
// ast is edited in place from the updateCenterRectangleSketch
|
||||
const expectedSourceCode = `sketch001 = startSketchOn(XZ)
|
||||
profile001 = startProfileAt([80, 120], %)
|
||||
profile001 = startProfile(at = [80, 120])
|
||||
|> angledLine(angle = 0, length = 80, tag = $rectangleSegmentA001)
|
||||
|> angledLine(angle = segAng(rectangleSegmentA001) + 90, length = 120, tag = $rectangleSegmentB001)
|
||||
|> angledLine(angle = segAng(rectangleSegmentA001), length = -segLen(rectangleSegmentA001), tag = $rectangleSegmentC001)
|
||||
|
@ -1,6 +1,7 @@
|
||||
import type { Node } from '@rust/kcl-lib/bindings/Node'
|
||||
import {
|
||||
ARG_ANGLE,
|
||||
ARG_AT,
|
||||
ARG_END_ABSOLUTE,
|
||||
ARG_LENGTH,
|
||||
ARG_TAG,
|
||||
@ -21,7 +22,6 @@ import { mutateKwArgOnly } from '@src/lang/modifyAst'
|
||||
import {
|
||||
findKwArg,
|
||||
isArrayExpression,
|
||||
isCallExpression,
|
||||
isCallExpressionKw,
|
||||
} from '@src/lang/util'
|
||||
import type { CallExpressionKw, Expr, PipeExpression } from '@src/lang/wasm'
|
||||
@ -43,10 +43,10 @@ function angledLine(
|
||||
}
|
||||
|
||||
/**
|
||||
* It does not create the startSketchOn and it does not create the startProfileAt.
|
||||
* It does not create the startSketchOn and it does not create the startProfile.
|
||||
* Returns AST expressions for this KCL code:
|
||||
* const yo = startSketchOn(XY)
|
||||
* |> startProfileAt([0, 0], %)
|
||||
* |> startProfile(at = [0, 0])
|
||||
* |> angledLine(angle = 0, length = 0, tag = $a)
|
||||
* |> angledLine(angle = segAng(a) - 90, length = 0, tag = $b)
|
||||
* |> angledLine(angle = segAng(a), length = -segLen(a), tag = $c)
|
||||
@ -149,17 +149,20 @@ export function updateCenterRectangleSketch(
|
||||
|
||||
{
|
||||
let callExpression = pipeExpression.body[0]
|
||||
if (!isCallExpression(callExpression)) {
|
||||
if (!isCallExpressionKw(callExpression)) {
|
||||
return new Error(`Expected call expression, got ${callExpression.type}`)
|
||||
}
|
||||
const arrayExpression = callExpression.arguments[0]
|
||||
const arrayExpression = findKwArg(ARG_AT, callExpression)
|
||||
if (!isArrayExpression(arrayExpression)) {
|
||||
return new Error(`Expected array expression, got ${arrayExpression.type}`)
|
||||
return new Error(
|
||||
`Expected array expression, got ${arrayExpression?.type}`
|
||||
)
|
||||
}
|
||||
callExpression.arguments[0] = createArrayExpression([
|
||||
const at = createArrayExpression([
|
||||
createLiteral(roundOff(startX)),
|
||||
createLiteral(roundOff(startY)),
|
||||
])
|
||||
mutateKwArgOnly(ARG_AT, callExpression, at)
|
||||
}
|
||||
|
||||
const twoX = deltaX * 2
|
||||
|
@ -19,7 +19,7 @@ beforeAll(async () => {
|
||||
|
||||
describe('testing source range to artifact conversion', () => {
|
||||
const MY_CODE = `sketch001 = startSketchOn(XZ)
|
||||
profile001 = startProfileAt([105.55, 105.55], sketch001)
|
||||
profile001 = startProfile(sketch001,at=[105.55, 105.55])
|
||||
|> xLine(332.55, %, $seg01)
|
||||
|> yLine(-310.12, %, $seg02)
|
||||
|> xLine(-373.65, %)
|
||||
@ -28,7 +28,7 @@ profile001 = startProfileAt([105.55, 105.55], sketch001)
|
||||
extrude001 = extrude(profile001, length = 500)
|
||||
|
||||
sketch002 = startSketchOn(extrude001, seg01)
|
||||
profile002 = startProfileAt([-321.34, 361.76], sketch002)
|
||||
profile002 = startProfile(sketch002,at=[-321.34, 361.76])
|
||||
|> line(end = [109.03, -61.79])
|
||||
|> line(end = [-124.48, -132.65])
|
||||
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||
@ -40,7 +40,7 @@ profile006 = circle(sketch005,
|
||||
radius = 25.89
|
||||
)
|
||||
sketch004 = startSketchOn(extrude001, seg02)
|
||||
profile005 = startProfileAt([36.1, 174.49], sketch004)
|
||||
profile005 = startProfile(sketch004,at=[36.1, 174.49])
|
||||
|> angledLine(angle = 0, length = 22.33, tag = $rectangleSegmentA003)
|
||||
|> angledLine(
|
||||
angle = segAng(rectangleSegmentA003) - 90,
|
||||
@ -53,7 +53,7 @@ profile005 = startProfileAt([36.1, 174.49], sketch004)
|
||||
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||
|> close()
|
||||
sketch003 = startSketchOn(extrude001, seg02)
|
||||
profile003 = startProfileAt([-115.59, 439.4], sketch003)
|
||||
profile003 = startProfile(sketch003,at=[-115.59, 439.4])
|
||||
|> angledLine(angle = 0, length = 130.08, tag = $rectangleSegmentA002)
|
||||
|> angledLine(
|
||||
angle = segAng(rectangleSegmentA002) - 90,
|
||||
@ -1170,7 +1170,7 @@ profile004 = circle(sketch003,
|
||||
[
|
||||
'path selection for a sketch on face',
|
||||
{
|
||||
snippet: 'profile002 = startProfileAt([-321.34, 361.76], sketch002)',
|
||||
snippet: 'profile002 = startProfile(sketch002,at=[-321.34, 361.76])',
|
||||
artifactDetails: {
|
||||
type: 'solid2d',
|
||||
range: [398, 398, 0],
|
||||
|
@ -4693,7 +4693,7 @@ export function isEditingExistingSketch({
|
||||
sketchDetails: SketchDetails | null
|
||||
}): boolean {
|
||||
// should check that the variable declaration is a pipeExpression
|
||||
// and that the pipeExpression contains a "startProfileAt" callExpression
|
||||
// and that the pipeExpression contains a "startProfile" callExpression
|
||||
if (!sketchDetails?.sketchEntryNodePath) return false
|
||||
const variableDeclaration = getNodeFromPath<VariableDeclarator>(
|
||||
kclManager.ast,
|
||||
@ -4709,7 +4709,7 @@ export function isEditingExistingSketch({
|
||||
if (
|
||||
(maybePipeExpression.type === 'CallExpression' ||
|
||||
maybePipeExpression.type === 'CallExpressionKw') &&
|
||||
(maybePipeExpression.callee.name.name === 'startProfileAt' ||
|
||||
(maybePipeExpression.callee.name.name === 'startProfile' ||
|
||||
maybePipeExpression.callee.name.name === 'circle' ||
|
||||
maybePipeExpression.callee.name.name === 'circleThreePoint')
|
||||
)
|
||||
@ -4717,8 +4717,8 @@ export function isEditingExistingSketch({
|
||||
if (maybePipeExpression.type !== 'PipeExpression') return false
|
||||
const hasStartProfileAt = maybePipeExpression.body.some(
|
||||
(item) =>
|
||||
item.type === 'CallExpression' &&
|
||||
item.callee.name.name === 'startProfileAt'
|
||||
item.type === 'CallExpressionKw' &&
|
||||
item.callee.name.name === 'startProfile'
|
||||
)
|
||||
const hasCircle =
|
||||
maybePipeExpression.body.some(
|
||||
|
@ -3,7 +3,7 @@ import { normaliseKclNumbers } from '@e2e/playwright/test-utils'
|
||||
test('normaliseKclNumbers', () => {
|
||||
expect(
|
||||
normaliseKclNumbers(`sketch001 = startSketchOn(XY)
|
||||
|> startProfileAt([-10, 10], %)
|
||||
|> startProfile(at = [-10, 10])
|
||||
|> line(end = [20, 0])
|
||||
|> line(end = [0, -20])
|
||||
|> line(end = [-20, 0])
|
||||
@ -11,7 +11,7 @@ test('normaliseKclNumbers', () => {
|
||||
|> close()
|
||||
const extrude001 = extrude(sketch001, length = -15)`)
|
||||
).toBe(`sketch001 = startSketchOn(XY)
|
||||
|> startProfileAt([-12.34, 12.34], %)
|
||||
|> startProfile(at = [-12.34, 12.34])
|
||||
|> line(end = [12.34, 0])
|
||||
|> line(end = [0, -12.34])
|
||||
|> line(end = [-12.34, 0])
|
||||
@ -21,7 +21,7 @@ const extrude001 = extrude(sketch001, length = -12.34)`)
|
||||
expect(
|
||||
normaliseKclNumbers(
|
||||
`sketch001 = startSketchOn(XY)
|
||||
|> startProfileAt([-10, 10], %)
|
||||
|> startProfile(at = [-10, 10])
|
||||
|> line(end = [20, 0])
|
||||
|> line(end = [0, -20])
|
||||
|> line(end = [-20, 0])
|
||||
@ -31,7 +31,7 @@ const extrude001 = extrude(sketch001, length = -15)`,
|
||||
false
|
||||
)
|
||||
).toBe(`sketch001 = startSketchOn(XY)
|
||||
|> startProfileAt([-12.34, 12.34], %)
|
||||
|> startProfile(at = [-12.34, 12.34])
|
||||
|> line(end = [12.34, 12.34])
|
||||
|> line(end = [12.34, -12.34])
|
||||
|> line(end = [-12.34, 12.34])
|
||||
|
Reference in New Issue
Block a user