-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hook up chamfer UI with AST-mod #4694
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -180,9 +180,14 @@ export const toolbarConfig: Record<ToolbarModeName, ToolbarMode> = { | |
}, | ||
{ | ||
id: 'chamfer', | ||
onClick: () => console.error('Chamfer not yet implemented'), | ||
onClick: ({ commandBarSend }) => | ||
commandBarSend({ | ||
type: 'Find and select command', | ||
data: { name: 'Chamfer', groupId: 'modeling' }, | ||
}), | ||
icon: 'chamfer3d', | ||
status: 'kcl-only', | ||
status: DEV ? 'available' : 'kcl-only', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Not specific to this PR, no change requested here) @franknoirot I think we might want to start checking against another variable than DEV here? Something that could resolve to true on app.zoo.dev and nightly builds, but not release builds. Seems to me that DEV might be a tad too restrictive here. But I could be wrong too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice! I’d be happy to follow this path for Overall, I think shipping semi-working features for nightly builds could be a good practice, as we have enough warning messages in place. Including the Command Bar UI warnings. We could add an extra indication for the buttons that are "nightly only". Besides, DEV blocks part of our team like Nick and Josh from checking and testing new stuff. On the other hand, it doesn’t fully align with the general rule: “Don’t ship shit.” : D There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like this idea, we should add another environment variable for this. @pierremtb would you be able to do that? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For sure! And should be a separate PR too There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Created #4709 |
||
disabled: (state) => !state.can({ type: 'Chamfer' }), | ||
title: 'Chamfer', | ||
hotkey: 'C', | ||
description: 'Bevel the edges of a 3D solid.', | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,7 @@ import { | |
} from 'lang/modifyAst' | ||
import { | ||
applyEdgeTreatmentToSelection, | ||
ChamferParameters, | ||
EdgeTreatmentType, | ||
FilletParameters, | ||
} from 'lang/modifyAst/addEdgeTreatment' | ||
|
@@ -262,6 +263,7 @@ export type ModelingMachineEvent = | |
| { type: 'Loft'; data?: ModelingCommandSchema['Loft'] } | ||
| { type: 'Revolve'; data?: ModelingCommandSchema['Revolve'] } | ||
| { type: 'Fillet'; data?: ModelingCommandSchema['Fillet'] } | ||
| { type: 'Chamfer'; data?: ModelingCommandSchema['Chamfer'] } | ||
| { type: 'Offset plane'; data: ModelingCommandSchema['Offset plane'] } | ||
| { type: 'Text-to-CAD'; data: ModelingCommandSchema['Text-to-CAD'] } | ||
| { | ||
|
@@ -768,6 +770,30 @@ export const modelingMachine = setup({ | |
// eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
codeManager.updateEditorWithAstAndWriteToFile(kclManager.ast) | ||
}, | ||
'AST chamfer': ({ event }) => { | ||
if (event.type !== 'Chamfer') return | ||
if (!event.data) return | ||
|
||
// Extract inputs | ||
const ast = kclManager.ast | ||
const { selection, length } = event.data | ||
const parameters: ChamferParameters = { | ||
type: EdgeTreatmentType.Chamfer, | ||
length, | ||
} | ||
|
||
// Apply chamfer to selection | ||
const applyEdgeTreatmentToSelectionResult = applyEdgeTreatmentToSelection( | ||
ast, | ||
selection, | ||
parameters | ||
) | ||
if (err(applyEdgeTreatmentToSelectionResult)) | ||
return applyEdgeTreatmentToSelectionResult | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're trying to prevent using these ESLint disabling comments in any new code. Would you mind converting this There is a fresh example here from Pierre's shell PR. As you can see, it requires adding a bit of extra code and another state for the machine to sit in while the async code runs. I'm happy to pair with you or do a video walkthrough of Pierre's code if you need! Then we can go back and refactor the Fillet code in another small PR. |
||
codeManager.updateEditorWithAstAndWriteToFile(kclManager.ast) | ||
}, | ||
'set selection filter to curves only': () => { | ||
;(async () => { | ||
await engineCommandManager.sendSceneCommand({ | ||
|
@@ -1637,6 +1663,13 @@ export const modelingMachine = setup({ | |
reenter: false, | ||
}, | ||
|
||
Chamfer: { | ||
target: 'idle', | ||
guard: 'has valid edge treatment selection', | ||
actions: ['AST chamfer'], | ||
reenter: false, | ||
}, | ||
|
||
Export: { | ||
target: 'idle', | ||
reenter: false, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[optional] we can come back and rewrite this test in our new fixture-based approach later, but since I'm already asking you to switch out the XState actor to an action I figure I'd give you a heads up on this one too.
Pierre has a good example of a Playwright test that uses our new fixture-based approach here in his Shell PR, and we're going to try to make any new tests use it, not least of all because Lee's work on migrating our tests to Electron uses it and then all our tests can run on both desktop and browser at-will.
I can show you how to rewrite this test in the new style if you need a hand or anything, although I think it would be pretty trivial for you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good poits, thanks. Is it ok if I'll do that in the following pr so I can tackle one thing at a time ? Then I can fix both chamfer and fillet in one batch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've seen Pierre's states too and was curious about it. Thanks for clarifying:)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@franknoirot I've created an issue for it (#4749). The current chamfer PR will wait until the older fillet code is updated to the latest XState requirements. Once that's done, I'll base current chamfer PR on the updated code so we don't mix everything into a single pull request.