2023-10-16 21:20:05 +11:00
|
|
|
import { Models } from '@kittycad/lib'
|
2024-03-22 16:55:30 +11:00
|
|
|
import {
|
2024-04-17 20:18:07 -07:00
|
|
|
codeManager,
|
2024-03-22 16:55:30 +11:00
|
|
|
engineCommandManager,
|
|
|
|
kclManager,
|
|
|
|
sceneEntitiesManager,
|
|
|
|
} from 'lib/singletons'
|
2024-09-06 17:52:52 -04:00
|
|
|
import { CallExpression, SourceRange, Expr, parse } from 'lang/wasm'
|
2023-10-16 21:20:05 +11:00
|
|
|
import { ModelingMachineEvent } from 'machines/modelingMachine'
|
2024-04-03 19:38:16 +11:00
|
|
|
import { uuidv4 } from 'lib/utils'
|
2024-07-03 21:28:51 -07:00
|
|
|
import { EditorSelection, SelectionRange } from '@codemirror/state'
|
2024-03-22 10:23:04 +11:00
|
|
|
import { getNormalisedCoordinates, isOverlap } from 'lib/utils'
|
Command bar: add extrude command, nonlinear editing, etc (#1204)
* Tweak toaster look and feel
* Add icons, tweak plus icon names
* Rename commandBarMeta to commandBarConfig
* Refactor command bar, add support for icons
* Create a tailwind plugin for aria-pressed button state
* Remove overlay from behind command bar
* Clean up toolbar
* Button and other style tweaks
* Icon tweaks follow-up: make old icons work with new sizing
* Delete unused static icons
* More CSS tweaks
* Small CSS tweak to project sidebar
* Add command bar E2E test
* fumpt
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu)
* fix typo in a comment
* Fix icon padding (built version only)
* Update onboarding and warning banner icons padding
* Misc minor style fixes
* Get Extrude opening and canceling from command bar
* Iconography tweaks
* Get extrude kind of working
* Refactor command bar config types and organization
* Move command bar configs to be co-located with each other
* Start building a state machine for the command bar
* Start converting command bar to state machine
* Add support for multiple args, confirmation step
* Submission behavior, hotkeys, code organization
* Add new test for extruding from command bar
* Polish step back and selection hotkeys, CSS tweaks
* Loading style tweaks
* Validate selection inputs, polish UX of args re-editing
* Prevent submission with multiple selection on singlular arg
* Remove stray console logs
* Tweak test, CSS nit, remove extrude "result" argument
* Fix linting warnings
* Show Ctrl+/ instead of ⌘K on all platforms but Mac
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu)
* Add "Enter sketch" to command bar
* fix command bar test
* Fix flaky cmd bar extrude test by waiting for engine select response
* Cover both button labels '⌘K' and 'Ctrl+/' in test
---------
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2023-12-13 12:49:01 -05:00
|
|
|
import { isCursorInSketchCommandRange } from 'lang/util'
|
|
|
|
import { Program } from 'lang/wasm'
|
2024-02-19 17:23:03 +11:00
|
|
|
import {
|
|
|
|
doesPipeHaveCallExp,
|
|
|
|
getNodeFromPath,
|
2024-06-21 13:20:42 +10:00
|
|
|
hasSketchPipeBeenExtruded,
|
2024-02-19 17:23:03 +11:00
|
|
|
isSingleCursorInPipe,
|
|
|
|
} from 'lang/queryAst'
|
Command bar: add extrude command, nonlinear editing, etc (#1204)
* Tweak toaster look and feel
* Add icons, tweak plus icon names
* Rename commandBarMeta to commandBarConfig
* Refactor command bar, add support for icons
* Create a tailwind plugin for aria-pressed button state
* Remove overlay from behind command bar
* Clean up toolbar
* Button and other style tweaks
* Icon tweaks follow-up: make old icons work with new sizing
* Delete unused static icons
* More CSS tweaks
* Small CSS tweak to project sidebar
* Add command bar E2E test
* fumpt
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu)
* fix typo in a comment
* Fix icon padding (built version only)
* Update onboarding and warning banner icons padding
* Misc minor style fixes
* Get Extrude opening and canceling from command bar
* Iconography tweaks
* Get extrude kind of working
* Refactor command bar config types and organization
* Move command bar configs to be co-located with each other
* Start building a state machine for the command bar
* Start converting command bar to state machine
* Add support for multiple args, confirmation step
* Submission behavior, hotkeys, code organization
* Add new test for extruding from command bar
* Polish step back and selection hotkeys, CSS tweaks
* Loading style tweaks
* Validate selection inputs, polish UX of args re-editing
* Prevent submission with multiple selection on singlular arg
* Remove stray console logs
* Tweak test, CSS nit, remove extrude "result" argument
* Fix linting warnings
* Show Ctrl+/ instead of ⌘K on all platforms but Mac
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu)
* Add "Enter sketch" to command bar
* fix command bar test
* Fix flaky cmd bar extrude test by waiting for engine select response
* Cover both button labels '⌘K' and 'Ctrl+/' in test
---------
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2023-12-13 12:49:01 -05:00
|
|
|
import { CommandArgument } from './commandTypes'
|
2024-02-11 12:59:00 +11:00
|
|
|
import {
|
|
|
|
STRAIGHT_SEGMENT,
|
|
|
|
TANGENTIAL_ARC_TO_SEGMENT,
|
|
|
|
getParentGroup,
|
2024-03-02 19:00:24 +11:00
|
|
|
PROFILE_START,
|
2024-02-14 08:03:20 +11:00
|
|
|
} from 'clientSideScene/sceneEntities'
|
2024-03-22 10:23:04 +11:00
|
|
|
import { Mesh, Object3D, Object3DEventMap } from 'three'
|
2024-02-14 08:03:20 +11:00
|
|
|
import { AXIS_GROUP, X_AXIS } from 'clientSideScene/sceneInfra'
|
2024-05-30 13:28:29 +10:00
|
|
|
import { PathToNodeMap } from 'lang/std/sketchcombos'
|
2024-06-24 11:45:40 -04:00
|
|
|
import { err } from 'lib/trap'
|
2024-08-03 18:08:51 +10:00
|
|
|
import {
|
|
|
|
getArtifactOfTypes,
|
|
|
|
getArtifactsOfTypes,
|
|
|
|
getCapCodeRef,
|
2024-08-30 19:46:48 +10:00
|
|
|
getExtrudeEdgeCodeRef,
|
2024-08-03 18:08:51 +10:00
|
|
|
getSolid2dCodeRef,
|
|
|
|
getWallCodeRef,
|
|
|
|
} from 'lang/std/artifactGraph'
|
2023-10-16 21:20:05 +11:00
|
|
|
|
2023-12-01 20:18:51 +11:00
|
|
|
export const X_AXIS_UUID = 'ad792545-7fd3-482a-a602-a93924e3055b'
|
|
|
|
export const Y_AXIS_UUID = '680fd157-266f-4b8a-984f-cdf46b8bdf01'
|
|
|
|
|
2023-10-16 21:20:05 +11:00
|
|
|
export type Axis = 'y-axis' | 'x-axis' | 'z-axis'
|
|
|
|
|
|
|
|
export type Selection = {
|
|
|
|
type:
|
|
|
|
| 'default'
|
|
|
|
| 'line-end'
|
|
|
|
| 'line-mid'
|
2024-03-22 10:23:04 +11:00
|
|
|
| 'extrude-wall'
|
2024-08-03 18:08:51 +10:00
|
|
|
| 'solid2D'
|
2024-03-22 10:23:04 +11:00
|
|
|
| 'start-cap'
|
|
|
|
| 'end-cap'
|
2023-10-16 21:20:05 +11:00
|
|
|
| 'point'
|
|
|
|
| 'edge'
|
|
|
|
| 'line'
|
|
|
|
| 'arc'
|
|
|
|
| 'all'
|
|
|
|
range: SourceRange
|
|
|
|
}
|
|
|
|
export type Selections = {
|
|
|
|
otherSelections: Axis[]
|
|
|
|
codeBasedSelections: Selection[]
|
|
|
|
}
|
|
|
|
|
2024-08-03 18:08:51 +10:00
|
|
|
export async function getEventForSelectWithPoint({
|
|
|
|
data,
|
|
|
|
}: Extract<
|
|
|
|
Models['OkModelingCmdResponse_type'],
|
|
|
|
{ type: 'select_with_point' }
|
|
|
|
>): Promise<ModelingMachineEvent | null> {
|
2023-10-16 21:20:05 +11:00
|
|
|
if (!data?.entity_id) {
|
|
|
|
return {
|
|
|
|
type: 'Set selection',
|
|
|
|
data: { selectionType: 'singleCodeCursor' },
|
|
|
|
}
|
|
|
|
}
|
2023-12-01 20:18:51 +11:00
|
|
|
if ([X_AXIS_UUID, Y_AXIS_UUID].includes(data.entity_id)) {
|
|
|
|
return {
|
|
|
|
type: 'Set selection',
|
|
|
|
data: {
|
|
|
|
selectionType: 'otherSelection',
|
|
|
|
selection: X_AXIS_UUID === data.entity_id ? 'x-axis' : 'y-axis',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
2024-08-03 18:08:51 +10:00
|
|
|
let _artifact = engineCommandManager.artifactGraph.get(data.entity_id)
|
|
|
|
if (!_artifact)
|
|
|
|
return {
|
|
|
|
type: 'Set selection',
|
|
|
|
data: { selectionType: 'singleCodeCursor' },
|
|
|
|
}
|
|
|
|
if (_artifact.type === 'solid2D') {
|
|
|
|
const codeRef = getSolid2dCodeRef(
|
|
|
|
_artifact,
|
|
|
|
engineCommandManager.artifactGraph
|
|
|
|
)
|
|
|
|
if (err(codeRef)) return null
|
|
|
|
return {
|
|
|
|
type: 'Set selection',
|
|
|
|
data: {
|
|
|
|
selectionType: 'singleCodeCursor',
|
|
|
|
selection: { range: codeRef.range, type: 'solid2D' },
|
2024-07-23 17:13:23 +10:00
|
|
|
},
|
2024-05-21 05:55:34 +10:00
|
|
|
}
|
|
|
|
}
|
2024-08-03 18:08:51 +10:00
|
|
|
if (_artifact.type === 'cap') {
|
|
|
|
const codeRef = getCapCodeRef(_artifact, engineCommandManager.artifactGraph)
|
|
|
|
if (err(codeRef)) return null
|
|
|
|
return {
|
|
|
|
type: 'Set selection',
|
|
|
|
data: {
|
|
|
|
selectionType: 'singleCodeCursor',
|
|
|
|
selection: {
|
|
|
|
range: codeRef.range,
|
|
|
|
type: _artifact?.subType === 'end' ? 'end-cap' : 'start-cap',
|
2024-03-22 10:23:04 +11:00
|
|
|
},
|
2024-08-03 18:08:51 +10:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (_artifact.type === 'wall') {
|
|
|
|
const codeRef = getWallCodeRef(
|
|
|
|
_artifact,
|
|
|
|
engineCommandManager.artifactGraph
|
|
|
|
)
|
|
|
|
if (err(codeRef)) return null
|
2023-10-16 21:20:05 +11:00
|
|
|
return {
|
|
|
|
type: 'Set selection',
|
|
|
|
data: {
|
|
|
|
selectionType: 'singleCodeCursor',
|
2024-08-03 18:08:51 +10:00
|
|
|
selection: { range: codeRef.range, type: 'extrude-wall' },
|
2023-10-16 21:20:05 +11:00
|
|
|
},
|
|
|
|
}
|
2024-08-03 18:08:51 +10:00
|
|
|
}
|
|
|
|
if (_artifact.type === 'segment' || _artifact.type === 'path') {
|
2024-03-22 10:23:04 +11:00
|
|
|
return {
|
|
|
|
type: 'Set selection',
|
2024-08-03 18:08:51 +10:00
|
|
|
data: {
|
|
|
|
selectionType: 'singleCodeCursor',
|
|
|
|
selection: { range: _artifact.codeRef.range, type: 'default' },
|
|
|
|
},
|
2024-03-22 10:23:04 +11:00
|
|
|
}
|
2023-10-16 21:20:05 +11:00
|
|
|
}
|
2024-08-30 19:46:48 +10:00
|
|
|
if (_artifact.type === 'extrudeEdge') {
|
|
|
|
const codeRef = getExtrudeEdgeCodeRef(
|
|
|
|
_artifact,
|
|
|
|
engineCommandManager.artifactGraph
|
|
|
|
)
|
|
|
|
if (err(codeRef)) return null
|
|
|
|
return {
|
|
|
|
type: 'Set selection',
|
|
|
|
data: {
|
|
|
|
selectionType: 'singleCodeCursor',
|
|
|
|
selection: { range: codeRef.range, type: 'edge' },
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
2024-08-03 18:08:51 +10:00
|
|
|
return null
|
2023-10-16 21:20:05 +11:00
|
|
|
}
|
|
|
|
|
2024-02-11 12:59:00 +11:00
|
|
|
export function getEventForSegmentSelection(
|
2024-03-22 10:23:04 +11:00
|
|
|
obj: Object3D<Object3DEventMap>
|
2024-02-11 12:59:00 +11:00
|
|
|
): ModelingMachineEvent | null {
|
2024-03-02 19:00:24 +11:00
|
|
|
const group = getParentGroup(obj, [
|
|
|
|
STRAIGHT_SEGMENT,
|
|
|
|
TANGENTIAL_ARC_TO_SEGMENT,
|
|
|
|
PROFILE_START,
|
|
|
|
])
|
2024-02-11 12:59:00 +11:00
|
|
|
const axisGroup = getParentGroup(obj, [AXIS_GROUP])
|
|
|
|
if (!group && !axisGroup) return null
|
|
|
|
if (axisGroup?.userData.type === AXIS_GROUP) {
|
|
|
|
return {
|
|
|
|
type: 'Set selection',
|
|
|
|
data: {
|
|
|
|
selectionType: 'otherSelection',
|
|
|
|
selection: obj?.userData?.type === X_AXIS ? 'x-axis' : 'y-axis',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const pathToNode = group?.userData?.pathToNode
|
|
|
|
if (!pathToNode) return null
|
|
|
|
// previous drags don't update ast for efficiency reasons
|
|
|
|
// So we want to make sure we have and updated ast with
|
|
|
|
// accurate source ranges
|
2024-04-17 20:18:07 -07:00
|
|
|
const updatedAst = parse(codeManager.code)
|
2024-06-24 11:45:40 -04:00
|
|
|
if (err(updatedAst)) return null
|
|
|
|
|
|
|
|
const nodeMeta = getNodeFromPath<CallExpression>(
|
2024-02-11 12:59:00 +11:00
|
|
|
updatedAst,
|
|
|
|
pathToNode,
|
|
|
|
'CallExpression'
|
2024-06-24 11:45:40 -04:00
|
|
|
)
|
|
|
|
if (err(nodeMeta)) return null
|
|
|
|
|
|
|
|
const node = nodeMeta.node
|
2024-02-11 12:59:00 +11:00
|
|
|
const range: SourceRange = [node.start, node.end]
|
|
|
|
return {
|
|
|
|
type: 'Set selection',
|
|
|
|
data: {
|
|
|
|
selectionType: 'singleCodeCursor',
|
|
|
|
selection: { range, type: 'default' },
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-16 21:20:05 +11:00
|
|
|
export function handleSelectionBatch({
|
|
|
|
selections,
|
|
|
|
}: {
|
|
|
|
selections: Selections
|
|
|
|
}): {
|
2024-03-22 10:23:04 +11:00
|
|
|
engineEvents: Models['WebSocketRequest_type'][]
|
|
|
|
codeMirrorSelection: EditorSelection
|
2023-12-01 20:18:51 +11:00
|
|
|
otherSelections: Axis[]
|
2024-03-22 10:23:04 +11:00
|
|
|
updateSceneObjectColors: () => void
|
2023-10-16 21:20:05 +11:00
|
|
|
} {
|
|
|
|
const ranges: ReturnType<typeof EditorSelection.cursor>[] = []
|
2024-03-22 10:23:04 +11:00
|
|
|
const engineEvents: Models['WebSocketRequest_type'][] =
|
|
|
|
resetAndSetEngineEntitySelectionCmds(
|
|
|
|
codeToIdSelections(selections.codeBasedSelections)
|
|
|
|
)
|
2023-10-16 21:20:05 +11:00
|
|
|
selections.codeBasedSelections.forEach(({ range, type }) => {
|
|
|
|
if (range?.[1]) {
|
|
|
|
ranges.push(EditorSelection.cursor(range[1]))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
if (ranges.length)
|
|
|
|
return {
|
2024-03-22 10:23:04 +11:00
|
|
|
engineEvents,
|
2023-10-16 21:20:05 +11:00
|
|
|
codeMirrorSelection: EditorSelection.create(
|
|
|
|
ranges,
|
|
|
|
selections.codeBasedSelections.length - 1
|
|
|
|
),
|
2023-12-01 20:18:51 +11:00
|
|
|
otherSelections: selections.otherSelections,
|
2024-03-22 10:23:04 +11:00
|
|
|
updateSceneObjectColors: () =>
|
|
|
|
updateSceneObjectColors(selections.codeBasedSelections),
|
2023-10-16 21:20:05 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
2024-03-22 10:23:04 +11:00
|
|
|
codeMirrorSelection: EditorSelection.create(
|
2024-04-17 20:18:07 -07:00
|
|
|
[EditorSelection.cursor(codeManager.code.length)],
|
2024-03-22 10:23:04 +11:00
|
|
|
0
|
|
|
|
),
|
|
|
|
engineEvents,
|
2023-12-01 20:18:51 +11:00
|
|
|
otherSelections: selections.otherSelections,
|
2024-03-22 10:23:04 +11:00
|
|
|
updateSceneObjectColors: () =>
|
|
|
|
updateSceneObjectColors(selections.codeBasedSelections),
|
2023-10-16 21:20:05 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type SelectionToEngine = { type: Selection['type']; id: string }
|
|
|
|
|
|
|
|
export function processCodeMirrorRanges({
|
|
|
|
codeMirrorRanges,
|
|
|
|
selectionRanges,
|
2023-12-01 20:18:51 +11:00
|
|
|
isShiftDown,
|
2023-10-16 21:20:05 +11:00
|
|
|
}: {
|
|
|
|
codeMirrorRanges: readonly SelectionRange[]
|
|
|
|
selectionRanges: Selections
|
2023-12-01 20:18:51 +11:00
|
|
|
isShiftDown: boolean
|
2023-10-16 21:20:05 +11:00
|
|
|
}): null | {
|
|
|
|
modelingEvent: ModelingMachineEvent
|
|
|
|
engineEvents: Models['WebSocketRequest_type'][]
|
|
|
|
} {
|
|
|
|
const isChange =
|
|
|
|
codeMirrorRanges.length !== selectionRanges.codeBasedSelections.length ||
|
|
|
|
codeMirrorRanges.some(({ from, to }, i) => {
|
|
|
|
return (
|
|
|
|
from !== selectionRanges.codeBasedSelections[i].range[0] ||
|
|
|
|
to !== selectionRanges.codeBasedSelections[i].range[1]
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
if (!isChange) return null
|
|
|
|
const codeBasedSelections: Selections['codeBasedSelections'] =
|
|
|
|
codeMirrorRanges.map(({ from, to }) => {
|
|
|
|
return {
|
|
|
|
type: 'default',
|
|
|
|
range: [from, to],
|
|
|
|
}
|
|
|
|
})
|
2024-03-22 10:23:04 +11:00
|
|
|
const idBasedSelections: SelectionToEngine[] =
|
|
|
|
codeToIdSelections(codeBasedSelections)
|
2023-10-16 21:20:05 +11:00
|
|
|
|
|
|
|
if (!selectionRanges) return null
|
2024-02-11 12:59:00 +11:00
|
|
|
updateSceneObjectColors(codeBasedSelections)
|
2023-10-16 21:20:05 +11:00
|
|
|
return {
|
|
|
|
modelingEvent: {
|
|
|
|
type: 'Set selection',
|
|
|
|
data: {
|
|
|
|
selectionType: 'mirrorCodeMirrorSelections',
|
|
|
|
selection: {
|
2023-12-01 20:18:51 +11:00
|
|
|
otherSelections: isShiftDown ? selectionRanges.otherSelections : [],
|
2023-10-16 21:20:05 +11:00
|
|
|
codeBasedSelections,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
engineEvents: resetAndSetEngineEntitySelectionCmds(idBasedSelections),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-24 11:45:40 -04:00
|
|
|
function updateSceneObjectColors(codeBasedSelections: Selection[]) {
|
2024-09-06 17:52:52 -04:00
|
|
|
const updated = kclManager.ast
|
2024-06-24 11:45:40 -04:00
|
|
|
|
2024-02-14 08:03:20 +11:00
|
|
|
Object.values(sceneEntitiesManager.activeSegments).forEach((segmentGroup) => {
|
2024-02-11 12:59:00 +11:00
|
|
|
if (
|
2024-03-02 19:00:24 +11:00
|
|
|
![STRAIGHT_SEGMENT, TANGENTIAL_ARC_TO_SEGMENT, PROFILE_START].includes(
|
|
|
|
segmentGroup?.name
|
2024-02-11 12:59:00 +11:00
|
|
|
)
|
|
|
|
)
|
|
|
|
return
|
2024-06-24 11:45:40 -04:00
|
|
|
const nodeMeta = getNodeFromPath<CallExpression>(
|
2024-02-11 12:59:00 +11:00
|
|
|
updated,
|
|
|
|
segmentGroup.userData.pathToNode,
|
|
|
|
'CallExpression'
|
2024-06-24 11:45:40 -04:00
|
|
|
)
|
|
|
|
if (err(nodeMeta)) return
|
|
|
|
const node = nodeMeta.node
|
2024-02-11 12:59:00 +11:00
|
|
|
const groupHasCursor = codeBasedSelections.some((selection) => {
|
|
|
|
return isOverlap(selection.range, [node.start, node.end])
|
|
|
|
})
|
2024-06-22 04:49:31 -04:00
|
|
|
|
2024-03-04 14:18:08 +11:00
|
|
|
const color = groupHasCursor
|
|
|
|
? 0x0000ff
|
|
|
|
: segmentGroup?.userData?.baseColor || 0xffffff
|
2024-02-11 12:59:00 +11:00
|
|
|
segmentGroup.traverse(
|
|
|
|
(child) => child instanceof Mesh && child.material.color.set(color)
|
|
|
|
)
|
|
|
|
// TODO if we had access to the xstate context and therefore selections
|
|
|
|
// we wouldn't need to set this here,
|
|
|
|
// it would be better to treat xstate context as the source of truth instead of having
|
|
|
|
// extra redundant state floating around
|
|
|
|
segmentGroup.userData.isSelected = groupHasCursor
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-12-01 20:18:51 +11:00
|
|
|
function resetAndSetEngineEntitySelectionCmds(
|
2023-10-16 21:20:05 +11:00
|
|
|
selections: SelectionToEngine[]
|
|
|
|
): Models['WebSocketRequest_type'][] {
|
|
|
|
if (!engineCommandManager.engineConnection?.isReady()) {
|
|
|
|
return []
|
|
|
|
}
|
|
|
|
return [
|
|
|
|
{
|
|
|
|
type: 'modeling_cmd_req',
|
|
|
|
cmd: {
|
|
|
|
type: 'select_clear',
|
|
|
|
},
|
|
|
|
cmd_id: uuidv4(),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'modeling_cmd_req',
|
|
|
|
cmd: {
|
|
|
|
type: 'select_add',
|
|
|
|
entities: selections.map(({ id }) => id),
|
|
|
|
},
|
|
|
|
cmd_id: uuidv4(),
|
|
|
|
},
|
|
|
|
]
|
|
|
|
}
|
Command bar: add extrude command, nonlinear editing, etc (#1204)
* Tweak toaster look and feel
* Add icons, tweak plus icon names
* Rename commandBarMeta to commandBarConfig
* Refactor command bar, add support for icons
* Create a tailwind plugin for aria-pressed button state
* Remove overlay from behind command bar
* Clean up toolbar
* Button and other style tweaks
* Icon tweaks follow-up: make old icons work with new sizing
* Delete unused static icons
* More CSS tweaks
* Small CSS tweak to project sidebar
* Add command bar E2E test
* fumpt
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu)
* fix typo in a comment
* Fix icon padding (built version only)
* Update onboarding and warning banner icons padding
* Misc minor style fixes
* Get Extrude opening and canceling from command bar
* Iconography tweaks
* Get extrude kind of working
* Refactor command bar config types and organization
* Move command bar configs to be co-located with each other
* Start building a state machine for the command bar
* Start converting command bar to state machine
* Add support for multiple args, confirmation step
* Submission behavior, hotkeys, code organization
* Add new test for extruding from command bar
* Polish step back and selection hotkeys, CSS tweaks
* Loading style tweaks
* Validate selection inputs, polish UX of args re-editing
* Prevent submission with multiple selection on singlular arg
* Remove stray console logs
* Tweak test, CSS nit, remove extrude "result" argument
* Fix linting warnings
* Show Ctrl+/ instead of ⌘K on all platforms but Mac
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu)
* Add "Enter sketch" to command bar
* fix command bar test
* Fix flaky cmd bar extrude test by waiting for engine select response
* Cover both button labels '⌘K' and 'Ctrl+/' in test
---------
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2023-12-13 12:49:01 -05:00
|
|
|
|
|
|
|
export function isSketchPipe(selectionRanges: Selections) {
|
2024-02-19 17:23:03 +11:00
|
|
|
if (!isSingleCursorInPipe(selectionRanges, kclManager.ast)) return false
|
Command bar: add extrude command, nonlinear editing, etc (#1204)
* Tweak toaster look and feel
* Add icons, tweak plus icon names
* Rename commandBarMeta to commandBarConfig
* Refactor command bar, add support for icons
* Create a tailwind plugin for aria-pressed button state
* Remove overlay from behind command bar
* Clean up toolbar
* Button and other style tweaks
* Icon tweaks follow-up: make old icons work with new sizing
* Delete unused static icons
* More CSS tweaks
* Small CSS tweak to project sidebar
* Add command bar E2E test
* fumpt
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu)
* fix typo in a comment
* Fix icon padding (built version only)
* Update onboarding and warning banner icons padding
* Misc minor style fixes
* Get Extrude opening and canceling from command bar
* Iconography tweaks
* Get extrude kind of working
* Refactor command bar config types and organization
* Move command bar configs to be co-located with each other
* Start building a state machine for the command bar
* Start converting command bar to state machine
* Add support for multiple args, confirmation step
* Submission behavior, hotkeys, code organization
* Add new test for extruding from command bar
* Polish step back and selection hotkeys, CSS tweaks
* Loading style tweaks
* Validate selection inputs, polish UX of args re-editing
* Prevent submission with multiple selection on singlular arg
* Remove stray console logs
* Tweak test, CSS nit, remove extrude "result" argument
* Fix linting warnings
* Show Ctrl+/ instead of ⌘K on all platforms but Mac
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu)
* Add "Enter sketch" to command bar
* fix command bar test
* Fix flaky cmd bar extrude test by waiting for engine select response
* Cover both button labels '⌘K' and 'Ctrl+/' in test
---------
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2023-12-13 12:49:01 -05:00
|
|
|
return isCursorInSketchCommandRange(
|
2024-08-03 18:08:51 +10:00
|
|
|
engineCommandManager.artifactGraph,
|
Command bar: add extrude command, nonlinear editing, etc (#1204)
* Tweak toaster look and feel
* Add icons, tweak plus icon names
* Rename commandBarMeta to commandBarConfig
* Refactor command bar, add support for icons
* Create a tailwind plugin for aria-pressed button state
* Remove overlay from behind command bar
* Clean up toolbar
* Button and other style tweaks
* Icon tweaks follow-up: make old icons work with new sizing
* Delete unused static icons
* More CSS tweaks
* Small CSS tweak to project sidebar
* Add command bar E2E test
* fumpt
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu)
* fix typo in a comment
* Fix icon padding (built version only)
* Update onboarding and warning banner icons padding
* Misc minor style fixes
* Get Extrude opening and canceling from command bar
* Iconography tweaks
* Get extrude kind of working
* Refactor command bar config types and organization
* Move command bar configs to be co-located with each other
* Start building a state machine for the command bar
* Start converting command bar to state machine
* Add support for multiple args, confirmation step
* Submission behavior, hotkeys, code organization
* Add new test for extruding from command bar
* Polish step back and selection hotkeys, CSS tweaks
* Loading style tweaks
* Validate selection inputs, polish UX of args re-editing
* Prevent submission with multiple selection on singlular arg
* Remove stray console logs
* Tweak test, CSS nit, remove extrude "result" argument
* Fix linting warnings
* Show Ctrl+/ instead of ⌘K on all platforms but Mac
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu)
* Add "Enter sketch" to command bar
* fix command bar test
* Fix flaky cmd bar extrude test by waiting for engine select response
* Cover both button labels '⌘K' and 'Ctrl+/' in test
---------
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2023-12-13 12:49:01 -05:00
|
|
|
selectionRanges
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export function isSelectionLastLine(
|
|
|
|
selectionRanges: Selections,
|
|
|
|
code: string,
|
|
|
|
i = 0
|
|
|
|
) {
|
|
|
|
return selectionRanges.codeBasedSelections[i].range[1] === code.length
|
|
|
|
}
|
|
|
|
|
2024-07-10 10:08:15 -04:00
|
|
|
export function isRangeInbetweenCharacters(selectionRanges: Selections) {
|
|
|
|
return (
|
|
|
|
selectionRanges.codeBasedSelections.length === 1 &&
|
|
|
|
selectionRanges.codeBasedSelections[0].range[0] === 0 &&
|
|
|
|
selectionRanges.codeBasedSelections[0].range[1] === 0
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
Command bar: add extrude command, nonlinear editing, etc (#1204)
* Tweak toaster look and feel
* Add icons, tweak plus icon names
* Rename commandBarMeta to commandBarConfig
* Refactor command bar, add support for icons
* Create a tailwind plugin for aria-pressed button state
* Remove overlay from behind command bar
* Clean up toolbar
* Button and other style tweaks
* Icon tweaks follow-up: make old icons work with new sizing
* Delete unused static icons
* More CSS tweaks
* Small CSS tweak to project sidebar
* Add command bar E2E test
* fumpt
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu)
* fix typo in a comment
* Fix icon padding (built version only)
* Update onboarding and warning banner icons padding
* Misc minor style fixes
* Get Extrude opening and canceling from command bar
* Iconography tweaks
* Get extrude kind of working
* Refactor command bar config types and organization
* Move command bar configs to be co-located with each other
* Start building a state machine for the command bar
* Start converting command bar to state machine
* Add support for multiple args, confirmation step
* Submission behavior, hotkeys, code organization
* Add new test for extruding from command bar
* Polish step back and selection hotkeys, CSS tweaks
* Loading style tweaks
* Validate selection inputs, polish UX of args re-editing
* Prevent submission with multiple selection on singlular arg
* Remove stray console logs
* Tweak test, CSS nit, remove extrude "result" argument
* Fix linting warnings
* Show Ctrl+/ instead of ⌘K on all platforms but Mac
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu)
* Add "Enter sketch" to command bar
* fix command bar test
* Fix flaky cmd bar extrude test by waiting for engine select response
* Cover both button labels '⌘K' and 'Ctrl+/' in test
---------
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2023-12-13 12:49:01 -05:00
|
|
|
export type CommonASTNode = {
|
|
|
|
selection: Selection
|
|
|
|
ast: Program
|
|
|
|
}
|
|
|
|
|
2024-03-22 10:23:04 +11:00
|
|
|
function buildCommonNodeFromSelection(selectionRanges: Selections, i: number) {
|
Command bar: add extrude command, nonlinear editing, etc (#1204)
* Tweak toaster look and feel
* Add icons, tweak plus icon names
* Rename commandBarMeta to commandBarConfig
* Refactor command bar, add support for icons
* Create a tailwind plugin for aria-pressed button state
* Remove overlay from behind command bar
* Clean up toolbar
* Button and other style tweaks
* Icon tweaks follow-up: make old icons work with new sizing
* Delete unused static icons
* More CSS tweaks
* Small CSS tweak to project sidebar
* Add command bar E2E test
* fumpt
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu)
* fix typo in a comment
* Fix icon padding (built version only)
* Update onboarding and warning banner icons padding
* Misc minor style fixes
* Get Extrude opening and canceling from command bar
* Iconography tweaks
* Get extrude kind of working
* Refactor command bar config types and organization
* Move command bar configs to be co-located with each other
* Start building a state machine for the command bar
* Start converting command bar to state machine
* Add support for multiple args, confirmation step
* Submission behavior, hotkeys, code organization
* Add new test for extruding from command bar
* Polish step back and selection hotkeys, CSS tweaks
* Loading style tweaks
* Validate selection inputs, polish UX of args re-editing
* Prevent submission with multiple selection on singlular arg
* Remove stray console logs
* Tweak test, CSS nit, remove extrude "result" argument
* Fix linting warnings
* Show Ctrl+/ instead of ⌘K on all platforms but Mac
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu)
* Add "Enter sketch" to command bar
* fix command bar test
* Fix flaky cmd bar extrude test by waiting for engine select response
* Cover both button labels '⌘K' and 'Ctrl+/' in test
---------
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2023-12-13 12:49:01 -05:00
|
|
|
return {
|
|
|
|
selection: selectionRanges.codeBasedSelections[i],
|
|
|
|
ast: kclManager.ast,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-22 10:23:04 +11:00
|
|
|
function nodeHasExtrude(node: CommonASTNode) {
|
Command bar: add extrude command, nonlinear editing, etc (#1204)
* Tweak toaster look and feel
* Add icons, tweak plus icon names
* Rename commandBarMeta to commandBarConfig
* Refactor command bar, add support for icons
* Create a tailwind plugin for aria-pressed button state
* Remove overlay from behind command bar
* Clean up toolbar
* Button and other style tweaks
* Icon tweaks follow-up: make old icons work with new sizing
* Delete unused static icons
* More CSS tweaks
* Small CSS tweak to project sidebar
* Add command bar E2E test
* fumpt
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu)
* fix typo in a comment
* Fix icon padding (built version only)
* Update onboarding and warning banner icons padding
* Misc minor style fixes
* Get Extrude opening and canceling from command bar
* Iconography tweaks
* Get extrude kind of working
* Refactor command bar config types and organization
* Move command bar configs to be co-located with each other
* Start building a state machine for the command bar
* Start converting command bar to state machine
* Add support for multiple args, confirmation step
* Submission behavior, hotkeys, code organization
* Add new test for extruding from command bar
* Polish step back and selection hotkeys, CSS tweaks
* Loading style tweaks
* Validate selection inputs, polish UX of args re-editing
* Prevent submission with multiple selection on singlular arg
* Remove stray console logs
* Tweak test, CSS nit, remove extrude "result" argument
* Fix linting warnings
* Show Ctrl+/ instead of ⌘K on all platforms but Mac
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu)
* Add "Enter sketch" to command bar
* fix command bar test
* Fix flaky cmd bar extrude test by waiting for engine select response
* Cover both button labels '⌘K' and 'Ctrl+/' in test
---------
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2023-12-13 12:49:01 -05:00
|
|
|
return doesPipeHaveCallExp({
|
|
|
|
calleeName: 'extrude',
|
|
|
|
...node,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-03-22 10:23:04 +11:00
|
|
|
function nodeHasClose(node: CommonASTNode) {
|
Command bar: add extrude command, nonlinear editing, etc (#1204)
* Tweak toaster look and feel
* Add icons, tweak plus icon names
* Rename commandBarMeta to commandBarConfig
* Refactor command bar, add support for icons
* Create a tailwind plugin for aria-pressed button state
* Remove overlay from behind command bar
* Clean up toolbar
* Button and other style tweaks
* Icon tweaks follow-up: make old icons work with new sizing
* Delete unused static icons
* More CSS tweaks
* Small CSS tweak to project sidebar
* Add command bar E2E test
* fumpt
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu)
* fix typo in a comment
* Fix icon padding (built version only)
* Update onboarding and warning banner icons padding
* Misc minor style fixes
* Get Extrude opening and canceling from command bar
* Iconography tweaks
* Get extrude kind of working
* Refactor command bar config types and organization
* Move command bar configs to be co-located with each other
* Start building a state machine for the command bar
* Start converting command bar to state machine
* Add support for multiple args, confirmation step
* Submission behavior, hotkeys, code organization
* Add new test for extruding from command bar
* Polish step back and selection hotkeys, CSS tweaks
* Loading style tweaks
* Validate selection inputs, polish UX of args re-editing
* Prevent submission with multiple selection on singlular arg
* Remove stray console logs
* Tweak test, CSS nit, remove extrude "result" argument
* Fix linting warnings
* Show Ctrl+/ instead of ⌘K on all platforms but Mac
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu)
* Add "Enter sketch" to command bar
* fix command bar test
* Fix flaky cmd bar extrude test by waiting for engine select response
* Cover both button labels '⌘K' and 'Ctrl+/' in test
---------
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2023-12-13 12:49:01 -05:00
|
|
|
return doesPipeHaveCallExp({
|
|
|
|
calleeName: 'close',
|
|
|
|
...node,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
export function canExtrudeSelection(selection: Selections) {
|
|
|
|
const commonNodes = selection.codeBasedSelections.map((_, i) =>
|
|
|
|
buildCommonNodeFromSelection(selection, i)
|
|
|
|
)
|
|
|
|
return (
|
|
|
|
!!isSketchPipe(selection) &&
|
2024-06-21 13:20:42 +10:00
|
|
|
commonNodes.every((n) => !hasSketchPipeBeenExtruded(n.selection, n.ast)) &&
|
Command bar: add extrude command, nonlinear editing, etc (#1204)
* Tweak toaster look and feel
* Add icons, tweak plus icon names
* Rename commandBarMeta to commandBarConfig
* Refactor command bar, add support for icons
* Create a tailwind plugin for aria-pressed button state
* Remove overlay from behind command bar
* Clean up toolbar
* Button and other style tweaks
* Icon tweaks follow-up: make old icons work with new sizing
* Delete unused static icons
* More CSS tweaks
* Small CSS tweak to project sidebar
* Add command bar E2E test
* fumpt
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu)
* fix typo in a comment
* Fix icon padding (built version only)
* Update onboarding and warning banner icons padding
* Misc minor style fixes
* Get Extrude opening and canceling from command bar
* Iconography tweaks
* Get extrude kind of working
* Refactor command bar config types and organization
* Move command bar configs to be co-located with each other
* Start building a state machine for the command bar
* Start converting command bar to state machine
* Add support for multiple args, confirmation step
* Submission behavior, hotkeys, code organization
* Add new test for extruding from command bar
* Polish step back and selection hotkeys, CSS tweaks
* Loading style tweaks
* Validate selection inputs, polish UX of args re-editing
* Prevent submission with multiple selection on singlular arg
* Remove stray console logs
* Tweak test, CSS nit, remove extrude "result" argument
* Fix linting warnings
* Show Ctrl+/ instead of ⌘K on all platforms but Mac
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu)
* Add "Enter sketch" to command bar
* fix command bar test
* Fix flaky cmd bar extrude test by waiting for engine select response
* Cover both button labels '⌘K' and 'Ctrl+/' in test
---------
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2023-12-13 12:49:01 -05:00
|
|
|
commonNodes.every((n) => nodeHasClose(n)) &&
|
|
|
|
commonNodes.every((n) => !nodeHasExtrude(n))
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2024-07-15 19:20:32 +10:00
|
|
|
export function canFilletSelection(selection: Selections) {
|
|
|
|
const commonNodes = selection.codeBasedSelections.map((_, i) =>
|
|
|
|
buildCommonNodeFromSelection(selection, i)
|
|
|
|
) // TODO FILLET DUMMY PLACEHOLDER
|
|
|
|
return (
|
|
|
|
!!isSketchPipe(selection) &&
|
|
|
|
commonNodes.every((n) => nodeHasClose(n)) &&
|
|
|
|
commonNodes.every((n) => !nodeHasExtrude(n))
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2024-03-22 10:23:04 +11:00
|
|
|
function canExtrudeSelectionItem(selection: Selections, i: number) {
|
Command bar: add extrude command, nonlinear editing, etc (#1204)
* Tweak toaster look and feel
* Add icons, tweak plus icon names
* Rename commandBarMeta to commandBarConfig
* Refactor command bar, add support for icons
* Create a tailwind plugin for aria-pressed button state
* Remove overlay from behind command bar
* Clean up toolbar
* Button and other style tweaks
* Icon tweaks follow-up: make old icons work with new sizing
* Delete unused static icons
* More CSS tweaks
* Small CSS tweak to project sidebar
* Add command bar E2E test
* fumpt
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu)
* fix typo in a comment
* Fix icon padding (built version only)
* Update onboarding and warning banner icons padding
* Misc minor style fixes
* Get Extrude opening and canceling from command bar
* Iconography tweaks
* Get extrude kind of working
* Refactor command bar config types and organization
* Move command bar configs to be co-located with each other
* Start building a state machine for the command bar
* Start converting command bar to state machine
* Add support for multiple args, confirmation step
* Submission behavior, hotkeys, code organization
* Add new test for extruding from command bar
* Polish step back and selection hotkeys, CSS tweaks
* Loading style tweaks
* Validate selection inputs, polish UX of args re-editing
* Prevent submission with multiple selection on singlular arg
* Remove stray console logs
* Tweak test, CSS nit, remove extrude "result" argument
* Fix linting warnings
* Show Ctrl+/ instead of ⌘K on all platforms but Mac
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu)
* Add "Enter sketch" to command bar
* fix command bar test
* Fix flaky cmd bar extrude test by waiting for engine select response
* Cover both button labels '⌘K' and 'Ctrl+/' in test
---------
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2023-12-13 12:49:01 -05:00
|
|
|
const commonNode = buildCommonNodeFromSelection(selection, i)
|
|
|
|
|
|
|
|
return (
|
|
|
|
!!isSketchPipe(selection) &&
|
|
|
|
nodeHasClose(commonNode) &&
|
|
|
|
!nodeHasExtrude(commonNode)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// This accounts for non-geometry selections under "other"
|
|
|
|
export type ResolvedSelectionType = [Selection['type'] | 'other', number]
|
|
|
|
|
|
|
|
/**
|
|
|
|
* In the future, I'd like this function to properly return the type of each selected entity based on
|
|
|
|
* its code source range, so that we can show something like "0 objects" or "1 face" or "1 line, 2 edges",
|
|
|
|
* and then validate the selection in CommandBarSelectionInput.tsx and show the proper label.
|
|
|
|
* @param selection
|
|
|
|
* @returns
|
|
|
|
*/
|
|
|
|
export function getSelectionType(
|
|
|
|
selection: Selections
|
|
|
|
): ResolvedSelectionType[] {
|
|
|
|
return selection.codeBasedSelections
|
|
|
|
.map((s, i) => {
|
|
|
|
if (canExtrudeSelectionItem(selection, i)) {
|
2024-03-22 10:23:04 +11:00
|
|
|
return ['extrude-wall', 1] as ResolvedSelectionType // This is implicitly determining what a face is, which is bad
|
Command bar: add extrude command, nonlinear editing, etc (#1204)
* Tweak toaster look and feel
* Add icons, tweak plus icon names
* Rename commandBarMeta to commandBarConfig
* Refactor command bar, add support for icons
* Create a tailwind plugin for aria-pressed button state
* Remove overlay from behind command bar
* Clean up toolbar
* Button and other style tweaks
* Icon tweaks follow-up: make old icons work with new sizing
* Delete unused static icons
* More CSS tweaks
* Small CSS tweak to project sidebar
* Add command bar E2E test
* fumpt
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu)
* fix typo in a comment
* Fix icon padding (built version only)
* Update onboarding and warning banner icons padding
* Misc minor style fixes
* Get Extrude opening and canceling from command bar
* Iconography tweaks
* Get extrude kind of working
* Refactor command bar config types and organization
* Move command bar configs to be co-located with each other
* Start building a state machine for the command bar
* Start converting command bar to state machine
* Add support for multiple args, confirmation step
* Submission behavior, hotkeys, code organization
* Add new test for extruding from command bar
* Polish step back and selection hotkeys, CSS tweaks
* Loading style tweaks
* Validate selection inputs, polish UX of args re-editing
* Prevent submission with multiple selection on singlular arg
* Remove stray console logs
* Tweak test, CSS nit, remove extrude "result" argument
* Fix linting warnings
* Show Ctrl+/ instead of ⌘K on all platforms but Mac
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu)
* Add "Enter sketch" to command bar
* fix command bar test
* Fix flaky cmd bar extrude test by waiting for engine select response
* Cover both button labels '⌘K' and 'Ctrl+/' in test
---------
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2023-12-13 12:49:01 -05:00
|
|
|
} else {
|
|
|
|
return ['other', 1] as ResolvedSelectionType
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.reduce((acc, [type, count]) => {
|
|
|
|
const foundIndex = acc.findIndex((item) => item && item[0] === type)
|
|
|
|
|
|
|
|
if (foundIndex === -1) {
|
|
|
|
return [...acc, [type, count]]
|
|
|
|
} else {
|
|
|
|
const temp = [...acc]
|
|
|
|
temp[foundIndex][1] += count
|
|
|
|
return temp
|
|
|
|
}
|
|
|
|
}, [] as ResolvedSelectionType[])
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getSelectionTypeDisplayText(
|
|
|
|
selection: Selections
|
|
|
|
): string | null {
|
|
|
|
const selectionsByType = getSelectionType(selection)
|
|
|
|
|
|
|
|
return (selectionsByType as Exclude<typeof selectionsByType, 'none'>)
|
2024-04-24 16:34:56 -04:00
|
|
|
.map(
|
|
|
|
// Hack for showing "face" instead of "extrude-wall" in command bar text
|
|
|
|
([type, count]) =>
|
|
|
|
`${count} ${type.replace('extrude-wall', 'face')}${
|
|
|
|
count > 1 ? 's' : ''
|
|
|
|
}`
|
|
|
|
)
|
Command bar: add extrude command, nonlinear editing, etc (#1204)
* Tweak toaster look and feel
* Add icons, tweak plus icon names
* Rename commandBarMeta to commandBarConfig
* Refactor command bar, add support for icons
* Create a tailwind plugin for aria-pressed button state
* Remove overlay from behind command bar
* Clean up toolbar
* Button and other style tweaks
* Icon tweaks follow-up: make old icons work with new sizing
* Delete unused static icons
* More CSS tweaks
* Small CSS tweak to project sidebar
* Add command bar E2E test
* fumpt
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu)
* fix typo in a comment
* Fix icon padding (built version only)
* Update onboarding and warning banner icons padding
* Misc minor style fixes
* Get Extrude opening and canceling from command bar
* Iconography tweaks
* Get extrude kind of working
* Refactor command bar config types and organization
* Move command bar configs to be co-located with each other
* Start building a state machine for the command bar
* Start converting command bar to state machine
* Add support for multiple args, confirmation step
* Submission behavior, hotkeys, code organization
* Add new test for extruding from command bar
* Polish step back and selection hotkeys, CSS tweaks
* Loading style tweaks
* Validate selection inputs, polish UX of args re-editing
* Prevent submission with multiple selection on singlular arg
* Remove stray console logs
* Tweak test, CSS nit, remove extrude "result" argument
* Fix linting warnings
* Show Ctrl+/ instead of ⌘K on all platforms but Mac
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu)
* Add "Enter sketch" to command bar
* fix command bar test
* Fix flaky cmd bar extrude test by waiting for engine select response
* Cover both button labels '⌘K' and 'Ctrl+/' in test
---------
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2023-12-13 12:49:01 -05:00
|
|
|
.join(', ')
|
|
|
|
}
|
|
|
|
|
|
|
|
export function canSubmitSelectionArg(
|
|
|
|
selectionsByType: 'none' | ResolvedSelectionType[],
|
|
|
|
argument: CommandArgument<unknown> & { inputType: 'selection' }
|
|
|
|
) {
|
|
|
|
return (
|
|
|
|
selectionsByType !== 'none' &&
|
|
|
|
selectionsByType.every(([type, count]) => {
|
|
|
|
const foundIndex = argument.selectionTypes.findIndex((s) => s === type)
|
|
|
|
return (
|
|
|
|
foundIndex !== -1 &&
|
|
|
|
(!argument.multiple ? count < 2 && count > 0 : count > 0)
|
|
|
|
)
|
|
|
|
})
|
|
|
|
)
|
|
|
|
}
|
2024-03-22 10:23:04 +11:00
|
|
|
|
|
|
|
function codeToIdSelections(
|
|
|
|
codeBasedSelections: Selection[]
|
|
|
|
): SelectionToEngine[] {
|
|
|
|
return codeBasedSelections
|
|
|
|
.flatMap(({ type, range, ...rest }): null | SelectionToEngine[] => {
|
|
|
|
// TODO #868: loops over all artifacts will become inefficient at a large scale
|
2024-08-03 18:08:51 +10:00
|
|
|
const overlappingEntries = Array.from(engineCommandManager.artifactGraph)
|
2024-03-22 10:23:04 +11:00
|
|
|
.map(([id, artifact]) => {
|
2024-08-03 18:08:51 +10:00
|
|
|
if (!('codeRef' in artifact)) return false
|
|
|
|
return isOverlap(artifact.codeRef.range, range)
|
2024-03-22 10:23:04 +11:00
|
|
|
? {
|
|
|
|
artifact,
|
|
|
|
selection: { type, range, ...rest },
|
|
|
|
id,
|
|
|
|
}
|
|
|
|
: false
|
|
|
|
})
|
|
|
|
.filter(Boolean)
|
2024-08-03 18:08:51 +10:00
|
|
|
|
|
|
|
/** TODO refactor
|
|
|
|
* selections in our app is a sourceRange plus some metadata
|
|
|
|
* The metadata is just a union type string of different types of artifacts or 3d features 'extrude-wall' 'segment' etc
|
|
|
|
* Because the source range is not enough to figure out what the user selected, so here we're using filtering through all the artifacts
|
|
|
|
* to find something that matches both the source range and the metadata.
|
|
|
|
*
|
|
|
|
* What we should migrate to is just storing what the user selected by what it matched in the artifactGraph it will simply the below a lot.
|
|
|
|
*
|
|
|
|
* In the case of a user moving the cursor them, we will still need to figure out what artifact from the graph matches best, but we will just need sane defaults
|
|
|
|
* and most of the time we can expect the user to be clicking in the 3d scene instead.
|
|
|
|
*/
|
2024-03-22 10:23:04 +11:00
|
|
|
let bestCandidate
|
2024-08-03 18:08:51 +10:00
|
|
|
overlappingEntries.forEach((entry) => {
|
2024-03-22 10:23:04 +11:00
|
|
|
if (!entry) return
|
2024-07-25 19:03:56 +10:00
|
|
|
if (type === 'default' && entry.artifact.type === 'segment') {
|
2024-03-22 10:23:04 +11:00
|
|
|
bestCandidate = entry
|
|
|
|
return
|
|
|
|
}
|
2024-08-03 18:08:51 +10:00
|
|
|
if (type === 'solid2D' && entry.artifact.type === 'path') {
|
|
|
|
const solid = engineCommandManager.artifactGraph.get(
|
|
|
|
entry.artifact.solid2dId || ''
|
|
|
|
)
|
|
|
|
if (solid?.type !== 'solid2D') return
|
|
|
|
bestCandidate = {
|
|
|
|
artifact: solid,
|
|
|
|
selection: { type, range, ...rest },
|
|
|
|
id: entry.artifact.solid2dId,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (type === 'extrude-wall' && entry.artifact.type === 'segment') {
|
|
|
|
const wall = engineCommandManager.artifactGraph.get(
|
|
|
|
entry.artifact.surfaceId
|
|
|
|
)
|
|
|
|
if (wall?.type !== 'wall') return
|
|
|
|
bestCandidate = {
|
|
|
|
artifact: wall,
|
|
|
|
selection: { type, range, ...rest },
|
|
|
|
id: entry.artifact.surfaceId,
|
|
|
|
}
|
2024-03-22 10:23:04 +11:00
|
|
|
return
|
|
|
|
}
|
|
|
|
if (
|
2024-08-03 18:08:51 +10:00
|
|
|
(type === 'end-cap' || type === 'start-cap') &&
|
|
|
|
entry.artifact.type === 'path'
|
2024-03-22 10:23:04 +11:00
|
|
|
) {
|
2024-08-03 18:08:51 +10:00
|
|
|
const extrusion = getArtifactOfTypes(
|
|
|
|
{
|
|
|
|
key: entry.artifact.extrusionId,
|
|
|
|
types: ['extrusion'],
|
|
|
|
},
|
|
|
|
engineCommandManager.artifactGraph
|
|
|
|
)
|
|
|
|
if (err(extrusion)) return
|
|
|
|
const caps = getArtifactsOfTypes(
|
|
|
|
{ keys: extrusion.surfaceIds, types: ['cap'] },
|
|
|
|
engineCommandManager.artifactGraph
|
|
|
|
)
|
|
|
|
const cap = [...caps].find(
|
|
|
|
([_, cap]) => cap.subType === (type === 'end-cap' ? 'end' : 'start')
|
|
|
|
)
|
|
|
|
if (!cap) return
|
|
|
|
bestCandidate = {
|
|
|
|
artifact: entry.artifact,
|
|
|
|
selection: { type, range, ...rest },
|
|
|
|
id: cap[0],
|
|
|
|
}
|
2024-03-22 10:23:04 +11:00
|
|
|
return
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
if (bestCandidate) {
|
|
|
|
const _bestCandidate = bestCandidate as {
|
|
|
|
artifact: any
|
|
|
|
selection: any
|
|
|
|
id: string
|
|
|
|
}
|
|
|
|
return [
|
|
|
|
{
|
|
|
|
type,
|
|
|
|
id: _bestCandidate.id,
|
|
|
|
},
|
|
|
|
]
|
|
|
|
}
|
|
|
|
return null
|
|
|
|
})
|
|
|
|
.filter(Boolean) as any
|
|
|
|
}
|
|
|
|
|
2024-06-18 16:08:41 +10:00
|
|
|
export async function sendSelectEventToEngine(
|
2024-03-22 10:23:04 +11:00
|
|
|
e: MouseEvent | React.MouseEvent<HTMLDivElement, MouseEvent>,
|
2024-09-12 22:06:50 -04:00
|
|
|
el: HTMLVideoElement
|
2024-03-22 10:23:04 +11:00
|
|
|
) {
|
|
|
|
const { x, y } = getNormalisedCoordinates({
|
|
|
|
clientX: e.clientX,
|
|
|
|
clientY: e.clientY,
|
|
|
|
el,
|
2024-09-12 22:06:50 -04:00
|
|
|
streamWidth: el.clientWidth,
|
|
|
|
streamHeight: el.clientHeight,
|
2024-03-22 10:23:04 +11:00
|
|
|
})
|
2024-07-23 17:13:23 +10:00
|
|
|
const res = await engineCommandManager.sendSceneCommand({
|
|
|
|
type: 'modeling_cmd_req',
|
|
|
|
cmd: {
|
|
|
|
type: 'select_with_point',
|
|
|
|
selected_at_window: { x, y },
|
|
|
|
selection_type: 'add',
|
|
|
|
},
|
|
|
|
cmd_id: uuidv4(),
|
|
|
|
})
|
|
|
|
if (
|
|
|
|
res?.success &&
|
|
|
|
res?.resp?.type === 'modeling' &&
|
|
|
|
res?.resp?.data?.modeling_response.type === 'select_with_point'
|
|
|
|
)
|
|
|
|
return res?.resp?.data?.modeling_response?.data
|
|
|
|
return { entity_id: '' }
|
2024-03-22 10:23:04 +11:00
|
|
|
}
|
2024-05-30 13:28:29 +10:00
|
|
|
|
|
|
|
export function updateSelections(
|
|
|
|
pathToNodeMap: PathToNodeMap,
|
|
|
|
prevSelectionRanges: Selections,
|
2024-06-24 11:45:40 -04:00
|
|
|
ast: Program | Error
|
|
|
|
): Selections | Error {
|
|
|
|
if (err(ast)) return ast
|
|
|
|
|
|
|
|
const newSelections = Object.entries(pathToNodeMap)
|
|
|
|
.map(([index, pathToNode]): Selection | undefined => {
|
2024-08-12 15:38:42 -05:00
|
|
|
const nodeMeta = getNodeFromPath<Expr>(ast, pathToNode)
|
2024-06-24 11:45:40 -04:00
|
|
|
if (err(nodeMeta)) return undefined
|
|
|
|
const node = nodeMeta.node
|
|
|
|
return {
|
|
|
|
range: [node.start, node.end],
|
|
|
|
type: prevSelectionRanges.codeBasedSelections[Number(index)]?.type,
|
2024-05-30 13:28:29 +10:00
|
|
|
}
|
2024-06-24 11:45:40 -04:00
|
|
|
})
|
|
|
|
.filter((x?: Selection) => x !== undefined) as Selection[]
|
|
|
|
|
|
|
|
return {
|
|
|
|
codeBasedSelections:
|
|
|
|
newSelections.length > 0
|
|
|
|
? newSelections
|
|
|
|
: prevSelectionRanges.codeBasedSelections,
|
|
|
|
otherSelections: prevSelectionRanges.otherSelections,
|
2024-05-30 13:28:29 +10:00
|
|
|
}
|
|
|
|
}
|