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

View File

@ -194,9 +194,7 @@ export const ModelingMachineProvider = ({
store.videoElement?.pause()
return kclManager
.executeCode({ isPartialExecution: true })
.then(() => {
return kclManager.executeCode().then(() => {
if (engineCommandManager.engineConnection?.idleMode) return
store.videoElement?.play().catch((e) => {
@ -224,7 +222,6 @@ export const ModelingMachineProvider = ({
})
})
.catch(reportRejection)
})().catch(reportRejection)
},
'Set mouse state': assign(({ context, event }) => {
if (event.type !== 'Set mouse state') return {}

View File

@ -381,7 +381,7 @@ export class KclManager {
this.ast,
execState.artifactCommands,
execState.artifacts,
args.isPartialExecution,
args.isPartialExecution
)
this._executeCallback()
if (!isInterrupted)
@ -485,7 +485,10 @@ export class KclManager {
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)
if (!ast) {

View File

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

View File

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

View File

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

View File

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