Add dry-run validation for Loft (#4820)
* WIP: mess with shell selection validation Will eventually fix #4711 * Update from main * WIP: not working yet * Working loft dry run validator * Clean up shell (still not working) * Bump kittycad-modeling-cmds * Clean up * Add logging * Add proper object_id and face_id mapping, still not working for shell * Fix faceId * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest-8-cores) * A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest-8-cores) * Trigger CI * A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest-8-cores) * Add dry-run validation to Loft Checks one box for #4711 * Add extra check for non solid2ds --------- Co-authored-by: Adam Chalmers <adam.chalmers@zoo.dev> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
This commit is contained in:
Binary file not shown.
Before Width: | Height: | Size: 40 KiB After Width: | Height: | Size: 40 KiB |
@ -625,7 +625,6 @@ export const ModelingMachineProvider = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const canShell = canShellSelection(selectionRanges)
|
const canShell = canShellSelection(selectionRanges)
|
||||||
console.log('canShellSelection', canShellSelection(selectionRanges))
|
|
||||||
if (err(canShell)) return false
|
if (err(canShell)) return false
|
||||||
return canShell
|
return canShell
|
||||||
},
|
},
|
||||||
|
@ -9,7 +9,7 @@ import { Selections } from 'lib/selections'
|
|||||||
import { kclManager } from 'lib/singletons'
|
import { kclManager } from 'lib/singletons'
|
||||||
import { err } from 'lib/trap'
|
import { err } from 'lib/trap'
|
||||||
import { modelingMachine, SketchTool } from 'machines/modelingMachine'
|
import { modelingMachine, SketchTool } from 'machines/modelingMachine'
|
||||||
import { revolveAxisValidator } from './validators'
|
import { loftValidator, revolveAxisValidator } from './validators'
|
||||||
|
|
||||||
type OutputFormat = Models['OutputFormat_type']
|
type OutputFormat = Models['OutputFormat_type']
|
||||||
type OutputTypeKey = OutputFormat['type']
|
type OutputTypeKey = OutputFormat['type']
|
||||||
@ -297,6 +297,7 @@ export const modelingMachineCommandConfig: StateMachineCommandSetConfig<
|
|||||||
multiple: true,
|
multiple: true,
|
||||||
required: true,
|
required: true,
|
||||||
skip: false,
|
skip: false,
|
||||||
|
validation: loftValidator,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -104,3 +104,52 @@ export const revolveAxisValidator = async ({
|
|||||||
return 'Unable to revolve with selected axis'
|
return 'Unable to revolve with selected axis'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const loftValidator = async ({
|
||||||
|
data,
|
||||||
|
}: {
|
||||||
|
data: { [key: string]: Selections }
|
||||||
|
context: CommandBarContext
|
||||||
|
}): Promise<boolean | string> => {
|
||||||
|
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'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user