Compare commits

..

38 Commits

Author SHA1 Message Date
cac7aa2bee Optionally chain error_code
Something in the Chamfer E2E tests is complaining about an uncaught
error with `error_code` trying to be referenced on something that is
`undefined`. That means that an API request is coming back as not
successful but does not have an actual error in the body of the
response.
2025-05-20 19:24:55 -04:00
0753987b5a [Fix]: Allow importing assemblies into exsiting projects and handling the collision (#7108)
* fix: saving off code

* fix: saving off progress

* chore: implemented kcl sample assembly unique sub dir creation

* fix: removing testing console logs

* fix: cleaning up old comment

* fix: add to file always does subdir/main.kcl now for single files

* fix: auto fmt

* fix: delete project and folder from ttc

* fix: fixed deleting projects and subdirs

* fix: if statement logic fixed for deleting project or subdir

* fix: TTC isProjectNew makes main.kcl not a subdir.

* fix: fixing e2e test

* fix: this should pass now
2025-05-20 19:03:54 -04:00
815ff7dc2b more subtract regression tests (#7123)
* more regression tests

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* snaps

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* iupdates

Signed-off-by: Jess Frazelle <github@jessfraz.com>

---------

Signed-off-by: Jess Frazelle <github@jessfraz.com>
2025-05-20 16:02:44 -07:00
46684d420d Test nested imports on all platforms (#7126) 2025-05-20 18:45:04 -04:00
eca09984a3 Fix: Follow up Text-to-CAD Edit to fix in browser (#7124)
* fix: web vs desktop who wins

* fix: fixed logic round two :(
2025-05-20 21:11:31 +00:00
ce63c6423e Impove naming in point-and-click Revolve to convey that axis are relative (#7122)
* Better axis options in point-and-click Revolve to convey the axis are relative
Fixes #7121

* Less changes
2025-05-20 16:57:55 -04:00
09699afe82 Fix: Can't go back to Profiles arg in Extrude, Revolve, Loft (#7106)
* Revert "Update failing E2E tests with new behavior, which allows skip with preselection"

This reverts commit d72bee8637.

* Fix: Can't go back to Profiles step in sweep commands
Fixes #7080

* Make it better but still not quite there

* I think I got it: this was likely the real bug making submit fire twice

* Bring timemouts back
2025-05-20 20:07:56 +00:00
36c8ad439d KCL: Add diameter arg to circle (#7116)
Paul's been requesting this for a long time. Now that we're fully using keyword args, this is easy to do.

We should probably add a similar `diameter` arg to `arc`, `tangentialArc`, `polygon` etc. And _maybe_ to `fillet`, but that might not be as helpful.
2025-05-20 19:44:35 +00:00
5dc77ceed5 Only start saving camera after scene is ready (#7120) 2025-05-20 15:12:08 -04:00
c7baa26b2d idiomatic kcl for hip sample (#7095)
* idiomatic kcl for hip sample

* Update kcl-samples simulation test output

* updates

Signed-off-by: Jess Frazelle <github@jessfraz.com>

---------

Signed-off-by: Jess Frazelle <github@jessfraz.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Jess Frazelle <github@jessfraz.com>
2025-05-20 11:36:08 -07:00
4d0454abcd Remove old ZMA logos, rip out JS theme state from open-in-desktop view (#7119)
* Remove old ZMA logos, rip out JS theme state from open-in-desktop view

Make this page dumber so that it doesn't break

* Lint and remove kcma refs

---------

Co-authored-by: Pierre Jacquier <pierre@zoo.dev>
2025-05-20 18:13:58 +00:00
1dafbf105e Identify distinct test suites (#7109) 2025-05-20 12:56:55 -04:00
773f013115 [Fix]: When loading the modeling page the user's settings for camera projection was ignored (#7111)
* fix: initialization of user camera projection is now used again, ope

* fix: removing comment
2025-05-20 12:46:53 -04:00
c5cd460595 Show error when trying to export at non-top-level (#7110) 2025-05-20 12:43:11 -04:00
845352046b Modeling machine unit tests (#7098)
* successfully transition to sketch idle

* get constraint to mod code

* clean up

* remove .only

* Fixed tsc

---------

Co-authored-by: lee-at-zoo-corp <lee@zoo.dev>
2025-05-20 12:22:52 -04:00
597f1087f9 Fix enter key loop in sweep commands (#7112)
* use effect for focus of command palette submit button, not autoFocus

autoFocus is being overridden by the Headless UI Dialog component's
focus management here
https://headlessui.com/v1/react/dialog#focus-management (we do not have
access to pass back initialFocus in this case). So we can use an effect
to imperatively focus the button when this component is mounted.

* Update sweep tests to submit the command with Enter
2025-05-20 16:04:56 +00:00
511334683a test: Add regression test for importing only at the top level (#7104)
Add regression test for importing only at the top level
2025-05-20 11:43:48 -04:00
223a4ad45d Style the experimental badge to match the website (#7100)
* Style the experimental badge to match the website

* Match the styling of the rest of the app

We don't use all apps monospace fonts anywhere.

* Bring back all caps
2025-05-20 14:57:53 +00:00
edf31ec1d3 Make the textarea command bar input run its resize initially (#7103)
We have a hook to auto-grow the textarea input but it wasn't running
once initially. This is noticable on the onboarding, where we show the
user a long Text-to-CAD Edit prompt that overflows.
2025-05-20 10:56:03 -04:00
1539557005 Always update snapshots if needed (#7105) 2025-05-20 14:34:26 +00:00
1d3ba4e3ac [Fix]: Remove console logs (#7102)
* fix: these got in when they should not have

* fix: spacemacs found wrong eslint again biome thing..
2025-05-20 14:12:32 +00:00
4110aa00db Only update snapshots for tests that repeatedly fail (#7101)
* Only update snapshots for tests that repeatedly fail

* Let TAB silence snapshot capture failures as well
2025-05-20 14:00:33 +00:00
7eb52cda36 Fix: creating a dir ending with .kcl panics the app (#7099)
* Fix: creating a dir ending with .kcl panics the app
Fixes #7082

* Update snapshots

* Update snapshots

* Add test

* tag: ['@electron', '@macos', '@windows']

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2025-05-20 13:53:26 +00:00
7872fb9cbd Update snapshots on CI (#7069) 2025-05-20 06:00:31 -04:00
651181e62c Restrict subdirectory imports to main.kcl (#7094)
Signed-off-by: Nick Cameron <nrc@ncameron.org>
2025-05-20 18:13:17 +12:00
max
38a245f2fc fix typos in the kcl samples (#7078)
typos
2025-05-20 05:47:33 +00:00
1b4289f93f allow nested files imported (#7090)
* allow nested files

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* fix test

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* disallow bad things

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* add playwright test on windows

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* add playwright test on windows

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* fixes

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* updates

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* updates

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* fix test

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* Update rust/kcl-lib/tests/nested_windows_main_kcl/unparsed@main.kcl.snap

Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>

* updates

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* updates

Signed-off-by: Jess Frazelle <github@jessfraz.com>

---------

Signed-off-by: Jess Frazelle <github@jessfraz.com>
Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
2025-05-19 22:42:25 -04:00
d0697c24fd Change Sketch to use the units of the module (#7076)
* Change Sketch to use the units of the module

* Update output
2025-05-19 20:20:47 -04:00
8c24e29081 [Fix]: P2E base path is always the project directory, P2E when completed stays in your current file (#7091)
* fix: fixes for p2e

* fix: yep tsc fixes

* fix: fixing reject workflow and navigate
2025-05-19 20:05:38 -04:00
2b9d26e2ff Make Text-to-CAD Edit the default workflow in the toolbar (#7092)
We want users to make edits first and foremost within projects, so we're
going to surface it as the default workflow button in the toolbar. WIP
until I verify that tests are okay with this.
2025-05-19 19:58:18 -04:00
ab148a7654 Fix: Esc key doesn't work in Text-to-CAD prompt (#7089)
* Fix: Esc key doesn't work in Text-to-CAD prompt
Fixes #7086

* Add e2e test because why not
2025-05-19 23:31:33 +00:00
553e650fbe Add brake disc to samples. (#7059)
* Add brake disc.

* Update kcl-samples simulation test output

* Update public/kcl-samples/brake-rotor/main.kcl

Co-authored-by: Adam Chalmers <adam.chalmers@zoo.dev>

* Update public/kcl-samples/brake-rotor/main.kcl

Co-authored-by: Adam Chalmers <adam.chalmers@zoo.dev>

* updates

Signed-off-by: Jess Frazelle <github@jessfraz.com>

---------

Signed-off-by: Jess Frazelle <github@jessfraz.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Adam Chalmers <adam.chalmers@zoo.dev>
Co-authored-by: Jess Frazelle <jessfraz@users.noreply.github.com>
Co-authored-by: Jess Frazelle <github@jessfraz.com>
2025-05-19 15:24:37 -07:00
9690a24c68 Avoid a spin-lock when auth is never resolved (#7084) 2025-05-19 18:16:07 -04:00
978d5d44a2 rotate a named axis (#7087)
updates

Signed-off-by: Jess Frazelle <github@jessfraz.com>
2025-05-19 22:11:35 +00:00
9df476543a turn on the revolve test (#7075)
* turn on the revolve test

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* updates

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* updates

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* updates

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* updates

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* updates

Signed-off-by: Jess Frazelle <github@jessfraz.com>

---------

Signed-off-by: Jess Frazelle <github@jessfraz.com>
2025-05-19 14:51:44 -07:00
cf303ebe97 Declare pattern transform functions in KCL (#7057)
* Declare pattern transform using KCL

Signed-off-by: Nick Cameron <nrc@ncameron.org>

* Boolean function param defaults

Signed-off-by: Nick Cameron <nrc@ncameron.org>

* Parse empty record types in fn types

Signed-off-by: Nick Cameron <nrc@ncameron.org>

---------

Signed-off-by: Nick Cameron <nrc@ncameron.org>
2025-05-20 08:25:29 +12:00
b1d1d89ca5 Include link to the new book (#7056)
Signed-off-by: Nick Cameron <nrc@ncameron.org>
2025-05-19 14:49:23 -05:00
3a599d0a0a Release KCL 75 (#7077) 2025-05-19 19:02:38 +00:00
228 changed files with 45718 additions and 23004 deletions

View File

@ -6,6 +6,7 @@ if [ -z "${TAB_API_URL:-}" ] || [ -z "${TAB_API_KEY:-}" ]; then
fi
project="https://github.com/KittyCAD/modeling-app"
suite="${CI_SUITE:-unit}"
branch="${GITHUB_HEAD_REF:-${GITHUB_REF_NAME:-}}"
commit="${CI_COMMIT_SHA:-${GITHUB_SHA:-}}"
@ -13,6 +14,7 @@ echo "Uploading batch results"
curl --silent --request POST \
--header "X-API-Key: ${TAB_API_KEY}" \
--form "project=${project}" \
--form "suite=${suite}" \
--form "branch=${branch}" \
--form "commit=${commit}" \
--form "tests=@test-results/junit.xml" \

View File

@ -193,6 +193,7 @@ jobs:
TAB_API_KEY: ${{ secrets.TAB_API_KEY }}
CI_COMMIT_SHA: ${{ github.event.pull_request.head.sha }}
CI_PR_NUMBER: ${{ github.event.pull_request.number }}
CI_SUITE: unit:kcl
run-internal-kcl-samples:
name: cargo test (internal-kcl-samples)
runs-on:

View File

@ -143,7 +143,7 @@ jobs:
- name: Install browsers
run: npm run playwright install --with-deps
- name: Capture snapshots
- name: Test snapshots
uses: nick-fields/retry@v3.0.2
with:
shell: bash
@ -156,6 +156,19 @@ jobs:
TAB_API_KEY: ${{ secrets.TAB_API_KEY }}
CI_COMMIT_SHA: ${{ github.event.pull_request.head.sha }}
CI_PR_NUMBER: ${{ github.event.pull_request.number }}
CI_SUITE: snapshots
TARGET: web
- name: Update snapshots
if: always()
run: npm run test:snapshots -- --last-failed --update-snapshots
env:
token: ${{ secrets.KITTYCAD_API_TOKEN_DEV }}
TAB_API_URL: ${{ secrets.TAB_API_URL }}
TAB_API_KEY: ${{ secrets.TAB_API_KEY }}
CI_COMMIT_SHA: ${{ github.event.pull_request.head.sha }}
CI_PR_NUMBER: ${{ github.event.pull_request.number }}
CI_SUITE: snapshots
TARGET: web
- uses: actions/upload-artifact@v4
@ -173,7 +186,7 @@ jobs:
id: git-check
run: |
git add e2e/playwright/snapshot-tests.spec.ts-snapshots e2e/playwright/snapshots
if git status | grep -q "Changes to be committed"
if git status | grep --quiet "Changes to be committed"
then echo "modified=true" >> $GITHUB_OUTPUT
else echo "modified=false" >> $GITHUB_OUTPUT
fi

View File

@ -4,7 +4,7 @@ excerpt: "Documentation of the KCL language for the Zoo Design Studio."
layout: manual
---
This is a reference for KCL. If you are learning KCL, you may prefer the [guide]() which explains
This is a reference for KCL. If you are learning KCL, you may prefer the [guide](https://zoo.dev/docs/kcl-book/intro.html) which explains
things in a more tutorial fashion. See also our documentation of the [standard library](/docs/kcl-std).
## Topics

View File

@ -27,9 +27,6 @@ import increment from "util.kcl"
answer = increment(41)
```
Imported files _must_ be in the same project so that units are uniform across
modules. This means that it must be in the same directory.
Import statements must be at the top-level of a file. It is not allowed to have
an `import` statement inside a function or in the body of an ifelse.
@ -58,6 +55,9 @@ Imported symbols can be renamed for convenience or to avoid name collisions.
import increment as inc, decrement as dec from "util.kcl"
```
You can import files from the current directory or from subdirectories, but if importing from a
subdirectory you can only import `main.kcl`.
---
## Functions vs `clone`
@ -229,6 +229,19 @@ The final statement is what's important because it's the return value of the
entire module. The module is expected to return a single object that can be used
as a variable by the file that imports it.
The name of the file or subdirectory is used as the name of the variable within the importing program.
If you want to use a different name, you can do so by using the `as` keyword:
```kcl,norun
import "cube.kcl" // Introduces a new variable called `cube`.
import "cube.kcl" as block // Introduces a new variable called `block`.
import "cube/main.kcl" // Introduces a new variable called `cube`.
import "cube/main.kcl" as block // Introduces a new variable called `block`.
```
If the filename includes hyphens (`-`) or starts with an underscore (`_`), then you must specify a
variable name.
---
## Multiple instances of the same import

View File

@ -11,7 +11,8 @@ layout: manual
circle(
@sketch_or_surface: Sketch | Plane | Face,
center: Point2d,
radius: number(Length),
radius?: number(Length),
diameter?: number(Length),
tag?: tag,
): Sketch
```
@ -25,7 +26,8 @@ the provided (x, y) origin point.
|----------|------|-------------|----------|
| `sketch_or_surface` | [`Sketch`](/docs/kcl-std/types/std-types-Sketch) or [`Plane`](/docs/kcl-std/types/std-types-Plane) or [`Face`](/docs/kcl-std/types/std-types-Face) | Sketch to extend, or plane or surface to sketch on. | Yes |
| `center` | [`Point2d`](/docs/kcl-std/types/std-types-Point2d) | The center of the circle. | Yes |
| `radius` | [`number(Length)`](/docs/kcl-std/types/std-types-number) | The radius of the circle. | Yes |
| `radius` | [`number(Length)`](/docs/kcl-std/types/std-types-number) | The radius of the circle. Incompatible with `diameter`. | No |
| `diameter` | [`number(Length)`](/docs/kcl-std/types/std-types-number) | The diameter of the circle. Incompatible with `radius`. | No |
| [`tag`](/docs/kcl-std/types/std-types-tag) | [`tag`](/docs/kcl-std/types/std-types-tag) | Create a new tag which refers to this circle. | No |
### Returns
@ -51,7 +53,7 @@ exampleSketch = startSketchOn(XZ)
|> line(end = [0, 30])
|> line(end = [-30, 0])
|> close()
|> subtract2d(tool = circle(center = [0, 15], radius = 5))
|> subtract2d(tool = circle(center = [0, 15], diameter = 10))
example = extrude(exampleSketch, length = 5)
```

View File

@ -1,19 +1,19 @@
---
title: "patternTransform2d"
subtitle: "Function in std::sketch"
excerpt: "Just like patternTransform, but works on 2D sketches not 3D solids."
excerpt: "Just like `patternTransform`, but works on 2D sketches not 3D solids."
layout: manual
---
Just like patternTransform, but works on 2D sketches not 3D solids.
Just like `patternTransform`, but works on 2D sketches not 3D solids.
```kcl
patternTransform2d(
@sketches: [Sketch],
instances: number,
transform: FunctionSource,
useOriginal?: bool,
): [Sketch]
@sketches: [Sketch; 1+],
instances: number(_),
transform: fn(number(_)): { },
useOriginal?: boolean,
): [Sketch; 1+]
```
@ -22,14 +22,14 @@ patternTransform2d(
| Name | Type | Description | Required |
|----------|------|-------------|----------|
| `sketches` | [`[Sketch]`](/docs/kcl-std/types/std-types-Sketch) | The sketch(es) to duplicate | Yes |
| `instances` | [`number`](/docs/kcl-std/types/std-types-number) | The number of total instances. Must be greater than or equal to 1. This includes the original entity. For example, if instances is 2, there will be two copies -- the original, and one new copy. If instances is 1, this has no effect. | Yes |
| `transform` | `FunctionSource` | How each replica should be transformed. The transform function takes a single parameter: an integer representing which number replication the transform is for. E.g. the first replica to be transformed will be passed the argument `1`. This simplifies your math: the transform function can rely on id `0` being the original instance passed into the `patternTransform`. See the examples. | Yes |
| `useOriginal` | [`bool`](/docs/kcl-std/types/std-types-bool) | If the target was sketched on an extrusion, setting this will use the original sketch as the target, not the entire joined solid. Defaults to false. | No |
| `sketches` | [`[Sketch; 1+]`](/docs/kcl-std/types/std-types-Sketch) | The sketch(es) to duplicate. | Yes |
| `instances` | [`number(_)`](/docs/kcl-std/types/std-types-number) | The number of total instances. Must be greater than or equal to 1. This includes the original entity. For example, if instances is 2, there will be two copies -- the original, and one new copy. If instances is 1, this has no effect. | Yes |
| `transform` | [`fn(number(_)): { }`](/docs/kcl-std/types/std-types-fn) | How each replica should be transformed. The transform function takes a single parameter: an integer representing which number replication the transform is for. E.g. the first replica to be transformed will be passed the argument `1`. This simplifies your math: the transform function can rely on id `0` being the original instance passed into the `patternTransform`. See the examples. | Yes |
| `useOriginal` | `boolean` | If the target was sketched on an extrusion, setting this will use the original sketch as the target, not the entire joined solid. | No |
### Returns
[`[Sketch]`](/docs/kcl-std/types/std-types-Sketch)
[`[Sketch; 1+]`](/docs/kcl-std/types/std-types-Sketch)
### Examples

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -65,7 +65,7 @@ layout: manual
* [`line`](/docs/kcl-std/line)
* [`loft`](/docs/kcl-std/loft)
* [`patternCircular2d`](/docs/kcl-std/patternCircular2d)
* [`patternTransform2d`](/docs/kcl-std/patternTransform2d)
* [`patternTransform2d`](/docs/kcl-std/functions/std-sketch-patternTransform2d)
* [`polygon`](/docs/kcl-std/polygon)
* [`profileStart`](/docs/kcl-std/profileStart)
* [`profileStartX`](/docs/kcl-std/profileStartX)
@ -94,7 +94,7 @@ layout: manual
* [`intersect`](/docs/kcl-std/intersect)
* [`patternCircular3d`](/docs/kcl-std/patternCircular3d)
* [`patternLinear3d`](/docs/kcl-std/patternLinear3d)
* [`patternTransform`](/docs/kcl-std/patternTransform)
* [`patternTransform`](/docs/kcl-std/functions/std-solid-patternTransform)
* [`shell`](/docs/kcl-std/functions/std-solid-shell)
* [`subtract`](/docs/kcl-std/subtract)
* [`union`](/docs/kcl-std/union)

View File

@ -30,7 +30,7 @@ This module contains functions for creating and manipulating sketches, and makin
* [`line`](/docs/kcl-std/line)
* [`loft`](/docs/kcl-std/loft)
* [`patternCircular2d`](/docs/kcl-std/patternCircular2d)
* [`patternTransform2d`](/docs/kcl-std/patternTransform2d)
* [`patternTransform2d`](/docs/kcl-std/functions/std-sketch-patternTransform2d)
* [`polygon`](/docs/kcl-std/polygon)
* [`profileStart`](/docs/kcl-std/profileStart)
* [`profileStartX`](/docs/kcl-std/profileStartX)

View File

@ -18,7 +18,7 @@ This module contains functions for modifying solids, e.g., by adding a fillet or
* [`intersect`](/docs/kcl-std/intersect)
* [`patternCircular3d`](/docs/kcl-std/patternCircular3d)
* [`patternLinear3d`](/docs/kcl-std/patternLinear3d)
* [`patternTransform`](/docs/kcl-std/patternTransform)
* [`patternTransform`](/docs/kcl-std/functions/std-solid-patternTransform)
* [`shell`](/docs/kcl-std/functions/std-solid-shell)
* [`subtract`](/docs/kcl-std/subtract)
* [`union`](/docs/kcl-std/union)

View File

@ -11,7 +11,7 @@ Contains frequently used constants, functions for interacting with the KittyCAD
The standard library is organised into modules (listed below), but most things are always available in KCL programs.
You might also want the [KCL language reference](/docs/kcl-lang) or the [KCL guide]().
You might also want the [KCL language reference](/docs/kcl-lang) or the [KCL guide](https://zoo.dev/docs/kcl-book/intro.html).
## Modules

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@ -45,15 +45,16 @@ test.describe('Command bar tests', () => {
await cmdBar.expectState({
stage: 'arguments',
commandName: 'Extrude',
currentArgKey: 'length',
currentArgValue: '5',
currentArgKey: 'sketches',
currentArgValue: '',
headerArguments: {
Profiles: '1 profile',
Profiles: '',
Length: '',
},
highlightedHeaderArg: 'length',
highlightedHeaderArg: 'Profiles',
})
await cmdBar.progressCmdBar()
await cmdBar.progressCmdBar()
await cmdBar.expectState({
stage: 'review',
commandName: 'Extrude',
@ -684,4 +685,33 @@ c = 3 + a`
highlightedHeaderArg: 'value',
})
})
test('Text-to-CAD command can be closed with escape while in prompt', async ({
page,
homePage,
cmdBar,
}) => {
await homePage.expectState({
projectCards: [],
sortBy: 'last-modified-desc',
})
await homePage.textToCadBtn.click()
await cmdBar.expectState({
stage: 'arguments',
commandName: 'Text-to-CAD Create',
currentArgKey: 'prompt',
currentArgValue: '',
headerArguments: {
Method: 'New project',
NewProjectName: 'untitled',
Prompt: '',
},
highlightedHeaderArg: 'prompt',
})
await page.keyboard.press('Escape')
await cmdBar.toBeClosed()
await cmdBar.expectState({
stage: 'commandBarClosed',
})
})
})

View File

@ -1134,6 +1134,7 @@ sketch001 = startSketchOn(XZ)
// Wait for the selection to register (TODO: we need a definitive way to wait for this)
await page.waitForTimeout(200)
await toolbar.extrudeButton.click()
await cmdBar.progressCmdBar()
await cmdBar.expectState({
stage: 'arguments',
currentArgKey: 'length',
@ -1355,9 +1356,7 @@ sketch001 = startSketchOn(XZ)
const u = await getUtils(page)
const projectLink = page.getByRole('link', { name: 'cube' })
const gizmo = page.locator('[aria-label*=gizmo]')
const resetCameraButton = page.getByRole('button', {
name: 'Reset view',
})
const resetCameraButton = page.getByRole('button', { name: 'Reset view' })
const locationToHaveColor = async (
position: { x: number; y: number },
color: [number, number, number]

View File

@ -238,6 +238,26 @@ test.describe('when using the file tree to', () => {
}
)
test(
`create new folders and that doesn't trigger a navigation`,
{ tag: ['@electron', '@macos', '@windows'] },
async ({ page, homePage, scene, toolbar, cmdBar }) => {
await homePage.goToModelingScene()
await scene.settled(cmdBar)
await toolbar.openPane('files')
const { createNewFolder } = await getUtils(page, test)
await createNewFolder('folder')
await createNewFolder('folder.kcl')
await test.step(`Postcondition: folders are created and we didn't navigate`, async () => {
await toolbar.expectFileTreeState(['folder', 'folder.kcl', 'main.kcl'])
await expect(toolbar.fileName).toHaveText('main.kcl')
})
}
)
test(
'deleting all files recreates a default main.kcl with no code',
{ tag: '@electron' },

View File

@ -105,14 +105,19 @@ export class CmdBarFixture {
expectState = async (expected: CmdBarSerialised) => {
return expect.poll(() => this._serialiseCmdBar()).toEqual(expected)
}
/** The method will use buttons OR press enter randomly to progress the cmdbar,
* this could have unexpected results depending on what's focused
*
* TODO: This method assumes the user has a valid input to the current stage,
/**
* This method is used to progress the command bar to the next step, defaulting to clicking the next button.
* Optionally, with the `shouldUseKeyboard` parameter, it will hit `Enter` to progress.
* * TODO: This method assumes the user has a valid input to the current stage,
* and assumes we are past the `pickCommand` step.
*/
progressCmdBar = async (shouldFuzzProgressMethod = true) => {
progressCmdBar = async (shouldUseKeyboard = false) => {
await this.page.waitForTimeout(2000)
if (shouldUseKeyboard) {
await this.page.keyboard.press('Enter')
return
}
const arrowButton = this.page.getByRole('button', {
name: 'arrow right Continue',
})
@ -308,6 +313,11 @@ export class CmdBarFixture {
await expect(this.cmdBarElement).toBeVisible({ timeout: 10_000 })
}
async toBeClosed() {
// Check that the command bar is closed
await expect(this.cmdBarElement).not.toBeVisible({ timeout: 10_000 })
}
async expectArgValue(value: string) {
// Check the placeholder project name exists
const actualArgument = await this.cmdBarElement

View File

@ -26,6 +26,7 @@ export class HomePageFixture {
sortByNameBtn!: Locator
appHeader!: Locator
tutorialBtn!: Locator
textToCadBtn!: Locator
constructor(page: Page) {
this.page = page
@ -47,6 +48,7 @@ export class HomePageFixture {
this.sortByNameBtn = this.page.getByTestId('home-sort-by-name')
this.appHeader = this.page.getByTestId('app-header')
this.tutorialBtn = this.page.getByTestId('home-tutorial-button')
this.textToCadBtn = this.page.getByTestId('home-text-to-cad')
}
private _serialiseSortBy = async (): Promise<

View File

@ -61,6 +61,7 @@ class MyAPIReporter implements Reporter {
const payload = {
// Required information
project: 'https://github.com/KittyCAD/modeling-app',
suite: process.env.CI_SUITE || 'e2e',
branch: process.env.GITHUB_HEAD_REF || process.env.GITHUB_REF_NAME || '',
commit: process.env.CI_COMMIT_SHA || process.env.GITHUB_SHA || '',
test: test.titlePath().slice(2).join(' '),

View File

@ -74,6 +74,15 @@ test.describe('Point-and-click tests', () => {
await test.step('do extrude flow and check extrude code is added to editor', async () => {
await toolbar.extrudeButton.click()
await cmdBar.expectState({
stage: 'arguments',
currentArgKey: 'sketches',
currentArgValue: '',
headerArguments: { Profiles: '', Length: '' },
highlightedHeaderArg: 'Profiles',
commandName: 'Extrude',
})
await cmdBar.progressCmdBar()
await cmdBar.expectState({
stage: 'arguments',
currentArgKey: 'length',
@ -1645,6 +1654,15 @@ sketch002 = startSketchOn(plane001)
await test.step(`Go through the command bar flow with preselected sketches`, async () => {
await toolbar.loftButton.click()
await cmdBar.expectState({
stage: 'arguments',
currentArgKey: 'sketches',
currentArgValue: '',
headerArguments: { Profiles: '' },
highlightedHeaderArg: 'Profiles',
commandName: 'Loft',
})
await cmdBar.progressCmdBar()
await cmdBar.expectState({
stage: 'review',
headerArguments: { Profiles: '2 profiles' },
@ -1855,7 +1873,11 @@ sketch002 = startSketchOn(XZ)
},
stage: 'review',
})
await cmdBar.progressCmdBar()
// Confirm we can submit from the review step with just `Enter`
await cmdBar.progressCmdBar(true)
await cmdBar.expectState({
stage: 'commandBarClosed',
})
})
await test.step(`Confirm code is added to the editor, scene has changed`, async () => {
@ -1995,7 +2017,7 @@ profile001 = ${circleCode}`
},
stage: 'review',
})
await cmdBar.progressCmdBar()
await cmdBar.progressCmdBar(true)
await editor.expectEditor.toContain(sweepDeclaration)
})
@ -2088,6 +2110,18 @@ extrude001 = extrude(sketch001, length = -12)
await test.step(`Apply fillet to the preselected edge`, async () => {
await page.waitForTimeout(100)
await toolbar.filletButton.click()
await cmdBar.expectState({
commandName: 'Fillet',
highlightedHeaderArg: 'selection',
currentArgKey: 'selection',
currentArgValue: '',
headerArguments: {
Selection: '',
Radius: '',
},
stage: 'arguments',
})
await cmdBar.progressCmdBar()
await cmdBar.expectState({
commandName: 'Fillet',
highlightedHeaderArg: 'radius',
@ -2617,6 +2651,18 @@ extrude001 = extrude(profile001, length = 5)
await test.step(`Apply fillet`, async () => {
await page.waitForTimeout(100)
await toolbar.filletButton.click()
await cmdBar.expectState({
commandName: 'Fillet',
highlightedHeaderArg: 'selection',
currentArgKey: 'selection',
currentArgValue: '',
headerArguments: {
Selection: '',
Radius: '',
},
stage: 'arguments',
})
await cmdBar.progressCmdBar()
await cmdBar.expectState({
commandName: 'Fillet',
highlightedHeaderArg: 'radius',
@ -2722,6 +2768,19 @@ extrude001 = extrude(sketch001, length = -12)
await test.step(`Apply chamfer to the preselected edge`, async () => {
await page.waitForTimeout(100)
await toolbar.chamferButton.click()
await cmdBar.expectState({
commandName: 'Chamfer',
highlightedHeaderArg: 'selection',
currentArgKey: 'selection',
currentArgValue: '',
headerArguments: {
Selection: '',
Length: '',
},
stage: 'arguments',
})
await cmdBar.progressCmdBar()
await page.waitForTimeout(1000)
await cmdBar.expectState({
commandName: 'Chamfer',
highlightedHeaderArg: 'length',
@ -3205,6 +3264,8 @@ extrude001 = extrude(sketch001, length = 30)
await test.step(`Go through the command bar flow with a preselected face (cap)`, async () => {
await toolbar.shellButton.click()
await cmdBar.progressCmdBar()
await page.waitForTimeout(500)
await cmdBar.progressCmdBar()
await cmdBar.expectState({
stage: 'review',
headerArguments: {
@ -3638,13 +3699,12 @@ tag=$rectangleSegmentC002,
// revolve
await editor.scrollToText(codeToSelection)
await page.getByText(codeToSelection).click()
// Wait for the selection to register (TODO: we need a definitive way to wait for this)
await page.waitForTimeout(200)
await toolbar.revolveButton.click()
await cmdBar.progressCmdBar()
await cmdBar.progressCmdBar()
await cmdBar.progressCmdBar()
await cmdBar.progressCmdBar()
await cmdBar.progressCmdBar()
const newCodeToFind = `revolve001 = revolve(sketch002, angle = 360, axis = X)`
expect(editor.expectEditor.toContain(newCodeToFind)).toBeTruthy()
@ -4573,6 +4633,18 @@ path001 = startProfile(sketch001, at = [0, 0])
await test.step('Go through command bar flow', async () => {
await toolbar.extrudeButton.click()
await cmdBar.expectState({
stage: 'arguments',
currentArgKey: 'sketches',
currentArgValue: '',
headerArguments: {
Profiles: '',
Length: '',
},
highlightedHeaderArg: 'Profiles',
commandName: 'Extrude',
})
await cmdBar.progressCmdBar()
await cmdBar.expectState({
stage: 'arguments',
currentArgKey: 'length',
@ -4655,6 +4727,19 @@ path001 = startProfile(sketch001, at = [0, 0])
await test.step('Go through command bar flow', async () => {
await toolbar.sweepButton.click()
await cmdBar.expectState({
stage: 'arguments',
currentArgKey: 'sketches',
currentArgValue: '',
headerArguments: {
Profiles: '',
Path: '',
Sectional: '',
},
highlightedHeaderArg: 'Profiles',
commandName: 'Sweep',
})
await cmdBar.progressCmdBar()
await cmdBar.expectState({
stage: 'arguments',
currentArgKey: 'path',
@ -4739,6 +4824,19 @@ path001 = startProfile(sketch001, at = [0, 0])
await test.step('Go through command bar flow', async () => {
await toolbar.closePane('code')
await toolbar.revolveButton.click()
await cmdBar.expectState({
stage: 'arguments',
currentArgKey: 'sketches',
currentArgValue: '',
headerArguments: {
Profiles: '',
AxisOrEdge: '',
Angle: '',
},
highlightedHeaderArg: 'Profiles',
commandName: 'Revolve',
})
await cmdBar.progressCmdBar()
await cmdBar.expectState({
stage: 'arguments',
currentArgKey: 'axisOrEdge',

View File

@ -11,6 +11,7 @@ import {
getPlaywrightDownloadDir,
getUtils,
isOutOfViewInScrollContainer,
runningOnWindows,
} from '@e2e/playwright/test-utils'
import { expect, test } from '@e2e/playwright/zoo-test'
@ -1979,7 +1980,6 @@ test(
}
)
// Flaky
test(
'Original project name persist after onboarding',
{ tag: '@electron' },
@ -2064,3 +2064,55 @@ test(
})
}
)
test(
'import from nested directory',
{ tag: ['@electron', '@windows', '@macos'] },
async ({ scene, cmdBar, context, page }) => {
await context.folderSetupFn(async (dir) => {
const bracketDir = path.join(dir, 'bracket')
await fsp.mkdir(bracketDir, { recursive: true })
const nestedDir = path.join(bracketDir, 'nested')
await fsp.mkdir(nestedDir, { recursive: true })
await fsp.copyFile(
executorInputPath('cylinder-inches.kcl'),
path.join(nestedDir, 'main.kcl')
)
await fsp.writeFile(
path.join(bracketDir, 'main.kcl'),
runningOnWindows()
? `import 'nested\\main.kcl' as thing\n\nthing`
: `import 'nested/main.kcl' as thing\n\nthing`
)
})
await page.setBodyDimensions({ width: 1200, height: 500 })
const u = await getUtils(page)
const pointOnModel = { x: 630, y: 280 }
await test.step('Opening the bracket project should load the stream', async () => {
// expect to see the text bracket
await expect(page.getByText('bracket')).toBeVisible()
await page.getByText('bracket').click()
await scene.settled(cmdBar)
await expect(
page.getByRole('button', { name: 'Start Sketch' })
).toBeEnabled({
timeout: 20_000,
})
// gray at this pixel means the stream has loaded in the most
// user way we can verify it (pixel color)
await expect
.poll(() => u.getGreatestPixDiff(pointOnModel, [125, 125, 125]), {
timeout: 10_000,
})
.toBeLessThan(15)
})
}
)

View File

@ -1016,6 +1016,7 @@ profile001 = startProfile(sketch001, at = [${roundOff(scale * 69.6)}, ${roundOff
// sketch selection should already have been made.
// otherwise the cmdbar would be waiting for a selection.
await cmdBar.progressCmdBar()
await cmdBar.expectState({
stage: 'arguments',
currentArgKey: 'length',

Binary file not shown.

Before

Width:  |  Height:  |  Size: 133 KiB

After

Width:  |  Height:  |  Size: 133 KiB

View File

@ -557,6 +557,14 @@ export async function getUtils(page: Page, test_?: typeof test) {
})
},
createNewFolder: async (name: string) => {
return test?.step(`Create a folder named ${name}`, async () => {
await page.getByTestId('create-folder-button').click()
await page.getByTestId('tree-input-field').fill(name)
await page.keyboard.press('Enter')
})
},
cloneFile: async (name: string) => {
return test?.step(`Cloning file '${name}'`, async () => {
await page

View File

@ -103,6 +103,8 @@ test.describe('Testing loading external models', () => {
file: 'ball-bearing' + FILE_EXT,
title: 'Ball Bearing',
file1: 'ball-bearing-1' + FILE_EXT,
folderName: 'ball-bearing',
folderName1: 'ball-bearing-1',
}
const projectCard = page.getByRole('link', { name: 'bracket' })
const overwriteWarning = page.getByText(
@ -154,8 +156,10 @@ test.describe('Testing loading external models', () => {
await test.step(`Ensure we made and opened a new file`, async () => {
await editor.expectEditor.toContain('// ' + sampleOne.title)
await expect(newlyCreatedFile(sampleOne.file)).toBeVisible()
await expect(projectMenuButton).toContainText(sampleOne.file)
await expect(
page.getByTestId('file-tree-item').getByText(sampleOne.folderName)
).toBeVisible()
await expect(projectMenuButton).toContainText('main.kcl')
})
await test.step(`Load a KCL sample with the command palette`, async () => {
@ -169,8 +173,10 @@ test.describe('Testing loading external models', () => {
await test.step(`Ensure we made and opened a new file with a unique name`, async () => {
await editor.expectEditor.toContain('// ' + sampleOne.title)
await expect(newlyCreatedFile(sampleOne.file1)).toBeVisible()
await expect(projectMenuButton).toContainText(sampleOne.file1)
await expect(
page.getByTestId('file-tree-item').getByText(sampleOne.folderName1)
).toBeVisible()
await expect(projectMenuButton).toContainText('main.kcl')
})
}
)

View File

@ -984,12 +984,12 @@ test.describe('Mocked Text-to-CAD API tests', { tag: ['@skipWin'] }, () => {
)
await expect(page.getByTestId('app-header-file-name')).toBeVisible()
await expect(page.getByTestId('app-header-file-name')).toContainText(
'2x2x2-cube.kcl'
'main.kcl'
)
await u.openFilePanel()
await expect(
page.getByTestId('file-tree-item').getByText('2x2x2-cube.kcl')
page.getByTestId('file-tree-item').getByText('2x2x2-cube')
).toBeVisible()
}
)
@ -1184,13 +1184,13 @@ test.describe('Mocked Text-to-CAD API tests', { tag: ['@skipWin'] }, () => {
)
await expect(page.getByTestId('app-header-file-name')).toBeVisible()
await expect(page.getByTestId('app-header-file-name')).toContainText(
'2x2x2-cube.kcl'
'main.kcl'
)
// Check file is created
await u.openFilePanel()
await expect(
page.getByTestId('file-tree-item').getByText('2x2x2-cube.kcl')
page.getByTestId('file-tree-item').getByText('2x2x2-cube')
).toBeVisible()
}
)
@ -1476,13 +1476,13 @@ test.describe('Mocked Text-to-CAD API tests', { tag: ['@skipWin'] }, () => {
)
await expect(page.getByTestId('app-header-file-name')).toBeVisible()
await expect(page.getByTestId('app-header-file-name')).toContainText(
'2x2x2-cube.kcl'
'main.kcl'
)
// Check file is created
await u.openFilePanel()
await expect(
page.getByTestId('file-tree-item').getByText('2x2x2-cube.kcl')
page.getByTestId('file-tree-item').getByText('2x2x2-cube')
).toBeVisible()
await expect(
page.getByTestId('file-tree-item').getByText('main.kcl')

View File

@ -573,6 +573,7 @@ profile001 = startProfile(sketch002, at = [-12.34, 12.34])
await expect(page.getByTestId('command-bar')).toBeVisible()
await page.waitForTimeout(100)
await cmdBar.progressCmdBar()
await cmdBar.progressCmdBar()
await expect(page.getByText('Confirm Extrude')).toBeVisible()
await cmdBar.progressCmdBar()

View File

@ -37,6 +37,8 @@ When you submit a PR to add or modify KCL samples, images will be generated and
[![bottle](screenshots/bottle.png)](bottle/main.kcl)
#### [bracket](bracket/main.kcl) ([screenshot](screenshots/bracket.png))
[![bracket](screenshots/bracket.png)](bracket/main.kcl)
#### [brake-rotor](brake-rotor/main.kcl) ([screenshot](screenshots/brake-rotor.png))
[![brake-rotor](screenshots/brake-rotor.png)](brake-rotor/main.kcl)
#### [car-wheel-assembly](car-wheel-assembly/main.kcl) ([screenshot](screenshots/car-wheel-assembly.png))
[![car-wheel-assembly](screenshots/car-wheel-assembly.png)](car-wheel-assembly/main.kcl)
#### [cold-plate](cold-plate/main.kcl) ([screenshot](screenshots/cold-plate.png))

View File

@ -0,0 +1,179 @@
// A 320mm vented brake disc (rotor), with straight vanes, 30mm thick. The disc bell should accommodate 5 M12 wheel studs on a 114.3mm pitch circle diameter.
@settings(defaultLengthUnit = mm)
// Define parameters.
dDisc = 320
dPitchCircle = 114.3
dBore = 64
nStuds = 5
dStudDrilling = 12.5 // M12
hFrictionSurface = 60
tDiscHalf = 10
// Vent parameters.
tVent = 10
wVent = 6
rVentFillet = 2
nVentBosses = 36
// Drilling parameters.
dDrillDia = 6
aBase = 90
aSweep = 30
nArcs = 12
// Bell parameters.
aDraftBell = 5
tBell = 5 // Wall thickness.
hBellAboveDiscFace = 40
hBellSubflush = 4
wUndercut = 8
fn drillHole(activeSketch, t) {
// Sketch a vent hole at line parameter value t on an arc drawn across the disc surface.
rInner = dDisc / 2 - hFrictionSurface
rOuter = dDisc / 2
aStart = aBase
aEnd = aBase - aSweep
// Linear interpolation of radius.
rCurrent = rInner + t * (rOuter - rInner)
// Linear interpolation of angle.
aCurrent = aStart + t * (aEnd - aStart)
// Calculate position.
xCenter = rCurrent * cos(aCurrent)
yCenter = rCurrent * sin(aCurrent)
// Draw.
drillCircle = circle(activeSketch, center = [xCenter, yCenter], radius = dDrillDia / 2)
return drillCircle
}
fn createDiscHalf(plane, dDiscParam, hFrictionSurfaceParam, tDiscHalfParam) {
// Create a disc half with a vent hole pattern.
sketchFace = startSketchOn(plane)
profileFace = circle(sketchFace, center = [0, 0], radius = dDiscParam / 2)
|> subtract2d(tool = circle(sketchFace, center = [0, 0], radius = dDiscParam / 2 - hFrictionSurfaceParam))
// Create three circles at t = 0, 0.5, and 1
hole1 = drillHole(activeSketch = sketchFace, t = 0.2)
hole2 = drillHole(activeSketch = sketchFace, t = 0.5)
hole3 = drillHole(activeSketch = sketchFace, t = 0.8)
// Pattern and cut.
holes = patternCircular2d(
[hole1, hole2, hole3],
instances = nArcs,
center = [0, 0],
arcDegrees = 360,
rotateDuplicates = true,
)
profileDrilled = subtract2d(profileFace, tool = holes)
// Extrude.
discHalf = extrude(profileFace, length = tDiscHalfParam)
return discHalf
}
// ---------------------------------------------------------------------------------------------------------------------
// Create inboard half.
discInboard = createDiscHalf(
plane = XY,
dDiscParam = dDisc,
hFrictionSurfaceParam = hFrictionSurface,
tDiscHalfParam = tDiscHalf,
)
// Create vents.
planeVent = offsetPlane(XY, offset = tDiscHalf)
sketchVent = startSketchOn(planeVent)
profileVent = startProfile(sketchVent, at = [-wVent, dDisc / 2])
|> angledLine(angle = 0, length = wVent, tag = $rectangleSegmentA001)
|> angledLine(angle = segAng(rectangleSegmentA001) - 90, length = hFrictionSurface, tag = $seg02)
|> angledLine(angle = segAng(rectangleSegmentA001), length = -segLen(rectangleSegmentA001), tag = $seg03)
|> line(endAbsolute = [profileStartX(%), profileStartY(%)], tag = $seg01)
|> close()
ventPad = extrude(profileVent, length = tVent)
|> fillet(
radius = rVentFillet,
tags = [
getCommonEdge(faces = [seg01, rectangleSegmentA001]),
getCommonEdge(faces = [seg02, rectangleSegmentA001]),
getCommonEdge(faces = [seg01, seg03]),
getCommonEdge(faces = [seg03, seg02])
],
)
ventSet = patternCircular3d(
ventPad,
instances = nVentBosses,
axis = [0, 0, 1],
center = [0, 0, tDiscHalf],
arcDegrees = 360,
rotateDuplicates = true,
)
// Create outboard half.
planeOutboard = offsetPlane(XY, offset = tDiscHalf + tVent)
discOutboard = createDiscHalf(
plane = planeOutboard,
dDiscParam = dDisc,
hFrictionSurfaceParam = hFrictionSurface,
tDiscHalfParam = tDiscHalf,
)
// Now create bell.
rCenter = dDisc / 2 - hFrictionSurface - wUndercut
rBore = dBore / 2
lDraftExterior = hBellAboveDiscFace / tan(90 - aDraftBell)
lDraftInterior = (hBellAboveDiscFace - tBell) / tan(90 - aDraftBell)
// Inner and outer radius of outboard face of disc bell.
rOuter = rCenter - lDraftExterior - rBore
rInner = rOuter + lDraftExterior - (tBell + lDraftInterior)
sketchDiscBell = startSketchOn(-YZ)
bodyDiscBell = startProfile(
sketchDiscBell,
at = [
-dDisc / 2 + hFrictionSurface,
tDiscHalf * 2 + tVent
],
)
|> arc(
%,
angleStart = -180,
angleEnd = 0,
radius = wUndercut / 2,
)
|> line(end = [lDraftExterior, hBellAboveDiscFace])
|> xLine(length = rOuter, tag = $seg04)
|> yLine(length = -tBell)
|> xLine(length = -rInner)
|> line(end = [-lDraftInterior, -hBellAboveDiscFace])
|> line(end = [0, -2]) // Wall thickness.
|> xLine(length = -1 * (tBell + wUndercut))
|> close(%)
|> revolve(axis = Y)
// Drill lug holes.
sketchLugs = startSketchOn(bodyDiscBell, face = seg04)
profileStud = circle(sketchLugs, center = [0, dPitchCircle / 2], radius = dStudDrilling / 2)
|> patternCircular2d(
%,
instances = nStuds,
center = [0, 0],
arcDegrees = 360,
rotateDuplicates = true,
)
clearance = 2 // Some margin on negative extrude.
lugs = extrude(profileStud, length = -1 * (tBell + clearance))

View File

@ -74,6 +74,16 @@
"main.kcl"
]
},
{
"file": "main.kcl",
"pathFromProjectDirectoryToFirstFile": "brake-rotor/main.kcl",
"multipleFiles": false,
"title": "A 320mm vented brake disc (rotor), with straight vanes, 30mm thick. The disc bell should accommodate 5 M12 wheel studs on a 114.3mm pitch circle diameter.",
"description": "",
"files": [
"main.kcl"
]
},
{
"file": "main.kcl",
"pathFromProjectDirectoryToFirstFile": "car-wheel-assembly/main.kcl",

View File

@ -72,25 +72,25 @@ leftSpacerShape = boxModuleFn(width = leftSpacerWidth)
// Module for power switch including front plate and red rocker button
switchPosition = leftSpacerPosition + leftSpacerWidth / 2 + moduleWidth / 2
swtichWidth = moduleWidth
switchWidth = moduleWidth
// Switch Body
switchBody = boxModuleFn(width = moduleWidth)
// Switch Plate
swtichPlateWidth = 20
switchPlateWidth = 20
switchPlateHeight = 30
switchPlateThickness = 3
switchPlateShape = startSketchOn(switchBody, face = END)
|> startProfile(
%,
at = [
-swtichPlateWidth / 2,
-switchPlateWidth / 2,
-switchPlateHeight / 2
],
)
|> yLine(length = switchPlateHeight)
|> xLine(length = swtichPlateWidth)
|> xLine(length = switchPlateWidth)
|> yLine(length = -switchPlateHeight)
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|> close()
@ -104,8 +104,8 @@ switchPlateBody = extrude(switchPlateShape, length = switchPlateThickness)
// Switch Button
switchButtonHeight = 26
swtichButtonWidth = 15
switchButtonShape = startSketchOn(offsetPlane(-YZ, offset = -swtichButtonWidth / 2))
switchButtonWidth = 15
switchButtonShape = startSketchOn(offsetPlane(-YZ, offset = -switchButtonWidth / 2))
|> startProfile(
%,
at = [
@ -121,7 +121,7 @@ switchButtonShape = startSketchOn(offsetPlane(-YZ, offset = -swtichButtonWidth /
])
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|> close()
switchButtonBody = extrude(switchButtonShape, length = swtichButtonWidth)
switchButtonBody = extrude(switchButtonShape, length = switchButtonWidth)
|> translate(
%,
x = switchPosition,
@ -132,7 +132,7 @@ switchButtonBody = extrude(switchButtonShape, length = swtichButtonWidth)
// Spacer between switch and plug modules for layout alignment
secondSpacerWidth = moduleWidth / 2
secondSpacerPosition = switchPosition + swtichWidth / 2 + secondSpacerWidth / 2
secondSpacerPosition = switchPosition + switchWidth / 2 + secondSpacerWidth / 2
secondSpacerBody = boxModuleFn(width = secondSpacerWidth)
|> translate(
%,

View File

@ -33,14 +33,9 @@ stemLoftProfile2 = startSketchOn(offsetPlane(XY, offset = 75))
// Draw the third profile for the lofted femur
p3Z = 110
p3A = 25
plane003 = {
origin = [0, 0.0, p3Z],
xAxis = [cos(p3A), 0, sin(p3A)],
yAxis = [0.0, 1.0, 0.0]
}
l3 = 32
r3 = 4
stemLoftProfile3 = startSketchOn(plane003)
stemLoftProfile3 = startSketchOn(XY)
|> startProfile(at = [-15.5, -l3 / 2])
|> yLine(length = l3, tag = $seg03)
|> tangentialArc(angle = -120, radius = r3)
@ -49,18 +44,14 @@ stemLoftProfile3 = startSketchOn(plane003)
|> angledLine(angle = 30, length = -segLen(seg03))
|> tangentialArc(endAbsolute = [profileStartX(%), profileStartY(%)])
|> close()
|> translate(z = p3Z)
|> rotate(pitch = -p3A)
// Draw the fourth profile for the lofted femur
p4Z = 130
p4A = 36.5
plane004 = {
origin = [0, 0.0, p4Z],
xAxis = [cos(p4A), 0, sin(p4A)],
yAxis = [0.0, 1.0, 0.0]
}
l4 = 16
r4 = 5
stemLoftProfile4 = startSketchOn(plane004)
stemLoftProfile4 = startSketchOn(XY)
|> startProfile(at = [-23, -l4 / 2])
|> yLine(length = l4, tag = $seg04)
|> tangentialArc(angle = -120, radius = r4)
@ -69,18 +60,14 @@ stemLoftProfile4 = startSketchOn(plane004)
|> angledLine(angle = 30, length = -segLen(seg04))
|> tangentialArc(endAbsolute = [profileStartX(%), profileStartY(%)])
|> close()
|> translate(z = p4Z)
|> rotate(pitch = -p4A)
// Draw the first profile for the femoral stem
p5Z = 140
p5A = 36.5
plane005 = {
origin = [0, 0.0, p5Z],
xAxis = [cos(p5A), 0, sin(p5A)],
yAxis = [0.0, 1.0, 0.0]
}
l5 = 1.6
r5 = 1.6
stemLoftProfile5 = startSketchOn(plane005)
stemLoftProfile5 = startSketchOn(XY)
|> startProfile(at = [-19.5, -l5 / 2])
|> yLine(length = l5, tag = $seg05)
|> tangentialArc(angle = -120, radius = r5)
@ -89,18 +76,14 @@ stemLoftProfile5 = startSketchOn(plane005)
|> angledLine(angle = 30, length = -segLen(seg05))
|> tangentialArc(endAbsolute = [profileStartX(%), profileStartY(%)])
|> close()
|> translate(z = p5Z)
|> rotate(pitch = -p5A)
// Draw the second profile for the femoral stem
p6Z = 145
p6A = 36.5
plane006 = {
origin = [0, 0.0, p6Z],
xAxis = [cos(p6A), 0, sin(p6A)],
yAxis = [0.0, 1.0, 0.0]
}
l6 = 1
r6 = 3
stemLoftProfile6 = startSketchOn(plane006)
stemLoftProfile6 = startSketchOn(XY)
|> startProfile(at = [-23.4, -l6 / 2])
|> yLine(length = l6, tag = $seg06)
|> tangentialArc(angle = -120, radius = r6)
@ -109,27 +92,24 @@ stemLoftProfile6 = startSketchOn(plane006)
|> angledLine(angle = 30, length = -segLen(seg06))
|> tangentialArc(endAbsolute = [profileStartX(%), profileStartY(%)])
|> close()
// Draw the third profile for the femoral stem
stemTab = clone(stemLoftProfile6)
|> extrude(%, length = 6)
|> translate(z = p6Z)
|> rotate(pitch = -p6A)
// Loft the femur using all profiles in sequence
femur = loft([
stemLoftProfile1,
stemLoftProfile2,
stemLoftProfile3,
stemLoftProfile4
])
// Loft the femoral stem
femoralStem = loft([
clone(stemLoftProfile4),
stemLoftProfile5,
stemLoftProfile6
clone(stemLoftProfile6)
])
// Draw the third profile for the femoral stem
stemTab = stemLoftProfile6
|> extrude(length = 6)
// Revolve a hollow socket to represent the femoral head
femoralHead = startSketchOn(XZ)
|> startProfile(at = [4, 0])

Binary file not shown.

Before

Width:  |  Height:  |  Size: 98 KiB

After

Width:  |  Height:  |  Size: 98 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 216 KiB

After

Width:  |  Height:  |  Size: 216 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 61 KiB

After

Width:  |  Height:  |  Size: 61 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 95 KiB

After

Width:  |  Height:  |  Size: 95 KiB

View File

@ -53,8 +53,8 @@ baseSlab = boxFn(plane = XY, width = slabWidth, height = -baseThickness)
|> appearance(%, color = "#dbd7d2")
// Create ground platform beneath the base
goundSize = 50
groundBody = boxFn(plane = offsetPlane(XY, offset = -baseThickness), width = goundSize, height = -5)
groundSize = 50
groundBody = boxFn(plane = offsetPlane(XY, offset = -baseThickness), width = groundSize, height = -5)
|> appearance(%, color = "#3a3631")
// Create a single slab with handrail height to be reused with pattern

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.1 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 16 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 13 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 13 KiB

20
rust/Cargo.lock generated
View File

@ -1815,7 +1815,7 @@ dependencies = [
[[package]]
name = "kcl-bumper"
version = "0.1.74"
version = "0.1.75"
dependencies = [
"anyhow",
"clap",
@ -1826,7 +1826,7 @@ dependencies = [
[[package]]
name = "kcl-derive-docs"
version = "0.1.74"
version = "0.1.75"
dependencies = [
"Inflector",
"anyhow",
@ -1845,7 +1845,7 @@ dependencies = [
[[package]]
name = "kcl-directory-test-macro"
version = "0.1.74"
version = "0.1.75"
dependencies = [
"convert_case",
"proc-macro2",
@ -1855,7 +1855,7 @@ dependencies = [
[[package]]
name = "kcl-language-server"
version = "0.2.74"
version = "0.2.75"
dependencies = [
"anyhow",
"clap",
@ -1876,7 +1876,7 @@ dependencies = [
[[package]]
name = "kcl-language-server-release"
version = "0.1.74"
version = "0.1.75"
dependencies = [
"anyhow",
"clap",
@ -1896,7 +1896,7 @@ dependencies = [
[[package]]
name = "kcl-lib"
version = "0.2.74"
version = "0.2.75"
dependencies = [
"anyhow",
"approx 0.5.1",
@ -1973,7 +1973,7 @@ dependencies = [
[[package]]
name = "kcl-python-bindings"
version = "0.3.74"
version = "0.3.75"
dependencies = [
"anyhow",
"kcl-lib",
@ -1988,7 +1988,7 @@ dependencies = [
[[package]]
name = "kcl-test-server"
version = "0.1.74"
version = "0.1.75"
dependencies = [
"anyhow",
"hyper 0.14.32",
@ -2001,7 +2001,7 @@ dependencies = [
[[package]]
name = "kcl-to-core"
version = "0.1.74"
version = "0.1.75"
dependencies = [
"anyhow",
"async-trait",
@ -2015,7 +2015,7 @@ dependencies = [
[[package]]
name = "kcl-wasm-lib"
version = "0.1.74"
version = "0.1.75"
dependencies = [
"anyhow",
"bson",

View File

@ -1,7 +1,7 @@
[package]
name = "kcl-bumper"
version = "0.1.74"
version = "0.1.75"
edition = "2021"
repository = "https://github.com/KittyCAD/modeling-api"
rust-version = "1.76"

View File

@ -1,7 +1,7 @@
[package]
name = "kcl-derive-docs"
description = "A tool for generating documentation from Rust derive macros"
version = "0.1.74"
version = "0.1.75"
edition = "2021"
license = "MIT"
repository = "https://github.com/KittyCAD/modeling-app"

View File

@ -1,7 +1,7 @@
[package]
name = "kcl-directory-test-macro"
description = "A tool for generating tests from a directory of kcl files"
version = "0.1.74"
version = "0.1.75"
edition = "2021"
license = "MIT"
repository = "https://github.com/KittyCAD/modeling-app"

View File

@ -1,6 +1,6 @@
[package]
name = "kcl-language-server-release"
version = "0.1.74"
version = "0.1.75"
edition = "2021"
authors = ["KittyCAD Inc <kcl@kittycad.io>"]
publish = false

View File

@ -2,7 +2,7 @@
name = "kcl-language-server"
description = "A language server for KCL."
authors = ["KittyCAD Inc <kcl@kittycad.io>"]
version = "0.2.74"
version = "0.2.75"
edition = "2021"
license = "MIT"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View File

@ -1,7 +1,7 @@
[package]
name = "kcl-lib"
description = "KittyCAD Language implementation and tools"
version = "0.2.74"
version = "0.2.75"
edition = "2021"
license = "MIT"
repository = "https://github.com/KittyCAD/modeling-app"

Binary file not shown.

Before

Width:  |  Height:  |  Size: 99 KiB

After

Width:  |  Height:  |  Size: 99 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 99 KiB

After

Width:  |  Height:  |  Size: 99 KiB

View File

@ -631,6 +631,8 @@ impl FnData {
return "clone(${0:part001})".to_owned();
} else if self.name == "hole" {
return "hole(${0:holeSketch}, ${1:%})".to_owned();
} else if self.name == "circle" {
return "circle(center = [${0:3.14}, ${1:3.14}], diameter = ${2:3.14})".to_owned();
}
let mut args = Vec::new();
let mut index = 0;

View File

@ -1018,7 +1018,7 @@ mod tests {
let snippet = circle_fn.to_autocomplete_snippet();
assert_eq!(
snippet,
r#"circle(center = [${0:3.14}, ${1:3.14}], radius = ${2:3.14})"#
r#"circle(center = [${0:3.14}, ${1:3.14}], diameter = ${2:3.14})"#
);
}

View File

@ -281,7 +281,14 @@ impl ExecutorContext {
// Track exports.
if let ItemVisibility::Export = variable_declaration.visibility {
exec_state.mod_local.module_exports.push(var_name);
if matches!(body_type, BodyType::Root) {
exec_state.mod_local.module_exports.push(var_name);
} else {
exec_state.err(CompilationError::err(
variable_declaration.as_source_range(),
"Exports are only supported at the top-level of a file. Remove `export` or move it to the top-level.",
));
}
}
// Variable declaration can be the return value of a module.
last_expr = matches!(body_type, BodyType::Root).then_some(value);

View File

@ -35,31 +35,28 @@ impl Default for TypedPath {
impl From<&String> for TypedPath {
fn from(path: &String) -> Self {
#[cfg(target_arch = "wasm32")]
{
TypedPath(typed_path::TypedPath::derive(path).to_path_buf())
}
#[cfg(not(target_arch = "wasm32"))]
{
TypedPath(std::path::PathBuf::from(path))
}
TypedPath::new(path)
}
}
impl From<&str> for TypedPath {
fn from(path: &str) -> Self {
TypedPath::new(path)
}
}
impl TypedPath {
pub fn new(path: &str) -> Self {
#[cfg(target_arch = "wasm32")]
{
TypedPath(typed_path::TypedPath::derive(path).to_path_buf())
}
#[cfg(not(target_arch = "wasm32"))]
{
TypedPath(std::path::PathBuf::from(path))
TypedPath(normalise_import(path))
}
}
}
impl TypedPath {
pub fn extension(&self) -> Option<&str> {
#[cfg(target_arch = "wasm32")]
{
@ -85,6 +82,17 @@ impl TypedPath {
}
}
pub fn join_typed(&self, path: &TypedPath) -> Self {
#[cfg(target_arch = "wasm32")]
{
TypedPath(self.0.join(path.0.to_path()))
}
#[cfg(not(target_arch = "wasm32"))]
{
TypedPath(self.0.join(&path.0))
}
}
pub fn parent(&self) -> Option<Self> {
#[cfg(target_arch = "wasm32")]
{
@ -206,3 +214,19 @@ impl schemars::JsonSchema for TypedPath {
gen.subschema_for::<std::path::PathBuf>()
}
}
/// Turn `nested\foo\bar\main.kcl` or `nested/foo/bar/main.kcl`
/// into a PathBuf that works on the host OS.
///
/// * Does **not** touch `..` or symlinks call `canonicalize()` if you need that.
/// * Returns an owned `PathBuf` only when normalisation was required.
fn normalise_import<S: AsRef<str>>(raw: S) -> std::path::PathBuf {
let s = raw.as_ref();
// On Unix we need to swap `\` → `/`. On Windows we leave it alone.
// (Windows happily consumes `/`)
if cfg!(unix) && s.contains('\\') {
std::path::PathBuf::from(s.replace('\\', "/"))
} else {
std::path::Path::new(s).to_path_buf()
}
}

View File

@ -155,9 +155,8 @@ impl RuntimeType {
.map(RuntimeType::Union),
Type::Object { properties } => properties
.into_iter()
.map(|p| {
RuntimeType::from_parsed(p.type_.unwrap().inner, exec_state, source_range)
.map(|ty| (p.identifier.inner.name, ty))
.map(|(id, ty)| {
RuntimeType::from_parsed(ty.inner, exec_state, source_range).map(|ty| (id.name.clone(), ty))
})
.collect::<Result<Vec<_>, CompilationError>>()
.map(RuntimeType::Object),

View File

@ -185,9 +185,9 @@ impl ModulePath {
match path {
ImportPath::Kcl { filename: path } | ImportPath::Foreign { path } => {
let resolved_path = if let Some(project_dir) = project_directory {
project_dir.join(path)
project_dir.join_typed(path)
} else {
TypedPath::from(path)
path.clone()
};
ModulePath::Local { value: resolved_path }
}

View File

@ -212,8 +212,9 @@ impl Type {
Type::Object { properties } => {
hasher.update(b"FnArgType::Object");
hasher.update(properties.len().to_ne_bytes());
for prop in properties.iter_mut() {
hasher.update(prop.compute_digest());
for (id, ty) in properties.iter_mut() {
hasher.update(id.compute_digest());
hasher.update(ty.compute_digest());
}
}
}

View File

@ -34,7 +34,7 @@ use crate::{
},
parsing::{ast::digest::Digest, token::NumericSuffix, PIPE_OPERATOR},
source_range::SourceRange,
ModuleId,
ModuleId, TypedPath,
};
mod condition;
@ -1741,8 +1741,8 @@ impl ImportSelector {
#[ts(export)]
#[serde(tag = "type")]
pub enum ImportPath {
Kcl { filename: String },
Foreign { path: String },
Kcl { filename: TypedPath },
Foreign { path: TypedPath },
Std { path: Vec<String> },
}
@ -1811,16 +1811,25 @@ impl ImportStatement {
match &self.path {
ImportPath::Kcl { filename: s } | ImportPath::Foreign { path: s } => {
let mut parts = s.split('.');
let path = parts.next()?;
let _ext = parts.next()?;
let rest = parts.next();
let name = s.to_string_lossy();
if name.ends_with("/main.kcl") || name.ends_with("\\main.kcl") {
let name = &name[..name.len() - 9];
let start = name.rfind(['/', '\\']).map(|s| s + 1).unwrap_or(0);
return Some(name[start..].to_owned());
}
if rest.is_some() {
let name = s.file_name().map(|f| f.to_string())?;
if name.contains('\\') || name.contains('/') {
return None;
}
path.rsplit(&['/', '\\']).next().map(str::to_owned)
// Remove the extension if it exists.
let extension = s.extension();
Some(if let Some(extension) = extension {
name.trim_end_matches(extension).trim_end_matches('.').to_string()
} else {
name
})
}
ImportPath::Std { path } => path.last().cloned(),
}
@ -3315,7 +3324,7 @@ pub enum Type {
},
// An object type.
Object {
properties: Vec<Parameter>,
properties: Vec<(Node<Identifier>, Node<Type>)>,
},
}
@ -3348,10 +3357,8 @@ impl fmt::Display for Type {
} else {
write!(f, ",")?;
}
write!(f, " {}:", p.identifier.name)?;
if let Some(ty) = &p.type_ {
write!(f, " {}", ty.inner)?;
}
write!(f, " {}:", p.0.name)?;
write!(f, " {}", p.1)?;
}
write!(f, " }}")
}
@ -3988,7 +3995,7 @@ cylinder = startSketchOn(-XZ)
#[tokio::test(flavor = "multi_thread")]
async fn test_parse_type_args_object_on_functions() {
let some_program_string = r#"fn thing(arg0: [number], arg1: {thing: number, things: [string], more?: string}, tag?: string) {
let some_program_string = r#"fn thing(arg0: [number], arg1: {thing: number, things: [string], more: string}, tag?: string) {
return arg0
}"#;
let module_id = ModuleId::default();
@ -4015,8 +4022,8 @@ cylinder = startSketchOn(-XZ)
params[1].type_.as_ref().unwrap().inner,
Type::Object {
properties: vec![
Parameter {
identifier: Node::new(
(
Node::new(
Identifier {
name: "thing".to_owned(),
digest: None,
@ -4025,18 +4032,15 @@ cylinder = startSketchOn(-XZ)
37,
module_id,
),
type_: Some(Node::new(
Node::new(
Type::Primitive(PrimitiveType::Number(NumericSuffix::None)),
39,
45,
module_id
)),
default_value: None,
labeled: true,
digest: None,
},
Parameter {
identifier: Node::new(
),
),
(
Node::new(
Identifier {
name: "things".to_owned(),
digest: None,
@ -4045,7 +4049,7 @@ cylinder = startSketchOn(-XZ)
53,
module_id,
),
type_: Some(Node::new(
Node::new(
Type::Array {
ty: Box::new(Type::Primitive(PrimitiveType::String)),
len: ArrayLen::None
@ -4053,13 +4057,10 @@ cylinder = startSketchOn(-XZ)
56,
62,
module_id
)),
default_value: None,
labeled: true,
digest: None
},
Parameter {
identifier: Node::new(
)
),
(
Node::new(
Identifier {
name: "more".to_owned(),
digest: None
@ -4068,11 +4069,8 @@ cylinder = startSketchOn(-XZ)
69,
module_id,
),
type_: Some(Node::new(Type::Primitive(PrimitiveType::String), 72, 78, module_id)),
labeled: true,
default_value: Some(DefaultParamVal::none()),
digest: None
}
Node::new(Type::Primitive(PrimitiveType::String), 71, 77, module_id),
)
]
}
);
@ -4343,4 +4341,20 @@ startSketchOn(XY)
"#
);
}
#[test]
fn module_name() {
#[track_caller]
fn assert_mod_name(stmt: &str, name: &str) {
let tokens = crate::parsing::token::lex(stmt, ModuleId::default()).unwrap();
let stmt = crate::parsing::parser::import_stmt(&mut tokens.as_slice()).unwrap();
assert_eq!(stmt.module_name().unwrap(), name);
}
assert_mod_name("import 'foo.kcl'", "foo");
assert_mod_name("import 'foo.kcl' as bar", "bar");
assert_mod_name("import 'main.kcl'", "main");
assert_mod_name("import 'foo/main.kcl'", "foo");
assert_mod_name("import 'foo\\bar\\main.kcl'", "bar");
}
}

View File

@ -35,7 +35,7 @@ use crate::{
token::{Token, TokenSlice, TokenType},
PIPE_OPERATOR, PIPE_SUBSTITUTION_OPERATOR,
},
SourceRange, IMPORT_FILE_EXTENSIONS,
SourceRange, TypedPath, IMPORT_FILE_EXTENSIONS,
};
thread_local! {
@ -436,7 +436,7 @@ fn pipe_expression(i: &mut TokenSlice) -> PResult<Node<PipeExpression>> {
))
}
fn bool_value(i: &mut TokenSlice) -> PResult<BoxNode<Literal>> {
fn bool_value(i: &mut TokenSlice) -> PResult<Node<Literal>> {
let (value, token) = any
.try_map(|token: Token| match token.token_type {
TokenType::Keyword if token.value == "true" => Ok((true, token)),
@ -448,7 +448,7 @@ fn bool_value(i: &mut TokenSlice) -> PResult<BoxNode<Literal>> {
})
.context(expected("a boolean literal (either true or false)"))
.parse_next(i)?;
Ok(Box::new(Node::new(
Ok(Node::new(
Literal {
value: LiteralValue::Bool(value),
raw: value.to_string(),
@ -457,11 +457,11 @@ fn bool_value(i: &mut TokenSlice) -> PResult<BoxNode<Literal>> {
token.start,
token.end,
token.module_id,
)))
))
}
fn literal(i: &mut TokenSlice) -> PResult<BoxNode<Literal>> {
alt((string_literal, unsigned_number_literal))
alt((string_literal, unsigned_number_literal, bool_value))
.map(Box::new)
.context(expected("a KCL literal, like 'myPart' or 3"))
.parse_next(i)
@ -1729,7 +1729,7 @@ fn glob(i: &mut TokenSlice) -> PResult<Token> {
.parse_next(i)
}
fn import_stmt(i: &mut TokenSlice) -> PResult<BoxNode<ImportStatement>> {
pub(super) fn import_stmt(i: &mut TokenSlice) -> PResult<BoxNode<ImportStatement>> {
let (visibility, visibility_token) = opt(terminated(item_visibility, whitespace))
.parse_next(i)?
.map_or((ItemVisibility::Default, None), |pair| (pair.0, Some(pair.1)));
@ -1862,18 +1862,50 @@ fn validate_path_string(path_string: String, var_name: bool, path_range: SourceR
let path = if path_string.ends_with(".kcl") {
if path_string
.chars()
.any(|c| !c.is_ascii_alphanumeric() && c != '_' && c != '-' && c != '.')
.any(|c| !c.is_ascii_alphanumeric() && c != '_' && c != '-' && c != '.' && c != '/' && c != '\\')
{
return Err(ErrMode::Cut(
CompilationError::fatal(
path_range,
"import path may only contain alphanumeric characters, underscore, hyphen, and period. KCL files in other directories are not yet supported.",
"import path may only contain alphanumeric characters, `_`, `-`, `.`, `/`, and `\\`.",
)
.into(),
));
}
ImportPath::Kcl { filename: path_string }
if path_string.starts_with("..") {
return Err(ErrMode::Cut(
CompilationError::fatal(
path_range,
"import path may not start with '..'. Cannot traverse to something outside the bounds of your project. If this path is inside your project please find a better way to reference it.",
)
.into(),
));
}
// Make sure they are not using an absolute path.
if path_string.starts_with('/') || path_string.starts_with('\\') {
return Err(ErrMode::Cut(
CompilationError::fatal(
path_range,
"import path may not start with '/' or '\\'. Cannot traverse to something outside the bounds of your project. If this path is inside your project please find a better way to reference it.",
)
.into(),
));
}
if (path_string.contains('/') || path_string.contains('\\'))
&& !(path_string.ends_with("/main.kcl") || path_string.ends_with("\\main.kcl"))
{
return Err(ErrMode::Cut(
CompilationError::fatal(path_range, "import path to a subdirectory must only refer to main.kcl.")
.into(),
));
}
ImportPath::Kcl {
filename: TypedPath::new(&path_string),
}
} else if path_string.starts_with("std::") {
ParseContext::warn(CompilationError::err(
path_range,
@ -1910,7 +1942,9 @@ fn validate_path_string(path_string: String, var_name: bool, path_range: SourceR
format!("unsupported import path format. KCL files can be imported from the current project, CAD files with the following formats are supported: {}", IMPORT_FILE_EXTENSIONS.join(", ")),
))
}
ImportPath::Foreign { path: path_string }
ImportPath::Foreign {
path: TypedPath::new(&path_string),
}
} else {
return Err(ErrMode::Cut(
CompilationError::fatal(
@ -2051,7 +2085,7 @@ fn unnecessarily_bracketed(i: &mut TokenSlice) -> PResult<Expr> {
fn expr_allowed_in_pipe_expr(i: &mut TokenSlice) -> PResult<Expr> {
alt((
member_expression.map(Box::new).map(Expr::MemberExpression),
bool_value.map(Expr::Literal),
bool_value.map(Box::new).map(Expr::Literal),
tag.map(Box::new).map(Expr::TagDeclarator),
literal.map(Expr::Literal),
fn_call_kw.map(Box::new).map(Expr::CallExpressionKw),
@ -2070,7 +2104,7 @@ fn expr_allowed_in_pipe_expr(i: &mut TokenSlice) -> PResult<Expr> {
fn possible_operands(i: &mut TokenSlice) -> PResult<Expr> {
let mut expr = alt((
unary_expression.map(Box::new).map(Expr::UnaryExpression),
bool_value.map(Expr::Literal),
bool_value.map(Box::new).map(Expr::Literal),
member_expression.map(Box::new).map(Expr::MemberExpression),
literal.map(Expr::Literal),
fn_call_kw.map(Box::new).map(Expr::CallExpressionKw),
@ -2780,27 +2814,31 @@ fn labeled_argument(i: &mut TokenSlice) -> PResult<LabeledArg> {
.parse_next(i)
}
fn record_ty_field(i: &mut TokenSlice) -> PResult<(Node<Identifier>, Node<Type>)> {
(identifier, colon, opt(whitespace), type_)
.map(|(id, _, _, ty)| (id, ty))
.parse_next(i)
}
/// Parse a type in various positions.
fn type_(i: &mut TokenSlice) -> PResult<Node<Type>> {
let type_ = alt((
// Object types
// TODO it is buggy to treat object fields like parameters since the parameters parser assumes a terminating `)`.
(open_brace, parameters, close_brace).try_map(|(open, params, close)| {
for p in &params {
if p.type_.is_none() {
return Err(CompilationError::fatal(
p.identifier.as_source_range(),
"Missing type for field in record type",
));
}
}
Ok(Node::new(
Type::Object { properties: params },
open.start,
close.end,
open.module_id,
))
}),
(
open_brace,
opt(whitespace),
separated(0.., record_ty_field, comma_sep),
opt(whitespace),
close_brace,
)
.try_map(|(open, _, params, _, close)| {
Ok(Node::new(
Type::Object { properties: params },
open.start,
close.end,
open.module_id,
))
}),
// Array types
array_type,
// Primitive or union types
@ -4530,9 +4568,24 @@ e
fn bad_imports() {
assert_err(
r#"import cube from "../cube.kcl""#,
"import path may only contain alphanumeric characters, underscore, hyphen, and period. KCL files in other directories are not yet supported.",
"import path may not start with '..'. Cannot traverse to something outside the bounds of your project. If this path is inside your project please find a better way to reference it.",
[17, 30],
);
assert_err(
r#"import cube from "/cube.kcl""#,
"import path may not start with '/' or '\\'. Cannot traverse to something outside the bounds of your project. If this path is inside your project please find a better way to reference it.",
[17, 28],
);
assert_err(
r#"import cube from "C:\cube.kcl""#,
"import path may only contain alphanumeric characters, `_`, `-`, `.`, `/`, and `\\`.",
[17, 30],
);
assert_err(
r#"import cube from "cube/cube.kcl""#,
"import path to a subdirectory must only refer to main.kcl.",
[17, 32],
);
assert_err(
r#"import * as foo from "dsfs""#,
"as is not the 'from' keyword",
@ -4866,6 +4919,15 @@ let myBox = box(p=[0,0], h=-3, l=-16, w=-10)
|> line(%, tag = $var01)"#;
assert_no_err(some_program_string);
}
#[test]
fn test_parse_param_bool_default() {
let some_program_string = r#"fn patternTransform(
use_original?: boolean = false,
) {}"#;
assert_no_err(some_program_string);
}
#[test]
fn parse_function_types() {
let code = r#"foo = x: fn
@ -4875,6 +4937,8 @@ fn foo(x: fn(a, b: number(mm), c: d): number(Angle)): fn { return 0 }
type fn
type foo = fn
type foo = fn(a: string, b: { f: fn(): any })
type foo = fn(a: string, b: {})
type foo = fn(a: string, b: { })
type foo = fn([fn])
type foo = fn(fn, f: fn(number(_))): [fn([any]): string]
"#;

View File

@ -996,6 +996,27 @@ mod import_cycle1 {
super::execute(TEST_NAME, false).await
}
}
mod import_only_at_top_level {
const TEST_NAME: &str = "import_only_at_top_level";
/// Test parsing KCL.
#[test]
fn parse() {
super::parse(TEST_NAME)
}
/// Test that parsing and unparsing KCL produces the original KCL input.
#[tokio::test(flavor = "multi_thread")]
async fn unparse() {
super::unparse(TEST_NAME).await
}
/// Test that KCL is executed correctly.
#[tokio::test(flavor = "multi_thread")]
async fn kcl_test_execute() {
super::execute(TEST_NAME, false).await
}
}
mod import_function_not_sketch {
const TEST_NAME: &str = "import_function_not_sketch";
@ -1164,6 +1185,27 @@ mod import_foreign {
super::execute(TEST_NAME, false).await
}
}
mod export_var_only_at_top_level {
const TEST_NAME: &str = "export_var_only_at_top_level";
/// Test parsing KCL.
#[test]
fn parse() {
super::parse(TEST_NAME)
}
/// Test that parsing and unparsing KCL produces the original KCL input.
#[tokio::test(flavor = "multi_thread")]
async fn unparse() {
super::unparse(TEST_NAME).await
}
/// Test that KCL is executed correctly.
#[tokio::test(flavor = "multi_thread")]
async fn kcl_test_execute() {
super::execute(TEST_NAME, false).await
}
}
mod assembly_non_default_units {
const TEST_NAME: &str = "assembly_non_default_units";
@ -3188,7 +3230,6 @@ mod revolve_colinear {
/// Test that KCL is executed correctly.
#[tokio::test(flavor = "multi_thread")]
#[ignore] // until https://github.com/KittyCAD/engine/pull/3417 lands
async fn kcl_test_execute() {
super::execute(TEST_NAME, true).await
}
@ -3277,3 +3318,87 @@ mod subtract_regression10 {
super::execute(TEST_NAME, true).await
}
}
mod nested_main_kcl {
const TEST_NAME: &str = "nested_main_kcl";
/// Test parsing KCL.
#[test]
fn parse() {
super::parse(TEST_NAME)
}
/// Test that parsing and unparsing KCL produces the original KCL input.
#[tokio::test(flavor = "multi_thread")]
async fn unparse() {
super::unparse(TEST_NAME).await
}
/// Test that KCL is executed correctly.
#[tokio::test(flavor = "multi_thread")]
async fn kcl_test_execute() {
super::execute(TEST_NAME, true).await
}
}
mod nested_windows_main_kcl {
const TEST_NAME: &str = "nested_windows_main_kcl";
/// Test parsing KCL.
#[test]
fn parse() {
super::parse(TEST_NAME)
}
/// Test that parsing and unparsing KCL produces the original KCL input.
#[tokio::test(flavor = "multi_thread")]
async fn unparse() {
super::unparse(TEST_NAME).await
}
/// Test that KCL is executed correctly.
#[tokio::test(flavor = "multi_thread")]
async fn kcl_test_execute() {
super::execute(TEST_NAME, true).await
}
}
mod subtract_regression11 {
const TEST_NAME: &str = "subtract_regression11";
/// Test parsing KCL.
#[test]
fn parse() {
super::parse(TEST_NAME)
}
/// Test that parsing and unparsing KCL produces the original KCL input.
#[tokio::test(flavor = "multi_thread")]
async fn unparse() {
super::unparse(TEST_NAME).await
}
/// Test that KCL is executed correctly.
#[tokio::test(flavor = "multi_thread")]
async fn kcl_test_execute() {
super::execute(TEST_NAME, true).await
}
}
mod subtract_regression12 {
const TEST_NAME: &str = "subtract_regression12";
/// Test parsing KCL.
#[test]
fn parse() {
super::parse(TEST_NAME)
}
/// Test that parsing and unparsing KCL produces the original KCL input.
#[tokio::test(flavor = "multi_thread")]
async fn unparse() {
super::unparse(TEST_NAME).await
}
/// Test that KCL is executed correctly.
#[tokio::test(flavor = "multi_thread")]
async fn kcl_test_execute() {
super::execute(TEST_NAME, true).await
}
}

View File

@ -9,6 +9,7 @@ use kittycad_modeling_cmds as kcmc;
use schemars::JsonSchema;
use serde::Serialize;
pub use crate::execution::fn_call::Args;
use crate::{
errors::{KclError, KclErrorDetails},
execution::{
@ -27,8 +28,6 @@ use crate::{
ModuleId,
};
pub use crate::execution::fn_call::Args;
const ERROR_STRING_SKETCH_TO_SOLID_HELPER: &str =
"You can convert a sketch (2D) into a Solid (3D) by calling a function like `extrude` or `revolve`";

View File

@ -80,8 +80,6 @@ lazy_static! {
Box::new(crate::std::patterns::PatternLinear3D),
Box::new(crate::std::patterns::PatternCircular2D),
Box::new(crate::std::patterns::PatternCircular3D),
Box::new(crate::std::patterns::PatternTransform),
Box::new(crate::std::patterns::PatternTransform2D),
Box::new(crate::std::edge::GetOppositeEdge),
Box::new(crate::std::edge::GetNextAdjacentEdge),
Box::new(crate::std::edge::GetPreviousAdjacentEdge),
@ -280,6 +278,14 @@ pub(crate) fn std_fn(path: &str, fn_name: &str) -> (crate::std::StdFn, StdFnProp
|e, a| Box::pin(crate::std::clone::clone(e, a)),
StdFnProps::default("std::clone").include_in_feature_tree(),
),
("solid", "patternTransform") => (
|e, a| Box::pin(crate::std::patterns::pattern_transform(e, a)),
StdFnProps::default("std::solid::patternTransform").include_in_feature_tree(),
),
("sketch", "patternTransform2d") => (
|e, a| Box::pin(crate::std::patterns::pattern_transform_2d(e, a)),
StdFnProps::default("std::sketch::patternTransform2d"),
),
_ => unreachable!(),
}
}

View File

@ -15,6 +15,7 @@ use kittycad_modeling_cmds::{
use serde::Serialize;
use uuid::Uuid;
use super::axis_or_reference::Axis3dOrPoint3d;
use crate::{
errors::{KclError, KclErrorDetails},
execution::{
@ -31,8 +32,6 @@ use crate::{
ExecutorContext, SourceRange,
};
use super::axis_or_reference::Axis3dOrPoint3d;
const MUST_HAVE_ONE_INSTANCE: &str = "There must be at least 1 instance of your geometry";
/// Repeat some 3D solid, changing each repetition slightly.
@ -57,202 +56,6 @@ pub async fn pattern_transform_2d(exec_state: &mut ExecState, args: Args) -> Res
Ok(sketches.into())
}
/// Repeat a 3-dimensional solid, changing it each time.
///
/// Replicates the 3D solid, applying a transformation function to each replica.
/// Transformation function could alter rotation, scale, visibility, position, etc.
///
/// The `patternTransform` call itself takes a number for how many total instances of
/// the shape should be. For example, if you use a circle with `patternTransform(instances = 4, transform = f)`
/// then there will be 4 circles: the original, and 3 created by replicating the original and
/// calling the transform function on each.
///
/// The transform function takes a single parameter: an integer representing which
/// number replication the transform is for. E.g. the first replica to be transformed
/// will be passed the argument `1`. This simplifies your math: the transform function can
/// rely on id `0` being the original instance passed into the `patternTransform`. See the examples.
///
/// The transform function returns a transform object. All properties of the object are optional,
/// they each default to "no change". So the overall transform object defaults to "no change" too.
/// Its properties are:
///
/// - `translate` (3D point)
///
/// Translates the replica, moving its position in space.
///
/// - `replicate` (bool)
///
/// If false, this ID will not actually copy the object. It'll be skipped.
///
/// - `scale` (3D point)
///
/// Stretches the object, multiplying its width in the given dimension by the point's component in
/// that direction.
///
/// - `rotation` (object, with the following properties)
///
/// - `rotation.axis` (a 3D point, defaults to the Z axis)
///
/// - `rotation.angle` (number of degrees)
///
/// - `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")
///
/// ```no_run
/// // Each instance will be shifted along the X axis.
/// fn transform(@id) {
/// return { translate = [4 * id, 0, 0] }
/// }
///
/// // Sketch 4 cylinders.
/// sketch001 = startSketchOn(XZ)
/// |> circle(center = [0, 0], radius = 2)
/// |> extrude(length = 5)
/// |> patternTransform(instances = 4, transform = transform)
/// ```
/// ```no_run
/// // Each instance will be shifted along the X axis,
/// // with a gap between the original (at x = 0) and the first replica
/// // (at x = 8). This is because `id` starts at 1.
/// fn transform(@id) {
/// return { translate = [4 * (1+id), 0, 0] }
/// }
///
/// sketch001 = startSketchOn(XZ)
/// |> circle(center = [0, 0], radius = 2)
/// |> extrude(length = 5)
/// |> patternTransform(instances = 4, transform = transform)
/// ```
/// ```no_run
/// fn cube(length, center) {
/// l = length/2
/// x = center[0]
/// y = center[1]
/// p0 = [-l + x, -l + y]
/// p1 = [-l + x, l + y]
/// p2 = [ l + x, l + y]
/// p3 = [ l + x, -l + y]
///
/// return startSketchOn(XY)
/// |> startProfile(at = p0)
/// |> line(endAbsolute = p1)
/// |> line(endAbsolute = p2)
/// |> line(endAbsolute = p3)
/// |> line(endAbsolute = p0)
/// |> close()
/// |> extrude(length = length)
/// }
///
/// width = 20
/// fn transform(@i) {
/// return {
/// // Move down each time.
/// translate = [0, 0, -i * width],
/// // Make the cube longer, wider and flatter each time.
/// scale = [pow(1.1, exp = i), pow(1.1, exp = i), pow(0.9, exp = i)],
/// // Turn by 15 degrees each time.
/// rotation = {
/// angle = 15 * i,
/// origin = "local",
/// }
/// }
/// }
///
/// myCubes =
/// cube(length = width, center = [100,0])
/// |> patternTransform(instances = 25, transform = transform)
/// ```
///
/// ```no_run
/// fn cube(length, center) {
/// l = length/2
/// x = center[0]
/// y = center[1]
/// p0 = [-l + x, -l + y]
/// p1 = [-l + x, l + y]
/// p2 = [ l + x, l + y]
/// p3 = [ l + x, -l + y]
///
/// return startSketchOn(XY)
/// |> startProfile(at = p0)
/// |> line(endAbsolute = p1)
/// |> line(endAbsolute = p2)
/// |> line(endAbsolute = p3)
/// |> line(endAbsolute = p0)
/// |> close()
/// |> extrude(length = length)
/// }
///
/// width = 20
/// fn transform(@i) {
/// return {
/// translate = [0, 0, -i * width],
/// rotation = {
/// angle = 90 * i,
/// // Rotate around the overall scene's origin.
/// origin = "global",
/// }
/// }
/// }
/// myCubes =
/// cube(length = width, center = [100,100])
/// |> patternTransform(instances = 4, transform = transform)
/// ```
/// ```no_run
/// // Parameters
/// r = 50 // base radius
/// h = 10 // layer height
/// t = 0.005 // taper factor [0-1)
/// // Defines how to modify each layer of the vase.
/// // Each replica is shifted up the Z axis, and has a smoothly-varying radius
/// fn transform(@replicaId) {
/// scale = r * abs(1 - (t * replicaId)) * (5 + cos((replicaId / 8): number(rad)))
/// return {
/// translate = [0, 0, replicaId * 10],
/// scale = [scale, scale, 0],
/// }
/// }
/// // Each layer is just a pretty thin cylinder.
/// fn layer() {
/// return startSketchOn(XY) // or some other plane idk
/// |> circle(center = [0, 0], radius = 1, tag = $tag1)
/// |> extrude(length = h)
/// }
/// // The vase is 100 layers tall.
/// // The 100 layers are replica of each other, with a slight transformation applied to each.
/// vase = layer() |> patternTransform(instances = 100, transform = transform)
/// ```
/// ```
/// fn transform(@i) {
/// // Transform functions can return multiple transforms. They'll be applied in order.
/// return [
/// { translate = [30 * i, 0, 0] },
/// { rotation = { angle = 45 * i } },
/// ]
/// }
/// startSketchOn(XY)
/// |> startProfile(at = [0, 0])
/// |> polygon(
/// radius = 10,
/// numSides = 4,
/// center = [0, 0],
/// inscribed = false,
/// )
/// |> extrude(length = 4)
/// |> patternTransform(instances = 3, transform = transform)
/// ```
#[stdlib {
name = "patternTransform",
feature_tree_operation = true,
keywords = true,
unlabeled_first = true,
args = {
solids = { docs = "The solid(s) to duplicate" },
instances = { docs = "The number of total instances. Must be greater than or equal to 1. This includes the original entity. For example, if instances is 2, there will be two copies -- the original, and one new copy. If instances is 1, this has no effect." },
transform = { docs = "How each replica should be transformed. The transform function takes a single parameter: an integer representing which number replication the transform is for. E.g. the first replica to be transformed will be passed the argument `1`. This simplifies your math: the transform function can rely on id `0` being the original instance passed into the `patternTransform`. See the examples." },
use_original = { docs = "If the target was sketched on an extrusion, setting this will use the original sketch as the target, not the entire joined solid. Defaults to false." },
},
tags = ["solid"]
}]
async fn inner_pattern_transform<'a>(
solids: Vec<Solid>,
instances: u32,
@ -283,30 +86,6 @@ async fn inner_pattern_transform<'a>(
.await
}
/// Just like patternTransform, but works on 2D sketches not 3D solids.
/// ```no_run
/// // Each instance will be shifted along the X axis.
/// fn transform(@id) {
/// return { translate = [4 * id, 0] }
/// }
///
/// // Sketch 4 circles.
/// sketch001 = startSketchOn(XZ)
/// |> circle(center = [0, 0], radius= 2)
/// |> patternTransform2d(instances = 4, transform = transform)
/// ```
#[stdlib {
name = "patternTransform2d",
keywords = true,
unlabeled_first = true,
args = {
sketches = { docs = "The sketch(es) to duplicate" },
instances = { docs = "The number of total instances. Must be greater than or equal to 1. This includes the original entity. For example, if instances is 2, there will be two copies -- the original, and one new copy. If instances is 1, this has no effect." },
transform = { docs = "How each replica should be transformed. The transform function takes a single parameter: an integer representing which number replication the transform is for. E.g. the first replica to be transformed will be passed the argument `1`. This simplifies your math: the transform function can rely on id `0` being the original instance passed into the `patternTransform`. See the examples." },
use_original = { docs = "If the target was sketched on an extrusion, setting this will use the original sketch as the target, not the entire joined solid. Defaults to false." },
},
tags = ["sketch"]
}]
async fn inner_pattern_transform_2d<'a>(
sketches: Vec<Sketch>,
instances: u32,
@ -1228,7 +1007,16 @@ pub async fn pattern_circular_3d(exec_state: &mut ExecState, args: Args) -> Resu
// If instances is 1, this has no effect.
let instances: u32 = args.get_kw_arg_typed("instances", &RuntimeType::count(), exec_state)?;
// The axis around which to make the pattern. This is a 3D vector.
let axis: [TyF64; 3] = args.get_kw_arg_typed("axis", &RuntimeType::point3d(), exec_state)?;
let axis: Axis3dOrPoint3d = args.get_kw_arg_typed(
"axis",
&RuntimeType::Union(vec![
RuntimeType::Primitive(PrimitiveType::Axis3d),
RuntimeType::point3d(),
]),
exec_state,
)?;
let axis = axis.to_point3d();
// The center about which to make the pattern. This is a 3D vector.
let center: [TyF64; 3] = args.get_kw_arg_typed("center", &RuntimeType::point3d(), exec_state)?;
// The arc angle (in degrees) to place the repetitions. Must be greater than 0.
@ -1260,6 +1048,24 @@ pub async fn pattern_circular_3d(exec_state: &mut ExecState, args: Args) -> Resu
/// solid with respect to the center of the circle is maintained.
///
/// ```no_run
/// /// Pattern using a named axis.
///
/// exampleSketch = startSketchOn(XZ)
/// |> circle(center = [0, 0], radius = 1)
///
/// example = extrude(exampleSketch, length = -5)
/// |> patternCircular3d(
/// axis = X,
/// center = [10, -20, 0],
/// instances = 11,
/// arcDegrees = 360,
/// rotateDuplicates = true
/// )
/// ```
///
/// ```no_run
/// /// Pattern using a raw axis.
///
/// exampleSketch = startSketchOn(XZ)
/// |> circle(center = [0, 0], radius = 1)
///

View File

@ -44,10 +44,11 @@ pub enum SketchOrSurface {
pub async fn circle(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
let sketch_or_surface = args.get_unlabeled_kw_arg("sketchOrSurface")?;
let center = args.get_kw_arg_typed("center", &RuntimeType::point2d(), exec_state)?;
let radius: TyF64 = args.get_kw_arg_typed("radius", &RuntimeType::length(), exec_state)?;
let radius: Option<TyF64> = args.get_kw_arg_opt_typed("radius", &RuntimeType::length(), exec_state)?;
let diameter: Option<TyF64> = args.get_kw_arg_opt_typed("diameter", &RuntimeType::length(), exec_state)?;
let tag = args.get_kw_arg_opt(NEW_TAG_KW)?;
let sketch = inner_circle(sketch_or_surface, center, radius, tag, exec_state, args).await?;
let sketch = inner_circle(sketch_or_surface, center, radius, diameter, tag, exec_state, args).await?;
Ok(KclValue::Sketch {
value: Box::new(sketch),
})
@ -56,7 +57,8 @@ pub async fn circle(exec_state: &mut ExecState, args: Args) -> Result<KclValue,
async fn inner_circle(
sketch_or_surface: SketchOrSurface,
center: [TyF64; 2],
radius: TyF64,
radius: Option<TyF64>,
diameter: Option<TyF64>,
tag: Option<TagNode>,
exec_state: &mut ExecState,
args: Args,
@ -68,6 +70,25 @@ async fn inner_circle(
let (center_u, ty) = untype_point(center.clone());
let units = ty.expect_length();
let radius = match (radius, diameter) {
(Some(radius), None) => radius,
(None, Some(mut diameter)) => {
diameter.n /= 2.0;
diameter
}
(None, None) => {
return Err(KclError::Type(KclErrorDetails::new(
"This function needs either `diameter` or `radius`".to_string(),
vec![args.source_range],
)))
}
(Some(_), Some(_)) => {
return Err(KclError::Type(KclErrorDetails::new(
"You cannot specify both `diameter` and `radius`, please remove one".to_string(),
vec![args.source_range],
)))
}
};
let from = [center_u[0] + radius.to_length_units(units), center_u[1]];
let from_t = [TyF64::new(from[0], ty.clone()), TyF64::new(from[1], ty)];

View File

@ -26,7 +26,7 @@ use crate::{
args::{Args, TyF64},
utils::{
arc_center_and_end, get_tangential_arc_to_info, get_x_component, get_y_component,
intersection_with_parallel_line, point_to_len_unit, point_to_mm, untype_point, untyped_point_to_mm,
intersection_with_parallel_line, point_to_len_unit, point_to_mm, untyped_point_to_mm,
TangentialArcInfoInput,
},
},
@ -1396,12 +1396,14 @@ pub(crate) async fn inner_start_profile(
])
.await?;
let (to, ty) = untype_point(at);
// Convert to the units of the module. This is what the frontend expects.
let units = exec_state.length_unit();
let to = point_to_len_unit(at, units);
let current_path = BasePath {
from: to,
to,
tag: tag.clone(),
units: ty.expect_length(),
units,
geo_meta: GeoMeta {
id: move_pen_id,
metadata: args.source_range.into(),
@ -1414,7 +1416,7 @@ pub(crate) async fn inner_start_profile(
artifact_id: path_id.into(),
on: sketch_surface.clone(),
paths: vec![],
units: ty.expect_length(),
units,
mirror: Default::default(),
meta: vec![args.source_range.into()],
tags: if let Some(tag) = &tag {

View File

@ -11,11 +11,13 @@ use kcmc::{
};
use kittycad_modeling_cmds as kcmc;
use super::args::TyF64;
use crate::{
errors::{KclError, KclErrorDetails},
execution::{types::RuntimeType, ExecState, KclValue, SolidOrSketchOrImportedGeometry},
std::Args,
execution::{
types::{PrimitiveType, RuntimeType},
ExecState, KclValue, SolidOrSketchOrImportedGeometry,
},
std::{args::TyF64, axis_or_reference::Axis3dOrPoint3d, Args},
};
/// Scale a solid or a sketch.
@ -446,7 +448,15 @@ pub async fn rotate(exec_state: &mut ExecState, args: Args) -> Result<KclValue,
let roll: Option<TyF64> = args.get_kw_arg_opt_typed("roll", &RuntimeType::degrees(), exec_state)?;
let pitch: Option<TyF64> = args.get_kw_arg_opt_typed("pitch", &RuntimeType::degrees(), exec_state)?;
let yaw: Option<TyF64> = args.get_kw_arg_opt_typed("yaw", &RuntimeType::degrees(), exec_state)?;
let axis: Option<[TyF64; 3]> = args.get_kw_arg_opt_typed("axis", &RuntimeType::point3d(), exec_state)?;
let axis: Option<Axis3dOrPoint3d> = args.get_kw_arg_opt_typed(
"axis",
&RuntimeType::Union(vec![
RuntimeType::Primitive(PrimitiveType::Axis3d),
RuntimeType::point3d(),
]),
exec_state,
)?;
let axis = axis.map(|a| a.to_point3d());
let angle: Option<TyF64> = args.get_kw_arg_opt_typed("angle", &RuntimeType::degrees(), exec_state)?;
let global = args.get_kw_arg_opt("global")?;
@ -642,7 +652,51 @@ pub async fn rotate(exec_state: &mut ExecState, args: Args) -> Result<KclValue,
/// ```
///
/// ```no_run
/// // Rotate a pipe about an axis with an angle.
/// // Rotate a pipe about a named axis with an angle.
///
/// // Create a path for the sweep.
/// sweepPath = startSketchOn(XZ)
/// |> startProfile(at = [0.05, 0.05])
/// |> line(end = [0, 7])
/// |> tangentialArc(angle = 90, radius = 5)
/// |> line(end = [-3, 0])
/// |> tangentialArc(angle = -90, radius = 5)
/// |> line(end = [0, 7])
///
/// // Create a hole for the pipe.
/// pipeHole = startSketchOn(XY)
/// |> circle(
/// center = [0, 0],
/// radius = 1.5,
/// )
///
/// sweepSketch = startSketchOn(XY)
/// |> circle(
/// center = [0, 0],
/// radius = 2,
/// )
/// |> subtract2d(tool = pipeHole)
/// |> sweep(path = sweepPath)
/// |> rotate(
/// axis = Z,
/// angle = 90,
/// )
/// ```
///
/// ```no_run
/// // Rotate an imported model.
///
/// import "tests/inputs/cube.sldprt" as cube
///
/// cube
/// |> rotate(
/// axis = [0, 0, 1.0],
/// angle = 9,
/// )
/// ```
///
/// ```no_run
/// // Rotate a pipe about a raw axis with an angle.
///
/// // Create a path for the sweep.
/// sweepPath = startSketchOn(XZ)
@ -673,18 +727,6 @@ pub async fn rotate(exec_state: &mut ExecState, args: Args) -> Result<KclValue,
/// )
/// ```
///
/// ```no_run
/// // Rotate an imported model.
///
/// import "tests/inputs/cube.sldprt" as cube
///
/// cube
/// |> rotate(
/// axis = [0, 0, 1.0],
/// angle = 9,
/// )
/// ```
///
/// ```
/// // Sweep two sketches along the same path.
///

View File

@ -6,7 +6,7 @@
/// The standard library is organised into modules (listed below), but most things are always available
/// in KCL programs.
///
/// You might also want the [KCL language reference](/docs/kcl-lang) or the [KCL guide]().
/// You might also want the [KCL language reference](/docs/kcl-lang) or the [KCL guide](https://zoo.dev/docs/kcl-book/intro.html).
@no_std
@settings(defaultLengthUnit = mm, kclVersion = 1.0)

View File

@ -24,7 +24,7 @@
/// |> line(end = [0, 30])
/// |> line(end = [-30, 0])
/// |> close()
/// |> subtract2d(tool = circle(center = [0, 15], radius = 5))
/// |> subtract2d(tool = circle(center = [0, 15], diameter = 10))
///
/// example = extrude(exampleSketch, length = 5)
/// ```
@ -34,8 +34,10 @@ export fn circle(
@sketch_or_surface: Sketch | Plane | Face,
/// The center of the circle.
center: Point2d,
/// The radius of the circle.
radius: number(Length),
/// The radius of the circle. Incompatible with `diameter`.
radius?: number(Length),
/// The diameter of the circle. Incompatible with `radius`.
diameter?: number(Length),
/// Create a new tag which refers to this circle.
tag?: tag,
): Sketch {}
@ -278,3 +280,28 @@ export fn revolve(
/// A named tag for the face at the end of the revolve.
tagEnd?: tag,
): [Solid; 1+] {}
/// Just like `patternTransform`, but works on 2D sketches not 3D solids.
///
/// ```kcl
/// // Each instance will be shifted along the X axis.
/// fn transform(@id) {
/// return { translate = [4 * id, 0] }
/// }
///
/// // Sketch 4 circles.
/// sketch001 = startSketchOn(XZ)
/// |> circle(center = [0, 0], radius = 2)
/// |> patternTransform2d(instances = 4, transform = transform)
/// ```
@(impl = std_rust)
export fn patternTransform2d(
/// The sketch(es) to duplicate.
@sketches: [Sketch; 1+],
/// The number of total instances. Must be greater than or equal to 1. This includes the original entity. For example, if instances is 2, there will be two copies -- the original, and one new copy. If instances is 1, this has no effect.
instances: number(Count),
/// How each replica should be transformed. The transform function takes a single parameter: an integer representing which number replication the transform is for. E.g. the first replica to be transformed will be passed the argument `1`. This simplifies your math: the transform function can rely on id `0` being the original instance passed into the `patternTransform`. See the examples.
transform: fn(number(Count)): {},
/// If the target was sketched on an extrusion, setting this will use the original sketch as the target, not the entire joined solid.
useOriginal?: boolean = false,
): [Sketch; 1+] {}

View File

@ -365,3 +365,202 @@ export fn hollow(
/// The thickness of the remaining shell
thickness: number(Length),
): Solid {}
/// Repeat a 3-dimensional solid, changing it each time.
///
/// Replicates the 3D solid, applying a transformation function to each replica.
/// Transformation function could alter rotation, scale, visibility, position, etc.
///
/// The `patternTransform` call itself takes a number for how many total instances of
/// the shape should be. For example, if you use a circle with `patternTransform(instances = 4, transform = f)`
/// then there will be 4 circles: the original, and 3 created by replicating the original and
/// calling the transform function on each.
///
/// The transform function takes a single parameter: an integer representing which
/// number replication the transform is for. E.g. the first replica to be transformed
/// will be passed the argument `1`. This simplifies your math: the transform function can
/// rely on id `0` being the original instance passed into the `patternTransform`. See the examples.
///
/// The transform function returns a transform object. All properties of the object are optional,
/// they each default to "no change". So the overall transform object defaults to "no change" too.
/// Its properties are:
///
/// - `translate` (3D point)
///
/// Translates the replica, moving its position in space.
///
/// - `replicate` (bool)
///
/// If false, this ID will not actually copy the object. It'll be skipped.
///
/// - `scale` (3D point)
///
/// Stretches the object, multiplying its width in the given dimension by the point's component in
/// that direction.
///
/// - `rotation` (object, with the following properties)
///
/// - `rotation.axis` (a 3D point, defaults to the Z axis)
///
/// - `rotation.angle` (number of degrees)
///
/// - `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")
///
/// ```kcl
/// // Each instance will be shifted along the X axis.
/// fn transform(@id) {
/// return { translate = [4 * id, 0, 0] }
/// }
///
/// // Sketch 4 cylinders.
/// sketch001 = startSketchOn(XZ)
/// |> circle(center = [0, 0], radius = 2)
/// |> extrude(length = 5)
/// |> patternTransform(instances = 4, transform = transform)
/// ```
///
/// ```kcl
/// // Each instance will be shifted along the X axis,
/// // with a gap between the original (at x = 0) and the first replica
/// // (at x = 8). This is because `id` starts at 1.
/// fn transform(@id) {
/// return { translate = [4 * (1+id), 0, 0] }
/// }
///
/// sketch001 = startSketchOn(XZ)
/// |> circle(center = [0, 0], radius = 2)
/// |> extrude(length = 5)
/// |> patternTransform(instances = 4, transform = transform)
/// ```
///
/// ```kcl
/// fn cube(length, center) {
/// l = length/2
/// x = center[0]
/// y = center[1]
/// p0 = [-l + x, -l + y]
/// p1 = [-l + x, l + y]
/// p2 = [ l + x, l + y]
/// p3 = [ l + x, -l + y]
///
/// return startSketchOn(XY)
/// |> startProfile(at = p0)
/// |> line(endAbsolute = p1)
/// |> line(endAbsolute = p2)
/// |> line(endAbsolute = p3)
/// |> line(endAbsolute = p0)
/// |> close()
/// |> extrude(length = length)
/// }
///
/// width = 20
/// fn transform(@i) {
/// return {
/// // Move down each time.
/// translate = [0, 0, -i * width],
/// // Make the cube longer, wider and flatter each time.
/// scale = [pow(1.1, exp = i), pow(1.1, exp = i), pow(0.9, exp = i)],
/// // Turn by 15 degrees each time.
/// rotation = {
/// angle = 15 * i,
/// origin = "local",
/// }
/// }
/// }
///
/// myCubes =
/// cube(length = width, center = [100,0])
/// |> patternTransform(instances = 25, transform = transform)
/// ```
///
/// ```kcl
/// fn cube(length, center) {
/// l = length/2
/// x = center[0]
/// y = center[1]
/// p0 = [-l + x, -l + y]
/// p1 = [-l + x, l + y]
/// p2 = [ l + x, l + y]
/// p3 = [ l + x, -l + y]
///
/// return startSketchOn(XY)
/// |> startProfile(at = p0)
/// |> line(endAbsolute = p1)
/// |> line(endAbsolute = p2)
/// |> line(endAbsolute = p3)
/// |> line(endAbsolute = p0)
/// |> close()
/// |> extrude(length = length)
/// }
///
/// width = 20
/// fn transform(@i) {
/// return {
/// translate = [0, 0, -i * width],
/// rotation = {
/// angle = 90 * i,
/// // Rotate around the overall scene's origin.
/// origin = "global",
/// }
/// }
/// }
/// myCubes =
/// cube(length = width, center = [100,100])
/// |> patternTransform(instances = 4, transform = transform)
/// ```
///
/// ```kcl
/// // Parameters
/// r = 50 // base radius
/// h = 10 // layer height
/// t = 0.005 // taper factor [0-1)
/// // Defines how to modify each layer of the vase.
/// // Each replica is shifted up the Z axis, and has a smoothly-varying radius
/// fn transform(@replicaId) {
/// scale = r * abs(1 - (t * replicaId)) * (5 + cos((replicaId / 8): number(rad)))
/// return {
/// translate = [0, 0, replicaId * 10],
/// scale = [scale, scale, 0],
/// }
/// }
/// // Each layer is just a pretty thin cylinder.
/// fn layer() {
/// return startSketchOn(XY) // or some other plane idk
/// |> circle(center = [0, 0], radius = 1, tag = $tag1)
/// |> extrude(length = h)
/// }
/// // The vase is 100 layers tall.
/// // The 100 layers are replica of each other, with a slight transformation applied to each.
/// vase = layer() |> patternTransform(instances = 100, transform = transform)
/// ```
///
/// ```kcl
/// fn transform(@i) {
/// // Transform functions can return multiple transforms. They'll be applied in order.
/// return [
/// { translate = [30 * i, 0, 0] },
/// { rotation = { angle = 45 * i } },
/// ]
/// }
/// startSketchOn(XY)
/// |> startProfile(at = [0, 0])
/// |> polygon(
/// radius = 10,
/// numSides = 4,
/// center = [0, 0],
/// inscribed = false,
/// )
/// |> extrude(length = 4)
/// |> patternTransform(instances = 3, transform = transform)
/// ```
@(impl = std_rust)
export fn patternTransform(
/// The solid(s) to duplicate.
@solids: [Solid; 1+],
/// The number of total instances. Must be greater than or equal to 1. This includes the original entity. For example, if instances is 2, there will be two copies -- the original, and one new copy. If instances is 1, this has no effect.
instances: number(Count),
/// How each replica should be transformed. The transform function takes a single parameter: an integer representing which number replication the transform is for. E.g. the first replica to be transformed will be passed the argument `1`. This simplifies your math: the transform function can rely on id `0` being the original instance passed into the `patternTransform`. See the examples.
transform: fn(number(Count)): {},
/// If the target was sketched on an extrusion, setting this will use the original sketch as the target, not the entire joined solid.
useOriginal?: boolean = false,
): [Solid; 1+] {}

View File

@ -296,15 +296,15 @@ flowchart LR
33 --- 92
33 --- 105
37 --- 65
37 x--> 84
37 x--> 80
37 --- 86
37 --- 99
38 --- 66
38 x--> 84
38 x--> 80
38 --- 87
38 --- 100
39 --- 67
39 x--> 84
39 x--> 80
39 --- 88
39 --- 101
46 --- 75
@ -409,9 +409,6 @@ flowchart LR
77 --- 96
77 --- 109
110 <--x 77
86 <--x 80
87 <--x 80
88 <--x 80
92 <--x 82
93 <--x 82
94 <--x 82
@ -419,6 +416,9 @@ flowchart LR
96 <--x 83
97 <--x 83
98 <--x 83
86 <--x 84
87 <--x 84
88 <--x 84
89 <--x 85
90 <--x 85
91 <--x 85

View File

@ -337,6 +337,15 @@ description: Artifact commands error_revolve_on_edge_get_edge.kcl
"opposite": "None"
}
},
{
"cmdId": "[uuid]",
"range": [],
"command": {
"type": "solid3d_get_adjacency_info",
"object_id": "[uuid]",
"edge_id": "[uuid]"
}
},
{
"cmdId": "[uuid]",
"range": [],

View File

@ -32,28 +32,30 @@ flowchart LR
%% [ProgramBodyItem { index: 1 }, VariableDeclarationDeclaration, VariableDeclarationInit, PipeBodyItem { index: 0 }]
15["Sweep Extrusion<br>[169, 189, 0]"]
%% [ProgramBodyItem { index: 0 }, VariableDeclarationDeclaration, VariableDeclarationInit, PipeBodyItem { index: 6 }]
16[Wall]
%% face_code_ref=Missing NodePath
16["Sweep RevolveAboutEdge<br>[367, 406, 0]"]
%% [ProgramBodyItem { index: 1 }, VariableDeclarationDeclaration, VariableDeclarationInit, PipeBodyItem { index: 6 }]
17[Wall]
%% face_code_ref=Missing NodePath
18[Wall]
%% face_code_ref=Missing NodePath
19[Wall]
%% face_code_ref=Missing NodePath
20[Wall]
%% face_code_ref=[ProgramBodyItem { index: 1 }, VariableDeclarationDeclaration, VariableDeclarationInit, PipeBodyItem { index: 0 }]
20["Cap Start"]
21["Cap Start"]
%% face_code_ref=Missing NodePath
21["Cap End"]
22["Cap End"]
%% face_code_ref=Missing NodePath
22["SweepEdge Opposite"]
23["SweepEdge Opposite"]
24["SweepEdge Opposite"]
25["SweepEdge Opposite"]
26["SweepEdge Adjacent"]
26["SweepEdge Opposite"]
27["SweepEdge Adjacent"]
28["SweepEdge Adjacent"]
29["SweepEdge Adjacent"]
30["SweepEdge Adjacent"]
1 --- 3
19 x--> 2
20 x--> 2
3 --- 5
3 --- 6
3 --- 7
@ -65,24 +67,24 @@ flowchart LR
4 --- 11
4 --- 12
4 --- 14
19 --- 4
5 --- 18
5 x--> 20
5 --- 25
5 --- 29
6 --- 16
6 x--> 20
6 --- 24
6 --- 28
7 --- 19
7 x--> 20
7 --- 23
7 --- 27
8 --- 17
8 x--> 20
8 --- 22
8 --- 26
15 --- 16
4 ---- 16
20 --- 4
5 --- 19
5 x--> 21
5 --- 26
5 --- 30
6 --- 17
6 x--> 21
6 --- 25
6 --- 29
7 --- 20
7 x--> 21
7 --- 24
7 --- 28
8 --- 18
8 x--> 21
8 --- 23
8 --- 27
15 --- 17
15 --- 18
15 --- 19
@ -96,20 +98,21 @@ flowchart LR
15 --- 27
15 --- 28
15 --- 29
16 --- 24
16 --- 28
29 <--x 16
17 --- 22
17 --- 26
27 <--x 17
18 --- 25
26 <--x 18
18 --- 29
19 --- 23
19 --- 27
28 <--x 19
22 <--x 21
23 <--x 21
24 <--x 21
25 <--x 21
15 --- 30
17 --- 25
17 --- 29
30 <--x 17
18 --- 23
18 --- 27
28 <--x 18
19 --- 26
27 <--x 19
19 --- 30
20 --- 24
20 --- 28
29 <--x 20
23 <--x 22
24 <--x 22
25 <--x 22
26 <--x 22
```

View File

@ -4,23 +4,11 @@ description: Error from executing error_revolve_on_edge_get_edge.kcl
---
KCL Engine error
× engine: Solid3D revolve failed: sketch profile must lie entirely on one
side of the revolution axis
× engine: Entity found but it was of the wrong type
No such edge exists, cannot retrieve adjacency information.
╭─[15:6]
14 │ |> close()
15 │ |> revolve(axis = revolveAxis, angle = 90)
· ───────────────────┬───────────────────
· ╰── tests/error_revolve_on_edge_get_edge/input.kcl
· ───────────────────┬───────────────────
· ╰── tests/error_revolve_on_edge_get_edge/input.kcl
╰────
╰─▶ KCL Engine error
× engine: Solid3D revolve failed: sketch profile must lie entirely on
│ one side of the revolution axis
╭─[15:6]
14 │ |> close()
15 │ |> revolve(axis = revolveAxis, angle = 90)
· ───────────────────┬───────────────────
· ╰── tests/error_revolve_on_edge_get_edge/
input.kcl
╰────

View File

@ -110,7 +110,6 @@ description: Operations executed error_revolve_on_edge_get_edge.kcl
"sourceRange": []
}
},
"sourceRange": [],
"isError": true
"sourceRange": []
}
]

View File

@ -0,0 +1,5 @@
---
source: kcl-lib/src/simulation_tests.rs
description: Artifact commands export_only_at_top_level.kcl
---
[]

View File

@ -0,0 +1,6 @@
---
source: kcl-lib/src/simulation_tests.rs
description: Artifact graph flowchart export_only_at_top_level.kcl
extension: md
snapshot_kind: binary
---

View File

@ -0,0 +1,3 @@
```mermaid
flowchart LR
```

View File

@ -0,0 +1,148 @@
---
source: kcl-lib/src/simulation_tests.rs
description: Result of parsing export_only_at_top_level.kcl
---
{
"Ok": {
"body": [
{
"commentStart": 0,
"declaration": {
"commentStart": 0,
"end": 0,
"id": {
"commentStart": 0,
"end": 0,
"name": "main",
"start": 0,
"type": "Identifier"
},
"init": {
"body": {
"body": [
{
"commentStart": 0,
"declaration": {
"commentStart": 0,
"end": 0,
"id": {
"commentStart": 0,
"end": 0,
"name": "x",
"start": 0,
"type": "Identifier"
},
"init": {
"commentStart": 0,
"end": 0,
"raw": "2",
"start": 0,
"type": "Literal",
"type": "Literal",
"value": {
"value": 2.0,
"suffix": "None"
}
},
"start": 0,
"type": "VariableDeclarator"
},
"end": 0,
"kind": "const",
"start": 0,
"type": "VariableDeclaration",
"type": "VariableDeclaration",
"visibility": "export"
},
{
"argument": {
"commentStart": 0,
"end": 0,
"raw": "0",
"start": 0,
"type": "Literal",
"type": "Literal",
"value": {
"value": 0.0,
"suffix": "None"
}
},
"commentStart": 0,
"end": 0,
"start": 0,
"type": "ReturnStatement",
"type": "ReturnStatement"
}
],
"commentStart": 0,
"end": 0,
"start": 0
},
"commentStart": 0,
"end": 0,
"params": [],
"start": 0,
"type": "FunctionExpression",
"type": "FunctionExpression"
},
"start": 0,
"type": "VariableDeclarator"
},
"end": 0,
"kind": "fn",
"start": 0,
"type": "VariableDeclaration",
"type": "VariableDeclaration"
},
{
"commentStart": 0,
"end": 0,
"expression": {
"callee": {
"abs_path": false,
"commentStart": 0,
"end": 0,
"name": {
"commentStart": 0,
"end": 0,
"name": "main",
"start": 0,
"type": "Identifier"
},
"path": [],
"start": 0,
"type": "Name"
},
"commentStart": 0,
"end": 0,
"start": 0,
"type": "CallExpressionKw",
"type": "CallExpressionKw",
"unlabeled": null
},
"start": 0,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
}
],
"commentStart": 0,
"end": 0,
"nonCodeMeta": {
"nonCodeNodes": {
"0": [
{
"commentStart": 0,
"end": 0,
"start": 0,
"type": "NonCodeNode",
"value": {
"type": "newLine"
}
}
]
},
"startNodes": []
},
"start": 0
}
}

View File

@ -0,0 +1,15 @@
---
source: kcl-lib/src/simulation_tests.rs
description: Error from executing export_only_at_top_level.kcl
---
KCL Semantic error
× semantic: Exports are only supported at the top-level of a file. Remove
│ `export` or move it to the top-level.
╭─[2:3]
1 │ fn main() {
2 │ export x = 2
· ──────┬─────
· ╰── main
3 │ return 0
╰────

View File

@ -0,0 +1,6 @@
fn main() {
export x = 2
return 0
}
main()

View File

@ -0,0 +1,5 @@
---
source: kcl-lib/src/simulation_tests.rs
description: Operations executed export_only_at_top_level.kcl
---
[]

View File

@ -0,0 +1,10 @@
---
source: kcl-lib/src/simulation_tests.rs
description: Result of unparsing export_only_at_top_level.kcl
---
fn main() {
export x = 2
return 0
}
main()

Binary file not shown.

Before

Width:  |  Height:  |  Size: 99 KiB

After

Width:  |  Height:  |  Size: 99 KiB

View File

@ -0,0 +1,32 @@
---
source: kcl-lib/src/simulation_tests.rs
description: Artifact commands import_only_at_top_level.kcl
---
[
{
"cmdId": "[uuid]",
"range": [],
"command": {
"type": "edge_lines_visible",
"hidden": false
}
},
{
"cmdId": "[uuid]",
"range": [],
"command": {
"type": "object_visible",
"object_id": "[uuid]",
"hidden": true
}
},
{
"cmdId": "[uuid]",
"range": [],
"command": {
"type": "object_visible",
"object_id": "[uuid]",
"hidden": true
}
}
]

View File

@ -0,0 +1,6 @@
---
source: kcl-lib/src/simulation_tests.rs
description: Artifact graph flowchart import_only_at_top_level.kcl
extension: md
snapshot_kind: binary
---

View File

@ -0,0 +1,3 @@
```mermaid
flowchart LR
```

View File

@ -0,0 +1,129 @@
---
source: kcl-lib/src/simulation_tests.rs
description: Result of parsing import_only_at_top_level.kcl
---
{
"Ok": {
"body": [
{
"commentStart": 0,
"declaration": {
"commentStart": 0,
"end": 0,
"id": {
"commentStart": 0,
"end": 0,
"name": "main",
"start": 0,
"type": "Identifier"
},
"init": {
"body": {
"body": [
{
"commentStart": 0,
"end": 0,
"path": {
"type": "Kcl",
"filename": "empty.kcl"
},
"selector": {
"type": "None",
"alias": null
},
"start": 0,
"type": "ImportStatement",
"type": "ImportStatement"
},
{
"argument": {
"commentStart": 0,
"end": 0,
"raw": "0",
"start": 0,
"type": "Literal",
"type": "Literal",
"value": {
"value": 0.0,
"suffix": "None"
}
},
"commentStart": 0,
"end": 0,
"start": 0,
"type": "ReturnStatement",
"type": "ReturnStatement"
}
],
"commentStart": 0,
"end": 0,
"start": 0
},
"commentStart": 0,
"end": 0,
"params": [],
"start": 0,
"type": "FunctionExpression",
"type": "FunctionExpression"
},
"start": 0,
"type": "VariableDeclarator"
},
"end": 0,
"kind": "fn",
"start": 0,
"type": "VariableDeclaration",
"type": "VariableDeclaration"
},
{
"commentStart": 0,
"end": 0,
"expression": {
"callee": {
"abs_path": false,
"commentStart": 0,
"end": 0,
"name": {
"commentStart": 0,
"end": 0,
"name": "main",
"start": 0,
"type": "Identifier"
},
"path": [],
"start": 0,
"type": "Name"
},
"commentStart": 0,
"end": 0,
"start": 0,
"type": "CallExpressionKw",
"type": "CallExpressionKw",
"unlabeled": null
},
"start": 0,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
}
],
"commentStart": 0,
"end": 0,
"nonCodeMeta": {
"nonCodeNodes": {
"0": [
{
"commentStart": 0,
"end": 0,
"start": 0,
"type": "NonCodeNode",
"value": {
"type": "newLine"
}
}
]
},
"startNodes": []
},
"start": 0
}
}

View File

@ -0,0 +1,30 @@
---
source: kcl-lib/src/simulation_tests.rs
description: Error from executing import_only_at_top_level.kcl
---
KCL Semantic error
× semantic: Imports are only supported at the top-level of a file.
╭─[2:3]
1 │ fn main() {
2 │ import "empty.kcl"
· ─────────┬────────
· ╰── tests/import_only_at_top_level/input.kcl
3 │ return 0
╰────
╭─[6:1]
5 │
6 │ main()
· ───┬──
· ╰── tests/import_only_at_top_level/input.kcl
╰────
╰─▶ KCL Semantic error
× semantic: Imports are only supported at the top-level of a file.
╭─[2:3]
1 │ fn main() {
2 │ import "empty.kcl"
· ─────────┬────────
· ╰── tests/import_only_at_top_level/input.kcl
3 │ return 0
╰────

View File

@ -0,0 +1,6 @@
fn main() {
import "empty.kcl"
return 0
}
main()

View File

@ -0,0 +1,32 @@
---
source: kcl-lib/src/simulation_tests.rs
description: Operations executed import_only_at_top_level.kcl
---
[
{
"type": "GroupBegin",
"group": {
"type": "ModuleInstance",
"name": "empty.kcl",
"moduleId": 0
},
"sourceRange": []
},
{
"type": "GroupBegin",
"group": {
"type": "FunctionCall",
"name": "main",
"functionSourceRange": [],
"unlabeledArg": null,
"labeledArgs": {}
},
"sourceRange": []
},
{
"type": "GroupEnd"
},
{
"type": "GroupEnd"
}
]

View File

@ -0,0 +1,10 @@
---
source: kcl-lib/src/simulation_tests.rs
description: Result of unparsing import_only_at_top_level.kcl
---
fn main() {
import "empty.kcl"
return 0
}
main()

View File

@ -0,0 +1,5 @@
---
source: kcl-lib/src/simulation_tests.rs
description: Result of unparsing tests/import_only_at_top_level/empty.kcl
---

View File

@ -661,19 +661,19 @@ flowchart LR
84 --- 144
84 --- 237
86 --- 168
86 x--> 188
86 x--> 189
86 --- 212
86 --- 256
88 --- 169
88 x--> 188
88 x--> 189
88 --- 213
88 --- 257
90 --- 167
90 x--> 188
90 x--> 189
90 --- 214
90 --- 258
92 --- 170
92 x--> 188
92 x--> 189
92 --- 215
92 --- 259
119 --- 133
@ -955,10 +955,10 @@ flowchart LR
218 <--x 186
219 <--x 186
194 <--x 187
212 <--x 189
213 <--x 189
214 <--x 189
215 <--x 189
212 <--x 188
213 <--x 188
214 <--x 188
215 <--x 188
220 <--x 275
223 <--x 270
224 <--x 274

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