Compare commits

..

4 Commits

50 changed files with 6505 additions and 1638 deletions

View File

@ -5,24 +5,16 @@
}, },
"plugins": [ "plugins": [
"css-modules", "css-modules",
"jest",
"react",
"suggest-no-throw", "suggest-no-throw",
"@typescript-eslint"
], ],
"extends": [ "extends": [
"react-app",
"react-app/jest",
"plugin:css-modules/recommended" "plugin:css-modules/recommended"
], ],
"rules": { "rules": {
"@typescript-eslint/no-floating-promises": "error", "@typescript-eslint/no-floating-promises": "error",
"@typescript-eslint/no-misused-promises": "error", "@typescript-eslint/no-misused-promises": "error",
"no-restricted-globals": [
"error",
{
"name": "isNaN",
"message": "Use Number.isNaN() instead."
}
],
"semi": [ "semi": [
"error", "error",
"never" "never"

View File

@ -21,7 +21,7 @@ if [[ ! -f "test-results/.last-run.json" ]]; then
fi fi
retry=1 retry=1
max_retrys=5 max_retrys=4
# retry failed tests, doing our own retries because using inbuilt playwright retries causes connection issues # retry failed tests, doing our own retries because using inbuilt playwright retries causes connection issues
while [[ $retry -le $max_retrys ]]; do while [[ $retry -le $max_retrys ]]; do

View File

@ -59,6 +59,7 @@ layout: manual
* [`legAngX`](kcl/legAngX) * [`legAngX`](kcl/legAngX)
* [`legAngY`](kcl/legAngY) * [`legAngY`](kcl/legAngY)
* [`legLen`](kcl/legLen) * [`legLen`](kcl/legLen)
* [`len`](kcl/len)
* [`line`](kcl/line) * [`line`](kcl/line)
* [`lineTo`](kcl/lineTo) * [`lineTo`](kcl/lineTo)
* [`ln`](kcl/ln) * [`ln`](kcl/ln)

37
docs/kcl/len.md Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@ -14,7 +14,6 @@ export class ToolbarFixture {
extrudeButton!: Locator extrudeButton!: Locator
loftButton!: Locator loftButton!: Locator
sweepButton!: Locator
shellButton!: Locator shellButton!: Locator
offsetPlaneButton!: Locator offsetPlaneButton!: Locator
startSketchBtn!: Locator startSketchBtn!: Locator
@ -41,7 +40,6 @@ export class ToolbarFixture {
this.page = page this.page = page
this.extrudeButton = page.getByTestId('extrude') this.extrudeButton = page.getByTestId('extrude')
this.loftButton = page.getByTestId('loft') this.loftButton = page.getByTestId('loft')
this.sweepButton = page.getByTestId('sweep')
this.shellButton = page.getByTestId('shell') this.shellButton = page.getByTestId('shell')
this.offsetPlaneButton = page.getByTestId('plane-offset') this.offsetPlaneButton = page.getByTestId('plane-offset')
this.startSketchBtn = page.getByTestId('sketch') this.startSketchBtn = page.getByTestId('sketch')

View File

@ -756,17 +756,6 @@ test(`Offset plane point-and-click`, async ({
}) })
await scene.expectPixelColor([74, 74, 74], testPoint, 15) await scene.expectPixelColor([74, 74, 74], testPoint, 15)
}) })
await test.step('Delete offset plane via feature tree selection', async () => {
await editor.closePane()
const operationButton = await toolbar.getFeatureTreeOperation(
'Offset Plane',
0
)
await operationButton.click({ button: 'left' })
await page.keyboard.press('Backspace')
await scene.expectPixelColor([50, 51, 96], testPoint, 15)
})
}) })
const loftPointAndClickCases = [ const loftPointAndClickCases = [
@ -862,173 +851,6 @@ loftPointAndClickCases.forEach(({ shouldPreselect }) => {
}) })
await scene.expectPixelColor([89, 89, 89], testPoint, 15) await scene.expectPixelColor([89, 89, 89], testPoint, 15)
}) })
await test.step('Delete loft via feature tree selection', async () => {
await editor.closePane()
const operationButton = await toolbar.getFeatureTreeOperation('Loft', 0)
await operationButton.click({ button: 'left' })
await page.keyboard.press('Backspace')
await scene.expectPixelColor([254, 254, 254], testPoint, 15)
})
})
})
// TODO: merge with above test. Right now we're not able to delete a loft
// right after creation via selection for some reason, so we go with a new instance
test('Loft and offset plane deletion via selection', async ({
context,
page,
homePage,
scene,
}) => {
const initialCode = `sketch001 = startSketchOn('XZ')
|> circle({ center = [0, 0], radius = 30 }, %)
plane001 = offsetPlane('XZ', 50)
sketch002 = startSketchOn(plane001)
|> circle({ center = [0, 0], radius = 20 }, %)
loft001 = loft([sketch001, sketch002])
`
await context.addInitScript((initialCode) => {
localStorage.setItem('persistCode', initialCode)
}, initialCode)
await page.setBodyDimensions({ width: 1000, height: 500 })
await homePage.goToModelingScene()
// One dumb hardcoded screen pixel value
const testPoint = { x: 575, y: 200 }
const [clickOnSketch1] = scene.makeMouseHelpers(testPoint.x, testPoint.y)
const [clickOnSketch2] = scene.makeMouseHelpers(testPoint.x, testPoint.y + 80)
await test.step(`Delete loft`, async () => {
// Check for loft
await scene.expectPixelColor([89, 89, 89], testPoint, 15)
await clickOnSketch1()
await expect(page.locator('.cm-activeLine')).toHaveText(`
|> circle({ center = [0, 0], radius = 30 }, %)
`)
await page.keyboard.press('Backspace')
// Check for sketch 1
await scene.expectPixelColor([254, 254, 254], testPoint, 15)
})
await test.step('Delete sketch002', async () => {
await page.waitForTimeout(1000)
await clickOnSketch2()
await expect(page.locator('.cm-activeLine')).toHaveText(`
|> circle({ center = [0, 0], radius = 20 }, %)
`)
await page.keyboard.press('Backspace')
// Check for plane001
await scene.expectPixelColor([228, 228, 228], testPoint, 15)
})
await test.step('Delete plane001', async () => {
await page.waitForTimeout(1000)
await clickOnSketch2()
await expect(page.locator('.cm-activeLine')).toHaveText(`
plane001 = offsetPlane('XZ', 50)
`)
await page.keyboard.press('Backspace')
// Check for sketch 1
await scene.expectPixelColor([254, 254, 254], testPoint, 15)
})
})
test(`Sweep point-and-click`, async ({
context,
page,
homePage,
scene,
editor,
toolbar,
cmdBar,
}) => {
const initialCode = `sketch001 = startSketchOn('YZ')
|> circle({
center = [0, 0],
radius = 500
}, %)
sketch002 = startSketchOn('XZ')
|> startProfileAt([0, 0], %)
|> xLine(-500, %)
|> tangentialArcTo([-2000, 500], %)
`
await context.addInitScript((initialCode) => {
localStorage.setItem('persistCode', initialCode)
}, initialCode)
await page.setBodyDimensions({ width: 1000, height: 500 })
await homePage.goToModelingScene()
await scene.waitForExecutionDone()
// One dumb hardcoded screen pixel value
const testPoint = { x: 700, y: 250 }
const [clickOnSketch1] = scene.makeMouseHelpers(testPoint.x, testPoint.y)
const [clickOnSketch2] = scene.makeMouseHelpers(testPoint.x - 50, testPoint.y)
const sweepDeclaration = 'sweep001 = sweep({ path = sketch002 }, sketch001)'
await test.step(`Look for sketch001`, async () => {
await toolbar.closePane('code')
await scene.expectPixelColor([53, 53, 53], testPoint, 15)
})
await test.step(`Go through the command bar flow`, async () => {
await toolbar.sweepButton.click()
await cmdBar.expectState({
commandName: 'Sweep',
currentArgKey: 'profile',
currentArgValue: '',
headerArguments: {
Path: '',
Profile: '',
},
highlightedHeaderArg: 'profile',
stage: 'arguments',
})
await clickOnSketch1()
await cmdBar.expectState({
commandName: 'Sweep',
currentArgKey: 'path',
currentArgValue: '',
headerArguments: {
Path: '',
Profile: '1 face',
},
highlightedHeaderArg: 'path',
stage: 'arguments',
})
await clickOnSketch2()
await cmdBar.expectState({
commandName: 'Sweep',
headerArguments: {
Path: '1 face',
Profile: '1 face',
},
stage: 'review',
})
await cmdBar.progressCmdBar()
})
await test.step(`Confirm code is added to the editor, scene has changed`, async () => {
await scene.expectPixelColor([135, 64, 73], testPoint, 15)
await toolbar.openPane('code')
await editor.expectEditor.toContain(sweepDeclaration)
await editor.expectState({
diagnostics: [],
activeLines: [sweepDeclaration],
highlightedCode: '',
})
await toolbar.closePane('code')
})
await test.step('Delete sweep via feature tree selection', async () => {
await toolbar.openPane('feature-tree')
await page.waitForTimeout(500)
const operationButton = await toolbar.getFeatureTreeOperation('Sweep', 0)
await operationButton.click({ button: 'left' })
await page.keyboard.press('Backspace')
await page.waitForTimeout(500)
await toolbar.closePane('feature-tree')
await scene.expectPixelColor([53, 53, 53], testPoint, 15)
}) })
}) })
@ -1208,104 +1030,4 @@ extrude001 = extrude(40, sketch001)
}) })
await scene.expectPixelColor([49, 49, 49], testPoint, 15) await scene.expectPixelColor([49, 49, 49], testPoint, 15)
}) })
await test.step('Delete shell via feature tree selection', async () => {
await editor.closePane()
const operationButton = await toolbar.getFeatureTreeOperation('Shell', 0)
await operationButton.click({ button: 'left' })
await page.keyboard.press('Backspace')
await scene.expectPixelColor([99, 99, 99], testPoint, 15)
})
})
const shellSketchOnFacesCases = [
`sketch001 = startSketchOn('XZ')
|> circle({ center = [0, 0], radius = 100 }, %)
|> extrude(100, %)
sketch002 = startSketchOn(sketch001, 'END')
|> circle({ center = [0, 0], radius = 50 }, %)
|> extrude(50, %)
`,
`sketch001 = startSketchOn('XZ')
|> circle({ center = [0, 0], radius = 100 }, %)
extrude001 = extrude(100, sketch001)
sketch002 = startSketchOn(extrude001, 'END')
|> circle({ center = [0, 0], radius = 50 }, %)
extrude002 = extrude(50, sketch002)
`,
]
shellSketchOnFacesCases.forEach((initialCode, index) => {
const hasExtrudesInPipe = index === 0
test(`Shell point-and-click sketch on face (extrudes in pipes: ${hasExtrudesInPipe})`, async ({
context,
page,
homePage,
scene,
editor,
toolbar,
cmdBar,
}) => {
await context.addInitScript((initialCode) => {
localStorage.setItem('persistCode', initialCode)
}, initialCode)
await page.setBodyDimensions({ width: 1000, height: 500 })
await homePage.goToModelingScene()
await scene.waitForExecutionDone()
// One dumb hardcoded screen pixel value
const testPoint = { x: 550, y: 295 }
const [clickOnCap] = scene.makeMouseHelpers(testPoint.x, testPoint.y)
const shellDeclaration = `shell001 = shell({ faces = ['end'], thickness = 5 }, ${
hasExtrudesInPipe ? 'sketch002' : 'extrude002'
})`
await test.step(`Look for the grey of the shape`, async () => {
await toolbar.closePane('code')
await scene.expectPixelColor([128, 128, 128], testPoint, 15)
})
await test.step(`Go through the command bar flow, selecting a cap and keeping default thickness`, async () => {
await toolbar.shellButton.click()
await cmdBar.expectState({
stage: 'arguments',
currentArgKey: 'selection',
currentArgValue: '',
headerArguments: {
Selection: '',
Thickness: '',
},
highlightedHeaderArg: 'selection',
commandName: 'Shell',
})
await clickOnCap()
await page.waitForTimeout(500)
await cmdBar.progressCmdBar()
await page.waitForTimeout(500)
await cmdBar.progressCmdBar()
await page.waitForTimeout(500)
await cmdBar.expectState({
stage: 'review',
headerArguments: {
Selection: '1 cap',
Thickness: '5',
},
commandName: 'Shell',
})
await cmdBar.progressCmdBar()
})
await test.step(`Confirm code is added to the editor, scene has changed`, async () => {
await toolbar.openPane('code')
await editor.expectEditor.toContain(shellDeclaration)
await editor.expectState({
diagnostics: [],
activeLines: [shellDeclaration],
highlightedCode: '',
})
await toolbar.closePane('code')
await scene.expectPixelColor([73, 73, 73], testPoint, 15)
})
})
}) })

18
flake.lock generated
View File

@ -2,11 +2,11 @@
"nodes": { "nodes": {
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1736320768, "lastModified": 1721933792,
"narHash": "sha256-nIYdTAiKIGnFNugbomgBJR+Xv5F1ZQU+HfaBqJKroC0=", "narHash": "sha256-zYVwABlQnxpbaHMfX6Wt9jhyQstFYwN2XjleOJV3VVg=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "4bc9c909d9ac828a039f288cf872d16d38185db8", "rev": "2122a9b35b35719ad9a395fe783eabb092df01b1",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -18,11 +18,11 @@
}, },
"nixpkgs_2": { "nixpkgs_2": {
"locked": { "locked": {
"lastModified": 1728538411, "lastModified": 1718428119,
"narHash": "sha256-f0SBJz1eZ2yOuKUr5CA9BHULGXVSn6miBuUWdTyhUhU=", "narHash": "sha256-WdWDpNaq6u1IPtxtYHHWpl5BmabtpmLnMAx0RdJ/vo8=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "b69de56fac8c2b6f8fd27f2eca01dcda8e0a4221", "rev": "e6cea36f83499eb4e9cd184c8a8e823296b50ad5",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -43,11 +43,11 @@
"nixpkgs": "nixpkgs_2" "nixpkgs": "nixpkgs_2"
}, },
"locked": { "locked": {
"lastModified": 1736476219, "lastModified": 1721960387,
"narHash": "sha256-+qyv3QqdZCdZ3cSO/cbpEY6tntyYjfe1bB12mdpNFaY=", "narHash": "sha256-o21ax+745ETGXrcgc/yUuLw1SI77ymp3xEpJt+w/kks=",
"owner": "oxalica", "owner": "oxalica",
"repo": "rust-overlay", "repo": "rust-overlay",
"rev": "de30cc5963da22e9742bbbbb9a3344570ed237b9", "rev": "9cbf831c5b20a53354fc12758abd05966f9f1699",
"type": "github" "type": "github"
}, },
"original": { "original": {

View File

@ -26,7 +26,7 @@
"@fortawesome/react-fontawesome": "^0.2.0", "@fortawesome/react-fontawesome": "^0.2.0",
"@headlessui/react": "^1.7.19", "@headlessui/react": "^1.7.19",
"@headlessui/tailwindcss": "^0.2.0", "@headlessui/tailwindcss": "^0.2.0",
"@kittycad/lib": "2.0.13", "@kittycad/lib": "2.0.12",
"@lezer/highlight": "^1.2.1", "@lezer/highlight": "^1.2.1",
"@lezer/lr": "^1.4.1", "@lezer/lr": "^1.4.1",
"@react-hook/resize-observer": "^2.0.1", "@react-hook/resize-observer": "^2.0.1",
@ -91,8 +91,8 @@
"build:wasm": "yarn wasm-prep && cd src/wasm-lib && wasm-pack build --release --target web --out-dir pkg && cargo test -p kcl-lib export_bindings && cd ../.. && yarn isomorphic-copy-wasm && yarn fmt", "build:wasm": "yarn wasm-prep && cd src/wasm-lib && wasm-pack build --release --target web --out-dir pkg && cargo test -p kcl-lib export_bindings && cd ../.. && yarn isomorphic-copy-wasm && yarn fmt",
"remove-importmeta": "sed -i 's/import.meta.url/window.location.origin/g' \"./src/wasm-lib/pkg/wasm_lib.js\"; sed -i '' 's/import.meta.url/window.location.origin/g' \"./src/wasm-lib/pkg/wasm_lib.js\" || echo \"sed for both mac and linux\"", "remove-importmeta": "sed -i 's/import.meta.url/window.location.origin/g' \"./src/wasm-lib/pkg/wasm_lib.js\"; sed -i '' 's/import.meta.url/window.location.origin/g' \"./src/wasm-lib/pkg/wasm_lib.js\" || echo \"sed for both mac and linux\"",
"wasm-prep": "rimraf src/wasm-lib/pkg && mkdirp src/wasm-lib/pkg && rimraf src/wasm-lib/kcl/bindings", "wasm-prep": "rimraf src/wasm-lib/pkg && mkdirp src/wasm-lib/pkg && rimraf src/wasm-lib/kcl/bindings",
"lint-fix": "eslint --fix --ext .ts --ext .tsx src e2e packages/codemirror-lsp-client/src", "lint-fix": "eslint --fix src e2e packages/codemirror-lsp-client",
"lint": "eslint --max-warnings 0 --ext .ts --ext .tsx src e2e packages/codemirror-lsp-client/src", "lint": "eslint --max-warnings 0 src e2e packages/codemirror-lsp-client",
"files:set-version": "echo \"$(jq --arg v \"$VERSION\" '.version=$v' package.json --indent 2)\" > package.json", "files:set-version": "echo \"$(jq --arg v \"$VERSION\" '.version=$v' package.json --indent 2)\" > package.json",
"files:set-notes": "./scripts/set-files-notes.sh", "files:set-notes": "./scripts/set-files-notes.sh",
"files:flip-to-nightly": "./scripts/flip-files-to-nightly.sh", "files:flip-to-nightly": "./scripts/flip-files-to-nightly.sh",
@ -171,6 +171,8 @@
"@types/uuid": "^9.0.8", "@types/uuid": "^9.0.8",
"@types/wicg-file-system-access": "^2023.10.5", "@types/wicg-file-system-access": "^2023.10.5",
"@types/ws": "^8.5.13", "@types/ws": "^8.5.13",
"@typescript-eslint/eslint-plugin": "^5.0.0",
"@typescript-eslint/parser": "^5.0.0",
"@vitejs/plugin-react": "^4.3.0", "@vitejs/plugin-react": "^4.3.0",
"@vitest/web-worker": "^1.5.0", "@vitest/web-worker": "^1.5.0",
"@xstate/cli": "^0.5.17", "@xstate/cli": "^0.5.17",
@ -180,10 +182,9 @@
"electron-builder": "24.13.3", "electron-builder": "24.13.3",
"electron-notarize": "1.2.2", "electron-notarize": "1.2.2",
"eslint": "^8.0.1", "eslint": "^8.0.1",
"eslint-config-react-app": "^7.0.1",
"eslint-plugin-css-modules": "^2.12.0", "eslint-plugin-css-modules": "^2.12.0",
"eslint-plugin-import": "^2.30.0", "eslint-plugin-import": "^2.30.0",
"eslint-plugin-jest": "^28.10.0",
"eslint-plugin-react": "^7.37.3",
"eslint-plugin-suggest-no-throw": "^1.0.0", "eslint-plugin-suggest-no-throw": "^1.0.0",
"happy-dom": "^16.3.0", "happy-dom": "^16.3.0",
"http-server": "^14.1.1", "http-server": "^14.1.1",
@ -199,7 +200,6 @@
"tailwindcss": "^3.4.1", "tailwindcss": "^3.4.1",
"ts-node": "^10.0.0", "ts-node": "^10.0.0",
"typescript": "^5.7.2", "typescript": "^5.7.2",
"typescript-eslint": "^8.19.1",
"vite": "^5.4.6", "vite": "^5.4.6",
"vite-plugin-package-version": "^1.1.0", "vite-plugin-package-version": "^1.1.0",
"vite-tsconfig-paths": "^4.3.2", "vite-tsconfig-paths": "^4.3.2",

View File

@ -42,7 +42,7 @@ export default class StreamDemuxer extends Queue<Uint8Array> {
// try to parse the content-length from the headers // try to parse the content-length from the headers
const length = parseInt(match[1]) const length = parseInt(match[1])
if (Number.isNaN(length)) if (isNaN(length))
return Promise.reject(new Error('invalid content length')) return Promise.reject(new Error('invalid content length'))
// slice the headers since we now have the content length // slice the headers since we now have the content length

View File

@ -368,20 +368,13 @@ export class LanguageServerPlugin implements PluginValue {
sortText, sortText,
filterText, filterText,
}) => { }) => {
const detailText = [
deprecated ? 'Deprecated' : undefined,
labelDetails ? labelDetails.detail : detail,
]
// Don't let undefined appear.
.filter(Boolean)
.join(' ')
const completion: Completion & { const completion: Completion & {
filterText: string filterText: string
sortText?: string sortText?: string
apply: string apply: string
} = { } = {
label, label,
detail: detailText, detail: labelDetails ? labelDetails.detail : detail,
apply: label, apply: label,
type: kind && CompletionItemKindMap[kind].toLowerCase(), type: kind && CompletionItemKindMap[kind].toLowerCase(),
sortText: sortText ?? label, sortText: sortText ?? label,
@ -389,11 +382,7 @@ export class LanguageServerPlugin implements PluginValue {
} }
if (documentation) { if (documentation) {
completion.info = () => { completion.info = () => {
const deprecatedHtml = deprecated const htmlString = formatMarkdownContents(documentation)
? '<p><strong>Deprecated</strong></p>'
: ''
const htmlString =
deprecatedHtml + formatMarkdownContents(documentation)
const htmlNode = document.createElement('div') const htmlNode = document.createElement('div')
htmlNode.style.display = 'contents' htmlNode.style.display = 'contents'
htmlNode.innerHTML = htmlString htmlNode.innerHTML = htmlString

View File

@ -32,9 +32,10 @@ export default defineConfig({
}, },
projects: [ projects: [
{ {
name: 'chromium', name: 'Google Chrome',
use: { use: {
...devices['Desktop Chrome'], ...devices['Desktop Chrome'],
channel: 'chrome',
contextOptions: { contextOptions: {
/* Chromium is the only one with these permission types */ /* Chromium is the only one with these permission types */
permissions: ['clipboard-write', 'clipboard-read'], permissions: ['clipboard-write', 'clipboard-read'],

View File

@ -157,38 +157,39 @@ export const ModelingMachineProvider = ({
'enable copilot': () => { 'enable copilot': () => {
editorManager.setCopilotEnabled(true) editorManager.setCopilotEnabled(true)
}, },
'sketch exit execute': ({ context: { store } }) => { // tsc reports this typing as perfectly fine, but eslint is complaining.
// TODO: Remove this async callback. For some reason eslint wouldn't // It's actually nonsensical, so I'm quieting.
// let me disable @typescript-eslint/no-misused-promises for the line. // eslint-disable-next-line @typescript-eslint/no-misused-promises
;(async () => { 'sketch exit execute': async ({
// When cancelling the sketch mode we should disable sketch mode within the engine. context: { store },
await engineCommandManager.sendSceneCommand({ }): Promise<void> => {
type: 'modeling_cmd_req', // When cancelling the sketch mode we should disable sketch mode within the engine.
cmd_id: uuidv4(), await engineCommandManager.sendSceneCommand({
cmd: { type: 'sketch_mode_disable' }, type: 'modeling_cmd_req',
}) cmd_id: uuidv4(),
cmd: { type: 'sketch_mode_disable' },
})
sceneInfra.camControls.syncDirection = 'clientToEngine' sceneInfra.camControls.syncDirection = 'clientToEngine'
if (cameraProjection.current === 'perspective') { if (cameraProjection.current === 'perspective') {
await sceneInfra.camControls.snapToPerspectiveBeforeHandingBackControlToEngine() await sceneInfra.camControls.snapToPerspectiveBeforeHandingBackControlToEngine()
} }
sceneInfra.camControls.syncDirection = 'engineToClient' sceneInfra.camControls.syncDirection = 'engineToClient'
store.videoElement?.pause() store.videoElement?.pause()
return kclManager return kclManager
.executeCode() .executeCode()
.then(() => { .then(() => {
if (engineCommandManager.engineConnection?.idleMode) return if (engineCommandManager.engineConnection?.idleMode) return
store.videoElement?.play().catch((e) => { store.videoElement?.play().catch((e) => {
console.warn('Video playing was prevented', e) console.warn('Video playing was prevented', e)
})
}) })
.catch(reportRejection) })
})().catch(reportRejection) .catch(reportRejection)
}, },
'Set mouse state': assign(({ context, event }) => { 'Set mouse state': assign(({ context, event }) => {
if (event.type !== 'Set mouse state') return {} if (event.type !== 'Set mouse state') return {}
@ -270,7 +271,6 @@ export const ModelingMachineProvider = ({
cmd_id: uuidv4(), cmd_id: uuidv4(),
cmd: { cmd: {
type: 'default_camera_center_to_selection', type: 'default_camera_center_to_selection',
camera_movement: 'vantage',
}, },
}) })
.catch(reportRejection) .catch(reportRejection)

View File

@ -374,37 +374,6 @@ export function loftSketches(
} }
} }
export function addSweep(
node: Node<Program>,
profileDeclarator: VariableDeclarator,
pathDeclarator: VariableDeclarator
): {
modifiedAst: Node<Program>
pathToNode: PathToNode
} {
const modifiedAst = structuredClone(node)
const name = findUniqueName(node, KCL_DEFAULT_CONSTANT_PREFIXES.SWEEP)
const sweep = createCallExpressionStdLib('sweep', [
createObjectExpression({ path: createIdentifier(pathDeclarator.id.name) }),
createIdentifier(profileDeclarator.id.name),
])
const declaration = createVariableDeclaration(name, sweep)
modifiedAst.body.push(declaration)
const pathToNode: PathToNode = [
['body', ''],
[modifiedAst.body.length - 1, 'index'],
['declaration', 'VariableDeclaration'],
['init', 'VariableDeclarator'],
['arguments', 'CallExpression'],
[0, 'index'],
]
return {
modifiedAst,
pathToNode,
}
}
export function revolveSketch( export function revolveSketch(
node: Node<Program>, node: Node<Program>,
pathToNode: PathToNode, pathToNode: PathToNode,
@ -1180,17 +1149,11 @@ export async function deleteFromSelection(
((selection?.artifact?.type === 'wall' || ((selection?.artifact?.type === 'wall' ||
selection?.artifact?.type === 'cap') && selection?.artifact?.type === 'cap') &&
varDec.node.init.type === 'PipeExpression') || varDec.node.init.type === 'PipeExpression') ||
selection.artifact?.type === 'sweep' || selection.artifact?.type === 'sweep'
selection.artifact?.type === 'plane' ||
!selection.artifact // aka expected to be a shell at this point
) { ) {
let extrudeNameToDelete = '' let extrudeNameToDelete = ''
let pathToNode: PathToNode | null = null let pathToNode: PathToNode | null = null
if ( if (selection.artifact?.type !== 'sweep') {
selection.artifact &&
selection.artifact.type !== 'sweep' &&
selection.artifact.type !== 'plane'
) {
const varDecName = varDec.node.id.name const varDecName = varDec.node.id.name
traverse(astClone, { traverse(astClone, {
enter: (node, path) => { enter: (node, path) => {
@ -1206,17 +1169,6 @@ export async function deleteFromSelection(
pathToNode = path pathToNode = path
extrudeNameToDelete = dec.id.name extrudeNameToDelete = dec.id.name
} }
if (
dec.init.type === 'CallExpression' &&
dec.init.callee.name === 'loft' &&
dec.init.arguments?.[0].type === 'ArrayExpression' &&
dec.init.arguments?.[0].elements.some(
(a) => a.type === 'Identifier' && a.name === varDecName
)
) {
pathToNode = path
extrudeNameToDelete = dec.id.name
}
} }
}, },
}) })

View File

@ -29,9 +29,7 @@ export function revolveSketch(
pathToSketchNode: PathToNode, pathToSketchNode: PathToNode,
shouldPipe = false, shouldPipe = false,
angle: Expr = createLiteral(4), angle: Expr = createLiteral(4),
axisOrEdge: string, axis: Selections
axis: string,
edge: Selections
): ):
| { | {
modifiedAst: Node<Program> modifiedAst: Node<Program>
@ -43,34 +41,31 @@ export function revolveSketch(
const sketchNode = getNodeFromPath(clonedAst, pathToSketchNode) const sketchNode = getNodeFromPath(clonedAst, pathToSketchNode)
if (err(sketchNode)) return sketchNode if (err(sketchNode)) return sketchNode
let generatedAxis // testing code
const pathToAxisSelection = getNodePathFromSourceRange(
clonedAst,
axis.graphSelections[0]?.codeRef.range
)
if (axisOrEdge === 'Edge') { const lineNode = getNodeFromPath<CallExpression>(
const pathToAxisSelection = getNodePathFromSourceRange( clonedAst,
clonedAst, pathToAxisSelection,
edge.graphSelections[0]?.codeRef.range 'CallExpression'
) )
const lineNode = getNodeFromPath<CallExpression>( if (err(lineNode)) return lineNode
clonedAst,
pathToAxisSelection,
'CallExpression'
)
if (err(lineNode)) return lineNode
const tagResult = mutateAstWithTagForSketchSegment( // TODO Kevin: What if |> close(%)?
clonedAst, // TODO Kevin: What if opposite edge
pathToAxisSelection // TODO Kevin: What if the edge isn't planar to the sketch?
) // TODO Kevin: add a tag.
const tagResult = mutateAstWithTagForSketchSegment(
clonedAst,
pathToAxisSelection
)
// Have the tag whether it is already created or a new one is generated // Have the tag whether it is already created or a new one is generated
if (err(tagResult)) return tagResult if (err(tagResult)) return tagResult
const { tag } = tagResult const { tag } = tagResult
const axisSelection = edge?.graphSelections[0]?.artifact
if (!axisSelection) return new Error('Generated axis selection is missing.')
generatedAxis = getEdgeTagCall(tag, axisSelection)
} else {
generatedAxis = createLiteral(axis)
}
/* Original Code */ /* Original Code */
const { node: sketchExpression } = sketchNode const { node: sketchExpression } = sketchNode
@ -96,12 +91,14 @@ export function revolveSketch(
shallowPath: sketchPathToDecleration, shallowPath: sketchPathToDecleration,
} = sketchVariableDeclaratorNode } = sketchVariableDeclaratorNode
if (!generatedAxis) return new Error('Generated axis selection is missing.') const axisSelection = axis?.graphSelections[0]?.artifact
if (!axisSelection) return new Error('Axis selection is missing.')
const revolveCall = createCallExpressionStdLib('revolve', [ const revolveCall = createCallExpressionStdLib('revolve', [
createObjectExpression({ createObjectExpression({
angle: angle, angle: angle,
axis: generatedAxis, axis: getEdgeTagCall(tag, axisSelection),
}), }),
createIdentifier(sketchVariableDeclarator.id.name), createIdentifier(sketchVariableDeclarator.id.name),
]) ])

View File

@ -49,27 +49,17 @@ export function addShell({
return new Error("Couldn't find extrude") return new Error("Couldn't find extrude")
} }
pathToExtrudeNode = extrudeLookupResult.pathToExtrudeNode
// Get the sketch ref from the selection
// TODO: this assumes the segment is piped directly from the sketch, with no intermediate `VariableDeclarator` between. // TODO: this assumes the segment is piped directly from the sketch, with no intermediate `VariableDeclarator` between.
// We must find a technique for these situations that is robust to intermediate declarations // We must find a technique for these situations that is robust to intermediate declarations
const extrudeNode = getNodeFromPath<VariableDeclarator>( const sketchNode = getNodeFromPath<VariableDeclarator>(
modifiedAst, modifiedAst,
extrudeLookupResult.pathToExtrudeNode, graphSelection.codeRef.pathToNode,
'VariableDeclarator' 'VariableDeclarator'
) )
const segmentNode = getNodeFromPath<VariableDeclarator>( if (err(sketchNode)) {
modifiedAst, return sketchNode
extrudeLookupResult.pathToSegmentNode,
'VariableDeclarator'
)
if (err(extrudeNode) || err(segmentNode)) {
return new Error("Couldn't find extrude")
}
if (extrudeNode.node.init.type === 'CallExpression') {
pathToExtrudeNode = extrudeLookupResult.pathToExtrudeNode
} else if (segmentNode.node.init.type === 'PipeExpression') {
pathToExtrudeNode = extrudeLookupResult.pathToSegmentNode
} else {
return new Error("Couldn't find extrude")
} }
const selectedArtifact = graphSelection.artifact const selectedArtifact = graphSelection.artifact

View File

@ -77,7 +77,7 @@ interface SegmentArtifactRich extends BaseArtifact {
/** A Sweep is a more generic term for extrude, revolve, loft and sweep*/ /** A Sweep is a more generic term for extrude, revolve, loft and sweep*/
interface SweepArtifact extends BaseArtifact { interface SweepArtifact extends BaseArtifact {
type: 'sweep' type: 'sweep'
subType: 'extrusion' | 'revolve' | 'loft' | 'sweep' subType: 'extrusion' | 'revolve'
pathId: string pathId: string
surfaceIds: Array<string> surfaceIds: Array<string>
edgeIds: Array<string> edgeIds: Array<string>
@ -85,7 +85,7 @@ interface SweepArtifact extends BaseArtifact {
} }
interface SweepArtifactRich extends BaseArtifact { interface SweepArtifactRich extends BaseArtifact {
type: 'sweep' type: 'sweep'
subType: 'extrusion' | 'revolve' | 'loft' | 'sweep' subType: 'extrusion' | 'revolve'
path: PathArtifact path: PathArtifact
surfaces: Array<WallArtifact | CapArtifact> surfaces: Array<WallArtifact | CapArtifact>
edges: Array<SweepEdge> edges: Array<SweepEdge>
@ -377,11 +377,7 @@ export function getArtifactsToUpdate({
}) })
} }
return returnArr return returnArr
} else if ( } else if (cmd.type === 'extrude' || cmd.type === 'revolve') {
cmd.type === 'extrude' ||
cmd.type === 'revolve' ||
cmd.type === 'sweep'
) {
const subType = cmd.type === 'extrude' ? 'extrusion' : cmd.type const subType = cmd.type === 'extrude' ? 'extrusion' : cmd.type
returnArr.push({ returnArr.push({
id, id,
@ -402,33 +398,6 @@ export function getArtifactsToUpdate({
artifact: { ...path, sweepId: id }, artifact: { ...path, sweepId: id },
}) })
return returnArr return returnArr
} else if (
cmd.type === 'loft' &&
response.type === 'modeling' &&
response.data.modeling_response.type === 'loft'
) {
returnArr.push({
id,
artifact: {
type: 'sweep',
subType: 'loft',
id,
// TODO: make sure to revisit this choice, don't think it matters for now
pathId: cmd.section_ids[0],
surfaceIds: [],
edgeIds: [],
codeRef: { range, pathToNode },
},
})
for (const sectionId of cmd.section_ids) {
const path = getArtifact(sectionId)
if (path?.type === 'path')
returnArr.push({
id: sectionId,
artifact: { ...path, sweepId: id },
})
}
return returnArr
} else if ( } else if (
cmd.type === 'solid3d_get_extrusion_face_info' && cmd.type === 'solid3d_get_extrusion_face_info' &&
response?.type === 'modeling' && response?.type === 'modeling' &&

View File

@ -37,10 +37,6 @@ export type ModelingCommandSchema = {
// result: (typeof EXTRUSION_RESULTS)[number] // result: (typeof EXTRUSION_RESULTS)[number]
distance: KclCommandValue distance: KclCommandValue
} }
Sweep: {
path: Selections
profile: Selections
}
Loft: { Loft: {
selection: Selections selection: Selections
} }
@ -51,9 +47,7 @@ export type ModelingCommandSchema = {
Revolve: { Revolve: {
selection: Selections selection: Selections
angle: KclCommandValue angle: KclCommandValue
axisOrEdge: string axis: Selections
axis: string
edge: Selections
} }
Fillet: { Fillet: {
// todo // todo
@ -296,33 +290,6 @@ export const modelingMachineCommandConfig: StateMachineCommandSetConfig<
}, },
}, },
}, },
Sweep: {
description:
'Create a 3D body by moving a sketch region along an arbitrary path.',
icon: 'sweep',
status: 'development',
needsReview: true,
args: {
profile: {
inputType: 'selection',
selectionTypes: ['solid2D'],
required: true,
skip: true,
multiple: false,
// TODO: add dry-run validation
warningMessage:
'The sweep workflow is new and under tested. Please break it and report issues.',
},
path: {
inputType: 'selection',
selectionTypes: ['segment', 'path'],
required: true,
skip: true,
multiple: false,
// TODO: add dry-run validation
},
},
},
Loft: { Loft: {
description: 'Create a 3D body by blending between two or more sketches', description: 'Create a 3D body by blending between two or more sketches',
icon: 'loft', icon: 'loft',
@ -357,10 +324,10 @@ export const modelingMachineCommandConfig: StateMachineCommandSetConfig<
}, },
}, },
}, },
// TODO: Update this configuration, copied from extrude for MVP of revolve, specifically the args.selection
Revolve: { Revolve: {
description: 'Create a 3D body by rotating a sketch region about an axis.', description: 'Create a 3D body by rotating a sketch region about an axis.',
icon: 'revolve', icon: 'revolve',
status: 'development',
needsReview: true, needsReview: true,
args: { args: {
selection: { selection: {
@ -369,34 +336,9 @@ export const modelingMachineCommandConfig: StateMachineCommandSetConfig<
multiple: false, // TODO: multiple selection multiple: false, // TODO: multiple selection
required: true, required: true,
skip: true, skip: true,
warningMessage:
'The revolve workflow is new and under tested. Please break it and report issues.',
},
axisOrEdge: {
inputType: 'options',
required: true,
defaultValue: 'Axis',
options: [
{ name: 'Axis', isCurrent: true, value: 'Axis' },
{ name: 'Edge', isCurrent: false, value: 'Edge' },
],
}, },
axis: { axis: {
required: (commandContext) => required: true,
['Axis'].includes(
commandContext.argumentsToSubmit.axisOrEdge as string
),
inputType: 'options',
options: [
{ name: 'X Axis', isCurrent: true, value: 'X' },
{ name: 'Y Axis', isCurrent: false, value: 'Y' },
],
},
edge: {
required: (commandContext) =>
['Edge'].includes(
commandContext.argumentsToSubmit.axisOrEdge as string
),
inputType: 'selection', inputType: 'selection',
selectionTypes: ['segment', 'sweepEdge', 'edgeCutEdge'], selectionTypes: ['segment', 'sweepEdge', 'edgeCutEdge'],
multiple: false, multiple: false,

View File

@ -68,7 +68,7 @@ export const revolveAxisValidator = async ({
} }
const sketchSelection = artifact.pathId const sketchSelection = artifact.pathId
let edgeSelection = data.edge.graphSelections[0].artifact?.id let edgeSelection = data.axis.graphSelections[0].artifact?.id
if (!sketchSelection) { if (!sketchSelection) {
return 'Unable to revolve, sketch is missing' return 'Unable to revolve, sketch is missing'
@ -101,7 +101,7 @@ export const revolveAxisValidator = async ({
return true return true
} else { } else {
// return error message for the toast // return error message for the toast
return 'Unable to revolve with selected edge' return 'Unable to revolve with selected axis'
} }
} }

View File

@ -53,7 +53,6 @@ export const KCL_DEFAULT_CONSTANT_PREFIXES = {
SKETCH: 'sketch', SKETCH: 'sketch',
EXTRUDE: 'extrude', EXTRUDE: 'extrude',
LOFT: 'loft', LOFT: 'loft',
SWEEP: 'sweep',
SHELL: 'shell', SHELL: 'shell',
SEGMENT: 'seg', SEGMENT: 'seg',
REVOLVE: 'revolve', REVOLVE: 'revolve',

View File

@ -15,7 +15,6 @@ import {
StateMachineCommandSetSchema, StateMachineCommandSetSchema,
} from './commandTypes' } from './commandTypes'
import { DEV } from 'env' import { DEV } from 'env'
import { IS_NIGHTLY_OR_DEBUG } from 'routes/Settings'
interface CreateMachineCommandProps< interface CreateMachineCommandProps<
T extends AnyStateMachine, T extends AnyStateMachine,
@ -85,7 +84,7 @@ export function createMachineCommand<
} else if ('status' in commandConfig) { } else if ('status' in commandConfig) {
const { status } = commandConfig const { status } = commandConfig
if (status === 'inactive') return null if (status === 'inactive') return null
if (status === 'development' && !(DEV || IS_NIGHTLY_OR_DEBUG)) return null if (status === 'development' && !DEV) return null
} }
const icon = ('icon' in commandConfig && commandConfig.icon) || undefined const icon = ('icon' in commandConfig && commandConfig.icon) || undefined

View File

@ -8,7 +8,6 @@ import {
modelingMachine, modelingMachine,
pipeHasCircle, pipeHasCircle,
} from 'machines/modelingMachine' } from 'machines/modelingMachine'
import { IS_NIGHTLY_OR_DEBUG } from 'routes/Settings'
import { EventFrom, StateFrom } from 'xstate' import { EventFrom, StateFrom } from 'xstate'
export type ToolbarModeName = 'modeling' | 'sketching' export type ToolbarModeName = 'modeling' | 'sketching'
@ -104,7 +103,7 @@ export const toolbarConfig: Record<ToolbarModeName, ToolbarMode> = {
data: { name: 'Revolve', groupId: 'modeling' }, data: { name: 'Revolve', groupId: 'modeling' },
}), }),
icon: 'revolve', icon: 'revolve',
status: DEV || IS_NIGHTLY_OR_DEBUG ? 'available' : 'kcl-only', status: DEV ? 'available' : 'kcl-only',
title: 'Revolve', title: 'Revolve',
hotkey: 'R', hotkey: 'R',
description: description:
@ -119,21 +118,17 @@ export const toolbarConfig: Record<ToolbarModeName, ToolbarMode> = {
}, },
{ {
id: 'sweep', id: 'sweep',
onClick: ({ commandBarSend }) => onClick: () => console.error('Sweep not yet implemented'),
commandBarSend({
type: 'Find and select command',
data: { name: 'Sweep', groupId: 'modeling' },
}),
icon: 'sweep', icon: 'sweep',
status: DEV || IS_NIGHTLY_OR_DEBUG ? 'available' : 'kcl-only', status: 'unavailable',
title: 'Sweep', title: 'Sweep',
hotkey: 'W', hotkey: 'W',
description: description:
'Create a 3D body by moving a sketch region along an arbitrary path.', 'Create a 3D body by moving a sketch region along an arbitrary path.',
links: [ links: [
{ {
label: 'KCL docs', label: 'GitHub discussion',
url: 'https://zoo.dev/docs/kcl/sweep', url: 'https://github.com/KittyCAD/modeling-app/discussions/498',
}, },
], ],
}, },
@ -166,7 +161,7 @@ export const toolbarConfig: Record<ToolbarModeName, ToolbarMode> = {
data: { name: 'Fillet', groupId: 'modeling' }, data: { name: 'Fillet', groupId: 'modeling' },
}), }),
icon: 'fillet3d', icon: 'fillet3d',
status: DEV || IS_NIGHTLY_OR_DEBUG ? 'available' : 'kcl-only', status: DEV ? 'available' : 'kcl-only',
title: 'Fillet', title: 'Fillet',
hotkey: 'F', hotkey: 'F',
description: 'Round the edges of a 3D solid.', description: 'Round the edges of a 3D solid.',

View File

@ -345,7 +345,7 @@ export function onDragNumberCalculation(text: string, e: MouseEvent) {
) )
const newVal = roundOff(addition, precision) const newVal = roundOff(addition, precision)
if (Number.isNaN(newVal)) { if (isNaN(newVal)) {
return return
} }

View File

@ -45,7 +45,6 @@ import {
import { revolveSketch } from 'lang/modifyAst/addRevolve' import { revolveSketch } from 'lang/modifyAst/addRevolve'
import { import {
addOffsetPlane, addOffsetPlane,
addSweep,
deleteFromSelection, deleteFromSelection,
extrudeSketch, extrudeSketch,
loftSketches, loftSketches,
@ -267,7 +266,6 @@ export type ModelingMachineEvent =
| { type: 'Export'; data: ModelingCommandSchema['Export'] } | { type: 'Export'; data: ModelingCommandSchema['Export'] }
| { type: 'Make'; data: ModelingCommandSchema['Make'] } | { type: 'Make'; data: ModelingCommandSchema['Make'] }
| { type: 'Extrude'; data?: ModelingCommandSchema['Extrude'] } | { type: 'Extrude'; data?: ModelingCommandSchema['Extrude'] }
| { type: 'Sweep'; data?: ModelingCommandSchema['Sweep'] }
| { type: 'Loft'; data?: ModelingCommandSchema['Loft'] } | { type: 'Loft'; data?: ModelingCommandSchema['Loft'] }
| { type: 'Shell'; data?: ModelingCommandSchema['Shell'] } | { type: 'Shell'; data?: ModelingCommandSchema['Shell'] }
| { type: 'Revolve'; data?: ModelingCommandSchema['Revolve'] } | { type: 'Revolve'; data?: ModelingCommandSchema['Revolve'] }
@ -687,7 +685,7 @@ export const modelingMachine = setup({
if (event.type !== 'Revolve') return if (event.type !== 'Revolve') return
;(async () => { ;(async () => {
if (!event.data) return if (!event.data) return
const { selection, angle, axis, edge, axisOrEdge } = event.data const { selection, angle, axis } = event.data
let ast = kclManager.ast let ast = kclManager.ast
if ( if (
'variableName' in angle && 'variableName' in angle &&
@ -712,9 +710,7 @@ export const modelingMachine = setup({
'variableName' in angle 'variableName' in angle
? angle.variableIdentifierAst ? angle.variableIdentifierAst
: angle.valueAst, : angle.valueAst,
axisOrEdge, axis
axis,
edge
) )
if (trap(revolveSketchRes)) return if (trap(revolveSketchRes)) return
const { modifiedAst, pathToRevolveArg } = revolveSketchRes const { modifiedAst, pathToRevolveArg } = revolveSketchRes
@ -1546,66 +1542,6 @@ export const modelingMachine = setup({
} }
} }
), ),
sweepAstMod: fromPromise(
async ({
input,
}: {
input: ModelingCommandSchema['Sweep'] | undefined
}) => {
if (!input) return new Error('No input provided')
// Extract inputs
const ast = kclManager.ast
const { profile, path } = input
// Find the profile declaration
const profileNodePath = getNodePathFromSourceRange(
ast,
profile.graphSelections[0].codeRef.range
)
const profileNode = getNodeFromPath<VariableDeclarator>(
ast,
profileNodePath,
'VariableDeclarator'
)
if (err(profileNode)) {
return new Error("Couldn't parse profile selection")
}
const profileDeclarator = profileNode.node
// Find the path declaration
const pathNodePath = getNodePathFromSourceRange(
ast,
path.graphSelections[0].codeRef.range
)
const pathNode = getNodeFromPath<VariableDeclarator>(
ast,
pathNodePath,
'VariableDeclarator'
)
if (err(pathNode)) {
return new Error("Couldn't parse path selection")
}
const pathDeclarator = pathNode.node
// Perform the sweep
const sweepRes = addSweep(ast, profileDeclarator, pathDeclarator)
const updateAstResult = await kclManager.updateAst(
sweepRes.modifiedAst,
true,
{
focusPath: [sweepRes.pathToNode],
}
)
await codeManager.updateEditorWithAstAndWriteToFile(
updateAstResult.newAst
)
if (updateAstResult?.selections) {
editorManager.selectRange(updateAstResult?.selections)
}
}
),
loftAstMod: fromPromise( loftAstMod: fromPromise(
async ({ async ({
input, input,
@ -1801,11 +1737,6 @@ export const modelingMachine = setup({
reenter: false, reenter: false,
}, },
Sweep: {
target: 'Applying sweep',
reenter: true,
},
Loft: { Loft: {
target: 'Applying loft', target: 'Applying loft',
reenter: true, reenter: true,
@ -2598,19 +2529,6 @@ export const modelingMachine = setup({
}, },
}, },
'Applying sweep': {
invoke: {
src: 'sweepAstMod',
id: 'sweepAstMod',
input: ({ event }) => {
if (event.type !== 'Sweep') return undefined
return event.data
},
onDone: ['idle'],
onError: ['idle'],
},
},
'Applying loft': { 'Applying loft': {
invoke: { invoke: {
src: 'loftAstMod', src: 'loftAstMod',

View File

@ -41,13 +41,13 @@ export default function Export() {
export to almost any CAD software. export to almost any CAD software.
</p> </p>
<p className="my-4"> <p className="my-4">
Our teammate Katie is working on the file format, check out{' '} Our teammate David is working on the file format, check out{' '}
<a <a
href="https://github.com/KhronosGroup/glTF/pull/2343" href="https://www.youtube.com/watch?v=8SuW0qkYCZo"
target="_blank" target="_blank"
rel="noreferrer noopener" rel="noreferrer noopener"
> >
her standards proposal on GitHub his talk with the Metaverse Standards Forum
</a> </a>
! !
</p> </p>

View File

@ -32,8 +32,6 @@ export const PACKAGE_NAME = isDesktop()
export const IS_NIGHTLY = PACKAGE_NAME.indexOf('-nightly') > -1 export const IS_NIGHTLY = PACKAGE_NAME.indexOf('-nightly') > -1
export const IS_NIGHTLY_OR_DEBUG = IS_NIGHTLY || APP_VERSION === '0.0.0'
export function getReleaseUrl(version: string = APP_VERSION) { export function getReleaseUrl(version: string = APP_VERSION) {
return `https://github.com/KittyCAD/modeling-app/releases/tag/${ return `https://github.com/KittyCAD/modeling-app/releases/tag/${
IS_NIGHTLY ? 'nightly-' : '' IS_NIGHTLY ? 'nightly-' : ''

View File

@ -502,6 +502,4 @@ impl kcl_lib::EngineManager for EngineConnection {
})), })),
} }
} }
async fn close(&self) {}
} }

View File

@ -37,10 +37,9 @@ enum SocketHealth {
} }
type WebSocketTcpWrite = futures::stream::SplitSink<tokio_tungstenite::WebSocketStream<reqwest::Upgraded>, WsMsg>; type WebSocketTcpWrite = futures::stream::SplitSink<tokio_tungstenite::WebSocketStream<reqwest::Upgraded>, WsMsg>;
#[derive(Debug)] #[derive(Debug, Clone)]
pub struct EngineConnection { pub struct EngineConnection {
engine_req_tx: mpsc::Sender<ToEngineReq>, engine_req_tx: mpsc::Sender<ToEngineReq>,
shutdown_tx: mpsc::Sender<()>,
responses: Arc<DashMap<uuid::Uuid, WebSocketResponse>>, responses: Arc<DashMap<uuid::Uuid, WebSocketResponse>>,
pending_errors: Arc<Mutex<Vec<String>>>, pending_errors: Arc<Mutex<Vec<String>>>,
#[allow(dead_code)] #[allow(dead_code)]
@ -131,49 +130,21 @@ struct ToEngineReq {
impl EngineConnection { impl EngineConnection {
/// Start waiting for incoming engine requests, and send each one over the WebSocket to the engine. /// Start waiting for incoming engine requests, and send each one over the WebSocket to the engine.
async fn start_write_actor( async fn start_write_actor(mut tcp_write: WebSocketTcpWrite, mut engine_req_rx: mpsc::Receiver<ToEngineReq>) {
mut tcp_write: WebSocketTcpWrite, while let Some(req) = engine_req_rx.recv().await {
mut engine_req_rx: mpsc::Receiver<ToEngineReq>, let ToEngineReq { req, request_sent } = req;
mut shutdown_rx: mpsc::Receiver<()>, let res = if let WebSocketRequest::ModelingCmdReq(ModelingCmdReq {
) { cmd: ModelingCmd::ImportFiles { .. },
loop { cmd_id: _,
tokio::select! { }) = &req
maybe_req = engine_req_rx.recv() => { {
match maybe_req { // Send it as binary.
Some(ToEngineReq { req, request_sent }) => { Self::inner_send_to_engine_binary(req, &mut tcp_write).await
// Decide whether to send as binary or text, } else {
// then send to the engine. Self::inner_send_to_engine(req, &mut tcp_write).await
let res = if let WebSocketRequest::ModelingCmdReq(ModelingCmdReq { };
cmd: ModelingCmd::ImportFiles { .. }, let _ = request_sent.send(res);
cmd_id: _,
}) = &req
{
Self::inner_send_to_engine_binary(req, &mut tcp_write).await
} else {
Self::inner_send_to_engine(req, &mut tcp_write).await
};
// Let the caller know weve sent the request (ok or error).
let _ = request_sent.send(res);
}
None => {
// The engine_req_rx channel has closed, so no more requests.
// We'll gracefully exit the loop and close the engine.
break;
}
}
},
// If we get a shutdown signal, close the engine immediately and return.
_ = shutdown_rx.recv() => {
let _ = Self::inner_close_engine(&mut tcp_write).await;
return;
}
}
} }
// If we exit the loop (e.g. engine_req_rx was closed),
// still gracefully close the engine before returning.
let _ = Self::inner_close_engine(&mut tcp_write).await; let _ = Self::inner_close_engine(&mut tcp_write).await;
} }
@ -223,8 +194,7 @@ impl EngineConnection {
let (tcp_write, tcp_read) = ws_stream.split(); let (tcp_write, tcp_read) = ws_stream.split();
let (engine_req_tx, engine_req_rx) = mpsc::channel(10); let (engine_req_tx, engine_req_rx) = mpsc::channel(10);
let (shutdown_tx, shutdown_rx) = mpsc::channel(1); tokio::task::spawn(Self::start_write_actor(tcp_write, engine_req_rx));
tokio::task::spawn(Self::start_write_actor(tcp_write, engine_req_rx, shutdown_rx));
let mut tcp_read = TcpRead { stream: tcp_read }; let mut tcp_read = TcpRead { stream: tcp_read };
@ -334,7 +304,6 @@ impl EngineConnection {
Ok(EngineConnection { Ok(EngineConnection {
engine_req_tx, engine_req_tx,
shutdown_tx,
tcp_read_handle: Arc::new(TcpReadHandle { tcp_read_handle: Arc::new(TcpReadHandle {
handle: Arc::new(tcp_read_handle), handle: Arc::new(tcp_read_handle),
}), }),
@ -515,15 +484,4 @@ impl EngineManager for EngineConnection {
fn get_session_data(&self) -> Option<ModelingSessionData> { fn get_session_data(&self) -> Option<ModelingSessionData> {
self.session_data.lock().unwrap().clone() self.session_data.lock().unwrap().clone()
} }
async fn close(&self) {
let _ = self.shutdown_tx.send(()).await;
loop {
if let Ok(guard) = self.socket_health.lock() {
if *guard == SocketHealth::Inactive {
return;
}
}
}
}
} }

View File

@ -160,6 +160,4 @@ impl crate::engine::EngineManager for EngineConnection {
})), })),
} }
} }
async fn close(&self) {}
} }

View File

@ -267,7 +267,4 @@ impl crate::engine::EngineManager for EngineConnection {
Ok(ws_result) Ok(ws_result)
} }
// maybe we can actually impl this here? not sure how atm.
async fn close(&self) {}
} }

View File

@ -600,9 +600,6 @@ pub trait EngineManager: std::fmt::Debug + Send + Sync + 'static {
fn get_session_data(&self) -> Option<ModelingSessionData> { fn get_session_data(&self) -> Option<ModelingSessionData> {
None None
} }
/// Close the engine connection and wait for it to finish.
async fn close(&self);
} }
#[derive(Debug, Hash, Eq, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema)] #[derive(Debug, Hash, Eq, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema)]

View File

@ -2013,13 +2013,10 @@ impl ExecutorContext {
// AND if we aren't in wasm it doesn't really matter. // AND if we aren't in wasm it doesn't really matter.
Ok(()) Ok(())
} }
/// Given an old ast, old program memory and new ast, find the parts of the code that need to be // Given an old ast, old program memory and new ast, find the parts of the code that need to be
/// re-executed. // re-executed.
/// This function should never error, because in the case of any internal error, we should just pop // This function should never error, because in the case of any internal error, we should just pop
/// the cache. // the cache.
///
/// Returns `None` when there are no changes to the program, i.e. it is
/// fully cached.
pub async fn get_changed_program(&self, info: CacheInformation) -> Option<CacheResult> { pub async fn get_changed_program(&self, info: CacheInformation) -> Option<CacheResult> {
let Some(old) = info.old else { let Some(old) = info.old else {
// We have no old info, we need to re-execute the whole thing. // We have no old info, we need to re-execute the whole thing.
@ -2140,7 +2137,7 @@ impl ExecutorContext {
} }
} }
std::cmp::Ordering::Equal => { std::cmp::Ordering::Equal => {
// currently unreachable, but let's pretend like the code // currently unreachable, but lets pretend like the code
// above can do something meaningful here for when we get // above can do something meaningful here for when we get
// to diffing and yanking chunks of the program apart. // to diffing and yanking chunks of the program apart.
@ -2239,10 +2236,7 @@ impl ExecutorContext {
) )
})?; })?;
// Move the artifact commands to simplify cache management. // Move the artifact commands to simplify cache management.
exec_state exec_state.global.artifact_commands = self.engine.take_artifact_commands();
.global
.artifact_commands
.extend(self.engine.take_artifact_commands());
let session_data = self.engine.get_session_data(); let session_data = self.engine.get_session_data();
Ok(session_data) Ok(session_data)
} }
@ -2632,10 +2626,6 @@ impl ExecutorContext {
self.prepare_snapshot().await self.prepare_snapshot().await
} }
pub async fn close(&self) {
self.engine.close().await;
}
} }
/// For each argument given, /// For each argument given,

View File

@ -1755,3 +1755,24 @@ mod array_elem_pop_fail {
super::execute(TEST_NAME, false).await super::execute(TEST_NAME, false).await
} }
} }
mod array_length {
const TEST_NAME: &str = "array_length";
/// Test parsing KCL.
#[test]
fn parse() {
super::parse(TEST_NAME)
}
/// Test that parsing and unparsing KCL produces the original KCL input.
#[test]
fn unparse() {
super::unparse(TEST_NAME)
}
/// Test that KCL is executed correctly.
#[tokio::test(flavor = "multi_thread")]
async fn kcl_test_execute() {
super::execute(TEST_NAME, false).await
}
}

View File

@ -308,3 +308,40 @@ pub async fn pop(_exec_state: &mut ExecState, args: Args) -> Result<KclValue, Kc
inner_pop(array, &args).await inner_pop(array, &args).await
} }
/// Get the length of an array.
///
/// Returns the number of elements in an array.
///
/// ```no_run
/// arr = [1, 2, 3]
/// length = len(arr)
/// assertEqual(length, 3, 0.00001, "The length of the array is 3")
/// ```
#[stdlib {
name = "len",
keywords = true,
unlabeled_first = true,
arg_docs = {
array = "The array to get the length of.",
}
}]
async fn inner_len(array: Vec<KclValue>, args: &Args) -> Result<KclValue, KclError> {
Ok(KclValue::Number {
value: array.len() as f64,
meta: vec![args.source_range.into()],
})
}
pub async fn len(_exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
let val = args.get_unlabeled_kw_arg("array")?;
let meta = vec![args.source_range];
let KclValue::Array { value: array, meta: _ } = val else {
let actual_type = val.human_friendly_type();
return Err(KclError::Semantic(KclErrorDetails {
source_ranges: meta,
message: format!("You can't get the length of a value of type {actual_type}, only an array"),
}));
};
inner_len(array, &args).await
}

View File

@ -156,8 +156,5 @@ async fn inner_loft(
.await?; .await?;
// Using the first sketch as the base curve, idk we might want to change this later. // Using the first sketch as the base curve, idk we might want to change this later.
let mut sketch = sketches[0].clone(); do_post_extrude(sketches[0].clone(), 0.0, exec_state, args).await
// Override its id with the loft id so we can get its faces later
sketch.id = id;
do_post_extrude(sketch, 0.0, exec_state, args).await
} }

View File

@ -108,6 +108,7 @@ lazy_static! {
Box::new(crate::std::array::Reduce), Box::new(crate::std::array::Reduce),
Box::new(crate::std::array::Map), Box::new(crate::std::array::Map),
Box::new(crate::std::array::Push), Box::new(crate::std::array::Push),
Box::new(crate::std::array::Len),
Box::new(crate::std::array::Pop), Box::new(crate::std::array::Pop),
Box::new(crate::std::chamfer::Chamfer), Box::new(crate::std::chamfer::Chamfer),
Box::new(crate::std::fillet::Fillet), Box::new(crate::std::fillet::Fillet),

View File

@ -25,12 +25,10 @@ pub async fn execute_and_snapshot(
) -> Result<image::DynamicImage, ExecError> { ) -> Result<image::DynamicImage, ExecError> {
let ctx = new_context(units, true, project_directory).await?; let ctx = new_context(units, true, project_directory).await?;
let program = Program::parse_no_errs(code).map_err(KclErrorWithOutputs::no_outputs)?; let program = Program::parse_no_errs(code).map_err(KclErrorWithOutputs::no_outputs)?;
let res = do_execute_and_snapshot(&ctx, program) do_execute_and_snapshot(&ctx, program)
.await .await
.map(|(_state, snap)| snap) .map(|(_state, snap)| snap)
.map_err(|err| err.error); .map_err(|err| err.error)
ctx.close().await;
res
} }
/// Executes a kcl program and takes a snapshot of the result. /// Executes a kcl program and takes a snapshot of the result.
@ -41,16 +39,14 @@ pub async fn execute_and_snapshot_ast(
project_directory: Option<PathBuf>, project_directory: Option<PathBuf>,
) -> Result<(ProgramMemory, Vec<Operation>, Vec<ArtifactCommand>, image::DynamicImage), ExecErrorWithState> { ) -> Result<(ProgramMemory, Vec<Operation>, Vec<ArtifactCommand>, image::DynamicImage), ExecErrorWithState> {
let ctx = new_context(units, true, project_directory).await?; let ctx = new_context(units, true, project_directory).await?;
let res = do_execute_and_snapshot(&ctx, ast).await.map(|(state, snap)| { do_execute_and_snapshot(&ctx, ast).await.map(|(state, snap)| {
( (
state.mod_local.memory, state.mod_local.memory,
state.mod_local.operations, state.mod_local.operations,
state.global.artifact_commands, state.global.artifact_commands,
snap, snap,
) )
}); })
ctx.close().await;
res
} }
pub async fn execute_and_snapshot_no_auth( pub async fn execute_and_snapshot_no_auth(
@ -60,12 +56,10 @@ pub async fn execute_and_snapshot_no_auth(
) -> Result<image::DynamicImage, ExecError> { ) -> Result<image::DynamicImage, ExecError> {
let ctx = new_context(units, false, project_directory).await?; let ctx = new_context(units, false, project_directory).await?;
let program = Program::parse_no_errs(code).map_err(KclErrorWithOutputs::no_outputs)?; let program = Program::parse_no_errs(code).map_err(KclErrorWithOutputs::no_outputs)?;
let res = do_execute_and_snapshot(&ctx, program) do_execute_and_snapshot(&ctx, program)
.await .await
.map(|(_state, snap)| snap) .map(|(_state, snap)| snap)
.map_err(|err| err.error); .map_err(|err| err.error)
ctx.close().await;
res
} }
async fn do_execute_and_snapshot( async fn do_execute_and_snapshot(
@ -86,9 +80,6 @@ async fn do_execute_and_snapshot(
.map_err(|e| ExecError::BadPng(e.to_string())) .map_err(|e| ExecError::BadPng(e.to_string()))
.and_then(|x| x.decode().map_err(|e| ExecError::BadPng(e.to_string()))) .and_then(|x| x.decode().map_err(|e| ExecError::BadPng(e.to_string())))
.map_err(|err| ExecErrorWithState::new(err, exec_state.clone()))?; .map_err(|err| ExecErrorWithState::new(err, exec_state.clone()))?;
ctx.close().await;
Ok((exec_state, img)) Ok((exec_state, img))
} }

View File

@ -0,0 +1,284 @@
---
source: kcl/src/simulation_tests.rs
description: Artifact commands array_length.kcl
---
[
{
"cmdId": "[uuid]",
"range": [
0,
0,
0
],
"command": {
"type": "make_plane",
"origin": {
"x": 0.0,
"y": 0.0,
"z": 0.0
},
"x_axis": {
"x": 1.0,
"y": 0.0,
"z": 0.0
},
"y_axis": {
"x": 0.0,
"y": 1.0,
"z": 0.0
},
"size": 100.0,
"clobber": false,
"hide": true
}
},
{
"cmdId": "[uuid]",
"range": [
0,
0,
0
],
"command": {
"type": "plane_set_color",
"plane_id": "[uuid]",
"color": {
"r": 0.7,
"g": 0.28,
"b": 0.28,
"a": 0.4
}
}
},
{
"cmdId": "[uuid]",
"range": [
0,
0,
0
],
"command": {
"type": "make_plane",
"origin": {
"x": 0.0,
"y": 0.0,
"z": 0.0
},
"x_axis": {
"x": 0.0,
"y": 1.0,
"z": 0.0
},
"y_axis": {
"x": 0.0,
"y": 0.0,
"z": 1.0
},
"size": 100.0,
"clobber": false,
"hide": true
}
},
{
"cmdId": "[uuid]",
"range": [
0,
0,
0
],
"command": {
"type": "plane_set_color",
"plane_id": "[uuid]",
"color": {
"r": 0.28,
"g": 0.7,
"b": 0.28,
"a": 0.4
}
}
},
{
"cmdId": "[uuid]",
"range": [
0,
0,
0
],
"command": {
"type": "make_plane",
"origin": {
"x": 0.0,
"y": 0.0,
"z": 0.0
},
"x_axis": {
"x": 1.0,
"y": 0.0,
"z": 0.0
},
"y_axis": {
"x": 0.0,
"y": 0.0,
"z": 1.0
},
"size": 100.0,
"clobber": false,
"hide": true
}
},
{
"cmdId": "[uuid]",
"range": [
0,
0,
0
],
"command": {
"type": "plane_set_color",
"plane_id": "[uuid]",
"color": {
"r": 0.28,
"g": 0.28,
"b": 0.7,
"a": 0.4
}
}
},
{
"cmdId": "[uuid]",
"range": [
0,
0,
0
],
"command": {
"type": "make_plane",
"origin": {
"x": 0.0,
"y": 0.0,
"z": 0.0
},
"x_axis": {
"x": -1.0,
"y": 0.0,
"z": 0.0
},
"y_axis": {
"x": 0.0,
"y": 1.0,
"z": 0.0
},
"size": 100.0,
"clobber": false,
"hide": true
}
},
{
"cmdId": "[uuid]",
"range": [
0,
0,
0
],
"command": {
"type": "make_plane",
"origin": {
"x": 0.0,
"y": 0.0,
"z": 0.0
},
"x_axis": {
"x": 0.0,
"y": -1.0,
"z": 0.0
},
"y_axis": {
"x": 0.0,
"y": 0.0,
"z": 1.0
},
"size": 100.0,
"clobber": false,
"hide": true
}
},
{
"cmdId": "[uuid]",
"range": [
0,
0,
0
],
"command": {
"type": "make_plane",
"origin": {
"x": 0.0,
"y": 0.0,
"z": 0.0
},
"x_axis": {
"x": -1.0,
"y": 0.0,
"z": 0.0
},
"y_axis": {
"x": 0.0,
"y": 0.0,
"z": 1.0
},
"size": 100.0,
"clobber": false,
"hide": true
}
},
{
"cmdId": "[uuid]",
"range": [
0,
0,
0
],
"command": {
"type": "edge_lines_visible",
"hidden": false
}
},
{
"cmdId": "[uuid]",
"range": [
0,
0,
0
],
"command": {
"type": "set_scene_units",
"unit": "mm"
}
},
{
"cmdId": "[uuid]",
"range": [
0,
0,
0
],
"command": {
"type": "object_visible",
"object_id": "[uuid]",
"hidden": true
}
},
{
"cmdId": "[uuid]",
"range": [
0,
0,
0
],
"command": {
"type": "object_visible",
"object_id": "[uuid]",
"hidden": true
}
}
]

View File

@ -0,0 +1,282 @@
---
source: kcl/src/simulation_tests.rs
description: Result of parsing array_length.kcl
---
{
"Ok": {
"body": [
{
"declaration": {
"end": 15,
"id": {
"end": 3,
"name": "arr",
"start": 0,
"type": "Identifier"
},
"init": {
"elements": [
{
"end": 8,
"raw": "1",
"start": 7,
"type": "Literal",
"type": "Literal",
"value": 1.0
},
{
"end": 11,
"raw": "2",
"start": 10,
"type": "Literal",
"type": "Literal",
"value": 2.0
},
{
"end": 14,
"raw": "3",
"start": 13,
"type": "Literal",
"type": "Literal",
"value": 3.0
}
],
"end": 15,
"start": 6,
"type": "ArrayExpression",
"type": "ArrayExpression"
},
"start": 0,
"type": "VariableDeclarator"
},
"end": 15,
"kind": "const",
"start": 0,
"type": "VariableDeclaration",
"type": "VariableDeclaration"
},
{
"declaration": {
"end": 34,
"id": {
"end": 23,
"name": "arr_len",
"start": 16,
"type": "Identifier"
},
"init": {
"arguments": [
{
"end": 33,
"name": "arr",
"start": 30,
"type": "Identifier",
"type": "Identifier"
}
],
"callee": {
"end": 29,
"name": "len",
"start": 26,
"type": "Identifier"
},
"end": 34,
"start": 26,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 16,
"type": "VariableDeclarator"
},
"end": 34,
"kind": "const",
"start": 16,
"type": "VariableDeclaration",
"type": "VariableDeclaration"
},
{
"end": 99,
"expression": {
"arguments": [
{
"end": 54,
"name": "arr_len",
"start": 47,
"type": "Identifier",
"type": "Identifier"
},
{
"end": 57,
"raw": "3",
"start": 56,
"type": "Literal",
"type": "Literal",
"value": 3.0
},
{
"end": 66,
"raw": "0.00001",
"start": 59,
"type": "Literal",
"type": "Literal",
"value": 0.00001
},
{
"end": 98,
"raw": "\"The length of the array is 3\"",
"start": 68,
"type": "Literal",
"type": "Literal",
"value": "The length of the array is 3"
}
],
"callee": {
"end": 46,
"name": "assertEqual",
"start": 35,
"type": "Identifier"
},
"end": 99,
"start": 35,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 35,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
},
{
"declaration": {
"end": 115,
"id": {
"end": 110,
"name": "arr_empty",
"start": 101,
"type": "Identifier"
},
"init": {
"elements": [],
"end": 115,
"start": 113,
"type": "ArrayExpression",
"type": "ArrayExpression"
},
"start": 101,
"type": "VariableDeclarator"
},
"end": 115,
"kind": "const",
"start": 101,
"type": "VariableDeclaration",
"type": "VariableDeclaration"
},
{
"declaration": {
"end": 142,
"id": {
"end": 125,
"name": "len_empty",
"start": 116,
"type": "Identifier"
},
"init": {
"arguments": [
{
"end": 141,
"name": "arr_empty",
"start": 132,
"type": "Identifier",
"type": "Identifier"
}
],
"callee": {
"end": 131,
"name": "len",
"start": 128,
"type": "Identifier"
},
"end": 142,
"start": 128,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 116,
"type": "VariableDeclarator"
},
"end": 142,
"kind": "const",
"start": 116,
"type": "VariableDeclaration",
"type": "VariableDeclaration"
},
{
"end": 209,
"expression": {
"arguments": [
{
"end": 164,
"name": "len_empty",
"start": 155,
"type": "Identifier",
"type": "Identifier"
},
{
"end": 167,
"raw": "0",
"start": 166,
"type": "Literal",
"type": "Literal",
"value": 0.0
},
{
"end": 176,
"raw": "0.00001",
"start": 169,
"type": "Literal",
"type": "Literal",
"value": 0.00001
},
{
"end": 208,
"raw": "\"The length of the array is 0\"",
"start": 178,
"type": "Literal",
"type": "Literal",
"value": "The length of the array is 0"
}
],
"callee": {
"end": 154,
"name": "assertEqual",
"start": 143,
"type": "Identifier"
},
"end": 209,
"start": 143,
"type": "CallExpression",
"type": "CallExpression"
},
"start": 143,
"type": "ExpressionStatement",
"type": "ExpressionStatement"
}
],
"end": 210,
"nonCodeMeta": {
"nonCodeNodes": {
"2": [
{
"end": 101,
"start": 99,
"type": "NonCodeNode",
"value": {
"type": "newLine"
}
}
]
},
"startNodes": []
},
"start": 0
}
}

View File

@ -0,0 +1,7 @@
arr = [1, 2, 3]
arr_len = len(arr)
assertEqual(arr_len, 3, 0.00001, "The length of the array is 3")
arr_empty = []
len_empty = len(arr_empty)
assertEqual(len_empty, 0, 0.00001, "The length of the array is 0")

View File

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

View File

@ -0,0 +1,127 @@
---
source: kcl/src/simulation_tests.rs
description: Program memory after executing array_length.kcl
---
{
"environments": [
{
"bindings": {
"HALF_TURN": {
"type": "Number",
"value": 180.0,
"__meta": []
},
"QUARTER_TURN": {
"type": "Number",
"value": 90.0,
"__meta": []
},
"THREE_QUARTER_TURN": {
"type": "Number",
"value": 270.0,
"__meta": []
},
"ZERO": {
"type": "Number",
"value": 0.0,
"__meta": []
},
"arr": {
"type": "Array",
"value": [
{
"type": "Number",
"value": 1.0,
"__meta": [
{
"sourceRange": [
7,
8,
0
]
}
]
},
{
"type": "Number",
"value": 2.0,
"__meta": [
{
"sourceRange": [
10,
11,
0
]
}
]
},
{
"type": "Number",
"value": 3.0,
"__meta": [
{
"sourceRange": [
13,
14,
0
]
}
]
}
],
"__meta": [
{
"sourceRange": [
6,
15,
0
]
}
]
},
"arr_empty": {
"type": "Array",
"value": [],
"__meta": [
{
"sourceRange": [
113,
115,
0
]
}
]
},
"arr_len": {
"type": "Number",
"value": 3.0,
"__meta": [
{
"sourceRange": [
26,
34,
0
]
}
]
},
"len_empty": {
"type": "Number",
"value": 0.0,
"__meta": [
{
"sourceRange": [
128,
142,
0
]
}
]
}
},
"parent": null
}
],
"currentEnv": 0,
"return": null
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

View File

@ -1,18 +1,14 @@
//! Cache testing framework. //! Cache testing framework.
use anyhow::Result; use anyhow::Result;
use kcl_lib::{ExecError, ExecState}; use kcl_lib::ExecError;
#[derive(Debug)]
struct Variation<'a> { struct Variation<'a> {
code: &'a str, code: &'a str,
settings: &'a kcl_lib::ExecutorSettings, settings: &'a kcl_lib::ExecutorSettings,
} }
async fn cache_test( async fn cache_test(test_name: &str, variations: Vec<Variation<'_>>) -> Result<Vec<(String, image::DynamicImage)>> {
test_name: &str,
variations: Vec<Variation<'_>>,
) -> Result<Vec<(String, image::DynamicImage, ExecState)>> {
let first = variations let first = variations
.first() .first()
.ok_or_else(|| anyhow::anyhow!("No variations provided for test '{}'", test_name))?; .ok_or_else(|| anyhow::anyhow!("No variations provided for test '{}'", test_name))?;
@ -46,7 +42,7 @@ async fn cache_test(
// Save the snapshot. // Save the snapshot.
let path = crate::assert_out(&format!("cache_{}_{}", test_name, index), &img); let path = crate::assert_out(&format!("cache_{}_{}", test_name, index), &img);
img_results.push((path, img, exec_state.clone())); img_results.push((path, img));
// Prepare the last state. // Prepare the last state.
old_ast_state = Some(kcl_lib::OldAstState { old_ast_state = Some(kcl_lib::OldAstState {
@ -56,8 +52,6 @@ async fn cache_test(
}); });
} }
ctx.close().await;
Ok(img_results) Ok(img_results)
} }
@ -220,47 +214,3 @@ async fn kcl_test_cache_change_highlight_edges_changes_visual() {
assert!(first.1 != second.1); assert!(first.1 != second.1);
} }
#[tokio::test(flavor = "multi_thread")]
async fn kcl_test_cache_add_line_preserves_artifact_commands() {
let code = r#"sketch001 = startSketchOn('XY')
|> startProfileAt([5.5229, 5.25217], %)
|> line([10.50433, -1.19122], %)
|> line([8.01362, -5.48731], %)
|> line([-1.02877, -6.76825], %)
|> line([-11.53311, 2.81559], %)
|> close(%)
"#;
// Use a new statement; don't extend the prior pipeline. This allows us to
// detect a prefix.
let code_with_extrude = code.to_owned()
+ r#"
extrude(4, sketch001)
"#;
let result = cache_test(
"add_line_preserves_artifact_commands",
vec![
Variation {
code,
settings: &Default::default(),
},
Variation {
code: code_with_extrude.as_str(),
settings: &Default::default(),
},
],
)
.await
.unwrap();
let first = result.first().unwrap();
let second = result.last().unwrap();
assert!(
first.2.global.artifact_commands.len() < second.2.global.artifact_commands.len(),
"Second should have all the artifact commands of the first, plus more. first={:?}, second={:?}",
first.2.global.artifact_commands.len(),
second.2.global.artifact_commands.len()
);
}

View File

@ -1169,25 +1169,25 @@ async fn kcl_test_plumbus_fillets() {
return sg return sg
} }
fn pentagon = (len) => { fn pentagon = (sideLen) => {
sg = startSketchOn('XY') sg = startSketchOn('XY')
|> startProfileAt([-len / 2, -len / 2], %) |> startProfileAt([-sideLen / 2, -sideLen / 2], %)
|> angledLine({ angle: 0, length: len }, %, $a) |> angledLine({ angle: 0, length: sideLen }, %, $a)
|> angledLine({ |> angledLine({
angle: segAng(a) + 180 - 108, angle: segAng(a) + 180 - 108,
length: len length: sideLen
}, %, $b) }, %, $b)
|> angledLine({ |> angledLine({
angle: segAng(b) + 180 - 108, angle: segAng(b) + 180 - 108,
length: len length: sideLen
}, %, $c) }, %, $c)
|> angledLine({ |> angledLine({
angle: segAng(c) + 180 - 108, angle: segAng(c) + 180 - 108,
length: len length: sideLen
}, %, $d) }, %, $d)
|> angledLine({ |> angledLine({
angle: segAng(d) + 180 - 108, angle: segAng(d) + 180 - 108,
length: len length: sideLen
}, %) }, %)
return sg return sg
@ -1653,17 +1653,17 @@ part001 = cube([0,0], 20)
#[tokio::test(flavor = "multi_thread")] #[tokio::test(flavor = "multi_thread")]
async fn kcl_test_duplicate_tags_should_error() { async fn kcl_test_duplicate_tags_should_error() {
let code = r#"fn triangle = (len) => { let code = r#"fn triangle = (sideLen) => {
return startSketchOn('XY') return startSketchOn('XY')
|> startProfileAt([-len / 2, -len / 2], %) |> startProfileAt([-sideLen / 2, -sideLen / 2], %)
|> angledLine({ angle: 0, length: len }, %, $a) |> angledLine({ angle: 0, length: sideLen }, %, $a)
|> angledLine({ |> angledLine({
angle: segAng(a) + 120, angle: segAng(a) + 120,
length: len length: sideLen
}, %, $b) }, %, $b)
|> angledLine({ |> angledLine({
angle: segAng(b) + 120, angle: segAng(b) + 120,
length: len length: sideLen
}, %, $a) }, %, $a)
} }
@ -1674,7 +1674,7 @@ let p = triangle(200)
assert!(result.is_err()); assert!(result.is_err());
assert_eq!( assert_eq!(
result.err().unwrap().to_string(), result.err().unwrap().to_string(),
r#"value already defined: KclErrorDetails { source_ranges: [SourceRange([311, 313, 0]), SourceRange([326, 339, 0])], message: "Cannot redefine `a`" }"# r#"value already defined: KclErrorDetails { source_ranges: [SourceRange([335, 337, 0]), SourceRange([350, 363, 0])], message: "Cannot redefine `a`" }"#
); );
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 47 KiB

1528
yarn.lock

File diff suppressed because it is too large Load Diff