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], %) |> line([8.62, -9.57], %)
|> close(%) |> close(%)
|> extrude(5 + 7, %) |> 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 () => { test('it should be able to extrude on close segments', async () => {
const code = `const part001 = startSketchOn('-XZ') const code = `const part001 = startSketchOn('-XZ')
@ -354,7 +355,8 @@ const sketch001 = startSketchOn(part001, 'seg01')`)
|> line([8.62, -9.57], %) |> line([8.62, -9.57], %)
|> close(%, 'seg01') |> close(%, 'seg01')
|> extrude(5 + 7, %) |> 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 () => { test('it should be able to extrude on start-end caps', async () => {
const code = `const part001 = startSketchOn('-XZ') const code = `const part001 = startSketchOn('-XZ')
@ -392,7 +394,8 @@ const sketch001 = startSketchOn(part001, 'seg01')`)
|> line([8.62, -9.57], %) |> line([8.62, -9.57], %)
|> close(%) |> close(%)
|> extrude(5 + 7, %) |> 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 () => { test('it should ensure that the new sketch is inserted after the extrude', async () => {
const code = `const sketch001 = startSketchOn('-XZ') const code = `const sketch001 = startSketchOn('-XZ')
@ -432,7 +435,8 @@ const sketch001 = startSketchOn(part001, 'END')`)
) )
const newCode = recast(modifiedAst) const newCode = recast(modifiedAst)
expect(newCode).toContain(`const part001 = extrude(5 + 7, sketch001) 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 = '' name = ''
): { modifiedAst: Program; id: string; pathToNode: PathToNode } { ): { modifiedAst: Program; id: string; pathToNode: PathToNode } {
const _node = { ...node } const _node = { ...node }
const _name = const surfaceName =
name || findUniqueName(node, KCL_DEFAULT_CONSTANT_PREFIXES.SKETCH) name || findUniqueName(node, KCL_DEFAULT_CONSTANT_PREFIXES.SURFACE)
const startSketchOn = createCallExpressionStdLib('startSketchOn', [ const startSketchOn = createCallExpressionStdLib('startSketchOn', [
createLiteral(axis), createLiteral(axis),
]) ])
const variableDeclaration = createVariableDeclaration(_name, startSketchOn) const surfaceVariableDeclaration = createVariableDeclaration(
_node.body = [...node.body, variableDeclaration] 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 const sketchIndex = _node.body.length - 1
let pathToNode: PathToNode = [ let pathToNode: PathToNode = [
@ -64,7 +76,7 @@ export function startSketchOnDefault(
return { return {
modifiedAst: _node, modifiedAst: _node,
id: _name, id: sketchName,
pathToNode, pathToNode,
} }
} }
@ -333,10 +345,11 @@ export function sketchOnExtrudedFace(
cap: 'none' | 'start' | 'end' = 'none' cap: 'none' | 'start' | 'end' = 'none'
): { modifiedAst: Program; pathToNode: PathToNode } { ): { modifiedAst: Program; pathToNode: PathToNode } {
let _node = { ...node } let _node = { ...node }
const newSketchName = findUniqueName( const newSurfaceName = findUniqueName(
node, node,
KCL_DEFAULT_CONSTANT_PREFIXES.SKETCH KCL_DEFAULT_CONSTANT_PREFIXES.SURFACE
) )
const { node: oldSketchNode } = getNodeFromPath<VariableDeclarator>( const { node: oldSketchNode } = getNodeFromPath<VariableDeclarator>(
_node, _node,
sketchPathToNode, sketchPathToNode,
@ -372,8 +385,8 @@ export function sketchOnExtrudedFace(
_tag = cap.toUpperCase() _tag = cap.toUpperCase()
} }
const newSketch = createVariableDeclaration( const newSurface = createVariableDeclaration(
newSketchName, newSurfaceName,
createCallExpressionStdLib('startSketchOn', [ createCallExpressionStdLib('startSketchOn', [
createIdentifier(extrudeName ? extrudeName : oldSketchName), createIdentifier(extrudeName ? extrudeName : oldSketchName),
createLiteral(_tag), createLiteral(_tag),
@ -385,18 +398,31 @@ export function sketchOnExtrudedFace(
sketchPathToNode[1][0] as number, sketchPathToNode[1][0] as number,
extrudePathToNode[1][0] as number extrudePathToNode[1][0] as number
) )
_node.body.splice(expressionIndex + 1, 0, newSketch) _node.body.splice(expressionIndex + 1, 0, newSurface)
const newpathToNode: PathToNode = [
// 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', ''], ['body', ''],
[expressionIndex + 1, 'index'], [sketchIndex, 'index'],
['declarations', 'VariableDeclaration'], ['declarations', 'VariableDeclaration'],
[0, 'index'], ['0', 'index'],
['init', 'VariableDeclarator'], ['init', 'VariableDeclarator'],
] ]
return { return {
modifiedAst: _node, 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. * These are used to generate unique names for new objects.
* */ * */
export const KCL_DEFAULT_CONSTANT_PREFIXES = { export const KCL_DEFAULT_CONSTANT_PREFIXES = {
SURFACE: 'surface',
PROFILE: 'profile',
SKETCH: 'sketch', SKETCH: 'sketch',
EXTRUDE: 'extrude', EXTRUDE: 'extrude',
} as const } as const