Compare commits

...

14 Commits

Author SHA1 Message Date
239ab6850e Cut release v0.26.2 (#4322)
* Cut release v0.26.2

* A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest)

* A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest)

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2024-10-26 03:06:01 -04:00
4a7dd6e650 update env vars to match other repos, make dry (#4321)
* update env vars to match other repos, make dry

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

* bump

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

* updates

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

---------

Signed-off-by: Jess Frazelle <github@jessfraz.com>
2024-10-26 03:06:32 +00:00
af2609e678 Fix NetworkMachineIndicator and machines dynamically showing in CommandBar (#4311) 2024-10-25 16:28:10 -07:00
30909dedda Bump kittycad from 0.3.23 to 0.3.25 in /src/wasm-lib (#4316)
Bumps [kittycad](https://github.com/KittyCAD/kittycad.rs) from 0.3.23 to 0.3.25.
- [Release notes](https://github.com/KittyCAD/kittycad.rs/releases)
- [Commits](https://github.com/KittyCAD/kittycad.rs/compare/v0.3.23...v0.3.25)

---
updated-dependencies:
- dependency-name: kittycad
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-10-25 22:58:59 +00:00
39d76ed54f Bugfix: arc paths were stored as straight line paths (#4310)
Problem 1 of https://github.com/KittyCAD/modeling-app/issues/4297
2024-10-25 22:49:30 +00:00
4925251c29 Make application aware it saved the buffer and not something else (#4314)
Make application aware it saved the buffer and something else
2024-10-25 18:07:50 -04:00
9772869545 Add a radius length indicator to the circle sketch tool (#4304)
* Add a radius length indicator to the circle sketch tool

* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest)

* A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest)

* A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest)

* Revert "A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest)"

This reverts commit 15b078f641.

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: 49fl <ircsurfer33@gmail.com>
2024-10-25 17:42:27 -04:00
a7e830cd02 Update machine-api spec (#4305)
YOYO NEW API SPEC!

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2024-10-25 20:53:08 +00:00
ca102116b6 Bump kittycad-modeling-cmds from 0.2.70 to 0.2.71 in /src/wasm-lib (#4302)
Bumps [kittycad-modeling-cmds](https://github.com/KittyCAD/modeling-api) from 0.2.70 to 0.2.71.
- [Commits](https://github.com/KittyCAD/modeling-api/compare/kittycad-modeling-cmds-0.2.70...kittycad-modeling-cmds-0.2.71)

---
updated-dependencies:
- dependency-name: kittycad-modeling-cmds
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Adam Chalmers <adam.chalmers@zoo.dev>
2024-10-25 20:52:22 +00:00
c2fba89e77 Bump regex from 1.11.0 to 1.11.1 in /src/wasm-lib (#4301)
Bumps [regex](https://github.com/rust-lang/regex) from 1.11.0 to 1.11.1.
- [Release notes](https://github.com/rust-lang/regex/releases)
- [Changelog](https://github.com/rust-lang/regex/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/regex/compare/1.11.0...1.11.1)

---
updated-dependencies:
- dependency-name: regex
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-10-25 13:50:21 -07:00
7e31678ba2 Chore: Don't let draft lines receive mouseEnter/Leave events, or create invalid overlays (#4306) 2024-10-25 15:34:53 -04:00
1140ced121 Tags should refer to full paths, not just base paths. (#4299)
See "Problem 2" in https://github.com/KittyCAD/modeling-app/issues/4297

This is a pure refactor, it should not change any behaviour at all.
It adds more information into the tag system, but nothing reads that
extra information yet. It will be used to address problem 3 of the above
issue.
2024-10-25 10:27:40 -04:00
32b7ddaa7c Update circular pattern snapshots (#4303)
Engine changed (Serena fixed a bug with circular patterns), so snapshots need to be updated.
2024-10-25 08:28:46 -04:00
2525f99515 Move more KCL tests into files (#4260) 2024-10-25 01:52:43 +00:00
56 changed files with 28239 additions and 11683 deletions

View File

@ -62,7 +62,7 @@ jobs:
shell: bash shell: bash
run: |- run: |-
cd "${{ matrix.dir }}" cd "${{ matrix.dir }}"
cargo llvm-cov nextest --all --lcov --output-path lcov.info --test-threads=1 --no-fail-fast -P ci 2>&1 | tee /tmp/github-actions.log cargo llvm-cov nextest --workspace --lcov --output-path lcov.info --test-threads=1 --no-fail-fast -P ci 2>&1 | tee /tmp/github-actions.log
env: env:
KITTYCAD_API_TOKEN: ${{secrets.KITTYCAD_API_TOKEN}} KITTYCAD_API_TOKEN: ${{secrets.KITTYCAD_API_TOKEN}}
RUST_MIN_STACK: 10485760000 RUST_MIN_STACK: 10485760000

File diff suppressed because it is too large Load Diff

View File

@ -162,6 +162,28 @@ A base path.
---- ----
A circular arc, not necessarily tangential to the current point.
**Type:** `object`
## Properties
| Property | Type | Description | Required |
|----------|------|-------------|----------|
| `type` |enum: `Arc`| | No |
| `center` |`[number, number]`| Center of the circle that this arc is drawn on. | No |
| `radius` |`number`| Radius of the circle that this arc is drawn on. | No |
| `from` |`[number, number]`| The from point. | No |
| `to` |`[number, number]`| The to point. | No |
| `tag` |[`TagDeclarator`](/docs/kcl/types#tag-declaration)| The tag of the path. | No |
| `__geoMeta` |[`GeoMeta`](/docs/kcl/types/GeoMeta)| Metadata. | No |
----

View File

@ -18,7 +18,7 @@ Engine information for a tag.
|----------|------|-------------|----------| |----------|------|-------------|----------|
| `id` |`string`| The id of the tagged object. | No | | `id` |`string`| The id of the tagged object. | No |
| `sketch` |`string`| The sketch the tag is on. | No | | `sketch` |`string`| The sketch the tag is on. | No |
| `path` |[`BasePath`](/docs/kcl/types/BasePath)| The path the tag is on. | No | | `path` |[`Path`](/docs/kcl/types/Path)| The path the tag is on. | No |
| `surface` |[`ExtrudeSurface`](/docs/kcl/types/ExtrudeSurface)| The surface information for the tag. | No | | `surface` |[`ExtrudeSurface`](/docs/kcl/types/ExtrudeSurface)| The surface information for the tag. | No |

Binary file not shown.

Before

Width:  |  Height:  |  Size: 44 KiB

After

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 41 KiB

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 40 KiB

2
interface.d.ts vendored
View File

@ -2,7 +2,7 @@ import fs from 'node:fs/promises'
import fsSync from 'node:fs' import fsSync from 'node:fs'
import path from 'path' import path from 'path'
import { dialog, shell } from 'electron' import { dialog, shell } from 'electron'
import { MachinesListing } from 'lib/machineManager' import { MachinesListing } from 'components/MachineManagerProvider'
type EnvFn = (value?: string) => string type EnvFn = (value?: string) => string

View File

@ -996,7 +996,7 @@
}, },
"description": "", "description": "",
"title": "machine-api", "title": "machine-api",
"version": "0.1.0" "version": "0.1.1"
}, },
"openapi": "3.0.3", "openapi": "3.0.3",
"paths": { "paths": {

View File

@ -1,6 +1,6 @@
{ {
"name": "zoo-modeling-app", "name": "zoo-modeling-app",
"version": "0.26.1", "version": "0.26.2",
"private": true, "private": true,
"productName": "Zoo Modeling App", "productName": "Zoo Modeling App",
"author": { "author": {

View File

@ -21,6 +21,7 @@ import { WasmErrBanner } from 'components/WasmErrBanner'
import { CommandBar } from 'components/CommandBar/CommandBar' import { CommandBar } from 'components/CommandBar/CommandBar'
import ModelingMachineProvider from 'components/ModelingMachineProvider' import ModelingMachineProvider from 'components/ModelingMachineProvider'
import FileMachineProvider from 'components/FileMachineProvider' import FileMachineProvider from 'components/FileMachineProvider'
import { MachineManagerProvider } from 'components/MachineManagerProvider'
import { PATHS } from 'lib/paths' import { PATHS } from 'lib/paths'
import { import {
fileLoader, fileLoader,
@ -49,6 +50,7 @@ const router = createRouter([
{ {
loader: settingsLoader, loader: settingsLoader,
id: PATHS.INDEX, id: PATHS.INDEX,
// TODO: Re-evaluate if this is true
/* Make sure auth is the outermost provider or else we will have /* Make sure auth is the outermost provider or else we will have
* inefficient re-renders, use the react profiler to see. */ * inefficient re-renders, use the react profiler to see. */
element: ( element: (
@ -57,7 +59,9 @@ const router = createRouter([
<LspProvider> <LspProvider>
<KclContextProvider> <KclContextProvider>
<AppStateProvider> <AppStateProvider>
<MachineManagerProvider>
<Outlet /> <Outlet />
</MachineManagerProvider>
</AppStateProvider> </AppStateProvider>
</KclContextProvider> </KclContextProvider>
</LspProvider> </LspProvider>

View File

@ -746,7 +746,6 @@ export class SceneEntities {
}, },
}) })
}, },
...this.mouseEnterLeaveCallbacks(),
}) })
} }
setupDraftRectangle = async ( setupDraftRectangle = async (

View File

@ -213,7 +213,7 @@ export class SceneInfra {
to: Coords2d to: Coords2d
angle?: number angle?: number
}): SegmentOverlayPayload | null { }): SegmentOverlayPayload | null {
if (group.userData.pathToNode && arrowGroup) { if (!group.userData.draft && group.userData.pathToNode && arrowGroup) {
const vector = new Vector3(0, 0, 0) const vector = new Vector3(0, 0, 0)
// Get the position of the object3D in world space // Get the position of the object3D in world space

View File

@ -147,6 +147,7 @@ class StraightSegment implements SegmentUtils {
segmentGroup.name = STRAIGHT_SEGMENT segmentGroup.name = STRAIGHT_SEGMENT
segmentGroup.userData = { segmentGroup.userData = {
type: STRAIGHT_SEGMENT, type: STRAIGHT_SEGMENT,
draft: isDraftSegment,
id, id,
from, from,
to, to,
@ -347,6 +348,7 @@ class TangentialArcToSegment implements SegmentUtils {
mesh.name = meshName mesh.name = meshName
group.userData = { group.userData = {
type: TANGENTIAL_ARC_TO_SEGMENT, type: TANGENTIAL_ARC_TO_SEGMENT,
draft: isDraftSegment,
id, id,
from, from,
to, to,
@ -515,11 +517,18 @@ class CircleSegment implements SegmentUtils {
const meshType = isDraftSegment ? CIRCLE_SEGMENT_DASH : CIRCLE_SEGMENT_BODY const meshType = isDraftSegment ? CIRCLE_SEGMENT_DASH : CIRCLE_SEGMENT_BODY
const arrowGroup = createArrowhead(scale, theme, color) const arrowGroup = createArrowhead(scale, theme, color)
const circleCenterGroup = createCircleCenterHandle(scale, theme, color) const circleCenterGroup = createCircleCenterHandle(scale, theme, color)
// A radius indicator that appears from the center to the perimeter
const radiusIndicatorGroup = createLengthIndicator({
from: center,
to: [center[0] + radius, center[1]],
scale,
})
arcMesh.userData.type = meshType arcMesh.userData.type = meshType
arcMesh.name = meshType arcMesh.name = meshType
group.userData = { group.userData = {
type: CIRCLE_SEGMENT, type: CIRCLE_SEGMENT,
draft: isDraftSegment,
id, id,
from, from,
radius, radius,
@ -532,7 +541,7 @@ class CircleSegment implements SegmentUtils {
} }
group.name = CIRCLE_SEGMENT group.name = CIRCLE_SEGMENT
group.add(arcMesh, arrowGroup, circleCenterGroup) group.add(arcMesh, arrowGroup, circleCenterGroup, radiusIndicatorGroup)
const updateOverlaysCallback = this.update({ const updateOverlaysCallback = this.update({
prevSegment, prevSegment,
input, input,
@ -564,6 +573,9 @@ class CircleSegment implements SegmentUtils {
group.userData.radius = radius group.userData.radius = radius
group.userData.prevSegment = prevSegment group.userData.prevSegment = prevSegment
const arrowGroup = group.getObjectByName(ARROWHEAD) as Group const arrowGroup = group.getObjectByName(ARROWHEAD) as Group
const radiusLengthIndicator = group.getObjectByName(
SEGMENT_LENGTH_LABEL
) as Group
const circleCenterHandle = group.getObjectByName( const circleCenterHandle = group.getObjectByName(
CIRCLE_CENTER_HANDLE CIRCLE_CENTER_HANDLE
) as Group ) as Group
@ -581,11 +593,14 @@ class CircleSegment implements SegmentUtils {
} }
if (arrowGroup) { if (arrowGroup) {
arrowGroup.position.set( // The arrowhead is placed at the perimeter of the circle,
center[0] + Math.cos(Math.PI / 4) * radius, // pointing up and to the right
center[1] + Math.sin(Math.PI / 4) * radius, const arrowPoint = {
0 x: center[0] + Math.cos(Math.PI / 4) * radius,
) y: center[1] + Math.sin(Math.PI / 4) * radius,
}
arrowGroup.position.set(arrowPoint.x, arrowPoint.y, 0)
const arrowheadAngle = Math.PI / 4 const arrowheadAngle = Math.PI / 4
arrowGroup.quaternion.setFromUnitVectors( arrowGroup.quaternion.setFromUnitVectors(
@ -596,6 +611,31 @@ class CircleSegment implements SegmentUtils {
arrowGroup.visible = isHandlesVisible arrowGroup.visible = isHandlesVisible
} }
if (radiusLengthIndicator) {
// The radius indicator is placed at the midpoint of the radius,
// at a 45 degree CCW angle from the positive X-axis
const indicatorPoint = {
x: center[0] + (Math.cos(Math.PI / 4) * radius) / 2,
y: center[1] + (Math.sin(Math.PI / 4) * radius) / 2,
}
const labelWrapper = radiusLengthIndicator.getObjectByName(
SEGMENT_LENGTH_LABEL_TEXT
) as CSS2DObject
const labelWrapperElem = labelWrapper.element as HTMLDivElement
const label = labelWrapperElem.children[0] as HTMLParagraphElement
label.innerText = `${roundOff(radius)}`
label.classList.add(SEGMENT_LENGTH_LABEL_TEXT)
const isPlaneBackFace = center[0] > indicatorPoint.x
label.style.setProperty(
'--degree',
`${isPlaneBackFace ? '45' : '-45'}deg`
)
label.style.setProperty('--x', `0px`)
label.style.setProperty('--y', `0px`)
labelWrapper.position.set(indicatorPoint.x, indicatorPoint.y, 0)
radiusLengthIndicator.visible = isHandlesVisible
}
if (circleCenterHandle) { if (circleCenterHandle) {
circleCenterHandle.position.set(center[0], center[1], 0) circleCenterHandle.position.set(center[0], center[1], 0)
circleCenterHandle.scale.set(scale, scale, scale) circleCenterHandle.scale.set(scale, scale, scale)

View File

@ -140,6 +140,13 @@ const FileTreeItem = ({
async (eventType, path) => { async (eventType, path) => {
// Don't try to read a file that was removed. // Don't try to read a file that was removed.
if (isCurrentFile && eventType !== 'unlink') { if (isCurrentFile && eventType !== 'unlink') {
// Prevents a cyclic read / write causing editor problems such as
// misplaced cursor positions.
if (codeManager.writeCausedByAppCheckedInFileTreeFileSystemWatcher) {
codeManager.writeCausedByAppCheckedInFileTreeFileSystemWatcher = false
return
}
let code = await window.electron.readFile(path, { encoding: 'utf-8' }) let code = await window.electron.readFile(path, { encoding: 'utf-8' })
code = normalizeLineEndings(code) code = normalizeLineEndings(code)
codeManager.updateCodeStateEditor(code) codeManager.updateCodeStateEditor(code)

View File

@ -23,6 +23,7 @@ export function LowerRightControls({
}) { }) {
const location = useLocation() const location = useLocation()
const filePath = useAbsoluteFilePath() const filePath = useAbsoluteFilePath()
const linkOverrideClassName = const linkOverrideClassName =
'!text-chalkboard-70 hover:!text-chalkboard-80 dark:!text-chalkboard-40 dark:hover:!text-chalkboard-30' '!text-chalkboard-70 hover:!text-chalkboard-80 dark:!text-chalkboard-40 dark:hover:!text-chalkboard-30'

View File

@ -0,0 +1,123 @@
import { createContext, useEffect, useState } from 'react'
import { engineCommandManager } from 'lib/singletons'
import { CommandsContext } from 'components/CommandBar/CommandBarProvider'
import { isDesktop } from 'lib/isDesktop'
import { components } from 'lib/machine-api'
import { reportRejection } from 'lib/trap'
import { toSync } from 'lib/utils'
export type MachinesListing = Array<
components['schemas']['MachineInfoResponse']
>
export interface MachineManager {
machines: MachinesListing
machineApiIp: string | null
currentMachine: components['schemas']['MachineInfoResponse'] | null
noMachinesReason: () => string | undefined
setCurrentMachine: (
m: components['schemas']['MachineInfoResponse'] | null
) => void
}
export const MachineManagerContext = createContext<MachineManager>({
machines: [],
machineApiIp: null,
currentMachine: null,
setCurrentMachine: (
_: components['schemas']['MachineInfoResponse'] | null
) => {},
noMachinesReason: () => undefined,
})
export const MachineManagerProvider = ({
children,
}: {
children: React.ReactNode
}) => {
const [machines, setMachines] = useState<MachinesListing>([])
const [machineApiIp, setMachineApiIp] = useState<string | null>(null)
const [currentMachine, setCurrentMachine] = useState<
components['schemas']['MachineInfoResponse'] | null
>(null)
const commandBarActor = CommandsContext.useActorRef()
// Get the reason message for why there are no machines.
const noMachinesReason = (): string | undefined => {
if (machines.length > 0) {
return undefined
}
if (machineApiIp === null) {
return 'Machine API server was not discovered'
}
return 'Machine API server was discovered, but no machines are available'
}
useEffect(() => {
if (!isDesktop()) return
const update = async () => {
const _machineApiIp = await window.electron.getMachineApiIp()
if (_machineApiIp === null) return
setMachineApiIp(_machineApiIp)
const _machines = await window.electron.listMachines(_machineApiIp)
setMachines(_machines)
}
// Start a background job to update the machines every ten seconds.
// If MDNS is already watching, this timeout will wait until it's done to trigger the
// finding again.
let timeoutId: ReturnType<typeof setTimeout> | undefined = undefined
const timeoutLoop = () => {
clearTimeout(timeoutId)
timeoutId = setTimeout(
toSync(async () => {
await update()
timeoutLoop()
}, reportRejection),
1000
)
}
timeoutLoop()
update().catch(reportRejection)
}, [])
// Update engineCommandManager's copy of this data.
useEffect(() => {
const machineManagerNext = {
machines,
machineApiIp,
currentMachine,
noMachinesReason,
setCurrentMachine,
}
engineCommandManager.machineManager = machineManagerNext
commandBarActor.send({
type: 'Set machine manager',
data: machineManagerNext,
})
}, [machines, machineApiIp, currentMachine])
return (
<MachineManagerContext.Provider
value={{
machines,
machineApiIp,
currentMachine,
setCurrentMachine,
noMachinesReason,
}}
>
{' '}
{children}{' '}
</MachineManagerContext.Provider>
)
}

View File

@ -1,5 +1,11 @@
import { useMachine } from '@xstate/react' import { useMachine } from '@xstate/react'
import React, { createContext, useEffect, useMemo, useRef } from 'react' import React, {
createContext,
useEffect,
useMemo,
useRef,
useContext,
} from 'react'
import { import {
Actor, Actor,
AnyStateMachine, AnyStateMachine,
@ -28,7 +34,7 @@ import {
editorManager, editorManager,
sceneEntitiesManager, sceneEntitiesManager,
} from 'lib/singletons' } from 'lib/singletons'
import { machineManager } from 'lib/machineManager' import { MachineManagerContext } from 'components/MachineManagerProvider'
import { useHotkeys } from 'react-hotkeys-hook' import { useHotkeys } from 'react-hotkeys-hook'
import { applyConstraintHorzVertDistance } from './Toolbar/SetHorzVertDistance' import { applyConstraintHorzVertDistance } from './Toolbar/SetHorzVertDistance'
import { import {
@ -140,6 +146,8 @@ export const ModelingMachineProvider = ({
// > // >
// ) // )
const machineManager = useContext(MachineManagerContext)
const [modelingState, modelingSend, modelingActor] = useMachine( const [modelingState, modelingSend, modelingActor] = useMachine(
modelingMachine.provide({ modelingMachine.provide({
actions: { actions: {
@ -408,7 +416,7 @@ export const ModelingMachineProvider = ({
return {} return {}
} }
), ),
Make: ({ event }) => { Make: ({ context, event }) => {
if (event.type !== 'Make') return if (event.type !== 'Make') return
// Check if we already have an export intent. // Check if we already have an export intent.
if (engineCommandManager.exportInfo) { if (engineCommandManager.exportInfo) {
@ -422,7 +430,21 @@ export const ModelingMachineProvider = ({
} }
// Set the current machine. // Set the current machine.
machineManager.currentMachine = event.data.machine // Due to our use of singeton pattern, we need to do this to reliably
// update this object across React and non-React boundary.
// We need to do this eagerly because of the exportToEngine call below.
if (engineCommandManager.machineManager === null) {
console.warn(
"engineCommandManager.machineManager is null. It shouldn't be at this point. Aborting operation."
)
return
} else {
engineCommandManager.machineManager.currentMachine =
event.data.machine
}
// Update the rest of the UI that needs to know the current machine
context.machineManager.setCurrentMachine(event.data.machine)
const format: Models['OutputFormat_type'] = { const format: Models['OutputFormat_type'] = {
type: 'stl', type: 'stl',
@ -995,6 +1017,7 @@ export const ModelingMachineProvider = ({
...modelingMachineDefaultContext.store, ...modelingMachineDefaultContext.store,
...persistedContext, ...persistedContext,
}, },
machineManager,
}, },
// devTools: true, // devTools: true,
} }

View File

@ -1,6 +1,12 @@
import { useSettingsAuthContext } from 'hooks/useSettingsAuthContext' import { useSettingsAuthContext } from 'hooks/useSettingsAuthContext'
import { Resizable } from 're-resizable' import { Resizable } from 're-resizable'
import { MouseEventHandler, useCallback, useEffect, useMemo } from 'react' import {
MouseEventHandler,
useCallback,
useEffect,
useMemo,
useContext,
} from 'react'
import { useHotkeys } from 'react-hotkeys-hook' import { useHotkeys } from 'react-hotkeys-hook'
import { SidebarAction, SidebarType, sidebarPanes } from './ModelingPanes' import { SidebarAction, SidebarType, sidebarPanes } from './ModelingPanes'
import Tooltip from 'components/Tooltip' import Tooltip from 'components/Tooltip'
@ -13,7 +19,7 @@ import { CustomIconName } from 'components/CustomIcon'
import { useCommandsContext } from 'hooks/useCommandsContext' import { useCommandsContext } from 'hooks/useCommandsContext'
import { IconDefinition } from '@fortawesome/free-solid-svg-icons' import { IconDefinition } from '@fortawesome/free-solid-svg-icons'
import { useKclContext } from 'lang/KclProvider' import { useKclContext } from 'lang/KclProvider'
import { machineManager } from 'lib/machineManager' import { MachineManagerContext } from 'components/MachineManagerProvider'
interface ModelingSidebarProps { interface ModelingSidebarProps {
paneOpacity: '' | 'opacity-20' | 'opacity-40' paneOpacity: '' | 'opacity-20' | 'opacity-40'
@ -29,6 +35,7 @@ function getPlatformString(): 'web' | 'desktop' {
} }
export function ModelingSidebar({ paneOpacity }: ModelingSidebarProps) { export function ModelingSidebar({ paneOpacity }: ModelingSidebarProps) {
const machineManager = useContext(MachineManagerContext)
const { commandBarSend } = useCommandsContext() const { commandBarSend } = useCommandsContext()
const kclContext = useKclContext() const kclContext = useKclContext()
const { settings } = useSettingsAuthContext() const { settings } = useSettingsAuthContext()

View File

@ -1,7 +1,9 @@
import { Popover } from '@headlessui/react' import { Popover } from '@headlessui/react'
import { useContext } from 'react'
import Tooltip from './Tooltip' import Tooltip from './Tooltip'
import { machineManager } from 'lib/machineManager'
import { isDesktop } from 'lib/isDesktop' import { isDesktop } from 'lib/isDesktop'
import { components } from 'lib/machine-api'
import { MachineManagerContext } from 'components/MachineManagerProvider'
import { CustomIcon } from './CustomIcon' import { CustomIcon } from './CustomIcon'
export const NetworkMachineIndicator = ({ export const NetworkMachineIndicator = ({
@ -9,9 +11,12 @@ export const NetworkMachineIndicator = ({
}: { }: {
className?: string className?: string
}) => { }) => {
const machineCount = machineManager.machineCount() const {
const reason = machineManager.noMachinesReason() noMachinesReason,
const machines = machineManager.machines machines,
machines: { length: machineCount },
} = useContext(MachineManagerContext)
const reason = noMachinesReason()
return isDesktop() ? ( return isDesktop() ? (
<Popover className="relative"> <Popover className="relative">
@ -47,7 +52,8 @@ export const NetworkMachineIndicator = ({
</div> </div>
{machineCount > 0 && ( {machineCount > 0 && (
<ul className="divide-y divide-chalkboard-20 dark:divide-chalkboard-80"> <ul className="divide-y divide-chalkboard-20 dark:divide-chalkboard-80">
{machines.map((machine) => { {machines.map(
(machine: components['schemas']['MachineInfoResponse']) => {
return ( return (
<li key={machine.id} className={'px-2 py-4 gap-1 last:mb-0 '}> <li key={machine.id} className={'px-2 py-4 gap-1 last:mb-0 '}>
<p className="">{machine.id.toUpperCase()}</p> <p className="">{machine.id.toUpperCase()}</p>
@ -74,7 +80,8 @@ export const NetworkMachineIndicator = ({
</p> </p>
</li> </li>
) )
})} }
)}
</ul> </ul>
)} )}
</Popover.Panel> </Popover.Panel>

View File

@ -4,14 +4,14 @@ import { type IndexLoaderData } from 'lib/types'
import { PATHS } from 'lib/paths' import { PATHS } from 'lib/paths'
import { isDesktop } from '../lib/isDesktop' import { isDesktop } from '../lib/isDesktop'
import { Link, useLocation, useNavigate } from 'react-router-dom' import { Link, useLocation, useNavigate } from 'react-router-dom'
import { Fragment, useMemo } from 'react' import { Fragment, useMemo, useContext } from 'react'
import { Logo } from './Logo' import { Logo } from './Logo'
import { APP_NAME } from 'lib/constants' import { APP_NAME } from 'lib/constants'
import { useCommandsContext } from 'hooks/useCommandsContext' import { useCommandsContext } from 'hooks/useCommandsContext'
import { CustomIcon } from './CustomIcon' import { CustomIcon } from './CustomIcon'
import { useLspContext } from './LspProvider' import { useLspContext } from './LspProvider'
import { engineCommandManager } from 'lib/singletons' import { engineCommandManager } from 'lib/singletons'
import { machineManager } from 'lib/machineManager' import { MachineManagerContext } from 'components/MachineManagerProvider'
import usePlatform from 'hooks/usePlatform' import usePlatform from 'hooks/usePlatform'
import { useAbsoluteFilePath } from 'hooks/useAbsoluteFilePath' import { useAbsoluteFilePath } from 'hooks/useAbsoluteFilePath'
import Tooltip from './Tooltip' import Tooltip from './Tooltip'
@ -96,6 +96,8 @@ function ProjectMenuPopover({
const location = useLocation() const location = useLocation()
const navigate = useNavigate() const navigate = useNavigate()
const filePath = useAbsoluteFilePath() const filePath = useAbsoluteFilePath()
const machineManager = useContext(MachineManagerContext)
const { commandBarState, commandBarSend } = useCommandsContext() const { commandBarState, commandBarSend } = useCommandsContext()
const { onProjectClose } = useLspContext() const { onProjectClose } = useLspContext()
const exportCommandInfo = { name: 'Export', groupId: 'modeling' } const exportCommandInfo = { name: 'Export', groupId: 'modeling' }
@ -106,7 +108,7 @@ function ProjectMenuPopover({
(c) => c.name === obj.name && c.groupId === obj.groupId (c) => c.name === obj.name && c.groupId === obj.groupId
) )
) )
const machineCount = machineManager.machineCount() const machineCount = machineManager.machines.length
// We filter this memoized list so that no orphan "break" elements are rendered. // We filter this memoized list so that no orphan "break" elements are rendered.
const projectMenuItems = useMemo<(ActionButtonProps | 'break')[]>( const projectMenuItems = useMemo<(ActionButtonProps | 'break')[]>(

View File

@ -20,6 +20,8 @@ export default class CodeManager {
private _hotkeys: { [key: string]: () => void } = {} private _hotkeys: { [key: string]: () => void } = {}
private timeoutWriter: ReturnType<typeof setTimeout> | undefined = undefined private timeoutWriter: ReturnType<typeof setTimeout> | undefined = undefined
public writeCausedByAppCheckedInFileTreeFileSystemWatcher = false
constructor() { constructor() {
if (isDesktop()) { if (isDesktop()) {
this.code = '' this.code = ''
@ -120,6 +122,7 @@ export default class CodeManager {
// and file-system watchers which read, will receive empty data during // and file-system watchers which read, will receive empty data during
// writes. // writes.
clearTimeout(this.timeoutWriter) clearTimeout(this.timeoutWriter)
this.writeCausedByAppCheckedInFileTreeFileSystemWatcher = true
this.timeoutWriter = setTimeout(() => { this.timeoutWriter = setTimeout(() => {
// Wait one event loop to give a chance for params to be set // Wait one event loop to give a chance for params to be set
// Save the file to disk // Save the file to disk

View File

@ -28,6 +28,7 @@ import {
} from 'lib/constants' } from 'lib/constants'
import { KclManager } from 'lang/KclSingleton' import { KclManager } from 'lang/KclSingleton'
import { reportRejection } from 'lib/trap' import { reportRejection } from 'lib/trap'
import { MachineManager } from 'components/MachineManagerProvider'
// TODO(paultag): This ought to be tweakable. // TODO(paultag): This ought to be tweakable.
const pingIntervalMs = 5_000 const pingIntervalMs = 5_000
@ -1415,6 +1416,9 @@ export class EngineCommandManager extends EventTarget {
(() => {}) as any (() => {}) as any
kclManager: null | KclManager = null kclManager: null | KclManager = null
// The current "manufacturing machine" aka 3D printer, CNC, etc.
public machineManager: MachineManager | null = null
set exportInfo(info: ExportInfo | null) { set exportInfo(info: ExportInfo | null) {
this._exportInfo = info this._exportInfo = info
} }
@ -1630,10 +1634,16 @@ export class EngineCommandManager extends EventTarget {
break break
} }
case ExportIntent.Make: { case ExportIntent.Make: {
if (!this.machineManager) {
console.warn('Some how, no manufacturing machine is selected.')
break
}
exportMake( exportMake(
event.data, event.data,
this.exportInfo.name, this.exportInfo.name,
this.pendingExport.toastId this.pendingExport.toastId,
this.machineManager
).then((result) => { ).then((result) => {
if (result) { if (result) {
this.pendingExport?.resolve(null) this.pendingExport?.resolve(null)

View File

@ -3,7 +3,6 @@ import { StateMachineCommandSetConfig, KclCommandValue } from 'lib/commandTypes'
import { KCL_DEFAULT_LENGTH, KCL_DEFAULT_DEGREE } from 'lib/constants' import { KCL_DEFAULT_LENGTH, KCL_DEFAULT_DEGREE } from 'lib/constants'
import { components } from 'lib/machine-api' import { components } from 'lib/machine-api'
import { Selections } from 'lib/selections' import { Selections } from 'lib/selections'
import { machineManager } from 'lib/machineManager'
import { modelingMachine, SketchTool } from 'machines/modelingMachine' import { modelingMachine, SketchTool } from 'machines/modelingMachine'
type OutputFormat = Models['OutputFormat_type'] type OutputFormat = Models['OutputFormat_type']
@ -187,9 +186,10 @@ export const modelingMachineCommandConfig: StateMachineCommandSetConfig<
machine.make_model.model || machine.make_model.model ||
machine.make_model.manufacturer || machine.make_model.manufacturer ||
'Unknown Machine', 'Unknown Machine',
options: () => { options: (commandBarContext) => {
return Object.entries(machineManager.machines).map( return Object.values(
([_, machine]) => ({ commandBarContext.machineManager?.machines || []
).map((machine: components['schemas']['MachineInfoResponse']) => ({
name: name:
`${machine.id} (${ `${machine.id} (${
machine.make_model.model || machine.make_model.manufacturer machine.make_model.model || machine.make_model.manufacturer
@ -215,13 +215,12 @@ export const modelingMachineCommandConfig: StateMachineCommandSetConfig<
: ''), : ''),
isCurrent: false, isCurrent: false,
disabled: machine.state.state !== 'idle', disabled: machine.state.state !== 'idle',
value: machine as components['schemas']['MachineInfoResponse'], value: machine,
}) }))
)
}, },
defaultValue: () => { defaultValue: (commandBarContext) => {
return Object.values( return Object.values(
machineManager.machines commandBarContext.machineManager.machines || []
)[0] as components['schemas']['MachineInfoResponse'] )[0] as components['schemas']['MachineInfoResponse']
}, },
}, },

View File

@ -5,6 +5,7 @@ import { Selection } from './selections'
import { Identifier, Expr, VariableDeclaration } from 'lang/wasm' import { Identifier, Expr, VariableDeclaration } from 'lang/wasm'
import { commandBarMachine } from 'machines/commandBarMachine' import { commandBarMachine } from 'machines/commandBarMachine'
import { ReactNode } from 'react' import { ReactNode } from 'react'
import { MachineManager } from 'components/MachineManagerProvider'
type Icon = CustomIconName type Icon = CustomIconName
const PLATFORMS = ['both', 'web', 'desktop'] as const const PLATFORMS = ['both', 'web', 'desktop'] as const
@ -127,6 +128,7 @@ export type CommandArgumentConfig<
| (( | ((
commandBarContext: { commandBarContext: {
argumentsToSubmit: Record<string, unknown> argumentsToSubmit: Record<string, unknown>
machineManager?: MachineManager
}, // Should be the commandbarMachine's context, but it creates a circular dependency }, // Should be the commandbarMachine's context, but it creates a circular dependency
machineContext?: C machineContext?: C
) => CommandArgumentOption<OutputType>[]) ) => CommandArgumentOption<OutputType>[])

View File

@ -1,5 +1,5 @@
import { deserialize_files } from 'wasm-lib/pkg/wasm_lib' import { deserialize_files } from 'wasm-lib/pkg/wasm_lib'
import { machineManager } from './machineManager' import { MachineManager } from 'components/MachineManagerProvider'
import toast from 'react-hot-toast' import toast from 'react-hot-toast'
import { components } from './machine-api' import { components } from './machine-api'
import ModelingAppFile from './modelingAppFile' import ModelingAppFile from './modelingAppFile'
@ -9,7 +9,8 @@ import { MAKE_TOAST_MESSAGES } from './constants'
export async function exportMake( export async function exportMake(
data: ArrayBuffer, data: ArrayBuffer,
name: string, name: string,
toastId: string toastId: string,
machineManager: MachineManager
): Promise<Response | null> { ): Promise<Response | null> {
if (name === '') { if (name === '') {
console.error(MAKE_TOAST_MESSAGES.NO_NAME) console.error(MAKE_TOAST_MESSAGES.NO_NAME)
@ -17,7 +18,7 @@ export async function exportMake(
return null return null
} }
if (machineManager.machineCount() === 0) { if (machineManager.machines.length === 0) {
console.error(MAKE_TOAST_MESSAGES.NO_MACHINES) console.error(MAKE_TOAST_MESSAGES.NO_MACHINES)
toast.error(MAKE_TOAST_MESSAGES.NO_MACHINES, { id: toastId }) toast.error(MAKE_TOAST_MESSAGES.NO_MACHINES, { id: toastId })
return null return null

View File

@ -1,105 +0,0 @@
import { isDesktop } from './isDesktop'
import { components } from './machine-api'
import { reportRejection } from './trap'
import { toSync } from './utils'
export type MachinesListing = Array<
components['schemas']['MachineInfoResponse']
>
export class MachineManager {
private _isDesktop: boolean = isDesktop()
private _machines: MachinesListing = []
private _machineApiIp: string | null = null
private _currentMachine: components['schemas']['MachineInfoResponse'] | null =
null
constructor() {
if (!this._isDesktop) {
return
}
this.updateMachines().catch(reportRejection)
}
start() {
if (!this._isDesktop) {
return
}
// Start a background job to update the machines every ten seconds.
// If MDNS is already watching, this timeout will wait until it's done to trigger the
// finding again.
let timeoutId: ReturnType<typeof setTimeout> | undefined = undefined
const timeoutLoop = () => {
clearTimeout(timeoutId)
timeoutId = setTimeout(
toSync(async () => {
await this.updateMachineApiIp()
await this.updateMachines()
timeoutLoop()
}, reportRejection),
10000
)
}
timeoutLoop()
}
get machines(): MachinesListing {
return this._machines
}
machineCount(): number {
return this._machines.length
}
get machineApiIp(): string | null {
return this._machineApiIp
}
// Get the reason message for why there are no machines.
noMachinesReason(): string | undefined {
if (this.machineCount() > 0) {
return undefined
}
if (this.machineApiIp === null) {
return 'Machine API server was not discovered'
}
return 'Machine API server was discovered, but no machines are available'
}
get currentMachine(): components['schemas']['MachineInfoResponse'] | null {
return this._currentMachine
}
set currentMachine(
machine: components['schemas']['MachineInfoResponse'] | null
) {
this._currentMachine = machine
}
private async updateMachines(): Promise<void> {
if (!this._isDesktop) {
return
}
if (this._machineApiIp === null) {
return
}
this._machines = await window.electron.listMachines(this._machineApiIp)
}
private async updateMachineApiIp(): Promise<void> {
if (!this._isDesktop) {
return
}
this._machineApiIp = await window.electron.getMachineApiIp()
}
}
export const machineManager = new MachineManager()
machineManager.start()

View File

@ -7,6 +7,7 @@ import {
} from 'lib/commandTypes' } from 'lib/commandTypes'
import { Selections } from 'lib/selections' import { Selections } from 'lib/selections'
import { getCommandArgumentKclValuesOnly } from 'lib/commandUtils' import { getCommandArgumentKclValuesOnly } from 'lib/commandUtils'
import { MachineManager } from 'components/MachineManagerProvider'
export type CommandBarContext = { export type CommandBarContext = {
commands: Command[] commands: Command[]
@ -14,6 +15,7 @@ export type CommandBarContext = {
currentArgument?: CommandArgument<unknown> & { name: string } currentArgument?: CommandArgument<unknown> & { name: string }
selectionRanges: Selections selectionRanges: Selections
argumentsToSubmit: { [x: string]: unknown } argumentsToSubmit: { [x: string]: unknown }
machineManager: MachineManager
} }
export type CommandBarMachineEvent = export type CommandBarMachineEvent =
@ -71,6 +73,7 @@ export type CommandBarMachineEvent =
type: 'Change current argument' type: 'Change current argument'
data: { [x: string]: CommandArgumentWithName<unknown> } data: { [x: string]: CommandArgumentWithName<unknown> }
} }
| { type: 'Set machine manager'; data: MachineManager }
export const commandBarMachine = setup({ export const commandBarMachine = setup({
types: { types: {
@ -90,6 +93,12 @@ export const commandBarMachine = setup({
} }
}, },
}), }),
'Set machine manager': assign({
machineManager: ({ event, context }) => {
if (event.type !== 'Set machine manager') return context.machineManager
return event.data
},
}),
'Execute command': ({ context, event }) => { 'Execute command': ({ context, event }) => {
const { selectedCommand } = context const { selectedCommand } = context
if (!selectedCommand) return if (!selectedCommand) return
@ -339,6 +348,13 @@ export const commandBarMachine = setup({
codeBasedSelections: [], codeBasedSelections: [],
}, },
argumentsToSubmit: {}, argumentsToSubmit: {},
machineManager: {
machines: [],
machineApiIp: null,
currentMachine: null,
setCurrentMachine: () => {},
noMachinesReason: () => undefined,
},
}, },
id: 'Command Bar', id: 'Command Bar',
initial: 'Closed', initial: 'Closed',
@ -520,6 +536,11 @@ export const commandBarMachine = setup({
}, },
}, },
on: { on: {
'Set machine manager': {
reenter: false,
actions: 'Set machine manager',
},
Close: { Close: {
target: '.Closed', target: '.Closed',
}, },

View File

@ -64,6 +64,7 @@ import toast from 'react-hot-toast'
import { ToolbarModeName } from 'lib/toolbar' import { ToolbarModeName } from 'lib/toolbar'
import { quaternionFromUpNForward } from 'clientSideScene/helpers' import { quaternionFromUpNForward } from 'clientSideScene/helpers'
import { Vector3 } from 'three' import { Vector3 } from 'three'
import { MachineManager } from 'components/MachineManagerProvider'
export const MODELING_PERSIST_KEY = 'MODELING_PERSIST_KEY' export const MODELING_PERSIST_KEY = 'MODELING_PERSIST_KEY'
@ -301,6 +302,7 @@ export const getPersistedContext = (): Partial<PersistedModelingContext> => {
export interface ModelingMachineContext { export interface ModelingMachineContext {
currentMode: ToolbarModeName currentMode: ToolbarModeName
currentTool: SketchTool currentTool: SketchTool
machineManager: MachineManager
selection: string[] selection: string[]
selectionRanges: Selections selectionRanges: Selections
sketchDetails: SketchDetails | null sketchDetails: SketchDetails | null
@ -315,6 +317,13 @@ export interface ModelingMachineContext {
export const modelingMachineDefaultContext: ModelingMachineContext = { export const modelingMachineDefaultContext: ModelingMachineContext = {
currentMode: 'modeling', currentMode: 'modeling',
currentTool: 'none', currentTool: 'none',
machineManager: {
machines: [],
machineApiIp: null,
currentMachine: null,
setCurrentMachine: () => {},
noMachinesReason: () => undefined,
},
selection: [], selection: [],
selectionRanges: { selectionRanges: {
otherSelections: [], otherSelections: [],

View File

@ -4,7 +4,7 @@ import fs from 'node:fs/promises'
import os from 'node:os' import os from 'node:os'
import fsSync from 'node:fs' import fsSync from 'node:fs'
import packageJson from '../package.json' import packageJson from '../package.json'
import { MachinesListing } from 'lib/machineManager' import { MachinesListing } from 'components/MachineManagerProvider'
import chokidar from 'chokidar' import chokidar from 'chokidar'
const open = (args: any) => ipcRenderer.invoke('dialog.showOpenDialog', args) const open = (args: any) => ipcRenderer.invoke('dialog.showOpenDialog', args)

View File

@ -1542,7 +1542,7 @@ dependencies = [
[[package]] [[package]]
name = "kcl-lib" name = "kcl-lib"
version = "0.2.22" version = "0.2.23"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"approx 0.5.1", "approx 0.5.1",
@ -1617,7 +1617,7 @@ dependencies = [
[[package]] [[package]]
name = "kcl-test-server" name = "kcl-test-server"
version = "0.1.14" version = "0.1.15"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"hyper 0.14.30", "hyper 0.14.30",
@ -1644,9 +1644,9 @@ dependencies = [
[[package]] [[package]]
name = "kittycad" name = "kittycad"
version = "0.3.23" version = "0.3.25"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "71b6f0c34165939697548dd0c94221200dbb8b5d1c84b5d8e803e70f9f720ea7" checksum = "f6359cc0a1bbccbcf78775eea17a033cf2aa89d3fe6a9784f8ce94e5f882c185"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"async-trait", "async-trait",
@ -1684,9 +1684,9 @@ dependencies = [
[[package]] [[package]]
name = "kittycad-modeling-cmds" name = "kittycad-modeling-cmds"
version = "0.2.70" version = "0.2.71"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b135696d07a4fab928e5abace4dd05f4976eafab5d73e5747a85dc5a684b936c" checksum = "c6d2160dcb0e5373b1242a760dbf17fb9c12de523c410c11b145381c852b377b"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"chrono", "chrono",
@ -2586,9 +2586,9 @@ dependencies = [
[[package]] [[package]]
name = "regex" name = "regex"
version = "1.11.0" version = "1.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38200e5ee88914975b69f657f0801b6f6dccafd44fd9326302a4aaeecfacb1d8" checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191"
dependencies = [ dependencies = [
"aho-corasick", "aho-corasick",
"memchr", "memchr",

View File

@ -71,8 +71,8 @@ members = [
[workspace.dependencies] [workspace.dependencies]
http = "1" http = "1"
kittycad = { version = "0.3.23", default-features = false, features = ["js", "requests"] } kittycad = { version = "0.3.25", default-features = false, features = ["js", "requests"] }
kittycad-modeling-cmds = { version = "0.2.70", features = ["websocket"] } kittycad-modeling-cmds = { version = "0.2.71", features = ["websocket"] }
[[test]] [[test]]
name = "executor" name = "executor"

View File

@ -17,7 +17,7 @@ convert_case = "0.6.0"
once_cell = "1.20.2" once_cell = "1.20.2"
proc-macro2 = "1" proc-macro2 = "1"
quote = "1" quote = "1"
regex = "1.10" regex = "1.11"
serde = { version = "1.0.213", features = ["derive"] } serde = { version = "1.0.213", features = ["derive"] }
serde_tokenstream = "0.2" serde_tokenstream = "0.2"
syn = { version = "2.0.85", features = ["full"] } syn = { version = "2.0.85", features = ["full"] }

View File

@ -1,7 +1,7 @@
[package] [package]
name = "kcl-test-server" name = "kcl-test-server"
description = "A test server for KCL" description = "A test server for KCL"
version = "0.1.14" version = "0.1.15"
edition = "2021" edition = "2021"
license = "MIT" license = "MIT"

View File

@ -31,7 +31,7 @@ pub struct ServerArgs {
/// Where to find the engine. /// Where to find the engine.
/// If none, uses the prod engine. /// If none, uses the prod engine.
/// This is useful for testing a local engine instance. /// This is useful for testing a local engine instance.
/// Overridden by the $LOCAL_ENGINE_ADDR environment variable. /// Overridden by the $ZOO_HOST environment variable.
pub engine_address: Option<String>, pub engine_address: Option<String>,
} }
@ -44,8 +44,8 @@ impl ServerArgs {
num_engine_conns: pargs.opt_value_from_str("--num-engine-conns")?.unwrap_or(1), num_engine_conns: pargs.opt_value_from_str("--num-engine-conns")?.unwrap_or(1),
engine_address: pargs.opt_value_from_str("--engine-address")?, engine_address: pargs.opt_value_from_str("--engine-address")?,
}; };
if let Ok(addr) = std::env::var("LOCAL_ENGINE_ADDR") { if let Ok(addr) = std::env::var("ZOO_HOST") {
println!("Overriding engine address via $LOCAL_ENGINE_ADDR"); println!("Overriding engine address via $ZOO_HOST");
args.engine_address = Some(addr); args.engine_address = Some(addr);
} }
println!("Config is {args:?}"); println!("Config is {args:?}");

View File

@ -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.22" version = "0.2.23"
edition = "2021" edition = "2021"
license = "MIT" license = "MIT"
repository = "https://github.com/KittyCAD/modeling-app" repository = "https://github.com/KittyCAD/modeling-app"

View File

@ -1127,7 +1127,7 @@ pub struct TagEngineInfo {
/// The sketch the tag is on. /// The sketch the tag is on.
pub sketch: uuid::Uuid, pub sketch: uuid::Uuid,
/// The path the tag is on. /// The path the tag is on.
pub path: Option<BasePath>, pub path: Option<Path>,
/// The surface information for the tag. /// The surface information for the tag.
pub surface: Option<ExtrudeSurface>, pub surface: Option<ExtrudeSurface>,
} }
@ -1206,7 +1206,7 @@ impl Sketch {
tag_identifier.info = Some(TagEngineInfo { tag_identifier.info = Some(TagEngineInfo {
id: base.geo_meta.id, id: base.geo_meta.id,
sketch: self.id, sketch: self.id,
path: Some(base.clone()), path: Some(current_path.clone()),
surface: None, surface: None,
}); });
@ -1656,6 +1656,43 @@ pub enum Path {
#[serde(flatten)] #[serde(flatten)]
base: BasePath, base: BasePath,
}, },
/// A circular arc, not necessarily tangential to the current point.
Arc {
#[serde(flatten)]
base: BasePath,
/// Center of the circle that this arc is drawn on.
center: [f64; 2],
/// Radius of the circle that this arc is drawn on.
radius: f64,
},
}
/// What kind of path is this?
#[derive(Display)]
enum PathType {
ToPoint,
Base,
TangentialArc,
TangentialArcTo,
Circle,
Horizontal,
AngledLineTo,
Arc,
}
impl From<&Path> for PathType {
fn from(value: &Path) -> Self {
match value {
Path::ToPoint { .. } => Self::ToPoint,
Path::TangentialArcTo { .. } => Self::TangentialArcTo,
Path::TangentialArc { .. } => Self::TangentialArc,
Path::Circle { .. } => Self::Circle,
Path::Horizontal { .. } => Self::Horizontal,
Path::AngledLineTo { .. } => Self::AngledLineTo,
Path::Base { .. } => Self::Base,
Path::Arc { .. } => Self::Arc,
}
}
} }
impl Path { impl Path {
@ -1668,6 +1705,7 @@ impl Path {
Path::TangentialArcTo { base, .. } => base.geo_meta.id, Path::TangentialArcTo { base, .. } => base.geo_meta.id,
Path::TangentialArc { base, .. } => base.geo_meta.id, Path::TangentialArc { base, .. } => base.geo_meta.id,
Path::Circle { base, .. } => base.geo_meta.id, Path::Circle { base, .. } => base.geo_meta.id,
Path::Arc { base, .. } => base.geo_meta.id,
} }
} }
@ -1680,6 +1718,7 @@ impl Path {
Path::TangentialArcTo { base, .. } => base.tag.clone(), Path::TangentialArcTo { base, .. } => base.tag.clone(),
Path::TangentialArc { base, .. } => base.tag.clone(), Path::TangentialArc { base, .. } => base.tag.clone(),
Path::Circle { base, .. } => base.tag.clone(), Path::Circle { base, .. } => base.tag.clone(),
Path::Arc { base, .. } => base.tag.clone(),
} }
} }
@ -1692,6 +1731,47 @@ impl Path {
Path::TangentialArcTo { base, .. } => base, Path::TangentialArcTo { base, .. } => base,
Path::TangentialArc { base, .. } => base, Path::TangentialArc { base, .. } => base,
Path::Circle { base, .. } => base, Path::Circle { base, .. } => base,
Path::Arc { base, .. } => base,
}
}
/// Where does this path segment start?
pub fn get_from(&self) -> &[f64; 2] {
&self.get_base().from
}
/// Where does this path segment end?
pub fn get_to(&self) -> &[f64; 2] {
&self.get_base().to
}
/// Length of this path segment, in cartesian plane.
pub fn length(&self) -> f64 {
match self {
Self::ToPoint { .. } | Self::Base { .. } | Self::Horizontal { .. } | Self::AngledLineTo { .. } => {
linear_distance(self.get_from(), self.get_to())
}
Self::TangentialArc {
base: _,
center,
ccw: _,
}
| Self::TangentialArcTo {
base: _,
center,
ccw: _,
} => {
// The radius can be calculated as the linear distance between `to` and `center`,
// or between `from` and `center`. They should be the same.
let radius = linear_distance(self.get_from(), center);
debug_assert_eq!(radius, linear_distance(self.get_to(), center));
// TODO: Call engine utils to figure this out.
linear_distance(self.get_from(), self.get_to())
}
Self::Circle { radius, .. } => 2.0 * std::f64::consts::PI * radius,
Self::Arc { .. } => {
// TODO: Call engine utils to figure this out.
linear_distance(self.get_from(), self.get_to())
}
} }
} }
@ -1704,10 +1784,22 @@ impl Path {
Path::TangentialArcTo { base, .. } => Some(base), Path::TangentialArcTo { base, .. } => Some(base),
Path::TangentialArc { base, .. } => Some(base), Path::TangentialArc { base, .. } => Some(base),
Path::Circle { base, .. } => Some(base), Path::Circle { base, .. } => Some(base),
Path::Arc { base, .. } => Some(base),
} }
} }
} }
/// Compute the straight-line distance between a pair of (2D) points.
#[rustfmt::skip]
fn linear_distance(
[x0, y0]: &[f64; 2],
[x1, y1]: &[f64; 2]
) -> f64 {
let y_sq = (y1 - y0).powi(2);
let x_sq = (x1 - x0).powi(2);
(y_sq + x_sq).sqrt()
}
/// An extrude surface. /// An extrude surface.
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema)] #[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema)]
#[ts(export)] #[ts(export)]
@ -1888,9 +1980,73 @@ impl From<crate::settings::types::ModelingSettings> for ExecutorSettings {
} }
} }
/// Create a new zoo api client.
#[cfg(not(target_arch = "wasm32"))]
pub fn new_zoo_client(token: Option<String>, engine_addr: Option<String>) -> Result<kittycad::Client> {
let user_agent = concat!(env!("CARGO_PKG_NAME"), ".rs/", env!("CARGO_PKG_VERSION"),);
let http_client = reqwest::Client::builder()
.user_agent(user_agent)
// For file conversions we need this to be long.
.timeout(std::time::Duration::from_secs(600))
.connect_timeout(std::time::Duration::from_secs(60));
let ws_client = reqwest::Client::builder()
.user_agent(user_agent)
// For file conversions we need this to be long.
.timeout(std::time::Duration::from_secs(600))
.connect_timeout(std::time::Duration::from_secs(60))
.connection_verbose(true)
.tcp_keepalive(std::time::Duration::from_secs(600))
.http1_only();
let zoo_token_env = std::env::var("ZOO_API_TOKEN");
let token = if let Some(token) = token {
token
} else if let Ok(token) = std::env::var("KITTYCAD_API_TOKEN") {
if let Ok(zoo_token) = zoo_token_env {
if zoo_token != token {
return Err(anyhow::anyhow!(
"Both environment variables KITTYCAD_API_TOKEN=`{}` and ZOO_API_TOKEN=`{}` are set. Use only one.",
token,
zoo_token
));
}
}
token
} else if let Ok(token) = zoo_token_env {
token
} else {
return Err(anyhow::anyhow!(
"No API token found in environment variables. Use KITTYCAD_API_TOKEN or ZOO_API_TOKEN"
));
};
// Create the client.
let mut client = kittycad::Client::new_from_reqwest(token, http_client, ws_client);
// Set an engine address if it's set.
let kittycad_host_env = std::env::var("KITTYCAD_HOST");
if let Some(addr) = engine_addr {
client.set_base_url(addr);
} else if let Ok(addr) = std::env::var("ZOO_HOST") {
if let Ok(kittycad_host) = kittycad_host_env {
if kittycad_host != addr {
return Err(anyhow::anyhow!(
"Both environment variables KITTYCAD_HOST=`{}` and ZOO_HOST=`{}` are set. Use only one.",
kittycad_host,
addr
));
}
}
client.set_base_url(addr);
} else if let Ok(addr) = kittycad_host_env {
client.set_base_url(addr);
}
Ok(client)
}
impl ExecutorContext { impl ExecutorContext {
/// Create a new default executor context. /// Create a new default executor context.
/// Also returns the response HTTP headers from the server.
#[cfg(not(target_arch = "wasm32"))] #[cfg(not(target_arch = "wasm32"))]
pub async fn new(client: &kittycad::Client, settings: ExecutorSettings) -> Result<Self> { pub async fn new(client: &kittycad::Client, settings: ExecutorSettings) -> Result<Self> {
let (ws, _headers) = client let (ws, _headers) = client
@ -1935,6 +2091,35 @@ impl ExecutorContext {
}) })
} }
/// Create a new default executor context.
/// With a kittycad client.
/// This allows for passing in `ZOO_API_TOKEN` and `ZOO_HOST` as environment
/// variables.
/// But also allows for passing in a token and engine address directly.
#[cfg(not(target_arch = "wasm32"))]
pub async fn new_with_client(
settings: ExecutorSettings,
token: Option<String>,
engine_addr: Option<String>,
) -> Result<Self> {
// Create the client.
let client = new_zoo_client(token, engine_addr)?;
let ctx = Self::new(&client, settings).await?;
Ok(ctx)
}
/// Create a new default executor context.
/// With the default kittycad client.
/// This allows for passing in `ZOO_API_TOKEN` and `ZOO_HOST` as environment
/// variables.
#[cfg(not(target_arch = "wasm32"))]
pub async fn new_with_default_client(settings: ExecutorSettings) -> Result<Self> {
// Create the client.
let ctx = Self::new_with_client(settings, None, None).await?;
Ok(ctx)
}
pub fn is_mock(&self) -> bool { pub fn is_mock(&self) -> bool {
self.context_type == ContextType::Mock || self.context_type == ContextType::MockCustomForwarded self.context_type == ContextType::Mock || self.context_type == ContextType::MockCustomForwarded
} }
@ -1942,35 +2127,7 @@ impl ExecutorContext {
/// For executing unit tests. /// For executing unit tests.
#[cfg(not(target_arch = "wasm32"))] #[cfg(not(target_arch = "wasm32"))]
pub async fn new_for_unit_test(units: UnitLength, engine_addr: Option<String>) -> Result<Self> { pub async fn new_for_unit_test(units: UnitLength, engine_addr: Option<String>) -> Result<Self> {
let user_agent = concat!(env!("CARGO_PKG_NAME"), ".rs/", env!("CARGO_PKG_VERSION")); let ctx = ExecutorContext::new_with_client(
let http_client = reqwest::Client::builder()
.user_agent(user_agent)
// For file conversions we need this to be long.
.timeout(std::time::Duration::from_secs(600))
.connect_timeout(std::time::Duration::from_secs(60));
let ws_client = reqwest::Client::builder()
.user_agent(user_agent)
// For file conversions we need this to be long.
.timeout(std::time::Duration::from_secs(600))
.connect_timeout(std::time::Duration::from_secs(60))
.connection_verbose(true)
.tcp_keepalive(std::time::Duration::from_secs(600))
.http1_only();
let token = std::env::var("KITTYCAD_API_TOKEN").expect("KITTYCAD_API_TOKEN not set");
// Create the client.
let mut client = kittycad::Client::new_from_reqwest(token, http_client, ws_client);
// Set a local engine address if it's set.
if let Ok(addr) = std::env::var("LOCAL_ENGINE_ADDR") {
client.set_base_url(addr);
}
if let Some(addr) = engine_addr {
client.set_base_url(addr);
}
let ctx = ExecutorContext::new(
&client,
ExecutorSettings { ExecutorSettings {
units, units,
highlight_edges: true, highlight_edges: true,
@ -1978,6 +2135,8 @@ impl ExecutorContext {
show_grid: false, show_grid: false,
replay: None, replay: None,
}, },
None,
engine_addr,
) )
.await?; .await?;
Ok(ctx) Ok(ctx)

View File

@ -3,41 +3,13 @@ use std::sync::{Arc, RwLock};
use anyhow::Result; use anyhow::Result;
use tower_lsp::LanguageServer; use tower_lsp::LanguageServer;
fn new_zoo_client() -> kittycad::Client {
let user_agent = concat!(env!("CARGO_PKG_NAME"), ".rs/", env!("CARGO_PKG_VERSION"),);
let http_client = reqwest::Client::builder()
.user_agent(user_agent)
// For file conversions we need this to be long.
.timeout(std::time::Duration::from_secs(600))
.connect_timeout(std::time::Duration::from_secs(60));
let ws_client = reqwest::Client::builder()
.user_agent(user_agent)
// For file conversions we need this to be long.
.timeout(std::time::Duration::from_secs(600))
.connect_timeout(std::time::Duration::from_secs(60))
.connection_verbose(true)
.tcp_keepalive(std::time::Duration::from_secs(600))
.http1_only();
let token = std::env::var("KITTYCAD_API_TOKEN").expect("KITTYCAD_API_TOKEN not set");
// Create the client.
let mut client = kittycad::Client::new_from_reqwest(token, http_client, ws_client);
// Set a local engine address if it's set.
if let Ok(addr) = std::env::var("LOCAL_ENGINE_ADDR") {
client.set_base_url(addr);
}
client
}
// Create a fake kcl lsp server for testing. // Create a fake kcl lsp server for testing.
pub async fn kcl_lsp_server(execute: bool) -> Result<crate::lsp::kcl::Backend> { pub async fn kcl_lsp_server(execute: bool) -> Result<crate::lsp::kcl::Backend> {
let stdlib = crate::std::StdLib::new(); let stdlib = crate::std::StdLib::new();
let stdlib_completions = crate::lsp::kcl::get_completions_from_stdlib(&stdlib)?; let stdlib_completions = crate::lsp::kcl::get_completions_from_stdlib(&stdlib)?;
let stdlib_signatures = crate::lsp::kcl::get_signatures_from_stdlib(&stdlib)?; let stdlib_signatures = crate::lsp::kcl::get_signatures_from_stdlib(&stdlib)?;
let zoo_client = new_zoo_client(); let zoo_client = crate::executor::new_zoo_client(None, None)?;
let executor_ctx = if execute { let executor_ctx = if execute {
Some(crate::executor::ExecutorContext::new(&zoo_client, Default::default()).await?) Some(crate::executor::ExecutorContext::new(&zoo_client, Default::default()).await?)

View File

@ -149,7 +149,7 @@ pub(crate) async fn do_post_extrude(
} }
let edge_id = sketch.paths.iter().find_map(|segment| match segment { let edge_id = sketch.paths.iter().find_map(|segment| match segment {
Path::ToPoint { base } | Path::Circle { base, .. } => Some(base.geo_meta.id), Path::ToPoint { base } | Path::Circle { base, .. } | Path::Arc { base, .. } => Some(base.geo_meta.id),
_ => None, _ => None,
}); });
@ -234,7 +234,10 @@ pub(crate) async fn do_post_extrude(
.flat_map(|path| { .flat_map(|path| {
if let Some(Some(actual_face_id)) = face_id_map.get(&path.get_base().geo_meta.id) { if let Some(Some(actual_face_id)) = face_id_map.get(&path.get_base().geo_meta.id) {
match path { match path {
Path::TangentialArc { .. } | Path::TangentialArcTo { .. } | Path::Circle { .. } => { Path::Arc { .. }
| Path::TangentialArc { .. }
| Path::TangentialArcTo { .. }
| Path::Circle { .. } => {
let extrude_surface = ExtrudeSurface::ExtrudeArc(crate::executor::ExtrudeArc { let extrude_surface = ExtrudeSurface::ExtrudeArc(crate::executor::ExtrudeArc {
face_id: *actual_face_id, face_id: *actual_face_id,
tag: path.get_base().tag.clone(), tag: path.get_base().tag.clone(),

View File

@ -42,7 +42,7 @@ fn inner_segment_end_x(tag: &TagIdentifier, exec_state: &mut ExecState, args: Ar
}) })
})?; })?;
Ok(path.to[0]) Ok(path.get_base().to[0])
} }
/// Returns the segment end of y. /// Returns the segment end of y.
@ -79,7 +79,7 @@ fn inner_segment_end_y(tag: &TagIdentifier, exec_state: &mut ExecState, args: Ar
}) })
})?; })?;
Ok(path.to[1]) Ok(path.get_to()[1])
} }
/// Returns the last segment of x. /// Returns the last segment of x.
@ -202,7 +202,7 @@ fn inner_segment_length(tag: &TagIdentifier, exec_state: &mut ExecState, args: A
}) })
})?; })?;
let result = ((path.from[1] - path.to[1]).powi(2) + (path.from[0] - path.to[0]).powi(2)).sqrt(); let result = path.length();
Ok(result) Ok(result)
} }
@ -242,7 +242,7 @@ fn inner_segment_angle(tag: &TagIdentifier, exec_state: &mut ExecState, args: Ar
}) })
})?; })?;
let result = between(path.from.into(), path.to.into()); let result = between(path.get_from().into(), path.get_to().into());
Ok(result.to_degrees()) Ok(result.to_degrees())
} }
@ -286,7 +286,7 @@ fn inner_angle_to_match_length_x(
}) })
})?; })?;
let length = ((path.from[1] - path.to[1]).powi(2) + (path.from[0] - path.to[0]).powi(2)).sqrt(); let length = path.length();
let last_line = sketch let last_line = sketch
.paths .paths
@ -350,7 +350,7 @@ fn inner_angle_to_match_length_y(
}) })
})?; })?;
let length = ((path.from[1] - path.to[1]).powi(2) + (path.from[0] - path.to[0]).powi(2)).sqrt(); let length = path.length();
let last_line = sketch let last_line = sketch
.paths .paths

View File

@ -813,7 +813,7 @@ async fn inner_angled_line_that_intersects(
let from = sketch.current_pen_position()?; let from = sketch.current_pen_position()?;
let to = intersection_with_parallel_line( let to = intersection_with_parallel_line(
&[path.from.into(), path.to.into()], &[path.get_from().into(), path.get_to().into()],
data.offset.unwrap_or_default(), data.offset.unwrap_or_default(),
data.angle, data.angle,
from, from,
@ -1244,7 +1244,9 @@ pub(crate) async fn inner_start_profile_at(
tag_identifier.info = Some(TagEngineInfo { tag_identifier.info = Some(TagEngineInfo {
id: current_path.geo_meta.id, id: current_path.geo_meta.id,
sketch: path_id, sketch: path_id,
path: Some(current_path.clone()), path: Some(Path::Base {
base: current_path.clone(),
}),
surface: None, surface: None,
}); });
HashMap::from([(tag.name.to_string(), tag_identifier)]) HashMap::from([(tag.name.to_string(), tag_identifier)])
@ -1528,7 +1530,7 @@ pub(crate) async fn inner_arc(
) )
.await?; .await?;
let current_path = Path::ToPoint { let current_path = Path::Arc {
base: BasePath { base: BasePath {
from: from.into(), from: from.into(),
to: end.into(), to: end.into(),
@ -1538,6 +1540,8 @@ pub(crate) async fn inner_arc(
metadata: args.source_range.into(), metadata: args.source_range.into(),
}, },
}, },
center: center.into(),
radius,
}; };
let mut new_sketch = sketch.clone(); let mut new_sketch = sketch.clone();

View File

@ -21,7 +21,7 @@ pub fn normalize(angle: Angle) -> Angle {
Angle::from_degrees(if result > 180.0 { result - 360.0 } else { result }) Angle::from_degrees(if result > 180.0 { result - 360.0 } else { result })
} }
/// Gives the ▲-angle between from and to angles (shortest path), use radians. /// Gives the ▲-angle between from and to angles (shortest path)
/// ///
/// Sign of the returned angle denotes direction, positive means counterClockwise 🔄 /// Sign of the returned angle denotes direction, positive means counterClockwise 🔄
/// # Examples /// # Examples

View File

@ -43,38 +43,7 @@ async fn do_execute_and_snapshot(ctx: &ExecutorContext, code: &str) -> anyhow::R
} }
async fn new_context(units: UnitLength, with_auth: bool) -> anyhow::Result<ExecutorContext> { async fn new_context(units: UnitLength, with_auth: bool) -> anyhow::Result<ExecutorContext> {
let user_agent = concat!(env!("CARGO_PKG_NAME"), ".rs/", env!("CARGO_PKG_VERSION"),); let ctx = ExecutorContext::new_with_client(
let http_client = reqwest::Client::builder()
.user_agent(user_agent)
// For file conversions we need this to be long.
.timeout(std::time::Duration::from_secs(600))
.connect_timeout(std::time::Duration::from_secs(60));
let ws_client = reqwest::Client::builder()
.user_agent(user_agent)
// For file conversions we need this to be long.
.timeout(std::time::Duration::from_secs(600))
.connect_timeout(std::time::Duration::from_secs(60))
.connection_verbose(true)
.tcp_keepalive(std::time::Duration::from_secs(600))
.http1_only();
let token = if with_auth {
std::env::var("KITTYCAD_API_TOKEN").expect("KITTYCAD_API_TOKEN not set")
} else {
"bad_token".to_string()
};
// Create the client.
let mut client = kittycad::Client::new_from_reqwest(token, http_client, ws_client);
// Set a local engine address if it's set.
if let Ok(addr) = std::env::var("LOCAL_ENGINE_ADDR") {
if with_auth {
client.set_base_url(addr);
}
}
let ctx = ExecutorContext::new(
&client,
ExecutorSettings { ExecutorSettings {
units, units,
highlight_edges: true, highlight_edges: true,
@ -82,6 +51,8 @@ async fn new_context(units: UnitLength, with_auth: bool) -> anyhow::Result<Execu
show_grid: false, show_grid: false,
replay: None, replay: None,
}, },
if with_auth { None } else { Some("bad_token".to_string()) },
None,
) )
.await?; .await?;
Ok(ctx) Ok(ctx)

View File

@ -0,0 +1,15 @@
exampleSketch = startSketchOn('XZ')
|> startProfileAt([0, 0], %)
|> line([0, 2], %)
|> line([3, 1], %)
|> line([0, -4], %)
|> close(%)
|> extrude(1, %)
pattn1 = patternLinear3d({
axis: [1, 0, 0],
instances: 7,
distance: 6
}, exampleSketch)
pattn2 = patternCircular3d({axis: [0,0, 1], center: [-20, -20, -20], instances: 41, arcDegrees: 360, rotateDuplicates: false}, pattn1)

View File

@ -0,0 +1,19 @@
exampleSketch = startSketchOn('XZ')
|> startProfileAt([0, 0], %)
|> line([0, 2], %)
|> line([3, 1], %)
|> line([0, -4], %)
|> close(%)
|> extrude(1, %)
pattn1 = patternLinear3d({
axis: [1, 0, 0],
instances: 7,
distance: 6
}, exampleSketch)
pattn2 = patternLinear3d({
axis: [0, 0, 1],
distance: 1,
instances: 7
}, pattn1)

View File

@ -0,0 +1,6 @@
part001 = startSketchOn('-XZ')
|> startProfileAt([0, 0], %)
|> lineTo([100, 100], %)
|> lineTo([100, 0], %)
|> close(%)
|> extrude(5 + 7, %)

View File

@ -0,0 +1,55 @@
// Shelf Bracket
// This is a shelf bracket made out of 6061-T6 aluminum sheet metal. The required thickness is calculated based on a point load of 300 lbs applied to the end of the shelf. There are two brackets holding up the shelf, so the moment experienced is divided by 2. The shelf is 1 foot long from the wall.
// Define our bracket feet lengths
shelfMountL = 8 // The length of the bracket holding up the shelf is 6 inches
wallMountL = 6 // the length of the bracket
// Define constants required to calculate the thickness needed to support 300 lbs
sigmaAllow = 35000 // psi
width = 6 // inch
p = 300 // Force on shelf - lbs
L = 12 // inches
M = L * p / 2 // Moment experienced at fixed end of bracket
FOS = 2 // Factor of safety of 2 to be conservative
// Calculate the thickness off the bending stress and factor of safety
thickness = sqrt(6 * M * FOS / (width * sigmaAllow))
// 0.25 inch fillet radius
filletR = 0.25
// Sketch the bracket and extrude with fillets
bracket = startSketchOn('XY')
|> startProfileAt([0, 0], %)
|> line([0, wallMountL], %, $outerEdge)
|> line([-shelfMountL, 0], %, $seg01)
|> line([0, -thickness], %)
|> line([shelfMountL - thickness, 0], %, $innerEdge)
|> line([0, -wallMountL + thickness], %)
|> close(%)
|> extrude(width, %)
|> fillet({
radius: filletR,
tags: [
getNextAdjacentEdge(innerEdge)
]
}, %)
|> fillet({
radius: filletR + thickness,
tags: [
getNextAdjacentEdge(outerEdge)
]
}, %)
sketch001 = startSketchOn(bracket, seg01)
|> startProfileAt([4.28, 3.83], %)
|> line([2.17, -0.03], %)
|> line([-0.07, -1.8], %)
|> line([-2.07, 0.05], %)
|> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%)
|> extrude(10, %)

View File

@ -0,0 +1,6 @@
part001 = startSketchOn('XZ')
|> startProfileAt([0, 0], %)
|> lineTo([100, 100], %)
|> lineTo([100, 0], %)
|> close(%)
|> extrude(5 + 7, %)

View File

@ -1389,84 +1389,6 @@ extrusion = startSketchOn('XY')
); );
} }
#[tokio::test(flavor = "multi_thread")]
async fn kcl_test_xz_plane() {
let code = r#"part001 = startSketchOn('XZ')
|> startProfileAt([0, 0], %)
|> lineTo([100, 100], %)
|> lineTo([100, 0], %)
|> close(%)
|> extrude(5 + 7, %)
"#;
let result = execute_and_snapshot(code, UnitLength::Mm).await.unwrap();
assert_out("xz_plane", &result);
}
#[tokio::test(flavor = "multi_thread")]
async fn kcl_test_neg_xz_plane() {
let code = r#"part001 = startSketchOn('-XZ')
|> startProfileAt([0, 0], %)
|> lineTo([100, 100], %)
|> lineTo([100, 0], %)
|> close(%)
|> extrude(5 + 7, %)
"#;
let result = execute_and_snapshot(code, UnitLength::Mm).await.unwrap();
assert_out("neg_xz_plane", &result);
}
#[tokio::test(flavor = "multi_thread")]
async fn kcl_test_linear_pattern3d_a_pattern() {
let code = r#"exampleSketch = startSketchOn('XZ')
|> startProfileAt([0, 0], %)
|> line([0, 2], %)
|> line([3, 1], %)
|> line([0, -4], %)
|> close(%)
|> extrude(1, %)
pattn1 = patternLinear3d({
axis: [1, 0, 0],
instances: 7,
distance: 6
}, exampleSketch)
pattn2 = patternLinear3d({
axis: [0, 0, 1],
distance: 1,
instances: 7
}, pattn1)
"#;
let result = execute_and_snapshot(code, UnitLength::Mm).await.unwrap();
assert_out("linear_pattern3d_a_pattern", &result);
}
#[tokio::test(flavor = "multi_thread")]
async fn kcl_test_circular_pattern3d_a_pattern() {
let code = r#"exampleSketch = startSketchOn('XZ')
|> startProfileAt([0, 0], %)
|> line([0, 2], %)
|> line([3, 1], %)
|> line([0, -4], %)
|> close(%)
|> extrude(1, %)
pattn1 = patternLinear3d({
axis: [1, 0, 0],
instances: 7,
distance: 6
}, exampleSketch)
pattn2 = patternCircular3d({axis: [0,0, 1], center: [-20, -20, -20], instances: 41, arcDegrees: 360, rotateDuplicates: false}, pattn1)
"#;
let result = execute_and_snapshot(code, UnitLength::Mm).await.unwrap();
assert_out("circular_pattern3d_a_pattern", &result);
}
#[tokio::test(flavor = "multi_thread")] #[tokio::test(flavor = "multi_thread")]
async fn kcl_test_array_of_sketches() { async fn kcl_test_array_of_sketches() {
let code = r#"plane001 = startSketchOn('XZ') let code = r#"plane001 = startSketchOn('XZ')
@ -1496,69 +1418,6 @@ extrude(10, sketch001)
assert_out("array_of_sketches", &result); assert_out("array_of_sketches", &result);
} }
#[tokio::test(flavor = "multi_thread")]
async fn kcl_test_sketch_on_face_after_fillets_referencing_face() {
let code = r#"// Shelf Bracket
// This is a shelf bracket made out of 6061-T6 aluminum sheet metal. The required thickness is calculated based on a point load of 300 lbs applied to the end of the shelf. There are two brackets holding up the shelf, so the moment experienced is divided by 2. The shelf is 1 foot long from the wall.
// Define our bracket feet lengths
shelfMountL = 8 // The length of the bracket holding up the shelf is 6 inches
wallMountL = 6 // the length of the bracket
// Define constants required to calculate the thickness needed to support 300 lbs
sigmaAllow = 35000 // psi
width = 6 // inch
p = 300 // Force on shelf - lbs
L = 12 // inches
M = L * p / 2 // Moment experienced at fixed end of bracket
FOS = 2 // Factor of safety of 2 to be conservative
// Calculate the thickness off the bending stress and factor of safety
thickness = sqrt(6 * M * FOS / (width * sigmaAllow))
// 0.25 inch fillet radius
filletR = 0.25
// Sketch the bracket and extrude with fillets
bracket = startSketchOn('XY')
|> startProfileAt([0, 0], %)
|> line([0, wallMountL], %, $outerEdge)
|> line([-shelfMountL, 0], %, $seg01)
|> line([0, -thickness], %)
|> line([shelfMountL - thickness, 0], %, $innerEdge)
|> line([0, -wallMountL + thickness], %)
|> close(%)
|> extrude(width, %)
|> fillet({
radius: filletR,
tags: [
getNextAdjacentEdge(innerEdge)
]
}, %)
|> fillet({
radius: filletR + thickness,
tags: [
getNextAdjacentEdge(outerEdge)
]
}, %)
sketch001 = startSketchOn(bracket, seg01)
|> startProfileAt([4.28, 3.83], %)
|> line([2.17, -0.03], %)
|> line([-0.07, -1.8], %)
|> line([-2.07, 0.05], %)
|> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%)
|> extrude(10, %)
"#;
let result = execute_and_snapshot(code, UnitLength::Mm).await.unwrap();
assert_out("sketch_on_face_after_fillets_referencing_face", &result);
}
#[tokio::test(flavor = "multi_thread")] #[tokio::test(flavor = "multi_thread")]
async fn kcl_test_circular_pattern3d_array_of_extrudes() { async fn kcl_test_circular_pattern3d_array_of_extrudes() {
let code = r#"plane001 = startSketchOn('XZ') let code = r#"plane001 = startSketchOn('XZ')

Binary file not shown.

Before

Width:  |  Height:  |  Size: 133 KiB

After

Width:  |  Height:  |  Size: 127 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 54 KiB

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 61 KiB

After

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 52 KiB

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 35 KiB

After

Width:  |  Height:  |  Size: 33 KiB

View File

@ -19,6 +19,15 @@ macro_rules! kcl_test {
} }
kcl_test!("sketch_on_face", kcl_test_sketch_on_face); kcl_test!("sketch_on_face", kcl_test_sketch_on_face);
kcl_test!("neg_xz_plane", kcl_test_neg_xz_plane);
kcl_test!("xz_plane", kcl_test_xz_plane);
kcl_test!(
"sketch_on_face_after_fillets_referencing_face",
kcl_test_sketch_on_face_after_fillets_referencing_face
);
kcl_test!("circular_pattern3d_a_pattern", kcl_test_circular_pattern3d_a_pattern);
kcl_test!("linear_pattern3d_a_pattern", kcl_test_linear_pattern3d_a_pattern);
kcl_test!("tangential_arc", kcl_test_tangential_arc); kcl_test!("tangential_arc", kcl_test_tangential_arc);
kcl_test!( kcl_test!(
"big_number_angle_to_match_length_x", "big_number_angle_to_match_length_x",

View File

@ -8,33 +8,10 @@ use pretty_assertions::assert_eq;
/// Setup the engine and parse code for an ast. /// Setup the engine and parse code for an ast.
async fn setup(code: &str, name: &str) -> Result<(ExecutorContext, Program, uuid::Uuid)> { async fn setup(code: &str, name: &str) -> Result<(ExecutorContext, Program, uuid::Uuid)> {
let user_agent = concat!(env!("CARGO_PKG_NAME"), ".rs/", env!("CARGO_PKG_VERSION"),);
let http_client = reqwest::Client::builder()
.user_agent(user_agent)
// For file conversions we need this to be long.
.timeout(std::time::Duration::from_secs(600))
.connect_timeout(std::time::Duration::from_secs(60));
let ws_client = reqwest::Client::builder()
.user_agent(user_agent)
// For file conversions we need this to be long.
.timeout(std::time::Duration::from_secs(600))
.connect_timeout(std::time::Duration::from_secs(60))
.tcp_keepalive(std::time::Duration::from_secs(600))
.http1_only();
let token = std::env::var("KITTYCAD_API_TOKEN").expect("KITTYCAD_API_TOKEN not set");
// Create the client.
let mut client = kittycad::Client::new_from_reqwest(token, http_client, ws_client);
// Set a local engine address if it's set.
if let Ok(addr) = std::env::var("LOCAL_ENGINE_ADDR") {
client.set_base_url(addr);
}
let tokens = kcl_lib::token::lexer(code)?; let tokens = kcl_lib::token::lexer(code)?;
let parser = kcl_lib::parser::Parser::new(tokens); let parser = kcl_lib::parser::Parser::new(tokens);
let program = parser.ast()?; let program = parser.ast()?;
let ctx = kcl_lib::executor::ExecutorContext::new(&client, Default::default()).await?; let ctx = kcl_lib::executor::ExecutorContext::new_with_default_client(Default::default()).await?;
let exec_state = ctx.run(&program, None, IdGenerator::default(), None).await?; let exec_state = ctx.run(&program, None, IdGenerator::default(), None).await?;
// We need to get the sketch ID. // We need to get the sketch ID.