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
}
export function sketchFromPathToNode({
function sketchFromPathToNode({
pathToNode,
ast,
variables,
@ -2603,23 +2603,13 @@ export function getSketchQuaternion(
return getQuaternionFromZAxis(massageFormats(zAxis))
}
export async function getSketchOrientationDetails(
sketchEntryNodePath: PathToNode
): Promise<{
export async function getSketchOrientationDetails(sketch: Sketch): Promise<{
quat: Quaternion
sketchDetails: Omit<
SketchDetails & { faceId?: string },
'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') {
const zAxis = sketch?.on.zAxis
return {
@ -2632,8 +2622,6 @@ export async function getSketchOrientationDetails(
},
}
}
if (sketch.on.type === 'face') {
const faceInfo = await getFaceDetails(sketch.on.id)
if (!faceInfo?.origin || !faceInfo?.z_axis || !faceInfo?.y_axis)
@ -2653,10 +2641,6 @@ export async function getSketchOrientationDetails(
},
}
}
return Promise.reject(
'sketch.on.type not recognized, has a new type been added?'
)
}
/**
* Retrieves orientation details for a given entity representing a face (brep face or default plane).

View File

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

View File

@ -13,12 +13,7 @@ import {
getOperationLabel,
stdLibMap,
} from 'lib/operations'
import {
codeManager,
editorManager,
engineCommandManager,
kclManager,
} from 'lib/singletons'
import { editorManager, engineCommandManager, kclManager } from 'lib/singletons'
import { ComponentProps, useEffect, useMemo, useRef, useState } from 'react'
import { Operation } from 'wasm-lib/kcl/bindings/Operation'
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 === 'segment') return getPlaneFromSegment(artifact, graph)
if (artifact.type === 'solid2d') return getPlaneFromSolid2D(artifact, graph)
if (artifact.type === 'cap') return getPlaneFromCap(artifact, graph)
if (artifact.type === 'wall') return getPlaneFromWall(artifact, graph)
if (artifact.type === 'wall' || artifact.type === 'cap') return artifact
if (artifact.type === 'sweepEdge')
return getPlaneFromSweepEdge(artifact, graph)
return new Error(`Artifact type ${artifact.type} does not have a plane`)

View File

@ -76,7 +76,12 @@ export function isCursorInSketchCommandRange(
artifactGraph
)
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
? parentId

View File

@ -671,6 +671,13 @@ export function codeToIdSelections(
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 (!entry.artifact.surfaceId) return
const wall = engineCommandManager.artifactGraph.get(