fix types

This commit is contained in:
Kurt Hutten Irev-Dev
2025-02-03 22:06:24 +11:00
parent 4ec44690bf
commit 774e3efcb7
13 changed files with 38 additions and 46 deletions

View File

@ -101,7 +101,6 @@ test.describe('Sketch tests', () => {
page, page,
scene, scene,
homePage, homePage,
scene,
}) => { }) => {
const u = await getUtils(page) const u = await getUtils(page)
await page.addInitScript(async () => { await page.addInitScript(async () => {

View File

@ -124,14 +124,7 @@ export const ClientSideScene = ({
'mouseup', 'mouseup',
toSync(sceneInfra.onMouseUp, reportRejection) toSync(sceneInfra.onMouseUp, reportRejection)
) )
sceneEntitiesManager sceneEntitiesManager.tearDownSketch({ removeAxis: true })
.tearDownSketch()
.then(() => {
// no op
})
.catch((e) => {
console.error(e)
})
} }
}, []) }, [])

View File

@ -724,7 +724,7 @@ export class SceneEntities {
} }
const startRange = _node1.node.start const startRange = _node1.node.start
const endRange = _node1.node.end const endRange = _node1.node.end
const sourceRange: SourceRange = [startRange, endRange, true] const sourceRange: SourceRange = [startRange, endRange, 0]
const selection: Selections = computeSelectionFromSourceRangeAndAST( const selection: Selections = computeSelectionFromSourceRangeAndAST(
sourceRange, sourceRange,
maybeModdedAst maybeModdedAst
@ -793,7 +793,7 @@ export class SceneEntities {
) => { ) => {
if (trap(modifiedAst)) return Promise.reject(modifiedAst) if (trap(modifiedAst)) return Promise.reject(modifiedAst)
const nextAst = await kclManager.updateAst(modifiedAst, false) const nextAst = await kclManager.updateAst(modifiedAst, false)
await this.tearDownSketch({ removeAxis: false }) this.tearDownSketch({ removeAxis: false })
sceneInfra.resetMouseListeners() sceneInfra.resetMouseListeners()
await this.setupSketch({ await this.setupSketch({
sketchEntryNodePath, sketchEntryNodePath,
@ -859,7 +859,7 @@ export class SceneEntities {
const draftExpressionsIndices = { start: index, end: index } const draftExpressionsIndices = { start: index, end: index }
if (shouldTearDown) await this.tearDownSketch({ removeAxis: false }) if (shouldTearDown) this.tearDownSketch({ removeAxis: false })
sceneInfra.resetMouseListeners() sceneInfra.resetMouseListeners()
const { truncatedAst, programMemoryOverride } = await this.setupSketch({ const { truncatedAst, programMemoryOverride } = await this.setupSketch({
@ -1797,7 +1797,7 @@ export class SceneEntities {
sceneInfra.setCallbacks({ sceneInfra.setCallbacks({
onDragEnd: async () => { onDragEnd: async () => {
if (addingNewSegmentStatus !== 'nothing') { if (addingNewSegmentStatus !== 'nothing') {
await this.tearDownSketch({ removeAxis: false }) this.tearDownSketch({ removeAxis: false })
// eslint-disable-next-line @typescript-eslint/no-floating-promises // eslint-disable-next-line @typescript-eslint/no-floating-promises
this.setupSketch({ this.setupSketch({
sketchEntryNodePath, sketchEntryNodePath,
@ -1868,7 +1868,7 @@ export class SceneEntities {
if (trap(mod)) return if (trap(mod)) return
await kclManager.executeAstMock(mod.modifiedAst) await kclManager.executeAstMock(mod.modifiedAst)
await this.tearDownSketch({ removeAxis: false }) this.tearDownSketch({ removeAxis: false })
// eslint-disable-next-line @typescript-eslint/no-floating-promises // eslint-disable-next-line @typescript-eslint/no-floating-promises
this.setupSketch({ this.setupSketch({
sketchEntryNodePath: pathToNode, sketchEntryNodePath: pathToNode,
@ -2289,7 +2289,7 @@ export class SceneEntities {
removeSketchGrid() { removeSketchGrid() {
if (this.axisGroup) this.scene.remove(this.axisGroup) if (this.axisGroup) this.scene.remove(this.axisGroup)
} }
async tearDownSketch({ removeAxis = true }: { removeAxis?: boolean }) { tearDownSketch({ removeAxis = true }: { removeAxis?: boolean }) {
// Remove all draft groups // Remove all draft groups
this.draftPointGroups.forEach((draftPointGroup) => { this.draftPointGroups.forEach((draftPointGroup) => {
this.scene.remove(draftPointGroup) this.scene.remove(draftPointGroup)

View File

@ -767,8 +767,9 @@ export const ModelingMachineProvider = ({
sketchPathToNode: sketchPathToNode || [], sketchPathToNode: sketchPathToNode || [],
}) })
if (err(sketchPaths)) return Promise.reject(sketchPaths) if (err(sketchPaths)) return Promise.reject(sketchPaths)
if (!plane.codeRef) const noCodeRefErr = new Error('No plane codeRef')
return Promise.reject(new Error('No plane codeRef')) if (!('codeRef' in plane)) return Promise.reject(noCodeRefErr)
if (!plane.codeRef) return Promise.reject(noCodeRefErr)
return { return {
sketchEntryNodePath: sketchPathToNode || [], sketchEntryNodePath: sketchPathToNode || [],
sketchNodePaths: sketchPaths, sketchNodePaths: sketchPaths,
@ -1314,7 +1315,7 @@ export const ModelingMachineProvider = ({
async ({ input: { sketchDetails, data } }) => { async ({ input: { sketchDetails, data } }) => {
if (!sketchDetails || !data) if (!sketchDetails || !data)
return reject('No sketch details or data') return reject('No sketch details or data')
await sceneEntitiesManager.tearDownSketch({ removeAxis: false }) sceneEntitiesManager.tearDownSketch({ removeAxis: false })
const result = await sceneEntitiesManager.setupDraftCircle( const result = await sceneEntitiesManager.setupDraftCircle(
sketchDetails.sketchEntryNodePath, sketchDetails.sketchEntryNodePath,
@ -1335,7 +1336,7 @@ export const ModelingMachineProvider = ({
async ({ input: { sketchDetails, data } }) => { async ({ input: { sketchDetails, data } }) => {
if (!sketchDetails || !data) if (!sketchDetails || !data)
return reject('No sketch details or data') return reject('No sketch details or data')
await sceneEntitiesManager.tearDownSketch({ removeAxis: false }) sceneEntitiesManager.tearDownSketch({ removeAxis: false })
const result = const result =
await sceneEntitiesManager.setupDraftCircleThreePoint( await sceneEntitiesManager.setupDraftCircleThreePoint(
@ -1358,7 +1359,7 @@ export const ModelingMachineProvider = ({
async ({ input: { sketchDetails, data } }) => { async ({ input: { sketchDetails, data } }) => {
if (!sketchDetails || !data) if (!sketchDetails || !data)
return reject('No sketch details or data') return reject('No sketch details or data')
await sceneEntitiesManager.tearDownSketch({ removeAxis: false }) sceneEntitiesManager.tearDownSketch({ removeAxis: false })
const result = await sceneEntitiesManager.setupDraftRectangle( const result = await sceneEntitiesManager.setupDraftRectangle(
sketchDetails.sketchEntryNodePath, sketchDetails.sketchEntryNodePath,
@ -1379,7 +1380,7 @@ export const ModelingMachineProvider = ({
async ({ input: { sketchDetails, data } }) => { async ({ input: { sketchDetails, data } }) => {
if (!sketchDetails || !data) if (!sketchDetails || !data)
return reject('No sketch details or data') return reject('No sketch details or data')
await sceneEntitiesManager.tearDownSketch({ removeAxis: false }) sceneEntitiesManager.tearDownSketch({ removeAxis: false })
const result = await sceneEntitiesManager.setupDraftCenterRectangle( const result = await sceneEntitiesManager.setupDraftCenterRectangle(
sketchDetails.sketchEntryNodePath, sketchDetails.sketchEntryNodePath,
sketchDetails.sketchNodePaths, sketchDetails.sketchNodePaths,

View File

@ -379,12 +379,7 @@ export class KclManager {
} }
this.ast = { ...ast } this.ast = { ...ast }
// updateArtifactGraph relies on updated executeState/programMemory // updateArtifactGraph relies on updated executeState/programMemory
await this.engineCommandManager.updateArtifactGraph( await this.engineCommandManager.updateArtifactGraph(execState.artifactGraph)
this.ast,
execState.artifactCommands,
execState.artifacts,
args.isPartialExecution
)
this._executeCallback() this._executeCallback()
if (!isInterrupted) if (!isInterrupted)
sceneInfra.modelingSend({ type: 'code edit during sketch' }) sceneInfra.modelingSend({ type: 'code edit during sketch' })

View File

@ -950,10 +950,10 @@ extrude001 = extrude(5, part001)
const ast = assertParse(codeBefore) const ast = assertParse(codeBefore)
const codeOfInterest = `startSketchOn('XZ')` const codeOfInterest = `startSketchOn('XZ')`
const range: [number, number, boolean] = [ const range: [number, number, number] = [
codeBefore.indexOf(codeOfInterest), codeBefore.indexOf(codeOfInterest),
codeBefore.indexOf(codeOfInterest) + codeOfInterest.length, codeBefore.indexOf(codeOfInterest) + codeOfInterest.length,
true, 0,
] ]
const pathToPipe = getNodePathFromSourceRange(ast, range) const pathToPipe = getNodePathFromSourceRange(ast, range)
@ -977,10 +977,10 @@ extrude001 = extrude(5, part001)
const ast = assertParse(codeBefore) const ast = assertParse(codeBefore)
const codeOfInterest = `startProfileAt([1, 2], sketch001)` const codeOfInterest = `startProfileAt([1, 2], sketch001)`
const range: [number, number, boolean] = [ const range: [number, number, number] = [
codeBefore.indexOf(codeOfInterest), codeBefore.indexOf(codeOfInterest),
codeBefore.indexOf(codeOfInterest) + codeOfInterest.length, codeBefore.indexOf(codeOfInterest) + codeOfInterest.length,
true, 0,
] ]
const pathToPipe = getNodePathFromSourceRange(ast, range) const pathToPipe = getNodePathFromSourceRange(ast, range)

View File

@ -28,7 +28,9 @@ export function revolveSketch(
ast: Node<Program>, ast: Node<Program>,
pathToSketchNode: PathToNode, pathToSketchNode: PathToNode,
angle: Expr = createLiteral(4), angle: Expr = createLiteral(4),
axis: Selections, axisOrEdge: string,
axis: string,
edge: Selections,
artifact?: Artifact artifact?: Artifact
): ):
| { | {

View File

@ -21,6 +21,7 @@ import {
VariableDeclaration, VariableDeclaration,
VariableDeclarator, VariableDeclarator,
recast, recast,
ArtifactGraph,
} from './wasm' } from './wasm'
import { getNodePathFromSourceRange } from 'lang/queryAstNodePathUtils' import { getNodePathFromSourceRange } from 'lang/queryAstNodePathUtils'
import { createIdentifier, splitPathAtLastIndex } from './modifyAst' import { createIdentifier, splitPathAtLastIndex } from './modifyAst'
@ -33,7 +34,7 @@ import {
} from './std/sketchcombos' } from './std/sketchcombos'
import { err, Reason } from 'lib/trap' import { err, Reason } from 'lib/trap'
import { Node } from 'wasm-lib/kcl/bindings/Node' import { Node } from 'wasm-lib/kcl/bindings/Node'
import { ArtifactGraph, codeRefFromRange } from './std/artifactGraph' import { codeRefFromRange } from './std/artifactGraph'
import { FunctionExpression } from 'wasm-lib/kcl/bindings/FunctionExpression' import { FunctionExpression } from 'wasm-lib/kcl/bindings/FunctionExpression'
/** /**

View File

@ -240,6 +240,7 @@ export function expandSegment(
if (err(path)) return path if (err(path)) return path
if (err(surf)) return surf if (err(surf)) return surf
if (err(edgeCut)) return edgeCut if (err(edgeCut)) return edgeCut
if (!surf) return new Error('Segment does not have a surface')
return { return {
type: 'segment', type: 'segment',
@ -435,7 +436,7 @@ function getPlaneFromSegment(
return getPlaneFromPath(path, graph) return getPlaneFromPath(path, graph)
} }
function getPlaneFromSolid2D( function getPlaneFromSolid2D(
solid2D: Solid2DArtifact, solid2D: Solid2D,
graph: ArtifactGraph graph: ArtifactGraph
): PlaneArtifact | WallArtifact | CapArtifact | Error { ): PlaneArtifact | WallArtifact | CapArtifact | Error {
const path = getArtifactOfTypes( const path = getArtifactOfTypes(
@ -490,7 +491,7 @@ export function getPlaneFromArtifact(
if (artifact.type === 'plane') return artifact if (artifact.type === 'plane') return artifact
if (artifact.type === 'path') return getPlaneFromPath(artifact, graph) if (artifact.type === 'path') return getPlaneFromPath(artifact, graph)
if (artifact.type === 'segment') return getPlaneFromSegment(artifact, graph) if (artifact.type === 'segment') return getPlaneFromSegment(artifact, graph)
if (artifact.type === 'solid2D') return getPlaneFromSolid2D(artifact, graph) if (artifact.type === 'solid2d') return getPlaneFromSolid2D(artifact, graph)
if (artifact.type === 'cap') return getPlaneFromCap(artifact, graph) if (artifact.type === 'cap') return getPlaneFromCap(artifact, graph)
if (artifact.type === 'wall') return getPlaneFromWall(artifact, graph) if (artifact.type === 'wall') return getPlaneFromWall(artifact, graph)
if (artifact.type === 'sweepEdge') if (artifact.type === 'sweepEdge')

View File

@ -1304,7 +1304,7 @@ export const circleThreePoint: SketchLineHelper = {
sourceRange: [ sourceRange: [
p1Details.expr.elements[0].start, p1Details.expr.elements[0].start,
p1Details.expr.elements[0].end, p1Details.expr.elements[0].end,
true, 0,
], ],
pathToNode: pathToP1XArg, pathToNode: pathToP1XArg,
value: code.slice( value: code.slice(
@ -1325,7 +1325,7 @@ export const circleThreePoint: SketchLineHelper = {
sourceRange: [ sourceRange: [
p1Details.expr.elements[1].start, p1Details.expr.elements[1].start,
p1Details.expr.elements[1].end, p1Details.expr.elements[1].end,
true, 0,
], ],
pathToNode: pathToP1YArg, pathToNode: pathToP1YArg,
value: code.slice( value: code.slice(
@ -1346,7 +1346,7 @@ export const circleThreePoint: SketchLineHelper = {
sourceRange: [ sourceRange: [
p2Details.expr.elements[0].start, p2Details.expr.elements[0].start,
p2Details.expr.elements[0].end, p2Details.expr.elements[0].end,
true, 0,
], ],
pathToNode: pathToP2XArg, pathToNode: pathToP2XArg,
value: code.slice( value: code.slice(
@ -1367,7 +1367,7 @@ export const circleThreePoint: SketchLineHelper = {
sourceRange: [ sourceRange: [
p2Details.expr.elements[1].start, p2Details.expr.elements[1].start,
p2Details.expr.elements[1].end, p2Details.expr.elements[1].end,
true, 0,
], ],
pathToNode: pathToP2YArg, pathToNode: pathToP2YArg,
value: code.slice( value: code.slice(
@ -1388,7 +1388,7 @@ export const circleThreePoint: SketchLineHelper = {
sourceRange: [ sourceRange: [
p3Details.expr.elements[0].start, p3Details.expr.elements[0].start,
p3Details.expr.elements[0].end, p3Details.expr.elements[0].end,
true, 0,
], ],
pathToNode: pathToP3XArg, pathToNode: pathToP3XArg,
value: code.slice( value: code.slice(
@ -1409,7 +1409,7 @@ export const circleThreePoint: SketchLineHelper = {
sourceRange: [ sourceRange: [
p3Details.expr.elements[1].start, p3Details.expr.elements[1].start,
p3Details.expr.elements[1].end, p3Details.expr.elements[1].end,
true, 0,
], ],
pathToNode: pathToP3YArg, pathToNode: pathToP3YArg,
value: code.slice( value: code.slice(

View File

@ -56,7 +56,7 @@ export type ModelingCommandSchema = {
Revolve: { Revolve: {
selection: Selections selection: Selections
angle: KclCommandValue angle: KclCommandValue
axisOrEdge: string axisOrEdge: 'Axis' | 'Edge'
axis: string axis: string
edge: Selections edge: Selections
} }

View File

@ -287,7 +287,7 @@ export function getEventForSegmentSelection(
artifact, artifact,
codeRef: { codeRef: {
pathToNode: group?.userData?.pathToNode, pathToNode: group?.userData?.pathToNode,
range: [node.node.start, node.node.end, true], range: [node.node.start, node.node.end, 0],
}, },
}, },
}, },

View File

@ -700,7 +700,8 @@ export const modelingMachine = setup({
: angle.valueAst, : angle.valueAst,
axisOrEdge, axisOrEdge,
axis, axis,
edge edge,
selection.graphSelections[0]?.artifact
) )
if (trap(revolveSketchRes)) return if (trap(revolveSketchRes)) return
const { modifiedAst, pathToRevolveArg } = revolveSketchRes const { modifiedAst, pathToRevolveArg } = revolveSketchRes
@ -1604,7 +1605,6 @@ export const modelingMachine = setup({
if (!input) return Promise.reject('No input provided') if (!input) return Promise.reject('No input provided')
const { selection, distance } = input const { selection, distance } = input
let ast = structuredClone(kclManager.ast) let ast = structuredClone(kclManager.ast)
let extrudeName: string | undefined = undefined
const pathToNode = getNodePathFromSourceRange( const pathToNode = getNodePathFromSourceRange(
ast, ast,
@ -1614,7 +1614,7 @@ export const modelingMachine = setup({
const extrudeSketchRes = extrudeSketch( const extrudeSketchRes = extrudeSketch(
ast, ast,
pathToNode, pathToNode,
false, selection.graphSelections[0].artifact,
'variableName' in distance 'variableName' in distance
? distance.variableIdentifierAst ? distance.variableIdentifierAst
: distance.valueAst : distance.valueAst