Compare commits
4 Commits
codex/upda
...
achalmers/
Author | SHA1 | Date | |
---|---|---|---|
f7fb2ce05e | |||
bed2070d97 | |||
61830e6f0a | |||
199947b2e0 |
@ -140,23 +140,6 @@ export function createPipeSubstitution(): Node<PipeSubstitution> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createCallExpressionStdLib(
|
|
||||||
name: string,
|
|
||||||
args: CallExpression['arguments']
|
|
||||||
): Node<CallExpression> {
|
|
||||||
return {
|
|
||||||
type: 'CallExpression',
|
|
||||||
start: 0,
|
|
||||||
end: 0,
|
|
||||||
moduleId: 0,
|
|
||||||
outerAttrs: [],
|
|
||||||
preComments: [],
|
|
||||||
commentStart: 0,
|
|
||||||
callee: createLocalName(name),
|
|
||||||
arguments: args,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const nonCodeMetaEmpty = () => {
|
export const nonCodeMetaEmpty = () => {
|
||||||
return { nonCodeNodes: {}, startNodes: [], start: 0, end: 0 }
|
return { nonCodeNodes: {}, startNodes: [], start: 0, end: 0 }
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@ import type { NonCodeMeta } from '@rust/kcl-lib/bindings/NonCodeMeta'
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
createArrayExpression,
|
createArrayExpression,
|
||||||
createCallExpressionStdLib,
|
|
||||||
createCallExpressionStdLibKw,
|
createCallExpressionStdLibKw,
|
||||||
createExpressionStatement,
|
createExpressionStatement,
|
||||||
createIdentifier,
|
createIdentifier,
|
||||||
@ -14,7 +13,6 @@ import {
|
|||||||
createLabeledArg,
|
createLabeledArg,
|
||||||
createLiteral,
|
createLiteral,
|
||||||
createLocalName,
|
createLocalName,
|
||||||
createObjectExpression,
|
|
||||||
createPipeExpression,
|
createPipeExpression,
|
||||||
createVariableDeclaration,
|
createVariableDeclaration,
|
||||||
findUniqueName,
|
findUniqueName,
|
||||||
@ -439,9 +437,11 @@ export function loftSketches(
|
|||||||
const modifiedAst = structuredClone(node)
|
const modifiedAst = structuredClone(node)
|
||||||
const name = findUniqueName(node, KCL_DEFAULT_CONSTANT_PREFIXES.LOFT)
|
const name = findUniqueName(node, KCL_DEFAULT_CONSTANT_PREFIXES.LOFT)
|
||||||
const elements = declarators.map((d) => createLocalName(d.id.name))
|
const elements = declarators.map((d) => createLocalName(d.id.name))
|
||||||
const loft = createCallExpressionStdLib('loft', [
|
const loft = createCallExpressionStdLibKw(
|
||||||
|
'loft',
|
||||||
createArrayExpression(elements),
|
createArrayExpression(elements),
|
||||||
])
|
[]
|
||||||
|
)
|
||||||
const declaration = createVariableDeclaration(name, loft)
|
const declaration = createVariableDeclaration(name, loft)
|
||||||
modifiedAst.body.push(declaration)
|
modifiedAst.body.push(declaration)
|
||||||
const pathToNode: PathToNode = [
|
const pathToNode: PathToNode = [
|
||||||
@ -574,101 +574,6 @@ export function addSweep({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function revolveSketch(
|
|
||||||
node: Node<Program>,
|
|
||||||
pathToNode: PathToNode,
|
|
||||||
shouldPipe = false,
|
|
||||||
angle: Expr = createLiteral(4)
|
|
||||||
):
|
|
||||||
| {
|
|
||||||
modifiedAst: Node<Program>
|
|
||||||
pathToNode: PathToNode
|
|
||||||
pathToRevolveArg: PathToNode
|
|
||||||
}
|
|
||||||
| Error {
|
|
||||||
const _node = structuredClone(node)
|
|
||||||
const _node1 = getNodeFromPath(_node, pathToNode)
|
|
||||||
if (err(_node1)) return _node1
|
|
||||||
const { node: sketchExpression } = _node1
|
|
||||||
|
|
||||||
// determine if sketchExpression is in a pipeExpression or not
|
|
||||||
const _node2 = getNodeFromPath<PipeExpression>(
|
|
||||||
_node,
|
|
||||||
pathToNode,
|
|
||||||
'PipeExpression'
|
|
||||||
)
|
|
||||||
if (err(_node2)) return _node2
|
|
||||||
const { node: pipeExpression } = _node2
|
|
||||||
|
|
||||||
const isInPipeExpression = pipeExpression.type === 'PipeExpression'
|
|
||||||
|
|
||||||
const _node3 = getNodeFromPath<VariableDeclarator>(
|
|
||||||
_node,
|
|
||||||
pathToNode,
|
|
||||||
'VariableDeclarator'
|
|
||||||
)
|
|
||||||
if (err(_node3)) return _node3
|
|
||||||
const { node: variableDeclarator, shallowPath: pathToDecleration } = _node3
|
|
||||||
|
|
||||||
const revolveCall = createCallExpressionStdLib('revolve', [
|
|
||||||
createObjectExpression({
|
|
||||||
angle: angle,
|
|
||||||
// TODO: hard coded 'X' axis for revolve MVP, should be changed.
|
|
||||||
axis: createLocalName('X'),
|
|
||||||
}),
|
|
||||||
createLocalName(variableDeclarator.id.name),
|
|
||||||
])
|
|
||||||
|
|
||||||
if (shouldPipe) {
|
|
||||||
const pipeChain = createPipeExpression(
|
|
||||||
isInPipeExpression
|
|
||||||
? [...pipeExpression.body, revolveCall]
|
|
||||||
: [sketchExpression as any, revolveCall]
|
|
||||||
)
|
|
||||||
|
|
||||||
variableDeclarator.init = pipeChain
|
|
||||||
const pathToRevolveArg: PathToNode = [
|
|
||||||
...pathToDecleration,
|
|
||||||
['init', 'VariableDeclarator'],
|
|
||||||
['body', ''],
|
|
||||||
[pipeChain.body.length - 1, 'index'],
|
|
||||||
['arguments', 'CallExpression'],
|
|
||||||
[0, 'index'],
|
|
||||||
]
|
|
||||||
|
|
||||||
return {
|
|
||||||
modifiedAst: _node,
|
|
||||||
pathToNode,
|
|
||||||
pathToRevolveArg,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// We're not creating a pipe expression,
|
|
||||||
// but rather a separate constant for the extrusion
|
|
||||||
const name = findUniqueName(node, KCL_DEFAULT_CONSTANT_PREFIXES.REVOLVE)
|
|
||||||
const VariableDeclaration = createVariableDeclaration(name, revolveCall)
|
|
||||||
const sketchIndexInPathToNode =
|
|
||||||
pathToDecleration.findIndex((a) => a[0] === 'body') + 1
|
|
||||||
const sketchIndexInBody = pathToDecleration[sketchIndexInPathToNode][0]
|
|
||||||
if (typeof sketchIndexInBody !== 'number')
|
|
||||||
return new Error('expected sketchIndexInBody to be a number')
|
|
||||||
_node.body.splice(sketchIndexInBody + 1, 0, VariableDeclaration)
|
|
||||||
|
|
||||||
const pathToRevolveArg: PathToNode = [
|
|
||||||
['body', ''],
|
|
||||||
[sketchIndexInBody + 1, 'index'],
|
|
||||||
['declaration', 'VariableDeclaration'],
|
|
||||||
['init', 'VariableDeclarator'],
|
|
||||||
['arguments', 'CallExpression'],
|
|
||||||
[0, 'index'],
|
|
||||||
]
|
|
||||||
return {
|
|
||||||
modifiedAst: _node,
|
|
||||||
pathToNode: [...pathToNode.slice(0, -1), [-1, 'index']],
|
|
||||||
pathToRevolveArg,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function sketchOnExtrudedFace(
|
export function sketchOnExtrudedFace(
|
||||||
node: Node<Program>,
|
node: Node<Program>,
|
||||||
sketchPathToNode: PathToNode,
|
sketchPathToNode: PathToNode,
|
||||||
|
@ -207,11 +207,11 @@ export async function deleteFromSelection(
|
|||||||
extrudeNameToDelete = dec.id.name
|
extrudeNameToDelete = dec.id.name
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
// TODO: This is wrong, loft is now a CallExpressionKw.
|
dec.init.type === 'CallExpressionKw' &&
|
||||||
dec.init.type === 'CallExpression' &&
|
|
||||||
dec.init.callee.name.name === 'loft' &&
|
dec.init.callee.name.name === 'loft' &&
|
||||||
dec.init.arguments?.[0].type === 'ArrayExpression' &&
|
dec.init.unlabeled !== null &&
|
||||||
dec.init.arguments?.[0].elements.some(
|
dec.init.unlabeled.type === 'ArrayExpression' &&
|
||||||
|
dec.init.unlabeled.elements.some(
|
||||||
(a) => a.type === 'Name' && a.name.name === varDecName
|
(a) => a.type === 'Name' && a.name.name === varDecName
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
|
@ -22,7 +22,6 @@ import type {
|
|||||||
Program,
|
Program,
|
||||||
} from '@src/lang/wasm'
|
} from '@src/lang/wasm'
|
||||||
import {
|
import {
|
||||||
createCallExpressionStdLib,
|
|
||||||
createArrayExpression,
|
createArrayExpression,
|
||||||
createLocalName,
|
createLocalName,
|
||||||
createCallExpressionStdLibKw,
|
createCallExpressionStdLibKw,
|
||||||
@ -194,12 +193,16 @@ export function createTagExpressions(
|
|||||||
|
|
||||||
// Modify the tag based on selectionType
|
// Modify the tag based on selectionType
|
||||||
if (artifact.type === 'sweepEdge' && artifact.subType === 'opposite') {
|
if (artifact.type === 'sweepEdge' && artifact.subType === 'opposite') {
|
||||||
tagCall = createCallExpressionStdLib('getOppositeEdge', [tagCall])
|
tagCall = createCallExpressionStdLibKw('getOppositeEdge', tagCall, [])
|
||||||
} else if (
|
} else if (
|
||||||
artifact.type === 'sweepEdge' &&
|
artifact.type === 'sweepEdge' &&
|
||||||
artifact.subType === 'adjacent'
|
artifact.subType === 'adjacent'
|
||||||
) {
|
) {
|
||||||
tagCall = createCallExpressionStdLib('getNextAdjacentEdge', [tagCall])
|
tagCall = createCallExpressionStdLibKw(
|
||||||
|
'getNextAdjacentEdge',
|
||||||
|
tagCall,
|
||||||
|
[]
|
||||||
|
)
|
||||||
}
|
}
|
||||||
return tagCall
|
return tagCall
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,8 @@ import type { Name } from '@rust/kcl-lib/bindings/Name'
|
|||||||
import {
|
import {
|
||||||
createArrayExpression,
|
createArrayExpression,
|
||||||
createCallExpression,
|
createCallExpression,
|
||||||
createCallExpressionStdLib,
|
createCallExpressionStdLibKw,
|
||||||
|
createLabeledArg,
|
||||||
createLiteral,
|
createLiteral,
|
||||||
createPipeSubstitution,
|
createPipeSubstitution,
|
||||||
} from '@src/lang/create'
|
} from '@src/lang/create'
|
||||||
@ -28,6 +29,7 @@ import { assertParse, recast } from '@src/lang/wasm'
|
|||||||
import { initPromise } from '@src/lang/wasmUtils'
|
import { initPromise } from '@src/lang/wasmUtils'
|
||||||
import { enginelessExecutor } from '@src/lib/testHelpers'
|
import { enginelessExecutor } from '@src/lib/testHelpers'
|
||||||
import { err } from '@src/lib/trap'
|
import { err } from '@src/lib/trap'
|
||||||
|
import { ARG_END_ABSOLUTE } from '@src/lang/constants'
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
await initPromise
|
await initPromise
|
||||||
@ -721,20 +723,23 @@ describe('Testing specific sketch getNodeFromPath workflow', () => {
|
|||||||
variables: {},
|
variables: {},
|
||||||
pathToNode: sketchPathToNode,
|
pathToNode: sketchPathToNode,
|
||||||
expressions: [
|
expressions: [
|
||||||
createCallExpressionStdLib(
|
createCallExpressionStdLibKw('line', null, [
|
||||||
'lineTo', // We are forcing lineTo!
|
createLabeledArg(
|
||||||
[
|
ARG_END_ABSOLUTE,
|
||||||
createArrayExpression([
|
createArrayExpression([
|
||||||
createCallExpressionStdLib('profileStartX', [
|
createCallExpressionStdLibKw(
|
||||||
|
'profileStartX',
|
||||||
createPipeSubstitution(),
|
createPipeSubstitution(),
|
||||||
]),
|
[]
|
||||||
createCallExpressionStdLib('profileStartY', [
|
),
|
||||||
|
createCallExpressionStdLibKw(
|
||||||
|
'profileStartY',
|
||||||
createPipeSubstitution(),
|
createPipeSubstitution(),
|
||||||
]),
|
[]
|
||||||
]),
|
),
|
||||||
createPipeSubstitution(),
|
])
|
||||||
]
|
),
|
||||||
),
|
]),
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
if (err(modifiedAst)) throw modifiedAst
|
if (err(modifiedAst)) throw modifiedAst
|
||||||
@ -748,7 +753,7 @@ describe('Testing specific sketch getNodeFromPath workflow', () => {
|
|||||||
|> xLine(length = -0.15)
|
|> xLine(length = -0.15)
|
||||||
|> line([-0.02, 0.21], %)
|
|> line([-0.02, 0.21], %)
|
||||||
|> line([-0.08, 0.05], %)
|
|> line([-0.08, 0.05], %)
|
||||||
|> lineTo([profileStartX(%), profileStartY(%)], %)
|
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||||
`
|
`
|
||||||
expect(recasted).toEqual(expectedCode)
|
expect(recasted).toEqual(expectedCode)
|
||||||
})
|
})
|
||||||
|
@ -9,7 +9,6 @@ import {
|
|||||||
import {
|
import {
|
||||||
createArrayExpression,
|
createArrayExpression,
|
||||||
createBinaryExpression,
|
createBinaryExpression,
|
||||||
createCallExpressionStdLib,
|
|
||||||
createCallExpressionStdLibKw,
|
createCallExpressionStdLibKw,
|
||||||
createLabeledArg,
|
createLabeledArg,
|
||||||
createLiteral,
|
createLiteral,
|
||||||
@ -64,16 +63,16 @@ export const getRectangleCallExpressions = (
|
|||||||
),
|
),
|
||||||
angledLine(
|
angledLine(
|
||||||
createBinaryExpression([
|
createBinaryExpression([
|
||||||
createCallExpressionStdLib('segAng', [createLocalName(tag)]),
|
createCallExpressionStdLibKw('segAng', createLocalName(tag), []),
|
||||||
'+',
|
'+',
|
||||||
createLiteral(90),
|
createLiteral(90),
|
||||||
]), // 90 offset from the previous line
|
]), // 90 offset from the previous line
|
||||||
createLiteral(0) // This will be the height of the rectangle
|
createLiteral(0) // This will be the height of the rectangle
|
||||||
),
|
),
|
||||||
angledLine(
|
angledLine(
|
||||||
createCallExpressionStdLib('segAng', [createLocalName(tag)]), // same angle as the first line
|
createCallExpressionStdLibKw('segAng', createLocalName(tag), []), // same angle as the first line
|
||||||
createUnaryExpression(
|
createUnaryExpression(
|
||||||
createCallExpressionStdLib('segLen', [createLocalName(tag)]),
|
createCallExpressionStdLibKw('segLen', createLocalName(tag), []),
|
||||||
'-'
|
'-'
|
||||||
) // negative height
|
) // negative height
|
||||||
),
|
),
|
||||||
@ -120,7 +119,7 @@ export function updateRectangleSketch(
|
|||||||
'angle',
|
'angle',
|
||||||
secondEdge,
|
secondEdge,
|
||||||
createBinaryExpression([
|
createBinaryExpression([
|
||||||
createCallExpressionStdLib('segAng', [createLocalName(tag)]),
|
createCallExpressionStdLibKw('segAng', createLocalName(tag), []),
|
||||||
Math.sign(y) === Math.sign(x) ? '+' : '-',
|
Math.sign(y) === Math.sign(x) ? '+' : '-',
|
||||||
createLiteral(90),
|
createLiteral(90),
|
||||||
])
|
])
|
||||||
@ -198,7 +197,7 @@ export function updateCenterRectangleSketch(
|
|||||||
}
|
}
|
||||||
oldAngleOperator = oldAngle.operator
|
oldAngleOperator = oldAngle.operator
|
||||||
const newAngle = createBinaryExpression([
|
const newAngle = createBinaryExpression([
|
||||||
createCallExpressionStdLib('segAng', [createLocalName(tag)]),
|
createCallExpressionStdLibKw('segAng', createLocalName(tag), []),
|
||||||
oldAngleOperator,
|
oldAngleOperator,
|
||||||
createLiteral(90),
|
createLiteral(90),
|
||||||
])
|
])
|
||||||
|
Reference in New Issue
Block a user