fix no profile errors (#5877)

* fix no profile errors

* add test and tweak a couple things

* quick fix

* fix animation

* add another test

* Use actor.getSnapshot in the debug function

So we don't have to rebuild that listener every time that the state
changes.

* try fix tests

---------

Co-authored-by: Frank Noirot <frankjohnson1993@gmail.com>
This commit is contained in:
Kurt Hutten
2025-03-20 08:30:11 +11:00
committed by GitHub
parent e7d00f148b
commit 4b6166dc4f
9 changed files with 195 additions and 31 deletions

View File

@ -580,8 +580,7 @@ export class SceneEntities {
if (interaction !== 'none') return
if (args.mouseEvent.which !== 1) return
const { intersectionPoint } = args
if (!intersectionPoint?.twoD || !sketchDetails?.sketchEntryNodePath)
return
if (!intersectionPoint?.twoD) return
const parent = getParentGroup(
args?.intersects?.[0]?.object,
@ -616,7 +615,7 @@ export class SceneEntities {
const inserted = insertNewStartProfileAt(
kclManager.ast,
sketchDetails.sketchEntryNodePath,
sketchDetails.sketchEntryNodePath || [],
sketchDetails.sketchNodePaths,
sketchDetails.planeNodePath,
[snappedClickPoint.x, snappedClickPoint.y],

View File

@ -114,10 +114,11 @@ import { useToken } from 'machines/appMachine'
import { getNodePathFromSourceRange } from 'lang/queryAstNodePathUtils'
import { useSettings } from 'machines/appMachine'
import { IndexLoaderData } from 'lib/types'
import { OutputFormat3d } from '@rust/kcl-lib/bindings/ModelingCmd'
import { OutputFormat3d, Point3d } from '@rust/kcl-lib/bindings/ModelingCmd'
import { EXPORT_TOAST_MESSAGES, MAKE_TOAST_MESSAGES } from 'lib/constants'
import { exportMake } from 'lib/exportMake'
import { exportSave } from 'lib/exportSave'
import { Plane } from '@rust/kcl-lib/bindings/Plane'
export const ModelingMachineContext = createContext(
{} as {
@ -573,8 +574,9 @@ export const ModelingMachineProvider = ({
kclManager.ast,
selectionRanges.graphSelections[0]
)
)
) {
return false
}
return !!isCursorInSketchCommandRange(
engineCommandManager.artifactGraph,
selectionRanges
@ -602,7 +604,6 @@ export const ModelingMachineProvider = ({
}
let fileName = file?.name?.replace('.kcl', `.${input.type}`) || ''
console.log('fileName', fileName)
// Ensure the file has an extension.
if (!fileName.includes('.')) {
fileName += `.${input.type}`
@ -852,6 +853,7 @@ export const ModelingMachineProvider = ({
? artifact?.pathId
: plane?.pathIds[0]
let sketch: KclValue | null = null
let planeVar: Plane | null = null
for (const variable of Object.values(
kclManager.execState.variables
)) {
@ -875,13 +877,43 @@ export const ModelingMachineProvider = ({
}
break
}
if (
variable?.type === 'Plane' &&
plane.id === variable.value.id
) {
planeVar = variable.value
}
}
if (!sketch || sketch.type !== 'Sketch')
return Promise.reject(new Error('No sketch'))
if (!sketch || sketch.type !== 'Sketch')
if (!sketch || sketch.type !== 'Sketch') {
if (artifact?.type !== 'plane')
return Promise.reject(new Error('No sketch'))
const planeCodeRef = getFaceCodeRef(artifact)
if (planeVar && planeCodeRef) {
const toTuple = (point: Point3d): [number, number, number] => [
point.x,
point.y,
point.z,
]
const planPath = getNodePathFromSourceRange(
kclManager.ast,
planeCodeRef.range
)
await letEngineAnimateAndSyncCamAfter(
engineCommandManager,
artifact.id
)
return {
sketchEntryNodePath: [],
planeNodePath: planPath,
sketchNodePaths: [],
zAxis: toTuple(planeVar.zAxis),
yAxis: toTuple(planeVar.yAxis),
origin: toTuple(planeVar.origin),
}
}
return Promise.reject(new Error('No sketch'))
}
const info = await getSketchOrientationDetails(sketch.value)
await letEngineAnimateAndSyncCamAfter(
engineCommandManager,
info?.sketchDetails?.faceId || ''
@ -1576,7 +1608,7 @@ export const ModelingMachineProvider = ({
'setup-client-side-sketch-segments': fromPromise(
async ({ input: { sketchDetails, selectionRanges } }) => {
if (!sketchDetails) return
if (!sketchDetails.sketchEntryNodePath.length) return
if (!sketchDetails.sketchEntryNodePath?.length) return
if (Object.keys(sceneEntitiesManager.activeSegments).length > 0) {
sceneEntitiesManager.tearDownSketch({ removeAxis: false })
}
@ -1617,6 +1649,9 @@ export const ModelingMachineProvider = ({
updatedPlaneNodePath: sketchDetails.planeNodePath,
expressionIndexToDelete: -1,
} as const
if (!sketchDetails?.sketchEntryNodePath?.length) {
return existingSketchInfoNoOp
}
if (
!sketchDetails.sketchNodePaths.length &&
sketchDetails.planeNodePath.length
@ -1727,6 +1762,18 @@ export const ModelingMachineProvider = ({
}
)
// Add debug function to window object
useEffect(() => {
// @ts-ignore - we're intentionally adding this to window
window.getModelingState = () => {
const modelingState = modelingActor.getSnapshot()
return {
modelingState,
id: modelingState._nodes[modelingState._nodes.length - 1].id,
}
}
}, [modelingActor])
useSetupEngineManager(
streamRef,
modelingSend,

View File

@ -61,6 +61,7 @@ export function getNodeFromPath<T>(
path: PathToNode,
stopAt?: SyntaxType | SyntaxType[],
returnEarly = false,
suppressNoise = false,
replacement?: any
):
| {
@ -105,9 +106,11 @@ export function getNodeFromPath<T>(
.filter((a) => a)
.join(' > ')}`
)
console.error(tree)
console.error(sourceCode)
console.error(error.stack)
if (!suppressNoise) {
console.error(tree)
console.error(sourceCode)
console.error(error.stack)
}
return error
}
parent = currentNode
@ -967,3 +970,11 @@ export function getSettingsAnnotation(
return settings
}
function pathToNodeKeys(pathToNode: PathToNode): (string | number)[] {
return pathToNode.map(([key]) => key)
}
export function stringifyPathToNode(pathToNode: PathToNode): string {
return JSON.stringify(pathToNodeKeys(pathToNode))
}

View File

@ -748,6 +748,9 @@ export function getPathsFromPlaneArtifact(
)
}
}
if (nodePaths.length === 0) {
return []
}
return onlyConsecutivePaths(nodePaths, nodePaths[0], ast)
}

View File

@ -3541,7 +3541,7 @@ function addTagKw(): addTagFn {
// If we changed the node, we must replace the old node with the new node in the AST.
const mustReplaceNode = primaryCallExp.type !== callExpr.node.type
if (mustReplaceNode) {
getNodeFromPath(_node, pathToNode, ['CallExpression'], false, {
getNodeFromPath(_node, pathToNode, ['CallExpression'], false, false, {
...primaryCallExp,
start: callExpr.node.start,
end: callExpr.node.end,

File diff suppressed because one or more lines are too long