Display numeric units in the variables pane (#6683)

This commit is contained in:
Jonathan Tran
2025-05-05 23:40:18 -04:00
committed by GitHub
parent 32db31e6c3
commit 1e056cfd8a
69 changed files with 602 additions and 163 deletions

View File

@ -11,7 +11,7 @@ import { useModelingContext } from '@src/hooks/useModelingContext'
import { useResolvedTheme } from '@src/hooks/useResolvedTheme'
import { useKclContext } from '@src/lang/KclProvider'
import type { VariableMap } from '@src/lang/wasm'
import { sketchFromKclValueOptional } from '@src/lang/wasm'
import { humanDisplayNumber, sketchFromKclValueOptional } from '@src/lang/wasm'
import { Reason, trap } from '@src/lib/trap'
export const MemoryPaneMenu = () => {
@ -81,31 +81,29 @@ export const MemoryPane = () => {
}
export const processMemory = (variables: VariableMap) => {
const processedMemory: any = {}
const processedMemory: Record<
string,
string | number | boolean | object | undefined
> = {}
for (const [key, val] of Object.entries(variables)) {
if (val === undefined) continue
if (
val.type === 'Sketch' ||
// @ts-ignore
val.type !== 'Function'
) {
const sk = sketchFromKclValueOptional(val, key)
if (val.type === 'Solid') {
processedMemory[key] = val.value.value.map(
({ ...rest }: ExtrudeSurface) => {
return rest
}
)
} else if (!(sk instanceof Reason)) {
processedMemory[key] = sk.paths.map(({ __geoMeta, ...rest }: Path) => {
const sk = sketchFromKclValueOptional(val, key)
if (val.type === 'Solid') {
processedMemory[key] = val.value.value.map(
({ ...rest }: ExtrudeSurface) => {
return rest
})
} else {
processedMemory[key] = val.value
}
//@ts-ignore
}
)
} else if (!(sk instanceof Reason)) {
processedMemory[key] = sk.paths.map(({ __geoMeta, ...rest }: Path) => {
return rest
})
} else if (val.type === 'Function') {
processedMemory[key] = `__function__`
processedMemory[key] = '__function__'
} else if (val.type === 'Number') {
processedMemory[key] = humanDisplayNumber(val.value, val.ty)
} else {
processedMemory[key] = val.value
}
}
return processedMemory