Add selection guard
This commit is contained in:
@ -50,6 +50,7 @@ import {
|
|||||||
isSketchPipe,
|
isSketchPipe,
|
||||||
Selections,
|
Selections,
|
||||||
updateSelections,
|
updateSelections,
|
||||||
|
canLoftSelection,
|
||||||
} from 'lib/selections'
|
} from 'lib/selections'
|
||||||
import { applyConstraintIntersect } from './Toolbar/Intersect'
|
import { applyConstraintIntersect } from './Toolbar/Intersect'
|
||||||
import { applyConstraintAbsDistance } from './Toolbar/SetAbsDistance'
|
import { applyConstraintAbsDistance } from './Toolbar/SetAbsDistance'
|
||||||
@ -569,6 +570,29 @@ export const ModelingMachineProvider = ({
|
|||||||
if (err(canSweep)) return false
|
if (err(canSweep)) return false
|
||||||
return canSweep
|
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': ({
|
'has valid selection for deletion': ({
|
||||||
context: { selectionRanges },
|
context: { selectionRanges },
|
||||||
}) => {
|
}) => {
|
||||||
|
@ -559,6 +559,21 @@ export function canSweepSelection(selection: Selections) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function canLoftSelection(selection: Selections) {
|
||||||
|
console.log('selection', selection)
|
||||||
|
const commonNodes = selection.graphSelections.map((_, i) =>
|
||||||
|
buildCommonNodeFromSelection(selection, i)
|
||||||
|
)
|
||||||
|
console.log('commonNodes', commonNodes)
|
||||||
|
return (
|
||||||
|
// !!isSketchPipe(selection) &&
|
||||||
|
commonNodes.length > 1 &&
|
||||||
|
// commonNodes.every((n) => !hasSketchPipeBeenExtruded(n.selection, n.ast)) &&
|
||||||
|
(commonNodes.every((n) => nodeHasClose(n) || nodeHasCircle(n))) &&
|
||||||
|
commonNodes.every((n) => !nodeHasExtrude(n))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
// This accounts for non-geometry selections under "other"
|
// This accounts for non-geometry selections under "other"
|
||||||
export type ResolvedSelectionType = Artifact['type'] | 'other'
|
export type ResolvedSelectionType = Artifact['type'] | 'other'
|
||||||
export type SelectionCountsByType = Map<ResolvedSelectionType, number>
|
export type SelectionCountsByType = Map<ResolvedSelectionType, number>
|
||||||
|
@ -144,7 +144,7 @@ export const toolbarConfig: Record<ToolbarModeName, ToolbarMode> = {
|
|||||||
type: 'Find and select command',
|
type: 'Find and select command',
|
||||||
data: { name: 'Loft', groupId: 'modeling' },
|
data: { name: 'Loft', groupId: 'modeling' },
|
||||||
}),
|
}),
|
||||||
disabled: (state) => !state.can({ type: 'Extrude' }),
|
disabled: (state) => !state.can({ type: 'Loft' }),
|
||||||
icon: 'loft',
|
icon: 'loft',
|
||||||
status: 'available',
|
status: 'available',
|
||||||
title: 'Loft',
|
title: 'Loft',
|
||||||
|
@ -384,6 +384,7 @@ export const modelingMachine = setup({
|
|||||||
guards: {
|
guards: {
|
||||||
'Selection is on face': () => false,
|
'Selection is on face': () => false,
|
||||||
'has valid sweep selection': () => false,
|
'has valid sweep selection': () => false,
|
||||||
|
'has valid loft selection': () => false,
|
||||||
'has valid fillet selection': () => false,
|
'has valid fillet selection': () => false,
|
||||||
'Has exportable geometry': () => false,
|
'Has exportable geometry': () => false,
|
||||||
'has valid selection for deletion': () => false,
|
'has valid selection for deletion': () => false,
|
||||||
@ -1597,7 +1598,7 @@ export const modelingMachine = setup({
|
|||||||
|
|
||||||
Loft: {
|
Loft: {
|
||||||
target: 'idle',
|
target: 'idle',
|
||||||
guard: 'has valid sweep selection',
|
guard: 'has valid loft selection',
|
||||||
actions: ['AST loft'],
|
actions: ['AST loft'],
|
||||||
reenter: false,
|
reenter: false,
|
||||||
},
|
},
|
||||||
|
Reference in New Issue
Block a user