Enable optional arguments in point-and-click Revolve (#7590)
* WIP: Enable optional arguments in point-and-click Revolve * Add e2e test step
This commit is contained in:
@ -3881,6 +3881,8 @@ sketch002 = startSketchOn(extrude001, face = rectangleSegmentA001)
|
||||
|
||||
// Edit flow
|
||||
const newAngle = '270'
|
||||
const newAngle2 = '5'
|
||||
const editedCodeToFind = `revolve001 = revolve(sketch003, angle = ${newAngle}, axis = seg01, bidirectionalAngle = ${newAngle2}, )`
|
||||
await toolbar.openPane('feature-tree')
|
||||
const operationButton = await toolbar.getFeatureTreeOperation(
|
||||
'Revolve',
|
||||
@ -3906,11 +3908,33 @@ sketch002 = startSketchOn(extrude001, face = rectangleSegmentA001)
|
||||
},
|
||||
commandName: 'Revolve',
|
||||
})
|
||||
await cmdBar.clickOptionalArgument('bidirectionalAngle')
|
||||
await cmdBar.expectState({
|
||||
commandName: 'Revolve',
|
||||
currentArgKey: 'bidirectionalAngle',
|
||||
currentArgValue: '',
|
||||
headerArguments: {
|
||||
Angle: newAngle,
|
||||
BidirectionalAngle: '',
|
||||
},
|
||||
highlightedHeaderArg: 'bidirectionalAngle',
|
||||
stage: 'arguments',
|
||||
})
|
||||
await page.keyboard.insertText(newAngle2)
|
||||
await cmdBar.progressCmdBar()
|
||||
await cmdBar.expectState({
|
||||
stage: 'review',
|
||||
headerArguments: {
|
||||
Angle: newAngle,
|
||||
BidirectionalAngle: newAngle2,
|
||||
},
|
||||
commandName: 'Revolve',
|
||||
})
|
||||
await cmdBar.submit()
|
||||
await toolbar.closePane('feature-tree')
|
||||
await editor.expectEditor.toContain(
|
||||
newCodeToFind.replace('angle = 360', 'angle = ' + newAngle)
|
||||
)
|
||||
await editor.expectEditor.toContain(editedCodeToFind, {
|
||||
shouldNormalise: true,
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -315,6 +315,8 @@ export function addRevolve({
|
||||
axisOrEdge,
|
||||
axis,
|
||||
edge,
|
||||
symmetric,
|
||||
bidirectionalAngle,
|
||||
nodeToEdit,
|
||||
}: {
|
||||
ast: Node<Program>
|
||||
@ -323,6 +325,8 @@ export function addRevolve({
|
||||
axisOrEdge: 'Axis' | 'Edge'
|
||||
axis: string | undefined
|
||||
edge: Selections | undefined
|
||||
symmetric?: boolean
|
||||
bidirectionalAngle?: KclCommandValue
|
||||
nodeToEdit?: PathToNode
|
||||
}):
|
||||
| {
|
||||
@ -355,10 +359,25 @@ export function addRevolve({
|
||||
return new Error('Generated axis selection is missing.')
|
||||
}
|
||||
|
||||
// Extra labeled args expressions
|
||||
const symmetricExpr = symmetric
|
||||
? [createLabeledArg('symmetric', createLiteral(symmetric))]
|
||||
: []
|
||||
const bidirectionalAngleExpr = bidirectionalAngle
|
||||
? [
|
||||
createLabeledArg(
|
||||
'bidirectionalAngle',
|
||||
valueOrVariable(bidirectionalAngle)
|
||||
),
|
||||
]
|
||||
: []
|
||||
|
||||
const sketchesExpr = createSketchExpression(sketchesExprList)
|
||||
const call = createCallExpressionStdLibKw('revolve', sketchesExpr, [
|
||||
createLabeledArg('angle', valueOrVariable(angle)),
|
||||
createLabeledArg('axis', getAxisResult.generatedAxis),
|
||||
...symmetricExpr,
|
||||
...bidirectionalAngleExpr,
|
||||
])
|
||||
|
||||
// Insert variables for labeled arguments if provided
|
||||
@ -366,6 +385,18 @@ export function addRevolve({
|
||||
insertVariableAndOffsetPathToNode(angle, modifiedAst, nodeToEdit)
|
||||
}
|
||||
|
||||
if (
|
||||
bidirectionalAngle &&
|
||||
'variableName' in bidirectionalAngle &&
|
||||
bidirectionalAngle.variableName
|
||||
) {
|
||||
insertVariableAndOffsetPathToNode(
|
||||
bidirectionalAngle,
|
||||
modifiedAst,
|
||||
nodeToEdit
|
||||
)
|
||||
}
|
||||
|
||||
// 3. If edit, we assign the new function call declaration to the existing node,
|
||||
// otherwise just push to the end
|
||||
let pathToNode: PathToNode | undefined
|
||||
|
@ -105,6 +105,8 @@ export type ModelingCommandSchema = {
|
||||
angle: KclCommandValue
|
||||
axis: string | undefined
|
||||
edge: Selections | undefined
|
||||
symmetric?: boolean
|
||||
bidirectionalAngle?: KclCommandValue
|
||||
}
|
||||
Shell: {
|
||||
// Enables editing workflow
|
||||
@ -552,6 +554,18 @@ export const modelingMachineCommandConfig: StateMachineCommandSetConfig<
|
||||
defaultValue: KCL_DEFAULT_DEGREE,
|
||||
required: true,
|
||||
},
|
||||
symmetric: {
|
||||
inputType: 'options',
|
||||
required: false,
|
||||
options: [
|
||||
{ name: 'False', value: false },
|
||||
{ name: 'True', value: true },
|
||||
],
|
||||
},
|
||||
bidirectionalAngle: {
|
||||
inputType: 'kcl',
|
||||
required: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
Shell: {
|
||||
|
@ -1029,6 +1029,35 @@ const prepareToEditRevolve: PrepareToEditCallback = async ({
|
||||
return { reason: 'Error in angle argument retrieval' }
|
||||
}
|
||||
|
||||
// symmetric argument from a string to boolean
|
||||
let symmetric: boolean | undefined
|
||||
if ('symmetric' in operation.labeledArgs && operation.labeledArgs.symmetric) {
|
||||
symmetric =
|
||||
codeManager.code.slice(
|
||||
operation.labeledArgs.symmetric.sourceRange[0],
|
||||
operation.labeledArgs.symmetric.sourceRange[1]
|
||||
) === 'true'
|
||||
}
|
||||
|
||||
// bidirectionalLength argument from a string to a KCL expression
|
||||
let bidirectionalAngle: KclCommandValue | undefined
|
||||
if (
|
||||
'bidirectionalAngle' in operation.labeledArgs &&
|
||||
operation.labeledArgs.bidirectionalAngle
|
||||
) {
|
||||
const result = await stringToKclExpression(
|
||||
codeManager.code.slice(
|
||||
operation.labeledArgs.bidirectionalAngle.sourceRange[0],
|
||||
operation.labeledArgs.bidirectionalAngle.sourceRange[1]
|
||||
)
|
||||
)
|
||||
if (err(result) || 'errors' in result) {
|
||||
return { reason: "Couldn't retrieve bidirectionalAngle argument" }
|
||||
}
|
||||
|
||||
bidirectionalAngle = result
|
||||
}
|
||||
|
||||
// 3. Assemble the default argument values for the command,
|
||||
// with `nodeToEdit` set, which will let the actor know
|
||||
// to edit the node that corresponds to the StdLibCall.
|
||||
@ -1038,6 +1067,8 @@ const prepareToEditRevolve: PrepareToEditCallback = async ({
|
||||
axis,
|
||||
edge,
|
||||
angle,
|
||||
symmetric,
|
||||
bidirectionalAngle,
|
||||
nodeToEdit: pathToNodeFromRustNodePath(operation.nodePath),
|
||||
}
|
||||
return {
|
||||
|
@ -2547,16 +2547,10 @@ export const modelingMachine = setup({
|
||||
return Promise.reject(new Error(NO_INPUT_PROVIDED_MESSAGE))
|
||||
}
|
||||
|
||||
const { nodeToEdit, sketches, angle, axis, edge, axisOrEdge } = input
|
||||
const { ast } = kclManager
|
||||
const astResult = addRevolve({
|
||||
ast,
|
||||
sketches,
|
||||
angle,
|
||||
axisOrEdge,
|
||||
axis,
|
||||
edge,
|
||||
nodeToEdit,
|
||||
...input,
|
||||
})
|
||||
if (err(astResult)) {
|
||||
return Promise.reject(astResult)
|
||||
|
Reference in New Issue
Block a user