Add TS schema, selection actions to modelingMachine

This commit is contained in:
Frank Noirot
2023-09-13 14:45:14 -04:00
parent 26737e055a
commit c33107aa28
3 changed files with 516 additions and 435 deletions

View File

@ -1,319 +1,466 @@
import { Program } from 'lang/abstractSyntaxTreeTypes'
import { ProgramMemory } from 'lang/executor'
import { Selections } from 'useStore'
import { createMachine } from 'xstate'
import { Axis, Selection, Selections } from 'useStore'
import { assign, createMachine } from 'xstate'
export const modelingMachine = createMachine({
/** @xstate-layout N4IgpgJg5mDOIC5QFkD2EwBsCWA7KAxAMICGuAxlgNoAMAuoqAA6qzYAu2qujIAHogC0AFgCMAOgCsADlHThYgGw1JAZlEB2DQBoQATyEAmRRvHTFATnnW1NK6oC+D3Wgw5847BExgCAETgsMHJ2AAIWPHZaBiQQFjZObl4BBEFVaWlxYUVFYQsLGkUZDUMaVV0DBE1TSU1JGmkS0XrhVUdnEFcsPChPb18A2CCQ0MgYaN54ji4eWJS0xrMLRWtDQ3VRdMUKxA1hcU0y0ULJYulDUScXdG6PLx8CAGVhsIjcKPpJ1mmkuaNVRRmaQWUSiYQZGiaKw7BCqDQ0LI0GglGjCGiGNQaUSKK6dG7uXr3XzPHwjMZgCaxKaJWagebrQEZEFgiFQ6Qw7L7AqSSwNRogyy4roEvoPEnBMIAMxIlEpzG+NOS-0ZwNB4OkkI0VkMMJ5+0Me3SGs2FjhkiF+J6ot8AFF3mAAE6hWAAazA7HIAAs5XEFTMlQg9uILMJJBp5KaVtJVMIYYJNplwcpzpDhIYxBp2tc3FaiQQ7exHc63R7vaIYvKEv6-oHDOIyki9ssQ9jo3HgeJ08iNDIwbVThoLTm7v18wBHACu2CYoz47AdE4wPup1bpiDWpjWFlqWkhlmWuvOWS0FkMIdUkgKqgsQ9uhNHNsn09n88XFPLXyrvzXCAuEnMqgXLI4ZWHY2z6IgiiqAipoND2ijGMIJQ3h0wq5qOgwvKE0qyp8VJ+t+-BCOkqjiDGeRarkOTrJscYXIicjGOGWrnK0t4inm4ojCQmCYMu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68zq1jIskdTRojN1BFW7htnZBN+V-MqJ5qF79x2p2MKibEyx5LvapisLQnHfsAn+-5AV-yttghcl-VVAClDc3h59pHP3VSo5izjHFeKZRgC26rMRH9wQXnSCoOMdKXIyAKNRaCF4lo9d6Bm90W2EKkVLZI8t9gpJWVOtTSwYYfOclKg5wXBq7udrB4GEaZgjS7obA4rLSlAQpOOMpsESFdXtt5SEIHgqQcSy8+D9DzSJ3olPIhB1aqzxIkkReYEZ4Lf6vEBju3hD9ppn2BqXcChIQXCRblR1dlvdqE5-74DQA */
id: 'Modeling',
export const MODELING_PERSIST_KEY = 'MODELING_PERSIST_KEY'
tsTypes: {} as import('./modelingMachine.typegen').Typegen0,
export const modelingMachine = createMachine(
{
/** @xstate-layout N4IgpgJg5mDOIC5QFkD2EwBsCWA7KAxAMICGuAxlgNoAMAuoqAA6qzYAu2qujIAHogC0AFgCMAOgBMogOwyAzAE5hNABw0ZAVlGKANCACeQyQDZh4zTMWj5GmqfnDN8gL4v9aDDnzjsETGAEAMpg7AAEsFhg5JzctAxIICxssTyJAgiimuZOkqqSMjRqipKKcvpGCIKiqibiwrVqkjSiwpJiCm4e6Fh4UL7+gQAicFExYSx47PG8yRxcaaAZgvKqivUaJquywtYyohWIojbiqqr7NZprps2u7iCevT5+AQQjkQHjkDAziXOpvGWSnkUk0JhMVkkmmkbRMmkOVWE5mkighNHk7WaZzu3S8fQGr3eY3CJD42Fgv2YrHm3EBQhkpVBpm0q2EMi2qgRImROjRGLaahkqi6Dx63n6L0CIU+4UmuGm9Fm1IB6SE8kK4hku1MilUlgh4JkCNWIJMzQhThKiiukhFj3FBKlxLC3zAlKSyoWdKq8hMqnEinRtgaohoELB8MMiE0zikpUkpnR1sDijtYvxkuCztJ5Pd-y9qqq4PWKgjZ2yUJ0COcdXRNEUvvyMYxqfu9ozgyzMrCADMSJQ857aYWVpp1udRAVA1kTMckQiGTRxGHWtaYyYaA1NGm8c9OwBReVgABOEQA1qFyAALQcpAtLRBagNOIW7Ruq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322tKsRu6nKxcnTlIDkpRJzsmTCs1JmAHFOIyfKEzoqLOZEDONQb0WRvaDdicJwEZS2Z2lrhObay0lDBRr1kZ1glynYcE0PYSD9FIkEuoNoDIk1FDO3FjrKSLsLeW1s3pEAbubVwiCVE0tVjTlMXotUB31zZDMA0U72c2uZoDgD7rRGukg5yeDgypaJBqzDGY15DYEc+iR0d1H9LfuY-EFqjARPEBmn9PkQo0qHJVWrOqe20hwZ5AxB+VruKeWup3mz1CCrxnZGcFaW21rNCBXOHZ3CawbAY4l58qX7ruBeokzL0MGotSTjNGYD88kauPhQSasMRQ0dFHVUJ5nUvSO+pN0VJzWRxLZFwgoPQyC9Rq7kFsTX1hfSCJzXm-sXn3ofv4jGKeZQ0tyXMuUReII0EMjKPyBO7ndc+AIy9GXHJ7aVZC2j-9QMnCajyPkWWUfsIQdCNLxP8nULYSIsoYLNVsLU+OMoJhlopqlqhEXjN4hS-t4N7gI3ZHKhrZ86buodMGwYjy6nIf3G71olkO0FWbf2DiE98vq2XfWhKCkDUDEWosIJlt5kPfjcD8MhUGUNwbggA */
id: 'Modeling',
context: {
guiMode: 'default',
selection: [] as string[],
ast: null as Program | null,
selectionRanges: {
otherSelections: [],
codeBasedSelections: [],
} as Selections,
programMemory: { root: {}, pendingMemory: {} } as ProgramMemory,
},
tsTypes: {} as import('./modelingMachine.typegen').Typegen0,
predictableActionArguments: true,
states: {
idle: {
on: {
'Deselect point': {
target: 'idle',
internal: true,
actions: 'Remove from selection',
cond: 'Selection contains point',
},
'Deselect edge': {
target: 'idle',
internal: true,
actions: 'Remove from selection',
cond: 'Selection contains edge',
},
'Select point': {
target: 'idle',
internal: true,
actions: 'Add to selection',
},
'Select edge': {
target: 'idle',
internal: true,
actions: 'Add to selection',
},
'Select face': {
target: 'idle',
internal: true,
actions: 'Add to selection',
},
'Enter sketch': [
{
target: 'Sketch',
cond: 'Selection is one face',
},
'Sketch no face',
],
'Equip extrude': [
{
target: 'Extrude',
cond: 'Selection is empty',
},
{
target: 'Extrude',
cond: 'Selection is one face',
},
],
'Deselect face': {
target: 'idle',
internal: true,
actions: 'Remove from selection',
cond: 'Selection contains face',
},
'Select all': {
target: 'idle',
internal: true,
actions: 'Add to selection',
},
'Deselect all': {
target: 'idle',
internal: true,
actions: 'Remove from selection',
cond: 'Selection is not empty',
},
'Equip fillet': [
{
target: 'Fillet',
cond: 'Selection is empty',
},
{
target: 'Fillet',
cond: 'Selection is one or more edges',
},
],
},
context: {
guiMode: 'default',
selection: [] as string[],
ast: null as Program | null,
selectionRanges: {
otherSelections: [],
codeBasedSelections: [],
} as Selections,
programMemory: { root: {}, pendingMemory: {} } as ProgramMemory,
// TODO: migrate engineCommandManager from useStore
// engineCommandManager?: EngineCommandManager
},
Sketch: {
states: {
Idle: {
on: {
'Equip Line Tool': 'Line Tool',
schema: {
events: {} as
| { type: 'Deselect all' }
| { type: 'Deselect edge'; data: Selection & { type: 'edge' } }
| { type: 'Deselect axis'; data: Axis }
| {
type: 'Deselect segment'
data: Selection & { type: 'line' | 'arc' }
}
| { type: 'Deselect face'; data: Selection & { type: 'face' } }
| {
type: 'Deselect point'
data: Selection & { type: 'point' | 'line-end' | 'line-mid' }
}
| { type: 'Equip extrude' }
| { type: 'Equip fillet' }
| { type: 'Enter sketch' }
| { type: 'Select all'; data: Selection & { type: 'all ' } }
| { type: 'Select edge'; data: Selection & { type: 'edge' } }
| { type: 'Select axis'; data: Axis }
| { type: 'Select segment'; data: Selection & { type: 'line' | 'arc' } }
| { type: 'Select face'; data: Selection & { type: 'face' } }
| { type: 'Set selection'; data: Selections }
| {
type: 'Select point'
data: Selection & { type: 'point' | 'line-end' | 'line-mid' }
}
| { type: 'Sketch no face' }
| { type: 'Toggle gui mode' }
| { type: 'Cancel' }
| { type: 'Add point' }
| { type: 'Equip line tool' }
| { type: 'Set radius' }
| { type: 'Make segment horizontal' }
| { type: 'Make segment vertical' }
| { type: 'Complete line' }
| { type: 'Set distance' },
},
'Select Point': {
target: 'Idle',
internal: true,
},
'Select Line': {
target: 'Idle',
internal: true,
},
'Make line horizontal': {
target: 'Idle',
internal: true,
cond: 'Can make selection horizontal',
actions: [
'Make selected line horizontal',
'Update code selection cursors',
],
},
'Deselect point': {
target: 'Idle',
internal: true,
cond: 'Selection contains point',
},
'Deselect line': {
target: 'Idle',
internal: true,
cond: 'Selection contains line',
},
'Make segment vertical': {
cond: 'Can make selection vertical',
target: 'Idle',
internal: true,
},
states: {
idle: {
on: {
'Set selection': {
target: 'idle',
internal: true,
actions: 'Set selection',
},
},
'Line Tool': {
states: {
'No Points': {
on: {
'Add Point': 'Point Added',
},
},
Done: {
type: 'final',
},
'Point Added': {
on: {
'Add Point': 'Segment Added',
},
},
'Segment Added': {
on: {
'Add Point': {
target: 'Segment Added',
internal: true,
},
'Complete Line': 'Done',
},
},
'Deselect point': {
target: 'idle',
internal: true,
actions: [
'Remove from code-based selection',
'Update code selection cursors',
// 'Engine: remove highlight',
],
cond: 'Selection contains point',
},
initial: 'No Points',
invoke: {
src: 'createLine',
id: 'Create line',
onDone: 'Idle',
onError: 'Idle',
},
},
Extrude: {
states: {
Idle: {
on: {
'Select Face': 'Selection Ready',
},
},
'Selection Ready': {
on: {
'Set Distance': 'Ready',
},
},
Ready: {},
'Deselect edge': {
target: 'idle',
internal: true,
actions: [
'Remove from code-based selection',
'Update code selection cursors',
// 'Engine: remove highlight',
],
cond: 'Selection contains edge',
},
initial: 'Idle',
'Deselect axis': {
target: 'idle',
internal: true,
actions: [
'Remove from other selection',
'Update code selection cursors',
// 'Engine: remove highlight',
],
cond: 'Selection contains axis',
},
on: {
'Equip Extrude Tool': [
{
target: '.Selection Ready',
cond: 'Selection is one face',
},
'.Idle',
'Select point': {
target: 'idle',
internal: true,
actions: [
'Add to code-based selection',
'Update code selection cursors',
// 'Engine: add highlight',
],
},
'Select edge': {
target: 'idle',
internal: true,
actions: [
'Add to code-based selection',
'Update code selection cursors',
// 'Engine: add highlight',
],
},
'Select axis': {
target: 'idle',
internal: true,
actions: [
'Add to other selection',
// 'Engine: add highlight',
],
},
'Select face': {
target: 'idle',
internal: true,
actions: [
'Add to code-based selection',
'Update code selection cursors',
// 'Engine: add highlight',
],
},
'Enter sketch': [
{
target: 'Sketch',
cond: 'Selection is one face',
},
'Sketch no face',
],
'Equip extrude': [
{
target: 'Extrude',
cond: 'Selection is empty',
},
{
target: 'Extrude',
cond: 'Selection is one face',
},
],
'Deselect face': {
target: 'idle',
internal: true,
actions: [
'Remove from code-based selection',
'Update code selection cursors',
// 'Engine: remove highlight',
],
cond: 'Selection contains face',
},
'Select all': {
target: 'idle',
internal: true,
actions: 'Add to code-based selection',
},
'Deselect all': {
target: 'idle',
internal: true,
actions: [
'Clear selection',
'Update code selection cursors',
// 'Engine: remove highlight',
],
cond: 'Selection is not empty',
},
'Equip fillet': [
{
target: 'Fillet',
cond: 'Selection is empty',
},
{
target: 'Fillet',
cond: 'Selection is one or more edges',
},
],
},
},
initial: 'Idle',
Sketch: {
states: {
Idle: {
on: {
'Equip line tool': 'Line Tool',
on: {
Cancel: '.Idle',
'Select point': {
target: 'Idle',
internal: true,
actions: [
'Update code selection cursors',
'Add to code-based selection',
],
},
'Select segment': {
target: 'Idle',
internal: true,
actions: [
'Update code selection cursors',
'Add to code-based selection',
],
},
'Deselect point': {
target: 'Idle',
internal: true,
cond: 'Selection contains point',
actions: [
'Update code selection cursors',
'Add to code-based selection',
],
},
'Deselect segment': {
target: 'Idle',
internal: true,
cond: 'Selection contains line',
actions: [
'Update code selection cursors',
'Add to code-based selection',
],
},
'Make segment vertical': {
cond: 'Can make selection vertical',
target: 'Idle',
internal: true,
actions: ['Make selection vertical'],
},
'Make segment horizontal': {
target: 'Idle',
internal: true,
cond: 'Can make selection horizontal',
actions: ['Make selection horizontal'],
},
},
},
'Line Tool': {
states: {
'No Points': {
on: {
'Add point': {
target: 'Point Added',
actions: ['Modify AST', 'Update code selection cursors'],
},
},
},
Done: {
type: 'final',
},
'Point Added': {
on: {
'Add point': {
target: 'Segment Added',
actions: ['Modify AST', 'Update code selection cursors'],
},
},
},
'Segment Added': {
on: {
'Add point': {
target: 'Segment Added',
internal: true,
actions: ['Modify AST', 'Update code selection cursors'],
},
'Complete line': {
target: 'Done',
actions: ['Modify AST', 'Update code selection cursors'],
},
},
},
},
initial: 'No Points',
invoke: {
src: 'createLine',
id: 'Create line',
onDone: 'Idle',
},
},
},
initial: 'Idle',
on: {
Cancel: '.Idle',
},
invoke: {
src: 'createSketch',
id: 'Create sketch',
onDone: 'idle',
},
},
invoke: {
src: 'createSketch',
id: 'Create sketch',
onDone: 'idle',
onError: 'idle',
Extrude: {
states: {
Idle: {
on: {
'Select face': 'Selection Ready',
},
},
'Selection Ready': {
on: {
'Set distance': 'Ready',
},
},
Ready: {},
},
initial: 'Idle',
on: {
'Equip extrude': [
{
target: '.Selection Ready',
cond: 'Selection is one face',
},
'.Idle',
],
},
invoke: {
src: 'createExtrude',
id: 'Create extrude',
onDone: {
target: 'idle',
actions: ['Modify AST', 'Clear selection'],
},
},
},
'Sketch no face': {
on: {
'Select face': 'Sketch',
},
},
Fillet: {
states: {
Idle: {
on: {
'Select edge': 'Selection Ready',
},
},
'Selection Ready': {
on: {
'Set radius': 'Ready',
'Select edge': {
target: 'Selection Ready',
internal: true,
},
},
},
Ready: {},
},
initial: 'Ready',
on: {
'Equip fillet': [
{
target: '.Selection Ready',
cond: 'Selection is one or more edges',
},
'.Idle',
],
},
invoke: {
src: 'createFillet',
id: 'Create fillet',
onDone: {
target: 'idle',
actions: ['Modify AST', 'Clear selection'],
},
},
},
},
Extrude: {
states: {
Idle: {
on: {
'Select face': 'Selection Ready',
},
},
'Selection Ready': {
on: {
'Set distance': 'Ready',
},
},
Ready: {},
},
initial: 'idle',
initial: 'Idle',
on: {
'Equip extrude': [
{
target: '.Selection Ready',
cond: 'Selection is one face',
},
'.Idle',
],
},
invoke: {
src: 'createExtrude',
id: 'Create extrude',
},
},
'Sketch no face': {
on: {
'Select face': 'Sketch',
},
},
Fillet: {
states: {
Idle: {
on: {
'Select edge': 'Selection Ready',
},
},
'Selection Ready': {
on: {
'Set radius': 'Ready',
},
},
Ready: {},
},
initial: 'Ready',
on: {
'Equip fillet': [
{
target: '.Selection Ready',
cond: 'Selection is one or more edges',
},
'.Idle',
],
},
invoke: {
src: 'createFillet',
id: 'Create fillet',
},
on: {
Cancel: '.idle',
},
},
initial: 'idle',
on: {
Cancel: '.idle',
},
})
{
actions: {
'Set selection': assign({
selectionRanges: (_, event) => event.data,
}),
'Add to code-based selection': assign({
selectionRanges: ({ selectionRanges }, event) => ({
...selectionRanges,
codeBasedSelections: [
...selectionRanges.codeBasedSelections,
event.data,
],
}),
}),
'Add to other selection': assign({
selectionRanges: ({ selectionRanges }, event) => ({
...selectionRanges,
otherSelections: [...selectionRanges.otherSelections, event.data],
}),
}),
'Remove from code-based selection': assign({
selectionRanges: ({ selectionRanges }, event) => ({
...selectionRanges,
codeBasedSelections: [
...selectionRanges.codeBasedSelections,
event.data,
],
}),
}),
'Remove from other selection': assign({
selectionRanges: ({ selectionRanges }, event) => ({
...selectionRanges,
otherSelections: [...selectionRanges.otherSelections, event.data],
}),
}),
'Clear selection': assign({
selectionRanges: () => ({
otherSelections: [],
codeBasedSelections: [],
}),
}),
},
}
)

View File

@ -1,145 +1,68 @@
// This file was automatically generated. Edits will be overwritten
export interface Typegen0 {
'@@xstate/typegen': true
internalEvents: {
'done.invoke.Create extrude': {
type: 'done.invoke.Create extrude'
data: unknown
__tip: 'See the XState TS docs to learn how to strongly type this.'
}
'done.invoke.Create fillet': {
type: 'done.invoke.Create fillet'
data: unknown
__tip: 'See the XState TS docs to learn how to strongly type this.'
}
'done.invoke.Create line': {
type: 'done.invoke.Create line'
data: unknown
__tip: 'See the XState TS docs to learn how to strongly type this.'
}
'done.invoke.Create sketch': {
type: 'done.invoke.Create sketch'
data: unknown
__tip: 'See the XState TS docs to learn how to strongly type this.'
}
'error.platform.Create extrude': {
type: 'error.platform.Create extrude'
data: unknown
}
'error.platform.Create fillet': {
type: 'error.platform.Create fillet'
data: unknown
}
'error.platform.Create line': {
type: 'error.platform.Create line'
data: unknown
}
'error.platform.Create sketch': {
type: 'error.platform.Create sketch'
data: unknown
}
'xstate.init': { type: 'xstate.init' }
}
invokeSrcNameMap: {
createExtrude: 'done.invoke.Create extrude'
createFillet: 'done.invoke.Create fillet'
createLine: 'done.invoke.Create line'
createSketch: 'done.invoke.Create sketch'
}
missingImplementations: {
actions:
| 'Add to selection'
| 'Make selected line horizontal'
| 'Remove from selection'
| 'Update code selection cursors'
delays: never
guards:
| 'Can make selection horizontal'
| 'Can make selection vertical'
| 'Selection contains edge'
| 'Selection contains face'
| 'Selection contains line'
| 'Selection contains point'
| 'Selection is empty'
| 'Selection is not empty'
| 'Selection is one face'
| 'Selection is one or more edges'
services: 'createExtrude' | 'createFillet' | 'createLine' | 'createSketch'
}
eventsCausingActions: {
'Add to selection':
| 'Select all'
| 'Select edge'
| 'Select face'
| 'Select point'
'Make selected line horizontal': 'Make line horizontal'
'Remove from selection':
| 'Deselect all'
| 'Deselect edge'
| 'Deselect face'
| 'Deselect point'
'Update code selection cursors': 'Make line horizontal'
}
eventsCausingDelays: {}
eventsCausingGuards: {
'Can make selection horizontal': 'Make line horizontal'
'Can make selection vertical': 'Make segment vertical'
'Selection contains edge': 'Deselect edge'
'Selection contains face': 'Deselect face'
'Selection contains line': 'Deselect line'
'Selection contains point': 'Deselect point'
'Selection is empty': 'Equip extrude' | 'Equip fillet'
'Selection is not empty': 'Deselect all'
'Selection is one face':
| 'Enter sketch'
| 'Equip Extrude Tool'
| 'Equip extrude'
'Selection is one or more edges': 'Equip fillet'
}
eventsCausingServices: {
createExtrude: 'Equip extrude'
createFillet: 'Equip fillet'
createLine: 'Equip Line Tool'
createSketch: 'Enter sketch' | 'Select face'
}
matchesStates:
| 'Extrude'
| 'Extrude.Idle'
| 'Extrude.Ready'
| 'Extrude.Selection Ready'
| 'Fillet'
| 'Fillet.Idle'
| 'Fillet.Ready'
| 'Fillet.Selection Ready'
| 'Sketch'
| 'Sketch no face'
| 'Sketch.Extrude'
| 'Sketch.Extrude.Idle'
| 'Sketch.Extrude.Ready'
| 'Sketch.Extrude.Selection Ready'
| 'Sketch.Idle'
| 'Sketch.Line Tool'
| 'Sketch.Line Tool.Done'
| 'Sketch.Line Tool.No Points'
| 'Sketch.Line Tool.Point Added'
| 'Sketch.Line Tool.Segment Added'
| 'idle'
| {
Extrude?: 'Idle' | 'Ready' | 'Selection Ready'
Fillet?: 'Idle' | 'Ready' | 'Selection Ready'
Sketch?:
| 'Extrude'
| 'Idle'
| 'Line Tool'
| {
Extrude?: 'Idle' | 'Ready' | 'Selection Ready'
'Line Tool'?:
| 'Done'
| 'No Points'
| 'Point Added'
| 'Segment Added'
}
// This file was automatically generated. Edits will be overwritten
export interface Typegen0 {
'@@xstate/typegen': true;
internalEvents: {
"done.invoke.Create extrude": { type: "done.invoke.Create extrude"; data: unknown; __tip: "See the XState TS docs to learn how to strongly type this." };
"done.invoke.Create fillet": { type: "done.invoke.Create fillet"; data: unknown; __tip: "See the XState TS docs to learn how to strongly type this." };
"done.invoke.Create line": { type: "done.invoke.Create line"; data: unknown; __tip: "See the XState TS docs to learn how to strongly type this." };
"done.invoke.Create sketch": { type: "done.invoke.Create sketch"; data: unknown; __tip: "See the XState TS docs to learn how to strongly type this." };
"error.platform.Create extrude": { type: "error.platform.Create extrude"; data: unknown };
"error.platform.Create fillet": { type: "error.platform.Create fillet"; data: unknown };
"error.platform.Create line": { type: "error.platform.Create line"; data: unknown };
"error.platform.Create sketch": { type: "error.platform.Create sketch"; data: unknown };
"xstate.init": { type: "xstate.init" };
};
invokeSrcNameMap: {
"createExtrude": "done.invoke.Create extrude";
"createFillet": "done.invoke.Create fillet";
"createLine": "done.invoke.Create line";
"createSketch": "done.invoke.Create sketch";
};
missingImplementations: {
actions: "Make selection horizontal" | "Make selection vertical" | "Modify AST" | "Update code selection cursors";
delays: never;
guards: "Can make selection horizontal" | "Can make selection vertical" | "Selection contains axis" | "Selection contains edge" | "Selection contains face" | "Selection contains line" | "Selection contains point" | "Selection is empty" | "Selection is not empty" | "Selection is one face" | "Selection is one or more edges";
services: "createExtrude" | "createFillet" | "createLine" | "createSketch";
};
eventsCausingActions: {
"Add to code-based selection": "Deselect point" | "Deselect segment" | "Select all" | "Select edge" | "Select face" | "Select point" | "Select segment";
"Add to other selection": "Select axis";
"Clear selection": "Deselect all" | "done.invoke.Create extrude" | "done.invoke.Create fillet";
"Make selection horizontal": "Make segment horizontal";
"Make selection vertical": "Make segment vertical";
"Modify AST": "Add point" | "Complete line" | "done.invoke.Create extrude" | "done.invoke.Create fillet";
"Remove from code-based selection": "Deselect edge" | "Deselect face" | "Deselect point";
"Remove from other selection": "Deselect axis";
"Set selection": "Set selection";
"Update code selection cursors": "Add point" | "Complete line" | "Deselect all" | "Deselect axis" | "Deselect edge" | "Deselect face" | "Deselect point" | "Deselect segment" | "Select edge" | "Select face" | "Select point" | "Select segment";
};
eventsCausingDelays: {
};
eventsCausingGuards: {
"Can make selection horizontal": "Make segment horizontal";
"Can make selection vertical": "Make segment vertical";
"Selection contains axis": "Deselect axis";
"Selection contains edge": "Deselect edge";
"Selection contains face": "Deselect face";
"Selection contains line": "Deselect segment";
"Selection contains point": "Deselect point";
"Selection is empty": "Equip extrude" | "Equip fillet";
"Selection is not empty": "Deselect all";
"Selection is one face": "Enter sketch" | "Equip extrude";
"Selection is one or more edges": "Equip fillet";
};
eventsCausingServices: {
"createExtrude": "Equip extrude";
"createFillet": "Equip fillet";
"createLine": "Equip line tool";
"createSketch": "Enter sketch" | "Select face";
};
matchesStates: "Extrude" | "Extrude.Idle" | "Extrude.Ready" | "Extrude.Selection Ready" | "Fillet" | "Fillet.Idle" | "Fillet.Ready" | "Fillet.Selection Ready" | "Sketch" | "Sketch no face" | "Sketch.Idle" | "Sketch.Line Tool" | "Sketch.Line Tool.Done" | "Sketch.Line Tool.No Points" | "Sketch.Line Tool.Point Added" | "Sketch.Line Tool.Segment Added" | "idle" | { "Extrude"?: "Idle" | "Ready" | "Selection Ready";
"Fillet"?: "Idle" | "Ready" | "Selection Ready";
"Sketch"?: "Idle" | "Line Tool" | { "Line Tool"?: "Done" | "No Points" | "Point Added" | "Segment Added"; }; };
tags: never;
}
tags: never
}

View File

@ -21,12 +21,23 @@ import {
import { KCLError } from './lang/errors'
import { defferExecution } from 'lib/utils'
export type Axis = 'y-axis' | 'x-axis' | 'z-axis'
export type Selection = {
type: 'default' | 'line-end' | 'line-mid'
type:
| 'default'
| 'line-end'
| 'line-mid'
| 'face'
| 'point'
| 'edge'
| 'line'
| 'arc'
| 'all'
range: SourceRange
}
export type Selections = {
otherSelections: ('y-axis' | 'x-axis' | 'z-axis')[]
otherSelections: Axis[]
codeBasedSelections: Selection[]
}
export type TooTip =