WIP: closer
This commit is contained in:
@ -45,6 +45,7 @@ import { TagDeclarator } from 'wasm-lib/kcl/bindings/TagDeclarator'
|
||||
import { Models } from '@kittycad/lib'
|
||||
import { ExtrudeFacePlane } from 'machines/modelingMachine'
|
||||
import { Node } from 'wasm-lib/kcl/bindings/Node'
|
||||
import { Artifact } from './std/artifactGraph'
|
||||
|
||||
export function startSketchOnDefault(
|
||||
node: Node<Program>,
|
||||
@ -602,18 +603,29 @@ export function addOffsetPlane({
|
||||
*/
|
||||
export function addShell({
|
||||
node,
|
||||
face,
|
||||
selection,
|
||||
thickness,
|
||||
}: {
|
||||
node: Node<Program>
|
||||
face: PathToNode
|
||||
selection: Selection
|
||||
thickness: Expr
|
||||
}): { modifiedAst: Node<Program>; pathToNode: PathToNode } {
|
||||
}): { modifiedAst: Node<Program>; pathToNode: PathToNode } | Error {
|
||||
const modifiedAst = structuredClone(node)
|
||||
const name = findUniqueName(node, KCL_DEFAULT_CONSTANT_PREFIXES.SHELL)
|
||||
// TODO: change to what's needed for shell
|
||||
console.log(face, thickness)
|
||||
const shell = createCallExpressionStdLib('shell', [])
|
||||
console.log('selection, thickness', selection, thickness)
|
||||
const baseNode = getNodeFromPath<VariableDeclarator>(
|
||||
node,
|
||||
selection.codeRef.pathToNode,
|
||||
'VariableDeclarator'
|
||||
)
|
||||
console.log('baseNode', baseNode)
|
||||
if (err(baseNode)) return baseNode
|
||||
console.log("selection.artifact['subType']", selection.artifact['subType'])
|
||||
const shell = createCallExpressionStdLib('shell', [
|
||||
createObjectExpression({ faces: [ selection.artifact['subType'] ], thickness }),
|
||||
createIdentifier(baseNode.node.id.name),
|
||||
])
|
||||
const declaration = createVariableDeclaration(name, shell)
|
||||
modifiedAst.body.push(declaration)
|
||||
|
||||
|
||||
@ -288,10 +288,11 @@ export const modelingMachineCommandConfig: StateMachineCommandSetConfig<
|
||||
args: {
|
||||
selection: {
|
||||
inputType: 'selection',
|
||||
selectionTypes: ['face'],
|
||||
multiple: true,
|
||||
selectionTypes: ['cap', 'wall'],
|
||||
// TODO: check if we can have multiple here
|
||||
multiple: false,
|
||||
required: true,
|
||||
skip: false,
|
||||
skip: true,
|
||||
},
|
||||
thickness: {
|
||||
inputType: 'kcl',
|
||||
|
||||
@ -193,7 +193,7 @@ export const toolbarConfig: Record<ToolbarModeName, ToolbarMode> = {
|
||||
onClick: ({ commandBarSend }) => {
|
||||
commandBarSend({
|
||||
type: 'Find and select command',
|
||||
data: { name: 'Offset plane', groupId: 'modeling' },
|
||||
data: { name: 'Shell', groupId: 'modeling' },
|
||||
})
|
||||
},
|
||||
disabled: (state) => !state.can({ type: 'Shell' }),
|
||||
|
||||
@ -259,6 +259,7 @@ export type ModelingMachineEvent =
|
||||
| { type: 'Make'; data: ModelingCommandSchema['Make'] }
|
||||
| { type: 'Extrude'; data?: ModelingCommandSchema['Extrude'] }
|
||||
| { type: 'Loft'; data?: ModelingCommandSchema['Loft'] }
|
||||
| { type: 'Shell'; data?: ModelingCommandSchema['Shell'] }
|
||||
| { type: 'Revolve'; data?: ModelingCommandSchema['Revolve'] }
|
||||
| { type: 'Fillet'; data?: ModelingCommandSchema['Fillet'] }
|
||||
| { type: 'Offset plane'; data: ModelingCommandSchema['Offset plane'] }
|
||||
@ -1595,9 +1596,10 @@ export const modelingMachine = setup({
|
||||
const { selection, thickness } = input
|
||||
|
||||
// TODO: extract selection
|
||||
// const plane = selection.otherSelections[0]
|
||||
// if (!(plane && plane instanceof Object && 'name' in plane))
|
||||
// return trap('No plane selected')
|
||||
console.log('selection', selection)
|
||||
const graphSelection = selection.graphSelections[0]
|
||||
if (!(graphSelection && graphSelection instanceof Object))
|
||||
return trap('No plane selected')
|
||||
|
||||
// Insert the thickness variable if it exists
|
||||
if (
|
||||
@ -1619,13 +1621,14 @@ export const modelingMachine = setup({
|
||||
|
||||
const shellResult = addShell({
|
||||
node: ast,
|
||||
face: selection.graphSelections[0],
|
||||
selection: graphSelection,
|
||||
thickness:
|
||||
'variableName' in thickness
|
||||
? thickness.variableIdentifierAst
|
||||
: thickness.valueAst,
|
||||
})
|
||||
|
||||
if (trap(shellResult)) return
|
||||
const updateAstResult = await kclManager.updateAst(
|
||||
shellResult.modifiedAst,
|
||||
true,
|
||||
|
||||
Reference in New Issue
Block a user