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,13 +1,17 @@
import { Program } from 'lang/abstractSyntaxTreeTypes' import { Program } from 'lang/abstractSyntaxTreeTypes'
import { ProgramMemory } from 'lang/executor' import { ProgramMemory } from 'lang/executor'
import { Selections } from 'useStore' import { Axis, Selection, Selections } from 'useStore'
import { createMachine } from 'xstate' import { assign, createMachine } from 'xstate'
export const modelingMachine = createMachine({ export const MODELING_PERSIST_KEY = 'MODELING_PERSIST_KEY'
/** @xstate-layout N4IgpgJg5mDOIC5QFkD2EwBsCWA7KAxAMICGuAxlgNoAMAuoqAA6qzYAu2qujIAHogC0AFgCMAOgCsADlHThYgGw1JAZlEB2DQBoQATyEAmRRvHTFATnnW1NK6oC+D3Wgw5847BExgCAETgsMHJ2AAIWPHZaBiQQFjZObl4BBEFVaWlxYUVFYQsLGkUZDUMaVV0DBE1TSU1JGmkS0XrhVUdnEFcsPChPb18A2CCQ0MgYaN54ji4eWJS0xrMLRWtDQ3VRdMUKxA1hcU0y0ULJYulDUScXdG6PLx8CAGVhsIjcKPpJ1mmkuaNVRRmaQWUSiYQZGiaKw7BCqDQ0LI0GglGjCGiGNQaUSKK6dG7uXr3XzPHwjMZgCaxKaJWagebrQEZEFgiFQ6Qw7L7AqSSwNRogyy4roEvoPEnBMIAMxIlEpzG+NOS-0ZwNB4OkkI0VkMMJ5+0Me3SGs2FjhkiF+J6ot8AFF3mAAE6hWAAazA7HIAAs5XEFTMlQg9uILMJJBp5KaVtJVMIYYJNplwcpzpDhIYxBp2tc3FaiQQ7exHc63R7vaIYvKEv6-oHDOIyki9ssQ9jo3HgeJ08iNDIwbVThoLTm7v18wBHACu2CYoz47AdE4wPup1bpiDWpjWFlqWkhlmWuvOWS0FkMIdUkgKqgsQ9uhNHNsn09n88XFPLXyrvzXCAuEnMqgXLI4ZWHY2z6IgiiqAipoND2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KCnUMa8tTYnujGy6IW2uZhkCsU4-I3lvjG3XTKZhZlHDXqrXUUMTyMzW5YQCg4HPFO2f5MuW2tASFM-W68zq1jIskdTRojN1BFW7htnZBN+V-MqJ5qF79x2p2MKibEyx5LvapisLQnHfsAn+-5AV-yttghcl-VVAClDc3h59pHP3VSo5izjHFeKZRgC26rMRH9wQXnSCoOMdKXIyAKNRaCF4lo9d6Bm90W2EKkVLZI8t9gpJWVOtTSwYYfOclKg5wXBq7udrB4GEaZgjS7obA4rLSlAQpOOMpsESFdXtt5SEIHgqQcSy8+D9DzSJ3olPIhB1aqzxIkkReYEZ4Lf6vEBju3hD9ppn2BqXcChIQXCRblR1dlvdqE5-74DQA */
export const modelingMachine = createMachine(
{
/** @xstate-layout N4IgpgJg5mDOIC5QFkD2EwBsCWA7KAxAMICGuAxlgNoAMAuoqAA6qzYAu2qujIAHogC0AFgCMAOgBMogOwyAzAE5hNABw0ZAVlGKANCACeQyQDZh4zTMWj5GmqfnDN8gL4v9aDDnzjsETGAEAMpg7AAEsFhg5JzctAxIICxssTyJAgiimuZOkqqSMjRqipKKcvpGCIKiqibiwrVqkjSiwpJiCm4e6Fh4UL7+gQAicFExYSx47PG8yRxcaaAZgvKqivUaJquywtYyohWIojbiqqr7NZprps2u7iCevT5+AQQjkQHjkDAziXOpvGWSnkUk0JhMVkkmmkbRMmkOVWE5mkighNHk7WaZzu3S8fQGr3eY3CJD42Fgv2YrHm3EBQhkpVBpm0q2EMi2qgRImROjRGLaahkqi6Dx63n6L0CIU+4UmuGm9Fm1IB6SE8kK4hku1MilUlgh4JkCNWIJMzQhThKiiukhFj3FBKlxLC3zAlKSyoWdKq8hMqnEinRtgaohoELB8MMiE0zikpUkpnR1sDijtYvxkuCztJ5Pd-y9qqq4PWKgjZ2yUJ0COcdXRNEUvvyMYxqfu9ozgyzMrCADMSJQ857aYWVpp1udRAVA1kTMckQiGTRxGHWtaYyYaA1NGm8c9OwBReVgABOEQA1qFyAALQcpAtLRBagNOIW7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4sY322tKsRu6nKxcnTlIDkpRJzsmTCs1JmAHFOIyfKEzoqLOZEDONQb0WRvaDdicJwEZS2Z2lrhObay0lDBRr1kZ1glynYcE0PYSD9FIkEuoNoDIk1FDO3FjrKSLsLeW1s3pEAbubVwiCVE0tVjTlMXotUB31zZDMA0U72c2uZoDgD7rRGukg5yeDgypaJBqzDGY15DYEc+iR0d1H9LfuY-EFqjARPEBmn9PkQo0qHJVWrOqe20hwZ5AxB+VruKeWup3mz1CCrxnZGcFaW21rNCBXOHZ3CawbAY4l58qX7ruBeokzL0MGotSTjNGYD88kauPhQSasMRQ0dFHVUJ5nUvSO+pN0VJzWRxLZFwgoPQyC9Rq7kFsTX1hfSCJzXm-sXn3ofv4jGKeZQ0tyXMuUReII0EMjKPyBO7ndc+AIy9GXHJ7aVZC2j-9QMnCajyPkWWUfsIQdCNLxP8nULYSIsoYLNVsLU+OMoJhlopqlqhEXjN4hS-t4N7gI3ZHKhrZ86buodMGwYjy6nIf3G71olkO0FWbf2DiE98vq2XfWhKCkDUDEWosIJlt5kPfjcD8MhUGUNwbggA */
id: 'Modeling', id: 'Modeling',
tsTypes: {} as import('./modelingMachine.typegen').Typegen0, tsTypes: {} as import('./modelingMachine.typegen').Typegen0,
predictableActionArguments: true,
context: { context: {
guiMode: 'default', guiMode: 'default',
@ -18,41 +22,127 @@ export const modelingMachine = createMachine({
codeBasedSelections: [], codeBasedSelections: [],
} as Selections, } as Selections,
programMemory: { root: {}, pendingMemory: {} } as ProgramMemory, programMemory: { root: {}, pendingMemory: {} } as ProgramMemory,
// TODO: migrate engineCommandManager from useStore
// engineCommandManager?: EngineCommandManager
},
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' },
}, },
states: { states: {
idle: { idle: {
on: { on: {
'Set selection': {
target: 'idle',
internal: true,
actions: 'Set selection',
},
'Deselect point': { 'Deselect point': {
target: 'idle', target: 'idle',
internal: true, internal: true,
actions: 'Remove from selection', actions: [
'Remove from code-based selection',
'Update code selection cursors',
// 'Engine: remove highlight',
],
cond: 'Selection contains point', cond: 'Selection contains point',
}, },
'Deselect edge': { 'Deselect edge': {
target: 'idle', target: 'idle',
internal: true, internal: true,
actions: 'Remove from selection', actions: [
'Remove from code-based selection',
'Update code selection cursors',
// 'Engine: remove highlight',
],
cond: 'Selection contains edge', cond: 'Selection contains edge',
}, },
'Deselect axis': {
target: 'idle',
internal: true,
actions: [
'Remove from other selection',
'Update code selection cursors',
// 'Engine: remove highlight',
],
cond: 'Selection contains axis',
},
'Select point': { 'Select point': {
target: 'idle', target: 'idle',
internal: true, internal: true,
actions: 'Add to selection', actions: [
'Add to code-based selection',
'Update code selection cursors',
// 'Engine: add highlight',
],
}, },
'Select edge': { 'Select edge': {
target: 'idle', target: 'idle',
internal: true, internal: true,
actions: 'Add to selection', 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': { 'Select face': {
target: 'idle', target: 'idle',
internal: true, internal: true,
actions: 'Add to selection', actions: [
'Add to code-based selection',
'Update code selection cursors',
// 'Engine: add highlight',
],
}, },
'Enter sketch': [ 'Enter sketch': [
@ -77,20 +167,28 @@ export const modelingMachine = createMachine({
'Deselect face': { 'Deselect face': {
target: 'idle', target: 'idle',
internal: true, internal: true,
actions: 'Remove from selection', actions: [
'Remove from code-based selection',
'Update code selection cursors',
// 'Engine: remove highlight',
],
cond: 'Selection contains face', cond: 'Selection contains face',
}, },
'Select all': { 'Select all': {
target: 'idle', target: 'idle',
internal: true, internal: true,
actions: 'Add to selection', actions: 'Add to code-based selection',
}, },
'Deselect all': { 'Deselect all': {
target: 'idle', target: 'idle',
internal: true, internal: true,
actions: 'Remove from selection', actions: [
'Clear selection',
'Update code selection cursors',
// 'Engine: remove highlight',
],
cond: 'Selection is not empty', cond: 'Selection is not empty',
}, },
@ -111,25 +209,23 @@ export const modelingMachine = createMachine({
states: { states: {
Idle: { Idle: {
on: { on: {
'Equip Line Tool': 'Line Tool', 'Equip line tool': 'Line Tool',
'Select Point': { 'Select point': {
target: 'Idle', target: 'Idle',
internal: true, internal: true,
},
'Select Line': {
target: 'Idle',
internal: true,
},
'Make line horizontal': {
target: 'Idle',
internal: true,
cond: 'Can make selection horizontal',
actions: [ actions: [
'Make selected line horizontal',
'Update code selection cursors', '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',
], ],
}, },
@ -137,18 +233,34 @@ export const modelingMachine = createMachine({
target: 'Idle', target: 'Idle',
internal: true, internal: true,
cond: 'Selection contains point', cond: 'Selection contains point',
actions: [
'Update code selection cursors',
'Add to code-based selection',
],
}, },
'Deselect line': { 'Deselect segment': {
target: 'Idle', target: 'Idle',
internal: true, internal: true,
cond: 'Selection contains line', cond: 'Selection contains line',
actions: [
'Update code selection cursors',
'Add to code-based selection',
],
}, },
'Make segment vertical': { 'Make segment vertical': {
cond: 'Can make selection vertical', cond: 'Can make selection vertical',
target: 'Idle', target: 'Idle',
internal: true, internal: true,
actions: ['Make selection vertical'],
},
'Make segment horizontal': {
target: 'Idle',
internal: true,
cond: 'Can make selection horizontal',
actions: ['Make selection horizontal'],
}, },
}, },
}, },
@ -157,7 +269,10 @@ export const modelingMachine = createMachine({
states: { states: {
'No Points': { 'No Points': {
on: { on: {
'Add Point': 'Point Added', 'Add point': {
target: 'Point Added',
actions: ['Modify AST', 'Update code selection cursors'],
},
}, },
}, },
@ -167,18 +282,25 @@ export const modelingMachine = createMachine({
'Point Added': { 'Point Added': {
on: { on: {
'Add Point': 'Segment Added', 'Add point': {
target: 'Segment Added',
actions: ['Modify AST', 'Update code selection cursors'],
},
}, },
}, },
'Segment Added': { 'Segment Added': {
on: { on: {
'Add Point': { 'Add point': {
target: 'Segment Added', target: 'Segment Added',
internal: true, internal: true,
actions: ['Modify AST', 'Update code selection cursors'],
}, },
'Complete Line': 'Done', 'Complete line': {
target: 'Done',
actions: ['Modify AST', 'Update code selection cursors'],
},
}, },
}, },
}, },
@ -189,37 +311,6 @@ export const modelingMachine = createMachine({
src: 'createLine', src: 'createLine',
id: 'Create line', id: 'Create line',
onDone: 'Idle', onDone: 'Idle',
onError: 'Idle',
},
},
Extrude: {
states: {
Idle: {
on: {
'Select Face': 'Selection Ready',
},
},
'Selection Ready': {
on: {
'Set Distance': 'Ready',
},
},
Ready: {},
},
initial: 'Idle',
on: {
'Equip Extrude Tool': [
{
target: '.Selection Ready',
cond: 'Selection is one face',
},
'.Idle',
],
}, },
}, },
}, },
@ -234,7 +325,6 @@ export const modelingMachine = createMachine({
src: 'createSketch', src: 'createSketch',
id: 'Create sketch', id: 'Create sketch',
onDone: 'idle', onDone: 'idle',
onError: 'idle',
}, },
}, },
@ -268,6 +358,10 @@ export const modelingMachine = createMachine({
invoke: { invoke: {
src: 'createExtrude', src: 'createExtrude',
id: 'Create extrude', id: 'Create extrude',
onDone: {
target: 'idle',
actions: ['Modify AST', 'Clear selection'],
},
}, },
}, },
@ -287,6 +381,11 @@ export const modelingMachine = createMachine({
'Selection Ready': { 'Selection Ready': {
on: { on: {
'Set radius': 'Ready', 'Set radius': 'Ready',
'Select edge': {
target: 'Selection Ready',
internal: true,
},
}, },
}, },
Ready: {}, Ready: {},
@ -307,6 +406,10 @@ export const modelingMachine = createMachine({
invoke: { invoke: {
src: 'createFillet', src: 'createFillet',
id: 'Create fillet', id: 'Create fillet',
onDone: {
target: 'idle',
actions: ['Modify AST', 'Clear selection'],
},
}, },
}, },
}, },
@ -316,4 +419,48 @@ export const modelingMachine = createMachine({
on: { on: {
Cancel: '.idle', 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 { // This file was automatically generated. Edits will be overwritten
'@@xstate/typegen': true
export interface Typegen0 {
'@@xstate/typegen': true;
internalEvents: { internalEvents: {
'done.invoke.Create extrude': { "done.invoke.Create extrude": { type: "done.invoke.Create extrude"; data: unknown; __tip: "See the XState TS docs to learn how to strongly type this." };
type: 'done.invoke.Create extrude' "done.invoke.Create fillet": { type: "done.invoke.Create fillet"; data: unknown; __tip: "See the XState TS docs to learn how to strongly type this." };
data: unknown "done.invoke.Create line": { type: "done.invoke.Create line"; data: unknown; __tip: "See the XState TS docs to learn how to strongly type this." };
__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 };
'done.invoke.Create fillet': { "error.platform.Create fillet": { type: "error.platform.Create fillet"; data: unknown };
type: 'done.invoke.Create fillet' "error.platform.Create line": { type: "error.platform.Create line"; data: unknown };
data: unknown "error.platform.Create sketch": { type: "error.platform.Create sketch"; data: unknown };
__tip: 'See the XState TS docs to learn how to strongly type this.' "xstate.init": { type: "xstate.init" };
} };
'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: { invokeSrcNameMap: {
createExtrude: 'done.invoke.Create extrude' "createExtrude": "done.invoke.Create extrude";
createFillet: 'done.invoke.Create fillet' "createFillet": "done.invoke.Create fillet";
createLine: 'done.invoke.Create line' "createLine": "done.invoke.Create line";
createSketch: 'done.invoke.Create sketch' "createSketch": "done.invoke.Create sketch";
} };
missingImplementations: { missingImplementations: {
actions: actions: "Make selection horizontal" | "Make selection vertical" | "Modify AST" | "Update code selection cursors";
| 'Add to selection' delays: never;
| 'Make selected line horizontal' 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";
| 'Remove from selection' services: "createExtrude" | "createFillet" | "createLine" | "createSketch";
| '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: { eventsCausingActions: {
'Add to selection': "Add to code-based selection": "Deselect point" | "Deselect segment" | "Select all" | "Select edge" | "Select face" | "Select point" | "Select segment";
| 'Select all' "Add to other selection": "Select axis";
| 'Select edge' "Clear selection": "Deselect all" | "done.invoke.Create extrude" | "done.invoke.Create fillet";
| 'Select face' "Make selection horizontal": "Make segment horizontal";
| 'Select point' "Make selection vertical": "Make segment vertical";
'Make selected line horizontal': 'Make line horizontal' "Modify AST": "Add point" | "Complete line" | "done.invoke.Create extrude" | "done.invoke.Create fillet";
'Remove from selection': "Remove from code-based selection": "Deselect edge" | "Deselect face" | "Deselect point";
| 'Deselect all' "Remove from other selection": "Deselect axis";
| 'Deselect edge' "Set selection": "Set selection";
| 'Deselect face' "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";
| 'Deselect point' };
'Update code selection cursors': 'Make line horizontal' eventsCausingDelays: {
}
eventsCausingDelays: {} };
eventsCausingGuards: { eventsCausingGuards: {
'Can make selection horizontal': 'Make line horizontal' "Can make selection horizontal": "Make segment horizontal";
'Can make selection vertical': 'Make segment vertical' "Can make selection vertical": "Make segment vertical";
'Selection contains edge': 'Deselect edge' "Selection contains axis": "Deselect axis";
'Selection contains face': 'Deselect face' "Selection contains edge": "Deselect edge";
'Selection contains line': 'Deselect line' "Selection contains face": "Deselect face";
'Selection contains point': 'Deselect point' "Selection contains line": "Deselect segment";
'Selection is empty': 'Equip extrude' | 'Equip fillet' "Selection contains point": "Deselect point";
'Selection is not empty': 'Deselect all' "Selection is empty": "Equip extrude" | "Equip fillet";
'Selection is one face': "Selection is not empty": "Deselect all";
| 'Enter sketch' "Selection is one face": "Enter sketch" | "Equip extrude";
| 'Equip Extrude Tool' "Selection is one or more edges": "Equip fillet";
| 'Equip extrude' };
'Selection is one or more edges': 'Equip fillet'
}
eventsCausingServices: { eventsCausingServices: {
createExtrude: 'Equip extrude' "createExtrude": "Equip extrude";
createFillet: 'Equip fillet' "createFillet": "Equip fillet";
createLine: 'Equip Line Tool' "createLine": "Equip line tool";
createSketch: 'Enter sketch' | 'Select face' "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;
} }
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'
}
}
tags: never
}

View File

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