xstate migration (#713)
* Add basic Popover functionality * Fix up light mode of basic bar * Add support for 2D and 3D mode styling * Turn toolbar buttons back on * Remove ActionButton until after tool logic refactor * Add transitions * Add initial modeling machine This is not a full description of how the modelingMachine should work, but begins to replicate all of the features of our useStore in XState instead of zustand. * Add fillet tool flow * Refactor: break out engine manager setup into hook Preparing for making a wrapper component around the App that will manage the engine manager at the same level as the modelingMachine. * Create modeling provider, move engine management to it * Refactor: move other engine-related useEffect into hook * Add TS schema, selection actions to modelingMachine * Add barebones modeling machine to app Only implementing adding to code-based selections in the text editor so far * Update moved useEffect hook after merge * give myself reminder TODO * fix engineCommandManager waitForReady Promise * enable devtools * make utility class for handling default planes * progresson startNewSketch and EditSketch * add provider to tests * too large of a commit put all of the lang state into another singleton, but did lots of work on xstate too * fix edit sketch ast issue * re-execute on sketch exit * prettierignore xstate typegen file * add move tool button back in * handle mouse commands with xState states * fix move * remove old imports * big useStore delete * fix some destructuring bugs * start of constraint actions * add horizontal/vertical distance constraints * fix more destructuring errors * fix * add angle constaints * add align vertically/horizontally constraints * add length and equal length constraints * rename modal states to be more cmd bar friendly * add doesPipeHave query * add another query * add extrude states * state machine clean up * xstate layout tweak * make xstate types happy * Revamp cursor logic and place curors after ast mod * Xstate merge (#796) * turning back on all planes (#720) * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> tests Signed-off-by: Jess Frazelle <github@jessfraz.com> fix more tests Signed-off-by: Jess Frazelle <github@jessfraz.com> fixes Signed-off-by: Jess Frazelle <github@jessfraz.com> fix stdlib Signed-off-by: Jess Frazelle <github@jessfraz.com> fix tests Signed-off-by: Jess Frazelle <github@jessfraz.com> fixes Signed-off-by: Jess Frazelle <github@jessfraz.com> updates Signed-off-by: Jess Frazelle <github@jessfraz.com> updates Signed-off-by: Jess Frazelle <github@jessfraz.com> compile Signed-off-by: Jess Frazelle <github@jessfraz.com> update sample code Signed-off-by: Jess Frazelle <github@jessfraz.com> re-enable the planes Signed-off-by: Jess Frazelle <github@jessfraz.com> fix tests Signed-off-by: Jess Frazelle <github@jessfraz.com> fix tests Signed-off-by: Jess Frazelle <github@jessfraz.com> fix tests Signed-off-by: Jess Frazelle <github@jessfraz.com> fix tests Signed-off-by: Jess Frazelle <github@jessfraz.com> fix tests Signed-off-by: Jess Frazelle <github@jessfraz.com> fix tests Signed-off-by: Jess Frazelle <github@jessfraz.com> fix tests Signed-off-by: Jess Frazelle <github@jessfraz.com> updates Signed-off-by: Jess Frazelle <github@jessfraz.com> fix all tests Signed-off-by: Jess Frazelle <github@jessfraz.com> updates Signed-off-by: Jess Frazelle <github@jessfraz.com> boilerplate Signed-off-by: Jess Frazelle <github@jessfraz.com> Cut release v0.9.2 (#714) rust make default planes Signed-off-by: Jess Frazelle <github@jessfraz.com> updates Signed-off-by: Jess Frazelle <github@jessfraz.com> use the planes from engine Signed-off-by: Jess Frazelle <github@jessfraz.com> fixups Signed-off-by: Jess Frazelle <github@jessfraz.com> updates Signed-off-by: Jess Frazelle <github@jessfraz.com> fixes Signed-off-by: Jess Frazelle <github@jessfraz.com> updates Signed-off-by: Jess Frazelle <github@jessfraz.com> fixes Signed-off-by: Jess Frazelle <github@jessfraz.com> fixes Signed-off-by: Jess Frazelle <github@jessfraz.com> negative args Signed-off-by: Jess Frazelle <github@jessfraz.com> diable camera Signed-off-by: Jess Frazelle <github@jessfraz.com> hide planes Signed-off-by: Jess Frazelle <github@jessfraz.com> updates Signed-off-by: Jess Frazelle <github@jessfraz.com> updates Signed-off-by: Jess Frazelle <github@jessfraz.com> updatress Signed-off-by: Jess Frazelle <github@jessfraz.com> fmt Signed-off-by: Jess Frazelle <github@jessfraz.com> Update src/hooks/useAppMode.ts Co-authored-by: Kurt Hutten <k.hutten@protonmail.ch> Update src/hooks/useAppMode.ts Co-authored-by: Kurt Hutten <k.hutten@protonmail.ch> cleanups Signed-off-by: Jess Frazelle <github@jessfraz.com> Bump kittycad from 0.2.26 to 0.2.27 in /src-tauri (#726) Bumps [kittycad](https://github.com/KittyCAD/kittycad.rs) from 0.2.26 to 0.2.27. - [Release notes](https://github.com/KittyCAD/kittycad.rs/releases) - [Commits](https://github.com/KittyCAD/kittycad.rs/compare/v0.2.26...v0.2.27) --- updated-dependencies: - dependency-name: kittycad dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Bump tauri-plugin-fs-extra from `b04bde3` to `6c7a4c0` in /src-tauri (#725) Bumps [tauri-plugin-fs-extra](https://github.com/tauri-apps/plugins-workspace) from `b04bde3` to `6c7a4c0`. - [Release notes](https://github.com/tauri-apps/plugins-workspace/releases) - [Commits](b04bde3461...6c7a4c0984
) --- updated-dependencies: - dependency-name: tauri-plugin-fs-extra dependency-type: direct:production ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Bump toml from 0.8.0 to 0.8.1 in /src-tauri (#724) Bumps [toml](https://github.com/toml-rs/toml) from 0.8.0 to 0.8.1. - [Commits](https://github.com/toml-rs/toml/compare/toml-v0.8.0...toml-v0.8.1) --- updated-dependencies: - dependency-name: toml dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Bump openapitor from `61a1605` to `d3e98c4` in /src/wasm-lib (#723) Bumps [openapitor](https://github.com/KittyCAD/kittycad.rs) from `61a1605` to `d3e98c4`. - [Release notes](https://github.com/KittyCAD/kittycad.rs/releases) - [Commits](61a16059b3...d3e98c4ec0
) --- updated-dependencies: - dependency-name: openapitor dependency-type: direct:production ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Bump kittycad from 0.2.26 to 0.2.27 in /src/wasm-lib (#722) Bumps [kittycad](https://github.com/KittyCAD/kittycad.rs) from 0.2.26 to 0.2.27. - [Release notes](https://github.com/KittyCAD/kittycad.rs/releases) - [Commits](https://github.com/KittyCAD/kittycad.rs/compare/v0.2.26...v0.2.27) --- updated-dependencies: - dependency-name: kittycad dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Bump thiserror from 1.0.48 to 1.0.49 in /src/wasm-lib (#721) Bumps [thiserror](https://github.com/dtolnay/thiserror) from 1.0.48 to 1.0.49. - [Release notes](https://github.com/dtolnay/thiserror/releases) - [Commits](https://github.com/dtolnay/thiserror/compare/1.0.48...1.0.49) --- updated-dependencies: - dependency-name: thiserror dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Bump expectorate from 1.0.7 to 1.1.0 in /src/wasm-lib (#712) Bumps [expectorate](https://github.com/oxidecomputer/expectorate) from 1.0.7 to 1.1.0. - [Release notes](https://github.com/oxidecomputer/expectorate/releases) - [Commits](https://github.com/oxidecomputer/expectorate/compare/v1.0.7...v1.1.0) --- updated-dependencies: - dependency-name: expectorate dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Bump clap from 4.4.4 to 4.4.5 in /src/wasm-lib (#711) Bumps [clap](https://github.com/clap-rs/clap) from 4.4.4 to 4.4.5. - [Release notes](https://github.com/clap-rs/clap/releases) - [Changelog](https://github.com/clap-rs/clap/blob/master/CHANGELOG.md) - [Commits](https://github.com/clap-rs/clap/compare/v4.4.4...v4.4.5) --- updated-dependencies: - dependency-name: clap dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> refactor cleanup Signed-off-by: Jess Frazelle <github@jessfraz.com> updates Signed-off-by: Jess Frazelle <github@jessfraz.com> updates Signed-off-by: Jess Frazelle <github@jessfraz.com> type improvements * use new sketchmode no camera Signed-off-by: Jess Frazelle <github@jessfraz.com> * js working better Signed-off-by: Jess Frazelle <github@jessfraz.com> * start of negative planes Signed-off-by: Jess Frazelle <github@jessfraz.com> * tests and neg Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * images Signed-off-by: Jess Frazelle <github@jessfraz.com> * norma;s Signed-off-by: Jess Frazelle <github@jessfraz.com> * better initial load of planes Signed-off-by: Jess Frazelle <github@jessfraz.com> * ts Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * fixes Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * fixes Signed-off-by: Jess Frazelle <github@jessfraz.com> * fix tsc Signed-off-by: Jess Frazelle <github@jessfraz.com> * fix edit sketch Signed-off-by: Jess Frazelle <github@jessfraz.com> * add regression test for 2d solid issue Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * show planes Signed-off-by: Jess Frazelle <github@jessfraz.com> * fix clippy Signed-off-by: Jess Frazelle <github@jessfraz.com> * fix tests Signed-off-by: Jess Frazelle <github@jessfraz.com> * canecel in progress Signed-off-by: Jess Frazelle <github@jessfraz.com> * fix ci as well Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> --------- Signed-off-by: Jess Frazelle <github@jessfraz.com> * stopping point Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * fixes Signed-off-by: Jess Frazelle <github@jessfraz.com> * refactor Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * it works Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * Hide planes (#797) * hide planes in one go Signed-off-by: Jess Frazelle <github@jessfraz.com> * update hide; Signed-off-by: Jess Frazelle <github@jessfraz.com> * fixes Signed-off-by: Jess Frazelle <github@jessfraz.com> --------- Signed-off-by: Jess Frazelle <github@jessfraz.com> * make tsc happy * Make "Replay Onboarding" button available on home settings page (#804) * Fix unrelated bug, settings button in the home sidebar doesn't go to the home settings after my previous fixes to routes * Turn on "Replay Onboarding" button in home settings * Use ONBOARDING_PROJECT_NAME in both places * Fix formatting * Cut release v0.10.0 (#803) Co-authored-by: Frank Noirot <frank@kittycad.io> * Bump kittycad from 0.2.28 to 0.2.31 in /src-tauri (#798) Bumps [kittycad](https://github.com/KittyCAD/kittycad.rs) from 0.2.28 to 0.2.31. - [Release notes](https://github.com/KittyCAD/kittycad.rs/releases) - [Commits](https://github.com/KittyCAD/kittycad.rs/compare/v0.2.28...v0.2.31) --- updated-dependencies: - dependency-name: kittycad dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump openapitor from `fa0345c` to `c122a9b` in /src/wasm-lib (#800) Bumps [openapitor](https://github.com/KittyCAD/kittycad.rs) from `fa0345c` to `c122a9b`. - [Release notes](https://github.com/KittyCAD/kittycad.rs/releases) - [Commits](fa0345c514...c122a9b1d6
) --- updated-dependencies: - dependency-name: openapitor dependency-type: direct:production ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump syn from 2.0.37 to 2.0.38 in /src/wasm-lib (#801) Bumps [syn](https://github.com/dtolnay/syn) from 2.0.37 to 2.0.38. - [Release notes](https://github.com/dtolnay/syn/releases) - [Commits](https://github.com/dtolnay/syn/compare/2.0.37...2.0.38) --- updated-dependencies: - dependency-name: syn dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump winnow from 0.5.15 to 0.5.16 in /src/wasm-lib (#799) Bumps [winnow](https://github.com/winnow-rs/winnow) from 0.5.15 to 0.5.16. - [Changelog](https://github.com/winnow-rs/winnow/blob/main/CHANGELOG.md) - [Commits](https://github.com/winnow-rs/winnow/compare/v0.5.15...v0.5.16) --- updated-dependencies: - dependency-name: winnow dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump tauri-plugin-fs-extra from `fa32d1a` to `9f27e6e` in /src-tauri (#802) Bumps [tauri-plugin-fs-extra](https://github.com/tauri-apps/plugins-workspace) from `fa32d1a` to `9f27e6e`. - [Release notes](https://github.com/tauri-apps/plugins-workspace/releases) - [Commits](fa32d1afa9...9f27e6e441
) --- updated-dependencies: - dependency-name: tauri-plugin-fs-extra dependency-type: direct:production ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * better plane selection Signed-off-by: Jess Frazelle <github@jessfraz.com> * use the sketch plane id Signed-off-by: Jess Frazelle <github@jessfraz.com> * add todo w bug Signed-off-by: Jess Frazelle <github@jessfraz.com> * Improve Prop Typings for Modals. Remove instances of `any`. (#792) * Update typings for modals. Remove instances of `any` * Fix generic type for creating modals * cleanup other stuffs Signed-off-by: Jess Frazelle <github@jessfraz.com> * make plane id available when selecting default plane * few clean up things * change enter sketch action order to make sure plane id is available to 'enter edit mode' * Revert "Improve Prop Typings for Modals. Remove instances of `any`. (… (#813) Revert "Improve Prop Typings for Modals. Remove instances of `any`. (#792)" This reverts commit629f326f4c
. * ffmpeg instructions (#814) * fix some tsc stuff * small tweak --------- Signed-off-by: Jess Frazelle <github@jessfraz.com> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Kurt Hutten Irev-Dev <k.hutten@protonmail.ch> Co-authored-by: Frank Noirot <frank@kittycad.io> Co-authored-by: Pierre Jacquier <pierrejacquier39@gmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Jason Rametta <rametta@outlook.com> * clean up * fix test and tsc * remove one more thing from useStore * tweak state digrame layout * fmt --------- Signed-off-by: Jess Frazelle <github@jessfraz.com> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Frank Johnson <frankjohnson1993@gmail.com> Co-authored-by: Frank Noirot <frank@kittycad.io> Co-authored-by: Jess Frazelle <jessfraz@users.noreply.github.com> Co-authored-by: Pierre Jacquier <pierrejacquier39@gmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Jason Rametta <rametta@outlook.com>
This commit is contained in:
853
src/machines/modelingMachine.ts
Normal file
853
src/machines/modelingMachine.ts
Normal file
@ -0,0 +1,853 @@
|
||||
import { PathToNode } from 'lang/wasm'
|
||||
import { engineCommandManager } from 'lang/std/engineConnection'
|
||||
import { isReducedMotion } from 'lang/util'
|
||||
import { Axis, Selection, SelectionRangeTypeMap, Selections } from 'useStore'
|
||||
import { assign, createMachine } from 'xstate'
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
import { isCursorInSketchCommandRange } from 'hooks/useAppMode'
|
||||
import {
|
||||
doesPipeHaveCallExp,
|
||||
getNodePathFromSourceRange,
|
||||
hasExtrudeSketchGroup,
|
||||
} from 'lang/queryAst'
|
||||
import { kclManager } from 'lang/KclSinglton'
|
||||
import {
|
||||
horzVertInfo,
|
||||
applyConstraintHorzVert,
|
||||
} from 'components/Toolbar/HorzVert'
|
||||
import {
|
||||
applyConstraintHorzVertAlign,
|
||||
horzVertDistanceInfo,
|
||||
} from 'components/Toolbar/SetHorzVertDistance'
|
||||
import { angleBetweenInfo } from 'components/Toolbar/SetAngleBetween'
|
||||
import { setAngleLengthInfo } from 'components/Toolbar/setAngleLength'
|
||||
import {
|
||||
applyConstraintEqualLength,
|
||||
setEqualLengthInfo,
|
||||
} from 'components/Toolbar/EqualLength'
|
||||
import { extrudeSketch } from 'lang/modifyAst'
|
||||
import { getNodeFromPath } from '../lang/queryAst'
|
||||
import { CallExpression, PipeExpression } from '../lang/wasm'
|
||||
|
||||
export const MODELING_PERSIST_KEY = 'MODELING_PERSIST_KEY'
|
||||
|
||||
export type SetSelections =
|
||||
| {
|
||||
selectionType: 'singleCodeCursor'
|
||||
selection?: Selection
|
||||
}
|
||||
| {
|
||||
selectionType: 'otherSelection'
|
||||
selection: Axis
|
||||
}
|
||||
| {
|
||||
selectionType: 'completeSelection'
|
||||
selection: Selections
|
||||
}
|
||||
| {
|
||||
selectionType: 'mirrorCodeMirrorSelections'
|
||||
selection: Selections
|
||||
}
|
||||
|
||||
export const modelingMachine = createMachine(
|
||||
{
|
||||
/** @xstate-layout N4IgpgJg5mDOIC5QFkD2EwBsCWA7KAxAMICGuAxlgNoAMAuoqAA6qzYAu2qujIAHogDMAVgDsAOmEiAjLMGCAHIIAsAJlHKANCACeiaQDZBEsctGrVATmmiaNQQF8H2tBhz5x2CJjAEAymDsAASwWGDknNy0DEggLGyRPLECCMrCCuL20qrCRpYagvnaegjZBtLiBqLploIGCtZVyk4u6Fh4UJ7evgAicGERQSx47NG88RxcSaApdcKSNKIKi8ppwsrLwsX60oriqgaWBgbKImpWqi0gru0eXj4EfaE+g5AwY7ETibyzx5lLu1sygM61ERV0+ho0mU4gURlOwihlis2SuN3cnXuvX6L2CJD42FgH2YrEm3B+QnM4mqdhoyPUILqBm2CAaFTS5houQUCMczmubQxXQeAVxQ1QI2JcVJ32SiGUXPEhjBtWklgaokMzIhqVUNHEG0WgjVqkEUN2aMFHWFvlF4WCbzAUq+UwpqRoGQ2pwacPW4JKJxhgYU0kWu3Wymklrc1qx-gGeIJRPo4xlrrlqUEqkqdMKOSRNEOLPWGTVhkswlU0O5fNaMbu3XjYoAZiRKM60+SMwqMgY7Go6mbalCWaIjLCjtJ0n36tUFNHbpjGwBRXDsMAAJxCAGtAuQ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NbIZaExDYWA0AjiCwI4RPTo5ghTBbZ7LTDY35PUIwIcZaEQJQQJRYTIEWBEewOoCsZnNHJJW409A7RzcPD6d8dBCFXIKnEQTINtZKaoPUAaJ3ZOJXFXNsMACos46kEQVVawCsQsSnFCd4woHkCItqKsWWF3HDdPOvOaLWN0XKC8A5dzG1PgkxTKHmJYAofKJ-SvfcVPGk33dGekzmBnSQE4anQ2OKQodk7MWQCxREFVOiJwJwIAA */
|
||||
id: 'Modeling',
|
||||
|
||||
tsTypes: {} as import('./modelingMachine.typegen').Typegen0,
|
||||
predictableActionArguments: true,
|
||||
preserveActionOrder: true,
|
||||
|
||||
context: {
|
||||
guiMode: 'default',
|
||||
selection: [] as string[],
|
||||
selectionRanges: {
|
||||
otherSelections: [],
|
||||
codeBasedSelections: [],
|
||||
} as Selections,
|
||||
selectionRangeTypeMap: {} as SelectionRangeTypeMap,
|
||||
sketchPathToNode: null as PathToNode | null, // maybe too specific, and we should have a generic pathToNode, but being specific seems less risky when I'm not sure
|
||||
sketchEnginePathId: '' as string,
|
||||
sketchPlaneId: '' as string,
|
||||
},
|
||||
|
||||
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: '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: 'Select default plane'; data: { planeId: string } }
|
||||
| { type: 'Set selection'; data: SetSelections }
|
||||
| {
|
||||
type: 'Select point'
|
||||
data: Selection & { type: 'point' | 'line-end' | 'line-mid' }
|
||||
}
|
||||
| { type: 'Sketch no face' }
|
||||
| { type: 'Toggle gui mode' }
|
||||
| { type: 'Cancel' }
|
||||
| { type: 'CancelSketch' }
|
||||
| {
|
||||
type: 'Add point'
|
||||
data: {
|
||||
coords: { x: number; y: number }[]
|
||||
axis: 'xy' | 'xz' | 'yz' | '-xy' | '-xz' | '-yz' | null
|
||||
}
|
||||
}
|
||||
| { type: 'Equip tool' }
|
||||
| { type: 'Equip move tool' }
|
||||
| { type: 'Set radius' }
|
||||
| { type: 'Complete line' }
|
||||
| { type: 'Set distance' }
|
||||
| { type: 'Equip new tool' }
|
||||
| { type: 'update_code'; data: string }
|
||||
| { type: 'Make segment horizontal' }
|
||||
| { type: 'Make segment vertical' }
|
||||
| { type: 'Constrain horizontal distance' }
|
||||
| { type: 'Constrain vertical distance' }
|
||||
| { type: 'Constrain angle' }
|
||||
| { type: 'Constrain horizontally align' }
|
||||
| { type: 'Constrain vertically align' }
|
||||
| { type: 'Constrain length' }
|
||||
| { type: 'Constrain equal length' }
|
||||
| { type: 'extrude intent' },
|
||||
// ,
|
||||
},
|
||||
|
||||
states: {
|
||||
idle: {
|
||||
on: {
|
||||
'Set selection': {
|
||||
target: 'idle',
|
||||
internal: true,
|
||||
actions: 'Set selection',
|
||||
},
|
||||
|
||||
'Deselect point': {
|
||||
target: 'idle',
|
||||
internal: true,
|
||||
actions: [
|
||||
'Remove from code-based selection',
|
||||
'Update code selection cursors',
|
||||
// 'Engine: remove highlight',
|
||||
],
|
||||
cond: 'Selection contains point',
|
||||
},
|
||||
|
||||
'Deselect edge': {
|
||||
target: 'idle',
|
||||
internal: true,
|
||||
actions: [
|
||||
'Remove from code-based selection',
|
||||
'Update code selection cursors',
|
||||
// 'Engine: remove highlight',
|
||||
],
|
||||
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': {
|
||||
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',
|
||||
actions: [
|
||||
'set sketch metadata',
|
||||
'sketch mode enabled',
|
||||
'edit mode enter',
|
||||
],
|
||||
},
|
||||
'Sketch no 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',
|
||||
},
|
||||
|
||||
'extrude intent': [
|
||||
{
|
||||
target: 'awaiting selection',
|
||||
cond: 'has no selection',
|
||||
},
|
||||
{
|
||||
target: 'idle',
|
||||
cond: 'has valid extrude selection',
|
||||
internal: true,
|
||||
actions: 'AST extrude',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
|
||||
Sketch: {
|
||||
states: {
|
||||
SketchIdle: {
|
||||
on: {
|
||||
'Select point': {
|
||||
target: 'SketchIdle',
|
||||
internal: true,
|
||||
actions: [
|
||||
'Update code selection cursors',
|
||||
'Add to code-based selection',
|
||||
],
|
||||
},
|
||||
|
||||
'Select segment': {
|
||||
target: 'SketchIdle',
|
||||
internal: true,
|
||||
actions: [
|
||||
'Update code selection cursors',
|
||||
'Add to code-based selection',
|
||||
],
|
||||
},
|
||||
|
||||
'Deselect point': {
|
||||
target: 'SketchIdle',
|
||||
internal: true,
|
||||
cond: 'Selection contains point',
|
||||
actions: [
|
||||
'Update code selection cursors',
|
||||
'Add to code-based selection',
|
||||
],
|
||||
},
|
||||
|
||||
'Deselect segment': {
|
||||
target: 'SketchIdle',
|
||||
internal: true,
|
||||
cond: 'Selection contains line',
|
||||
actions: [
|
||||
'Update code selection cursors',
|
||||
'Add to code-based selection',
|
||||
],
|
||||
},
|
||||
|
||||
'Equip tool': {
|
||||
target: 'Line Tool',
|
||||
actions: 'set tool line',
|
||||
},
|
||||
|
||||
'Equip move tool': 'Move Tool',
|
||||
|
||||
'Set selection': {
|
||||
target: 'SketchIdle',
|
||||
internal: true,
|
||||
actions: 'Set selection',
|
||||
},
|
||||
|
||||
'Make segment vertical': {
|
||||
cond: 'Can make selection vertical',
|
||||
target: 'SketchIdle',
|
||||
internal: true,
|
||||
actions: ['Make selection vertical'],
|
||||
},
|
||||
|
||||
'Make segment horizontal': {
|
||||
target: 'SketchIdle',
|
||||
internal: true,
|
||||
cond: 'Can make selection horizontal',
|
||||
actions: ['Make selection horizontal'],
|
||||
},
|
||||
|
||||
'Constrain horizontal distance': {
|
||||
target: 'Await horizontal distance info',
|
||||
cond: 'Can constrain horizontal distance',
|
||||
},
|
||||
|
||||
'Constrain vertical distance': {
|
||||
target: 'Await vertical distance info',
|
||||
cond: 'Can constrain vertical distance',
|
||||
},
|
||||
|
||||
'Constrain angle': {
|
||||
target: 'Await angle info',
|
||||
cond: 'Can constrain angle',
|
||||
},
|
||||
|
||||
'Constrain length': {
|
||||
target: 'Await length info',
|
||||
cond: 'Can constrain length',
|
||||
},
|
||||
|
||||
'Constrain horizontally align': {
|
||||
cond: 'Can constrain horizontally align',
|
||||
target: 'SketchIdle',
|
||||
internal: true,
|
||||
actions: ['Constrain horizontally align'],
|
||||
},
|
||||
|
||||
'Constrain vertically align': {
|
||||
cond: 'Can constrain vertically align',
|
||||
target: 'SketchIdle',
|
||||
internal: true,
|
||||
actions: ['Constrain vertically align'],
|
||||
},
|
||||
|
||||
'Constrain equal length': {
|
||||
cond: 'Can constrain equal length',
|
||||
target: 'SketchIdle',
|
||||
internal: true,
|
||||
actions: ['Constrain equal length'],
|
||||
},
|
||||
},
|
||||
|
||||
entry: 'equip select',
|
||||
},
|
||||
|
||||
'Line Tool': {
|
||||
states: {
|
||||
Done: {
|
||||
type: 'final',
|
||||
},
|
||||
|
||||
'Point Added': {
|
||||
on: {
|
||||
'Add point': {
|
||||
target: 'Segment Added',
|
||||
actions: ['AST start new sketch'],
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
'Segment Added': {
|
||||
on: {
|
||||
'Add point': {
|
||||
target: 'Segment Added',
|
||||
internal: true,
|
||||
actions: ['AST add line segment'],
|
||||
},
|
||||
|
||||
'Complete line': {
|
||||
target: 'Done',
|
||||
actions: ['Modify AST', 'Update code selection cursors'],
|
||||
},
|
||||
|
||||
'Equip new tool': {
|
||||
target: 'Segment Added',
|
||||
internal: true,
|
||||
actions: 'set tool',
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
Init: {
|
||||
always: [
|
||||
{
|
||||
target: 'Segment Added',
|
||||
cond: 'is editing existing sketch',
|
||||
},
|
||||
'No Points',
|
||||
],
|
||||
},
|
||||
|
||||
'No Points': {
|
||||
on: {
|
||||
'Add point': 'Point Added',
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
// invoke: [
|
||||
// {
|
||||
// src: 'createLine',
|
||||
// id: 'Create line',
|
||||
// onDone: 'SketchIdle',
|
||||
// },
|
||||
// ],
|
||||
initial: 'Init',
|
||||
|
||||
on: {
|
||||
'Equip move tool': 'Move Tool',
|
||||
},
|
||||
},
|
||||
|
||||
'Move Tool': {
|
||||
entry: 'set tool move',
|
||||
},
|
||||
|
||||
'Await horizontal distance info': {
|
||||
invoke: {
|
||||
src: 'Get horizontal info',
|
||||
id: 'get-horizontal-info',
|
||||
onDone: {
|
||||
target: 'SketchIdle',
|
||||
actions: 'Set selection',
|
||||
},
|
||||
onError: 'SketchIdle',
|
||||
},
|
||||
},
|
||||
|
||||
'Await vertical distance info': {
|
||||
invoke: {
|
||||
src: 'Get vertical info',
|
||||
id: 'get-vertical-info',
|
||||
onDone: {
|
||||
target: 'SketchIdle',
|
||||
actions: 'Set selection',
|
||||
},
|
||||
onError: 'SketchIdle',
|
||||
},
|
||||
},
|
||||
|
||||
'Await angle info': {
|
||||
invoke: {
|
||||
src: 'Get angle info',
|
||||
id: 'get-angle-info',
|
||||
onDone: {
|
||||
target: 'SketchIdle',
|
||||
actions: 'Set selection',
|
||||
},
|
||||
onError: 'SketchIdle',
|
||||
},
|
||||
},
|
||||
|
||||
'Await length info': {
|
||||
invoke: {
|
||||
src: 'Get length info',
|
||||
id: 'get-length-info',
|
||||
onDone: {
|
||||
target: 'SketchIdle',
|
||||
actions: 'Set selection',
|
||||
},
|
||||
onError: 'SketchIdle',
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
initial: 'SketchIdle',
|
||||
|
||||
on: {
|
||||
CancelSketch: '.SketchIdle',
|
||||
},
|
||||
|
||||
exit: 'sketch exit execute',
|
||||
},
|
||||
|
||||
'Sketch no face': {
|
||||
entry: 'show default planes',
|
||||
|
||||
exit: 'hide default planes',
|
||||
on: {
|
||||
'Select default plane': {
|
||||
target: 'Sketch',
|
||||
actions: [
|
||||
'reset sketch metadata',
|
||||
'set default plane id',
|
||||
'sketch mode enabled',
|
||||
'create path',
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
'awaiting selection': {
|
||||
on: {
|
||||
'Set selection': {
|
||||
target: 'checking selection',
|
||||
actions: 'Set selection',
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
'checking selection': {
|
||||
always: [
|
||||
{
|
||||
target: 'idle',
|
||||
cond: 'has valid extrude selection',
|
||||
actions: 'AST extrude',
|
||||
},
|
||||
{
|
||||
target: 'idle',
|
||||
actions: 'toast extrude failed',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
|
||||
initial: 'idle',
|
||||
|
||||
on: {
|
||||
Cancel: {
|
||||
target: 'idle',
|
||||
// TODO what if we're existing extrude equiped, should these actions still be fired?
|
||||
// mabye cancel needs to have a guard for if else logic?
|
||||
actions: [
|
||||
'edit_mode_exit',
|
||||
'default_camera_disable_sketch_mode',
|
||||
'reset sketch metadata',
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
guards: {
|
||||
'is editing existing sketch': ({ sketchPathToNode }) =>
|
||||
!!sketchPathToNode,
|
||||
'Can make selection horizontal': ({ selectionRanges }) =>
|
||||
horzVertInfo(selectionRanges, 'horizontal').enabled,
|
||||
'Can make selection vertical': ({ selectionRanges }) =>
|
||||
horzVertInfo(selectionRanges, 'vertical').enabled,
|
||||
'Can constrain horizontal distance': ({ selectionRanges }) =>
|
||||
horzVertDistanceInfo({ selectionRanges, constraint: 'setHorzDistance' })
|
||||
.enabled,
|
||||
'Can constrain vertical distance': ({ selectionRanges }) =>
|
||||
horzVertDistanceInfo({ selectionRanges, constraint: 'setVertDistance' })
|
||||
.enabled,
|
||||
'Can constrain angle': ({ selectionRanges }) =>
|
||||
angleBetweenInfo({ selectionRanges }).enabled,
|
||||
'Can constrain length': ({ selectionRanges }) =>
|
||||
setAngleLengthInfo({ selectionRanges }).enabled,
|
||||
'Can constrain horizontally align': ({ selectionRanges }) =>
|
||||
horzVertDistanceInfo({ selectionRanges, constraint: 'setHorzDistance' })
|
||||
.enabled,
|
||||
'Can constrain vertically align': ({ selectionRanges }) =>
|
||||
horzVertDistanceInfo({ selectionRanges, constraint: 'setHorzDistance' })
|
||||
.enabled,
|
||||
'Can constrain equal length': ({ selectionRanges }) =>
|
||||
setEqualLengthInfo({ selectionRanges }).enabled,
|
||||
'has no selection': ({ selectionRanges }) => {
|
||||
if (selectionRanges?.codeBasedSelections?.length < 1) return true
|
||||
const selection = selectionRanges?.codeBasedSelections?.[0] || {}
|
||||
|
||||
return (
|
||||
selectionRanges.codeBasedSelections.length === 1 &&
|
||||
!hasExtrudeSketchGroup({
|
||||
ast: kclManager.ast,
|
||||
programMemory: kclManager.programMemory,
|
||||
selection,
|
||||
})
|
||||
)
|
||||
},
|
||||
'has valid extrude selection': ({ selectionRanges }) => {
|
||||
if (selectionRanges.codeBasedSelections.length !== 1) return false
|
||||
const isSketchPipe = isCursorInSketchCommandRange(
|
||||
engineCommandManager.artifactMap,
|
||||
selectionRanges
|
||||
)
|
||||
const common = {
|
||||
selection: selectionRanges.codeBasedSelections[0],
|
||||
ast: kclManager.ast,
|
||||
}
|
||||
const hasClose = doesPipeHaveCallExp({ calleeName: 'close', ...common })
|
||||
const hasExtrude = doesPipeHaveCallExp({
|
||||
calleeName: 'extrude',
|
||||
...common,
|
||||
})
|
||||
return !!isSketchPipe && hasClose && !hasExtrude
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
'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: [],
|
||||
}),
|
||||
}),
|
||||
'sketch mode enabled': ({ sketchPlaneId }) => {
|
||||
engineCommandManager.sendSceneCommand({
|
||||
type: 'modeling_cmd_req',
|
||||
cmd_id: uuidv4(),
|
||||
cmd: {
|
||||
type: 'sketch_mode_enable',
|
||||
plane_id: sketchPlaneId,
|
||||
ortho: true,
|
||||
animated: !isReducedMotion(),
|
||||
},
|
||||
})
|
||||
},
|
||||
'edit mode enter': ({ selectionRanges }) => {
|
||||
const pathId = isCursorInSketchCommandRange(
|
||||
engineCommandManager.artifactMap,
|
||||
selectionRanges
|
||||
)
|
||||
pathId &&
|
||||
engineCommandManager.sendSceneCommand({
|
||||
type: 'modeling_cmd_req',
|
||||
cmd_id: uuidv4(),
|
||||
cmd: {
|
||||
type: 'edit_mode_enter',
|
||||
target: pathId,
|
||||
},
|
||||
})
|
||||
},
|
||||
'hide default planes': ({}) => {
|
||||
kclManager.hidePlanes()
|
||||
},
|
||||
edit_mode_exit: () =>
|
||||
engineCommandManager.sendSceneCommand({
|
||||
type: 'modeling_cmd_req',
|
||||
cmd_id: uuidv4(),
|
||||
cmd: { type: 'edit_mode_exit' },
|
||||
}),
|
||||
default_camera_disable_sketch_mode: () =>
|
||||
engineCommandManager.sendSceneCommand({
|
||||
type: 'modeling_cmd_req',
|
||||
cmd_id: uuidv4(),
|
||||
cmd: { type: 'default_camera_disable_sketch_mode' },
|
||||
}),
|
||||
'reset sketch metadata': assign({
|
||||
sketchPathToNode: null,
|
||||
sketchEnginePathId: '',
|
||||
sketchPlaneId: '',
|
||||
}),
|
||||
'set sketch metadata': assign(({ selectionRanges }) => {
|
||||
const sourceRange = selectionRanges.codeBasedSelections[0].range
|
||||
const sketchPathToNode = getNodePathFromSourceRange(
|
||||
kclManager.ast,
|
||||
sourceRange
|
||||
)
|
||||
const pipeExpression = getNodeFromPath<PipeExpression>(
|
||||
kclManager.ast,
|
||||
sketchPathToNode,
|
||||
'PipeExpression'
|
||||
).node
|
||||
if (pipeExpression.type !== 'PipeExpression') return {}
|
||||
const sketchCallExpression = pipeExpression.body.find(
|
||||
(e) =>
|
||||
e.type === 'CallExpression' && e.callee.name === 'startSketchOn'
|
||||
) as CallExpression
|
||||
if (!sketchCallExpression) return {}
|
||||
const firstArg = sketchCallExpression.arguments[0]
|
||||
let planeId = ''
|
||||
if (firstArg.type === 'Literal' && firstArg.value) {
|
||||
const planeStrCleaned = firstArg.value
|
||||
.toString()
|
||||
.toLowerCase()
|
||||
.replace('-', '')
|
||||
if (
|
||||
planeStrCleaned === 'xy' ||
|
||||
planeStrCleaned === 'xz' ||
|
||||
planeStrCleaned === 'yz'
|
||||
) {
|
||||
planeId = kclManager.getPlaneId(planeStrCleaned)
|
||||
}
|
||||
}
|
||||
|
||||
console.log('planeId', planeId)
|
||||
|
||||
const sketchEnginePathId =
|
||||
isCursorInSketchCommandRange(
|
||||
engineCommandManager.artifactMap,
|
||||
selectionRanges
|
||||
) || ''
|
||||
return {
|
||||
sketchPathToNode,
|
||||
sketchEnginePathId,
|
||||
sketchPlaneId: planeId,
|
||||
}
|
||||
}),
|
||||
'set tool line': () =>
|
||||
engineCommandManager.sendSceneCommand({
|
||||
type: 'modeling_cmd_req',
|
||||
cmd_id: uuidv4(),
|
||||
cmd: {
|
||||
type: 'set_tool',
|
||||
tool: 'sketch_line',
|
||||
},
|
||||
}),
|
||||
'equip select': () =>
|
||||
engineCommandManager.sendSceneCommand({
|
||||
type: 'modeling_cmd_req',
|
||||
cmd_id: uuidv4(),
|
||||
cmd: {
|
||||
type: 'set_tool',
|
||||
tool: 'select',
|
||||
},
|
||||
}),
|
||||
'set tool move': () =>
|
||||
engineCommandManager.sendSceneCommand({
|
||||
type: 'modeling_cmd_req',
|
||||
cmd_id: uuidv4(),
|
||||
cmd: {
|
||||
type: 'set_tool',
|
||||
tool: 'move',
|
||||
},
|
||||
}),
|
||||
'Make selection horizontal': ({ selectionRanges }) => {
|
||||
const { modifiedAst, pathToNodeMap } = applyConstraintHorzVert(
|
||||
selectionRanges,
|
||||
'horizontal',
|
||||
kclManager.ast,
|
||||
kclManager.programMemory
|
||||
)
|
||||
kclManager.updateAst(modifiedAst, true, {
|
||||
// TODO re implement cursor shit
|
||||
// callBack: updateCursors(setCursor, selectionRanges, pathToNodeMap),
|
||||
})
|
||||
},
|
||||
'Make selection vertical': ({ selectionRanges }) => {
|
||||
const { modifiedAst, pathToNodeMap } = applyConstraintHorzVert(
|
||||
selectionRanges,
|
||||
'vertical',
|
||||
kclManager.ast,
|
||||
kclManager.programMemory
|
||||
)
|
||||
kclManager.updateAst(modifiedAst, true, {
|
||||
// TODO re implement cursor shit
|
||||
// callBack: updateCursors(setCursor, selectionRanges, pathToNodeMap),
|
||||
})
|
||||
},
|
||||
'Constrain horizontally align': ({ selectionRanges }) => {
|
||||
const { modifiedAst, pathToNodeMap } = applyConstraintHorzVertAlign({
|
||||
selectionRanges,
|
||||
constraint: 'setVertDistance',
|
||||
})
|
||||
kclManager.updateAst(modifiedAst, true, {
|
||||
// TODO re implement cursor shit
|
||||
// callBack: updateCursors(setCursor, selectionRanges, pathToNodeMap),
|
||||
})
|
||||
},
|
||||
'Constrain vertically align': ({ selectionRanges }) => {
|
||||
const { modifiedAst, pathToNodeMap } = applyConstraintHorzVertAlign({
|
||||
selectionRanges,
|
||||
constraint: 'setHorzDistance',
|
||||
})
|
||||
kclManager.updateAst(modifiedAst, true, {
|
||||
// TODO re implement cursor shit
|
||||
// callBack: updateCursors(setCursor, selectionRanges, pathToNodeMap),
|
||||
})
|
||||
},
|
||||
'Constrain equal length': ({ selectionRanges }) => {
|
||||
const { modifiedAst, pathToNodeMap } = applyConstraintEqualLength({
|
||||
selectionRanges,
|
||||
})
|
||||
kclManager.updateAst(modifiedAst, true, {
|
||||
// TODO re implement cursor shit
|
||||
// callBack: updateCursors(setCursor, selectionRanges, pathToNodeMap),
|
||||
})
|
||||
},
|
||||
'AST extrude': ({ selectionRanges }) => {
|
||||
const pathToNode = getNodePathFromSourceRange(
|
||||
kclManager.ast,
|
||||
selectionRanges.codeBasedSelections[0].range
|
||||
)
|
||||
const { modifiedAst, pathToExtrudeArg } = extrudeSketch(
|
||||
kclManager.ast,
|
||||
pathToNode
|
||||
)
|
||||
// TODO not handling focusPath correctly I think
|
||||
kclManager.updateAst(modifiedAst, true, {
|
||||
focusPath: pathToExtrudeArg,
|
||||
})
|
||||
},
|
||||
'set default plane id': assign({
|
||||
sketchPlaneId: (_, { data }) => data.planeId,
|
||||
}),
|
||||
},
|
||||
}
|
||||
)
|
Reference in New Issue
Block a user