can use circle tool tip
This commit is contained in:
@ -947,7 +947,7 @@ export class SceneEntities {
|
|||||||
forward: [number, number, number],
|
forward: [number, number, number],
|
||||||
up: [number, number, number],
|
up: [number, number, number],
|
||||||
sketchOrigin: [number, number, number],
|
sketchOrigin: [number, number, number],
|
||||||
rectangleOrigin: [x: number, y: number]
|
circleCenter: [x: number, y: number]
|
||||||
) => {
|
) => {
|
||||||
let _ast = structuredClone(kclManager.ast)
|
let _ast = structuredClone(kclManager.ast)
|
||||||
|
|
||||||
@ -962,33 +962,36 @@ export class SceneEntities {
|
|||||||
const startSketchOn = _node1.node?.declarations
|
const startSketchOn = _node1.node?.declarations
|
||||||
const startSketchOnInit = startSketchOn?.[0]?.init
|
const startSketchOnInit = startSketchOn?.[0]?.init
|
||||||
|
|
||||||
const tags: [string, string, string] = [
|
|
||||||
findUniqueName(_ast, 'rectangleSegmentA'),
|
|
||||||
findUniqueName(_ast, 'rectangleSegmentB'),
|
|
||||||
findUniqueName(_ast, 'rectangleSegmentC'),
|
|
||||||
]
|
|
||||||
|
|
||||||
startSketchOn[0].init = createPipeExpression([
|
startSketchOn[0].init = createPipeExpression([
|
||||||
startSketchOnInit,
|
startSketchOnInit,
|
||||||
...getRectangleCallExpressions(rectangleOrigin, tags),
|
createCallExpressionStdLib('circle', [
|
||||||
|
createArrayExpression([
|
||||||
|
createLiteral(roundOff(circleCenter[0])),
|
||||||
|
createLiteral(roundOff(circleCenter[1])),
|
||||||
|
]),
|
||||||
|
createLiteral(1),
|
||||||
|
createPipeSubstitution(),
|
||||||
|
]),
|
||||||
])
|
])
|
||||||
|
|
||||||
let _recastAst = parse(recast(_ast))
|
let _recastAst = parse(recast(_ast))
|
||||||
if (trap(_recastAst)) return Promise.reject(_recastAst)
|
if (trap(_recastAst)) return Promise.reject(_recastAst)
|
||||||
_ast = _recastAst
|
_ast = _recastAst
|
||||||
|
|
||||||
|
// do a quick mock execution to get the program memory up-to-date
|
||||||
|
await kclManager.executeAstMock(_ast)
|
||||||
|
|
||||||
const { programMemoryOverride, truncatedAst } = await this.setupSketch({
|
const { programMemoryOverride, truncatedAst } = await this.setupSketch({
|
||||||
sketchPathToNode,
|
sketchPathToNode,
|
||||||
forward,
|
forward,
|
||||||
up,
|
up,
|
||||||
position: sketchOrigin,
|
position: sketchOrigin,
|
||||||
maybeModdedAst: _ast,
|
maybeModdedAst: _ast,
|
||||||
draftExpressionsIndices: { start: 0, end: 3 },
|
draftExpressionsIndices: { start: 0, end: 0 },
|
||||||
})
|
})
|
||||||
|
|
||||||
sceneInfra.setCallbacks({
|
sceneInfra.setCallbacks({
|
||||||
onMove: async (args) => {
|
onMove: async (args) => {
|
||||||
// Update the width and height of the draft rectangle
|
|
||||||
const pathToNodeTwo = structuredClone(sketchPathToNode)
|
const pathToNodeTwo = structuredClone(sketchPathToNode)
|
||||||
pathToNodeTwo[1][0] = 0
|
pathToNodeTwo[1][0] = 0
|
||||||
|
|
||||||
@ -997,18 +1000,27 @@ export class SceneEntities {
|
|||||||
pathToNodeTwo || [],
|
pathToNodeTwo || [],
|
||||||
'VariableDeclaration'
|
'VariableDeclaration'
|
||||||
)
|
)
|
||||||
|
let modded = structuredClone(truncatedAst)
|
||||||
if (trap(_node)) return Promise.reject(_node)
|
if (trap(_node)) return Promise.reject(_node)
|
||||||
const sketchInit = _node.node?.declarations?.[0]?.init
|
const sketchInit = _node.node?.declarations?.[0]?.init
|
||||||
|
|
||||||
const x = (args.intersectionPoint.twoD.x || 0) - rectangleOrigin[0]
|
const x = (args.intersectionPoint.twoD.x || 0) - circleCenter[0]
|
||||||
const y = (args.intersectionPoint.twoD.y || 0) - rectangleOrigin[1]
|
const y = (args.intersectionPoint.twoD.y || 0) - circleCenter[1]
|
||||||
|
|
||||||
if (sketchInit.type === 'PipeExpression') {
|
if (sketchInit.type === 'PipeExpression') {
|
||||||
updateRectangleSketch(sketchInit, x, y, tags[0])
|
const moddedResult = changeCircleArguments(
|
||||||
|
modded,
|
||||||
|
kclManager.programMemory,
|
||||||
|
[..._node.deepPath, ['body', 'PipeExpression'], [1, 'index']],
|
||||||
|
circleCenter,
|
||||||
|
Math.sqrt(x ** 2 + y ** 2)
|
||||||
|
)
|
||||||
|
if (err(moddedResult)) return Promise.reject(moddedResult)
|
||||||
|
modded = moddedResult.modifiedAst
|
||||||
}
|
}
|
||||||
|
|
||||||
const { programMemory } = await executeAst({
|
const { programMemory } = await executeAst({
|
||||||
ast: truncatedAst,
|
ast: modded,
|
||||||
useFakeExecutor: true,
|
useFakeExecutor: true,
|
||||||
engineCommandManager: this.engineCommandManager,
|
engineCommandManager: this.engineCommandManager,
|
||||||
programMemoryOverride,
|
programMemoryOverride,
|
||||||
@ -1039,8 +1051,8 @@ export class SceneEntities {
|
|||||||
const cornerPoint = args.intersectionPoint?.twoD
|
const cornerPoint = args.intersectionPoint?.twoD
|
||||||
if (!cornerPoint || args.mouseEvent.button !== 0) return
|
if (!cornerPoint || args.mouseEvent.button !== 0) return
|
||||||
|
|
||||||
const x = roundOff((cornerPoint.x || 0) - rectangleOrigin[0])
|
const x = roundOff((cornerPoint.x || 0) - circleCenter[0])
|
||||||
const y = roundOff((cornerPoint.y || 0) - rectangleOrigin[1])
|
const y = roundOff((cornerPoint.y || 0) - circleCenter[1])
|
||||||
|
|
||||||
const _node = getNodeFromPath<VariableDeclaration>(
|
const _node = getNodeFromPath<VariableDeclaration>(
|
||||||
_ast,
|
_ast,
|
||||||
@ -1050,16 +1062,25 @@ export class SceneEntities {
|
|||||||
if (trap(_node)) return Promise.reject(_node)
|
if (trap(_node)) return Promise.reject(_node)
|
||||||
const sketchInit = _node.node?.declarations?.[0]?.init
|
const sketchInit = _node.node?.declarations?.[0]?.init
|
||||||
|
|
||||||
|
let modded = structuredClone(_ast)
|
||||||
if (sketchInit.type === 'PipeExpression') {
|
if (sketchInit.type === 'PipeExpression') {
|
||||||
updateRectangleSketch(sketchInit, x, y, tags[0])
|
const moddedResult = changeCircleArguments(
|
||||||
|
modded,
|
||||||
|
kclManager.programMemory,
|
||||||
|
[..._node.deepPath, ['body', 'PipeExpression'], [1, 'index']],
|
||||||
|
circleCenter,
|
||||||
|
Math.sqrt(x ** 2 + y ** 2)
|
||||||
|
)
|
||||||
|
if (err(moddedResult)) return Promise.reject(moddedResult)
|
||||||
|
modded = moddedResult.modifiedAst
|
||||||
|
|
||||||
let _recastAst = parse(recast(_ast))
|
let _recastAst = parse(recast(modded))
|
||||||
if (trap(_recastAst)) return Promise.reject(_recastAst)
|
if (trap(_recastAst)) return Promise.reject(_recastAst)
|
||||||
_ast = _recastAst
|
_ast = _recastAst
|
||||||
|
|
||||||
// Update the primary AST and unequip the rectangle tool
|
// Update the primary AST and unequip the rectangle tool
|
||||||
await kclManager.executeAstMock(_ast)
|
await kclManager.executeAstMock(_ast)
|
||||||
sceneInfra.modelingSend({ type: 'Finish rectangle' })
|
sceneInfra.modelingSend({ type: 'Finish circle' })
|
||||||
|
|
||||||
const { programMemory } = await executeAst({
|
const { programMemory } = await executeAst({
|
||||||
ast: _ast,
|
ast: _ast,
|
||||||
@ -1315,7 +1336,7 @@ export class SceneEntities {
|
|||||||
modded = changeCircleArguments(
|
modded = changeCircleArguments(
|
||||||
modifiedAst,
|
modifiedAst,
|
||||||
kclManager.programMemory,
|
kclManager.programMemory,
|
||||||
[node.start, node.end],
|
getNodePathFromSourceRange(modifiedAst, [node.start, node.end]),
|
||||||
group.userData.center,
|
group.userData.center,
|
||||||
Math.sqrt(
|
Math.sqrt(
|
||||||
(group.userData.center[0] - dragTo[0]) ** 2 +
|
(group.userData.center[0] - dragTo[0]) ** 2 +
|
||||||
@ -1330,7 +1351,7 @@ export class SceneEntities {
|
|||||||
modded = changeCircleArguments(
|
modded = changeCircleArguments(
|
||||||
modifiedAst,
|
modifiedAst,
|
||||||
kclManager.programMemory,
|
kclManager.programMemory,
|
||||||
[node.start, node.end],
|
getNodePathFromSourceRange(modifiedAst, [node.start, node.end]),
|
||||||
dragTo,
|
dragTo,
|
||||||
group.userData.radius
|
group.userData.radius
|
||||||
)
|
)
|
||||||
|
|||||||
@ -1614,13 +1614,12 @@ export const sketchLineHelperMap: { [key: string]: SketchLineHelper } = {
|
|||||||
export function changeCircleArguments(
|
export function changeCircleArguments(
|
||||||
node: Program,
|
node: Program,
|
||||||
programMemory: ProgramMemory,
|
programMemory: ProgramMemory,
|
||||||
sourceRange: SourceRange,
|
pathToNode: PathToNode,
|
||||||
center: [number, number],
|
center: [number, number],
|
||||||
radius: number
|
radius: number
|
||||||
): { modifiedAst: Program; pathToNode: PathToNode } | Error {
|
): { modifiedAst: Program; pathToNode: PathToNode } | Error {
|
||||||
const _node = { ...node }
|
const _node = { ...node }
|
||||||
const thePath = getNodePathFromSourceRange(_node, sourceRange)
|
const nodeMeta = getNodeFromPath<CallExpression>(_node, pathToNode)
|
||||||
const nodeMeta = getNodeFromPath<CallExpression>(_node, thePath)
|
|
||||||
if (err(nodeMeta)) return nodeMeta
|
if (err(nodeMeta)) return nodeMeta
|
||||||
|
|
||||||
const { node: callExpression, shallowPath } = nodeMeta
|
const { node: callExpression, shallowPath } = nodeMeta
|
||||||
@ -1639,7 +1638,7 @@ export function changeCircleArguments(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Error(`not a sketch line helper: ${callExpression?.callee?.name}`)
|
return new Error(`There was a problem: ${callExpression?.callee?.name}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function changeSketchArguments(
|
export function changeSketchArguments(
|
||||||
|
|||||||
@ -359,7 +359,7 @@ export const toolbarConfig: Record<ToolbarModeName, ToolbarMode> = {
|
|||||||
modelingSend({
|
modelingSend({
|
||||||
type: 'change tool',
|
type: 'change tool',
|
||||||
data: {
|
data: {
|
||||||
tool: !modelingStateMatches('Sketch.Rectangle tool')
|
tool: !modelingStateMatches('Sketch.Circle tool')
|
||||||
? 'circle'
|
? 'circle'
|
||||||
: 'none',
|
: 'none',
|
||||||
},
|
},
|
||||||
@ -367,6 +367,10 @@ export const toolbarConfig: Record<ToolbarModeName, ToolbarMode> = {
|
|||||||
icon: 'circle',
|
icon: 'circle',
|
||||||
status: 'available',
|
status: 'available',
|
||||||
title: 'Center circle',
|
title: 'Center circle',
|
||||||
|
disabled: (state) =>
|
||||||
|
!canRectangleOrCircleTool(state.context) &&
|
||||||
|
!state.matches('Sketch.Circle tool'),
|
||||||
|
isActive: (state) => state.matches('Sketch.Circle tool'),
|
||||||
showTitle: false,
|
showTitle: false,
|
||||||
description: 'Start drawing a circle from its center',
|
description: 'Start drawing a circle from its center',
|
||||||
links: [
|
links: [
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user