This commit is contained in:
49lf
2025-01-17 15:37:28 -05:00
parent 648616c667
commit 32e8975799
7 changed files with 53 additions and 42 deletions

View File

@ -1431,7 +1431,8 @@ export class SceneEntities {
let target: Object3D | undefined = undefined let target: Object3D | undefined = undefined
// The KCL this will generate. // The KCL this will generate.
const kclCircle3Point = parse(`circleThreePoint( const kclCircle3Point = parse(`profileVarNameToBeReplaced = circleThreePoint(
sketchVarNameToBeReplaced,
p1 = [0.0, 0.0], p1 = [0.0, 0.0],
p2 = [0.0, 0.0], p2 = [0.0, 0.0],
p3 = [0.0, 0.0], p3 = [0.0, 0.0],
@ -1519,17 +1520,19 @@ export class SceneEntities {
} }
const insertCircle3PointKclIntoAstSnapshot = ( const insertCircle3PointKclIntoAstSnapshot = (
points: Vector2[] points: Vector2[],
sketchVarName: string
): Program => { ): Program => {
if (err(kclCircle3Point) || kclCircle3Point.program === null) if (err(kclCircle3Point) || kclCircle3Point.program === null)
return kclManager.ast return kclManager.ast
if (kclCircle3Point.program.body[0].type !== 'ExpressionStatement') if (kclCircle3Point.program.body[0].type !== 'VariableDeclaration')
return kclManager.ast return kclManager.ast
if ( if (
kclCircle3Point.program.body[0].expression.type !== 'CallExpressionKw' kclCircle3Point.program.body[0].declaration.init.type !== 'CallExpressionKw'
) )
return kclManager.ast return kclManager.ast
// Make accessing the labeled arguments easier / less verbose
const arg = (x: LabeledArg): Literal[] | undefined => { const arg = (x: LabeledArg): Literal[] | undefined => {
if ( if (
'arg' in x && 'arg' in x &&
@ -1543,8 +1546,18 @@ export class SceneEntities {
return undefined return undefined
} }
// Set the `profileXXX =` variable name if not set
if (kclCircle3Point.program.body[0].declaration.id.name === 'profileVarNameToBeReplaced') {
const profileVarName = findUniqueName(_ast, 'profile')
kclCircle3Point.program.body[0].declaration.id.name = profileVarName
}
// Set the sketch variable name
kclCircle3Point.program.body[0].declaration.init.unlabeled.name = sketchVarName
// Set the points 1-3
const kclCircle3PointArgs = const kclCircle3PointArgs =
kclCircle3Point.program.body[0].expression.arguments kclCircle3Point.program.body[0].declaration.init.arguments
const arg0 = arg(kclCircle3PointArgs[0]) const arg0 = arg(kclCircle3PointArgs[0])
if (!arg0) return kclManager.ast if (!arg0) return kclManager.ast
@ -1575,8 +1588,8 @@ export class SceneEntities {
) )
if (err(startSketchOnASTNode)) return astSnapshot if (err(startSketchOnASTNode)) return astSnapshot
// It's possible we're already dealing with a PipeExpression. // It's possible we're not the first profile on this sketch!
// Modify the current one. // It's also possible we've already added this profile, so modify it.
if ( if (
startSketchOnASTNode.node.declaration.init.type === 'PipeExpression' && startSketchOnASTNode.node.declaration.init.type === 'PipeExpression' &&
startSketchOnASTNode.node.declaration.init.body[1].type === startSketchOnASTNode.node.declaration.init.body[1].type ===
@ -1641,7 +1654,7 @@ export class SceneEntities {
const maybeCallExpressionKw = maybeVariableDeclaration.node.declaration.init const maybeCallExpressionKw = maybeVariableDeclaration.node.declaration.init
if ( if (
maybeCallExpressionKw.type === 'PipeExpression' && maybeCallExpressionKw.type === 'VariableDeclaration' &&
maybeCallExpressionKw.body[1].type === 'CallExpressionKw' && maybeCallExpressionKw.body[1].type === 'CallExpressionKw' &&
maybeCallExpressionKw.body[1]?.callee.name === 'circleThreePoint' maybeCallExpressionKw.body[1]?.callee.name === 'circleThreePoint'
) { ) {

View File

@ -194,8 +194,26 @@ export const ModelingMachineProvider = ({
store.videoElement?.pause() store.videoElement?.pause()
return kclManager.executeCode().then(() => {
if (engineCommandManager.engineConnection?.idleMode) return
store.videoElement?.play().catch((e) => {
console.warn('Video playing was prevented', e)
})
})
sceneInfra.camControls.syncDirection = 'clientToEngine'
if (cameraProjection.current === 'perspective') {
await sceneInfra.camControls.snapToPerspectiveBeforeHandingBackControlToEngine()
}
sceneInfra.camControls.syncDirection = 'engineToClient'
store.videoElement?.pause()
return kclManager return kclManager
.executeCode({ isPartialExecution: true }) .executeCode()
.then(() => { .then(() => {
if (engineCommandManager.engineConnection?.idleMode) return if (engineCommandManager.engineConnection?.idleMode) return
@ -203,28 +221,7 @@ export const ModelingMachineProvider = ({
console.warn('Video playing was prevented', e) console.warn('Video playing was prevented', e)
}) })
}) })
.catch(reportRejection)
sceneInfra.camControls.syncDirection = 'clientToEngine'
if (cameraProjection.current === 'perspective') {
await sceneInfra.camControls.snapToPerspectiveBeforeHandingBackControlToEngine()
}
sceneInfra.camControls.syncDirection = 'engineToClient'
store.videoElement?.pause()
return kclManager
.executeCode()
.then(() => {
if (engineCommandManager.engineConnection?.idleMode) return
store.videoElement?.play().catch((e) => {
console.warn('Video playing was prevented', e)
})
})
.catch(reportRejection)
})().catch(reportRejection)
}, },
'Set mouse state': assign(({ context, event }) => { 'Set mouse state': assign(({ context, event }) => {
if (event.type !== 'Set mouse state') return {} if (event.type !== 'Set mouse state') return {}

View File

@ -381,7 +381,7 @@ export class KclManager {
this.ast, this.ast,
execState.artifactCommands, execState.artifactCommands,
execState.artifacts, execState.artifacts,
args.isPartialExecution, args.isPartialExecution
) )
this._executeCallback() this._executeCallback()
if (!isInterrupted) if (!isInterrupted)
@ -485,7 +485,10 @@ export class KclManager {
this._cancelTokens.set(key, true) this._cancelTokens.set(key, true)
}) })
} }
async executeCode(opts?: { zoomToFit?: true, isPartialExecution?: true }): Promise<void> { async executeCode(opts?: {
zoomToFit?: true
isPartialExecution?: true
}): Promise<void> {
const ast = await this.safeParse(codeManager.code) const ast = await this.safeParse(codeManager.code)
if (!ast) { if (!ast) {

View File

@ -507,7 +507,6 @@ export function getArtifactsToUpdate({
returnArr.push({ returnArr.push({
id: face_id, id: face_id,
artifact: wallArtifact, artifact: wallArtifact,
}) })
returnArr.push({ returnArr.push({
id: curve_id, id: curve_id,

View File

@ -2091,7 +2091,7 @@ export class EngineCommandManager extends EventTarget {
ast: Node<Program>, ast: Node<Program>,
artifactCommands: ArtifactCommand[], artifactCommands: ArtifactCommand[],
execStateArtifacts: ExecState['artifacts'], execStateArtifacts: ExecState['artifacts'],
isPartialExecution?: true, isPartialExecution?: true
) { ) {
const newGraphArtifacts = createArtifactGraph({ const newGraphArtifacts = createArtifactGraph({
artifactCommands, artifactCommands,

View File

@ -447,10 +447,7 @@ export const toolbarConfig: Record<ToolbarModeName, ToolbarMode> = {
status: 'available', status: 'available',
title: 'Center circle', title: 'Center circle',
disabled: (state) => disabled: (state) =>
state.matches('Sketch no face') || state.matches('Sketch no face'),
(!canRectangleOrCircleTool(state.context) &&
!state.matches({ Sketch: 'Circle tool' }) &&
!state.matches({ Sketch: 'circle3PointToolSelect' })),
isActive: (state) => isActive: (state) =>
state.matches({ Sketch: 'Circle tool' }) || state.matches({ Sketch: 'Circle tool' }) ||
state.matches({ Sketch: 'circle3PointToolSelect' }), state.matches({ Sketch: 'circle3PointToolSelect' }),

View File

@ -1826,6 +1826,8 @@ export const modelingMachine = setup({
'split-sketch-pipe-if-needed': fromPromise( 'split-sketch-pipe-if-needed': fromPromise(
async (_: { input: Pick<ModelingMachineContext, 'sketchDetails'> }) => { async (_: { input: Pick<ModelingMachineContext, 'sketchDetails'> }) => {
return {} as SketchDetailsUpdate return {} as SketchDetailsUpdate
}
),
chamferAstMod: fromPromise( chamferAstMod: fromPromise(
async ({ async ({
input, input,
@ -1874,7 +1876,7 @@ export const modelingMachine = setup({
const cleanupFn = sceneEntitiesManager.entryDraftCircle3Point( const cleanupFn = sceneEntitiesManager.entryDraftCircle3Point(
// I make it clear that the stop is coming from an internal call // I make it clear that the stop is coming from an internal call
() => sendBack({ type: 'stop-internal' }), () => sendBack({ type: 'stop-internal' }),
sketchDetails.sketchPathToNode, sketchDetails.planeNodePath,
new Vector3(...sketchDetails.zAxis), new Vector3(...sketchDetails.zAxis),
new Vector3(...sketchDetails.yAxis), new Vector3(...sketchDetails.yAxis),
new Vector3(...sketchDetails.origin) new Vector3(...sketchDetails.origin)
@ -3031,10 +3033,10 @@ export function isEditing3PointCircle({
}: { }: {
sketchDetails: SketchDetails | null sketchDetails: SketchDetails | null
}): boolean { }): boolean {
if (!sketchDetails?.sketchPathToNode) return false if (!sketchDetails?.sketchEntryNodePath) return false
const variableDeclaration = getNodeFromPath<VariableDeclarator>( const variableDeclaration = getNodeFromPath<VariableDeclarator>(
kclManager.ast, kclManager.ast,
sketchDetails.sketchPathToNode, sketchDetails.sketchEntryNodePath,
'VariableDeclarator' 'VariableDeclarator'
) )
if (err(variableDeclaration)) return false if (err(variableDeclaration)) return false