Compare commits

...

7 Commits

Author SHA1 Message Date
0e02e95c55 Merge branch 'main' into wip-multi-profile 2024-06-22 09:26:06 -07:00
a94f0191b5 fix tests
Signed-off-by: Jess Frazelle <github@jessfraz.com>
2024-06-21 22:22:47 -07:00
99655d623e updates
Signed-off-by: Jess Frazelle <github@jessfraz.com>
2024-06-21 21:59:10 -07:00
4d7cac6c1d add code mods for surfaces
Signed-off-by: Jess Frazelle <github@jessfraz.com>
2024-06-21 21:57:51 -07:00
59ed422907 fmt
Signed-off-by: Jess Frazelle <github@jessfraz.com>
2024-06-21 21:51:39 -07:00
3b30ac7d39 Merge branch 'main' into wip-multi-profile 2024-06-21 21:49:54 -07:00
41a6ddd769 updates
Signed-off-by: Jess Frazelle <github@jessfraz.com>

updates

Signed-off-by: Jess Frazelle <github@jessfraz.com>

more

Signed-off-by: Jess Frazelle <github@jessfraz.com>
2024-06-21 20:20:31 -07:00
3 changed files with 50 additions and 18 deletions

View File

@ -317,7 +317,8 @@ describe('testing sketchOnExtrudedFace', () => {
|> line([8.62, -9.57], %)
|> close(%)
|> extrude(5 + 7, %)
const sketch001 = startSketchOn(part001, 'seg01')`)
const surface001 = startSketchOn(part001, 'seg01')
const sketch001 = surface001`)
})
test('it should be able to extrude on close segments', async () => {
const code = `const part001 = startSketchOn('-XZ')
@ -354,7 +355,8 @@ const sketch001 = startSketchOn(part001, 'seg01')`)
|> line([8.62, -9.57], %)
|> close(%, 'seg01')
|> extrude(5 + 7, %)
const sketch001 = startSketchOn(part001, 'seg01')`)
const surface001 = startSketchOn(part001, 'seg01')
const sketch001 = surface001`)
})
test('it should be able to extrude on start-end caps', async () => {
const code = `const part001 = startSketchOn('-XZ')
@ -392,7 +394,8 @@ const sketch001 = startSketchOn(part001, 'seg01')`)
|> line([8.62, -9.57], %)
|> close(%)
|> extrude(5 + 7, %)
const sketch001 = startSketchOn(part001, 'END')`)
const surface001 = startSketchOn(part001, 'END')
const sketch001 = surface001`)
})
test('it should ensure that the new sketch is inserted after the extrude', async () => {
const code = `const sketch001 = startSketchOn('-XZ')
@ -432,7 +435,8 @@ const sketch001 = startSketchOn(part001, 'END')`)
)
const newCode = recast(modifiedAst)
expect(newCode).toContain(`const part001 = extrude(5 + 7, sketch001)
const sketch002 = startSketchOn(part001, 'seg01')`)
const surface001 = startSketchOn(part001, 'seg01')
const sketch002 = surface001`)
})
})

View File

@ -43,15 +43,27 @@ export function startSketchOnDefault(
name = ''
): { modifiedAst: Program; id: string; pathToNode: PathToNode } {
const _node = { ...node }
const _name =
name || findUniqueName(node, KCL_DEFAULT_CONSTANT_PREFIXES.SKETCH)
const surfaceName =
name || findUniqueName(node, KCL_DEFAULT_CONSTANT_PREFIXES.SURFACE)
const startSketchOn = createCallExpressionStdLib('startSketchOn', [
createLiteral(axis),
])
const variableDeclaration = createVariableDeclaration(_name, startSketchOn)
_node.body = [...node.body, variableDeclaration]
const surfaceVariableDeclaration = createVariableDeclaration(
surfaceName,
startSketchOn
)
_node.body = [..._node.body, surfaceVariableDeclaration]
// Create the variable for the sketch.
const sketchName =
name || findUniqueName(node, KCL_DEFAULT_CONSTANT_PREFIXES.SKETCH)
const sketchVariableDeclaration = createVariableDeclaration(
sketchName,
createIdentifier(surfaceName)
)
_node.body = [..._node.body, sketchVariableDeclaration]
const sketchIndex = _node.body.length - 1
let pathToNode: PathToNode = [
@ -64,7 +76,7 @@ export function startSketchOnDefault(
return {
modifiedAst: _node,
id: _name,
id: sketchName,
pathToNode,
}
}
@ -333,10 +345,11 @@ export function sketchOnExtrudedFace(
cap: 'none' | 'start' | 'end' = 'none'
): { modifiedAst: Program; pathToNode: PathToNode } {
let _node = { ...node }
const newSketchName = findUniqueName(
const newSurfaceName = findUniqueName(
node,
KCL_DEFAULT_CONSTANT_PREFIXES.SKETCH
KCL_DEFAULT_CONSTANT_PREFIXES.SURFACE
)
const { node: oldSketchNode } = getNodeFromPath<VariableDeclarator>(
_node,
sketchPathToNode,
@ -372,8 +385,8 @@ export function sketchOnExtrudedFace(
_tag = cap.toUpperCase()
}
const newSketch = createVariableDeclaration(
newSketchName,
const newSurface = createVariableDeclaration(
newSurfaceName,
createCallExpressionStdLib('startSketchOn', [
createIdentifier(extrudeName ? extrudeName : oldSketchName),
createLiteral(_tag),
@ -385,18 +398,31 @@ export function sketchOnExtrudedFace(
sketchPathToNode[1][0] as number,
extrudePathToNode[1][0] as number
)
_node.body.splice(expressionIndex + 1, 0, newSketch)
const newpathToNode: PathToNode = [
_node.body.splice(expressionIndex + 1, 0, newSurface)
// Create the variable for the sketch.
const newSketchName = findUniqueName(
node,
KCL_DEFAULT_CONSTANT_PREFIXES.SKETCH
)
const sketchVariableDeclaration = createVariableDeclaration(
newSketchName,
createIdentifier(newSurfaceName)
)
const sketchIndex = expressionIndex + 2
_node.body.splice(sketchIndex, 0, sketchVariableDeclaration)
let newPathToNode: PathToNode = [
['body', ''],
[expressionIndex + 1, 'index'],
[sketchIndex, 'index'],
['declarations', 'VariableDeclaration'],
[0, 'index'],
['0', 'index'],
['init', 'VariableDeclarator'],
]
return {
modifiedAst: _node,
pathToNode: newpathToNode,
pathToNode: newPathToNode,
}
}

View File

@ -49,6 +49,8 @@ export const ONBOARDING_PROJECT_NAME = 'Tutorial Project $nn'
* These are used to generate unique names for new objects.
* */
export const KCL_DEFAULT_CONSTANT_PREFIXES = {
SURFACE: 'surface',
PROFILE: 'profile',
SKETCH: 'sketch',
EXTRUDE: 'extrude',
} as const