Compare commits

..

52 Commits

Author SHA1 Message Date
d70ebca165 Merge remote-tracking branch 'origin' into kurt-multi-profile-again 2025-02-06 17:40:24 +11:00
d8a9abba69 overlay fix 2025-02-06 17:16:51 +11:00
0fd18c14ef more rust fixes 2025-02-05 14:29:39 +11:00
36d4830c34 Merge remote-tracking branch 'origin' into kurt-multi-profile-again 2025-02-05 13:56:55 +11:00
4ce6054e64 Merge remote-tracking branch 'origin' into kurt-multi-profile-again 2025-02-05 13:56:44 +11:00
ced49f8ddc fix rust 2025-02-05 12:50:58 +11:00
e063622139 more 2025-02-05 12:42:23 +11:00
42178fa649 more 2025-02-05 12:34:19 +11:00
4bb23bc917 bad attempts at fixing rust 2025-02-05 12:27:58 +11:00
72272d5d98 Merge remote-tracking branch 'origin' into kurt-multi-profile-again 2025-02-05 11:49:09 +11:00
5ef0a1e75f Merge remote-tracking branch 'origin' into kurt-multi-profile-again 2025-02-05 11:48:43 +11:00
d8dc49b08a some things needed for multi-profile tests 2025-02-04 15:55:57 +11:00
87eabef450 fix sketch on face after updates to rust side artifact graph 2025-02-04 15:23:35 +11:00
40e4f2236f Merge remote-tracking branch 'origin' into kurt-multi-profile-again 2025-02-04 15:18:30 +11:00
663076f790 add face codef ref for walls and caps 2025-02-04 15:17:50 +11:00
f2c76b0509 Merge remote-tracking branch 'origin' into kurt-multi-profile-again 2025-02-04 06:46:35 +11:00
481bef859a cargo fmt 2025-02-03 22:12:05 +11:00
1a67d344ee Merge remote-tracking branch 'origin' into kurt-multi-profile-again 2025-02-03 22:08:13 +11:00
774e3efcb7 fix types 2025-02-03 22:06:24 +11:00
4ec44690bf fmt 2025-02-03 18:37:16 +11:00
d2f0865f95 Merge remote-tracking branch 'origin' into kurt-multi-profile-again 2025-02-03 18:36:38 +11:00
84d17454e9 get overlays working for circle three point 2025-02-03 17:53:08 +11:00
5a5138a703 most of the fix for 3 point circle 2025-01-31 21:26:19 +11:00
33468c4c96 rust changes to make three point confrom to same as others since we're not ready with name params yet 2025-01-31 13:31:04 +11:00
b3467bbe5a wip 2025-01-27 17:36:29 -05:00
90086488b5 WIP 2025-01-24 15:58:54 -05:00
32e8975799 wip 2025-01-17 15:37:28 -05:00
648616c667 Merge branch 'main' into lf94/kurt-bring-back-multi-profile 2025-01-16 11:13:59 -05:00
482487cf57 Merge branch 'main' into lf94/kurt-bring-back-multi-profile 2025-01-15 14:07:47 -05:00
5fe3023be9 Fix partial execution 2025-01-10 15:39:25 -05:00
30397ba7ab Fix up all the tests 2025-01-09 15:59:11 -05:00
3344208c63 Trigger CI 2025-01-08 21:28:36 -05:00
fcf3272ad2 A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubuntu-8-cores) 2025-01-09 02:17:14 +00:00
d3e4b123d0 Merge branch 'main' into kurt-bring-back-multi-profile 2025-01-08 21:08:47 -05:00
2bb548c000 Trigger CI 2024-12-20 11:11:39 -05:00
b09c240e36 A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubuntu-8-cores) 2024-12-20 12:32:43 +00:00
6c9d14af93 partial fixes 2024-12-20 23:24:15 +11:00
0642e49189 A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubuntu-8-cores) 2024-12-20 23:21:32 +11:00
6add1d73ad chore: disabled file watcher which prevents faster file write (#4835) 2024-12-20 23:21:21 +11:00
68c89746c7 trigger CI 2024-12-20 22:14:49 +11:00
9f323c207c A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-16-cores) 2024-12-20 11:06:49 +00:00
7197b6c85d A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubuntu-8-cores) 2024-12-20 10:54:43 +00:00
913f2641c3 A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-macos-8-cores) 2024-12-20 10:53:02 +00:00
e9086c54ba lint 2024-12-20 21:46:48 +11:00
9f93346dc6 lint 2024-12-20 21:45:04 +11:00
1b9f5f20f5 Merge remote-tracking branch 'origin' into kurt-bring-back-multi-profile 2024-12-20 21:43:41 +11:00
3865637c61 Add Rust side artifacts for startSketchOn face or plane (#4834)
* Add Rust side artifacts for startSketchOn face or plane

* move ast digging

---------

Co-authored-by: Kurt Hutten Irev-Dev <k.hutten@protonmail.ch>
2024-12-19 11:03:21 +11:00
2c40e8a97c trigger CI 2024-12-18 10:12:18 +11:00
c696f0837a A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest-8-cores) 2024-12-17 22:58:41 +00:00
30edf2ad56 Merge remote-tracking branch 'origin' into kurt-bring-back-multi-profile 2024-12-18 09:53:34 +11:00
e60cabb193 fix poor 1000ms wait UX 2024-12-18 08:44:35 +11:00
1e9cf6f256 Revert "Revert multi-profile (#4812)"
This reverts commit efe8089b08.
2024-12-18 07:08:41 +11:00
268 changed files with 11194 additions and 27206 deletions

View File

@ -1,4 +1,5 @@
NODE_ENV=production NODE_ENV=production
DEV=false
VITE_KC_API_WS_MODELING_URL=wss://api.zoo.dev/ws/modeling/commands VITE_KC_API_WS_MODELING_URL=wss://api.zoo.dev/ws/modeling/commands
VITE_KC_API_BASE_URL=https://api.zoo.dev VITE_KC_API_BASE_URL=https://api.zoo.dev
VITE_KC_SITE_BASE_URL=https://zoo.dev VITE_KC_SITE_BASE_URL=https://zoo.dev

View File

@ -3,6 +3,7 @@ on:
push: push:
branches: [ main ] branches: [ main ]
pull_request: pull_request:
branches: [ main ]
concurrency: concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -9,7 +9,7 @@ Repeat a 2-dimensional sketch along some dimension, with a dynamic amount
of distance between each repetition, some specified number of times. of distance between each repetition, some specified number of times.
```js ```js
patternLinear2d(data: LinearPattern2dData, sketch_set: SketchSet, use_original?: bool) -> [Sketch] patternLinear2d(data: LinearPattern2dData, sketch_set: SketchSet) -> [Sketch]
``` ```
@ -19,7 +19,6 @@ patternLinear2d(data: LinearPattern2dData, sketch_set: SketchSet, use_original?:
|----------|------|-------------|----------| |----------|------|-------------|----------|
| `data` | [`LinearPattern2dData`](/docs/kcl/types/LinearPattern2dData) | Data for a linear pattern on a 2D sketch. | Yes | | `data` | [`LinearPattern2dData`](/docs/kcl/types/LinearPattern2dData) | Data for a linear pattern on a 2D sketch. | Yes |
| `sketch_set` | [`SketchSet`](/docs/kcl/types/SketchSet) | A sketch or a group of sketches. | Yes | | `sketch_set` | [`SketchSet`](/docs/kcl/types/SketchSet) | A sketch or a group of sketches. | Yes |
| `use_original` | `bool` | | No |
### Returns ### Returns

View File

@ -9,7 +9,7 @@ Repeat a 3-dimensional solid along a linear path, with a dynamic amount
of distance between each repetition, some specified number of times. of distance between each repetition, some specified number of times.
```js ```js
patternLinear3d(data: LinearPattern3dData, solid_set: SolidSet, use_original?: bool) -> [Solid] patternLinear3d(data: LinearPattern3dData, solid_set: SolidSet) -> [Solid]
``` ```
@ -19,7 +19,6 @@ patternLinear3d(data: LinearPattern3dData, solid_set: SolidSet, use_original?: b
|----------|------|-------------|----------| |----------|------|-------------|----------|
| `data` | [`LinearPattern3dData`](/docs/kcl/types/LinearPattern3dData) | Data for a linear pattern on a 3D model. | Yes | | `data` | [`LinearPattern3dData`](/docs/kcl/types/LinearPattern3dData) | Data for a linear pattern on a 3D model. | Yes |
| `solid_set` | [`SolidSet`](/docs/kcl/types/SolidSet) | A solid or a group of solids. | Yes | | `solid_set` | [`SolidSet`](/docs/kcl/types/SolidSet) | A solid or a group of solids. | Yes |
| `use_original` | `bool` | | No |
### Returns ### Returns

View File

@ -35,7 +35,7 @@ The transform function returns a transform object. All properties of the object
- `rotation.origin` (either "local" i.e. rotate around its own center, "global" i.e. rotate around the scene's center, or a 3D point, defaults to "local") - `rotation.origin` (either "local" i.e. rotate around its own center, "global" i.e. rotate around the scene's center, or a 3D point, defaults to "local")
```js ```js
patternTransform(total_instances: integer, transform_function: FunctionParam, solid_set: SolidSet, use_original?: bool) -> [Solid] patternTransform(total_instances: integer, transform_function: FunctionParam, solid_set: SolidSet) -> [Solid]
``` ```
@ -46,7 +46,6 @@ patternTransform(total_instances: integer, transform_function: FunctionParam, so
| `total_instances` | `integer` | | Yes | | `total_instances` | `integer` | | Yes |
| `transform_function` | `FunctionParam` | | Yes | | `transform_function` | `FunctionParam` | | Yes |
| `solid_set` | [`SolidSet`](/docs/kcl/types/SolidSet) | A solid or a group of solids. | Yes | | `solid_set` | [`SolidSet`](/docs/kcl/types/SolidSet) | A solid or a group of solids. | Yes |
| `use_original` | `bool` | | No |
### Returns ### Returns

View File

@ -9,7 +9,7 @@ Just like patternTransform, but works on 2D sketches not 3D solids.
```js ```js
patternTransform2d(total_instances: integer, transform_function: FunctionParam, solid_set: SketchSet, use_original?: bool) -> [Sketch] patternTransform2d(total_instances: integer, transform_function: FunctionParam, solid_set: SketchSet) -> [Sketch]
``` ```
@ -20,7 +20,6 @@ patternTransform2d(total_instances: integer, transform_function: FunctionParam,
| `total_instances` | `integer` | | Yes | | `total_instances` | `integer` | | Yes |
| `transform_function` | `FunctionParam` | | Yes | | `transform_function` | `FunctionParam` | | Yes |
| `solid_set` | [`SketchSet`](/docs/kcl/types/SketchSet) | A sketch or a group of sketches. | Yes | | `solid_set` | [`SketchSet`](/docs/kcl/types/SketchSet) | A sketch or a group of sketches. | Yes |
| `use_original` | `bool` | | No |
### Returns ### Returns

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -20,6 +20,5 @@ Data for a circular pattern on a 2D sketch.
| `center` |`[number, number]`| The center about which to make the pattern. This is a 2D vector. | No | | `center` |`[number, number]`| The center about which to make the pattern. This is a 2D vector. | No |
| `arcDegrees` |`number`| The arc angle (in degrees) to place the repetitions. Must be greater than 0. | No | | `arcDegrees` |`number`| The arc angle (in degrees) to place the repetitions. Must be greater than 0. | No |
| `rotateDuplicates` |`boolean`| Whether or not to rotate the duplicates as they are copied. | No | | `rotateDuplicates` |`boolean`| Whether or not to rotate the duplicates as they are copied. | No |
| `useOriginal` |`boolean`| If the target being patterned is itself a pattern, then, should you use the original solid, or the pattern? | No |

View File

@ -21,6 +21,5 @@ Data for a circular pattern on a 3D model.
| `center` |`[number, number, number]`| The center about which to make the pattern. This is a 3D vector. | No | | `center` |`[number, number, number]`| The center about which to make the pattern. This is a 3D vector. | No |
| `arcDegrees` |`number`| The arc angle (in degrees) to place the repetitions. Must be greater than 0. | No | | `arcDegrees` |`number`| The arc angle (in degrees) to place the repetitions. Must be greater than 0. | No |
| `rotateDuplicates` |`boolean`| Whether or not to rotate the duplicates as they are copied. | No | | `rotateDuplicates` |`boolean`| Whether or not to rotate the duplicates as they are copied. | No |
| `useOriginal` |`boolean`| If the target being patterned is itself a pattern, then, should you use the original solid, or the pattern? | No |

View File

@ -22,7 +22,6 @@ A sketch is a collection of paths.
| `start` |[`BasePath`](/docs/kcl/types/BasePath)| The starting path. | No | | `start` |[`BasePath`](/docs/kcl/types/BasePath)| The starting path. | No |
| `tags` |`object`| Tag identifiers that have been declared in this sketch. | No | | `tags` |`object`| Tag identifiers that have been declared in this sketch. | No |
| `artifactId` |[`ArtifactId`](/docs/kcl/types/ArtifactId)| The original id of the sketch. This stays the same even if the sketch is is sketched on face etc. | No | | `artifactId` |[`ArtifactId`](/docs/kcl/types/ArtifactId)| The original id of the sketch. This stays the same even if the sketch is is sketched on face etc. | No |
| `originalId` |`string`| | No |
| `units` |[`UnitLen`](/docs/kcl/types/UnitLen)| A sketch is a collection of paths. | No | | `units` |[`UnitLen`](/docs/kcl/types/UnitLen)| A sketch is a collection of paths. | No |
| `__meta` |`[` [`Metadata`](/docs/kcl/types/Metadata) `]`| Metadata. | No | | `__meta` |`[` [`Metadata`](/docs/kcl/types/Metadata) `]`| Metadata. | No |

View File

@ -31,7 +31,6 @@ A sketch is a collection of paths.
| `start` |[`BasePath`](/docs/kcl/types/BasePath)| The starting path. | No | | `start` |[`BasePath`](/docs/kcl/types/BasePath)| The starting path. | No |
| `tags` |`object`| Tag identifiers that have been declared in this sketch. | No | | `tags` |`object`| Tag identifiers that have been declared in this sketch. | No |
| `artifactId` |[`ArtifactId`](/docs/kcl/types/ArtifactId)| The original id of the sketch. This stays the same even if the sketch is is sketched on face etc. | No | | `artifactId` |[`ArtifactId`](/docs/kcl/types/ArtifactId)| The original id of the sketch. This stays the same even if the sketch is is sketched on face etc. | No |
| `originalId` |`string`| | No |
| `units` |[`UnitLen`](/docs/kcl/types/UnitLen)| A sketch or a group of sketches. | No | | `units` |[`UnitLen`](/docs/kcl/types/UnitLen)| A sketch or a group of sketches. | No |
| `__meta` |`[` [`Metadata`](/docs/kcl/types/Metadata) `]`| Metadata. | No | | `__meta` |`[` [`Metadata`](/docs/kcl/types/Metadata) `]`| Metadata. | No |

View File

@ -54,23 +54,26 @@ async function doBasicSketch(
const startXPx = 600 const startXPx = 600
await page.mouse.click(startXPx + PUR * 10, 500 - PUR * 10) await page.mouse.click(startXPx + PUR * 10, 500 - PUR * 10)
if (openPanes.includes('code')) { if (openPanes.includes('code')) {
await expect(u.codeLocator).toHaveText(`sketch001 = startSketchOn('XZ') await expect(u.codeLocator).toContainText(
|> startProfileAt(${commonPoints.startAt}, %)`) `sketch001 = startSketchOn('XZ')profile001 = startProfileAt(${commonPoints.startAt}, sketch001)`
)
} }
await page.waitForTimeout(500) await page.waitForTimeout(500)
await page.mouse.click(startXPx + PUR * 20, 500 - PUR * 10) await page.mouse.click(startXPx + PUR * 20, 500 - PUR * 10)
await page.waitForTimeout(500) await page.waitForTimeout(500)
if (openPanes.includes('code')) { if (openPanes.includes('code')) {
await expect(u.codeLocator).toHaveText(`sketch001 = startSketchOn('XZ') await expect(u.codeLocator)
|> startProfileAt(${commonPoints.startAt}, %) .toHaveText(`sketch001 = startSketchOn('XZ')profile001 = startProfileAt(${commonPoints.startAt}, sketch001)
|> xLine(${commonPoints.num1}, %)`) |> xLine(${commonPoints.num1}, %)`)
} }
await page.waitForTimeout(500) await page.waitForTimeout(500)
await page.mouse.click(startXPx + PUR * 20, 500 - PUR * 20) await page.mouse.click(startXPx + PUR * 20, 500 - PUR * 20)
if (openPanes.includes('code')) { if (openPanes.includes('code')) {
await expect(u.codeLocator).toHaveText(`sketch001 = startSketchOn('XZ') await expect(u.codeLocator)
|> startProfileAt(${commonPoints.startAt}, %) .toHaveText(`sketch001 = startSketchOn('XZ')profile001 = startProfileAt(${
commonPoints.startAt
}, sketch001)
|> xLine(${commonPoints.num1}, %) |> xLine(${commonPoints.num1}, %)
|> yLine(${commonPoints.num1 + 0.01}, %)`) |> yLine(${commonPoints.num1 + 0.01}, %)`)
} else { } else {
@ -79,8 +82,10 @@ async function doBasicSketch(
await page.waitForTimeout(200) await page.waitForTimeout(200)
await page.mouse.click(startXPx, 500 - PUR * 20) await page.mouse.click(startXPx, 500 - PUR * 20)
if (openPanes.includes('code')) { if (openPanes.includes('code')) {
await expect(u.codeLocator).toHaveText(`sketch001 = startSketchOn('XZ') await expect(u.codeLocator)
|> startProfileAt(${commonPoints.startAt}, %) .toHaveText(`sketch001 = startSketchOn('XZ')profile001 = startProfileAt(${
commonPoints.startAt
}, sketch001)
|> xLine(${commonPoints.num1}, %) |> xLine(${commonPoints.num1}, %)
|> yLine(${commonPoints.num1 + 0.01}, %) |> yLine(${commonPoints.num1 + 0.01}, %)
|> xLine(${commonPoints.num2 * -1}, %)`) |> xLine(${commonPoints.num2 * -1}, %)`)
@ -137,8 +142,10 @@ async function doBasicSketch(
// Open the code pane. // Open the code pane.
await u.openKclCodePanel() await u.openKclCodePanel()
await expect(u.codeLocator).toHaveText(`sketch001 = startSketchOn('XZ') await expect(u.codeLocator)
|> startProfileAt(${commonPoints.startAt}, %) .toHaveText(`sketch001 = startSketchOn('XZ')profile001 = startProfileAt(${
commonPoints.startAt
}, sketch001)
|> xLine(${commonPoints.num1}, %, $seg01) |> xLine(${commonPoints.num1}, %, $seg01)
|> yLine(${commonPoints.num1 + 0.01}, %) |> yLine(${commonPoints.num1 + 0.01}, %)
|> xLine(-segLen(seg01), %)`) |> xLine(-segLen(seg01), %)`)

View File

@ -19,8 +19,6 @@ test.describe(
await page.setBodyDimensions({ width: 1200, height: 500 }) await page.setBodyDimensions({ width: 1200, height: 500 })
await homePage.goToModelingScene() await homePage.goToModelingScene()
// FIXME: Cannot use scene.waitForExecutionDone() since there is no KCL code
await page.waitForTimeout(10000)
await u.openDebugPanel() await u.openDebugPanel()
const coord = const coord =
@ -43,8 +41,7 @@ test.describe(
}, },
} }
const code = `sketch001 = startSketchOn('${plane}') const code = `sketch001 = startSketchOn('${plane}')profile001 = startProfileAt([0.9, -1.22], sketch001)`
|> startProfileAt([0.9, -1.22], %)`
await u.openDebugPanel() await u.openDebugPanel()

View File

@ -10,7 +10,6 @@ test.describe('Code pane and errors', { tag: ['@skipWin'] }, () => {
test('Typing KCL errors induces a badge on the code pane button', async ({ test('Typing KCL errors induces a badge on the code pane button', async ({
page, page,
homePage, homePage,
scene,
}) => { }) => {
const u = await getUtils(page) const u = await getUtils(page)
@ -31,7 +30,11 @@ test.describe('Code pane and errors', { tag: ['@skipWin'] }, () => {
await page.setBodyDimensions({ width: 1200, height: 500 }) await page.setBodyDimensions({ width: 1200, height: 500 })
await homePage.goToModelingScene() await homePage.goToModelingScene()
await scene.waitForExecutionDone()
// wait for execution done
await u.openDebugPanel()
await u.expectCmdLog('[data-message-type="execution-done"]')
await u.closeDebugPanel()
// Ensure no badge is present // Ensure no badge is present
const codePaneButtonHolder = page.locator('#code-button-holder') const codePaneButtonHolder = page.locator('#code-button-holder')
@ -172,9 +175,7 @@ test.describe('Code pane and errors', { tag: ['@skipWin'] }, () => {
await page.setBodyDimensions({ width: 1200, height: 500 }) await page.setBodyDimensions({ width: 1200, height: 500 })
await homePage.goToModelingScene() await homePage.goToModelingScene()
// FIXME: await scene.waitForExecutionDone() does not work. It still fails. await page.waitForTimeout(1000)
// I needed to increase this timeout to get this to pass.
await page.waitForTimeout(10000)
// Ensure badge is present // Ensure badge is present
const codePaneButtonHolder = page.locator('#code-button-holder') const codePaneButtonHolder = page.locator('#code-button-holder')
@ -186,7 +187,7 @@ test.describe('Code pane and errors', { tag: ['@skipWin'] }, () => {
// click in the editor to focus it // click in the editor to focus it
await page.locator('.cm-content').click() await page.locator('.cm-content').click()
await page.waitForTimeout(2000) await page.waitForTimeout(500)
// go to the start of the editor and enter more text which will trigger // go to the start of the editor and enter more text which will trigger
// a lint error. // a lint error.
@ -203,9 +204,8 @@ test.describe('Code pane and errors', { tag: ['@skipWin'] }, () => {
await page.keyboard.press('ArrowUp') await page.keyboard.press('ArrowUp')
await page.keyboard.press('Home') await page.keyboard.press('Home')
await page.keyboard.type('foo_bar = 1') await page.keyboard.type('foo_bar = 1')
await page.waitForTimeout(2000) await page.waitForTimeout(500)
await page.keyboard.press('Enter') await page.keyboard.press('Enter')
await page.waitForTimeout(2000)
// ensure we have a lint error // ensure we have a lint error
await expect(page.locator('.cm-lint-marker-info').first()).toBeVisible() await expect(page.locator('.cm-lint-marker-info').first()).toBeVisible()
@ -301,7 +301,7 @@ test(
} }
) )
test( test.skip(
'external change of file contents are reflected in editor', 'external change of file contents are reflected in editor',
{ tag: '@electron' }, { tag: '@electron' },
async ({ context, page }, testInfo) => { async ({ context, page }, testInfo) => {

View File

@ -174,9 +174,6 @@ test.describe('Command bar tests', { tag: ['@skipWin'] }, () => {
await page.setBodyDimensions({ width: 1200, height: 500 }) await page.setBodyDimensions({ width: 1200, height: 500 })
await homePage.goToModelingScene() await homePage.goToModelingScene()
// FIXME: No KCL code, unable to wait for engine execution
await page.waitForTimeout(10000)
await expect( await expect(
page.getByRole('button', { name: 'Start Sketch' }) page.getByRole('button', { name: 'Start Sketch' })
).not.toBeDisabled() ).not.toBeDisabled()

View File

@ -9,8 +9,8 @@ import fsp from 'fs/promises'
test( test(
'export works on the first try', 'export works on the first try',
{ tag: ['@electron', '@skipLocalEngine'] }, { tag: '@electron' },
async ({ page, context, scene }, testInfo) => { async ({ page, context }, testInfo) => {
await context.folderSetupFn(async (dir) => { await context.folderSetupFn(async (dir) => {
const bracketDir = path.join(dir, 'bracket') const bracketDir = path.join(dir, 'bracket')
await Promise.all([fsp.mkdir(bracketDir, { recursive: true })]) await Promise.all([fsp.mkdir(bracketDir, { recursive: true })])
@ -118,9 +118,8 @@ test(
// Close the file pane // Close the file pane
await u.closeFilePanel() await u.closeFilePanel()
// FIXME: await scene.waitForExecutionDone() does not work. The modeling indicator stays in -receive-reliable and not execution done // wait for it to finish executing (todo: make this more robust)
await page.waitForTimeout(10000) await page.waitForTimeout(1000)
// expect zero errors in guter // expect zero errors in guter
await expect(page.locator('.cm-lint-marker-error')).not.toBeVisible() await expect(page.locator('.cm-lint-marker-error')).not.toBeVisible()

View File

@ -490,11 +490,6 @@ test.describe('Editor tests', { tag: ['@skipWin'] }, () => {
await page.keyboard.press('ArrowLeft') await page.keyboard.press('ArrowLeft')
await page.keyboard.press('ArrowRight') await page.keyboard.press('ArrowRight')
// FIXME: lsp errors do not propagate to the frontend until engine is connected and code is executed
// This timeout is to wait for engine connection. LSP and code execution errors should be handled differently
// LSP can emit errors as fast as it waits and show them in the editor
await page.waitForTimeout(10000)
// error in guter // error in guter
await expect(page.locator('.cm-lint-marker-info').first()).toBeVisible() await expect(page.locator('.cm-lint-marker-info').first()).toBeVisible()

View File

@ -112,9 +112,6 @@ export class CmdBarFixture {
* and assumes we are past the `pickCommand` step. * and assumes we are past the `pickCommand` step.
*/ */
progressCmdBar = async (shouldFuzzProgressMethod = true) => { progressCmdBar = async (shouldFuzzProgressMethod = true) => {
// FIXME: Progressing the command bar is a race condition. We have an async useEffect that reports the final state via useCalculateKclExpression. If this does not run quickly enough, it will not "fail" the continue because you can press continue if the state is not ready. E2E tests do not know this.
// Wait 1250ms to assume the await executeAst of the KCL input field is finished
await this.page.waitForTimeout(1250)
if (shouldFuzzProgressMethod || Math.random() > 0.5) { if (shouldFuzzProgressMethod || Math.random() > 0.5) {
const arrowButton = this.page.getByRole('button', { const arrowButton = this.page.getByRole('button', {
name: 'arrow right Continue', name: 'arrow right Continue',
@ -131,23 +128,6 @@ export class CmdBarFixture {
} }
} }
// Added data-testid to the command bar buttons
// command-bar-continue are the buttons to go to the next step
// does not include the submit which is the final button press
// aka the right arrow button
continue = async () => {
const continueButton = this.page.getByTestId('command-bar-continue')
await continueButton.click()
}
// Added data-testid to the command bar buttons
// command-bar-submit is the button for the final step to submit
// the command bar flow aka the checkmark button.
submit = async () => {
const submitButton = this.page.getByTestId('command-bar-submit')
await submitButton.click()
}
openCmdBar = async (selectCmd?: 'promptToEdit') => { openCmdBar = async (selectCmd?: 'promptToEdit') => {
// TODO why does this button not work in electron tests? // TODO why does this button not work in electron tests?
// await this.cmdBarOpenBtn.click() // await this.cmdBarOpenBtn.click()

View File

@ -9,13 +9,15 @@ import {
sendCustomCmd, sendCustomCmd,
} from '../test-utils' } from '../test-utils'
type mouseParams = { type MouseParams = {
pixelDiff?: number pixelDiff?: number
shouldDbClick?: boolean
delay?: number
} }
type mouseDragToParams = mouseParams & { type MouseDragToParams = MouseParams & {
fromPoint: { x: number; y: number } fromPoint: { x: number; y: number }
} }
type mouseDragFromParams = mouseParams & { type MouseDragFromParams = MouseParams & {
toPoint: { x: number; y: number } toPoint: { x: number; y: number }
} }
@ -26,12 +28,12 @@ type SceneSerialised = {
} }
} }
type ClickHandler = (clickParams?: mouseParams) => Promise<void | boolean> type ClickHandler = (clickParams?: MouseParams) => Promise<void | boolean>
type MoveHandler = (moveParams?: mouseParams) => Promise<void | boolean> type MoveHandler = (moveParams?: MouseParams) => Promise<void | boolean>
type DblClickHandler = (clickParams?: mouseParams) => Promise<void | boolean> type DblClickHandler = (clickParams?: MouseParams) => Promise<void | boolean>
type DragToHandler = (dragParams: mouseDragToParams) => Promise<void | boolean> type DragToHandler = (dragParams: MouseDragToParams) => Promise<void | boolean>
type DragFromHandler = ( type DragFromHandler = (
dragParams: mouseDragFromParams dragParams: MouseDragFromParams
) => Promise<void | boolean> ) => Promise<void | boolean>
export class SceneFixture { export class SceneFixture {
@ -77,17 +79,26 @@ export class SceneFixture {
{ steps }: { steps: number } = { steps: 20 } { steps }: { steps: number } = { steps: 20 }
): [ClickHandler, MoveHandler, DblClickHandler] => ): [ClickHandler, MoveHandler, DblClickHandler] =>
[ [
(clickParams?: mouseParams) => { (clickParams?: MouseParams) => {
if (clickParams?.pixelDiff) { if (clickParams?.pixelDiff) {
return doAndWaitForImageDiff( return doAndWaitForImageDiff(
this.page, this.page,
() => this.page.mouse.click(x, y), () =>
clickParams?.shouldDbClick
? this.page.mouse.dblclick(x, y, {
delay: clickParams?.delay || 0,
})
: this.page.mouse.click(x, y, {
delay: clickParams?.delay || 0,
}),
clickParams.pixelDiff clickParams.pixelDiff
) )
} }
return this.page.mouse.click(x, y) return clickParams?.shouldDbClick
? this.page.mouse.dblclick(x, y, { delay: clickParams?.delay || 0 })
: this.page.mouse.click(x, y, { delay: clickParams?.delay || 0 })
}, },
(moveParams?: mouseParams) => { (moveParams?: MouseParams) => {
if (moveParams?.pixelDiff) { if (moveParams?.pixelDiff) {
return doAndWaitForImageDiff( return doAndWaitForImageDiff(
this.page, this.page,
@ -97,7 +108,7 @@ export class SceneFixture {
} }
return this.page.mouse.move(x, y, { steps }) return this.page.mouse.move(x, y, { steps })
}, },
(clickParams?: mouseParams) => { (clickParams?: MouseParams) => {
if (clickParams?.pixelDiff) { if (clickParams?.pixelDiff) {
return doAndWaitForImageDiff( return doAndWaitForImageDiff(
this.page, this.page,
@ -114,7 +125,7 @@ export class SceneFixture {
{ steps }: { steps: number } = { steps: 20 } { steps }: { steps: number } = { steps: 20 }
): [DragToHandler, DragFromHandler] => ): [DragToHandler, DragFromHandler] =>
[ [
(dragToParams: mouseDragToParams) => { (dragToParams: MouseDragToParams) => {
if (dragToParams?.pixelDiff) { if (dragToParams?.pixelDiff) {
return doAndWaitForImageDiff( return doAndWaitForImageDiff(
this.page, this.page,
@ -131,7 +142,7 @@ export class SceneFixture {
targetPosition: { x, y }, targetPosition: { x, y },
}) })
}, },
(dragFromParams: mouseDragFromParams) => { (dragFromParams: MouseDragFromParams) => {
if (dragFromParams?.pixelDiff) { if (dragFromParams?.pixelDiff) {
return doAndWaitForImageDiff( return doAndWaitForImageDiff(
this.page, this.page,
@ -219,7 +230,7 @@ export class SceneFixture {
} }
expectPixelColor = async ( expectPixelColor = async (
colour: [number, number, number], colour: [number, number, number] | [number, number, number][],
coords: { x: number; y: number }, coords: { x: number; y: number },
diff: number diff: number
) => { ) => {
@ -241,22 +252,36 @@ export class SceneFixture {
} }
} }
function isColourArray(
colour: [number, number, number] | [number, number, number][]
): colour is [number, number, number][] {
return Array.isArray(colour[0])
}
export async function expectPixelColor( export async function expectPixelColor(
page: Page, page: Page,
colour: [number, number, number], colour: [number, number, number] | [number, number, number][],
coords: { x: number; y: number }, coords: { x: number; y: number },
diff: number diff: number
) { ) {
let finalValue = colour let finalValue = colour
await expect await expect
.poll(async () => { .poll(
const pixel = (await getPixelRGBs(page)(coords, 1))[0] async () => {
if (!pixel) return null const pixel = (await getPixelRGBs(page)(coords, 1))[0]
finalValue = pixel if (!pixel) return null
return pixel.every( finalValue = pixel
(channel, index) => Math.abs(channel - colour[index]) < diff if (!isColourArray(colour)) {
) return pixel.every(
}) (channel, index) => Math.abs(channel - colour[index]) < diff
)
}
return colour.some((c) =>
c.every((channel, index) => Math.abs(pixel[index] - channel) < diff)
)
},
{ timeout: 10_000 }
)
.toBeTruthy() .toBeTruthy()
.catch((cause) => { .catch((cause) => {
throw new Error( throw new Error(

View File

@ -20,10 +20,12 @@ export class ToolbarFixture {
shellButton!: Locator shellButton!: Locator
revolveButton!: Locator revolveButton!: Locator
offsetPlaneButton!: Locator offsetPlaneButton!: Locator
helixButton!: Locator
startSketchBtn!: Locator startSketchBtn!: Locator
lineBtn!: Locator lineBtn!: Locator
tangentialArcBtn!: Locator
circleBtn!: Locator
rectangleBtn!: Locator rectangleBtn!: Locator
lengthConstraintBtn!: Locator
exitSketchBtn!: Locator exitSketchBtn!: Locator
editSketchBtn!: Locator editSketchBtn!: Locator
fileTreeBtn!: Locator fileTreeBtn!: Locator
@ -50,10 +52,12 @@ export class ToolbarFixture {
this.shellButton = page.getByTestId('shell') this.shellButton = page.getByTestId('shell')
this.revolveButton = page.getByTestId('revolve') this.revolveButton = page.getByTestId('revolve')
this.offsetPlaneButton = page.getByTestId('plane-offset') this.offsetPlaneButton = page.getByTestId('plane-offset')
this.helixButton = page.getByTestId('helix')
this.startSketchBtn = page.getByTestId('sketch') this.startSketchBtn = page.getByTestId('sketch')
this.lineBtn = page.getByTestId('line') this.lineBtn = page.getByTestId('line')
this.tangentialArcBtn = page.getByTestId('tangential-arc')
this.circleBtn = page.getByTestId('circle-center')
this.rectangleBtn = page.getByTestId('corner-rectangle') this.rectangleBtn = page.getByTestId('corner-rectangle')
this.lengthConstraintBtn = page.getByTestId('constraint-length')
this.exitSketchBtn = page.getByTestId('sketch-exit') this.exitSketchBtn = page.getByTestId('sketch-exit')
this.editSketchBtn = page.getByText('Edit Sketch') this.editSketchBtn = page.getByText('Edit Sketch')
this.fileTreeBtn = page.locator('[id="files-button-holder"]') this.fileTreeBtn = page.locator('[id="files-button-holder"]')
@ -119,6 +123,15 @@ export class ToolbarFixture {
await expect(this.exeIndicator).toBeVisible({ timeout: 15_000 }) await expect(this.exeIndicator).toBeVisible({ timeout: 15_000 })
} }
} }
selectCenterRectangle = async () => {
await this.page
.getByRole('button', { name: 'caret down Corner rectangle:' })
.click()
await expect(
this.page.getByTestId('dropdown-center-rectangle')
).toBeVisible()
await this.page.getByTestId('dropdown-center-rectangle').click()
}
async closePane(paneId: SidebarType) { async closePane(paneId: SidebarType) {
return closePane(this.page, paneId + SIDEBAR_BUTTON_SUFFIX) return closePane(this.page, paneId + SIDEBAR_BUTTON_SUFFIX)

View File

@ -27,7 +27,7 @@ test.describe('Onboarding tests', () => {
}, },
cleanProjectDir: true, cleanProjectDir: true,
}, },
async ({ page, homePage }) => { async ({ context, page, homePage }) => {
const u = await getUtils(page) const u = await getUtils(page)
await page.setBodyDimensions({ width: 1200, height: 500 }) await page.setBodyDimensions({ width: 1200, height: 500 })
await homePage.goToModelingScene() await homePage.goToModelingScene()
@ -68,7 +68,7 @@ test.describe('Onboarding tests', () => {
}, },
cleanProjectDir: true, cleanProjectDir: true,
}, },
async ({ page }) => { async ({ page, homePage }, testInfo) => {
const u = await getUtils(page) const u = await getUtils(page)
const viewportSize = { width: 1200, height: 500 } const viewportSize = { width: 1200, height: 500 }
@ -154,7 +154,7 @@ test.describe('Onboarding tests', () => {
) )
test( test(
'Click through each onboarding step and back', 'Click through each onboarding step',
{ {
appSettings: { appSettings: {
app: { app: {
@ -187,21 +187,15 @@ test.describe('Onboarding tests', () => {
).toBeVisible() ).toBeVisible()
const nextButton = page.getByTestId('onboarding-next') const nextButton = page.getByTestId('onboarding-next')
const prevButton = page.getByTestId('onboarding-prev')
while ((await nextButton.innerText()) !== 'Finish') { while ((await nextButton.innerText()) !== 'Finish') {
await nextButton.hover() await nextButton.hover()
await nextButton.click() await nextButton.click()
} }
while ((await prevButton.innerText()) !== 'Dismiss') { // Finish the onboarding
await prevButton.hover() await nextButton.hover()
await prevButton.click() await nextButton.click()
}
// Dismiss the onboarding
await prevButton.hover()
await prevButton.click()
// Test that the onboarding pane is gone // Test that the onboarding pane is gone
await expect(page.getByTestId('onboarding-content')).not.toBeVisible() await expect(page.getByTestId('onboarding-content')).not.toBeVisible()
@ -275,7 +269,7 @@ test.describe('Onboarding tests', () => {
cleanProjectDir: true, cleanProjectDir: true,
}, },
async ({ page, homePage }) => { async ({ context, page, homePage }) => {
const u = await getUtils(page) const u = await getUtils(page)
const badCode = `// This is bad code we shouldn't see` const badCode = `// This is bad code we shouldn't see`
@ -342,10 +336,10 @@ test.describe('Onboarding tests', () => {
await homePage.goToModelingScene() await homePage.goToModelingScene()
// Test that the text in this step is correct // Test that the text in this step is correct
const avatarLocator = page const avatarLocator = await page
.getByTestId('user-sidebar-toggle') .getByTestId('user-sidebar-toggle')
.locator('img') .locator('img')
const onboardingOverlayLocator = page const onboardingOverlayLocator = await page
.getByTestId('onboarding-content') .getByTestId('onboarding-content')
.locator('div') .locator('div')
.nth(1) .nth(1)
@ -443,7 +437,7 @@ test.describe('Onboarding tests', () => {
) )
}) })
test.fixme( test(
'Restarting onboarding on desktop takes one attempt', 'Restarting onboarding on desktop takes one attempt',
{ {
appSettings: { appSettings: {
@ -453,7 +447,7 @@ test.fixme(
}, },
cleanProjectDir: true, cleanProjectDir: true,
}, },
async ({ context, page }) => { async ({ context, page, homePage }, testInfo) => {
await context.folderSetupFn(async (dir) => { await context.folderSetupFn(async (dir) => {
const routerTemplateDir = join(dir, 'router-template-slate') const routerTemplateDir = join(dir, 'router-template-slate')
await fsp.mkdir(routerTemplateDir, { recursive: true }) await fsp.mkdir(routerTemplateDir, { recursive: true })
@ -492,6 +486,10 @@ test.fixme(
}) })
await test.step('Navigate into project', async () => { await test.step('Navigate into project', async () => {
await page.setBodyDimensions({ width: 1200, height: 500 })
page.on('console', console.log)
await expect( await expect(
page.getByRole('heading', { name: 'Your Projects' }) page.getByRole('heading', { name: 'Your Projects' })
).toBeVisible() ).toBeVisible()
@ -516,10 +514,7 @@ test.fixme(
const modelColor: [number, number, number] = [76, 76, 76] const modelColor: [number, number, number] = [76, 76, 76]
await page.mouse.move(XYPlanePoint.x, XYPlanePoint.y) await page.mouse.move(XYPlanePoint.x, XYPlanePoint.y)
await expectPixelColor(page, modelColor, XYPlanePoint, 8)
await tutorialDismissButton.click() await tutorialDismissButton.click()
// Make sure model still there.
await expectPixelColor(page, modelColor, XYPlanePoint, 8)
}) })
await test.step('Clear code and restart onboarding from settings', async () => { await test.step('Clear code and restart onboarding from settings', async () => {

View File

@ -29,13 +29,11 @@ test.describe('Point-and-click tests', { tag: ['@skipWin'] }, () => {
localStorage.setItem('persistCode', file) localStorage.setItem('persistCode', file)
}, file) }, file)
await homePage.goToModelingScene() await homePage.goToModelingScene()
await scene.waitForExecutionDone()
const [clickCircle, moveToCircle] = scene.makeMouseHelpers(582, 217) const [clickCircle, moveToCircle] = scene.makeMouseHelpers(582, 217)
await test.step('because there is sweepable geometry, verify extrude is enable when nothing is selected', async () => { await test.step('because there is sweepable geometry, verify extrude is enable when nothing is selected', async () => {
// FIXME: Do not click, clicking removes the activeLines in future checks await scene.clickNoWhere()
// await scene.clickNoWhere()
await expect(toolbar.extrudeButton).toBeEnabled() await expect(toolbar.extrudeButton).toBeEnabled()
}) })
@ -201,7 +199,6 @@ test.describe('Point-and-click tests', { tag: ['@skipWin'] }, () => {
}, file) }, file)
await page.setBodyDimensions({ width: 1000, height: 500 }) await page.setBodyDimensions({ width: 1000, height: 500 })
await homePage.goToModelingScene() await homePage.goToModelingScene()
await scene.waitForExecutionDone()
const sketchOnAChamfer = _sketchOnAChamfer(page, editor, toolbar, scene) const sketchOnAChamfer = _sketchOnAChamfer(page, editor, toolbar, scene)
@ -219,18 +216,13 @@ test.describe('Point-and-click tests', { tag: ['@skipWin'] }, () => {
afterChamferSelectSnippet: afterChamferSelectSnippet:
'sketch002 = startSketchOn(extrude001, seg03)', 'sketch002 = startSketchOn(extrude001, seg03)',
afterRectangle1stClickSnippet: 'startProfileAt([205.96, 254.59], %)', afterRectangle1stClickSnippet:
afterRectangle2ndClickSnippet: `angledLine([0, 11.39], %, $rectangleSegmentA002) 'startProfileAt([205.96, 254.59], sketch002)',
|> angledLine([ afterRectangle2ndClickSnippet: `angledLine([0,11.39],%,$rectangleSegmentA002)
segAng(rectangleSegmentA002) - 90, |>angledLine([segAng(rectangleSegmentA002)-90,105.26],%)
105.26 |>angledLine([segAng(rectangleSegmentA002),-segLen(rectangleSegmentA002)],%)
], %, $rectangleSegmentB001) |>line(endAbsolute=[profileStartX(%),profileStartY(%)],%)
|> angledLine([ |>close(%)`,
segAng(rectangleSegmentA002),
-segLen(rectangleSegmentA002)
], %, $rectangleSegmentC001)
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|> close()`,
}) })
await sketchOnAChamfer({ await sketchOnAChamfer({
@ -251,19 +243,15 @@ test.describe('Point-and-click tests', { tag: ['@skipWin'] }, () => {
afterChamferSelectSnippet: afterChamferSelectSnippet:
'sketch003 = startSketchOn(extrude001, seg04)', 'sketch003 = startSketchOn(extrude001, seg04)',
afterRectangle1stClickSnippet: 'startProfileAt([-209.64, 255.28], %)', afterRectangle1stClickSnippet:
afterRectangle2ndClickSnippet: `angledLine([0, 11.56], %, $rectangleSegmentA003) 'startProfileAt([-209.64, 255.28], sketch003)',
|> angledLine([ afterRectangle2ndClickSnippet: `angledLine([0,11.56],%,$rectangleSegmentA003)
segAng(rectangleSegmentA003) - 90, |>angledLine([segAng(rectangleSegmentA003)-90,106.84],%)
106.84 |>angledLine([segAng(rectangleSegmentA003),-segLen(rectangleSegmentA003)],%)
], %, $rectangleSegmentB002) |>line(endAbsolute=[profileStartX(%),profileStartY(%)],%)
|> angledLine([ |>close(%)`,
segAng(rectangleSegmentA003),
-segLen(rectangleSegmentA003)
], %, $rectangleSegmentC002)
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|> close()`,
}) })
await sketchOnAChamfer({ await sketchOnAChamfer({
clickCoords: { x: 677, y: 87 }, clickCoords: { x: 677, y: 87 },
cameraPos: { x: -6200, y: 1500, z: 6200 }, cameraPos: { x: -6200, y: 1500, z: 6200 },
@ -276,19 +264,14 @@ test.describe('Point-and-click tests', { tag: ['@skipWin'] }, () => {
] ]
}, %)`, }, %)`,
afterChamferSelectSnippet: afterChamferSelectSnippet:
'sketch003 = startSketchOn(extrude001, seg04)', 'sketch004 = startSketchOn(extrude001, seg05)',
afterRectangle1stClickSnippet: 'startProfileAt([75.8, 317.2], %)', afterRectangle1stClickSnippet:
afterRectangle2ndClickSnippet: `angledLine([0, 11.56], %, $rectangleSegmentA003) 'startProfileAt([82.57, 322.96], sketch004)',
|> angledLine([ afterRectangle2ndClickSnippet: `angledLine([0,11.16],%,$rectangleSegmentA004)
segAng(rectangleSegmentA003) - 90, |>angledLine([segAng(rectangleSegmentA004)-90,103.07],%)
106.84 |>angledLine([segAng(rectangleSegmentA004),-segLen(rectangleSegmentA004)],%)
], %, $rectangleSegmentB002) |>line(endAbsolute=[profileStartX(%),profileStartY(%)],%)|
|> angledLine([ >close(%)`,
segAng(rectangleSegmentA003),
-segLen(rectangleSegmentA003)
], %, $rectangleSegmentC002)
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|> close()`,
}) })
/// last one /// last one
await sketchOnAChamfer({ await sketchOnAChamfer({
@ -301,104 +284,97 @@ test.describe('Point-and-click tests', { tag: ['@skipWin'] }, () => {
}, %)`, }, %)`,
afterChamferSelectSnippet: afterChamferSelectSnippet:
'sketch005 = startSketchOn(extrude001, seg06)', 'sketch005 = startSketchOn(extrude001, seg06)',
afterRectangle1stClickSnippet: 'startProfileAt([-23.43, 19.69], %)', afterRectangle1stClickSnippet:
afterRectangle2ndClickSnippet: `angledLine([0, 9.1], %, $rectangleSegmentA005) 'startProfileAt([-23.43, 19.69], sketch005)',
afterRectangle2ndClickSnippet: `angledLine([0,9.1],%,$rectangleSegmentA005)
|> angledLine([ |>angledLine([segAng(rectangleSegmentA005)-90,84.07],%)
segAng(rectangleSegmentA005) - 90, |>angledLine([segAng(rectangleSegmentA005),-segLen(rectangleSegmentA005)],%)
84.07 |>line(endAbsolute=[profileStartX(%),profileStartY(%)],%)
], %, $rectangleSegmentB004) |>close(%)`,
|> angledLine([
segAng(rectangleSegmentA005),
-segLen(rectangleSegmentA005)
], %, $rectangleSegmentC004)
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|> close()`,
}) })
await test.step('verify at the end of the test that final code is what is expected', async () => { await test.step('verify at the end of the test that final code is what is expected', async () => {
await editor.expectEditor.toContain( await editor.expectEditor.toContain(
`sketch001 = startSketchOn('XZ') `sketch001 = startSketchOn('XZ')
|> startProfileAt([75.8, 317.2], %) // [$startCapTag, $EndCapTag]
|> startProfileAt([75.8, 317.2], %) // [$startCapTag, $EndCapTag] |> angledLine([0, 268.43], %, $rectangleSegmentA001)
|> angledLine([0, 268.43], %, $rectangleSegmentA001) |> angledLine([
|> angledLine([ segAng(rectangleSegmentA001) - 90,
segAng(rectangleSegmentA001) - 90, 217.26
217.26 ], %, $seg01)
], %, $seg01) |> angledLine([
|> angledLine([ segAng(rectangleSegmentA001),
segAng(rectangleSegmentA001), -segLen(rectangleSegmentA001)
-segLen(rectangleSegmentA001) ], %, $yo)
], %, $yo) |> line(endAbsolute=[profileStartX(%), profileStartY(%)], %, $seg02)
|> line(endAbsolute = [profileStartX(%), profileStartY(%)], tag = $seg02) |> close(%)
|> close() extrude001 = extrude(100, sketch001)
extrude001 = extrude(sketch001, length = 100) |> chamfer({
|> chamfer({ length = 30,
length = 30, tags = [getOppositeEdge(seg01)]
tags = [getOppositeEdge(seg01)] }, %, $seg03)
}, %, $seg03) |> chamfer({ length = 30, tags = [seg01] }, %, $seg04)
|> chamfer({ length = 30, tags = [seg01] }, %, $seg04) |> chamfer({
|> chamfer({ length = 30,
length = 30, tags = [getNextAdjacentEdge(seg02)]
tags = [getNextAdjacentEdge(seg02)] }, %, $seg05)
}, %, $seg05) |> chamfer({
|> chamfer({ length = 30,
length = 30, tags = [getNextAdjacentEdge(yo)]
tags = [getNextAdjacentEdge(yo)] }, %, $seg06)
}, %, $seg06) sketch005 = startSketchOn(extrude001, seg06)
sketch005 = startSketchOn(extrude001, seg06) profile004 = startProfileAt([-23.43, 19.69], sketch005)
|> startProfileAt([-23.43,19.69], %) |> angledLine([0, 9.1], %, $rectangleSegmentA005)
|> angledLine([0, 9.1], %, $rectangleSegmentA005) |> angledLine([
|> angledLine([ segAng(rectangleSegmentA005) - 90,
segAng(rectangleSegmentA005) - 90, 84.07
84.07 ], %)
], %, $rectangleSegmentB004) |> angledLine([
|> angledLine([ segAng(rectangleSegmentA005),
segAng(rectangleSegmentA005), -segLen(rectangleSegmentA005)
-segLen(rectangleSegmentA005) ], %)
], %, $rectangleSegmentC004) |> line(endAbsolute=[profileStartX(%), profileStartY(%)], %)
|> line(endAbsolute = [profileStartX(%), profileStartY(%)]) |> close(%)
|> close() sketch004 = startSketchOn(extrude001, seg05)
sketch004 = startSketchOn(extrude001, seg05) profile003 = startProfileAt([82.57, 322.96], sketch004)
|> startProfileAt([82.57,322.96], %) |> angledLine([0, 11.16], %, $rectangleSegmentA004)
|> angledLine([0, 11.16], %, $rectangleSegmentA004) |> angledLine([
|> angledLine([ segAng(rectangleSegmentA004) - 90,
segAng(rectangleSegmentA004) - 90, 103.07
103.07 ], %)
], %, $rectangleSegmentB003) |> angledLine([
|> angledLine([ segAng(rectangleSegmentA004),
segAng(rectangleSegmentA004), -segLen(rectangleSegmentA004)
-segLen(rectangleSegmentA004) ], %)
], %, $rectangleSegmentC003) |> line(endAbsolute=[profileStartX(%), profileStartY(%)], %)
|> line(endAbsolute = [profileStartX(%), profileStartY(%)]) |> close(%)
|> close() sketch003 = startSketchOn(extrude001, seg04)
sketch003 = startSketchOn(extrude001, seg04) profile002 = startProfileAt([-209.64, 255.28], sketch003)
|> startProfileAt([-209.64,255.28], %) |> angledLine([0, 11.56], %, $rectangleSegmentA003)
|> angledLine([0, 11.56], %, $rectangleSegmentA003) |> angledLine([
|> angledLine([ segAng(rectangleSegmentA003) - 90,
segAng(rectangleSegmentA003) - 90, 106.84
106.84 ], %)
], %, $rectangleSegmentB002) |> angledLine([
|> angledLine([ segAng(rectangleSegmentA003),
segAng(rectangleSegmentA003), -segLen(rectangleSegmentA003)
-segLen(rectangleSegmentA003) ], %)
], %, $rectangleSegmentC002) |> line(endAbsolute=[profileStartX(%), profileStartY(%)], %)
|> line(endAbsolute = [profileStartX(%), profileStartY(%)]) |> close(%)
|> close() sketch002 = startSketchOn(extrude001, seg03)
sketch002 = startSketchOn(extrude001, seg03) profile001 = startProfileAt([205.96, 254.59], sketch002)
|> startProfileAt([205.96,254.59], %) |> angledLine([0, 11.39], %, $rectangleSegmentA002)
|> angledLine([0, 11.39], %, $rectangleSegmentA002) |> angledLine([
|> angledLine([ segAng(rectangleSegmentA002) - 90,
segAng(rectangleSegmentA002) - 90, 105.26
105.26 ], %)
], %, $rectangleSegmentB001) |> angledLine([
|> angledLine([ segAng(rectangleSegmentA002),
segAng(rectangleSegmentA002), -segLen(rectangleSegmentA002)
-segLen(rectangleSegmentA002) ], %)
], %, $rectangleSegmentC001) |> line(endAbsolute=[profileStartX(%), profileStartY(%)], %)
|> line(endAbsolute = [profileStartX(%), profileStartY(%)]) |> close(%)
|> close() `,
`,
{ shouldNormalise: true } { shouldNormalise: true }
) )
}) })
@ -425,7 +401,6 @@ test.describe('Point-and-click tests', { tag: ['@skipWin'] }, () => {
}, file) }, file)
await page.setBodyDimensions({ width: 1000, height: 500 }) await page.setBodyDimensions({ width: 1000, height: 500 })
await homePage.goToModelingScene() await homePage.goToModelingScene()
await scene.waitForExecutionDone()
const sketchOnAChamfer = _sketchOnAChamfer(page, editor, toolbar, scene) const sketchOnAChamfer = _sketchOnAChamfer(page, editor, toolbar, scene)
@ -443,18 +418,13 @@ test.describe('Point-and-click tests', { tag: ['@skipWin'] }, () => {
beforeChamferSnippetEnd: '}, extrude001)', beforeChamferSnippetEnd: '}, extrude001)',
afterChamferSelectSnippet: afterChamferSelectSnippet:
'sketch002 = startSketchOn(extrude001, seg03)', 'sketch002 = startSketchOn(extrude001, seg03)',
afterRectangle1stClickSnippet: 'startProfileAt([205.96, 254.59], %)', afterRectangle1stClickSnippet:
afterRectangle2ndClickSnippet: `angledLine([0, 11.39], %, $rectangleSegmentA002) 'startProfileAt([205.96, 254.59], sketch002)',
|> angledLine([ afterRectangle2ndClickSnippet: `angledLine([0,11.39],%,$rectangleSegmentA002)
segAng(rectangleSegmentA002) - 90, |>angledLine([segAng(rectangleSegmentA002)-90,105.26],%)
105.26 |>angledLine([segAng(rectangleSegmentA002),-segLen(rectangleSegmentA002)],%)
], %, $rectangleSegmentB001) |>line(endAbsolute=[profileStartX(%),profileStartY(%)],%)
|> angledLine([ |>close(%)`,
segAng(rectangleSegmentA002),
-segLen(rectangleSegmentA002)
], %, $rectangleSegmentC001)
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|> close()`,
}) })
await editor.expectEditor.toContain( await editor.expectEditor.toContain(
`sketch001 = startSketchOn('XZ') `sketch001 = startSketchOn('XZ')
@ -484,24 +454,119 @@ chamf = chamfer({
] ]
}, %) }, %)
sketch002 = startSketchOn(extrude001, seg03) sketch002 = startSketchOn(extrude001, seg03)
|> startProfileAt([205.96, 254.59], %) profile001 = startProfileAt([205.96, 254.59], sketch002)
|> angledLine([0, 11.39], %, $rectangleSegmentA002) |> angledLine([0, 11.39], %, $rectangleSegmentA002)
|> angledLine([ |> angledLine([
segAng(rectangleSegmentA002) - 90, segAng(rectangleSegmentA002) - 90,
105.26 105.26
], %, $rectangleSegmentB001) ], %)
|> angledLine([ |> angledLine([
segAng(rectangleSegmentA002), segAng(rectangleSegmentA002),
-segLen(rectangleSegmentA002) -segLen(rectangleSegmentA002)
], %, $rectangleSegmentC001) ], %)
|> line(endAbsolute = [profileStartX(%), profileStartY(%)]) |> line(endAbsolute=[profileStartX(%), profileStartY(%)], %)
|> close() |> close(%)
`, `,
{ shouldNormalise: true } { shouldNormalise: true }
) )
}) })
}) })
test(`Verify axis, origin, and horizontal snapping`, async ({
page,
homePage,
editor,
toolbar,
scene,
}) => {
const viewPortSize = { width: 1200, height: 500 }
await page.setBodyDimensions(viewPortSize)
await homePage.goToModelingScene()
// Constants and locators
// These are mappings from screenspace to KCL coordinates,
// until we merge in our coordinate system helpers
const xzPlane = [
viewPortSize.width * 0.65,
viewPortSize.height * 0.3,
] as const
const originSloppy = {
screen: [
viewPortSize.width / 2 + 3, // 3px off the center of the screen
viewPortSize.height / 2,
],
kcl: [0, 0],
} as const
const xAxisSloppy = {
screen: [
viewPortSize.width * 0.75,
viewPortSize.height / 2 - 3, // 3px off the X-axis
],
kcl: [20.34, 0],
} as const
const offYAxis = {
screen: [
viewPortSize.width * 0.6, // Well off the Y-axis, out of snapping range
viewPortSize.height * 0.3,
],
kcl: [8.14, 6.78],
} as const
const yAxisSloppy = {
screen: [
viewPortSize.width / 2 + 5, // 5px off the Y-axis
viewPortSize.height * 0.3,
],
kcl: [0, 6.78],
} as const
const [clickOnXzPlane, moveToXzPlane] = scene.makeMouseHelpers(...xzPlane)
const [clickOriginSloppy] = scene.makeMouseHelpers(...originSloppy.screen)
const [clickXAxisSloppy, moveXAxisSloppy] = scene.makeMouseHelpers(
...xAxisSloppy.screen
)
const [dragToOffYAxis, dragFromOffAxis] = scene.makeDragHelpers(
...offYAxis.screen
)
const expectedCodeSnippets = {
sketchOnXzPlane: `sketch001 = startSketchOn('XZ')`,
pointAtOrigin: `startProfileAt([${originSloppy.kcl[0]}, ${originSloppy.kcl[1]}], sketch001)`,
segmentOnXAxis: `xLine(${xAxisSloppy.kcl[0]}, %)`,
afterSegmentDraggedOffYAxis: `startProfileAt([${offYAxis.kcl[0]}, ${offYAxis.kcl[1]}], sketch001)`,
afterSegmentDraggedOnYAxis: `startProfileAt([${yAxisSloppy.kcl[0]}, ${yAxisSloppy.kcl[1]}], sketch001)`,
}
await test.step(`Start a sketch on the XZ plane`, async () => {
await editor.closePane()
await toolbar.startSketchPlaneSelection()
await moveToXzPlane()
await clickOnXzPlane()
// timeout wait for engine animation is unavoidable
await page.waitForTimeout(600)
await editor.expectEditor.toContain(expectedCodeSnippets.sketchOnXzPlane)
})
await test.step(`Place a point a few pixels off the middle, verify it still snaps to 0,0`, async () => {
await clickOriginSloppy()
await editor.expectEditor.toContain(expectedCodeSnippets.pointAtOrigin)
})
await test.step(`Add a segment on x-axis after moving the mouse a bit, verify it snaps`, async () => {
await moveXAxisSloppy()
await clickXAxisSloppy()
await editor.expectEditor.toContain(expectedCodeSnippets.segmentOnXAxis)
})
await test.step(`Unequip line tool`, async () => {
await toolbar.lineBtn.click()
await expect(toolbar.lineBtn).not.toHaveAttribute('aria-pressed', 'true')
})
await test.step(`Drag the origin point up and to the right, verify it's past snapping`, async () => {
await dragToOffYAxis({
fromPoint: { x: originSloppy.screen[0], y: originSloppy.screen[1] },
})
})
})
// yo
test(`Verify axis, origin, and horizontal snapping`, async ({ test(`Verify axis, origin, and horizontal snapping`, async ({
page, page,
homePage, homePage,
@ -716,330 +781,6 @@ openSketch = startSketchOn('XY')
}) })
}) })
test(`Shift-click to select and deselect edges and faces`, async ({
context,
page,
homePage,
scene,
}) => {
// Code samples
const initialCode = `sketch001 = startSketchOn('XY')
|> startProfileAt([-12, -6], %)
|> line(end = [0, 12])
|> line(end = [24, 0])
|> line(end = [0, -12])
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|> close()
|> extrude(%, length = -12)`
// Locators
const upperEdgeLocation = { x: 600, y: 192 }
const lowerEdgeLocation = { x: 600, y: 383 }
const faceLocation = { x: 630, y: 290 }
// Click helpers
const [clickOnUpperEdge] = scene.makeMouseHelpers(
upperEdgeLocation.x,
upperEdgeLocation.y
)
const [clickOnLowerEdge] = scene.makeMouseHelpers(
lowerEdgeLocation.x,
lowerEdgeLocation.y
)
const [clickOnFace] = scene.makeMouseHelpers(faceLocation.x, faceLocation.y)
// Colors
const edgeColorWhite: [number, number, number] = [220, 220, 220] // varies from 192 to 255
const edgeColorYellow: [number, number, number] = [251, 251, 40] // vaies from 12 to 67
const faceColorGray: [number, number, number] = [168, 168, 168]
const faceColorYellow: [number, number, number] = [155, 155, 155]
const tolerance = 40
const timeout = 150
// Setup
await test.step(`Initial test setup`, async () => {
await context.addInitScript((initialCode) => {
localStorage.setItem('persistCode', initialCode)
}, initialCode)
await page.setBodyDimensions({ width: 1000, height: 500 })
await homePage.goToModelingScene()
// Wait for the scene and stream to load
await scene.expectPixelColor(faceColorGray, faceLocation, tolerance)
})
await test.step('Select and deselect a single edge', async () => {
await test.step('Click the edge', async () => {
await scene.expectPixelColor(
edgeColorWhite,
upperEdgeLocation,
tolerance
)
await clickOnUpperEdge()
await scene.expectPixelColor(
edgeColorYellow,
upperEdgeLocation,
tolerance
)
})
await test.step('Shift-click the same edge to deselect', async () => {
await page.keyboard.down('Shift')
await page.waitForTimeout(timeout)
await clickOnUpperEdge()
await page.waitForTimeout(timeout)
await page.keyboard.up('Shift')
await scene.expectPixelColor(
edgeColorWhite,
upperEdgeLocation,
tolerance
)
})
})
await test.step('Select and deselect multiple objects', async () => {
await test.step('Select both edges and the face', async () => {
await test.step('Select the upper edge', async () => {
await scene.expectPixelColor(
edgeColorWhite,
upperEdgeLocation,
tolerance
)
await clickOnUpperEdge()
await scene.expectPixelColor(
edgeColorYellow,
upperEdgeLocation,
tolerance
)
})
await test.step('Select the lower edge (Shift-click)', async () => {
await scene.expectPixelColor(
edgeColorWhite,
lowerEdgeLocation,
tolerance
)
await page.keyboard.down('Shift')
await page.waitForTimeout(timeout)
await clickOnLowerEdge()
await page.waitForTimeout(timeout)
await page.keyboard.up('Shift')
await scene.expectPixelColor(
edgeColorYellow,
lowerEdgeLocation,
tolerance
)
})
await test.step('Select the face (Shift-click)', async () => {
await scene.expectPixelColor(faceColorGray, faceLocation, tolerance)
await page.keyboard.down('Shift')
await page.waitForTimeout(timeout)
await clickOnFace()
await page.waitForTimeout(timeout)
await page.keyboard.up('Shift')
await scene.expectPixelColor(faceColorYellow, faceLocation, tolerance)
})
})
await test.step('Deselect them one by one', async () => {
await test.step('Deselect the face (Shift-click)', async () => {
await scene.expectPixelColor(faceColorYellow, faceLocation, tolerance)
await page.keyboard.down('Shift')
await page.waitForTimeout(timeout)
await clickOnFace()
await page.waitForTimeout(timeout)
await page.keyboard.up('Shift')
await scene.expectPixelColor(faceColorGray, faceLocation, tolerance)
})
await test.step('Deselect the lower edge (Shift-click)', async () => {
await scene.expectPixelColor(
edgeColorYellow,
lowerEdgeLocation,
tolerance
)
await page.keyboard.down('Shift')
await page.waitForTimeout(timeout)
await clickOnLowerEdge()
await page.waitForTimeout(timeout)
await page.keyboard.up('Shift')
await scene.expectPixelColor(
edgeColorWhite,
lowerEdgeLocation,
tolerance
)
})
await test.step('Deselect the upper edge (Shift-click)', async () => {
await scene.expectPixelColor(
edgeColorYellow,
upperEdgeLocation,
tolerance
)
await page.keyboard.down('Shift')
await page.waitForTimeout(timeout)
await clickOnUpperEdge()
await page.waitForTimeout(timeout)
await page.keyboard.up('Shift')
await scene.expectPixelColor(
edgeColorWhite,
upperEdgeLocation,
tolerance
)
})
})
})
})
test(`Shift-click to select and deselect sketch segments`, async ({
page,
homePage,
scene,
editor,
}) => {
// Locators
const firstPointLocation = { x: 200, y: 100 }
const secondPointLocation = { x: 800, y: 100 }
const thirdPointLocation = { x: 800, y: 400 }
const fristSegmentLocation = { x: 750, y: 100 }
const secondSegmentLocation = { x: 800, y: 150 }
const planeLocation = { x: 700, y: 200 }
// Click helpers
const [clickFirstPoint] = scene.makeMouseHelpers(
firstPointLocation.x,
firstPointLocation.y
)
const [clickSecondPoint] = scene.makeMouseHelpers(
secondPointLocation.x,
secondPointLocation.y
)
const [clickThirdPoint] = scene.makeMouseHelpers(
thirdPointLocation.x,
thirdPointLocation.y
)
const [clickFirstSegment] = scene.makeMouseHelpers(
fristSegmentLocation.x,
fristSegmentLocation.y
)
const [clickSecondSegment] = scene.makeMouseHelpers(
secondSegmentLocation.x,
secondSegmentLocation.y
)
const [clickPlane] = scene.makeMouseHelpers(
planeLocation.x,
planeLocation.y
)
// Colors
const edgeColorWhite: [number, number, number] = [220, 220, 220]
const edgeColorBlue: [number, number, number] = [20, 20, 200]
const backgroundColor: [number, number, number] = [30, 30, 30]
const tolerance = 40
const timeout = 150
// Setup
await test.step(`Initial test setup`, async () => {
await page.setBodyDimensions({ width: 1000, height: 500 })
await homePage.goToModelingScene()
// Wait for the scene and stream to load
await scene.expectPixelColor(
backgroundColor,
secondPointLocation,
tolerance
)
})
await test.step('Select and deselect a single sketch segment', async () => {
await test.step('Get into sketch mode', async () => {
await editor.closePane()
await page.waitForTimeout(timeout)
await page.getByRole('button', { name: 'Start Sketch' }).click()
await page.waitForTimeout(timeout)
await clickPlane()
await page.waitForTimeout(1000)
})
await test.step('Draw sketch', async () => {
await clickFirstPoint()
await page.waitForTimeout(timeout)
await clickSecondPoint()
await page.waitForTimeout(timeout)
await clickThirdPoint()
await page.waitForTimeout(timeout)
})
await test.step('Deselect line tool', async () => {
const btnLine = page.getByTestId('line')
const btnLineAriaPressed = await btnLine.getAttribute('aria-pressed')
if (btnLineAriaPressed === 'true') {
await btnLine.click()
}
await page.waitForTimeout(timeout)
})
await test.step('Select the first segment', async () => {
await page.waitForTimeout(timeout)
await clickFirstSegment()
await page.waitForTimeout(timeout)
await scene.expectPixelColor(
edgeColorBlue,
fristSegmentLocation,
tolerance
)
await scene.expectPixelColor(
edgeColorWhite,
secondSegmentLocation,
tolerance
)
})
await test.step('Select the second segment (Shift-click)', async () => {
await page.keyboard.down('Shift')
await page.waitForTimeout(timeout)
await clickSecondSegment()
await page.waitForTimeout(timeout)
await page.keyboard.up('Shift')
await scene.expectPixelColor(
edgeColorBlue,
fristSegmentLocation,
tolerance
)
await scene.expectPixelColor(
edgeColorBlue,
secondSegmentLocation,
tolerance
)
})
await test.step('Deselect the first segment', async () => {
await page.keyboard.down('Shift')
await page.waitForTimeout(timeout)
await clickFirstSegment()
await page.waitForTimeout(timeout)
await page.keyboard.up('Shift')
await scene.expectPixelColor(
edgeColorWhite,
fristSegmentLocation,
tolerance
)
await scene.expectPixelColor(
edgeColorBlue,
secondSegmentLocation,
tolerance
)
})
await test.step('Deselect the second segment', async () => {
await page.keyboard.down('Shift')
await page.waitForTimeout(timeout)
await clickSecondSegment()
await page.waitForTimeout(timeout)
await page.keyboard.up('Shift')
await scene.expectPixelColor(
edgeColorWhite,
fristSegmentLocation,
tolerance
)
await scene.expectPixelColor(
edgeColorWhite,
secondSegmentLocation,
tolerance
)
})
})
})
test(`Offset plane point-and-click`, async ({ test(`Offset plane point-and-click`, async ({
context, context,
page, page,
@ -1055,9 +796,6 @@ openSketch = startSketchOn('XY')
const expectedOutput = `plane001 = offsetPlane('XZ', 5)` const expectedOutput = `plane001 = offsetPlane('XZ', 5)`
await homePage.goToModelingScene() await homePage.goToModelingScene()
// FIXME: Since there is no KCL code loaded. We need to wait for the scene to load before we continue.
// The engine may not be connected
await page.waitForTimeout(15000)
await test.step(`Look for the blue of the XZ plane`, async () => { await test.step(`Look for the blue of the XZ plane`, async () => {
await scene.expectPixelColor([50, 51, 96], testPoint, 15) await scene.expectPixelColor([50, 51, 96], testPoint, 15)
@ -1106,71 +844,6 @@ openSketch = startSketchOn('XY')
}) })
}) })
test('Helix point-and-click', async ({
context,
page,
homePage,
scene,
editor,
toolbar,
cmdBar,
}) => {
// One dumb hardcoded screen pixel value
const testPoint = { x: 620, y: 257 }
const expectedOutput = `helix001 = helix(revolutions = 1, angleStart = 360, counterClockWise = false, radius = 5, axis = 'X', length = 5)`
await homePage.goToModelingScene()
await test.step(`Look for the red of the default plane`, async () => {
await scene.expectPixelColor([96, 52, 52], testPoint, 15)
})
await test.step(`Go through the command bar flow`, async () => {
await toolbar.helixButton.click()
await cmdBar.expectState({
stage: 'arguments',
currentArgKey: 'revolutions',
currentArgValue: '1',
headerArguments: {
AngleStart: '',
Axis: '',
CounterClockWise: '',
Length: '',
Radius: '',
Revolutions: '',
},
highlightedHeaderArg: 'revolutions',
commandName: 'Helix',
})
await cmdBar.progressCmdBar()
await cmdBar.progressCmdBar()
await cmdBar.progressCmdBar()
await cmdBar.progressCmdBar()
await cmdBar.progressCmdBar()
await cmdBar.progressCmdBar()
await cmdBar.progressCmdBar()
})
await test.step(`Confirm code is added to the editor, scene has changed`, async () => {
await editor.expectEditor.toContain(expectedOutput)
await editor.expectState({
diagnostics: [],
activeLines: [expectedOutput],
highlightedCode: '',
})
// Red plane is now gone, white helix is there
await scene.expectPixelColor([250, 250, 250], testPoint, 15)
})
await test.step('Delete offset plane via feature tree selection', async () => {
await editor.closePane()
const operationButton = await toolbar.getFeatureTreeOperation('Helix', 0)
await operationButton.click({ button: 'left' })
await page.keyboard.press('Backspace')
// Red plane is back
await scene.expectPixelColor([96, 52, 52], testPoint, 15)
})
})
const loftPointAndClickCases = [ const loftPointAndClickCases = [
{ shouldPreselect: true }, { shouldPreselect: true },
{ shouldPreselect: false }, { shouldPreselect: false },
@ -1283,7 +956,6 @@ loft001 = loft([sketch001, sketch002])
}, initialCode) }, initialCode)
await page.setBodyDimensions({ width: 1000, height: 500 }) await page.setBodyDimensions({ width: 1000, height: 500 })
await homePage.goToModelingScene() await homePage.goToModelingScene()
await scene.waitForExecutionDone()
// One dumb hardcoded screen pixel value // One dumb hardcoded screen pixel value
const testPoint = { x: 575, y: 200 } const testPoint = { x: 575, y: 200 }
@ -1361,7 +1033,7 @@ sketch002 = startSketchOn('XZ')
testPoint.x - 50, testPoint.x - 50,
testPoint.y testPoint.y
) )
const sweepDeclaration = 'sweep001 = sweep(sketch001, path = sketch002)' const sweepDeclaration = 'sweep001 = sweep({ path = sketch002 }, sketch001)'
await test.step(`Look for sketch001`, async () => { await test.step(`Look for sketch001`, async () => {
await toolbar.closePane('code') await toolbar.closePane('code')
@ -1398,6 +1070,21 @@ sketch002 = startSketchOn('XZ')
await cmdBar.progressCmdBar() await cmdBar.progressCmdBar()
await page.waitForTimeout(500) await page.waitForTimeout(500)
}) })
// // yo
// await clickOnSketch2()
// await page.waitForTimeout(500)
// await cmdBar.progressCmdBar()
// await toolbar.openPane('code')
// await page.waitForTimeout(500)
// })
// await test.step(`Confirm code is added to the editor, scene has changed`, async () => {
// await scene.expectPixelColor([135, 64, 73], testPoint, 15)
// await editor.expectEditor.toContain(sweepDeclaration)
// await editor.expectState({
// diagnostics: [],
// activeLines: [sweepDeclaration],
// highlightedCode: '',
await test.step(`Confirm code is added to the editor, scene has changed`, async () => { await test.step(`Confirm code is added to the editor, scene has changed`, async () => {
await scene.expectPixelColor([135, 64, 73], testPoint, 15) await scene.expectPixelColor([135, 64, 73], testPoint, 15)
@ -1926,7 +1613,16 @@ extrude001 = extrude(sketch001, length = -12)
}, initialCode) }, initialCode)
await page.setBodyDimensions({ width: 1000, height: 500 }) await page.setBodyDimensions({ width: 1000, height: 500 })
await homePage.goToModelingScene() await homePage.goToModelingScene()
await scene.waitForExecutionDone()
// verify modeling scene is loaded
await scene.expectPixelColor(
backgroundColor,
secondEdgeLocation,
lowTolerance
)
// wait for stream to load
await scene.expectPixelColor(bodyColor, bodyLocation, highTolerance)
}) })
// Test 1: Command bar flow with preselected edges // Test 1: Command bar flow with preselected edges
@ -2151,7 +1847,6 @@ chamfer04 = chamfer({ length = 5, tags = [getOppositeEdge(seg02)]}, extrude001
}, initialCode) }, initialCode)
await page.setBodyDimensions({ width: 1000, height: 500 }) await page.setBodyDimensions({ width: 1000, height: 500 })
await homePage.goToModelingScene() await homePage.goToModelingScene()
await scene.waitForExecutionDone()
// verify modeling scene is loaded // verify modeling scene is loaded
await scene.expectPixelColor( await scene.expectPixelColor(
@ -2274,13 +1969,12 @@ chamfer04 = chamfer({ length = 5, tags = [getOppositeEdge(seg02)]}, extrude001
}, initialCode) }, initialCode)
await page.setBodyDimensions({ width: 1000, height: 500 }) await page.setBodyDimensions({ width: 1000, height: 500 })
await homePage.goToModelingScene() await homePage.goToModelingScene()
await scene.waitForExecutionDone()
// One dumb hardcoded screen pixel value // One dumb hardcoded screen pixel value
const testPoint = { x: 575, y: 200 } const testPoint = { x: 575, y: 200 }
const [clickOnCap] = scene.makeMouseHelpers(testPoint.x, testPoint.y) const [clickOnCap] = scene.makeMouseHelpers(testPoint.x, testPoint.y)
const shellDeclaration = const shellDeclaration =
"shell001 = shell(extrude001, faces = ['end'], thickness = 5)" "shell001 = shell({ faces = ['end'], thickness = 5 }, extrude001)"
await test.step(`Look for the grey of the shape`, async () => { await test.step(`Look for the grey of the shape`, async () => {
await scene.expectPixelColor([127, 127, 127], testPoint, 15) await scene.expectPixelColor([127, 127, 127], testPoint, 15)
@ -2373,7 +2067,6 @@ extrude001 = extrude(sketch001, length = 40)
}, initialCode) }, initialCode)
await page.setBodyDimensions({ width: 1000, height: 500 }) await page.setBodyDimensions({ width: 1000, height: 500 })
await homePage.goToModelingScene() await homePage.goToModelingScene()
await scene.waitForExecutionDone()
// One dumb hardcoded screen pixel value // One dumb hardcoded screen pixel value
const testPoint = { x: 580, y: 180 } const testPoint = { x: 580, y: 180 }
@ -2381,7 +2074,8 @@ extrude001 = extrude(sketch001, length = 40)
const [clickOnWall] = scene.makeMouseHelpers(testPoint.x, testPoint.y + 70) const [clickOnWall] = scene.makeMouseHelpers(testPoint.x, testPoint.y + 70)
const mutatedCode = 'xLine(-40, %, $seg01)' const mutatedCode = 'xLine(-40, %, $seg01)'
const shellDeclaration = const shellDeclaration =
"shell001 = shell(extrude001, faces = ['end', seg01], thickness = 5)" "shell001 = shell({ faces = ['end', seg01], thickness = 5}, extrude001)"
const formattedOutLastLine = '}, extrude001)'
await test.step(`Look for the grey of the shape`, async () => { await test.step(`Look for the grey of the shape`, async () => {
await scene.expectPixelColor([99, 99, 99], testPoint, 15) await scene.expectPixelColor([99, 99, 99], testPoint, 15)
@ -2424,7 +2118,7 @@ extrude001 = extrude(sketch001, length = 40)
await editor.expectEditor.toContain(shellDeclaration) await editor.expectEditor.toContain(shellDeclaration)
await editor.expectState({ await editor.expectState({
diagnostics: [], diagnostics: [],
activeLines: [shellDeclaration], activeLines: [formattedOutLastLine],
highlightedCode: '', highlightedCode: '',
}) })
await scene.expectPixelColor([49, 49, 49], testPoint, 15) await scene.expectPixelColor([49, 49, 49], testPoint, 15)
@ -2478,8 +2172,9 @@ extrude002 = extrude(sketch002, length = 50)
// One dumb hardcoded screen pixel value // One dumb hardcoded screen pixel value
const testPoint = { x: 550, y: 295 } const testPoint = { x: 550, y: 295 }
const [clickOnCap] = scene.makeMouseHelpers(testPoint.x, testPoint.y) const [clickOnCap] = scene.makeMouseHelpers(testPoint.x, testPoint.y)
const shellTarget = hasExtrudesInPipe ? 'sketch002' : 'extrude002' const shellDeclaration = `shell001 = shell({ faces = ['end'], thickness = 5 }, ${
const shellDeclaration = `shell001 = shell(${shellTarget}, faces = ['end'], thickness = 5)` hasExtrudesInPipe ? 'sketch002' : 'extrude002'
})`
await test.step(`Look for the grey of the shape`, async () => { await test.step(`Look for the grey of the shape`, async () => {
await toolbar.closePane('code') await toolbar.closePane('code')
@ -2547,7 +2242,7 @@ extrude002 = extrude(sketch002, length = 50)
sketch002 = startSketchOn('XZ') sketch002 = startSketchOn('XZ')
|> startProfileAt([0, 0], %) |> startProfileAt([0, 0], %)
|> xLine(-2000, %) |> xLine(-2000, %)
sweep001 = sweep(sketch001, path = sketch002) sweep001 = sweep({ path = sketch002 }, sketch001)
` `
await context.addInitScript((initialCode) => { await context.addInitScript((initialCode) => {
localStorage.setItem('persistCode', initialCode) localStorage.setItem('persistCode', initialCode)

View File

@ -455,7 +455,7 @@ test.describe('Can export from electron app', () => {
for (const method of exportMethods) { for (const method of exportMethods) {
test( test(
`Can export using ${method}`, `Can export using ${method}`,
{ tag: ['@electron', '@skipLocalEngine'] }, { tag: '@electron' },
async ({ context, page }, testInfo) => { async ({ context, page }, testInfo) => {
await context.folderSetupFn(async (dir) => { await context.folderSetupFn(async (dir) => {
const bracketDir = path.join(dir, 'bracket') const bracketDir = path.join(dir, 'bracket')

View File

@ -35,113 +35,106 @@ sketch003 = startSketchOn('XY')
extrude003 = extrude(sketch003, length = 20) extrude003 = extrude(sketch003, length = 20)
` `
test.describe('Prompt-to-edit tests', { tag: '@skipWin' }, () => { test.describe('Check the happy path, for basic changing color', () => {
test.fixme('Check the happy path, for basic changing color', () => { const cases = [
const cases = [ {
{ desc: 'User accepts change',
desc: 'User accepts change', shouldReject: false,
shouldReject: false, },
}, {
{ desc: 'User rejects change',
desc: 'User rejects change', shouldReject: true,
shouldReject: true, },
}, ] as const
] as const for (const { desc, shouldReject } of cases) {
for (const { desc, shouldReject } of cases) { test(`${desc}`, async ({
test(`${desc}`, async ({ context,
context, homePage,
homePage, cmdBar,
cmdBar, editor,
editor, page,
page, scene,
scene, }) => {
}) => { await context.addInitScript((file) => {
await context.addInitScript((file) => { localStorage.setItem('persistCode', file)
localStorage.setItem('persistCode', file) }, file)
}, file) await homePage.goToModelingScene()
await homePage.goToModelingScene()
await scene.waitForExecutionDone()
const body1CapCoords = { x: 571, y: 351 } const body1CapCoords = { x: 571, y: 351 }
const greenCheckCoords = { x: 565, y: 345 } const greenCheckCoords = { x: 565, y: 345 }
const body2WallCoords = { x: 609, y: 153 } const body2WallCoords = { x: 609, y: 153 }
const [clickBody1Cap] = scene.makeMouseHelpers( const [clickBody1Cap] = scene.makeMouseHelpers(
body1CapCoords.x, body1CapCoords.x,
body1CapCoords.y body1CapCoords.y
) )
const yellow: [number, number, number] = [179, 179, 131] const yellow: [number, number, number] = [179, 179, 131]
const green: [number, number, number] = [108, 152, 75] const green: [number, number, number] = [108, 152, 75]
const notGreen: [number, number, number] = [132, 132, 132] const notGreen: [number, number, number] = [132, 132, 132]
const body2NotGreen: [number, number, number] = [88, 88, 88] const body2NotGreen: [number, number, number] = [88, 88, 88]
const submittingToast = page.getByText( const submittingToast = page.getByText('Submitting to Text-to-CAD API...')
'Submitting to Text-to-CAD API...' const successToast = page.getByText('Prompt to edit successful')
) const acceptBtn = page.getByRole('button', { name: 'checkmark Accept' })
const successToast = page.getByText('Prompt to edit successful') const rejectBtn = page.getByRole('button', { name: 'close Reject' })
const acceptBtn = page.getByRole('button', {
name: 'checkmark Accept', await test.step('wait for scene to load select body and check selection came through', async () => {
await scene.expectPixelColor([134, 134, 134], body1CapCoords, 15)
await clickBody1Cap()
await scene.expectPixelColor(yellow, body1CapCoords, 20)
await editor.expectState({
highlightedCode: '',
activeLines: ['|>startProfileAt([-73.64,-42.89],%)'],
diagnostics: [],
}) })
const rejectBtn = page.getByRole('button', { name: 'close Reject' })
await test.step('wait for scene to load select body and check selection came through', async () => {
await scene.expectPixelColor([134, 134, 134], body1CapCoords, 15)
await clickBody1Cap()
await scene.expectPixelColor(yellow, body1CapCoords, 20)
await editor.expectState({
highlightedCode: '',
activeLines: ['|>startProfileAt([-73.64,-42.89],%)'],
diagnostics: [],
})
})
await test.step('fire off edit prompt', async () => {
await cmdBar.openCmdBar('promptToEdit')
// being specific about the color with a hex means asserting pixel color is more stable
await page
.getByTestId('cmd-bar-arg-value')
.fill('make this neon green please, use #39FF14')
await page.waitForTimeout(100)
await cmdBar.progressCmdBar()
await expect(submittingToast).toBeVisible()
await expect(submittingToast).not.toBeVisible({
timeout: 2 * 60_000,
}) // can take a while
await expect(successToast).toBeVisible()
})
await test.step('verify initial change', async () => {
await scene.expectPixelColor(green, greenCheckCoords, 15)
await scene.expectPixelColor(body2NotGreen, body2WallCoords, 15)
await editor.expectEditor.toContain('appearance(')
})
if (!shouldReject) {
await test.step('check accept works and can be "undo"ed', async () => {
await acceptBtn.click()
await expect(successToast).not.toBeVisible()
await scene.expectPixelColor(green, greenCheckCoords, 15)
await editor.expectEditor.toContain('appearance(')
// ctrl-z works after accepting
await page.keyboard.down('ControlOrMeta')
await page.keyboard.press('KeyZ')
await page.keyboard.up('ControlOrMeta')
await editor.expectEditor.not.toContain('appearance(')
await scene.expectPixelColor(notGreen, greenCheckCoords, 15)
})
} else {
await test.step('check reject works', async () => {
await rejectBtn.click()
await expect(successToast).not.toBeVisible()
await scene.expectPixelColor(notGreen, greenCheckCoords, 15)
await editor.expectEditor.not.toContain('appearance(')
})
}
}) })
}
})
await test.step('fire off edit prompt', async () => {
await cmdBar.openCmdBar('promptToEdit')
// being specific about the color with a hex means asserting pixel color is more stable
await page
.getByTestId('cmd-bar-arg-value')
.fill('make this neon green please, use #39FF14')
await page.waitForTimeout(100)
await cmdBar.progressCmdBar()
await expect(submittingToast).toBeVisible()
await expect(submittingToast).not.toBeVisible({ timeout: 2 * 60_000 }) // can take a while
await expect(successToast).toBeVisible()
})
await test.step('verify initial change', async () => {
await scene.expectPixelColor(green, greenCheckCoords, 15)
await scene.expectPixelColor(body2NotGreen, body2WallCoords, 15)
await editor.expectEditor.toContain('appearance({')
})
if (!shouldReject) {
await test.step('check accept works and can be "undo"ed', async () => {
await acceptBtn.click()
await expect(successToast).not.toBeVisible()
await scene.expectPixelColor(green, greenCheckCoords, 15)
await editor.expectEditor.toContain('appearance({')
// ctrl-z works after accepting
await page.keyboard.down('ControlOrMeta')
await page.keyboard.press('KeyZ')
await page.keyboard.up('ControlOrMeta')
await editor.expectEditor.not.toContain('appearance({')
await scene.expectPixelColor(notGreen, greenCheckCoords, 15)
})
} else {
await test.step('check reject works', async () => {
await rejectBtn.click()
await expect(successToast).not.toBeVisible()
await scene.expectPixelColor(notGreen, greenCheckCoords, 15)
await editor.expectEditor.not.toContain('appearance({')
})
}
})
}
})
test.describe('bad path', { tag: ['@skipWin'] }, () => {
test(`bad edit prompt`, async ({ test(`bad edit prompt`, async ({
context, context,
homePage, homePage,
@ -155,7 +148,6 @@ test.describe('Prompt-to-edit tests', { tag: '@skipWin' }, () => {
localStorage.setItem('persistCode', file) localStorage.setItem('persistCode', file)
}, file) }, file)
await homePage.goToModelingScene() await homePage.goToModelingScene()
await scene.waitForExecutionDone()
const body1CapCoords = { x: 571, y: 351 } const body1CapCoords = { x: 571, y: 351 }
const [clickBody1Cap] = scene.makeMouseHelpers( const [clickBody1Cap] = scene.makeMouseHelpers(

View File

@ -253,7 +253,7 @@ extrude001 = extrude(sketch001, length = 50)
|> |>
example = extrude(exampleSketch, length = 5) example = extrude(exampleSketch, length = 5)
shell(exampleSketch, faces = ['end'], thickness = 0.25)` shell({ faces: ['end'], thickness: 0.25 }, exampleSketch)`
) )
}) })
@ -313,106 +313,108 @@ extrude001 = extrude(sketch001, length = 50)
} }
) )
test( test('when engine fails export we handle the failure and alert the user', async ({
'when engine fails export we handle the failure and alert the user', page,
{ tag: '@skipLocalEngine' }, homePage,
async ({ scene, page, homePage }) => { }) => {
const u = await getUtils(page) const u = await getUtils(page)
await page.addInitScript( await page.addInitScript(
async ({ code }) => { async ({ code }) => {
localStorage.setItem('persistCode', code) localStorage.setItem('persistCode', code)
;(window as any).playwrightSkipFilePicker = true ;(window as any).playwrightSkipFilePicker = true
}, },
{ code: TEST_CODE_TRIGGER_ENGINE_EXPORT_ERROR } { code: TEST_CODE_TRIGGER_ENGINE_EXPORT_ERROR }
) )
await page.setBodyDimensions({ width: 1000, height: 500 }) await page.setBodyDimensions({ width: 1000, height: 500 })
await homePage.goToModelingScene() await homePage.goToModelingScene()
await u.waitForPageLoad() await u.waitForPageLoad()
// wait for execution done // wait for execution done
await u.openDebugPanel() await u.openDebugPanel()
await u.expectCmdLog('[data-message-type="execution-done"]') await u.expectCmdLog('[data-message-type="execution-done"]')
await u.closeDebugPanel() await u.closeDebugPanel()
// expect zero errors in guter // expect zero errors in guter
await expect(page.locator('.cm-lint-marker-error')).not.toBeVisible() await expect(page.locator('.cm-lint-marker-error')).not.toBeVisible()
// export the model // export the model
const exportButton = page.getByTestId('export-pane-button') const exportButton = page.getByTestId('export-pane-button')
await expect(exportButton).toBeVisible() await expect(exportButton).toBeVisible()
// Click the export button // Click the export button
await exportButton.click() await exportButton.click()
// Click the stl. // Click the stl.
const stlOption = page.getByText('glTF') const stlOption = page.getByText('glTF')
await expect(stlOption).toBeVisible() await expect(stlOption).toBeVisible()
await page.keyboard.press('Enter') await page.keyboard.press('Enter')
// Click the checkbox // Click the checkbox
const submitButton = page.getByText('Confirm Export') const submitButton = page.getByText('Confirm Export')
await expect(submitButton).toBeVisible() await expect(submitButton).toBeVisible()
await page.keyboard.press('Enter') await page.keyboard.press('Enter')
// Find the toast. // Find the toast.
// Look out for the toast message // Look out for the toast message
const exportingToastMessage = page.getByText(`Exporting...`) const exportingToastMessage = page.getByText(`Exporting...`)
const errorToastMessage = page.getByText(`Error while exporting`) const errorToastMessage = page.getByText(`Error while exporting`)
const engineErrorToastMessage = page.getByText(`Nothing to export`) const engineErrorToastMessage = page.getByText(`Nothing to export`)
await expect(engineErrorToastMessage).toBeVisible() await expect(engineErrorToastMessage).toBeVisible()
// Make sure the exporting toast is gone // Make sure the exporting toast is gone
await expect(exportingToastMessage).not.toBeVisible() await expect(exportingToastMessage).not.toBeVisible()
// Click the code editor // Click the code editor
await page.locator('.cm-content').click() await page.locator('.cm-content').click()
await page.waitForTimeout(2000) await page.waitForTimeout(2000)
// Expect the toast to be gone // Expect the toast to be gone
await expect(errorToastMessage).not.toBeVisible() await expect(errorToastMessage).not.toBeVisible()
await expect(engineErrorToastMessage).not.toBeVisible() await expect(engineErrorToastMessage).not.toBeVisible()
// Now add in code that works. // Now add in code that works.
await page.locator('.cm-content').fill(bracket) await page.locator('.cm-content').fill(bracket)
await page.keyboard.press('End') await page.keyboard.press('End')
await page.keyboard.press('Enter') await page.keyboard.press('Enter')
await scene.waitForExecutionDone() // wait for execution done
await u.openDebugPanel()
await u.expectCmdLog('[data-message-type="execution-done"]')
await u.closeDebugPanel()
// Now try exporting // Now try exporting
// Click the export button // Click the export button
await exportButton.click() await exportButton.click()
// Click the stl. // Click the stl.
await expect(stlOption).toBeVisible() await expect(stlOption).toBeVisible()
await page.keyboard.press('Enter') await page.keyboard.press('Enter')
// Click the checkbox // Click the checkbox
await expect(submitButton).toBeVisible() await expect(submitButton).toBeVisible()
await page.keyboard.press('Enter') await page.keyboard.press('Enter')
// Find the toast. // Find the toast.
// Look out for the toast message // Look out for the toast message
await expect(exportingToastMessage).toBeVisible() await expect(exportingToastMessage).toBeVisible()
// Expect it to succeed. // Expect it to succeed.
await expect(exportingToastMessage).not.toBeVisible({ timeout: 15_000 }) await expect(exportingToastMessage).not.toBeVisible({ timeout: 15_000 })
await expect(errorToastMessage).not.toBeVisible() await expect(errorToastMessage).not.toBeVisible()
await expect(engineErrorToastMessage).not.toBeVisible() await expect(engineErrorToastMessage).not.toBeVisible()
const successToastMessage = page.getByText(`Exported successfully`) const successToastMessage = page.getByText(`Exported successfully`)
await expect(successToastMessage).toBeVisible() await expect(successToastMessage).toBeVisible()
} })
)
test( test(
'ensure you can not export while an export is already going', 'ensure you can not export while an export is already going',
{ tag: ['@skipLinux', '@skipWin'] }, { tag: ['@skipLinux', '@skipWin'] },

File diff suppressed because it is too large Load Diff

View File

@ -444,8 +444,7 @@ test(
const startXPx = 600 const startXPx = 600
await page.mouse.click(startXPx + PUR * 10, 500 - PUR * 10) await page.mouse.click(startXPx + PUR * 10, 500 - PUR * 10)
code += ` code += `profile001 = startProfileAt([7.19, -9.7], sketch001)`
|> startProfileAt([7.19, -9.7], %)`
await expect(page.locator('.cm-content')).toHaveText(code) await expect(page.locator('.cm-content')).toHaveText(code)
await page.waitForTimeout(100) await page.waitForTimeout(100)
@ -467,6 +466,10 @@ test(
.getByRole('button', { name: 'arc Tangential Arc', exact: true }) .getByRole('button', { name: 'arc Tangential Arc', exact: true })
.click() .click()
// click to continue profile
await page.mouse.move(813, 392, { steps: 10 })
await page.waitForTimeout(100)
await page.mouse.move(startXPx + PUR * 30, 500 - PUR * 20, { steps: 10 }) await page.mouse.move(startXPx + PUR * 30, 500 - PUR * 20, { steps: 10 })
await page.waitForTimeout(1000) await page.waitForTimeout(1000)
@ -589,8 +592,7 @@ test(
mask: [page.getByTestId('model-state-indicator')], mask: [page.getByTestId('model-state-indicator')],
}) })
await expect(page.locator('.cm-content')).toHaveText( await expect(page.locator('.cm-content')).toHaveText(
`sketch001 = startSketchOn('XZ') `sketch001 = startSketchOn('XZ')profile001 = circle({ center = [14.44, -2.44], radius = 1 }, sketch001)`
|> circle({ center = [14.44, -2.44], radius = 1 }, %)`
) )
} }
) )
@ -634,8 +636,7 @@ test.describe(
const startXPx = 600 const startXPx = 600
await page.mouse.click(startXPx + PUR * 10, 500 - PUR * 10) await page.mouse.click(startXPx + PUR * 10, 500 - PUR * 10)
code += ` code += `profile001 = startProfileAt([7.19, -9.7], sketch001)`
|> startProfileAt([7.19, -9.7], %)`
await expect(u.codeLocator).toHaveText(code) await expect(u.codeLocator).toHaveText(code)
await page.waitForTimeout(100) await page.waitForTimeout(100)
@ -653,6 +654,10 @@ test.describe(
.click() .click()
await page.waitForTimeout(100) await page.waitForTimeout(100)
// click to continue profile
await page.mouse.click(813, 392)
await page.waitForTimeout(100)
await page.mouse.click(startXPx + PUR * 30, 500 - PUR * 20) await page.mouse.click(startXPx + PUR * 30, 500 - PUR * 20)
code += ` code += `
@ -739,8 +744,7 @@ test.describe(
const startXPx = 600 const startXPx = 600
await page.mouse.click(startXPx + PUR * 10, 500 - PUR * 10) await page.mouse.click(startXPx + PUR * 10, 500 - PUR * 10)
code += ` code += `profile001 = startProfileAt([182.59, -246.32], sketch001)`
|> startProfileAt([182.59, -246.32], %)`
await expect(u.codeLocator).toHaveText(code) await expect(u.codeLocator).toHaveText(code)
await page.waitForTimeout(100) await page.waitForTimeout(100)
@ -758,6 +762,10 @@ test.describe(
.click() .click()
await page.waitForTimeout(100) await page.waitForTimeout(100)
// click to continue profile
await page.mouse.click(813, 392)
await page.waitForTimeout(100)
await page.mouse.click(startXPx + PUR * 30, 500 - PUR * 20) await page.mouse.click(startXPx + PUR * 30, 500 - PUR * 20)
code += ` code += `
@ -1187,12 +1195,14 @@ sweepSketch = startSketchOn('XY')
angleStart = 0, angleStart = 0,
radius = 2 radius = 2
}, %) }, %)
|> sweep(path = sweepPath) |> sweep({
|> appearance( path = sweepPath,
}, %)
|> appearance({
color = "#bb00ff", color = "#bb00ff",
metalness = 90, metalness = 90,
roughness = 90 roughness = 90
) }, %)
` `
) )
}) })
@ -1233,12 +1243,14 @@ sweepSketch = startSketchOn('XY')
angleStart = 0, angleStart = 0,
radius = 2 radius = 2
}, %) }, %)
|> sweep(path = sweepPath) |> sweep({
|> appearance( path = sweepPath,
}, %)
|> appearance({
color = "#bb00ff", color = "#bb00ff",
metalness = 90, metalness = 90,
roughness = 90 roughness = 90
) }, %)
` `
) )
}) })

Binary file not shown.

Before

Width:  |  Height:  |  Size: 54 KiB

After

Width:  |  Height:  |  Size: 55 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 52 KiB

After

Width:  |  Height:  |  Size: 53 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 60 KiB

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 54 KiB

After

Width:  |  Height:  |  Size: 55 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 48 KiB

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 44 KiB

After

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 42 KiB

After

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 44 KiB

After

Width:  |  Height:  |  Size: 51 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 76 KiB

After

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 51 KiB

After

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 67 KiB

After

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 143 KiB

After

Width:  |  Height:  |  Size: 145 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 127 KiB

After

Width:  |  Height:  |  Size: 129 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 49 KiB

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 54 KiB

After

Width:  |  Height:  |  Size: 53 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 54 KiB

After

Width:  |  Height:  |  Size: 54 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 49 KiB

After

Width:  |  Height:  |  Size: 49 KiB

View File

@ -1,224 +1,249 @@
import { test, expect } from './zoo-test' import { test, expect } from './zoo-test'
import { commonPoints, getUtils } from './test-utils' import { commonPoints, getUtils } from './test-utils'
import { EngineCommand } from 'lang/std/artifactGraph'
import { uuidv4 } from 'lib/utils'
test.describe('Test network and connection issues', () => { test.describe('Test network and connection issues', () => {
test( test('simulate network down and network little widget', async ({
'simulate network down and network little widget', page,
{ tag: '@skipLocalEngine' }, homePage,
async ({ page, homePage }) => { }) => {
const u = await getUtils(page) const u = await getUtils(page)
await page.setBodyDimensions({ width: 1200, height: 500 }) await page.setBodyDimensions({ width: 1200, height: 500 })
await homePage.goToModelingScene() await homePage.goToModelingScene()
const networkToggle = page.getByTestId('network-toggle') const networkToggle = page.getByTestId('network-toggle')
// This is how we wait until the stream is online // This is how we wait until the stream is online
await expect( await expect(
page.getByRole('button', { name: 'Start Sketch' }) page.getByRole('button', { name: 'Start Sketch' })
).not.toBeDisabled({ timeout: 15000 }) ).not.toBeDisabled({ timeout: 15000 })
const networkWidget = page.locator('[data-testid="network-toggle"]') const networkWidget = page.locator('[data-testid="network-toggle"]')
await expect(networkWidget).toBeVisible() await expect(networkWidget).toBeVisible()
await networkWidget.hover() await networkWidget.hover()
const networkPopover = page.locator('[data-testid="network-popover"]') const networkPopover = page.locator('[data-testid="network-popover"]')
await expect(networkPopover).not.toBeVisible() await expect(networkPopover).not.toBeVisible()
// (First check) Expect the network to be up // (First check) Expect the network to be up
await expect(networkToggle).toContainText('Connected') await expect(networkToggle).toContainText('Connected')
// Click the network widget // Click the network widget
await networkWidget.click() await networkWidget.click()
// Check the modal opened. // Check the modal opened.
await expect(networkPopover).toBeVisible() await expect(networkPopover).toBeVisible()
// Click off the modal. // Click off the modal.
await page.mouse.click(100, 100) await page.mouse.click(100, 100)
await expect(networkPopover).not.toBeVisible() await expect(networkPopover).not.toBeVisible()
// Turn off the network // Turn off the network
await u.emulateNetworkConditions({ await u.emulateNetworkConditions({
offline: true, offline: true,
// values of 0 remove any active throttling. crbug.com/456324#c9 // values of 0 remove any active throttling. crbug.com/456324#c9
latency: 0, latency: 0,
downloadThroughput: -1, downloadThroughput: -1,
uploadThroughput: -1, uploadThroughput: -1,
}) })
// Expect the network to be down // Expect the network to be down
await expect(networkToggle).toContainText('Problem') await expect(networkToggle).toContainText('Problem')
// Click the network widget // Click the network widget
await networkWidget.click() await networkWidget.click()
// Check the modal opened. // Check the modal opened.
await expect(networkPopover).toBeVisible() await expect(networkPopover).toBeVisible()
// Click off the modal. // Click off the modal.
await page.mouse.click(0, 0) await page.mouse.click(0, 0)
await expect(networkPopover).not.toBeVisible() await expect(networkPopover).not.toBeVisible()
// Turn back on the network // Turn back on the network
await u.emulateNetworkConditions({ await u.emulateNetworkConditions({
offline: false, offline: false,
// values of 0 remove any active throttling. crbug.com/456324#c9 // values of 0 remove any active throttling. crbug.com/456324#c9
latency: 0, latency: 0,
downloadThroughput: -1, downloadThroughput: -1,
uploadThroughput: -1, uploadThroughput: -1,
}) })
await expect( await expect(
page.getByRole('button', { name: 'Start Sketch' }) page.getByRole('button', { name: 'Start Sketch' })
).not.toBeDisabled({ timeout: 15000 }) ).not.toBeDisabled({ timeout: 15000 })
// (Second check) expect the network to be up // (Second check) expect the network to be up
await expect(networkToggle).toContainText('Connected') await expect(networkToggle).toContainText('Connected')
})
test('Engine disconnect & reconnect in sketch mode', async ({
page,
homePage,
}) => {
// TODO: Don't skip Mac for these. After `window.tearDown` is working in Safari, these should work on webkit
const networkToggle = page.getByTestId('network-toggle')
const u = await getUtils(page)
await page.setBodyDimensions({ width: 1200, height: 500 })
const PUR = 400 / 37.5 //pixeltoUnitRatio
await homePage.goToModelingScene()
await u.waitForPageLoad()
await u.openDebugPanel()
// click on "Start Sketch" button
await u.clearCommandLogs()
await page.getByRole('button', { name: 'Start Sketch' }).click()
await page.waitForTimeout(100)
// select a plane
await page.mouse.click(700, 200)
await expect(page.locator('.cm-content')).toHaveText(
`sketch001 = startSketchOn('XZ')`
)
await u.closeDebugPanel()
await page.waitForTimeout(500) // TODO detect animation ending, or disable animation
const startXPx = 600
await page.mouse.click(startXPx + PUR * 10, 500 - PUR * 10)
await expect(page.locator('.cm-content')).toHaveText(
`sketch001 = startSketchOn('XZ')profile001 = startProfileAt(${commonPoints.startAt}, sketch001)`
)
await page.waitForTimeout(100)
await page.mouse.click(startXPx + PUR * 20, 500 - PUR * 10)
await page.waitForTimeout(100)
await expect(page.locator('.cm-content'))
.toHaveText(`sketch001 = startSketchOn('XZ')profile001 = startProfileAt(${commonPoints.startAt}, sketch001)
|> xLine(${commonPoints.num1}, %)`)
// Expect the network to be up
await expect(networkToggle).toContainText('Connected')
// simulate network down
await u.emulateNetworkConditions({
offline: true,
// values of 0 remove any active throttling. crbug.com/456324#c9
latency: 0,
downloadThroughput: -1,
uploadThroughput: -1,
})
// Expect the network to be down
await expect(networkToggle).toContainText('Problem')
// Ensure we are not in sketch mode
await expect(
page.getByRole('button', { name: 'Exit Sketch' })
).not.toBeVisible()
await expect(
page.getByRole('button', { name: 'Start Sketch' })
).toBeVisible()
// simulate network up
await u.emulateNetworkConditions({
offline: false,
// values of 0 remove any active throttling. crbug.com/456324#c9
latency: 0,
downloadThroughput: -1,
uploadThroughput: -1,
})
// Wait for the app to be ready for use
await expect(
page.getByRole('button', { name: 'Start Sketch' })
).not.toBeDisabled({ timeout: 15000 })
// Expect the network to be up
await expect(networkToggle).toContainText('Connected')
await expect(page.getByTestId('loading-stream')).not.toBeAttached()
// Click off the code pane.
await page.mouse.click(100, 100)
// select a line
await page
.getByText(`startProfileAt(${commonPoints.startAt}, sketch001)`)
.click()
// enter sketch again
await u.doAndWaitForCmd(
() => page.getByRole('button', { name: 'Edit Sketch' }).click(),
'default_camera_get_settings'
)
await page.waitForTimeout(150)
// Click the line tool
await page.getByRole('button', { name: 'line Line', exact: true }).click()
await page.waitForTimeout(150)
const camCommand: EngineCommand = {
type: 'modeling_cmd_req',
cmd_id: uuidv4(),
cmd: {
type: 'default_camera_look_at',
center: { x: 109, y: 0, z: -152 },
vantage: { x: 115, y: -505, z: -152 },
up: { x: 0, y: 0, z: 1 },
},
} }
) const updateCamCommand: EngineCommand = {
type: 'modeling_cmd_req',
cmd_id: uuidv4(),
cmd: {
type: 'default_camera_get_settings',
},
}
await u.sendCustomCmd(camCommand)
await page.waitForTimeout(100)
await u.sendCustomCmd(updateCamCommand)
await page.waitForTimeout(100)
test( // click to continue profile
'Engine disconnect & reconnect in sketch mode', await page.mouse.click(1007, 400)
{ tag: '@skipLocalEngine' }, await page.waitForTimeout(100)
async ({ page, homePage }) => { // Ensure we can continue sketching
// TODO: Don't skip Mac for these. After `window.tearDown` is working in Safari, these should work on webkit await page.mouse.click(startXPx + PUR * 20, 500 - PUR * 20)
const networkToggle = page.getByTestId('network-toggle') await expect.poll(u.normalisedEditorCode)
.toBe(`sketch001 = startSketchOn('XZ')
const u = await getUtils(page) profile001 = startProfileAt([12.34, -12.34], sketch001)
await page.setBodyDimensions({ width: 1200, height: 500 })
const PUR = 400 / 37.5 //pixeltoUnitRatio
await homePage.goToModelingScene()
await u.waitForPageLoad()
await u.openDebugPanel()
// click on "Start Sketch" button
await u.clearCommandLogs()
await page.getByRole('button', { name: 'Start Sketch' }).click()
await page.waitForTimeout(100)
// select a plane
await page.mouse.click(700, 200)
await expect(page.locator('.cm-content')).toHaveText(
`sketch001 = startSketchOn('XZ')`
)
await u.closeDebugPanel()
await page.waitForTimeout(500) // TODO detect animation ending, or disable animation
const startXPx = 600
await page.mouse.click(startXPx + PUR * 10, 500 - PUR * 10)
await expect(page.locator('.cm-content'))
.toHaveText(`sketch001 = startSketchOn('XZ')
|> startProfileAt(${commonPoints.startAt}, %)`)
await page.waitForTimeout(100)
await page.mouse.click(startXPx + PUR * 20, 500 - PUR * 10)
await page.waitForTimeout(100)
await expect(page.locator('.cm-content'))
.toHaveText(`sketch001 = startSketchOn('XZ')
|> startProfileAt(${commonPoints.startAt}, %)
|> xLine(${commonPoints.num1}, %)`)
// Expect the network to be up
await expect(networkToggle).toContainText('Connected')
// simulate network down
await u.emulateNetworkConditions({
offline: true,
// values of 0 remove any active throttling. crbug.com/456324#c9
latency: 0,
downloadThroughput: -1,
uploadThroughput: -1,
})
// Expect the network to be down
await expect(networkToggle).toContainText('Problem')
// Ensure we are not in sketch mode
await expect(
page.getByRole('button', { name: 'Exit Sketch' })
).not.toBeVisible()
await expect(
page.getByRole('button', { name: 'Start Sketch' })
).toBeVisible()
// simulate network up
await u.emulateNetworkConditions({
offline: false,
// values of 0 remove any active throttling. crbug.com/456324#c9
latency: 0,
downloadThroughput: -1,
uploadThroughput: -1,
})
// Wait for the app to be ready for use
await expect(
page.getByRole('button', { name: 'Start Sketch' })
).not.toBeDisabled({ timeout: 15000 })
// Expect the network to be up
await expect(networkToggle).toContainText('Connected')
await expect(page.getByTestId('loading-stream')).not.toBeAttached()
// Click off the code pane.
await page.mouse.click(100, 100)
// select a line
await page.getByText(`startProfileAt(${commonPoints.startAt}, %)`).click()
// enter sketch again
await u.doAndWaitForCmd(
() => page.getByRole('button', { name: 'Edit Sketch' }).click(),
'default_camera_get_settings'
)
await page.waitForTimeout(150)
// Click the line tool
await page.getByRole('button', { name: 'line Line', exact: true }).click()
await page.waitForTimeout(150)
// Ensure we can continue sketching
await page.mouse.click(startXPx + PUR * 20, 500 - PUR * 20)
await expect.poll(u.normalisedEditorCode)
.toBe(`sketch001 = startSketchOn('XZ')
|> startProfileAt([12.34, -12.34], %)
|> xLine(12.34, %) |> xLine(12.34, %)
|> line(end = [-12.34, 12.34]) |> line(end = [-12.34, 12.34])
`) `)
await page.waitForTimeout(100) await page.waitForTimeout(100)
await page.mouse.click(startXPx, 500 - PUR * 20) await page.mouse.click(startXPx, 500 - PUR * 20)
await expect.poll(u.normalisedEditorCode) await expect.poll(u.normalisedEditorCode)
.toBe(`sketch001 = startSketchOn('XZ') .toBe(`sketch001 = startSketchOn('XZ')
|> startProfileAt([12.34, -12.34], %) profile001 = startProfileAt([12.34, -12.34], sketch001)
|> xLine(12.34, %) |> xLine(12.34, %)
|> line(end = [-12.34, 12.34]) |> line(end = [-12.34, 12.34])
|> xLine(-12.34, %) |> xLine(-12.34, %)
`) `)
// Unequip line tool // Unequip line tool
await page.keyboard.press('Escape') await page.keyboard.press('Escape')
// Make sure we didn't pop out of sketch mode. // Make sure we didn't pop out of sketch mode.
await expect( await expect(
page.getByRole('button', { name: 'Exit Sketch' }) page.getByRole('button', { name: 'Exit Sketch' })
).toBeVisible() ).toBeVisible()
await expect( await expect(
page.getByRole('button', { name: 'line Line', exact: true }) page.getByRole('button', { name: 'line Line', exact: true })
).not.toHaveAttribute('aria-pressed', 'true') ).not.toHaveAttribute('aria-pressed', 'true')
// Exit sketch // Exit sketch
await page.keyboard.press('Escape') await page.keyboard.press('Escape')
await expect( await expect(
page.getByRole('button', { name: 'Exit Sketch' }) page.getByRole('button', { name: 'Exit Sketch' })
).not.toBeVisible() ).not.toBeVisible()
} })
)
}) })

View File

@ -109,8 +109,7 @@ test.describe('Testing Camera Movement', { tag: ['@skipWin'] }, () => {
await page.keyboard.down('Shift') await page.keyboard.down('Shift')
await page.mouse.move(600, 200) await page.mouse.move(600, 200)
await page.mouse.down({ button: 'right' }) await page.mouse.down({ button: 'right' })
// Gotcha: remove steps:2 from this 700,200 mouse move. This bricked the test on local host engine. await page.mouse.move(700, 200, { steps: 2 })
await page.mouse.move(700, 200)
await page.mouse.up({ button: 'right' }) await page.mouse.up({ button: 'right' })
await page.keyboard.up('Shift') await page.keyboard.up('Shift')
}, [-19, -85, -85]) }, [-19, -85, -85])

View File

@ -19,7 +19,7 @@ test.describe('Testing constraints', { tag: ['@skipWin'] }, () => {
|> line(end = [20, 0]) |> line(end = [20, 0])
|> line(end = [0, 20]) |> line(end = [0, 20])
|> xLine(-20, %) |> xLine(-20, %)
` `
) )
}) })
@ -673,7 +673,7 @@ test.describe('Testing constraints', { tag: ['@skipWin'] }, () => {
}, },
] as const ] as const
for (const { testName, addVariable, value, constraint } of cases) { for (const { testName, addVariable, value, constraint } of cases) {
test(`${testName}`, async ({ context, homePage, page }) => { test(`${testName}`, async ({ context, homePage, page, editor }) => {
// constants and locators // constants and locators
const cmdBarKclInput = page const cmdBarKclInput = page
.getByTestId('cmd-bar-arg-value') .getByTestId('cmd-bar-arg-value')
@ -706,8 +706,11 @@ part002 = startSketchOn('XZ')
await page.setBodyDimensions({ width: 1200, height: 500 }) await page.setBodyDimensions({ width: 1200, height: 500 })
await homePage.goToModelingScene() await homePage.goToModelingScene()
await u.waitForPageLoad()
await page.getByText('line(end = [74.36, 130.4])').click() await editor.scrollToText('line(end = [74.36, 130.4], %)', true)
await page.getByText('line(end = [74.36, 130.4], %)').click()
await page.screenshot({ path: 'ok.png' })
await page.getByRole('button', { name: 'Edit Sketch' }).click() await page.getByRole('button', { name: 'Edit Sketch' }).click()
const line3 = await u.getSegmentBodyCoords( const line3 = await u.getSegmentBodyCoords(

View File

@ -63,36 +63,41 @@ test.describe('Testing selections', { tag: ['@skipWin'] }, () => {
await page.mouse.click(700, 200) await page.mouse.click(700, 200)
await page.waitForTimeout(700) // wait for animation await page.waitForTimeout(700) // wait for animation
// select a plane
await page.mouse.click(700, 200)
await page.waitForTimeout(700) // wait for animation
const startXPx = 600 const startXPx = 600
await u.closeDebugPanel() await u.closeDebugPanel()
await page.mouse.click(startXPx + PUR * 10, 500 - PUR * 10) await page.mouse.click(startXPx + PUR * 10, 500 - PUR * 10)
await expect(page.locator('.cm-content')) await expect(page.locator('.cm-content')).toHaveText(
.toHaveText(`sketch001 = startSketchOn('XZ') `sketch001 = startSketchOn('XZ')profile001 = startProfileAt(${commonPoints.startAt}, sketch001)`
|> startProfileAt(${commonPoints.startAt}, %)`) )
await page.waitForTimeout(100) await page.waitForTimeout(100)
await page.mouse.click(startXPx + PUR * 20, 500 - PUR * 10) await page.mouse.click(startXPx + PUR * 20, 500 - PUR * 10)
await expect(page.locator('.cm-content')) await expect(page.locator('.cm-content'))
.toHaveText(`sketch001 = startSketchOn('XZ') .toHaveText(`sketch001 = startSketchOn('XZ')profile001 = startProfileAt(${commonPoints.startAt}, sketch001)
|> startProfileAt(${commonPoints.startAt}, %) |> xLine(${commonPoints.num1}, %)`)
|> xLine(${commonPoints.num1}, %)`)
await page.waitForTimeout(100) await page.waitForTimeout(100)
await page.mouse.click(startXPx + PUR * 20, 500 - PUR * 20) await page.mouse.click(startXPx + PUR * 20, 500 - PUR * 20)
await expect(page.locator('.cm-content')) await expect(page.locator('.cm-content'))
.toHaveText(`sketch001 = startSketchOn('XZ') .toHaveText(`sketch001 = startSketchOn('XZ')profile001 = startProfileAt(${
|> startProfileAt(${commonPoints.startAt}, %) commonPoints.startAt
|> xLine(${commonPoints.num1}, %) }, sketch001)
|> yLine(${commonPoints.num1 + 0.01}, %)`) |> xLine(${commonPoints.num1}, %)
|> yLine(${commonPoints.num1 + 0.01}, %)`)
await page.waitForTimeout(100) await page.waitForTimeout(100)
await page.mouse.click(startXPx, 500 - PUR * 20) await page.mouse.click(startXPx, 500 - PUR * 20)
await expect(page.locator('.cm-content')) await expect(page.locator('.cm-content'))
.toHaveText(`sketch001 = startSketchOn('XZ') .toHaveText(`sketch001 = startSketchOn('XZ')profile001 = startProfileAt(${
|> startProfileAt(${commonPoints.startAt}, %) commonPoints.startAt
|> xLine(${commonPoints.num1}, %) }, sketch001)
|> yLine(${commonPoints.num1 + 0.01}, %) |> xLine(${commonPoints.num1}, %)
|> xLine(${commonPoints.num2 * -1}, %)`) |> yLine(${commonPoints.num1 + 0.01}, %)
|> xLine(${commonPoints.num2 * -1}, %)`)
// deselect line tool // deselect line tool
await page.getByRole('button', { name: 'line Line', exact: true }).click() await page.getByRole('button', { name: 'line Line', exact: true }).click()
@ -248,83 +253,104 @@ test.describe('Testing selections', { tag: ['@skipWin'] }, () => {
}) })
}) })
test('Solids should be select and deletable', async ({ test('Solids should be select and deletable', async ({ page, homePage }) => {
page,
homePage,
scene,
}) => {
test.setTimeout(90_000) test.setTimeout(90_000)
const u = await getUtils(page) const u = await getUtils(page)
await page.addInitScript(async () => { await page.addInitScript(async () => {
localStorage.setItem( localStorage.setItem(
'persistCode', 'persistCode',
`sketch001 = startSketchOn('XZ') `sketch001 = startSketchOn('XZ')
|> startProfileAt([-79.26, 95.04], %) |> startProfileAt([-79.26, 95.04], %)
|> line(end = [112.54, 127.64], tag = $seg02) |> line(end=[112.54, 127.64], %, $seg02)
|> line(end = [170.36, -121.61], tag = $seg01) |> line(end=[170.36, -121.61], %, $seg01)
|> line(endAbsolute = [profileStartX(%), profileStartY(%)]) |> line(endAbsolute=[profileStartX(%), profileStartY(%)], %)
|> close() |> close(%)
extrude001 = extrude(sketch001, length = 50) extrude001 = extrude(50, sketch001)
sketch005 = startSketchOn(extrude001, 'END') sketch005 = startSketchOn(extrude001, 'END')
|> startProfileAt([23.24, 136.52], %) |> startProfileAt([23.24, 136.52], %)
|> line(end = [-8.44, 36.61]) |> line(end=[-8.44, 36.61], %)
|> line(end = [49.4, 2.05]) |> line(end=[49.4, 2.05], %)
|> line(end = [29.69, -46.95]) |> line(end=[29.69, -46.95], %)
|> line(endAbsolute = [profileStartX(%), profileStartY(%)]) |> line(endAbsolute=[profileStartX(%), profileStartY(%)], %)
|> close() |> close(%)
sketch003 = startSketchOn(extrude001, seg01) sketch003 = startSketchOn(extrude001, seg01)
|> startProfileAt([21.23, 17.81], %) |> startProfileAt([21.23, 17.81], %)
|> line(end = [51.97, 21.32]) |> line(end=[51.97, 21.32], %)
|> line(end = [4.07, -22.75]) |> line(end=[4.07, -22.75], %)
|> line(endAbsolute = [profileStartX(%), profileStartY(%)]) |> line(endAbsolute=[profileStartX(%), profileStartY(%)], %)
|> close() |> close(%)
sketch002 = startSketchOn(extrude001, seg02) sketch002 = startSketchOn(extrude001, seg02)
|> startProfileAt([-100.54, 16.99], %) |> startProfileAt([-100.54, 16.99], %)
|> line(end = [0, 20.03]) |> line(end=[0, 20.03], %)
|> line(end = [62.61, 0], tag = $seg03) |> line(end=[62.61, 0], %, $seg03)
|> line(endAbsolute = [profileStartX(%), profileStartY(%)]) |> line(endAbsolute=[profileStartX(%), profileStartY(%)], %)
|> close() |> close(%)
extrude002 = extrude(sketch002, length = 50) extrude002 = extrude(50, sketch002)
sketch004 = startSketchOn(extrude002, seg03) sketch004 = startSketchOn(extrude002, seg03)
|> startProfileAt([57.07, 134.77], %) |> startProfileAt([57.07, 134.77], %)
|> line(end = [-4.72, 22.84]) |> line(end=[-4.72, 22.84], %)
|> line(end = [28.8, 6.71]) |> line(end=[28.8, 6.71], %)
|> line(end = [9.19, -25.33]) |> line(end=[9.19, -25.33], %)
|> line(endAbsolute = [profileStartX(%), profileStartY(%)]) |> line(endAbsolute=[profileStartX(%), profileStartY(%)], %)
|> close() |> close(%)
extrude003 = extrude(sketch004, length = 20) extrude003 = extrude(20, sketch004)
pipeLength = 40 pipeLength = 40
pipeSmallDia = 10 pipeSmallDia = 10
pipeLargeDia = 20 pipeLargeDia = 20
thickness = 0.5 thickness = 0.5
part009 = startSketchOn('XY') part009 = startSketchOn('XY')
|> startProfileAt([pipeLargeDia - (thickness / 2), 38], %) |> startProfileAt([pipeLargeDia - (thickness / 2), 38], %)
|> line(end = [thickness, 0]) |> line(end=[thickness, 0], %)
|> line(end = [0, -1]) |> line(end=[0, -1], %)
|> angledLineToX({ |> angledLineToX({
angle = 60, angle = 60,
to = pipeSmallDia + thickness to = pipeSmallDia + thickness
}, %) }, %)
|> line(end = [0, -pipeLength]) |> line(end=[0, -pipeLength], %)
|> angledLineToX({ |> angledLineToX({
angle = -60, angle = -60,
to = pipeLargeDia + thickness to = pipeLargeDia + thickness
}, %) }, %)
|> line(end = [0, -1]) |> line(end=[0, -1], %)
|> line(end = [-thickness, 0]) |> line(end=[-thickness, 0], %)
|> line(end = [0, 1]) |> line(end=[0, 1], %)
|> angledLineToX({ angle = 120, to = pipeSmallDia }, %) |> angledLineToX({ angle = 120, to = pipeSmallDia }, %)
|> line(end = [0, pipeLength]) |> line(end=[0, pipeLength], %)
|> angledLineToX({ angle = 60, to = pipeLargeDia }, %) |> angledLineToX({ angle = 60, to = pipeLargeDia }, %)
|> close() |> close(%)
rev = revolve({ axis: 'y' }, part009) rev = revolve({ axis = 'y' }, part009)
` sketch006 = startSketchOn('XY')
profile001 = circle({
center = [42.91, -70.42],
radius = 17.96
}, sketch006)
profile002 = startProfileAt([86.92, -63.81], sketch006)
|> angledLine([0, 63.81], %, $rectangleSegmentA001)
|> angledLine([
segAng(rectangleSegmentA001) - 90,
17.05
], %)
|> angledLine([
segAng(rectangleSegmentA001),
-segLen(rectangleSegmentA001)
], %)
|> line(endAbsolute=[profileStartX(%), profileStartY(%)], %)
|> close(%)
profile003 = startProfileAt([40.16, -120.48], sketch006)
|> line(end=[26.95, 24.21], %)
|> line(end=[20.91, -28.61], %)
|> line(end=[32.46, 18.71], %)
`
) )
}, KCL_DEFAULT_LENGTH) }, KCL_DEFAULT_LENGTH)
await page.setBodyDimensions({ width: 1000, height: 500 }) await page.setBodyDimensions({ width: 1000, height: 500 })
await homePage.goToModelingScene() await homePage.goToModelingScene()
await scene.waitForExecutionDone()
await u.openDebugPanel()
await u.expectCmdLog('[data-message-type="execution-done"]')
await u.closeDebugPanel()
await u.openAndClearDebugPanel() await u.openAndClearDebugPanel()
await u.sendCustomCmd({ await u.sendCustomCmd({
@ -347,9 +373,10 @@ test.describe('Testing selections', { tag: ['@skipWin'] }, () => {
}) })
await page.waitForTimeout(100) await page.waitForTimeout(100)
const revolve = { x: 646, y: 248 } const revolve = { x: 635, y: 253 }
const parentExtrude = { x: 915, y: 133 } const parentExtrude = { x: 915, y: 133 }
const solid2d = { x: 770, y: 167 } const solid2d = { x: 770, y: 167 }
const individualProfile = { x: 694, y: 432 }
// DELETE REVOLVE // DELETE REVOLVE
await page.mouse.click(revolve.x, revolve.y) await page.mouse.click(revolve.x, revolve.y)
@ -415,6 +442,20 @@ test.describe('Testing selections', { tag: ['@skipWin'] }, () => {
await u.expectCmdLog('[data-message-type="execution-done"]', 10_000) await u.expectCmdLog('[data-message-type="execution-done"]', 10_000)
await page.waitForTimeout(200) await page.waitForTimeout(200)
await expect(u.codeLocator).not.toContainText(`sketch005 = startSketchOn({`) await expect(u.codeLocator).not.toContainText(`sketch005 = startSketchOn({`)
// Delete a single profile
await page.mouse.click(individualProfile.x, individualProfile.y)
await page.waitForTimeout(100)
const codeToBeDeletedSnippet =
'profile003 = startProfileAt([40.16, -120.48], sketch006)'
await expect(page.locator('.cm-activeLine')).toHaveText(
' |> line([20.91, -28.61], %)'
)
await u.clearCommandLogs()
await page.keyboard.press('Backspace')
await u.expectCmdLog('[data-message-type="execution-done"]', 10_000)
await page.waitForTimeout(200)
await expect(u.codeLocator).not.toContainText(codeToBeDeletedSnippet)
}) })
test("Deleting solid that the AST mod can't handle results in a toast message", async ({ test("Deleting solid that the AST mod can't handle results in a toast message", async ({
page, page,
@ -903,7 +944,6 @@ test.describe('Testing selections', { tag: ['@skipWin'] }, () => {
test('Testing selections (and hovers) work on sketches when NOT in sketch mode', async ({ test('Testing selections (and hovers) work on sketches when NOT in sketch mode', async ({
page, page,
homePage, homePage,
scene,
}) => { }) => {
const cases = [ const cases = [
{ {
@ -939,7 +979,6 @@ test.describe('Testing selections', { tag: ['@skipWin'] }, () => {
await page.setBodyDimensions({ width: 1200, height: 500 }) await page.setBodyDimensions({ width: 1200, height: 500 })
await homePage.goToModelingScene() await homePage.goToModelingScene()
await scene.waitForExecutionDone()
await u.openAndClearDebugPanel() await u.openAndClearDebugPanel()
await u.sendCustomCmd({ await u.sendCustomCmd({
@ -973,7 +1012,6 @@ test.describe('Testing selections', { tag: ['@skipWin'] }, () => {
test("Hovering and selection of extruded faces works, and is not overridden shortly after user's click", async ({ test("Hovering and selection of extruded faces works, and is not overridden shortly after user's click", async ({
page, page,
homePage, homePage,
scene,
}) => { }) => {
await page.addInitScript(async () => { await page.addInitScript(async () => {
localStorage.setItem( localStorage.setItem(
@ -992,7 +1030,6 @@ test.describe('Testing selections', { tag: ['@skipWin'] }, () => {
await page.setBodyDimensions({ width: 1200, height: 500 }) await page.setBodyDimensions({ width: 1200, height: 500 })
await homePage.goToModelingScene() await homePage.goToModelingScene()
await scene.waitForExecutionDone()
await u.openAndClearDebugPanel() await u.openAndClearDebugPanel()
await u.sendCustomCmd({ await u.sendCustomCmd({
@ -1026,19 +1063,19 @@ test.describe('Testing selections', { tag: ['@skipWin'] }, () => {
.poll(() => u.getGreatestPixDiff(extrudeWall, noHoverColor)) .poll(() => u.getGreatestPixDiff(extrudeWall, noHoverColor))
.toBeLessThan(15) .toBeLessThan(15)
await page.mouse.move(nothing.x, nothing.y) await page.mouse.move(nothing.x, nothing.y)
await page.waitForTimeout(1000) await page.waitForTimeout(100)
await page.mouse.move(extrudeWall.x, extrudeWall.y) await page.mouse.move(extrudeWall.x, extrudeWall.y)
await expect(page.getByTestId('hover-highlight').first()).toBeVisible() await expect(page.getByTestId('hover-highlight').first()).toBeVisible()
await expect(page.getByTestId('hover-highlight').first()).toContainText( await expect(page.getByTestId('hover-highlight').first()).toContainText(
removeAfterFirstParenthesis(extrudeText) removeAfterFirstParenthesis(extrudeText)
) )
await page.waitForTimeout(1000) await page.waitForTimeout(200)
await expect( await expect(
await u.getGreatestPixDiff(extrudeWall, hoverColor) await u.getGreatestPixDiff(extrudeWall, hoverColor)
).toBeLessThan(15) ).toBeLessThan(15)
await page.mouse.click(extrudeWall.x, extrudeWall.y) await page.mouse.click(extrudeWall.x, extrudeWall.y)
await expect(page.locator('.cm-activeLine')).toHaveText(`|> ${extrudeText}`) await expect(page.locator('.cm-activeLine')).toHaveText(`|> ${extrudeText}`)
await page.waitForTimeout(1000) await page.waitForTimeout(200)
await expect( await expect(
await u.getGreatestPixDiff(extrudeWall, selectColor) await u.getGreatestPixDiff(extrudeWall, selectColor)
).toBeLessThan(15) ).toBeLessThan(15)
@ -1049,7 +1086,7 @@ test.describe('Testing selections', { tag: ['@skipWin'] }, () => {
).toBeLessThan(15) ).toBeLessThan(15)
await page.mouse.move(nothing.x, nothing.y) await page.mouse.move(nothing.x, nothing.y)
await page.waitForTimeout(1000) await page.waitForTimeout(300)
await expect(page.getByTestId('hover-highlight')).not.toBeVisible() await expect(page.getByTestId('hover-highlight')).not.toBeVisible()
// because of shading, color is not exact everywhere on the face // because of shading, color is not exact everywhere on the face
@ -1063,11 +1100,11 @@ test.describe('Testing selections', { tag: ['@skipWin'] }, () => {
await expect(page.getByTestId('hover-highlight').first()).toContainText( await expect(page.getByTestId('hover-highlight').first()).toContainText(
removeAfterFirstParenthesis(capText) removeAfterFirstParenthesis(capText)
) )
await page.waitForTimeout(1000) await page.waitForTimeout(200)
await expect(await u.getGreatestPixDiff(cap, hoverColor)).toBeLessThan(15) await expect(await u.getGreatestPixDiff(cap, hoverColor)).toBeLessThan(15)
await page.mouse.click(cap.x, cap.y) await page.mouse.click(cap.x, cap.y)
await expect(page.locator('.cm-activeLine')).toHaveText(`|> ${capText}`) await expect(page.locator('.cm-activeLine')).toHaveText(`|> ${capText}`)
await page.waitForTimeout(1000) await page.waitForTimeout(200)
await expect(await u.getGreatestPixDiff(cap, selectColor)).toBeLessThan(15) await expect(await u.getGreatestPixDiff(cap, selectColor)).toBeLessThan(15)
await page.waitForTimeout(1000) await page.waitForTimeout(1000)
// check color stays there, i.e. not overridden (this was a bug previously) // check color stays there, i.e. not overridden (this was a bug previously)
@ -1216,12 +1253,15 @@ test.describe('Testing selections', { tag: ['@skipWin'] }, () => {
await page.waitForTimeout(600) await page.waitForTimeout(600)
const firstClickCoords = { x: 650, y: 200 } as const
// Place a point because the line tool will exit if no points are pressed // Place a point because the line tool will exit if no points are pressed
await page.mouse.click(650, 200) await page.mouse.click(firstClickCoords.x, firstClickCoords.y)
await page.waitForTimeout(600) await page.waitForTimeout(600)
// Code before exiting the tool // Code before exiting the tool
let previousCodeContent = await page.locator('.cm-content').innerText() let previousCodeContent = (
await page.locator('.cm-content').innerText()
).replace(/\s+/g, '')
// deselect the line tool by clicking it // deselect the line tool by clicking it
await page.getByRole('button', { name: 'line Line', exact: true }).click() await page.getByRole('button', { name: 'line Line', exact: true }).click()
@ -1233,14 +1273,23 @@ test.describe('Testing selections', { tag: ['@skipWin'] }, () => {
await page.mouse.click(750, 200) await page.mouse.click(750, 200)
await page.waitForTimeout(100) await page.waitForTimeout(100)
// expect no change await expect
await expect(page.locator('.cm-content')).toHaveText(previousCodeContent) .poll(async () => {
let str = await page.locator('.cm-content').innerText()
str = str.replace(/\s+/g, '')
return str
})
.toBe(previousCodeContent)
// select line tool again // select line tool again
await page.getByRole('button', { name: 'line Line', exact: true }).click() await page.getByRole('button', { name: 'line Line', exact: true }).click()
await u.closeDebugPanel() await u.closeDebugPanel()
// Click to continue profile
await page.mouse.click(firstClickCoords.x, firstClickCoords.y)
await page.waitForTimeout(100)
// line tool should work as expected again // line tool should work as expected again
await page.mouse.click(700, 200) await page.mouse.click(700, 200)
await expect(page.locator('.cm-content')).not.toHaveText( await expect(page.locator('.cm-content')).not.toHaveText(

View File

@ -896,53 +896,4 @@ test.describe('Testing settings', () => {
}) })
} }
) )
test(`Change inline units setting`, async ({
page,
homePage,
context,
editor,
}) => {
const initialInlineUnits = 'yd'
const editedInlineUnits = { short: 'mm', long: 'Millimeters' }
const inlineSettingsString = (s: string) =>
`@settings(defaultLengthUnit = ${s})`
const unitsIndicator = page.getByRole('button', {
name: 'Current units are:',
})
const unitsChangeButton = (name: string) =>
page.getByRole('button', { name, exact: true })
await context.folderSetupFn(async (dir) => {
const bracketDir = join(dir, 'project-000')
await fsp.mkdir(bracketDir, { recursive: true })
await fsp.copyFile(
executorInputPath('cube.kcl'),
join(bracketDir, 'main.kcl')
)
})
await test.step(`Initial units from settings`, async () => {
await homePage.openProject('project-000')
await expect(unitsIndicator).toHaveText('Current units are: in')
})
await test.step(`Manually write inline settings`, async () => {
await editor.openPane()
await editor.replaceCode(
`fn cube`,
`${inlineSettingsString(initialInlineUnits)}
fn cube`
)
await expect(unitsIndicator).toContainText(initialInlineUnits)
})
await test.step(`Change units setting via lower-right control`, async () => {
await unitsIndicator.click()
await unitsChangeButton(editedInlineUnits.long).click()
await expect(
page.getByText(`Updated per-file units to ${editedInlineUnits.short}`)
).toBeVisible()
})
})
}) })

View File

@ -3,7 +3,7 @@ import { getUtils, createProject } from './test-utils'
import { join } from 'path' import { join } from 'path'
import fs from 'fs' import fs from 'fs'
test.describe('Text-to-CAD tests', { tag: ['@skipWin'] }, () => { test.describe('Text-to-CAD tests', () => {
test('basic lego happy case', async ({ page, homePage }) => { test('basic lego happy case', async ({ page, homePage }) => {
const u = await getUtils(page) const u = await getUtils(page)

View File

@ -32,18 +32,15 @@ test.fixme('Units menu', async ({ page, homePage }) => {
await expect(unitsMenuButton).toContainText('mm') await expect(unitsMenuButton).toContainText('mm')
}) })
test( test('Successful export shows a success toast', async ({ page, homePage }) => {
'Successful export shows a success toast', // FYI this test doesn't work with only engine running locally
{ tag: '@skipLocalEngine' }, // And you will need to have the KittyCAD CLI installed
async ({ page, homePage }) => { const u = await getUtils(page)
// FYI this test doesn't work with only engine running locally await page.addInitScript(async () => {
// And you will need to have the KittyCAD CLI installed ;(window as any).playwrightSkipFilePicker = true
const u = await getUtils(page) localStorage.setItem(
await page.addInitScript(async () => { 'persistCode',
;(window as any).playwrightSkipFilePicker = true `topAng = 25
localStorage.setItem(
'persistCode',
`topAng = 25
bottomAng = 35 bottomAng = 35
baseLen = 3.5 baseLen = 3.5
baseHeight = 1 baseHeight = 1
@ -81,27 +78,26 @@ part001 = startSketchOn('-XZ')
|> xLineTo(ZERO, %) |> xLineTo(ZERO, %)
|> close() |> close()
|> extrude(length = 4)` |> extrude(length = 4)`
)
})
await page.setBodyDimensions({ width: 1200, height: 500 })
await homePage.goToModelingScene()
await u.openDebugPanel()
await u.expectCmdLog('[data-message-type="execution-done"]')
await u.waitForCmdReceive('extrude')
await page.waitForTimeout(1000)
await u.clearAndCloseDebugPanel()
await doExport(
{
type: 'gltf',
storage: 'embedded',
presentation: 'pretty',
},
page
) )
} })
) await page.setBodyDimensions({ width: 1200, height: 500 })
await homePage.goToModelingScene()
await u.openDebugPanel()
await u.expectCmdLog('[data-message-type="execution-done"]')
await u.waitForCmdReceive('extrude')
await page.waitForTimeout(1000)
await u.clearAndCloseDebugPanel()
await doExport(
{
type: 'gltf',
storage: 'embedded',
presentation: 'pretty',
},
page
)
})
test('Paste should not work unless an input is focused', async ({ test('Paste should not work unless an input is focused', async ({
page, page,
@ -209,8 +205,13 @@ test('First escape in tool pops you out of tool, second exits sketch mode', asyn
// Draw a line // Draw a line
await page.mouse.move(700, 200, { steps: 5 }) await page.mouse.move(700, 200, { steps: 5 })
await page.mouse.click(700, 200) await page.mouse.click(700, 200)
await page.mouse.move(800, 250, { steps: 5 })
await page.mouse.click(800, 250) const secondMousePosition = { x: 800, y: 250 }
await page.mouse.move(secondMousePosition.x, secondMousePosition.y, {
steps: 5,
})
await page.mouse.click(secondMousePosition.x, secondMousePosition.y)
// Unequip line tool // Unequip line tool
await page.keyboard.press('Escape') await page.keyboard.press('Escape')
// Make sure we didn't pop out of sketch mode. // Make sure we didn't pop out of sketch mode.
@ -219,9 +220,17 @@ test('First escape in tool pops you out of tool, second exits sketch mode', asyn
// Equip arc tool // Equip arc tool
await page.keyboard.press('a') await page.keyboard.press('a')
await expect(arcButton).toHaveAttribute('aria-pressed', 'true') await expect(arcButton).toHaveAttribute('aria-pressed', 'true')
// click in the same position again to continue the profile
await page.mouse.move(secondMousePosition.x, secondMousePosition.y, {
steps: 5,
})
await page.mouse.click(secondMousePosition.x, secondMousePosition.y)
await page.mouse.move(1000, 100, { steps: 5 }) await page.mouse.move(1000, 100, { steps: 5 })
await page.mouse.click(1000, 100) await page.mouse.click(1000, 100)
await page.keyboard.press('Escape') await page.keyboard.press('Escape')
await expect(arcButton).toHaveAttribute('aria-pressed', 'false')
await page.keyboard.press('l') await page.keyboard.press('l')
await expect(lineButton).toHaveAttribute('aria-pressed', 'true') await expect(lineButton).toHaveAttribute('aria-pressed', 'true')
@ -448,7 +457,7 @@ test('Delete key does not navigate back', async ({ page, homePage }) => {
await expect.poll(() => page.url()).not.toContain('/settings') await expect.poll(() => page.url()).not.toContain('/settings')
}) })
test('Sketch on face', async ({ page, homePage, scene, cmdBar }) => { test('Sketch on face', async ({ page, homePage }) => {
test.setTimeout(90_000) test.setTimeout(90_000)
const u = await getUtils(page) const u = await getUtils(page)
await page.addInitScript(async () => { await page.addInitScript(async () => {
@ -474,7 +483,11 @@ extrude001 = extrude(sketch001, length = 5 + 7)`
await page.setBodyDimensions({ width: 1200, height: 500 }) await page.setBodyDimensions({ width: 1200, height: 500 })
await homePage.goToModelingScene() await homePage.goToModelingScene()
await scene.waitForExecutionDone()
// wait for execution done
await u.openDebugPanel()
await u.expectCmdLog('[data-message-type="execution-done"]')
await u.closeDebugPanel()
await expect( await expect(
page.getByRole('button', { name: 'Start Sketch' }) page.getByRole('button', { name: 'Start Sketch' })
@ -519,11 +532,11 @@ extrude001 = extrude(sketch001, length = 5 + 7)`
await expect.poll(u.normalisedEditorCode).toContain( await expect.poll(u.normalisedEditorCode).toContain(
u.normalisedCode(`sketch002 = startSketchOn(extrude001, seg01) u.normalisedCode(`sketch002 = startSketchOn(extrude001, seg01)
|> startProfileAt([-12.94, 6.6], %) profile001 = startProfileAt([-12.88, 6.66], sketch002)
|> line(end = [2.45, -0.2]) |> line(end = [2.71, -0.22], %)
|> line(end = [-2.6, -1.25]) |> line(end = [-2.87, -1.38], %)
|> line(endAbsolute = [profileStartX(%), profileStartY(%)]) |> lineTo(endAbsolute = [profileStartX(%), profileStartY(%)], %)
|> close() |> close(%)
`) `)
) )
@ -537,9 +550,8 @@ extrude001 = extrude(sketch001, length = 5 + 7)`
await page.getByText('startProfileAt([-12').click() await page.getByText('startProfileAt([-12').click()
await expect(page.getByRole('button', { name: 'Edit Sketch' })).toBeVisible() await expect(page.getByRole('button', { name: 'Edit Sketch' })).toBeVisible()
await page.getByRole('button', { name: 'Edit Sketch' }).click() await page.getByRole('button', { name: 'Edit Sketch' }).click()
await page.waitForTimeout(400) await page.waitForTimeout(500)
await page.waitForTimeout(150) await page.setViewportSize({ width: 1200, height: 1200 })
await page.setBodyDimensions({ width: 1200, height: 1200 })
await u.openAndClearDebugPanel() await u.openAndClearDebugPanel()
await u.updateCamPosition([452, -152, 1166]) await u.updateCamPosition([452, -152, 1166])
await u.closeDebugPanel() await u.closeDebugPanel()
@ -579,9 +591,10 @@ extrude001 = extrude(sketch001, length = 5 + 7)`
await expect(page.getByTestId('command-bar')).toBeVisible() await expect(page.getByTestId('command-bar')).toBeVisible()
await page.waitForTimeout(100) await page.waitForTimeout(100)
await cmdBar.progressCmdBar() await page.getByRole('button', { name: 'arrow right Continue' }).click()
await page.waitForTimeout(100)
await expect(page.getByText('Confirm Extrude')).toBeVisible() await expect(page.getByText('Confirm Extrude')).toBeVisible()
await cmdBar.progressCmdBar() await page.getByRole('button', { name: 'checkmark Submit command' }).click()
const result2 = result.genNext` const result2 = result.genNext`
const sketch002 = extrude(sketch002, length = ${[5, 5]} + 7)` const sketch002 = extrude(sketch002, length = ${[5, 5]} + 7)`

View File

@ -32,6 +32,10 @@ win:
arch: arch:
- x64 - x64
- arm64 - arm64
# - target: msi
# arch:
# - x64
# - arm64
signingHashAlgorithms: signingHashAlgorithms:
- sha256 - sha256
sign: "./scripts/sign-win.js" sign: "./scripts/sign-win.js"
@ -43,12 +47,15 @@ win:
mimeType: text/vnd.zoo.kcl mimeType: text/vnd.zoo.kcl
description: Zoo KCL File description: Zoo KCL File
role: Editor role: Editor
# msi:
# oneClick: false
# perMachine: true
nsis: nsis:
oneClick: false oneClick: false
perMachine: true perMachine: true
allowElevation: true allowElevation: true
installerIcon: "assets/icon.ico" installerIcon: "assets/icon.ico"
include: "./scripts/installer.nsh" include: "./installer.nsh"
linux: linux:
artifactName: "${productName}-${version}-${arch}-${os}.${ext}" artifactName: "${productName}-${version}-${arch}-${os}.${ext}"
target: target:

View File

@ -85,7 +85,7 @@
"fmt": "prettier --write ./src *.ts *.json *.js ./e2e ./packages", "fmt": "prettier --write ./src *.ts *.json *.js ./e2e ./packages",
"fmt-check": "prettier --check ./src *.ts *.json *.js ./e2e ./packages", "fmt-check": "prettier --check ./src *.ts *.json *.js ./e2e ./packages",
"fetch:wasm": "./get-latest-wasm-bundle.sh", "fetch:wasm": "./get-latest-wasm-bundle.sh",
"fetch:samples": "echo \"Fetching latest KCL samples...\" && curl -o public/kcl-samples-manifest-fallback.json https://raw.githubusercontent.com/KittyCAD/kcl-samples/achalmers/kw-appearance/manifest.json", "fetch:samples": "echo \"Fetching latest KCL samples...\" && curl -o public/kcl-samples-manifest-fallback.json https://raw.githubusercontent.com/KittyCAD/kcl-samples/main/manifest.json",
"isomorphic-copy-wasm": "(copy src/wasm-lib/pkg/wasm_lib_bg.wasm public || cp src/wasm-lib/pkg/wasm_lib_bg.wasm public)", "isomorphic-copy-wasm": "(copy src/wasm-lib/pkg/wasm_lib_bg.wasm public || cp src/wasm-lib/pkg/wasm_lib_bg.wasm public)",
"build:wasm-dev": "yarn wasm-prep && (cd src/wasm-lib && wasm-pack build --dev --target web --out-dir pkg && cargo test -p kcl-lib export_bindings) && yarn isomorphic-copy-wasm && yarn fmt", "build:wasm-dev": "yarn wasm-prep && (cd src/wasm-lib && wasm-pack build --dev --target web --out-dir pkg && cargo test -p kcl-lib export_bindings) && yarn isomorphic-copy-wasm && yarn fmt",
"build:wasm": "yarn wasm-prep && cd src/wasm-lib && wasm-pack build --release --target web --out-dir pkg && cargo test -p kcl-lib export_bindings && cd ../.. && yarn isomorphic-copy-wasm && yarn fmt", "build:wasm": "yarn wasm-prep && cd src/wasm-lib && wasm-pack build --release --target web --out-dir pkg && cargo test -p kcl-lib export_bindings && cd ../.. && yarn isomorphic-copy-wasm && yarn fmt",
@ -120,7 +120,6 @@
"test:playwright:electron:windows:local": "yarn tronb:vite:dev && set NODE_ENV='development' && playwright test --config=playwright.electron.config.ts --grep-invert=\"@skipWin|@snapshot\"", "test:playwright:electron:windows:local": "yarn tronb:vite:dev && set NODE_ENV='development' && playwright test --config=playwright.electron.config.ts --grep-invert=\"@skipWin|@snapshot\"",
"test:playwright:electron:macos:local": "yarn tronb:vite:dev && NODE_ENV=development playwright test --config=playwright.electron.config.ts --grep-invert='@skipMacos|@snapshot'", "test:playwright:electron:macos:local": "yarn tronb:vite:dev && NODE_ENV=development playwright test --config=playwright.electron.config.ts --grep-invert='@skipMacos|@snapshot'",
"test:playwright:electron:ubuntu:local": "yarn tronb:vite:dev && NODE_ENV=development playwright test --config=playwright.electron.config.ts --grep-invert='@skipLinux|@snapshot'", "test:playwright:electron:ubuntu:local": "yarn tronb:vite:dev && NODE_ENV=development playwright test --config=playwright.electron.config.ts --grep-invert='@skipLinux|@snapshot'",
"test:playwright:electron:ubuntu:engine:local": "yarn tronb:vite:dev && NODE_ENV=development playwright test --config=playwright.electron.config.ts --grep-invert='@skipLinux|@snapshot|@skipLocalEngine'",
"test:unit:local": "yarn simpleserver:bg && yarn test:unit; kill-port 3000", "test:unit:local": "yarn simpleserver:bg && yarn test:unit; kill-port 3000",
"test:unit:kcl-samples:local": "yarn simpleserver:bg && yarn test:unit:kcl-samples; kill-port 3000" "test:unit:kcl-samples:local": "yarn simpleserver:bg && yarn test:unit:kcl-samples; kill-port 3000"
}, },
@ -159,8 +158,8 @@
"@types/electron": "^1.6.10", "@types/electron": "^1.6.10",
"@types/isomorphic-fetch": "^0.0.39", "@types/isomorphic-fetch": "^0.0.39",
"@types/minimist": "^1.2.5", "@types/minimist": "^1.2.5",
"@types/mocha": "^10.0.10", "@types/mocha": "^10.0.6",
"@types/node": "^22.13.1", "@types/node": "^22.7.8",
"@types/pixelmatch": "^5.2.6", "@types/pixelmatch": "^5.2.6",
"@types/pngjs": "^6.0.4", "@types/pngjs": "^6.0.4",
"@types/react": "^18.3.4", "@types/react": "^18.3.4",
@ -201,7 +200,7 @@
"tailwindcss": "^3.4.1", "tailwindcss": "^3.4.1",
"ts-node": "^10.0.0", "ts-node": "^10.0.0",
"typescript": "^5.7.3", "typescript": "^5.7.3",
"typescript-eslint": "^8.23.0", "typescript-eslint": "^8.19.1",
"vite": "^5.4.12", "vite": "^5.4.12",
"vite-plugin-package-version": "^1.1.0", "vite-plugin-package-version": "^1.1.0",
"vite-tsconfig-paths": "^4.3.2", "vite-tsconfig-paths": "^4.3.2",

View File

@ -59,9 +59,7 @@ UnaryOp { AddOp | BangOp }
ObjectProperty { PropertyName (":" | Equals) expression } ObjectProperty { PropertyName (":" | Equals) expression }
LabeledArgument { ArgumentLabel Equals expression } ArgumentList { "(" commaSep<expression> ")" }
ArgumentList { "(" commaSep<LabeledArgument | expression> ")" }
type[@isGroup=Type] { type[@isGroup=Type] {
@specialize[@name=PrimitiveType]< @specialize[@name=PrimitiveType]<
@ -76,8 +74,6 @@ VariableDefinition { identifier }
VariableName { identifier } VariableName { identifier }
ArgumentLabel { identifier }
@skip { whitespace | LineComment | BlockComment } @skip { whitespace | LineComment | BlockComment }
kw<term> { @specialize[@name={term}]<identifier, term> } kw<term> { @specialize[@name={term}]<identifier, term> }

View File

@ -1,85 +0,0 @@
# empty
f()
==>
Program(ExpressionStatement(CallExpression(VariableName,
ArgumentList)))
# single anon arg
f(1)
==>
Program(ExpressionStatement(CallExpression(VariableName,
ArgumentList(Number))))
# deprecated multiple anon args
f(1, 2)
==>
Program(ExpressionStatement(CallExpression(VariableName,
ArgumentList(Number,
Number))))
# deprecated trailing %
startSketchOn('XY')
|> line([thickness, 0], %)
==>
Program(ExpressionStatement(PipeExpression(CallExpression(VariableName,
ArgumentList(String)),
PipeOperator,
CallExpression(VariableName,
ArgumentList(ArrayExpression(VariableName,
Number),
PipeSubstitution)))))
# % and named arg
startSketchOn('XY')
|> line(%, end = [thickness, 0])
==>
Program(ExpressionStatement(PipeExpression(CallExpression(VariableName,
ArgumentList(String)),
PipeOperator,
CallExpression(VariableName,
ArgumentList(PipeSubstitution,
LabeledArgument(ArgumentLabel,
Equals,
ArrayExpression(VariableName,
Number)))))))
# implied % and named arg
startSketchOn('XY')
|> line(end = [thickness, 0])
==>
Program(ExpressionStatement(PipeExpression(CallExpression(VariableName,
ArgumentList(String)),
PipeOperator,
CallExpression(VariableName,
ArgumentList(LabeledArgument(ArgumentLabel,
Equals,
ArrayExpression(VariableName,
Number)))))))
# multiple named arg
ngon(plane = "XY", numSides = 5, radius = pentR)
==>
Program(ExpressionStatement(CallExpression(VariableName,
ArgumentList(LabeledArgument(ArgumentLabel,
Equals,
String),
LabeledArgument(ArgumentLabel,
Equals,
Number),
LabeledArgument(ArgumentLabel,
Equals,
VariableName)))))

View File

@ -29,7 +29,7 @@
"vscode-uri": "^3.0.8" "vscode-uri": "^3.0.8"
}, },
"devDependencies": { "devDependencies": {
"@types/node": "^22.13.1", "@types/node": "^22.10.6",
"ts-node": "^10.9.2" "ts-node": "^10.9.2"
} }
} }

View File

@ -109,10 +109,10 @@
resolved "https://registry.yarnpkg.com/@tsconfig/node16/-/node16-1.0.4.tgz#0b92dcc0cc1c81f6f306a381f28e31b1a56536e9" resolved "https://registry.yarnpkg.com/@tsconfig/node16/-/node16-1.0.4.tgz#0b92dcc0cc1c81f6f306a381f28e31b1a56536e9"
integrity sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA== integrity sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==
"@types/node@^22.13.1": "@types/node@^22.10.6":
version "22.13.1" version "22.10.6"
resolved "https://registry.yarnpkg.com/@types/node/-/node-22.13.1.tgz#a2a3fefbdeb7ba6b89f40371842162fac0934f33" resolved "https://registry.yarnpkg.com/@types/node/-/node-22.10.6.tgz#5c6795e71635876039f853cbccd59f523d9e4239"
integrity sha512-jK8uzQlrvXqEU91UxiK5J7pKHyzgnI1Qnl0QDHIgVGuolJhRb9EEl28Cj9b3rGR8B2lhFCtvIm5os8lFnO/1Ew== integrity sha512-qNiuwC4ZDAUNcY47xgaSuS92cjf8JbSUoaKS77bmLG1rU7MlATVSiw/IlrjtIyyskXBZ8KkNfjK/P5na7rgXbQ==
dependencies: dependencies:
undici-types "~6.20.0" undici-types "~6.20.0"

View File

@ -1,212 +1 @@
[ 404: Not Found
{
"file": "main.kcl",
"pathFromProjectDirectoryToFirstFile": "80-20-rail/main.kcl",
"multipleFiles": false,
"title": "80/20 Rail",
"description": "An 80/20 extruded aluminum linear rail. T-slot profile adjustable by profile height, rail length, and origin position"
},
{
"file": "main.kcl",
"pathFromProjectDirectoryToFirstFile": "a-parametric-bearing-pillow-block/main.kcl",
"multipleFiles": false,
"title": "A Parametric Bearing Pillow Block",
"description": "A bearing pillow block, also known as a plummer block or pillow block bearing, is a pedestal used to provide support for a rotating shaft with the help of compatible bearings and various accessories. Housing a bearing, the pillow block provides a secure and stable foundation that allows the shaft to rotate smoothly within its machinery setup. These components are essential in a wide range of mechanical systems and machinery, playing a key role in reducing friction and supporting radial and axial loads."
},
{
"file": "main.kcl",
"pathFromProjectDirectoryToFirstFile": "ball-bearing/main.kcl",
"multipleFiles": false,
"title": "Ball Bearing",
"description": "A ball bearing is a type of rolling-element bearing that uses balls to maintain the separation between the bearing races. The primary purpose of a ball bearing is to reduce rotational friction and support radial and axial loads."
},
{
"file": "main.kcl",
"pathFromProjectDirectoryToFirstFile": "bracket/main.kcl",
"multipleFiles": false,
"title": "Shelf Bracket",
"description": "This is a bracket that holds a shelf. It is made of aluminum and is designed to hold a force of 300 lbs. The bracket is 6 inches wide and the force is applied at the end of the shelf, 12 inches from the wall. The bracket has a factor of safety of 1.2. The legs of the bracket are 5 inches and 2 inches long. The thickness of the bracket is calculated from the constraints provided."
},
{
"file": "main.kcl",
"pathFromProjectDirectoryToFirstFile": "car-wheel-assembly/main.kcl",
"multipleFiles": true,
"title": "Car Wheel Assembly",
"description": "A car wheel assembly with a rotor, tire, and lug nuts."
},
{
"file": "main.kcl",
"pathFromProjectDirectoryToFirstFile": "dodecahedron/main.kcl",
"multipleFiles": false,
"title": "Hollow Dodecahedron",
"description": "A regular dodecahedron or pentagonal dodecahedron is a dodecahedron composed of regular pentagonal faces, three meeting at each vertex. This example shows constructing the individual faces of the dodecahedron and extruding inwards."
},
{
"file": "main.kcl",
"pathFromProjectDirectoryToFirstFile": "enclosure/main.kcl",
"multipleFiles": false,
"title": "Enclosure",
"description": "An enclosure body and sealing lid for storing items"
},
{
"file": "main.kcl",
"pathFromProjectDirectoryToFirstFile": "flange-with-patterns/main.kcl",
"multipleFiles": false,
"title": "Flange",
"description": "A flange is a flat rim, collar, or rib, typically forged or cast, that is used to strengthen an object, guide it, or attach it to another object. Flanges are known for their use in various applications, including piping, plumbing, and mechanical engineering, among others."
},
{
"file": "main.kcl",
"pathFromProjectDirectoryToFirstFile": "flange-xy/main.kcl",
"multipleFiles": false,
"title": "Flange with XY coordinates",
"description": "A flange is a flat rim, collar, or rib, typically forged or cast, that is used to strengthen an object, guide it, or attach it to another object. Flanges are known for their use in various applications, including piping, plumbing, and mechanical engineering, among others."
},
{
"file": "main.kcl",
"pathFromProjectDirectoryToFirstFile": "focusrite-scarlett-mounting-bracket/main.kcl",
"multipleFiles": false,
"title": "A mounting bracket for the Focusrite Scarlett Solo audio interface",
"description": "This is a bracket that holds an audio device underneath a desk or shelf. The audio device has dimensions of 144mm wide, 80mm length and 45mm depth with fillets of 6mm. This mounting bracket is designed to be 3D printed with PLA material"
},
{
"file": "main.kcl",
"pathFromProjectDirectoryToFirstFile": "food-service-spatula/main.kcl",
"multipleFiles": false,
"title": "Food Service Spatula",
"description": "Use these spatulas for mixing, flipping, and scraping."
},
{
"file": "main.kcl",
"pathFromProjectDirectoryToFirstFile": "french-press/main.kcl",
"multipleFiles": false,
"title": "French Press",
"description": "A french press immersion coffee maker"
},
{
"file": "main.kcl",
"pathFromProjectDirectoryToFirstFile": "gear/main.kcl",
"multipleFiles": false,
"title": "Spur Gear",
"description": "A rotating machine part having cut teeth or, in the case of a cogwheel, inserted teeth (called cogs), which mesh with another toothed part to transmit torque. Geared devices can change the speed, torque, and direction of a power source. The two elements that define a gear are its circular shape and the teeth that are integrated into its outer edge, which are designed to fit into the teeth of another gear."
},
{
"file": "main.kcl",
"pathFromProjectDirectoryToFirstFile": "gear-rack/main.kcl",
"multipleFiles": false,
"title": "100mm Gear Rack",
"description": "A flat bar or rail that is engraved with teeth along its length. These teeth are designed to mesh with the teeth of a gear, known as a pinion. When the pinion, a small cylindrical gear, rotates, its teeth engage with the teeth on the rack, causing the rack to move linearly. Conversely, linear motion applied to the rack will cause the pinion to rotate."
},
{
"file": "main.kcl",
"pathFromProjectDirectoryToFirstFile": "hex-nut/main.kcl",
"multipleFiles": false,
"title": "Hex nut",
"description": "A hex nut is a type of fastener with a threaded hole and a hexagonal outer shape, used in a wide variety of applications to secure parts together. The hexagonal shape allows for a greater torque to be applied with wrenches or tools, making it one of the most common nut types in hardware."
},
{
"file": "main.kcl",
"pathFromProjectDirectoryToFirstFile": "i-beam/main.kcl",
"multipleFiles": false,
"title": "I-beam",
"description": "A structural metal beam with an I shaped cross section. Often used in construction"
},
{
"file": "main.kcl",
"pathFromProjectDirectoryToFirstFile": "kitt/main.kcl",
"multipleFiles": false,
"title": "Kitt",
"description": "The beloved KittyCAD mascot in a voxelized style."
},
{
"file": "main.kcl",
"pathFromProjectDirectoryToFirstFile": "lego/main.kcl",
"multipleFiles": false,
"title": "Lego Brick",
"description": "A standard Lego brick. This is a small, plastic construction block toy that can be interlocked with other blocks to build various structures, models, and figures. There are a lot of hacks used in this code."
},
{
"file": "main.kcl",
"pathFromProjectDirectoryToFirstFile": "mounting-plate/main.kcl",
"multipleFiles": false,
"title": "Mounting Plate",
"description": "A flat piece of material, often metal or plastic, that serves as a support or base for attaching, securing, or mounting various types of equipment, devices, or components."
},
{
"file": "main.kcl",
"pathFromProjectDirectoryToFirstFile": "multi-axis-robot/main.kcl",
"multipleFiles": true,
"title": "Robot Arm",
"description": "A 4 axis robotic arm for industrial use. These machines can be used for assembly, packaging, organization of goods, and quality inspection processes"
},
{
"file": "main.kcl",
"pathFromProjectDirectoryToFirstFile": "pipe/main.kcl",
"multipleFiles": false,
"title": "Pipe",
"description": "A tubular section or hollow cylinder, usually but not necessarily of circular cross-section, used mainly to convey substances that can flow."
},
{
"file": "main.kcl",
"pathFromProjectDirectoryToFirstFile": "pipe-flange-assembly/main.kcl",
"multipleFiles": false,
"title": "Pipe and Flange Assembly",
"description": "A crucial component in various piping systems, designed to facilitate the connection, disconnection, and access to piping for inspection, cleaning, and modifications. This assembly combines pipes (long cylindrical conduits) with flanges (plate-like fittings) to create a secure yet detachable joint."
},
{
"file": "main.kcl",
"pathFromProjectDirectoryToFirstFile": "pipe-with-bend/main.kcl",
"multipleFiles": false,
"title": "Pipe with bend",
"description": "A tubular section or hollow cylinder, usually but not necessarily of circular cross-section, used mainly to convey substances that can flow."
},
{
"file": "main.kcl",
"pathFromProjectDirectoryToFirstFile": "poopy-shoe/main.kcl",
"multipleFiles": false,
"title": "Poopy Shoe",
"description": "poop shute for bambu labs printer - optimized for printing."
},
{
"file": "main.kcl",
"pathFromProjectDirectoryToFirstFile": "router-template-cross-bar/main.kcl",
"multipleFiles": false,
"title": "Router template for a cross bar",
"description": "A guide for routing a notch into a cross bar."
},
{
"file": "main.kcl",
"pathFromProjectDirectoryToFirstFile": "router-template-slate/main.kcl",
"multipleFiles": false,
"title": "Router template for a slate",
"description": "A guide for routing a slate for a cross bar."
},
{
"file": "main.kcl",
"pathFromProjectDirectoryToFirstFile": "sheet-metal-bracket/main.kcl",
"multipleFiles": false,
"title": "Sheet Metal Bracket",
"description": "A component typically made from flat sheet metal through various manufacturing processes such as bending, punching, cutting, and forming. These brackets are used to support, attach, or mount other hardware components, often providing a structural or functional base for assembly."
},
{
"file": "main.kcl",
"pathFromProjectDirectoryToFirstFile": "socket-head-cap-screw/main.kcl",
"multipleFiles": false,
"title": "Socket Head Cap Screw",
"description": "This is for a #10-24 screw that is 1.00 inches long. A socket head cap screw is a type of fastener that is widely used in a variety of applications requiring a high strength fastening solution. It is characterized by its cylindrical head and internal hexagonal drive, which allows for tightening with an Allen wrench or hex key."
},
{
"file": "main.kcl",
"pathFromProjectDirectoryToFirstFile": "walkie-talkie/main.kcl",
"multipleFiles": true,
"title": "Walkie Talkie",
"description": "A portable, handheld two-way radio device that allows users to communicate wirelessly over short to medium distances. It operates on specific radio frequencies and features a push-to-talk button for transmitting messages, making it ideal for quick and reliable communication in outdoor, work, or emergency settings."
},
{
"file": "main.kcl",
"pathFromProjectDirectoryToFirstFile": "washer/main.kcl",
"multipleFiles": false,
"title": "Washer",
"description": "A small, typically disk-shaped component with a hole in the middle, used in a wide range of applications, primarily in conjunction with fasteners like bolts and screws. Washers distribute the load of a fastener across a broader area. This is especially important when the fastening surface is soft or uneven, as it helps to prevent damage to the surface and ensures the load is evenly distributed, reducing the risk of the fastener becoming loose over time."
}
]

View File

@ -11,7 +11,6 @@ echo "$PACKAGE" > package.json
# electron-builder.yml # electron-builder.yml
yq -i '.publish[0].url = "https://dl.zoo.dev/releases/modeling-app/nightly"' electron-builder.yml yq -i '.publish[0].url = "https://dl.zoo.dev/releases/modeling-app/nightly"' electron-builder.yml
yq -i '.appId = "dev.zoo.modeling-app-nightly"' electron-builder.yml yq -i '.appId = "dev.zoo.modeling-app-nightly"' electron-builder.yml
yq -i '.nsis.include = "./scripts/installer-nightly.nsh"' electron-builder.yml
# Release notes # Release notes
echo "Nightly build $VERSION (commit $COMMIT)" > release-notes.md echo "Nightly build $VERSION (commit $COMMIT)" > release-notes.md

View File

@ -1,8 +0,0 @@
!macro preInit
SetRegView 64
WriteRegExpandStr HKLM "${INSTALL_REGISTRY_KEY}" InstallLocation "C:\Program Files\Zoo Modeling App (Nightly)"
WriteRegExpandStr HKCU "${INSTALL_REGISTRY_KEY}" InstallLocation "C:\Program Files\Zoo Modeling App (Nightly)"
SetRegView 32
WriteRegExpandStr HKLM "${INSTALL_REGISTRY_KEY}" InstallLocation "C:\Program Files\Zoo Modeling App (Nightly)"
WriteRegExpandStr HKCU "${INSTALL_REGISTRY_KEY}" InstallLocation "C:\Program Files\Zoo Modeling App (Nightly)"
!macroend

View File

@ -5,7 +5,6 @@ import { useModelingContext } from 'hooks/useModelingContext'
import { useNetworkContext } from 'hooks/useNetworkContext' import { useNetworkContext } from 'hooks/useNetworkContext'
import { NetworkHealthState } from 'hooks/useNetworkStatus' import { NetworkHealthState } from 'hooks/useNetworkStatus'
import { ActionButton } from 'components/ActionButton' import { ActionButton } from 'components/ActionButton'
import { isSingleCursorInPipe } from 'lang/queryAst'
import { useKclContext } from 'lang/KclProvider' import { useKclContext } from 'lang/KclProvider'
import { ActionButtonDropdown } from 'components/ActionButtonDropdown' import { ActionButtonDropdown } from 'components/ActionButtonDropdown'
import { useHotkeys } from 'react-hotkeys-hook' import { useHotkeys } from 'react-hotkeys-hook'
@ -21,6 +20,7 @@ import {
} from 'lib/toolbar' } from 'lib/toolbar'
import { isDesktop } from 'lib/isDesktop' import { isDesktop } from 'lib/isDesktop'
import { openExternalBrowserIfDesktop } from 'lib/openWindow' import { openExternalBrowserIfDesktop } from 'lib/openWindow'
import { isCursorInFunctionDefinition } from 'lang/queryAst'
import { commandBarActor } from 'machines/commandBarMachine' import { commandBarActor } from 'machines/commandBarMachine'
import { isArray } from 'lib/utils' import { isArray } from 'lib/utils'
@ -37,7 +37,12 @@ export function Toolbar({
const buttonBorderClassName = '!border-transparent' const buttonBorderClassName = '!border-transparent'
const sketchPathId = useMemo(() => { const sketchPathId = useMemo(() => {
if (!isSingleCursorInPipe(context.selectionRanges, kclManager.ast)) if (
isCursorInFunctionDefinition(
kclManager.ast,
context.selectionRanges.graphSelections[0]
)
)
return false return false
return isCursorInSketchCommandRange( return isCursorInSketchCommandRange(
engineCommandManager.artifactGraph, engineCommandManager.artifactGraph,

View File

@ -125,14 +125,7 @@ export const ClientSideScene = ({
'mouseup', 'mouseup',
toSync(sceneInfra.onMouseUp, reportRejection) toSync(sceneInfra.onMouseUp, reportRejection)
) )
sceneEntitiesManager sceneEntitiesManager.tearDownSketch({ removeAxis: true })
.tearDownSketch()
.then(() => {
// no op
})
.catch((e) => {
console.error(e)
})
} }
}, []) }, [])
@ -191,12 +184,15 @@ const Overlays = () => {
style={{ zIndex: '99999999' }} style={{ zIndex: '99999999' }}
> >
{Object.entries(context.segmentOverlays) {Object.entries(context.segmentOverlays)
.filter((a) => a[1].visible) .flatMap((a) =>
.map(([pathToNodeString, overlay], index) => { a[1].map((b) => ({ pathToNodeString: a[0], overlay: b }))
)
.filter((a) => a.overlay.visible)
.map(({ pathToNodeString, overlay }, index) => {
return ( return (
<Overlay <Overlay
overlay={overlay} overlay={overlay}
key={pathToNodeString} key={pathToNodeString + String(index)}
pathToNodeString={pathToNodeString} pathToNodeString={pathToNodeString}
overlayIndex={index} overlayIndex={index}
/> />
@ -237,11 +233,17 @@ const Overlay = ({
const constraints = const constraints =
callExpression.type === 'CallExpression' callExpression.type === 'CallExpression'
? getConstraintInfo(callExpression, codeManager.code, overlay.pathToNode) ? getConstraintInfo(
callExpression,
codeManager.code,
overlay.pathToNode,
overlay.filterValue
)
: getConstraintInfoKw( : getConstraintInfoKw(
callExpression, callExpression,
codeManager.code, codeManager.code,
overlay.pathToNode overlay.pathToNode,
overlay.filterValue
) )
const offset = 20 // px const offset = 20 // px
@ -261,7 +263,6 @@ const Overlay = ({
state.matches({ Sketch: 'Tangential arc to' }) || state.matches({ Sketch: 'Tangential arc to' }) ||
state.matches({ Sketch: 'Rectangle tool' }) state.matches({ Sketch: 'Rectangle tool' })
) )
return ( return (
<div className={`absolute w-0 h-0`}> <div className={`absolute w-0 h-0`}>
<div <div
@ -319,17 +320,18 @@ const Overlay = ({
this will likely change soon when we implement multi-profile so we'll leave it for now this will likely change soon when we implement multi-profile so we'll leave it for now
issue: https://github.com/KittyCAD/modeling-app/issues/3910 issue: https://github.com/KittyCAD/modeling-app/issues/3910
*/} */}
{callExpression?.callee?.name !== 'circle' && ( {callExpression?.callee?.name !== 'circle' &&
<SegmentMenu callExpression?.callee?.name !== 'circleThreePoint' && (
verticalPosition={ <SegmentMenu
overlay.windowCoords[1] > window.innerHeight / 2 verticalPosition={
? 'top' overlay.windowCoords[1] > window.innerHeight / 2
: 'bottom' ? 'top'
} : 'bottom'
pathToNode={overlay.pathToNode} }
stdLibFnName={constraints[0]?.stdLibFnName} pathToNode={overlay.pathToNode}
/> stdLibFnName={constraints[0]?.stdLibFnName}
)} />
)}
</div> </div>
)} )}
</div> </div>
@ -450,6 +452,8 @@ export async function deleteSegment({
if (!sketchDetails) return if (!sketchDetails) return
await sceneEntitiesManager.updateAstAndRejigSketch( await sceneEntitiesManager.updateAstAndRejigSketch(
pathToNode, pathToNode,
sketchDetails.sketchNodePaths,
sketchDetails.planeNodePath,
modifiedAst, modifiedAst,
sketchDetails.zAxis, sketchDetails.zAxis,
sketchDetails.yAxis, sketchDetails.yAxis,

File diff suppressed because it is too large Load Diff

View File

@ -182,13 +182,15 @@ export class SceneInfra {
callbacks: (() => SegmentOverlayPayload | null)[] = [] callbacks: (() => SegmentOverlayPayload | null)[] = []
_overlayCallbacks(callbacks: (() => SegmentOverlayPayload | null)[]) { _overlayCallbacks(callbacks: (() => SegmentOverlayPayload | null)[]) {
const segmentOverlayPayload: SegmentOverlayPayload = { const segmentOverlayPayload: SegmentOverlayPayload = {
type: 'set-many', type: 'add-many',
overlays: {}, overlays: {},
} }
callbacks.forEach((cb) => { callbacks.forEach((cb) => {
const overlay = cb() const overlay = cb()
if (overlay?.type === 'set-one') { if (overlay?.type === 'set-one') {
segmentOverlayPayload.overlays[overlay.pathToNodeString] = overlay.seg segmentOverlayPayload.overlays[overlay.pathToNodeString] = overlay.seg
} else if (overlay?.type === 'add-many') {
Object.assign(segmentOverlayPayload.overlays, overlay.overlays)
} }
}) })
this.modelingSend({ this.modelingSend({
@ -213,25 +215,27 @@ export class SceneInfra {
overlayThrottleMap: { [pathToNodeString: string]: number } = {} overlayThrottleMap: { [pathToNodeString: string]: number } = {}
updateOverlayDetails({ updateOverlayDetails({
arrowGroup, handle,
group, group,
isHandlesVisible, isHandlesVisible,
from, from,
to, to,
angle, angle,
hasThreeDotMenu,
}: { }: {
arrowGroup: Group handle: Group
group: Group group: Group
isHandlesVisible: boolean isHandlesVisible: boolean
from: Coords2d from: Coords2d
to: Coords2d to: Coords2d
hasThreeDotMenu: boolean
angle?: number angle?: number
}): SegmentOverlayPayload | null { }): SegmentOverlayPayload | null {
if (!group.userData.draft && group.userData.pathToNode && arrowGroup) { if (!group.userData.draft && group.userData.pathToNode && handle) {
const vector = new Vector3(0, 0, 0) const vector = new Vector3(0, 0, 0)
// Get the position of the object3D in world space // Get the position of the object3D in world space
arrowGroup.getWorldPosition(vector) handle.getWorldPosition(vector)
// Project that position to screen space // Project that position to screen space
vector.project(this.camControls.camera) vector.project(this.camControls.camera)
@ -244,13 +248,16 @@ export class SceneInfra {
return { return {
type: 'set-one', type: 'set-one',
pathToNodeString, pathToNodeString,
seg: { seg: [
windowCoords: [x, y], {
angle: _angle, windowCoords: [x, y],
group, angle: _angle,
pathToNode: group.userData.pathToNode, group,
visible: isHandlesVisible, pathToNode: group.userData.pathToNode,
}, visible: isHandlesVisible,
hasThreeDotMenu,
},
],
} }
} }
return null return null

View File

@ -31,6 +31,12 @@ import {
CIRCLE_SEGMENT, CIRCLE_SEGMENT,
CIRCLE_SEGMENT_BODY, CIRCLE_SEGMENT_BODY,
CIRCLE_SEGMENT_DASH, CIRCLE_SEGMENT_DASH,
CIRCLE_THREE_POINT_HANDLE1,
CIRCLE_THREE_POINT_HANDLE2,
CIRCLE_THREE_POINT_HANDLE3,
CIRCLE_THREE_POINT_SEGMENT,
CIRCLE_THREE_POINT_SEGMENT_BODY,
CIRCLE_THREE_POINT_SEGMENT_DASH,
EXTRA_SEGMENT_HANDLE, EXTRA_SEGMENT_HANDLE,
EXTRA_SEGMENT_OFFSET_PX, EXTRA_SEGMENT_OFFSET_PX,
HIDE_HOVER_SEGMENT_LENGTH, HIDE_HOVER_SEGMENT_LENGTH,
@ -48,19 +54,26 @@ import {
import { getTangentPointFromPreviousArc } from 'lib/utils2d' import { getTangentPointFromPreviousArc } from 'lib/utils2d'
import { import {
ARROWHEAD, ARROWHEAD,
CIRCLE_3_POINT_DRAFT_CIRCLE,
DRAFT_POINT, DRAFT_POINT,
SceneInfra, SceneInfra,
SEGMENT_LENGTH_LABEL, SEGMENT_LENGTH_LABEL,
SEGMENT_LENGTH_LABEL_OFFSET_PX, SEGMENT_LENGTH_LABEL_OFFSET_PX,
SEGMENT_LENGTH_LABEL_TEXT, SEGMENT_LENGTH_LABEL_TEXT,
SKETCH_LAYER,
} from './sceneInfra' } from './sceneInfra'
import { Themes, getThemeColorForThreeJs } from 'lib/theme' import { Themes, getThemeColorForThreeJs } from 'lib/theme'
import { normaliseAngle, roundOff } from 'lib/utils' import { normaliseAngle, roundOff } from 'lib/utils'
import { SegmentOverlayPayload } from 'machines/modelingMachine' import {
SegmentOverlay,
SegmentOverlayPayload,
SegmentOverlays,
} from 'machines/modelingMachine'
import { SegmentInputs } from 'lang/std/stdTypes' import { SegmentInputs } from 'lang/std/stdTypes'
import { err } from 'lib/trap' import { err } from 'lib/trap'
import { editorManager, sceneInfra } from 'lib/singletons' import { editorManager, sceneInfra } from 'lib/singletons'
import { Selections } from 'lib/selections' import { Selections } from 'lib/selections'
import { calculate_circle_from_3_points } from 'wasm-lib/pkg/wasm_lib'
import { commandBarActor } from 'machines/commandBarMachine' import { commandBarActor } from 'machines/commandBarMachine'
interface CreateSegmentArgs { interface CreateSegmentArgs {
@ -307,11 +320,12 @@ class StraightSegment implements SegmentUtils {
} }
return () => return () =>
sceneInfra.updateOverlayDetails({ sceneInfra.updateOverlayDetails({
arrowGroup, handle: arrowGroup,
group, group,
isHandlesVisible, isHandlesVisible,
from, from,
to, to,
hasThreeDotMenu: true,
}) })
} }
} }
@ -483,12 +497,13 @@ class TangentialArcToSegment implements SegmentUtils {
) )
return () => return () =>
sceneInfra.updateOverlayDetails({ sceneInfra.updateOverlayDetails({
arrowGroup, handle: arrowGroup,
group, group,
isHandlesVisible, isHandlesVisible,
from, from,
to, to,
angle, angle,
hasThreeDotMenu: true,
}) })
} }
} }
@ -684,35 +699,255 @@ class CircleSegment implements SegmentUtils {
} }
return () => return () =>
sceneInfra.updateOverlayDetails({ sceneInfra.updateOverlayDetails({
arrowGroup, handle: arrowGroup,
group, group,
isHandlesVisible, isHandlesVisible,
from: from, from: from,
to: [center[0], center[1]], to: [center[0], center[1]],
angle: Math.PI / 4, angle: Math.PI / 4,
hasThreeDotMenu: true,
}) })
} }
} }
class CircleThreePointSegment implements SegmentUtils {
init: SegmentUtils['init'] = ({
input,
id,
pathToNode,
isDraftSegment,
scale = 1,
theme,
isSelected = false,
sceneInfra,
prevSegment,
}) => {
if (input.type !== 'circle-three-point-segment') {
return new Error('Invalid segment type')
}
const { p1, p2, p3 } = input
const { center_x, center_y, radius } = calculate_circle_from_3_points(
p1[0],
p1[1],
p2[0],
p2[1],
p3[0],
p3[1]
)
const center: [number, number] = [center_x, center_y]
const baseColor = getThemeColorForThreeJs(theme)
const color = isSelected ? 0x0000ff : baseColor
const group = new Group()
const geometry = createArcGeometry({
center,
radius,
startAngle: 0,
endAngle: Math.PI * 2,
ccw: true,
isDashed: isDraftSegment,
scale,
})
const mat = new MeshBasicMaterial({ color })
const arcMesh = new Mesh(geometry, mat)
const meshType = isDraftSegment
? CIRCLE_THREE_POINT_SEGMENT_DASH
: CIRCLE_THREE_POINT_SEGMENT_BODY
const handle1 = createCircleThreePointHandle(
scale,
theme,
CIRCLE_THREE_POINT_HANDLE1,
color
)
const handle2 = createCircleThreePointHandle(
scale,
theme,
CIRCLE_THREE_POINT_HANDLE2,
color
)
const handle3 = createCircleThreePointHandle(
scale,
theme,
CIRCLE_THREE_POINT_HANDLE3,
color
)
arcMesh.userData.type = meshType
arcMesh.name = meshType
group.userData = {
type: CIRCLE_THREE_POINT_SEGMENT,
draft: isDraftSegment,
id,
p1,
p2,
p3,
ccw: true,
prevSegment,
pathToNode,
isSelected,
baseColor,
}
group.name = CIRCLE_THREE_POINT_SEGMENT
group.add(arcMesh, handle1, handle2, handle3)
const updateOverlaysCallback = this.update({
prevSegment,
input,
group,
scale,
sceneInfra,
})
if (err(updateOverlaysCallback)) return updateOverlaysCallback
return {
group,
updateOverlaysCallback,
}
}
update: SegmentUtils['update'] = ({
input,
group,
scale = 1,
sceneInfra,
}) => {
if (input.type !== 'circle-three-point-segment') {
return new Error('Invalid segment type')
}
const { p1, p2, p3 } = input
group.userData.p1 = p1
group.userData.p2 = p2
group.userData.p3 = p3
const { center_x, center_y, radius } = calculate_circle_from_3_points(
p1[0],
p1[1],
p2[0],
p2[1],
p3[0],
p3[1]
)
const center: [number, number] = [center_x, center_y]
const points = [p1, p2, p3]
const handles = [
CIRCLE_THREE_POINT_HANDLE1,
CIRCLE_THREE_POINT_HANDLE2,
CIRCLE_THREE_POINT_HANDLE3,
].map((handle) => group.getObjectByName(handle) as Group)
handles.forEach((handle, i) => {
const point = points[i]
if (handle && point) {
handle.position.set(point[0], point[1], 0)
handle.scale.set(scale, scale, scale)
handle.visible = true
}
})
const pxLength = (2 * radius * Math.PI) / scale
const shouldHideIdle = pxLength < HIDE_SEGMENT_LENGTH
const shouldHideHover = pxLength < HIDE_HOVER_SEGMENT_LENGTH
const hoveredParent =
sceneInfra.hoveredObject &&
getParentGroup(sceneInfra.hoveredObject, [CIRCLE_SEGMENT])
let isHandlesVisible = !shouldHideIdle
if (hoveredParent && hoveredParent?.uuid === group?.uuid) {
isHandlesVisible = !shouldHideHover
}
const circleSegmentBody = group.children.find(
(child) => child.userData.type === CIRCLE_THREE_POINT_SEGMENT_BODY
) as Mesh
if (circleSegmentBody) {
const newGeo = createArcGeometry({
radius,
center,
startAngle: 0,
endAngle: Math.PI * 2,
ccw: true,
scale,
})
circleSegmentBody.geometry = newGeo
}
const circleSegmentBodyDashed = group.getObjectByName(
CIRCLE_THREE_POINT_SEGMENT_DASH
)
if (circleSegmentBodyDashed instanceof Mesh) {
// consider throttling the whole updateTangentialArcToSegment
// if there are more perf considerations going forward
circleSegmentBodyDashed.geometry = createArcGeometry({
center,
radius,
ccw: true,
// make the start end where the handle is
startAngle: Math.PI * 0.25,
endAngle: Math.PI * 2.25,
isDashed: true,
scale,
})
}
return () => {
const overlays: SegmentOverlays = {}
const points = [p1, p2, p3]
const overlayDetails = handles.map((handle, index) => {
const currentPoint = points[index]
const angle = Math.atan2(
currentPoint[1] - center[1],
currentPoint[0] - center[0]
)
return sceneInfra.updateOverlayDetails({
handle,
group,
isHandlesVisible,
from: [0, 0],
to: [center[0], center[1]],
angle: angle,
hasThreeDotMenu: index === 0,
})
})
const segmentOverlays: SegmentOverlay[] = []
overlayDetails.forEach((payload, index) => {
if (payload?.type === 'set-one') {
overlays[payload.pathToNodeString] = payload.seg
segmentOverlays.push({
...payload.seg[0],
filterValue: index === 0 ? 'p1' : index === 1 ? 'p2' : 'p3',
})
}
})
const segmentOverlayPayload: SegmentOverlayPayload = {
type: 'set-one',
pathToNodeString:
overlayDetails[0]?.type === 'set-one'
? overlayDetails[0].pathToNodeString
: '',
seg: segmentOverlays,
}
return segmentOverlayPayload
}
}
}
export function createProfileStartHandle({ export function createProfileStartHandle({
from, from,
isDraft = false, isDraft = false,
scale = 1, scale = 1,
theme, theme,
isSelected, isSelected,
size = 12,
...rest ...rest
}: { }: {
from: Coords2d from: Coords2d
scale?: number scale?: number
theme: Themes theme: Themes
isSelected?: boolean isSelected?: boolean
size?: number
} & ( } & (
| { isDraft: true } | { isDraft: true }
| { isDraft: false; id: string; pathToNode: PathToNode } | { isDraft: false; id: string; pathToNode: PathToNode }
)) { )) {
const group = new Group() const group = new Group()
const geometry = new BoxGeometry(12, 12, 12) // in pixels scaled later const geometry = new BoxGeometry(size, size, size) // in pixels scaled later
const baseColor = getThemeColorForThreeJs(theme) const baseColor = getThemeColorForThreeJs(theme)
const color = isSelected ? 0x0000ff : baseColor const color = isSelected ? 0x0000ff : baseColor
const body = new MeshBasicMaterial({ color }) const body = new MeshBasicMaterial({ color })
@ -774,6 +1009,32 @@ function createCircleCenterHandle(
circleCenterGroup.scale.set(scale, scale, scale) circleCenterGroup.scale.set(scale, scale, scale)
return circleCenterGroup return circleCenterGroup
} }
function createCircleThreePointHandle(
scale = 1,
theme: Themes,
name:
| 'circle-three-point-handle1'
| 'circle-three-point-handle2'
| 'circle-three-point-handle3',
color?: number
): Group {
const circleCenterGroup = new Group()
const geometry = new BoxGeometry(12, 12, 12) // in pixels scaled later
const baseColor = getThemeColorForThreeJs(theme)
const body = new MeshBasicMaterial({ color })
const mesh = new Mesh(geometry, body)
circleCenterGroup.add(mesh)
circleCenterGroup.userData = {
type: name,
baseColor,
}
circleCenterGroup.name = name
circleCenterGroup.scale.set(scale, scale, scale)
return circleCenterGroup
}
function createExtraSegmentHandle( function createExtraSegmentHandle(
scale: number, scale: number,
@ -1100,4 +1361,5 @@ export const segmentUtils = {
straight: new StraightSegment(), straight: new StraightSegment(),
tangentialArcTo: new TangentialArcToSegment(), tangentialArcTo: new TangentialArcToSegment(),
circle: new CircleSegment(), circle: new CircleSegment(),
circleThreePoint: new CircleThreePointSegment(),
} as const } as const

View File

@ -196,7 +196,6 @@ function ReviewingButton() {
type="submit" type="submit"
form="review-form" form="review-form"
className="w-fit !p-0 rounded-sm hover:shadow" className="w-fit !p-0 rounded-sm hover:shadow"
data-testid="command-bar-submit"
iconStart={{ iconStart={{
icon: 'checkmark', icon: 'checkmark',
bgClassName: 'p-1 rounded-sm !bg-primary hover:brightness-110', bgClassName: 'p-1 rounded-sm !bg-primary hover:brightness-110',
@ -215,7 +214,6 @@ function GatheringArgsButton() {
type="submit" type="submit"
form="arg-form" form="arg-form"
className="w-fit !p-0 rounded-sm hover:shadow" className="w-fit !p-0 rounded-sm hover:shadow"
data-testid="command-bar-continue"
iconStart={{ iconStart={{
icon: 'arrowRight', icon: 'arrowRight',
bgClassName: 'p-1 rounded-sm !bg-primary hover:brightness-110', bgClassName: 'p-1 rounded-sm !bg-primary hover:brightness-110',

View File

@ -20,7 +20,6 @@ import { createIdentifier, createVariableDeclaration } from 'lang/modifyAst'
import { useCodeMirror } from 'components/ModelingSidebar/ModelingPanes/CodeEditor' import { useCodeMirror } from 'components/ModelingSidebar/ModelingPanes/CodeEditor'
import { useSelector } from '@xstate/react' import { useSelector } from '@xstate/react'
import { commandBarActor, useCommandBarState } from 'machines/commandBarMachine' import { commandBarActor, useCommandBarState } from 'machines/commandBarMachine'
import toast from 'react-hot-toast'
const machineContextSelector = (snapshot?: { const machineContextSelector = (snapshot?: {
context: Record<string, unknown> context: Record<string, unknown>
@ -98,7 +97,6 @@ function CommandBarKclInput({
value, value,
initialVariableName, initialVariableName,
}) })
const varMentionData: Completion[] = prevVariables.map((v) => ({ const varMentionData: Completion[] = prevVariables.map((v) => ({
label: v.key, label: v.key,
detail: String(roundOff(v.value as number)), detail: String(roundOff(v.value as number)),
@ -172,15 +170,7 @@ function CommandBarKclInput({
function handleSubmit(e?: React.FormEvent<HTMLFormElement>) { function handleSubmit(e?: React.FormEvent<HTMLFormElement>) {
e?.preventDefault() e?.preventDefault()
if (!canSubmit || valueNode === null) { if (!canSubmit || valueNode === null) return
// Gotcha: Our application can attempt to submit a command value before the command bar kcl input is ready. Notify the scene and user.
if (!canSubmit) {
toast.error('Unable to submit command')
} else if (valueNode === null) {
toast.error('Unable to submit undefined command value')
}
return
}
onSubmit( onSubmit(
createNewVariable createNewVariable

View File

@ -57,7 +57,7 @@ function CommandComboBox({
onKeyDown={(event) => { onKeyDown={(event) => {
if ( if (
(event.metaKey && event.key === 'k') || (event.metaKey && event.key === 'k') ||
event.key === 'Escape' (event.key === 'Backspace' && !event.currentTarget.value)
) { ) {
event.preventDefault() event.preventDefault()
commandBarActor.send({ type: 'Close' }) commandBarActor.send({ type: 'Close' })

View File

@ -2,15 +2,11 @@ import { Dialog } from '@headlessui/react'
import { ActionButton } from './ActionButton' import { ActionButton } from './ActionButton'
import { useSettingsAuthContext } from 'hooks/useSettingsAuthContext' import { useSettingsAuthContext } from 'hooks/useSettingsAuthContext'
import { useState } from 'react' import { useState } from 'react'
import { useSearchParams } from 'react-router-dom'
import { CREATE_FILE_URL_PARAM } from 'lib/constants'
const DownloadAppBanner = () => { const DownloadAppBanner = () => {
const [searchParams] = useSearchParams()
const hasCreateFileParam = searchParams.has(CREATE_FILE_URL_PARAM)
const { settings } = useSettingsAuthContext() const { settings } = useSettingsAuthContext()
const [isBannerDismissed, setIsBannerDismissed] = useState( const [isBannerDismissed, setIsBannerDismissed] = useState(
settings.context.app.dismissWebBanner.current || hasCreateFileParam settings.context.app.dismissWebBanner.current
) )
return ( return (

View File

@ -329,7 +329,7 @@ export const FileMachineProvider = ({
onSubmit: async (data) => { onSubmit: async (data) => {
if (data.method === 'overwrite') { if (data.method === 'overwrite') {
codeManager.updateCodeStateEditor(data.code) codeManager.updateCodeStateEditor(data.code)
await kclManager.executeCode(true) await kclManager.executeCode({ zoomToFit: true })
await codeManager.writeToFile() await codeManager.writeToFile()
} else if (data.method === 'newFile' && isDesktop()) { } else if (data.method === 'newFile' && isDesktop()) {
send({ send({

View File

@ -21,7 +21,6 @@ import { ContextMenu, ContextMenuItem } from './ContextMenu'
import usePlatform from 'hooks/usePlatform' import usePlatform from 'hooks/usePlatform'
import { FileEntry } from 'lib/project' import { FileEntry } from 'lib/project'
import { useFileSystemWatcher } from 'hooks/useFileSystemWatcher' import { useFileSystemWatcher } from 'hooks/useFileSystemWatcher'
import { normalizeLineEndings } from 'lib/codeEditor'
import { reportRejection } from 'lib/trap' import { reportRejection } from 'lib/trap'
function getIndentationCSS(level: number) { function getIndentationCSS(level: number) {
@ -190,24 +189,25 @@ const FileTreeItem = ({
// Because subtrees only render when they are opened, that means this // Because subtrees only render when they are opened, that means this
// only listens when they open. Because this acts like a useEffect, when // only listens when they open. Because this acts like a useEffect, when
// the ReactNodes are destroyed, so is this listener :) // the ReactNodes are destroyed, so is this listener :)
useFileSystemWatcher( /** Disabling this in favor of faster file writes until we fix file writing **/
async (eventType, path) => { /* useFileSystemWatcher(
// Prevents a cyclic read / write causing editor problems such as * async (eventType, path) => {
// misplaced cursor positions. * // Prevents a cyclic read / write causing editor problems such as
if (codeManager.writeCausedByAppCheckedInFileTreeFileSystemWatcher) { * // misplaced cursor positions.
codeManager.writeCausedByAppCheckedInFileTreeFileSystemWatcher = false * if (codeManager.writeCausedByAppCheckedInFileTreeFileSystemWatcher) {
return * codeManager.writeCausedByAppCheckedInFileTreeFileSystemWatcher = false
} * return
* }
if (isCurrentFile && eventType === 'change') { * if (isCurrentFile && eventType === 'change') {
let code = await window.electron.readFile(path, { encoding: 'utf-8' }) * let code = await window.electron.readFile(path, { encoding: 'utf-8' })
code = normalizeLineEndings(code) * code = normalizeLineEndings(code)
codeManager.updateCodeStateEditor(code) * codeManager.updateCodeStateEditor(code)
} * }
fileSend({ type: 'Refresh' }) * fileSend({ type: 'Refresh' })
}, * },
[fileOrDir.path] * [fileOrDir.path]
) * ) */
const showNewTreeEntry = const showNewTreeEntry =
newTreeEntry !== undefined && newTreeEntry !== undefined &&
@ -263,7 +263,7 @@ const FileTreeItem = ({
await codeManager.writeToFile() await codeManager.writeToFile()
// Prevent seeing the model built one piece at a time when changing files // Prevent seeing the model built one piece at a time when changing files
await kclManager.executeCode(true) await kclManager.executeCode({ zoomToFit: true })
} else { } else {
// Let the lsp servers know we closed a file. // Let the lsp servers know we closed a file.
onFileClose(currentFile?.path || null, project?.path || null) onFileClose(currentFile?.path || null, project?.path || null)

View File

@ -25,7 +25,7 @@ import { useSetupEngineManager } from 'hooks/useSetupEngineManager'
import { useSettingsAuthContext } from 'hooks/useSettingsAuthContext' import { useSettingsAuthContext } from 'hooks/useSettingsAuthContext'
import { import {
isCursorInSketchCommandRange, isCursorInSketchCommandRange,
updatePathToNodeFromMap, updateSketchDetailsNodePaths,
} from 'lang/util' } from 'lang/util'
import { import {
kclManager, kclManager,
@ -65,17 +65,32 @@ import {
replaceValueAtNodePath, replaceValueAtNodePath,
sketchOnExtrudedFace, sketchOnExtrudedFace,
sketchOnOffsetPlane, sketchOnOffsetPlane,
splitPipedProfile,
startSketchOnDefault, startSketchOnDefault,
} from 'lang/modifyAst' } from 'lang/modifyAst'
import { PathToNode, Program, parse, recast, resultIsOk } from 'lang/wasm' import {
import { artifactIsPlaneWithPaths, isSingleCursorInPipe } from 'lang/queryAst' CodeRef,
PathToNode,
Program,
VariableDeclaration,
parse,
recast,
resultIsOk,
} from 'lang/wasm'
import {
artifactIsPlaneWithPaths,
doesSketchPipeNeedSplitting,
getNodeFromPath,
isCursorInFunctionDefinition,
traverse,
} from 'lang/queryAst'
import { getNodePathFromSourceRange } from 'lang/queryAstNodePathUtils' import { getNodePathFromSourceRange } from 'lang/queryAstNodePathUtils'
import { exportFromEngine } from 'lib/exportFromEngine' import { exportFromEngine } from 'lib/exportFromEngine'
import { Models } from '@kittycad/lib/dist/types/src' import { Models } from '@kittycad/lib/dist/types/src'
import toast from 'react-hot-toast' import toast from 'react-hot-toast'
import { useLoaderData, useNavigate, useSearchParams } from 'react-router-dom' import { useLoaderData, useNavigate, useSearchParams } from 'react-router-dom'
import { letEngineAnimateAndSyncCamAfter } from 'clientSideScene/CameraControls' import { letEngineAnimateAndSyncCamAfter } from 'clientSideScene/CameraControls'
import { err, reportRejection, trap } from 'lib/trap' import { err, reportRejection, trap, reject } from 'lib/trap'
import { import {
ExportIntent, ExportIntent,
EngineConnectionStateType, EngineConnectionStateType,
@ -86,6 +101,10 @@ import { useFileContext } from 'hooks/useFileContext'
import { uuidv4 } from 'lib/utils' import { uuidv4 } from 'lib/utils'
import { IndexLoaderData } from 'lib/types' import { IndexLoaderData } from 'lib/types'
import { Node } from 'wasm-lib/kcl/bindings/Node' import { Node } from 'wasm-lib/kcl/bindings/Node'
import {
getPathsFromArtifact,
getPlaneFromArtifact,
} from 'lang/std/artifactGraph'
import { promptToEditFlow } from 'lib/promptToEdit' import { promptToEditFlow } from 'lib/promptToEdit'
import { kclEditorActor } from 'machines/kclEditorMachine' import { kclEditorActor } from 'machines/kclEditorMachine'
import { commandBarActor } from 'machines/commandBarMachine' import { commandBarActor } from 'machines/commandBarMachine'
@ -163,38 +182,57 @@ export const ModelingMachineProvider = ({
'enable copilot': () => { 'enable copilot': () => {
editorManager.setCopilotEnabled(true) editorManager.setCopilotEnabled(true)
}, },
'sketch exit execute': ({ context: { store } }) => { // tsc reports this typing as perfectly fine, but eslint is complaining.
// TODO: Remove this async callback. For some reason eslint wouldn't // It's actually nonsensical, so I'm quieting.
// let me disable @typescript-eslint/no-misused-promises for the line. // eslint-disable-next-line @typescript-eslint/no-misused-promises
;(async () => { 'sketch exit execute': async ({
// When cancelling the sketch mode we should disable sketch mode within the engine. context: { store },
await engineCommandManager.sendSceneCommand({ }): Promise<void> => {
type: 'modeling_cmd_req', // When cancelling the sketch mode we should disable sketch mode within the engine.
cmd_id: uuidv4(), await engineCommandManager.sendSceneCommand({
cmd: { type: 'sketch_mode_disable' }, type: 'modeling_cmd_req',
cmd_id: uuidv4(),
cmd: { type: 'sketch_mode_disable' },
})
sceneInfra.camControls.syncDirection = 'clientToEngine'
if (cameraProjection.current === 'perspective') {
await sceneInfra.camControls.snapToPerspectiveBeforeHandingBackControlToEngine()
}
sceneInfra.camControls.syncDirection = 'engineToClient'
store.videoElement?.pause()
return kclManager.executeCode().then(() => {
if (engineCommandManager.engineConnection?.idleMode) return
store.videoElement?.play().catch((e) => {
console.warn('Video playing was prevented', e)
}) })
})
sceneInfra.camControls.syncDirection = 'clientToEngine' sceneInfra.camControls.syncDirection = 'clientToEngine'
if (cameraProjection.current === 'perspective') { if (cameraProjection.current === 'perspective') {
await sceneInfra.camControls.snapToPerspectiveBeforeHandingBackControlToEngine() await sceneInfra.camControls.snapToPerspectiveBeforeHandingBackControlToEngine()
} }
sceneInfra.camControls.syncDirection = 'engineToClient' sceneInfra.camControls.syncDirection = 'engineToClient'
store.videoElement?.pause() store.videoElement?.pause()
return kclManager return kclManager
.executeCode() .executeCode()
.then(() => { .then(() => {
if (engineCommandManager.engineConnection?.idleMode) return if (engineCommandManager.engineConnection?.idleMode) return
store.videoElement?.play().catch((e) => { store.videoElement?.play().catch((e) => {
console.warn('Video playing was prevented', e) console.warn('Video playing was prevented', e)
})
}) })
.catch(reportRejection) })
})().catch(reportRejection) .catch(reportRejection)
}, },
'Set mouse state': assign(({ context, event }) => { 'Set mouse state': assign(({ context, event }) => {
if (event.type !== 'Set mouse state') return {} if (event.type !== 'Set mouse state') return {}
@ -254,7 +292,11 @@ export const ModelingMachineProvider = ({
'Set Segment Overlays': assign({ 'Set Segment Overlays': assign({
segmentOverlays: ({ context: { segmentOverlays }, event }) => { segmentOverlays: ({ context: { segmentOverlays }, event }) => {
if (event.type !== 'Set Segment Overlays') return {} if (event.type !== 'Set Segment Overlays') return {}
if (event.data.type === 'set-many') return event.data.overlays if (event.data.type === 'add-many')
return {
...segmentOverlays,
...event.data.overlays,
}
if (event.data.type === 'set-one') if (event.data.type === 'set-one')
return { return {
...segmentOverlays, ...segmentOverlays,
@ -287,7 +329,7 @@ export const ModelingMachineProvider = ({
return { return {
sketchDetails: { sketchDetails: {
...sketchDetails, ...sketchDetails,
sketchPathToNode: event.data, sketchEntryNodePath: event.data,
}, },
} }
}), }),
@ -329,83 +371,11 @@ export const ModelingMachineProvider = ({
otherSelections: [], otherSelections: [],
} }
} else if (setSelections.selection && editorManager.isShiftDown) { } else if (setSelections.selection && editorManager.isShiftDown) {
// selecting and deselecting multiple objects
/**
* There are two scenarios:
* 1. General case:
* When selecting and deselecting edges,
* faces or segment (during sketch edit)
* we use its artifact ID to identify the selection
* 2. Initial sketch setup:
* The artifact is not yet created
* so we use the codeRef.range
*/
let updatedSelections: typeof selectionRanges.graphSelections
// 1. General case: Artifact exists, use its ID
if (setSelections.selection.artifact?.id) {
// check if already selected
const alreadySelected = selectionRanges.graphSelections.some(
(selection) =>
selection.artifact?.id ===
setSelections.selection?.artifact?.id
)
if (
alreadySelected &&
setSelections.selection?.artifact?.id
) {
// remove it
updatedSelections = selectionRanges.graphSelections.filter(
(selection) =>
selection.artifact?.id !==
setSelections.selection?.artifact?.id
)
} else {
// add it
updatedSelections = [
...selectionRanges.graphSelections,
setSelections.selection,
]
}
} else {
// 2. Initial sketch setup: Artifact not yet created use codeRef.range
const selectionRange = JSON.stringify(
setSelections.selection?.codeRef?.range
)
// check if already selected
const alreadySelected = selectionRanges.graphSelections.some(
(selection) => {
const existingRange = JSON.stringify(
selection.codeRef?.range
)
return existingRange === selectionRange
}
)
if (
alreadySelected &&
setSelections.selection?.codeRef?.range
) {
// remove it
updatedSelections = selectionRanges.graphSelections.filter(
(selection) =>
JSON.stringify(selection.codeRef?.range) !==
selectionRange
)
} else {
// add it
updatedSelections = [
...selectionRanges.graphSelections,
setSelections.selection,
]
}
}
selections = { selections = {
graphSelections: updatedSelections, graphSelections: [
...selectionRanges.graphSelections,
setSelections.selection,
],
otherSelections: selectionRanges.otherSelections, otherSelections: selectionRanges.otherSelections,
} }
} }
@ -483,9 +453,17 @@ export const ModelingMachineProvider = ({
selectionRanges: setSelections.selection, selectionRanges: setSelections.selection,
sketchDetails: { sketchDetails: {
...sketchDetails, ...sketchDetails,
sketchPathToNode: sketchEntryNodePath:
setSelections.updatedPathToNode || setSelections.updatedSketchEntryNodePath ||
sketchDetails?.sketchPathToNode || sketchDetails?.sketchEntryNodePath ||
[],
sketchNodePaths:
setSelections.updatedSketchNodePaths ||
sketchDetails?.sketchNodePaths ||
[],
planeNodePath:
setSelections.updatedPlaneNodePath ||
sketchDetails?.planeNodePath ||
[], [],
}, },
} }
@ -638,7 +616,12 @@ export const ModelingMachineProvider = ({
if (artifactIsPlaneWithPaths(selectionRanges)) { if (artifactIsPlaneWithPaths(selectionRanges)) {
return true return true
} }
if (!isSingleCursorInPipe(selectionRanges, kclManager.ast)) if (
isCursorInFunctionDefinition(
kclManager.ast,
selectionRanges.graphSelections[0]
)
)
return false return false
return !!isCursorInSketchCommandRange( return !!isCursorInSketchCommandRange(
engineCommandManager.artifactGraph, engineCommandManager.artifactGraph,
@ -669,10 +652,32 @@ export const ModelingMachineProvider = ({
// this assumes no changes have been made to the sketch besides what we did when entering the sketch // this assumes no changes have been made to the sketch besides what we did when entering the sketch
// i.e. doesn't account for user's adding code themselves, maybe we need store a flag userEditedSinceSketchMode? // i.e. doesn't account for user's adding code themselves, maybe we need store a flag userEditedSinceSketchMode?
const newAst = structuredClone(kclManager.ast) const newAst = structuredClone(kclManager.ast)
const varDecIndex = sketchDetails.sketchPathToNode[1][0] const varDecIndex = sketchDetails.planeNodePath[1][0]
const varDec = getNodeFromPath<VariableDeclaration>(
newAst,
sketchDetails.planeNodePath,
'VariableDeclaration'
)
if (err(varDec)) return reject(new Error('No varDec'))
const variableName = varDec.node.declaration.id.name
let isIdentifierUsed = false
traverse(newAst, {
enter: (node) => {
if (
node.type === 'Identifier' &&
node.name === variableName
) {
isIdentifierUsed = true
}
},
})
if (isIdentifierUsed) return
// remove body item at varDecIndex // remove body item at varDecIndex
newAst.body = newAst.body.filter((_, i) => i !== varDecIndex) newAst.body = newAst.body.filter((_, i) => i !== varDecIndex)
await kclManager.executeAstMock(newAst) await kclManager.executeAstMock(newAst)
await codeManager.updateEditorWithAstAndWriteToFile(newAst)
} }
sceneInfra.setCallbacks({ sceneInfra.setCallbacks({
onClick: () => {}, onClick: () => {},
@ -682,7 +687,7 @@ export const ModelingMachineProvider = ({
} }
), ),
'animate-to-face': fromPromise(async ({ input }) => { 'animate-to-face': fromPromise(async ({ input }) => {
if (!input) return undefined if (!input) return null
if (input.type === 'extrudeFace' || input.type === 'offsetPlane') { if (input.type === 'extrudeFace' || input.type === 'offsetPlane') {
const sketched = const sketched =
input.type === 'extrudeFace' input.type === 'extrudeFace'
@ -709,7 +714,9 @@ export const ModelingMachineProvider = ({
await letEngineAnimateAndSyncCamAfter(engineCommandManager, id) await letEngineAnimateAndSyncCamAfter(engineCommandManager, id)
sceneInfra.camControls.syncDirection = 'clientToEngine' sceneInfra.camControls.syncDirection = 'clientToEngine'
return { return {
sketchPathToNode: pathToNewSketchNode, sketchEntryNodePath: [],
planeNodePath: pathToNewSketchNode,
sketchNodePaths: [],
zAxis: input.zAxis, zAxis: input.zAxis,
yAxis: input.yAxis, yAxis: input.yAxis,
origin: input.position, origin: input.position,
@ -730,7 +737,9 @@ export const ModelingMachineProvider = ({
) )
return { return {
sketchPathToNode: pathToNode, sketchEntryNodePath: [],
planeNodePath: pathToNode,
sketchNodePaths: [],
zAxis: input.zAxis, zAxis: input.zAxis,
yAxis: input.yAxis, yAxis: input.yAxis,
origin: [0, 0, 0], origin: [0, 0, 0],
@ -739,12 +748,14 @@ export const ModelingMachineProvider = ({
}), }),
'animate-to-sketch': fromPromise( 'animate-to-sketch': fromPromise(
async ({ input: { selectionRanges } }) => { async ({ input: { selectionRanges } }) => {
const sourceRange = const sketchPathToNode =
selectionRanges.graphSelections[0]?.codeRef?.range selectionRanges.graphSelections[0]?.codeRef?.pathToNode
const sketchPathToNode = getNodePathFromSourceRange( const plane = getPlaneFromArtifact(
kclManager.ast, selectionRanges.graphSelections[0].artifact,
sourceRange engineCommandManager.artifactGraph
) )
if (err(plane)) return Promise.reject(plane)
const info = await getSketchOrientationDetails( const info = await getSketchOrientationDetails(
sketchPathToNode || [] sketchPathToNode || []
) )
@ -752,8 +763,22 @@ export const ModelingMachineProvider = ({
engineCommandManager, engineCommandManager,
info?.sketchDetails?.faceId || '' info?.sketchDetails?.faceId || ''
) )
return { const sketchPaths = getPathsFromArtifact({
artifact: selectionRanges.graphSelections[0].artifact,
sketchPathToNode: sketchPathToNode || [], sketchPathToNode: sketchPathToNode || [],
})
if (err(sketchPaths)) return Promise.reject(sketchPaths)
let codeRef =
'faceCodeRef' in plane && plane.faceCodeRef
? plane.faceCodeRef
: 'codeRef' in plane && plane.codeRef
? plane.codeRef
: null
if (!codeRef) return Promise.reject(new Error('No plane codeRef'))
return {
sketchEntryNodePath: sketchPathToNode || [],
sketchNodePaths: sketchPaths,
planeNodePath: codeRef.pathToNode,
zAxis: info.sketchDetails.zAxis || null, zAxis: info.sketchDetails.zAxis || null,
yAxis: info.sketchDetails.yAxis || null, yAxis: info.sketchDetails.yAxis || null,
origin: info.sketchDetails.origin.map( origin: info.sketchDetails.origin.map(
@ -766,7 +791,7 @@ export const ModelingMachineProvider = ({
'Get horizontal info': fromPromise( 'Get horizontal info': fromPromise(
async ({ input: { selectionRanges, sketchDetails } }) => { async ({ input: { selectionRanges, sketchDetails } }) => {
const { modifiedAst, pathToNodeMap } = const { modifiedAst, pathToNodeMap, exprInsertIndex } =
await applyConstraintHorzVertDistance({ await applyConstraintHorzVertDistance({
constraint: 'setHorzDistance', constraint: 'setHorzDistance',
selectionRanges, selectionRanges,
@ -778,13 +803,23 @@ export const ModelingMachineProvider = ({
if (!sketchDetails) if (!sketchDetails)
return Promise.reject(new Error('No sketch details')) return Promise.reject(new Error('No sketch details'))
const updatedPathToNode = updatePathToNodeFromMap(
sketchDetails.sketchPathToNode, const {
pathToNodeMap updatedSketchEntryNodePath,
) updatedSketchNodePaths,
updatedPlaneNodePath,
} = updateSketchDetailsNodePaths({
sketchEntryNodePath: sketchDetails.sketchEntryNodePath,
sketchNodePaths: sketchDetails.sketchNodePaths,
planeNodePath: sketchDetails.planeNodePath,
exprInsertIndex,
})
const updatedAst = const updatedAst =
await sceneEntitiesManager.updateAstAndRejigSketch( await sceneEntitiesManager.updateAstAndRejigSketch(
updatedPathToNode, updatedSketchEntryNodePath,
updatedSketchNodePaths,
updatedPlaneNodePath,
_modifiedAst, _modifiedAst,
sketchDetails.zAxis, sketchDetails.zAxis,
sketchDetails.yAxis, sketchDetails.yAxis,
@ -805,13 +840,15 @@ export const ModelingMachineProvider = ({
return { return {
selectionType: 'completeSelection', selectionType: 'completeSelection',
selection, selection,
updatedPathToNode, updatedSketchEntryNodePath,
updatedSketchNodePaths,
updatedPlaneNodePath,
} }
} }
), ),
'Get vertical info': fromPromise( 'Get vertical info': fromPromise(
async ({ input: { selectionRanges, sketchDetails } }) => { async ({ input: { selectionRanges, sketchDetails } }) => {
const { modifiedAst, pathToNodeMap } = const { modifiedAst, pathToNodeMap, exprInsertIndex } =
await applyConstraintHorzVertDistance({ await applyConstraintHorzVertDistance({
constraint: 'setVertDistance', constraint: 'setVertDistance',
selectionRanges, selectionRanges,
@ -822,13 +859,23 @@ export const ModelingMachineProvider = ({
const _modifiedAst = pResult.program const _modifiedAst = pResult.program
if (!sketchDetails) if (!sketchDetails)
return Promise.reject(new Error('No sketch details')) return Promise.reject(new Error('No sketch details'))
const updatedPathToNode = updatePathToNodeFromMap(
sketchDetails.sketchPathToNode, const {
pathToNodeMap updatedSketchEntryNodePath,
) updatedSketchNodePaths,
updatedPlaneNodePath,
} = updateSketchDetailsNodePaths({
sketchEntryNodePath: sketchDetails.sketchEntryNodePath,
sketchNodePaths: sketchDetails.sketchNodePaths,
planeNodePath: sketchDetails.planeNodePath,
exprInsertIndex,
})
const updatedAst = const updatedAst =
await sceneEntitiesManager.updateAstAndRejigSketch( await sceneEntitiesManager.updateAstAndRejigSketch(
updatedPathToNode, updatedSketchEntryNodePath,
updatedSketchNodePaths,
updatedPlaneNodePath,
_modifiedAst, _modifiedAst,
sketchDetails.zAxis, sketchDetails.zAxis,
sketchDetails.yAxis, sketchDetails.yAxis,
@ -849,7 +896,9 @@ export const ModelingMachineProvider = ({
return { return {
selectionType: 'completeSelection', selectionType: 'completeSelection',
selection, selection,
updatedPathToNode, updatedSketchEntryNodePath,
updatedSketchNodePaths,
updatedPlaneNodePath,
} }
} }
), ),
@ -859,14 +908,15 @@ export const ModelingMachineProvider = ({
selectionRanges, selectionRanges,
}) })
if (err(info)) return Promise.reject(info) if (err(info)) return Promise.reject(info)
const { modifiedAst, pathToNodeMap } = await (info.enabled const { modifiedAst, pathToNodeMap, exprInsertIndex } =
? applyConstraintAngleBetween({ await (info.enabled
selectionRanges, ? applyConstraintAngleBetween({
}) selectionRanges,
: applyConstraintAngleLength({ })
selectionRanges, : applyConstraintAngleLength({
angleOrLength: 'setAngle', selectionRanges,
})) angleOrLength: 'setAngle',
}))
const pResult = parse(recast(modifiedAst)) const pResult = parse(recast(modifiedAst))
if (trap(pResult) || !resultIsOk(pResult)) if (trap(pResult) || !resultIsOk(pResult))
return Promise.reject(new Error('Unexpected compilation error')) return Promise.reject(new Error('Unexpected compilation error'))
@ -875,13 +925,23 @@ export const ModelingMachineProvider = ({
if (!sketchDetails) if (!sketchDetails)
return Promise.reject(new Error('No sketch details')) return Promise.reject(new Error('No sketch details'))
const updatedPathToNode = updatePathToNodeFromMap(
sketchDetails.sketchPathToNode, const {
pathToNodeMap updatedSketchEntryNodePath,
) updatedSketchNodePaths,
updatedPlaneNodePath,
} = updateSketchDetailsNodePaths({
sketchEntryNodePath: sketchDetails.sketchEntryNodePath,
sketchNodePaths: sketchDetails.sketchNodePaths,
planeNodePath: sketchDetails.planeNodePath,
exprInsertIndex,
})
const updatedAst = const updatedAst =
await sceneEntitiesManager.updateAstAndRejigSketch( await sceneEntitiesManager.updateAstAndRejigSketch(
updatedPathToNode, updatedSketchEntryNodePath,
updatedSketchNodePaths,
updatedPlaneNodePath,
_modifiedAst, _modifiedAst,
sketchDetails.zAxis, sketchDetails.zAxis,
sketchDetails.yAxis, sketchDetails.yAxis,
@ -902,7 +962,9 @@ export const ModelingMachineProvider = ({
return { return {
selectionType: 'completeSelection', selectionType: 'completeSelection',
selection, selection,
updatedPathToNode, updatedSketchEntryNodePath,
updatedSketchNodePaths,
updatedPlaneNodePath,
} }
} }
), ),
@ -917,20 +979,30 @@ export const ModelingMachineProvider = ({
length: lengthValue, length: lengthValue,
}) })
if (err(constraintResult)) return Promise.reject(constraintResult) if (err(constraintResult)) return Promise.reject(constraintResult)
const { modifiedAst, pathToNodeMap } = constraintResult const { modifiedAst, pathToNodeMap, exprInsertIndex } =
constraintResult
const pResult = parse(recast(modifiedAst)) const pResult = parse(recast(modifiedAst))
if (trap(pResult) || !resultIsOk(pResult)) if (trap(pResult) || !resultIsOk(pResult))
return Promise.reject(new Error('Unexpected compilation error')) return Promise.reject(new Error('Unexpected compilation error'))
const _modifiedAst = pResult.program const _modifiedAst = pResult.program
if (!sketchDetails) if (!sketchDetails)
return Promise.reject(new Error('No sketch details')) return Promise.reject(new Error('No sketch details'))
const updatedPathToNode = updatePathToNodeFromMap(
sketchDetails.sketchPathToNode, const {
pathToNodeMap updatedSketchEntryNodePath,
) updatedSketchNodePaths,
updatedPlaneNodePath,
} = updateSketchDetailsNodePaths({
sketchEntryNodePath: sketchDetails.sketchEntryNodePath,
sketchNodePaths: sketchDetails.sketchNodePaths,
planeNodePath: sketchDetails.planeNodePath,
exprInsertIndex,
})
const updatedAst = const updatedAst =
await sceneEntitiesManager.updateAstAndRejigSketch( await sceneEntitiesManager.updateAstAndRejigSketch(
updatedPathToNode, updatedSketchEntryNodePath,
updatedSketchNodePaths,
updatedPlaneNodePath,
_modifiedAst, _modifiedAst,
sketchDetails.zAxis, sketchDetails.zAxis,
sketchDetails.yAxis, sketchDetails.yAxis,
@ -951,13 +1023,15 @@ export const ModelingMachineProvider = ({
return { return {
selectionType: 'completeSelection', selectionType: 'completeSelection',
selection, selection,
updatedPathToNode, updatedSketchEntryNodePath,
updatedSketchNodePaths,
updatedPlaneNodePath,
} }
} }
), ),
'Get perpendicular distance info': fromPromise( 'Get perpendicular distance info': fromPromise(
async ({ input: { selectionRanges, sketchDetails } }) => { async ({ input: { selectionRanges, sketchDetails } }) => {
const { modifiedAst, pathToNodeMap } = const { modifiedAst, pathToNodeMap, exprInsertIndex } =
await applyConstraintIntersect({ await applyConstraintIntersect({
selectionRanges, selectionRanges,
}) })
@ -967,13 +1041,22 @@ export const ModelingMachineProvider = ({
const _modifiedAst = pResult.program const _modifiedAst = pResult.program
if (!sketchDetails) if (!sketchDetails)
return Promise.reject(new Error('No sketch details')) return Promise.reject(new Error('No sketch details'))
const updatedPathToNode = updatePathToNodeFromMap(
sketchDetails.sketchPathToNode, const {
pathToNodeMap updatedSketchEntryNodePath,
) updatedSketchNodePaths,
updatedPlaneNodePath,
} = updateSketchDetailsNodePaths({
sketchEntryNodePath: sketchDetails.sketchEntryNodePath,
sketchNodePaths: sketchDetails.sketchNodePaths,
planeNodePath: sketchDetails.planeNodePath,
exprInsertIndex,
})
const updatedAst = const updatedAst =
await sceneEntitiesManager.updateAstAndRejigSketch( await sceneEntitiesManager.updateAstAndRejigSketch(
updatedPathToNode, updatedSketchEntryNodePath,
updatedSketchNodePaths,
updatedPlaneNodePath,
_modifiedAst, _modifiedAst,
sketchDetails.zAxis, sketchDetails.zAxis,
sketchDetails.yAxis, sketchDetails.yAxis,
@ -994,13 +1077,15 @@ export const ModelingMachineProvider = ({
return { return {
selectionType: 'completeSelection', selectionType: 'completeSelection',
selection, selection,
updatedPathToNode, updatedSketchEntryNodePath,
updatedSketchNodePaths,
updatedPlaneNodePath,
} }
} }
), ),
'Get ABS X info': fromPromise( 'Get ABS X info': fromPromise(
async ({ input: { selectionRanges, sketchDetails } }) => { async ({ input: { selectionRanges, sketchDetails } }) => {
const { modifiedAst, pathToNodeMap } = const { modifiedAst, pathToNodeMap, exprInsertIndex } =
await applyConstraintAbsDistance({ await applyConstraintAbsDistance({
constraint: 'xAbs', constraint: 'xAbs',
selectionRanges, selectionRanges,
@ -1011,13 +1096,22 @@ export const ModelingMachineProvider = ({
const _modifiedAst = pResult.program const _modifiedAst = pResult.program
if (!sketchDetails) if (!sketchDetails)
return Promise.reject(new Error('No sketch details')) return Promise.reject(new Error('No sketch details'))
const updatedPathToNode = updatePathToNodeFromMap(
sketchDetails.sketchPathToNode, const {
pathToNodeMap updatedSketchEntryNodePath,
) updatedSketchNodePaths,
updatedPlaneNodePath,
} = updateSketchDetailsNodePaths({
sketchEntryNodePath: sketchDetails.sketchEntryNodePath,
sketchNodePaths: sketchDetails.sketchNodePaths,
planeNodePath: sketchDetails.planeNodePath,
exprInsertIndex,
})
const updatedAst = const updatedAst =
await sceneEntitiesManager.updateAstAndRejigSketch( await sceneEntitiesManager.updateAstAndRejigSketch(
updatedPathToNode, updatedSketchEntryNodePath,
updatedSketchNodePaths,
updatedPlaneNodePath,
_modifiedAst, _modifiedAst,
sketchDetails.zAxis, sketchDetails.zAxis,
sketchDetails.yAxis, sketchDetails.yAxis,
@ -1038,13 +1132,15 @@ export const ModelingMachineProvider = ({
return { return {
selectionType: 'completeSelection', selectionType: 'completeSelection',
selection, selection,
updatedPathToNode, updatedSketchEntryNodePath,
updatedSketchNodePaths,
updatedPlaneNodePath,
} }
} }
), ),
'Get ABS Y info': fromPromise( 'Get ABS Y info': fromPromise(
async ({ input: { selectionRanges, sketchDetails } }) => { async ({ input: { selectionRanges, sketchDetails } }) => {
const { modifiedAst, pathToNodeMap } = const { modifiedAst, pathToNodeMap, exprInsertIndex } =
await applyConstraintAbsDistance({ await applyConstraintAbsDistance({
constraint: 'yAbs', constraint: 'yAbs',
selectionRanges, selectionRanges,
@ -1055,13 +1151,22 @@ export const ModelingMachineProvider = ({
const _modifiedAst = pResult.program const _modifiedAst = pResult.program
if (!sketchDetails) if (!sketchDetails)
return Promise.reject(new Error('No sketch details')) return Promise.reject(new Error('No sketch details'))
const updatedPathToNode = updatePathToNodeFromMap(
sketchDetails.sketchPathToNode, const {
pathToNodeMap updatedSketchEntryNodePath,
) updatedSketchNodePaths,
updatedPlaneNodePath,
} = updateSketchDetailsNodePaths({
sketchEntryNodePath: sketchDetails.sketchEntryNodePath,
sketchNodePaths: sketchDetails.sketchNodePaths,
planeNodePath: sketchDetails.planeNodePath,
exprInsertIndex,
})
const updatedAst = const updatedAst =
await sceneEntitiesManager.updateAstAndRejigSketch( await sceneEntitiesManager.updateAstAndRejigSketch(
updatedPathToNode, updatedSketchEntryNodePath,
updatedSketchNodePaths,
updatedPlaneNodePath,
_modifiedAst, _modifiedAst,
sketchDetails.zAxis, sketchDetails.zAxis,
sketchDetails.yAxis, sketchDetails.yAxis,
@ -1082,7 +1187,9 @@ export const ModelingMachineProvider = ({
return { return {
selectionType: 'completeSelection', selectionType: 'completeSelection',
selection, selection,
updatedPathToNode, updatedSketchEntryNodePath,
updatedSketchNodePaths,
updatedPlaneNodePath,
} }
} }
), ),
@ -1102,9 +1209,11 @@ export const ModelingMachineProvider = ({
let result: { let result: {
modifiedAst: Node<Program> modifiedAst: Node<Program>
pathToReplaced: PathToNode | null pathToReplaced: PathToNode | null
exprInsertIndex: number
} = { } = {
modifiedAst: parsed, modifiedAst: parsed,
pathToReplaced: null, pathToReplaced: null,
exprInsertIndex: -1,
} }
// If the user provided a constant name, // If the user provided a constant name,
// we need to insert the named constant // we need to insert the named constant
@ -1134,6 +1243,7 @@ export const ModelingMachineProvider = ({
result = { result = {
modifiedAst: parseResultAfterInsertion.program, modifiedAst: parseResultAfterInsertion.program,
pathToReplaced: astAfterReplacement.pathToReplaced, pathToReplaced: astAfterReplacement.pathToReplaced,
exprInsertIndex: astAfterReplacement.exprInsertIndex,
} }
} else if ('valueText' in data.namedValue) { } else if ('valueText' in data.namedValue) {
// If they didn't provide a constant name, // If they didn't provide a constant name,
@ -1164,10 +1274,22 @@ export const ModelingMachineProvider = ({
parsed = parsed as Node<Program> parsed = parsed as Node<Program>
if (!result.pathToReplaced) if (!result.pathToReplaced)
return Promise.reject(new Error('No path to replaced node')) return Promise.reject(new Error('No path to replaced node'))
const {
updatedSketchEntryNodePath,
updatedSketchNodePaths,
updatedPlaneNodePath,
} = updateSketchDetailsNodePaths({
sketchEntryNodePath: sketchDetails.sketchEntryNodePath,
sketchNodePaths: sketchDetails.sketchNodePaths,
planeNodePath: sketchDetails.planeNodePath,
exprInsertIndex: result.exprInsertIndex,
})
const updatedAst = const updatedAst =
await sceneEntitiesManager.updateAstAndRejigSketch( await sceneEntitiesManager.updateAstAndRejigSketch(
result.pathToReplaced || [], updatedSketchEntryNodePath,
updatedSketchNodePaths,
updatedPlaneNodePath,
parsed, parsed,
sketchDetails.zAxis, sketchDetails.zAxis,
sketchDetails.yAxis, sketchDetails.yAxis,
@ -1188,7 +1310,168 @@ export const ModelingMachineProvider = ({
return { return {
selectionType: 'completeSelection', selectionType: 'completeSelection',
selection, selection,
updatedPathToNode: result.pathToReplaced, updatedSketchEntryNodePath,
updatedSketchNodePaths,
updatedPlaneNodePath,
}
}
),
'set-up-draft-circle': fromPromise(
async ({ input: { sketchDetails, data } }) => {
if (!sketchDetails || !data)
return reject('No sketch details or data')
sceneEntitiesManager.tearDownSketch({ removeAxis: false })
const result = await sceneEntitiesManager.setupDraftCircle(
sketchDetails.sketchEntryNodePath,
sketchDetails.sketchNodePaths,
sketchDetails.planeNodePath,
sketchDetails.zAxis,
sketchDetails.yAxis,
sketchDetails.origin,
data
)
if (err(result)) return reject(result)
await codeManager.updateEditorWithAstAndWriteToFile(kclManager.ast)
return result
}
),
'set-up-draft-circle-three-point': fromPromise(
async ({ input: { sketchDetails, data } }) => {
if (!sketchDetails || !data)
return reject('No sketch details or data')
sceneEntitiesManager.tearDownSketch({ removeAxis: false })
const result =
await sceneEntitiesManager.setupDraftCircleThreePoint(
sketchDetails.sketchEntryNodePath,
sketchDetails.sketchNodePaths,
sketchDetails.planeNodePath,
sketchDetails.zAxis,
sketchDetails.yAxis,
sketchDetails.origin,
data.p1,
data.p2
)
if (err(result)) return reject(result)
await codeManager.updateEditorWithAstAndWriteToFile(kclManager.ast)
return result
}
),
'set-up-draft-rectangle': fromPromise(
async ({ input: { sketchDetails, data } }) => {
if (!sketchDetails || !data)
return reject('No sketch details or data')
sceneEntitiesManager.tearDownSketch({ removeAxis: false })
const result = await sceneEntitiesManager.setupDraftRectangle(
sketchDetails.sketchEntryNodePath,
sketchDetails.sketchNodePaths,
sketchDetails.planeNodePath,
sketchDetails.zAxis,
sketchDetails.yAxis,
sketchDetails.origin,
data
)
if (err(result)) return reject(result)
await codeManager.updateEditorWithAstAndWriteToFile(kclManager.ast)
return result
}
),
'set-up-draft-center-rectangle': fromPromise(
async ({ input: { sketchDetails, data } }) => {
if (!sketchDetails || !data)
return reject('No sketch details or data')
sceneEntitiesManager.tearDownSketch({ removeAxis: false })
const result = await sceneEntitiesManager.setupDraftCenterRectangle(
sketchDetails.sketchEntryNodePath,
sketchDetails.sketchNodePaths,
sketchDetails.planeNodePath,
sketchDetails.zAxis,
sketchDetails.yAxis,
sketchDetails.origin,
data
)
if (err(result)) return reject(result)
await codeManager.updateEditorWithAstAndWriteToFile(kclManager.ast)
return result
}
),
'setup-client-side-sketch-segments': fromPromise(
async ({ input: { sketchDetails, selectionRanges } }) => {
if (!sketchDetails) return
if (!sketchDetails.sketchEntryNodePath.length) return
if (Object.keys(sceneEntitiesManager.activeSegments).length > 0) {
sceneEntitiesManager.tearDownSketch({ removeAxis: false })
}
sceneInfra.resetMouseListeners()
await sceneEntitiesManager.setupSketch({
sketchEntryNodePath: sketchDetails?.sketchEntryNodePath || [],
sketchNodePaths: sketchDetails.sketchNodePaths,
forward: sketchDetails.zAxis,
up: sketchDetails.yAxis,
position: sketchDetails.origin,
maybeModdedAst: kclManager.ast,
selectionRanges,
})
sceneInfra.resetMouseListeners()
sceneEntitiesManager.setupSketchIdleCallbacks({
sketchEntryNodePath: sketchDetails?.sketchEntryNodePath || [],
forward: sketchDetails.zAxis,
up: sketchDetails.yAxis,
position: sketchDetails.origin,
sketchNodePaths: sketchDetails.sketchNodePaths,
planeNodePath: sketchDetails.planeNodePath,
// We will want to pass sketchTools here
// to add their interactions
})
// We will want to update the context with sketchTools.
// They'll be used for their .destroy() in tearDownSketch
return undefined
}
),
'split-sketch-pipe-if-needed': fromPromise(
async ({ input: { sketchDetails } }) => {
if (!sketchDetails) return reject('No sketch details')
const existingSketchInfoNoOp = {
updatedEntryNodePath: sketchDetails.sketchEntryNodePath,
updatedSketchNodePaths: sketchDetails.sketchNodePaths,
updatedPlaneNodePath: sketchDetails.planeNodePath,
} as const
if (
!sketchDetails.sketchNodePaths.length &&
sketchDetails.planeNodePath.length
) {
// new sketch, no profiles yet
return existingSketchInfoNoOp
}
const doesNeedSplitting = doesSketchPipeNeedSplitting(
kclManager.ast,
sketchDetails.sketchEntryNodePath
)
if (err(doesNeedSplitting)) return reject(doesNeedSplitting)
if (!doesNeedSplitting) return existingSketchInfoNoOp
const splitResult = splitPipedProfile(
kclManager.ast,
sketchDetails.sketchEntryNodePath
)
if (err(splitResult)) return reject(splitResult)
await kclManager.executeAstMock(splitResult.modifiedAst)
await codeManager.updateEditorWithAstAndWriteToFile(
splitResult.modifiedAst
)
return {
updatedEntryNodePath: splitResult.pathToProfile,
updatedSketchNodePaths: [splitResult.pathToProfile],
updatedPlaneNodePath: sketchDetails.planeNodePath,
} }
} }
), ),

View File

@ -168,7 +168,7 @@ export function ModelingSidebar({ paneOpacity }: ModelingSidebarProps) {
height: 'auto', height: 'auto',
}} }}
minWidth={200} minWidth={200}
maxWidth={window.innerWidth - 10} maxWidth={800}
handleWrapperClass="sidebar-resize-handles" handleWrapperClass="sidebar-resize-handles"
handleClasses={{ handleClasses={{
right: right:

View File

@ -104,7 +104,7 @@ function ProjectMenuPopover({
const location = useLocation() const location = useLocation()
const navigate = useNavigate() const navigate = useNavigate()
const filePath = useAbsoluteFilePath() const filePath = useAbsoluteFilePath()
useSettingsAuthContext() const { settings } = useSettingsAuthContext()
const token = useToken() const token = useToken()
const machineManager = useContext(MachineManagerContext) const machineManager = useContext(MachineManagerContext)
const commands = useSelector(commandBarActor, commandsSelector) const commands = useSelector(commandBarActor, commandsSelector)
@ -193,13 +193,14 @@ function ProjectMenuPopover({
{ {
id: 'share-link', id: 'share-link',
Element: 'button', Element: 'button',
children: 'Share current part (via Zoo link)', children: 'Share link to file',
disabled: !(IS_NIGHTLY_OR_DEBUG && findCommand(shareCommandInfo)), disabled: IS_NIGHTLY_OR_DEBUG || !findCommand(shareCommandInfo),
onClick: async () => { onClick: async () => {
await copyFileShareLink({ await copyFileShareLink({
token: token ?? '', token: token ?? '',
code: codeManager.code, code: codeManager.code,
name: project?.name || '', name: project?.name || '',
units: settings.context.modeling.defaultUnit.current,
}) })
}, },
}, },
@ -262,7 +263,7 @@ function ProjectMenuPopover({
as={Fragment} as={Fragment}
> >
<Popover.Panel <Popover.Panel
className={`z-10 absolute top-full left-0 mt-1 pb-1 w-52 bg-chalkboard-10 dark:bg-chalkboard-90 className={`z-10 absolute top-full left-0 mt-1 pb-1 w-48 bg-chalkboard-10 dark:bg-chalkboard-90
border border-solid border-chalkboard-20 dark:border-chalkboard-90 rounded border border-solid border-chalkboard-20 dark:border-chalkboard-90 rounded
shadow-lg`} shadow-lg`}
> >

View File

@ -30,7 +30,15 @@ import {
FILE_EXT, FILE_EXT,
PROJECT_ENTRYPOINT, PROJECT_ENTRYPOINT,
} from 'lib/constants' } from 'lib/constants'
import { codeManager, kclManager } from 'lib/singletons' import { DeepPartial } from 'lib/types'
import { Configuration } from 'wasm-lib/kcl/bindings/Configuration'
import { codeManager } from 'lib/singletons'
import {
loadAndValidateSettings,
projectConfigurationToSettingsPayload,
saveSettings,
setSettingsAtLevel,
} from 'lib/settings/settingsUtils'
import { Project } from 'lib/project' import { Project } from 'lib/project'
type MachineContext<T extends AnyStateMachine> = { type MachineContext<T extends AnyStateMachine> = {
@ -78,7 +86,7 @@ const ProjectsContextWeb = ({ children }: { children: React.ReactNode }) => {
setSearchParams(searchParams) setSearchParams(searchParams)
}, [searchParams, setSearchParams]) }, [searchParams, setSearchParams])
const { const {
settings: { context: settings }, settings: { context: settings, send: settingsSend },
} = useSettingsAuthContext() } = useSettingsAuthContext()
const [state, send, actor] = useMachine( const [state, send, actor] = useMachine(
@ -124,10 +132,17 @@ const ProjectsContextWeb = ({ children }: { children: React.ReactNode }) => {
clearImportSearchParams() clearImportSearchParams()
codeManager.updateCodeStateEditor(input.code || '') codeManager.updateCodeStateEditor(input.code || '')
await codeManager.writeToFile() await codeManager.writeToFile()
await kclManager.executeCode(true)
settingsSend({
type: 'set.modeling.defaultUnit',
data: {
level: 'project',
value: input.units,
},
})
return { return {
message: 'File overwritten successfully', message: 'File and units overwritten successfully',
fileName: input.name, fileName: input.name,
projectName: '', projectName: '',
} }
@ -377,6 +392,16 @@ const ProjectsContextDesktop = ({
? input.name ? input.name
: input.name + FILE_EXT : input.name + FILE_EXT
let message = 'File created successfully' let message = 'File created successfully'
const unitsConfiguration: DeepPartial<Configuration> = {
settings: {
project: {
directory: settings.app.projectDirectory.current,
},
modeling: {
base_unit: input.units,
},
},
}
const needsInterpolated = doesProjectNameNeedInterpolated(projectName) const needsInterpolated = doesProjectNameNeedInterpolated(projectName)
if (needsInterpolated) { if (needsInterpolated) {
@ -389,10 +414,28 @@ const ProjectsContextDesktop = ({
// Create the project around the file if newProject // Create the project around the file if newProject
if (input.method === 'newProject') { if (input.method === 'newProject') {
await createNewProjectDirectory(projectName, input.code) await createNewProjectDirectory(
projectName,
input.code,
unitsConfiguration
)
message = `Project "${projectName}" created successfully with link contents` message = `Project "${projectName}" created successfully with link contents`
} else { } else {
let projectPath = window.electron.join(
settings.app.projectDirectory.current,
projectName
)
message = `File "${fileName}" created successfully` message = `File "${fileName}" created successfully`
const existingConfiguration = await loadAndValidateSettings(
projectPath
)
const settingsToSave = setSettingsAtLevel(
existingConfiguration.settings,
'project',
projectConfigurationToSettingsPayload(unitsConfiguration)
)
await saveSettings(settingsToSave, projectPath)
} }
// Create the file // Create the file

View File

@ -187,7 +187,7 @@ export const SettingsAuthProviderBase = ({
) { ) {
// Unit changes requires a re-exec of code // Unit changes requires a re-exec of code
// eslint-disable-next-line @typescript-eslint/no-floating-promises // eslint-disable-next-line @typescript-eslint/no-floating-promises
kclManager.executeCode(true) kclManager.executeCode({ zoomToFit: true })
} else { } else {
// For any future logging we'd like to do // For any future logging we'd like to do
// console.log( // console.log(

View File

@ -2,7 +2,12 @@ import { SVGProps } from 'react'
export const Spinner = (props: SVGProps<SVGSVGElement>) => { export const Spinner = (props: SVGProps<SVGSVGElement>) => {
return ( return (
<svg viewBox="0 0 10 10" className={'w-8 h-8'} {...props}> <svg
data-testid="spinner"
viewBox="0 0 10 10"
className={'w-8 h-8'}
{...props}
>
<circle <circle
cx="5" cx="5"
cy="5" cy="5"

View File

@ -60,7 +60,7 @@ export const Stream = () => {
*/ */
function executeCodeAndPlayStream() { function executeCodeAndPlayStream() {
// eslint-disable-next-line @typescript-eslint/no-floating-promises // eslint-disable-next-line @typescript-eslint/no-floating-promises
kclManager.executeCode(true).then(async () => { kclManager.executeCode({ zoomToFit: true }).then(async () => {
await videoRef.current?.play().catch((e) => { await videoRef.current?.play().catch((e) => {
console.warn('Video playing was prevented', e, videoRef.current) console.warn('Video playing was prevented', e, videoRef.current)
}) })
@ -302,7 +302,7 @@ export const Stream = () => {
return return
} }
const path = getArtifactOfTypes( const path = getArtifactOfTypes(
{ key: entity_id, types: ['path', 'solid2d', 'segment', 'helix'] }, { key: entity_id, types: ['path', 'solid2d', 'segment'] },
engineCommandManager.artifactGraph engineCommandManager.artifactGraph
) )
if (err(path)) { if (err(path)) {

View File

@ -136,6 +136,7 @@ export async function applyConstraintIntersect({
}): Promise<{ }): Promise<{
modifiedAst: Node<Program> modifiedAst: Node<Program>
pathToNodeMap: PathToNodeMap pathToNodeMap: PathToNodeMap
exprInsertIndex: number
}> { }> {
const info = intersectInfo({ const info = intersectInfo({
selectionRanges, selectionRanges,
@ -174,6 +175,7 @@ export async function applyConstraintIntersect({
return { return {
modifiedAst, modifiedAst,
pathToNodeMap, pathToNodeMap,
exprInsertIndex: -1,
} }
} }
// transform again but forcing certain values // transform again but forcing certain values
@ -192,6 +194,7 @@ export async function applyConstraintIntersect({
const { modifiedAst: _modifiedAst, pathToNodeMap: _pathToNodeMap } = const { modifiedAst: _modifiedAst, pathToNodeMap: _pathToNodeMap } =
transform2 transform2
let exprInsertIndex = -1
if (variableName) { if (variableName) {
const newBody = [..._modifiedAst.body] const newBody = [..._modifiedAst.body]
newBody.splice( newBody.splice(
@ -204,9 +207,11 @@ export async function applyConstraintIntersect({
const index = pathToNode.findIndex((a) => a[0] === 'body') + 1 const index = pathToNode.findIndex((a) => a[0] === 'body') + 1
pathToNode[index][0] = Number(pathToNode[index][0]) + 1 pathToNode[index][0] = Number(pathToNode[index][0]) + 1
}) })
exprInsertIndex = newVariableInsertIndex
} }
return { return {
modifiedAst: _modifiedAst, modifiedAst: _modifiedAst,
pathToNodeMap: _pathToNodeMap, pathToNodeMap: _pathToNodeMap,
exprInsertIndex,
} }
} }

View File

@ -28,7 +28,7 @@ export function removeConstrainingValuesInfo({
| Error { | Error {
const _nodes = selectionRanges.graphSelections.map(({ codeRef }) => { const _nodes = selectionRanges.graphSelections.map(({ codeRef }) => {
const tmp = getNodeFromPath<Expr>(kclManager.ast, codeRef.pathToNode) const tmp = getNodeFromPath<Expr>(kclManager.ast, codeRef.pathToNode)
if (err(tmp)) return tmp if (tmp instanceof Error) return tmp
return tmp.node return tmp.node
}) })
const _err1 = _nodes.find(err) const _err1 = _nodes.find(err)

View File

@ -92,6 +92,7 @@ export async function applyConstraintAbsDistance({
}): Promise<{ }): Promise<{
modifiedAst: Program modifiedAst: Program
pathToNodeMap: PathToNodeMap pathToNodeMap: PathToNodeMap
exprInsertIndex: number
}> { }> {
const info = absDistanceInfo({ const info = absDistanceInfo({
selectionRanges, selectionRanges,
@ -131,6 +132,7 @@ export async function applyConstraintAbsDistance({
if (err(transform2)) return Promise.reject(transform2) if (err(transform2)) return Promise.reject(transform2)
const { modifiedAst: _modifiedAst, pathToNodeMap } = transform2 const { modifiedAst: _modifiedAst, pathToNodeMap } = transform2
let exprInsertIndex = -1
if (variableName) { if (variableName) {
const newBody = [..._modifiedAst.body] const newBody = [..._modifiedAst.body]
newBody.splice( newBody.splice(
@ -143,8 +145,9 @@ export async function applyConstraintAbsDistance({
const index = pathToNode.findIndex((a) => a[0] === 'body') + 1 const index = pathToNode.findIndex((a) => a[0] === 'body') + 1
pathToNode[index][0] = Number(pathToNode[index][0]) + 1 pathToNode[index][0] = Number(pathToNode[index][0]) + 1
}) })
exprInsertIndex = newVariableInsertIndex
} }
return { modifiedAst: _modifiedAst, pathToNodeMap } return { modifiedAst: _modifiedAst, pathToNodeMap, exprInsertIndex }
} }
export function applyConstraintAxisAlign({ export function applyConstraintAxisAlign({

View File

@ -86,6 +86,7 @@ export async function applyConstraintAngleBetween({
}): Promise<{ }): Promise<{
modifiedAst: Program modifiedAst: Program
pathToNodeMap: PathToNodeMap pathToNodeMap: PathToNodeMap
exprInsertIndex: number
}> { }> {
const info = angleBetweenInfo({ selectionRanges }) const info = angleBetweenInfo({ selectionRanges })
if (err(info)) return Promise.reject(info) if (err(info)) return Promise.reject(info)
@ -122,6 +123,7 @@ export async function applyConstraintAngleBetween({
return { return {
modifiedAst, modifiedAst,
pathToNodeMap, pathToNodeMap,
exprInsertIndex: -1,
} }
} }
@ -141,6 +143,7 @@ export async function applyConstraintAngleBetween({
const { modifiedAst: _modifiedAst, pathToNodeMap: _pathToNodeMap } = const { modifiedAst: _modifiedAst, pathToNodeMap: _pathToNodeMap } =
transformed2 transformed2
let exprInsertIndex = -1
if (variableName) { if (variableName) {
const newBody = [..._modifiedAst.body] const newBody = [..._modifiedAst.body]
newBody.splice( newBody.splice(
@ -153,9 +156,11 @@ export async function applyConstraintAngleBetween({
const index = pathToNode.findIndex((a) => a[0] === 'body') + 1 const index = pathToNode.findIndex((a) => a[0] === 'body') + 1
pathToNode[index][0] = Number(pathToNode[index][0]) + 1 pathToNode[index][0] = Number(pathToNode[index][0]) + 1
}) })
exprInsertIndex = newVariableInsertIndex
} }
return { return {
modifiedAst: _modifiedAst, modifiedAst: _modifiedAst,
pathToNodeMap: _pathToNodeMap, pathToNodeMap: _pathToNodeMap,
exprInsertIndex,
} }
} }

View File

@ -87,15 +87,13 @@ export function horzVertDistanceInfo({
export async function applyConstraintHorzVertDistance({ export async function applyConstraintHorzVertDistance({
selectionRanges, selectionRanges,
constraint, constraint,
// TODO align will always be false (covered by synconous applyConstraintHorzVertAlign), remove it
isAlign = false,
}: { }: {
selectionRanges: Selections selectionRanges: Selections
constraint: 'setHorzDistance' | 'setVertDistance' constraint: 'setHorzDistance' | 'setVertDistance'
isAlign?: false
}): Promise<{ }): Promise<{
modifiedAst: Program modifiedAst: Program
pathToNodeMap: PathToNodeMap pathToNodeMap: PathToNodeMap
exprInsertIndex: number
}> { }> {
const info = horzVertDistanceInfo({ const info = horzVertDistanceInfo({
selectionRanges: selectionRanges, selectionRanges: selectionRanges,
@ -133,13 +131,12 @@ export async function applyConstraintHorzVertDistance({
return { return {
modifiedAst, modifiedAst,
pathToNodeMap, pathToNodeMap,
exprInsertIndex: -1,
} }
} else { } else {
if (!isExprBinaryPart(valueNode)) if (!isExprBinaryPart(valueNode))
return Promise.reject('Invalid valueNode, is not a BinaryPart') return Promise.reject('Invalid valueNode, is not a BinaryPart')
let finalValue = isAlign let finalValue = removeDoubleNegatives(valueNode, sign, variableName)
? createLiteral(0)
: removeDoubleNegatives(valueNode, sign, variableName)
// transform again but forcing certain values // transform again but forcing certain values
const transformed = transformSecondarySketchLinesTagFirst({ const transformed = transformSecondarySketchLinesTagFirst({
ast: kclManager.ast, ast: kclManager.ast,
@ -152,6 +149,7 @@ export async function applyConstraintHorzVertDistance({
if (err(transformed)) return Promise.reject(transformed) if (err(transformed)) return Promise.reject(transformed)
const { modifiedAst: _modifiedAst, pathToNodeMap } = transformed const { modifiedAst: _modifiedAst, pathToNodeMap } = transformed
let exprInsertIndex = -1
if (variableName) { if (variableName) {
const newBody = [..._modifiedAst.body] const newBody = [..._modifiedAst.body]
newBody.splice( newBody.splice(
@ -164,10 +162,12 @@ export async function applyConstraintHorzVertDistance({
const index = pathToNode.findIndex((a) => a[0] === 'body') + 1 const index = pathToNode.findIndex((a) => a[0] === 'body') + 1
pathToNode[index][0] = Number(pathToNode[index][0]) + 1 pathToNode[index][0] = Number(pathToNode[index][0]) + 1
}) })
exprInsertIndex = newVariableInsertIndex
} }
return { return {
modifiedAst: _modifiedAst, modifiedAst: _modifiedAst,
pathToNodeMap, pathToNodeMap,
exprInsertIndex,
} }
} }
} }

View File

@ -74,10 +74,14 @@ export async function applyConstraintLength({
}: { }: {
length: KclCommandValue length: KclCommandValue
selectionRanges: Selections selectionRanges: Selections
}) { }): Promise<{
modifiedAst: Program
pathToNodeMap: PathToNodeMap
exprInsertIndex: number
}> {
const ast = kclManager.ast const ast = kclManager.ast
const angleLength = angleLengthInfo({ selectionRanges }) const angleLength = angleLengthInfo({ selectionRanges })
if (err(angleLength)) return angleLength if (err(angleLength)) return Promise.reject(angleLength)
const { transforms } = angleLength const { transforms } = angleLength
let distanceExpression: Expr = length.valueAst let distanceExpression: Expr = length.valueAst
@ -98,7 +102,7 @@ export async function applyConstraintLength({
} }
if (!isExprBinaryPart(distanceExpression)) { if (!isExprBinaryPart(distanceExpression)) {
return new Error('Invalid valueNode, is not a BinaryPart') return Promise.reject('Invalid valueNode, is not a BinaryPart')
} }
const retval = transformAstSketchLines({ const retval = transformAstSketchLines({
@ -116,6 +120,12 @@ export async function applyConstraintLength({
return { return {
modifiedAst: _modifiedAst, modifiedAst: _modifiedAst,
pathToNodeMap, pathToNodeMap,
exprInsertIndex:
'variableName' in length &&
length.variableName &&
length.insertIndex !== undefined
? length.insertIndex
: -1,
} }
} }
@ -128,6 +138,7 @@ export async function applyConstraintAngleLength({
}): Promise<{ }): Promise<{
modifiedAst: Program modifiedAst: Program
pathToNodeMap: PathToNodeMap pathToNodeMap: PathToNodeMap
exprInsertIndex: number
}> { }> {
const angleLength = angleLengthInfo({ selectionRanges, angleOrLength }) const angleLength = angleLengthInfo({ selectionRanges, angleOrLength })
if (err(angleLength)) return Promise.reject(angleLength) if (err(angleLength)) return Promise.reject(angleLength)
@ -212,5 +223,6 @@ export async function applyConstraintAngleLength({
return { return {
modifiedAst: _modifiedAst, modifiedAst: _modifiedAst,
pathToNodeMap, pathToNodeMap,
exprInsertIndex: variableName ? newVariableInsertIndex : -1,
} }
} }

View File

@ -1,31 +1,9 @@
import { Popover } from '@headlessui/react' import { Popover } from '@headlessui/react'
import { useSettingsAuthContext } from 'hooks/useSettingsAuthContext' import { useSettingsAuthContext } from 'hooks/useSettingsAuthContext'
import { changeKclSettings, unitLengthToUnitLen } from 'lang/wasm'
import { baseUnitLabels, baseUnitsUnion } from 'lib/settings/settingsTypes' import { baseUnitLabels, baseUnitsUnion } from 'lib/settings/settingsTypes'
import { codeManager, kclManager } from 'lib/singletons'
import { err, reportRejection } from 'lib/trap'
import { useEffect, useState } from 'react'
import toast from 'react-hot-toast'
export function UnitsMenu() { export function UnitsMenu() {
const { settings } = useSettingsAuthContext() const { settings } = useSettingsAuthContext()
const [hasPerFileLengthUnit, setHasPerFileLengthUnit] = useState(
Boolean(kclManager.fileSettings.defaultLengthUnit)
)
const [lengthSetting, setLengthSetting] = useState(
kclManager.fileSettings.defaultLengthUnit ||
settings.context.modeling.defaultUnit.current
)
useEffect(() => {
setHasPerFileLengthUnit(Boolean(kclManager.fileSettings.defaultLengthUnit))
setLengthSetting(
kclManager.fileSettings.defaultLengthUnit ||
settings.context.modeling.defaultUnit.current
)
}, [
kclManager.fileSettings.defaultLengthUnit,
settings.context.modeling.defaultUnit.current,
])
return ( return (
<Popover className="relative pointer-events-auto"> <Popover className="relative pointer-events-auto">
{({ close }) => ( {({ close }) => (
@ -40,7 +18,7 @@ export function UnitsMenu() {
<div className="absolute w-[1px] h-[1em] bg-primary right-0 top-1/2 -translate-y-1/2"></div> <div className="absolute w-[1px] h-[1em] bg-primary right-0 top-1/2 -translate-y-1/2"></div>
</div> </div>
<span className="sr-only">Current units are:&nbsp;</span> <span className="sr-only">Current units are:&nbsp;</span>
{lengthSetting} {settings.context.modeling.defaultUnit.current}
</Popover.Button> </Popover.Button>
<Popover.Panel <Popover.Panel
className={`absolute bottom-full right-0 mb-2 w-48 bg-chalkboard-10 dark:bg-chalkboard-90 className={`absolute bottom-full right-0 mb-2 w-48 bg-chalkboard-10 dark:bg-chalkboard-90
@ -53,40 +31,18 @@ export function UnitsMenu() {
<button <button
className="flex items-center gap-2 m-0 py-1.5 px-2 cursor-pointer hover:bg-chalkboard-20 dark:hover:bg-chalkboard-80 border-none text-left" className="flex items-center gap-2 m-0 py-1.5 px-2 cursor-pointer hover:bg-chalkboard-20 dark:hover:bg-chalkboard-80 border-none text-left"
onClick={() => { onClick={() => {
if (hasPerFileLengthUnit) { settings.send({
const newCode = changeKclSettings(codeManager.code, { type: 'set.modeling.defaultUnit',
defaultLengthUnits: unitLengthToUnitLen(unit), data: {
defaultAngleUnits: { type: 'Degrees' }, level: 'project',
}) value: unit,
if (err(newCode)) { },
toast.error( })
`Failed to set per-file units: ${newCode.message}`
)
} else {
codeManager.updateCodeStateEditor(newCode)
Promise.all([
codeManager.writeToFile(),
kclManager.executeCode(),
])
.then(() => {
toast.success(`Updated per-file units to ${unit}`)
})
.catch(reportRejection)
}
} else {
settings.send({
type: 'set.modeling.defaultUnit',
data: {
level: 'project',
value: unit,
},
})
}
close() close()
}} }}
> >
<span className="flex-1">{baseUnitLabels[unit]}</span> <span className="flex-1">{baseUnitLabels[unit]}</span>
{unit === lengthSetting && ( {unit === settings.context.modeling.defaultUnit.current && (
<span className="text-chalkboard-60">current</span> <span className="text-chalkboard-60">current</span>
)} )}
</button> </button>

View File

@ -25,18 +25,6 @@ export class KclPlugin implements PluginValue {
constructor(client: LanguageServerClient) { constructor(client: LanguageServerClient) {
this.client = client this.client = client
// Gotcha: Code can be written into the CodeMirror editor but not propagated to codeManager.code
// because the update function has not run. We need to initialize the codeManager.code when lsp initializes
// because new code could have been written into the editor before the update callback is initialized.
// There appears to be limited ways to safely get the current doc content. This appears to be sync and safe.
const kclLspPlugin = this.client.plugins.find((plugin) => {
return plugin.client.name === 'kcl'
})
if (kclLspPlugin) {
// @ts-ignore Ignoring this private dereference of .view on the plugin. I do not have another helper method that can give me doc string
codeManager.code = kclLspPlugin.view.state.doc.toString()
}
} }
// When a doc update needs to be sent to the server, this holds the // When a doc update needs to be sent to the server, this holds the

View File

@ -6,6 +6,7 @@ import { useSettingsAuthContext } from './useSettingsAuthContext'
import { isDesktop } from 'lib/isDesktop' import { isDesktop } from 'lib/isDesktop'
import { FileLinkParams } from 'lib/links' import { FileLinkParams } from 'lib/links'
import { ProjectsCommandSchema } from 'lib/commandBarConfigs/projectsCommandConfig' import { ProjectsCommandSchema } from 'lib/commandBarConfigs/projectsCommandConfig'
import { baseUnitsUnion } from 'lib/settings/settingsTypes'
// For initializing the command arguments, we actually want `method` to be undefined // For initializing the command arguments, we actually want `method` to be undefined
// so that we don't skip it in the command palette. // so that we don't skip it in the command palette.
@ -36,7 +37,13 @@ export function useCreateFileLinkQuery(
code: base64ToString( code: base64ToString(
decodeURIComponent(searchParams.get('code') ?? '') decodeURIComponent(searchParams.get('code') ?? '')
), ),
name: searchParams.get('name') ?? DEFAULT_FILE_NAME, name: searchParams.get('name') ?? DEFAULT_FILE_NAME,
units:
(baseUnitsUnion.find((unit) => searchParams.get('units') === unit) ||
settings.context.modeling.defaultUnit.default) ??
settings.context.modeling.defaultUnit.current,
} }
const argDefaultValues: CreateFileSchemaMethodOptional = { const argDefaultValues: CreateFileSchemaMethodOptional = {
@ -48,6 +55,7 @@ export function useCreateFileLinkQuery(
? settings.context.projects.defaultProjectName.current ? settings.context.projects.defaultProjectName.current
: DEFAULT_FILE_NAME, : DEFAULT_FILE_NAME,
code: params.code || '', code: params.code || '',
units: params.units,
method: isDesktop() ? undefined : 'existingProject', method: isDesktop() ? undefined : 'existingProject',
} }

View File

@ -25,7 +25,7 @@ import {
SourceRange, SourceRange,
topLevelRange, topLevelRange,
} from 'lang/wasm' } from 'lang/wasm'
import { getNodeFromPath, getSettingsAnnotation } from './queryAst' import { getNodeFromPath } from './queryAst'
import { codeManager, editorManager, sceneInfra } from 'lib/singletons' import { codeManager, editorManager, sceneInfra } from 'lib/singletons'
import { Diagnostic } from '@codemirror/lint' import { Diagnostic } from '@codemirror/lint'
import { markOnce } from 'lib/performance' import { markOnce } from 'lib/performance'
@ -35,11 +35,11 @@ import {
ModelingCmdReq_type, ModelingCmdReq_type,
} from '@kittycad/lib/dist/types/src/models' } from '@kittycad/lib/dist/types/src/models'
import { Operation } from 'wasm-lib/kcl/bindings/Operation' import { Operation } from 'wasm-lib/kcl/bindings/Operation'
import { KclSettingsAnnotation } from 'lib/settings/settingsTypes'
interface ExecuteArgs { interface ExecuteArgs {
ast?: Node<Program> ast?: Node<Program>
zoomToFit?: boolean zoomToFit?: boolean
isPartialExecution?: boolean
executionId?: number executionId?: number
zoomOnRangeAndType?: { zoomOnRangeAndType?: {
range: SourceRange range: SourceRange
@ -58,7 +58,6 @@ export class KclManager {
nonCodeNodes: {}, nonCodeNodes: {},
startNodes: [], startNodes: [],
}, },
trivia: [],
} }
private _execState: ExecState = emptyExecState() private _execState: ExecState = emptyExecState()
private _programMemory: ProgramMemory = ProgramMemory.empty() private _programMemory: ProgramMemory = ProgramMemory.empty()
@ -72,7 +71,6 @@ export class KclManager {
private _wasmInitFailed = true private _wasmInitFailed = true
private _hasErrors = false private _hasErrors = false
private _switchedFiles = false private _switchedFiles = false
private _fileSettings: KclSettingsAnnotation = {}
engineCommandManager: EngineCommandManager engineCommandManager: EngineCommandManager
@ -240,7 +238,6 @@ export class KclManager {
nonCodeNodes: {}, nonCodeNodes: {},
startNodes: [], startNodes: [],
}, },
trivia: [],
} }
} }
@ -372,13 +369,6 @@ export class KclManager {
await this.disableSketchMode() await this.disableSketchMode()
} }
let fileSettings = getSettingsAnnotation(ast)
if (err(fileSettings)) {
console.error(fileSettings)
fileSettings = {}
}
this.fileSettings = fileSettings
this.logs = logs this.logs = logs
this.errors = errors this.errors = errors
// Do not add the errors since the program was interrupted and the error is not a real KCL error // Do not add the errors since the program was interrupted and the error is not a real KCL error
@ -390,12 +380,10 @@ export class KclManager {
} }
this.ast = { ...ast } this.ast = { ...ast }
// updateArtifactGraph relies on updated executeState/programMemory // updateArtifactGraph relies on updated executeState/programMemory
this.engineCommandManager.updateArtifactGraph(execState.artifactGraph) await this.engineCommandManager.updateArtifactGraph(execState.artifactGraph)
this._executeCallback() this._executeCallback()
if (!isInterrupted) { if (!isInterrupted)
sceneInfra.modelingSend({ type: 'code edit during sketch' }) sceneInfra.modelingSend({ type: 'code edit during sketch' })
}
this.engineCommandManager.addCommandLog({ this.engineCommandManager.addCommandLog({
type: 'execution-done', type: 'execution-done',
data: null, data: null,
@ -424,7 +412,14 @@ export class KclManager {
// NOTE: this always updates the code state and editor. // NOTE: this always updates the code state and editor.
// DO NOT CALL THIS from codemirror ever. // DO NOT CALL THIS from codemirror ever.
async executeAstMock(ast: Program = this._ast) { async executeAstMock(
ast: Program = this._ast,
{
updates,
}: {
updates: 'none' | 'artifactRanges'
} = { updates: 'none' }
) {
await this.ensureWasmInit() await this.ensureWasmInit()
const newCode = recast(ast) const newCode = recast(ast)
@ -448,19 +443,51 @@ export class KclManager {
this._logs = logs this._logs = logs
this.addDiagnostics(kclErrorsToDiagnostics(errors)) this.addDiagnostics(kclErrorsToDiagnostics(errors))
this._execState = execState this._execState = execState
this._programMemory = execState.memory this._programMemory = execState.memory
if (!errors.length) { if (!errors.length) {
this.lastSuccessfulProgramMemory = execState.memory this.lastSuccessfulProgramMemory = execState.memory
this.lastSuccessfulOperations = execState.operations this.lastSuccessfulOperations = execState.operations
} }
if (updates !== 'artifactRanges') return
// TODO the below seems like a work around, I wish there's a comment explaining exactly what
// problem this solves, but either way we should strive to remove it.
Array.from(this.engineCommandManager.artifactGraph).forEach(
([commandId, artifact]) => {
if (!('codeRef' in artifact && artifact.codeRef)) return
const _node1 = getNodeFromPath<Node<CallExpression | CallExpressionKw>>(
this.ast,
artifact.codeRef.pathToNode,
['CallExpression', 'CallExpressionKw']
)
if (err(_node1)) return
const { node } = _node1
if (node.type !== 'CallExpression' && node.type !== 'CallExpressionKw')
return
const [oldStart, oldEnd] = artifact.codeRef.range
if (oldStart === 0 && oldEnd === 0) return
if (oldStart === node.start && oldEnd === node.end) return
this.engineCommandManager.artifactGraph.set(commandId, {
...artifact,
codeRef: {
...artifact.codeRef,
range: topLevelRange(node.start, node.end),
},
})
}
)
} }
cancelAllExecutions() { cancelAllExecutions() {
this._cancelTokens.forEach((_, key) => { this._cancelTokens.forEach((_, key) => {
this._cancelTokens.set(key, true) this._cancelTokens.set(key, true)
}) })
} }
async executeCode(zoomToFit?: boolean): Promise<void> { async executeCode(opts?: {
zoomToFit?: true
isPartialExecution?: true
}): Promise<void> {
const ast = await this.safeParse(codeManager.code) const ast = await this.safeParse(codeManager.code)
if (!ast) { if (!ast) {
@ -468,10 +495,10 @@ export class KclManager {
return return
} }
zoomToFit = this.tryToZoomToFitOnCodeUpdate(ast, zoomToFit) // zoomToFit = this.tryToZoomToFitOnCodeUpdate(ast, opts?.zoomToFit)
this.ast = { ...ast } this.ast = { ...ast }
return this.executeAst({ zoomToFit }) return this.executeAst(opts)
} }
/** /**
* This will override the zoom to fit to zoom into the model if the previous AST was empty. * This will override the zoom to fit to zoom into the model if the previous AST was empty.
@ -675,14 +702,6 @@ export class KclManager {
_isAstEmpty(ast: Node<Program>) { _isAstEmpty(ast: Node<Program>) {
return ast.start === 0 && ast.end === 0 && ast.body.length === 0 return ast.start === 0 && ast.end === 0 && ast.body.length === 0
} }
get fileSettings() {
return this._fileSettings
}
set fileSettings(settings: KclSettingsAnnotation) {
this._fileSettings = settings
}
} }
const defaultSelectionFilter: EntityType_type[] = [ const defaultSelectionFilter: EntityType_type[] = [

View File

@ -55,7 +55,6 @@ const mySketch001 = startSketchOn('XY')
], ],
id: expect.any(String), id: expect.any(String),
artifactId: expect.any(String), artifactId: expect.any(String),
originalId: expect.any(String),
units: { units: {
type: 'Mm', type: 'Mm',
}, },
@ -99,7 +98,6 @@ const mySketch001 = startSketchOn('XY')
], ],
sketch: { sketch: {
id: expect.any(String), id: expect.any(String),
originalId: expect.any(String),
artifactId: expect.any(String), artifactId: expect.any(String),
units: { units: {
type: 'Mm', type: 'Mm',
@ -205,7 +203,6 @@ const sk2 = startSketchOn('XY')
], ],
sketch: { sketch: {
id: expect.any(String), id: expect.any(String),
originalId: expect.any(String),
artifactId: expect.any(String), artifactId: expect.any(String),
__meta: expect.any(Array), __meta: expect.any(Array),
on: expect.any(Object), on: expect.any(Object),
@ -311,7 +308,6 @@ const sk2 = startSketchOn('XY')
], ],
sketch: { sketch: {
id: expect.any(String), id: expect.any(String),
originalId: expect.any(String),
artifactId: expect.any(String), artifactId: expect.any(String),
units: { units: {
type: 'Mm', type: 'Mm',

View File

@ -157,7 +157,7 @@ export default class CodeManager {
toast.error('Error saving file, please check file permissions') toast.error('Error saving file, please check file permissions')
reject(err) reject(err)
}) })
}, 1000) }, 10)
}) })
} else { } else {
safeLSSetItem(PERSIST_CODE_KEY, this.code) safeLSSetItem(PERSIST_CODE_KEY, this.code)

View File

@ -221,7 +221,6 @@ const newVar = myVar + 1`
}, },
], ],
id: expect.any(String), id: expect.any(String),
originalId: expect.any(String),
artifactId: expect.any(String), artifactId: expect.any(String),
units: { units: {
type: 'Mm', type: 'Mm',

View File

@ -28,14 +28,7 @@ try {
console.log(e) console.log(e)
} }
child_process.spawnSync('git', [ child_process.spawnSync('git', ['clone', URL_GIT_KCL_SAMPLES, DIR_KCL_SAMPLES])
'clone',
'--single-branch',
'--branch',
'achalmers/kw-appearance',
URL_GIT_KCL_SAMPLES,
DIR_KCL_SAMPLES,
])
// @ts-expect-error // @ts-expect-error
let files = await fs.readdir(DIR_KCL_SAMPLES) let files = await fs.readdir(DIR_KCL_SAMPLES)

View File

@ -27,6 +27,7 @@ export type ToolTip =
| 'angledLineThatIntersects' | 'angledLineThatIntersects'
| 'tangentialArcTo' | 'tangentialArcTo'
| 'circle' | 'circle'
| 'circleThreePoint'
export const toolTips: Array<ToolTip> = [ export const toolTips: Array<ToolTip> = [
'line', 'line',
@ -42,6 +43,7 @@ export const toolTips: Array<ToolTip> = [
'yLineTo', 'yLineTo',
'angledLineThatIntersects', 'angledLineThatIntersects',
'tangentialArcTo', 'tangentialArcTo',
'circleThreePoint',
] ]
export async function executeAst({ export async function executeAst({
@ -69,7 +71,6 @@ export async function executeAst({
: executor(ast, engineCommandManager, path)) : executor(ast, engineCommandManager, path))
await engineCommandManager.waitForAllCommands() await engineCommandManager.waitForAllCommands()
return { return {
logs: [], logs: [],
errors: [], errors: [],

View File

@ -25,6 +25,7 @@ import {
deleteSegmentFromPipeExpression, deleteSegmentFromPipeExpression,
removeSingleConstraintInfo, removeSingleConstraintInfo,
deleteFromSelection, deleteFromSelection,
splitPipedProfile,
} from './modifyAst' } from './modifyAst'
import { enginelessExecutor } from '../lib/testHelpers' import { enginelessExecutor } from '../lib/testHelpers'
import { findUsesOfTagInPipe } from './queryAst' import { findUsesOfTagInPipe } from './queryAst'
@ -128,78 +129,15 @@ describe('Testing findUniqueName', () => {
it('should find a unique name', () => { it('should find a unique name', () => {
const result = findUniqueName( const result = findUniqueName(
JSON.stringify([ JSON.stringify([
{ { type: 'Identifier', name: 'yo01', start: 0, end: 0, moduleId: 0 },
type: 'Identifier', { type: 'Identifier', name: 'yo02', start: 0, end: 0, moduleId: 0 },
name: 'yo01', { type: 'Identifier', name: 'yo03', start: 0, end: 0, moduleId: 0 },
start: 0, { type: 'Identifier', name: 'yo04', start: 0, end: 0, moduleId: 0 },
end: 0, { type: 'Identifier', name: 'yo05', start: 0, end: 0, moduleId: 0 },
moduleId: 0, { type: 'Identifier', name: 'yo06', start: 0, end: 0, moduleId: 0 },
trivia: [], { type: 'Identifier', name: 'yo07', start: 0, end: 0, moduleId: 0 },
}, { type: 'Identifier', name: 'yo08', start: 0, end: 0, moduleId: 0 },
{ { type: 'Identifier', name: 'yo09', start: 0, end: 0, moduleId: 0 },
type: 'Identifier',
name: 'yo02',
start: 0,
end: 0,
moduleId: 0,
trivia: [],
},
{
type: 'Identifier',
name: 'yo03',
start: 0,
end: 0,
moduleId: 0,
trivia: [],
},
{
type: 'Identifier',
name: 'yo04',
start: 0,
end: 0,
moduleId: 0,
trivia: [],
},
{
type: 'Identifier',
name: 'yo05',
start: 0,
end: 0,
moduleId: 0,
trivia: [],
},
{
type: 'Identifier',
name: 'yo06',
start: 0,
end: 0,
moduleId: 0,
trivia: [],
},
{
type: 'Identifier',
name: 'yo07',
start: 0,
end: 0,
moduleId: 0,
trivia: [],
},
{
type: 'Identifier',
name: 'yo08',
start: 0,
end: 0,
moduleId: 0,
trivia: [],
},
{
type: 'Identifier',
name: 'yo09',
start: 0,
end: 0,
moduleId: 0,
trivia: [],
},
] satisfies Node<Identifier>[]), ] satisfies Node<Identifier>[]),
'yo', 'yo',
2 2
@ -217,7 +155,6 @@ describe('Testing addSketchTo', () => {
end: 0, end: 0,
moduleId: 0, moduleId: 0,
nonCodeMeta: { nonCodeNodes: {}, startNodes: [] }, nonCodeMeta: { nonCodeNodes: {}, startNodes: [] },
trivia: [],
}, },
'yz' 'yz'
) )
@ -995,3 +932,63 @@ sketch002 = startSketchOn({
} }
) )
}) })
describe('Testing splitPipedProfile', () => {
it('should split the pipe expression correctly', () => {
const codeBefore = `part001 = startSketchOn('XZ')
|> startProfileAt([1, 2], %)
|> line([3, 4], %)
|> line([5, 6], %)
|> close(%)
extrude001 = extrude(5, part001)
`
const expectedCodeAfter = `sketch001 = startSketchOn('XZ')
part001 = startProfileAt([1, 2], sketch001)
|> line([3, 4], %)
|> line([5, 6], %)
|> close(%)
extrude001 = extrude(5, part001)
`
const ast = assertParse(codeBefore)
const codeOfInterest = `startSketchOn('XZ')`
const range: [number, number, number] = [
codeBefore.indexOf(codeOfInterest),
codeBefore.indexOf(codeOfInterest) + codeOfInterest.length,
0,
]
const pathToPipe = getNodePathFromSourceRange(ast, range)
const result = splitPipedProfile(ast, pathToPipe)
if (err(result)) throw result
const newCode = recast(result.modifiedAst)
if (err(newCode)) throw newCode
expect(newCode.trim()).toBe(expectedCodeAfter.trim())
})
it('should return error for already split pipe', () => {
const codeBefore = `sketch001 = startSketchOn('XZ')
part001 = startProfileAt([1, 2], sketch001)
|> line([3, 4], %)
|> line([5, 6], %)
|> close(%)
extrude001 = extrude(5, part001)
`
const ast = assertParse(codeBefore)
const codeOfInterest = `startProfileAt([1, 2], sketch001)`
const range: [number, number, number] = [
codeBefore.indexOf(codeOfInterest),
codeBefore.indexOf(codeOfInterest) + codeOfInterest.length,
0,
]
const pathToPipe = getNodePathFromSourceRange(ast, range)
const result = splitPipedProfile(ast, pathToPipe)
expect(result instanceof Error).toBe(true)
})
})

View File

@ -22,6 +22,7 @@ import {
SourceRange, SourceRange,
sketchFromKclValue, sketchFromKclValue,
isPathToNodeNumber, isPathToNodeNumber,
parse,
formatNumber, formatNumber,
} from './wasm' } from './wasm'
import { import {
@ -31,6 +32,8 @@ import {
getNodeFromPath, getNodeFromPath,
isNodeSafeToReplace, isNodeSafeToReplace,
traverse, traverse,
getBodyIndex,
isCallExprWithName,
ARG_INDEX_FIELD, ARG_INDEX_FIELD,
LABELED_ARG_FIELD, LABELED_ARG_FIELD,
} from './queryAst' } from './queryAst'
@ -56,6 +59,8 @@ import { Models } from '@kittycad/lib'
import { ExtrudeFacePlane } from 'machines/modelingMachine' import { ExtrudeFacePlane } from 'machines/modelingMachine'
import { Node } from 'wasm-lib/kcl/bindings/Node' import { Node } from 'wasm-lib/kcl/bindings/Node'
import { KclExpressionWithVariable } from 'lib/commandTypes' import { KclExpressionWithVariable } from 'lib/commandTypes'
import { Artifact, getPathsFromArtifact } from './std/artifactGraph'
import { BodyItem } from 'wasm-lib/kcl/bindings/BodyItem'
import { findKwArg } from './util' import { findKwArg } from './util'
import { deleteEdgeTreatment } from './modifyAst/addEdgeTreatment' import { deleteEdgeTreatment } from './modifyAst/addEdgeTreatment'
@ -90,41 +95,54 @@ export function startSketchOnDefault(
} }
} }
export function addStartProfileAt( export function insertNewStartProfileAt(
node: Node<Program>, node: Node<Program>,
pathToNode: PathToNode, sketchEntryNodePath: PathToNode,
at: [number, number] sketchNodePaths: PathToNode[],
): { modifiedAst: Node<Program>; pathToNode: PathToNode } | Error { planeNodePath: PathToNode,
const _node1 = getNodeFromPath<VariableDeclaration>( at: [number, number],
insertType: 'start' | 'end' = 'end'
):
| {
modifiedAst: Node<Program>
updatedSketchNodePaths: PathToNode[]
updatedEntryNodePath: PathToNode
}
| Error {
const varDec = getNodeFromPath<VariableDeclarator>(
node, node,
pathToNode, planeNodePath,
'VariableDeclaration' 'VariableDeclarator'
) )
if (err(_node1)) return _node1 if (err(varDec)) return varDec
const variableDeclaration = _node1.node if (varDec.node.type !== 'VariableDeclarator') return new Error('not a var')
if (variableDeclaration.type !== 'VariableDeclaration') {
return new Error('variableDeclaration.init.type !== PipeExpression') const newExpression = createVariableDeclaration(
} findUniqueName(node, 'profile'),
const _node = { ...node } createCallExpressionStdLib('startProfileAt', [
const init = variableDeclaration.declaration.init createArrayExpression([
const startProfileAt = createCallExpressionStdLib('startProfileAt', [ createLiteral(roundOff(at[0])),
createArrayExpression([ createLiteral(roundOff(at[1])),
createLiteral(roundOff(at[0])), ]),
createLiteral(roundOff(at[1])), createIdentifier(varDec.node.id.name),
]),
createPipeSubstitution(),
])
if (init.type === 'PipeExpression') {
init.body.splice(1, 0, startProfileAt)
} else {
variableDeclaration.declaration.init = createPipeExpression([
init,
startProfileAt,
]) ])
} )
const insertIndex = getInsertIndex(sketchNodePaths, planeNodePath, insertType)
const _node = structuredClone(node)
// TODO the rest of this function will not be robust to work for sketches defined within a function declaration
_node.body.splice(insertIndex, 0, newExpression)
const { updatedEntryNodePath, updatedSketchNodePaths } =
updateSketchNodePathsWithInsertIndex({
insertIndex,
insertType,
sketchNodePaths,
})
return { return {
modifiedAst: _node, modifiedAst: _node,
pathToNode, updatedSketchNodePaths,
updatedEntryNodePath,
} }
} }
@ -224,8 +242,21 @@ export function mutateKwArg(
for (let i = 0; i < node.arguments.length; i++) { for (let i = 0; i < node.arguments.length; i++) {
const arg = node.arguments[i] const arg = node.arguments[i]
if (arg.label.name === label) { if (arg.label.name === label) {
node.arguments[i].arg = val if (isLiteralArrayOrStatic(val) && isLiteralArrayOrStatic(arg.arg)) {
return true node.arguments[i].arg = val
return true
} else if (
arg.arg.type === 'ArrayExpression' &&
val.type === 'ArrayExpression'
) {
const arrExp = arg.arg
arrExp.elements.forEach((element, i) => {
if (isLiteralArrayOrStatic(element)) {
arrExp.elements[i] = val.elements[i]
}
})
return true
}
} }
} }
node.arguments.push(createLabeledArg(label, val)) node.arguments.push(createLabeledArg(label, val))
@ -278,7 +309,6 @@ export function mutateObjExpProp(
start: 0, start: 0,
end: 0, end: 0,
moduleId: 0, moduleId: 0,
trivia: [],
}) })
} }
} }
@ -288,15 +318,16 @@ export function mutateObjExpProp(
export function extrudeSketch({ export function extrudeSketch({
node, node,
pathToNode, pathToNode,
shouldPipe = false,
distance = createLiteral(4), distance = createLiteral(4),
extrudeName, extrudeName,
artifact
}: { }: {
node: Node<Program> node: Node<Program>
pathToNode: PathToNode pathToNode: PathToNode
shouldPipe?: boolean shouldPipe?: boolean
distance: Expr distance: Expr
extrudeName?: string extrudeName?: string
artifact?: Artifact,
}): }):
| { | {
modifiedAst: Node<Program> modifiedAst: Node<Program>
@ -304,10 +335,14 @@ export function extrudeSketch({
pathToExtrudeArg: PathToNode pathToExtrudeArg: PathToNode
} }
| Error { | Error {
const orderedSketchNodePaths = getPathsFromArtifact({
artifact: artifact,
sketchPathToNode: pathToNode,
})
if (err(orderedSketchNodePaths)) return orderedSketchNodePaths
const _node = structuredClone(node) const _node = structuredClone(node)
const _node1 = getNodeFromPath(_node, pathToNode) const _node1 = getNodeFromPath(_node, pathToNode)
if (err(_node1)) return _node1 if (err(_node1)) return _node1
const { node: sketchExpression } = _node1
// determine if sketchExpression is in a pipeExpression or not // determine if sketchExpression is in a pipeExpression or not
const _node2 = getNodeFromPath<PipeExpression>( const _node2 = getNodeFromPath<PipeExpression>(
@ -316,9 +351,6 @@ export function extrudeSketch({
'PipeExpression' 'PipeExpression'
) )
if (err(_node2)) return _node2 if (err(_node2)) return _node2
const { node: pipeExpression } = _node2
const isInPipeExpression = pipeExpression.type === 'PipeExpression'
const _node3 = getNodeFromPath<VariableDeclarator>( const _node3 = getNodeFromPath<VariableDeclarator>(
_node, _node,
@ -326,54 +358,27 @@ export function extrudeSketch({
'VariableDeclarator' 'VariableDeclarator'
) )
if (err(_node3)) return _node3 if (err(_node3)) return _node3
const { node: variableDeclarator, shallowPath: pathToDecleration } = _node3 const { node: variableDeclarator } = _node3
const sketchToExtrude = shouldPipe const extrudeCall = createCallExpressionStdLibKw(
? createPipeSubstitution() 'extrude',
: createIdentifier(variableDeclarator.id.name) createIdentifier(variableDeclarator.id.name),
const extrudeCall = createCallExpressionStdLibKw('extrude', sketchToExtrude, [ [createLabeledArg('length', distance)]
createLabeledArg('length', distance), )
])
// index of the 'length' arg above. If you reorder the labeled args above, // index of the 'length' arg above. If you reorder the labeled args above,
// make sure to update this too. // make sure to update this too.
const argIndex = 0 const argIndex = 0
if (shouldPipe) {
const pipeChain = createPipeExpression(
isInPipeExpression
? [...pipeExpression.body, extrudeCall]
: [sketchExpression as any, extrudeCall]
)
variableDeclarator.init = pipeChain
const pathToExtrudeArg: PathToNode = [
...pathToDecleration,
['init', 'VariableDeclarator'],
['body', ''],
[pipeChain.body.length - 1, 'index'],
['arguments', 'CallExpressionKw'],
[argIndex, ARG_INDEX_FIELD],
['arg', LABELED_ARG_FIELD],
]
return {
modifiedAst: _node,
pathToNode,
pathToExtrudeArg,
}
}
// We're not creating a pipe expression, // We're not creating a pipe expression,
// but rather a separate constant for the extrusion // but rather a separate constant for the extrusion
const name = const name =
extrudeName ?? findUniqueName(node, KCL_DEFAULT_CONSTANT_PREFIXES.EXTRUDE) extrudeName ?? findUniqueName(node, KCL_DEFAULT_CONSTANT_PREFIXES.EXTRUDE)
const VariableDeclaration = createVariableDeclaration(name, extrudeCall) const VariableDeclaration = createVariableDeclaration(name, extrudeCall)
const sketchIndexInPathToNode = const lastSketchNodePath =
pathToDecleration.findIndex((a) => a[0] === 'body') + 1 orderedSketchNodePaths[orderedSketchNodePaths.length - 1]
const sketchIndexInBody = pathToDecleration[
sketchIndexInPathToNode const sketchIndexInBody = Number(lastSketchNodePath[1][0])
][0] as number
_node.body.splice(sketchIndexInBody + 1, 0, VariableDeclaration) _node.body.splice(sketchIndexInBody + 1, 0, VariableDeclaration)
const pathToExtrudeArg: PathToNode = [ const pathToExtrudeArg: PathToNode = [
@ -432,11 +437,10 @@ export function addSweep(
} { } {
const modifiedAst = structuredClone(node) const modifiedAst = structuredClone(node)
const name = findUniqueName(node, KCL_DEFAULT_CONSTANT_PREFIXES.SWEEP) const name = findUniqueName(node, KCL_DEFAULT_CONSTANT_PREFIXES.SWEEP)
const sweep = createCallExpressionStdLibKw( const sweep = createCallExpressionStdLib('sweep', [
'sweep', createObjectExpression({ path: createIdentifier(pathDeclarator.id.name) }),
createIdentifier(profileDeclarator.id.name), createIdentifier(profileDeclarator.id.name),
[createLabeledArg('path', createIdentifier(pathDeclarator.id.name))] ])
)
const declaration = createVariableDeclaration(name, sweep) const declaration = createVariableDeclaration(name, sweep)
modifiedAst.body.push(declaration) modifiedAst.body.push(declaration)
const pathToNode: PathToNode = [ const pathToNode: PathToNode = [
@ -444,9 +448,8 @@ export function addSweep(
[modifiedAst.body.length - 1, 'index'], [modifiedAst.body.length - 1, 'index'],
['declaration', 'VariableDeclaration'], ['declaration', 'VariableDeclaration'],
['init', 'VariableDeclarator'], ['init', 'VariableDeclarator'],
['arguments', 'CallExpressionKw'], ['arguments', 'CallExpression'],
[0, ARG_INDEX_FIELD], [0, 'index'],
['arg', LABELED_ARG_FIELD],
] ]
return { return {
@ -686,63 +689,6 @@ export function addOffsetPlane({
} }
} }
/**
* Append a helix to the AST
*/
export function addHelix({
node,
revolutions,
angleStart,
counterClockWise,
radius,
axis,
length,
}: {
node: Node<Program>
revolutions: Expr
angleStart: Expr
counterClockWise: boolean
radius: Expr
axis: string
length: Expr
}): { modifiedAst: Node<Program>; pathToNode: PathToNode } {
const modifiedAst = structuredClone(node)
const name = findUniqueName(node, KCL_DEFAULT_CONSTANT_PREFIXES.HELIX)
const variable = createVariableDeclaration(
name,
createCallExpressionStdLibKw(
'helix',
null, // Not in a pipeline
[
createLabeledArg('revolutions', revolutions),
createLabeledArg('angleStart', angleStart),
createLabeledArg('counterClockWise', createLiteral(counterClockWise)),
createLabeledArg('radius', radius),
createLabeledArg('axis', createLiteral(axis)),
createLabeledArg('length', length),
]
)
)
// TODO: figure out smart insertion than just appending at the end
const argIndex = 0
modifiedAst.body.push(variable)
const pathToNode: PathToNode = [
['body', ''],
[modifiedAst.body.length - 1, 'index'],
['declaration', 'VariableDeclaration'],
['init', 'VariableDeclarator'],
['arguments', 'CallExpressionKw'],
[argIndex, ARG_INDEX_FIELD],
['arg', LABELED_ARG_FIELD],
]
return {
modifiedAst,
pathToNode,
}
}
/** /**
* Return a modified clone of an AST with a named constant inserted into the body * Return a modified clone of an AST with a named constant inserted into the body
*/ */
@ -891,7 +837,6 @@ export function createLiteral(value: LiteralValue | number): Node<Literal> {
moduleId: 0, moduleId: 0,
value, value,
raw, raw,
trivia: [],
} }
} }
@ -901,7 +846,6 @@ export function createTagDeclarator(value: string): Node<TagDeclarator> {
start: 0, start: 0,
end: 0, end: 0,
moduleId: 0, moduleId: 0,
trivia: [],
value, value,
} }
@ -913,7 +857,6 @@ export function createIdentifier(name: string): Node<Identifier> {
start: 0, start: 0,
end: 0, end: 0,
moduleId: 0, moduleId: 0,
trivia: [],
name, name,
} }
@ -925,7 +868,6 @@ export function createPipeSubstitution(): Node<PipeSubstitution> {
start: 0, start: 0,
end: 0, end: 0,
moduleId: 0, moduleId: 0,
trivia: [],
} }
} }
@ -938,13 +880,11 @@ export function createCallExpressionStdLib(
start: 0, start: 0,
end: 0, end: 0,
moduleId: 0, moduleId: 0,
trivia: [],
callee: { callee: {
type: 'Identifier', type: 'Identifier',
start: 0, start: 0,
end: 0, end: 0,
moduleId: 0, moduleId: 0,
trivia: [],
name, name,
}, },
@ -962,13 +902,11 @@ export function createCallExpressionStdLibKw(
start: 0, start: 0,
end: 0, end: 0,
moduleId: 0, moduleId: 0,
trivia: [],
callee: { callee: {
type: 'Identifier', type: 'Identifier',
start: 0, start: 0,
end: 0, end: 0,
moduleId: 0, moduleId: 0,
trivia: [],
name, name,
}, },
@ -986,13 +924,11 @@ export function createCallExpression(
start: 0, start: 0,
end: 0, end: 0,
moduleId: 0, moduleId: 0,
trivia: [],
callee: { callee: {
type: 'Identifier', type: 'Identifier',
start: 0, start: 0,
end: 0, end: 0,
moduleId: 0, moduleId: 0,
trivia: [],
name, name,
}, },
@ -1008,7 +944,6 @@ export function createArrayExpression(
start: 0, start: 0,
end: 0, end: 0,
moduleId: 0, moduleId: 0,
trivia: [],
nonCodeMeta: nonCodeMetaEmpty(), nonCodeMeta: nonCodeMetaEmpty(),
elements, elements,
@ -1023,7 +958,6 @@ export function createPipeExpression(
start: 0, start: 0,
end: 0, end: 0,
moduleId: 0, moduleId: 0,
trivia: [],
body, body,
nonCodeMeta: nonCodeMetaEmpty(), nonCodeMeta: nonCodeMetaEmpty(),
@ -1041,14 +975,12 @@ export function createVariableDeclaration(
start: 0, start: 0,
end: 0, end: 0,
moduleId: 0, moduleId: 0,
trivia: [],
declaration: { declaration: {
type: 'VariableDeclarator', type: 'VariableDeclarator',
start: 0, start: 0,
end: 0, end: 0,
moduleId: 0, moduleId: 0,
trivia: [],
id: createIdentifier(varName), id: createIdentifier(varName),
init, init,
@ -1066,7 +998,6 @@ export function createObjectExpression(properties: {
start: 0, start: 0,
end: 0, end: 0,
moduleId: 0, moduleId: 0,
trivia: [],
nonCodeMeta: nonCodeMetaEmpty(), nonCodeMeta: nonCodeMetaEmpty(),
properties: Object.entries(properties).map(([key, value]) => ({ properties: Object.entries(properties).map(([key, value]) => ({
@ -1074,7 +1005,6 @@ export function createObjectExpression(properties: {
start: 0, start: 0,
end: 0, end: 0,
moduleId: 0, moduleId: 0,
trivia: [],
key: createIdentifier(key), key: createIdentifier(key),
value, value,
@ -1091,7 +1021,6 @@ export function createUnaryExpression(
start: 0, start: 0,
end: 0, end: 0,
moduleId: 0, moduleId: 0,
trivia: [],
operator, operator,
argument, argument,
@ -1108,7 +1037,6 @@ export function createBinaryExpression([left, operator, right]: [
start: 0, start: 0,
end: 0, end: 0,
moduleId: 0, moduleId: 0,
trivia: [],
operator, operator,
left, left,
@ -1394,7 +1322,6 @@ export async function deleteFromSelection(
varDec.node.init.type === 'PipeExpression') || varDec.node.init.type === 'PipeExpression') ||
selection.artifact?.type === 'sweep' || selection.artifact?.type === 'sweep' ||
selection.artifact?.type === 'plane' || selection.artifact?.type === 'plane' ||
selection.artifact?.type === 'helix' ||
!selection.artifact // aka expected to be a shell at this point !selection.artifact // aka expected to be a shell at this point
) { ) {
let extrudeNameToDelete = '' let extrudeNameToDelete = ''
@ -1402,8 +1329,7 @@ export async function deleteFromSelection(
if ( if (
selection.artifact && selection.artifact &&
selection.artifact.type !== 'sweep' && selection.artifact.type !== 'sweep' &&
selection.artifact.type !== 'plane' && selection.artifact.type !== 'plane'
selection.artifact.type !== 'helix'
) { ) {
const varDecName = varDec.node.id.name const varDecName = varDec.node.id.name
traverse(astClone, { traverse(astClone, {
@ -1442,17 +1368,13 @@ export async function deleteFromSelection(
if (!pathToNode) return new Error('Could not find extrude variable') if (!pathToNode) return new Error('Could not find extrude variable')
} else { } else {
pathToNode = selection.codeRef.pathToNode pathToNode = selection.codeRef.pathToNode
if (varDec.node.type !== 'VariableDeclarator') { const extrudeVarDec = getNodeFromPath<VariableDeclarator>(
const callExp = getNodeFromPath<CallExpression>( astClone,
astClone, pathToNode,
pathToNode, 'VariableDeclarator'
'CallExpression' )
) if (err(extrudeVarDec)) return extrudeVarDec
if (err(callExp)) return callExp extrudeNameToDelete = extrudeVarDec.node.id.name
extrudeNameToDelete = callExp.node.callee.name
} else {
extrudeNameToDelete = varDec.node.id.name
}
} }
const expressionIndex = pathToNode[1][0] as number const expressionIndex = pathToNode[1][0] as number
@ -1580,13 +1502,21 @@ export async function deleteFromSelection(
const pipeBody = varDec.node.init.body const pipeBody = varDec.node.init.body
if ( if (
pipeBody[0].type === 'CallExpression' && pipeBody[0].type === 'CallExpression' &&
pipeBody[0].callee.name === 'startSketchOn' (pipeBody[0].callee.name === 'startSketchOn' ||
pipeBody[0].callee.name === 'startProfileAt')
) { ) {
// remove varDec // remove varDec
const varDecIndex = varDec.shallowPath[1][0] as number const varDecIndex = varDec.shallowPath[1][0] as number
astClone.body.splice(varDecIndex, 1) astClone.body.splice(varDecIndex, 1)
return astClone return astClone
} }
} else if (
varDec.node.init.type === 'CallExpressionKw' &&
varDec.node.init.callee.name === 'circleThreePoint'
) {
const varDecIndex = varDec.shallowPath[1][0] as number
astClone.body.splice(varDecIndex, 1)
return astClone
} }
return new Error('Selection not recognised, could not delete') return new Error('Selection not recognised, could not delete')
@ -1596,6 +1526,167 @@ const nonCodeMetaEmpty = () => {
return { nonCodeNodes: {}, startNodes: [], start: 0, end: 0 } return { nonCodeNodes: {}, startNodes: [], start: 0, end: 0 }
} }
export const createLabeledArg = (name: string, arg: Expr): LabeledArg => { export function getInsertIndex(
return { label: createIdentifier(name), arg, type: 'LabeledArg' } sketchNodePaths: PathToNode[],
planeNodePath: PathToNode,
insertType: 'start' | 'end'
) {
let minIndex = 0
let maxIndex = 0
for (const path of sketchNodePaths) {
const index = Number(path[1][0])
if (index < minIndex) minIndex = index
if (index > maxIndex) maxIndex = index
}
const insertIndex = !sketchNodePaths.length
? Number(planeNodePath[1][0]) + 1
: insertType === 'start'
? minIndex
: maxIndex + 1
return insertIndex
}
export function updateSketchNodePathsWithInsertIndex({
insertIndex,
insertType,
sketchNodePaths,
}: {
insertIndex: number
insertType: 'start' | 'end'
sketchNodePaths: PathToNode[]
}): {
updatedEntryNodePath: PathToNode
updatedSketchNodePaths: PathToNode[]
} {
// TODO the rest of this function will not be robust to work for sketches defined within a function declaration
const newExpressionPathToNode: PathToNode = [
['body', ''],
[insertIndex, 'index'],
['declaration', 'VariableDeclaration'],
['init', 'VariableDeclarator'],
]
let updatedSketchNodePaths = structuredClone(sketchNodePaths)
if (insertType === 'start') {
updatedSketchNodePaths = updatedSketchNodePaths.map((path) => {
path[1][0] = Number(path[1][0]) + 1
return path
})
updatedSketchNodePaths.unshift(newExpressionPathToNode)
} else {
updatedSketchNodePaths.push(newExpressionPathToNode)
}
return {
updatedSketchNodePaths,
updatedEntryNodePath: newExpressionPathToNode,
}
}
/**
*
* Split the following pipe expression into
* ```ts
* part001 = startSketchOn('XZ')
|> startProfileAt([1, 2], %)
|> line([3, 4], %)
|> line([5, 6], %)
|> close(%)
extrude001 = extrude(5, part001)
```
into
```ts
sketch001 = startSketchOn('XZ')
part001 = startProfileAt([1, 2], sketch001)
|> line([3, 4], %)
|> line([5, 6], %)
|> close(%)
extrude001 = extrude(5, part001)
```
Notice that the `startSketchOn` is what gets the new variable name, this is so part001 still has the same data as before
making it safe for later code that uses part001 (the extrude in this example)
*
*/
export function splitPipedProfile(
ast: Program,
pathToPipe: PathToNode
):
| {
modifiedAst: Program
pathToProfile: PathToNode
pathToPlane: PathToNode
}
| Error {
const _ast = structuredClone(ast)
const varDec = getNodeFromPath<VariableDeclaration>(
_ast,
pathToPipe,
'VariableDeclaration'
)
if (err(varDec)) return varDec
if (
varDec.node.type !== 'VariableDeclaration' ||
varDec.node.declaration.init.type !== 'PipeExpression'
) {
return new Error('pathToNode does not point to pipe')
}
const init = varDec.node.declaration.init
const firstCall = init.body[0]
if (!isCallExprWithName(firstCall, 'startSketchOn'))
return new Error('First call is not startSketchOn')
const secondCall = init.body[1]
if (!isCallExprWithName(secondCall, 'startProfileAt'))
return new Error('Second call is not startProfileAt')
const varName = varDec.node.declaration.id.name
const newVarName = findUniqueName(_ast, 'sketch')
const secondCallArgs = structuredClone(secondCall.arguments)
secondCallArgs[1] = createIdentifier(newVarName)
const firstCallOfNewPipe = createCallExpression(
'startProfileAt',
secondCallArgs
)
const newSketch = createVariableDeclaration(
newVarName,
varDec.node.declaration.init.body[0]
)
const newProfile = createVariableDeclaration(
varName,
varDec.node.declaration.init.body.length <= 2
? firstCallOfNewPipe
: createPipeExpression([
firstCallOfNewPipe,
...varDec.node.declaration.init.body.slice(2),
])
)
const index = getBodyIndex(pathToPipe)
if (err(index)) return index
_ast.body.splice(index, 1, newSketch, newProfile)
const pathToPlane = structuredClone(pathToPipe)
const pathToProfile = structuredClone(pathToPipe)
pathToProfile[1][0] = index + 1
return {
modifiedAst: _ast,
pathToProfile,
pathToPlane,
}
}
export function createNodeFromExprSnippet(
strings: TemplateStringsArray,
...expressions: any[]
): Node<BodyItem> | Error {
const code = strings.reduce(
(acc, str, i) => acc + str + (expressions[i] || ''),
''
)
let program = parse(code)
if (err(program)) return program
const node = program.program?.body[0]
if (!node) return new Error('No node found')
return node
}
export const createLabeledArg = (label: string, arg: Expr): LabeledArg => {
return { label: createIdentifier(label), arg, type: 'LabeledArg' }
} }

Some files were not shown because too many files have changed in this diff Show More