Compare commits
38 Commits
v0.62.0
...
franknoiro
Author | SHA1 | Date | |
---|---|---|---|
cac7aa2bee | |||
0753987b5a | |||
815ff7dc2b | |||
46684d420d | |||
eca09984a3 | |||
ce63c6423e | |||
09699afe82 | |||
36c8ad439d | |||
5dc77ceed5 | |||
c7baa26b2d | |||
4d0454abcd | |||
1dafbf105e | |||
773f013115 | |||
c5cd460595 | |||
845352046b | |||
597f1087f9 | |||
511334683a | |||
223a4ad45d | |||
edf31ec1d3 | |||
1539557005 | |||
1d3ba4e3ac | |||
4110aa00db | |||
7eb52cda36 | |||
7872fb9cbd | |||
651181e62c | |||
38a245f2fc | |||
1b4289f93f | |||
d0697c24fd | |||
8c24e29081 | |||
2b9d26e2ff | |||
ab148a7654 | |||
553e650fbe | |||
9690a24c68 | |||
978d5d44a2 | |||
9df476543a | |||
cf303ebe97 | |||
b1d1d89ca5 | |||
3a599d0a0a |
2
.github/ci-cd-scripts/upload-results.sh
vendored
@ -6,6 +6,7 @@ if [ -z "${TAB_API_URL:-}" ] || [ -z "${TAB_API_KEY:-}" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
project="https://github.com/KittyCAD/modeling-app"
|
project="https://github.com/KittyCAD/modeling-app"
|
||||||
|
suite="${CI_SUITE:-unit}"
|
||||||
branch="${GITHUB_HEAD_REF:-${GITHUB_REF_NAME:-}}"
|
branch="${GITHUB_HEAD_REF:-${GITHUB_REF_NAME:-}}"
|
||||||
commit="${CI_COMMIT_SHA:-${GITHUB_SHA:-}}"
|
commit="${CI_COMMIT_SHA:-${GITHUB_SHA:-}}"
|
||||||
|
|
||||||
@ -13,6 +14,7 @@ echo "Uploading batch results"
|
|||||||
curl --silent --request POST \
|
curl --silent --request POST \
|
||||||
--header "X-API-Key: ${TAB_API_KEY}" \
|
--header "X-API-Key: ${TAB_API_KEY}" \
|
||||||
--form "project=${project}" \
|
--form "project=${project}" \
|
||||||
|
--form "suite=${suite}" \
|
||||||
--form "branch=${branch}" \
|
--form "branch=${branch}" \
|
||||||
--form "commit=${commit}" \
|
--form "commit=${commit}" \
|
||||||
--form "tests=@test-results/junit.xml" \
|
--form "tests=@test-results/junit.xml" \
|
||||||
|
1
.github/workflows/cargo-test.yml
vendored
@ -193,6 +193,7 @@ jobs:
|
|||||||
TAB_API_KEY: ${{ secrets.TAB_API_KEY }}
|
TAB_API_KEY: ${{ secrets.TAB_API_KEY }}
|
||||||
CI_COMMIT_SHA: ${{ github.event.pull_request.head.sha }}
|
CI_COMMIT_SHA: ${{ github.event.pull_request.head.sha }}
|
||||||
CI_PR_NUMBER: ${{ github.event.pull_request.number }}
|
CI_PR_NUMBER: ${{ github.event.pull_request.number }}
|
||||||
|
CI_SUITE: unit:kcl
|
||||||
run-internal-kcl-samples:
|
run-internal-kcl-samples:
|
||||||
name: cargo test (internal-kcl-samples)
|
name: cargo test (internal-kcl-samples)
|
||||||
runs-on:
|
runs-on:
|
||||||
|
17
.github/workflows/e2e-tests.yml
vendored
@ -143,7 +143,7 @@ jobs:
|
|||||||
- name: Install browsers
|
- name: Install browsers
|
||||||
run: npm run playwright install --with-deps
|
run: npm run playwright install --with-deps
|
||||||
|
|
||||||
- name: Capture snapshots
|
- name: Test snapshots
|
||||||
uses: nick-fields/retry@v3.0.2
|
uses: nick-fields/retry@v3.0.2
|
||||||
with:
|
with:
|
||||||
shell: bash
|
shell: bash
|
||||||
@ -156,6 +156,19 @@ jobs:
|
|||||||
TAB_API_KEY: ${{ secrets.TAB_API_KEY }}
|
TAB_API_KEY: ${{ secrets.TAB_API_KEY }}
|
||||||
CI_COMMIT_SHA: ${{ github.event.pull_request.head.sha }}
|
CI_COMMIT_SHA: ${{ github.event.pull_request.head.sha }}
|
||||||
CI_PR_NUMBER: ${{ github.event.pull_request.number }}
|
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
|
TARGET: web
|
||||||
|
|
||||||
- uses: actions/upload-artifact@v4
|
- uses: actions/upload-artifact@v4
|
||||||
@ -173,7 +186,7 @@ jobs:
|
|||||||
id: git-check
|
id: git-check
|
||||||
run: |
|
run: |
|
||||||
git add e2e/playwright/snapshot-tests.spec.ts-snapshots e2e/playwright/snapshots
|
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
|
then echo "modified=true" >> $GITHUB_OUTPUT
|
||||||
else echo "modified=false" >> $GITHUB_OUTPUT
|
else echo "modified=false" >> $GITHUB_OUTPUT
|
||||||
fi
|
fi
|
||||||
|
@ -4,7 +4,7 @@ excerpt: "Documentation of the KCL language for the Zoo Design Studio."
|
|||||||
layout: manual
|
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).
|
things in a more tutorial fashion. See also our documentation of the [standard library](/docs/kcl-std).
|
||||||
|
|
||||||
## Topics
|
## Topics
|
||||||
|
@ -27,9 +27,6 @@ import increment from "util.kcl"
|
|||||||
answer = increment(41)
|
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
|
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 if‑else.
|
an `import` statement inside a function or in the body of an if‑else.
|
||||||
|
|
||||||
@ -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"
|
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`
|
## 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
|
entire module. The module is expected to return a single object that can be used
|
||||||
as a variable by the file that imports it.
|
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
|
## Multiple instances of the same import
|
||||||
|
@ -11,7 +11,8 @@ layout: manual
|
|||||||
circle(
|
circle(
|
||||||
@sketch_or_surface: Sketch | Plane | Face,
|
@sketch_or_surface: Sketch | Plane | Face,
|
||||||
center: Point2d,
|
center: Point2d,
|
||||||
radius: number(Length),
|
radius?: number(Length),
|
||||||
|
diameter?: number(Length),
|
||||||
tag?: tag,
|
tag?: tag,
|
||||||
): Sketch
|
): 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 |
|
| `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 |
|
| `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 |
|
| [`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
|
### Returns
|
||||||
@ -51,7 +53,7 @@ exampleSketch = startSketchOn(XZ)
|
|||||||
|> line(end = [0, 30])
|
|> line(end = [0, 30])
|
||||||
|> line(end = [-30, 0])
|
|> line(end = [-30, 0])
|
||||||
|> close()
|
|> close()
|
||||||
|> subtract2d(tool = circle(center = [0, 15], radius = 5))
|
|> subtract2d(tool = circle(center = [0, 15], diameter = 10))
|
||||||
|
|
||||||
example = extrude(exampleSketch, length = 5)
|
example = extrude(exampleSketch, length = 5)
|
||||||
```
|
```
|
||||||
|
@ -1,19 +1,19 @@
|
|||||||
---
|
---
|
||||||
title: "patternTransform2d"
|
title: "patternTransform2d"
|
||||||
subtitle: "Function in std::sketch"
|
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
|
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
|
```kcl
|
||||||
patternTransform2d(
|
patternTransform2d(
|
||||||
@sketches: [Sketch],
|
@sketches: [Sketch; 1+],
|
||||||
instances: number,
|
instances: number(_),
|
||||||
transform: FunctionSource,
|
transform: fn(number(_)): { },
|
||||||
useOriginal?: bool,
|
useOriginal?: boolean,
|
||||||
): [Sketch]
|
): [Sketch; 1+]
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
@ -22,14 +22,14 @@ patternTransform2d(
|
|||||||
|
|
||||||
| Name | Type | Description | Required |
|
| Name | Type | Description | Required |
|
||||||
|----------|------|-------------|----------|
|
|----------|------|-------------|----------|
|
||||||
| `sketches` | [`[Sketch]`](/docs/kcl-std/types/std-types-Sketch) | The sketch(es) to duplicate | Yes |
|
| `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 |
|
| `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 |
|
| `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` | [`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 |
|
| `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
|
### Returns
|
||||||
|
|
||||||
[`[Sketch]`](/docs/kcl-std/types/std-types-Sketch)
|
[`[Sketch; 1+]`](/docs/kcl-std/types/std-types-Sketch)
|
||||||
|
|
||||||
|
|
||||||
### Examples
|
### Examples
|
@ -65,7 +65,7 @@ layout: manual
|
|||||||
* [`line`](/docs/kcl-std/line)
|
* [`line`](/docs/kcl-std/line)
|
||||||
* [`loft`](/docs/kcl-std/loft)
|
* [`loft`](/docs/kcl-std/loft)
|
||||||
* [`patternCircular2d`](/docs/kcl-std/patternCircular2d)
|
* [`patternCircular2d`](/docs/kcl-std/patternCircular2d)
|
||||||
* [`patternTransform2d`](/docs/kcl-std/patternTransform2d)
|
* [`patternTransform2d`](/docs/kcl-std/functions/std-sketch-patternTransform2d)
|
||||||
* [`polygon`](/docs/kcl-std/polygon)
|
* [`polygon`](/docs/kcl-std/polygon)
|
||||||
* [`profileStart`](/docs/kcl-std/profileStart)
|
* [`profileStart`](/docs/kcl-std/profileStart)
|
||||||
* [`profileStartX`](/docs/kcl-std/profileStartX)
|
* [`profileStartX`](/docs/kcl-std/profileStartX)
|
||||||
@ -94,7 +94,7 @@ layout: manual
|
|||||||
* [`intersect`](/docs/kcl-std/intersect)
|
* [`intersect`](/docs/kcl-std/intersect)
|
||||||
* [`patternCircular3d`](/docs/kcl-std/patternCircular3d)
|
* [`patternCircular3d`](/docs/kcl-std/patternCircular3d)
|
||||||
* [`patternLinear3d`](/docs/kcl-std/patternLinear3d)
|
* [`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)
|
* [`shell`](/docs/kcl-std/functions/std-solid-shell)
|
||||||
* [`subtract`](/docs/kcl-std/subtract)
|
* [`subtract`](/docs/kcl-std/subtract)
|
||||||
* [`union`](/docs/kcl-std/union)
|
* [`union`](/docs/kcl-std/union)
|
||||||
|
@ -30,7 +30,7 @@ This module contains functions for creating and manipulating sketches, and makin
|
|||||||
* [`line`](/docs/kcl-std/line)
|
* [`line`](/docs/kcl-std/line)
|
||||||
* [`loft`](/docs/kcl-std/loft)
|
* [`loft`](/docs/kcl-std/loft)
|
||||||
* [`patternCircular2d`](/docs/kcl-std/patternCircular2d)
|
* [`patternCircular2d`](/docs/kcl-std/patternCircular2d)
|
||||||
* [`patternTransform2d`](/docs/kcl-std/patternTransform2d)
|
* [`patternTransform2d`](/docs/kcl-std/functions/std-sketch-patternTransform2d)
|
||||||
* [`polygon`](/docs/kcl-std/polygon)
|
* [`polygon`](/docs/kcl-std/polygon)
|
||||||
* [`profileStart`](/docs/kcl-std/profileStart)
|
* [`profileStart`](/docs/kcl-std/profileStart)
|
||||||
* [`profileStartX`](/docs/kcl-std/profileStartX)
|
* [`profileStartX`](/docs/kcl-std/profileStartX)
|
||||||
|
@ -18,7 +18,7 @@ This module contains functions for modifying solids, e.g., by adding a fillet or
|
|||||||
* [`intersect`](/docs/kcl-std/intersect)
|
* [`intersect`](/docs/kcl-std/intersect)
|
||||||
* [`patternCircular3d`](/docs/kcl-std/patternCircular3d)
|
* [`patternCircular3d`](/docs/kcl-std/patternCircular3d)
|
||||||
* [`patternLinear3d`](/docs/kcl-std/patternLinear3d)
|
* [`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)
|
* [`shell`](/docs/kcl-std/functions/std-solid-shell)
|
||||||
* [`subtract`](/docs/kcl-std/subtract)
|
* [`subtract`](/docs/kcl-std/subtract)
|
||||||
* [`union`](/docs/kcl-std/union)
|
* [`union`](/docs/kcl-std/union)
|
||||||
|
@ -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.
|
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
|
## Modules
|
||||||
|
|
||||||
|
16124
docs/kcl-std/std.json
@ -45,15 +45,16 @@ test.describe('Command bar tests', () => {
|
|||||||
await cmdBar.expectState({
|
await cmdBar.expectState({
|
||||||
stage: 'arguments',
|
stage: 'arguments',
|
||||||
commandName: 'Extrude',
|
commandName: 'Extrude',
|
||||||
currentArgKey: 'length',
|
currentArgKey: 'sketches',
|
||||||
currentArgValue: '5',
|
currentArgValue: '',
|
||||||
headerArguments: {
|
headerArguments: {
|
||||||
Profiles: '1 profile',
|
Profiles: '',
|
||||||
Length: '',
|
Length: '',
|
||||||
},
|
},
|
||||||
highlightedHeaderArg: 'length',
|
highlightedHeaderArg: 'Profiles',
|
||||||
})
|
})
|
||||||
await cmdBar.progressCmdBar()
|
await cmdBar.progressCmdBar()
|
||||||
|
await cmdBar.progressCmdBar()
|
||||||
await cmdBar.expectState({
|
await cmdBar.expectState({
|
||||||
stage: 'review',
|
stage: 'review',
|
||||||
commandName: 'Extrude',
|
commandName: 'Extrude',
|
||||||
@ -684,4 +685,33 @@ c = 3 + a`
|
|||||||
highlightedHeaderArg: 'value',
|
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',
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
@ -1134,6 +1134,7 @@ sketch001 = startSketchOn(XZ)
|
|||||||
// Wait for the selection to register (TODO: we need a definitive way to wait for this)
|
// Wait for the selection to register (TODO: we need a definitive way to wait for this)
|
||||||
await page.waitForTimeout(200)
|
await page.waitForTimeout(200)
|
||||||
await toolbar.extrudeButton.click()
|
await toolbar.extrudeButton.click()
|
||||||
|
await cmdBar.progressCmdBar()
|
||||||
await cmdBar.expectState({
|
await cmdBar.expectState({
|
||||||
stage: 'arguments',
|
stage: 'arguments',
|
||||||
currentArgKey: 'length',
|
currentArgKey: 'length',
|
||||||
@ -1355,9 +1356,7 @@ sketch001 = startSketchOn(XZ)
|
|||||||
const u = await getUtils(page)
|
const u = await getUtils(page)
|
||||||
const projectLink = page.getByRole('link', { name: 'cube' })
|
const projectLink = page.getByRole('link', { name: 'cube' })
|
||||||
const gizmo = page.locator('[aria-label*=gizmo]')
|
const gizmo = page.locator('[aria-label*=gizmo]')
|
||||||
const resetCameraButton = page.getByRole('button', {
|
const resetCameraButton = page.getByRole('button', { name: 'Reset view' })
|
||||||
name: 'Reset view',
|
|
||||||
})
|
|
||||||
const locationToHaveColor = async (
|
const locationToHaveColor = async (
|
||||||
position: { x: number; y: number },
|
position: { x: number; y: number },
|
||||||
color: [number, number, number]
|
color: [number, number, number]
|
||||||
|
@ -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(
|
test(
|
||||||
'deleting all files recreates a default main.kcl with no code',
|
'deleting all files recreates a default main.kcl with no code',
|
||||||
{ tag: '@electron' },
|
{ tag: '@electron' },
|
||||||
|
@ -105,14 +105,19 @@ export class CmdBarFixture {
|
|||||||
expectState = async (expected: CmdBarSerialised) => {
|
expectState = async (expected: CmdBarSerialised) => {
|
||||||
return expect.poll(() => this._serialiseCmdBar()).toEqual(expected)
|
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
|
* 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,
|
* * TODO: This method assumes the user has a valid input to the current stage,
|
||||||
* and assumes we are past the `pickCommand` step.
|
* and assumes we are past the `pickCommand` step.
|
||||||
*/
|
*/
|
||||||
progressCmdBar = async (shouldFuzzProgressMethod = true) => {
|
progressCmdBar = async (shouldUseKeyboard = false) => {
|
||||||
await this.page.waitForTimeout(2000)
|
await this.page.waitForTimeout(2000)
|
||||||
|
if (shouldUseKeyboard) {
|
||||||
|
await this.page.keyboard.press('Enter')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const arrowButton = this.page.getByRole('button', {
|
const arrowButton = this.page.getByRole('button', {
|
||||||
name: 'arrow right Continue',
|
name: 'arrow right Continue',
|
||||||
})
|
})
|
||||||
@ -308,6 +313,11 @@ export class CmdBarFixture {
|
|||||||
await expect(this.cmdBarElement).toBeVisible({ timeout: 10_000 })
|
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) {
|
async expectArgValue(value: string) {
|
||||||
// Check the placeholder project name exists
|
// Check the placeholder project name exists
|
||||||
const actualArgument = await this.cmdBarElement
|
const actualArgument = await this.cmdBarElement
|
||||||
|
@ -26,6 +26,7 @@ export class HomePageFixture {
|
|||||||
sortByNameBtn!: Locator
|
sortByNameBtn!: Locator
|
||||||
appHeader!: Locator
|
appHeader!: Locator
|
||||||
tutorialBtn!: Locator
|
tutorialBtn!: Locator
|
||||||
|
textToCadBtn!: Locator
|
||||||
|
|
||||||
constructor(page: Page) {
|
constructor(page: Page) {
|
||||||
this.page = page
|
this.page = page
|
||||||
@ -47,6 +48,7 @@ export class HomePageFixture {
|
|||||||
this.sortByNameBtn = this.page.getByTestId('home-sort-by-name')
|
this.sortByNameBtn = this.page.getByTestId('home-sort-by-name')
|
||||||
this.appHeader = this.page.getByTestId('app-header')
|
this.appHeader = this.page.getByTestId('app-header')
|
||||||
this.tutorialBtn = this.page.getByTestId('home-tutorial-button')
|
this.tutorialBtn = this.page.getByTestId('home-tutorial-button')
|
||||||
|
this.textToCadBtn = this.page.getByTestId('home-text-to-cad')
|
||||||
}
|
}
|
||||||
|
|
||||||
private _serialiseSortBy = async (): Promise<
|
private _serialiseSortBy = async (): Promise<
|
||||||
|
@ -61,6 +61,7 @@ class MyAPIReporter implements Reporter {
|
|||||||
const payload = {
|
const payload = {
|
||||||
// Required information
|
// Required information
|
||||||
project: 'https://github.com/KittyCAD/modeling-app',
|
project: 'https://github.com/KittyCAD/modeling-app',
|
||||||
|
suite: process.env.CI_SUITE || 'e2e',
|
||||||
branch: process.env.GITHUB_HEAD_REF || process.env.GITHUB_REF_NAME || '',
|
branch: process.env.GITHUB_HEAD_REF || process.env.GITHUB_REF_NAME || '',
|
||||||
commit: process.env.CI_COMMIT_SHA || process.env.GITHUB_SHA || '',
|
commit: process.env.CI_COMMIT_SHA || process.env.GITHUB_SHA || '',
|
||||||
test: test.titlePath().slice(2).join(' › '),
|
test: test.titlePath().slice(2).join(' › '),
|
||||||
|
@ -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 test.step('do extrude flow and check extrude code is added to editor', async () => {
|
||||||
await toolbar.extrudeButton.click()
|
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({
|
await cmdBar.expectState({
|
||||||
stage: 'arguments',
|
stage: 'arguments',
|
||||||
currentArgKey: 'length',
|
currentArgKey: 'length',
|
||||||
@ -1645,6 +1654,15 @@ sketch002 = startSketchOn(plane001)
|
|||||||
|
|
||||||
await test.step(`Go through the command bar flow with preselected sketches`, async () => {
|
await test.step(`Go through the command bar flow with preselected sketches`, async () => {
|
||||||
await toolbar.loftButton.click()
|
await toolbar.loftButton.click()
|
||||||
|
await cmdBar.expectState({
|
||||||
|
stage: 'arguments',
|
||||||
|
currentArgKey: 'sketches',
|
||||||
|
currentArgValue: '',
|
||||||
|
headerArguments: { Profiles: '' },
|
||||||
|
highlightedHeaderArg: 'Profiles',
|
||||||
|
commandName: 'Loft',
|
||||||
|
})
|
||||||
|
await cmdBar.progressCmdBar()
|
||||||
await cmdBar.expectState({
|
await cmdBar.expectState({
|
||||||
stage: 'review',
|
stage: 'review',
|
||||||
headerArguments: { Profiles: '2 profiles' },
|
headerArguments: { Profiles: '2 profiles' },
|
||||||
@ -1855,7 +1873,11 @@ sketch002 = startSketchOn(XZ)
|
|||||||
},
|
},
|
||||||
stage: 'review',
|
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 () => {
|
await test.step(`Confirm code is added to the editor, scene has changed`, async () => {
|
||||||
@ -1995,7 +2017,7 @@ profile001 = ${circleCode}`
|
|||||||
},
|
},
|
||||||
stage: 'review',
|
stage: 'review',
|
||||||
})
|
})
|
||||||
await cmdBar.progressCmdBar()
|
await cmdBar.progressCmdBar(true)
|
||||||
await editor.expectEditor.toContain(sweepDeclaration)
|
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 test.step(`Apply fillet to the preselected edge`, async () => {
|
||||||
await page.waitForTimeout(100)
|
await page.waitForTimeout(100)
|
||||||
await toolbar.filletButton.click()
|
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({
|
await cmdBar.expectState({
|
||||||
commandName: 'Fillet',
|
commandName: 'Fillet',
|
||||||
highlightedHeaderArg: 'radius',
|
highlightedHeaderArg: 'radius',
|
||||||
@ -2617,6 +2651,18 @@ extrude001 = extrude(profile001, length = 5)
|
|||||||
await test.step(`Apply fillet`, async () => {
|
await test.step(`Apply fillet`, async () => {
|
||||||
await page.waitForTimeout(100)
|
await page.waitForTimeout(100)
|
||||||
await toolbar.filletButton.click()
|
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({
|
await cmdBar.expectState({
|
||||||
commandName: 'Fillet',
|
commandName: 'Fillet',
|
||||||
highlightedHeaderArg: 'radius',
|
highlightedHeaderArg: 'radius',
|
||||||
@ -2722,6 +2768,19 @@ extrude001 = extrude(sketch001, length = -12)
|
|||||||
await test.step(`Apply chamfer to the preselected edge`, async () => {
|
await test.step(`Apply chamfer to the preselected edge`, async () => {
|
||||||
await page.waitForTimeout(100)
|
await page.waitForTimeout(100)
|
||||||
await toolbar.chamferButton.click()
|
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({
|
await cmdBar.expectState({
|
||||||
commandName: 'Chamfer',
|
commandName: 'Chamfer',
|
||||||
highlightedHeaderArg: 'length',
|
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 test.step(`Go through the command bar flow with a preselected face (cap)`, async () => {
|
||||||
await toolbar.shellButton.click()
|
await toolbar.shellButton.click()
|
||||||
await cmdBar.progressCmdBar()
|
await cmdBar.progressCmdBar()
|
||||||
|
await page.waitForTimeout(500)
|
||||||
|
await cmdBar.progressCmdBar()
|
||||||
await cmdBar.expectState({
|
await cmdBar.expectState({
|
||||||
stage: 'review',
|
stage: 'review',
|
||||||
headerArguments: {
|
headerArguments: {
|
||||||
@ -3638,13 +3699,12 @@ tag=$rectangleSegmentC002,
|
|||||||
// revolve
|
// revolve
|
||||||
await editor.scrollToText(codeToSelection)
|
await editor.scrollToText(codeToSelection)
|
||||||
await page.getByText(codeToSelection).click()
|
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 toolbar.revolveButton.click()
|
||||||
await cmdBar.progressCmdBar()
|
await cmdBar.progressCmdBar()
|
||||||
await cmdBar.progressCmdBar()
|
await cmdBar.progressCmdBar()
|
||||||
await cmdBar.progressCmdBar()
|
await cmdBar.progressCmdBar()
|
||||||
await cmdBar.progressCmdBar()
|
await cmdBar.progressCmdBar()
|
||||||
|
await cmdBar.progressCmdBar()
|
||||||
|
|
||||||
const newCodeToFind = `revolve001 = revolve(sketch002, angle = 360, axis = X)`
|
const newCodeToFind = `revolve001 = revolve(sketch002, angle = 360, axis = X)`
|
||||||
expect(editor.expectEditor.toContain(newCodeToFind)).toBeTruthy()
|
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 test.step('Go through command bar flow', async () => {
|
||||||
await toolbar.extrudeButton.click()
|
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({
|
await cmdBar.expectState({
|
||||||
stage: 'arguments',
|
stage: 'arguments',
|
||||||
currentArgKey: 'length',
|
currentArgKey: 'length',
|
||||||
@ -4655,6 +4727,19 @@ path001 = startProfile(sketch001, at = [0, 0])
|
|||||||
|
|
||||||
await test.step('Go through command bar flow', async () => {
|
await test.step('Go through command bar flow', async () => {
|
||||||
await toolbar.sweepButton.click()
|
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({
|
await cmdBar.expectState({
|
||||||
stage: 'arguments',
|
stage: 'arguments',
|
||||||
currentArgKey: 'path',
|
currentArgKey: 'path',
|
||||||
@ -4739,6 +4824,19 @@ path001 = startProfile(sketch001, at = [0, 0])
|
|||||||
await test.step('Go through command bar flow', async () => {
|
await test.step('Go through command bar flow', async () => {
|
||||||
await toolbar.closePane('code')
|
await toolbar.closePane('code')
|
||||||
await toolbar.revolveButton.click()
|
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({
|
await cmdBar.expectState({
|
||||||
stage: 'arguments',
|
stage: 'arguments',
|
||||||
currentArgKey: 'axisOrEdge',
|
currentArgKey: 'axisOrEdge',
|
||||||
|
@ -11,6 +11,7 @@ import {
|
|||||||
getPlaywrightDownloadDir,
|
getPlaywrightDownloadDir,
|
||||||
getUtils,
|
getUtils,
|
||||||
isOutOfViewInScrollContainer,
|
isOutOfViewInScrollContainer,
|
||||||
|
runningOnWindows,
|
||||||
} from '@e2e/playwright/test-utils'
|
} from '@e2e/playwright/test-utils'
|
||||||
import { expect, test } from '@e2e/playwright/zoo-test'
|
import { expect, test } from '@e2e/playwright/zoo-test'
|
||||||
|
|
||||||
@ -1979,7 +1980,6 @@ test(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
// Flaky
|
|
||||||
test(
|
test(
|
||||||
'Original project name persist after onboarding',
|
'Original project name persist after onboarding',
|
||||||
{ tag: '@electron' },
|
{ 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)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
)
|
||||||
|
@ -1016,6 +1016,7 @@ profile001 = startProfile(sketch001, at = [${roundOff(scale * 69.6)}, ${roundOff
|
|||||||
|
|
||||||
// sketch selection should already have been made.
|
// sketch selection should already have been made.
|
||||||
// otherwise the cmdbar would be waiting for a selection.
|
// otherwise the cmdbar would be waiting for a selection.
|
||||||
|
await cmdBar.progressCmdBar()
|
||||||
await cmdBar.expectState({
|
await cmdBar.expectState({
|
||||||
stage: 'arguments',
|
stage: 'arguments',
|
||||||
currentArgKey: 'length',
|
currentArgKey: 'length',
|
||||||
|
Before Width: | Height: | Size: 133 KiB After Width: | Height: | Size: 133 KiB |
@ -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) => {
|
cloneFile: async (name: string) => {
|
||||||
return test?.step(`Cloning file '${name}'`, async () => {
|
return test?.step(`Cloning file '${name}'`, async () => {
|
||||||
await page
|
await page
|
||||||
|
@ -103,6 +103,8 @@ test.describe('Testing loading external models', () => {
|
|||||||
file: 'ball-bearing' + FILE_EXT,
|
file: 'ball-bearing' + FILE_EXT,
|
||||||
title: 'Ball Bearing',
|
title: 'Ball Bearing',
|
||||||
file1: 'ball-bearing-1' + FILE_EXT,
|
file1: 'ball-bearing-1' + FILE_EXT,
|
||||||
|
folderName: 'ball-bearing',
|
||||||
|
folderName1: 'ball-bearing-1',
|
||||||
}
|
}
|
||||||
const projectCard = page.getByRole('link', { name: 'bracket' })
|
const projectCard = page.getByRole('link', { name: 'bracket' })
|
||||||
const overwriteWarning = page.getByText(
|
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 test.step(`Ensure we made and opened a new file`, async () => {
|
||||||
await editor.expectEditor.toContain('// ' + sampleOne.title)
|
await editor.expectEditor.toContain('// ' + sampleOne.title)
|
||||||
await expect(newlyCreatedFile(sampleOne.file)).toBeVisible()
|
await expect(
|
||||||
await expect(projectMenuButton).toContainText(sampleOne.file)
|
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 () => {
|
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 test.step(`Ensure we made and opened a new file with a unique name`, async () => {
|
||||||
await editor.expectEditor.toContain('// ' + sampleOne.title)
|
await editor.expectEditor.toContain('// ' + sampleOne.title)
|
||||||
await expect(newlyCreatedFile(sampleOne.file1)).toBeVisible()
|
await expect(
|
||||||
await expect(projectMenuButton).toContainText(sampleOne.file1)
|
page.getByTestId('file-tree-item').getByText(sampleOne.folderName1)
|
||||||
|
).toBeVisible()
|
||||||
|
await expect(projectMenuButton).toContainText('main.kcl')
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -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')).toBeVisible()
|
||||||
await expect(page.getByTestId('app-header-file-name')).toContainText(
|
await expect(page.getByTestId('app-header-file-name')).toContainText(
|
||||||
'2x2x2-cube.kcl'
|
'main.kcl'
|
||||||
)
|
)
|
||||||
|
|
||||||
await u.openFilePanel()
|
await u.openFilePanel()
|
||||||
await expect(
|
await expect(
|
||||||
page.getByTestId('file-tree-item').getByText('2x2x2-cube.kcl')
|
page.getByTestId('file-tree-item').getByText('2x2x2-cube')
|
||||||
).toBeVisible()
|
).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')).toBeVisible()
|
||||||
await expect(page.getByTestId('app-header-file-name')).toContainText(
|
await expect(page.getByTestId('app-header-file-name')).toContainText(
|
||||||
'2x2x2-cube.kcl'
|
'main.kcl'
|
||||||
)
|
)
|
||||||
|
|
||||||
// Check file is created
|
// Check file is created
|
||||||
await u.openFilePanel()
|
await u.openFilePanel()
|
||||||
await expect(
|
await expect(
|
||||||
page.getByTestId('file-tree-item').getByText('2x2x2-cube.kcl')
|
page.getByTestId('file-tree-item').getByText('2x2x2-cube')
|
||||||
).toBeVisible()
|
).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')).toBeVisible()
|
||||||
await expect(page.getByTestId('app-header-file-name')).toContainText(
|
await expect(page.getByTestId('app-header-file-name')).toContainText(
|
||||||
'2x2x2-cube.kcl'
|
'main.kcl'
|
||||||
)
|
)
|
||||||
|
|
||||||
// Check file is created
|
// Check file is created
|
||||||
await u.openFilePanel()
|
await u.openFilePanel()
|
||||||
await expect(
|
await expect(
|
||||||
page.getByTestId('file-tree-item').getByText('2x2x2-cube.kcl')
|
page.getByTestId('file-tree-item').getByText('2x2x2-cube')
|
||||||
).toBeVisible()
|
).toBeVisible()
|
||||||
await expect(
|
await expect(
|
||||||
page.getByTestId('file-tree-item').getByText('main.kcl')
|
page.getByTestId('file-tree-item').getByText('main.kcl')
|
||||||
|
@ -573,6 +573,7 @@ profile001 = startProfile(sketch002, at = [-12.34, 12.34])
|
|||||||
await expect(page.getByTestId('command-bar')).toBeVisible()
|
await expect(page.getByTestId('command-bar')).toBeVisible()
|
||||||
await page.waitForTimeout(100)
|
await page.waitForTimeout(100)
|
||||||
|
|
||||||
|
await cmdBar.progressCmdBar()
|
||||||
await cmdBar.progressCmdBar()
|
await cmdBar.progressCmdBar()
|
||||||
await expect(page.getByText('Confirm Extrude')).toBeVisible()
|
await expect(page.getByText('Confirm Extrude')).toBeVisible()
|
||||||
await cmdBar.progressCmdBar()
|
await cmdBar.progressCmdBar()
|
||||||
|
@ -37,6 +37,8 @@ When you submit a PR to add or modify KCL samples, images will be generated and
|
|||||||
[](bottle/main.kcl)
|
[](bottle/main.kcl)
|
||||||
#### [bracket](bracket/main.kcl) ([screenshot](screenshots/bracket.png))
|
#### [bracket](bracket/main.kcl) ([screenshot](screenshots/bracket.png))
|
||||||
[](bracket/main.kcl)
|
[](bracket/main.kcl)
|
||||||
|
#### [brake-rotor](brake-rotor/main.kcl) ([screenshot](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](car-wheel-assembly/main.kcl) ([screenshot](screenshots/car-wheel-assembly.png))
|
||||||
[](car-wheel-assembly/main.kcl)
|
[](car-wheel-assembly/main.kcl)
|
||||||
#### [cold-plate](cold-plate/main.kcl) ([screenshot](screenshots/cold-plate.png))
|
#### [cold-plate](cold-plate/main.kcl) ([screenshot](screenshots/cold-plate.png))
|
||||||
|
179
public/kcl-samples/brake-rotor/main.kcl
Normal 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))
|
@ -74,6 +74,16 @@
|
|||||||
"main.kcl"
|
"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",
|
"file": "main.kcl",
|
||||||
"pathFromProjectDirectoryToFirstFile": "car-wheel-assembly/main.kcl",
|
"pathFromProjectDirectoryToFirstFile": "car-wheel-assembly/main.kcl",
|
||||||
|
@ -72,25 +72,25 @@ leftSpacerShape = boxModuleFn(width = leftSpacerWidth)
|
|||||||
|
|
||||||
// Module for power switch including front plate and red rocker button
|
// Module for power switch including front plate and red rocker button
|
||||||
switchPosition = leftSpacerPosition + leftSpacerWidth / 2 + moduleWidth / 2
|
switchPosition = leftSpacerPosition + leftSpacerWidth / 2 + moduleWidth / 2
|
||||||
swtichWidth = moduleWidth
|
switchWidth = moduleWidth
|
||||||
|
|
||||||
// Switch Body
|
// Switch Body
|
||||||
switchBody = boxModuleFn(width = moduleWidth)
|
switchBody = boxModuleFn(width = moduleWidth)
|
||||||
|
|
||||||
// Switch Plate
|
// Switch Plate
|
||||||
swtichPlateWidth = 20
|
switchPlateWidth = 20
|
||||||
switchPlateHeight = 30
|
switchPlateHeight = 30
|
||||||
switchPlateThickness = 3
|
switchPlateThickness = 3
|
||||||
switchPlateShape = startSketchOn(switchBody, face = END)
|
switchPlateShape = startSketchOn(switchBody, face = END)
|
||||||
|> startProfile(
|
|> startProfile(
|
||||||
%,
|
%,
|
||||||
at = [
|
at = [
|
||||||
-swtichPlateWidth / 2,
|
-switchPlateWidth / 2,
|
||||||
-switchPlateHeight / 2
|
-switchPlateHeight / 2
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|> yLine(length = switchPlateHeight)
|
|> yLine(length = switchPlateHeight)
|
||||||
|> xLine(length = swtichPlateWidth)
|
|> xLine(length = switchPlateWidth)
|
||||||
|> yLine(length = -switchPlateHeight)
|
|> yLine(length = -switchPlateHeight)
|
||||||
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||||
|> close()
|
|> close()
|
||||||
@ -104,8 +104,8 @@ switchPlateBody = extrude(switchPlateShape, length = switchPlateThickness)
|
|||||||
|
|
||||||
// Switch Button
|
// Switch Button
|
||||||
switchButtonHeight = 26
|
switchButtonHeight = 26
|
||||||
swtichButtonWidth = 15
|
switchButtonWidth = 15
|
||||||
switchButtonShape = startSketchOn(offsetPlane(-YZ, offset = -swtichButtonWidth / 2))
|
switchButtonShape = startSketchOn(offsetPlane(-YZ, offset = -switchButtonWidth / 2))
|
||||||
|> startProfile(
|
|> startProfile(
|
||||||
%,
|
%,
|
||||||
at = [
|
at = [
|
||||||
@ -121,7 +121,7 @@ switchButtonShape = startSketchOn(offsetPlane(-YZ, offset = -swtichButtonWidth /
|
|||||||
])
|
])
|
||||||
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||||
|> close()
|
|> close()
|
||||||
switchButtonBody = extrude(switchButtonShape, length = swtichButtonWidth)
|
switchButtonBody = extrude(switchButtonShape, length = switchButtonWidth)
|
||||||
|> translate(
|
|> translate(
|
||||||
%,
|
%,
|
||||||
x = switchPosition,
|
x = switchPosition,
|
||||||
@ -132,7 +132,7 @@ switchButtonBody = extrude(switchButtonShape, length = swtichButtonWidth)
|
|||||||
|
|
||||||
// Spacer between switch and plug modules for layout alignment
|
// Spacer between switch and plug modules for layout alignment
|
||||||
secondSpacerWidth = moduleWidth / 2
|
secondSpacerWidth = moduleWidth / 2
|
||||||
secondSpacerPosition = switchPosition + swtichWidth / 2 + secondSpacerWidth / 2
|
secondSpacerPosition = switchPosition + switchWidth / 2 + secondSpacerWidth / 2
|
||||||
secondSpacerBody = boxModuleFn(width = secondSpacerWidth)
|
secondSpacerBody = boxModuleFn(width = secondSpacerWidth)
|
||||||
|> translate(
|
|> translate(
|
||||||
%,
|
%,
|
||||||
|
@ -33,14 +33,9 @@ stemLoftProfile2 = startSketchOn(offsetPlane(XY, offset = 75))
|
|||||||
// Draw the third profile for the lofted femur
|
// Draw the third profile for the lofted femur
|
||||||
p3Z = 110
|
p3Z = 110
|
||||||
p3A = 25
|
p3A = 25
|
||||||
plane003 = {
|
|
||||||
origin = [0, 0.0, p3Z],
|
|
||||||
xAxis = [cos(p3A), 0, sin(p3A)],
|
|
||||||
yAxis = [0.0, 1.0, 0.0]
|
|
||||||
}
|
|
||||||
l3 = 32
|
l3 = 32
|
||||||
r3 = 4
|
r3 = 4
|
||||||
stemLoftProfile3 = startSketchOn(plane003)
|
stemLoftProfile3 = startSketchOn(XY)
|
||||||
|> startProfile(at = [-15.5, -l3 / 2])
|
|> startProfile(at = [-15.5, -l3 / 2])
|
||||||
|> yLine(length = l3, tag = $seg03)
|
|> yLine(length = l3, tag = $seg03)
|
||||||
|> tangentialArc(angle = -120, radius = r3)
|
|> tangentialArc(angle = -120, radius = r3)
|
||||||
@ -49,18 +44,14 @@ stemLoftProfile3 = startSketchOn(plane003)
|
|||||||
|> angledLine(angle = 30, length = -segLen(seg03))
|
|> angledLine(angle = 30, length = -segLen(seg03))
|
||||||
|> tangentialArc(endAbsolute = [profileStartX(%), profileStartY(%)])
|
|> tangentialArc(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||||
|> close()
|
|> close()
|
||||||
|
|> translate(z = p3Z)
|
||||||
|
|> rotate(pitch = -p3A)
|
||||||
// Draw the fourth profile for the lofted femur
|
// Draw the fourth profile for the lofted femur
|
||||||
p4Z = 130
|
p4Z = 130
|
||||||
p4A = 36.5
|
p4A = 36.5
|
||||||
plane004 = {
|
|
||||||
origin = [0, 0.0, p4Z],
|
|
||||||
xAxis = [cos(p4A), 0, sin(p4A)],
|
|
||||||
yAxis = [0.0, 1.0, 0.0]
|
|
||||||
}
|
|
||||||
l4 = 16
|
l4 = 16
|
||||||
r4 = 5
|
r4 = 5
|
||||||
stemLoftProfile4 = startSketchOn(plane004)
|
stemLoftProfile4 = startSketchOn(XY)
|
||||||
|> startProfile(at = [-23, -l4 / 2])
|
|> startProfile(at = [-23, -l4 / 2])
|
||||||
|> yLine(length = l4, tag = $seg04)
|
|> yLine(length = l4, tag = $seg04)
|
||||||
|> tangentialArc(angle = -120, radius = r4)
|
|> tangentialArc(angle = -120, radius = r4)
|
||||||
@ -69,18 +60,14 @@ stemLoftProfile4 = startSketchOn(plane004)
|
|||||||
|> angledLine(angle = 30, length = -segLen(seg04))
|
|> angledLine(angle = 30, length = -segLen(seg04))
|
||||||
|> tangentialArc(endAbsolute = [profileStartX(%), profileStartY(%)])
|
|> tangentialArc(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||||
|> close()
|
|> close()
|
||||||
|
|> translate(z = p4Z)
|
||||||
|
|> rotate(pitch = -p4A)
|
||||||
// Draw the first profile for the femoral stem
|
// Draw the first profile for the femoral stem
|
||||||
p5Z = 140
|
p5Z = 140
|
||||||
p5A = 36.5
|
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
|
l5 = 1.6
|
||||||
r5 = 1.6
|
r5 = 1.6
|
||||||
stemLoftProfile5 = startSketchOn(plane005)
|
stemLoftProfile5 = startSketchOn(XY)
|
||||||
|> startProfile(at = [-19.5, -l5 / 2])
|
|> startProfile(at = [-19.5, -l5 / 2])
|
||||||
|> yLine(length = l5, tag = $seg05)
|
|> yLine(length = l5, tag = $seg05)
|
||||||
|> tangentialArc(angle = -120, radius = r5)
|
|> tangentialArc(angle = -120, radius = r5)
|
||||||
@ -89,18 +76,14 @@ stemLoftProfile5 = startSketchOn(plane005)
|
|||||||
|> angledLine(angle = 30, length = -segLen(seg05))
|
|> angledLine(angle = 30, length = -segLen(seg05))
|
||||||
|> tangentialArc(endAbsolute = [profileStartX(%), profileStartY(%)])
|
|> tangentialArc(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||||
|> close()
|
|> close()
|
||||||
|
|> translate(z = p5Z)
|
||||||
|
|> rotate(pitch = -p5A)
|
||||||
// Draw the second profile for the femoral stem
|
// Draw the second profile for the femoral stem
|
||||||
p6Z = 145
|
p6Z = 145
|
||||||
p6A = 36.5
|
p6A = 36.5
|
||||||
plane006 = {
|
|
||||||
origin = [0, 0.0, p6Z],
|
|
||||||
xAxis = [cos(p6A), 0, sin(p6A)],
|
|
||||||
yAxis = [0.0, 1.0, 0.0]
|
|
||||||
}
|
|
||||||
l6 = 1
|
l6 = 1
|
||||||
r6 = 3
|
r6 = 3
|
||||||
stemLoftProfile6 = startSketchOn(plane006)
|
stemLoftProfile6 = startSketchOn(XY)
|
||||||
|> startProfile(at = [-23.4, -l6 / 2])
|
|> startProfile(at = [-23.4, -l6 / 2])
|
||||||
|> yLine(length = l6, tag = $seg06)
|
|> yLine(length = l6, tag = $seg06)
|
||||||
|> tangentialArc(angle = -120, radius = r6)
|
|> tangentialArc(angle = -120, radius = r6)
|
||||||
@ -109,27 +92,24 @@ stemLoftProfile6 = startSketchOn(plane006)
|
|||||||
|> angledLine(angle = 30, length = -segLen(seg06))
|
|> angledLine(angle = 30, length = -segLen(seg06))
|
||||||
|> tangentialArc(endAbsolute = [profileStartX(%), profileStartY(%)])
|
|> tangentialArc(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||||
|> close()
|
|> close()
|
||||||
|
|> translate(z = p6Z)
|
||||||
// Draw the third profile for the femoral stem
|
|> rotate(pitch = -p6A)
|
||||||
stemTab = clone(stemLoftProfile6)
|
|
||||||
|> extrude(%, length = 6)
|
|
||||||
|
|
||||||
// Loft the femur using all profiles in sequence
|
// Loft the femur using all profiles in sequence
|
||||||
|
|
||||||
femur = loft([
|
femur = loft([
|
||||||
stemLoftProfile1,
|
stemLoftProfile1,
|
||||||
stemLoftProfile2,
|
stemLoftProfile2,
|
||||||
stemLoftProfile3,
|
stemLoftProfile3,
|
||||||
stemLoftProfile4
|
stemLoftProfile4
|
||||||
])
|
])
|
||||||
|
|
||||||
// Loft the femoral stem
|
// Loft the femoral stem
|
||||||
femoralStem = loft([
|
femoralStem = loft([
|
||||||
clone(stemLoftProfile4),
|
clone(stemLoftProfile4),
|
||||||
stemLoftProfile5,
|
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
|
// Revolve a hollow socket to represent the femoral head
|
||||||
femoralHead = startSketchOn(XZ)
|
femoralHead = startSketchOn(XZ)
|
||||||
|> startProfile(at = [4, 0])
|
|> startProfile(at = [4, 0])
|
||||||
|
Before Width: | Height: | Size: 98 KiB After Width: | Height: | Size: 98 KiB |
BIN
public/kcl-samples/screenshots/brake-rotor.png
Normal file
After Width: | Height: | Size: 82 KiB |
Before Width: | Height: | Size: 216 KiB After Width: | Height: | Size: 216 KiB |
Before Width: | Height: | Size: 61 KiB After Width: | Height: | Size: 61 KiB |
Before Width: | Height: | Size: 95 KiB After Width: | Height: | Size: 95 KiB |
@ -53,8 +53,8 @@ baseSlab = boxFn(plane = XY, width = slabWidth, height = -baseThickness)
|
|||||||
|> appearance(%, color = "#dbd7d2")
|
|> appearance(%, color = "#dbd7d2")
|
||||||
|
|
||||||
// Create ground platform beneath the base
|
// Create ground platform beneath the base
|
||||||
goundSize = 50
|
groundSize = 50
|
||||||
groundBody = boxFn(plane = offsetPlane(XY, offset = -baseThickness), width = goundSize, height = -5)
|
groundBody = boxFn(plane = offsetPlane(XY, offset = -baseThickness), width = groundSize, height = -5)
|
||||||
|> appearance(%, color = "#3a3631")
|
|> appearance(%, color = "#3a3631")
|
||||||
|
|
||||||
// Create a single slab with handrail height to be reused with pattern
|
// Create a single slab with handrail height to be reused with pattern
|
||||||
|
Before Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 8.1 KiB |
Before Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 13 KiB |
20
rust/Cargo.lock
generated
@ -1815,7 +1815,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "kcl-bumper"
|
name = "kcl-bumper"
|
||||||
version = "0.1.74"
|
version = "0.1.75"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"clap",
|
"clap",
|
||||||
@ -1826,7 +1826,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "kcl-derive-docs"
|
name = "kcl-derive-docs"
|
||||||
version = "0.1.74"
|
version = "0.1.75"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"Inflector",
|
"Inflector",
|
||||||
"anyhow",
|
"anyhow",
|
||||||
@ -1845,7 +1845,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "kcl-directory-test-macro"
|
name = "kcl-directory-test-macro"
|
||||||
version = "0.1.74"
|
version = "0.1.75"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"convert_case",
|
"convert_case",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
@ -1855,7 +1855,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "kcl-language-server"
|
name = "kcl-language-server"
|
||||||
version = "0.2.74"
|
version = "0.2.75"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"clap",
|
"clap",
|
||||||
@ -1876,7 +1876,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "kcl-language-server-release"
|
name = "kcl-language-server-release"
|
||||||
version = "0.1.74"
|
version = "0.1.75"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"clap",
|
"clap",
|
||||||
@ -1896,7 +1896,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "kcl-lib"
|
name = "kcl-lib"
|
||||||
version = "0.2.74"
|
version = "0.2.75"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"approx 0.5.1",
|
"approx 0.5.1",
|
||||||
@ -1973,7 +1973,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "kcl-python-bindings"
|
name = "kcl-python-bindings"
|
||||||
version = "0.3.74"
|
version = "0.3.75"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"kcl-lib",
|
"kcl-lib",
|
||||||
@ -1988,7 +1988,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "kcl-test-server"
|
name = "kcl-test-server"
|
||||||
version = "0.1.74"
|
version = "0.1.75"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"hyper 0.14.32",
|
"hyper 0.14.32",
|
||||||
@ -2001,7 +2001,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "kcl-to-core"
|
name = "kcl-to-core"
|
||||||
version = "0.1.74"
|
version = "0.1.75"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
@ -2015,7 +2015,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "kcl-wasm-lib"
|
name = "kcl-wasm-lib"
|
||||||
version = "0.1.74"
|
version = "0.1.75"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"bson",
|
"bson",
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
[package]
|
[package]
|
||||||
name = "kcl-bumper"
|
name = "kcl-bumper"
|
||||||
version = "0.1.74"
|
version = "0.1.75"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
repository = "https://github.com/KittyCAD/modeling-api"
|
repository = "https://github.com/KittyCAD/modeling-api"
|
||||||
rust-version = "1.76"
|
rust-version = "1.76"
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "kcl-derive-docs"
|
name = "kcl-derive-docs"
|
||||||
description = "A tool for generating documentation from Rust derive macros"
|
description = "A tool for generating documentation from Rust derive macros"
|
||||||
version = "0.1.74"
|
version = "0.1.75"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
repository = "https://github.com/KittyCAD/modeling-app"
|
repository = "https://github.com/KittyCAD/modeling-app"
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "kcl-directory-test-macro"
|
name = "kcl-directory-test-macro"
|
||||||
description = "A tool for generating tests from a directory of kcl files"
|
description = "A tool for generating tests from a directory of kcl files"
|
||||||
version = "0.1.74"
|
version = "0.1.75"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
repository = "https://github.com/KittyCAD/modeling-app"
|
repository = "https://github.com/KittyCAD/modeling-app"
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "kcl-language-server-release"
|
name = "kcl-language-server-release"
|
||||||
version = "0.1.74"
|
version = "0.1.75"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
authors = ["KittyCAD Inc <kcl@kittycad.io>"]
|
authors = ["KittyCAD Inc <kcl@kittycad.io>"]
|
||||||
publish = false
|
publish = false
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
name = "kcl-language-server"
|
name = "kcl-language-server"
|
||||||
description = "A language server for KCL."
|
description = "A language server for KCL."
|
||||||
authors = ["KittyCAD Inc <kcl@kittycad.io>"]
|
authors = ["KittyCAD Inc <kcl@kittycad.io>"]
|
||||||
version = "0.2.74"
|
version = "0.2.75"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "kcl-lib"
|
name = "kcl-lib"
|
||||||
description = "KittyCAD Language implementation and tools"
|
description = "KittyCAD Language implementation and tools"
|
||||||
version = "0.2.74"
|
version = "0.2.75"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
repository = "https://github.com/KittyCAD/modeling-app"
|
repository = "https://github.com/KittyCAD/modeling-app"
|
||||||
|
Before Width: | Height: | Size: 99 KiB After Width: | Height: | Size: 99 KiB |
Before Width: | Height: | Size: 99 KiB After Width: | Height: | Size: 99 KiB |
@ -631,6 +631,8 @@ impl FnData {
|
|||||||
return "clone(${0:part001})".to_owned();
|
return "clone(${0:part001})".to_owned();
|
||||||
} else if self.name == "hole" {
|
} else if self.name == "hole" {
|
||||||
return "hole(${0:holeSketch}, ${1:%})".to_owned();
|
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 args = Vec::new();
|
||||||
let mut index = 0;
|
let mut index = 0;
|
||||||
|
@ -1018,7 +1018,7 @@ mod tests {
|
|||||||
let snippet = circle_fn.to_autocomplete_snippet();
|
let snippet = circle_fn.to_autocomplete_snippet();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
snippet,
|
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})"#
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -281,7 +281,14 @@ impl ExecutorContext {
|
|||||||
|
|
||||||
// Track exports.
|
// Track exports.
|
||||||
if let ItemVisibility::Export = variable_declaration.visibility {
|
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.
|
// Variable declaration can be the return value of a module.
|
||||||
last_expr = matches!(body_type, BodyType::Root).then_some(value);
|
last_expr = matches!(body_type, BodyType::Root).then_some(value);
|
||||||
|
@ -35,31 +35,28 @@ impl Default for TypedPath {
|
|||||||
|
|
||||||
impl From<&String> for TypedPath {
|
impl From<&String> for TypedPath {
|
||||||
fn from(path: &String) -> Self {
|
fn from(path: &String) -> Self {
|
||||||
#[cfg(target_arch = "wasm32")]
|
TypedPath::new(path)
|
||||||
{
|
|
||||||
TypedPath(typed_path::TypedPath::derive(path).to_path_buf())
|
|
||||||
}
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
{
|
|
||||||
TypedPath(std::path::PathBuf::from(path))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<&str> for TypedPath {
|
impl From<&str> for TypedPath {
|
||||||
fn from(path: &str) -> Self {
|
fn from(path: &str) -> Self {
|
||||||
|
TypedPath::new(path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TypedPath {
|
||||||
|
pub fn new(path: &str) -> Self {
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
{
|
{
|
||||||
TypedPath(typed_path::TypedPath::derive(path).to_path_buf())
|
TypedPath(typed_path::TypedPath::derive(path).to_path_buf())
|
||||||
}
|
}
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
{
|
{
|
||||||
TypedPath(std::path::PathBuf::from(path))
|
TypedPath(normalise_import(path))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl TypedPath {
|
|
||||||
pub fn extension(&self) -> Option<&str> {
|
pub fn extension(&self) -> Option<&str> {
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[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> {
|
pub fn parent(&self) -> Option<Self> {
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
{
|
{
|
||||||
@ -206,3 +214,19 @@ impl schemars::JsonSchema for TypedPath {
|
|||||||
gen.subschema_for::<std::path::PathBuf>()
|
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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -155,9 +155,8 @@ impl RuntimeType {
|
|||||||
.map(RuntimeType::Union),
|
.map(RuntimeType::Union),
|
||||||
Type::Object { properties } => properties
|
Type::Object { properties } => properties
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|p| {
|
.map(|(id, ty)| {
|
||||||
RuntimeType::from_parsed(p.type_.unwrap().inner, exec_state, source_range)
|
RuntimeType::from_parsed(ty.inner, exec_state, source_range).map(|ty| (id.name.clone(), ty))
|
||||||
.map(|ty| (p.identifier.inner.name, ty))
|
|
||||||
})
|
})
|
||||||
.collect::<Result<Vec<_>, CompilationError>>()
|
.collect::<Result<Vec<_>, CompilationError>>()
|
||||||
.map(RuntimeType::Object),
|
.map(RuntimeType::Object),
|
||||||
|
@ -185,9 +185,9 @@ impl ModulePath {
|
|||||||
match path {
|
match path {
|
||||||
ImportPath::Kcl { filename: path } | ImportPath::Foreign { path } => {
|
ImportPath::Kcl { filename: path } | ImportPath::Foreign { path } => {
|
||||||
let resolved_path = if let Some(project_dir) = project_directory {
|
let resolved_path = if let Some(project_dir) = project_directory {
|
||||||
project_dir.join(path)
|
project_dir.join_typed(path)
|
||||||
} else {
|
} else {
|
||||||
TypedPath::from(path)
|
path.clone()
|
||||||
};
|
};
|
||||||
ModulePath::Local { value: resolved_path }
|
ModulePath::Local { value: resolved_path }
|
||||||
}
|
}
|
||||||
|
@ -212,8 +212,9 @@ impl Type {
|
|||||||
Type::Object { properties } => {
|
Type::Object { properties } => {
|
||||||
hasher.update(b"FnArgType::Object");
|
hasher.update(b"FnArgType::Object");
|
||||||
hasher.update(properties.len().to_ne_bytes());
|
hasher.update(properties.len().to_ne_bytes());
|
||||||
for prop in properties.iter_mut() {
|
for (id, ty) in properties.iter_mut() {
|
||||||
hasher.update(prop.compute_digest());
|
hasher.update(id.compute_digest());
|
||||||
|
hasher.update(ty.compute_digest());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ use crate::{
|
|||||||
},
|
},
|
||||||
parsing::{ast::digest::Digest, token::NumericSuffix, PIPE_OPERATOR},
|
parsing::{ast::digest::Digest, token::NumericSuffix, PIPE_OPERATOR},
|
||||||
source_range::SourceRange,
|
source_range::SourceRange,
|
||||||
ModuleId,
|
ModuleId, TypedPath,
|
||||||
};
|
};
|
||||||
|
|
||||||
mod condition;
|
mod condition;
|
||||||
@ -1741,8 +1741,8 @@ impl ImportSelector {
|
|||||||
#[ts(export)]
|
#[ts(export)]
|
||||||
#[serde(tag = "type")]
|
#[serde(tag = "type")]
|
||||||
pub enum ImportPath {
|
pub enum ImportPath {
|
||||||
Kcl { filename: String },
|
Kcl { filename: TypedPath },
|
||||||
Foreign { path: String },
|
Foreign { path: TypedPath },
|
||||||
Std { path: Vec<String> },
|
Std { path: Vec<String> },
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1811,16 +1811,25 @@ impl ImportStatement {
|
|||||||
|
|
||||||
match &self.path {
|
match &self.path {
|
||||||
ImportPath::Kcl { filename: s } | ImportPath::Foreign { path: s } => {
|
ImportPath::Kcl { filename: s } | ImportPath::Foreign { path: s } => {
|
||||||
let mut parts = s.split('.');
|
let name = s.to_string_lossy();
|
||||||
let path = parts.next()?;
|
if name.ends_with("/main.kcl") || name.ends_with("\\main.kcl") {
|
||||||
let _ext = parts.next()?;
|
let name = &name[..name.len() - 9];
|
||||||
let rest = parts.next();
|
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;
|
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(),
|
ImportPath::Std { path } => path.last().cloned(),
|
||||||
}
|
}
|
||||||
@ -3315,7 +3324,7 @@ pub enum Type {
|
|||||||
},
|
},
|
||||||
// An object type.
|
// An object type.
|
||||||
Object {
|
Object {
|
||||||
properties: Vec<Parameter>,
|
properties: Vec<(Node<Identifier>, Node<Type>)>,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3348,10 +3357,8 @@ impl fmt::Display for Type {
|
|||||||
} else {
|
} else {
|
||||||
write!(f, ",")?;
|
write!(f, ",")?;
|
||||||
}
|
}
|
||||||
write!(f, " {}:", p.identifier.name)?;
|
write!(f, " {}:", p.0.name)?;
|
||||||
if let Some(ty) = &p.type_ {
|
write!(f, " {}", p.1)?;
|
||||||
write!(f, " {}", ty.inner)?;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
write!(f, " }}")
|
write!(f, " }}")
|
||||||
}
|
}
|
||||||
@ -3988,7 +3995,7 @@ cylinder = startSketchOn(-XZ)
|
|||||||
|
|
||||||
#[tokio::test(flavor = "multi_thread")]
|
#[tokio::test(flavor = "multi_thread")]
|
||||||
async fn test_parse_type_args_object_on_functions() {
|
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
|
return arg0
|
||||||
}"#;
|
}"#;
|
||||||
let module_id = ModuleId::default();
|
let module_id = ModuleId::default();
|
||||||
@ -4015,8 +4022,8 @@ cylinder = startSketchOn(-XZ)
|
|||||||
params[1].type_.as_ref().unwrap().inner,
|
params[1].type_.as_ref().unwrap().inner,
|
||||||
Type::Object {
|
Type::Object {
|
||||||
properties: vec![
|
properties: vec![
|
||||||
Parameter {
|
(
|
||||||
identifier: Node::new(
|
Node::new(
|
||||||
Identifier {
|
Identifier {
|
||||||
name: "thing".to_owned(),
|
name: "thing".to_owned(),
|
||||||
digest: None,
|
digest: None,
|
||||||
@ -4025,18 +4032,15 @@ cylinder = startSketchOn(-XZ)
|
|||||||
37,
|
37,
|
||||||
module_id,
|
module_id,
|
||||||
),
|
),
|
||||||
type_: Some(Node::new(
|
Node::new(
|
||||||
Type::Primitive(PrimitiveType::Number(NumericSuffix::None)),
|
Type::Primitive(PrimitiveType::Number(NumericSuffix::None)),
|
||||||
39,
|
39,
|
||||||
45,
|
45,
|
||||||
module_id
|
module_id
|
||||||
)),
|
),
|
||||||
default_value: None,
|
),
|
||||||
labeled: true,
|
(
|
||||||
digest: None,
|
Node::new(
|
||||||
},
|
|
||||||
Parameter {
|
|
||||||
identifier: Node::new(
|
|
||||||
Identifier {
|
Identifier {
|
||||||
name: "things".to_owned(),
|
name: "things".to_owned(),
|
||||||
digest: None,
|
digest: None,
|
||||||
@ -4045,7 +4049,7 @@ cylinder = startSketchOn(-XZ)
|
|||||||
53,
|
53,
|
||||||
module_id,
|
module_id,
|
||||||
),
|
),
|
||||||
type_: Some(Node::new(
|
Node::new(
|
||||||
Type::Array {
|
Type::Array {
|
||||||
ty: Box::new(Type::Primitive(PrimitiveType::String)),
|
ty: Box::new(Type::Primitive(PrimitiveType::String)),
|
||||||
len: ArrayLen::None
|
len: ArrayLen::None
|
||||||
@ -4053,13 +4057,10 @@ cylinder = startSketchOn(-XZ)
|
|||||||
56,
|
56,
|
||||||
62,
|
62,
|
||||||
module_id
|
module_id
|
||||||
)),
|
)
|
||||||
default_value: None,
|
),
|
||||||
labeled: true,
|
(
|
||||||
digest: None
|
Node::new(
|
||||||
},
|
|
||||||
Parameter {
|
|
||||||
identifier: Node::new(
|
|
||||||
Identifier {
|
Identifier {
|
||||||
name: "more".to_owned(),
|
name: "more".to_owned(),
|
||||||
digest: None
|
digest: None
|
||||||
@ -4068,11 +4069,8 @@ cylinder = startSketchOn(-XZ)
|
|||||||
69,
|
69,
|
||||||
module_id,
|
module_id,
|
||||||
),
|
),
|
||||||
type_: Some(Node::new(Type::Primitive(PrimitiveType::String), 72, 78, module_id)),
|
Node::new(Type::Primitive(PrimitiveType::String), 71, 77, module_id),
|
||||||
labeled: true,
|
)
|
||||||
default_value: Some(DefaultParamVal::none()),
|
|
||||||
digest: None
|
|
||||||
}
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -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");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ use crate::{
|
|||||||
token::{Token, TokenSlice, TokenType},
|
token::{Token, TokenSlice, TokenType},
|
||||||
PIPE_OPERATOR, PIPE_SUBSTITUTION_OPERATOR,
|
PIPE_OPERATOR, PIPE_SUBSTITUTION_OPERATOR,
|
||||||
},
|
},
|
||||||
SourceRange, IMPORT_FILE_EXTENSIONS,
|
SourceRange, TypedPath, IMPORT_FILE_EXTENSIONS,
|
||||||
};
|
};
|
||||||
|
|
||||||
thread_local! {
|
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
|
let (value, token) = any
|
||||||
.try_map(|token: Token| match token.token_type {
|
.try_map(|token: Token| match token.token_type {
|
||||||
TokenType::Keyword if token.value == "true" => Ok((true, token)),
|
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)"))
|
.context(expected("a boolean literal (either true or false)"))
|
||||||
.parse_next(i)?;
|
.parse_next(i)?;
|
||||||
Ok(Box::new(Node::new(
|
Ok(Node::new(
|
||||||
Literal {
|
Literal {
|
||||||
value: LiteralValue::Bool(value),
|
value: LiteralValue::Bool(value),
|
||||||
raw: value.to_string(),
|
raw: value.to_string(),
|
||||||
@ -457,11 +457,11 @@ fn bool_value(i: &mut TokenSlice) -> PResult<BoxNode<Literal>> {
|
|||||||
token.start,
|
token.start,
|
||||||
token.end,
|
token.end,
|
||||||
token.module_id,
|
token.module_id,
|
||||||
)))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn literal(i: &mut TokenSlice) -> PResult<BoxNode<Literal>> {
|
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)
|
.map(Box::new)
|
||||||
.context(expected("a KCL literal, like 'myPart' or 3"))
|
.context(expected("a KCL literal, like 'myPart' or 3"))
|
||||||
.parse_next(i)
|
.parse_next(i)
|
||||||
@ -1729,7 +1729,7 @@ fn glob(i: &mut TokenSlice) -> PResult<Token> {
|
|||||||
.parse_next(i)
|
.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))
|
let (visibility, visibility_token) = opt(terminated(item_visibility, whitespace))
|
||||||
.parse_next(i)?
|
.parse_next(i)?
|
||||||
.map_or((ItemVisibility::Default, None), |pair| (pair.0, Some(pair.1)));
|
.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") {
|
let path = if path_string.ends_with(".kcl") {
|
||||||
if path_string
|
if path_string
|
||||||
.chars()
|
.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(
|
return Err(ErrMode::Cut(
|
||||||
CompilationError::fatal(
|
CompilationError::fatal(
|
||||||
path_range,
|
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(),
|
.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::") {
|
} else if path_string.starts_with("std::") {
|
||||||
ParseContext::warn(CompilationError::err(
|
ParseContext::warn(CompilationError::err(
|
||||||
path_range,
|
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(", ")),
|
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 {
|
} else {
|
||||||
return Err(ErrMode::Cut(
|
return Err(ErrMode::Cut(
|
||||||
CompilationError::fatal(
|
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> {
|
fn expr_allowed_in_pipe_expr(i: &mut TokenSlice) -> PResult<Expr> {
|
||||||
alt((
|
alt((
|
||||||
member_expression.map(Box::new).map(Expr::MemberExpression),
|
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),
|
tag.map(Box::new).map(Expr::TagDeclarator),
|
||||||
literal.map(Expr::Literal),
|
literal.map(Expr::Literal),
|
||||||
fn_call_kw.map(Box::new).map(Expr::CallExpressionKw),
|
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> {
|
fn possible_operands(i: &mut TokenSlice) -> PResult<Expr> {
|
||||||
let mut expr = alt((
|
let mut expr = alt((
|
||||||
unary_expression.map(Box::new).map(Expr::UnaryExpression),
|
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),
|
member_expression.map(Box::new).map(Expr::MemberExpression),
|
||||||
literal.map(Expr::Literal),
|
literal.map(Expr::Literal),
|
||||||
fn_call_kw.map(Box::new).map(Expr::CallExpressionKw),
|
fn_call_kw.map(Box::new).map(Expr::CallExpressionKw),
|
||||||
@ -2780,27 +2814,31 @@ fn labeled_argument(i: &mut TokenSlice) -> PResult<LabeledArg> {
|
|||||||
.parse_next(i)
|
.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.
|
/// Parse a type in various positions.
|
||||||
fn type_(i: &mut TokenSlice) -> PResult<Node<Type>> {
|
fn type_(i: &mut TokenSlice) -> PResult<Node<Type>> {
|
||||||
let type_ = alt((
|
let type_ = alt((
|
||||||
// Object types
|
// 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)| {
|
open_brace,
|
||||||
for p in ¶ms {
|
opt(whitespace),
|
||||||
if p.type_.is_none() {
|
separated(0.., record_ty_field, comma_sep),
|
||||||
return Err(CompilationError::fatal(
|
opt(whitespace),
|
||||||
p.identifier.as_source_range(),
|
close_brace,
|
||||||
"Missing type for field in record type",
|
)
|
||||||
));
|
.try_map(|(open, _, params, _, close)| {
|
||||||
}
|
Ok(Node::new(
|
||||||
}
|
Type::Object { properties: params },
|
||||||
Ok(Node::new(
|
open.start,
|
||||||
Type::Object { properties: params },
|
close.end,
|
||||||
open.start,
|
open.module_id,
|
||||||
close.end,
|
))
|
||||||
open.module_id,
|
}),
|
||||||
))
|
|
||||||
}),
|
|
||||||
// Array types
|
// Array types
|
||||||
array_type,
|
array_type,
|
||||||
// Primitive or union types
|
// Primitive or union types
|
||||||
@ -4530,9 +4568,24 @@ e
|
|||||||
fn bad_imports() {
|
fn bad_imports() {
|
||||||
assert_err(
|
assert_err(
|
||||||
r#"import cube from "../cube.kcl""#,
|
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],
|
[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(
|
assert_err(
|
||||||
r#"import * as foo from "dsfs""#,
|
r#"import * as foo from "dsfs""#,
|
||||||
"as is not the 'from' keyword",
|
"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)"#;
|
|> line(%, tag = $var01)"#;
|
||||||
assert_no_err(some_program_string);
|
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]
|
#[test]
|
||||||
fn parse_function_types() {
|
fn parse_function_types() {
|
||||||
let code = r#"foo = x: fn
|
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 fn
|
||||||
type foo = fn
|
type foo = fn
|
||||||
type foo = fn(a: string, b: { f: fn(): any })
|
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])
|
||||||
type foo = fn(fn, f: fn(number(_))): [fn([any]): string]
|
type foo = fn(fn, f: fn(number(_))): [fn([any]): string]
|
||||||
"#;
|
"#;
|
||||||
|
@ -996,6 +996,27 @@ mod import_cycle1 {
|
|||||||
super::execute(TEST_NAME, false).await
|
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 {
|
mod import_function_not_sketch {
|
||||||
const TEST_NAME: &str = "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
|
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 {
|
mod assembly_non_default_units {
|
||||||
const TEST_NAME: &str = "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.
|
/// Test that KCL is executed correctly.
|
||||||
#[tokio::test(flavor = "multi_thread")]
|
#[tokio::test(flavor = "multi_thread")]
|
||||||
#[ignore] // until https://github.com/KittyCAD/engine/pull/3417 lands
|
|
||||||
async fn kcl_test_execute() {
|
async fn kcl_test_execute() {
|
||||||
super::execute(TEST_NAME, true).await
|
super::execute(TEST_NAME, true).await
|
||||||
}
|
}
|
||||||
@ -3277,3 +3318,87 @@ mod subtract_regression10 {
|
|||||||
super::execute(TEST_NAME, true).await
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -9,6 +9,7 @@ use kittycad_modeling_cmds as kcmc;
|
|||||||
use schemars::JsonSchema;
|
use schemars::JsonSchema;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
|
pub use crate::execution::fn_call::Args;
|
||||||
use crate::{
|
use crate::{
|
||||||
errors::{KclError, KclErrorDetails},
|
errors::{KclError, KclErrorDetails},
|
||||||
execution::{
|
execution::{
|
||||||
@ -27,8 +28,6 @@ use crate::{
|
|||||||
ModuleId,
|
ModuleId,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub use crate::execution::fn_call::Args;
|
|
||||||
|
|
||||||
const ERROR_STRING_SKETCH_TO_SOLID_HELPER: &str =
|
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`";
|
"You can convert a sketch (2D) into a Solid (3D) by calling a function like `extrude` or `revolve`";
|
||||||
|
|
||||||
|
@ -80,8 +80,6 @@ lazy_static! {
|
|||||||
Box::new(crate::std::patterns::PatternLinear3D),
|
Box::new(crate::std::patterns::PatternLinear3D),
|
||||||
Box::new(crate::std::patterns::PatternCircular2D),
|
Box::new(crate::std::patterns::PatternCircular2D),
|
||||||
Box::new(crate::std::patterns::PatternCircular3D),
|
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::GetOppositeEdge),
|
||||||
Box::new(crate::std::edge::GetNextAdjacentEdge),
|
Box::new(crate::std::edge::GetNextAdjacentEdge),
|
||||||
Box::new(crate::std::edge::GetPreviousAdjacentEdge),
|
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)),
|
|e, a| Box::pin(crate::std::clone::clone(e, a)),
|
||||||
StdFnProps::default("std::clone").include_in_feature_tree(),
|
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!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@ use kittycad_modeling_cmds::{
|
|||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
use super::axis_or_reference::Axis3dOrPoint3d;
|
||||||
use crate::{
|
use crate::{
|
||||||
errors::{KclError, KclErrorDetails},
|
errors::{KclError, KclErrorDetails},
|
||||||
execution::{
|
execution::{
|
||||||
@ -31,8 +32,6 @@ use crate::{
|
|||||||
ExecutorContext, SourceRange,
|
ExecutorContext, SourceRange,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::axis_or_reference::Axis3dOrPoint3d;
|
|
||||||
|
|
||||||
const MUST_HAVE_ONE_INSTANCE: &str = "There must be at least 1 instance of your geometry";
|
const MUST_HAVE_ONE_INSTANCE: &str = "There must be at least 1 instance of your geometry";
|
||||||
|
|
||||||
/// Repeat some 3D solid, changing each repetition slightly.
|
/// 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())
|
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>(
|
async fn inner_pattern_transform<'a>(
|
||||||
solids: Vec<Solid>,
|
solids: Vec<Solid>,
|
||||||
instances: u32,
|
instances: u32,
|
||||||
@ -283,30 +86,6 @@ async fn inner_pattern_transform<'a>(
|
|||||||
.await
|
.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>(
|
async fn inner_pattern_transform_2d<'a>(
|
||||||
sketches: Vec<Sketch>,
|
sketches: Vec<Sketch>,
|
||||||
instances: u32,
|
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.
|
// If instances is 1, this has no effect.
|
||||||
let instances: u32 = args.get_kw_arg_typed("instances", &RuntimeType::count(), exec_state)?;
|
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.
|
// 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.
|
// 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)?;
|
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.
|
// 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.
|
/// solid with respect to the center of the circle is maintained.
|
||||||
///
|
///
|
||||||
/// ```no_run
|
/// ```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)
|
/// exampleSketch = startSketchOn(XZ)
|
||||||
/// |> circle(center = [0, 0], radius = 1)
|
/// |> circle(center = [0, 0], radius = 1)
|
||||||
///
|
///
|
||||||
|
@ -44,10 +44,11 @@ pub enum SketchOrSurface {
|
|||||||
pub async fn circle(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
|
pub async fn circle(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
|
||||||
let sketch_or_surface = args.get_unlabeled_kw_arg("sketchOrSurface")?;
|
let sketch_or_surface = args.get_unlabeled_kw_arg("sketchOrSurface")?;
|
||||||
let center = args.get_kw_arg_typed("center", &RuntimeType::point2d(), exec_state)?;
|
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 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 {
|
Ok(KclValue::Sketch {
|
||||||
value: Box::new(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(
|
async fn inner_circle(
|
||||||
sketch_or_surface: SketchOrSurface,
|
sketch_or_surface: SketchOrSurface,
|
||||||
center: [TyF64; 2],
|
center: [TyF64; 2],
|
||||||
radius: TyF64,
|
radius: Option<TyF64>,
|
||||||
|
diameter: Option<TyF64>,
|
||||||
tag: Option<TagNode>,
|
tag: Option<TagNode>,
|
||||||
exec_state: &mut ExecState,
|
exec_state: &mut ExecState,
|
||||||
args: Args,
|
args: Args,
|
||||||
@ -68,6 +70,25 @@ async fn inner_circle(
|
|||||||
let (center_u, ty) = untype_point(center.clone());
|
let (center_u, ty) = untype_point(center.clone());
|
||||||
let units = ty.expect_length();
|
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 = [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)];
|
let from_t = [TyF64::new(from[0], ty.clone()), TyF64::new(from[1], ty)];
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ use crate::{
|
|||||||
args::{Args, TyF64},
|
args::{Args, TyF64},
|
||||||
utils::{
|
utils::{
|
||||||
arc_center_and_end, get_tangential_arc_to_info, get_x_component, get_y_component,
|
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,
|
TangentialArcInfoInput,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -1396,12 +1396,14 @@ pub(crate) async fn inner_start_profile(
|
|||||||
])
|
])
|
||||||
.await?;
|
.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 {
|
let current_path = BasePath {
|
||||||
from: to,
|
from: to,
|
||||||
to,
|
to,
|
||||||
tag: tag.clone(),
|
tag: tag.clone(),
|
||||||
units: ty.expect_length(),
|
units,
|
||||||
geo_meta: GeoMeta {
|
geo_meta: GeoMeta {
|
||||||
id: move_pen_id,
|
id: move_pen_id,
|
||||||
metadata: args.source_range.into(),
|
metadata: args.source_range.into(),
|
||||||
@ -1414,7 +1416,7 @@ pub(crate) async fn inner_start_profile(
|
|||||||
artifact_id: path_id.into(),
|
artifact_id: path_id.into(),
|
||||||
on: sketch_surface.clone(),
|
on: sketch_surface.clone(),
|
||||||
paths: vec![],
|
paths: vec![],
|
||||||
units: ty.expect_length(),
|
units,
|
||||||
mirror: Default::default(),
|
mirror: Default::default(),
|
||||||
meta: vec![args.source_range.into()],
|
meta: vec![args.source_range.into()],
|
||||||
tags: if let Some(tag) = &tag {
|
tags: if let Some(tag) = &tag {
|
||||||
|
@ -11,11 +11,13 @@ use kcmc::{
|
|||||||
};
|
};
|
||||||
use kittycad_modeling_cmds as kcmc;
|
use kittycad_modeling_cmds as kcmc;
|
||||||
|
|
||||||
use super::args::TyF64;
|
|
||||||
use crate::{
|
use crate::{
|
||||||
errors::{KclError, KclErrorDetails},
|
errors::{KclError, KclErrorDetails},
|
||||||
execution::{types::RuntimeType, ExecState, KclValue, SolidOrSketchOrImportedGeometry},
|
execution::{
|
||||||
std::Args,
|
types::{PrimitiveType, RuntimeType},
|
||||||
|
ExecState, KclValue, SolidOrSketchOrImportedGeometry,
|
||||||
|
},
|
||||||
|
std::{args::TyF64, axis_or_reference::Axis3dOrPoint3d, Args},
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Scale a solid or a sketch.
|
/// 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 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 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 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 angle: Option<TyF64> = args.get_kw_arg_opt_typed("angle", &RuntimeType::degrees(), exec_state)?;
|
||||||
let global = args.get_kw_arg_opt("global")?;
|
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
|
/// ```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.
|
/// // Create a path for the sweep.
|
||||||
/// sweepPath = startSketchOn(XZ)
|
/// 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.
|
/// // Sweep two sketches along the same path.
|
||||||
///
|
///
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/// The standard library is organised into modules (listed below), but most things are always available
|
/// The standard library is organised into modules (listed below), but most things are always available
|
||||||
/// in KCL programs.
|
/// 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
|
@no_std
|
||||||
@settings(defaultLengthUnit = mm, kclVersion = 1.0)
|
@settings(defaultLengthUnit = mm, kclVersion = 1.0)
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
/// |> line(end = [0, 30])
|
/// |> line(end = [0, 30])
|
||||||
/// |> line(end = [-30, 0])
|
/// |> line(end = [-30, 0])
|
||||||
/// |> close()
|
/// |> close()
|
||||||
/// |> subtract2d(tool = circle(center = [0, 15], radius = 5))
|
/// |> subtract2d(tool = circle(center = [0, 15], diameter = 10))
|
||||||
///
|
///
|
||||||
/// example = extrude(exampleSketch, length = 5)
|
/// example = extrude(exampleSketch, length = 5)
|
||||||
/// ```
|
/// ```
|
||||||
@ -34,8 +34,10 @@ export fn circle(
|
|||||||
@sketch_or_surface: Sketch | Plane | Face,
|
@sketch_or_surface: Sketch | Plane | Face,
|
||||||
/// The center of the circle.
|
/// The center of the circle.
|
||||||
center: Point2d,
|
center: Point2d,
|
||||||
/// The radius of the circle.
|
/// The radius of the circle. Incompatible with `diameter`.
|
||||||
radius: number(Length),
|
radius?: number(Length),
|
||||||
|
/// The diameter of the circle. Incompatible with `radius`.
|
||||||
|
diameter?: number(Length),
|
||||||
/// Create a new tag which refers to this circle.
|
/// Create a new tag which refers to this circle.
|
||||||
tag?: tag,
|
tag?: tag,
|
||||||
): Sketch {}
|
): Sketch {}
|
||||||
@ -278,3 +280,28 @@ export fn revolve(
|
|||||||
/// A named tag for the face at the end of the revolve.
|
/// A named tag for the face at the end of the revolve.
|
||||||
tagEnd?: tag,
|
tagEnd?: tag,
|
||||||
): [Solid; 1+] {}
|
): [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+] {}
|
||||||
|
@ -365,3 +365,202 @@ export fn hollow(
|
|||||||
/// The thickness of the remaining shell
|
/// The thickness of the remaining shell
|
||||||
thickness: number(Length),
|
thickness: number(Length),
|
||||||
): Solid {}
|
): 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+] {}
|
||||||
|
@ -296,15 +296,15 @@ flowchart LR
|
|||||||
33 --- 92
|
33 --- 92
|
||||||
33 --- 105
|
33 --- 105
|
||||||
37 --- 65
|
37 --- 65
|
||||||
37 x--> 84
|
37 x--> 80
|
||||||
37 --- 86
|
37 --- 86
|
||||||
37 --- 99
|
37 --- 99
|
||||||
38 --- 66
|
38 --- 66
|
||||||
38 x--> 84
|
38 x--> 80
|
||||||
38 --- 87
|
38 --- 87
|
||||||
38 --- 100
|
38 --- 100
|
||||||
39 --- 67
|
39 --- 67
|
||||||
39 x--> 84
|
39 x--> 80
|
||||||
39 --- 88
|
39 --- 88
|
||||||
39 --- 101
|
39 --- 101
|
||||||
46 --- 75
|
46 --- 75
|
||||||
@ -409,9 +409,6 @@ flowchart LR
|
|||||||
77 --- 96
|
77 --- 96
|
||||||
77 --- 109
|
77 --- 109
|
||||||
110 <--x 77
|
110 <--x 77
|
||||||
86 <--x 80
|
|
||||||
87 <--x 80
|
|
||||||
88 <--x 80
|
|
||||||
92 <--x 82
|
92 <--x 82
|
||||||
93 <--x 82
|
93 <--x 82
|
||||||
94 <--x 82
|
94 <--x 82
|
||||||
@ -419,6 +416,9 @@ flowchart LR
|
|||||||
96 <--x 83
|
96 <--x 83
|
||||||
97 <--x 83
|
97 <--x 83
|
||||||
98 <--x 83
|
98 <--x 83
|
||||||
|
86 <--x 84
|
||||||
|
87 <--x 84
|
||||||
|
88 <--x 84
|
||||||
89 <--x 85
|
89 <--x 85
|
||||||
90 <--x 85
|
90 <--x 85
|
||||||
91 <--x 85
|
91 <--x 85
|
||||||
|
@ -337,6 +337,15 @@ description: Artifact commands error_revolve_on_edge_get_edge.kcl
|
|||||||
"opposite": "None"
|
"opposite": "None"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"cmdId": "[uuid]",
|
||||||
|
"range": [],
|
||||||
|
"command": {
|
||||||
|
"type": "solid3d_get_adjacency_info",
|
||||||
|
"object_id": "[uuid]",
|
||||||
|
"edge_id": "[uuid]"
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"cmdId": "[uuid]",
|
"cmdId": "[uuid]",
|
||||||
"range": [],
|
"range": [],
|
||||||
|
@ -32,28 +32,30 @@ flowchart LR
|
|||||||
%% [ProgramBodyItem { index: 1 }, VariableDeclarationDeclaration, VariableDeclarationInit, PipeBodyItem { index: 0 }]
|
%% [ProgramBodyItem { index: 1 }, VariableDeclarationDeclaration, VariableDeclarationInit, PipeBodyItem { index: 0 }]
|
||||||
15["Sweep Extrusion<br>[169, 189, 0]"]
|
15["Sweep Extrusion<br>[169, 189, 0]"]
|
||||||
%% [ProgramBodyItem { index: 0 }, VariableDeclarationDeclaration, VariableDeclarationInit, PipeBodyItem { index: 6 }]
|
%% [ProgramBodyItem { index: 0 }, VariableDeclarationDeclaration, VariableDeclarationInit, PipeBodyItem { index: 6 }]
|
||||||
16[Wall]
|
16["Sweep RevolveAboutEdge<br>[367, 406, 0]"]
|
||||||
%% face_code_ref=Missing NodePath
|
%% [ProgramBodyItem { index: 1 }, VariableDeclarationDeclaration, VariableDeclarationInit, PipeBodyItem { index: 6 }]
|
||||||
17[Wall]
|
17[Wall]
|
||||||
%% face_code_ref=Missing NodePath
|
%% face_code_ref=Missing NodePath
|
||||||
18[Wall]
|
18[Wall]
|
||||||
%% face_code_ref=Missing NodePath
|
%% face_code_ref=Missing NodePath
|
||||||
19[Wall]
|
19[Wall]
|
||||||
|
%% face_code_ref=Missing NodePath
|
||||||
|
20[Wall]
|
||||||
%% face_code_ref=[ProgramBodyItem { index: 1 }, VariableDeclarationDeclaration, VariableDeclarationInit, PipeBodyItem { index: 0 }]
|
%% face_code_ref=[ProgramBodyItem { index: 1 }, VariableDeclarationDeclaration, VariableDeclarationInit, PipeBodyItem { index: 0 }]
|
||||||
20["Cap Start"]
|
21["Cap Start"]
|
||||||
%% face_code_ref=Missing NodePath
|
%% face_code_ref=Missing NodePath
|
||||||
21["Cap End"]
|
22["Cap End"]
|
||||||
%% face_code_ref=Missing NodePath
|
%% face_code_ref=Missing NodePath
|
||||||
22["SweepEdge Opposite"]
|
|
||||||
23["SweepEdge Opposite"]
|
23["SweepEdge Opposite"]
|
||||||
24["SweepEdge Opposite"]
|
24["SweepEdge Opposite"]
|
||||||
25["SweepEdge Opposite"]
|
25["SweepEdge Opposite"]
|
||||||
26["SweepEdge Adjacent"]
|
26["SweepEdge Opposite"]
|
||||||
27["SweepEdge Adjacent"]
|
27["SweepEdge Adjacent"]
|
||||||
28["SweepEdge Adjacent"]
|
28["SweepEdge Adjacent"]
|
||||||
29["SweepEdge Adjacent"]
|
29["SweepEdge Adjacent"]
|
||||||
|
30["SweepEdge Adjacent"]
|
||||||
1 --- 3
|
1 --- 3
|
||||||
19 x--> 2
|
20 x--> 2
|
||||||
3 --- 5
|
3 --- 5
|
||||||
3 --- 6
|
3 --- 6
|
||||||
3 --- 7
|
3 --- 7
|
||||||
@ -65,24 +67,24 @@ flowchart LR
|
|||||||
4 --- 11
|
4 --- 11
|
||||||
4 --- 12
|
4 --- 12
|
||||||
4 --- 14
|
4 --- 14
|
||||||
19 --- 4
|
4 ---- 16
|
||||||
5 --- 18
|
20 --- 4
|
||||||
5 x--> 20
|
5 --- 19
|
||||||
5 --- 25
|
5 x--> 21
|
||||||
5 --- 29
|
5 --- 26
|
||||||
6 --- 16
|
5 --- 30
|
||||||
6 x--> 20
|
6 --- 17
|
||||||
6 --- 24
|
6 x--> 21
|
||||||
6 --- 28
|
6 --- 25
|
||||||
7 --- 19
|
6 --- 29
|
||||||
7 x--> 20
|
7 --- 20
|
||||||
7 --- 23
|
7 x--> 21
|
||||||
7 --- 27
|
7 --- 24
|
||||||
8 --- 17
|
7 --- 28
|
||||||
8 x--> 20
|
8 --- 18
|
||||||
8 --- 22
|
8 x--> 21
|
||||||
8 --- 26
|
8 --- 23
|
||||||
15 --- 16
|
8 --- 27
|
||||||
15 --- 17
|
15 --- 17
|
||||||
15 --- 18
|
15 --- 18
|
||||||
15 --- 19
|
15 --- 19
|
||||||
@ -96,20 +98,21 @@ flowchart LR
|
|||||||
15 --- 27
|
15 --- 27
|
||||||
15 --- 28
|
15 --- 28
|
||||||
15 --- 29
|
15 --- 29
|
||||||
16 --- 24
|
15 --- 30
|
||||||
16 --- 28
|
17 --- 25
|
||||||
29 <--x 16
|
17 --- 29
|
||||||
17 --- 22
|
30 <--x 17
|
||||||
17 --- 26
|
18 --- 23
|
||||||
27 <--x 17
|
18 --- 27
|
||||||
18 --- 25
|
28 <--x 18
|
||||||
26 <--x 18
|
19 --- 26
|
||||||
18 --- 29
|
27 <--x 19
|
||||||
19 --- 23
|
19 --- 30
|
||||||
19 --- 27
|
20 --- 24
|
||||||
28 <--x 19
|
20 --- 28
|
||||||
22 <--x 21
|
29 <--x 20
|
||||||
23 <--x 21
|
23 <--x 22
|
||||||
24 <--x 21
|
24 <--x 22
|
||||||
25 <--x 21
|
25 <--x 22
|
||||||
|
26 <--x 22
|
||||||
```
|
```
|
||||||
|
@ -4,23 +4,11 @@ description: Error from executing error_revolve_on_edge_get_edge.kcl
|
|||||||
---
|
---
|
||||||
KCL Engine error
|
KCL Engine error
|
||||||
|
|
||||||
× engine: Solid3D revolve failed: sketch profile must lie entirely on one
|
× engine: Entity found but it was of the wrong type
|
||||||
│ side of the revolution axis
|
│ No such edge exists, cannot retrieve adjacency information.
|
||||||
╭─[15:6]
|
╭─[15:6]
|
||||||
14 │ |> close()
|
14 │ |> close()
|
||||||
15 │ |> revolve(axis = revolveAxis, angle = 90)
|
15 │ |> revolve(axis = revolveAxis, angle = 90)
|
||||||
· ───────────────────┬───────────────────┬
|
· ───────────────────┬───────────────────
|
||||||
· ╰── tests/error_revolve_on_edge_get_edge/input.kcl
|
|
||||||
· ╰── 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
|
|
||||||
╰────
|
|
||||||
|
@ -110,7 +110,6 @@ description: Operations executed error_revolve_on_edge_get_edge.kcl
|
|||||||
"sourceRange": []
|
"sourceRange": []
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"sourceRange": [],
|
"sourceRange": []
|
||||||
"isError": true
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
source: kcl-lib/src/simulation_tests.rs
|
||||||
|
description: Artifact commands export_only_at_top_level.kcl
|
||||||
|
---
|
||||||
|
[]
|
@ -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
|
||||||
|
---
|
@ -0,0 +1,3 @@
|
|||||||
|
```mermaid
|
||||||
|
flowchart LR
|
||||||
|
```
|
148
rust/kcl-lib/tests/export_var_only_at_top_level/ast.snap
Normal 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
|
||||||
|
}
|
||||||
|
}
|
@ -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
|
||||||
|
╰────
|
@ -0,0 +1,6 @@
|
|||||||
|
fn main() {
|
||||||
|
export x = 2
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
main()
|
5
rust/kcl-lib/tests/export_var_only_at_top_level/ops.snap
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
source: kcl-lib/src/simulation_tests.rs
|
||||||
|
description: Operations executed export_only_at_top_level.kcl
|
||||||
|
---
|
||||||
|
[]
|
@ -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()
|
Before Width: | Height: | Size: 99 KiB After Width: | Height: | Size: 99 KiB |
@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
@ -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
|
||||||
|
---
|
@ -0,0 +1,3 @@
|
|||||||
|
```mermaid
|
||||||
|
flowchart LR
|
||||||
|
```
|
129
rust/kcl-lib/tests/import_only_at_top_level/ast.snap
Normal 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
|
||||||
|
}
|
||||||
|
}
|
@ -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
|
||||||
|
╰────
|
6
rust/kcl-lib/tests/import_only_at_top_level/input.kcl
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
fn main() {
|
||||||
|
import "empty.kcl"
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
main()
|
32
rust/kcl-lib/tests/import_only_at_top_level/ops.snap
Normal 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"
|
||||||
|
}
|
||||||
|
]
|
10
rust/kcl-lib/tests/import_only_at_top_level/unparsed.snap
Normal 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()
|
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
source: kcl-lib/src/simulation_tests.rs
|
||||||
|
description: Result of unparsing tests/import_only_at_top_level/empty.kcl
|
||||||
|
---
|
||||||
|
|
@ -661,19 +661,19 @@ flowchart LR
|
|||||||
84 --- 144
|
84 --- 144
|
||||||
84 --- 237
|
84 --- 237
|
||||||
86 --- 168
|
86 --- 168
|
||||||
86 x--> 188
|
86 x--> 189
|
||||||
86 --- 212
|
86 --- 212
|
||||||
86 --- 256
|
86 --- 256
|
||||||
88 --- 169
|
88 --- 169
|
||||||
88 x--> 188
|
88 x--> 189
|
||||||
88 --- 213
|
88 --- 213
|
||||||
88 --- 257
|
88 --- 257
|
||||||
90 --- 167
|
90 --- 167
|
||||||
90 x--> 188
|
90 x--> 189
|
||||||
90 --- 214
|
90 --- 214
|
||||||
90 --- 258
|
90 --- 258
|
||||||
92 --- 170
|
92 --- 170
|
||||||
92 x--> 188
|
92 x--> 189
|
||||||
92 --- 215
|
92 --- 215
|
||||||
92 --- 259
|
92 --- 259
|
||||||
119 --- 133
|
119 --- 133
|
||||||
@ -955,10 +955,10 @@ flowchart LR
|
|||||||
218 <--x 186
|
218 <--x 186
|
||||||
219 <--x 186
|
219 <--x 186
|
||||||
194 <--x 187
|
194 <--x 187
|
||||||
212 <--x 189
|
212 <--x 188
|
||||||
213 <--x 189
|
213 <--x 188
|
||||||
214 <--x 189
|
214 <--x 188
|
||||||
215 <--x 189
|
215 <--x 188
|
||||||
220 <--x 275
|
220 <--x 275
|
||||||
223 <--x 270
|
223 <--x 270
|
||||||
224 <--x 274
|
224 <--x 274
|
||||||
|