don't query program memory for add sketch line (#895)
* don't query program memory for add sketch line * add issue TODO * fmt * fix test tsc
This commit is contained in:
@ -172,27 +172,38 @@ export const ModelingMachineProvider = ({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
'AST add line segment': (
|
'AST add line segment': async (
|
||||||
{ sketchPathToNode, sketchEnginePathId },
|
{ sketchPathToNode, sketchEnginePathId },
|
||||||
{ data: { coords, segmentId } }
|
{ data: { coords, segmentId } }
|
||||||
) => {
|
) => {
|
||||||
if (!sketchPathToNode) return
|
if (!sketchPathToNode) return
|
||||||
const lastCoord = coords[coords.length - 1]
|
const lastCoord = coords[coords.length - 1]
|
||||||
|
|
||||||
const { node: varDec } = getNodeFromPath<VariableDeclarator>(
|
const pathInfo = await engineCommandManager.sendSceneCommand({
|
||||||
kclManager.ast,
|
type: 'modeling_cmd_req',
|
||||||
sketchPathToNode,
|
cmd_id: uuidv4(),
|
||||||
'VariableDeclarator'
|
cmd: {
|
||||||
|
type: 'path_get_info',
|
||||||
|
path_id: sketchEnginePathId,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
const firstSegment = pathInfo?.data?.data?.segments.find(
|
||||||
|
(seg: any) => seg.command === 'line_to'
|
||||||
)
|
)
|
||||||
const variableName = varDec.id.name
|
const firstSegCoords = await engineCommandManager.sendSceneCommand({
|
||||||
const sketchGroup = kclManager.programMemory.root[variableName]
|
type: 'modeling_cmd_req',
|
||||||
if (!sketchGroup || sketchGroup.type !== 'SketchGroup') return
|
cmd_id: uuidv4(),
|
||||||
const initialCoords = sketchGroup.value[0].from
|
cmd: {
|
||||||
|
type: 'curve_get_control_points',
|
||||||
|
curve_id: firstSegment.command_id,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
const startPathCoord = firstSegCoords?.data?.data?.control_points[0]
|
||||||
|
|
||||||
const isClose = compareVec2Epsilon(initialCoords, [
|
const isClose = compareVec2Epsilon(
|
||||||
lastCoord.x,
|
[startPathCoord.x, startPathCoord.y],
|
||||||
lastCoord.y,
|
[lastCoord.x, lastCoord.y]
|
||||||
])
|
)
|
||||||
|
|
||||||
let _modifiedAst: Program
|
let _modifiedAst: Program
|
||||||
if (!isClose) {
|
if (!isClose) {
|
||||||
@ -200,6 +211,7 @@ export const ModelingMachineProvider = ({
|
|||||||
node: kclManager.ast,
|
node: kclManager.ast,
|
||||||
programMemory: kclManager.programMemory,
|
programMemory: kclManager.programMemory,
|
||||||
to: [lastCoord.x, lastCoord.y],
|
to: [lastCoord.x, lastCoord.y],
|
||||||
|
from: [coords[0].x, coords[0].y],
|
||||||
fnName: 'line',
|
fnName: 'line',
|
||||||
pathToNode: sketchPathToNode,
|
pathToNode: sketchPathToNode,
|
||||||
})
|
})
|
||||||
|
@ -138,6 +138,7 @@ show(mySketch001)`
|
|||||||
node: ast,
|
node: ast,
|
||||||
programMemory,
|
programMemory,
|
||||||
to: [2, 3],
|
to: [2, 3],
|
||||||
|
from: [0, 0],
|
||||||
fnName: 'lineTo',
|
fnName: 'lineTo',
|
||||||
pathToNode: [
|
pathToNode: [
|
||||||
['body', ''],
|
['body', ''],
|
||||||
|
@ -193,9 +193,6 @@ export const line: SketchLineHelper = {
|
|||||||
pathToNode,
|
pathToNode,
|
||||||
'VariableDeclarator'
|
'VariableDeclarator'
|
||||||
)
|
)
|
||||||
const variableName = varDec.id.name
|
|
||||||
const sketch = previousProgramMemory?.root?.[variableName]
|
|
||||||
if (sketch.type !== 'SketchGroup') throw new Error('not a SketchGroup')
|
|
||||||
|
|
||||||
const newXVal = createLiteral(roundOff(to[0] - from[0], 2))
|
const newXVal = createLiteral(roundOff(to[0] - from[0], 2))
|
||||||
const newYVal = createLiteral(roundOff(to[1] - from[1], 2))
|
const newYVal = createLiteral(roundOff(to[1] - from[1], 2))
|
||||||
@ -969,7 +966,8 @@ export function addNewSketchLn({
|
|||||||
to,
|
to,
|
||||||
fnName,
|
fnName,
|
||||||
pathToNode,
|
pathToNode,
|
||||||
}: Omit<CreateLineFnCallArgs, 'from'>): {
|
from,
|
||||||
|
}: CreateLineFnCallArgs): {
|
||||||
modifiedAst: Program
|
modifiedAst: Program
|
||||||
pathToNode: PathToNode
|
pathToNode: PathToNode
|
||||||
} {
|
} {
|
||||||
@ -984,12 +982,6 @@ export function addNewSketchLn({
|
|||||||
const { node: pipeExp, shallowPath: pipePath } = getNodeFromPath<
|
const { node: pipeExp, shallowPath: pipePath } = getNodeFromPath<
|
||||||
PipeExpression | CallExpression
|
PipeExpression | CallExpression
|
||||||
>(node, pathToNode, 'PipeExpression')
|
>(node, pathToNode, 'PipeExpression')
|
||||||
const variableName = varDec.id.name
|
|
||||||
const sketch = previousProgramMemory?.root?.[variableName]
|
|
||||||
if (sketch.type !== 'SketchGroup') throw new Error('not a SketchGroup')
|
|
||||||
|
|
||||||
const last = sketch.value[sketch.value.length - 1] || sketch.start
|
|
||||||
const from = last.to
|
|
||||||
return add({
|
return add({
|
||||||
node,
|
node,
|
||||||
previousProgramMemory,
|
previousProgramMemory,
|
||||||
|
@ -24,6 +24,7 @@ export interface PathReturn {
|
|||||||
|
|
||||||
export interface ModifyAstBase {
|
export interface ModifyAstBase {
|
||||||
node: Program
|
node: Program
|
||||||
|
// TODO #896: Remove ProgramMemory from this interface
|
||||||
previousProgramMemory: ProgramMemory
|
previousProgramMemory: ProgramMemory
|
||||||
pathToNode: PathToNode
|
pathToNode: PathToNode
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user