Update code mods for extrude so that new top-level constants are created (#2549)

* Make sketch and extrude produce separate top-level constants

* Fix most tests

* Add a breaking test for sketch on face AST mod

* Use `extrude` instead of `part`

* Implement @Irev-Dev's branch changes from https://github.com/KittyCAD/modeling-app/pull/2472

* Get extrude on face working

* Update incorrect sketch on face test

* Update unit tests

* Fix up E2E test changes

* fmt

* Fix a couple of goofed up test updates

* More specific names for paths to node sent to modelingMachine

* Bump down playwright workers for now

* Slightly more explicit type coercion

* Update snapshot tests

* Missed one other new flow test that wasn't updated to use "sketch001"

* Typo

* Damn missed one more sorry

* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu)

* Re-run CI

* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu)

* I think the multiple sketches test reverted from under me

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
This commit is contained in:
Frank Noirot
2024-06-04 13:57:01 -04:00
committed by GitHub
parent e46aca4992
commit c9800a58d0
17 changed files with 319 additions and 138 deletions

View File

@ -34,6 +34,7 @@ import {
} from './std/sketchcombos'
import { DefaultPlaneStr } from 'clientSideScene/sceneEntities'
import { isOverlap, roundOff } from 'lib/utils'
import { KCL_DEFAULT_CONSTANT_PREFIXES } from 'lib/constants'
import { ConstrainInfo } from './std/stdTypes'
export function startSketchOnDefault(
@ -42,7 +43,8 @@ export function startSketchOnDefault(
name = ''
): { modifiedAst: Program; id: string; pathToNode: PathToNode } {
const _node = { ...node }
const _name = name || findUniqueName(node, 'part')
const _name =
name || findUniqueName(node, KCL_DEFAULT_CONSTANT_PREFIXES.SKETCH)
const startSketchOn = createCallExpressionStdLib('startSketchOn', [
createLiteral(axis),
@ -109,7 +111,8 @@ export function addSketchTo(
name = ''
): { modifiedAst: Program; id: string; pathToNode: PathToNode } {
const _node = { ...node }
const _name = name || findUniqueName(node, 'part')
const _name =
name || findUniqueName(node, KCL_DEFAULT_CONSTANT_PREFIXES.SKETCH)
const startSketchOn = createCallExpressionStdLib('startSketchOn', [
createLiteral(axis.toUpperCase()),
@ -242,7 +245,7 @@ export function mutateObjExpProp(
export function extrudeSketch(
node: Program,
pathToNode: PathToNode,
shouldPipe = true,
shouldPipe = false,
distance = createLiteral(4) as Value
): {
modifiedAst: Program
@ -293,12 +296,22 @@ export function extrudeSketch(
pathToExtrudeArg,
}
}
const name = findUniqueName(node, 'part')
// We're not creating a pipe expression,
// but rather a separate constant for the extrusion
const name = findUniqueName(node, KCL_DEFAULT_CONSTANT_PREFIXES.EXTRUDE)
const VariableDeclaration = createVariableDeclaration(name, extrudeCall)
_node.body.splice(_node.body.length, 0, VariableDeclaration)
const sketchIndexInPathToNode =
pathToDecleration.findIndex((a) => a[0] === 'body') + 1
const sketchIndexInBody = pathToDecleration[
sketchIndexInPathToNode
][0] as number
_node.body.splice(sketchIndexInBody + 1, 0, VariableDeclaration)
const pathToExtrudeArg: PathToNode = [
['body', ''],
[_node.body.length, 'index'],
[sketchIndexInBody + 1, 'index'],
['declarations', 'VariableDeclaration'],
[0, 'index'],
['init', 'VariableDeclarator'],
@ -306,7 +319,7 @@ export function extrudeSketch(
[0, 'index'],
]
return {
modifiedAst: node,
modifiedAst: _node,
pathToNode: [...pathToNode.slice(0, -1), [-1, 'index']],
pathToExtrudeArg,
}
@ -314,31 +327,41 @@ export function extrudeSketch(
export function sketchOnExtrudedFace(
node: Program,
pathToNode: PathToNode,
sketchPathToNode: PathToNode,
extrudePathToNode: PathToNode,
programMemory: ProgramMemory,
cap: 'none' | 'start' | 'end' = 'none'
): { modifiedAst: Program; pathToNode: PathToNode } {
let _node = { ...node }
const newSketchName = findUniqueName(node, 'part')
const newSketchName = findUniqueName(
node,
KCL_DEFAULT_CONSTANT_PREFIXES.SKETCH
)
const { node: oldSketchNode } = getNodeFromPath<VariableDeclarator>(
_node,
pathToNode,
sketchPathToNode,
'VariableDeclarator',
true
)
const oldSketchName = oldSketchNode.id.name
const { node: expression } = getNodeFromPath<CallExpression>(
_node,
pathToNode,
sketchPathToNode,
'CallExpression'
)
const { node: extrudeVarDec } = getNodeFromPath<VariableDeclarator>(
_node,
extrudePathToNode,
'VariableDeclarator'
)
const extrudeName = extrudeVarDec.id?.name
let _tag = ''
if (cap === 'none') {
const { modifiedAst, tag } = addTagForSketchOnFace(
{
previousProgramMemory: programMemory,
pathToNode,
pathToNode: sketchPathToNode,
node: _node,
},
expression.callee.name
@ -352,13 +375,16 @@ export function sketchOnExtrudedFace(
const newSketch = createVariableDeclaration(
newSketchName,
createCallExpressionStdLib('startSketchOn', [
createIdentifier(oldSketchName),
createIdentifier(extrudeName ? extrudeName : oldSketchName),
createLiteral(_tag),
]),
'const'
)
const expressionIndex = pathToNode[1][0] as number
const expressionIndex = Math.max(
sketchPathToNode[1][0] as number,
extrudePathToNode[1][0] as number
)
_node.body.splice(expressionIndex + 1, 0, newSketch)
const newpathToNode: PathToNode = [
['body', ''],