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