Compare commits
7 Commits
v0.24.6
...
wip-multi-
Author | SHA1 | Date | |
---|---|---|---|
0e02e95c55 | |||
a94f0191b5 | |||
99655d623e | |||
4d7cac6c1d | |||
59ed422907 | |||
3b30ac7d39 | |||
41a6ddd769 |
@ -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`)
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user