Adding point and click revolve workflow for sketch and axis selection (#4687)
* selection stuff
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest)
* trigger CI
* fix bugs
* some edge cut stuff
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest-8-cores)
* trigger CI
* A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest-8-cores)
* fix sketch mode issues
* fix more tests, selection in sketch related
* more test fixing
* 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)
* Trigger ci
* more sketch mode selection fixes
* fix unit tests
* rename function
* remove .only
* migrate a more selections types
* migrate a more selections types
* migrate a more selections types
* lint
* migrate a more selections types
* migrate a more selections types
* migrate a more selections types
* migrate a more selections types
* migrate a more selections types
* migrate a more selections types
* migrate a more selections types
* migrate a more selections types
* migrate a more selections types
* migrate a more selections types
* fix bad pathToNode issue
* A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest-8-cores)
* fix sketch on face
* migrate a more selections types
* migrate a more selections types
* fix code selection of fillets
* migrate a more selections types
* migrate a more selections types
* migrate a more selections types
* migrate a more selections types
* migrate a more selections types
* fix bad path to node, looks like a race
* migrate a more selections types
* migrate a more selections types
* fix cmd bar selections
* fix cmd bar selections
* fix display issues
* feat: implementing axis selection for point and click revolve
* feat: enforcing selection of 2 options for axis rotation
* feat: added negative rotations for the revolve
* fix: fmt, tsc fixes
* migrate a more selections types
* Revert "migrate a more selections types"
This reverts commit 0d0e453bbb
.
* migrate a more selections types
* clean up1
* clean up 2
* chore: improving the copy after discussing with Frank
* fix: merge main fixes
* chore: was able to add a seg to a line. Does not check if one exists already
* saving off some code
* chore: moving revolveSketch into own file for readability, improving variable names instead of node1
* chore: renaming more variables for readability
* chore: more renaming
* fix: allows creating a custom rotation on axis
* fix: added opposite edge logic and adj, need to error handle still
* fix: use other import
* feat: point and click on edges, crude implementation
* feat: implemented toast message and returned error message from validation
* fix: auto linter
* fix: addressing tsc errors
* fix: fighting typescript
* fix: cleaning up PR
* fix: trying to resolve more typescript issues
* fix: save off tsc fixes
* fix: adding comments
* fix: resolving tsc errors
* fix: tsc errors
* fix: auto linter fixes and tsc fixes
* fix:??
* fix: revolve ast works with declaration
* fix: retry logic to make sure the disable dry run actually runs
* fix: codespell typo
---------
Co-authored-by: Kurt Hutten Irev-Dev <k.hutten@protonmail.ch>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
This commit is contained in:
107
src/lib/commandBarConfigs/validators.ts
Normal file
107
src/lib/commandBarConfigs/validators.ts
Normal file
@ -0,0 +1,107 @@
|
||||
import { Models } from '@kittycad/lib'
|
||||
import { engineCommandManager } from 'lib/singletons'
|
||||
import { uuidv4 } from 'lib/utils'
|
||||
import { CommandBarContext } from 'machines/commandBarMachine'
|
||||
import { Selections } from 'lib/selections'
|
||||
import { isSolid2D, isSegment, isSweep } from 'lang/std/artifactGraph'
|
||||
|
||||
export const disableDryRunWithRetry = async (numberOfRetries = 3) => {
|
||||
for (let tries = 0; tries < numberOfRetries; tries++) {
|
||||
try {
|
||||
await engineCommandManager.sendSceneCommand({
|
||||
type: 'modeling_cmd_req',
|
||||
cmd_id: uuidv4(),
|
||||
cmd: { type: 'disable_dry_run' },
|
||||
})
|
||||
// Exit out since the command was successful
|
||||
return
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
console.error('disable_dry_run failed. This is bad!')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Takes a callback function and wraps it around enable_dry_run and disable_dry_run
|
||||
export const dryRunWrapper = async (callback: () => Promise<any>) => {
|
||||
// Gotcha: What about race conditions?
|
||||
try {
|
||||
await engineCommandManager.sendSceneCommand({
|
||||
type: 'modeling_cmd_req',
|
||||
cmd_id: uuidv4(),
|
||||
cmd: { type: 'enable_dry_run' },
|
||||
})
|
||||
const result = await callback()
|
||||
return result
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
} finally {
|
||||
await disableDryRunWithRetry(5)
|
||||
}
|
||||
}
|
||||
|
||||
function isSelections(selections: unknown): selections is Selections {
|
||||
return (
|
||||
(selections as Selections).graphSelections !== undefined &&
|
||||
(selections as Selections).otherSelections !== undefined
|
||||
)
|
||||
}
|
||||
|
||||
export const revolveAxisValidator = async ({
|
||||
data,
|
||||
context,
|
||||
}: {
|
||||
data: { [key: string]: Selections }
|
||||
context: CommandBarContext
|
||||
}): Promise<boolean | string> => {
|
||||
if (!isSelections(context.argumentsToSubmit.selection)) {
|
||||
return 'Unable to revolve, selections are missing'
|
||||
}
|
||||
const artifact =
|
||||
context.argumentsToSubmit.selection.graphSelections[0].artifact
|
||||
|
||||
if (!artifact) {
|
||||
return 'Unable to revolve, sketch not found'
|
||||
}
|
||||
|
||||
if (!(isSolid2D(artifact) || isSegment(artifact) || isSweep(artifact))) {
|
||||
return 'Unable to revolve, sketch has no path'
|
||||
}
|
||||
|
||||
const sketchSelection = artifact.pathId
|
||||
let edgeSelection = data.axis.graphSelections[0].artifact?.id
|
||||
|
||||
if (!sketchSelection) {
|
||||
return 'Unable to revolve, sketch is missing'
|
||||
}
|
||||
|
||||
if (!edgeSelection) {
|
||||
return 'Unable to revolve, edge is missing'
|
||||
}
|
||||
|
||||
const angleInDegrees: Models['Angle_type'] = {
|
||||
unit: 'degrees',
|
||||
value: 360,
|
||||
}
|
||||
|
||||
const revolveAboutEdgeCommand = async () => {
|
||||
return await engineCommandManager.sendSceneCommand({
|
||||
type: 'modeling_cmd_req',
|
||||
cmd_id: uuidv4(),
|
||||
cmd: {
|
||||
type: 'revolve_about_edge',
|
||||
angle: angleInDegrees,
|
||||
edge_id: edgeSelection,
|
||||
target: sketchSelection,
|
||||
tolerance: 0.0001,
|
||||
},
|
||||
})
|
||||
}
|
||||
const attemptRevolve = await dryRunWrapper(revolveAboutEdgeCommand)
|
||||
if (attemptRevolve?.success) {
|
||||
return true
|
||||
} else {
|
||||
// return error message for the toast
|
||||
return 'Unable to revolve with selected axis'
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user