Fillet UI (#2718)
* draft: fillet ast mod + test * Kurt's rejig * playwright * update button enable logic * remove fillet button in production build * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu) * trigger CI * fix typo * give a way to turn on fillets --------- Co-authored-by: max-mrgrsk <margorskyi@gmail.com> Co-authored-by: max-mrgrsk <156543465+max-mrgrsk@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
This commit is contained in:
@ -38,6 +38,7 @@ import {
|
||||
deleteFromSelection,
|
||||
extrudeSketch,
|
||||
} from 'lang/modifyAst'
|
||||
import { addFillet } from 'lang/modifyAst/addFillet'
|
||||
import { getNodeFromPath } from '../lang/queryAst'
|
||||
import {
|
||||
applyConstraintEqualAngle,
|
||||
@ -207,6 +208,7 @@ export type ModelingMachineEvent =
|
||||
| { type: 'Re-execute' }
|
||||
| { type: 'Export'; data: ModelingCommandSchema['Export'] }
|
||||
| { type: 'Extrude'; data?: ModelingCommandSchema['Extrude'] }
|
||||
| { type: 'Fillet'; data?: ModelingCommandSchema['Fillet'] }
|
||||
| {
|
||||
type: 'Add rectangle origin'
|
||||
data: [x: number, y: number]
|
||||
@ -317,6 +319,13 @@ export const modelingMachine = createMachine(
|
||||
internal: true,
|
||||
},
|
||||
|
||||
Fillet: {
|
||||
target: 'idle',
|
||||
cond: 'has valid fillet selection', // TODO: fix selections
|
||||
actions: ['AST fillet'],
|
||||
internal: true,
|
||||
},
|
||||
|
||||
Export: {
|
||||
target: 'idle',
|
||||
internal: true,
|
||||
@ -1102,6 +1111,71 @@ export const modelingMachine = createMachine(
|
||||
|
||||
await kclManager.updateAst(modifiedAst, true)
|
||||
},
|
||||
'AST fillet': async (_, event) => {
|
||||
if (!event.data) return
|
||||
|
||||
const { selection, radius } = event.data
|
||||
let ast = kclManager.ast
|
||||
|
||||
if (
|
||||
'variableName' in radius &&
|
||||
radius.variableName &&
|
||||
radius.insertIndex !== undefined
|
||||
) {
|
||||
const newBody = [...ast.body]
|
||||
newBody.splice(radius.insertIndex, 0, radius.variableDeclarationAst)
|
||||
ast.body = newBody
|
||||
}
|
||||
|
||||
const pathToSegmentNode = getNodePathFromSourceRange(
|
||||
ast,
|
||||
selection.codeBasedSelections[0].range
|
||||
)
|
||||
|
||||
const varDecNode = getNodeFromPath<VariableDeclaration>(
|
||||
ast,
|
||||
pathToSegmentNode,
|
||||
'VariableDeclaration'
|
||||
)
|
||||
if (err(varDecNode)) return
|
||||
const sketchVar = varDecNode.node.declarations[0].id.name
|
||||
const sketchGroup = kclManager.programMemory.root[sketchVar]
|
||||
if (sketchGroup.type !== 'SketchGroup') return
|
||||
const idArtifact = engineCommandManager.artifactMap[sketchGroup.id]
|
||||
if (idArtifact.commandType !== 'start_path') return
|
||||
const extrusionArtifactId = (idArtifact as any)?.extrusions?.[0]
|
||||
if (typeof extrusionArtifactId !== 'string') return
|
||||
const extrusionArtifact = (engineCommandManager.artifactMap as any)[
|
||||
extrusionArtifactId
|
||||
]
|
||||
if (!extrusionArtifact) return
|
||||
const pathToExtrudeNode = getNodePathFromSourceRange(
|
||||
ast,
|
||||
extrusionArtifact.range
|
||||
)
|
||||
|
||||
// we assume that there is only one body related to the sketch
|
||||
// and apply the fillet to it
|
||||
|
||||
const addFilletResult = addFillet(
|
||||
ast,
|
||||
pathToSegmentNode,
|
||||
pathToExtrudeNode,
|
||||
'variableName' in radius
|
||||
? radius.variableIdentifierAst
|
||||
: radius.valueAst
|
||||
)
|
||||
|
||||
if (trap(addFilletResult)) return
|
||||
const { modifiedAst, pathToFilletNode } = addFilletResult
|
||||
|
||||
const updatedAst = await kclManager.updateAst(modifiedAst, true, {
|
||||
focusPath: pathToFilletNode,
|
||||
})
|
||||
if (updatedAst?.selections) {
|
||||
editorManager.selectRange(updatedAst?.selections)
|
||||
}
|
||||
},
|
||||
'conditionally equip line tool': (_, { type }) => {
|
||||
if (type === 'done.invoke.animate-to-face') {
|
||||
sceneInfra.modelingSend({
|
||||
|
Reference in New Issue
Block a user