fix going into edit sketch

This commit is contained in:
Kurt Hutten Irev-Dev
2025-02-12 17:28:06 +11:00
parent 1854064274
commit 4a8e582865
6 changed files with 57 additions and 51 deletions

View File

@ -2540,7 +2540,7 @@ export function getParentGroup(
return null return null
} }
export function sketchFromPathToNode({ function sketchFromPathToNode({
pathToNode, pathToNode,
ast, ast,
variables, variables,
@ -2603,23 +2603,13 @@ export function getSketchQuaternion(
return getQuaternionFromZAxis(massageFormats(zAxis)) return getQuaternionFromZAxis(massageFormats(zAxis))
} }
export async function getSketchOrientationDetails( export async function getSketchOrientationDetails(sketch: Sketch): Promise<{
sketchEntryNodePath: PathToNode
): Promise<{
quat: Quaternion quat: Quaternion
sketchDetails: Omit< sketchDetails: Omit<
SketchDetails & { faceId?: string }, SketchDetails & { faceId?: string },
'sketchNodePaths' | 'sketchEntryNodePath' | 'planeNodePath' 'sketchNodePaths' | 'sketchEntryNodePath' | 'planeNodePath'
> >
}> { }> {
const sketch = sketchFromPathToNode({
pathToNode: sketchEntryNodePath,
ast: kclManager.ast,
variables: kclManager.variables,
})
if (err(sketch)) return Promise.reject(sketch)
if (!sketch) return Promise.reject('sketch not found')
if (sketch.on.type === 'plane') { if (sketch.on.type === 'plane') {
const zAxis = sketch?.on.zAxis const zAxis = sketch?.on.zAxis
return { return {
@ -2632,30 +2622,24 @@ export async function getSketchOrientationDetails(
}, },
} }
} }
const faceInfo = await getFaceDetails(sketch.on.id)
if (sketch.on.type === 'face') { if (!faceInfo?.origin || !faceInfo?.z_axis || !faceInfo?.y_axis)
const faceInfo = await getFaceDetails(sketch.on.id) return Promise.reject('face info')
const { z_axis, y_axis, origin } = faceInfo
if (!faceInfo?.origin || !faceInfo?.z_axis || !faceInfo?.y_axis) const quaternion = quaternionFromUpNForward(
return Promise.reject('face info') new Vector3(y_axis.x, y_axis.y, y_axis.z),
const { z_axis, y_axis, origin } = faceInfo new Vector3(z_axis.x, z_axis.y, z_axis.z)
const quaternion = quaternionFromUpNForward(
new Vector3(y_axis.x, y_axis.y, y_axis.z),
new Vector3(z_axis.x, z_axis.y, z_axis.z)
)
return {
quat: quaternion,
sketchDetails: {
zAxis: [z_axis.x, z_axis.y, z_axis.z],
yAxis: [y_axis.x, y_axis.y, y_axis.z],
origin: [origin.x, origin.y, origin.z],
faceId: sketch.on.id,
},
}
}
return Promise.reject(
'sketch.on.type not recognized, has a new type been added?'
) )
return {
quat: quaternion,
sketchDetails: {
zAxis: [z_axis.x, z_axis.y, z_axis.z],
yAxis: [y_axis.x, y_axis.y, y_axis.z],
origin: [origin.x, origin.y, origin.z],
faceId: sketch.on.id,
},
}
} }
/** /**

View File

@ -107,6 +107,7 @@ import { promptToEditFlow } from 'lib/promptToEdit'
import { kclEditorActor } from 'machines/kclEditorMachine' import { kclEditorActor } from 'machines/kclEditorMachine'
import { commandBarActor } from 'machines/commandBarMachine' import { commandBarActor } from 'machines/commandBarMachine'
import { useToken } from 'machines/appMachine' import { useToken } from 'machines/appMachine'
import { getNodePathFromSourceRange } from 'lang/queryAstNodePathUtils'
type MachineContext<T extends AnyStateMachine> = { type MachineContext<T extends AnyStateMachine> = {
state: StateFrom<T> state: StateFrom<T>
@ -799,24 +800,34 @@ export const ModelingMachineProvider = ({
}), }),
'animate-to-sketch': fromPromise( 'animate-to-sketch': fromPromise(
async ({ input: { selectionRanges } }) => { async ({ input: { selectionRanges } }) => {
const sketchPathToNode =
selectionRanges.graphSelections[0]?.codeRef?.pathToNode
const plane = getPlaneFromArtifact( const plane = getPlaneFromArtifact(
selectionRanges.graphSelections[0].artifact, selectionRanges.graphSelections[0].artifact,
engineCommandManager.artifactGraph engineCommandManager.artifactGraph
) )
if (err(plane)) return Promise.reject(plane) if (err(plane)) return Promise.reject(plane)
const info = await getSketchOrientationDetails( const sketch = Object.values(kclManager.execState.variables).find(
sketchPathToNode || [] (variable) =>
variable?.type === 'Sketch' &&
variable.value.artifactId === plane.pathIds[0]
) )
if (!sketch || sketch.type !== 'Sketch')
return Promise.reject(new Error('No sketch'))
const info = await getSketchOrientationDetails(sketch.value)
await letEngineAnimateAndSyncCamAfter( await letEngineAnimateAndSyncCamAfter(
engineCommandManager, engineCommandManager,
info?.sketchDetails?.faceId || '' info?.sketchDetails?.faceId || ''
) )
const sketchArtifact = engineCommandManager.artifactGraph.get(
plane.pathIds[0]
)
if (sketchArtifact?.type !== 'path')
return Promise.reject(new Error('No sketch artifact'))
const sketchPaths = getPathsFromArtifact({ const sketchPaths = getPathsFromArtifact({
artifact: selectionRanges.graphSelections[0].artifact, artifact: engineCommandManager.artifactGraph.get(plane.id),
sketchPathToNode: sketchPathToNode || [], sketchPathToNode: sketchArtifact?.codeRef?.pathToNode,
artifactGraph: engineCommandManager.artifactGraph, artifactGraph: engineCommandManager.artifactGraph,
ast: kclManager.ast, ast: kclManager.ast,
}) })
@ -828,10 +839,15 @@ export const ModelingMachineProvider = ({
? plane.codeRef ? plane.codeRef
: null : null
if (!codeRef) return Promise.reject(new Error('No plane codeRef')) if (!codeRef) return Promise.reject(new Error('No plane codeRef'))
// codeRef.pathToNode is not always populated correctly
const planeNodePath = getNodePathFromSourceRange(
kclManager.ast,
codeRef.range
)
return { return {
sketchEntryNodePath: sketchPathToNode || [], sketchEntryNodePath: sketchArtifact.codeRef.pathToNode || [],
sketchNodePaths: sketchPaths, sketchNodePaths: sketchPaths,
planeNodePath: codeRef.pathToNode, planeNodePath,
zAxis: info.sketchDetails.zAxis || null, zAxis: info.sketchDetails.zAxis || null,
yAxis: info.sketchDetails.yAxis || null, yAxis: info.sketchDetails.yAxis || null,
origin: info.sketchDetails.origin.map( origin: info.sketchDetails.origin.map(

View File

@ -13,12 +13,7 @@ import {
getOperationLabel, getOperationLabel,
stdLibMap, stdLibMap,
} from 'lib/operations' } from 'lib/operations'
import { import { editorManager, engineCommandManager, kclManager } from 'lib/singletons'
codeManager,
editorManager,
engineCommandManager,
kclManager,
} from 'lib/singletons'
import { ComponentProps, useEffect, useMemo, useRef, useState } from 'react' import { ComponentProps, useEffect, useMemo, useRef, useState } from 'react'
import { Operation } from 'wasm-lib/kcl/bindings/Operation' import { Operation } from 'wasm-lib/kcl/bindings/Operation'
import { Actor, Prop } from 'xstate' import { Actor, Prop } from 'xstate'

View File

@ -491,8 +491,7 @@ export function getPlaneFromArtifact(
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 === 'wall' || artifact.type === 'cap') return artifact
if (artifact.type === 'wall') return getPlaneFromWall(artifact, graph)
if (artifact.type === 'sweepEdge') if (artifact.type === 'sweepEdge')
return getPlaneFromSweepEdge(artifact, graph) return getPlaneFromSweepEdge(artifact, graph)
return new Error(`Artifact type ${artifact.type} does not have a plane`) return new Error(`Artifact type ${artifact.type} does not have a plane`)

View File

@ -76,7 +76,12 @@ export function isCursorInSketchCommandRange(
artifactGraph artifactGraph
) )
const firstEntry = [...overlappingEntries.values()]?.[0] const firstEntry = [...overlappingEntries.values()]?.[0]
const parentId = firstEntry?.type === 'segment' ? firstEntry.pathId : false const parentId =
firstEntry?.type === 'segment'
? firstEntry.pathId
: firstEntry?.type === 'plane' && firstEntry.pathIds.length
? firstEntry.pathIds[0]
: false
return parentId return parentId
? parentId ? parentId

View File

@ -671,6 +671,13 @@ export function codeToIdSelections(
id: entry.artifact.solid2dId, id: entry.artifact.solid2dId,
} }
} }
if (entry.artifact.type === 'plane') {
bestCandidate = {
artifact: entry.artifact,
selection,
id: entry.id,
}
}
if (type === 'extrude-wall' && entry.artifact.type === 'segment') { if (type === 'extrude-wall' && entry.artifact.type === 'segment') {
if (!entry.artifact.surfaceId) return if (!entry.artifact.surfaceId) return
const wall = engineCommandManager.artifactGraph.get( const wall = engineCommandManager.artifactGraph.get(