Add selection guard

This commit is contained in:
Pierre Jacquier
2024-11-28 16:45:41 -05:00
parent c79c02f18e
commit 9b2de237b8
4 changed files with 42 additions and 2 deletions

View File

@ -50,6 +50,7 @@ import {
isSketchPipe,
Selections,
updateSelections,
canLoftSelection,
} from 'lib/selections'
import { applyConstraintIntersect } from './Toolbar/Intersect'
import { applyConstraintAbsDistance } from './Toolbar/SetAbsDistance'
@ -569,6 +570,29 @@ export const ModelingMachineProvider = ({
if (err(canSweep)) return false
return canSweep
},
'has valid loft selection': ({ context: { selectionRanges } }) => {
console.log('selectionRanges', selectionRanges)
// A user can begin lofting if they either have 2+ faces selected or nothing selected
// TODO: this is a dummy copy from the sweep one
const hasNoSelection =
selectionRanges.graphSelections.length === 0 ||
isRangeBetweenCharacters(selectionRanges) ||
isSelectionLastLine(selectionRanges, codeManager.code)
if (hasNoSelection) {
// they have no selection, we should enable the button
// so they can select the faces through the cmdbar
// BUT only if there's extrudable geometry
return doesSceneHaveSweepableSketch(kclManager.ast)
}
// TODO: check if we need a check like this for loft
console.log('isSketchPipe(selectionRanges)', isSketchPipe(selectionRanges))
// if (!isSketchPipe(selectionRanges)) return false
const canLoft = canLoftSelection(selectionRanges)
if (err(canLoft)) return false
return canLoft
},
'has valid selection for deletion': ({
context: { selectionRanges },
}) => {