2023-10-11 13:36:54 +11:00
import { PathToNode } from 'lang/wasm'
import { engineCommandManager } from 'lang/std/engineConnection'
import { isReducedMotion } from 'lang/util'
2023-10-16 21:20:05 +11:00
import {
Axis ,
Selection ,
SelectionRangeTypeMap ,
Selections ,
} from 'lib/selections'
2023-10-11 13:36:54 +11:00
import { assign , createMachine } from 'xstate'
import { v4 as uuidv4 } from 'uuid'
2023-10-11 15:12:29 +11:00
import { isCursorInSketchCommandRange } from 'lang/util'
2023-10-11 13:36:54 +11:00
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'
2023-12-01 20:18:51 +11:00
import { angleLengthInfo } from 'components/Toolbar/setAngleLength'
2023-10-11 13:36:54 +11:00
import {
applyConstraintEqualLength ,
setEqualLengthInfo ,
} from 'components/Toolbar/EqualLength'
import { extrudeSketch } from 'lang/modifyAst'
import { getNodeFromPath } from '../lang/queryAst'
import { CallExpression , PipeExpression } from '../lang/wasm'
2023-10-14 03:47:46 +11:00
import { getConstraintLevelFromSourceRange } from 'lang/std/sketchcombos'
2023-10-16 08:54:38 +11:00
import {
applyConstraintEqualAngle ,
equalAngleInfo ,
} from 'components/Toolbar/EqualAngle'
import {
applyRemoveConstrainingValues ,
removeConstrainingValuesInfo ,
} from 'components/Toolbar/RemoveConstrainingValues'
import { intersectInfo } from 'components/Toolbar/Intersect'
2023-12-01 20:18:51 +11:00
import {
absDistanceInfo ,
applyConstraintAxisAlign ,
} from 'components/Toolbar/SetAbsDistance'
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 { ModelingCommandSchema } from 'lib/commandBarConfigs/modelingCommandConfig'
2023-10-11 13:36:54 +11:00
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
}
2023-10-16 21:20:05 +11:00
export type ModelingMachineEvent =
| { 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
segmentId? : string
}
}
| { 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' }
2023-12-01 20:18:51 +11:00
| { type : 'Constrain ABS X' }
| { type : 'Constrain ABS Y' }
2023-10-16 21:20:05 +11:00
| { type : 'Constrain vertical distance' }
| { type : 'Constrain angle' }
| { type : 'Constrain perpendicular distance' }
| { type : 'Constrain horizontally align' }
| { type : 'Constrain vertically align' }
2023-12-01 20:18:51 +11:00
| { type : 'Constrain snap to X' }
| { type : 'Constrain snap to Y' }
2023-10-16 21:20:05 +11:00
| { type : 'Constrain length' }
| { type : 'Constrain equal length' }
| { type : 'Constrain parallel' }
| { type : 'Constrain remove constraints' }
2023-10-18 08:03:02 +11:00
| { type : 'Re-execute' }
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
| { type : 'Extrude' ; data? : ModelingCommandSchema [ 'Extrude' ] }
2023-10-16 21:20:05 +11:00
2023-10-11 13:36:54 +11:00
export const modelingMachine = createMachine (
{
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
/ * * @ x s t a t e - l a y o u t N 4 I g p g J g 5 m D O I C 5 Q F k D 2 E w B s C W A 7 K A x A M I C G u A x l g N o A M A u o q A A 6 q z Y A u 2 q u j I A H o g D M A V g D s A O m E i A j L M G C A H I I A s A J l H K A N C A C e i a Q D Z B E s c t G r V A T m m i a N Q Q F 8 H 2 t B h z 4 C A Z T D s A B L C w w c k 5 u W g Y k E B Y 2 E J 4 I g Q R p Z W F p c Q V L e 1 V 7 S w V b Y U t t P Q R B R M t x Z U t l G k t 0 w V V p B T M n F 3 Q s P C h x b A h M M C 8 f f 0 D g r l w w 3 i i O I d 5 4 p I V x e 2 l V Y S N L D U F l g v 1 V A x S D U W E 0 w Q M 0 w w 0 m k F d W - A 6 u n o A R O A G - F j x 2 E Y i x m M m h A 2 F J G l E F P 7 K J L C Z Q A 4 T r B L S R T i T a W A w G Z Q i N R W V S n c 7 u d q d b o E O 4 B b r B X y Q G C v Z i s c b c T 5 F e G z f 5 Q 2 z K b 5 m N a 6 f Q 0 R K p I y I 4 R s y x W e Z o l o Y q 7 Y 3 E P X w k P j Y W A k y J k j 5 x I T m c S 7 O x V C y i b 4 H A w Q o 5 l M S Z R Y N E S O Z x n Q V t Y U 9 b z 4 x 6 o Z 4 y 9 4 T B U I S o - Y 7 V Y r Z Z a G b U s l 2 Z M o A 0 S e 1 S C N l Q g V u C 1 Y q 1 i o l g B 1 y p 2 g K Y 0 G a g x F p B S M 5 m F B H K c T 5 h T S P 5 Q k H K a S R i 6 Y 6 6 9 G 3 i y X S + i j J M U 5 2 I 1 S F q q r B Y 8 m g G f J + k E z a T W A f C O p J Q 4 m 5 p R y 4 x u t B P w A M x I l E T 0 W T - E Q l R m B j s a g O Y c s Y e k E I 1 g l S c O k e 3 3 h 1 2 C i r Q o X A F F c O w w A A n f w A a x 8 5 A A C w 3 c l Y h T f R E h S C o E V H C t j F W U Q I V D A s t m W R Y 8 j y B Q p G U J 9 o 1 r N 8 P 2 - W A - 3 Y Q C q G k c J S U 3 N s w I Q a d l W L b 0 7 F U Y t w T 9 N Q a E L H J 4 I Z E t z F R U 1 0 V w k V 7 n r V d 1 2 b N 5 W 1 A 7 c i l s Q t a g U d R V j 2 D R f U K U 9 x G M E 8 l j U R S B x w + d a 2 t J d x U w T B g P l G j Y J h T Y x A a T I a G E J z E J o A t e Q M V Q M 0 z Z I a H 4 2 d q 0 t H E R J M k g z I s r d 4 k U F I G V B L T f N k N T E G L S Q H L m B p E n 3 G c z T n G t s R f P h 2 E - A B X D B w u o m T 0 s 0 n J 0 k y W x j C k C F E i S G z b G L U R D H m L Y D P a T x i M A 4 g y E o T B e v - I C J M o k D K R s S p Z j U b k N F c t l 1 A h C p L 1 2 K R k g W K F L D E b r x B G k i A P 2 v q A I A S S M s U n n f M r p P i e p q n E a x R H M K Q S y M V j C l B D i F v q V Y G n a 1 y 9 o O w D j t G 8 7 s W M g k A i g A B b M B r v G 2 U q N u - Q 0 l K J 6 X u K f s k Q h F Q D E L c p N j S J z M j h I G T t B w 7 w d u Y K C S u l 5 E c d c q 7 s w - G K l k D Q F o s R D 6 m V J j N i x - t - k f A T z U u Y G j o l 6 m g r x E z o b h h G K K R y b n X q U E Y W D U c d i s a w P q S - H m I R a w q l k R y R H J 0 b K c A 6 W X w A R y K 7 A m F 8 d h U F Q c z G a k y k w 2 S T T b x L T I t g Z Q R z 3 3 c R 5 g a Y 2 - g B C s L c O q 2 z r w + 3 H d 8 G H U A A N z A Z 3 X f d p W m Z R o o 0 x S W p N n U V y K w a v 0 d o L I E t h B e w E U U 4 R Y 5 B q W L r 8 W X B l C D 3 k a m i o J H 3 Z 7 j B 9 Q 5 E o Q D U O P D 7 k B 1 q M R Z G b y W T u l 5 A S D - f p Y f h v w M 8 - T h y F C m 6 p p Y s O Q X e p C F D P h C - V k C s y j q b 5 9 0 w 4 o m 9 F n L 4 - j p e V 8 z + W N 9 8 A D U E - b A A B e 3 B 2 B 7 2 7 i r G i N h s i S A B D 2 e E B w r B 6 w S F k Q s O x 5 B 1 C U L e U Q 8 8 3 6 1 i I N w W A h U S B 4 B - n - Q B w D Q q + A g F K E B F A E x g M s j J G w u w u w C x s E 5 U 8 P M x C P X v J 5 G K G C R b + S F B L H B 2 I 8 G 4 A I Z + I h u B f B b x 3 h Q q h B D B p 0 N z p 7 V W o h 0 i S C h D Y E Q g d 4 Q u R E G U Y w u 5 - h W D P g I 7 K A V h G t 1 E f g w h x C A C C A A h T w v g A A a + 9 V Y A j Z s s J Q h x k i o I U I h d q + M c i q k q M U A c O x s H W J 6 G I i R U j f B O J c Q A T Q 8 R A r x q R f J e Q O P Y R S i F M I c S M D k X Y g c G R Y O f p Y i m M T i C 2 M k c Q s g U B u h p M Y d m N y Q I b y u W y I s P 4 i F Y R h 3 a g C G w H k J x Z U E u L K p i 9 c G 1 I S d 0 f A 7 A x o q J 7 p 4 v Y j 0 F g n h L B O A c w Z E K K E K X p C s O 1 H I G G i Z M m x 4 i 7 H S K Y F + K 5 u A q H k C K p g E g 3 4 F E 0 P E o s 8 B j C V S z D y J y Y u n l Q y I T E P j I w x Q 6 j B j Z O 1 E 5 Y M p n n L q d I 3 + - 8 g H v l C p g H Q p l s B Q G G P Q i K + h - g h L D O o Z i c I i a I P m E C M o 0 0 T E A i q O U K F V M Y X x O I b I 7 A u 8 z J o t C h i r F 7 y G E s 3 s G U V y 8 J b D a z E I 1 Y 0 y o r 4 o h E M k b M d L r Y M o u f 4 X A J A n Y u z c c 0 l m x g Y R S r h B O S O g T L 7 P Q 4 i o c w 3 o 9 j h P M W M n q E z o V n M Z d I 2 A S q V W o F 8 K k 7 F z N U a a t c s W R y z F 1 H f E H I U e o z C d j 2 E W A y a o Z M K l C O t f S 2 1 C q w D 2 w o b M q A 8 z 1 W o x s I G O + L 0 t g 3 i 0 J f a Y k h k g n n 7 C b O w o y x Z W s t t U u J C q m B P J R d Q N 1 + d 6 j c k e h U A 5 T V 1 A B v 0 P C N 0 I J 1 E L A 7 K s Y 5 U a L R W N O b E 6 Z x D P x g F T h n X w 5 A p 3 v i b N y n F C R n q d j N Z 5 R Q I g e T 6 s D U 5 U o U J M L c i 6 V s Z 6 s q E 7 Y g A E p g A A L R g D 4 E E I q H 4 0 0 J G K W H e w 7 V n q s x s K o C E W w O I 8 S z H U b S 6 j s E A B k 8 C Z w A C r Z w I H b B 2 T s 5 2 Z x d m 7 N 9 8 g z 6 S B M U 5 U c e w M r n i U J + q e j 8 8 j P W w q O 8 Z l s o O 4 F g - B 2 9 D 6 n 3 3 N f U 2 r 2 i 0 C Z 4 Z y J h I V E I 8 i z H S N m P Y O 1 I k x 0 o 5 W u O N G 6 N u 3 E A A B T t O + R J E A M A Q A I P Y p T v h 6 Y Y Y F V V H a D 8 P J q C B L x t k Y c E R s h y C C L p U h I P Q d 8 H B 6 T 3 h 1 4 K b U 8 p 1 T 6 n N O s e d A p b Y 2 R x 7 y D s P C f d O 5 Q w 3 3 0 3 f e o 8 x N j W d o 7 Z 7 O + 0 w C O b 8 M 5 y A N S Y Z M G 6 B + X w 7 h l E t i W T R P G E g C m D 2 m L y R B o I R w 5 H a f S K w t K x O v 0 k z F + z 8 W F a J a U 8 l x D y d a M A H c s 7 o Y 8 3 l 0 u M J 6 g j 1 8 n C O E u N e a j n Z s k Y 9 V c o t S c w O I U 6 u A O A E D f Z 5 U c N I p X t T D T e A D f L + z c Y G R 0 - s c 2 G s L a W y t s i q 7 3 U I F D A 9 N U Y Y - o H B B L x z Y m l 0 h 7 F 1 X 8 P 4 I 7 B F j o p v V u z C 2 A B y z q 5 P P F g K 5 i A G n 5 M M 2 u - n d Q A 5 H r z G e j t K w a p X s F k S I 5 d I N Q b w 5 G w W g e d Q P e j t w e E M D D g q 2 1 + Y F k k d I F 9 C g a B + I i f c - Z 1 l c Q o 3 9 q j c c i f z Y I A x x 9 z 6 W P w 6 9 k a f p 8 g B O H H r u e X m o J D Z 2 A n B Y S L t X h G 8 7 O + I N X e B L t 9 Z k i I D R w Y L B b C J W y P N g b + z A r h P 2 c J i R V i c 4 s d G y 2 a u g c a - T p n L X 7 B V v k R y x 8 y K o I 3 S e j M E T a w v J G r z F K I s V Y q w S g g i s I T 1 3 6 v N f L Y 9 1 Q V Q I v P N 7 B m G k D y x h P L 1 3 s K H j R I 8 W K F y 0 e W l + w j 7 G d a I X 4 B F Z D k W Y E o d Q p R v g 8 D L l Q A Q C A 3 A w A d F w G n V A f 5 x A w H Y H e 2 v S K Q G Y D v a 3 1 A a 2 9 K z C F h E z K t 4 e b J Q 1 P u M w 0 1 l i R q 5 + J k G l f q 8 k M R e Q h v L z m 9 T 4 I F + T 8 f 9 x B p Z I O w N v n 4 Y a D 5 8 C P 0 h Y - Q q T 9 w G 3 m f b 2 d h m D Q V m x I H m R E R 6 K Q R S L k B o I 0 b B P f D g G R L 8 O R Y - J v W h F v T - d v T v W j H v P v A f I f O 9 Z l V l D - L - H X e I Z i e Q Q s b I K E C w c z D Q F y Z q Y W M w L Y R Q Y m K A q v G A 3 A + R R A y g Z A t v c - T 8 S - T 8 a - R 5 O - P + R - b A 1 g i f K f G f F Q T S e E Q u K o D y O o R B B y A s K O P S W 3 c M J + b f V + a A x L Z x N x T g 1 A r v D A - v b v b A k g A A I 1 g D v T 4 H w O n 0 I M Q G I J m G L l q A r G D G v C C U 8 m + Q O E q E z H N h V w p i 0 M S R 0 N c T 0 O 4 N 4 P 4 N v 3 v 2 E O f z M I s K s P E N s N u y U B m G q H Y l w z V G 7 V u x 2 B m H U C D X a h L E D y Y P 3 y S R d W C L Q O 7 z w E w O M K i P M L v R 0 G s I k I k D H D + H + H K H W k C w S K s A p T B W m G K X K Q 0 I r 2 Y O 0 J S W C I v y v x v 0 E I f y f 2 H 2 i J q L q P i P s O g X U T y C G 3 M H k E Q h K 0 e k U j P m G V s B 2 g K J g I a W 6 B K I M P K K M M m L v Q O P v T i L T x o n m O z E S F n h g Q U h 2 V 5 i N B e g 6 i W L 2 L 8 A u O G J 4 N G I E I i L O I u N m O u J k m Y h m k 2 C B G 5 F c h R x U F 6 X U V m E 2 H U T m m G U + M y 3 h h T Q A i O P Q J O K w O f 2 T X m W B O 9 x 5 T s N 8 T b W y P 3 A q D N U Q h r k e g 1 B B C h F - y R F R P x M x L P x G L 4 L G I B O w J Z M J M k l y 1 B K U H 7 j v G p T M Q 2 m p N
2023-10-11 13:36:54 +11:00
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 : {
2023-10-16 21:20:05 +11:00
events : { } as ModelingMachineEvent ,
2023-10-11 13:36:54 +11:00
} ,
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' ,
} ,
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
Extrude : {
target : 'idle' ,
cond : 'has valid extrude selection' ,
actions : [ 'AST extrude' ] ,
internal : true ,
} ,
2023-10-11 13:36:54 +11:00
} ,
} ,
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' ,
} ,
2023-12-01 20:18:51 +11:00
'Constrain ABS X' : {
target : 'Await ABS X info' ,
cond : 'Can constrain ABS X' ,
} ,
'Constrain ABS Y' : {
target : 'Await ABS Y info' ,
cond : 'Can constrain ABS Y' ,
} ,
2023-10-11 13:36:54 +11:00
'Constrain angle' : {
target : 'Await angle info' ,
cond : 'Can constrain angle' ,
} ,
'Constrain length' : {
target : 'Await length info' ,
cond : 'Can constrain length' ,
} ,
2023-10-16 08:54:38 +11:00
'Constrain perpendicular distance' : {
target : 'Await perpendicular distance info' ,
cond : 'Can constrain perpendicular distance' ,
} ,
2023-10-11 13:36:54 +11:00
'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' ] ,
} ,
2023-12-01 20:18:51 +11:00
'Constrain snap to X' : {
cond : 'Can constrain snap to X' ,
target : 'SketchIdle' ,
internal : true ,
actions : [ 'Constrain snap to X' ] ,
} ,
'Constrain snap to Y' : {
cond : 'Can constrain snap to Y' ,
target : 'SketchIdle' ,
internal : true ,
actions : [ 'Constrain snap to Y' ] ,
} ,
2023-10-11 13:36:54 +11:00
'Constrain equal length' : {
cond : 'Can constrain equal length' ,
target : 'SketchIdle' ,
internal : true ,
actions : [ 'Constrain equal length' ] ,
} ,
2023-10-16 08:54:38 +11:00
'Constrain parallel' : {
target : 'SketchIdle' ,
internal : true ,
cond : 'Can canstrain parallel' ,
actions : [ 'Constrain parallel' ] ,
} ,
'Constrain remove constraints' : {
target : 'SketchIdle' ,
internal : true ,
cond : 'Can constrain remove constraints' ,
actions : [ 'Constrain remove constraints' ] ,
} ,
2023-10-18 08:03:02 +11:00
'Re-execute' : {
target : 'SketchIdle' ,
internal : true ,
actions : [
'set sketchMetadata from pathToNode' ,
'sketch mode enabled' ,
'edit mode enter' ,
] ,
} ,
2023-10-11 13:36:54 +11:00
} ,
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' ,
2023-10-18 08:03:02 +11:00
'Re-execute' : {
target : 'Line Tool' ,
internal : true ,
actions : [
'set sketchMetadata from pathToNode' ,
'sketch mode enabled' ,
'edit mode enter' ,
] ,
} ,
2023-10-11 13:36:54 +11:00
} ,
} ,
'Move Tool' : {
entry : 'set tool move' ,
2023-10-14 03:47:46 +11:00
on : {
'Set selection' : {
target : 'Move Tool' ,
internal : true ,
actions : 'Set selection' ,
} ,
2023-10-18 08:03:02 +11:00
'Re-execute' : {
target : 'Move Tool' ,
internal : true ,
actions : [
'set sketchMetadata from pathToNode' ,
'sketch mode enabled' ,
'edit mode enter' ,
] ,
} ,
2023-10-14 03:47:46 +11:00
} ,
states : {
'Move init' : {
always : [
{
target : 'Move without re-execute' ,
cond : 'can move' ,
} ,
{
target : 'Move with execute' ,
cond : 'can move with execute' ,
} ,
'No move' ,
] ,
} ,
'Move without re-execute' : { } ,
'Move with execute' : { } ,
'No move' : { } ,
} ,
initial : 'Move init' ,
2023-10-11 13:36:54 +11:00
} ,
'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' ,
} ,
} ,
2023-12-01 20:18:51 +11:00
'Await ABS X info' : {
invoke : {
src : 'Get ABS X info' ,
id : 'get-abs-x-info' ,
onDone : {
target : 'SketchIdle' ,
actions : 'Set selection' ,
} ,
onError : 'SketchIdle' ,
} ,
} ,
'Await ABS Y info' : {
invoke : {
src : 'Get ABS Y info' ,
id : 'get-abs-y-info' ,
onDone : {
target : 'SketchIdle' ,
actions : 'Set selection' ,
} ,
onError : 'SketchIdle' ,
} ,
} ,
2023-10-11 13:36:54 +11:00
'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' ,
} ,
} ,
2023-10-16 08:54:38 +11:00
'Await perpendicular distance info' : {
invoke : {
src : 'Get perpendicular distance info' ,
id : 'get-perpendicular-distance-info' ,
onDone : {
target : 'SketchIdle' ,
actions : 'Set selection' ,
} ,
onError : 'SketchIdle' ,
} ,
} ,
2023-10-11 13:36:54 +11:00
} ,
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' ,
] ,
} ,
} ,
} ,
} ,
initial : 'idle' ,
on : {
Cancel : {
target : 'idle' ,
2023-11-01 17:34:54 -05:00
// TODO what if we're existing extrude equipped, should these actions still be fired?
// maybe cancel needs to have a guard for if else logic?
2023-10-11 13:36:54 +11:00
actions : [
'edit_mode_exit' ,
'default_camera_disable_sketch_mode' ,
'reset sketch metadata' ,
] ,
} ,
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
'Set selection' : {
target : '#Modeling' ,
internal : true ,
actions : 'Set selection' ,
} ,
2023-10-11 13:36:54 +11:00
} ,
} ,
{
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 ,
2023-12-01 20:18:51 +11:00
'Can constrain ABS X' : ( { selectionRanges } ) = >
absDistanceInfo ( { selectionRanges , constraint : 'xAbs' } ) . enabled ,
'Can constrain ABS Y' : ( { selectionRanges } ) = >
absDistanceInfo ( { selectionRanges , constraint : 'yAbs' } ) . enabled ,
2023-10-11 13:36:54 +11:00
'Can constrain angle' : ( { selectionRanges } ) = >
2023-12-01 20:18:51 +11:00
angleBetweenInfo ( { selectionRanges } ) . enabled ||
angleLengthInfo ( { selectionRanges , angleOrLength : 'setAngle' } ) . enabled ,
2023-10-11 13:36:54 +11:00
'Can constrain length' : ( { selectionRanges } ) = >
2023-12-01 20:18:51 +11:00
angleLengthInfo ( { selectionRanges } ) . enabled ,
2023-10-16 08:54:38 +11:00
'Can constrain perpendicular distance' : ( { selectionRanges } ) = >
intersectInfo ( { selectionRanges } ) . enabled ,
2023-10-11 13:36:54 +11:00
'Can constrain horizontally align' : ( { selectionRanges } ) = >
horzVertDistanceInfo ( { selectionRanges , constraint : 'setHorzDistance' } )
. enabled ,
'Can constrain vertically align' : ( { selectionRanges } ) = >
horzVertDistanceInfo ( { selectionRanges , constraint : 'setHorzDistance' } )
. enabled ,
2023-12-01 20:18:51 +11:00
'Can constrain snap to X' : ( { selectionRanges } ) = >
absDistanceInfo ( { selectionRanges , constraint : 'snapToXAxis' } ) . enabled ,
'Can constrain snap to Y' : ( { selectionRanges } ) = >
absDistanceInfo ( { selectionRanges , constraint : 'snapToYAxis' } ) . enabled ,
2023-10-11 13:36:54 +11:00
'Can constrain equal length' : ( { selectionRanges } ) = >
setEqualLengthInfo ( { selectionRanges } ) . enabled ,
2023-10-16 08:54:38 +11:00
'Can canstrain parallel' : ( { selectionRanges } ) = >
equalAngleInfo ( { selectionRanges } ) . enabled ,
'Can constrain remove constraints' : ( { selectionRanges } ) = >
removeConstrainingValuesInfo ( { selectionRanges } ) . enabled ,
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
// '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,
// })
// )
// },
2023-10-14 03:47:46 +11:00
'can move' : ( { selectionRanges } ) = >
// todo check all cursors are also in the right sketch
selectionRanges . codeBasedSelections . every (
( selection ) = >
getConstraintLevelFromSourceRange (
selection . range ,
kclManager . ast
) === 'free'
) ,
'can move with execute' : ( { selectionRanges } ) = >
// todo check all cursors are also in the right sketch
selectionRanges . codeBasedSelections . every ( ( selection ) = >
[ 'partial' , 'free' ] . includes (
getConstraintLevelFromSourceRange ( selection . range , kclManager . ast )
)
) ,
2023-10-11 13:36:54 +11:00
} ,
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 ( ) ,
} ,
} )
} ,
2023-10-18 08:03:02 +11:00
'set sketchMetadata from pathToNode' : assign ( ( { sketchPathToNode } ) = > {
if ( ! sketchPathToNode ) return { }
return getSketchMetadataFromPathToNode ( sketchPathToNode )
} ) ,
2023-10-11 13:36:54 +11:00
'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 ,
} ,
} )
} ,
2023-10-17 20:08:17 +11:00
'hide default planes' : ( ) = > {
2023-10-11 13:36:54 +11:00
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
)
2023-10-18 08:03:02 +11:00
return getSketchMetadataFromPathToNode (
2023-10-11 13:36:54 +11:00
sketchPathToNode ,
2023-10-18 08:03:02 +11:00
selectionRanges
)
2023-10-11 13:36:54 +11:00
} ) ,
'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' ,
} ,
} ) ,
2023-10-16 08:54:38 +11:00
// TODO implement source ranges for all of these constraints
// need to make the async like the modal constraints
2023-10-11 13:36:54 +11:00
'Make selection horizontal' : ( { selectionRanges } ) = > {
2023-11-01 07:39:31 -04:00
const { modifiedAst } = applyConstraintHorzVert (
2023-10-11 13:36:54 +11:00
selectionRanges ,
'horizontal' ,
kclManager . ast ,
kclManager . programMemory
)
2023-10-16 08:54:38 +11:00
kclManager . updateAst ( modifiedAst , true )
2023-10-11 13:36:54 +11:00
} ,
'Make selection vertical' : ( { selectionRanges } ) = > {
2023-11-01 07:39:31 -04:00
const { modifiedAst } = applyConstraintHorzVert (
2023-10-11 13:36:54 +11:00
selectionRanges ,
'vertical' ,
kclManager . ast ,
kclManager . programMemory
)
2023-10-16 08:54:38 +11:00
kclManager . updateAst ( modifiedAst , true )
2023-10-11 13:36:54 +11:00
} ,
'Constrain horizontally align' : ( { selectionRanges } ) = > {
2023-11-01 07:39:31 -04:00
const { modifiedAst } = applyConstraintHorzVertAlign ( {
2023-10-11 13:36:54 +11:00
selectionRanges ,
constraint : 'setVertDistance' ,
} )
2023-10-16 08:54:38 +11:00
kclManager . updateAst ( modifiedAst , true )
2023-10-11 13:36:54 +11:00
} ,
'Constrain vertically align' : ( { selectionRanges } ) = > {
2023-11-01 07:39:31 -04:00
const { modifiedAst } = applyConstraintHorzVertAlign ( {
2023-10-11 13:36:54 +11:00
selectionRanges ,
constraint : 'setHorzDistance' ,
} )
2023-10-16 08:54:38 +11:00
kclManager . updateAst ( modifiedAst , true )
2023-10-11 13:36:54 +11:00
} ,
2023-12-01 20:18:51 +11:00
'Constrain snap to X' : ( { selectionRanges } ) = > {
const { modifiedAst } = applyConstraintAxisAlign ( {
selectionRanges ,
constraint : 'snapToXAxis' ,
} )
kclManager . updateAst ( modifiedAst , true )
} ,
'Constrain snap to Y' : ( { selectionRanges } ) = > {
const { modifiedAst } = applyConstraintAxisAlign ( {
selectionRanges ,
constraint : 'snapToYAxis' ,
} )
kclManager . updateAst ( modifiedAst , true )
} ,
2023-10-11 13:36:54 +11:00
'Constrain equal length' : ( { selectionRanges } ) = > {
2023-11-01 07:39:31 -04:00
const { modifiedAst } = applyConstraintEqualLength ( {
2023-10-11 13:36:54 +11:00
selectionRanges ,
} )
2023-10-16 08:54:38 +11:00
kclManager . updateAst ( modifiedAst , true )
} ,
'Constrain parallel' : ( { selectionRanges } ) = > {
2023-11-01 07:39:31 -04:00
const { modifiedAst } = applyConstraintEqualAngle ( {
2023-10-16 08:54:38 +11:00
selectionRanges ,
} )
kclManager . updateAst ( modifiedAst , true )
} ,
'Constrain remove constraints' : ( { selectionRanges } ) = > {
2023-11-01 07:39:31 -04:00
const { modifiedAst } = applyRemoveConstrainingValues ( {
2023-10-16 08:54:38 +11:00
selectionRanges ,
2023-10-11 13:36:54 +11:00
} )
2023-10-16 08:54:38 +11:00
kclManager . updateAst ( modifiedAst , true )
2023-10-11 13:36:54 +11:00
} ,
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
'AST extrude' : ( _ , event ) = > {
if ( ! event . data ) return
const { selection , distance } = event . data
2023-10-11 13:36:54 +11:00
const pathToNode = getNodePathFromSourceRange (
kclManager . 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
selection . codeBasedSelections [ 0 ] . range
2023-10-11 13:36:54 +11:00
)
const { modifiedAst , pathToExtrudeArg } = extrudeSketch (
kclManager . 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
pathToNode ,
true ,
distance
2023-10-11 13:36:54 +11:00
)
// TODO not handling focusPath correctly I think
kclManager . updateAst ( modifiedAst , true , {
focusPath : pathToExtrudeArg ,
} )
} ,
'set default plane id' : assign ( {
sketchPlaneId : ( _ , { data } ) = > data . planeId ,
} ) ,
} ,
}
)
2023-10-18 08:03:02 +11:00
function getSketchMetadataFromPathToNode (
pathToNode : PathToNode ,
selectionRanges? : Selections
) {
const pipeExpression = getNodeFromPath < PipeExpression > (
kclManager . ast ,
pathToNode ,
'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 )
}
}
let sketchEnginePathId : string
if ( selectionRanges ) {
sketchEnginePathId =
isCursorInSketchCommandRange (
engineCommandManager . artifactMap ,
selectionRanges
) || ''
} else {
const _selectionRanges : Selections = {
otherSelections : [ ] ,
codeBasedSelections : [
{ range : [ pipeExpression . start , pipeExpression . end ] , type : 'default' } ,
] ,
}
sketchEnginePathId =
isCursorInSketchCommandRange (
engineCommandManager . artifactMap ,
_selectionRanges
) || ''
}
console . log ( 'returning:' , {
sketchPathToNode : pathToNode ,
sketchEnginePathId ,
sketchPlaneId : planeId ,
} )
return {
sketchPathToNode : pathToNode ,
sketchEnginePathId ,
sketchPlaneId : planeId ,
}
}