-
Notifications
You must be signed in to change notification settings - Fork 88
Selection Coercion Implementation #8498
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
Draft
max-mrgrsk
wants to merge
8
commits into
main
Choose a base branch
from
max/8400-selections-bug
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Added logic to support 'edgeCut' artifact type in getSweepArtifactFromSelection. The function now retrieves the associated sweep artifact by resolving the consumed edge, handling both 'segment' and 'sweepEdge' cases.
Introduces coerceSelectionsToBody to convert selections containing faces or edges to their parent body artifacts. This utility helps commands that require body-level selections by ensuring only body artifacts are returned, handling various artifact types and avoiding duplicates.
Adds logic to automatically coerce selections to body types (path, sweep, compositeSolid) when the argument only accepts bodies. Updates selection filter handling to ensure correct selection state after coercion, improving support for body-only commands in the command bar.
Added an optional selectionsToRestore parameter to setSelectionFilter in KclManager and passed it to setSelectionFilter implementation. This allows restoring selections when setting the filter.
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Introduces unit tests for getSweepArtifactFromSelection and coerceSelectionsToBody functions, verifying correct artifact resolution and selection coercion behavior in artifactGraph.
Updates setSelectionFilter to explicitly pass handleSelectionBatchFn as an argument, ensuring the correct function is used for selection batch handling.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Selection Coercion Implementation
Problem
When users select a face or edge and then click a command button that only works with bodies (like Pattern Linear 3D, Pattern Circular 3D, Translate, Rotate, Scale, Clone, and all Boolean operations), the selection would pass initial validation but fail at submission time with an error.
The issue occurred because:
selectionFilter
was set to['object']
which allows clicking on bodiesSolution
Implemented a selection coercion mechanism that automatically converts face/edge selections to their parent body selections immediately when the command button is clicked, providing instant visual feedback in the viewport.
Changes Made
1. New Utility Function (
src/lang/std/artifactGraph.ts
)Enhanced
getSweepArtifactFromSelection()
function:edgeCut
artifact type in addition to existing typessweepEdge
,segment
,wall
,cap
, andedgeCut
Added
coerceSelectionsToBody()
function:Selections
object that may contain faces, edges, or bodiesgetSweepArtifactFromSelection()
once to find the parent bodySelections
object containing only body artifacts2. Component-Level Coercion (
src/components/CommandBar/CommandBarSelectionMixedInput.tsx
)Added coercion logic that runs immediately when the command button is clicked:
First useEffect:
selectionTypes
includes 'path', 'sweep', or 'compositeSolid')coerceSelectionsToBody()
selectionType: 'completeSelection'
to update the modeling machine statehasCoercedSelections
flag to prevent infinite loopsSecond useEffect (only bodies are clickable):
hasCoercedSelections
flag)setSelectionFilter()
with the coerced selections3. Selection Filter Batching (
src/lang/KclSingleton.ts
)Updated
setSelectionFilter()
method:selectionsToRestore
parameter to the public APIKclManager
classDetailed Flow
Before Fix:
After Fix - Complete Step-by-Step:
['face', 'edge', 'curve', 'object']
)selectionTypes: ['path', 'sweep', 'compositeSolid']
)coerceSelectionsToBody(selection, artifactGraph)
'Set selection'
event withselectionType: 'completeSelection'
to modeling machineselectionRanges.graphSelections = [pathArtifact]
hasCoercedSelections = true
arg.selectionFilter === ['object']
(body-only filter)setSelectionFilter(['object'], selection)
defaultSelectionFilter(selection)
['face', 'edge', 'curve', 'object']
Why Two useEffects:
Benefits
Commands Affected
The coercion applies to all commands with
selectionTypes: ['path', 'sweep', 'compositeSolid']
:Visual States
The selection content (what's in state) is always the same (just the PATH/SWEEP artifact), but what's visually highlighted differs based on the active selection filter and how the selection was made.
Three Visual States:
After Coercion (filter:
['object']
):select_add
with body ID, filter =['object']
Clicking Body in Viewport (filter:
['object']
):select_with_point
, filter =['object']
After Clicking Continue (filter: default):
select_add
with body ID, filter =['face', 'edge', 'solid2d', 'curve', 'object']