Skip to content
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

Fix canExtrudeSelectionItem and getSelectionType for multiple selections #3884

Merged

Conversation

max-mrgrsk
Copy link
Collaborator

This pr closes: #3834
It is a part of bigger project: #2606

PR Description:

This PR addresses and fixes two key issues within the selection logic in the canExtrudeSelectionItem and getSelectionType functions. The previous implementation had limitations when handling multiple selections, resulting in incorrect selection typing and behavior for mixed sets of selections:

Example:
it would return: ['extrude-wall', 1] for a selection of single edge, which is correct
but for 2 edges it would return ['other', 2], which is incorrect and expected to be ['extrude-wall', 2]

Data Flow:

  1. getSelectionType uses canExtrudeSelectionItem to determine whether a selection is an extrude-wall or not, and passes the whole selection with all currently selected ranges stored in the selection.codeBasedSelections array and the index of the item that shall be checked.
  2. canExtrudeSelectionItem performs a triple check of the selected item with: isSketchPipe, nodeHasClose, and nodeHasExtrude.
  3. isSketchPipe does not have an index argument, only selection. It checks the selection with isSingleCursorInPipe and always returns false in the case of multiple selections. It has to be fixed.

Key Changes:

  1. Fixed canExtrudeSelectionItem:

    • The issue arose due to the function calling isSketchPipe, which is only capable of handling single selections.
    • The solution was to isolate each selection when calling isSketchPipe, ensuring it works correctly for each item in the selection list. This fix allows canExtrudeSelectionItem to return the correct result for each selection, even in cases where multiple selections are made.
  2. Improved getSelectionType:

    • Previously, the function only compared subsequent selections to the first one. If the first selection was of type other, any subsequent extrude-wall types would be ignored, and vice versa.
    • The fix ensures that all selections are evaluated before determining the final type. If all selections are extrudable, the result is extrude-wall. If there’s any non-extrudable selection, the type defaults to other, accurately reflecting the mixed nature of the selection set.

These changes ensure the selection logic works as expected for both single and multiple selections.

Other Findings:

  1. Generalization: Currently, everything is marked as an extrude-wall, including not-extruded sketches, faces, and edges. Since it does not block me from multiple fillets and will be addressed in the PR mentioned above by @Irev-Dev - I am ignoring it.
  2. nodeHasExtrude: Returns true even if an extrude does not exist. Shall I fix it in a separate PR ?

Next steps:

I am 1 step away from the multiple fillets working, only one thing left to address is:

const updatedAst = await kclManager.updateAst(modifiedAst, true, {
    focusPath: pathToFilletNode,
  })

commenting out the focusPath works:
Screenshot 2024-09-14 at 19 36 34

Screenshot 2024-09-14 at 19 36 11

Copy link

qa-wolf bot commented Sep 14, 2024

QA Wolf here! As you write new code it's important that your test coverage is keeping up.
Click here to request test coverage for this PR!

Copy link

vercel bot commented Sep 14, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
modeling-app ✅ Ready (Inspect) Visit Preview Sep 14, 2024 6:21pm

@max-mrgrsk max-mrgrsk self-assigned this Sep 14, 2024
@max-mrgrsk max-mrgrsk added desktop-app Issues from the desktop app. polish labels Sep 14, 2024
Copy link
Collaborator

@franknoirot franknoirot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it'll work for the purposes of unblocking you so I support it, but I do think we should rethink the generic approach in future.

Instead of this getSelectionType and canExtrudeSectionItem stuff, I think future selection command argument configurations should pass in their own validate() functions, which inspect the raw selection to see if it is valid for that command.

Comment on lines +463 to +466
const singleSelection = {
...selection,
codeBasedSelections: [selection.codeBasedSelections[i]],
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is likely a nit, but aren't you already set up to isolate the codeBasedSelections up within the canExtrudeSelectionItem function itself?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nah, can extrude selection gets as an argument the whooooole list of selections and an index of the one to check. While isSketchPile is expecting only one argument - selection. Not selection+index. So it gets the whole array of selections and just fails to work with it.
Screenshot 2024-09-17 at 22 19 10

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should rethink the generic approach in future.
@franknoirot
agree, those are good points, probably will be covered by #3837

@max-mrgrsk max-mrgrsk marked this pull request as ready for review September 17, 2024 20:30
@max-mrgrsk max-mrgrsk merged commit 62b7884 into main Sep 17, 2024
24 checks passed
@max-mrgrsk max-mrgrsk deleted the max-getselectiontype-improvement-for-multiple-selections branch September 17, 2024 20:32
@Irev-Dev Irev-Dev mentioned this pull request Sep 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
desktop-app Issues from the desktop app. polish
Projects
None yet
Development

Successfully merging this pull request may close these issues.

getSelectionType needs improvement for handling multiple types and selections
3 participants