Feature: new axis and edge selection workflow for point and click revolve (#4939)
* feat: implemented axis or edge selection workflow in the commandbar * fix: removing comment * fix: removing console logs from testing * fix: fixing lint and tsc errors * fix: changed copy * A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-16-cores) * A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-16-cores) --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Frank Noirot <frank@zoo.dev>
This commit is contained in:
Binary file not shown.
After Width: | Height: | Size: 42 KiB |
Binary file not shown.
After Width: | Height: | Size: 47 KiB |
@ -29,7 +29,9 @@ export function revolveSketch(
|
|||||||
pathToSketchNode: PathToNode,
|
pathToSketchNode: PathToNode,
|
||||||
shouldPipe = false,
|
shouldPipe = false,
|
||||||
angle: Expr = createLiteral(4),
|
angle: Expr = createLiteral(4),
|
||||||
axis: Selections
|
axisOrEdge: string,
|
||||||
|
axis: string,
|
||||||
|
edge: Selections
|
||||||
):
|
):
|
||||||
| {
|
| {
|
||||||
modifiedAst: Node<Program>
|
modifiedAst: Node<Program>
|
||||||
@ -41,12 +43,13 @@ export function revolveSketch(
|
|||||||
const sketchNode = getNodeFromPath(clonedAst, pathToSketchNode)
|
const sketchNode = getNodeFromPath(clonedAst, pathToSketchNode)
|
||||||
if (err(sketchNode)) return sketchNode
|
if (err(sketchNode)) return sketchNode
|
||||||
|
|
||||||
// testing code
|
let generatedAxis
|
||||||
|
|
||||||
|
if (axisOrEdge === 'Edge') {
|
||||||
const pathToAxisSelection = getNodePathFromSourceRange(
|
const pathToAxisSelection = getNodePathFromSourceRange(
|
||||||
clonedAst,
|
clonedAst,
|
||||||
axis.graphSelections[0]?.codeRef.range
|
edge.graphSelections[0]?.codeRef.range
|
||||||
)
|
)
|
||||||
|
|
||||||
const lineNode = getNodeFromPath<CallExpression>(
|
const lineNode = getNodeFromPath<CallExpression>(
|
||||||
clonedAst,
|
clonedAst,
|
||||||
pathToAxisSelection,
|
pathToAxisSelection,
|
||||||
@ -54,10 +57,6 @@ export function revolveSketch(
|
|||||||
)
|
)
|
||||||
if (err(lineNode)) return lineNode
|
if (err(lineNode)) return lineNode
|
||||||
|
|
||||||
// TODO Kevin: What if |> close(%)?
|
|
||||||
// TODO Kevin: What if opposite edge
|
|
||||||
// TODO Kevin: What if the edge isn't planar to the sketch?
|
|
||||||
// TODO Kevin: add a tag.
|
|
||||||
const tagResult = mutateAstWithTagForSketchSegment(
|
const tagResult = mutateAstWithTagForSketchSegment(
|
||||||
clonedAst,
|
clonedAst,
|
||||||
pathToAxisSelection
|
pathToAxisSelection
|
||||||
@ -66,6 +65,12 @@ export function revolveSketch(
|
|||||||
// Have the tag whether it is already created or a new one is generated
|
// Have the tag whether it is already created or a new one is generated
|
||||||
if (err(tagResult)) return tagResult
|
if (err(tagResult)) return tagResult
|
||||||
const { tag } = tagResult
|
const { tag } = tagResult
|
||||||
|
const axisSelection = edge?.graphSelections[0]?.artifact
|
||||||
|
if (!axisSelection) return new Error('Generated axis selection is missing.')
|
||||||
|
generatedAxis = getEdgeTagCall(tag, axisSelection)
|
||||||
|
} else {
|
||||||
|
generatedAxis = createLiteral(axis)
|
||||||
|
}
|
||||||
|
|
||||||
/* Original Code */
|
/* Original Code */
|
||||||
const { node: sketchExpression } = sketchNode
|
const { node: sketchExpression } = sketchNode
|
||||||
@ -91,14 +96,12 @@ export function revolveSketch(
|
|||||||
shallowPath: sketchPathToDecleration,
|
shallowPath: sketchPathToDecleration,
|
||||||
} = sketchVariableDeclaratorNode
|
} = sketchVariableDeclaratorNode
|
||||||
|
|
||||||
const axisSelection = axis?.graphSelections[0]?.artifact
|
if (!generatedAxis) return new Error('Generated axis selection is missing.')
|
||||||
|
|
||||||
if (!axisSelection) return new Error('Axis selection is missing.')
|
|
||||||
|
|
||||||
const revolveCall = createCallExpressionStdLib('revolve', [
|
const revolveCall = createCallExpressionStdLib('revolve', [
|
||||||
createObjectExpression({
|
createObjectExpression({
|
||||||
angle: angle,
|
angle: angle,
|
||||||
axis: getEdgeTagCall(tag, axisSelection),
|
axis: generatedAxis,
|
||||||
}),
|
}),
|
||||||
createIdentifier(sketchVariableDeclarator.id.name),
|
createIdentifier(sketchVariableDeclarator.id.name),
|
||||||
])
|
])
|
||||||
|
@ -47,7 +47,9 @@ export type ModelingCommandSchema = {
|
|||||||
Revolve: {
|
Revolve: {
|
||||||
selection: Selections
|
selection: Selections
|
||||||
angle: KclCommandValue
|
angle: KclCommandValue
|
||||||
axis: Selections
|
axisOrEdge: string
|
||||||
|
axis: string
|
||||||
|
edge: Selections
|
||||||
}
|
}
|
||||||
Fillet: {
|
Fillet: {
|
||||||
// todo
|
// todo
|
||||||
@ -324,7 +326,6 @@ export const modelingMachineCommandConfig: StateMachineCommandSetConfig<
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
// TODO: Update this configuration, copied from extrude for MVP of revolve, specifically the args.selection
|
|
||||||
Revolve: {
|
Revolve: {
|
||||||
description: 'Create a 3D body by rotating a sketch region about an axis.',
|
description: 'Create a 3D body by rotating a sketch region about an axis.',
|
||||||
icon: 'revolve',
|
icon: 'revolve',
|
||||||
@ -337,8 +338,31 @@ export const modelingMachineCommandConfig: StateMachineCommandSetConfig<
|
|||||||
required: true,
|
required: true,
|
||||||
skip: true,
|
skip: true,
|
||||||
},
|
},
|
||||||
axis: {
|
axisOrEdge: {
|
||||||
|
inputType: 'options',
|
||||||
required: true,
|
required: true,
|
||||||
|
defaultValue: 'Axis',
|
||||||
|
options: [
|
||||||
|
{ name: 'Axis', isCurrent: true, value: 'Axis' },
|
||||||
|
{ name: 'Edge', isCurrent: false, value: 'Edge' },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
axis: {
|
||||||
|
required: (commandContext) =>
|
||||||
|
['Axis'].includes(
|
||||||
|
commandContext.argumentsToSubmit.axisOrEdge as string
|
||||||
|
),
|
||||||
|
inputType: 'options',
|
||||||
|
options: [
|
||||||
|
{ name: 'X Axis', isCurrent: true, value: 'X' },
|
||||||
|
{ name: 'Y Axis', isCurrent: false, value: 'Y' },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
edge: {
|
||||||
|
required: (commandContext) =>
|
||||||
|
['Edge'].includes(
|
||||||
|
commandContext.argumentsToSubmit.axisOrEdge as string
|
||||||
|
),
|
||||||
inputType: 'selection',
|
inputType: 'selection',
|
||||||
selectionTypes: ['segment', 'sweepEdge', 'edgeCutEdge'],
|
selectionTypes: ['segment', 'sweepEdge', 'edgeCutEdge'],
|
||||||
multiple: false,
|
multiple: false,
|
||||||
|
@ -68,7 +68,7 @@ export const revolveAxisValidator = async ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const sketchSelection = artifact.pathId
|
const sketchSelection = artifact.pathId
|
||||||
let edgeSelection = data.axis.graphSelections[0].artifact?.id
|
let edgeSelection = data.edge.graphSelections[0].artifact?.id
|
||||||
|
|
||||||
if (!sketchSelection) {
|
if (!sketchSelection) {
|
||||||
return 'Unable to revolve, sketch is missing'
|
return 'Unable to revolve, sketch is missing'
|
||||||
@ -101,7 +101,7 @@ export const revolveAxisValidator = async ({
|
|||||||
return true
|
return true
|
||||||
} else {
|
} else {
|
||||||
// return error message for the toast
|
// return error message for the toast
|
||||||
return 'Unable to revolve with selected axis'
|
return 'Unable to revolve with selected edge'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -685,7 +685,7 @@ export const modelingMachine = setup({
|
|||||||
if (event.type !== 'Revolve') return
|
if (event.type !== 'Revolve') return
|
||||||
;(async () => {
|
;(async () => {
|
||||||
if (!event.data) return
|
if (!event.data) return
|
||||||
const { selection, angle, axis } = event.data
|
const { selection, angle, axis, edge, axisOrEdge } = event.data
|
||||||
let ast = kclManager.ast
|
let ast = kclManager.ast
|
||||||
if (
|
if (
|
||||||
'variableName' in angle &&
|
'variableName' in angle &&
|
||||||
@ -710,7 +710,9 @@ export const modelingMachine = setup({
|
|||||||
'variableName' in angle
|
'variableName' in angle
|
||||||
? angle.variableIdentifierAst
|
? angle.variableIdentifierAst
|
||||||
: angle.valueAst,
|
: angle.valueAst,
|
||||||
axis
|
axisOrEdge,
|
||||||
|
axis,
|
||||||
|
edge
|
||||||
)
|
)
|
||||||
if (trap(revolveSketchRes)) return
|
if (trap(revolveSketchRes)) return
|
||||||
const { modifiedAst, pathToRevolveArg } = revolveSketchRes
|
const { modifiedAst, pathToRevolveArg } = revolveSketchRes
|
||||||
|
Reference in New Issue
Block a user