Add dry-run validation for Sweep (#5097)
* Add dry-run validation for Sweep Fixes #5095 * Add sweep test failing validation * Make naming more consistent with engine * Fix tests after big rename * Fix tsc after main merge
This commit is contained in:
@ -13,6 +13,7 @@ import {
|
||||
loftValidator,
|
||||
revolveAxisValidator,
|
||||
shellValidator,
|
||||
sweepValidator,
|
||||
} from './validators'
|
||||
|
||||
type OutputFormat = Models['OutputFormat_type']
|
||||
@ -42,8 +43,8 @@ export type ModelingCommandSchema = {
|
||||
distance: KclCommandValue
|
||||
}
|
||||
Sweep: {
|
||||
path: Selections
|
||||
profile: Selections
|
||||
target: Selections
|
||||
trajectory: Selections
|
||||
}
|
||||
Loft: {
|
||||
selection: Selections
|
||||
@ -308,25 +309,24 @@ export const modelingMachineCommandConfig: StateMachineCommandSetConfig<
|
||||
'Create a 3D body by moving a sketch region along an arbitrary path.',
|
||||
icon: 'sweep',
|
||||
status: 'development',
|
||||
needsReview: true,
|
||||
needsReview: false,
|
||||
args: {
|
||||
profile: {
|
||||
target: {
|
||||
inputType: 'selection',
|
||||
selectionTypes: ['solid2d'],
|
||||
required: true,
|
||||
skip: true,
|
||||
multiple: false,
|
||||
// TODO: add dry-run validation
|
||||
warningMessage:
|
||||
'The sweep workflow is new and under tested. Please break it and report issues.',
|
||||
},
|
||||
path: {
|
||||
trajectory: {
|
||||
inputType: 'selection',
|
||||
selectionTypes: ['segment', 'path'],
|
||||
required: true,
|
||||
skip: true,
|
||||
skip: false,
|
||||
multiple: false,
|
||||
// TODO: add dry-run validation
|
||||
validation: sweepValidator,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -207,3 +207,64 @@ export const shellValidator = async ({
|
||||
|
||||
return 'Unable to shell with the provided selection'
|
||||
}
|
||||
|
||||
export const sweepValidator = async ({
|
||||
context,
|
||||
data,
|
||||
}: {
|
||||
context: CommandBarContext
|
||||
data: { trajectory: Selections }
|
||||
}): Promise<boolean | string> => {
|
||||
if (!isSelections(data.trajectory)) {
|
||||
console.log('Unable to sweep, selections are missing')
|
||||
return 'Unable to sweep, selections are missing'
|
||||
}
|
||||
|
||||
// Retrieve the parent path from the segment selection directly
|
||||
const trajectoryArtifact = data.trajectory.graphSelections[0].artifact
|
||||
if (!trajectoryArtifact) {
|
||||
return "Unable to sweep, couldn't find the trajectory artifact"
|
||||
}
|
||||
if (trajectoryArtifact.type !== 'segment') {
|
||||
return "Unable to sweep, couldn't find the target from a non-segment selection"
|
||||
}
|
||||
const trajectory = trajectoryArtifact.pathId
|
||||
|
||||
// Get the former arg in the command bar flow, and retrieve the path from the solid2d directly
|
||||
const targetArg = context.argumentsToSubmit['target'] as Selections
|
||||
const targetArtifact = targetArg.graphSelections[0].artifact
|
||||
if (!targetArtifact) {
|
||||
return "Unable to sweep, couldn't find the profile artifact"
|
||||
}
|
||||
if (targetArtifact.type !== 'solid2d') {
|
||||
return "Unable to sweep, couldn't find the target from a non-solid2d selection"
|
||||
}
|
||||
const target = targetArtifact.pathId
|
||||
|
||||
const sweepCommand = async () => {
|
||||
// TODO: second look on defaults here
|
||||
const DEFAULT_TOLERANCE: Models['LengthUnit_type'] = 1e-7
|
||||
const DEFAULT_SECTIONAL = false
|
||||
const cmdArgs = {
|
||||
target,
|
||||
trajectory,
|
||||
sectional: DEFAULT_SECTIONAL,
|
||||
tolerance: DEFAULT_TOLERANCE,
|
||||
}
|
||||
return await engineCommandManager.sendSceneCommand({
|
||||
type: 'modeling_cmd_req',
|
||||
cmd_id: uuidv4(),
|
||||
cmd: {
|
||||
type: 'sweep',
|
||||
...cmdArgs,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
const attemptSweep = await dryRunWrapper(sweepCommand)
|
||||
if (attemptSweep?.success) {
|
||||
return true
|
||||
}
|
||||
|
||||
return 'Unable to sweep with the provided selection'
|
||||
}
|
||||
|
Reference in New Issue
Block a user