diff --git a/e2e/playwright/snapshot-tests.spec.ts-snapshots/extrude-on-default-planes-should-be-stable-XY-1-Google-Chrome-win32.png b/e2e/playwright/snapshot-tests.spec.ts-snapshots/extrude-on-default-planes-should-be-stable-XY-1-Google-Chrome-win32.png index 7c00fa129..6358dca59 100644 Binary files a/e2e/playwright/snapshot-tests.spec.ts-snapshots/extrude-on-default-planes-should-be-stable-XY-1-Google-Chrome-win32.png and b/e2e/playwright/snapshot-tests.spec.ts-snapshots/extrude-on-default-planes-should-be-stable-XY-1-Google-Chrome-win32.png differ diff --git a/src/components/ModelingMachineProvider.tsx b/src/components/ModelingMachineProvider.tsx index 3b921bd48..faf2c0ac9 100644 --- a/src/components/ModelingMachineProvider.tsx +++ b/src/components/ModelingMachineProvider.tsx @@ -625,7 +625,6 @@ export const ModelingMachineProvider = ({ } const canShell = canShellSelection(selectionRanges) - console.log('canShellSelection', canShellSelection(selectionRanges)) if (err(canShell)) return false return canShell }, diff --git a/src/lib/commandBarConfigs/modelingCommandConfig.ts b/src/lib/commandBarConfigs/modelingCommandConfig.ts index e66e4ffce..d6042fdf1 100644 --- a/src/lib/commandBarConfigs/modelingCommandConfig.ts +++ b/src/lib/commandBarConfigs/modelingCommandConfig.ts @@ -9,7 +9,7 @@ import { Selections } from 'lib/selections' import { kclManager } from 'lib/singletons' import { err } from 'lib/trap' import { modelingMachine, SketchTool } from 'machines/modelingMachine' -import { revolveAxisValidator } from './validators' +import { loftValidator, revolveAxisValidator } from './validators' type OutputFormat = Models['OutputFormat_type'] type OutputTypeKey = OutputFormat['type'] @@ -297,6 +297,7 @@ export const modelingMachineCommandConfig: StateMachineCommandSetConfig< multiple: true, required: true, skip: false, + validation: loftValidator, }, }, }, diff --git a/src/lib/commandBarConfigs/validators.ts b/src/lib/commandBarConfigs/validators.ts index bd59cd4ee..41522c25c 100644 --- a/src/lib/commandBarConfigs/validators.ts +++ b/src/lib/commandBarConfigs/validators.ts @@ -104,3 +104,52 @@ export const revolveAxisValidator = async ({ return 'Unable to revolve with selected axis' } } + +export const loftValidator = async ({ + data, +}: { + data: { [key: string]: Selections } + context: CommandBarContext +}): Promise => { + if (!isSelections(data.selection)) { + return 'Unable to loft, selections are missing' + } + const { selection } = data + + if (selection.graphSelections.some((s) => s.artifact?.type !== 'solid2D')) { + return 'Unable to loft, some selection are not solid2Ds' + } + + const sectionIds = data.selection.graphSelections.flatMap((s) => + s.artifact?.type === 'solid2D' ? s.artifact.pathId : [] + ) + + if (sectionIds.length < 2) { + return 'Unable to loft, selection contains less than two solid2Ds' + } + + const loftCommand = async () => { + // TODO: check what to do with these + const DEFAULT_V_DEGREE = 2 + const DEFAULT_TOLERANCE = 2 + const DEFAULT_BEZ_APPROXIMATE_RATIONAL = false + return await engineCommandManager.sendSceneCommand({ + type: 'modeling_cmd_req', + cmd_id: uuidv4(), + cmd: { + section_ids: sectionIds, + type: 'loft', + bez_approximate_rational: DEFAULT_BEZ_APPROXIMATE_RATIONAL, + tolerance: DEFAULT_TOLERANCE, + v_degree: DEFAULT_V_DEGREE, + }, + }) + } + const attempt = await dryRunWrapper(loftCommand) + if (attempt?.success) { + return true + } else { + // return error message for the toast + return 'Unable to loft with selected sketches' + } +}