-
Notifications
You must be signed in to change notification settings - Fork 90
Point & Click GDT Datum #8909
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
base: main
Are you sure you want to change the base?
Point & Click GDT Datum #8909
Conversation
Introduces addDatumGdt to create a gdt::datum call for a selected face in the AST. Ensures only one face is annotated, updates the AST with tagged face, and appends the annotation at the end of the AST body.
Added unit tests for the addDatumGdt function to verify correct datum annotation on cap, wall, and chamfer faces. Tests ensure proper tagging and GDT annotation insertion for each face type.
Added tests to verify that addDatumGdt fails when multiple or no faces are selected, ensuring proper error handling for invalid face selection scenarios.
Adds a check to ensure the datum name is a single character in the addDatumGdt function. Returns an error if the validation fails to prevent invalid datum names.
Added tests to ensure addDatumGdt rejects multi-character and empty datum names, verifying that only single-character names are accepted and appropriate error messages are returned.
Introduces the 'GDT Datum' command to the modelingCommandConfig schema and command set. This command allows users to add datum geometric dimensioning & tolerancing annotations to selected faces, with configurable node, face selection, and name. Marked as experimental and requires review.
Introduces the prepareToEditGdtDatum function to handle editing of GDT Datum operations, extracting face and name arguments and providing default values. Updates stdLibMap to use the new callback for 'gdt::datum'.
Changed the 'gdt-datum' button to trigger the 'Find and select command' for 'GDT Datum' in the modeling group. Updated its status to 'experimental' and revised the description for clarity.
Introduces support for the 'GDT Datum' modeling command, including event type, handler, and state logic. This enables experimental application of datum GDTs in the modeling workflow.
Added validation logic. Refactored gdt::datum call construction to use module path and updated related code to remove unnecessary mock execution error skipping.
Added calls to enginelessExecutor in GDT datum annotation tests to validate runtime consistency after AST modification. This ensures that the modified ASTs execute correctly in the test context.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Introduces getUsedDatumNames and getNextAvailableDatumName functions to scan AST for used datum names and suggest the next available name. Integrates getNextAvailableDatumName into the command bar config for datum creation, ensuring default names do not conflict. Adds related tests for both AST utilities and command bar integration.
Relocated deduplicateFaceExprs, exprToKey, getUsedDatumNames, and getNextAvailableDatumName functions from earlier in the file to the end. No functional changes; improves code organization and readability.
Added a check to reject datum names containing double quotes in addDatumGdt. Updated tests to verify validation error is thrown for such names.
Added data attributes (data-1p-ignore, data-lpignore, data-form-type, data-bwignore) to the input element to prevent password managers and autofill extensions from interfering with command bar input.
Enhances the OperationItem component to display the datum name for 'gdt::datum' StdLibCall operations by extracting and formatting the 'name' argument from the code. This improves clarity when viewing GDT Datum operations in the feature tree.
The addDatumGdt function now supports optional parameters for framePosition, framePlane, fontPointSize, and fontScale. These allow more control over the feature control frame's display and annotation text, and variables for these arguments are inserted only when needed.
pierremtb
left a comment
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.
Works great in Vercel Preview, and thanks for the comprehensive demo and details ❤️
Just a few comments before I approve, not all of them are 100% needed to merge especially as an experimental command.
| data-1p-ignore | ||
| data-lpignore="true" | ||
| data-form-type="other" | ||
| data-bwignore |
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.
Oh wow you had your pw manager try to fill this up?
| it('should extract datum name from GDT datum operation', () => { | ||
| const mockCode = 'gdt::datum(face = extrude001, name = "A")' | ||
| // Calculate sourceRange positions dynamically | ||
| const nameStart = mockCode.indexOf('"A"') | ||
| const nameEnd = nameStart + 3 // Length of "A" including quotes | ||
| const nameSourceRange: [number, number, number] = [nameStart, nameEnd, 0] | ||
| const mockOperation = createGdtDatumOperation(nameSourceRange) | ||
|
|
||
| const valueDetail = getFeatureTreeValueDetail(mockOperation, mockCode) | ||
|
|
||
| expect(valueDetail?.display).toBe('A') | ||
| expect(valueDetail?.calculated).toEqual({ type: 'String', value: 'A' }) | ||
| }) |
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.
Should we add another test case for getFeatureTreeValueDetail about VariableDeclaration types?
| |> close() | ||
| extrude001 = extrude(profile001, length = 10)` | ||
| const ast = assertParse(code, instanceInThisFile) | ||
| const { getUsedDatumNames } = await import('@src/lang/modifyAst/gdt') |
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.
Let's move that import to the top?
| nodeToEdit?: PathToNode | ||
| }): Error | { modifiedAst: Node<Program>; pathToNode: PathToNode } { | ||
| // Clone the AST to avoid mutating the original | ||
| let modifiedAst = structuredClone(ast) |
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.
Let's also create a copied nodeToEdit here, so that mock exec doesn't mutate it.
const mNodeToEdit = structuredClone(nodeToEdit)
and then use it throughout. Check other codemods for ref!
| const faceSelections = faces.graphSelections.filter((selection) => | ||
| isFaceArtifact(selection.artifact) | ||
| ) |
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.
Don't mind the extra step here, just wondering why this isn't a guarantee from the command bar?
| if (typeof framePlane === 'string') { | ||
| // Named plane like 'XY', 'XZ', 'YZ' | ||
| framePlaneExpr = createLocalName(framePlane) | ||
| } else { | ||
| // Variable reference | ||
| framePlaneExpr = valueOrVariable(framePlane) | ||
| } |
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 know you mentioned it in the note, would likely be good to get a helper fn here
| // Add optional labeled arguments if provided | ||
| if (framePositionExpr !== undefined) { | ||
| labeledArgs.push(createLabeledArg('framePosition', framePositionExpr)) | ||
| } |
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 think I have a slight pref for the pattern at
modeling-app/src/lang/modifyAst/sweeps.ts
Lines 262 to 264 in 3a7f58d
| const sectionalExpr = sectional | |
| ? [createLabeledArg('sectional', createLiteral(sectional))] | |
| : [] |
| defaultValue: (commandBarContext) => { | ||
| return getNextAvailableDatumName(kclManager.ast) | ||
| }, |
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.
| defaultValue: (commandBarContext) => { | |
| return getNextAvailableDatumName(kclManager.ast) | |
| }, | |
| defaultValue: (_) => getNextAvailableDatumName(kclManager.ast), |
|
|
||
| // Extract name argument as a plain string (strip quotes if present) | ||
| const nameRaw = extractStringArgument(operation, 'name') | ||
| const name = nameRaw?.replace(/^["']|["']$/g, '') || '' |
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 think that regex should be part of a tested util fn?
| }: { | ||
| input: ModelingCommandSchema['GDT Datum'] | undefined | ||
| }) => { |
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.
Closes: #8577
datum-short.mp4
To do
Style Parameters Added:
src/lang/modifyAst/gdt.ts- code modsrc/lib/operations.ts- feature tree edit flowsrc/lib/commandBarConfigs/modelingCommandConfig.ts- review validationsrc/machines/modelingMachine.ts- event and statesrc/lib/toolbar.ts- icon and buttonsrc/components/layout/areas/FeatureTreePane.tsx- datum name is a valuegetValueDetail()src/components/CommandBar/CommandBarBasicInput.tsx- fixed 1Password interferencesrc/lang/modifyAst/gdt.spec.ts- unit testse2e/playwright/point-click.spec.ts- e2e testssrc/components/layout/areas/FeatureTreePane.spec.tsfeature tree test forgetValueDetail()Review Validation
similar to flatness, thanks @pierremtb
mockExecAstAndReportErrors()to validate generated codeQuote Stripping & Validation
The
|| ''fallback in operations.ts enforces validation:"A"from KCL + strips toA+ shows in UI''+ validation catches it with clear error messagedefaultValue: 'A'so UI always shows usable valueNotes for separate PR